Skip to content

Commit

Permalink
new string handling and ... maybe no need for fmt?
Browse files Browse the repository at this point in the history
  • Loading branch information
Yangff committed Feb 19, 2024
1 parent 6b49b6c commit 1741ceb
Show file tree
Hide file tree
Showing 37 changed files with 601 additions and 433 deletions.
2 changes: 1 addition & 1 deletion UE4SS/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ target_link_libraries(${TARGET} PUBLIC
Unreal SinglePassSigScanner LuaMadeSimple
Function IniParser JSON
Constructs Helpers
MProgram ScopedTimer Profiler fmt
MProgram ScopedTimer Profiler
)
if (WIN32)
target_link_libraries(${TARGET} PUBLIC
Expand Down
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>(SYSSTR("Error: {}\n"), to_generic_string(e.what())); \
Output::send<LogLevel::Error>(SYSSTR("Error: {}\n"), to_system(e.what())); \
} \
else \
{ \
Expand Down
16 changes: 8 additions & 8 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");
}
SystemStringType property_name = to_generic_string(lua.get_string(2));
auto property_name = to_system(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 All @@ -478,7 +478,7 @@ namespace RC::LuaType
{
obj_as_struct = reflected_object->GetClassPrivate();
}
auto* property = obj_as_struct->FindProperty(Unreal::FName(SystemStringToUEString(property_name)));
auto* property = obj_as_struct->FindProperty(Unreal::FName(to_ue(property_name)));

construct_xproperty(lua, property);
return 1;
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_generic_string(lua.get_string());
auto cmd = to_system(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(SystemStringToUEString(cmd).c_str(), ar, executor.get_remote_cpp_object());
auto return_value = lua_object.get_remote_cpp_object()->ProcessConsoleExec(to_ue_string(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 SystemStringType& member_name = to_generic_string(lua.get_string());
auto member_name = to_system_string(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 All @@ -666,7 +666,7 @@ No overload found for function 'UObject.ProcessConsoleExec'.
return;
}

Unreal::FName property_name = Unreal::FName(SystemStringToUEString(member_name));
Unreal::FName property_name = Unreal::FName(to_ue(member_name));
Unreal::FField* field = LuaCustomProperty::StaticStorage::property_list.find_or_nullptr(lua_object.get_remote_cpp_object(), member_name);

if (!field)
Expand Down Expand Up @@ -777,10 +777,10 @@ No overload found for function 'UObject.ProcessConsoleExec'.
{
// We can either throw an error and kill the execution
/**/
SystemStringType property_type_name = UEStringToSystemString(property_type.ToString());
auto property_type_name = to_string(property_type.ToString());
lua.throw_error(std::format(
"[LocalUnrealParam::prepare_to_handle] Tried accessing unreal property without a registered handler. Property type '{}' not supported.",
to_string(property_type_name)));
property_type_name));
//*/

// Or we can treat unhandled property types as some sort of generic type
Expand Down
4 changes: 2 additions & 2 deletions UE4SS/include/UE4SSProgram.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,10 @@ namespace RC
template <typename T>
static auto find_mod_by_name(SystemStringViewType mod_name, IsInstalled is_installed = IsInstalled::No, IsStarted is_started = IsStarted::No) -> T*
{
return find_mod_by_name<T>(to_generic_string(mod_name), is_installed, is_started);
return find_mod_by_name<T>(to_system(mod_name), is_installed, is_started);
};

RC_UE4SS_API static auto find_lua_mod_by_name(UEViewType mod_name, IsInstalled = IsInstalled::No, IsStarted = IsStarted::No) -> LuaMod*;
RC_UE4SS_API static auto find_lua_mod_by_name(UEStringViewType mod_name, IsInstalled = IsInstalled::No, IsStarted = IsStarted::No) -> LuaMod*;
RC_UE4SS_API static auto find_lua_mod_by_name(SystemStringViewType mod_name, IsInstalled = IsInstalled::No, IsStarted = IsStarted::No) -> LuaMod*;
static auto static_cleanup() -> void;
RC_UE4SS_API static auto get_program() -> UE4SSProgram&
Expand Down
4 changes: 2 additions & 2 deletions UE4SS/src/EntryLinux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void UE4SS_Start()
fprintf(stderr, "%s\n", e.what());
}
#endif
SystemStringType ue4sspath = to_generic_string(dl_info.dli_fname);
auto ue4sspath = to_system_string(dl_info.dli_fname);
auto program = new UE4SSProgram(ue4sspath, {});

// use pthread here
Expand All @@ -50,7 +50,7 @@ void UE4SS_Start()
// Logging will only happen to the debug console but it's something at least
if (!Output::has_internal_error())
{
Output::send<LogLevel::Error>(SYSSTR("Fatal Error: {}\n"), to_generic_string(e->get_message()));
Output::send<LogLevel::Error>(SYSSTR("Fatal Error: {}\n"), e->get_message());
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion UE4SS/src/GUI/BPMods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ namespace RC::GUI::BPMods
const auto& mod_button = mod_info.ModButtons[i2];
if (ImGui::Button(std::format("{}", mod_button).c_str()))
{
Output::send(SYSSTR("Mod button {} hit.\n"), to_generic_string(mod_button));
Output::send(SYSSTR("Mod button {} hit.\n"), to_system(mod_button));
mod_info.ModActor->ModMenuButtonPressed(static_cast<int32_t>(i2));
}
}
Expand Down
2 changes: 1 addition & 1 deletion UE4SS/src/GUI/GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ namespace RC::GUI
{
if (!Output::has_internal_error())
{
Output::send<LogLevel::Error>(SYSSTR("Error: {}\n"), to_generic_string(e.what()));
Output::send<LogLevel::Error>(SYSSTR("Error: {}\n"), to_system(e.what()));
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions UE4SS/src/GUI/UFunctionCallerWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ namespace RC::GUI
}
auto function = m_currently_selected_function->function;

auto cmd = std::format(SYSSTR("{}"), UEStringToSystemString(function->GetName()));
auto cmd = std::format(SYSSTR("{}"), to_system(function->GetName()));
for (const auto& param : m_params_for_selected_function)
{
cmd.append(std::format(SYSSTR(" {}"), to_wstring(param.value_from_ui)));
Expand Down Expand Up @@ -245,7 +245,7 @@ namespace RC::GUI

static auto get_typeless_object_name(UObject* object) -> std::string
{
auto object_name = UEStringToSystemString(object->GetFullName());
auto object_name = to_system(object->GetFullName());
auto object_name_type_space_location = object_name.find(" ");
if (object_name_type_space_location == object_name.npos)
{
Expand Down
6 changes: 3 additions & 3 deletions UE4SS/src/LuaLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace RC::LuaLibrary
lua.get_type_string()));
}

SystemStringType format = to_generic_string(lua.get_string());
auto format = to_system_string(lua.get_string());

// The output device is at the top of the stack, therefore we must call this function after retrieving all of the params.
auto* output_device = get_outputdevice_ref(lua);
Expand All @@ -61,7 +61,7 @@ namespace RC::LuaLibrary
Output::send(formatted_string);
if (output_device)
{
output_device->Log(SystemStringToUEString(formatted_string).c_str());
output_device->Log(to_ue(formatted_string).c_str());
}
}
else if (stack_size >= 2)
Expand Down Expand Up @@ -107,7 +107,7 @@ namespace RC::LuaLibrary
// Logging will only happen to the debug console but it's something at least
if (!Output::has_internal_error())
{
Output::send(SYSSTR("Error: {}\n"), to_generic_string(e));
Output::send(SYSSTR("Error: {}\n"), to_system(e));
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions UE4SS/src/LuaType/LuaFName.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ No overload found for function 'FName'.
Unreal::EFindName find_type{Unreal::EFindName::FNAME_Add};
if (lua.is_string())
{
name_string = to_generic_string(lua.get_string());
name_string = to_system(lua.get_string());
}
else if (lua.is_integer())
{
Expand Down Expand Up @@ -94,7 +94,7 @@ No overload found for function 'FName'.
}
else
{
LuaType::FName::construct(lua, Unreal::FName(SystemStringToUEString(name_string), find_type));
LuaType::FName::construct(lua, Unreal::FName(to_ue(name_string), find_type));
}

return 1;
Expand Down
2 changes: 1 addition & 1 deletion UE4SS/src/LuaType/LuaFOutputDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ No overload found for function 'Log'.
}
auto message = lua.get_string();

lua_object.get_remote_cpp_object()->Log(SystemStringToUEString(to_generic_string(message)).c_str());
lua_object.get_remote_cpp_object()->Log(to_ue(to_system(message)).c_str());

return 0;
});
Expand Down
4 changes: 2 additions & 2 deletions UE4SS/src/LuaType/LuaFText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ No overload found for function 'FText'.
SystemStringType text_string{};
if (lua.is_string())
{
text_string = to_generic_string(lua.get_string());
text_string = to_system(lua.get_string());
}
else
{
lua.throw_error(error_overload_not_found);
}

