Skip to content
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions examples/function_registration/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* You have to take care of the type conversion from stack variables, stack management, etc..
*/

void MyGlobalFunc(RED4ext::IScriptable* aContext, RED4ext::CStackFrame* aFrame, RED4ext::CString* aOut, int64_t a4)
void MyGlobalFunc(RED4ext::IScriptable* aContext, RED4ext::CStackFrame* aFrame, RED4ext::String* aOut, int64_t a4)
{
RED4EXT_UNUSED_PARAMETER(aContext);
RED4EXT_UNUSED_PARAMETER(aFrame);
Expand All @@ -30,7 +30,7 @@ void MyGlobalFunc(RED4ext::IScriptable* aContext, RED4ext::CStackFrame* aFrame,

if (aOut)
{
RED4ext::CString result("Returned from MyGlobalFunc");
RED4ext::String result("Returned from MyGlobalFunc");
*aOut = result;
}
}
Expand Down
8 changes: 4 additions & 4 deletions include/RED4ext/CNamePool-inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ RED4EXT_INLINE RED4ext::CName RED4ext::CNamePool::Add(const char* aText)
return result;
}

RED4EXT_INLINE RED4ext::CName RED4ext::CNamePool::Add(const CString& aText)
RED4EXT_INLINE RED4ext::CName RED4ext::CNamePool::Add(const String& aText)
{
CName result;

static UniversalRelocFunc<CName* (*)(CName&, const CString&)> func(Detail::AddressHashes::CNamePool_AddCString);
static UniversalRelocFunc<CName* (*)(CName&, const String&)> func(Detail::AddressHashes::CNamePool_AddCString);
func(result, aText);
return result;
}
Expand All @@ -32,9 +32,9 @@ RED4EXT_INLINE void RED4ext::CNamePool::Add(const CName& aName, const char* aTex
func(aName, aText);
}

RED4EXT_INLINE void RED4ext::CNamePool::Add(const CName& aName, const CString& aText)
RED4EXT_INLINE void RED4ext::CNamePool::Add(const CName& aName, const String& aText)
{
Add(aName, aText.c_str());
Add(aName, aText.AsChar());
}

RED4EXT_INLINE const char* RED4ext::CNamePool::Get(const CName& aName)
Expand Down
6 changes: 3 additions & 3 deletions include/RED4ext/CNamePool.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#pragma once

#include <RED4ext/CName.hpp>
#include <RED4ext/CString.hpp>
#include <RED4ext/String.hpp>

