Skip to content

Commit

Permalink
[ResourceLib] Fix ZHMArena::GetType when RL is used from a game
Browse files Browse the repository at this point in the history
  • Loading branch information
OrfeasZ committed Nov 10, 2023
1 parent 313a4df commit e9f0c97
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
49 changes: 49 additions & 0 deletions Libraries/ResourceLib/Src/ZHM/ZHMArenas.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,53 @@
#include "ZHMArenas.h"
#include "ZHMTypeInfo.h"

ZHMArena ZHMArenas::g_Arenas[ZHMArenaCount];
ZHMArenas::ZHMArenaInitializer ZHMArenas::g_ArenaInitializer;

IZHMTypeInfo* ZHMArena::GetType(zhmptr_t p_Index) const {
// Real game pointer.
if (m_Id == 0) {
struct STypeFunctions;
class STypeID;
class ZString;

class IType {
public:
STypeFunctions* m_pTypeFunctions;
uint16_t m_nTypeSize;
uint16_t m_nTypeAlignment;
uint16_t m_nTypeInfoFlags;
char* m_pTypeName;
STypeID* m_pTypeID;
bool (*fromString)(void*, IType*, const ZString&);
uint32_t(*toString)(void*, IType*, char*, uint32_t, const ZString&);
};

class STypeID {
public:
inline IType* typeInfo() const
{
if (m_nFlags == 1 || (!m_pType && m_pSource))
return m_pSource->m_pType;

return m_pType;
}

public:
uint16_t m_nFlags;
uint16_t m_nTypeNum;
IType* m_pType;
STypeID* m_pSource;
};


auto s_TypeId = reinterpret_cast<STypeID*>(p_Index);

if (s_TypeId == nullptr || s_TypeId->typeInfo() == nullptr || s_TypeId->typeInfo()->m_pTypeName == nullptr)
return nullptr;

return ZHMTypeInfo::GetTypeByName(std::string(s_TypeId->typeInfo()->m_pTypeName));
}

return m_TypeRegistry[p_Index];
}
5 changes: 1 addition & 4 deletions Libraries/ResourceLib/Src/ZHM/ZHMArenas.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,7 @@ struct ZHMArena
m_TypeIndices[p_Type] = p_Index;
}

[[nodiscard]] IZHMTypeInfo* GetType(uint32_t p_Index) const
{
return m_TypeRegistry[p_Index];
}
[[nodiscard]] IZHMTypeInfo* GetType(zhmptr_t p_Index) const;

[[nodiscard]] uint32_t GetTypeIndex(IZHMTypeInfo* p_Type)
{
Expand Down

0 comments on commit e9f0c97

Please sign in to comment.