Skip to content

Commit aec2bb7

Browse files
Merge pull request #1 from danielpereira/v15_dev
Merging temporary v1.5 dev branch
2 parents 99c3ec5 + 14bc957 commit aec2bb7

File tree

144 files changed

+158942
-2250
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+158942
-2250
lines changed

DLL/AILimit.asm

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
LoadPersonalities proto stdcall info:UHCInfoPtr
2+
3+
code_cave_begin 00603B0Bh
4+
invoke LoadPersonalities, _UHCInfoPtr
5+
mov edi, _UHCInfoPtr
6+
mov esi, [edi].UHCInfo.PersonalityCount
7+
mov dword ptr ss:[esp + 040h], esi
8+
mov esi, [edi].UHCInfo.Personalities
9+
mov dword ptr ss:[esp + 050h], esi
10+
code_cave_end 00603C4Fh
11+
12+
public stdcall PatchAILimit
13+
PatchAILimit proc
14+
patch_code_cave 00603B0Bh, 00603C4Fh
15+
ret
16+
PatchAILimit endp

DLL/Asians.asm

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
; Asian Civs Patch #1
2+
code_cave_begin 00454F1Dh
3+
cmp eax, dword ptr ds:[00C6FB88h]
4+
je_rel32 00454F2A
5+
invoke checkID,3,eax
6+
test eax,eax
7+
je apatch1_invalid_id
8+
mov al,1
9+
retn 4
10+
11+
apatch1_invalid_id:
12+
xor al,al
13+
retn 4
14+
code_cave_end 00454F22h
15+
16+
; Asian Civs Patch #2
17+
code_cave_begin 008D6AC4h
18+
cmp eax, dword ptr ds:[00C6FB88h]
19+
je_rel32 008D6ACC
20+
invoke checkID,3,eax
21+
test eax,eax
22+
je_rel32 008D6B0C
23+
jmp_rel32 008D6AF7
24+
code_cave_end 008D6AC9h
25+
26+
; Asian Civs Patch #3
27+
code_cave_begin 00818284h
28+
call_rel32 0049A2D8
29+
test eax,eax
30+
jne_rel32 0081828D
31+
mov ecx,ebp
32+
invoke checkWonders,esi,edi
33+
test eax,eax
34+
je_rel32 008182EB
35+
jmp_rel32 008182A9
36+
code_cave_end 00818288h
37+
38+
public stdcall PatchAsianCivs
39+
PatchAsianCivs proc
40+
patch_code_cave 00454F1Dh, 00454F22h
41+
invoke PatchAddress,esi,loc_00454F2A, 00454F2Ah, 1
42+
43+
patch_code_cave 008D6AC4h, 008D6AC9h
44+
invoke PatchAddress, _hProcess, loc_008D6ACC, 008D6ACCh, 1
45+
invoke PatchAddress, _hProcess, loc_008D6B0C, 008D6B0Ch, 1
46+
invoke PatchAddress, _hProcess, loc_008D6AF7, 008D6AF7h, 1
47+
48+
patch_code_cave 00818284h, 00818288h
49+
invoke PatchAddress, _hProcess, sub_0049A2D8, 0049A2D8h, 1
50+
invoke PatchAddress, _hProcess, loc_0081828D, 0081828Dh, 1
51+
invoke PatchAddress, _hProcess, loc_008182EB, 008182EBh, 1
52+
invoke PatchAddress, _hProcess, loc_008182A9, 008182A9h, 1
53+
ret
54+
PatchAsianCivs endp

DLL/AsmPatch.cpp

+127
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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+
}

DLL/BigButton.asm

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
code_cave_begin 00461BD8h
2+
jne bb_exclude_buildings
3+
mov eax,edi
4+
cmp dword ptr ds:[eax+24h],0
5+
jg bb_not_null
6+
or eax,-1
7+
jmp bb_check
8+
9+
bb_not_null:
10+
mov eax,[eax+20h]
11+
mov eax,[eax]
12+
13+
bb_check:
14+
invoke checkID,5,eax
15+
test eax,eax
16+
je bb_back
17+
18+
bb_exclude_buildings:
19+
mov eax,[esi+5Ch]
20+
test eax,eax
21+
je_rel32 00695955_1
22+
mov eax,[eax+08h]
23+
invoke checkID,6,eax
24+
test eax,eax
25+
je_rel32 00695955_2
26+
27+
bb_back:
28+
jmp_rel32 00461BDE
29+
code_cave_end 00461BDDh
30+
31+
public stdcall PatchWoLBigButton
32+
33+
PatchWoLBigButton proc
34+
35+
patch_code_cave 00461BD8h, 00461BDDh
36+
invoke PatchAddress,_hProcess,loc_00695955_1,00695955h,1
37+
invoke PatchAddress,_hProcess,loc_00461BDE,00461BDEh,1
38+
invoke PatchAddress,_hProcess,loc_00695955_2,00695955h,1
39+
ret
40+
PatchWoLBigButton endp

