Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/Title/TitleSetup.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: TitleSetup Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectTitleSetup *TitleSetup;
11
12
void TitleSetup_Update(void)
13
{
14
RSDK_THIS(TitleSetup);
15
16
StateMachine_Run(self->state);
17
18
ScreenInfo->position.x = 0x100 - ScreenInfo->center.x;
19
}
20
21
void TitleSetup_LateUpdate(void) {}
22
23
void TitleSetup_StaticUpdate(void) {}
24
25
void TitleSetup_Draw(void)
26
{
27
RSDK_THIS(TitleSetup);
28
29
StateMachine_Run(self->stateDraw);
30
}
31
32
void TitleSetup_Create(void *data)
33
{
34
RSDK_THIS(TitleSetup);
35
36
if (!SceneInfo->inEditor) {
37
RSDK.SetSpriteAnimation(TitleSetup->aniFrames, 0, &self->animator, true, 0);
38
39
self->active = ACTIVE_ALWAYS;
40
self->visible = true;
41
self->drawGroup = 12;
42
self->drawFX = FX_FLIP;
43
self->state = TitleSetup_State_Wait;
44
self->stateDraw = TitleSetup_Draw_FadeBlack;
45
self->timer = 1024;
46
self->drawPos.x = 256 << 16;
47
self->drawPos.y = 108 << 16;
48
}
49
}
50
51
void TitleSetup_StageLoad(void)
52
{
53
String presence;
54
Localization_GetString(&presence, STR_RPC_TITLE);
55
API_SetRichPresence(PRESENCE_TITLE, &presence);
56
57
API_SetNoSave(false);
58
59
globals->blueSpheresInit = false;
60
TimeAttackData_Clear();
61
62
API_ClearPrerollErrors();
63
#if MANIA_USE_PLUS
64
API.ClearSaveStatus();
65
#endif
66
67
globals->saveLoaded = false;
68
memset(globals->saveRAM, 0, sizeof(globals->saveRAM));
69
70
globals->optionsLoaded = false;
71
memset(globals->optionsRAM, 0, sizeof(globals->optionsRAM));
72
73
#if MANIA_USE_PLUS
74
API.ClearUserDB(globals->replayTableID);
75
API.ClearUserDB(globals->taTableID);
76
77
globals->replayTableID = (uint16)-1;
78
globals->replayTableLoaded = STATUS_NONE;
79
globals->taTableID = (uint16)-1;
80
globals->taTableLoaded = STATUS_NONE;
81
#endif
82
83
TitleSetup->aniFrames = RSDK.LoadSpriteAnimation("Title/Electricity.bin", SCOPE_STAGE);
84
85
TitleSetup->sfxMenuBleep = RSDK.GetSfx("Global/MenuBleep.wav");
86
TitleSetup->sfxMenuAccept = RSDK.GetSfx("Global/MenuAccept.wav");
87
TitleSetup->sfxRing = RSDK.GetSfx("Global/Ring.wav");
88
89
RSDK.ResetEntitySlot(0, TitleSetup->classID, NULL);
90
}
91
92
#if MANIA_USE_PLUS
93
void TitleSetup_HandleCheatInputs(void)
94
{
95
uint8 keyState = 0;
96
if (ControllerInfo->keyUp.press || AnalogStickInfoL->keyUp.press)
97
keyState = 1;
98
if (ControllerInfo->keyDown.press || AnalogStickInfoL->keyDown.press)
99
keyState = 2;
100
101
if (keyState) {
102
TitleSetup->cheatCode[0] = TitleSetup->cheatCode[1];
103
TitleSetup->cheatCode[1] = TitleSetup->cheatCode[2];
104
TitleSetup->cheatCode[2] = TitleSetup->cheatCode[3];
105
TitleSetup->cheatCode[3] = TitleSetup->cheatCode[4];
106
TitleSetup->cheatCode[4] = TitleSetup->cheatCode[5];
107
TitleSetup->cheatCode[5] = TitleSetup->cheatCode[6];
108
TitleSetup->cheatCode[6] = TitleSetup->cheatCode[7];
109
TitleSetup->cheatCode[7] = keyState;
110
}
111
}
112
113
void TitleSetup_CheckCheatCode(void)
114
{
115
TitleSetup_HandleCheatInputs();
116
117
if (TitleSetup->cheatCode[0] == 1 && TitleSetup->cheatCode[1] == 1 && TitleSetup->cheatCode[2] == 2 && TitleSetup->cheatCode[3] == 2
118
&& TitleSetup->cheatCode[4] == 1 && TitleSetup->cheatCode[5] == 1 && TitleSetup->cheatCode[6] == 1 && TitleSetup->cheatCode[7] == 1) {
119
if (!globals->superSecret) {
120
RSDK.PlaySfx(TitleSetup->sfxRing, false, 255);
121
globals->superSecret = true;
122
}
123
}
124
}
125
#endif
126
127
bool32 TitleSetup_VideoSkipCB(void)
128
{
129
if (ControllerInfo->keyA.press || ControllerInfo->keyB.press || ControllerInfo->keyStart.press) {
130
Music_Stop();
131
return true;
132
}
133
134
return false;
135
}
136
137
void TitleSetup_State_Wait(void)
138
{
139
RSDK_THIS(TitleSetup);
140
141
if (self->timer <= -0x400) {
142
self->timer = 0;
143
self->state = TitleSetup_State_AnimateUntilFlash;
144
self->stateDraw = TitleSetup_Draw_DrawRing;
145
Music_PlayTrack(TRACK_STAGE);
146
}
147
else {
148
self->timer -= 16;
149
}
150
}
151
152
void TitleSetup_State_AnimateUntilFlash(void)
153
{
154
RSDK_THIS(TitleSetup);
155
156
RSDK.ProcessAnimation(&self->animator);
157
158
if (self->animator.frameID == 31) {
159
foreach_all(TitleLogo, titleLogo)
160
{
161
if (titleLogo->type >= TITLELOGO_EMBLEM) {
162
if (titleLogo->type <= TITLELOGO_RIBBON) {
163
titleLogo->active = ACTIVE_NORMAL;
164
titleLogo->visible = true;
165
}
166
else if (titleLogo->type == TITLELOGO_POWERLED) {
167
destroyEntity(titleLogo);
168
}
169
}
170
}
171
172
self->state = TitleSetup_State_FlashIn;
173
}
174
}
175
176
void TitleSetup_State_FlashIn(void)
177
{
178
RSDK_THIS(TitleSetup);
179
180
RSDK.ProcessAnimation(&self->animator);
181
if (self->animator.frameID == self->animator.frameCount - 1) {
182
foreach_all(TitleLogo, titleLogo)
183
{
184
#if MANIA_USE_PLUS
185
if (titleLogo->type == TITLELOGO_PLUS) {
186
titleLogo->position.y -= 0x200000;
187
}
188
else if (titleLogo->type != TITLELOGO_PRESSSTART) {
189
#else
190
if (titleLogo->type != TITLELOGO_PRESSSTART) {
191
#endif
192
titleLogo->active = ACTIVE_NORMAL;
193
titleLogo->visible = true;
194
}
195
196
if (titleLogo->type == TITLELOGO_RIBBON) {
197
titleLogo->showRibbonCenter = true;
198
RSDK.SetSpriteAnimation(TitleLogo->aniFrames, 2, &titleLogo->mainAnimator, true, 0);
199
}
200
}
201
202
foreach_all(TitleSonic, titleSonic)
203
{
204
titleSonic->active = ACTIVE_NORMAL;
205
titleSonic->visible = true;
206
}
207
208
TitleBG_SetupFX();
209
self->timer = 0x300;
210
self->state = TitleSetup_State_WaitForSonic;
211
self->stateDraw = TitleSetup_Draw_Flash;
212
}
213
}
214
215
void TitleSetup_State_WaitForSonic(void)
216
{
217
RSDK_THIS(TitleSetup);
218
219
#if MANIA_USE_PLUS
220
TitleSetup_CheckCheatCode();
221
#endif
222
223
if (self->timer <= 0) {
224
self->stateDraw = StateMachine_None;
225
226
#if MANIA_USE_PLUS
227
if (API.CheckDLC(DLC_PLUS))
228
self->state = TitleSetup_State_SetupPlusLogo;
229
else
230
#endif
231
self->state = TitleSetup_State_SetupLogo;
232
}
233
else {
234
self->timer -= 16;
235
}
236
}
237
238
void TitleSetup_State_SetupLogo(void)
239
{
240
RSDK_THIS(TitleSetup);
241
242
#if MANIA_USE_PLUS
243
if (self->timer < 120)
244
TitleSetup_CheckCheatCode();
245
#endif
246
247
if (++self->timer == 120) {
248
foreach_all(TitleLogo, titleLogo)
249
{
250
if (titleLogo->type == TITLELOGO_PRESSSTART) {
251
titleLogo->active = ACTIVE_NORMAL;
252
titleLogo->visible = true;
253
254
#if MANIA_USE_PLUS
255
Entity *store = SceneInfo->entity;
256
SceneInfo->entity = (Entity *)titleLogo;
257
TitleLogo_SetupPressStart();
258
SceneInfo->entity = store;
259
#endif
260
}
261
}
262
263
self->timer = 0;
264
self->state = TitleSetup_State_WaitForEnter;
265
}
266
}
267
#if MANIA_USE_PLUS
268
void TitleSetup_State_SetupPlusLogo(void)
269
{
270
RSDK_THIS(TitleSetup);
271
272
if (self->timer < 120)
273
TitleSetup_CheckCheatCode();
274
275
if (++self->timer == 120) {
276
foreach_all(TitleLogo, titleLogo)
277
{
278
switch (titleLogo->type) {
279
case TITLELOGO_RIBBON:
280
case TITLELOGO_GAMETITLE:
281
titleLogo->storeY = titleLogo->position.y - 0x70000;
282
titleLogo->velocity.y = -0x30000;
283
titleLogo->timer = 2;
284
titleLogo->state = TitleLogo_State_HandleSetup;
285
286
RSDK.PlaySfx(TitleLogo->sfxPlus, false, 255);
287
break;
288
289
case TITLELOGO_PRESSSTART: titleLogo->position.y += 0x80000; break;
290
291
case TITLELOGO_PLUS:
292
titleLogo->active = ACTIVE_NORMAL;
293
titleLogo->visible = true;
294
titleLogo->timer = 2;
295
titleLogo->position.y -= 0x40000;
296
titleLogo->state = TitleLogo_State_HandleSetup;
297
break;
298
299
default: break;
300
}
301
}
302
303
CREATE_ENTITY(TitleEggman, NULL, 0, 0xC00000);
304
self->timer = 0;
305
self->state = TitleSetup_State_SetupLogo;
306
}
307
}
308
#endif
309
310
void TitleSetup_State_WaitForEnter(void)
311
{
312
RSDK_THIS(TitleSetup);
313
314
bool32 anyButton = ControllerInfo->keyA.press || ControllerInfo->keyB.press || ControllerInfo->keyC.press || ControllerInfo->keyX.press
315
|| ControllerInfo->keyY.press || ControllerInfo->keyZ.press || ControllerInfo->keyStart.press
316
|| ControllerInfo->keySelect.press;
317
318
bool32 anyClick = (!TouchInfo->count && self->touched) || Unknown_anyKeyPress;
319
self->touched = TouchInfo->count > 0;
320
321
if (anyClick || anyButton) {
322
RSDK.PlaySfx(TitleSetup->sfxMenuAccept, false, 0xFF);
323
self->timer = 0;
324
325
const char *nextScene = "Menu";
326
// Switch 1.0 dev level select cheat (Skips all the funky API setup stuff the menu does, so it was known for causin a bunch of issues)
327
#if GAME_VERSION == VER_100
328
if (ControllerInfo->keyA.down && (ControllerInfo->keyX.down || ControllerInfo->keyC.down))
329
nextScene = "Level Select";
330
#endif
331
RSDK.SetScene("Presentation", nextScene);
332
333
#if MANIA_USE_PLUS
334
int32 id = API_GetFilteredInputDeviceID(false, false, 5);
335
#else
336
int32 id = API_GetFilteredInputDeviceID(INPUT_NONE);
337
#endif
338
API_ResetInputSlotAssignments();
339
API_AssignInputSlotToDevice(CONT_P1, id);
340
341
Music_Stop();
342
self->state = TitleSetup_State_FadeToMenu;
343
self->stateDraw = TitleSetup_Draw_FadeBlack;
344
}
345
else if (++self->timer == 800) {
346
self->timer = 0;
347
self->state = TitleSetup_State_FadeToVideo;
348
self->stateDraw = TitleSetup_Draw_FadeBlack;
349
}
350
}
351
352
void TitleSetup_State_FadeToMenu(void)
353
{
354
RSDK_THIS(TitleSetup);
355
356
if (self->timer >= 1024)
357
RSDK.LoadScene();
358
else
359
self->timer += 8;
360
}
361
362
void TitleSetup_State_FadeToVideo(void)
363
{
364
RSDK_THIS(TitleSetup);
365
366
if (self->timer >= 1024) {
367
RSDK.LoadScene();
368
Music_Stop();
369
370
if (TitleSetup->useAltIntroMusic) {
371
RSDK.PlayStream("IntroTee.ogg", Music->channelID, 0, 0, false);
372
RSDK.LoadVideo("Mania.ogv", 1.8, TitleSetup_VideoSkipCB);
373
TitleSetup->useAltIntroMusic = false;
374
}
375
else {
376
RSDK.PlayStream("IntroHP.ogg", Music->channelID, 0, 0, false);
377
RSDK.LoadVideo("Mania.ogv", 0, TitleSetup_VideoSkipCB);
378
TitleSetup->useAltIntroMusic = true;
379
}
380
}
381
else {
382
self->timer += 8;
383
}
384
}
385
386
void TitleSetup_Draw_FadeBlack(void)
387
{
388
RSDK_THIS(TitleSetup);
389
390
RSDK.FillScreen(0x000000, self->timer, self->timer - 128, self->timer - 256);
391
}
392
393
void TitleSetup_Draw_DrawRing(void)
394
{
395
RSDK_THIS(TitleSetup);
396
397
self->direction = FLIP_NONE;
398
RSDK.DrawSprite(&self->animator, &self->drawPos, false);
399
400
self->direction = FLIP_X;
401
RSDK.DrawSprite(&self->animator, &self->drawPos, false);
402
}
403
404
void TitleSetup_Draw_Flash(void)
405
{
406
RSDK_THIS(TitleSetup);
407
408
RSDK.FillScreen(0xF0F0F0, self->timer, self->timer - 128, self->timer - 256);
409
}
410
411
#if GAME_INCLUDE_EDITOR
412
void TitleSetup_EditorDraw(void) {}
413
414
void TitleSetup_EditorLoad(void) {}
415
#endif
416
417
void TitleSetup_Serialize(void) {}
418
419