mirror of
https://codeberg.org/KeybadeBlox/JSRF-Decompilation.git
synced 2026-04-07 04:50:23 +03:00
549 lines
14 KiB
C++
549 lines
14 KiB
C++
/* JSRF Decompilation: JSRF/Core.hpp
|
|
Game and GameObj classes that form the foundation of the JSRF game code.
|
|
*/
|
|
|
|
#ifndef CORE_HPP
|
|
#define CORE_HPP
|
|
|
|
#include "../MUSASHI/MMatrix.hpp"
|
|
#include "../XDK/CRT/stddef.h"
|
|
#include "../XDK/D3D.h"
|
|
#include "../XDK/Win32.h"
|
|
|
|
|
|
// TODO; move to header for Graphics COM object in Smilebit libraries
|
|
struct GraphicsPerformanceCounters {
|
|
unsigned fps;
|
|
unsigned trianglesPerSecond;
|
|
unsigned frameTriangleCnt;
|
|
unsigned unknown0xC;
|
|
unsigned unknown0x10;
|
|
unsigned unknown0x14;
|
|
};
|
|
|
|
// TODO: Just here to get delinking working until we make dedicated source
|
|
// files for these classes
|
|
struct CollisionManager {
|
|
CollisionManager();
|
|
virtual ~CollisionManager();
|
|
};
|
|
struct UnknownGlobal {
|
|
UnknownGlobal();
|
|
virtual ~UnknownGlobal();
|
|
};
|
|
struct UnknownStatic02 {
|
|
UnknownStatic02();
|
|
virtual ~UnknownStatic02();
|
|
};
|
|
struct UnknownStatic04 {
|
|
UnknownStatic04();
|
|
virtual ~UnknownStatic04();
|
|
};
|
|
struct UnknownStatic05 {
|
|
UnknownStatic05();
|
|
virtual ~UnknownStatic05();
|
|
};
|
|
struct UnknownStatic06 {
|
|
UnknownStatic06();
|
|
virtual ~UnknownStatic06();
|
|
};
|
|
struct UnknownStatic07 {
|
|
UnknownStatic07();
|
|
virtual ~UnknownStatic07();
|
|
};
|
|
struct UnknownStatic09 {
|
|
UnknownStatic09();
|
|
virtual ~UnknownStatic09();
|
|
};
|
|
struct UnknownStatic13 {
|
|
char unknown1[0x274];
|
|
void * unknown2;
|
|
void * unknown3;
|
|
};
|
|
struct UnknownStatic16 {
|
|
UnknownStatic16();
|
|
virtual ~UnknownStatic16();
|
|
};
|
|
struct UnknownStatic17 {
|
|
UnknownStatic17();
|
|
virtual ~UnknownStatic17();
|
|
};
|
|
struct UnknownStatic18 {
|
|
UnknownStatic18();
|
|
virtual ~UnknownStatic18();
|
|
};
|
|
struct UnknownStatic19 {
|
|
UnknownStatic19();
|
|
virtual ~UnknownStatic19();
|
|
};
|
|
struct UnknownStatic24 {
|
|
UnknownStatic24();
|
|
virtual ~UnknownStatic19();
|
|
};
|
|
struct UnknownStatic27 {
|
|
UnknownStatic27();
|
|
virtual ~UnknownStatic27();
|
|
void * unknown[3];
|
|
};
|
|
struct GraphicsSetting {
|
|
unsigned countedIfZero;
|
|
char * name;
|
|
D3DVECTOR unknown;
|
|
float value;
|
|
unsigned index;
|
|
};
|
|
struct GraphicsSettings {
|
|
float * settings;
|
|
unsigned settingsArrSizeInBytes;
|
|
unsigned unknown1;
|
|
unsigned unknown2;
|
|
unsigned srcArrZeroCnt;
|
|
GraphicsSetting * srcItemsMarked0;
|
|
unsigned * offsetsFromPrevSrcItemMarked0;
|
|
};
|
|
enum GraphicsSettingType {
|
|
GST_WARP = 0x0,
|
|
GST_WARP_X = 0x1,
|
|
GST_WARP_Y = 0x2,
|
|
GST_WARP_Z = 0x3,
|
|
GST_GO = 0x4,
|
|
GST_MEMORY = 0x5,
|
|
GST_DRAW = 0x6,
|
|
GST_COLOR = 0x7,
|
|
GST_COLOR_R = 0x8,
|
|
GST_COLOR_G = 0x9,
|
|
GST_COLOR_B = 0xa,
|
|
GST_AMBIENT = 0xb,
|
|
GST_AMBIENT_R = 0xc,
|
|
GST_AMBIENT_G = 0xd,
|
|
GST_AMBIENT_B = 0xe,
|
|
GST_SHADOWCOLOR = 0xf,
|
|
GST_SHADOWCOLOR_A = 0x10,
|
|
GST_SHADOWCOLOR_R = 0x11,
|
|
GST_SHADOWCOLOR_G = 0x12,
|
|
GST_SHADOWCOLOR_B = 0x13,
|
|
GST_BGCOLOR = 0x14,
|
|
GST_BGCOLOR_R = 0x15,
|
|
GST_BGCOLOR_G = 0x16,
|
|
GST_BGCOLOR_B = 0x17,
|
|
GST_MIPMAPLOD = 0x18,
|
|
GST_MIPMAPLOD_BIAS = 0x19,
|
|
GST_G_CONTRAST = 0x1a,
|
|
GST_G_CONTRAST_R = 0x1b,
|
|
GST_G_CONTRAST_G = 0x1c,
|
|
GST_G_CONTRAST_B = 0x1d,
|
|
GST_G_LUMINANCE = 0x1e,
|
|
GST_G_LUMINANCE_R = 0x1f,
|
|
GST_G_LUMINANCE_G = 0x20,
|
|
GST_G_LUMINANCE_B = 0x21,
|
|
GST_GRIND = 0x22,
|
|
GST_GRIND_NS = 0x23,
|
|
GST_GRIND_XS = 0x24,
|
|
GST_GRIND_NR = 0x25,
|
|
GST_GRIND_XR = 0x26,
|
|
GST_GIZA_NO = 0x27,
|
|
GST_GIZA_NO_T = 0x28,
|
|
GST_GIZA_SPEED = 0x29,
|
|
GST_GIZA_SPEED_R = 0x2a,
|
|
GST_GIZA_SPEED_T = 0x2b,
|
|
GST_GIZA_SPEED_S = 0x2c,
|
|
GST_GIZA_GRIND = 0x2d,
|
|
GST_GIZA_GRIND_R = 0x2e,
|
|
GST_GIZA_GRIND_T = 0x2f,
|
|
GST_GIZA_GRIND_S = 0x30,
|
|
GST_GIZA_NORMAL = 0x31,
|
|
GST_GIZA_NORMAL_R = 0x32,
|
|
GST_GIZA_NORMAL_T = 0x33,
|
|
GST_GIZA_NORMAL_S = 0x34,
|
|
GST_GIZA_SDASH = 0x35,
|
|
GST_GIZA_SDASH_R = 0x36,
|
|
GST_GIZA_SDASH_T = 0x37,
|
|
GST_GIZA_SDASH_S = 0x38,
|
|
GST_GIZA_CAMZ = 0x39,
|
|
GST_GIZA_CAMZ_ND = 0x3a,
|
|
GST_GIZA_CAMZ_XD = 0x3b,
|
|
GST_GIZA_CAMZ_NR = 0x3c,
|
|
GST_GIZA_CAMZ_XR = 0x3d,
|
|
GST_GIZA_CAMTRT = 0x3e,
|
|
GST_GIZA_CAMTRT_ND = 0x3f,
|
|
GST_GIZA_CAMTRT_XD = 0x40,
|
|
GST_GIZA_CAMTRT_NR = 0x41,
|
|
GST_GIZA_CAMTRT_XR = 0x42,
|
|
GST_GIZA_CAMANG_NA = 0x43,
|
|
GST_GIZA_CAMANG_XA = 0x44,
|
|
GST_GIZA_CAMANG_NR = 0x45,
|
|
GST_GIZA_CAMANG_XR = 0x46,
|
|
GST_GIZA_MESH = 0x47,
|
|
GST_GIZA_MESH_IP = 0x48,
|
|
GST_GIZA_MESH_AP = 0x49,
|
|
GST_GIZA_MESH_BA = 0x4a,
|
|
GST_GIZA_CAMALPHA = 0x4b,
|
|
GST_GIZA_CAMALPHA_ENABLE = 0x4c,
|
|
GST_DIST = 0x4d,
|
|
GST_FOG = 0x4e,
|
|
GST_FOG_ENABLE = 0x4f,
|
|
GST_FOG_R = 0x50,
|
|
GST_FOG_G = 0x51,
|
|
GST_FOG_B = 0x52,
|
|
GST_FOG_RANGE = 0x53,
|
|
GST_FOG_RANGE_NEAR = 0x54,
|
|
GST_FOG_RANGE_FAR = 0x55,
|
|
GST_POWER = 0x56,
|
|
GST_WIRE_FRAME = 0x57,
|
|
GST_WIRE_FRAME_ENABLE = 0x58,
|
|
GST_TEXTURE = 0x59,
|
|
GST_TEXTURE_NO = 0x5a,
|
|
GST_SCREENGAUGE = 0x5b,
|
|
GST_SCREENGAUGE_ENABLE = 0x5c,
|
|
GST_OWARI = 0x5d,
|
|
GST_COUNT = 0x5e,
|
|
};
|
|
|
|
|
|
enum GameObjFlags {
|
|
GOF_DRAWTREEHEAD = 1 << 0,
|
|
GOF_SKIPDRAWINGSOMETHING = 1 << 1,
|
|
GOF_NODRAWPHASE2 = 1 << 16,
|
|
GOF_DRAWTREE2 = 1 << 18,
|
|
GOF_DRAWPHASE1 = 1 << 22,
|
|
GOF_DRAWTREECHILD = 1 << 30,
|
|
GOF_DELETEAFTEREXEC = 1 << 31
|
|
};
|
|
|
|
// Position in g_game->objects array
|
|
// Different indices and ranges are dedicated to different kinds of
|
|
// objecs.
|
|
enum GameObjIndex {
|
|
OBJ_NOTINDEXED = -1, // Not stored in array
|
|
OBJ_DIRECTOR = 0,
|
|
// TODO
|
|
|
|
OBJ_CNT = 0x1DF4
|
|
};
|
|
|
|
// Base class of most objects (and everything in g_game->objects)
|
|
struct GameObj {
|
|
GameObjFlags flags;
|
|
GameObjIndex index;
|
|
|
|
unsigned otherBitfield;
|
|
float reverseSortKey; // Sign flipped to produced sortKey
|
|
unsigned sortKey; // Four-level key, one byte each
|
|
D3DVECTOR someTranslation;
|
|
|
|
// Links forming a tree of objects for exec phase
|
|
GameObj * parent;
|
|
GameObj * firstChild;
|
|
GameObj * prevSibling;
|
|
GameObj * nextSibling;
|
|
|
|
// Some data structures used for draw phrase
|
|
GameObj * nextDrawTree;
|
|
GameObj * * prevDrawTreeNext;
|
|
GameObj * * * lastDrawTreeNextPtr;
|
|
|
|
GameObj * drawPriorityListNext;
|
|
|
|
virtual ~GameObj();
|
|
|
|
void recursiveExecDefault();
|
|
void drawListDefault(
|
|
GameObjFlags flagFilterAny1,
|
|
int drawArg1,
|
|
int drawArg2,
|
|
GameObjFlags flagFilterAll,
|
|
unsigned otherBitfieldFilterAny,
|
|
GameObjFlags flagFilterNone,
|
|
GameObjFlags flagFilterAny2
|
|
);
|
|
void drawTreeDefault1();
|
|
void drawTreeDefault2();
|
|
|
|
void recursiveExecEvent();
|
|
void drawListEvent(
|
|
GameObjFlags flagFilterAny1,
|
|
int drawArg1,
|
|
int drawArg2,
|
|
GameObjFlags flagFilterAll,
|
|
unsigned otherBitfieldFilterAny,
|
|
GameObjFlags flagFilterNone,
|
|
GameObjFlags flagFilterAny2
|
|
);
|
|
void drawTreeEvent1();
|
|
void drawTreeEvent2();
|
|
|
|
void recursiveExecCoveredPause();
|
|
void drawListCoveredPause(
|
|
GameObjFlags flagFilterAny1,
|
|
int drawArg1,
|
|
int drawArg2,
|
|
GameObjFlags flagFilterAll,
|
|
unsigned otherBitfieldFilterAny,
|
|
GameObjFlags flagFilterNone,
|
|
GameObjFlags flagFilterAny2
|
|
);
|
|
void drawTreeCoveredPause1();
|
|
void drawTreeCoveredPause2();
|
|
|
|
void recursiveExecFreezeCam();
|
|
void drawListFreezeCam(
|
|
GameObjFlags flagFilterAny1,
|
|
int drawArg1,
|
|
int drawArg2,
|
|
GameObjFlags flagFilterAll,
|
|
unsigned otherBitfieldFilterAny,
|
|
GameObjFlags flagFilterNone,
|
|
GameObjFlags flagFilterAny2
|
|
);
|
|
void drawTreeFreezeCam1();
|
|
void drawTreeFreezeCam2();
|
|
|
|
void recursiveExecUncoveredPause();
|
|
void drawListUncoveredPause(
|
|
GameObjFlags flagFilterAny1,
|
|
int drawArg1,
|
|
int drawArg2,
|
|
GameObjFlags flagFilterAll,
|
|
unsigned otherBitfieldFilterAny,
|
|
GameObjFlags flagFilterNone,
|
|
GameObjFlags flagFilterAny2
|
|
);
|
|
void drawTreeUncoveredPause1();
|
|
void drawTreeUncoveredPause2();
|
|
|
|
void addToSiblings(GameObj * sibling, GameObj * parent);
|
|
void destructChildren(GameObj * firstChild);
|
|
GameObj * getParent();
|
|
|
|
void removeFromObjList (GameObj * obj);
|
|
void removeChildrenFromObjList(GameObj * firstChild);
|
|
|
|
// Each frame, one of these trios of methods is called depending on
|
|
// which state the game is in
|
|
// Default implementation of each does nothing; inheriting objects
|
|
// override these methods to run some code during each phase of each
|
|
// frame.
|
|
virtual void execDefault();
|
|
virtual void postExecDefault();
|
|
virtual void drawDefault(unsigned);
|
|
|
|
virtual void execEvent();
|
|
virtual void postExecEvent();
|
|
virtual void drawEvent(unsigned);
|
|
|
|
virtual void execCoveredPause();
|
|
virtual void postExecCoveredPause();
|
|
virtual void drawCoveredPause(unsigned);
|
|
|
|
virtual void execFreezeCam();
|
|
virtual void postExecFreezeCam();
|
|
virtual void drawFreezeCam(unsigned);
|
|
|
|
virtual void execUncoveredPause();
|
|
virtual void postExecUncoveredPause();
|
|
virtual void drawUncoveredPause(unsigned);
|
|
|
|
void recursivePostExecDefault();
|
|
void recursivePostExecEvent();
|
|
void recursivePostExecCoveredPause();
|
|
void recursivePostExecFreezeCam();
|
|
void recursivePostExecUncoveredPause();
|
|
|
|
void setParent(GameObj * parent);
|
|
|
|
GameObj(GameObj * parent, GameObjIndex index, GameObjFlags flags);
|
|
};
|
|
|
|
// There's a big array of possible arguments for draw methods with these
|
|
struct DrawFuncArgs {
|
|
GameObjFlags flagFilterAny;
|
|
int arg1;
|
|
int arg2;
|
|
};
|
|
|
|
// Base class of objects serving as the head of a tree of objects to draw
|
|
// recursively
|
|
struct DrawTree : GameObj {
|
|
D3DVECTOR unknown0x44;
|
|
D3DVECTOR unknown0x50;
|
|
D3DVECTOR unknown0x5C;
|
|
D3DVECTOR unknown0x68;
|
|
unsigned unknown0x74;
|
|
unsigned unknown0x78;
|
|
unsigned unknown0x7C;
|
|
unsigned unknown0x80;
|
|
D3DRECT viewport;
|
|
unsigned someIndex;
|
|
|
|
void copySomeVectors();
|
|
DrawTree(GameObj * parent, GameObjIndex index, GameObjFlags flags);
|
|
virtual ~DrawTree();
|
|
};
|
|
|
|
struct PlayerObj : GameObj {
|
|
unsigned unknown0x44;
|
|
unsigned unknown0x48;
|
|
|
|
PlayerObj(GameObj * parent, GameObjIndex index, GameObjFlags flags);
|
|
virtual ~PlayerObj();
|
|
};
|
|
|
|
// Top-level globally-accessible "god object" that runs the main loop and
|
|
// provides global access to most other objects and many variables
|
|
enum DrawMode {
|
|
DRAW_YES,
|
|
DRAW_WAITVBLANK,
|
|
DRAW_NO
|
|
};
|
|
|
|
enum GlobalIndex {
|
|
};
|
|
|
|
#pragma pack(4)
|
|
struct Game {
|
|
char unknown0x4[4];
|
|
unsigned unknown0x8;
|
|
unsigned * unknown0xC;
|
|
int initState;
|
|
unsigned unknown0x14;
|
|
BOOL drawProfilingInfo;
|
|
int unknown0x1C;
|
|
BOOL logosStarted;
|
|
BOOL fatalErr;
|
|
|
|
D3DCOLOR colour;
|
|
D3DCOLOR ambientColour;
|
|
D3DCOLOR shadowColour;
|
|
D3DCOLOR bgColour;
|
|
D3DCOLOR bgColourFallback;
|
|
BOOL useFallbackBgColour;
|
|
|
|
// Game state used to select GameObj methods to call in main loop
|
|
// If multiple states are activated, the precedence is
|
|
// coveredPause > Event > FreezeCam > UncoveredPause > Default
|
|
BOOL coveredPause; // Game paused with world not visible
|
|
BOOL event; // Events (cutscenes)
|
|
BOOL freezeCam; // Time-frozen camera shots
|
|
BOOL uncoveredPause; // Game paused with world visible, or
|
|
// automatic pause at start of mission
|
|
|
|
BOOL coveredPauseNextFrame;
|
|
BOOL noCoveredPauseNextFrame;
|
|
BOOL eventNextFrame;
|
|
BOOL noEventNextFrame;
|
|
BOOL freezeCamNextFrame;
|
|
BOOL noFreezeCamNextFrame;
|
|
BOOL uncoveredPauseNextFrame;
|
|
BOOL noUncoveredPauseNextFrame;
|
|
|
|
BOOL drawChildren;
|
|
BOOL skipDraw;
|
|
BOOL runSomeExtraDrawListCode;
|
|
GraphicsPerformanceCounters perfCounters;
|
|
|
|
DrawMode drawMode;
|
|
|
|
// Globally accessible objects and variables
|
|
GameObj * objects[7668];
|
|
unsigned globals[461]; // Items may be any 32-bit type, e.g. ptr
|
|
|
|
DrawTree * drawTreesHead;
|
|
DrawTree * * drawTreesEndNext;
|
|
|
|
GameObj * drawListHead;
|
|
GameObj * * drawListEndNext;
|
|
|
|
GameObj * drawPriorityListHead;
|
|
GameObj * * drawPriorityListEndNext;
|
|
|
|
GameObj * drawPriorityListsByKeyHeads [256];
|
|
GameObj * * drawPriorityListsByKeyEndNexts[256];
|
|
|
|
unsigned unknown0x87B4;
|
|
|
|
LARGE_INTEGER execPerfCount;
|
|
LARGE_INTEGER drawPerfCount;
|
|
|
|
unsigned unknown0x87C8;
|
|
unsigned unknown0x87CC;
|
|
unsigned frameCnt1;
|
|
unsigned unknown0x87D4;
|
|
unsigned unknown0x87D8;
|
|
GameObj * rootExecObj;
|
|
int frameCnt2;
|
|
int frameCnt3;
|
|
unsigned gameObjCnt;
|
|
DrawTree * currentDrawTree;
|
|
GameObjIndex currentDrawTreeIndex;
|
|
int unknown0x87F4;
|
|
Mat4 parentMatrix;
|
|
unsigned unknown0x8838;
|
|
unsigned unknown0x883C;
|
|
|
|
Game(unsigned *, unsigned);
|
|
virtual ~Game();
|
|
void exec();
|
|
void drawObj(GameObj * obj, unsigned);
|
|
void drawList_(
|
|
GameObjFlags flagFilterAny1,
|
|
int drawArg1,
|
|
int drawArg2,
|
|
GameObjFlags flagFilterAll,
|
|
unsigned otherBitfieldFilterAny,
|
|
GameObjFlags flagFilterNone,
|
|
GameObjFlags flagFilterAny2
|
|
);
|
|
void drawTree1(GameObj * obj);
|
|
|
|
void setCoveredPauseNextFrame (BOOL val);
|
|
void setEventNextFrame (BOOL val);
|
|
void setFreezeCamNextFrame (BOOL val);
|
|
void setUncoveredPauseNextFrame(BOOL val);
|
|
|
|
void enableDrawChildren();
|
|
void enableSkipDraw();
|
|
void fatal();
|
|
void setDrawMode(DrawMode mode);
|
|
|
|
void setGlobal(GlobalIndex index, unsigned val);
|
|
unsigned getGlobal(GlobalIndex index);
|
|
|
|
void addToDrawList (GameObj * obj);
|
|
void removeFromDrawList(GameObj * obj);
|
|
|
|
void setObj (GameObjIndex index , GameObj * obj);
|
|
void unsetObj (GameObjIndex index );
|
|
GameObj * getObj (GameObjIndex index );
|
|
int allocObjIndex(GameObjIndex min , GameObjIndex max);
|
|
BOOL objIndexAvail(GameObjIndex index );
|
|
void swapObjs (GameObjIndex index1, GameObjIndex index2);
|
|
|
|
void clearScreen();
|
|
void enableSomeExtraDrawListCode();
|
|
void setLogosStarted(BOOL val);
|
|
|
|
void clearDrawPriorityList();
|
|
GameObj * getDrawPriorityListHead();
|
|
void appendToDrawPriorityList(GameObj * obj);
|
|
void sortDrawPriorityListSingleLevel(unsigned char sortKeyBitOffset);
|
|
|
|
void setFallbackBgColour(D3DCOLOR colour, BOOL useFallback);
|
|
void initRootExecObj();
|
|
void drawList(GameObjFlags flagFilterAll, BOOL);
|
|
void sortDrawPriorityList();
|
|
void drawObjs();
|
|
void draw();
|
|
void frame();
|
|
int mainLoop();
|
|
};
|
|
extern Game * g_game;
|
|
|
|
// Root of the exec GameObj tree
|
|
struct RootExecObj : GameObj {
|
|
RootExecObj(GameObj * parent, GameObjIndex index, GameObjFlags flags);
|
|
virtual ~RootExecObj();
|
|
};
|
|
|
|
void removeFromObjListByIndex(GameObjIndex index);
|
|
|
|
#endif
|