Skip to content

Commit ed17e43

Browse files
Merge branch 'refactoring'
2 parents 031b66e + 0e6e987 commit ed17e43

31 files changed

+600
-1202
lines changed

Hayzen/Hayzen.vcxproj

+3
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
</Deploy>
7272
</ItemDefinitionGroup>
7373
<ItemGroup>
74+
<ClInclude Include="src\Games\Common\MultiplayerFunctions.h" />
75+
<ClInclude Include="src\Games\Common\SpecOpsFunctions.h" />
7476
<ClInclude Include="src\Elements\Rectangle.h" />
7577
<ClInclude Include="src\Core\Title.h" />
7678
<ClInclude Include="src\Core\Menu.h" />
@@ -82,6 +84,7 @@
8284
<ClInclude Include="src\Games\AlphaMW2\MenuFunctions.h" />
8385
<ClInclude Include="src\Games\AlphaMW2\AlphaMW2Title.h" />
8486
<ClInclude Include="src\Games\AlphaMW2\Structs.h" />
87+
<ClInclude Include="src\Games\Common\CommonFunctions.h" />
8588
<ClInclude Include="src\Games\MW2\GameFunctions.h" />
8689
<ClInclude Include="src\Games\MW2\MenuFunctions.h" />
8790
<ClInclude Include="src\Games\MW2\MW2Title.h" />

Hayzen/Hayzen.vcxproj.filters

+3
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,8 @@
6262
<ClInclude Include="src\Games\SpecOps\AlphaMW2\MenuFunctions.h" />
6363
<ClInclude Include="src\Games\SpecOps\AlphaMW2\SpecOpsAlphaMW2Title.h" />
6464
<ClInclude Include="src\Games\SpecOps\AlphaMW2\Structs.h" />
65+
<ClInclude Include="src\Games\Common\CommonFunctions.h" />
66+
<ClInclude Include="src\Games\Common\MultiplayerFunctions.h" />
67+
<ClInclude Include="src\Games\Common\SpecOpsFunctions.h" />
6568
</ItemGroup>
6669
</Project>

Hayzen/src/Games/AlphaMW2/AlphaMW2Title.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ void AlphaMW2Title::CreateStructure()
4343
pMain->AddChild(MakeOption("God Mode", 0, AlphaMW2::ToggleGodMode));
4444
pMain->AddChild(MakeOption("Fall Damage", 1, AlphaMW2::ToggleFallDamage));
4545
pMain->AddChild(MakeOption("Ammo", 2, AlphaMW2::ToggleAmmo));
46-
pMain->AddChild(MakeOption("Spawn Care Package", 3, AlphaMW2::SpawnCP));
46+
pMain->AddChild(MakeOption("Spawn Care Package", 3, AlphaMW2::SpawnCarePackage));
4747
s_RootOption.AddChild(pMain);
4848

4949
// Teleport section
5050
auto pTeleport = MakeOption("Teleport", 1);
5151
pTeleport->AddChild(MakeOption("Save/Load Binds", 0, AlphaMW2::ToggleSaveLoadBinds));
5252
pTeleport->AddChild(MakeOption("Save Position", 1, AlphaMW2::SavePosition));
5353
pTeleport->AddChild(MakeOption("Load Position", 2, AlphaMW2::LoadPosition));
54-
pTeleport->AddChild(MakeOption("UFO", 3, AlphaMW2::ToggleUFO));
54+
pTeleport->AddChild(MakeOption("UFO", 3, AlphaMW2::ToggleUfo));
5555
s_RootOption.AddChild(pTeleport);
5656

5757
// Bot section

Hayzen/src/Games/AlphaMW2/GameFunctions.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ void (*Cbuf_AddText)(int localClientNum, const char *text) = reinterpret_cast<vo
1818

1919
bool (*Dvar_GetBool)(const char *dvarName) = reinterpret_cast<bool(*)(const char *)>(0x82303B00);
2020

21-
float (*Dvar_GetFloat)(const char *dvarName) = reinterpret_cast<float(*)(const char *)>(0x82303BD0);
22-
2321
const char *(*Dvar_GetString)(const char *dvarName) = reinterpret_cast<const char *(*)(const char *)>(0x82303CC0);
2422

2523
playerState_s *(*GetPlayerState)(int clientNum) = reinterpret_cast<playerState_s *(*)(int)>(0x8222C108);

Hayzen/src/Games/AlphaMW2/GameFunctions.h

-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ extern void (*Cbuf_AddText)(int localClientNum, const char *text);
1717

1818
extern bool (*Dvar_GetBool)(const char *dvarName);
1919

20-
extern float (*Dvar_GetFloat)(const char *dvarName);
21-
2220
extern const char *(*Dvar_GetString)(const char *dvarName);
2321

2422
extern playerState_s *(*GetPlayerState)(int clientNum);

Hayzen/src/Games/AlphaMW2/MenuFunctions.cpp

+26-237
Original file line numberDiff line numberDiff line change
@@ -3,261 +3,50 @@
33

44
using namespace AlphaMW2::Game;
55

6+
#ifdef COMMON_FN_NAMESPACE
7+
#undef COMMON_FN_NAMESPACE
8+
#endif
9+
#define COMMON_FN_NAMESPACE AlphaMW2Common
610

7-
void AlphaMW2::ToggleGodMode(Menu *pMenu)
8-
{
9-
int iClientNum = pMenu->GetClientNum();
11+
#include "Games\Common\CommonFunctions.h"
12+
#include "Games\Common\MultiplayerFunctions.h"
1013

11-
const int GOD_MODE_ON = 4097;
12-
const int GOD_MODE_OFF = 4096;
1314

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); }
2516

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); }
4318

4419
void AlphaMW2::ToggleAmmo(Menu *pMenu)
4520
{
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;
15226

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);
16328
}
16429

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); }
17431

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); }
17733

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); }
18135

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); }
18537

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); }
19639

19740
void AlphaMW2::SpawnBot(Menu *pMenu)
19841
{
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;
20046

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);
21648
}
21749

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); }
22351

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); }

Hayzen/src/Games/AlphaMW2/MenuFunctions.h

+2-13
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,26 @@
77
namespace AlphaMW2
88
{
99

10-
// Toggle God Mode.
1110
void ToggleGodMode(Menu *pMenu);
1211

13-
// Toggle fall damage.
1412
void ToggleFallDamage(Menu *pMenu);
1513

16-
// Toggle unlimited ammo.
1714
void ToggleAmmo(Menu *pMenu);
1815

19-
// Spawn a care package.
20-
void SpawnCP(Menu *pMenu);
16+
void SpawnCarePackage(Menu *pMenu);
2117

22-
// Toggle save and load binds.
2318
void ToggleSaveLoadBinds(Menu *pMenu);
2419

25-
// Save the current player's position.
2620
void SavePosition(Menu *pMenu);
2721

28-
// Load the previously saved player's position.
2922
void LoadPosition(Menu *pMenu);
3023

31-
// Toggle UFO.
32-
void ToggleUFO(Menu *pMenu);
24+
void ToggleUfo(Menu *pMenu);
3325

34-
// Spawn a bot.
3526
void SpawnBot(Menu *pMenu);
3627

37-
// Teleport the bot in front of the player.
3828
void TeleportBotToMe(Menu *pMenu);
3929

40-
// Toggle the bot's movement.
4130
void ToggleBotMovement(Menu *pMenu);
4231

4332
}

0 commit comments

Comments
 (0)