forked from Phobos-developers/YRpp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEventClass.h
486 lines (402 loc) · 8.79 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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
#pragma once
#include <ScenarioClass.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)
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*, 0x0082091C, 47> const EventNames {};
static constexpr reference<EventList<0x80>, 0x00A802C8> OutList {};
static constexpr reference<EventList<0x4000>, 0x008B41F8> DoList {};
// If the event is a MegaMission, then add it to this list
static constexpr reference<EventList<0x100>, 0x00A83ED0> MegaMissionList {};
// this points to CRCs from 0x100 last frames
static constexpr reference<DWORD, 0x00B04474, 256> const LatestFramesCRC {};
static constexpr reference<DWORD, 0x00AC51FC> 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 = (LOBYTE(OutList->Tail) + 1) & 127;
return true;
}
explicit EventClass(int houseIndex, EventType eventType)
{
JMP_THIS(0x4C66C0);
}
// 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;
}
bool operator==(const EventClass& q) const
{
return memcmp(this, &q, sizeof(q)) == 0;
};
// ========================
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.
union
{
char DataBuffer[104];
struct EMPTY
{ } Empty;
struct POWERON
{
TargetClass Target;
} Poweron;
struct POWEROFF
{
TargetClass Target;
} Poweroff;
struct ALLY
{
int HouseID;
} Ally;
struct MEGAMISSION
{
TargetClass Whom;
unsigned char Mission;
char _gap_;
TargetClass Target;
TargetClass Destination;
TargetClass Follow;
bool IsPlanningEvent;
} MegaMission;
struct MEGAMISSION_F
{
TargetClass Whom;
unsigned char Mission;
TargetClass Target;
TargetClass Destination;
int Speed;
int MaxSpeed;
} MegaMissionF;
struct IDLE
{
TargetClass Whom;
} Idle;
struct SCATTER
{
TargetClass Whom;
} Scatter;
struct DESTRUCT
{ } Destruct;
struct DEPLOY
{
TargetClass Whom;
} Deploy;
struct DETONATE
{
TargetClass Whom;
} Detonate;
struct PLACE
{
AbstractType RTTIType;
int HeapID;
int IsNaval;
CellStruct Location;
} Place;
struct OPTIONS
{ } Options;
struct GAMESPEED
{
int GameSpeed;
} GameSpeed;
// This event starts production of the specified object type. The house can
// determine from the type and ID value, what object to begin production on and
// what factory to use.
struct PRODUCE
{
AbstractType RTTIType;
int HeapID;
int IsNaval;
} Produce;
struct SUSPEND
{
AbstractType RTTIType;
int HeapID;
int IsNaval;
} Suspend;
// This event is generated when the player cancels production of the specified
// object type. From the object type, the exact factory can be inferred.
struct ABANDON
{
AbstractType RTTIType;
int HeapID;
int IsNaval;
} Abandon;
// Toggles the primary factory state of the specified building.
struct PRIMARY
{
TargetClass Whom;
} Primary;
struct SPECIAL_PLACE
{
int ID;
CellStruct Location;
} SpecialPlace;
struct EXIT
{ } Exit;
struct ANIMATION
{
int AnimID;
int HouseID;
Point2D Location;
} Animation;
// Starts or stops repair on the specified object. This event is triggered by the
// player clicking the repair wrench on a building.
struct REPAIR
{
TargetClass Whom;
} Repair;
// Tells a building/unit to sell. This event is triggered by the player clicking the
// sell animating cursor over the building or unit.
struct SELL
{
TargetClass Whom;
} Sell;
// Used to sell walls
struct SELLCELL
{
CellStruct Location;
} SellCell;
// Update the special control flags. This is necessary so that in a multiplayer
// game, all machines will agree on the rules. If these options change during
// game play, then all players are informed that options have changed.
struct SPECIAL
{
ScenarioFlags SpecialFlags;
} Special;
struct FRAMESYNC
{ } FrameSync;
struct MESSAGE
{ } Message;
struct RESPONSE_TIME
{
char unknown;
} ResponseTime;
struct FRAMEINFO
{
unsigned int CRC;
unsigned short CommandCount;
unsigned char Delay;
} FrameInfo;
struct SAVEGAME
{ } SaveGame;
// Update the archive target for this building.
struct ARCHIVE
{
TargetClass Whom1;
TargetClass Whom2;
} Archive;
struct ADDPLAYER
{
void* unknownPointer;
} AddPlayer;
struct TIMING
{
unsigned short RequestedFPS;
unsigned short MaxAhead;
unsigned char FrameSendRate;
} Timing;
struct PROCESS_TIME
{
unsigned short Time;
} ProcessTime;
struct PAGEUSER
{ } PageUser;
struct REMOVEPLAYER
{
int HouseID;
} RemovePlayer;
struct LATENCYFUDGE
{
int LatencyFudge;
} LatencyFudge;
struct MEGAFRAMEINFO
{
char Unknown[104];
} MegafFameInfo;
struct PACKETTIMING
{
char Unknown[64];
} PacketTiming;
struct ABOUTTOEXIT
{ } AboutToExit;
struct FALLBACKHOST
{
int FallbackHost;
} FallbackHost;
struct ADDRESSCHANGE
{
char PlayerID;
DWORD Address;
} AddressChange;
struct PLANCONNECT
{
TargetClass Target1;
TargetClass Target2;
} PlanConnect;
struct PLANCOMMIT
{ } PlanCommit;
struct PLANNODEDELETE
{
TargetClass Target;
} PlanNodeDelete;
struct ALLCHEER
{
char Unknown[4];
} AllCheer;
struct ABANDON_ALL
{
char Unknown[12];
} AbandonAll;
};
};
#pragma pack(pop)
static_assert(sizeof(EventClass) == 111);
static_assert(offsetof(EventClass, DataBuffer) == 7);