2
2
//
3
3
4
4
#include " stdafx.h"
5
- # include < stdio.h >
6
- #include < stdlib.h >
5
+
6
+ #include < cmath >
7
7
8
8
using namespace syscalls ;
9
9
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 ;
14
11
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 ;
18
15
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
+ }
22
24
23
- // Turns a random enemy's settlers into sheep
24
- void __stdcall cheatExample (void * playerData) {
25
- xsSetContextPlayer (1 );
26
25
for (int i = 1 ; i < GetNumberPlayers (); i++) {
26
+ xsSetContextPlayer (1 );
27
+
27
28
if (kbIsPlayerEnemy (i) && !kbIsPlayerResigned (i)) {
28
29
xsSetContextPlayer (i);
29
30
trUnitSelectClear ();
30
31
31
32
int unitQueryID = kbUnitQueryCreate (" CheatUnitQuery" );
32
33
kbUnitQuerySetIgnoreKnockedOutUnits (unitQueryID, true );
33
34
kbUnitQuerySetPlayerID (unitQueryID, i, true );
34
- kbUnitQuerySetUnitType (unitQueryID, kbGetProtoUnitID ( " Settler " ) );
35
+ kbUnitQuerySetUnitType (unitQueryID, villagerType );
35
36
kbUnitQuerySetState (unitQueryID, cUnitStateAlive);
36
37
kbUnitQueryResetResults (unitQueryID);
37
38
int numberFound = kbUnitQueryExecute (unitQueryID);
@@ -40,32 +41,65 @@ void __stdcall cheatExample(void* playerData) {
40
41
trUnitSelectByID (kbUnitQueryGetResult (unitQueryID, n));
41
42
42
43
trUnitChangeProtoUnit (" Sheep" );
43
- // trSoundPlayFN("SheepSelect.wav", "", -1, "", "");
44
- break ;
44
+
45
+ kbUnitQueryDestroy (unitQueryID) ;
45
46
}
46
47
}
47
48
}
48
49
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 ;
50
77
51
78
extern " C" _declspec(dllexport)
52
- int __stdcall UHCPluginMain (UHCPluginInfo* pluginInfo) {
79
+ int UHCPluginMain (UHCPluginInfo* pluginInfo) {
80
+ g_PluginInfo = pluginInfo;
81
+
53
82
// Register your syscalls and cheats here...
54
83
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." );
58
94
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);
61
96
62
- pluginInfo->SyscallSetParam (aiTest, 0 , Integer, &aiDefaultParamValue);
97
+ // Second parameter is always true
98
+ pluginInfo->RegisterCheat (" force of nature" , TRUE , ForceOfNature);
63
99
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);
67
101
68
- pluginInfo->RegisterCheat (pluginInfo-> info , L" force of nature " , true , cheatExample );
102
+ pluginInfo->RegisterCheat (" kill 'em all " , TRUE , KillemAll );
69
103
70
104
return 0 ;
71
105
}
0 commit comments