4#include "../Commands.h"
6#include "../PluginManager/PluginManager.h"
7#include "../IBaseApi.h"
8#include <../Private/Ark/Globals.h>
9#include "Containers/UnrealString.h"
10#include "HAL/UnrealMemory.h"
11#include <Logger/Logger.h>
45 auto& hooks = API::game_api->GetHooks();
46 hooks->SetHook(
"UEngine.Init(IEngineLoop*)", &Hook_UEngine_Init, &UEngine_Init_original);
47 hooks->SetHook(
"UWorld.Tick(ELevelTick,float)", &Hook_UWorld_Tick, &UWorld_Tick_original);
48 hooks->SetHook(
"AShooterGameMode.InitGame(FString&,FString&,FString&)", &Hook_AShooterGameMode_InitGame, &AShooterGameMode_InitGame_original);
49 hooks->SetHook(
"AShooterPlayerController.ServerSendChatMessage_Implementation(FString&,EChatSendMode::Type,int)", &Hook_AShooterPlayerController_ServerSendChatMessage_Impl, &AShooterPlayerController_ServerSendChatMessage_Impl_original);
50 hooks->SetHook(
"AShooterPlayerController.ConsoleCommand(FString&,bool)", &Hook_AShooterPlayerController_ConsoleCommand, &AShooterPlayerController_ConsoleCommand_original);
51 hooks->SetHook(
"RCONClientConnection.ProcessRCONPacket(RCONPacket&,UWorld*)", &Hook_RCONClientConnection_ProcessRCONPacket, &RCONClientConnection_ProcessRCONPacket_original);
52 hooks->SetHook(
"AGameState.DefaultTimer()", &Hook_AGameState_DefaultTimer, &AGameState_DefaultTimer_original);
53 hooks->SetHook(
"AShooterGameMode.BeginPlay()", &Hook_AShooterGameMode_BeginPlay, &AShooterGameMode_BeginPlay_original);
54 hooks->SetHook(
"URCONServer.Init(FString,int,UShooterCheatManager*)", &Hook_URCONServer_Init, &URCONServer_Init_original);
55 hooks->SetHook(
"AShooterPlayerController.OnPossess(APawn*)", &Hook_AShooterPlayerController_OnPossess, &AShooterPlayerController_OnPossess_original);
56 hooks->SetHook(
"AShooterGameMode.Logout(AController*)", &Hook_AShooterGameMode_Logout, &AShooterGameMode_Logout_original);
57 hooks->SetHook(
"UShooterCheatManager.Broadcast(FString&)", &Hook_UShooterCheatManager_Broadcast, &UShooterCheatManager_Broadcast_original);
58 hooks->SetHook(
"AShooterGameMode.HandleNewPlayer_Implementation(AShooterPlayerController*,UPrimalPlayerData*,AShooterCharacter*,bool)", &Hook_AShooterGameMode_HandleNewPlayer_Implementation, &AShooterGameMode_HandleNewPlayer_Implementation_original);
60 Log::GetLog()->info(
"Initialized hooks\n");
67 UEngine_Init_original(_this, InEngineLoop);
69 Log::GetLog()->info(
"UGameEngine::Init was called");
70 Log::GetLog()->info(
"Loading plugins..\n");
74 dynamic_cast<API::IBaseApi&>(*API::game_api).RegisterCommands();
79 Commands* command =
dynamic_cast<Commands*>(API::game_api->GetCommands().get());
83 UWorld_Tick_original(world, tick_type, delta_seconds);
88 Log::GetLog()->info(
"AShooterGameMode::InitGame was called");
89 dynamic_cast<ApiUtils&>(*API::game_api->GetApiUtils()).SetShooterGameMode(a_shooter_game_mode);
90 dynamic_cast<ApiUtils&>(*API::game_api->GetApiUtils()).SetWorld(a_shooter_game_mode->GetWorld());
92 AShooterGameMode_InitGame_original(a_shooter_game_mode, map_name, options, error_message);
94 const auto& actors = AsaApi::GetApiUtils().GetWorld()->PersistentLevelField().Get()->ActorsField();
95 for (
auto actor : actors)
97 FString bp = AsaApi::GetApiUtils().GetBlueprint(actor);
98 if (bp.Equals(
"Blueprint'/Script/ShooterGame.PrimalPersistentWorldData'"))
100 if (actor->TargetingTeamField() == 0)
101 actor->TargetingTeamField() = a_shooter_game_mode->ServerIDField();
103 a_shooter_game_mode->MyServerIdField() = FString(std::to_string(actor->TargetingTeamField()));
104 a_shooter_game_mode->ServerIDField() = actor->TargetingTeamField();
105 Log::GetLog()->info(
"SERVER ID: {}", a_shooter_game_mode->ServerIDField());
111 dynamic_cast<ApiUtils&>(*API::game_api->GetApiUtils()).CheckMessagingManagersRequirements();
119 const auto spam_check = now_time - last_chat_time < 1.0;
120 if (last_chat_time > 0 && spam_check)
125 const auto command_executed =
dynamic_cast<AsaApi::Commands&>(*API::game_api->GetCommands()).CheckChatCommands(player_controller, message, mode, senderPlatform);
127 const auto prevent_default =
dynamic_cast<AsaApi::Commands&>(*API::game_api->GetCommands()).CheckOnChatMessageCallbacks(player_controller, message, mode, senderPlatform, spam_check, command_executed);
129 if (command_executed || prevent_default)
132 AShooterPlayerController_ServerSendChatMessage_Impl_original(player_controller, message, mode, senderPlatform);
137 if (
dynamic_cast<Commands&>(*API::game_api->GetCommands()).CheckConsoleCommands(_this, Command, bWriteToLog))
141 return _this->PlayerField().Get()->ConsoleCommand(result, Command,
false);
143 return AShooterPlayerController_ConsoleCommand_original(_this, result, Command, bWriteToLog);
150 if (
dynamic_cast<Commands&>(*API::game_api->GetCommands()).CheckRconCommands(_this, packet, in_world))
154 RCONClientConnection_ProcessRCONPacket_original(_this, packet, in_world);
159 Commands* command =
dynamic_cast<Commands*>(API::game_api->GetCommands().get());
165 AGameState_DefaultTimer_original(_this);
170 AShooterGameMode_BeginPlay_original(_AShooterGameMode);
171 dynamic_cast<ApiUtils&>(*API::game_api->GetApiUtils()).SetStatus(ServerStatus::Ready);
176 dynamic_cast<ApiUtils&>(*API::game_api->GetApiUtils()).SetCheatManager(SCheatManager);
178 return URCONServer_Init_original(_this, Password, InPort, SCheatManager);
183 dynamic_cast<ApiUtils&>(*API::game_api->GetApiUtils()).SetPlayerController(_this);
185 AShooterPlayerController_OnPossess_original(_this, inPawn);
191 dynamic_cast<ApiUtils&>(*API::game_api->GetApiUtils()).RemovePlayerController(Exiting_SPC);
193 AShooterGameMode_Logout_original(_this, Exiting);
204 return UShooterCheatManager_Broadcast_original(_this, msg);
209 dynamic_cast<ApiUtils&>(*API::game_api->GetApiUtils()).SetPlayerController(NewPlayer);
211 return AShooterGameMode_HandleNewPlayer_Implementation_original(_this, NewPlayer, PlayerData, PlayerCharacter, bIsFromLogin);
#define DECLARE_HOOK(name, returnType,...)
void LoadAllPlugins()
Find and load all plugins.
static PluginManager & Get()
static void DetectPluginChangesTimerCallback()
Checks for auto plugin reloads.
void CheckOnTickCallbacks(float delta_seconds)
void CheckOnTimerCallbacks()
virtual AShooterGameMode * GetShooterGameMode() const =0
Returns a pointer to AShooterGameMode.
static FORCEINLINE FString GetEOSIDFromController(AController *controller)
Returns EOS ID from player controller.
virtual UWorld * GetWorld() const =0
Returns a pointer to UWorld.
static const FColor Yellow
void Hook_UShooterCheatManager_Broadcast(UShooterCheatManager *_this, FString *msg)
void Hook_AShooterGameMode_BeginPlay(AShooterGameMode *_AShooterGameMode)
void Hook_AShooterGameMode_Logout(AShooterGameMode *_this, AController *Exiting)
void Hook_AShooterPlayerController_OnPossess(AShooterPlayerController *_this, APawn *inPawn)
IApiUtils & GetApiUtils()
void Hook_AShooterGameMode_InitGame(AShooterGameMode *a_shooter_game_mode, FString *map_name, FString *options, FString *error_message)
void Hook_AShooterPlayerController_ServerSendChatMessage_Impl(AShooterPlayerController *player_controller, FString *message, int mode, int senderPlatform)
bool Hook_AShooterGameMode_HandleNewPlayer_Implementation(AShooterGameMode *_this, AShooterPlayerController *NewPlayer, UPrimalPlayerData *PlayerData, AShooterCharacter *PlayerCharacter, bool bIsFromLogin)
bool Hook_URCONServer_Init(URCONServer *_this, FString *Password, unsigned int InPort, UShooterCheatManager *SCheatManager)
void Hook_AGameState_DefaultTimer(AGameState *_this)
void Hook_UEngine_Init(DWORD64 _this, DWORD64 InEngineLoop)
void Hook_RCONClientConnection_ProcessRCONPacket(RCONClientConnection *_this, RCONPacket *packet, UWorld *in_world)
FString * Hook_AShooterPlayerController_ConsoleCommand(AShooterPlayerController *_this, FString *result, FString *Command, bool bWriteToLog)
void Hook_UWorld_Tick(DWORD64 world, DWORD64 tick_type, float delta_seconds)
void SendServerChatMessage(FString *MessageText, FLinearColor MessageColor, bool bIsBold, int ReceiverTeamId, int ReceiverPlayerID, FString SenderID)
long double & LastChatMessageTimeField()
bool & IsAuthenticatedField()
AShooterPlayerController *& MyPCField()
APlayerController * GetFirstPlayerController()
long double & TimeSecondsField()