Spyro 1 Reverse Engineering
Decompilation of functions from Spyro 1 into human readable C
 
Loading...
Searching...
No Matches
common.h
Go to the documentation of this file.
1#ifndef COMMON_H
2#define COMMON_H
3
4#include "custom_types.h"
5#include "vector.h"
6
7//~~~~~~~~~~~~~~~~~~~~~~~~
8//Constants/Magic Numbers
9//~~~~~~~~~~~~~~~~~~~~~~~~
10
11#define SCREEN_LEFT_EDGE 0x0
12#define SCREEN_RIGHT_EDGE 0x200
13#define SCREEN_TOP_EDGE 0x0
14#define SCREEN_BOTTOM_EDGE 0xE8
15
16#define FPS 30
17
18#define WORLD_UNIT 4096
19#define GAME_UNIT 64
20
21typedef enum Direction
22{
24 RIGHT
26
27typedef enum Buttons
28{
29 X_BUTTON = 0x0040,
30 SQUARE_BUTTON = 0x0080,
31 CIRCLE_BUTTON = 0x0020,
33
34 UP_BUTTON = 0x1000,
35 RIGHT_BUTTON = 0x2000,
36 DOWN_BUTTON = 0x4000,
37 LEFT_BUTTON = 0x8000,
38
39 SELECT_BUTTON = 0x0100,
40 START_BUTTON = 0x0800,
41
42 R1_BUTTON = 0x0008,
43 L1_BUTTON = 0x0004,
44 R2_BUTTON = 0x0002,
45 L2_BUTTON = 0x0001,
46
47 L3_BUTTON = 0x0200,
48 R3_BUTTON = 0x0400
50
51typedef enum GameState
52{
70
72{
76 NO_SPARX = 0
78
79typedef enum LevelIDS
80{
85 TOASTY_ID = 0xE,
87
92 SHEMP_ID = 0x18,
94
101
108
115
120 GNASTYS_LOOT_ID = 0x40
122
124{
132
134{
140
142
144{
150
152{
161
163
164
166{
167 FACING_LEFT = 0xCA6C,
168 FACING_RIGHT = 0xCA3C,
171 FACING_DIAGONAL = 0xCA9C, // wizard peak specific
172 RETURNING_HOME = 0xCA54
174
175
176//~~~~~~~
177//Structs
178//~~~~~~~
179
180typedef struct RECT
181{
182 short x, y, w, h;
183}RECT;
184
185typedef struct RGBA_u8
186{
187 unsigned char R;
188 unsigned char G;
189 unsigned char B;
190 unsigned char opacity;
191}RGBA_u8;
192
193typedef struct RGB_u8
194{
195 unsigned char R;
196 unsigned char G;
197 unsigned char B;
198}RGB_u8;
199
200typedef struct BGR_u8
201{
202 unsigned char B;
203 unsigned char G;
204 unsigned char R;
205}BGR_u8;
206
207
208//*~~~~~~~~~~~~~~~~~~~~~~~~
209//* SYMBOLS
210//*~~~~~~~~~~~~~~~~~~~~~~~~
211
212
213
214//*~~~~~~~~~~~~~~~~~~
215//*In game Functions
216//*~~~~~~~~~~~~~~~~~~
217
222int printf (const char * format, ...);
223int sprintf(char *output, const char *format, ...);
224void memset(void *str, int c, int n);
225int rand();
226void srand(int seed); // end of psyq_functions
228
229
234void Maybe_ArrayCopy(int *outputArray,int *inputArray,int arrayLength); //? This function copies one array to another
235
240
245
251
255void PrimitiveAlphaHack(void* param_1, int param_2, int param_3, short colorSpace, int param_5);
256
258
268void DrawLine(int point1X, int point1Y, int point2X, int point2Y); //? This function draws a yellow line.
269
270void FillScreenColor(int colorSpace, char r, char g, char b); //? Fills the screen with a specific color.
271
272void PlayIntroCutscenes(); //? This function is related to the intro cutscenes.
273
274void TheAdventureBegins(); //? This function calls the "The Adventure Begins" start sequence in the game.
276
278
279void Vec3IntToShortDiv4(short *Vec3ShortPTR,int *Vec3PTR); //? This function takes an int vector, divides it by 4, then stores it as a short. Some things in spyro need to refer to position as a short rather than an int, like particles, this is where you'd convert them.
280
281char* GetNextParticleSlot(char param_1); //? param_1 might be storing its subtype. It affects the way the particle looks ratio wise? It also stores the param value you pass into param_1 into the 1st element of the particle struct. NOT THE 0th.
282
283void CreateParticle(int param_1, int param_2, int **ptrToMoby, int *param_4); //? This function creates a particle. param_1 amount of particles, param_2 Is the Particle ID, param_3 is a Vec3 to its Initial Spawn Position, param_4 Vec3 of Amount of Units to Travel from Inital POS
284
285void UpdateMobyCollision(int param_1, unsigned int param_2); //? Research this more.
286
287int PlaySoundEffect(int soundEffectID, int ptrToMoby, int playbackMode, char *param_4);
288
298void PlayMusicTrack(int track_number, int flags);
299
300int LoadImageOrTexture(RECT *rect, int *p);
301
302int DrawSync(int mode);
303
304void Maybe_ResetHudTimers(void); // end of labeled_functions
306
307
308//*~~~~~~~~~~~~~~~~~
309//*In Game Variables
310//*~~~~~~~~~~~~~~~~~
316// Booleans
317
321extern bool _isPastTitleScreen;
322
326extern bool _isLoading;
327
331extern bool _isInsideOptionsMenu;
332
336extern bool _canFlyIn;
337
338// Timers
339
343extern int _globalTimer;
344
348extern int _pausedTimer;
349
353extern int _loadingTimer;
354
358extern int _levelTimerWhenActive;
359
363extern int _levelTimer_60fps;
364
368extern int _vSyncTimer_60fps;
369
373extern int _wobbleAndOpacityTimer;
374
375
376// Important Stuff
377
382extern int _gameState;
383
388extern unsigned short _currentButtonsHeld;
389
394extern unsigned short _currentButtonsPressed;
395
400extern int _secondController;
401
406extern int _movementSubState;
407
412extern int _isInPortal;
413
417extern short _globalGemCount;
418
422extern int _globalDragonCount;
423
427extern int _globalEggCount;
428
429
435extern int _levelID;
436
442extern char _portalToExitFromInHW;
443
448extern short _flyInAnimation;
449
454extern Vec3 _cameraPosition;
455
461
462extern short _cameraRotationMatrix[3][3];
463extern short _cameraPureRotationMatrix[3][3];
464
469extern short _sinArray[256];
470
474extern char _mainMenuState;
475
479extern int _balloonistState;
480
485extern int _startMenuSelection;
486
491extern int _inventoryMenuScreen;
492
496extern char _whichCutscene;
497
502extern char _effect_ScreenFadeIn;
503
508extern char _effect_ScreenLetterBox;
509
514extern char _collectablesStateFlags[1231];
515
519extern int* _ptr_levelMobys;
520
525extern int* _ptr_dynamicLevelMobys;
526
531extern int* _ptr_levelMobySpecialData;
532
533// #define _ptr_levelMobySpecialData _ptr_endDynamicMobys //0x80075930 //? Just giving it another name, since it also could be used to indicate the end of dynamic mobys, instead of just being used to indicate the start of levelMobyData.
534
535
536
537extern int* _ptr_primitivesArray; //0x800757b0 //? Not too sure.
538extern int* _ptr_arrayGraphicsRelatedPointers; //0x8007581c //? Ptr the the array of primitives structs to be drawn every frame
539extern int _ptrTextUnk; //0x800720f4 //? Not too sure.
540extern char* _ptr_hudMobys; //0x80075710 //? A pointer to a dynamic downwards growing array of moby structs to render that gets rendered to the hud every frame.
541
542extern char* _ptr_particleLinkedList; //0x80075738 //? This is a pointer to the next available particle slot.
543
544extern char _hudChestState; //0x80077FA8
545extern char _hudDragonState; //0x80077FA9
546extern char _hudLivesState; //0x80077FAA
547extern char _hudEggsState; //0x80077FAB
548extern char _hudAnimationState; //0x80077FAC
549
550extern int _hudElementsSpinTimer; //0x80077fe4
551extern int _unk_spinRelated; //0x8006cc78
552extern char* _localSoundEffects; //0x800761D4
553
558extern int _musicLevelTrack; //0x0x800774b0
559
560extern int* _maybe_ptr_levelTextureRelated; //0x800785f0
561
562extern byte _cdStatus; //0x80074e44 // end of labeled_global_variables
564
565#endif /* COMMON_H */
Buttons
Definition common.h:28
@ START_BUTTON
Definition common.h:40
@ SQUARE_BUTTON
Definition common.h:30
@ RIGHT_BUTTON
Definition common.h:35
@ UP_BUTTON
Definition common.h:34
@ X_BUTTON
Definition common.h:29
@ DOWN_BUTTON
Definition common.h:36
@ R3_BUTTON
Definition common.h:48
@ L2_BUTTON
Definition common.h:45
@ L3_BUTTON
Definition common.h:47
@ R2_BUTTON
Definition common.h:44
@ CIRCLE_BUTTON
Definition common.h:31
@ TRIANGLE_BUTTON
Definition common.h:32
@ SELECT_BUTTON
Definition common.h:39
@ LEFT_BUTTON
Definition common.h:37
@ L1_BUTTON
Definition common.h:43
@ R1_BUTTON
Definition common.h:42
Direction
Definition common.h:22
@ LEFT
Definition common.h:23
@ RIGHT
Definition common.h:24
LevelFlyInAnimations
Definition common.h:166
@ FACING_FORWARD
Definition common.h:169
@ FACING_LEFT
Definition common.h:167
@ FACING_DIAGONAL
Definition common.h:171
@ FACING_BACKWARDS
Definition common.h:170
@ FACING_RIGHT
Definition common.h:168
@ RETURNING_HOME
Definition common.h:172
LevelIDS
Definition common.h:80
@ GNASTYS_WORLD_ID
Definition common.h:116
@ GNASTY_GNORC_ID
Definition common.h:119
@ TOWN_SQUARE_ID
Definition common.h:83
@ WIZARD_PEAK_ID
Definition common.h:98
@ TOASTY_ID
Definition common.h:85
@ DARK_HALLOW_ID
Definition common.h:84
@ PEACE_KEEPERS_ID
Definition common.h:88
@ WILD_FLIGHT_ID
Definition common.h:107
@ STONE_HILL_ID
Definition common.h:82
@ ALPINE_RIDGE_ID
Definition common.h:96
@ HIGH_CAVES_ID
Definition common.h:97
@ GNASTYS_LOOT_ID
Definition common.h:120
@ TREE_TOPS_ID
Definition common.h:105
@ TERRACE_VILLAGE_ID
Definition common.h:103
@ CRYSTAL_FLIGHT_ID
Definition common.h:100
@ ICE_CAVERN_ID
Definition common.h:91
@ BLOWHARD_ID
Definition common.h:99
@ BEAST_MAKERS_ID
Definition common.h:102
@ METALHEAD_ID
Definition common.h:106
@ LOFTY_CASTLE_ID
Definition common.h:112
@ NIGHT_FLIGHT_ID
Definition common.h:93
@ JACQUES_ID
Definition common.h:113
@ SHEMP_ID
Definition common.h:92
@ DRY_CANYON_ID
Definition common.h:89
@ DARK_PASSAGE_ID
Definition common.h:111
@ CLIFF_TOWN_ID
Definition common.h:90
@ SUNNY_FLIGHT_ID
Definition common.h:86
@ HAUNTED_TOWERS_ID
Definition common.h:110
@ DREAM_WEAVERS_ID
Definition common.h:109
@ MAGIC_CRAFTERS_ID
Definition common.h:95
@ TWILIGHT_HARBOR_ID
Definition common.h:118
@ ICY_FLIGHT_ID
Definition common.h:114
@ GNORC_COVE_ID
Definition common.h:117
@ MISTY_BOG_ID
Definition common.h:104
@ ARTISANS_ID
Definition common.h:81
StartMenuSelections
Definition common.h:134
@ STARTMENU_QUIT_GAME
Definition common.h:139
@ STARTMENU_EXIT_LEVEL
Definition common.h:138
@ STARTMENU_INVENTORY
Definition common.h:137
@ STARTMENU_CONTINUE
Definition common.h:135
@ STARTMENU_OPTIONS
Definition common.h:136
InventoryMenuSelections
Definition common.h:124
@ BEAST_MAKERS_MENU
Definition common.h:128
@ PEACE_KEEPERS_MENU
Definition common.h:126
@ MAGIC_CRAFTERS_MENU
Definition common.h:127
@ DREAM_WEAVERS_MENU
Definition common.h:129
@ ARTISANS_MENU
Definition common.h:125
@ GNASTYS_WORLD_MENU
Definition common.h:130
GameState
Definition common.h:52
@ GAMESTATE_DRAGON_FAIRY_TEXTBOX
Definition common.h:64
@ GAMESTATE_BALLOONIST
Definition common.h:65
@ GAMESTATE_FLIGHT_LEVEL_MENU
Definition common.h:60
@ GAMESTATE_TITLE_SCREEN
Definition common.h:66
@ GAMESTATE_INVENTORY
Definition common.h:56
@ GAMESTATE_CREDITS
Definition common.h:68
@ GAMESTATE_GAME_OVER
Definition common.h:58
@ GAMESTATE_DRAGON_STATE
Definition common.h:61
@ GAMESTATE_BETA_DRAGON_TEXTBOX_MAYBE
Definition common.h:59
@ GAMESTATE_CUTSCENE
Definition common.h:67
@ GAMESTATE_LOADING
Definition common.h:54
@ GAMESTATE_DEATH
Definition common.h:57
@ GAMESTATE_FLY_IN
Definition common.h:62
@ GAMESTATE_GAMEPLAY
Definition common.h:53
@ GAMESTATE_PAUSED
Definition common.h:55
@ GAMESTATE_EXITING_LEVEL
Definition common.h:63
BalloonistStates
Definition common.h:152
@ BALLOONIST_STATE_JUMPING_OUT_OF_BALLOON
Definition common.h:160
@ BALLOONIST_STATE_JUMPING_ONTO_BALLOON
Definition common.h:155
@ BALLOONIST_STATE_BALLOON_LOADING_PART_2
Definition common.h:158
@ BALLOONIST_STATE_TEXTBOX
Definition common.h:154
@ BALLOONIST_STATE_BALLOON_LOADING_PART_1
Definition common.h:157
@ BALLOONIST_STATE_BALLOON_RISING
Definition common.h:156
@ BALLOONIST_STATE_NEVER_TALKED_TO_BALLOONIST
Definition common.h:153
@ BALLOONIST_STATE_BALLOON_LOWERING
Definition common.h:159
SpyroHealthStates
Definition common.h:72
@ YELLOW_SPARX
Definition common.h:73
@ NO_SPARX
Definition common.h:76
@ GREEN_SPARX
Definition common.h:75
@ BLUE_SPARX
Definition common.h:74
MovementSubStates
Definition common.h:144
@ MOVEMENT_SUBSTATE_FLY_IN_LOOP
Definition common.h:147
@ MOVEMENT_SUBSTATE_LOADING
Definition common.h:145
@ MOVEMENT_SUBSTATE_FLY_IN_CAMERA_180
Definition common.h:148
@ MOVEMENT_SUBSTATE_EXIT_PORTAL
Definition common.h:146
void CopyHudToShaded()
void RenderNormalMobys()
Renders normal moby objects in the world. (Enemies, Chests, Dragons, etc.) Address: 0x8001f798.
void Maybe_ArrayCopy(int *outputArray, int *inputArray, int arrayLength)
void UpdateMobyCollision(int param_1, unsigned int param_2)
void FillScreenColor(int colorSpace, char r, char g, char b)
void TheAdventureContinues()
void PlayMusicTrack(int track_number, int flags)
Plays/Continues a music track Address: 0x800567f4.
void PrimitiveAlphaHack(void *param_1, int param_2, int param_3, short colorSpace, int param_5)
This is a weird hack that seems to be related to transparency for primitaves? Address: 0x80060670.
void LockCameraToSpyro(void)
void RenderAllObjects()
Renders all objects in the world. (Enemies, Chests, Dragons, etc.) Address: 0x8001f798.
void RenderShadedMobys()
Renders shaded moby objects in the world. (Gems, HUD Elements, etc.) Address: 0x80022a2c.
void TheAdventureBegins()
char * GetNextParticleSlot(char param_1)
void PlayIntroCutscenes()
int LoadImageOrTexture(RECT *rect, int *p)
int DrawSync(int mode)
void Maybe_ResetHudTimers(void)
void DrawLine(int point1X, int point1Y, int point2X, int point2Y)
Draws a golden line to the screen Address: 0x8001844c.
void Vec3IntToShortDiv4(short *Vec3ShortPTR, int *Vec3PTR)
int PlaySoundEffect(int soundEffectID, int ptrToMoby, int playbackMode, char *param_4)
void CreateParticle(int param_1, int param_2, int **ptrToMoby, int *param_4)
short _globalGemCount
Total amount of global gems Address: 0x80075860.
int _vSyncTimer_60fps
This is a global timer at 60fps. It is running at all times, and controls the vSync....
char _hudAnimationState
unsigned short _currentButtonsPressed
Value coorsponding the the current button(s) that were pressed for 1 frame. Goes back to 0 after 1 fr...
char _collectablesStateFlags[1231]
The array for what collectables you have collected globally so far. Address: 0x80077900.
int * _maybe_ptr_levelTextureRelated
int _loadingTimer
This is the pause/inventory menu timer. It is only running in those menus. Address: 0x8007588c.
char _whichCutscene
Which cutscene is currently being played Address: 0x80078D94.
char _hudDragonState
int _globalEggCount
Total amount of global eggs Address: 0x80075810.
int _balloonistState
The State for the balloonist. Should make an enum for this. Address: 0x800777e8.
bool _isLoading
true/1 if is in loading screen. Address: 0x800756B0
int * _ptr_levelMobySpecialData
This is a pointer to the start of the level moby's special data array of structs. Address: 0x800759...
bool _isInsideOptionsMenu
true/1 If inside options menu in start menu. Address: 0x800757C8
CameraAngle _cameraAngle
Camera Angle (yaw, pitch, roll) Address: 0x80076E1C.
int _gameState
Main gamestate. Gamestate values are stored in the GameState enums. Address: 0x800757D8.
int _levelTimerWhenActive
This is a level specific timer. This timer is running when when you are able to control spyro,...
int _globalDragonCount
Total amount of global dragons Address: 0x80075750.
short _cameraRotationMatrix[3][3]
short _sinArray[256]
A scaled up sin lookup table Address: 0x8006cbf8.
int _hudElementsSpinTimer
int * _ptr_dynamicLevelMobys
This is a pointer to the start of the dynamic level moby's array. Address: 0x8007573C.
int _startMenuSelection
This is the current option selected in the main start menu, according to the StartMenuSelections enum...
bool _isPastTitleScreen
If has started new game/continue game, then is 1 for true. Basically after you leave the title screen...
short _flyInAnimation
This is what determines the fly in animation during the loading screen of a level Address: 0x80076E...
int * _ptr_levelMobys
This is a pointer to the start of the level moby's array of stucts. Address: 0x80075828.
char _effect_ScreenLetterBox
This is what determines how much to fill the screen with the top and bottom letterbox effect....
int _levelID
Current Level ID according to the LevelIDS enum Address: 0x800758B4.
char * _ptr_hudMobys
bool _canFlyIn
true/1 If can fly in to level. This is always 1. If set to 0, will just fade in instead of flying in....
char _portalToExitFromInHW
Level ID for which portal to exit from in Homeworld. Uses same LevelIDS enum Address: 0x800758AC.
int _secondController
STILL RESEARCHING Address: 0x80078E50.
int _levelTimer_60fps
This is a level specific timer that runs at 60fps. This timer is running at all times,...
int _ptrTextUnk
byte _cdStatus
int _movementSubState
Research this more. 0xA is the loop for example. Address: 0x80078AD4.
int _wobbleAndOpacityTimer
This is a timer that is often used for changing the opacity of things like lines, the shimmer of text...
char _hudLivesState
int _inventoryMenuScreen
This is the current homeworld menu in the inventory menu according to the InventoryMenuSelections enu...
char * _localSoundEffects
char _hudEggsState
int * _ptr_primitivesArray
char _mainMenuState
This is the current state of the main menu. Should make an enum for this Address: 0x80078D88.
int _musicLevelTrack
The music track that is associated with the level you're currently in. Address: 0x80075828.
int * _ptr_arrayGraphicsRelatedPointers
int _unk_spinRelated
Vec3 _cameraPosition
Camera Position Address: 0x80076DF8.
char * _ptr_particleLinkedList
int _globalTimer
This is the global timer. It is running at all times from game boot up past BIOS. Address: 0x800749...
short _cameraPureRotationMatrix[3][3]
char _hudChestState
int _pausedTimer
This is the pause/inventory menu timer. It is only running in those menus. Address: 0x800758B8.
char _effect_ScreenFadeIn
This is what determines how much to fill the screen with a black fade in effect. Address: 0x8007591...
int _isInPortal
0x5 for in portal, 0xF for loading afterwards. Stays on 0xF until next portal. Address: 0x80078C70
unsigned short _currentButtonsHeld
Value coorsponding the the current button(s) being held. Address: 0x80077380.
int rand()
void srand(int seed)
void memset(void *str, int c, int n)
int printf(const char *format,...)
int sprintf(char *output, const char *format,...)
unsigned char G
Definition common.h:203
unsigned char B
Definition common.h:202
unsigned char R
Definition common.h:204
Definition common.h:181
short w
Definition common.h:182
short x
Definition common.h:182
short h
Definition common.h:182
short y
Definition common.h:182
unsigned char R
Definition common.h:195
unsigned char B
Definition common.h:197
unsigned char G
Definition common.h:196
unsigned char opacity
Definition common.h:190
unsigned char G
Definition common.h:188
unsigned char B
Definition common.h:189
unsigned char R
Definition common.h:187
Definition vector.h:9