~ares-developers/ares/gd03

« back to all changes in this revision

Viewing changes to src/Ext/SWType/Hooks.cpp

  • Committer: Renegade
  • Date: 2010-05-29 08:12:17 UTC
  • Revision ID: git-v1:0a1bb6321f04d723afe64d1b843dc87b4da783ec
Creating /trunk/src.

git-svn-id: svn://svn.renegadeprojects.com/ares/trunk@622 859b54a9-7a54-0410-aeb3-f8d2f1fa40fd

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "Body.h"
 
2
#include "../../Misc/SWTypes.h"
 
3
 
 
4
DEFINE_HOOK(6CEF84, SuperWeaponTypeClass_GetCursorOverObject, 7)
 
5
{
 
6
        GET(SuperWeaponTypeClass*, pThis, ECX);
 
7
 
 
8
        SWTypeExt::ExtData *pData = SWTypeExt::ExtMap.Find(pThis);
 
9
 
 
10
        if(pThis->Action == SW_YES_CURSOR) {
 
11
                GET_STACK(CellStruct *, pMapCoords, 0x0C);
 
12
 
 
13
                int Action = SW_YES_CURSOR;
 
14
 
 
15
                if(!pData->SW_FireToShroud.Get()) {
 
16
                        CellClass* pCell = MapClass::Instance->GetCellAt(pMapCoords);
 
17
                        CoordStruct Crd;
 
18
 
 
19
                        if(MapClass::Instance->IsLocationShrouded(pCell->GetCoords(&Crd))) {
 
20
                                Action = SW_NO_CURSOR;
 
21
                        }
 
22
                }
 
23
 
 
24
                if(pThis->Type >= FIRST_SW_TYPE && !NewSWType::GetNthItem(pThis->Type)->CanFireAt(pMapCoords)) {
 
25
                        Action = SW_NO_CURSOR;
 
26
                }
 
27
 
 
28
                R->EAX(Action);
 
29
 
 
30
                if(Action == SW_YES_CURSOR) {
 
31
                        SWTypeExt::CurrentSWType = pThis;
 
32
                        Actions::Set(&pData->SW_Cursor, pData->SW_FireToShroud);
 
33
                } else {
 
34
                        SWTypeExt::CurrentSWType = NULL;
 
35
                        Actions::Set(&pData->SW_NoCursor, pData->SW_FireToShroud);
 
36
                }
 
37
                return 0x6CEFD9;
 
38
        }
 
39
        return 0;
 
40
}
 
41
 
 
42
 
 
43
DEFINE_HOOK(653B3A, RadarClass_GetMouseAction_CustomSWAction, 5)
 
44
{
 
45
        int idxSWType = Unsorted::CurrentSWType;
 
46
        if(idxSWType > -1) {
 
47
                GET_STACK(byte, EventFlags, 0x58);
 
48
 
 
49
                MouseEvent::Value E(EventFlags);
 
50
                if(E & (MouseEvent::RightDown | MouseEvent::RightUp)) {
 
51
                        return 0x653D6F;
 
52
                }
 
53
 
 
54
                SuperWeaponTypeClass *pThis = SuperWeaponTypeClass::Array->GetItem(idxSWType);
 
55
                SWTypeExt::ExtData *pData = SWTypeExt::ExtMap.Find(pThis);
 
56
 
 
57
                if(pThis->Action == SW_YES_CURSOR) {
 
58
                        GET_STACK(CellStruct, pMapCoords, STACK_OFFS(0x54, 0x3C));
 
59
 
 
60
                        int Action = SW_YES_CURSOR;
 
61
 
 
62
                        if(!pData->SW_FireToShroud.Get()) {
 
63
                                CellClass* pCell = MapClass::Instance->GetCellAt(&pMapCoords);
 
64
                                CoordStruct Crd;
 
65
 
 
66
                                if(MapClass::Instance->IsLocationShrouded(pCell->GetCoords(&Crd))) {
 
67
                                        Action = SW_NO_CURSOR;
 
68
                                }
 
69
                        }
 
70
 
 
71
                        if(pThis->Type >= FIRST_SW_TYPE && !NewSWType::GetNthItem(pThis->Type)->CanFireAt(&pMapCoords)) {
 
72
                                Action = SW_NO_CURSOR;
 
73
                        }
 
74
 
 
75
                        R->ESI(Action);
 
76
 
 
77
                        if(Action == SW_YES_CURSOR) {
 
78
                                SWTypeExt::CurrentSWType = pThis;
 
79
                                Actions::Set(&pData->SW_Cursor, pData->SW_FireToShroud);
 
80
                        } else {
 
81
                                SWTypeExt::CurrentSWType = NULL;
 
82
                                Actions::Set(&pData->SW_NoCursor, pData->SW_FireToShroud);
 
83
                        }
 
84
                        return 0x653CA3;
 
85
                }
 
86
        }
 
87
        return 0;
 
88
}
 
