|
3 | 3 |
|
4 | 4 | using namespace AlphaMW2::Game;
|
5 | 5 |
|
| 6 | +#ifdef COMMON_FN_NAMESPACE |
| 7 | +#undef COMMON_FN_NAMESPACE |
| 8 | +#endif |
| 9 | +#define COMMON_FN_NAMESPACE AlphaMW2Common |
6 | 10 |
|
7 |
| -void AlphaMW2::ToggleGodMode(Menu *pMenu) |
8 |
| -{ |
9 |
| - int iClientNum = pMenu->GetClientNum(); |
| 11 | +#include "Games\Common\CommonFunctions.h" |
| 12 | +#include "Games\Common\MultiplayerFunctions.h" |
10 | 13 |
|
11 |
| - const int GOD_MODE_ON = 4097; |
12 |
| - const int GOD_MODE_OFF = 4096; |
13 | 14 |
|
14 |
| - if (GetEntity(iClientNum)->flags == GOD_MODE_OFF) |
15 |
| - { |
16 |
| - GetEntity(iClientNum)->flags = GOD_MODE_ON; |
17 |
| - iPrintLn(iClientNum, "God Mode ^2On"); |
18 |
| - } |
19 |
| - else |
20 |
| - { |
21 |
| - GetEntity(iClientNum)->flags = GOD_MODE_OFF; |
22 |
| - iPrintLn(iClientNum, "God Mode ^1Off"); |
23 |
| - } |
24 |
| -} |
| 15 | +void AlphaMW2::ToggleGodMode(Menu *pMenu) { COMMON_FN_NAMESPACE::ToggleGodModeMP(pMenu); } |
25 | 16 |
|
26 |
| -void AlphaMW2::ToggleFallDamage(Menu *pMenu) |
27 |
| -{ |
28 |
| - int iClientNum = pMenu->GetClientNum(); |
29 |
| - |
30 |
| - if (Dvar_GetFloat("bg_fallDamageMinHeight") == 128.0f) |
31 |
| - { |
32 |
| - SetClientDvar(-1, "bg_fallDamageMinHeight", "9998"); |
33 |
| - SetClientDvar(-1, "bg_fallDamageMaxHeight", "9999"); |
34 |
| - iPrintLn(iClientNum, "Fall Damage ^2Off"); |
35 |
| - } |
36 |
| - else |
37 |
| - { |
38 |
| - SetClientDvar(-1, "bg_fallDamageMinHeight", "128"); |
39 |
| - SetClientDvar(-1, "bg_fallDamageMaxHeight", "300"); |
40 |
| - iPrintLn(iClientNum, "Fall Damage ^1On"); |
41 |
| - } |
42 |
| -} |
| 17 | +void AlphaMW2::ToggleFallDamage(Menu *pMenu) { COMMON_FN_NAMESPACE::ToggleFallDamage(pMenu, 0x82023F50); } |
43 | 18 |
|
44 | 19 | void AlphaMW2::ToggleAmmo(Menu *pMenu)
|
45 | 20 | {
|
46 |
| - int iClientNum = pMenu->GetClientNum(); |
47 |
| - |
48 |
| - if (!Dvar_GetBool("player_sustainAmmo")) |
49 |
| - { |
50 |
| - SetClientDvar(-1, "player_sustainAmmo", "1"); |
51 |
| - iPrintLn(iClientNum, "Unlimited Ammo ^2On"); |
52 |
| - } |
53 |
| - else |
54 |
| - { |
55 |
| - SetClientDvar(-1, "player_sustainAmmo", "0"); |
56 |
| - iPrintLn(iClientNum, "Unlimited Ammo ^1Off"); |
57 |
| - } |
58 |
| -} |
59 |
| - |
60 |
| -void AlphaMW2::SpawnCP(Menu *pMenu) |
61 |
| -{ |
62 |
| - int iClientNum = pMenu->GetClientNum(); |
63 |
| - |
64 |
| - gentity_s *currentMapBrushModel = GetCurrentMapBrushModel(); |
65 |
| - |
66 |
| - // Return early if the map is not supported |
67 |
| - if (!currentMapBrushModel) |
68 |
| - { |
69 |
| - iPrintLn(iClientNum, "^1You cannot spawn a Care Package on this map!"); |
70 |
| - return; |
71 |
| - } |
72 |
| - |
73 |
| - // Get the player's current position |
74 |
| - float distance = 150.0f; |
75 |
| - vec3 origin = GetPlayerState(iClientNum)->origin; |
76 |
| - float viewY = GetPlayerState(iClientNum)->viewAngles.y; |
77 |
| - |
78 |
| - // Spawn an entity 150 units in front of the player and oriented towards |
79 |
| - // where they are looking at |
80 |
| - gentity_s *entity = G_Spawn(); |
81 |
| - entity->r.currentOrigin = Math::ToFront(origin, viewY, distance); |
82 |
| - entity->r.currentAngles.y = viewY; |
83 |
| - |
84 |
| - // Apply the care package mesh to the entity |
85 |
| - G_SetModel(entity, "com_plasticcase_friendly"); |
86 |
| - SP_script_model(entity); |
87 |
| - SV_UnlinkEntity(entity); |
88 |
| - entity->r.bmodel = 4; |
89 |
| - entity->state.index = currentMapBrushModel->state.index; |
90 |
| - |
91 |
| - // Make the care package solid |
92 |
| - int contents = entity->r.contents; |
93 |
| - SV_SetBrushModel(entity); |
94 |
| - contents |= entity->r.contents; |
95 |
| - entity->r.contents = contents; |
96 |
| - |
97 |
| - // Register the entity for the scene |
98 |
| - SV_LinkEntity(entity); |
99 |
| -} |
100 |
| - |
101 |
| -void AlphaMW2::ToggleSaveLoadBinds(Menu *pMenu) |
102 |
| -{ |
103 |
| - int iClientNum = pMenu->GetClientNum(); |
104 |
| - |
105 |
| - if (!pMenu->BindsEnabled()) |
106 |
| - { |
107 |
| - Cbuf_AddText(0, "unbind button_lshldr;unbind button_rshldr"); |
108 |
| - iPrintLn(iClientNum, "Press " CHAR_RB " to ^2Save^7 and " CHAR_LB " to ^2Load"); |
109 |
| - } |
110 |
| - else |
111 |
| - { |
112 |
| - Cbuf_AddText(0, "bind button_lshldr \"+smoke\";bind button_rshldr \"+frag\""); |
113 |
| - iPrintLn(iClientNum, "Save and Load binds ^1Off"); |
114 |
| - } |
115 |
| - |
116 |
| - pMenu->ToggleBinds(); |
117 |
| -} |
118 |
| - |
119 |
| -void AlphaMW2::SavePosition(Menu *pMenu) |
120 |
| -{ |
121 |
| - int iClientNum = pMenu->GetClientNum(); |
122 |
| - |
123 |
| - pMenu->SetSavedPos(GetPlayerState(iClientNum)->origin); |
124 |
| - pMenu->SetSavedAngles(GetPlayerState(iClientNum)->viewAngles); |
125 |
| - |
126 |
| - iPrintLn(iClientNum, "Position ^2Saved"); |
127 |
| -} |
128 |
| - |
129 |
| -void AlphaMW2::LoadPosition(Menu *pMenu) |
130 |
| -{ |
131 |
| - int iClientNum = pMenu->GetClientNum(); |
132 |
| - |
133 |
| - const vec3 &SavedPos = pMenu->GetSavedPos(); |
134 |
| - const vec3 &SavedAngles = pMenu->GetSavedAngles(); |
135 |
| - |
136 |
| - // Make sure the player previously saved their position |
137 |
| - if (SavedPos.isNull() || SavedAngles.isNull()) |
138 |
| - { |
139 |
| - iPrintLn(iClientNum, "^1Save a position first!"); |
140 |
| - return; |
141 |
| - } |
142 |
| - |
143 |
| - gentity_s *pPlayerEntity = GetEntity(iClientNum); |
144 |
| - |
145 |
| - SetClientOrigin(pPlayerEntity, reinterpret_cast<const float *>(&SavedPos)); |
146 |
| - SetClientViewAngle(pPlayerEntity, reinterpret_cast<const float *>(&SavedAngles)); |
147 |
| -} |
148 |
| - |
149 |
| -void AlphaMW2::ToggleUFO(Menu *pMenu) |
150 |
| -{ |
151 |
| - int iClientNum = pMenu->GetClientNum(); |
| 21 | + COMMON_FN_NAMESPACE::ToggleAmmoOptions Options; |
| 22 | + Options.pMenu = pMenu; |
| 23 | + Options.dwPatchAddress = 0x82113628; |
| 24 | + Options.dwDefaultValue = 0x7D1E4850; |
| 25 | + Options.dwPatchValue = 0x7D284B78; |
152 | 26 |
|
153 |
| - if (GetGClient(iClientNum)->mFlags != 2) |
154 |
| - { |
155 |
| - GetGClient(iClientNum)->mFlags = 2; |
156 |
| - iPrintLn(iClientNum, "Ufo ^2On"); |
157 |
| - } |
158 |
| - else |
159 |
| - { |
160 |
| - GetGClient(iClientNum)->mFlags = 0; |
161 |
| - iPrintLn(iClientNum, "Ufo ^1Off"); |
162 |
| - } |
| 27 | + COMMON_FN_NAMESPACE::ToggleAmmo(Options); |
163 | 28 | }
|
164 | 29 |
|
165 |
| -// Threaded function that makes the bot pick a team, then pick a class. |
166 |
| -static DWORD SpawnBotThread(Menu *pMenu) |
167 |
| -{ |
168 |
| - Sleep(150); |
169 |
| - |
170 |
| - // Prepare the commands to send to SV_ExecuteClientCommand |
171 |
| - int serverId = Memory::Read<int>(0x8355D5C4); |
172 |
| - std::string strChooseTeamCmd = Formatter::Format("mr %i 4 autoassign", serverId); |
173 |
| - std::string strChooseClassCmd = Formatter::Format("mr %i 11 class0", serverId); |
| 30 | +void AlphaMW2::SpawnCarePackage(Menu *pMenu) {COMMON_FN_NAMESPACE::SpawnCarePackage(pMenu); } |
174 | 31 |
|
175 |
| - // Get the address of the bot to pass to SV_ExecuteClientCommand |
176 |
| - DWORD dwBotAddr = Memory::Read<DWORD>(0x83577D98) + reinterpret_cast<gentity_s *>(pMenu->GetBot())->state.number * 0x97F80; |
| 32 | +void AlphaMW2::ToggleSaveLoadBinds(Menu *pMenu) { COMMON_FN_NAMESPACE::ToggleSaveLoadBinds(pMenu); } |
177 | 33 |
|
178 |
| - // Make the bot choose the opposite team and wait until it's done |
179 |
| - SV_ExecuteClientCommand(dwBotAddr, strChooseTeamCmd.c_str(), 1, 0); |
180 |
| - Sleep(150); |
| 34 | +void AlphaMW2::SavePosition(Menu *pMenu) { COMMON_FN_NAMESPACE::SavePosition(pMenu); } |
181 | 35 |
|
182 |
| - // Make the bot pick the first custom class and wait until it's done |
183 |
| - SV_ExecuteClientCommand(dwBotAddr, strChooseClassCmd.c_str(), 1, 0); |
184 |
| - Sleep(150); |
| 36 | +void AlphaMW2::LoadPosition(Menu *pMenu) { COMMON_FN_NAMESPACE::LoadPosition(pMenu); } |
185 | 37 |
|
186 |
| - // Set bot-related dvars to make it completely stand still |
187 |
| - SetClientDvar(-1, "testClients_doMove", "0"); |
188 |
| - SetClientDvar(-1, "testClients_doAttack", "0"); |
189 |
| - SetClientDvar(-1, "testClients_watchKillcam", "0"); |
190 |
| - |
191 |
| - // Teleport the bot in front of the player |
192 |
| - AlphaMW2::TeleportBotToMe(pMenu); |
193 |
| - |
194 |
| - return 0; |
195 |
| -} |
| 38 | +void AlphaMW2::ToggleUfo(Menu *pMenu) { COMMON_FN_NAMESPACE::ToggleUfo(pMenu); } |
196 | 39 |
|
197 | 40 | void AlphaMW2::SpawnBot(Menu *pMenu)
|
198 | 41 | {
|
199 |
| - gentity_s *pBot = reinterpret_cast<gentity_s *>(pMenu->GetBot()); |
| 42 | + COMMON_FN_NAMESPACE::SpawnBotOptions *pOptions = new COMMON_FN_NAMESPACE::SpawnBotOptions(); |
| 43 | + pOptions->pMenu = pMenu; |
| 44 | + pOptions->dwServerIdAddress = 0x8355D5C4; |
| 45 | + pOptions->dwClientsBaseAddress = 0x83577D98; |
200 | 46 |
|
201 |
| - // Prevent the user from spawning multiple bots |
202 |
| - if (pBot) |
203 |
| - { |
204 |
| - iPrintLn(pMenu->GetClientNum(), "^1There is already a bot in the game!"); |
205 |
| - return; |
206 |
| - } |
207 |
| - |
208 |
| - // Create the bot |
209 |
| - pBot = SV_AddTestClient(); |
210 |
| - pMenu->SetBot(pBot); |
211 |
| - |
212 |
| - // The rest of the code needs to execute on a separate thread because we need to |
213 |
| - // wait between certain operations. If this wasn't done on a separate thread, it |
214 |
| - // would block the game's thread and make it crash. |
215 |
| - Memory::Thread(reinterpret_cast<PTHREAD_START_ROUTINE>(SpawnBotThread), pMenu); |
| 47 | + COMMON_FN_NAMESPACE::SpawnBot(pOptions); |
216 | 48 | }
|
217 | 49 |
|
218 |
| -void AlphaMW2::TeleportBotToMe(Menu *pMenu) |
219 |
| -{ |
220 |
| - int iClientNum = pMenu->GetClientNum(); |
221 |
| - |
222 |
| - gentity_s *pBot = reinterpret_cast<gentity_s *>(pMenu->GetBot()); |
| 50 | +void AlphaMW2::TeleportBotToMe(Menu *pMenu) { COMMON_FN_NAMESPACE::TeleportBotToMe(pMenu); } |
223 | 51 |
|
224 |
| - // Make sure there is a bot in the game |
225 |
| - if (!pBot) |
226 |
| - { |
227 |
| - iPrintLn(iClientNum, "^1There is no bot in the game!"); |
228 |
| - return; |
229 |
| - } |
230 |
| - |
231 |
| - // Get the player's current position |
232 |
| - float fDistance = 100.0f; |
233 |
| - vec3 Origin = GetPlayerState(iClientNum)->origin; |
234 |
| - float fViewY = GetPlayerState(iClientNum)->viewAngles.y; |
235 |
| - |
236 |
| - // Teleport the bot in front of the player |
237 |
| - pBot->client->ps.origin = Math::ToFront(Origin, fViewY, fDistance); |
238 |
| -} |
239 |
| - |
240 |
| -void AlphaMW2::ToggleBotMovement(Menu *pMenu) |
241 |
| -{ |
242 |
| - int iClientNum = pMenu->GetClientNum(); |
243 |
| - |
244 |
| - gentity_s *pBot = reinterpret_cast<gentity_s *>(pMenu->GetBot()); |
245 |
| - |
246 |
| - // Make sure there is a bot in the game |
247 |
| - if (!pBot) |
248 |
| - { |
249 |
| - iPrintLn(iClientNum, "^1There is no bot in the game!"); |
250 |
| - return; |
251 |
| - } |
252 |
| - |
253 |
| - if (Dvar_GetBool("testClients_doMove")) |
254 |
| - { |
255 |
| - SetClientDvar(-1, "testClients_doMove", "0"); |
256 |
| - iPrintLn(iClientNum, "Bot ^2Frozen"); |
257 |
| - } |
258 |
| - else |
259 |
| - { |
260 |
| - SetClientDvar(-1, "testClients_doMove", "1"); |
261 |
| - iPrintLn(iClientNum, "Bot ^1Unfrozen"); |
262 |
| - } |
263 |
| -} |
| 52 | +void AlphaMW2::ToggleBotMovement(Menu *pMenu) { COMMON_FN_NAMESPACE::ToggleBotMovement(pMenu); } |
0 commit comments