From 6c07ef9648aabfd929a3e559a3266ccb076c7191 Mon Sep 17 00:00:00 2001 From: shadow578 <52449218+shadow578@users.noreply.github.com> Date: Mon, 2 Nov 2026 17:27:05 +0100 Subject: [PATCH 1/8] update to latest mod SDK version --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cea75a3..fb918fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ project(ChaosMod CXX) # Find latest version at https://github.com/OrfeasZ/ZHMModSDK/releases # Set ZHMMODSDK_DIR variable to a local directory to use a local copy of the ZHMModSDK. -set(ZHMMODSDK_VER "v4.1.1") +set(ZHMMODSDK_VER "v4.2.1") include(cmake/setup-zhmmodsdk.cmake) # Set C++ standard to C++23. From 569b4143b3b7bae245f7f6a179257f77e80817d3 Mon Sep 17 00:00:00 2001 From: shadow578 <52449218+shadow578@users.noreply.github.com> Date: Mon, 2 Nov 2026 18:27:14 +0100 Subject: [PATCH 2/8] improve invalid pointer / entity detection --- src/Helpers/EntityUtils.cpp | 58 +++++++++++++++++++++++++------------ src/Helpers/EntityUtils.h | 10 +++++-- src/Helpers/Utils.cpp | 55 +++++++++++++++++++++++++++++++++++ src/Helpers/Utils.h | 11 +++++++ 4 files changed, 113 insertions(+), 21 deletions(-) diff --git a/src/Helpers/EntityUtils.cpp b/src/Helpers/EntityUtils.cpp index f756944..bb92c20 100644 --- a/src/Helpers/EntityUtils.cpp +++ b/src/Helpers/EntityUtils.cpp @@ -7,7 +7,8 @@ #include #include -#include + +#include "Utils.h" #define TAG "[EntityUtils] " @@ -134,7 +135,7 @@ bool Utils::ZEntityFinder::Evaluate(const ZEntityRef& p_rEntity, ZEntityBlueprin std::string_view Utils::GetEntityName(const ZEntityRef& p_Entity, ZEntityBlueprintFactoryBase* p_pFactory, int p_nSubIndex) { - if (!p_Entity) + if (!IsReasonableEntityRef(p_Entity)) { return ""; } @@ -187,7 +188,7 @@ std::string_view Utils::GetEntityName(const ZEntityRef& p_Entity, ZEntityBluepri std::string_view Utils::GetEntityTypeName(const ZEntityRef& p_Entity) { - if (!p_Entity) + if (!IsReasonableEntityRef(p_Entity)) { return ""; } @@ -216,28 +217,15 @@ std::string_view Utils::GetEntityTypeName(const ZEntityRef& p_Entity) /// Heuristic checks for validity of blueprint factory pointers, checking for common failure cases after. static bool IsValidBlueprintFactoryPointer(ZEntityBlueprintFactoryBase* p_pBpFactory) { - // nullptr? - if (!p_pBpFactory) + if (!Utils::IsReasonablePointer(p_pBpFactory)) { #if _DEBUG - Logger::Error(TAG "Blueprint factory pointer is null."); + Logger::Error(TAG "Got likely invalid blueprint factory pointer {}.", p_pBpFactory); #endif return false; } - // seen invalid pointers with all bits set, check that too - std::uintptr_t s_nPtr = reinterpret_cast(p_pBpFactory); - if (s_nPtr == std::numeric_limits::max()) - { -#if _DEBUG - Logger::Error(TAG "Blueprint factory pointer is 0xFFFF(...)."); -#endif - - return false; - } - - // hopefully OK return true; } @@ -307,7 +295,7 @@ ZEntityBlueprintFactoryBase* Utils::GetEntityBlueprintFactoryFor(ZEntityRef p_rE ZEntityRef Utils::GetSubEntity(const ZEntityRef p_rParent, const uint64_t p_nSubEntityId, ZEntityBlueprintFactoryBase* p_pForcedBPFactory) { - if (!p_rParent) + if (!IsReasonableEntityRef(p_rParent)) { return {}; } @@ -330,3 +318,35 @@ ZEntityRef Utils::GetSubEntity(const ZEntityRef p_rParent, const uint64_t p_nSub return {}; } + + +bool Utils::IsReasonableEntityRef(const ZEntityRef& p_rEntity) +{ + if (!p_rEntity) + { + return false; + } + + if (!Utils::IsReasonablePointer(p_rEntity.m_pObj)) + { + return false; + } + + if (!Utils::IsReasonablePointer(p_rEntity.GetEntity())) + { + return false; + } + + if (!Utils::IsReasonablePointer(p_rEntity->GetType())) + { + return false; + } + + const auto s_nEid = p_rEntity->GetType()->m_nEntityID; + if (s_nEid == 0 || s_nEid == 0xFFFFFFFF) + { + return false; + } + + return true; +} diff --git a/src/Helpers/EntityUtils.h b/src/Helpers/EntityUtils.h index 5b66197..f8d9735 100644 --- a/src/Helpers/EntityUtils.h +++ b/src/Helpers/EntityUtils.h @@ -121,6 +121,12 @@ namespace Utils */ ZEntityRef GetSubEntity(const ZEntityRef p_rParent, const uint64_t p_nSubEntityId, ZEntityBlueprintFactoryBase* p_pForcedBPFactory = nullptr); + /** + * Check if an entity reference is reasonable, i.e. not null and not likely to be invalid. + * @param p_rEntity The entity reference to check. + */ + bool IsReasonableEntityRef(const ZEntityRef& p_rEntity); + /** * safely get a property from an entity. Returns std::nullopt if failed or invalid. * @template T The property type. @@ -130,7 +136,7 @@ namespace Utils template std::optional GetProperty(const ZEntityRef& p_rEntity, const std::string& p_sProperty) { - if (!p_rEntity) + if (!IsReasonableEntityRef(p_rEntity)) { return std::nullopt; } @@ -156,7 +162,7 @@ namespace Utils template inline bool SetProperty(ZEntityRef& p_rEntity, const std::string& p_sProperty, const T& p_Value, bool p_bInvokeChangeHandlers = true) { - if (!p_rEntity) + if (!IsReasonableEntityRef(p_rEntity)) { return false; } diff --git a/src/Helpers/Utils.cpp b/src/Helpers/Utils.cpp index 0f01d18..465c255 100644 --- a/src/Helpers/Utils.cpp +++ b/src/Helpers/Utils.cpp @@ -54,3 +54,58 @@ std::string Utils::ToLower(const std::string& p_sInput) std::transform(s_Result.begin(), s_Result.end(), s_Result.begin(), [](unsigned char c) { return std::tolower(c); }); return s_Result; } + +bool Utils::IsReasonablePointer(const void* p_pPtr) +{ + // nullptr? + if (!p_pPtr) + { + return false; + } + + const auto s_nPtr = reinterpret_cast(p_pPtr); + + // common invalid pointers in Glacier2 / SDK + // - 0xFFFF'FFFF'FFFF'FFFF (64-bit all bits set) - seen in BP factory pointers + // - 0x0000'0000'FFFF'FFFF (64-bit lower 32 bits set) - seen for invalid entity refs + if (s_nPtr == 0xFFFFFFFFFFFFFFFF || s_nPtr == 0x00000000FFFFFFFF) + { + return false; + } + + // "The first 64KB of address space is never mapped in, so the lowest valid address you'd expect to see is 0x10000" + // https://learn.microsoft.com/en-us/archive/msdn-magazine/2006/may/x64-starting-out-in-64-bit-windows-systems-with-visual-c + if (s_nPtr < 0x10000) + { + return false; + } + + // "A 64-bit process on 64-bit Windows has a virtual address space within the 128-terabyte range 0x000'00000000 through 0x7FFF'FFFFFFFF" + // https://learn.microsoft.com/en-us/windows-hardware/drivers/gettingstarted/virtual-address-spaces + if (s_nPtr > 0x7FFFFFFFFFFF) + { + return false; + } + + // aligned to 4 byte boundary? + // not guranteed, but most pointers do follow this. + if (s_nPtr % 4 != 0) + { + return false; + } + + /* + // check against application address space range. + SYSTEM_INFO s_SysInfo; + GetSystemInfo(&s_SysInfo); + const auto s_nMinAppAddress = reinterpret_cast(s_SysInfo.lpMinimumApplicationAddress); + const auto s_nMaxAppAddress = reinterpret_cast(s_SysInfo.lpMaximumApplicationAddress); + if (s_nPtr < s_nMinAppAddress || s_nPtr > s_nMaxAppAddress) + { + return false; + } + */ + + // looks reasonable enough + return true; +} diff --git a/src/Helpers/Utils.h b/src/Helpers/Utils.h index 72df614..eb1f677 100644 --- a/src/Helpers/Utils.h +++ b/src/Helpers/Utils.h @@ -46,4 +46,15 @@ namespace Utils * Convert a string to lowercase, without modifying the input string. */ std::string ToLower(const std::string& p_sInput); + + + /** + * Heuristic check if a pointer can be considered reasonable, checking + * for common failure cases observed in the engine. + * If this function returns false, the pointer is likely invalid and should not be dereferenced. + * TL;DR: this is basically a fancy nullptr check. + * + * @param p_pPtr Pointer to check. + */ + bool IsReasonablePointer(const void* p_pPtr); }; // namespace Utils \ No newline at end of file From 41151dc52c9b1ca1c3d4070d5686f8a8425eb7fb Mon Sep 17 00:00:00 2001 From: shadow578 <52449218+shadow578@users.noreply.github.com> Date: Mon, 2 Nov 2026 18:52:56 +0100 Subject: [PATCH 3/8] fix occasional crash of ZAuthoritativeFigureEffect --- .../Player/ZAuthoritativeFigureEffect.cpp | 26 ++++++++++++++++--- .../Player/ZAuthoritativeFigureEffect.h | 1 + src/Helpers/EntityUtils.cpp | 6 ++--- src/Helpers/EntityUtils.h | 8 ++++++ src/Helpers/PlayerUtils.cpp | 7 ++--- 5 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/Effects/Player/ZAuthoritativeFigureEffect.cpp b/src/Effects/Player/ZAuthoritativeFigureEffect.cpp index 82e08ba..66554c3 100644 --- a/src/Effects/Player/ZAuthoritativeFigureEffect.cpp +++ b/src/Effects/Player/ZAuthoritativeFigureEffect.cpp @@ -2,6 +2,7 @@ #include #include +#include #include "Registry.h" #include "Helpers/Math.h" @@ -41,8 +42,8 @@ void ZAuthoritativeFigureEffect::Start() m_bOriginalWeaponsAllowed = m_SelectedOutfit.m_pInterfaceRef->m_bWeaponsAllowed; // make outfit a authoritative figure - m_SelectedOutfit.m_pInterfaceRef->m_bAuthorityFigure = true; - m_SelectedOutfit.m_pInterfaceRef->m_bWeaponsAllowed = true; + //m_SelectedOutfit.m_pInterfaceRef->m_bAuthorityFigure = true; + //m_SelectedOutfit.m_pInterfaceRef->m_bWeaponsAllowed = true; } void ZAuthoritativeFigureEffect::Stop() @@ -52,8 +53,8 @@ void ZAuthoritativeFigureEffect::Stop() return; } - m_SelectedOutfit.m_pInterfaceRef->m_bAuthorityFigure = m_bOriginalAuthorityFigure; - m_SelectedOutfit.m_pInterfaceRef->m_bWeaponsAllowed = m_bOriginalWeaponsAllowed; + //m_SelectedOutfit.m_pInterfaceRef->m_bAuthorityFigure = m_bOriginalAuthorityFigure; + //m_SelectedOutfit.m_pInterfaceRef->m_bWeaponsAllowed = m_bOriginalWeaponsAllowed; } bool ZAuthoritativeFigureEffect::Available() const @@ -61,4 +62,21 @@ bool ZAuthoritativeFigureEffect::Available() const return IChaosEffect::Available() && Globals::ContentKitManager != nullptr; } + +void ZAuthoritativeFigureEffect::OnDrawDebugUI() +{ + ImGui::TextUnformatted("Outfits:"); + for (auto s_sOutfitName : m_aOutfitCommonNames) + { + if (ImGui::Button(s_sOutfitName.c_str())) + { + if (!Utils::SetPlayerOutfit(s_sOutfitName, m_SelectedOutfit)) + { + Logger::Error(TAG "Failed to set outfit."); + return; + } + } + } +} + REGISTER_CHAOS_EFFECT(ZAuthoritativeFigureEffect); diff --git a/src/Effects/Player/ZAuthoritativeFigureEffect.h b/src/Effects/Player/ZAuthoritativeFigureEffect.h index 33369b4..6f7b547 100644 --- a/src/Effects/Player/ZAuthoritativeFigureEffect.h +++ b/src/Effects/Player/ZAuthoritativeFigureEffect.h @@ -15,6 +15,7 @@ class ZAuthoritativeFigureEffect : public IChaosEffect void Start() override; void Stop() override; bool Available() const override; + void OnDrawDebugUI() override; std::string GetDisplayName(const bool p_bVoting) const override { diff --git a/src/Helpers/EntityUtils.cpp b/src/Helpers/EntityUtils.cpp index bb92c20..6e705c9 100644 --- a/src/Helpers/EntityUtils.cpp +++ b/src/Helpers/EntityUtils.cpp @@ -8,8 +8,6 @@ #include -#include "Utils.h" - #define TAG "[EntityUtils] " std::vector Utils::ZEntityFinder::Find(const size_t p_nMaxResults) const @@ -220,7 +218,7 @@ static bool IsValidBlueprintFactoryPointer(ZEntityBlueprintFactoryBase* p_pBpFac if (!Utils::IsReasonablePointer(p_pBpFactory)) { #if _DEBUG - Logger::Error(TAG "Got likely invalid blueprint factory pointer {}.", p_pBpFactory); + Logger::Error(TAG "Got likely invalid blueprint factory pointer {:016X}.", reinterpret_cast(p_pBpFactory)); #endif return false; @@ -343,7 +341,7 @@ bool Utils::IsReasonableEntityRef(const ZEntityRef& p_rEntity) } const auto s_nEid = p_rEntity->GetType()->m_nEntityID; - if (s_nEid == 0 || s_nEid == 0xFFFFFFFF) + if (s_nEid == 0 /* || s_nEid == 0xFFFFFFFF */) { return false; } diff --git a/src/Helpers/EntityUtils.h b/src/Helpers/EntityUtils.h index f8d9735..fca690e 100644 --- a/src/Helpers/EntityUtils.h +++ b/src/Helpers/EntityUtils.h @@ -10,6 +10,8 @@ #include #include +#include "Utils.h" + #define TAG "[EntityUtils] " namespace Utils @@ -126,6 +128,12 @@ namespace Utils * @param p_rEntity The entity reference to check. */ bool IsReasonableEntityRef(const ZEntityRef& p_rEntity); + template + inline bool IsReasonableEntityRef(const TEntityRef& p_rEntity) + { + return IsReasonableEntityRef(p_rEntity.m_entityRef) + && Utils::IsReasonablePointer(p_rEntity.m_pInterfaceRef); + } /** * safely get a property from an entity. Returns std::nullopt if failed or invalid. diff --git a/src/Helpers/PlayerUtils.cpp b/src/Helpers/PlayerUtils.cpp index 51973d2..27a833e 100644 --- a/src/Helpers/PlayerUtils.cpp +++ b/src/Helpers/PlayerUtils.cpp @@ -6,6 +6,7 @@ #include #include +#include "Helpers/Utils.h" #include "Helpers/EntityUtils.h" #include "Entity/EntityIds.h" @@ -66,13 +67,13 @@ bool Utils::TeleportPlayer(const SMatrix p_mTransform, SMatrix& p_mOldTransform, bool Utils::SetPlayerOutfit(const std::string& p_sCommonName, TEntityRef& p_OutfitOut) { const auto s_Player = Utils::GetLocalPlayer(); - if (!s_Player) + if (!Utils::IsReasonableEntityRef(s_Player)) { return false; } const auto* s_pContentKitManager = Globals::ContentKitManager; - if (!s_pContentKitManager) + if (!Utils::IsReasonablePointer(s_pContentKitManager)) { return false; } @@ -80,7 +81,7 @@ bool Utils::SetPlayerOutfit(const std::string& p_sCommonName, TEntityRefm_repositoryGlobalOutfitKits) { const auto& s_OutfitKit = s_KV.second; - if (!s_OutfitKit || !s_OutfitKit.m_pInterfaceRef) + if (!Utils::IsReasonableEntityRef(s_OutfitKit)) { continue; } From 51a0bb93e86749d07dc68bd7df0b5ca8be08dea7 Mon Sep 17 00:00:00 2001 From: shadow578 <52449218+shadow578@users.noreply.github.com> Date: Tue, 3 Nov 2026 11:29:49 +0100 Subject: [PATCH 4/8] improve misc. handling of invalid entities and props in utils --- src/Entity/Bindings/EntityBinding.h | 2 +- src/Helpers/EntityUtils.cpp | 33 ++++++++++++++++------------- src/Helpers/EntityUtils.h | 8 ++++++- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/Entity/Bindings/EntityBinding.h b/src/Entity/Bindings/EntityBinding.h index 7dd85b3..e6b51b0 100644 --- a/src/Entity/Bindings/EntityBinding.h +++ b/src/Entity/Bindings/EntityBinding.h @@ -37,7 +37,7 @@ struct SEntityBinding operator bool() const { - return !!m_rEntity; + return m_rEntity && Utils::IsReasonableEntityRef(m_rEntity); } }; diff --git a/src/Helpers/EntityUtils.cpp b/src/Helpers/EntityUtils.cpp index 6e705c9..4b1ea90 100644 --- a/src/Helpers/EntityUtils.cpp +++ b/src/Helpers/EntityUtils.cpp @@ -32,48 +32,52 @@ std::vector Utils::ZEntityFinder::Find(const size_t p_nMaxResults) c for (const auto& s_Brick : s_pSceneCtx->m_aLoadedBricks) { - const auto s_Entity = s_Brick.m_EntityRef; - if (!s_Entity) + const auto s_rEntity = s_Brick.m_EntityRef; + if (!Utils::IsReasonableEntityRef(s_rEntity)) { continue; } - const auto s_pBpFactory = s_Entity.GetBlueprintFactory(); - if (!s_pBpFactory) + const auto s_pBpFactory = s_rEntity.GetBlueprintFactory(); + if (!s_pBpFactory || !Utils::IsReasonablePointer(s_pBpFactory)) { continue; } - s_aNodeQueue.emplace_back(s_pBpFactory, s_Entity); + s_aNodeQueue.emplace_back(s_pBpFactory, s_rEntity); } while (s_nCurrentQueueIndex < s_aNodeQueue.size()) { - auto [s_pCurrentFactory, s_CurrentRoot] = s_aNodeQueue[s_nCurrentQueueIndex]; + auto [s_pCurrentFactory, s_rCurrentRoot] = s_aNodeQueue[s_nCurrentQueueIndex]; s_nCurrentQueueIndex++; // go through each sub-entity - const auto s_SubEntityCount = s_pCurrentFactory->GetSubEntitiesCount(); - for (int i = 0; i < s_SubEntityCount; ++i) + const auto s_nSubEntityCount = s_pCurrentFactory->GetSubEntitiesCount(); + for (int i = 0; i < s_nSubEntityCount; ++i) { - const ZEntityRef s_SubEntity = s_pCurrentFactory->GetSubEntity(s_CurrentRoot.m_pObj, i); + const ZEntityRef s_rSubEntity = s_pCurrentFactory->GetSubEntity(s_rCurrentRoot.m_pObj, i); const auto s_pSubEntityFactory = s_pCurrentFactory->GetSubEntityBlueprint(i); - if (!s_SubEntity.GetEntity() || !s_SubEntity->GetType()) + if (!s_rSubEntity + || !s_rSubEntity->GetType() + || !Utils::IsReasonableEntityRef(s_rSubEntity)) { continue; } // if the sub-entity has a factory with more sub-entities, add it to the queue. - if (s_pSubEntityFactory && s_pSubEntityFactory->GetSubEntitiesCount() > 0) + if (s_pSubEntityFactory + && Utils::IsReasonablePointer(s_pSubEntityFactory) + && s_pSubEntityFactory->GetSubEntitiesCount() > 0) { - s_aNodeQueue.emplace_back(s_pSubEntityFactory, s_SubEntity); + s_aNodeQueue.emplace_back(s_pSubEntityFactory, s_rSubEntity); } // add if matches - if (Evaluate(s_SubEntity, s_pCurrentFactory, s_pSubEntityFactory, i)) + if (Evaluate(s_rSubEntity, s_pCurrentFactory, s_pSubEntityFactory, i)) { - s_aFoundEntities.push_back(s_SubEntity); + s_aFoundEntities.push_back(s_rSubEntity); // check max results limit if (p_nMaxResults != 0 && s_aFoundEntities.size() >= p_nMaxResults) @@ -317,7 +321,6 @@ ZEntityRef Utils::GetSubEntity(const ZEntityRef p_rParent, const uint64_t p_nSub return {}; } - bool Utils::IsReasonableEntityRef(const ZEntityRef& p_rEntity) { if (!p_rEntity) diff --git a/src/Helpers/EntityUtils.h b/src/Helpers/EntityUtils.h index fca690e..142f23a 100644 --- a/src/Helpers/EntityUtils.h +++ b/src/Helpers/EntityUtils.h @@ -150,9 +150,15 @@ namespace Utils } auto s_PropValue = p_rEntity.GetProperty(p_sProperty); + if (s_PropValue.IsEmpty()) + { + Logger::Debug(TAG "Failed to get '{}' on EID {:016X}: was null.", p_sProperty, p_rEntity ? p_rEntity.GetEntity()->GetType()->m_nEntityID : 0); + return std::nullopt; + } + if (!s_PropValue.Is()) { - Logger::Warn(TAG "Failed to get '{}' on EID {:016X}", p_sProperty, p_rEntity ? p_rEntity.GetEntity()->GetType()->m_nEntityID : 0); + Logger::Warn(TAG "Failed to get '{}' on EID {:016X}: type is mismatched!", p_sProperty, p_rEntity ? p_rEntity.GetEntity()->GetType()->m_nEntityID : 0); return std::nullopt; } From 4c751662249674a5d0b4e28b33aa65c5ff68b03e Mon Sep 17 00:00:00 2001 From: shadow578 <52449218+shadow578@users.noreply.github.com> Date: Tue, 3 Nov 2026 11:30:19 +0100 Subject: [PATCH 5/8] fix incorrect type of m_rSpeakingActor in ZSpeakEntity_SondDef binding fixes console spam --- src/Entity/Bindings/SSpeakEntitySounddefBinding.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Entity/Bindings/SSpeakEntitySounddefBinding.h b/src/Entity/Bindings/SSpeakEntitySounddefBinding.h index b625ce3..a8dba6a 100644 --- a/src/Entity/Bindings/SSpeakEntitySounddefBinding.h +++ b/src/Entity/Bindings/SSpeakEntitySounddefBinding.h @@ -1,13 +1,15 @@ #pragma once #include "Entity/Bindings/EntityBinding.h" +class ZActor; + // [modules:/zspeakentity_sounddef.class].pc_entitytype struct SSpeakEntitySounddefBinding : SEntityBinding { using SEntityBinding::SEntityBinding; PROPERTY(ZEntityRef, m_rActor); // actor who will speak - PROPERTY_RO(ZEntityRef, m_rSpeakingActor); // while speaking == m_rActor, null when not speaking + PROPERTY_RO(TEntityRef, m_rSpeakingActor); // while speaking == m_rActor, null when not speaking PROPERTY(EGestureCategory, m_eGesture); // gesture to play while speaking PROPERTY(EActorSoundDefs, m_eSoundDef); // sounddef to speak PROPERTY(bool, m_bAllowInterrupt); // allow interrupting currently playing speech with this one From 1a55b0ce9dc0f04c4bca075f5e7f1fc0bc55563f Mon Sep 17 00:00:00 2001 From: shadow578 <52449218+shadow578@users.noreply.github.com> Date: Tue, 3 Nov 2026 11:42:13 +0100 Subject: [PATCH 6/8] skip disabled actors in GetActors() --- src/Helpers/ActorUtils.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Helpers/ActorUtils.cpp b/src/Helpers/ActorUtils.cpp index 808fb35..3381f7c 100644 --- a/src/Helpers/ActorUtils.cpp +++ b/src/Helpers/ActorUtils.cpp @@ -23,7 +23,9 @@ std::vector> Utils::GetActors(const bool p_bIncludeDead, cons for (auto& s_rActor : Globals::ActorManager->m_activatedActors) { - if (!s_rActor) + if (!s_rActor + || !Utils::IsReasonableEntityRef(s_rActor) + || !s_rActor.m_pInterfaceRef->m_bEnabled) { continue; } From 7bee0d13ef1fa8bfcb8b8c428e19ecd054eb7bf4 Mon Sep 17 00:00:00 2001 From: shadow578 <52449218+shadow578@users.noreply.github.com> Date: Tue, 3 Nov 2026 11:42:52 +0100 Subject: [PATCH 7/8] autoformat --- src/Effects/Player/ZAuthoritativeFigureEffect.cpp | 11 +++++------ src/Entity/Bindings/SSpeakEntitySounddefBinding.h | 8 ++++---- src/Helpers/ActorUtils.cpp | 4 ++-- src/Helpers/EntityUtils.cpp | 8 ++++---- src/Helpers/EntityUtils.h | 4 ++-- src/Helpers/Utils.cpp | 2 +- src/Helpers/Utils.h | 5 ++--- 7 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/Effects/Player/ZAuthoritativeFigureEffect.cpp b/src/Effects/Player/ZAuthoritativeFigureEffect.cpp index 66554c3..12292ef 100644 --- a/src/Effects/Player/ZAuthoritativeFigureEffect.cpp +++ b/src/Effects/Player/ZAuthoritativeFigureEffect.cpp @@ -42,8 +42,8 @@ void ZAuthoritativeFigureEffect::Start() m_bOriginalWeaponsAllowed = m_SelectedOutfit.m_pInterfaceRef->m_bWeaponsAllowed; // make outfit a authoritative figure - //m_SelectedOutfit.m_pInterfaceRef->m_bAuthorityFigure = true; - //m_SelectedOutfit.m_pInterfaceRef->m_bWeaponsAllowed = true; + // m_SelectedOutfit.m_pInterfaceRef->m_bAuthorityFigure = true; + // m_SelectedOutfit.m_pInterfaceRef->m_bWeaponsAllowed = true; } void ZAuthoritativeFigureEffect::Stop() @@ -53,8 +53,8 @@ void ZAuthoritativeFigureEffect::Stop() return; } - //m_SelectedOutfit.m_pInterfaceRef->m_bAuthorityFigure = m_bOriginalAuthorityFigure; - //m_SelectedOutfit.m_pInterfaceRef->m_bWeaponsAllowed = m_bOriginalWeaponsAllowed; + // m_SelectedOutfit.m_pInterfaceRef->m_bAuthorityFigure = m_bOriginalAuthorityFigure; + // m_SelectedOutfit.m_pInterfaceRef->m_bWeaponsAllowed = m_bOriginalWeaponsAllowed; } bool ZAuthoritativeFigureEffect::Available() const @@ -62,13 +62,12 @@ bool ZAuthoritativeFigureEffect::Available() const return IChaosEffect::Available() && Globals::ContentKitManager != nullptr; } - void ZAuthoritativeFigureEffect::OnDrawDebugUI() { ImGui::TextUnformatted("Outfits:"); for (auto s_sOutfitName : m_aOutfitCommonNames) { - if (ImGui::Button(s_sOutfitName.c_str())) + if (ImGui::Button(s_sOutfitName.c_str())) { if (!Utils::SetPlayerOutfit(s_sOutfitName, m_SelectedOutfit)) { diff --git a/src/Entity/Bindings/SSpeakEntitySounddefBinding.h b/src/Entity/Bindings/SSpeakEntitySounddefBinding.h index a8dba6a..7d7dc6f 100644 --- a/src/Entity/Bindings/SSpeakEntitySounddefBinding.h +++ b/src/Entity/Bindings/SSpeakEntitySounddefBinding.h @@ -8,11 +8,11 @@ struct SSpeakEntitySounddefBinding : SEntityBinding { using SEntityBinding::SEntityBinding; - PROPERTY(ZEntityRef, m_rActor); // actor who will speak + PROPERTY(ZEntityRef, m_rActor); // actor who will speak PROPERTY_RO(TEntityRef, m_rSpeakingActor); // while speaking == m_rActor, null when not speaking - PROPERTY(EGestureCategory, m_eGesture); // gesture to play while speaking - PROPERTY(EActorSoundDefs, m_eSoundDef); // sounddef to speak - PROPERTY(bool, m_bAllowInterrupt); // allow interrupting currently playing speech with this one + PROPERTY(EGestureCategory, m_eGesture); // gesture to play while speaking + PROPERTY(EActorSoundDefs, m_eSoundDef); // sounddef to speak + PROPERTY(bool, m_bAllowInterrupt); // allow interrupting currently playing speech with this one PROPERTY(bool, m_bEnableCulling); INPUT_PIN(Start); // start speaking diff --git a/src/Helpers/ActorUtils.cpp b/src/Helpers/ActorUtils.cpp index 3381f7c..ddaffc7 100644 --- a/src/Helpers/ActorUtils.cpp +++ b/src/Helpers/ActorUtils.cpp @@ -23,8 +23,8 @@ std::vector> Utils::GetActors(const bool p_bIncludeDead, cons for (auto& s_rActor : Globals::ActorManager->m_activatedActors) { - if (!s_rActor - || !Utils::IsReasonableEntityRef(s_rActor) + if (!s_rActor + || !Utils::IsReasonableEntityRef(s_rActor) || !s_rActor.m_pInterfaceRef->m_bEnabled) { continue; diff --git a/src/Helpers/EntityUtils.cpp b/src/Helpers/EntityUtils.cpp index 4b1ea90..31631de 100644 --- a/src/Helpers/EntityUtils.cpp +++ b/src/Helpers/EntityUtils.cpp @@ -59,16 +59,16 @@ std::vector Utils::ZEntityFinder::Find(const size_t p_nMaxResults) c const ZEntityRef s_rSubEntity = s_pCurrentFactory->GetSubEntity(s_rCurrentRoot.m_pObj, i); const auto s_pSubEntityFactory = s_pCurrentFactory->GetSubEntityBlueprint(i); - if (!s_rSubEntity - || !s_rSubEntity->GetType() + if (!s_rSubEntity + || !s_rSubEntity->GetType() || !Utils::IsReasonableEntityRef(s_rSubEntity)) { continue; } // if the sub-entity has a factory with more sub-entities, add it to the queue. - if (s_pSubEntityFactory - && Utils::IsReasonablePointer(s_pSubEntityFactory) + if (s_pSubEntityFactory + && Utils::IsReasonablePointer(s_pSubEntityFactory) && s_pSubEntityFactory->GetSubEntitiesCount() > 0) { s_aNodeQueue.emplace_back(s_pSubEntityFactory, s_rSubEntity); diff --git a/src/Helpers/EntityUtils.h b/src/Helpers/EntityUtils.h index 142f23a..fac851c 100644 --- a/src/Helpers/EntityUtils.h +++ b/src/Helpers/EntityUtils.h @@ -131,8 +131,8 @@ namespace Utils template inline bool IsReasonableEntityRef(const TEntityRef& p_rEntity) { - return IsReasonableEntityRef(p_rEntity.m_entityRef) - && Utils::IsReasonablePointer(p_rEntity.m_pInterfaceRef); + return IsReasonableEntityRef(p_rEntity.m_entityRef) + && Utils::IsReasonablePointer(p_rEntity.m_pInterfaceRef); } /** diff --git a/src/Helpers/Utils.cpp b/src/Helpers/Utils.cpp index 465c255..c5664ad 100644 --- a/src/Helpers/Utils.cpp +++ b/src/Helpers/Utils.cpp @@ -104,7 +104,7 @@ bool Utils::IsReasonablePointer(const void* p_pPtr) { return false; } - */ + */ // looks reasonable enough return true; diff --git a/src/Helpers/Utils.h b/src/Helpers/Utils.h index eb1f677..76acf1e 100644 --- a/src/Helpers/Utils.h +++ b/src/Helpers/Utils.h @@ -47,13 +47,12 @@ namespace Utils */ std::string ToLower(const std::string& p_sInput); - /** - * Heuristic check if a pointer can be considered reasonable, checking + * Heuristic check if a pointer can be considered reasonable, checking * for common failure cases observed in the engine. * If this function returns false, the pointer is likely invalid and should not be dereferenced. * TL;DR: this is basically a fancy nullptr check. - * + * * @param p_pPtr Pointer to check. */ bool IsReasonablePointer(const void* p_pPtr); From 5a395b86e49b69006476dc12387d169ca5af7b1d Mon Sep 17 00:00:00 2001 From: shadow578 <52449218+shadow578@users.noreply.github.com> Date: Tue, 3 Nov 2026 11:46:55 +0100 Subject: [PATCH 8/8] refactor IsReasonableEntityRef --- src/Helpers/EntityUtils.cpp | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/Helpers/EntityUtils.cpp b/src/Helpers/EntityUtils.cpp index 31631de..72c7f90 100644 --- a/src/Helpers/EntityUtils.cpp +++ b/src/Helpers/EntityUtils.cpp @@ -323,22 +323,10 @@ ZEntityRef Utils::GetSubEntity(const ZEntityRef p_rParent, const uint64_t p_nSub bool Utils::IsReasonableEntityRef(const ZEntityRef& p_rEntity) { - if (!p_rEntity) - { - return false; - } - - if (!Utils::IsReasonablePointer(p_rEntity.m_pObj)) - { - return false; - } - - if (!Utils::IsReasonablePointer(p_rEntity.GetEntity())) - { - return false; - } - - if (!Utils::IsReasonablePointer(p_rEntity->GetType())) + if (!p_rEntity + || !Utils::IsReasonablePointer(p_rEntity.m_pObj) + || !Utils::IsReasonablePointer(p_rEntity.GetEntity()) + || !Utils::IsReasonablePointer(p_rEntity->GetType())) { return false; }