Ark Server API (ASE) - Wiki
Loading...
Searching...
No Matches
HooksImpl.cpp
Go to the documentation of this file.
1#include "HooksImpl.h"
2
3#include "ApiUtils.h"
4#include "../Commands.h"
5#include "../Hooks.h"
6#include "../PluginManager/PluginManager.h"
7#include "../IBaseApi.h"
8
9#include <Logger/Logger.h>
10
11namespace AtlasApi
12{
13 // Hooks declaration
14 DECLARE_HOOK(UEngine_Init, void, DWORD64, DWORD64);
16 DECLARE_HOOK(UWorld_Tick, void, DWORD64, DWORD64, float);
27
28 void InitHooks()
29 {
30 auto& hooks = API::game_api->GetHooks();
31
32 hooks->SetHook("UEngine.Init", &Hook_UEngine_Init, &UEngine_Init_original);
33 hooks->SetHook("UWorld.InitWorld", &Hook_UWorld_InitWorld, &UWorld_InitWorld_original);
34 hooks->SetHook("UWorld.Tick", &Hook_UWorld_Tick, &UWorld_Tick_original);
35 hooks->SetHook("AShooterGameMode.InitGame", &Hook_AShooterGameMode_InitGame,
36 &AShooterGameMode_InitGame_original);
37 hooks->SetHook("AShooterPlayerController.ServerSendChatMessage_Implementation",
38 &Hook_AShooterPlayerController_ServerSendChatMessage_Impl,
39 &AShooterPlayerController_ServerSendChatMessage_Impl_original);
40 hooks->SetHook("APlayerController.ConsoleCommand", &Hook_APlayerController_ConsoleCommand,
41 &APlayerController_ConsoleCommand_original);
42 hooks->SetHook("RCONClientConnection.ProcessRCONPacket", &Hook_RCONClientConnection_ProcessRCONPacket,
43 &RCONClientConnection_ProcessRCONPacket_original);
44 hooks->SetHook("AGameState.DefaultTimer", &Hook_AGameState_DefaultTimer, &AGameState_DefaultTimer_original);
45 hooks->SetHook("AShooterGameMode.BeginPlay", &Hook_AShooterGameMode_BeginPlay,
46 &AShooterGameMode_BeginPlay_original);
47 hooks->SetHook("URCONServer.Init", &Hook_URCONServer_Init, &URCONServer_Init_original);
48 hooks->SetHook("AShooterPlayerController.Possess", &Hook_AShooterPlayerController_Possess,
49 &AShooterPlayerController_Possess_original);
50 hooks->SetHook("AShooterGameMode.Logout", &Hook_AShooterGameMode_Logout, &AShooterGameMode_Logout_original);
51
52 Log::GetLog()->info("Initialized hooks\n");
53 }
54
55 // Hooks
56
57 void Hook_UEngine_Init(DWORD64 _this, DWORD64 InEngineLoop)
58 {
59 UEngine_Init_original(_this, InEngineLoop);
60
61 Log::GetLog()->info("UGameEngine::Init was called");
62 Log::GetLog()->info("Loading plugins..\n");
63
65
66 dynamic_cast<API::IBaseApi&>(*API::game_api).RegisterCommands();
67 }
68
69 void Hook_UWorld_InitWorld(UWorld* world, DWORD64 ivs)
70 {
71 Log::GetLog()->info("UWorld::InitWorld was called");
72
73 dynamic_cast<ApiUtils&>(*API::game_api->GetApiUtils()).SetWorld(world);
74
75 UWorld_InitWorld_original(world, ivs);
76 }
77
78 void Hook_UWorld_Tick(DWORD64 world, DWORD64 tick_type, float delta_seconds)
79 {
80 dynamic_cast<ArkApi::Commands&>(*API::game_api->GetCommands()).CheckOnTickCallbacks(delta_seconds);
81
82 UWorld_Tick_original(world, tick_type, delta_seconds);
83 }
84
85 void Hook_AShooterGameMode_InitGame(AShooterGameMode* a_shooter_game_mode, FString* map_name, FString* options,
86 FString* error_message)
87 {
88 dynamic_cast<ApiUtils&>(*API::game_api->GetApiUtils()).SetShooterGameMode(a_shooter_game_mode);
89
90 AShooterGameMode_InitGame_original(a_shooter_game_mode, map_name, options, error_message);
91 }
92
94 AShooterPlayerController* player_controller, FString* message, EChatSendMode::Type mode)
95 {
96 const long double last_chat_time = player_controller->LastChatMessageTimeField();
98
99 const auto spam_check = now_time - last_chat_time < 1.0;
100 if (last_chat_time > 0 && spam_check)
101 {
102 return;
103 }
104
105 player_controller->LastChatMessageTimeField() = now_time;
106
107 const auto command_executed = dynamic_cast<ArkApi::Commands&>(*API::game_api->GetCommands()).
108 CheckChatCommands(player_controller, message, mode);
109
110 const auto prevent_default = dynamic_cast<ArkApi::Commands&>(*API::game_api->GetCommands()).
111 CheckOnChatMessageCallbacks(player_controller, message, mode, spam_check, command_executed);
112
113 if (command_executed || prevent_default)
114 {
115 return;
116 }
117
118 AShooterPlayerController_ServerSendChatMessage_Impl_original(player_controller, message, mode);
119 }
120
122 FString* cmd, bool write_to_log)
123 {
124 dynamic_cast<ArkApi::Commands&>(*API::game_api->GetCommands()).CheckConsoleCommands(
125 a_player_controller, cmd, write_to_log);
126
127 return APlayerController_ConsoleCommand_original(a_player_controller, result, cmd, write_to_log);
128 }
129
131 UWorld* in_world)
132 {
134 {
135 dynamic_cast<ArkApi::Commands&>(*API::game_api->GetCommands()).CheckRconCommands(_this, packet, in_world);
136 }
137
138 RCONClientConnection_ProcessRCONPacket_original(_this, packet, in_world);
139 }
140
142 {
143 dynamic_cast<ArkApi::Commands&>(*API::game_api->GetCommands()).CheckOnTimerCallbacks();
144
145 AGameState_DefaultTimer_original(_this);
146 }
147
149 {
150 AShooterGameMode_BeginPlay_original(_AShooterGameMode);
151
152 dynamic_cast<ApiUtils&>(*API::game_api->GetApiUtils()).SetStatus(ArkApi::ServerStatus::Ready);
153 }
154
155 bool Hook_URCONServer_Init(URCONServer* _this, FString Password, int InPort, UShooterCheatManager* SCheatManager)
156 {
157 dynamic_cast<ApiUtils&>(*API::game_api->GetApiUtils()).SetCheatManager(SCheatManager);
158
159 return URCONServer_Init_original(_this, Password, InPort, SCheatManager);
160 }
161
163 {
164 dynamic_cast<ApiUtils&>(*API::game_api->GetApiUtils()).SetPlayerController(_this);
165
166 AShooterPlayerController_Possess_original(_this, inPawn);
167 }
168
170 {
171 AShooterPlayerController* Exiting_SPC = static_cast<AShooterPlayerController*>(Exiting);
172 dynamic_cast<ApiUtils&>(*API::game_api->GetApiUtils()).RemovePlayerController(Exiting_SPC);
173
174 AShooterGameMode_Logout_original(_this, Exiting);
175 }
176} // namespace AtlasApi
#define DECLARE_HOOK(name, returnType,...)
Definition Base.h:690
void LoadAllPlugins()
Find and load all plugins.
static PluginManager & Get()
virtual UWorld * GetWorld() const =0
Returns a pointer to UWorld.
Definition Logger.h:9
static std::shared_ptr< spdlog::logger > & GetLog()
Definition Logger.h:22
Definition IBaseApi.h:9
IApiUtils & GetApiUtils()
Definition ApiUtils.cpp:99
void InitHooks()
Definition HooksImpl.cpp:28
void Hook_AGameState_DefaultTimer(AGameState *_this)
void Hook_UWorld_Tick(DWORD64 world, DWORD64 tick_type, float delta_seconds)
Definition HooksImpl.cpp:78
void Hook_AShooterPlayerController_Possess(AShooterPlayerController *_this, APawn *inPawn)
void Hook_AShooterGameMode_BeginPlay(AShooterGameMode *_AShooterGameMode)
void Hook_UEngine_Init(DWORD64 _this, DWORD64 InEngineLoop)
Definition HooksImpl.cpp:57
void Hook_UWorld_InitWorld(UWorld *world, DWORD64 ivs)
Definition HooksImpl.cpp:69
void Hook_AShooterGameMode_Logout(AShooterGameMode *_this, AController *Exiting)
bool Hook_URCONServer_Init(URCONServer *_this, FString Password, int InPort, UShooterCheatManager *SCheatManager)
void Hook_RCONClientConnection_ProcessRCONPacket(RCONClientConnection *_this, RCONPacket *packet, UWorld *in_world)
void Hook_AShooterGameMode_InitGame(AShooterGameMode *a_shooter_game_mode, FString *map_name, FString *options, FString *error_message)
Definition HooksImpl.cpp:85
FString * Hook_APlayerController_ConsoleCommand(APlayerController *a_player_controller, FString *result, FString *cmd, bool write_to_log)
void Hook_AShooterPlayerController_ServerSendChatMessage_Impl(AShooterPlayerController *player_controller, FString *message, EChatSendMode::Type mode)
Definition HooksImpl.cpp:93
long double & LastChatMessageTimeField()
Definition Actor.h:2521
bool & IsAuthenticatedField()
Definition Other.h:110
long double & TimeSecondsField()
Definition GameMode.h:452