Skip to content

Commit a93b17f

Browse files
Added a second player menu for MW2 Spec Ops
1 parent 114f142 commit a93b17f

File tree

4 files changed

+71
-2
lines changed

4 files changed

+71
-2
lines changed

Hayzen/src/Games/SpecOps/MW2/MW2.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ VOID SpecOpsMW2::CreateStructure()
6565
pTeleport->AddChild(MakeOption("Load Position", 2, SpecOpsMW2MenuFunctions::LoadPosition));
6666
pTeleport->AddChild(MakeOption("UFO", 3, SpecOpsMW2MenuFunctions::ToggleUFO));
6767
s_RootOption.AddChild(pTeleport);
68+
69+
auto pSecondPlayer = MakeOption("Second Player", 2);
70+
pSecondPlayer->AddChild(MakeOption("God Mode", 0, SpecOpsMW2MenuFunctions::ToggleSecondPlayerGodMode));
71+
pSecondPlayer->AddChild(MakeOption("Teleport to Me", 1, SpecOpsMW2MenuFunctions::TeleportSecondPlayerToMe));
72+
s_RootOption.AddChild(pSecondPlayer);
6873
}
6974

7075

Hayzen/src/Games/SpecOps/MW2/MenuFunctions.cpp

+59
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,62 @@ VOID SpecOpsMW2MenuFunctions::ToggleUFO(Menu* pMenu)
119119
pMenu->SetFeedbackText("Ufo ^1Off");
120120
}
121121
}
122+
123+
124+
//--------------------------------------------------------------------------------------
125+
// Name: ToggleSecondPlayerGodMode()
126+
// Desc: Toggle God Mode for the second player.
127+
//--------------------------------------------------------------------------------------
128+
VOID SpecOpsMW2MenuFunctions::ToggleSecondPlayerGodMode(Menu* pMenu)
129+
{
130+
// The second client num is always 1
131+
INT iSecondClientNum = 1;
132+
133+
// If the player name of the second client is empty, it means there is no second client
134+
gclient_s* pSecondClient = GetGClient(iSecondClientNum);
135+
if (!pSecondClient->connected)
136+
{
137+
pMenu->SetFeedbackText("^1No other player in the game!");
138+
return;
139+
}
140+
141+
playerState_s* playerState = SV_GetPlayerstateForClientNum(iSecondClientNum);
142+
143+
if (playerState->otherFlags == 0)
144+
{
145+
playerState->otherFlags = 1;
146+
pMenu->SetFeedbackText("Second Player God Mode ^2On");
147+
}
148+
else
149+
{
150+
playerState->otherFlags = 0;
151+
pMenu->SetFeedbackText("Second Player God Mode ^1Off");
152+
}
153+
}
154+
155+
156+
//--------------------------------------------------------------------------------------
157+
// Name: TeleportSecondPlayerToMe()
158+
// Desc: Teleport the second player in front of the first player.
159+
//--------------------------------------------------------------------------------------
160+
VOID SpecOpsMW2MenuFunctions::TeleportSecondPlayerToMe(Menu* pMenu)
161+
{
162+
// The second client num is always 1
163+
INT iSecondClientNum = 1;
164+
INT iFirstClientNum = pMenu->GetClientNum();
165+
166+
gclient_s* pSecondClient = GetGClient(iSecondClientNum);
167+
if (!pSecondClient->connected)
168+
{
169+
pMenu->SetFeedbackText("^1No other player in the game!");
170+
return;
171+
}
172+
173+
// Get the first player's current position
174+
FLOAT fDistance = 100.0f;
175+
vec3 Origin = SV_GetPlayerstateForClientNum(iFirstClientNum)->origin;
176+
FLOAT fViewY = SV_GetPlayerstateForClientNum(iFirstClientNum)->viewAngles.y;
177+
178+
// Teleport the second player in front of the first player
179+
pSecondClient->ps.origin = Math::ToFront(Origin, fViewY, fDistance);
180+
}

Hayzen/src/Games/SpecOps/MW2/MenuFunctions.h

+4
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,8 @@ VOID LoadPosition(Menu* pMenu);
1919

2020
VOID ToggleUFO(Menu* pMenu);
2121

22+
VOID ToggleSecondPlayerGodMode(Menu* pMenu);
23+
24+
VOID TeleportSecondPlayerToMe(Menu* pMenu);
25+
2226
}

Hayzen/src/Games/SpecOps/MW2/Structs.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ struct playerState_s
2121
struct gclient_s
2222
{
2323
playerState_s ps;
24-
CHAR padding1[0xB0];
24+
INT connected;
25+
CHAR padding1[0xAC];
2526
INT mFlags;
26-
CHAR padding2[0x27C];
27+
CHAR padding2[0x280];
2728
};
2829

2930
struct entityState_s

0 commit comments

Comments
 (0)