fork/training-mode-ce

git clone https://git.julia.blue/fork/training-mode-ce

AitchAdd rect/text drawing code -> add action log drawing code -> add float cancel event (#301)8e0b417

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