-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathBackRing.cpp
More file actions
543 lines (441 loc) · 12.8 KB
/
Copy pathBackRing.cpp
File metadata and controls
543 lines (441 loc) · 12.8 KB
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
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
#include "stdafx.h"
#include <fstream>
#define BackRingSize 34
//Back Ring Main Page, this is where the current goal of the stage is swapped with back ring, froggy, balloon etc. depending on the character.
//This is also where the race result are checked if the player 1 lose.
int RingCopy = 0; //Backring
char TimeSecCopy = 0;
char TimeMinCopy = 0;
char TimeFrameCopy = 0;
bool GetBackRing = false;
//back ring Model and Display Stuff
Trampoline* Capsule_Load_T = nullptr;
Trampoline* Froggy_Load_T = nullptr;
Trampoline* Froggy_Main_T = nullptr;
Trampoline* Balloon_Load_T = nullptr;
Trampoline* OTarget_T = nullptr;
void BackRingObj_Display(ObjectMaster* obj) {
if (!MissedFrames) {
njSetTexture(&GoalRingTextures);
njPushMatrix(0);
njTranslateV(nullptr, &obj->Data1->Position);
njRotateY(nullptr, obj->Data1->Rotation.y);
njScale(0, obj->Data1->Scale.x, obj->Data1->Scale.x, obj->Data1->Scale.x);
DrawObject(&object_GoalRing);
njPopMatrix(1);
}
}
enum BackRing_Actions {
BackRing_Init,
BackRing_Seek,
BackRing_Setting
};
int __cdecl CheckDynamiteBroken_r(int DynNumber)
{
int v1; // edi
EntityData1* data; // esi
int result; // eax
int v4; // [esp+10h] [ebp-4h]
v1 = 0;
v4 = 0;
if (!dynamite_num)
{
result = 0;
return result;
}
do
{
data = dynamiteArray[v1]->Data1;
if (!data) { //fix nonsense crash when using backring
break;
}
if (DynNumber == (unsigned __int64)data->Scale.x)
{
if ((data->Status & 0x100) == 0)
{
result = 0;
return result;
}
++v4;
}
++v1;
} while (v1 < (unsigned __int8)dynamite_num);
if (v4)
{
result = 1;
}
else
{
result = 0;
}
return result;
}
//ran every UNpaused frame
void BackRingObj_Main(ObjectMaster* obj) {
ObjectMaster* play1 = GetCharacterObject(0);
EntityData1* data = obj->Data1;
switch (data->Action) {
case BackRing_Init:
obj->DisplaySub = BackRingObj_Display;
data->Scale.x = 1;
data->Action = BackRing_Seek;
obj->SETData.SETData->Flags = 1; //the object will load only once forever ever
PlayCustomSound_EntityAndVolume(CommonSound_BackRing, obj, 170, 2.0f, true);
break;
case BackRing_Seek:
if (!IsPlayerInsideSphere_(&obj->Data1->Position, squareroot(obj->SETData.SETData->Distance)))
return;
if (IsSpecificPlayerInSphere(&data->Position, BackRingSize + 4, 0)) {
data->CharIndex = TimeFrames;
play1->Data1->Status &= ~(Status_Attack | Status_LightDash | Status_Unknown3);
data->Action = BackRing_Setting;
PlayVoice_Original(5001); //back ring hit SFX
DisableControl();
CharObj2Ptrs[0]->Speed.x = 1;
CharObj2Ptrs[0]->Speed.z = 1;
ResetGravity();
}
data->Rotation.y += 0x180;
obj->DisplaySub(obj);
break;
case BackRing_Setting:
if (data->Scale.x > 0) {
data->Scale.x -= 0.06f;
data->Rotation.y += 0x180;
obj->DisplaySub(obj);
}
else {
obj->Data1->Position.y += 10;
}
if (++data->InvulnerableTime > 70) {
int color = 0x00000000;
ScreenFade_Color = *(NJS_COLOR*)&color;
if (CurrentMission == Mission2_100Rings && Rings < 100 || CurrentMission == Mission3_LostChao)
{
EnableControl();
GetBackRing = true;
DisablePause();
RingCopy = Rings;
TimeSecCopy = TimeSeconds;
TimeMinCopy = TimeMinutes;
TimeFrameCopy = TimeFrames;
SoundManager_Delete2();
ChaoSpawn = false;
ResetRestartData();
if (CurrentStageVersion == TailsVersion || CurrentStageVersion == AmyVersion) {
GameState = 0xc;
}
else if (CurrentStageVersion == GammaVersion)
{
CurrentLevel = LevelCopy;
CurrentAct = ActCopy;
GameState = 7;
}
else
{
GameMode = GameModes_Adventure_Field;
GameState = 0xB;
}
}
else
{
LoadLevelResults();
}
UpdateSetDataAndDelete(obj);
}
else {
int color = 0xFFFFFFFF;
ScreenFade_Color = *(NJS_COLOR*)&color;
if (data->InvulnerableTime < 120) {
if (data->InvulnerableTime < 60) {
data->CharID += 4;
ScreenFade_Color.argb.a = data->CharID;
}
else {
ScreenFade_Color.argb.a = 0xFF;
}
}
else {
data->CharID -= 20;
ScreenFade_Color.argb.a = data->CharID;
}
ScreenFade_DrawColor();
}
break;
}
}
//Replace the capsule according to the character and the mission.
void __cdecl CheckLoadCapsule_r(ObjectMaster* a1) {
if (CurrentStageVersion == GammaVersion && CurrentMission < Mission2_100Rings)
{
if (CurrentAct == 2 && (CurrentLevel == LevelIDs_FinalEgg || (CurrentLevel == LevelIDs_HotShelter && CurrentCharacter == Characters_Gamma))) {
return;
}
}
if (CurrentMission < Mission2_100Rings && CurrentStageVersion != KnucklesVersion)
{
switch (CurrentCharacter)
{
case Characters_Amy:
a1->Data1->Position.y += 37;
a1->MainSub = Balloon_Main;
Balloon_Main(a1);
return;
case Characters_Big:
if (CurrentLevel != LevelIDs_SkyDeck)
{
a1->Data1->Position.y += 20;
a1->MainSub = OFrog;
OFrog(a1);
return;
}
break;
}
}
if (CurrentMission >= Mission2_100Rings)
{
a1->Data1->Position.y += 38;
a1->DisplaySub = BackRingObj_Display;
a1->MainSub = BackRingObj_Main;
return;
}
if (Race && !isAIActive && CurrentMission < Mission2_100Rings)
RaceResultCheck(a1);
//call original function (Capsule.)
if (CurrentStageVersion != KnucklesVersion && CurrentMission < Mission2_100Rings || CurrentLevel == LevelIDs_LostWorld && CurrentAct == 2) {
ObjectFunc(origin, Capsule_Load_T->Target());
origin(a1);
}
}
void Check_DisplayBackRing_Big(ObjectMaster* a1) {
ObjectMaster* play1 = GetCharacterObject(0);
EntityData1* v1 = a1->Data1;
if (CurrentMission >= Mission2_100Rings)
{
a1->Data1->Position.y += 28;
a1->DisplaySub = BackRingObj_Display;
a1->MainSub = BackRingObj_Main;
return;
}
if (Race && !isAIActive && CurrentMission < Mission2_100Rings)
{
RaceResultCheck(a1);
return;
}
}
void Check_DisplayBackRing_Amy(ObjectMaster* a1) {
ObjectMaster* play1 = GetCharacterObject(0);
EntityData1* v1 = a1->Data1;
if (CurrentMission >= Mission2_100Rings)
{
a1->Data1->Position.y += 0;
a1->DisplaySub = BackRingObj_Display;
a1->MainSub = BackRingObj_Main;
return;
}
if (Race && !isAIActive && CurrentMission < Mission2_100Rings)
{
RaceResultCheck(a1);
return;
}
}
void Check_Display_Frog_Balloon(ObjectMaster* a1) {
switch (CurrentCharacter)
{
case Characters_Amy:
a1->Data1->Position.y += 37;
a1->MainSub = Balloon_Main;
Balloon_Main(a1);
break;
case Characters_Big:
a1->Data1->Position.y += 20;
a1->MainSub = OFrog;
OFrog(a1);
break;
}
if (Race && !isAIActive && CurrentMission < Mission2_100Rings)
RaceResultCheck(a1);
}
void Check_Display_BackRing_Common(ObjectMaster* a1) {
if (CurrentStageVersion == GammaVersion && (CurrentLevel == LevelIDs_RedMountain || CurrentLevel == LevelIDs_WindyValley || CurrentLevel == LevelIDs_HotShelter))
a1->Data1->Position.y += 25;
else
a1->Data1->Position.y += 36;
a1->DisplaySub = BackRingObj_Display;
a1->MainSub = BackRingObj_Main;
}
//Check the current mission and replace Froggy with Back Ring.
void __cdecl CheckLoadFroggy_r(ObjectMaster* a1) {
Check_DisplayBackRing_Big(a1);
if (CurrentMission < Mission2_100Rings)
{
if (GetCharacter0ID() == Characters_Big && CurrentStageVersion == BigVersion)
{
return;
}
ObjectFunc(origin, Froggy_Load_T->Target());
origin(a1);
}
}
//Check the current mission and replace Froggy with Back Ring.
void __cdecl CheckLoadBig_Froggy_r(ObjectMaster* a1) {
if (CurrentMission < Mission2_100Rings && GetCharacter0ID() == Characters_Big)
{
ObjectFunc(origin, Froggy_Main_T->Target());
origin(a1);
}
else {
return;
}
}
//Check the current mission and replace Balloon with Back Ring.
void __cdecl CheckLoadBalloon_r(ObjectMaster* a1) {
Check_DisplayBackRing_Amy(a1);
if (CurrentMission < Mission2_100Rings && CurrentStageVersion != KnucklesVersion)
{
ObjectFunc(origin, Balloon_Load_T->Target());
origin(a1);
}
}
Trampoline CasinoEmerald_Load_T(0x5dd0a0, 0x5dd0a6, CheckLoadCasinoEmerald_r);
//Check the current mission and replace the capsule with a different object.
void __cdecl CheckLoadCasinoEmerald_r(ObjectMaster* a1) {
if (CurrentMission < Mission2_100Rings && (CurrentCharacter == Characters_Amy || CurrentCharacter == Characters_Big))
{
Check_Display_Frog_Balloon(a1);
return;
}
if (CurrentMission >= Mission2_100Rings)
{
Check_Display_BackRing_Common(a1);
return;
}
if (Race && !isAIActive && CurrentMission < Mission2_100Rings)
RaceResultCheck(a1);
//call original function (Emerald.)
if (CurrentStageVersion != KnucklesVersion) {
ObjectFunc(origin, CasinoEmerald_Load_T.Target());
origin(a1);
}
}
Trampoline WVEmerald_Load_T(0x4df3b0, 0x4df3b6, CheckLoadWVEmerald_r);
//Check the current mission and replace the capsule with a different object.
void __cdecl CheckLoadWVEmerald_r(ObjectMaster* a1) {
if (CurrentMission < Mission2_100Rings && (CurrentCharacter == Characters_Amy || CurrentCharacter == Characters_Big))
{
Check_Display_Frog_Balloon(a1);
return;
}
if (CurrentMission >= Mission2_100Rings)
{
Check_Display_BackRing_Common(a1);
return;
}
if (Race && !isAIActive && CurrentMission < Mission2_100Rings)
RaceResultCheck(a1);
//call original function (Emerald.)
ObjectFunc(origin, WVEmerald_Load_T.Target());
origin(a1);
}
Trampoline ICEmerald_Load_T(0x4ecfa0, 0x4ecfa6, CheckLoadICEmerald_r);
//Check the current mission and replace the capsule with a different object.
void __cdecl CheckLoadICEmerald_r(ObjectMaster* a1) {
if (CurrentMission < Mission2_100Rings && (CurrentCharacter == Characters_Amy || CurrentCharacter == Characters_Big))
{
Check_Display_Frog_Balloon(a1);
return;
}
if (CurrentMission >= Mission2_100Rings)
{
Check_Display_BackRing_Common(a1);
return;
}
if (Race && !isAIActive && CurrentMission < Mission2_100Rings)
RaceResultCheck(a1);
//call original function (Emerald.)
ObjectFunc(origin, ICEmerald_Load_T.Target());
origin(a1);
}
Trampoline CheckLoadTailsPlaneEC_t(0x4f9fb0, 0x4f9fb6, CheckLoadTailsPlaneEC_r);
void __cdecl CheckLoadTailsPlaneEC_r(ObjectMaster* a1) {
if (CurrentMission < Mission2_100Rings && (CurrentCharacter == Characters_Amy || CurrentCharacter == Characters_Big))
{
Check_Display_Frog_Balloon(a1);
return;
}
if (CurrentMission >= Mission2_100Rings)
{
Check_Display_BackRing_Common(a1);
return;
}
//call original function
ObjectFunc(origin, CheckLoadTailsPlaneEC_t.Target());
origin(a1);
}
Trampoline CheckLWTrigger_t(0x7b0da0, 0x7b0da6, CheckLWTrigger_r);
void __cdecl CheckLWTrigger_r(ObjectMaster* a1) {
if (CurrentMission < Mission2_100Rings && (CurrentCharacter == Characters_Amy || CurrentCharacter == Characters_Big))
{
Check_Display_Frog_Balloon(a1);
return;
}
if (CurrentMission >= Mission2_100Rings)
{
Check_Display_BackRing_Common(a1);
return;
}
//call original function
ObjectFunc(origin, CheckLWTrigger_t.Target());
origin(a1);
}
Trampoline CheckFETrigger_t(0x5b24f0, 0x5b24f6, CheckFETrigger_r);
void __cdecl CheckFETrigger_r(ObjectMaster* a1) {
if (CurrentMission < Mission2_100Rings && (CurrentCharacter == Characters_Amy || CurrentCharacter == Characters_Big))
{
Check_Display_Frog_Balloon(a1);
return;
}
if (CurrentMission >= Mission2_100Rings)
{
Check_Display_BackRing_Common(a1);
return;
}
//call original function
ObjectFunc(origin, CheckFETrigger_t.Target());
origin(a1);
}
void OTarget_R(ObjectMaster* obj) { //Sonic Doll Final Egg
if (CurrentMission < Mission2_100Rings) {
ObjectFunc(origin, OTarget_T->Target());
origin(obj);
}
}
void BackRing_CheckAndApply() {
if (GetBackRing && CurrentMission >= Mission2_100Rings)
{
Rings = RingCopy;
TimeSeconds = TimeSecCopy;
TimeMinutes = TimeMinCopy;
TimeFrames = TimeFrameCopy;
if (CurrentStageVersion == AmyVersion && CurrentLevel == LevelIDs_FinalEgg || CurrentStageVersion == TailsVersion)
Lives++;
ResetRestartData();
ResetGravity();
GameMode = GameModes_Adventure_ActionStg;
}
return;
}
void Set_BackRing() {
Capsule_Load_T = new Trampoline((int)Capsule_Load, (int)Capsule_Load + 0x7, CheckLoadCapsule_r);
Froggy_Load_T = new Trampoline((int)OFrog, (int)OFrog + 0x5, CheckLoadFroggy_r);
Froggy_Main_T = new Trampoline((int)Froggy_Main, (int)Froggy_Main + 0x5, CheckLoadBig_Froggy_r);
Balloon_Load_T = new Trampoline((int)Balloon_Main, (int)Balloon_Main + 0x6, CheckLoadBalloon_r);
OTarget_T = new Trampoline((int)OTarget, (int)OTarget + 0x5, OTarget_R);
WriteData((ObjectFuncPtr*)0x4FA050, CheckLoadCapsule_r); // crashed plane in Emerald Coast
WriteData((ObjectFuncPtr*)0x4DF3F0, CheckLoadCapsule_r); // Chaos Emerald in Windy Valley
WriteData((ObjectFuncPtr*)0x5DD0E0, CheckLoadCapsule_r); // Chaos Emerald in Casinopolis
WriteData((ObjectFuncPtr*)0x4ECFE0, CheckLoadCapsule_r); // Chaos Emerald in Ice Cap
WriteData((ObjectFuncPtr*)0x7B0DD3, CheckLoadCapsule_r); // ending of Lost World
WriteData((ObjectFuncPtr*)0x5B2523, CheckLoadCapsule_r); // ending of Final Egg
WriteJump(CheckDynamiteBroken, CheckDynamiteBroken_r);
}