89
 
 
90
/*
 
91
// 6AAF92, 6
 
92
XPORT_FUNC(SidebarClass_ProcessCameoClick)
 
93
{
 
94
        DWORD idx = R->get_ESI();
 
95
        SuperWeaponTypeClass *pThis = SuperWeaponTypeClass::Array->GetItem(idx);
 
96
//      int TypeIdx = pThis->get_Type();
 
97
 
 
98
        SWTypeExt::CurrentSWType = pThis;
 
99
        SWTypeExt::ExtData *pData = SWTypeExt::ExtMap.Find(pThis);
 
100
 
 
101
//      Actions::Set(&pData->SW_Cursor);
 
102
 
 
103
        return 0;
 
104
}
 
105
*/
 
106
 
 
107
// decouple SpyPlane from SPYP
 
108
DEFINE_HOOK(6CD67A, SuperClass_Launch_SpyPlane_FindType, 0)
 
109
{
 
110
        GET(SuperClass *, Super, EBX);
 
111
        SWTypeExt::ExtData *pData = SWTypeExt::ExtMap.Find(Super->Type);
 
112
 
 
113
        R->EAX<int>(pData->SpyPlane_TypeIndex);
 
114
        return 0x6CD684;
 
115
}
 
116
 
 
117
// decouple SpyPlane from allied paradrop counts
 
118
DEFINE_HOOK(6CD6A6, SuperClass_Launch_SpyPlane_Fire, 6)
 
119
{
 
120
        GET(SuperClass *, Super, EBX);
 
121
        GET(CellClass *,TargetCell, EDI);
 
122
        SWTypeExt::ExtData *pData = SWTypeExt::ExtMap.Find(Super->Type);
 
123
 
 
124
        Super->Owner->SendSpyPlanes(
 
125
                pData->SpyPlane_TypeIndex, pData->SpyPlane_Count, pData->SpyPlane_Mission, TargetCell, NULL);
 
126
 
 
127
        return 0x6CD6E9;
 
128
}
 
129
 
 
130
// decouple nuke siren from DigSound
 
131
DEFINE_HOOK(6CDDE3, SuperClass_Launch_Nuke_Siren, 6)
 
132
{
 
133
        GET(SuperClass *, Super, EBX);
 
134
        SWTypeExt::ExtData *pData = SWTypeExt::ExtMap.Find(Super->Type);
 
135
 
 
136
        R->ECX(pData->Nuke_Siren);
 
137
        return 0x6CDDE9;
 
138
}
 
139
 
 
140
// 6CEE96, 5
 
141
DEFINE_HOOK(6CEE96, SuperWeaponTypeClass_GetTypeIndex, 5)
 
142
{
 
143
        GET(const char *, TypeStr, EDI);
 
144
        int customType = NewSWType::FindIndex(TypeStr);
 
145
        if(customType > -1) {
 
146
                R->ESI(customType);
 
147
                return 0x6CEE9C;
 
148
        }
 
149
        return 0;
 
150
}
 
151
 
 
152
// 4AC20C, 7
 
153
// translates SW click to type
 
154
DEFINE_HOOK(4AC20C, DisplayClass_LMBUp, 7)
 
