From 7e46ce4a21509f320aacfaabee1ceeb26a5b6766 Mon Sep 17 00:00:00 2001 From: Isaac0-dev <62234577+Isaac0-dev@users.noreply.github.com> Date: Wed, 22 Mar 2023 09:43:29 +1000 Subject: [PATCH] fixes and other improvements (#309) * HOOK_JOINED_GAME * expose VERSION_TEXT, and two more adjusments * show if a constant type is a string with autogen * fix another blunder by that guy * should use an or operator here * fix frame limiter stuff --- Makefile | 2 +- autogen/convert_constants.py | 7 +++++-- autogen/lua_definitions/constants.lua | 8 +++++++- docs/lua/constants.md | 4 +++- docs/lua/guides/hooks.md | 2 ++ src/game/save_file.c | 1 - src/pc/lua/smlua_cobject_autogen.c | 2 +- src/pc/lua/smlua_constants_autogen.c | 4 +++- src/pc/lua/smlua_hooks.h | 2 ++ src/pc/network/discord/activity.c | 1 - src/pc/network/packets/packet_join.c | 8 +++++++- src/pc/network/packets/packet_mod_list.c | 3 +++ src/pc/network/version.c | 1 - src/pc/network/version.h | 1 + src/pc/pc_main.c | 2 +- 15 files changed, 36 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 06ef2e54..ea332aa7 100644 --- a/Makefile +++ b/Makefile @@ -102,7 +102,7 @@ EXTRA_CFLAGS ?= EXTRA_CPP_FLAGS ?= EXTRA_CFLAGS += -Wno-format-security -Wno-trigraphs -dev:; @$(MAKE) DEBUG=1 DEVELOPMENT=1 +dev:; @$(MAKE) DEVELOPMENT=1 # COMPILER - selects the C compiler to use # gcc - uses the GNU C Compiler diff --git a/autogen/convert_constants.py b/autogen/convert_constants.py index c0189ec8..b8f72f98 100644 --- a/autogen/convert_constants.py +++ b/autogen/convert_constants.py @@ -162,7 +162,7 @@ def process_define(filename, line): if p.startswith('0x'): continue p = re.sub(r'0x[a-fA-F0-9]+', '', p) - if re.search('[a-z]', p) != None: + if re.search('[a-z]', p) != None and 'VERSION_TEXT' not in line: if 'gCurrentObject' not in line: print('UNRECOGNIZED DEFINE: ' + line) return None @@ -327,7 +327,10 @@ def def_constant(processed_constant): return s for c in [processed_constant]: - s += '\n--- @type integer\n' + if "'" in c[1]: + s += '\n--- @type string\n' + else: + s += '\n--- @type integer\n' s += '%s = %s\n' % (c[0], c[1]) return s diff --git a/autogen/lua_definitions/constants.lua b/autogen/lua_definitions/constants.lua index cfb9b076..23df2f34 100644 --- a/autogen/lua_definitions/constants.lua +++ b/autogen/lua_definitions/constants.lua @@ -8209,7 +8209,10 @@ HOOK_CHARACTER_SOUND = 29 HOOK_BEFORE_SET_MARIO_ACTION = 30 --- @type LuaHookedEventType -HOOK_MAX = 31 +HOOK_JOINED_GAME = 31 + +--- @type LuaHookedEventType +HOOK_MAX = 32 --- @class HudDisplayFlags @@ -11484,3 +11487,6 @@ MINOR_VERSION_NUMBER = 0 --- @type integer VERSION_NUMBER = 32 + +--- @type string +VERSION_TEXT = 'beta' diff --git a/docs/lua/constants.md b/docs/lua/constants.md index 2f23c003..270c17fb 100644 --- a/docs/lua/constants.md +++ b/docs/lua/constants.md @@ -2927,7 +2927,8 @@ | HOOK_OBJECT_SET_MODEL | 28 | | HOOK_CHARACTER_SOUND | 29 | | HOOK_BEFORE_SET_MARIO_ACTION | 30 | -| HOOK_MAX | 31 | +| HOOK_JOINED_GAME | 31 | +| HOOK_MAX | 32 | [:arrow_up_small:](#) @@ -4072,6 +4073,7 @@ - MAX_VERSION_LENGTH - MINOR_VERSION_NUMBER - VERSION_NUMBER +- VERSION_TEXT [:arrow_up_small:](#) diff --git a/docs/lua/guides/hooks.md b/docs/lua/guides/hooks.md index b9888741..08ace7e3 100644 --- a/docs/lua/guides/hooks.md +++ b/docs/lua/guides/hooks.md @@ -116,6 +116,8 @@ The lua functions sent to `hook_event()` will be automatically called by SM64 wh | 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 | +| HOOK_BEFORE_SET_MARIO_ACTION | Called before Mario's action changes. Return an action to change the incoming action or `1` to cancel the action change. | `integer` incomingAction | +| HOOK_JOINED_GAME | Called when the local player finishes the join process (if the player isn't the host) | None | | HOOK_BEFORE_SET_MARIO_ACTION | Called before Mario's action changes. Return an action to change the incoming action or `1` to cancel the action change. | [MarioState](structs.md#MarioState) mario, `integer` incomingAction | ### Parameters diff --git a/src/game/save_file.c b/src/game/save_file.c index 8e2b9bec..8877a3bf 100644 --- a/src/game/save_file.c +++ b/src/game/save_file.c @@ -410,7 +410,6 @@ void save_file_erase_current_backup_save(void) { save_file_reload(FALSE); save_file_do_save(gCurrSaveFileNum-1, TRUE); - network_send_save_file(gCurrSaveFileNum-1); } } diff --git a/src/pc/lua/smlua_cobject_autogen.c b/src/pc/lua/smlua_cobject_autogen.c index d372ebb2..c99ba093 100644 --- a/src/pc/lua/smlua_cobject_autogen.c +++ b/src/pc/lua/smlua_cobject_autogen.c @@ -811,7 +811,7 @@ static struct LuaObjectField sMarioBodyStateFields[LUA_MARIO_BODY_STATE_FIELD_CO { "wingFlutter", LVT_S8, offsetof(struct MarioBodyState, wingFlutter), false, LOT_NONE }, }; -#define LUA_MARIO_STATE_FIELD_COUNT 76 +#define LUA_MARIO_STATE_FIELD_COUNT 77 static struct LuaObjectField sMarioStateFields[LUA_MARIO_STATE_FIELD_COUNT] = { { "action", LVT_U32, offsetof(struct MarioState, action), false, LOT_NONE }, { "actionArg", LVT_U32, offsetof(struct MarioState, actionArg), false, LOT_NONE }, diff --git a/src/pc/lua/smlua_constants_autogen.c b/src/pc/lua/smlua_constants_autogen.c index 60bcfc43..13fa67e2 100644 --- a/src/pc/lua/smlua_constants_autogen.c +++ b/src/pc/lua/smlua_constants_autogen.c @@ -2939,7 +2939,8 @@ char gSmluaConstants[] = "" "HOOK_OBJECT_SET_MODEL = 28\n" "HOOK_CHARACTER_SOUND = 29\n" "HOOK_BEFORE_SET_MARIO_ACTION = 30\n" -"HOOK_MAX = 31\n" +"HOOK_JOINED_GAME = 31\n" +"HOOK_MAX = 32\n" "ACTION_HOOK_EVERY_FRAME = 0\n" "ACTION_HOOK_GRAVITY = 1\n" "ACTION_HOOK_MAX = 2\n" @@ -4028,6 +4029,7 @@ char gSmluaConstants[] = "" "COOP_OBJ_FLAG_NETWORK = (1 << 0)\n" "COOP_OBJ_FLAG_LUA = (1 << 1)\n" "COOP_OBJ_FLAG_NON_SYNC = (1 << 2)\n" +"VERSION_TEXT = 'beta'\n" "VERSION_NUMBER = 32\n" "MINOR_VERSION_NUMBER = 0\n" "MAX_VERSION_LENGTH = 10\n" diff --git a/src/pc/lua/smlua_hooks.h b/src/pc/lua/smlua_hooks.h index af3d42f4..b971d5f4 100644 --- a/src/pc/lua/smlua_hooks.h +++ b/src/pc/lua/smlua_hooks.h @@ -42,6 +42,7 @@ enum LuaHookedEventType { HOOK_OBJECT_SET_MODEL, HOOK_CHARACTER_SOUND, HOOK_BEFORE_SET_MARIO_ACTION, + HOOK_JOINED_GAME, HOOK_MAX, }; @@ -77,6 +78,7 @@ static const char* LuaHookedEventTypeName[] = { "HOOK_OBJECT_SET_MODEL", "HOOK_CHARACTER_SOUND", "HOOK_BEFORE_SET_MARIO_ACTION", + "HOOK_JOINED_GAME", "HOOK_MAX" }; diff --git a/src/pc/network/discord/activity.c b/src/pc/network/discord/activity.c index 9f6104cf..2e4d6176 100644 --- a/src/pc/network/discord/activity.c +++ b/src/pc/network/discord/activity.c @@ -22,7 +22,6 @@ static void on_activity_join_callback(UNUSED void* data, enum EDiscordResult res DISCORD_REQUIRE(result); if (gNetworkType != NT_NONE) { LOGFILE_ERROR(LFT_DISCORD, "Joined lobby when already connected somewhere!"); - exit(0); return; } network_init(NT_CLIENT); diff --git a/src/pc/network/packets/packet_join.c b/src/pc/network/packets/packet_join.c index f946e775..4541191a 100644 --- a/src/pc/network/packets/packet_join.c +++ b/src/pc/network/packets/packet_join.c @@ -38,6 +38,9 @@ void network_send_join_request(void) { struct Packet p = { 0 }; packet_init(&p, PACKET_JOIN_REQUEST, true, PLMT_NONE); + char version[MAX_VERSION_LENGTH] = { 0 }; + snprintf(version, MAX_VERSION_LENGTH, "%s", get_version()); + packet_write(&p, &version, sizeof(u8) * MAX_VERSION_LENGTH); packet_write(&p, &configPlayerModel, sizeof(u8)); packet_write(&p, &configPlayerPalette, sizeof(struct PlayerPalette)); @@ -52,6 +55,8 @@ void network_receive_join_request(struct Packet* p) { LOG_INFO("received join request"); if (p->dataLength > 5) { + char version[MAX_VERSION_LENGTH] = { 0 }; + packet_read(p, &version, sizeof(u8) * MAX_VERSION_LENGTH); packet_read(p, &sJoinRequestPlayerModel, sizeof(u8)); packet_read(p, &sJoinRequestPlayerPalette, sizeof(struct PlayerPalette)); packet_read(p, &sJoinRequestPlayerName, sizeof(u8) * MAX_PLAYER_STRING); @@ -241,7 +246,8 @@ void network_receive_join(struct Packet* p) { network_send_network_players_request(); network_send_lua_sync_table_request(); + gCurrentlyJoining = false; + smlua_call_event_hooks(HOOK_JOINED_GAME); extern s16 gChangeLevel; gChangeLevel = gLevelValues.entryLevel; - gCurrentlyJoining = false; } diff --git a/src/pc/network/packets/packet_mod_list.c b/src/pc/network/packets/packet_mod_list.c index d753de56..ae0e1ba0 100644 --- a/src/pc/network/packets/packet_mod_list.c +++ b/src/pc/network/packets/packet_mod_list.c @@ -18,6 +18,9 @@ void network_send_mod_list_request(void) { struct Packet p = { 0 }; packet_init(&p, PACKET_MOD_LIST_REQUEST, true, PLMT_NONE); + char version[MAX_VERSION_LENGTH] = { 0 }; + snprintf(version, MAX_VERSION_LENGTH, "%s", get_version()); + packet_write(&p, &version, sizeof(u8) * MAX_VERSION_LENGTH); network_send_to((gNetworkPlayerServer != NULL) ? gNetworkPlayerServer->localIndex : 0, &p); LOG_INFO("sending mod list request"); diff --git a/src/pc/network/version.c b/src/pc/network/version.c index ddf37c1e..dc51bcfb 100644 --- a/src/pc/network/version.c +++ b/src/pc/network/version.c @@ -3,7 +3,6 @@ #include "types.h" static char sVersionString[MAX_VERSION_LENGTH] = { 0 }; -#define VERSION_TEXT "beta" char* get_version(void) { snprintf(sVersionString, MAX_VERSION_LENGTH, "%s %d.%d", VERSION_TEXT, VERSION_NUMBER, MINOR_VERSION_NUMBER); diff --git a/src/pc/network/version.h b/src/pc/network/version.h index 7909f53c..ac0924bf 100644 --- a/src/pc/network/version.h +++ b/src/pc/network/version.h @@ -1,6 +1,7 @@ #ifndef VERSION_H #define VERSION_H +#define VERSION_TEXT 'beta' #define VERSION_NUMBER 32 #define MINOR_VERSION_NUMBER 0 diff --git a/src/pc/pc_main.c b/src/pc/pc_main.c index 2c0b4c30..7eba1b03 100644 --- a/src/pc/pc_main.c +++ b/src/pc/pc_main.c @@ -174,7 +174,7 @@ void produce_interpolation_frames_and_delay(void) { gfx_start_frame(); f32 delta = MIN((curTime - sFrameTimeStart) / (sFrameTargetTime - sFrameTimeStart), 1); gRenderingDelta = delta; - if (!gSkipInterpolationTitleScreen && configFrameLimit > 30) { patch_interpolations(delta); } + if (!gSkipInterpolationTitleScreen && (configFrameLimit > 30 || configUncappedFramerate)) { patch_interpolations(delta); } send_display_list(gGfxSPTask); gfx_end_frame();