Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-1-Sonic-2-2013-Script-Decompilation
Path: blob/master/Sonic 1/Scripts/Special/DebugMode.txt
1483 views
1
// ----------------------------------
2
// RSDK Project: Sonic 1
3
// Script Description: Debug Mode Object
4
// Script Author: Christian Whitehead/Simon Thomley
5
// Unpacked by Rubberduckycooly's script unpacker
6
// ----------------------------------
7
8
// ========================
9
// Aliases
10
// ========================
11
12
private alias object.value10 : object.currentSelection
13
14
15
// ========================
16
// Function Declarations
17
// ========================
18
19
reserve function DebugMode_PlaceBlock
20
reserve function DebugMode_DummySpawn
21
reserve function DebugMode_DummyDraw
22
reserve function DebugMode_RemoveObject
23
reserve function DebugMode_RemoveIconDraw
24
reserve function DebugMode_LoadLayout
25
reserve function DebugMode_LoadIconDraw
26
reserve function DebugMode_SaveLayout
27
reserve function DebugMode_SaveIconDraw
28
reserve function DebugMode_ClrAllObjects
29
reserve function DebugMode_ClrIconDraw
30
reserve function DebugMode_FindBlockPos
31
32
33
// ========================
34
// Static Values
35
// ========================
36
37
public value DebugMode_ObjCount = 0
38
39
40
// ========================
41
// Tables
42
// ========================
43
44
// Three tables, to hold info about an object
45
// If an object is added to one table, it should be added to all the other three too
46
47
// Holds all the object types
48
public table DebugMode_TypeTable[64]
49
50
// Holds all the object Debug Draw functions
51
public table DebugMode_DrawTable[64]
52
53
// Holds all the object Debug Spawn functions
54
public table DebugMode_SpawnTable[64]
55
56
57
// ========================
58
// Function Definitions
59
// ========================
60
61
// Shared by several functions to place (or remove) an object
62
public function DebugMode_PlaceBlock
63
temp0 = 0
64
65
// Loop through all objects
66
arrayPos0 = 0x20
67
while arrayPos0 < 0x420
68
if object[arrayPos0].type == TypeName[Blank Object]
69
temp0 = arrayPos0
70
end if
71
72
if temp6 == object[arrayPos0].xpos
73
if temp7 == object[arrayPos0].ypos
74
temp0 = arrayPos0
75
arrayPos0 = 0x420
76
end if
77
end if
78
arrayPos0++
79
loop
80
81
if temp0 != 0
82
arrayPos0 = temp0
83
ResetObjectEntity(temp0, temp5, temp4, temp6, temp7)
84
else
85
CreateTempObject(temp5, temp4, temp6, temp7)
86
arrayPos0 = object[tempObjectPos].entityPos
87
end if
88
end function
89
90
91
public function DebugMode_DummySpawn
92
temp0 = 0
93
end function
94
95
96
public function DebugMode_DummyDraw
97
DrawSprite(0)
98
end function
99
100
101
public function DebugMode_RemoveObject
102
// Somewhat confusing, what it does here is places a blank object, which deletes the obj "under" it
103
temp5 = TypeName[Blank Object]
104
temp4 = 0
105
CallFunction(DebugMode_PlaceBlock)
106
end function
107
108
109
public function DebugMode_RemoveIconDraw
110
DrawSprite(2)
111
end function
112
113
114
public function DebugMode_LoadLayout
115
ReadSaveRAM()
116
117
arrayPos0 = 32
118
arrayPos1 = 0x800
119
while arrayPos0 < 0x420
120
temp0 = saveRAM[arrayPos1]
121
temp0 &= 255
122
temp1 = saveRAM[arrayPos1]
123
temp1 >>= 8
124
arrayPos1++
125
temp2 = saveRAM[arrayPos1]
126
temp2 &= 0x7FF
127
temp2 *= 0x180000
128
temp2 += 0xC0000
129
temp3 = saveRAM[arrayPos1]
130
temp3 >>= 11
131
temp3 *= 0x180000
132
temp3 += 0xC0000
133
ResetObjectEntity(arrayPos0, temp0, temp1, temp2, temp3)
134
arrayPos1++
135
arrayPos0++
136
loop
137
end function
138
139
140
public function DebugMode_LoadIconDraw
141
DrawSprite(3)
142
end function
143
144
145
public function DebugMode_SaveLayout
146
arrayPos0 = 32
147
arrayPos1 = 0x800
148
while arrayPos0 < 0x420
149
temp2 = object[arrayPos0].propertyValue
150
temp2 <<= 8
151
temp2 += object[arrayPos0].type
152
saveRAM[arrayPos1] = temp2
153
arrayPos1++
154
temp0 = object[arrayPos0].xpos
155
temp0 /= 0x180000
156
temp1 = object[arrayPos0].ypos
157
temp1 /= 0x180000
158
if temp0 < 0
159
temp0 -= 0x180000
160
end if
161
if temp1 < 0
162
temp1 -= 0x180000
163
end if
164
temp1 <<= 11
165
temp0 += temp1
166
saveRAM[arrayPos1] = temp0
167
arrayPos1++
168
arrayPos0++
169
loop
170
171
WriteSaveRAM()
172
end function
173
174
175
public function DebugMode_SaveIconDraw
176
DrawSprite(4)
177
end function
178
179
180
public function DebugMode_ClrAllObjects
181
temp0 = 0
182
183
// Loop through all objects and delete them
184
arrayPos0 = 0x20
185
while arrayPos0 < 0x420
186
ResetObjectEntity(arrayPos0, TypeName[Blank Object], 0, 0, 0)
187
arrayPos0++
188
loop
189
end function
190
191
192
public function DebugMode_ClrIconDraw
193
DrawSprite(5)
194
end function
195
196
197
public function DebugMode_FindBlockPos
198
// Called by most Special Stage objects, in order to find their position based on the stage's current rotation
199
// Along with finding position, it also finds the block's angle
200
201
temp2 = temp6
202
temp2 -= object[0].xpos
203
temp2 >>= 8
204
205
temp3 = temp7
206
temp3 -= object[0].ypos
207
temp3 >>= 8
208
209
Sin(temp4, Player_stageRotation)
210
211
temp4 *= temp3
212
Cos(temp5, Player_stageRotation)
213
214
temp5 *= temp2
215
temp0 = temp4
216
temp0 += temp5
217
temp0 >>= 1
218
temp0 += object[0].xpos
219
Cos(temp4, Player_stageRotation)
220
221
temp4 *= temp3
222
Sin(temp5, Player_stageRotation)
223
224
temp5 *= temp2
225
temp1 = temp4
226
temp1 -= temp5
227
temp1 >>= 1
228
temp1 += object[0].ypos
229
230
object.rotation = 512
231
object.rotation -= Player_stageRotation
232
end function
233
234
235
// ========================
236
// Events
237
// ========================
238
239
event ObjectUpdate
240
#platform: USE_STANDALONE
241
if options.touchControls == true
242
if object.controlMode == CONTROLMODE_P1
243
CheckTouchRect(0, 96, screen.xcenter, screen.ysize)
244
245
if checkResult > -1
246
arrayPos0 = checkResult
247
temp0 = touchscreen[arrayPos0].xpos
248
temp0 -= saveRAM[39]
249
temp1 = touchscreen[arrayPos0].ypos
250
temp1 -= saveRAM[40]
251
252
ATan2(temp2, temp0, temp1)
253
temp2 += 32
254
temp2 &= 255
255
temp2 >>= 6
256
257
switch temp2
258
case 0
259
keyDown[0].right = true
260
break
261
262
case 1
263
keyDown[0].down = true
264
break
265
266
case 2
267
keyDown[0].left = true
268
break
269
270
case 3
271
keyDown[0].up = true
272
break
273
end switch
274
end if
275
276
temp0 = screen.xcenter
277
temp0 -= 48
278
279
temp1 = temp0
280
temp1 += 96
281
282
CheckTouchRect(temp0, 0, temp1, 56)
283
284
if checkResult > -1
285
arrayPos0 = checkResult
286
287
if touchscreen[arrayPos0].xpos > screen.xcenter
288
if touchJump == false
289
object.currentSelection++
290
if object.currentSelection >= DebugMode_ObjCount
291
object.currentSelection = 0
292
end if
293
end if
294
295
touchJump = true
296
else
297
if touchJump == false
298
object.currentSelection--
299
if object.currentSelection < 0
300
object.currentSelection += DebugMode_ObjCount
301
end if
302
end if
303
304
touchJump = true
305
end if
306
else
307
CheckTouchRect(screen.xcenter, 96, screen.xsize, 240)
308
309
switch checkResult
310
case -1
311
touchJump = false
312
break
313
314
case 0
315
keyDown[0].buttonC = true
316
if touchJump == 0
317
keyPress[0].buttonC |= keyDown[0].buttonC
318
end if
319
320
touchJump = keyDown[0].buttonC
321
break
322
end switch
323
end if
324
325
CheckTouchRect(0, 0, 112, 56)
326
327
if checkResult > -1
328
keyDown[0].buttonB = true
329
end if
330
331
if touchDebug == false
332
keyPress[0].buttonB |= keyDown[0].buttonB
333
end if
334
335
touchDebug = keyDown[0].buttonB
336
temp0 = screen.xsize
337
temp0 -= 88
338
339
CheckTouchRect(temp0, 0, screen.xsize, 40)
340
341
if checkResult > -1
342
PlaySfx(SfxName[Menu Back], false)
343
engine.state = 5
344
end if
345
346
if keyPress[0].start == true
347
PlaySfx(SfxName[Menu Back], false)
348
engine.state = 5
349
end if
350
end if
351
end if
352
#endplatform
353
354
temp0 = false
355
if keyDown[0].left == true
356
object.xpos -= object.yvel
357
temp0 = true
358
end if
359
360
if keyDown[0].right == true
361
object.xpos += object.yvel
362
temp0 = true
363
end if
364
365
if keyDown[0].up == true
366
object.ypos -= object.yvel
367
temp0 = true
368
end if
369
370
if keyDown[0].down == true
371
object.ypos += object.yvel
372
temp0 = true
373
end if
374
375
if temp0 == true
376
object.yvel += 0xC00
377
if object.yvel > 0x100000
378
object.yvel = 0x100000
379
end if
380
else
381
object.yvel = 0
382
end if
383
384
if keyPress[0].buttonB == true
385
object.type = TypeName[Player Object]
386
if stage.playerListPos == PLAYER_TAILS_A
387
object[+1].type = TypeName[Tails Object]
388
end if
389
object.speed = 0
390
object.xvel = 0
391
object.yvel = 0
392
object.frame = 0
393
object.controlMode = CONTROLMODE_P1
394
object.interaction = true
395
Player_rotateSpeed = 0
396
Player_rotateDir = 0
397
else
398
// Sonic Team forgot you can spawn 1UPs in special stages, so there's no checks for them in Origins, farm coins to your heart's content!
399
400
if keyPress[0].buttonA == true
401
object.currentSelection++
402
if object.currentSelection >= DebugMode_ObjCount
403
object.currentSelection = 0
404
end if
405
end if
406
407
if keyDown[0].buttonA == true
408
if keyPress[0].buttonC == true
409
object.currentSelection--
410
if object.currentSelection < 0
411
object.currentSelection += DebugMode_ObjCount
412
end if
413
end if
414
else
415
if keyPress[0].buttonC == true
416
GetTableValue(temp0, object.currentSelection, DebugMode_SpawnTable)
417
CallFunction(temp0)
418
object[tempObjectPos].priority = PRIORITY_XBOUNDS_DESTROY
419
end if
420
end if
421
end if
422
end event
423
424
425
event ObjectDraw
426
temp6 = object.xpos
427
temp7 = object.ypos
428
if temp6 < 0
429
temp6 -= 0x180000
430
end if
431
if temp7 < 0
432
temp7 -= 0x180000
433
end if
434
temp6 /= 0x180000
435
temp7 /= 0x180000
436
temp6 *= 0x180000
437
temp7 *= 0x180000
438
temp6 += 0xC0000
439
temp7 += 0xC0000
440
CallFunction(DebugMode_FindBlockPos)
441
DrawSpriteXY(1, temp0, temp1)
442
443
// Temporarily switch to the selected object in order to draw the preview
444
GetTableValue(object.type, object.currentSelection, DebugMode_TypeTable)
445
GetTableValue(temp0, object.currentSelection, DebugMode_DrawTable)
446
CallFunction(temp0)
447
448
// Switch back
449
object.type = TypeName[Debug Mode]
450
451
// +/-
452
DrawSpriteScreenXY(6, screen.xcenter, 16)
453
DrawSpriteScreenXY(7, screen.xcenter, 16)
454
end event
455
456
457
event ObjectStartup
458
LoadSpriteSheet("Special/Objects.gif")
459
460
// Editor sprite frames
461
SpriteFrame(-12, -12, 24, 24, 251, 176) // life icon - #0
462
SpriteFrame(-12, -12, 24, 24, 131, 454) // selection box - #1
463
SpriteFrame(-12, -12, 24, 24, 131, 479) // delete icon - #2
464
SpriteFrame(-12, -12, 24, 24, 455, 486) // load icon - #3
465
SpriteFrame(-12, -12, 24, 24, 480, 486) // save icon - #4
466
SpriteFrame(-12, -12, 24, 24, 308, 376) // clear icon - #5
467
SpriteFrame(-16, 0, 8, 8, 339, 390) // - icon - #6
468
SpriteFrame(8, 0, 8, 8, 348, 390) // + icon - #7
469
470
DebugMode_ObjCount = 0
471
472
// Fill the list up with dummy entries
473
temp0 = 0
474
while temp0 < 64
475
SetTableValue(TypeName[Debug Mode], temp0, DebugMode_TypeTable)
476
SetTableValue(DebugMode_DummyDraw, temp0, DebugMode_DrawTable)
477
SetTableValue(DebugMode_DummySpawn, temp0, DebugMode_SpawnTable)
478
temp0++
479
loop
480
481
// Add the object deleter as an entry
482
SetTableValue(TypeName[Debug Mode], temp0, DebugMode_TypeTable)
483
SetTableValue(DebugMode_RemoveIconDraw, DebugMode_ObjCount, DebugMode_DrawTable)
484
SetTableValue(DebugMode_RemoveObject, DebugMode_ObjCount, DebugMode_SpawnTable)
485
DebugMode_ObjCount++
486
487
// Is the player in the custom special stage bulder scene?
488
if stage.actNum == 8
489
// Load saved stage
490
SetTableValue(TypeName[Debug Mode], temp0, DebugMode_TypeTable)
491
SetTableValue(DebugMode_LoadIconDraw, DebugMode_ObjCount, DebugMode_DrawTable)
492
SetTableValue(DebugMode_LoadLayout, DebugMode_ObjCount, DebugMode_SpawnTable)
493
DebugMode_ObjCount++
494
495
// Save current stage
496
SetTableValue(TypeName[Debug Mode], temp0, DebugMode_TypeTable)
497
SetTableValue(DebugMode_SaveIconDraw, DebugMode_ObjCount, DebugMode_DrawTable)
498
SetTableValue(DebugMode_SaveLayout, DebugMode_ObjCount, DebugMode_SpawnTable)
499
DebugMode_ObjCount++
500
501
// Clear current stage
502
SetTableValue(TypeName[Debug Mode], temp0, DebugMode_TypeTable)
503
SetTableValue(DebugMode_ClrIconDraw, DebugMode_ObjCount, DebugMode_DrawTable)
504
SetTableValue(DebugMode_ClrAllObjects, DebugMode_ObjCount, DebugMode_SpawnTable)
505
DebugMode_ObjCount++
506
end if
507
end event
508
509
510
// ========================
511
// Editor Events
512
// ========================
513
514
event RSDKDraw
515
DrawSprite(0)
516
end event
517
518
519
event RSDKLoad
520
LoadSpriteSheet("Global/Display.gif")
521
SpriteFrame(-16, -16, 32, 32, 1, 143)
522
523
SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
524
end event
525
526