Skip to content

Commit

Permalink
Merge pull request #636 from UE4SS-RE/port/strings-fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
narknon committed Aug 27, 2024
2 parents 1b5ff77 + 921bf9a commit fb8c324
Show file tree
Hide file tree
Showing 75 changed files with 1,122 additions and 918 deletions.
2 changes: 1 addition & 1 deletion UE4SS/include/ExceptionHandling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#define UE4SS_ERROR_OUTPUTTER() \
if (!Output::has_internal_error()) \
{ \
Output::send<LogLevel::Error>(STR("Error: {}\n"), to_wstring(e.what())); \
Output::send<LogLevel::Error>(STR("Error: {}\n"), ensure_str(e.what())); \
} \
else \
{ \
Expand Down
2 changes: 1 addition & 1 deletion UE4SS/include/GUI/Console.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ namespace RC::GUI
auto render() -> void;
auto render_search_box() -> void;
auto add_line(const std::string&, Color::Color) -> void;
auto add_line(const std::wstring&, Color::Color) -> void;
auto add_line(const StringType&, Color::Color) -> void;
};
} // namespace RC::GUI
2 changes: 1 addition & 1 deletion UE4SS/include/GUI/LiveView/Filter/HasProperty.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace RC::GUI::Filter
{
for (const auto& property : list_properties)
{
if (!property.empty() && !object->GetPropertyByNameInChain(property.c_str())) return true;
if (!property.empty() && !object->GetPropertyByNameInChain(FromCharTypePtr<TCHAR>(property.c_str()))) return true;
}
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions UE4SS/include/LuaLibrary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <Common.hpp>
#include <cstdint>

#include <String/StringType.hpp>

#define DefaultStructMemberData(member_name) \
union { \
const char* as_string{}; \
Expand Down
10 changes: 6 additions & 4 deletions UE4SS/include/LuaType/LuaCustomProperty.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <string>
#include <vector>

#include <String/StringType.hpp>

namespace RC::Unreal
{
class UObject;
Expand All @@ -17,11 +19,11 @@ namespace RC::LuaType
class LuaCustomProperty
{
public:
std::wstring m_name{};
StringType m_name{};
std::unique_ptr<Unreal::CustomProperty> m_property;

public:
LuaCustomProperty(std::wstring name, std::unique_ptr<Unreal::CustomProperty> property);
LuaCustomProperty(StringType name, std::unique_ptr<Unreal::CustomProperty> property);

private:
class PropertyList
Expand All @@ -30,9 +32,9 @@ namespace RC::LuaType
std::vector<LuaCustomProperty> properties;

public:
auto add(std::wstring property_name, std::unique_ptr<Unreal::CustomProperty>) -> void;
auto add(StringType property_name, std::unique_ptr<Unreal::CustomProperty>) -> void;
auto clear() -> void;
auto find_or_nullptr(Unreal::UObject* base, std::wstring property_name) -> Unreal::FProperty*;
auto find_or_nullptr(Unreal::UObject* base, StringType property_name) -> Unreal::FProperty*;
};

public:
Expand Down
10 changes: 5 additions & 5 deletions UE4SS/include/LuaType/LuaUObject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ namespace RC::LuaType
{
lua.throw_error("Function 'GetProperty' requires a string as the first parameter");
}
std::wstring property_name = to_wstring(lua.get_string(2));
auto property_name = ensure_str(lua.get_string(2));

auto reflection_table = lua.get_table();
const auto& reflected_object = reflection_table.get_userdata_field<SelfType>("ReflectedObject").get_remote_cpp_object();
Expand Down Expand Up @@ -586,7 +586,7 @@ No overload found for function 'UObject.ProcessConsoleExec'.
{
lua.throw_error(error_overload_not_found);
}
auto cmd = to_wstring(lua.get_string());
auto cmd = ensure_str(lua.get_string());

if (lua.get_stack_size() < 2)
{
Expand All @@ -601,7 +601,7 @@ No overload found for function 'UObject.ProcessConsoleExec'.
auto executor = lua.get_userdata<LuaType::UObject>();

auto ar = Unreal::FOutputDevice{};
auto return_value = lua_object.get_remote_cpp_object()->ProcessConsoleExec(cmd.c_str(), ar, executor.get_remote_cpp_object());
auto return_value = lua_object.get_remote_cpp_object()->ProcessConsoleExec(FromCharTypePtr<TCHAR>(cmd.c_str()), ar, executor.get_remote_cpp_object());

lua.set_bool(return_value);
return 1;
Expand Down Expand Up @@ -641,7 +641,7 @@ No overload found for function 'UObject.ProcessConsoleExec'.
{
auto& lua_object = lua.get_userdata<SelfType>();

const std::wstring& member_name = to_const_wstring(lua.get_string());
const StringType& member_name = ensure_str_const(lua.get_string());

// If nullptr then we assume the UObject wasn't found so lets return an invalid UObject to Lua
// This allows the safe chaining of "__index" as long as the Lua script checks ":IsValid()" before using the object
Expand Down Expand Up @@ -777,7 +777,7 @@ No overload found for function 'UObject.ProcessConsoleExec'.
{
// We can either throw an error and kill the execution
/**/
std::wstring property_type_name = property_type.ToString();
StringType property_type_name = property_type.ToString();
lua.throw_error(fmt::format(
"[LocalUnrealParam::prepare_to_handle] Tried accessing unreal property without a registered handler. Property type '{}' not supported.",
to_string(property_type_name)));
Expand Down
8 changes: 5 additions & 3 deletions UE4SS/include/Mod/CppMod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <Mod/CppUserModBase.hpp>
#include <Mod/Mod.hpp>

#include <String/StringType.hpp>

namespace RC
{
namespace LuaMadeSimple
Expand All @@ -21,7 +23,7 @@ namespace RC
typedef void (*uninstall_type)(CppUserModBase*);

private:
std::wstring m_dlls_path;
std::filesystem::path m_dlls_path;

Unreal::Windows::HMODULE m_main_dll_module = NULL;
void* m_dlls_path_cookie = NULL;
Expand All @@ -31,7 +33,7 @@ namespace RC
CppUserModBase* m_mod = nullptr;

public:
CppMod(UE4SSProgram&, std::wstring&& mod_name, std::wstring&& mod_path);
CppMod(UE4SSProgram&, StringType&& mod_name, StringType&& mod_path);
CppMod(CppMod&) = delete;
CppMod(CppMod&&) = delete;
~CppMod() override;
Expand Down Expand Up @@ -62,6 +64,6 @@ namespace RC
auto fire_ui_init() -> void override;
auto fire_program_start() -> void override;
auto fire_update() -> void override;
auto fire_dll_load(std::wstring_view dll_name) -> void;
auto fire_dll_load(StringViewType dll_name) -> void;
};
} // namespace RC
6 changes: 4 additions & 2 deletions UE4SS/include/Mod/CppUserModBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <GUI/GUITab.hpp>
#include <Input/Handler.hpp>

#include <String/StringType.hpp>

namespace RC
{
struct ModMetadata
Expand Down Expand Up @@ -125,14 +127,14 @@ namespace RC
{
}

RC_UE4SS_API virtual auto on_dll_load(std::wstring_view dll_name) -> void
RC_UE4SS_API virtual auto on_dll_load(StringViewType dll_name) -> void
{
}

RC_UE4SS_API virtual auto render_tab() -> void{};

protected:
RC_UE4SS_API auto register_tab(std::wstring_view tab_name, GUI::GUITab::RenderFunctionType) -> void;
RC_UE4SS_API auto register_tab(StringViewType tab_name, GUI::GUITab::RenderFunctionType) -> void;
RC_UE4SS_API auto register_keydown_event(Input::Key, const Input::EventCallbackCallable&, uint8_t custom_data = 0) -> void;
RC_UE4SS_API auto register_keydown_event(Input::Key, const Input::Handler::ModifierKeyArray&, const Input::EventCallbackCallable&, uint8_t custom_data = 0)
-> void;
Expand Down
7 changes: 5 additions & 2 deletions UE4SS/include/Mod/LuaMod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
#include <thread>
#include <unordered_map>
#include <unordered_set>
#include <filesystem>

#include <Common.hpp>
#include <File/File.hpp>
#include <LuaMadeSimple/LuaMadeSimple.hpp>
#include <Mod/Mod.hpp>

#include <String/StringType.hpp>

namespace RC
{
class UE4SSProgram;
Expand All @@ -26,7 +29,7 @@ namespace RC
class LuaMod : public Mod
{
private:
std::wstring m_scripts_path;
std::filesystem::path m_scripts_path;
LuaMadeSimple::Lua& m_lua;

public:
Expand Down Expand Up @@ -124,7 +127,7 @@ namespace RC
std::mutex m_actions_lock{};

public:
LuaMod(UE4SSProgram&, std::wstring&& mod_name, std::wstring&& mod_path);
LuaMod(UE4SSProgram&, StringType&& mod_name, StringType&& mod_path);
~LuaMod() override = default;

private:
Expand Down
10 changes: 6 additions & 4 deletions UE4SS/include/Mod/Mod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ namespace RC
UE4SSProgram& m_program;

protected:
std::wstring m_mod_name;
std::wstring m_mod_path;
#pragma warning(disable : 4251)
StringType m_mod_name;
std::filesystem::path m_mod_path;
#pragma warning(default : 4251)

protected:
// Whether the mod can be installed
Expand All @@ -43,11 +45,11 @@ namespace RC
};

public:
Mod(UE4SSProgram&, std::wstring&& mod_name, std::wstring&& mod_path);
Mod(UE4SSProgram&, StringType&& mod_name, std::filesystem::path&& mod_path);
virtual ~Mod() = default;

public:
auto get_name() const -> std::wstring_view;
auto get_name() const -> StringViewType;

virtual auto start_mod() -> void = 0;
virtual auto uninstall() -> void = 0;
Expand Down
46 changes: 24 additions & 22 deletions UE4SS/include/ObjectDumper/ObjectToString.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

#include <File/File.hpp>

#include <String/StringType.hpp>

namespace RC::ObjectDumper
{
using ToStringHash = size_t;
using ObjectToStringDecl = std::function<void(void*, std::wstring&)>;
using ObjectToStringDecl = std::function<void(void*, StringType&)>;
extern std::unordered_map<ToStringHash, ObjectToStringDecl> object_to_string_functions;

using ObjectToStringComplexDeclCallable = const std::function<void(void*)>&;
Expand All @@ -20,33 +22,33 @@ namespace RC::ObjectDumper
auto to_string_exists(size_t hash) -> bool;
auto to_string_complex_exists(size_t hash) -> bool;

auto object_trivial_dump_to_string(void* p_this, std::wstring& out_line, const wchar_t* post_delimiter = L".") -> void;
auto object_to_string(void* p_this, std::wstring& out_line) -> void;
auto object_trivial_dump_to_string(void* p_this, StringType& out_line, const CharType* post_delimiter = STR(".")) -> void;
auto object_to_string(void* p_this, StringType& out_line) -> void;

auto property_trivial_dump_to_string(void* p_this, std::wstring& out_line) -> void;
auto property_to_string(void* p_this, std::wstring& out_line) -> void;
auto property_trivial_dump_to_string(void* p_this, StringType& out_line) -> void;
auto property_to_string(void* p_this, StringType& out_line) -> void;

auto arrayproperty_to_string(void* p_this, std::wstring& out_line) -> void;
auto arrayproperty_to_string_complex(void* p_this, std::wstring& out_line, ObjectToStringComplexDeclCallable callable) -> void;
auto arrayproperty_to_string(void* p_this, StringType& out_line) -> void;
auto arrayproperty_to_string_complex(void* p_this, StringType& out_line, ObjectToStringComplexDeclCallable callable) -> void;

auto mapproperty_to_string(void* p_this, std::wstring& out_line) -> void;
auto mapproperty_to_string_complex(void* p_this, std::wstring& out_line, ObjectToStringComplexDeclCallable callable) -> void;
auto mapproperty_to_string(void* p_this, StringType& out_line) -> void;
auto mapproperty_to_string_complex(void* p_this, StringType& out_line, ObjectToStringComplexDeclCallable callable) -> void;

auto classproperty_to_string(void* p_this, std::wstring& out_line) -> void;
auto delegateproperty_to_string(void* p_this, std::wstring& out_line) -> void;
auto fieldpathproperty_to_string(void* p_this, std::wstring& out_line) -> void;
auto interfaceproperty_to_string(void* p_this, std::wstring& out_line) -> void;
auto multicastdelegateproperty_to_string(void* p_this, std::wstring& out_line) -> void;
auto objectproperty_to_string(void* p_this, std::wstring& out_line) -> void;
auto structproperty_to_string(void* p_this, std::wstring& out_line) -> void;
auto enumproperty_to_string(void* p_this, std::wstring& out_line) -> void;
auto boolproperty_to_string(void* p_this, std::wstring& out_line) -> void;
auto classproperty_to_string(void* p_this, StringType& out_line) -> void;
auto delegateproperty_to_string(void* p_this, StringType& out_line) -> void;
auto fieldpathproperty_to_string(void* p_this, StringType& out_line) -> void;
auto interfaceproperty_to_string(void* p_this, StringType& out_line) -> void;
auto multicastdelegateproperty_to_string(void* p_this, StringType& out_line) -> void;
auto objectproperty_to_string(void* p_this, StringType& out_line) -> void;
auto structproperty_to_string(void* p_this, StringType& out_line) -> void;
auto enumproperty_to_string(void* p_this, StringType& out_line) -> void;
auto boolproperty_to_string(void* p_this, StringType& out_line) -> void;

auto enum_to_string(void* p_this, std::wstring& out_line) -> void;
auto struct_to_string(void* p_this, std::wstring& out_line) -> void;
auto function_to_string(void* p_this, std::wstring& out_line) -> void;
auto enum_to_string(void* p_this, StringType& out_line) -> void;
auto struct_to_string(void* p_this, StringType& out_line) -> void;
auto function_to_string(void* p_this, StringType& out_line) -> void;

auto scriptstruct_to_string_complex(void* p_this, std::wstring& out_line, ObjectToStringComplexDeclCallable callable) -> void;
auto scriptstruct_to_string_complex(void* p_this, StringType& out_line, ObjectToStringComplexDeclCallable callable) -> void;

auto init() -> void;
} // namespace RC::ObjectDumper
Loading

0 comments on commit fb8c324

Please sign in to comment.