DLL/Cheat.asm

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
code_cave_begin 0551FE6h
2+
mov edi, _UHCInfoPtr
3+
mov ebx, [edi].UHCInfo.CheatCount
4+
test ebx, ebx
5+
je cheat_end
6+
mov edi, [edi].UHCInfo.Cheats
7+
dec ebx
8+
9+
cheat_loop:
10+
mov eax, [edi].UHCCheat.String
11+
push eax
12+
lea ecx, [esp+18h]
13+
mov eax, ebx
14+
add eax, 24
15+
mov dword ptr [esp+10h], eax
16+
mov eax, [edi].UHCCheat.Enable
17+
mov [esp+14h], eax
18+
mov eax, 00401A12h
19+
call eax
20+
mov esi, dword ptr ds:[00D65604h]
21+
push 0
22+
lea edx, [esi+1]
23+
push edx
24+
mov ecx, 00D65600h
25+
mov eax, [edi].UHCCheat.FunctionPtr
26+
mov dword ptr [esp+20h], eax
27+
mov eax, 005ACE63h
28+
call eax
29+
test al, al
30+
je cheat_next
31+
mov eax, [esp+0Ch]
32+
shl esi, 4
33+
add esi, dword ptr ds:[00D65600h]
34+
lea edx, [esp+14h]
35+
mov [esi], eax
36+
mov ecx, [esp+10h]
37+
mov [esi+04h], ecx
38+
push edx
39+
lea ecx, [esi+08]
40+
mov eax, 0040196Fh
41+
call eax
42+
mov ecx, [esp+18h]
43+
mov [esi+0Ch], ecx
44+
45+
cheat_next:
46+
lea ecx, [esp+14h]
47+
mov eax, 004010CAh
48+
call eax
49+
50+
add edi, UHCCheat
51+
dec ebx
52+
jns cheat_loop
53+
54+
cheat_end:
55+
code_cave_end 0551FE6h
56+
57+
public stdcall PatchCheat
58+
PatchCheat proc
59+
patch_code_cave 0551FE6h, 0551FE6h
60+
ret
61+
PatchCheat endp

DLL/CheatFunctions.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include "CheatFunctions.h"
2+
3+
char(__thiscall const* CheatAddResource)(void* playerData, __int32 resourceID, float resourceAmount, __int8 unk) = reinterpret_cast<char(__thiscall*)(void*, __int32, float, __int8)>(0x0049A98A);
4+
void(__cdecl const* CheatSpawnUnit)(void* playerData, char* protoUnitName) = reinterpret_cast<void(__cdecl*)(void*, char*)>(0x007B4F03);
5+

DLL/CheatFunctions.h

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#pragma once
2+
3+
typedef enum RESOURCE_ID {
4+
GOLD,
5+
WOOD,
6+
FOOD,
7+
FAME,
8+
ID_4,
9+
XP,
10+
SHIPMENTS,
11+
EXPORT
12+
} RESOURCE_ID;
13+
14+
extern char(__thiscall const* CheatAddResource)(void* playerData, __int32 resourceID, float resourceAmount, __int8 unk);
15+
extern void(__cdecl const* CheatSpawnUnit)(void* playerData, char* protoUnitName);

DLL/CivChecking.asm

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
code_cave_begin 008D0318h
2+
mov ecx, dword ptr ds:[00C66234h]
3+
mov ecx,[ecx+140h]
4+
invoke getCivIDs,3
5+
mov ecx, dword ptr ds:[00C66234h]
6+
mov ecx,[ecx+140h]
7+
invoke getCivIDs,4
8+
mov eax, dword ptr ds:[00C66234h]
9+
jmp_rel32 008D031D
10+
code_cave_end 008D031Ch
11+
12+
code_cave_begin 008DABA3h
13+
mov ecx, dword ptr ds:[00C66234h]
14+
mov ecx,[ecx+140h]
15+
invoke getCivIDs,3
16+
mov ecx, dword ptr ds:[00C66234h]
17+
mov ecx,[ecx+140h]
18+
invoke getCivIDs,4
19+
mov ecx, dword ptr ds:[00C66234h]
20+
mov ecx,[ecx+140h]
21+
invoke getCivIDs,5
22+
mov edx, dword ptr ds:[00C66234h]
23+
jmp_rel32 008DABA9
24+
code_cave_end 008DABA8h
25+
26+
public stdcall PatchCivChecking
27+
PatchCivChecking proc
28+
29+
patch_code_cave 008D0318h, 008DABA8h
30+
invoke PatchAddress, _hProcess, loc_008D031D, 008D031Dh, 1
31+
32+
patch_code_cave 008DABA3h, 008DABA8h
33+
invoke PatchAddress, _hProcess, loc_008DABA9, 008DABA9h, 1
34+
ret
35+
PatchCivChecking endp
36+

0 commit comments

Comments
 (0)