From de2ad3d9b08ade68c196fb03526e055e0d28a81c Mon Sep 17 00:00:00 2001 From: Jan Date: Thu, 12 Jun 2025 21:02:23 +0100 Subject: [PATCH] chore: make allocating redirect entry work with ptr directly --- .../Generating/Templates/ZoneLoadTemplate.cpp | 4 ++-- src/ZoneLoading/Game/IW4/ContentLoaderIW4.cpp | 2 +- src/ZoneLoading/Zone/Stream/ZoneInputStream.cpp | 5 +++-- src/ZoneLoading/Zone/Stream/ZoneInputStream.h | 7 +------ 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneLoadTemplate.cpp b/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneLoadTemplate.cpp index d4909a94..d06aa446 100644 --- a/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneLoadTemplate.cpp +++ b/src/ZoneCodeGeneratorLib/Generating/Templates/ZoneLoadTemplate.cpp @@ -567,7 +567,7 @@ namespace if (memberInfo.m_is_reusable || (memberInfo.m_type && StructureComputations(memberInfo.m_type).IsAsset())) { - LINEF("fillAccessor.InsertPointerRedirect(m_stream.AllocRedirectEntry({0}), {1});", + LINEF("fillAccessor.InsertPointerRedirect(m_stream.AllocRedirectEntry(&{0}), {1});", MakeMemberAccess(&structInfo, &memberInfo, modifier), OffsetForMemberModifier(memberInfo, modifier, nestedBaseOffset)) } @@ -1019,7 +1019,7 @@ namespace if (reusable || (info && StructureComputations(info).IsAsset())) { - LINEF("ptrArrayFill.InsertPointerRedirect(m_stream.AllocRedirectEntry({0}[index]), {1} * index);", + LINEF("ptrArrayFill.InsertPointerRedirect(m_stream.AllocRedirectEntry(&{0}[index]), {1} * index);", MakeTypePtrVarName(def), m_env.m_pointer_size) } diff --git a/src/ZoneLoading/Game/IW4/ContentLoaderIW4.cpp b/src/ZoneLoading/Game/IW4/ContentLoaderIW4.cpp index ea48f387..3b49930c 100644 --- a/src/ZoneLoading/Game/IW4/ContentLoaderIW4.cpp +++ b/src/ZoneLoading/Game/IW4/ContentLoaderIW4.cpp @@ -155,7 +155,7 @@ void ContentLoader::LoadXAssetArray(const bool atStreamStart, const size_t count { fill.Fill(varXAsset[index].type, 8u * index); fill.FillPtr(varXAsset[index].header.data, 8u * index + 4u); - fill.InsertPointerRedirect(m_stream.AllocRedirectEntry(varXAsset[index].header.data), 8u * index + 4u); + fill.InsertPointerRedirect(m_stream.AllocRedirectEntry(&varXAsset[index].header.data), 8u * index + 4u); } #endif } diff --git a/src/ZoneLoading/Zone/Stream/ZoneInputStream.cpp b/src/ZoneLoading/Zone/Stream/ZoneInputStream.cpp index ddc73227..200e336e 100644 --- a/src/ZoneLoading/Zone/Stream/ZoneInputStream.cpp +++ b/src/ZoneLoading/Zone/Stream/ZoneInputStream.cpp @@ -355,10 +355,11 @@ namespace return *reinterpret_cast(&block->m_buffer[blockOffset]); } - uintptr_t AllocRedirectEntry(void** alias) override + uintptr_t AllocRedirectEntry(void* alias) override { // nullptr is always lookup alias 0 - if (*alias == nullptr) + assert(alias); + if (alias == nullptr) return 0; const auto newIndex = m_pointer_redirect_lookup.size(); diff --git a/src/ZoneLoading/Zone/Stream/ZoneInputStream.h b/src/ZoneLoading/Zone/Stream/ZoneInputStream.h index 99d09f09..b881c26d 100644 --- a/src/ZoneLoading/Zone/Stream/ZoneInputStream.h +++ b/src/ZoneLoading/Zone/Stream/ZoneInputStream.h @@ -151,12 +151,7 @@ public: return static_cast(ConvertOffsetToAliasNative(static_cast(offset))); } - virtual uintptr_t AllocRedirectEntry(void** alias) = 0; - - template uintptr_t AllocRedirectEntry(T*& offset) - { - return AllocRedirectEntry(reinterpret_cast(const_cast**>(&offset))); - } + virtual uintptr_t AllocRedirectEntry(void* alias) = 0; virtual void* ConvertOffsetToPointerRedirect(const void* offset) = 0;