mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2024-11-26 22:13:01 +00:00
level_script_parse now calls the callback for objects with custom behaviors (#342)
This commit is contained in:
parent
265a3c6b03
commit
892e48d3da
1 changed files with 74 additions and 36 deletions
|
@ -473,66 +473,104 @@ struct LuaLevelScriptParse {
|
||||||
struct LuaLevelScriptParse sLevelScriptParse = { 0 };
|
struct LuaLevelScriptParse sLevelScriptParse = { 0 };
|
||||||
|
|
||||||
s32 smlua_func_level_script_parse_callback(u8 type, void *cmd) {
|
s32 smlua_func_level_script_parse_callback(u8 type, void *cmd) {
|
||||||
if (type != 0x24 && type != 0x39 && type != 0x1F) {
|
u32 areaIndex, bhvId, bhvArgs;
|
||||||
return 0;
|
u32 *pAreaIndex = NULL, *pBhvId = NULL, *pBhvArgs = NULL;
|
||||||
|
MacroObject *pMacroData = NULL;
|
||||||
|
|
||||||
|
// Gather arguments
|
||||||
|
switch (type) {
|
||||||
|
|
||||||
|
// AREA
|
||||||
|
case 0x1F: {
|
||||||
|
areaIndex = (u8) dynos_level_cmd_get(cmd, 2);
|
||||||
|
pAreaIndex = &areaIndex;
|
||||||
|
} break;
|
||||||
|
|
||||||
|
// OBJECT_WITH_ACTS
|
||||||
|
case 0x24: {
|
||||||
|
const BehaviorScript *bhv = (const BehaviorScript *) dynos_level_cmd_get(cmd, 20);
|
||||||
|
if (bhv) {
|
||||||
|
bhvId = (u32) get_id_from_behavior(bhv);
|
||||||
|
bhvArgs = (u32) dynos_level_cmd_get(cmd, 16);
|
||||||
|
pBhvId = &bhvId;
|
||||||
|
pBhvArgs = &bhvArgs;
|
||||||
}
|
}
|
||||||
|
} break;
|
||||||
|
|
||||||
|
// OBJECT_WITH_ACTS_EXT
|
||||||
|
case 0x3F: {
|
||||||
|
const char *bhvStr = dynos_level_get_token(dynos_level_cmd_get(cmd, 20));
|
||||||
|
if (bhvStr) {
|
||||||
|
bhvId = (u32) smlua_get_any_integer_mod_variable(bhvStr);
|
||||||
|
bhvArgs = (u32) dynos_level_cmd_get(cmd, 16);
|
||||||
|
pBhvId = &bhvId;
|
||||||
|
pBhvArgs = &bhvArgs;
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
|
||||||
|
// OBJECT_WITH_ACTS_EXT2
|
||||||
|
case 0x40: {
|
||||||
|
const char *bhvStr = dynos_level_get_token(dynos_level_cmd_get(cmd, 24));
|
||||||
|
if (bhvStr) {
|
||||||
|
bhvId = (u32) smlua_get_any_integer_mod_variable(bhvStr);
|
||||||
|
bhvArgs = (u32) dynos_level_cmd_get(cmd, 16);
|
||||||
|
pBhvId = &bhvId;
|
||||||
|
pBhvArgs = &bhvArgs;
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
|
||||||
|
// MACRO_OBJECTS
|
||||||
|
case 0x39: {
|
||||||
|
pMacroData = (MacroObject *) dynos_level_cmd_get(cmd, 4);
|
||||||
|
} break;
|
||||||
|
|
||||||
|
// None of the above
|
||||||
|
default: return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retrieve Lua state
|
||||||
lua_State* L = gLuaState;
|
lua_State* L = gLuaState;
|
||||||
if (L == NULL) { return 0; }
|
if (L == NULL) { return 0; }
|
||||||
struct LuaLevelScriptParse* preprocess = &sLevelScriptParse;
|
struct LuaLevelScriptParse* preprocess = &sLevelScriptParse;
|
||||||
|
|
||||||
lua_rawgeti(L, LUA_REGISTRYINDEX, preprocess->reference);
|
lua_rawgeti(L, LUA_REGISTRYINDEX, preprocess->reference);
|
||||||
|
|
||||||
if (type == 0x1F) {
|
// Push 'areaIndex'
|
||||||
u8 area = (u8) dynos_level_cmd_get(cmd, 2);
|
if (pAreaIndex) {
|
||||||
lua_pushinteger(L, area);
|
lua_pushinteger(L, *pAreaIndex);
|
||||||
} else {
|
} else {
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == 0x24) {
|
// Push 'bhvData'
|
||||||
const BehaviorScript *bhv = (const BehaviorScript *) dynos_level_cmd_get(cmd, 20);
|
if (pBhvId && pBhvArgs) {
|
||||||
u32 behaviorArg = (u32) dynos_level_cmd_get(cmd, 16);
|
|
||||||
|
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
|
|
||||||
lua_pushstring(L, "behavior");
|
lua_pushstring(L, "behavior");
|
||||||
lua_pushinteger(L, get_id_from_behavior(bhv));
|
lua_pushinteger(L, *pBhvId);
|
||||||
lua_settable(L, -3);
|
lua_settable(L, -3);
|
||||||
|
|
||||||
lua_pushstring(L, "behaviorArg");
|
lua_pushstring(L, "behaviorArg");
|
||||||
lua_pushinteger(L, behaviorArg);
|
lua_pushinteger(L, *pBhvArgs);
|
||||||
lua_settable(L, -3);
|
lua_settable(L, -3);
|
||||||
} else {
|
} else {
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == 0x39) {
|
// Push 'macroBhvIds' and 'macroBhvArgs'
|
||||||
MacroObject *data = (MacroObject *) dynos_level_cmd_get(cmd, 4);
|
if (pMacroData) {
|
||||||
int i = 0;
|
|
||||||
s32 len = 0;
|
|
||||||
|
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
int t = lua_gettop(gLuaState);
|
s32 macroBhvIdsIdx = lua_gettop(gLuaState);
|
||||||
|
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
int args = lua_gettop(gLuaState);
|
s32 macroBhvArgsIdx = lua_gettop(gLuaState);
|
||||||
while (data[len++] != MACRO_OBJECT_END()) {
|
for (s32 i = 0; *pMacroData != MACRO_OBJECT_END(); pMacroData += 5, i++) {
|
||||||
s32 presetId = (s32) ((data[len - 1] & 0x1FF) - 0x1F);
|
s32 presetId = (s32) ((pMacroData[0] & 0x1FF) - 0x1F);
|
||||||
const BehaviorScript *bhv = (const BehaviorScript *) MacroObjectPresets[presetId].behavior;
|
|
||||||
s32 presetParams = MacroObjectPresets[presetId].param;
|
s32 presetParams = MacroObjectPresets[presetId].param;
|
||||||
s32 objParams = (data[4] & 0xFF00) + (presetParams & 0x00FF);
|
s32 objParams = (pMacroData[4] & 0xFF00) | (presetParams & 0x00FF);
|
||||||
u32 behaviorArg = ((objParams & 0x00FF) << 16) + (objParams & 0xFF00);
|
s32 bhvParams = ((objParams & 0x00FF) << 16) | (objParams & 0xFF00);
|
||||||
|
|
||||||
lua_pushinteger(L, i);
|
lua_pushinteger(L, i);
|
||||||
lua_pushinteger(L, get_id_from_behavior(bhv));
|
lua_pushinteger(L, get_id_from_behavior(MacroObjectPresets[presetId].behavior));
|
||||||
lua_settable(L, t);
|
lua_settable(L, macroBhvIdsIdx);
|
||||||
|
|
||||||
lua_pushinteger(L, i);
|
lua_pushinteger(L, i);
|
||||||
lua_pushinteger(L, behaviorArg);
|
lua_pushinteger(L, bhvParams);
|
||||||
lua_settable(L, args);
|
lua_settable(L, macroBhvArgsIdx);
|
||||||
|
|
||||||
i++;
|
|
||||||
len += 4;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
|
|
Loading…
Reference in a new issue