Skip to content

Commit 5aea85a

Browse files
Used the new version of XexUtils to hook functions
1 parent 68a9466 commit 5aea85a

15 files changed

+115
-215
lines changed

Hayzen/src/Core/Title.cpp

+4-16
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66

77
Menu Title::s_Menu;
88
Option Title::s_RootOption;
9+
Detour *Title::s_pSCR_DrawScreenFieldDetour = nullptr;
910

1011

1112
Title::~Title()
1213
{
1314
s_Menu.Stop();
1415
s_RootOption.Cleanup();
16+
17+
delete s_pSCR_DrawScreenFieldDetour;
1518
}
1619

1720
void Title::Init()
@@ -26,7 +29,7 @@ void Title::Init()
2629
void Title::SCR_DrawScreenFieldHook(const int localClientNum, int refreshedUI)
2730
{
2831
// Call the original SCR_DrawScreenField function
29-
SCR_DrawScreenFieldStub(localClientNum, refreshedUI);
32+
s_pSCR_DrawScreenFieldDetour->GetOriginal<decltype(&SCR_DrawScreenFieldHook)>()(localClientNum, refreshedUI);
3033

3134
// If the menu is not initialized, no need to go further
3235
if (!s_Menu.IsInitialized())
@@ -39,21 +42,6 @@ void Title::SCR_DrawScreenFieldHook(const int localClientNum, int refreshedUI)
3942
s_Menu.Render();
4043
}
4144

