From 7006ba0f624054ddfe5d822eadeb60ece778f74b Mon Sep 17 00:00:00 2001 From: Zachary Lockwood Date: Fri, 23 Jun 2023 14:08:50 -0400 Subject: [PATCH] added better detection for the old string8s arrays generated from SMFX --- UniversalPropertyEnhancer/Property.h | 25 +++++++++++++------ .../UniversalPropertyPostInit.cpp | 8 +++--- .../UniversalPropertyReplacement.cpp | 9 ++++--- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/UniversalPropertyEnhancer/Property.h b/UniversalPropertyEnhancer/Property.h index e2964ef..f732504 100644 --- a/UniversalPropertyEnhancer/Property.h +++ b/UniversalPropertyEnhancer/Property.h @@ -52,18 +52,27 @@ namespace Extensions const char * mEnd; }; - static bool GetArrayString8(const App::PropertyList* pPropertyList, uint32_t propertyID, size_t& dstCount, array_string_8*& dst) + static bool Get8ByteArrayString8(const App::PropertyList* pPropertyList, uint32_t propertyID, size_t& dstCount, array_string_8*& dst) { - //as much as GetArrayString8 says it gives a string8 array it doesn't. - return App::Property::GetArrayString8(pPropertyList, propertyID, dstCount, reinterpret_cast(dst)); + dstCount = 0; + dst = nullptr; + + App::Property* prop; + if (!pPropertyList->GetProperty(propertyID, prop)) + return false; + + const auto extProp = static_cast(prop); + + if (extProp->mnType != App::PropertyType::String8 || !extProp->IsArray() || extProp->GetItemSize() != 8) + return false; + + dst = static_cast(extProp->GetValue()); + dstCount = extProp->GetItemCount(); + + return true; } }; - inline void CopyProperty(App::Property * prop, App::Property * copy_prop) - { - memcpy(copy_prop, prop, sizeof(App::Property)); - } - inline size_t GetArrayItemCount(App::Property * prop) { const auto prop_ex = static_cast(prop); diff --git a/UniversalPropertyEnhancer/UniversalPropertyPostInit.cpp b/UniversalPropertyEnhancer/UniversalPropertyPostInit.cpp index fcdcfe7..2641289 100644 --- a/UniversalPropertyEnhancer/UniversalPropertyPostInit.cpp +++ b/UniversalPropertyEnhancer/UniversalPropertyPostInit.cpp @@ -39,9 +39,11 @@ namespace UniversalPropertyPostInit { size_t stringCount = 0; eastl::string8* stringList = nullptr; Extensions::Property::array_string_8* altStringList = nullptr; - App::Property::GetArrayString8(propList.get(), id("postinitList"), stringCount, stringList); - Extensions::Property::GetArrayString8(propList.get(), id("postinitList"), stringCount, altStringList); - const bool is_bad_array_string = stringCount > 1 && altStringList[1].mEnd >= altStringList[1].mBegin; + const bool is_bad_array_string = Extensions::Property::Get8ByteArrayString8(propList.get(), id("postinitList"), stringCount, altStringList); + if (!is_bad_array_string) + { + App::Property::GetArrayString8(propList.get(), id("postinitList"), stringCount, stringList); + } for (size_t j = 0; j < stringCount; j++) { ResourceKey postinit {}; diff --git a/UniversalPropertyEnhancer/UniversalPropertyReplacement.cpp b/UniversalPropertyEnhancer/UniversalPropertyReplacement.cpp index 8975fc7..5fcf877 100644 --- a/UniversalPropertyEnhancer/UniversalPropertyReplacement.cpp +++ b/UniversalPropertyEnhancer/UniversalPropertyReplacement.cpp @@ -42,9 +42,12 @@ namespace UniversalPropertyReplacement { size_t stringCount = 0; eastl::string8* stringList = nullptr; Extensions::Property::array_string_8* altStringList = nullptr; - App::Property::GetArrayString8(propList.get(), id("replacementList"), stringCount, stringList); - Extensions::Property::GetArrayString8(propList.get(), id("replacementList"), stringCount, altStringList); - const bool is_bad_array_string = stringCount > 1 && altStringList[1].mEnd >= altStringList[1].mBegin; + const bool is_bad_array_string = Extensions::Property::Get8ByteArrayString8(propList.get(), id("replacementList"), stringCount, altStringList); + if (!is_bad_array_string) + { + App::Property::GetArrayString8(propList.get(), id("replacementList"), stringCount, stringList); + } + for (size_t j = 0; j < stringCount; j++) { bool result = false; union AppExtProperty