Added custom level script overrides, warps work now

This commit is contained in:
MysterD 2022-04-08 19:29:16 -07:00
parent 1a3bd3c685
commit 403bf30be9
13 changed files with 78 additions and 91 deletions

View file

@ -7105,12 +7105,6 @@ function set_environment_region(index, value)
-- ...
end
--- @param name string
--- @return Pointer_LevelScript
function smlua_level_util_get(name)
-- ...
end
--- @param aDelay integer
--- @return boolean
function warp_exit_level(aDelay)
@ -7447,4 +7441,3 @@ end
--- @class Pointer_BehaviorScript
--- @class Pointer_number
--- @class Pointer_Collision
--- @class Pointer_LevelScript

View file

@ -6,6 +6,8 @@
#include "types.h"
#include "src/game/moving_texture.h"
void *dynos_swap_cmd(void *cmd);
// -- built in -- //
void *dynos_update_cmd (void *cmd);
void dynos_update_gfx ();
@ -36,7 +38,6 @@ Collision* dynos_collision_get(const char* collisionName);
// -- levels -- //
void dynos_add_level(s32 modIndex, const char *modPath, const char* levelName);
LevelScript* dynos_level_get(const char* levelName);
const char* dynos_level_get_token(u32 index);
struct MovtexQuadCollection *dynos_level_get_movtexqc(s32 index);
void dynos_level_load_background(void *ptr);

View file

@ -638,6 +638,7 @@ static type &__##name() { \
//
void DynOS_UpdateOpt(void *aPad);
void *DynOS_SwapCmd(void *aCmd);
void *DynOS_UpdateCmd(void *aCmd);
void DynOS_UpdateGfx();
bool DynOS_IsTransitionActive();
@ -697,6 +698,7 @@ void *DynOS_Geo_GetGraphNode(const void *aGeoLayout, bool aKeepInMemory);
s32 DynOS_Level_GetCount();
const s32 *DynOS_Level_GetList();
s32 DynOS_Level_GetCourse(s32 aLevel);
void DynOS_Level_Override(void* originalScript, void* newScript);
const void *DynOS_Level_GetScript(s32 aLevel);
const u8 *DynOS_Level_GetName(s32 aLevel, bool aDecaps, bool aAddCourseNumber);
const u8 *DynOS_Level_GetActName(s32 aLevel, s32 aAct, bool aDecaps, bool aAddStarNumber);
@ -756,12 +758,11 @@ bool DynOS_Actor_IsCustom(s32 aIndex);
Array<Pair<const char*, GfxData*>> &DynOS_Lvl_GetArray();
void DynOS_Lvl_Activate(s32 modIndex, const SysPath &aPackFolder, const char *aLevelName);
LevelScript* DynOS_Lvl_GetScript(const char* levelName);
s32 DynOS_Lvl_GetModIndex(void* levelScript);
DataNode<TexData> *DynOS_Lvl_GetTexture(void *aPtr);
const char* DynOS_Lvl_GetToken(u32 index);
DataNode<MovtexQC> *DynOS_Lvl_GetMovtexQuadCollection(s32 index);
void DynOS_Lvl_LoadBackground(void *aPtr);
void *DynOS_Lvl_Override(void *aCmd);
//
// Col Manager

View file

