Added DynOS warp functions to Lua API

This commit is contained in:
MysterD 2022-03-11 18:11:32 -08:00
parent 1c7451fcfc
commit 24df92fa48
12 changed files with 290 additions and 2 deletions

View File

@ -26,10 +26,11 @@ in_files = [
"include/mario_geo_switch_case_ids.h",
"src/game/object_list_processor.h",
"src/engine/graph_node.h",
"levels/level_defines.h",
]
exclude_constants = {
'*': [ '^MAXCONTROLLERS$', '^LEVEL_.*', '^AREA_[^T].*', '^AREA_T[HTO]', '^CONT_ERR.*', '^READ_MASK$', '^SIGN_RANGE$', ]
'*': [ '^MAXCONTROLLERS$', '^AREA_[^T].*', '^AREA_T[HTO]', '^CONT_ERR.*', '^READ_MASK$', '^SIGN_RANGE$', ]
}
include_constants = {
@ -125,6 +126,7 @@ def process_enum(filename, line):
if saw_constant(field):
print('>>> ' + line)
index += 1
ret['constants'] = constants

View File

@ -2,10 +2,28 @@ import os
import re
import sys
def extract_level_defines(txt):
tmp = txt
txt = 'enum LevelNum {\n LEVEL_NONE,\n'
for line in tmp.splitlines():
if line.startswith('STUB_LEVEL') or line.startswith('DEFINE_LEVEL'):
txt += ' ' + line.split(',')[1].strip() + ',\n'
txt += ' LEVEL_COUNT,\n };'
return txt
extra_steps = {
"levels/level_defines.h": extract_level_defines,
}
def extract_constants(filename):
with open(filename) as file:
txt = file.read()
# perform special functions
short_filename = filename.split('/../', 1)[-1]
if short_filename in extra_steps:
txt = extra_steps[short_filename](txt)
# strip comments
txt = re.sub('//.*', ' ', txt)
while ('/*' in txt):
@ -82,4 +100,6 @@ def extract_constants(filename):
return txt
#print(extract_constants("include/audio_defines.h"))
if __name__ == "__main__":
print(extract_constants(sys.argv[1]))

View File

@ -72,3 +72,6 @@ def extract_structs(filename):
txt += line + '\n'
return txt.splitlines()
if __name__ == "__main__":
print(extract_structs(sys.argv[1]))

View File

@ -4,6 +4,9 @@
#ifndef __cplusplus
bool dynos_warp_to_level(s32 aLevel, s32 aArea, s32 aAct);
bool dynos_warp_restart_level(void);
bool dynos_warp_exit_level(s32 aDelay);
bool dynos_warp_to_castle(s32 aLevel);
int dynos_packs_get_count(void);
const char* dynos_packs_get(s32 index);

View File

@ -7,6 +7,18 @@ bool dynos_warp_to_level(s32 aLevel, s32 aArea, s32 aAct) {
return DynOS_Warp_ToLevel(aLevel, aArea, aAct);
}
bool dynos_warp_restart_level(void) {
return DynOS_Warp_RestartLevel();
}
bool dynos_warp_exit_level(s32 aDelay) {
return DynOS_Warp_ExitLevel(aDelay);
}
bool dynos_warp_to_castle(s32 aLevel) {
return DynOS_Warp_ToCastle(aLevel);
}
// -- dynos packs -- //
#define DYNOS_PACK_PATH_SPLIT_LEN 12

View File

@ -16,6 +16,8 @@
- [enum InteractionFlag](#enum-InteractionFlag)
- [interaction.h](#interactionh)
- [enum InteractionType](#enum-InteractionType)
- [level_defines.h](#level_definesh)
- [enum LevelNum](#enum-LevelNum)
- [mario_animation_ids.h](#mario_animation_idsh)
- [enum MarioAnimID](#enum-MarioAnimID)
- [mario_geo_switch_case_ids.h](#mario_geo_switch_case_idsh)
@ -1460,6 +1462,56 @@
<br />
## [level_defines.h](#level_defines.h)
### [enum LevelNum](#LevelNum)
| Identifier | Value |
| :--------- | :---- |
| LEVEL_NONE | 0 |
| LEVEL_UNKNOWN_1 | 1 |
| LEVEL_UNKNOWN_2 | 2 |
| LEVEL_UNKNOWN_3 | 3 |
| LEVEL_BBH | 4 |
| LEVEL_CCM | 5 |
| LEVEL_CASTLE | 6 |
| LEVEL_HMC | 7 |
| LEVEL_SSL | 8 |
| LEVEL_BOB | 9 |
| LEVEL_SL | 10 |
| LEVEL_WDW | 11 |
| LEVEL_JRB | 12 |
| LEVEL_THI | 13 |
| LEVEL_TTC | 14 |
| LEVEL_RR | 15 |
| LEVEL_CASTLE_GROUNDS | 16 |
| LEVEL_BITDW | 17 |
| LEVEL_VCUTM | 18 |
| LEVEL_BITFS | 19 |
| LEVEL_SA | 20 |
| LEVEL_BITS | 21 |
| LEVEL_LLL | 22 |
| LEVEL_DDD | 23 |
| LEVEL_WF | 24 |
| LEVEL_ENDING | 25 |
| LEVEL_CASTLE_COURTYARD | 26 |
| LEVEL_PSS | 27 |
| LEVEL_COTMC | 28 |
| LEVEL_TOTWC | 29 |
| LEVEL_BOWSER_1 | 30 |
| LEVEL_WMOTR | 31 |
| LEVEL_UNKNOWN_32 | 32 |
| LEVEL_BOWSER_2 | 33 |
| LEVEL_BOWSER_3 | 34 |
| LEVEL_UNKNOWN_35 | 35 |
| LEVEL_TTM | 36 |
| LEVEL_UNKNOWN_37 | 37 |
| LEVEL_UNKNOWN_38 | 38 |
| LEVEL_COUNT | 39 |
[:arrow_up_small:](#)
<br />
## [mario_animation_ids.h](#mario_animation_ids.h)
### [enum MarioAnimID](#MarioAnimID)

View File

@ -626,6 +626,10 @@
- [get_network_area_timer](#get_network_area_timer)
- [hud_hide](#hud_hide)
- [hud_show](#hud_show)
- [warp_exit_level](#warp_exit_level)
- [warp_restart_level](#warp_restart_level)
- [warp_to_castle](#warp_to_castle)
- [warp_to_level](#warp_to_level)
<br />
@ -11499,6 +11503,86 @@ The `reliable` field will ensure that the packet arrives, but should be used spa
<br />
## [warp_exit_level](#warp_exit_level)
### Lua Example
`local boolValue = warp_exit_level(aDelay)`
### Parameters
| Field | Type |
| ----- | ---- |
| aDelay | `integer` |
### Returns
- `bool`
### C Prototype
`bool warp_exit_level(s32 aDelay);`
[:arrow_up_small:](#)
<br />
## [warp_restart_level](#warp_restart_level)
### Lua Example
`local boolValue = warp_restart_level()`
### Parameters
- None
### Returns
- `bool`
### C Prototype
`bool warp_restart_level(void);`
[:arrow_up_small:](#)
<br />
## [warp_to_castle](#warp_to_castle)
### Lua Example
`local boolValue = warp_to_castle(aLevel)`
### Parameters
| Field | Type |
| ----- | ---- |
| aLevel | `integer` |
### Returns
- `bool`
### C Prototype
`bool warp_to_castle(s32 aLevel);`
[:arrow_up_small:](#)
<br />
## [warp_to_level](#warp_to_level)
### Lua Example
`local boolValue = warp_to_level(aLevel, aArea, aAct)`
### Parameters
| Field | Type |
| ----- | ---- |
| aLevel | `integer` |
| aArea | `integer` |
| aAct | `integer` |
### Returns
- `bool`
### C Prototype
`bool warp_to_level(s32 aLevel, s32 aArea, s32 aAct);`
[:arrow_up_small:](#)
<br />
---
# functions from smlua_obj_utils.h

View File

@ -426,6 +426,7 @@ static struct LuaObjectField sGlobalTexturesFields[LUA_GLOBAL_TEXTURES_FIELD_COU
static struct LuaObjectField sGraphNodeFields[LUA_GRAPH_NODE_FIELD_COUNT] = {
{ "children", LVT_COBJECT_P, offsetof(struct GraphNode, children), false, LOT_GRAPHNODE },
{ "flags", LVT_S16, offsetof(struct GraphNode, flags), false, LOT_NONE },
// { "georef", LVT_???, offsetof(struct GraphNode, georef), true, LOT_??? }, <--- UNIMPLEMENTED
{ "next", LVT_COBJECT_P, offsetof(struct GraphNode, next), false, LOT_GRAPHNODE },
{ "parent", LVT_COBJECT_P, offsetof(struct GraphNode, parent), false, LOT_GRAPHNODE },
{ "prev", LVT_COBJECT_P, offsetof(struct GraphNode, prev), false, LOT_GRAPHNODE },

View File

@ -1514,6 +1514,46 @@ char gSmluaConstants[] = ""
"INT_STATUS_HIT_MINE = (1 << 21)\n"
"INT_STATUS_STOP_RIDING = (1 << 22)\n"
"INT_STATUS_TOUCHED_BOB_OMB = (1 << 23)\n"
"LEVEL_NONE = 0\n"
"LEVEL_UNKNOWN_1 = 1\n"
"LEVEL_UNKNOWN_2 = 2\n"
"LEVEL_UNKNOWN_3 = 3\n"
"LEVEL_BBH = 4\n"
"LEVEL_CCM = 5\n"
"LEVEL_CASTLE = 6\n"
"LEVEL_HMC = 7\n"
"LEVEL_SSL = 8\n"
"LEVEL_BOB = 9\n"
"LEVEL_SL = 10\n"
"LEVEL_WDW = 11\n"
"LEVEL_JRB = 12\n"
"LEVEL_THI = 13\n"
"LEVEL_TTC = 14\n"
"LEVEL_RR = 15\n"
"LEVEL_CASTLE_GROUNDS = 16\n"
"LEVEL_BITDW = 17\n"
"LEVEL_VCUTM = 18\n"
"LEVEL_BITFS = 19\n"
"LEVEL_SA = 20\n"
"LEVEL_BITS = 21\n"
"LEVEL_LLL = 22\n"
"LEVEL_DDD = 23\n"
"LEVEL_WF = 24\n"
"LEVEL_ENDING = 25\n"
"LEVEL_CASTLE_COURTYARD = 26\n"
"LEVEL_PSS = 27\n"
"LEVEL_COTMC = 28\n"
"LEVEL_TOTWC = 29\n"
"LEVEL_BOWSER_1 = 30\n"
"LEVEL_WMOTR = 31\n"
"LEVEL_UNKNOWN_32 = 32\n"
"LEVEL_BOWSER_2 = 33\n"
"LEVEL_BOWSER_3 = 34\n"
"LEVEL_UNKNOWN_35 = 35\n"
"LEVEL_TTM = 36\n"
"LEVEL_UNKNOWN_37 = 37\n"
"LEVEL_UNKNOWN_38 = 38\n"
"LEVEL_COUNT = 39\n"
"MARIO_ANIM_SLOW_LEDGE_GRAB = 0\n"
"MARIO_ANIM_FALL_OVER_BACKWARDS = 1\n"
"MARIO_ANIM_BACKWARD_AIR_KB = 2\n"

View File

@ -7322,6 +7322,52 @@ int smlua_func_hud_show(UNUSED lua_State* L) {
return 1;
}
int smlua_func_warp_exit_level(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 1)) { return 0; }
s32 aDelay = smlua_to_integer(L, 1);
if (!gSmLuaConvertSuccess) { return 0; }
lua_pushboolean(L, warp_exit_level(aDelay));
return 1;
}
int smlua_func_warp_restart_level(UNUSED lua_State* L) {
if(!smlua_functions_valid_param_count(L, 0)) { return 0; }
lua_pushboolean(L, warp_restart_level());
return 1;
}
int smlua_func_warp_to_castle(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 1)) { return 0; }
s32 aLevel = smlua_to_integer(L, 1);
if (!gSmLuaConvertSuccess) { return 0; }
lua_pushboolean(L, warp_to_castle(aLevel));
return 1;
}
int smlua_func_warp_to_level(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 3)) { return 0; }
s32 aLevel = smlua_to_integer(L, 1);
if (!gSmLuaConvertSuccess) { return 0; }
s32 aArea = smlua_to_integer(L, 2);
if (!gSmLuaConvertSuccess) { return 0; }
s32 aAct = smlua_to_integer(L, 3);
if (!gSmLuaConvertSuccess) { return 0; }
lua_pushboolean(L, warp_to_level(aLevel, aArea, aAct));
return 1;
}
///////////////////////
// smlua_obj_utils.h //
///////////////////////
@ -8638,6 +8684,10 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "get_network_area_timer", smlua_func_get_network_area_timer);
smlua_bind_function(L, "hud_hide", smlua_func_hud_hide);
smlua_bind_function(L, "hud_show", smlua_func_hud_show);
smlua_bind_function(L, "warp_exit_level", smlua_func_warp_exit_level);
smlua_bind_function(L, "warp_restart_level", smlua_func_warp_restart_level);
smlua_bind_function(L, "warp_to_castle", smlua_func_warp_to_castle);
smlua_bind_function(L, "warp_to_level", smlua_func_warp_to_level);
// smlua_obj_utils.h
smlua_bind_function(L, "obj_get_first", smlua_func_obj_get_first);

View File

@ -1,5 +1,6 @@
#include "types.h"
#include "data/dynos_coop.c.h"
#include "game/hud.h"
#include "pc/lua/smlua.h"
#include "smlua_misc_utils.h"
@ -17,3 +18,18 @@ void hud_show(void) {
gOverrideHideHud = 0;
}
bool warp_to_level(s32 aLevel, s32 aArea, s32 aAct) {
return dynos_warp_to_level(aLevel, aArea, aAct);
}
bool warp_restart_level(void) {
return dynos_warp_restart_level();
}
bool warp_exit_level(s32 aDelay) {
return dynos_warp_exit_level(aDelay);
}
bool warp_to_castle(s32 aLevel) {
return dynos_warp_to_castle(aLevel);
}

View File

@ -6,4 +6,9 @@ u32 get_network_area_timer(void);
void hud_hide(void);
void hud_show(void);
bool warp_to_level(s32 aLevel, s32 aArea, s32 aAct);
bool warp_restart_level(void);
bool warp_exit_level(s32 aDelay);
bool warp_to_castle(s32 aLevel);
#endif