LuaType::FText::construct(lua, Unreal::FText(SystemStringToUEString(text_string)));
LuaType::FText::construct(lua, Unreal::FText(to_ue(text_string)));

return 1;
});
Expand Down
2 changes: 1 addition & 1 deletion UE4SS/src/LuaType/LuaTArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace RC::LuaType

if (!lua_object.m_inner_property)
{
Output::send<LogLevel::Error>(SYSSTR("TArray::construct: m_inner_property is nullptr for {}"), UEStringToSystemString(lua_object.m_property->GetFullName()));
Output::send<LogLevel::Error>(SYSSTR("TArray::construct: m_inner_property is nullptr for {}"), to_system(lua_object.m_property->GetFullName()));
}

auto metatable_name = ClassName::ToString();
Expand Down
6 changes: 3 additions & 3 deletions UE4SS/src/LuaType/LuaUEnum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ No overload found for function 'UEnum.InsertIntoNames'.
// P1 (Name), string
if (lua.is_string())
{
param_name = to_generic_string(lua.get_string());
param_name = to_system(lua.get_string());
}
else
{
Expand Down Expand Up @@ -195,7 +195,7 @@ No overload found for function 'UEnum.InsertIntoNames'.
param_shift = lua.get_bool();
}

const Unreal::FName key{SystemStringToUEString(param_name), Unreal::FNAME_Add};
const Unreal::FName key{to_ue(param_name), Unreal::FNAME_Add};
const auto pair = Unreal::TPair<Unreal::FName, Unreal::int64>{key, param_value};

