From 5fffa9e9d959a3fce33bb50f98b458fa51759f51 Mon Sep 17 00:00:00 2001 From: Agent X <44549182+Agent-11@users.noreply.github.com> Date: Tue, 20 Feb 2024 22:06:40 -0500 Subject: [PATCH] Add the ability to have global star IDs Set gLevelValues.useGlobalStarIds on init, this value not being the same for everyone will cause desyncs. --- autogen/lua_definitions/structs.lua | 1 + docs/lua/structs.md | 1 + src/game/behaviors/sparkle_spawn_star.inc.c | 3 ++- src/game/behaviors/spawn_star.inc.c | 4 ++-- src/game/hardcoded.c | 3 ++- src/game/hardcoded.h | 1 + src/game/interaction.c | 2 +- src/game/save_file.c | 9 ++++++--- src/pc/lua/smlua_cobject_autogen.c | 3 ++- 9 files changed, 18 insertions(+), 9 deletions(-) diff --git a/autogen/lua_definitions/structs.lua b/autogen/lua_definitions/structs.lua index 90036142..4c12bf06 100644 --- a/autogen/lua_definitions/structs.lua +++ b/autogen/lua_definitions/structs.lua @@ -919,6 +919,7 @@ --- @field public skipCreditsAt LevelNum --- @field public starHeal integer --- @field public starPositions StarPositions +--- @field public useGlobalStarIds integer --- @field public vanishCapDuration integer --- @field public vanishCapDurationVcutm integer --- @field public vanishCapSequence SeqId diff --git a/docs/lua/structs.md b/docs/lua/structs.md index d1c30080..c41b55aa 100644 --- a/docs/lua/structs.md +++ b/docs/lua/structs.md @@ -1258,6 +1258,7 @@ | skipCreditsAt | [enum LevelNum](constants.md#enum-LevelNum) | | | starHeal | `integer` | | | starPositions | [StarPositions](structs.md#StarPositions) | read-only | +| useGlobalStarIds | `integer` | | | vanishCapDuration | `integer` | | | vanishCapDurationVcutm | `integer` | | | vanishCapSequence | [enum SeqId](constants.md#enum-SeqId) | | diff --git a/src/game/behaviors/sparkle_spawn_star.inc.c b/src/game/behaviors/sparkle_spawn_star.inc.c index 84b3c0e5..26a2c3fe 100644 --- a/src/game/behaviors/sparkle_spawn_star.inc.c +++ b/src/game/behaviors/sparkle_spawn_star.inc.c @@ -17,8 +17,9 @@ void bhv_spawned_star_init(void) { o->oBehParams = o->parentObj->oBehParams; } s32 starId = (o->oBehParams >> 24) & 0xFF; - if (bit_shift_left(starId) & save_file_get_star_flags(gCurrSaveFileNum - 1, gCurrCourseNum - 1)) + if (bit_shift_left(gLevelValues.useGlobalStarIds ? starId % 7 : starId) & save_file_get_star_flags(gCurrSaveFileNum - 1, (gLevelValues.useGlobalStarIds ? (starId / 7) - 1 : gCurrCourseNum - 1))) { cur_obj_set_model(smlua_model_util_load(E_MODEL_TRANSPARENT_STAR)); + } cur_obj_play_sound_2(SOUND_GENERAL2_STAR_APPEARS); // exclamation box stars are not sent through the normal exclamation box diff --git a/src/game/behaviors/spawn_star.inc.c b/src/game/behaviors/spawn_star.inc.c index 5cbd989f..77f02ab2 100644 --- a/src/game/behaviors/spawn_star.inc.c +++ b/src/game/behaviors/spawn_star.inc.c @@ -63,8 +63,8 @@ void bhv_collect_star_init(void) { u8 currentLevelStarFlags; starId = o->oBehParams >> 24; - currentLevelStarFlags = save_file_get_star_flags(gCurrSaveFileNum - 1, gCurrCourseNum - 1); - if (currentLevelStarFlags & (1 << starId)) { + currentLevelStarFlags = save_file_get_star_flags(gCurrSaveFileNum - 1, (gLevelValues.useGlobalStarIds ? (starId / 7) - 1 : gCurrCourseNum - 1)); + if (currentLevelStarFlags & (1 << (gLevelValues.useGlobalStarIds ? starId % 7 : starId))) { cur_obj_set_model(MODEL_TRANSPARENT_STAR); } else { cur_obj_set_model(MODEL_STAR); diff --git a/src/game/hardcoded.c b/src/game/hardcoded.c index c76045e6..3dc19226 100644 --- a/src/game/hardcoded.c +++ b/src/game/hardcoded.c @@ -121,7 +121,8 @@ struct LevelValues gDefaultLevelValues = { .maxLives = 100, .maxCoins = 999, .numCoinsToLife = 50, - .wdwWaterLevelSpeed = 10.0f + .wdwWaterLevelSpeed = 10.0f, + .useGlobalStarIds = FALSE }; struct LevelValues gLevelValues = { 0 }; diff --git a/src/game/hardcoded.h b/src/game/hardcoded.h index d534b2df..0e810670 100644 --- a/src/game/hardcoded.h +++ b/src/game/hardcoded.h @@ -87,6 +87,7 @@ struct LevelValues { u16 maxCoins; u16 numCoinsToLife; f32 wdwWaterLevelSpeed; + u8 useGlobalStarIds; }; extern struct LevelValues gLevelValues; diff --git a/src/game/interaction.c b/src/game/interaction.c index a30dcf3e..b7bbd411 100644 --- a/src/game/interaction.c +++ b/src/game/interaction.c @@ -980,7 +980,7 @@ u32 interact_star_or_key(struct MarioState *m, UNUSED u32 interactType, struct O m->interactObj = o; m->usedObj = o; - starIndex = o->oBehParams >> 24; + starIndex = (o->oBehParams >> 24) & (gLevelValues.useGlobalStarIds ? 0xFF : 0x1F); if (m == &gMarioStates[0]) { // sync the star collection diff --git a/src/game/save_file.c b/src/game/save_file.c index c2c52ae4..1474409a 100644 --- a/src/game/save_file.c +++ b/src/game/save_file.c @@ -10,6 +10,7 @@ #include "level_table.h" #include "course_table.h" #include "rumble_init.h" +#include "hardcoded.h" #include "macros.h" #include "pc/network/network.h" #include "pc/lua/utils/smlua_level_utils.h" @@ -524,7 +525,8 @@ void save_file_collect_star_or_key(s16 coinScore, s16 starIndex, u8 fromNetwork) if (INVALID_FILE_INDEX(fileIndex)) { return; } if (INVALID_SRC_SLOT(gSaveFileUsingBackupSlot)) { return; } - s32 starFlag = 1 << starIndex; + s32 starByte = (starIndex / 7) - 1; + s32 starFlag = 1 << (gLevelValues.useGlobalStarIds ? (starIndex % 7) : starIndex); UNUSED s32 flags = save_file_get_flags(); if (!fromNetwork) { @@ -568,8 +570,9 @@ void save_file_collect_star_or_key(s16 coinScore, s16 starIndex, u8 fromNetwork) break; default: - if (!(save_file_get_star_flags(fileIndex, courseIndex) & starFlag)) { - save_file_set_star_flags(fileIndex, courseIndex, starFlag); + s32 index = gLevelValues.useGlobalStarIds ? starByte : courseIndex; + if (!(save_file_get_star_flags(fileIndex, index) & starFlag)) { + save_file_set_star_flags(fileIndex, index, starFlag); } break; } diff --git a/src/pc/lua/smlua_cobject_autogen.c b/src/pc/lua/smlua_cobject_autogen.c index 203e7144..d136b0b7 100644 --- a/src/pc/lua/smlua_cobject_autogen.c +++ b/src/pc/lua/smlua_cobject_autogen.c @@ -994,7 +994,7 @@ static struct LuaObjectField sLakituStateFields[LUA_LAKITU_STATE_FIELD_COUNT] = { "yaw", LVT_S16, offsetof(struct LakituState, yaw), false, LOT_NONE }, }; -#define LUA_LEVEL_VALUES_FIELD_COUNT 47 +#define LUA_LEVEL_VALUES_FIELD_COUNT 48 static struct LuaObjectField sLevelValuesFields[LUA_LEVEL_VALUES_FIELD_COUNT] = { { "bubbleOnDeathBarrierInCapStages", LVT_U8, offsetof(struct LevelValues, bubbleOnDeathBarrierInCapStages), false, LOT_NONE }, { "cellHeightLimit", LVT_S16, offsetof(struct LevelValues, cellHeightLimit), false, LOT_NONE }, @@ -1034,6 +1034,7 @@ static struct LuaObjectField sLevelValuesFields[LUA_LEVEL_VALUES_FIELD_COUNT] = { "skipCreditsAt", LVT_S32, offsetof(struct LevelValues, skipCreditsAt), false, LOT_NONE }, { "starHeal", LVT_U8, offsetof(struct LevelValues, starHeal), false, LOT_NONE }, { "starPositions", LVT_COBJECT, offsetof(struct LevelValues, starPositions), true, LOT_STARPOSITIONS }, + { "useGlobalStarIds", LVT_U8, offsetof(struct LevelValues, useGlobalStarIds), false, LOT_NONE }, { "vanishCapDuration", LVT_U16, offsetof(struct LevelValues, vanishCapDuration), false, LOT_NONE }, { "vanishCapDurationVcutm", LVT_U16, offsetof(struct LevelValues, vanishCapDurationVcutm), false, LOT_NONE }, { "vanishCapSequence", LVT_S32, offsetof(struct LevelValues, vanishCapSequence), false, LOT_NONE },