mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2026-04-22 10:01:46 +00:00
Fix get_texture_info and add HOOK_ON_DYNOS_PACKS_TOGGLED (#1181)
* respect overridden textures * add HOOK_ON_DYNOS_CHANGED * document HOOK_ON_DYNOS_CHANGED * HOOK_ON_DYNOS_CHANGED -> HOOK_ON_DYNOS_PACK_TOGGLED * Apply suggestions from code review Co-authored-by: Isaac0-dev <62234577+Isaac0-dev@users.noreply.github.com> * Update data/dynos_mgr_tex.cpp Co-authored-by: Isaac0-dev <62234577+Isaac0-dev@users.noreply.github.com> * add missing include * add pack name and enabled --------- Co-authored-by: Isaac0-dev <62234577+Isaac0-dev@users.noreply.github.com>
This commit is contained in:
parent
962ea72e41
commit
45bc3062be
9 changed files with 58 additions and 3 deletions
|
|
@ -8222,7 +8222,8 @@ HOOK_ON_FIND_FLOOR = 62 --- @type LuaHookedEventType
|
|||
HOOK_ON_FIND_WATER_LEVEL = 63 --- @type LuaHookedEventType
|
||||
HOOK_ON_FIND_POISON_GAS_LEVEL = 64 --- @type LuaHookedEventType
|
||||
HOOK_ON_FIND_SURFACE_ON_RAY = 65 --- @type LuaHookedEventType
|
||||
HOOK_MAX = 66 --- @type LuaHookedEventType
|
||||
HOOK_ON_DYNOS_PACK_TOGGLED = 66 --- @type LuaHookedEventType
|
||||
HOOK_MAX = 67 --- @type LuaHookedEventType
|
||||
|
||||
--- @alias LuaHookedEventType
|
||||
--- | `HOOK_UPDATE`
|
||||
|
|
@ -8291,6 +8292,7 @@ HOOK_MAX = 66 --- @type LuaHookedEventType
|
|||
--- | `HOOK_ON_FIND_WATER_LEVEL`
|
||||
--- | `HOOK_ON_FIND_POISON_GAS_LEVEL`
|
||||
--- | `HOOK_ON_FIND_SURFACE_ON_RAY`
|
||||
--- | `HOOK_ON_DYNOS_PACK_TOGGLED`
|
||||
--- | `HOOK_MAX`
|
||||
|
||||
--- @type integer
|
||||
|
|
|
|||
|
|
@ -502,6 +502,22 @@ bool DynOS_Tex_Get(const char* aTexName, struct TextureInfo* aOutTexInfo) {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// check override
|
||||
auto &_DynosOverrideTextures = DynosOverrideTextures();
|
||||
auto it = _DynosOverrideTextures.find(info->texture);
|
||||
if (it != _DynosOverrideTextures.end() && it->second) {
|
||||
auto *_Node = it->second->node;
|
||||
auto &_Data = _Node->mData;
|
||||
CONVERT_TEXINFO(aTexName);
|
||||
|
||||
// must link to the vanilla built in texture
|
||||
// so that the texture is correctly overridden
|
||||
// when DynOS_Tex_RetrieveNode is called.
|
||||
aOutTexInfo->texture = info->texture;
|
||||
return true;
|
||||
}
|
||||
|
||||
*aOutTexInfo = *info;
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3546,7 +3546,8 @@
|
|||
| HOOK_ON_FIND_WATER_LEVEL | 63 |
|
||||
| HOOK_ON_FIND_POISON_GAS_LEVEL | 64 |
|
||||
| HOOK_ON_FIND_SURFACE_ON_RAY | 65 |
|
||||
| HOOK_MAX | 66 |
|
||||
| HOOK_ON_DYNOS_PACK_TOGGLED | 66 |
|
||||
| HOOK_MAX | 67 |
|
||||
- MAX_HOOKED_BEHAVIORS
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
|
|
|||
|
|
@ -157,6 +157,7 @@ The lua functions sent to `hook_event()` will be automatically called by SM64 wh
|
|||
| HOOK_ON_FIND_WATER_LEVEL | Called after water level detection completes. Return a number to override the water level | `number` x, `number` z, `number` waterLevel |
|
||||
| HOOK_ON_FIND_POISON_GAS_LEVEL | Called after poison gas level detection completes. Return a number to override the gas level | `number` x, `number` z, `number` gasLevel |
|
||||
| HOOK_ON_FIND_SURFACE_ON_RAY | Called after ray-surface intersection completes. Return `surface` to override the hit surface, or `surface, hitPos` to override both | `Vec3f` orig, `Vec3f` dir, [Surface](../structs.md#Surface) hitSurface, `Vec3f` hitPos |
|
||||
| HOOK_ON_DYNOS_PACK_TOGGLED | Called after a DynOS pack is toggled | `string` dynosPackName, `boolean` enabled |
|
||||
|
||||
### Parameters
|
||||
|
||||
|
|
|
|||
|
|
@ -8,11 +8,13 @@
|
|||
#include "djui_panel_main.h"
|
||||
#include "djui_panel_options.h"
|
||||
#include "game/level_update.h"
|
||||
#include "pc/lua/smlua_hooks.h"
|
||||
|
||||
void djui_panel_dynos_create(struct DjuiBase* caller);
|
||||
|
||||
static void djui_panel_dynos_apply(struct DjuiBase* caller) {
|
||||
dynos_pack_set_enabled(caller->tag, caller->bTag);
|
||||
smlua_call_event_hooks(HOOK_ON_DYNOS_PACK_TOGGLED, dynos_pack_get_name(caller->tag), caller->bTag);
|
||||
}
|
||||
|
||||
static void djui_panel_dynos_local_player_model_only(UNUSED struct DjuiBase* caller) {
|
||||
|
|
|
|||
|
|
@ -3556,7 +3556,8 @@ char gSmluaConstants[] = ""
|
|||
"HOOK_ON_FIND_WATER_LEVEL=63\n"
|
||||
"HOOK_ON_FIND_POISON_GAS_LEVEL=64\n"
|
||||
"HOOK_ON_FIND_SURFACE_ON_RAY=65\n"
|
||||
"HOOK_MAX=66\n"
|
||||
"HOOK_ON_DYNOS_PACK_TOGGLED=66\n"
|
||||
"HOOK_MAX=67\n"
|
||||
"MAX_HOOKED_BEHAVIORS=1024\n"
|
||||
"HUD_DISPLAY_LIVES=0\n"
|
||||
"HUD_DISPLAY_COINS=1\n"
|
||||
|
|
|
|||
|
|
@ -64,3 +64,4 @@ SMLUA_EVENT_HOOK(HOOK_ON_FIND_FLOOR, _, f32 posX, f32 posY, f32 posZ, struct Sur
|
|||
SMLUA_EVENT_HOOK(HOOK_ON_FIND_WATER_LEVEL, _, f32 x, f32 z, f32 *waterLevel) // Manually defined hook
|
||||
SMLUA_EVENT_HOOK(HOOK_ON_FIND_POISON_GAS_LEVEL, _, f32 x, f32 z, f32 *gasLevel) // Manually defined hook
|
||||
SMLUA_EVENT_HOOK(HOOK_ON_FIND_SURFACE_ON_RAY, _, Vec3f orig, Vec3f dir, struct Surface **hit_surface, Vec3f hit_pos) // Manually defined hook
|
||||
SMLUA_EVENT_HOOK(HOOK_ON_DYNOS_PACK_TOGGLED, HOOK_RETURN_NEVER, const char *dynosPackName, bool enabled)
|
||||
|
|
|
|||
|
|
@ -1863,3 +1863,33 @@ bool smlua_call_event_hooks_HOOK_ON_PACKET_BYTESTRING_RECEIVE(s32 modIndex, s32
|
|||
}
|
||||
return hookResult;
|
||||
}
|
||||
|
||||
bool smlua_call_event_hooks_HOOK_ON_DYNOS_PACK_TOGGLED(const char *dynosPackName, bool enabled) {
|
||||
lua_State *L = gLuaState;
|
||||
if (L == NULL) { return false; }
|
||||
bool hookResult = false;
|
||||
|
||||
struct LuaHookedEvent *hook = &sHookedEvents[HOOK_ON_DYNOS_PACK_TOGGLED];
|
||||
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 dynosPackName
|
||||
lua_pushstring(L, dynosPackName);
|
||||
|
||||
// push enabled
|
||||
lua_pushboolean(L, enabled);
|
||||
|
||||
// call the callback
|
||||
if (0 != smlua_call_hook(L, 2, 0, 0, hook->mod[i], hook->modFile[i])) {
|
||||
LOG_LUA("Failed to call the callback for hook %s - '%s/%s'", sLuaHookedEventTypeName[HOOK_ON_DYNOS_PACK_TOGGLED], hook->mod[i]->relativePath, hook->modFile[i]->relativePath);
|
||||
continue;
|
||||
}
|
||||
hookResult = true;
|
||||
|
||||
lua_settop(L, prevTop);
|
||||
}
|
||||
return hookResult;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,6 +82,7 @@ enum LuaHookedEventType {
|
|||
HOOK_ON_FIND_WATER_LEVEL,
|
||||
HOOK_ON_FIND_POISON_GAS_LEVEL,
|
||||
HOOK_ON_FIND_SURFACE_ON_RAY,
|
||||
HOOK_ON_DYNOS_PACK_TOGGLED,
|
||||
HOOK_MAX,
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue