-
Notifications
You must be signed in to change notification settings - Fork 1
/
DynExt.h
296 lines (256 loc) · 7.54 KB
/
DynExt.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
#ifndef __DynExt_h__
#define __DynExt_h__
#pragma pack(push, 1)
// Make identifier
//#define MAKEID(a,b,c,d) ((#@a << 24)|(#@b << 16)|(#@c << 8)|(#@d))
#define IS_SET(flags, flag) (((flags) & (flag)) ? true : false)
#define PACK_FLOAT(f) *((long *)&(f))
#define UNPACK_FLOAT(f) *((float *)&(f))
////
template <class T> inline T * PtrAddBytes(T * ptr, int bytes)
{
return (T *)((__int8 *)ptr + bytes);
}
// HWA/Unicode handling, courtesy of Yves
#define EF_ISHWA 112 // Returns TRUE if HWA version (editor and runtime)
#define EF_ISUNICODE 113 // Returns TRUE if the editor or runtime is in Unicode mode
#define EF_GETAPPCODEPAGE 114 // Returns the code page of the application
extern int oiListItemSize;
void InitOiListItemSize(LPMV pMv);
#define GetOILPtr(oiListPtr, oiListIndex) \
PtrAddBytes(oiListPtr, oiListItemSize * oiListIndex)
#define NextOILPtr(oiListItemPtr) PtrAddBytes(oiListItemPtr, oiListItemSize)
// Convert a fixed value to an object
inline headerObject * Fixed2Object(LPRDATA rdPtr, unsigned int fixed)
{
LPOBL ObjectList = rdPtr->rHo.hoAdRunHeader->rhObjectList;
headerObject * pObject = ObjectList[0x0000FFFF & fixed].oblOffset;
if (pObject && pObject->hoCreationId == fixed >> 16) {
return pObject;
}
else {
return NULL;
}
}
// Convert an object to a fixed value
inline unsigned int Object2Fixed(headerObject * object)
{
return (object->hoCreationId << 16) + object->hoNumber;
}
inline long Float2Long(float value) { return *(long *)&value; }
inline float Long2Float(long value) { return *(float *)&value; }
////
double getAlterableValue(LPRO object, int ValueNum);
/*struct AltVal
{
long ValueType;
long ValueFlags;
union
{
long LongValue;
double DoubleValue;
};
};
double getAlterableValue(LPRO object, int ValueNum);
*/
////
enum Comparison {
PC_EQUAL = CMPOPE_EQU,
PC_DIFFERENT = CMPOPE_DIF,
PC_LOWER_OR_EQUAL = CMPOPE_LOWEQU,
PC_LOWER = CMPOPE_LOW,
PC_GREATER_OR_EQUAL = CMPOPE_GREEQU,
PC_GREATER = CMPOPE_GRE,
};
enum CompValueType {
PC_LONG = 0,
PC_FLOAT = 23,
PC_DOUBLE = 23,
};
struct ParamComp {
// Comparison compType:16;
short compType;
struct // CompValue
{
short unknown;
short valueType;
short valueSize;
union {
long longValue;
struct {
double doubleValue;
float floatValue;
};
};
}; // compValue;
inline double GetDoubleValue()
{
if (valueType == PC_LONG) {
return (double)longValue;
}
else if (valueType == PC_DOUBLE) // || PC_FLOAT, same thing
{
return doubleValue;
}
return 0.0;
};
};
inline ParamComp * GetComparisonParameter(LPRDATA rdPtr)
{
eventParam * CurrentParam = rdPtr->rHo.hoCurrentParam;
// EVPNEXT(rdPtr->rHo.hoCurrentParam);
switch (CurrentParam->evpCode) {
case PARAM_CMPSTRING:
case PARAM_COMPARAISON: {
ParamComp * pData = (ParamComp *)(&(CurrentParam->evp));
return pData;
} break;
}
return NULL;
}
inline long Param_Comparison_true(
Comparison comparison,
long value) // Returns a value such that (return comparison value) is true
{
switch (comparison) {
case PC_EQUAL:
case PC_LOWER_OR_EQUAL:
case PC_GREATER_OR_EQUAL:
return value;
case PC_DIFFERENT:
case PC_LOWER:
return value - 1;
case PC_GREATER:
return value + 1;
default:
return 0; // ERROR!!!
}
}
inline long Param_Comparison_false(
Comparison comparison,
long value) // Returns a value such that (return comparison value) is false
{
switch (comparison) {
case PC_DIFFERENT:
case PC_LOWER:
case PC_GREATER:
return value;
case PC_EQUAL:
case PC_GREATER_OR_EQUAL:
return value - 1;
case PC_LOWER_OR_EQUAL:
return value + 1;
default:
return 0; // ERROR!!!
}
}
inline bool Param_Comparison_Test(Comparison comparison, double left, double right)
{
switch (comparison) {
case PC_EQUAL:
return left == right;
case PC_DIFFERENT:
return left != right;
case PC_LOWER_OR_EQUAL:
return left <= right;
case PC_LOWER:
return left < right;
case PC_GREATER_OR_EQUAL:
return left >= right;
case PC_GREATER:
return left > right;
default:
return 0; // ERROR!!!
}
}
inline bool Param_Comparison_Test(Comparison comparison, const char * left, const char * right)
{
int result = strcmp(left, right);
switch (comparison) {
case PC_EQUAL:
return result == 0;
case PC_DIFFERENT:
return result != 0;
case PC_LOWER_OR_EQUAL:
return result <= 0;
case PC_LOWER:
return result < 0;
case PC_GREATER_OR_EQUAL:
return result >= 0;
case PC_GREATER:
return result > 0;
default:
return 0; // ERROR!!!
}
}
////
/*double GetDoubleParameter(LPRDATA rdPtr)
{
eventParam * CurrentParam = rdPtr->rHo.hoCurrentParam;
EVPNEXT(rdPtr->rHo.hoCurrentParam);
switch (CurrentParam->evpCode)
{
case PARAM_EXPRESSION:
case PARAM_COMPARAISON:
{
ParamComp* pData = (ParamComp*)(&(CurrentParam->evp));
return pData->GetDoubleValue();
}
break;
}
return 0.0;
}*/
////
__inline rCom * getrCom(headerObject * object)
{
DWORD OEFlags = object->hoOEFlags;
if (!IS_SET(OEFlags, OEFLAG_MOVEMENTS) && !IS_SET(OEFlags, OEFLAG_ANIMATIONS))
return 0;
return (rCom *)((__int8 *)object + sizeof(headerObject));
}
__inline rMvt * getrMvt(headerObject * object)
{
DWORD OEFlags = object->hoOEFlags;
if (!IS_SET(OEFlags, OEFLAG_MOVEMENTS))
return 0;
return (rMvt *)((__int8 *)object + sizeof(headerObject) + sizeof(rCom));
}
__inline rAni * getrAni(headerObject * object)
{
DWORD OEFlags = object->hoOEFlags;
if (!IS_SET(OEFlags, OEFLAG_ANIMATIONS))
return 0;
return (rAni *)((__int8 *)object + sizeof(headerObject) + sizeof(rCom) +
(IS_SET(OEFlags, OEFLAG_MOVEMENTS) ? sizeof(rMvt) : 0));
}
__inline rSpr * getrSpr(headerObject * object)
{
DWORD OEFlags = object->hoOEFlags;
if (!IS_SET(OEFlags, OEFLAG_SPRITES))
return 0;
return (rSpr *)((__int8 *)object + sizeof(headerObject) +
((IS_SET(OEFlags, OEFLAG_MOVEMENTS) || IS_SET(OEFlags, OEFLAG_ANIMATIONS))
? sizeof(rCom)
: 0) +
(IS_SET(OEFlags, OEFLAG_MOVEMENTS) ? sizeof(rMvt) : 0) +
(IS_SET(OEFlags, OEFLAG_ANIMATIONS) ? sizeof(rAni) : 0));
}
__inline rVal * getrVal(headerObject * object)
{
DWORD OEFlags = object->hoOEFlags;
if (!IS_SET(OEFlags, OEFLAG_VALUES))
return 0;
return (rVal *)((__int8 *)object + sizeof(headerObject) +
((IS_SET(OEFlags, OEFLAG_MOVEMENTS) || IS_SET(OEFlags, OEFLAG_ANIMATIONS))
? sizeof(rCom)
: 0) +
(IS_SET(OEFlags, OEFLAG_MOVEMENTS) ? sizeof(rMvt) : 0) +
(IS_SET(OEFlags, OEFLAG_ANIMATIONS) ? sizeof(rAni) : 0) +
(IS_SET(OEFlags, OEFLAG_SPRITES) ? sizeof(rSpr) : 0));
}
#pragma pack(pop)
#else
#ifdef WARNING_MULTI_INCLUDE
#pragma message(__FILE__ " included multiple times")
#endif
#endif