lua_object.get_remote_cpp_object()->InsertIntoNames(pair, param_index, param_shift);
Expand Down Expand Up @@ -243,7 +243,7 @@ No overload found for function 'UEnum.EditNameAt'.
lua.throw_error("'UEnum.EditNameAt' could not load parameter for \"NewName\"");
}

Unreal::FName new_key = Unreal::FName(SystemStringToUEString(to_generic_string(param_new_name)), Unreal::FNAME_Add);
Unreal::FName new_key = Unreal::FName(to_ue(to_system(param_new_name)), Unreal::FNAME_Add);
lua_object.get_remote_cpp_object()->EditNameAt(param_index, new_key);

return 0;
Expand Down
4 changes: 2 additions & 2 deletions UE4SS/src/LuaType/LuaUObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ namespace RC::LuaType
if (params.lua.is_string())
{
auto lua_string = params.lua.get_string();
auto fstring = Unreal::FString{ SystemStringToUEString(to_generic_string(lua_string)).c_str() };
auto fstring = Unreal::FString{ to_ue(to_system(lua_string)).c_str() };
*string = fstring;
}
else if (params.lua.is_userdata())
Expand Down Expand Up @@ -1232,7 +1232,7 @@ No overload found for function 'IsA'.
}
else if (lua.is_string())
{
auto* object_class = Unreal::UObjectGlobals::StaticFindObject<Unreal::UClass*>(nullptr, nullptr, SystemStringToUEString(to_generic_string(lua.get_string())));
auto* object_class = Unreal::UObjectGlobals::StaticFindObject<Unreal::UClass*>(nullptr, nullptr, to_ue(to_system(lua.get_string())));
lua.set_bool(is_a_internal(lua, object, object_class));
}
else
Expand Down
2 changes: 1 addition & 1 deletion UE4SS/src/LuaType/LuaUScriptStruct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ namespace RC::LuaType
{
auto& lua_object = lua.get_userdata<UScriptStruct>();

Unreal::FName property_name = Unreal::FName(SystemStringToUEString(to_generic_string(lua.get_string())));
Unreal::FName property_name = Unreal::FName(to_ue(to_system(lua.get_string())));

// Check if property_name is 'NONE'
if (property_name.GetComparisonIndex() == 0)
Expand Down
6 changes: 3 additions & 3 deletions UE4SS/src/LuaType/LuaXProperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ namespace RC::LuaType
if (lua_object.get_remote_cpp_object())
{
// Set the return value to the ansi version of the full name
lua.set_string(UEStringToSystemString(lua_object.get_remote_cpp_object()->GetFullName()).c_str());
lua.set_string(to_system(lua_object.get_remote_cpp_object()->GetFullName()).c_str());
}
else
{
Expand Down Expand Up @@ -227,7 +227,7 @@ No overload found for function 'ImportText'.
SystemStringType buffer;
if (lua.is_string())
{
buffer = to_generic_string(lua.get_string());
buffer = to_system(lua.get_string());
}
else
{
Expand Down Expand Up @@ -261,7 +261,7 @@ No overload found for function 'ImportText'.
}
auto* owner_object = lua.get_userdata<UObject>().get_remote_cpp_object();

lua_object.get_remote_cpp_object()->ImportText(SystemStringToUEString(buffer).c_str(), data, port_flags, owner_object, nullptr);
lua_object.get_remote_cpp_object()->ImportText(to_ue(buffer).c_str(), data, port_flags, owner_object, nullptr);
return 0;
});

Expand Down
4 changes: 2 additions & 2 deletions UE4SS/src/Mod/CppMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace RC

if (!std::filesystem::exists(m_dlls_path))
{
Output::send<LogLevel::Warning>(SYSSTR("Could not find the dlls folder for mod {}\n"), to_generic_string(m_mod_name));
Output::send<LogLevel::Warning>(SYSSTR("Could not find the dlls folder for mod {}\n"), to_system(m_mod_name));
set_installable(false);
return;
}
Expand Down Expand Up @@ -69,7 +69,7 @@ namespace RC
Output::send<LogLevel::Warning>(SYSSTR("Failed to load dll <{}> for mod {}, because: {}\n"),
(std::filesystem::path {m_dlls_path} / CONCATENATE_WIDE_STRING("main", DLLEXT)).generic_string() + "\n",
m_mod_name,
to_generic_string(e.what()));
to_system(e.what()));
}
else
{
Expand Down
Loading

0 comments on commit 1741ceb

Please sign in to comment.