Skip to content

Commit

Permalink
game std string fix
Browse files Browse the repository at this point in the history
  • Loading branch information
FynnTW committed Dec 20, 2024
1 parent 29cd713 commit 8fa154e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
29 changes: 26 additions & 3 deletions M2TWEOP Code/M2TWEOP library/realGameTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string*>(this);
const char* str = getData();
return {str};
}

void setString(const std::string& str)
{
*reinterpret_cast<std::string*>(this) = str;
if (stringCapacity < 16)
{
strcpy(short_string, str.c_str());
}
else
{
strcpy(long_string, str.c_str());
}
}
};

Expand Down
6 changes: 4 additions & 2 deletions M2TWEOP Code/M2TWEOP library/types/unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
{
Expand Down

0 comments on commit 8fa154e

Please sign in to comment.