diff --git a/autogen/lua_definitions/manual.lua b/autogen/lua_definitions/manual.lua index 309c3fe3b..e7de31ddf 100644 --- a/autogen/lua_definitions/manual.lua +++ b/autogen/lua_definitions/manual.lua @@ -74,6 +74,12 @@ function hook_chat_command(command, description, func) -- ... end +--- @param command string +--- @param description string +function update_chat_command_description(command, description) + -- ... +end + --- @param hookEventType LuaHookedEventType --- @param func function function hook_event(hookEventType, func) diff --git a/data/dynos_mgr_lvl.cpp b/data/dynos_mgr_lvl.cpp index e7871689a..7645f8491 100644 --- a/data/dynos_mgr_lvl.cpp +++ b/data/dynos_mgr_lvl.cpp @@ -181,6 +181,15 @@ void *DynOS_Lvl_Override(void *aCmd) { gLevelScriptActive = (LevelScript*)aCmd; } } + + auto& _CustomLevelScripts = DynOS_Lvl_GetArray(); + for (auto& script : _CustomLevelScripts) { + if (aCmd == script.second->mLevelScripts[0]->mData) { + gLevelScriptModIndex = script.second->mModIndex; + gLevelScriptActive = (LevelScript*)aCmd; + } + } + return aCmd; } diff --git a/mods/arena/levels/level_arena_forts_entry.lvl b/mods/arena/levels/level_arena_forts_entry.lvl new file mode 100644 index 000000000..a39c627dc Binary files /dev/null and b/mods/arena/levels/level_arena_forts_entry.lvl differ diff --git a/mods/arena/levels/level_arena_origin_entry.lvl b/mods/arena/levels/level_arena_origin_entry.lvl new file mode 100644 index 000000000..aad504dcf Binary files /dev/null and b/mods/arena/levels/level_arena_origin_entry.lvl differ diff --git a/mods/arena/levels/level_arena_pillars_entry.lvl b/mods/arena/levels/level_arena_pillars_entry.lvl new file mode 100644 index 000000000..729676768 Binary files /dev/null and b/mods/arena/levels/level_arena_pillars_entry.lvl differ diff --git a/mods/arena/levels/level_arena_platforms_entry.lvl b/mods/arena/levels/level_arena_platforms_entry.lvl new file mode 100644 index 000000000..0079a42b3 Binary files /dev/null and b/mods/arena/levels/level_arena_platforms_entry.lvl differ diff --git a/mods/arena/levels/level_arena_sky_beach_entry.lvl b/mods/arena/levels/level_arena_sky_beach_entry.lvl new file mode 100644 index 000000000..88d2bdbdc Binary files /dev/null and b/mods/arena/levels/level_arena_sky_beach_entry.lvl differ diff --git a/mods/arena/levels/level_bob_entry.lvl b/mods/arena/levels/level_bob_entry.lvl deleted file mode 100644 index d32aecc9d..000000000 Binary files a/mods/arena/levels/level_bob_entry.lvl and /dev/null differ diff --git a/mods/arena/levels/level_ccm_entry.lvl b/mods/arena/levels/level_ccm_entry.lvl deleted file mode 100644 index 49f331c8c..000000000 Binary files a/mods/arena/levels/level_ccm_entry.lvl and /dev/null differ diff --git a/mods/arena/levels/level_ddd_entry.lvl b/mods/arena/levels/level_ddd_entry.lvl deleted file mode 100644 index 739ae5cf9..000000000 Binary files a/mods/arena/levels/level_ddd_entry.lvl and /dev/null differ diff --git a/mods/arena/levels/level_jrb_entry.lvl b/mods/arena/levels/level_jrb_entry.lvl deleted file mode 100644 index 11121132e..000000000 Binary files a/mods/arena/levels/level_jrb_entry.lvl and /dev/null differ diff --git a/mods/arena/levels/level_wf_entry.lvl b/mods/arena/levels/level_wf_entry.lvl deleted file mode 100644 index 6d9b68ecb..000000000 Binary files a/mods/arena/levels/level_wf_entry.lvl and /dev/null differ diff --git a/mods/arena/main.lua b/mods/arena/main.lua index 7ffda1b14..1ee3eaf16 100644 --- a/mods/arena/main.lua +++ b/mods/arena/main.lua @@ -23,19 +23,27 @@ gGameModes = { [GAME_MODE_TKOTH] = { shortName = 'TKOTH', name = 'Team King of the Hill', teams = true, teamSpawns = false, useScore = true, scoreCap = 90, minPlayers = 4, maxPlayers = 99 }, } -gGameLevels = { - { level = LEVEL_BOB, name = 'Origin' }, - { level = LEVEL_CCM, name = 'Sky Beach' }, - { level = LEVEL_WF, name = 'Pillars' }, - { level = LEVEL_JRB, name = 'Forts' }, - { level = LEVEL_DDD, name = 'Platforms' }, +LEVEL_ARENA_ORIGIN = level_register('level_arena_origin_entry', COURSE_NONE, 'Origin', 'origin', 28000, 0x28, 0x28, 0x28) +LEVEL_ARENA_SKY_BEACH = level_register('level_arena_sky_beach_entry', COURSE_NONE, 'Sky Beach', 'beach', 28000, 0x28, 0x28, 0x28) +LEVEL_ARENA_PILLARS = level_register('level_arena_pillars_entry', COURSE_NONE, 'Pillars', 'pillars', 28000, 0x28, 0x28, 0x28) +LEVEL_ARENA_FORTS = level_register('level_arena_forts_entry', COURSE_NONE, 'Forts', 'forts', 28000, 0x28, 0x28, 0x28) +LEVEL_ARENA_PLATFORMS = level_register('level_arena_platforms_entry', COURSE_NONE, 'Platforms', 'platforms', 28000, 0x28, 0x28, 0x28) + +local gGameLevels = { + { level = LEVEL_ARENA_ORIGIN, name = 'Origin' }, + { level = LEVEL_ARENA_SKY_BEACH, name = 'Sky Beach' }, + { level = LEVEL_ARENA_PILLARS, name = 'Pillars' }, + { level = LEVEL_ARENA_FORTS, name = 'Forts' }, + { level = LEVEL_ARENA_PLATFORMS, name = 'Platforms' }, } -smlua_text_utils_course_acts_replace(COURSE_BOB, " 1 Origin", "?", "?", "?", "?", "?", "?") -smlua_text_utils_course_acts_replace(COURSE_CCM, " 4 Sky Beach", "?", "?", "?", "?", "?", "?") -smlua_text_utils_course_acts_replace(COURSE_WF, " 2 Pillars", "?", "?", "?", "?", "?", "?") -smlua_text_utils_course_acts_replace(COURSE_JRB, " 3 Forts", "?", "?", "?", "?", "?", "?") -smlua_text_utils_course_acts_replace(COURSE_DDD, " 4 Platforms", "?", "?", "?", "?", "?", "?") +-- expose certain functions to other mods +_G.Arena = { + add_level = function (levelNum, levelName) + table.insert(gGameLevels, { level = levelNum, name = levelName }) + update_chat_command_description('arena-level', string.format('[%s] sets level', get_level_choices())) + end +} -- setup global sync table gGlobalSyncTable.gameState = GAME_STATE_ACTIVE @@ -466,7 +474,6 @@ function on_gamemode_command(msg) end function on_level_command(msg) - local setLevel = nil for i, gl in ipairs(gGameLevels) do @@ -498,15 +505,18 @@ for i, gm in ipairs(gGameModes) do sGameModeShortTimes = sGameModeShortTimes .. gm.shortName end -sLevelChoices = '' -for i, gl in ipairs(gGameLevels) do - if string.len(sLevelChoices) > 0 then - sLevelChoices = sLevelChoices .. '|' +function get_level_choices() + local levelChoices = '' + for i, gl in ipairs(gGameLevels) do + if string.len(levelChoices) > 0 then + levelChoices = levelChoices .. '|' + end + levelChoices = levelChoices .. gl.name end - sLevelChoices = sLevelChoices .. gl.name + return levelChoices end if network_is_server() then hook_chat_command('arena-gamemode', string.format("[%s|random] sets gamemode", sGameModeShortTimes), on_gamemode_command) - hook_chat_command('arena-level', string.format('[%s] sets level', sLevelChoices), on_level_command) + hook_chat_command('arena-level', string.format('[%s] sets level', get_level_choices()), on_level_command) end diff --git a/src/pc/lua/smlua_hooks.c b/src/pc/lua/smlua_hooks.c index cec32e637..a039fba4c 100644 --- a/src/pc/lua/smlua_hooks.c +++ b/src/pc/lua/smlua_hooks.c @@ -1277,6 +1277,37 @@ int smlua_hook_chat_command(lua_State* L) { return 1; } +int smlua_update_chat_command_description(lua_State* L) { + if (L == NULL) { return 0; } + if (!smlua_functions_valid_param_count(L, 2)) { return 0; } + + const char* command = smlua_to_string(L, 1); + if (command == NULL || strlen(command) == 0 || !gSmLuaConvertSuccess) { + LOG_LUA_LINE("Update chat command: tried to update invalid command"); + return 0; + } + + const char* description = smlua_to_string(L, 2); + if (description == NULL || strlen(description) == 0 || !gSmLuaConvertSuccess) { + LOG_LUA_LINE("Update chat command: tried to update invalid description"); + return 0; + } + + for (int i = 0; i < sHookedChatCommandsCount; i++) { + struct LuaHookedChatCommand* hook = &sHookedChatCommands[i]; + if (!strcmp(hook->command, command)) { + if (hook->description) { + free(hook->description); + } + hook->description = strdup(description); + return 1; + } + } + + LOG_LUA_LINE("Update chat command: could not find command to update"); + return 0; +} + bool smlua_call_chat_command_hook(char* command) { lua_State* L = gLuaState; if (L == NULL) { return false; } @@ -1470,4 +1501,5 @@ void smlua_bind_hooks(void) { smlua_bind_function(L, "hook_chat_command", smlua_hook_chat_command); smlua_bind_function(L, "hook_on_sync_table_change", smlua_hook_on_sync_table_change); smlua_bind_function(L, "hook_behavior", smlua_hook_behavior); + smlua_bind_function(L, "update_chat_command_description", smlua_update_chat_command_description); }