Merge branch 'coop' of github.com:sm64ex-coop-dev/sm64ex-coop into coop

This commit is contained in:
MysterD 2023-04-23 13:54:39 -07:00
commit b7ab7c0c54
14 changed files with 82 additions and 5 deletions

View file

@ -10932,6 +10932,15 @@ SOUND_TERRAIN_WATER = 2
--- @type integer --- @type integer
SOUND_VIBRATO = 0x2000000 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 --- @type integer
SURFACE_0004 = 0x0004 SURFACE_0004 = 0x0004

View file

@ -3876,6 +3876,9 @@
<br /> <br />
## [surface_terrains.h](#surface_terrains.h) ## [surface_terrains.h](#surface_terrains.h)
- HAZARD_TYPE_LAVA_FLOOR
- HAZARD_TYPE_LAVA_WALL
- HAZARD_TYPE_QUICKSAND
- SURFACE_0004 - SURFACE_0004
- SURFACE_BOSS_FIGHT_CAMERA - SURFACE_BOSS_FIGHT_CAMERA
- SURFACE_BURNING - SURFACE_BURNING

View file

@ -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_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_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_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_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_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 | | 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 |

View file

@ -165,6 +165,10 @@
#define SURFACE_FLAG_NO_CAM_COLLISION (1 << 1) #define SURFACE_FLAG_NO_CAM_COLLISION (1 << 1)
#define SURFACE_FLAG_X_PROJECTION (1 << 3) #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 // These are effectively unique "surface" types like those defined higher
// And they are used as collision commands to load certain functions // And they are used as collision commands to load certain functions
#define TERRAIN_LOAD_VERTICES 0x0040 // Begins vertices list for collision triangles #define TERRAIN_LOAD_VERTICES 0x0040 // Begins vertices list for collision triangles

View file

