From 897f6712a34aced9b048f67cccdf131bdd88f335 Mon Sep 17 00:00:00 2001 From: MysterD Date: Tue, 17 May 2022 01:22:45 -0700 Subject: [PATCH] Reset hardcoded values on disconnect --- src/game/hardcoded.c | 17 +++++++++++++++-- src/game/hardcoded.h | 2 ++ src/game/rendering_graph_node.c | 18 +++++++++++------- src/pc/lua/smlua.c | 2 ++ 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/game/hardcoded.c b/src/game/hardcoded.c index 1e74a242..091a294b 100644 --- a/src/game/hardcoded.c +++ b/src/game/hardcoded.c @@ -37,7 +37,7 @@ // Levels // //////////// -struct LevelValues gLevelValues = { +struct LevelValues gDefaultLevelValues = { .entryLevel = LEVEL_CASTLE_GROUNDS, .exitCastleLevel = LEVEL_CASTLE, .exitCastleArea = 1, @@ -86,11 +86,13 @@ struct LevelValues gLevelValues = { }, }; +struct LevelValues gLevelValues = { 0 }; + /////////////// // Behaviors // /////////////// -struct BehaviorValues gBehaviorValues = { +struct BehaviorValues gDefaultBehaviorValues = { .KoopaBobAgility = 4.0f, .KoopaCatchupAgility = 8.0f, .KoopaThiAgility = 6.0f, @@ -218,3 +220,14 @@ struct BehaviorValues gBehaviorValues = { .PlatformLll2Trajectory = (Trajectory*) lll_seg7_trajectory_07028660, }, }; + +struct BehaviorValues gBehaviorValues = { 0 }; + + /////////////// + // functions // +/////////////// + +void hardcoded_reset_default_values(void) { + gLevelValues = gDefaultLevelValues; + gBehaviorValues = gDefaultBehaviorValues; +} diff --git a/src/game/hardcoded.h b/src/game/hardcoded.h index cca523b6..1b8be2d8 100644 --- a/src/game/hardcoded.h +++ b/src/game/hardcoded.h @@ -195,4 +195,6 @@ struct BehaviorValues { extern struct BehaviorValues gBehaviorValues; +void hardcoded_reset_default_values(void); + #endif \ No newline at end of file diff --git a/src/game/rendering_graph_node.c b/src/game/rendering_graph_node.c index a7a8c7d9..2af9cf14 100644 --- a/src/game/rendering_graph_node.c +++ b/src/game/rendering_graph_node.c @@ -378,10 +378,10 @@ static void geo_process_ortho_projection(struct GraphNodeOrthoProjection *node) if (node->node.children != NULL) { Mtx *mtx = alloc_display_list(sizeof(*mtx)); if (mtx == NULL) { return; } - f32 left = (gCurGraphNodeRoot->x - gCurGraphNodeRoot->width) / 2.0f * node->scale; - f32 right = (gCurGraphNodeRoot->x + gCurGraphNodeRoot->width) / 2.0f * node->scale; - f32 top = (gCurGraphNodeRoot->y - gCurGraphNodeRoot->height) / 2.0f * node->scale; - f32 bottom = (gCurGraphNodeRoot->y + gCurGraphNodeRoot->height) / 2.0f * node->scale; + f32 left = ((gCurGraphNodeRoot->x - gCurGraphNodeRoot->width) / 2.0f) * node->scale; + f32 right = ((gCurGraphNodeRoot->x + gCurGraphNodeRoot->width) / 2.0f) * node->scale; + f32 top = ((gCurGraphNodeRoot->y - gCurGraphNodeRoot->height) / 2.0f) * node->scale; + f32 bottom = ((gCurGraphNodeRoot->y + gCurGraphNodeRoot->height) / 2.0f) * node->scale; guOrtho(mtx, left, right, bottom, top, -2.0f, 2.0f, 1.0f); gSPPerspNormalize(gDisplayListHead++, 0xFFFF); @@ -404,10 +404,12 @@ static void geo_process_perspective(struct GraphNodePerspective *node) { Mtx *mtx = alloc_display_list(sizeof(*mtx)); if (mtx == NULL) { return; } + f32 divisor = (f32) gCurGraphNodeRoot->height; + if (divisor == 0) { divisor = 1; } #ifdef VERSION_EU - f32 aspect = ((f32) gCurGraphNodeRoot->width / (f32) gCurGraphNodeRoot->height) * 1.1f; + f32 aspect = ((f32) gCurGraphNodeRoot->width / divisor) * 1.1f; #else - f32 aspect = (f32) gCurGraphNodeRoot->width / (f32) gCurGraphNodeRoot->height; + f32 aspect = (f32) gCurGraphNodeRoot->width / divisor; #endif guPerspective(mtx, &perspNorm, not_zero(node->prevFov, gOverrideFOV), aspect, not_zero(node->near, gOverrideNear), not_zero(node->far, gOverrideFar), 1.0f); @@ -1066,7 +1068,9 @@ static s32 obj_is_in_view(struct GraphNodeObject *node, Mat4 matrix) { // Half of the fov in in-game angle units instead of degrees. s16 halfFov = (gCurGraphNodeCamFrustum->fov / 2.0f + 1.0f) * 32768.0f / 180.0f + 0.5f; - f32 hScreenEdge = -matrix[3][2] * sins(halfFov) / coss(halfFov); + f32 divisor = coss(halfFov); + if (divisor == 0) { divisor = 1; } + f32 hScreenEdge = -matrix[3][2] * sins(halfFov) / divisor; // -matrix[3][2] is the depth, which gets multiplied by tan(halfFov) to get // the amount of units between the center of the screen and the horizontal edge // given the distance from the object to the camera. diff --git a/src/pc/lua/smlua.c b/src/pc/lua/smlua.c index ed09391a..f91e0186 100644 --- a/src/pc/lua/smlua.c +++ b/src/pc/lua/smlua.c @@ -1,4 +1,5 @@ #include "smlua.h" +#include "game/hardcoded.h" #include "pc/mods/mods.h" #include "pc/mods/mods_utils.h" #include "pc/crash_handler.h" @@ -178,6 +179,7 @@ void smlua_update(void) { } void smlua_shutdown(void) { + hardcoded_reset_default_values(); smlua_text_utils_reset_all(); smlua_audio_utils_reset_all(); audio_custom_shutdown();