@ -2,6 +2,10 @@
extern "C" {
#include "src/game/moving_texture.h"
void *dynos_swap_cmd(void *cmd) {
return DynOS_SwapCmd(cmd);
}
// -- built in -- //
void *dynos_update_cmd(void *cmd) {
@ -104,10 +108,6 @@ void dynos_add_level(s32 modIndex, const char *modPath, const char* levelName) {
DynOS_Lvl_Activate(modIndex, modPath, levelName);
}
LevelScript* dynos_level_get(const char* levelName) {
return DynOS_Lvl_GetScript(levelName);
}
const char* dynos_level_get_token(u32 index) {
return DynOS_Lvl_GetToken(index);
}

View file

@ -225,17 +225,19 @@ s32 DynOS_Level_GetCourse(s32 aLevel) {
return (s32) gLevelToCourseNumTable[aLevel - 1];
}
void DynOS_Level_Override(void* originalScript, void* newScript) {
for (s32 i = 0; i < LEVEL_COUNT; i++) {
if (sDynosLevelScripts[i] == originalScript) {
sDynosLevelWarps[i].Clear();
DynOS_Level_ParseScript(newScript, DynOS_Level_PreprocessScript);
sDynosLevelScripts[i] = newScript;
return;
}
}
}
const void *DynOS_Level_GetScript(s32 aLevel) {
DynOS_Level_Init();
if (aLevel != LEVEL_WDW) {
LevelScript* script = DynOS_Lvl_GetScript("");
sDynosCurrentLevelNum = aLevel;
sDynosLevelWarps[sDynosCurrentLevelNum].Clear();
DynOS_Level_ParseScript(script, DynOS_Level_PreprocessScript);
gLevelScriptModIndex = DynOS_Lvl_GetModIndex(script);
gLevelScriptActive = (LevelScript*)script;
return script; // DO NOT COMMIT
}
return sDynosLevelScripts[aLevel];
}

View file

@ -49,6 +49,10 @@ void DynOS_UpdateOpt(void *aPad) {
gPrevFrameObjectCount = 0;
}
void *DynOS_SwapCmd(void *aCmd) {
return DynOS_Lvl_Override(aCmd);
}
void *DynOS_UpdateCmd(void *aCmd) {
static const uintptr_t sCmdLevelEntry[] = { CALL(0, lvl_init_or_update) };
sDynosIsLevelEntry |= (memcmp(aCmd, sCmdLevelEntry, sizeof(sCmdLevelEntry)) == 0);

View file

@ -122,6 +122,36 @@ static const void* sDynosBuiltinScriptPtrs[] = {
define_builtin(script_func_global_16),
define_builtin(script_func_global_17),
define_builtin(script_func_global_18),
define_builtin(level_bbh_entry),
define_builtin(level_bitdw_entry),
define_builtin(level_bitfs_entry),
define_builtin(level_bits_entry),
define_builtin(level_bob_entry),
define_builtin(level_bowser_1_entry),
define_builtin(level_bowser_2_entry),
define_builtin(level_bowser_3_entry),
define_builtin(level_castle_courtyard_entry),
define_builtin(level_castle_grounds_entry),
define_builtin(level_castle_inside_entry),
define_builtin(level_ccm_entry),
define_builtin(level_cotmc_entry),
define_builtin(level_ddd_entry),
define_builtin(level_hmc_entry),
define_builtin(level_jrb_entry),
define_builtin(level_lll_entry),
define_builtin(level_pss_entry),
define_builtin(level_rr_entry),
define_builtin(level_sa_entry),
define_builtin(level_sl_entry),
define_builtin(level_ssl_entry),
define_builtin(level_thi_entry),
define_builtin(level_totwc_entry),
define_builtin(level_ttc_entry),
define_builtin(level_ttm_entry),
define_builtin(level_vcutm_entry),
define_builtin(level_wdw_entry),
define_builtin(level_wf_entry),
define_builtin(level_wmotr_entry),
};
const void* DynOS_Builtin_ScriptPtr_GetFromName(const char* aDataName) {

View file

@ -5,6 +5,7 @@ extern "C" {
}
static Array<Pair<const char*, GfxData*>> sDynosCustomLevelScripts;
static Array<Pair<const void*, const void*>> sDynosOverrideLevelScripts;
Array<Pair<const char*, GfxData*>> &DynOS_Lvl_GetArray() {
return sDynosCustomLevelScripts;
@ -33,36 +34,18 @@ void DynOS_Lvl_Activate(s32 modIndex, const SysPath &aPackFolder, const char *aL
// Add to levels
sDynosCustomLevelScripts.Add({ levelName, _Node });
}
LevelScript* DynOS_Lvl_GetScript(const char* levelName) {
if (strlen(levelName) == 0) {
static u32 index = 0; // DO NOT COMMIT
s32 levelScriptCount = sDynosCustomLevelScripts.Count(); // DO NOT COMMIT
if (levelScriptCount < 1) { return NULL; } // DO NOT COMMIT
index = (index + 1) % levelScriptCount; // DO NOT COMMIT
auto& scripts = sDynosCustomLevelScripts[index].second->mLevelScripts; // DO NOT COMMIT
Print("Going to level: %s\n", scripts[scripts.Count() - 1]->mName); // DO NOT COMMIT
return scripts[scripts.Count() - 1]->mData; // DO NOT COMMIT
// Override vanilla script
auto& newScripts = _Node->mLevelScripts; // DO NOT COMMIT
auto& newScriptNode = newScripts[newScripts.Count() - 1];
const void* originalScript = DynOS_Builtin_ScriptPtr_GetFromName(newScriptNode->mName.begin());
if (originalScript == NULL) {
Print("Could not find level to override: '%s'", newScriptNode->mName);
return;
}
for (s32 i = 0; i < sDynosCustomLevelScripts.Count(); ++i) {
if (!strcmp(sDynosCustomLevelScripts[i].first, levelName)) {
auto& scripts = sDynosCustomLevelScripts[i].second->mLevelScripts;
return scripts[scripts.Count() - 1]->mData;
}
}
return NULL;
}
s32 DynOS_Lvl_GetModIndex(void* levelScript) {
for (s32 i = 0; i < sDynosCustomLevelScripts.Count(); ++i) {
auto& scripts = sDynosCustomLevelScripts[i].second->mLevelScripts;
if (levelScript == scripts[scripts.Count() - 1]->mData) {
return sDynosCustomLevelScripts[i].second->mModIndex;
}
}
return -1;
DynOS_Level_Override((void*)originalScript, newScriptNode->mData);
sDynosOverrideLevelScripts.Add({ originalScript, newScriptNode->mData});
}
DataNode<TexData> *DynOS_Lvl_GetTexture(void *aPtr) {
@ -154,3 +137,16 @@ double_break:
}
}
}
void *DynOS_Lvl_Override(void *aCmd) {
for (auto& overridePair : sDynosOverrideLevelScripts) {
if (aCmd == overridePair.first || aCmd == overridePair.second) {
aCmd = (void*)overridePair.second;
for (auto& customPair : sDynosCustomLevelScripts) {
gLevelScriptModIndex = customPair.second->mModIndex;
gLevelScriptActive = (LevelScript*)aCmd;
}
}
}
return aCmd;
}

View file

@ -1321,7 +1321,6 @@
- [hud_hide](#hud_hide)
- [hud_show](#hud_show)
- [set_environment_region](#set_environment_region)
- [smlua_level_util_get](#smlua_level_util_get)
- [warp_exit_level](#warp_exit_level)
- [warp_restart_level](#warp_restart_level)
- [warp_to_castle](#warp_to_castle)
@ -24828,26 +24827,6 @@ The `reliable` field will ensure that the packet arrives, but should be used spa
<br />
## [smlua_level_util_get](#smlua_level_util_get)
### Lua Example
`local PointerValue = smlua_level_util_get(name)`
### Parameters
| Field | Type |
| ----- | ---- |
| name | `string` |
### Returns
- `Pointer` <`LevelScript`>
### C Prototype
`LevelScript* smlua_level_util_get(const char* name);`
[:arrow_up_small:](#)
<br />
## [warp_exit_level](#warp_exit_level)
### Lua Example

View file

@ -1015,6 +1015,7 @@ struct LevelCommand *level_script_execute(struct LevelCommand *cmd) {
sCurrentCmd = cmd;
while (sScriptStatus == SCRIPT_RUNNING) {
sCurrentCmd = dynos_swap_cmd(sCurrentCmd);
void *dynosCurrCmd = (void *) sCurrentCmd;
LevelScriptJumpTable[sCurrentCmd->type]();
void *dynosNextCmd = dynos_update_cmd(dynosCurrCmd);

View file

@ -14766,17 +14766,6 @@ int smlua_func_set_environment_region(lua_State* L) {
return 1;
}
int smlua_func_smlua_level_util_get(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 1)) { return 0; }
const char* name = smlua_to_string(L, 1);
if (!gSmLuaConvertSuccess) { return 0; }
smlua_push_pointer(L, LVT_LEVELSCRIPT_P, (void*)smlua_level_util_get(name));
return 1;
}
int smlua_func_warp_exit_level(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 1)) { return 0; }
@ -16811,7 +16800,6 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "hud_hide", smlua_func_hud_hide);
smlua_bind_function(L, "hud_show", smlua_func_hud_show);
smlua_bind_function(L, "set_environment_region", smlua_func_set_environment_region);
smlua_bind_function(L, "smlua_level_util_get", smlua_func_smlua_level_util_get);
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);

View file

@ -90,12 +90,6 @@ s16 get_current_save_file_num(void) {
///
LevelScript* smlua_level_util_get(const char* name) {
return dynos_level_get(name);
}
///
f32 get_environment_region(u8 index) {
if (gEnvironmentRegions != NULL && index <= gEnvironmentRegions[0]) {
return gEnvironmentRegions[6 * (int)index];

View file

@ -22,8 +22,6 @@ f32 get_hand_foot_pos_z(struct MarioState* m, u8 index);
s16 get_current_save_file_num(void);
LevelScript* smlua_level_util_get(const char* name);
f32 get_environment_region(u8 index);
void set_environment_region(u8 index, s32 value);