155
{
 
156
        int Action = R->Stack32(0x9C);
 
157
        if(Action < SW_NO_CURSOR) {
 
158
                SuperWeaponTypeClass * pSW = SuperWeaponTypeClass::FindFirstOfAction(Action);
 
159
                R->EAX(pSW);
 
160
                return pSW ? 0x4AC21C : 0x4AC294;
 
161
        }
 
162
        else if(Action == SW_NO_CURSOR) {
 
163
                R->EAX(0);
 
164
                return 0x4AC294;
 
165
        }
 
166
 
 
167
        R->EAX(SWTypeExt::CurrentSWType);
 
168
 
 
169
        return 0x4AC21C;
 
170
}
 
171
 
 
172
// decoupling sw anims from types
 
173
// 446418, 6
 
174
DEFINE_HOOK(446418, BuildingClass_Place1, 6)
 
175
{
 
176
        GET(BuildingClass *, pBuild, EBP);
 
177
        GET(HouseClass *, pHouse, EAX);
 
178
        int swTIdx = pBuild->Type->SuperWeapon;
 
179
        if(swTIdx == -1) {
 
180
                swTIdx = pBuild->Type->SuperWeapon2;
 
181
                if(swTIdx == -1) {
 
182
                        return 0x446580;
 
183
                }
 
184
        }
 
185
 
 
186
        R->EAX(pHouse->Supers.GetItem(swTIdx));
 
187
        return 0x44643E;
 
188
}
 
189
 
 
190
// 44656D, 6
 
191
DEFINE_HOOK(44656D, BuildingClass_Place2, 6)
 
192
{
 
193
        return 0x446580;
 
194
}
 
195
 
 
196
// 45100A, 6
 
197
DEFINE_HOOK(45100A, BuildingClass_ProcessAnims1, 6)
 
198
{
 
199
        GET(BuildingClass *, pBuild, ESI);
 
200
        GET(HouseClass *, pHouse, EAX);
 
201
        int swTIdx = pBuild->Type->SuperWeapon;
 
202
        if(swTIdx == -1) {
 
203
                swTIdx = pBuild->Type->SuperWeapon2;
 
204
                if(swTIdx == -1) {
 
205
                        return 0x451145;
 
206
                }
 
207
        }
 
208
 
 
209
        R->EDI(pBuild->Type);
 
210
        R->EAX(pHouse->Supers.GetItem(swTIdx));
 
211
        return 0x451030;
 
212
}
 
213
 
 
214
// 451132, 6
 
215
DEFINE_HOOK(451132, BuildingClass_ProcessAnims2, 6)
 
216
{
 
217
        return 0x451145;
 
218
}
 
219
 
 
220
// EVA_Detected
 
221
// 446937, 6
 
222
DEFINE_HOOK(446937, BuildingClass_AnnounceSW, 6)
 
223
{
 
224
        GET(BuildingClass *, pBuild, EBP);
 
225
        int swTIdx = pBuild->Type->SuperWeapon;
 
226
        if(swTIdx == -1) {
 
227
                swTIdx = pBuild->Type->SuperWeapon2;
 
228
                if(swTIdx == -1) {
 
229
                        return 0x44699A;
 
230
                }
 
231
        }
 
232
 
 
233
        SuperWeaponTypeClass *pSW = SuperWeaponTypeClass::Array->GetItem(swTIdx);
 
234
        SWTypeExt::ExtData *pData = SWTypeExt::ExtMap.Find(pSW);
 
235
 
 
236
        if(pData->EVA_Detected != -1) {
 
237
                VoxClass::PlayIndex(pData->EVA_Detected);
 
238
                return 0x44699A;
 
239
        }
 
240
        return 0;
 
241
}
 
242
 
 
243
// EVA_Ready
 
244
// 6CBDD7, 6
 
245
DEFINE_HOOK(6CBDD7, SuperClass_AnnounceReady, 6)
 
246
{
 
247
        GET(SuperWeaponTypeClass *, pThis, EAX);
 
248
        SWTypeExt::ExtData *pData = SWTypeExt::ExtMap.Find(pThis);
 
249
 
 
250
        if(pData->EVA_Ready != -1) {
 
251
                VoxClass::PlayIndex(pData->EVA_Ready);
 
252
                return 0x6CBE68;
 
253
        }
 
254
        return 0;
 
255
}
 
256
 
 
257
// 6CC0EA, 9
 
258
DEFINE_HOOK(6CC0EA, SuperClass_AnnounceQuantity, 9)
 
