fork/training-mode-ce
git clone https://git.julia.blue/fork/training-mode-ce
4f5d26e
techchase-camera
1#ifndef MEX_H_PRELOAD 2#define MEX_H_PRELOAD 3 4#include "structs.h" 5#include "datatypes.h" 6 7#define PRELOADFLAG_FTCOSTUME (1 << 0) // 0x01, fighter costume files 8#define PRELOADFLAG_FTDAT (1 << 1) // 0x02, main fighter PlX dat files 9#define PRELOADFLAG_EFFECT (1 << 2) // 0x04, effect files 10#define PRELOADFLAG_FTANIM (1 << 3) // 0x08, fighter animations 11#define PRELOADFLAG_ALLOC (1 << 4) // 0x10, special allocs like fod reflection 12#define PRELOADFLAG_x20 (1 << 5) // 0x20, unk 13#define PRELOADFLAG_PERSIST (1 << 6) // 0x40, IfAll / EfMnData / EfCoData / ItCo 14#define PRELOADFLAG_x80 (1 << 7) // 0x80, LbRb 15 16typedef enum PreloadEntryLoadState // 0x0 of PreloadEntry 17{ 18PRELOADENTRYSTATE_NONE , 19PRELOADENTRYSTATE_QUEUED , 20PRELOADENTRYSTATE_LOADING , 21PRELOADENTRYSTATE_LOADED , 22PRELOADENTRYSTATE_ACCESSED , 23}PreloadEntryState ; 24 25typedef enum PreloadEntryInitKind // 0x3 of PreloadEntry 26{ 27PRELOADENTRYINITKIND_NOINIT ,// do not initialize the file when accessed 28PRELOADENTRYINITKIND_REQINIT ,// request the file be initialized upon being accessed 29PRELOADENTRYINITKIND_INITALIZED ,// file has been initialized 30}PreloadEntryInitKind ; 31 32typedef enum PreloadHeapKind // 0x2 of PreloadEntry 33{ 34PRELOADHEAPKIND_MAINDRAM ,// main DRAM heap 35PRELOADHEAPKIND_MAINARAM ,// main ARAM heap 36PRELOADHEAPKIND_LBRB ,// seems to only contain LbRb.dat 37PRELOADHEAPKIND_PERSIST ,// IfAll, ItCo, EfMnData, LbRb 38PRELOADHEAPKIND_FIGHTERCACHE ,// fighter files like main dat, costume, and effects. also stage and special allocations (entrynum 2000+) 39PRELOADHEAPKIND_FIGHTERANIMCACHE ,// fighter animations 40 41// custom heap that is resized dynamically to keep the major scene permenantly loaded. 42// i dont even think its fair to consider this a preload heap because it doesnt 43// adhere to the same rules as the others. its not created in the same way and 44// will crash without some hacky asm that constantly enables it so thegame 45// doesnt attempt to free or recreate it. this is because the preload heap "library" 46// isnt initialized in time when major scene files need to be loaded 47// (it steals its memory from PRELOADHEAPKIND_MAINDRAM). 48PRELOADHEAPKIND_MEXMAJORSCENE , 49 50}PreloadHeapKind ; 51 52typedef enum PreloadFileKind // 0x1 of PreloadEntry 53{ 54PRELOADFILEKIND_ALLOC ,// special alloc, code @ 80017c7c will skip loading a file 55PRELOADFILEKIND_1 ,// these will always result in an assertion?? 800180dc 56PRELOADFILEKIND_DEFAULT ,// will only init the archive 57PRELOADFILEKIND_EFFECT ,// will init particle bank and get a symbol from it @ 80018110 58PRELOADFILEKIND_STAGE ,// will init get stage symbol and init its ptcl bank @ 80018130 59PRELOADFILEKIND_NUM ,// m-ex uses this as a custom file_kind. its main purpose to not be marked as unneeded every time the preload table is updated (cant preload arbitrary files in vanilla melee) 60}PreloadFileKind ; 61 62struct PreloadHeapDesc // array of these are now located in m-ex injection @ 80015f88 63{ 64int id ; 65int location ; 66int pri ; 67int size ; 68}; 69 70struct PreloadHeap // 71{ 72int heap_index ;// 0x0, is a heap ID returned by OSCreateHeap, is = -1 if the heap doesnt use OSCreateHeap 73void * handle ;// 0x4, name evidenced by asset @ 80014f10 74void * addr_start ;// 0x8 75int size ;// 0xC 76int pri ;// 0x10. 0 will allocate using OSCreateHeap, 1 will create heap using 80014e24. 2 = use main heap AND handles?? has something to do with how the heap is built. check m-ex injection @ 800159b4. is referenced @ 80015d0c when freeing a preloaded file. if this is 1 it will properly free up the preload entry 77int x14 ;// 0x14 78int is_disable ;// 0x18 79}; 80 81struct PreloadHeapLookup 82{ 83// these dont seem to change for the entirety of runtime 84// i guess they're referenced when rebuilding heaps between scenes 85void * dram_addr_start ;// 0x0 86void * dram_addr_end ;// 0x4 87void * aram_addr_start ;// 0x8 88void * aram_addr_end ;// 0xC 89 90PreloadHeap heap_arr [7 ];// 0x10, indexed by PreloadHeapKind 91}; 92 93struct PreloadChar 94{ 95int kind ; 96u8 costume ; 97}; 98struct PreloadTable 99{ 100int x0 ; 101void * x4 ; 102u8 x8 ; 103int stage ;// 0xc 104PreloadChar fighters [8 ];// 0x10 105int defrag_num ;// 0x50 106}; 107 108struct PreloadAllocData 109{ 110PreloadAllocData * next ; 111void * alloc ;// 0x4 112int size ;// 0x8 113}; 114struct PreloadEntry // scene changes wait for asyncronous disc reads to finish if they are logged as a PreloadEntry! 115{ 116u8 load_state ;// 0x0, 0 = none, 1 = queued, 2 = loading, 3 = loaded, 4 = persistently loaded (IfAll, etc) 117u8 file_kind ;// 0x1, PreloadFileKind, alters the initialization behavior when the file is accessed with Preload_GetArchive/Preload_GetArchiveByEntrynum.its the value @ 0x0 in the tables relocated at m-ex injection 800186a8. 0 is used by special allocs (wont actually load anything, will auto mark as loaded), 2 is used by fighter files and ifall/itco/lbrb. 3 is used by efcodata and efmndata. 4 is used by stage files 118s8 heap_kind ;// 0x2, these heap kinds are defined in m-ex injection 80015f88 and in the header as PreloadHeapKind 119u8 init_kind ;// 0x3, 0, do not init archive, 1 = init archive when accessed with Preload_GetArchive/Preload_GetArchiveByEntrynum. 0 = fighter anims/special allocs (dont initialize), 1 = fighter files/itco/ifall/efco/efmn (queued for initialization), 2 = lbrb/ifall/stage (initialized) 120u8 flags ;// 0x4, indicates the purpose of the file. referenced when waiting for files using Preload_CheckIfFilesAreLoading. costume files are 0x1, plX files are 0x2, effect files are 0x4, anim files are 0x8, stage files and allocs are 0x10, IfAll/EfMnData/EfCoData/ItCo are 0x40, LbRb is 0x80 121u16 file_entry_num ;// 0x6, if this is greater than 2000 its a special allocation (like fountain reflection (2001) or pokemon stadium transformation (200?)) 122s16 status ;// 0x8, is -9999 when marked for unload, 9999 when needed 123int file_size ;// 0xc 124PreloadAllocData * file_data ;// 0x10, this gets allocated @ 80017c00 125PreloadAllocData * header_data ;// 0x14 126int x18 ;// 0x18 127}; 128 129struct Preload 130{ 131// int heap_kind; // 0x0, copied from current MinorScene struct, 132PreloadTable queued ;// 0x4, modify this to request files to preload 133PreloadTable updated ;// 0x? 134PreloadEntry entry [80 ];// 0xac 135}; 136 137static PreloadHeapLookup * stc_preload_heaps_lookup = (void * )0x804dfb64 ; 138 139/*** Functions ***/ 140void Preload_Update ();// checks for new files to preload and begins loading them synchronously 141void Preload_Invalidate ();// invalidates cache, this is usually used from scene prep on CSS's 142Preload * Preload_GetTable ();// gets preload table 143PreloadEntry * Preload_CreateEntry (PreloadFileKind file_kind ,char * filename ,int r5 ,int heap_kind ,int file_size ,int is_init_archive ,int r9 ,int flags ,int r11 );// creates a preload entry for any given file/ (file_kind is 0 for stuff like fod reflection, r5 = 4, r9 = 7) 80017740 144PreloadEntry * Preload_CreateEntryByEntrynum (int file_kind ,int entrynum ,int r5 ,int heap_kind ,int file_size ,int is_init_archive ,int r9 ,int flags ,int r11 );// creates a preload entry for any given file/ (file_kind is 0 for stuff like fod reflection, r5 = 4, r9 = 7) 80017740 145void Preload_RequestLoadEntry (int preload_entry_index );// 146void Preload_FreeEntry (int preload_entry_index );// 800174e8 147HSD_Archive * Preload_GetArchive_Init_ReturnSymbols (int unk ,char * filename ,void * symbol_return , ...);// variadic args are symbol strings, terminate the variadic args with a 0 148HSD_Archive * Preload_GetArchive (char * filename );// 149HSD_Archive * Preload_GetArchiveByEntrynum (int entrynum );// will wait if the file isnt loaded yet 150int Preload_CheckFileStatus (int entrynum );// 0 = not loading, 1 = loading, 2 = loaded 151int Preload_CheckIfFilesAreLoading (int preload_flags );// use PRELOADFLAG_ definitions 152void Preload_FreeUnneededInitializedArchivesInHeap (PreloadHeapKind heap_kind );// arg is heap_kind in PreloadEntry 153void Preload_Wait (int preload_flags );// will wait until all preload entries with the flags specified are finished loading before returning, use PRELOADFLAG_ definitions 154void Preload_LoadFighter (CharacterKind c_kind ,int costume ); 155void * Preload_AllocFromHeap (PreloadHeapKind heap_kind ,int size ); 156void Preload_FreeToHeap (void * ptr ,int size ); 157#endif