1
+ #include " stdafx.h"
2
+ #include " UHC.h"
3
+
4
+ extern " C" void __stdcall RegisterSyscallGroup (UHCInfo* info, UHCSyscallGroupName name, LPVOID _this) {
5
+ auto SyscallRegister = reinterpret_cast <BOOL (__thiscall *)(LPVOID _this, LPCSTR name, LPVOID fPtr , DWORD retType)>(0x624f52 );
6
+ auto SyscallPrintf = reinterpret_cast <int (*)(LPVOID _this, LPCSTR format, ...)>(0xa44b95 );
7
+ auto SyscallFree = reinterpret_cast <int (__thiscall *)(LPVOID _this)>(0xa44c0b );
8
+ auto SyscallGetName = reinterpret_cast <LPCSTR (__thiscall *)(LPVOID _this)> (0xa44bee );
9
+ auto SyscallSetParamInteger = reinterpret_cast <BOOL (__thiscall *)(LPVOID _this, int defaultVal)>(0x62505b );
10
+ auto SyscallSetParamFloat = reinterpret_cast <BOOL (__thiscall *)(LPVOID _this, float defaultVal)>(0x625079 );
11
+ auto SyscallSetParamBool = reinterpret_cast <BOOL (__thiscall *)(LPVOID _this, BOOL defaultVal)>(0x62506a );
12
+ auto SyscallSetParamString = reinterpret_cast <BOOL (__thiscall *)(LPVOID _this, LPCSTR defaultVal)>(0x624e3f );
13
+ auto SyscallSetParamVector = reinterpret_cast <BOOL (__thiscall *)(LPVOID _this, const float * defaultVal)>(0x62734a );
14
+ auto SyscallComment = reinterpret_cast <BOOL (__thiscall *)(LPVOID _this, LPCSTR comment)>(0x624e56 );
15
+ auto SyscallRegisterEnd = reinterpret_cast <BOOL (__thiscall *)(LPVOID _this)>(0x6250b0 );
16
+
17
+ TArray<UHCSyscall>& group = info->SyscallGroups [name];
18
+ for (size_t i = 0 ; i < group.GetNumElements (); i++) {
19
+ UHCSyscall& syscall = group[i];
20
+ if (!SyscallRegister (_this, syscall .Name , syscall .Ptr , syscall .RetType )) {
21
+ SyscallPrintf (_this, (LPCSTR)0xbf1e98 , syscall .Name );
22
+ SyscallFree (_this);
23
+ return ;
24
+ }
25
+
26
+ // to-do: rule related functions
27
+
28
+ for (DWORD i = 0 ; i < syscall .ParamCount ; i++) {
29
+ switch (syscall .Params [i].Type )
30
+ {
31
+ case SyscallInteger:
32
+ if (!SyscallSetParamInteger (_this, *(const int *)syscall .Params [i].Default )) {
33
+ SyscallPrintf (_this, (LPCSTR)0xbf1e50 , syscall .Params [i].Default , SyscallGetName (_this));
34
+ SyscallFree (_this);
35
+ return ;
36
+ }
37
+ break ;
38
+ case SyscallFloat:
39
+ if (!SyscallSetParamFloat (_this, *(const float *)syscall .Params [i].Default )) {
40
+ SyscallPrintf (_this, (LPCSTR)0xbf1e08 , syscall .Params [i].Default , SyscallGetName (_this));
41
+ SyscallFree (_this);
42
+ return ;
43
+ }
44
+ break ;
45
+ case SyscallBool:
46
+ if (!SyscallSetParamBool (_this, *(const BOOL*)syscall .Params [i].Default )) {
47
+ SyscallPrintf (_this, (LPCSTR)0xbf1dc0 , syscall .Params [i].Default , SyscallGetName (_this));
48
+ SyscallFree (_this);
49
+ return ;
50
+ }
51
+ break ;
52
+ case SyscallString:
53
+ if (!SyscallSetParamString (_this, (LPCSTR)syscall .Params [i].Default )) {
54
+ SyscallPrintf (_this, (LPCSTR)0xbf1d78 , syscall .Params [i].Default , SyscallGetName (_this));
55
+ SyscallFree (_this);
56
+ return ;
57
+ }
58
+ break ;
59
+ case SyscallVector:
60
+ const float * vec = (const float *)syscall .Params [i].Default ;
61
+ if (!SyscallSetParamVector (_this, vec)) {
62
+ SyscallPrintf (_this, (LPCSTR)0xbffa48 , vec[0 ], vec[1 ], vec[2 ], SyscallGetName (_this));
63
+ SyscallFree (_this);
64
+ return ;
65
+ }
66
+ }
67
+ }
68
+
69
+ if (!SyscallComment (_this, syscall .Comment )) {
70
+ SyscallFree (_this);
71
+ return ;
72
+ }
73
+
74
+ SyscallRegisterEnd (_this);
75
+
76
+ #ifdef _DEBUG
77
+ char debugString[256 ];
78
+ wsprintfA (debugString, " Loaded syscall '%s' with 'UHC.dll'." , syscall .Name );
79
+ OutputDebugStringA (debugString);
80
+ #endif
81
+
82
+ }
83
+ }
84
+
85
+ extern " C" void __stdcall LoadPersonalities (UHCInfo* info) {
86
+ WCHAR szFindPath[MAX_PATH];
87
+ LPCWSTR lpAI = (LPCWSTR)0x0be3a98 ;
88
+ LPCWSTR lpPersonalityExt = (LPCWSTR)0x0c0b39c ;
89
+ WIN32_FIND_DATAW fd;
90
+ HANDLE hFind;
91
+
92
+ lstrcpyW (szFindPath, lpAI);
93
+ lstrcatW (szFindPath, L" *" );
94
+ lstrcatW (szFindPath, lpPersonalityExt);
95
+
96
+ hFind = FindFirstFileW (szFindPath, &fd);
97
+
98
+ if (hFind != INVALID_HANDLE_VALUE) {
99
+ do
100
+ {
101
+ size_t length = wcschr (fd.cFileName , L' .' ) - fd.cFileName + 1 ;
102
+
103
+ info->Personalities .PushBack (new WCHAR[length]);
104
+ lstrcpynW (info->Personalities .Back (), fd.cFileName , length);
105
+
106
+ } while (FindNextFileW (hFind, &fd));
107
+
108
+ FindClose (hFind);
109
+ }
110
+ }
111
+
112
+ extern " C" BOOL __stdcall CheckRevBanner (LPCSTR lpRevTech, LPVOID lpThis, LPVOID lpPathObject) {
113
+ if (strncmp (lpRevTech, " XPRevolution" , 12 ) != 0 )
114
+ return FALSE ;
115
+
116
+ const WCHAR szBannerPrefix[] = L" ui\\ ingame\\ politicians\\ REV_banner_" ;
117
+ WCHAR szPath[MAX_PATH];
118
+ LPCSTR lpLeaderName = lpRevTech + 12 ;
119
+
120
+ lstrcpyW (szPath, szBannerPrefix);
121
+ mbstowcs (szPath + ((sizeof (szBannerPrefix) - 1 )/sizeof (WCHAR)), lpLeaderName, lstrlenA (lpLeaderName) + 1 );
122
+
123
+ reinterpret_cast <void (__thiscall *)(LPVOID, LPCWSTR)>(0x401a12 )(lpPathObject, szPath);
124
+ reinterpret_cast <void (__thiscall *)(LPVOID, LPVOID)>(0x638823 )(lpThis, lpPathObject);
125
+
126
+ return TRUE ;
127
+ }
0 commit comments