fork/training-mode-ce
git clone https://git.julia.blue/fork/training-mode-ce
8e0b417
nix
1#ifndef MEX_H_MEX 2#define MEX_H_MEX 3 4#include "structs.h" 5#include "datatypes.h" 6#include "obj.h" 7 8#define DB_FLAG 0 9 10enum MEX_GETDATA 11{ 12MXDT_FTINTNUM , 13MXDT_FTEXTNUM , 14MXDT_FTICONNUM , 15MXDT_FTICONDATA , 16MXDT_GRINTNUM , 17MXDT_GREXTNUM , 18MXDT_GRICONNUM , 19MXDT_GRICONDATA , 20MXDT_FTCOSTUMEARCHIVE , 21MXDT_GRDESC ,// gets GrDesc struct 22MXDT_GREXTLOOKUP ,// gets first stage external ID from internal ID 23MXDT_GRNAME ,// returns stage name char* 24MXDT_FTNAME ,// returns fighter name char*, indexed by external ID 25MXDT_FTDAT ,// returns pointer to fighter file struct, indexed by internal ID 26MXDT_FTKINDDESC ,// returns pointer to ftkind desc array, indexed by external ID 27MXDT_FTEMBLEMLOOKUP ,// returns pointer to ftkind desc array, indexed by external ID 28MXDT_MEXDATA ,// 29MXDT_PRELOADHEAP ,// returns pointer to PreloadHeap 30MXPT_FILE ,// returns pointer to Archive data for MxPt if it exists 31}; 32 33typedef enum SSMKind 34{ 35SSMKIND_CHAR , 36SSMKIND_STAGE , 37}SSMKind ; 38 39/*** Structs ***/ 40 41struct Stc_icns 42{ 43u16 reserved_num ; 44u16 stride ; 45MatAnimJointDesc * matanimjoint ; 46int custom_stock_num ; 47void * custom_stock_descs ; 48}; 49 50struct MEXPlaylistEntry 51{ 52u16 bgm ; 53u16 chance ; 54}; 55 56struct MEXPlaylist 57{ 58int entry_count ; 59MEXPlaylistEntry * entries ; 60}; 61 62struct MexCostumeDesc // this is the symbol in the file 63{ 64 65void * costume_vis_lookup ;// 0x0 66void * costume_mat_lookup ;// 0x4 67int accessory_num ;// 0x8 68struct MexCostumeDescAccessory 69 { 70JOBJDesc * joint_desc ; 71int bone_index ; 72int dynamic_num ; 73DynamicsDesc ** dynamic_desc ; 74int ftparts_num ; 75FtPartsVis * ftparts ; 76int dynamic_hit_num ; 77DynamicsHitDesc ** dynamic_hit_desc ; 78AnimJointDesc * animjointdesc ; 79MatAnimJointDesc * matanimjointdesc ; 80FtScript * script ; 81 }** accessories ; 82}; 83 84typedef struct MexCostumeRuntime 85{ 86JOBJDesc * joint_desc ; 87MatAnimJointDesc * matanim_desc ; 88int x08 ; 89int x0C ; 90int x10 ; 91HSD_Archive * archive ; 92}MexCostumeRuntime ; 93 94typedef struct MexCostumeRuntimeDesc 95{ 96MexCostumeRuntime * runtimes ; 97int count ; 98}MexCostumeRuntimeDesc ; 99 100typedef struct MEXInstructionTable 101{ 102u32 cmd :8 ;// 0x0 103u32 code_offset :24 ;// 0x01 104uint reloc_offset ;// 0x4 105}MEXInstructionTable ; 106 107typedef struct MEXFunctionTable 108{ 109int index ;// 0x0 110uint code_offset ;// 0x4 111}MEXFunctionTable ; 112 113typedef struct MEXDebugSymbol 114{ 115uint code_offset ;// 0x0 116uint code_length ;// 0x4 117char * symbol ;// 0x8 118}MEXDebugSymbol ; 119 120typedef struct MEXFunctionLookup 121{ 122int num ; 123void * function [30 ]; 124}MEXFunctionLookup ; 125 126typedef struct MEXFunction 127{ 128u8 * code ;// 0x0 129MEXInstructionTable * instruction_reloc_table ;// 0x4 130int instruction_reloc_table_num ;// 0x8 131MEXFunctionTable * func_reloc_table ;// 0xC 132int func_reloc_table_num ;// 0x10 133int code_size ;// 0x14 134int debug_symbol_num ;// 0x18 135MEXDebugSymbol * debug_symbol ;// 0x1c 136}MEXFunction ; 137 138typedef struct MexMetaData 139{ 140u8 v_major ; 141u8 v_minor ; 142short flags ; 143int internal_id_count ; 144int external_id_count ; 145int css_icon_count ; 146int internal_stage_count ; 147int external_stage_count ; 148int sss_icon_count ; 149int ssm_count ; 150int bgm_count ; 151int effect_count ; 152int bootup_scene ; 153int last_major ; 154int last_minor ; 155int trophy_count ; 156int trophy_sd_offset ; 157}MexMetaData ; 158 159typedef struct MnSlMapIcon 160{ 161JOBJ * runtime_joint ; 162int flags ; 163byte icon_state ; 164byte preview_id ; 165byte random_select_stage_id ; 166 167Vec2 cursor_size ; 168Vec2 outline_size ; 169int external_id ; 170}MnSlMapIcon ; 171 172typedef struct MexMenuData 173{ 174int * params ; 175MnSlChrIcon * css_icons ; 176MnSlMapIcon * sss_icons ; 177void * sss_bitfields ; 178}MexMenuData ; 179 180typedef struct MexMusicTable 181{ 182char ** filenames ; 183MEXPlaylistEntry * menu_playlist ; 184int menu_playlist_count ; 185char ** labels ; 186 187}MexMusicTable ; 188 189typedef struct MexStageSound 190{ 191char ssmid ; 192char reverb ; 193char x03 ; 194}MexStageSound ; 195 196typedef struct MexStageTable 197{ 198GrExtLookup * grkind_ext_desc ;// indexed by GrKindExt (external ID) 199MexStageSound * sound_table ; 200void * collision_table ; 201void * item_table ; 202char ** name_table ; 203MEXPlaylist * playlist_table ; 204}MexStageTable ; 205 206typedef struct MexSceneData 207{ 208MajorSceneDesc * major_desc_arr ; 209MinorSceneDesc * minor_desc_arr ; 210}MexSceneData ; 211 212typedef struct MexData 213{ 214MexMetaData * metadata ; 215MexMenuData * menu ; 216struct 217 {// 218char ** names ;// 0x0, 219struct // 220 {// 221char * name ;// 222char * symbol ;// 223 }* pl_file ;// 0x4 224u8 * insignia_idx ;// 0x8 225FtKindDesc * ft_kind_desc ;// 0xC, array of these 226struct // 227 {// 228u8 num ;// 229u8 red_idx ;// 230u8 blue_idx ;// 231u8 green_idx ;// 232 }* costume_info ;// 0x10, array of these 233struct // 234 {// 235struct // 236 {// 237char * file_name ;// 238char * joint_symbol ;// 239char * matanim_symbol ;// 240int visibility_lookup_idx ;// 241 }* costume_symbol_table ;// array of these per costume 242 }* costume_file ;// 0x14, array of these per character 243// theres more im just lazy 244void * ftdemo_filenames ; 245void * anim_filenames ; 246void * anim_num ; 247u8 * effect_index ; 248 }* fighter ;// indexed by ft_kind 249void * fighter_function ; 250void * ssm ; 251MexMusicTable * music ; 252struct 253 { 254struct 255 { 256char * dat_name ; 257char * symbol_name ; 258void * particle_data_runtime ;// this pointer is shifed back by (effect_idx_start * 4)! 259 }* files ; 260 }* effect ; 261void * item ; 262void * kirby ; 263void * kirby_function ; 264MexStageTable * stage ; 265GrDesc ** stage_desc ;// indexed by GrKind (internal ID) 266void * scene ; 267void * misc ; 268}MexData ; 269 270static MEXFunctionLookup ** stc_mexfunction_lookup = (void * )0x804dfad8 ; 271 272/*** Functions ***/ 273HSD_Archive * MEX_LoadRelArchive (char * file ,void * functions ,char * symbol ); 274void MEX_RelocRelArchive (void * xFunction ); 275void * calloc (int size ); 276void bp (); 277 278// see https://smashboards.com/threads/primitive-drawing-module.454232/ 279 280enum PRIM_Shape { 281PRIM_SHAPE_QUADS , 282PRIM_SHAPE_TRIANGLES = 2 , 283PRIM_SHAPE_TRIANGLE_STRIP , 284PRIM_SHAPE_TRIANGLE_FAN , 285PRIM_SHAPE_LINES , 286PRIM_SHAPE_LINE_STRIP , 287PRIM_SHAPE_POINTS , 288}; 289enum PRIM_Blend_Type { 290PRIM_BLEND_NONE , 291PRIM_BLEND_BLEND , 292PRIM_BLEND_LOGIC , 293PRIM_BLEND_SUBTRACT , 294}; 295enum PRIM_Logic { 296PRIM_LOGIC_CLEAR , 297PRIM_LOGIC_AND , 298PRIM_LOGIC_REVAND , 299PRIM_LOGIC_COPY , 300PRIM_LOGIC_INVAND , 301PRIM_LOGIC_NOOP , 302PRIM_LOGIC_XOR , 303PRIM_LOGIC_OR , 304PRIM_LOGIC_EQUIV , 305PRIM_LOGIC_INV , 306PRIM_LOGIC_REVOR , 307PRIM_LOGIC_INVCOPY , 308PRIM_LOGIC_INVOR , 309PRIM_LOGIC_NAND , 310PRIM_LOGIC_SET , 311}; 312enum PRIM_Source { 313PRIM_SOURCE_0 , 314PRIM_SOURCE_1 , 315PRIM_SOURCE_SRC_COLOR , 316PRIM_SOURCE_SRC_INV_COLOR , 317PRIM_SOURCE_SRC_ALPHA , 318PRIM_SOURCE_SRC_INV_ALPHA , 319PRIM_SOURCE_DST_ALPHA , 320PRIM_SOURCE_DST_INV_ALPHA , 321}; 322 323typedef struct PRIM_DrawMode { 324u32 cull_back :1 ; 325u32 cull_front :1 ; 326u32 unk1 :4 ; 327u32 line_width :10 ; 328u32 unk2 :2 ; 329u32 z_compare_timing :1 ; 330u32 z_compare_enable :1 ; 331u32 z_update_enable :1 ; 332u32 z_logic_gt :1 ; 333u32 z_logic_eq :1 ; 334u32 z_logic_lt :1 ; 335u32 shape :8 ; 336}PRIM_DrawMode ; 337typedef struct PRIM_BlendMode { 338u32 unk1 :18 ; 339u32 blend_type :2 ; 340u32 unk2 :1 ; 341u32 blend_src :3 ; 342u32 unk3 :1 ; 343u32 blend_dst :3 ; 344u32 blend_logic :4 ; 345}PRIM_BlendMode ; 346 347void PRIM_NEW_INTERNAL (int vert_count ,u32 draw_mode ,u32 blend_mode ); 348static inline void PRIM_NEW (int vert_count ,PRIM_DrawMode draw_mode ,PRIM_BlendMode blend_mode ) 349{ 350union { 351PRIM_DrawMode bitflags ; 352u32 integer ; 353 }dm ; 354union { 355PRIM_BlendMode bitflags ; 356u32 integer ; 357 }bm ; 358 359dm .bitflags = draw_mode ; 360bm .bitflags = blend_mode ; 361 362PRIM_NEW_INTERNAL (vert_count ,dm .integer ,bm .integer ); 363} 364void PRIM_CLOSE (); 365 366static void MEX_InitRELDAT (HSD_Archive * archive ,char * symbol_name ,void ** return_func_array ) 367{ 368MEXFunction * mex_function = Archive_GetPublicAddress (archive ,symbol_name ); 369 370// reloc instructions 371MEX_RelocRelArchive (mex_function ); 372 373// reloc function pointers 374for (int i = 0 ;i < mex_function -> func_reloc_table_num ;i ++ ) 375 { 376MEXFunctionTable * this_func = & mex_function -> func_reloc_table [i ]; 377return_func_array [i ]= (void * )& mex_function -> code [this_func -> code_offset ]; 378 } 379} 380 381#endif