From c439d6213780df715feb6c7773d6f39bad2107a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20Dub=C3=A9?= Date: Mon, 23 Mar 2026 16:27:20 +0000 Subject: [PATCH] Enemy rando: don't mutate ActorEntry (#6400) --- .../ExtraModes/EnemyRandomizer.cpp | 19 +++++++++++++------ .../vanilla-behavior/GIVanillaBehavior.h | 2 +- soh/src/code/z_actor.c | 2 +- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/soh/soh/Enhancements/ExtraModes/EnemyRandomizer.cpp b/soh/soh/Enhancements/ExtraModes/EnemyRandomizer.cpp index e7b93484f..e3d311535 100644 --- a/soh/soh/Enhancements/ExtraModes/EnemyRandomizer.cpp +++ b/soh/soh/Enhancements/ExtraModes/EnemyRandomizer.cpp @@ -5,12 +5,10 @@ #include "soh/Enhancements/enhancementTypes.h" #include "soh/ObjectExtension/ObjectExtension.h" #include "variables.h" -#include "soh/OTRGlobals.h" #include "soh/cvar_prefixes.h" #include "soh/ResourceManagerHelpers.h" #include "soh/SohGui/MenuTypes.h" #include "soh/SohGui/SohMenu.h" -#include "soh/SohGui/SohGui.hpp" extern "C" { #include @@ -627,11 +625,20 @@ void RegisterEnemyRandomizer() { ActorContext* actorCtx = va_arg(args, ActorContext*); ActorEntry* actorEntry = va_arg(args, ActorEntry*); PlayState* play = va_arg(args, PlayState*); - Actor* actor = va_arg(args, Actor*); + Actor** actor = va_arg(args, Actor**); - if (!GetRandomizedEnemy(play, &actorEntry->id, &actorEntry->pos.x, &actorEntry->pos.y, &actorEntry->pos.z, - &actorEntry->rot.x, &actorEntry->rot.y, &actorEntry->rot.z, &actorEntry->params)) { - *should = false; + s16 actorId = actorEntry->id; + s16 posX = actorEntry->pos.x; + s16 posY = actorEntry->pos.y; + s16 posZ = actorEntry->pos.z; + s16 rotX = actorEntry->rot.x; + s16 rotY = actorEntry->rot.y; + s16 rotZ = actorEntry->rot.z; + s16 params = actorEntry->params; + + *should = false; + if (GetRandomizedEnemy(play, &actorId, &posX, &posY, &posZ, &rotX, &rotY, &rotZ, ¶ms)) { + *actor = Actor_Spawn(actorCtx, play, actorId, posX, posY, posZ, rotX, rotY, rotZ, params); } }); diff --git a/soh/soh/Enhancements/game-interactor/vanilla-behavior/GIVanillaBehavior.h b/soh/soh/Enhancements/game-interactor/vanilla-behavior/GIVanillaBehavior.h index 2065c929d..aae11fe86 100644 --- a/soh/soh/Enhancements/game-interactor/vanilla-behavior/GIVanillaBehavior.h +++ b/soh/soh/Enhancements/game-interactor/vanilla-behavior/GIVanillaBehavior.h @@ -2663,7 +2663,7 @@ typedef enum { // - `*ActorContext` // - `*ActorEntry` // - `*PlayState` - // - `*Actor` + // - `**Actor` VB_SPAWN_ACTOR_ENTRY, // #### `result` diff --git a/soh/src/code/z_actor.c b/soh/src/code/z_actor.c index e999788a4..f0ca7c0cd 100644 --- a/soh/src/code/z_actor.c +++ b/soh/src/code/z_actor.c @@ -3471,7 +3471,7 @@ Actor* Actor_SpawnEntry(ActorContext* actorCtx, ActorEntry* actorEntry, PlayStat gMapLoading = 1; Actor* ret; - if (GameInteractor_Should(VB_SPAWN_ACTOR_ENTRY, true, actorCtx, actorEntry, play, ret)) { + if (GameInteractor_Should(VB_SPAWN_ACTOR_ENTRY, true, actorCtx, actorEntry, play, &ret)) { ret = Actor_Spawn(actorCtx, play, actorEntry->id, actorEntry->pos.x, actorEntry->pos.y, actorEntry->pos.z, actorEntry->rot.x, actorEntry->rot.y, actorEntry->rot.z, actorEntry->params); }