@ -2319,7 +2319,7 @@ void check_death_barrier(struct MarioState *m) {
void check_lava_boost(struct MarioState *m) { void check_lava_boost(struct MarioState *m) {
bool allow = true; 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_BUBBLED || (gServerSettings.enableCheats && gCheats.godMode) || (!allow)) { return; }
if (!(m->action & ACT_FLAG_RIDING_SHELL) && m->pos[1] < m->floorHeight + 10.0f) { if (!(m->action & ACT_FLAG_RIDING_SHELL) && m->pos[1] < m->floorHeight + 10.0f) {
if (!(m->flags & MARIO_METAL_CAP)) { if (!(m->flags & MARIO_METAL_CAP)) {

View file

@ -54,7 +54,7 @@ void play_knockback_sound(struct MarioState *m) {
s32 lava_boost_on_wall(struct MarioState *m) { s32 lava_boost_on_wall(struct MarioState *m) {
bool allow = true; 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; } if ((gServerSettings.enableCheats && gCheats.godMode) || (!allow)) { return FALSE; }
m->faceAngle[1] = atan2s(m->wallNormal[2], m->wallNormal[0]); m->faceAngle[1] = atan2s(m->wallNormal[2], m->wallNormal[0]);

View file

@ -110,7 +110,7 @@ void mario_bonk_reflection(struct MarioState *m, u32 negateSpeed) {
u32 mario_update_quicksand(struct MarioState *m, f32 sinkingSpeed) { u32 mario_update_quicksand(struct MarioState *m, f32 sinkingSpeed) {
bool allow = true; 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)) { if (m->action & ACT_FLAG_RIDING_SHELL || (gServerSettings.enableCheats && gCheats.godMode && m->playerIndex == 0) || (!allow)) {
m->quicksandDepth = 0.0f; m->quicksandDepth = 0.0f;
} else { } else {

View file

@ -8,6 +8,9 @@
// events // // events //
//////////// ////////////
static bool lTrigDown = false;
static bool rTrigDown = false;
static struct DjuiButton* sPrevButton = NULL; static struct DjuiButton* sPrevButton = NULL;
static struct DjuiButton* sNextButton = NULL; static struct DjuiButton* sNextButton = NULL;
static struct DjuiText* sPageNumText = NULL; static struct DjuiText* sPageNumText = NULL;
@ -106,6 +109,21 @@ bool djui_paginated_render(struct DjuiBase* base) {
} }
djui_rect_render(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; return true;
} }

View file

@ -72,13 +72,16 @@ static void gfx_sdl_set_fullscreen(void) {
SDL_SetWindowFullscreen(wnd, SDL_WINDOW_FULLSCREEN_DESKTOP); SDL_SetWindowFullscreen(wnd, SDL_WINDOW_FULLSCREEN_DESKTOP);
} else { } else {
SDL_SetWindowFullscreen(wnd, 0); SDL_SetWindowFullscreen(wnd, 0);
SDL_ShowCursor(1);
configWindow.exiting_fullscreen = true; configWindow.exiting_fullscreen = true;
} }
} }
static void gfx_sdl_reset_dimension_and_pos(void) { static void gfx_sdl_reset_dimension_and_pos(void) {
if (configWindow.exiting_fullscreen) if (configWindow.exiting_fullscreen) {
configWindow.exiting_fullscreen = false; configWindow.exiting_fullscreen = false;
SDL_ShowCursor(0);
}
if (configWindow.reset) { if (configWindow.reset) {
configWindow.x = WAPI_WIN_CENTERPOS; configWindow.x = WAPI_WIN_CENTERPOS;

View file

@ -68,6 +68,7 @@ static void smlua_load_script(struct Mod* mod, struct ModFile* file, u16 remoteI
gSmLuaConvertSuccess = true; gSmLuaConvertSuccess = true;
gLuaInitializingScript = 1; gLuaInitializingScript = 1;
LOG_INFO("Loading lua script '%s'", file->cachedPath);
if (luaL_loadfile(L, file->cachedPath) != LUA_OK) { if (luaL_loadfile(L, file->cachedPath) != LUA_OK) {
LOG_LUA("Failed to load lua script '%s'.", file->cachedPath); LOG_LUA("Failed to load lua script '%s'.", file->cachedPath);
LOG_LUA("%s", smlua_to_string(L, lua_gettop(L))); LOG_LUA("%s", smlua_to_string(L, lua_gettop(L)));

View file

@ -276,6 +276,8 @@ static int smlua_func_define_custom_obj_fields(lua_State* L) {
} }
lua_settable(L, -3); // set _custom_object_fields lua_settable(L, -3); // set _custom_object_fields
LOG_INFO("Registered custom object field: %02X - %s", fieldIndex, node->key);
fieldIndex++; fieldIndex++;
node = node->next; node = node->next;

View file

@ -3976,6 +3976,9 @@ char gSmluaConstants[] = ""
"SURFACE_FLAG_DYNAMIC = (1 << 0)\n" "SURFACE_FLAG_DYNAMIC = (1 << 0)\n"
"SURFACE_FLAG_NO_CAM_COLLISION = (1 << 1)\n" "SURFACE_FLAG_NO_CAM_COLLISION = (1 << 1)\n"
"SURFACE_FLAG_X_PROJECTION = (1 << 3)\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_VERTICES = 0x0040\n"
"TERRAIN_LOAD_CONTINUE = 0x0041\n" "TERRAIN_LOAD_CONTINUE = 0x0041\n"
"TERRAIN_LOAD_END = 0x0042\n" "TERRAIN_LOAD_END = 0x0042\n"

View file

@ -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 // // hooked actions //
//////////////////// ////////////////////

View file

@ -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); 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); 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_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); enum BehaviorId smlua_get_original_behavior_id(const BehaviorScript* behavior);
const BehaviorScript* smlua_override_behavior(const BehaviorScript* behavior); const BehaviorScript* smlua_override_behavior(const BehaviorScript* behavior);