This repository was archived by the owner on Apr 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathH2Rank.cpp
More file actions
209 lines (158 loc) · 4.62 KB
/
H2Rank.cpp
File metadata and controls
209 lines (158 loc) · 4.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#include "stdafx.h"
#include "H2Rank.h"
#include "hook.h"
#include "Structs.h"
#include <windows.h>
#include <stdio.h>
#pragma region Notused
H2RANK_API int nH2Rank=0;
H2RANK_API int fnH2Rank(void)
{
return 42;
}
CH2Rank::CH2Rank()
{
return;
}
#pragma endregion
#pragma region hook defines
typedef int(__stdcall *tjoinHook )(void *thisptr, int a2, const void* a3 );
tjoinHook pjoinHook;
typedef int(__stdcall *tRankHook )(void *thisptr, int a2, int a3 );
tRankHook pRankHook;
typedef int( __stdcall *tRankHookC )(void *thisptr, int a2, int a3 );
tRankHookC pRankHookC;
typedef int(__stdcall *tGameStatusUpdate )(void *thisptr, int a2, int a3, int a4 );
tGameStatusUpdate pGameStatusUpdate;
//typedef int(__stdcall *tPlayerQuit )( void* thisptr, int a2, char a3, int a4 );
//tPlayerQuit pPlayerQuit;
typedef int(__stdcall *tPlayerQuit )(void *thisptr, int a2, int a3 );
tPlayerQuit pPlayerQuit;
typedef int(__stdcall *tPlayerJoinAlt )(void *thisptr, int a2, int a3, int a4 );
tPlayerJoinAlt pPlayerJoinAlt;
#pragma endregion
#pragma region hooked functions
#pragma region oldquit
/*
int __stdcall PlayerQuit( void *thisptr, int PlayerSlot, char a3, int a4 )
{
//printf("thisptr: %08X - a3: %08X - a4: %08X\r\n",thisptr,a3,a4);
if( a3 == 1)
{
RankSystem.PlayerQuit( PlayerSlot );
}
return pPlayerQuit( thisptr, PlayerSlot, a3, a4 );
}*/
#pragma endregion
int __stdcall PlayerQuit( void *thisptr, int PlayerSlot, int a3 )
{
printf("playerquit: %08X\r\n",a3);
if( a3 == 9 || a3 == 2 || a3 == 1 )
{
RankSystem.PlayerQuit( PlayerSlot );
}
return pPlayerQuit( thisptr, PlayerSlot, a3 );
}
int __stdcall GameUpdateStatus (void *thisptr, int a2, int a3, int a4 )
{
Server.GameStatus = a2;
if( Server.GameStatus == 4 )
{
//Server.PGC_PlayerCount = *(DWORD*)(Base+0x49F6A0);
RankSystem.CalculateXP();
for( unsigned int i = 0; i < CurrentPlayers.size(); ++i )
{
RankSystem.CalculateRank( i );
}
RankSystem.CleanUp(); //Prevent memory leaks by removing players who've quit.
}
return pGameStatusUpdate( thisptr ,a2 ,a3 ,a4 );
}
int __stdcall RankHookC( void* thisptr, int a2, int a3 )
{
int rank;
int rankadd = 0;
DWORD nRankAddress = RankAddress+(0x128*a2);
rankadd = *(DWORD*)nRankAddress;
__asm
{
mov edx,a3
add edx,0x10
add edx,0x7E
mov eax,[edx]
mov rank,eax
mov eax,rankadd
mov [edx],eax
add edx,0x01
mov [edx],0x01
}
return pRankHookC( thisptr, a2, a3 );
}
int __stdcall RankHook( void* thisptr, int a2, int a3 )
{
int rank;
int rankadd = 0;
DWORD nRankAddress = RankAddress+(0x128*a2);
rankadd = *(DWORD*)nRankAddress;
__asm
{
mov edx, a3
add edx,0x1C
add edx,0x7E
mov eax,[edx]
mov rank,eax
mov eax,rankadd
mov [edx],eax
add edx,0x01
mov [edx],0x01
}
return pRankHook( thisptr, a2, a3 );
}
int __stdcall joinhook( void *thisptr, int a2, const void* a3 )
{
int rank;
int rankadd = 0;
DWORD nRankAddress = RankAddress+(0x128*a2);
rankadd = *(DWORD*)nRankAddress;
RankPlayer* nRankPlayer = new RankPlayer(a2);
__asm
{
mov edx,a3
add edx,0x7E
mov eax,[edx]
mov rank,eax
mov eax,rankadd
mov [edx],eax
add edx,0x01
mov [edx],0x01
}
return pjoinHook( thisptr, a2, a3 );
}
#pragma endregion
void Intialize()
{
SetConsoleTitle("Halo 2 Vista Dedicated Server - H2Rank Injected!");
printf("\r\nH2Rank has been loaded into this server!\r\n");
XPvsRankChart_Init();
#pragma region hook calls
DWORD dwBack;
DWORD PlayerQuitAddr = Base+0x1B79C6;
pPlayerQuit = ( tPlayerQuit ) DetourClassFunc( (BYTE*)PlayerQuitAddr, (BYTE*)PlayerQuit, 14 );
VirtualProtect( pPlayerQuit, 4, PAGE_EXECUTE_READWRITE, &dwBack );
//DWORD PlayerQuitAddr = Base+0x1B7FB4;
//pPlayerQuit = ( tPlayerQuit ) DetourClassFunc( (BYTE*)PlayerQuitAddr, (BYTE*)PlayerQuit, 12 );
//VirtualProtect( pPlayerQuit, 4, PAGE_EXECUTE_READWRITE, &dwBack );
DWORD RankHookCAddr = Base+0x19E5FF;
pRankHookC = ( tRankHookC ) DetourClassFunc( (BYTE*)RankHookCAddr, (BYTE*)RankHookC, 13);
VirtualProtect( pRankHookC, 4, PAGE_EXECUTE_READWRITE, &dwBack );
DWORD RankHookAddr = Base+0x1A42AC;
pRankHook = ( tRankHook ) DetourClassFunc( (BYTE*)RankHookAddr, (BYTE*)RankHook, 20 );
VirtualProtect( pRankHook, 4, PAGE_EXECUTE_READWRITE, &dwBack );
DWORD CallAddr = Base+0x19D2B6;
pjoinHook = ( tjoinHook ) DetourClassFunc( (BYTE*)CallAddr, (BYTE*) joinhook, 23 );
VirtualProtect( pjoinHook, 4, PAGE_EXECUTE_READWRITE, &dwBack );
DWORD GameStatusUpdateAddr = Base+0x01BCC47;
pGameStatusUpdate = ( tGameStatusUpdate ) DetourClassFunc( (BYTE*)GameStatusUpdateAddr, (BYTE*) GameUpdateStatus, 11 );
VirtualProtect( pGameStatusUpdate, 4, PAGE_EXECUTE_READWRITE, &dwBack );
#pragma endregion
}