Skip to content

Commit

Permalink
added better detection for the old string8s arrays generated from SMFX
Browse files Browse the repository at this point in the history
  • Loading branch information
Zarklord committed Jun 23, 2023
1 parent dbca3d6 commit 7006ba0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
25 changes: 17 additions & 8 deletions UniversalPropertyEnhancer/Property.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<eastl::string*&>(dst));
dstCount = 0;
dst = nullptr;

App::Property* prop;
if (!pPropertyList->GetProperty(propertyID, prop))
return false;

const auto extProp = static_cast<Property*>(prop);

if (extProp->mnType != App::PropertyType::String8 || !extProp->IsArray() || extProp->GetItemSize() != 8)
return false;

dst = static_cast<array_string_8*>(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<Property*>(prop);
Expand Down
8 changes: 5 additions & 3 deletions UniversalPropertyEnhancer/UniversalPropertyPostInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
Expand Down
9 changes: 6 additions & 3 deletions UniversalPropertyEnhancer/UniversalPropertyReplacement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7006ba0

Please sign in to comment.