Skip to content

Commit 4c3ad2c

Browse files
committed
Updating DLL, Patcher and Documentation to v1.7
1 parent 188ea1e commit 4c3ad2c

23 files changed

+160
-20767
lines changed
125 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
#ifndef _UHC_H
2-
#define _UHC_H
1+
#ifndef _UHCPLUGIN_H
2+
#define _UHCPLUGIN_H
33

44
#include "syscalls.h"
55

66
enum UHCSyscallType {
7-
Void = 1,
8-
Integer = 2,
9-
Float = 4,
10-
Bool = 8,
11-
String = 16,
12-
Vector = 32
7+
SyscallVoid = 1,
8+
SyscallInteger = 2,
9+
SyscallFloat = 4,
10+
SyscallBool = 8,
11+
SyscallString = 16,
12+
SyscallVector = 32
1313
};
1414

1515
enum UHCSyscallGroupName {
@@ -23,18 +23,35 @@ enum UHCSyscallGroupName {
2323
GroupXS
2424
};
2525

26-
struct UHCInfo;
2726
struct UHCSyscall;
2827

28+
typedef enum RESOURCE_ID {
29+
GOLD,
30+
WOOD,
31+
FOOD,
32+
FAME,
33+
ID_4,
34+
XP,
35+
SHIPMENTS,
36+
EXPORT
37+
} RESOURCE_ID;
38+
39+
#if defined(__MINGW32__) || defined(_MSC_VER)
40+
#define CHEATCALL __stdcall
41+
#elif defined(__GNUC__) || defined(__GNUG__)
42+
#define CHEATCALL __attribute__((stdcall))
43+
#endif
44+
2945
struct UHCPluginInfo {
30-
UHCInfo* info;
46+
void(*RegisterCheat)(const char* string, bool enable, void(CHEATCALL * fPtr)(void*));
47+
48+
UHCSyscall&(*RegisterSyscall)(UHCSyscallGroupName groupName, unsigned int retType, const char* name, const void* fPtr, unsigned int paramCount, const char* comment);
3149

32-
void(__stdcall *RegisterCheat)(UHCInfo* info, const wchar_t* string, bool enable, void(__stdcall * fPtr)(void*));
50+
void(*SyscallSetParam)(UHCSyscall& syscall, unsigned int paramId, unsigned int type, const void* defaultVal);
3351

34-
UHCSyscall& (__stdcall *RegisterSyscall)(UHCInfo* info, UHCSyscallGroupName groupName,
35-
__int32 retType, const char* name, void* fPtr, __int32 paramCount, const char* comment);
52+
bool(*CheatAddResource)(void* playerData, int resourceID, float resourceAmount, bool unk);
3653

37-
void(__stdcall *SyscallSetParam)(UHCSyscall& syscall, __int32 paramId, __int32 type, const void* defaultVal);
54+
void(*CheatSpawnUnit)(void* playerData, const char* protoUnitName);
3855
};
3956

4057
#endif

Release/Documentation/Examples/UHCPluginDemo/UHCPluginDemo.cpp

+64-30
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,37 @@
22
//
33

44
#include "stdafx.h"
5-
#include <stdio.h>
6-
#include <stdlib.h>
5+
6+
#include <cmath>
77

88
using namespace syscalls;
99

10-
// syscalls that returns a 'vector' uses the first parameter to return its value
11-
void vectorSyscallExample(vector ret) {
12-
kbGetMapCenter(ret);
13-
}
10+
UHCPluginInfo* g_PluginInfo = nullptr;
1411

15-
void test(int player) {
16-
aiChat(player, "Hello World!");
17-
}
12+
// Turns all enemy villagers into sheep
13+
void CHEATCALL ForceOfNature(void* playerData) {
14+
int villagerType = -1;
1815

19-
void msgBox(string caption, string message) {
20-
MessageBoxA(NULL, message, caption, MB_ICONASTERISK);
21-
}
16+
array<wchar_t*>* unitTypes = GetUnitTypes();
17+
18+
for (int i = 0; i < unitTypes->Count; i++) {
19+
if (wcscmp(unitTypes->Array[i], L"AbstractVillager") == 0) {
20+
villagerType = i;
21+
break;
22+
}
23+
}
2224

23-
// Turns a random enemy's settlers into sheep
24-
void __stdcall cheatExample(void* playerData) {
25-
xsSetContextPlayer(1);
2625
for (int i = 1; i < GetNumberPlayers(); i++) {
26+
xsSetContextPlayer(1);
27+
2728
if (kbIsPlayerEnemy(i) && !kbIsPlayerResigned(i)) {
2829
xsSetContextPlayer(i);
2930
trUnitSelectClear();
3031

3132
int unitQueryID = kbUnitQueryCreate("CheatUnitQuery");
3233
kbUnitQuerySetIgnoreKnockedOutUnits(unitQueryID, true);
3334
kbUnitQuerySetPlayerID(unitQueryID, i, true);
34-
kbUnitQuerySetUnitType(unitQueryID, kbGetProtoUnitID("Settler"));
35+
kbUnitQuerySetUnitType(unitQueryID, villagerType);
3536
kbUnitQuerySetState(unitQueryID, cUnitStateAlive);
3637
kbUnitQueryResetResults(unitQueryID);
3738
int numberFound = kbUnitQueryExecute(unitQueryID);
@@ -40,32 +41,65 @@ void __stdcall cheatExample(void* playerData) {
4041
trUnitSelectByID(kbUnitQueryGetResult(unitQueryID, n));
4142

4243
trUnitChangeProtoUnit("Sheep");
43-
//trSoundPlayFN("SheepSelect.wav", "", -1, "", "");
44-
break;
44+
45+
kbUnitQueryDestroy(unitQueryID);
4546
}
4647
}
4748
}
4849

49-
int aiDefaultParamValue = 1;
50+
// Add 10000 shipments
51+
void CHEATCALL ThisIsAComplication(void * playerData) {
52+
// last parameter is always false
53+
g_PluginInfo->CheatAddResource(playerData, SHIPMENTS, 10000.00, false);
54+
}
55+
56+
// Spawn 50 cannons
57+
void CHEATCALL KillemAll(void * playerData) {
58+
for (int i = 0; i < 50; i++)
59+
g_PluginInfo->CheatSpawnUnit(playerData, "Cannon");
60+
}
61+
62+
// Gets a random location on the circle
63+
// vector return syscall use first parameter to hold vector data
64+
vector rmGetLocationByDistance(vector result, vector center, float distance) {
65+
float radians = rmRandFloat(0, 2 * 3.1415926);
66+
67+
result->x = center->x + distance * cosf(radians);
68+
result->y = center->y;
69+
result->z = center->z + distance * sinf(radians);
70+
71+
// always return the first parameter (result vector)
72+
return result;
73+
}
74+
75+
float g_DefaultParamFloat = 0.0;
76+
int g_InvalidUnitID = -1;
5077

5178
extern "C" _declspec(dllexport)
52-
int __stdcall UHCPluginMain(UHCPluginInfo* pluginInfo) {
79+
int UHCPluginMain(UHCPluginInfo* pluginInfo) {
80+
g_PluginInfo = pluginInfo;
81+
5382
// Register your syscalls and cheats here...
5483

55-
// After registering a syscall, it can be used in the 'scope' you defined.
56-
pluginInfo->RegisterSyscall(pluginInfo->info, GroupXS, Vector,
57-
"xsTest", test, 0, "xsTest: vector syscall example.");
84+
// First parameter used to hold the return vector doesn't count as syscall parameter
85+
UHCSyscall& sRmGetLocationByDistance = pluginInfo->RegisterSyscall(GroupRM, SyscallVector, "rmGetLocationByDistance", rmGetLocationByDistance, 2, "rmGetLocationByDistance: no help.");
86+
87+
pluginInfo->SyscallSetParam(sRmGetLocationByDistance, 0, SyscallVector, cInvalidVector);
88+
89+
// Default param value must be stored globally, not on the function stack
90+
pluginInfo->SyscallSetParam(sRmGetLocationByDistance, 1, SyscallFloat, &g_DefaultParamFloat);
91+
92+
// Some syscalls might work if re-registered in a different scope
93+
UHCSyscall& sKbUnitGetTactic = pluginInfo->RegisterSyscall(GroupKB, SyscallInteger, "kbUnitGetTactic", aiUnitGetTactic, 1, "kbUnitGetTactic: no help.");
5894

59-
UHCSyscall& aiTest = pluginInfo->RegisterSyscall(pluginInfo->info, GroupAI, Void,
60-
"aiTest", (void*)test, 1, "aiTest: Sends 'Hello World!' to specified player.");
95+
pluginInfo->SyscallSetParam(sKbUnitGetTactic, 0, SyscallInteger, &g_InvalidUnitID);
6196

62-
pluginInfo->SyscallSetParam(aiTest, 0, Integer, &aiDefaultParamValue);
97+
// Second parameter is always true
98+
pluginInfo->RegisterCheat("force of nature", TRUE, ForceOfNature);
6399

64-
UHCSyscall& aiMsgBox = pluginInfo->RegisterSyscall(pluginInfo->info, GroupAI, Void, "aiMsgBox", (void*)msgBox, 2, "aiMsgBox: Displays a message box");
65-
pluginInfo->SyscallSetParam(aiMsgBox, 0, String, "Caption");
66-
pluginInfo->SyscallSetParam(aiMsgBox, 1, String, "Message");
100+
pluginInfo->RegisterCheat("this is a complication", TRUE, ThisIsAComplication);
67101

68-
pluginInfo->RegisterCheat(pluginInfo->info, L"force of nature", true, cheatExample);
102+
pluginInfo->RegisterCheat("kill 'em all", TRUE, KillemAll);
69103

70104
return 0;
71105
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.25420.1
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UHCPluginDemo", "UHCPluginDemo.vcxproj", "{B1C8E270-8914-4E5C-AC6F-B138285BFF11}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{B1C8E270-8914-4E5C-AC6F-B138285BFF11}.Debug|x64.ActiveCfg = Debug|x64
17+
{B1C8E270-8914-4E5C-AC6F-B138285BFF11}.Debug|x64.Build.0 = Debug|x64
18+
{B1C8E270-8914-4E5C-AC6F-B138285BFF11}.Debug|x86.ActiveCfg = Debug|Win32
19+
{B1C8E270-8914-4E5C-AC6F-B138285BFF11}.Debug|x86.Build.0 = Debug|Win32
20+
{B1C8E270-8914-4E5C-AC6F-B138285BFF11}.Release|x64.ActiveCfg = Release|x64
21+
{B1C8E270-8914-4E5C-AC6F-B138285BFF11}.Release|x64.Build.0 = Release|x64
22+
{B1C8E270-8914-4E5C-AC6F-B138285BFF11}.Release|x86.ActiveCfg = Release|Win32
23+
{B1C8E270-8914-4E5C-AC6F-B138285BFF11}.Release|x86.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
EndGlobal

Release/Documentation/Examples/UHCPluginDemo/UHCPluginDemo.vcxproj

+3-1
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,15 @@
7171
<PropertyGroup Label="UserMacros" />
7272
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
7373
<LinkIncremental>true</LinkIncremental>
74+
<OutDir>D:\Program Files (x86)\SteamLibrary\steamapps\common\Age Of Empires 3\bin</OutDir>
75+
<TargetExt>.upl</TargetExt>
7476
</PropertyGroup>
7577
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
7678
<LinkIncremental>true</LinkIncremental>
7779
</PropertyGroup>
7880
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
7981
<LinkIncremental>false</LinkIncremental>
80-
<OutDir>C:\Program Files (x86)\Microsoft Games\Age of Empires III</OutDir>
82+
<OutDir>D:\Program Files (x86)\SteamLibrary\steamapps\common\Age Of Empires 3\bin</OutDir>
8183
<TargetExt>.upl</TargetExt>
8284
<IgnoreImportLibrary>true</IgnoreImportLibrary>
8385
</PropertyGroup>

Release/Documentation/Examples/UHCPluginDemo/syscalls.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -11065,21 +11065,21 @@ namespace syscalls
1106511065
return (array<wchar_t*>*)(_this + 0x1ff0);
1106611066
}
1106711067

11068-
inline int getMyID() {
11068+
inline int GetMyID() {
1106911069
int _this = *(int*)(*(int*)0xc66234 + 0x13c);
1107011070
_this = *(int*)(*(int*)(_this + 0x58) + 4 * *(int*)0xc66664);
1107111071
int* _thisPlayer = (int*)(*(int*)(_this + 0x80) + 0xc);
1107211072
return _thisPlayer[1];
1107311073
}
1107411074

11075-
inline int getMyCiv() {
11075+
inline int GetMyCiv() {
1107611076
int _this = *(int*)(*(int*)0xc66234 + 0x13c);
1107711077
_this = *(int*)(*(int*)(_this + 0x58) + 4 * *(int*)0xc66664);
1107811078
int* _thisPlayer = (int*)(*(int*)(_this + 0x80) + 0xc);
1107911079
return **(int**)(*_thisPlayer + 0x20);
1108011080
}
1108111081

11082-
inline int getMyTeam() {
11082+
inline int GetMyTeam() {
1108311083
int _this = *(int*)(*(int*)0xc66234 + 0x13c);
1108411084
_this = *(int*)(*(int*)(_this + 0x58) + 4 * *(int*)0xc66664);
1108511085
int* _thisPlayer = (int*)(*(int*)(_this + 0x80) + 0xc);

Release/Documentation/Examples/UHCPluginDemo2/CheatFunctions.cpp

-6
This file was deleted.

Release/Documentation/Examples/UHCPluginDemo2/CheatFunctions.h

-15
This file was deleted.

Release/Documentation/Examples/UHCPluginDemo2/UHCPlugin.h

-40
This file was deleted.

Release/Documentation/Examples/UHCPluginDemo2/UHCPluginDemo2.cpp

-20
This file was deleted.

0 commit comments

Comments
 (0)