42-
void __declspec(naked) Title::SCR_DrawScreenFieldStub(const int localClientNum, int refreshedUI)
43-
{
44-
__asm
45-
{
46-
nop
47-
nop
48-
nop
49-
nop
50-
nop
51-
nop
52-
nop
53-
li r3, 0
54-
}
55-
}
56-
5745
void Title::SetDrawFunctionsPointers()
5846
{
5947
HudElem::R_RegisterFont = reinterpret_cast<R_REGISTERFONT>(m_dwRegisterFontFnAddr);

Hayzen/src/Core/Title.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ class Title
2424
// Create the menu structure (one implementation per game).
2525
virtual void CreateStructure() = 0;
2626

27+
// Pointer to the detour object for SCR_DrawScreenField.
28+
static Detour *s_pSCR_DrawScreenFieldDetour;
29+
2730
// Hook of a function that gets called every frame to execute the main loop on the game's thread.
2831
static void SCR_DrawScreenFieldHook(const int localClientNum, int refreshedUI);
29-
30-
// Stub to hold the original code of SCR_DrawScreenField.
31-
static void SCR_DrawScreenFieldStub(const int localClientNum, int refreshedUI);
3232
private:
3333
// Make the global drawing function pointers point to the current game's drawing functions.
3434
void SetDrawFunctionsPointers();

Hayzen/src/Games/AlphaMW2/AlphaMW2Title.cpp

+15-35
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
#include "Games\AlphaMW2\MenuFunctions.h"
55

66

7+
Detour *AlphaMW2Title::s_pScr_NotifyDetour = nullptr;
8+
Detour *AlphaMW2Title::s_pSV_ExecuteClientCommandDetour = nullptr;
9+
10+
11+
AlphaMW2Title::~AlphaMW2Title()
12+
{
13+
delete s_pScr_NotifyDetour;
14+
delete s_pSV_ExecuteClientCommandDetour;
15+
}
16+
717
void AlphaMW2Title::Init()
818
{
919
Xam::XNotify("Hayzen - MW2 Alpha Multiplayer Detected");
@@ -28,9 +38,9 @@ void AlphaMW2Title::Init()
2838
CreateStructure();
2939

3040
// Set up the function hooks
31-
Memory::HookFunctionStart(reinterpret_cast<DWORD *>(0x8218B5F0), reinterpret_cast<DWORD *>(SCR_DrawScreenFieldStub), reinterpret_cast<DWORD>(SCR_DrawScreenFieldHook));
32-
Memory::HookFunctionStart(reinterpret_cast<DWORD *>(0x822539C0), reinterpret_cast<DWORD *>(Scr_NotifyStub), reinterpret_cast<DWORD>(Scr_NotifyHook));
33-
Memory::HookFunctionStart(reinterpret_cast<DWORD *>(0x822B4700), reinterpret_cast<DWORD *>(SV_ExecuteClientCommandStub), reinterpret_cast<DWORD>(SV_ExecuteClientCommandHook));
41+
s_pSCR_DrawScreenFieldDetour = new Detour(0x8218B5F0, SCR_DrawScreenFieldHook);
42+
s_pScr_NotifyDetour = new Detour(0x822539C0, Scr_NotifyHook);
43+
s_pSV_ExecuteClientCommandDetour = new Detour(0x822B4700, SV_ExecuteClientCommandHook);
3444
}
3545

3646
void AlphaMW2Title::CreateStructure()
@@ -65,7 +75,7 @@ void AlphaMW2Title::CreateStructure()
6575
void AlphaMW2Title::Scr_NotifyHook(AlphaMW2::Game::gentity_s *entity, uint16_t stringValue, uint32_t paramCount)
6676
{
6777
// Call the original Scr_Notify function
68-
Scr_NotifyStub(entity, stringValue, paramCount);
78+
s_pScr_NotifyDetour->GetOriginal<decltype(&Scr_NotifyHook)>()(entity, stringValue, paramCount);
6979

7080
// If the client is not host, no need to go further
7181
int iClientNum = entity->state.number;
@@ -91,7 +101,7 @@ void AlphaMW2Title::Scr_NotifyHook(AlphaMW2::Game::gentity_s *entity, uint16_t s
91101
void AlphaMW2Title::SV_ExecuteClientCommandHook(int client, const char *s, int clientOK, int fromOldServer)
92102
{
93103
// Call the original Scr_Notify SV_ExecuteClientCommand
94-
SV_ExecuteClientCommandStub(client, s, clientOK, fromOldServer);
104+
s_pSV_ExecuteClientCommandDetour->GetOriginal<decltype(&SV_ExecuteClientCommandHook)>()(client, s, clientOK, fromOldServer);
95105

96106
// If the client is not host, no need to go further
97107
int iClientNum = (client - Memory::Read<int>(0x83577D98)) / 0x97F80;
@@ -102,33 +112,3 @@ void AlphaMW2Title::SV_ExecuteClientCommandHook(int client, const char *s, int c
102112
if (!strcmp(s, "matchdatadone"))
103113
s_Menu.Stop();
104114
}
105-
106-
void __declspec(naked) AlphaMW2Title::Scr_NotifyStub(AlphaMW2::Game::gentity_s *entity, uint16_t stringValue, uint32_t paramCount)
107-
{
108-
__asm
109-
{
110-
nop
111-
nop
112-
nop
113-
nop
114-
nop
115-
nop
116-
nop
117-
li r3, 1
118-
}
119-
}
120-
121-
void __declspec(naked) AlphaMW2Title::SV_ExecuteClientCommandStub(int client, const char *s, int clientOK, int fromOldServer)
122-
{
123-
__asm
124-
{
125-
nop
126-
nop
127-
nop
128-
nop
129-
nop
130-
nop
131-
nop
132-
li r3, 2
133-
}
134-
}

Hayzen/src/Games/AlphaMW2/AlphaMW2Title.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,22 @@
1010
class AlphaMW2Title : public Title
1111
{
1212
public:
13+
~AlphaMW2Title();
14+
1315
// Set the draw function pointers and the function hooks.
1416
virtual void Init();
1517
private:
1618
// Create the structure of the menu and save it a static member.
1719
virtual void CreateStructure();
1820

19-
// Stub to hold the original code of Scr_Notify.
20-
static void Scr_NotifyStub(AlphaMW2::Game::gentity_s *entity, uint16_t stringValue, uint32_t paramCount);
21+
// Pointer to the detour object for Scr_Notify.
22+
static Detour *s_pScr_NotifyDetour;
2123

2224
// Initialize the menu when the game starts.
2325
static void Scr_NotifyHook(AlphaMW2::Game::gentity_s *entity, uint16_t stringValue, uint32_t paramCount);
2426

25-
// Stub to hold the original code of SV_ExecuteClientCommand.
26-
static void SV_ExecuteClientCommandStub(int client, const char *s, int clientOK, int fromOldServer);
27+
// Pointer to the detour object for SV_ExecuteClientCommand.
28+
static Detour *s_pSV_ExecuteClientCommandDetour;
2729

2830
// Stop the menu when the game ends.
2931
static void SV_ExecuteClientCommandHook(int client, const char *s, int clientOK, int fromOldServer);

Hayzen/src/Games/MW2/MW2Title.cpp

+15-35
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
#include "Games\MW2\MenuFunctions.h"
55

66

7+
Detour *MW2Title::s_pScr_NotifyDetour = nullptr;
8+
Detour *MW2Title::s_pSV_ExecuteClientCommandDetour = nullptr;
9+
10+
11+
MW2Title::~MW2Title()
12+
{
13+
delete s_pScr_NotifyDetour;
14+
delete s_pSV_ExecuteClientCommandDetour;
15+
}
16+
717
void MW2Title::Init()
818
{
919
Xam::XNotify("Hayzen - MW2 Multiplayer Detected");
@@ -32,9 +42,9 @@ void MW2Title::Init()
3242
CreateStructure();
3343

3444
// Set up the function hooks
35-
Memory::HookFunctionStart(reinterpret_cast<DWORD *>(0x8214BEB8), reinterpret_cast<DWORD *>(SCR_DrawScreenFieldStub), reinterpret_cast<DWORD>(SCR_DrawScreenFieldHook));
36-
Memory::HookFunctionStart(reinterpret_cast<DWORD *>(0x82209710), reinterpret_cast<DWORD *>(Scr_NotifyStub), reinterpret_cast<DWORD>(Scr_NotifyHook));
37-
Memory::HookFunctionStart(reinterpret_cast<DWORD *>(0x82253140), reinterpret_cast<DWORD *>(SV_ExecuteClientCommandStub), reinterpret_cast<DWORD>(SV_ExecuteClientCommandHook));
45+
s_pSCR_DrawScreenFieldDetour = new Detour(0x8214BEB8, SCR_DrawScreenFieldHook);
46+
s_pScr_NotifyDetour = new Detour(0x82209710, Scr_NotifyHook);
47+
s_pSV_ExecuteClientCommandDetour = new Detour(0x82253140, SV_ExecuteClientCommandHook);
3848
}
3949

4050
void MW2Title::CreateStructure()
@@ -71,7 +81,7 @@ void MW2Title::CreateStructure()
7181
void MW2Title::Scr_NotifyHook(MW2::Game::gentity_s *entity, uint16_t stringValue, uint32_t paramCount)
7282
{
7383
// Call the original Scr_Notify function
74-
Scr_NotifyStub(entity, stringValue, paramCount);
84+
s_pScr_NotifyDetour->GetOriginal<decltype(&Scr_NotifyHook)>()(entity, stringValue, paramCount);
7585

7686
// If the client is not host, no need to go further
7787
int iClientNum = entity->state.number;
@@ -97,7 +107,7 @@ void MW2Title::Scr_NotifyHook(MW2::Game::gentity_s *entity, uint16_t stringValue
97107
void MW2Title::SV_ExecuteClientCommandHook(int client, const char *s, int clientOK, int fromOldServer)
98108
{
99109
// Call the original Scr_Notify SV_ExecuteClientCommand
100-
SV_ExecuteClientCommandStub(client, s, clientOK, fromOldServer);
110+
s_pSV_ExecuteClientCommandDetour->GetOriginal<decltype(&SV_ExecuteClientCommandHook)>()(client, s, clientOK, fromOldServer);
101111

102112
// If the client is not host, no need to go further
103113
int iClientNum = (client - Memory::Read<int>(0x83623B98)) / 0x97F80;
@@ -108,33 +118,3 @@ void MW2Title::SV_ExecuteClientCommandHook(int client, const char *s, int client
108118
if (!strcmp(s, "disconnect"))
109119
s_Menu.Stop();
110120
}
111-
112-
void __declspec(naked) MW2Title::Scr_NotifyStub(MW2::Game::gentity_s *entity, uint16_t stringValue, uint32_t paramCount)
113-
{
114-
__asm
115-
{
116-
nop
117-
nop
118-
nop
119-
nop
120-
nop
121-
nop
122-
nop
123-
li r3, 1
124-
}
125-
}
126-
127-
void __declspec(naked) MW2Title::SV_ExecuteClientCommandStub(int client, const char *s, int clientOK, int fromOldServer)
128-
{
129-
__asm
130-
{
131-
nop
132-
nop
133-
nop
134-
nop
135-
nop
136-
nop
137-
nop
138-
li r3, 2
139-
}
140-
}

Hayzen/src/Games/MW2/MW2Title.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,22 @@
1010
class MW2Title : public Title
1111
{
1212
public:
13+
~MW2Title();
14+
1315
// Set the draw function pointers and the function hooks.
1416
virtual void Init();
1517
private:
1618
// Create the structure of the menu and save it a static member.
1719
virtual void CreateStructure();
1820

19-
// Stub to hold the original code of Scr_Notify.
20-
static void Scr_NotifyStub(MW2::Game::gentity_s *entity, uint16_t stringValue, uint32_t paramCount);
21+
// Pointer to the detour object for Scr_Notify.
22+
static Detour *s_pScr_NotifyDetour;
2123

2224
// Initialize the menu when the game starts.
2325
static void Scr_NotifyHook(MW2::Game::gentity_s *entity, uint16_t stringValue, uint32_t paramCount);
2426

25-
// Stub to hold the original code of SV_ExecuteClientCommand.
26-
static void SV_ExecuteClientCommandStub(int client, const char *s, int clientOK, int fromOldServer);
27+
// Pointer to the detour object for SV_ExecuteClientCommand.
28+
static Detour *s_pSV_ExecuteClientCommandDetour;
2729

2830
// Stop the menu when the game ends.
2931
static void SV_ExecuteClientCommandHook(int client, const char *s, int clientOK, int fromOldServer);

Hayzen/src/Games/MW3/MW3Title.cpp

+15-35
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
#include "Games\MW3\MenuFunctions.h"
55

66

7+
Detour *MW3Title::s_pScr_NotifyDetour = nullptr;
8+
Detour *MW3Title::s_pSV_ExecuteClientCommandDetour = nullptr;
9+
10+
11+
MW3Title::~MW3Title()
12+
{
13+
delete s_pScr_NotifyDetour;
14+
delete s_pSV_ExecuteClientCommandDetour;
15+
}
16+
717
void MW3Title::Init()
818
{
919
Xam::XNotify("Hayzen - MW3 Multiplayer Detected");
@@ -32,9 +42,9 @@ void MW3Title::Init()
3242
CreateStructure();
3343

3444
// Set up the function hooks
35-
Memory::HookFunctionStart(reinterpret_cast<DWORD *>(0x8217CF90), reinterpret_cast<DWORD *>(SCR_DrawScreenFieldStub), reinterpret_cast<DWORD>(SCR_DrawScreenFieldHook));
36-
Memory::HookFunctionStart(reinterpret_cast<DWORD *>(0x8226AF98), reinterpret_cast<DWORD *>(Scr_NotifyStub), reinterpret_cast<DWORD>(Scr_NotifyHook));
37-
Memory::HookFunctionStart(reinterpret_cast<DWORD *>(0x822C78A0), reinterpret_cast<DWORD *>(SV_ExecuteClientCommandStub), reinterpret_cast<DWORD>(SV_ExecuteClientCommandHook));
45+
s_pSCR_DrawScreenFieldDetour = new Detour(0x8217CF90, SCR_DrawScreenFieldHook);
46+
s_pScr_NotifyDetour = new Detour(0x8226AF98, Scr_NotifyHook);
47+
s_pSV_ExecuteClientCommandDetour = new Detour(0x822C78A0, SV_ExecuteClientCommandHook);
3848
}
3949

4050
void MW3Title::CreateStructure()
@@ -62,7 +72,7 @@ void MW3Title::CreateStructure()
6272
void MW3Title::Scr_NotifyHook(MW3::Game::gentity_s *entity, uint16_t stringValue, uint32_t paramCount)
6373
{
6474
// Call the original Scr_Notify function
65-
Scr_NotifyStub(entity, stringValue, paramCount);
75+
s_pScr_NotifyDetour->GetOriginal<decltype(&Scr_NotifyHook)>()(entity, stringValue, paramCount);
6676

6777
// If the client is not host, no need to go further
6878
int iClientNum = entity->state.number;
@@ -88,7 +98,7 @@ void MW3Title::Scr_NotifyHook(MW3::Game::gentity_s *entity, uint16_t stringValue
8898
void MW3Title::SV_ExecuteClientCommandHook(int client, const char *s, int clientOK, int fromOldServer)
8999
{
90100
// Call the original Scr_Notify SV_ExecuteClientCommand
91-
SV_ExecuteClientCommandStub(client, s, clientOK, fromOldServer);
101+
s_pSV_ExecuteClientCommandDetour->GetOriginal<decltype(&SV_ExecuteClientCommandHook)>()(client, s, clientOK, fromOldServer);
92102

93103
// If the client is not host, no need to go further
94104
int iClientNum = (client - Memory::Read<int>(0x836C6310)) / 0x68B80;
@@ -99,33 +109,3 @@ void MW3Title::SV_ExecuteClientCommandHook(int client, const char *s, int client
99109
if (!strcmp(s, "matchdatadone"))
100110
s_Menu.Stop();
101111
}
102-
103-
void __declspec(naked) MW3Title::Scr_NotifyStub(MW3::Game::gentity_s *entity, uint16_t stringValue, uint32_t paramCount)
104-
{
105-
__asm
106-
{
107-
nop
108-
nop
109-
nop
110-
nop
111-
nop
112-
nop
113-
nop
114-
li r3, 1
115-
}
116-
}
117-
118-
void __declspec(naked) MW3Title::SV_ExecuteClientCommandStub(int client, const char *s, int clientOK, int fromOldServer)
119-
{
120-
__asm
121-
{
122-
nop
123-
nop
124-
nop
125-
nop
126-
nop
127-
nop
128-
nop
129-
li r3, 2
130-
}
131-
}

Hayzen/src/Games/MW3/MW3Title.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,22 @@
1010
class MW3Title : public Title
1111
{
1212
public:
13+
~MW3Title();
14+
1315
// Set the draw function pointers and the function hooks.
1416
virtual void Init();
1517
private:
1618
// Create the structure of the menu and save it a static member.
1719
virtual void CreateStructure();
1820

19-
// Stub to hold the original code of Scr_Notify.
20-
static void Scr_NotifyStub(MW3::Game::gentity_s *entity, uint16_t stringValue, uint32_t paramCount);
21+
// Pointer to the detour object for Scr_Notify.
22+
static Detour *s_pScr_NotifyDetour;
2123

2224
// Initialize the menu when the game starts.
2325
static void Scr_NotifyHook(MW3::Game::gentity_s *entity, uint16_t stringValue, uint32_t paramCount);
2426

25-
// Stub to hold the original code of SV_ExecuteClientCommand.
26-
static void SV_ExecuteClientCommandStub(int client, const char *s, int clientOK, int fromOldServer);
27+
// Pointer to the detour object for SV_ExecuteClientCommand.
28+
static Detour *s_pSV_ExecuteClientCommandDetour;
2729

2830
// Stop the menu when the game ends.
2931
static void SV_ExecuteClientCommandHook(int client, const char *s, int clientOK, int fromOldServer);

0 commit comments

Comments
 (0)