namespace RED4ext
{
struct CNamePool
{
static CName Add(const char* aText);
static CName Add(const CString& aText);
static CName Add(const String& aText);

/**
* @brief Add a hash and text pair.
Expand All @@ -22,7 +22,7 @@ struct CNamePool
* @param aName The hash for \p aText
* @param aText The text.
*/
static void Add(const CName& aName, const CString& aText);
static void Add(const CName& aName, const String& aText);

static const char* Get(const CName& aName);
};
Expand Down
144 changes: 0 additions & 144 deletions include/RED4ext/CString-inl.hpp

This file was deleted.

100 changes: 3 additions & 97 deletions include/RED4ext/CString.hpp
Original file line number Diff line number Diff line change
@@ -1,106 +1,12 @@
#pragma once
#pragma message("WARNING: 'RED4ext/CString.hpp' is deprecated. Please use 'RED4ext/String.hpp' instead.")

#include <RED4ext/Common.hpp>
#include <RED4ext/HashMap.hpp>
#include <cstdint>
#include <string>
#include <string_view>
#include <RED4ext/String.hpp>

namespace RED4ext
{
namespace Memory
struct [[deprecated("Use 'String' instead.")]] CString : String
{
struct IAllocator;
}

struct CString
{
CString(Memory::IAllocator* aAllocator = nullptr);
CString(const char* aText, Memory::IAllocator* aAllocator = nullptr);
CString(const char* aText, uint32_t aLength, Memory::IAllocator* aAllocator = nullptr);
CString(const std::string& aText, Memory::IAllocator* aAllocator = nullptr);
CString(const std::string_view& aText, Memory::IAllocator* aAllocator = nullptr);

CString(const CString& aOther);
CString(CString&& aOther) noexcept;

~CString();

CString& operator=(const CString& aRhs);
CString& operator=(CString&& aRhs) noexcept;

bool operator==(const char* aRhs) const noexcept;
bool operator==(const CString& aRhs) const noexcept;

inline bool operator!=(const char* aRhs) const noexcept
{
return !(*this == aRhs);
}

inline bool operator!=(const CString& aRhs) const noexcept
{
return !(*this == aRhs);
}

inline const char& operator[](size_t aIndex) const
{
return c_str()[aIndex];
}

[[nodiscard]] bool IsInline() const noexcept;

[[nodiscard]] const char* c_str() const noexcept;
[[nodiscard]] uint32_t Length() const noexcept;

[[nodiscard]] const char* begin() const
{
return c_str();
}

[[nodiscard]] const char* end() const
{
return c_str() + Length();
}

#pragma pack(push, 4)
union
{
char inline_str[0x14];
struct
{
char* ptr;
int8_t unk[8];
int32_t capacity;
} str;
} text; // 00
#pragma pack(pop)

uint32_t length; // 14
Memory::IAllocator* allocator; // 18
};
RED4EXT_ASSERT_SIZE(CString, 0x20);
RED4EXT_ASSERT_OFFSET(CString, text, 0x00);
RED4EXT_ASSERT_OFFSET(CString, length, 0x14);
RED4EXT_ASSERT_OFFSET(CString, allocator, 0x18);

template<typename T>
struct HashMapHash<T, std::enable_if_t<std::is_same_v<T, CString>>>
{
uint32_t operator()(const T& aKey) const noexcept
{
// I believe the game uses this implementation for StringView and String?
std::uint32_t hash{};

for (const auto i : aKey)
{
hash = static_cast<std::uint32_t>(i) + 31u * hash;
}

return hash;
}
};
} // namespace RED4ext

#ifdef RED4EXT_HEADER_ONLY
#include <RED4ext/CString-inl.hpp>
#endif
7 changes: 2 additions & 5 deletions include/RED4ext/Detail/AddressHashes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,8 @@ constexpr std::uint32_t CRTTISystem_Get = 0x4A610F64;
constexpr std::uint32_t CStack_vtbl = 0x349A0EE1;
#pragma endregion

#pragma region CString
constexpr std::uint32_t CString_ctor_str = 0xC81F0AAB;
constexpr std::uint32_t CString_ctor_span = 0x7B210877;
constexpr std::uint32_t CString_copy = 0xE8B40B51;
constexpr std::uint32_t CString_dtor = 0x5405072C;
#pragma region String
constexpr std::uint32_t String_SetCapacity = 1744572317UL;
#pragma endregion

#pragma region DeviceData
Expand Down
9 changes: 4 additions & 5 deletions include/RED4ext/Dump/Reflection-inl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -888,10 +888,9 @@ RED4EXT_INLINE std::string TypeToString(const RED4ext::CBaseRTTIType* aType, Nam
{
// Handle some simple type conversions and fundamentals
static std::unordered_map<std::string, std::string> s_typeMap = {
{"Int8", "int8_t"}, {"Int16", "int16_t"}, {"Int32", "int32_t"}, {"Int64", "int64_t"},
{"Uint8", "uint8_t"}, {"Uint16", "uint16_t"}, {"Uint32", "uint32_t"}, {"Uint64", "uint64_t"},
{"Float", "float"}, {"Bool", "bool"}, {"String", "CString"}, {"gameItemID", "ItemID"},
{"Double", "double"}};
{"Int8", "int8_t"}, {"Int16", "int16_t"}, {"Int32", "int32_t"}, {"Int64", "int64_t"},
{"Uint8", "uint8_t"}, {"Uint16", "uint16_t"}, {"Uint32", "uint32_t"}, {"Uint64", "uint64_t"},
{"Float", "float"}, {"Bool", "bool"}, {"gameItemID", "ItemID"}, {"Double", "double"}};

std::string typeName;

Expand Down Expand Up @@ -1002,7 +1001,7 @@ RED4EXT_INLINE std::string TypeToString(const RED4ext::CBaseRTTIType* aType, Nam

// We don't have this type supported yet but we can put some bytes in as placeholder as we know its size
typeName = "std::array<uint8_t, " + std::to_string(size) + ">/* UNHANDLED: " + trueName.ToString() + " (" +
tName.c_str() + ") */";
tName.AsChar() + ") */";
}

if (aVerbose)
Expand Down
8 changes: 4 additions & 4 deletions include/RED4ext/GameApplication.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ struct CGameOptions
uint32_t watchdogTimeout; // 10
int8_t scriptVersion; // 14
int16_t scriptProfiling; // 16
CString scriptsBlobPath; // 18
CString tweakdbBlobPath; // 38
String scriptsBlobPath; // 18
String tweakdbBlobPath; // 38
uint8_t unattended58; // 58
uint8_t unattended59; // 59
uint8_t unattended5A; // 5A
Expand All @@ -41,8 +41,8 @@ struct CGameOptions
uint8_t unk5F; // 5F
uint8_t unattended60; // 60
int64_t unk68; // 68
CString automator; // 70
CString windowCaption; // 90
String automator; // 70
String windowCaption; // 90
bool isBackendGameEngine; // B0
uint8_t unkB1; // B1
bool nochroma; // B2
Expand Down
Loading
Loading