259
{
 
260
        GET(SuperClass *, pThis, ESI);
 
261
        SuperWeaponTypeClass *pSW = pThis->Type;
 
262
        SWTypeExt::ExtData *pData = SWTypeExt::ExtMap.Find(pSW);
 
263
 
 
264
        if(pData->EVA_Ready != -1) {
 
265
                VoxClass::PlayIndex(pData->EVA_Ready);
 
266
                return 0x6CC17E;
 
267
        }
 
268
        return 0;
 
269
}
 
270
 
 
271
DEFINE_HOOK(50B319, HouseClass_UpdateSWs, 6)
 
272
{
 
273
//      GET(SuperClass *, Super, ECX);
 
274
        GET(HouseClass *, H, EBP);
 
275
        GET(int, Index, EDI);
 
276
        SuperClass *Super = H->Supers.GetItem(Index);
 
277
        SuperWeaponTypeClass *pSW = Super->Type;
 
278
        SWTypeExt::ExtData *pData = SWTypeExt::ExtMap.Find(pSW);
 
279
        if(pData->SW_AutoFire) {
 
280
        //      Fire! requires networking event woodoo or fake mouse clicks, bah
 
281
        }
 
282
        return 0;
 
283
}
 
284
 
 
285
// EVA_Activated is complex, will do later
 
286
 
 
287
// AI SW targeting submarines
 
288
DEFINE_HOOK(50CFAA, HouseClass_PickOffensiveSWTarget, 0)
 
289
{
 
290
        R->ESI(0);
 
291
        R->Stack8(0x13, 1);
 
292
        return 0x50CFC9;
 
293
}
 
294
 
 
295
// ARGH!
 
296
DEFINE_HOOK(6CC390, SuperClass_Launch, 6)
 
297
{
 
298
        GET(SuperClass *, pSuper, ECX);
 
299
        GET_STACK(CellStruct*, pCoords, 0x4);
 
300
        GET_STACK(byte, IsPlayer, 0x8);
 
301
        bool handled = SWTypeExt::SuperClass_Launch(pSuper, pCoords, IsPlayer);
 
302
 
 
303
        return handled ? 0x6CDE40 : 0;
 
304
}
 
305
 
 
306
DEFINE_HOOK(6CC360, SuperClass_IsReadyToFire, 5)
 
307
{
 
308
        GET(SuperClass *, pThis, ECX);
 
309
        SuperWeaponTypeClass *pSW = pThis->Type;
 
310
        SWTypeExt::ExtData *pData = SWTypeExt::ExtMap.Find(pSW);
 
311
 
 
312
        if(pData->Money_Amount) {
 
313
                if(pThis->Owner->Available_Money() < pData->Money_Amount) {
 
314
                        return 0x6CC381;
 
315
                }
 
316
        }
 
317
        return 0;
 
318
}
 
319
 
 
320
DEFINE_HOOK(44691B, BuildingClass_4DC_SWAvailable, 6)
 
321
{
 
322
        GET(BuildingClass *, Structure, EBP);
 
323
        GET(BuildingTypeClass *, AuxBuilding, EAX);
 
324
        return Structure->Owner->CountOwnedNow(AuxBuilding) > 0
 
325
                ? 0x446937
 
326
                : 0x44699A
 
327
        ;
 
328
}
 
329
 
 
330
DEFINE_HOOK(45765A, BuildingClass_SWAvailable, 6)
 
331
{
 
332
        GET(BuildingClass *, Structure, ESI);
 
333
        GET(BuildingTypeClass *, AuxBuilding, EAX);
 
334
        return Structure->Owner->CountOwnedNow(AuxBuilding) > 0
 
335
                ? 0x457676
 
336
                : 0x45767B
 
337
        ;
 
338
}
 
339
 
 
340
DEFINE_HOOK(4576BA, BuildingClass_SW2Available, 6)
 
341
{
 
342
        GET(BuildingClass *, Structure, ESI);
 
343
        GET(BuildingTypeClass *, AuxBuilding, EAX);
 
344
        return Structure->Owner->CountOwnedNow(AuxBuilding) > 0
 
345
                ? 0x4576D6
 
346
                : 0x4576DB
 
347
        ;
 
348
}