forked from Phobos-developers/YRpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EventClass.h
306 lines (260 loc) · 5.65 KB
/
EventClass.h
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
#pragma once
#include <Helpers/CompileTime.h>
#include <TargetClass.h>
#include <Unsorted.h>
enum class EventType : unsigned char
{
EMPTY = 0,
POWERON = 1,
POWEROFF = 2,
ALLY = 3,
MEGAMISSION = 4,
MEGAMISSION_F = 5,
IDLE = 6,
SCATTER = 7,
DESTRUCT = 8,
DEPLOY = 9,
DETONATE = 10,
PLACE = 11,
OPTIONS = 12,
GAMESPEED = 13,
PRODUCE = 14,
SUSPEND = 15,
ABANDON = 16,
PRIMARY = 17,
SPECIAL_PLACE = 18,
EXIT = 19,
ANIMATION = 20,
REPAIR = 21,
SELL = 22,
SELLCELL = 23,
SPECIAL = 24,
FRAMESYNC = 25,
MESSAGE = 26,
RESPONSE_TIME = 27,
FRAMEINFO = 28,
SAVEGAME = 29,
ARCHIVE = 30,
ADDPLAYER = 31,
TIMING = 32,
PROCESS_TIME = 33,
PAGEUSER = 34,
REMOVEPLAYER = 35,
LATENCYFUDGE = 36,
MEGAFRAMEINFO = 37,
PACKETTIMING = 38,
ABOUTTOEXIT = 39,
FALLBACKHOST = 40,
ADDRESSCHANGE = 41,
PLANCONNECT = 42,
PLANCOMMIT = 43,
PLANNODEDELETE = 44,
ALLCHEER = 45,
ABANDON_ALL = 46,
LAST_EVENT = 47,
};
#pragma pack(push, 1)
union EventData
{
EventData()
{
}
struct
{
char Data[104];
} SpaceGap; // Just a space gap to align the struct
struct
{
int ID; // Anim ID
int AnimOwner; // House ID
CellStruct Location;
} Animation;
struct
{
unsigned int CRC;
unsigned short CommandCount;
unsigned char Delay;
} FrameInfo;
struct
{
TargetClass Whom;
} Target;
struct
{
TargetClass Whom;
unsigned char Mission; // Mission but should be byte
char _gap_;
TargetClass Target;
TargetClass Destination;
TargetClass Follow;
bool IsPlanningEvent;
} MegaMission;
struct
{
TargetClass Whom;
unsigned char Mission;
TargetClass Target;
TargetClass Destination;
int Speed;
int MaxSpeed;
} MegaMission_F; // Seems unused in YR?
struct
{
int RTTI_ID;
int Heap_ID;
int IsNaval;
} Production;
struct
{
int Unknown_0;
long long Data;
int Unknown_C;
} Unknown_LongLong;
struct
{
int Unknown_0;
int Unknown_4;
int Data;
int Unknown_C;
} Unknown_Tuple;
struct
{
AbstractType RTTIType;
int HeapID;
int IsNaval;
CellStruct Location;
} Place;
struct
{
int ID;
CellStruct Location;
} SpecialPlace;
struct
{
AbstractType RTTIType;
int ID;
} Specific;
};
class EventClass;
template<size_t Length>
struct EventList
{
public:
int Count;
int Head;
int Tail;
EventClass List[Length];
int Timings[Length];
};
class EventClass
{
public:
static constexpr reference<const char*, 0x82091C, 47> const EventNames{};
static constexpr reference<EventList<0x80>, 0xA802C8> OutList{};
static constexpr reference<EventList<0x4000>, 0x8B41F8> DoList{};
// If the event is a MegaMission, then add it to this list
static constexpr reference<EventList<0x100>, 0xA83ED0> MegaMissionList{};
// this points to CRCs from 0x100 last frames
static constexpr reference<DWORD, 0xB04474, 256> const LatestFramesCRC{};
static constexpr reference<DWORD, 0xAC51FC> const CurrentFrameCRC{};
static bool AddEvent(const EventClass& event)
{
if (OutList->Count >= 128)
return false;
OutList->List[OutList->Tail] = event;
OutList->Timings[OutList->Tail] = static_cast<int>(Imports::TimeGetTime()());
++OutList->Count;
OutList->Tail = (OutList->Tail + 1) & 127;
}
// Special
explicit EventClass(int houseIndex, int id)
{
JMP_THIS(0x4C65A0);
}
// Target
explicit EventClass(int houseIndex, EventType eventType, int id, int rtti)
{
JMP_THIS(0x4C65E0);
}
// Sellcell
explicit EventClass(int houseIndex, EventType eventType, const CellStruct& cell)
{
JMP_THIS(0x4C6650);
}
// Archive & Planning_Connect
explicit EventClass(int houseIndex, EventType eventType, TargetClass src, TargetClass dest)
{
JMP_THIS(0x4C6780);
}
// Anim
explicit EventClass(int houseIndex, int anim_id, HouseClass* pHouse, const CellStruct& cell)
{
JMP_THIS(0x4C6800);
}
// MegaMission
explicit EventClass(int houseIndex, TargetClass src, Mission mission, TargetClass target, TargetClass dest, TargetClass follow)
{
JMP_THIS(0x4C6860);
}
// MegaMission_F
explicit EventClass(int houseIndex, TargetClass src, Mission mission, TargetClass target, TargetClass dest, SpeedType speed, int/*MPHType*/ maxSpeed)
{
JMP_THIS(0x4C68E0);
}
// Production
explicit EventClass(int houseIndex, EventType eventType, int rtti_id, int heap_id, BOOL is_naval)
{
JMP_THIS(0x4C6970);
}
// Unknown_LongLong
explicit EventClass(int houseIndex, EventType eventType, int unknown_0, const int& unknown_c)
{
JMP_THIS(0x4C69E0);
}
// Unknown_Tuple
explicit EventClass(int houseIndex, EventType eventType, int unknown_0, int unknown_4, int& unknown_c)
{
JMP_THIS(0x4C6A60);
}
// Place
explicit EventClass(int houseIndex, EventType eventType, AbstractType rttitype, int heapid, int is_naval, const CellStruct& cell)
{
JMP_THIS(0x4C6AE0);
}
// SpecialPlace
explicit EventClass(int houseIndex, EventType eventType, int id, const CellStruct& cell)
{
JMP_THIS(0x4C6B60);
}
// Specific?, maybe int[2] otherwise
explicit EventClass(int houseIndex, EventType eventType, AbstractType rttitype, int id)
{
JMP_THIS(0x4C6BE0);
}
// Address Change
explicit EventClass(int houseIndex, void*/*IPAddressClass*/ ip, char unknown_0)
{
JMP_THIS(0x4C6C50);
}
explicit EventClass(const EventClass& another)
{
memcpy(this, &another, sizeof(*this));
}
EventClass& operator=(const EventClass& another)
{
if (this != &another)
memcpy(this, &another, sizeof(*this));
return *this;
}
EventType Type;
bool IsExecuted;
char HouseIndex; // '-1' stands for not a valid house
unsigned int Frame; // 'Frame' is the frame that the command should execute on.
EventData Data;
bool operator==(const EventClass& q) const
{
return memcmp(this, &q, sizeof(q)) == 0;
};
};
#pragma pack(pop)
static_assert(sizeof(EventClass) == 111);