From 8fa154e8fa363d04e3371647b64a2c913884af8d Mon Sep 17 00:00:00 2001 From: FynnTW Date: Fri, 20 Dec 2024 13:16:04 +0200 Subject: [PATCH] game std string fix --- M2TWEOP Code/M2TWEOP library/realGameTypes.h | 29 ++++++++++++++++++-- M2TWEOP Code/M2TWEOP library/types/unit.h | 6 ++-- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/M2TWEOP Code/M2TWEOP library/realGameTypes.h b/M2TWEOP Code/M2TWEOP library/realGameTypes.h index 39f92a10..efec3c44 100644 --- a/M2TWEOP Code/M2TWEOP library/realGameTypes.h +++ b/M2TWEOP Code/M2TWEOP library/realGameTypes.h @@ -40,15 +40,38 @@ ReturnType callClassFunc(ClassType instance, const DWORD offset, TArgs ... args) struct basicStringGame { - char pad[0x1C]; + char pad[0x4]; + union + { + char* long_string; + char short_string[16]; + }; + int stringLength; + int stringCapacity; public: + char* getData () + { + if (stringCapacity < 16) + return short_string; + return long_string; + } + std::string getString() { - return *reinterpret_cast(this); + const char* str = getData(); + return {str}; } + void setString(const std::string& str) { - *reinterpret_cast(this) = str; + if (stringCapacity < 16) + { + strcpy(short_string, str.c_str()); + } + else + { + strcpy(long_string, str.c_str()); + } } }; diff --git a/M2TWEOP Code/M2TWEOP library/types/unit.h b/M2TWEOP Code/M2TWEOP library/types/unit.h index 382309af..2ef5b2a9 100644 --- a/M2TWEOP Code/M2TWEOP library/types/unit.h +++ b/M2TWEOP Code/M2TWEOP library/types/unit.h @@ -1280,7 +1280,8 @@ struct eduEntry { return ""; if (modelEntry->skeletons.empty()) return ""; - return modelEntry->skeletons[0].primary.getString(); + std::string name = modelEntry->skeletons[0].primary.getString(); + return name; } std::string getSecondaryAnim() @@ -1289,7 +1290,8 @@ struct eduEntry { return ""; if (modelEntry->skeletons.empty()) return ""; - return modelEntry->skeletons[0].secondary.getString(); + std::string name = modelEntry->skeletons[0].secondary.getString(); + return name; } bool getIsLegio() {