From e44a3c775da8693198b5f39f8b29a4a84988d3db Mon Sep 17 00:00:00 2001 From: Isaac0-dev <62234577+Isaac0-dev@users.noreply.github.com> Date: Mon, 24 Apr 2023 02:10:30 +1000 Subject: [PATCH 1/3] allow players to change paginated pages with L/R (#354) --- src/pc/djui/djui_paginated.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/pc/djui/djui_paginated.c b/src/pc/djui/djui_paginated.c index 6401d813..ab4314cf 100644 --- a/src/pc/djui/djui_paginated.c +++ b/src/pc/djui/djui_paginated.c @@ -8,6 +8,9 @@ // events // //////////// +static bool lTrigDown = false; +static bool rTrigDown = false; + static struct DjuiButton* sPrevButton = NULL; static struct DjuiButton* sNextButton = NULL; static struct DjuiText* sPageNumText = NULL; @@ -106,6 +109,21 @@ bool djui_paginated_render(struct DjuiBase* base) { } djui_rect_render(base); + + OSContPad* pad = &gInteractablePad; + + if (pad->button & L_TRIG) { + lTrigDown = true; + } else if (pad->button & R_TRIG) { + rTrigDown = true; + } else if (lTrigDown) { + djui_paginated_prev(&paginated->prevButton->base); + lTrigDown = false; + } else if (rTrigDown) { + djui_paginated_next(&paginated->nextButton->base); + rTrigDown = false; + } + return true; } From 1e8dfa66fd77cba270c3ff6a4cfa2ff8d64f1cc2 Mon Sep 17 00:00:00 2001 From: Isaac0-dev <62234577+Isaac0-dev@users.noreply.github.com> Date: Mon, 24 Apr 2023 02:10:43 +1000 Subject: [PATCH 2/3] stop trapping cursor in window leaving fullscreen (#353) --- src/pc/gfx/gfx_sdl2.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pc/gfx/gfx_sdl2.c b/src/pc/gfx/gfx_sdl2.c index 2552064b..62277b3f 100644 --- a/src/pc/gfx/gfx_sdl2.c +++ b/src/pc/gfx/gfx_sdl2.c @@ -72,13 +72,16 @@ static void gfx_sdl_set_fullscreen(void) { SDL_SetWindowFullscreen(wnd, SDL_WINDOW_FULLSCREEN_DESKTOP); } else { SDL_SetWindowFullscreen(wnd, 0); + SDL_ShowCursor(1); configWindow.exiting_fullscreen = true; } } static void gfx_sdl_reset_dimension_and_pos(void) { - if (configWindow.exiting_fullscreen) + if (configWindow.exiting_fullscreen) { configWindow.exiting_fullscreen = false; + SDL_ShowCursor(0); + } if (configWindow.reset) { configWindow.x = WAPI_WIN_CENTERPOS; From df248e5139f9a8ce498742897255c9e48312ace4 Mon Sep 17 00:00:00 2001 From: PeachyPeach <72323920+PeachyPeachSM64@users.noreply.github.com> Date: Sun, 23 Apr 2023 18:11:56 +0200 Subject: [PATCH 3/3] Adding hazardType to HOOK_ALLOW_HAZARD_SURFACE; more loading info (#355) --- autogen/lua_definitions/constants.lua | 9 ++++++++ docs/lua/constants.md | 3 +++ docs/lua/guides/hooks.md | 2 +- include/surface_terrains.h | 4 ++++ src/game/interaction.c | 2 +- src/game/mario_actions_airborne.c | 2 +- src/game/mario_step.c | 2 +- src/pc/lua/smlua.c | 1 + src/pc/lua/smlua_cobject.c | 2 ++ src/pc/lua/smlua_constants_autogen.c | 3 +++ src/pc/lua/smlua_hooks.c | 33 +++++++++++++++++++++++++++ src/pc/lua/smlua_hooks.h | 1 + 12 files changed, 60 insertions(+), 4 deletions(-) diff --git a/autogen/lua_definitions/constants.lua b/autogen/lua_definitions/constants.lua index ee960c0d..37295519 100644 --- a/autogen/lua_definitions/constants.lua +++ b/autogen/lua_definitions/constants.lua @@ -10932,6 +10932,15 @@ SOUND_TERRAIN_WATER = 2 --- @type integer SOUND_VIBRATO = 0x2000000 +--- @type integer +HAZARD_TYPE_LAVA_FLOOR = 1 + +--- @type integer +HAZARD_TYPE_LAVA_WALL = 2 + +--- @type integer +HAZARD_TYPE_QUICKSAND = 3 + --- @type integer SURFACE_0004 = 0x0004 diff --git a/docs/lua/constants.md b/docs/lua/constants.md index a7b85f2a..d43fb20b 100644 --- a/docs/lua/constants.md +++ b/docs/lua/constants.md @@ -3876,6 +3876,9 @@
## [surface_terrains.h](#surface_terrains.h) +- HAZARD_TYPE_LAVA_FLOOR +- HAZARD_TYPE_LAVA_WALL +- HAZARD_TYPE_QUICKSAND - SURFACE_0004 - SURFACE_BOSS_FIGHT_CAMERA - SURFACE_BURNING diff --git a/docs/lua/guides/hooks.md b/docs/lua/guides/hooks.md index 61f6f005..8a3d7c53 100644 --- a/docs/lua/guides/hooks.md +++ b/docs/lua/guides/hooks.md @@ -113,7 +113,7 @@ The lua functions sent to `hook_event()` will be automatically called by SM64 wh | HOOK_USE_ACT_SELECT | Called when the level changes, return `true` to show act selection screen and `false` otherwise | `integer` levelNum | | HOOK_ON_CHANGE_CAMERA_ANGLE | Called when the player changes the camera mode to Lakitu cam or Mario cam, return `false` to prevent the change. | `integer` mode | | HOOK_ON_SCREEN_TRANSITION | Called when the game is about to play a transition, return `false` to prevent the transition from playing. | `integer` type | -| HOOK_ALLOW_HAZARD_SURFACE | Called once per player per frame. Return `false` to prevent the player from being affected by lava or quicksand. | [MarioState](structs.md#MarioState) mario | +| HOOK_ALLOW_HAZARD_SURFACE | Called once per player per frame. Return `false` to prevent the player from being affected by lava or quicksand. | [MarioState](structs.md#MarioState) mario, `integer` hazardType | | HOOK_ON_CHAT_MESSAGE | Called when a chat message gets sent. Return `false` to prevent the message from being sent. | [MarioState](structs.md#MarioState) messageSender, `string` messageSent | | HOOK_OBJECT_SET_MODEL | Called when a behavior changes models. Also runs when a behavior spawns. | [Object](structs.md#Object) obj, `integer` modelID | | HOOK_CHARACTER_SOUND | Called when mario retrieves a character sound to play, return a character sound or `0` to override it. | [MarioState](structs.md#MarioState) mario, [enum CharacterSound](constants.md#enum-CharacterSound) characterSound | diff --git a/include/surface_terrains.h b/include/surface_terrains.h index 8e4abe79..482e5940 100644 --- a/include/surface_terrains.h +++ b/include/surface_terrains.h @@ -165,6 +165,10 @@ #define SURFACE_FLAG_NO_CAM_COLLISION (1 << 1) #define SURFACE_FLAG_X_PROJECTION (1 << 3) +#define HAZARD_TYPE_LAVA_FLOOR 1 +#define HAZARD_TYPE_LAVA_WALL 2 +#define HAZARD_TYPE_QUICKSAND 3 + // These are effectively unique "surface" types like those defined higher // And they are used as collision commands to load certain functions #define TERRAIN_LOAD_VERTICES 0x0040 // Begins vertices list for collision triangles diff --git a/src/game/interaction.c b/src/game/interaction.c index 6c1ff96d..171a95f2 100644 --- a/src/game/interaction.c +++ b/src/game/interaction.c @@ -2319,7 +2319,7 @@ void check_death_barrier(struct MarioState *m) { void check_lava_boost(struct MarioState *m) { bool allow = true; - smlua_call_event_hooks_mario_param_ret_bool(HOOK_ALLOW_HAZARD_SURFACE, m, &allow); + smlua_call_event_hooks_mario_param_and_int_ret_bool(HOOK_ALLOW_HAZARD_SURFACE, m, HAZARD_TYPE_LAVA_FLOOR, &allow); if (m->action == ACT_BUBBLED || (gServerSettings.enableCheats && gCheats.godMode) || (!allow)) { return; } if (!(m->action & ACT_FLAG_RIDING_SHELL) && m->pos[1] < m->floorHeight + 10.0f) { if (!(m->flags & MARIO_METAL_CAP)) { diff --git a/src/game/mario_actions_airborne.c b/src/game/mario_actions_airborne.c index 5e20fb08..aede83b6 100644 --- a/src/game/mario_actions_airborne.c +++ b/src/game/mario_actions_airborne.c @@ -54,7 +54,7 @@ void play_knockback_sound(struct MarioState *m) { s32 lava_boost_on_wall(struct MarioState *m) { bool allow = true; - smlua_call_event_hooks_mario_param_ret_bool(HOOK_ALLOW_HAZARD_SURFACE, m, &allow); + smlua_call_event_hooks_mario_param_and_int_ret_bool(HOOK_ALLOW_HAZARD_SURFACE, m, HAZARD_TYPE_LAVA_WALL, &allow); if ((gServerSettings.enableCheats && gCheats.godMode) || (!allow)) { return FALSE; } m->faceAngle[1] = atan2s(m->wallNormal[2], m->wallNormal[0]); diff --git a/src/game/mario_step.c b/src/game/mario_step.c index 2fc36838..ba133951 100644 --- a/src/game/mario_step.c +++ b/src/game/mario_step.c @@ -110,7 +110,7 @@ void mario_bonk_reflection(struct MarioState *m, u32 negateSpeed) { u32 mario_update_quicksand(struct MarioState *m, f32 sinkingSpeed) { bool allow = true; - smlua_call_event_hooks_mario_param_ret_bool(HOOK_ALLOW_HAZARD_SURFACE, m, &allow); + smlua_call_event_hooks_mario_param_and_int_ret_bool(HOOK_ALLOW_HAZARD_SURFACE, m, HAZARD_TYPE_QUICKSAND, &allow); if (m->action & ACT_FLAG_RIDING_SHELL || (gServerSettings.enableCheats && gCheats.godMode && m->playerIndex == 0) || (!allow)) { m->quicksandDepth = 0.0f; } else { diff --git a/src/pc/lua/smlua.c b/src/pc/lua/smlua.c index 4e6af359..9c9c27d5 100644 --- a/src/pc/lua/smlua.c +++ b/src/pc/lua/smlua.c @@ -68,6 +68,7 @@ static void smlua_load_script(struct Mod* mod, struct ModFile* file, u16 remoteI gSmLuaConvertSuccess = true; gLuaInitializingScript = 1; + LOG_INFO("Loading lua script '%s'", file->cachedPath); if (luaL_loadfile(L, file->cachedPath) != LUA_OK) { LOG_LUA("Failed to load lua script '%s'.", file->cachedPath); LOG_LUA("%s", smlua_to_string(L, lua_gettop(L))); diff --git a/src/pc/lua/smlua_cobject.c b/src/pc/lua/smlua_cobject.c index a6fdb88d..86161bd2 100644 --- a/src/pc/lua/smlua_cobject.c +++ b/src/pc/lua/smlua_cobject.c @@ -276,6 +276,8 @@ static int smlua_func_define_custom_obj_fields(lua_State* L) { } lua_settable(L, -3); // set _custom_object_fields + LOG_INFO("Registered custom object field: %02X - %s", fieldIndex, node->key); + fieldIndex++; node = node->next; diff --git a/src/pc/lua/smlua_constants_autogen.c b/src/pc/lua/smlua_constants_autogen.c index 0e52988f..d8b649ef 100644 --- a/src/pc/lua/smlua_constants_autogen.c +++ b/src/pc/lua/smlua_constants_autogen.c @@ -3976,6 +3976,9 @@ char gSmluaConstants[] = "" "SURFACE_FLAG_DYNAMIC = (1 << 0)\n" "SURFACE_FLAG_NO_CAM_COLLISION = (1 << 1)\n" "SURFACE_FLAG_X_PROJECTION = (1 << 3)\n" +"HAZARD_TYPE_LAVA_FLOOR = 1\n" +"HAZARD_TYPE_LAVA_WALL = 2\n" +"HAZARD_TYPE_QUICKSAND = 3\n" "TERRAIN_LOAD_VERTICES = 0x0040\n" "TERRAIN_LOAD_CONTINUE = 0x0041\n" "TERRAIN_LOAD_END = 0x0042\n" diff --git a/src/pc/lua/smlua_hooks.c b/src/pc/lua/smlua_hooks.c index 11a21d06..c0a59bcc 100644 --- a/src/pc/lua/smlua_hooks.c +++ b/src/pc/lua/smlua_hooks.c @@ -711,6 +711,39 @@ void smlua_call_event_hooks_mario_action_params_ret_int(enum LuaHookedEventType } } +void smlua_call_event_hooks_mario_param_and_int_ret_bool(enum LuaHookedEventType hookType, struct MarioState* m, s32 param, bool* returnValue) { + lua_State* L = gLuaState; + if (L == NULL) { return; } + struct LuaHookedEvent* hook = &sHookedEvents[hookType]; + for (int i = 0; i < hook->count; i++) { + s32 prevTop = lua_gettop(L); + + // push the callback onto the stack + lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]); + + // push mario state + lua_getglobal(L, "gMarioStates"); + lua_pushinteger(L, m->playerIndex); + lua_gettable(L, -2); + lua_remove(L, -2); + + // push param + lua_pushinteger(L, param); + + // call the callback + if (0 != smlua_call_hook(L, 2, 1, 0, hook->mod[i])) { + LOG_LUA("Failed to call the callback: %u", hookType); + continue; + } + + // output the return value + if (lua_type(L, -1) == LUA_TBOOLEAN) { + *returnValue = smlua_to_boolean(L, -1); + } + lua_settop(L, prevTop); + } +} + //////////////////// // hooked actions // //////////////////// diff --git a/src/pc/lua/smlua_hooks.h b/src/pc/lua/smlua_hooks.h index b971d5f4..fb2a4423 100644 --- a/src/pc/lua/smlua_hooks.h +++ b/src/pc/lua/smlua_hooks.h @@ -118,6 +118,7 @@ void smlua_call_event_hooks_ret_bool(enum LuaHookedEventType hookType, bool* ret void smlua_call_event_hooks_on_chat_message(enum LuaHookedEventType hookType, struct MarioState* m, const char* message, bool* returnValue); bool smlua_call_event_hooks_mario_character_sound_param_ret_int(enum LuaHookedEventType hookType, struct MarioState* m, enum CharacterSound characterSound, s32* returnValue); void smlua_call_event_hooks_mario_action_params_ret_int(enum LuaHookedEventType hookType, struct MarioState *m, u32 action, u32* returnValue); +void smlua_call_event_hooks_mario_param_and_int_ret_bool(enum LuaHookedEventType hookType, struct MarioState* m, s32 param, bool* returnValue); enum BehaviorId smlua_get_original_behavior_id(const BehaviorScript* behavior); const BehaviorScript* smlua_override_behavior(const BehaviorScript* behavior);