Skip to content

Commit

Permalink
seperate FileString
Browse files Browse the repository at this point in the history
  • Loading branch information
Yangff committed Feb 20, 2024
1 parent a17ce26 commit e9cdac6
Show file tree
Hide file tree
Showing 59 changed files with 806 additions and 678 deletions.
4 changes: 2 additions & 2 deletions UE4SS/include/GUI/ConsoleOutputDevice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace RC::Output

public:
auto has_optional_arg() const -> bool override;
auto receive(File::StringViewType fmt) const -> void override;
auto receive_with_optional_arg(File::StringViewType fmt, int32_t optional_arg = 0) const -> void override;
auto receive(SystemStringViewType fmt) const -> void override;
auto receive_with_optional_arg(SystemStringViewType fmt, int32_t optional_arg = 0) const -> void override;
};
} // namespace RC::Output
2 changes: 1 addition & 1 deletion UE4SS/include/ObjectDumper/ObjectToString.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace RC::ObjectDumper
extern std::unordered_map<ToStringHash, ObjectToStringDecl> object_to_string_functions;

using ObjectToStringComplexDeclCallable = const std::function<void(void*)>&;
using ObjectToStringComplexDecl = std::function<void(void*, File::StringType&, ObjectToStringComplexDeclCallable)>;
using ObjectToStringComplexDecl = std::function<void(void*, SystemStringType&, ObjectToStringComplexDeclCallable)>;
extern std::unordered_map<ToStringHash, ObjectToStringComplexDecl> object_to_string_complex_functions;

auto get_to_string(size_t hash) -> ObjectToStringDecl;
Expand Down
2 changes: 1 addition & 1 deletion UE4SS/include/SDKGenerator/UEHeaderGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ namespace RC::UEGenerator
auto static get_property_access_modifier(FProperty* property) -> AccessModifier;
auto static get_function_access_modifier(UFunction* function) -> AccessModifier;
auto static create_string_literal(const UEStringType& string) -> UEStringType;
auto static get_header_name_for_object(UObject* object, bool get_existing_header = false) -> UEStringType;
auto static get_header_name_for_object(UObject* object, bool get_existing_header = false) -> SystemStringType;
auto static generate_cross_module_include(UObject* object, const UEStringType& module_name, const UEStringType& fallback_name) -> UEStringType;
};
} // namespace RC::UEGenerator
2 changes: 1 addition & 1 deletion UE4SS/include/SettingsManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace RC
public:
struct SectionOverrides
{
File::StringType ModsFolderPath{};
UEStringType ModsFolderPath{};
} Overrides;

struct SectionGeneral
Expand Down
6 changes: 3 additions & 3 deletions UE4SS/src/GUI/ConsoleOutputDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ namespace RC::Output
return true;
}

auto ConsoleDevice::receive(File::StringViewType fmt) const -> void
auto ConsoleDevice::receive(SystemStringViewType fmt) const -> void
{
receive_with_optional_arg(fmt, Color::NoColor);
}

auto ConsoleDevice::receive_with_optional_arg(File::StringViewType fmt, [[maybe_unused]] int32_t optional_arg) const -> void
auto ConsoleDevice::receive_with_optional_arg(SystemStringViewType fmt, [[maybe_unused]] int32_t optional_arg) const -> void
{
#if ENABLE_OUTPUT_DEVICE_DEBUG_MODE
printf_s("ConsoleDevice received: %S", m_formatter(fmt).c_str());
#else
auto fmt_copy = File::StringType{fmt};
auto fmt_copy = SystemStringType{fmt};
if (fmt_copy.ends_with(STR('\n')))
{
fmt_copy.pop_back();
Expand Down
8 changes: 4 additions & 4 deletions UE4SS/src/GUI/Dumpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,14 +398,14 @@ namespace RC::GUI::Dumpers

if (ImGui::Button("Dump CXX Headers\n"))
{
File::StringType working_dir{UE4SSProgram::get_program().get_working_directory()};
UE4SSProgram::get_program().generate_cxx_headers(working_dir + STR("\\CXXHeaderDump"));
SystemStringType working_dir{UE4SSProgram::get_program().get_working_directory()};
UE4SSProgram::get_program().generate_cxx_headers(working_dir + SYSSTR("\\CXXHeaderDump"));
}

if (ImGui::Button("Generate Lua Types\n"))
{
File::StringType working_dir{UE4SSProgram::get_program().get_working_directory()};
UE4SSProgram::get_program().generate_lua_types(working_dir + STR("\\Mods\\shared\\types"));
SystemStringType working_dir{UE4SSProgram::get_program().get_working_directory()};
UE4SSProgram::get_program().generate_lua_types(working_dir + SYSSTR("\\Mods\\shared\\types"));
}
}
} // namespace RC::GUI::Dumpers
4 changes: 2 additions & 2 deletions UE4SS/src/GUI/LiveView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ namespace RC::GUI
auto& file_device = output.get_device<Output::FileDevice>();
file_device.set_file_name_and_path(UEStringType{UE4SSProgram::get_program().get_working_directory()} +
std::format(SYSSTR("\\watches\\ue4ss_watch_{}_{}.txt"), object_name, property_name));
file_device.set_formatter([](File::StringViewType string) -> File::StringType {
file_device.set_formatter([](SystemStringViewType string) -> SystemStringType {
const auto when_as_string = std::format(SYSSTR("{:%Y-%m-%d %H:%M:%S}"), std::chrono::system_clock::now());
return std::format(SYSSTR("[{}] {}"), when_as_string, string);
});
Expand Down Expand Up @@ -2847,7 +2847,7 @@ namespace RC::GUI
}
else
{
Output::send(SYSSTR("Search for: {}\n"), search_buffer.empty() ? SYSSTR("") : to_file(search_buffer));
Output::send(SYSSTR("Search for: {}\n"), search_buffer.empty() ? SYSSTR("") : to_system(search_buffer));
s_name_to_search_by = search_buffer;
m_object_iterator = &LiveView::guobjectarray_by_name_iterator;
m_is_searching_by_name = true;
Expand Down
8 changes: 4 additions & 4 deletions UE4SS/src/Mod/LuaMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ namespace RC
// Give the full path to the 'Scripts' directory to the mod container
std::filesystem::path mod_path_fs = m_mod_path;
auto path = (mod_path_fs / SYSSTR("scripts"));
m_scripts_path = to_system_string(path);
m_scripts_path = to_system(path);

// If the 'Scripts' directory doesn't exist then mark the mod as non-installable and move on to the next mod
if (!std::filesystem::exists(path))
Expand Down Expand Up @@ -4231,7 +4231,7 @@ No overload found for function 'FPackageName:IsValidLongPackageName'.
}

return TRY([&] {
auto command = to_system(cmd);
auto command = to_system_string(cmd);
auto command_parts = explode_by_occurrence(command, ' ');
SystemStringType command_name;
if (command_parts.size() > 1)
Expand Down Expand Up @@ -4291,8 +4291,8 @@ No overload found for function 'FPackageName:IsValidLongPackageName'.
(void)executor;

return TRY([&] {
auto command = to_system(cmd);
auto command_parts = explode_by_occurrence(command, ' ');
auto command = to_system_string(cmd);
auto command_parts = explode_by_occurrence(command, SYSSTR(' '));
SystemStringType command_name;
if (command_parts.size() > 1)
{
Expand Down
84 changes: 42 additions & 42 deletions UE4SS/src/SDKGenerator/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,28 @@ namespace RC::UEGenerator
{
using namespace Unreal;

auto get_native_class_name(UClass* uclass, bool interface_name) -> File::StringType
auto get_native_class_name(UClass* uclass, bool interface_name) -> UEStringType
{
File::StringType result_string;
UEStringType result_string;

if (interface_name)
{
result_string.append(SYSSTR("I"));
result_string.append(STR("I"));
}
else if (uclass->IsChildOf<AActor>())
{
result_string.append(SYSSTR("A"));
result_string.append(STR("A"));
}
else
{
result_string.append(SYSSTR("U"));
result_string.append(STR("U"));
}
if ((uclass->GetClassFlags() & Unreal::CLASS_Deprecated) != 0)
{
result_string.append(SYSSTR("DEPRECATED_"));
result_string.append(STR("DEPRECATED_"));
}

result_string.append(to_system(uclass->GetName()));
result_string.append(to_ue(uclass->GetName()));
return result_string;
}

Expand All @@ -74,43 +74,43 @@ namespace RC::UEGenerator
}
}

auto get_native_enum_name(UEnum* uenum, bool include_type) -> File::StringType
auto get_native_enum_name(UEnum* uenum, bool include_type) -> UEStringType
{
SystemStringType result_string;
UEStringType result_string;

// Seems to be not needed, because enum objects, unlike classes or structs, retain their normal E prefix
// ResultString.append(SYSSTR("E"));
result_string.append(to_system(uenum->GetName()));
result_string.append(to_ue(uenum->GetName()));

// Namespaced enums need to have ::Type appended for the type
if (uenum->GetCppForm() == UEnum::ECppForm::Namespaced && include_type)
{
result_string.append(SYSSTR("::Type"));
result_string.append(STR("::Type"));
}
return result_string;
}

auto get_native_struct_name(UScriptStruct* script_struct) -> File::StringType
auto get_native_struct_name(UScriptStruct* script_struct) -> UEStringType
{
SystemStringType result_string;
UEStringType result_string;

result_string.append(SYSSTR("F"));
result_string.append(to_system(script_struct->GetName()));
result_string.append(STR("F"));
result_string.append(to_ue(script_struct->GetName()));

return result_string;
}

auto sanitize_property_name(const File::StringType& property_name) -> File::StringType
auto sanitize_property_name(const UEStringType& property_name) -> UEStringType
{
SystemStringType resulting_name = property_name;
UEStringType resulting_name = property_name;

// Remove heading underscore, used by private variables in some games
if (resulting_name.length() >= 2 && resulting_name[0] == '_')
if (resulting_name.length() >= 2 && resulting_name[0] == STR('_'))
{
resulting_name.erase(0, 1);
}
// Remove heading m if it is followed by uppercase letter, used by variables in some games
if (resulting_name.length() >= 2 && resulting_name[0] == 'm' && towupper(resulting_name[1]) == resulting_name[1])
if (resulting_name.length() >= 2 && resulting_name[0] == STR('m') && towupper(resulting_name[1]) == resulting_name[1])
{
resulting_name.erase(0, 1);
}
Expand All @@ -123,14 +123,14 @@ namespace RC::UEGenerator
return resulting_name;
}

auto generate_delegate_name(FProperty* property, const File::StringType& context_name) -> File::StringType
auto generate_delegate_name(FProperty* property, const UEStringType& context_name) -> SystemStringType
{
const auto property_name = sanitize_property_name(to_system_string(property->GetName()));
return std::format(SYSSTR("F{}{}"), context_name, property_name);
return std::format(SYSSTR("F{}{}"), to_system(context_name), to_system(property_name));
}

auto generate_property_cxx_name(FProperty* property, bool is_top_level_declaration, UObject* class_context, EnableForwardDeclarations enable_forward_declarations)
-> File::StringType
-> UEStringType
{
const auto field_class_name = to_system(property->GetClass().GetName());

Expand All @@ -143,7 +143,7 @@ namespace RC::UEGenerator
if (enum_value != NULL)
{
// Non-EnumClass enumerations should be wrapped into TEnumAsByte according to UHT
const SystemStringType enum_type_name = get_native_enum_name(enum_value);
const SystemStringType enum_type_name = to_system(get_native_enum_name(enum_value));
return std::format(SYSSTR("TEnumAsByte<{}>"), enum_type_name);
}
return SYSSTR("uint8");
Expand Down Expand Up @@ -224,7 +224,7 @@ namespace RC::UEGenerator
return SYSSTR("UClass*");
}

File::StringType meta_class_name{};
SystemStringType meta_class_name{};
if (enable_forward_declarations == EnableForwardDeclarations::Yes)
{
meta_class_name = SYSSTR("class ");
Expand Down Expand Up @@ -299,7 +299,7 @@ namespace RC::UEGenerator
return SYSSTR("TWeakObjectPtr<UObject>");
}

File::StringType property_class_name{};
SystemStringType property_class_name{};
if (enable_forward_declarations == EnableForwardDeclarations::Yes)
{
property_class_name = std::format(SYSSTR("class "));
Expand All @@ -318,7 +318,7 @@ namespace RC::UEGenerator
return SYSSTR("TLazyObjectPtr<UObject>");
}

File::StringType property_class_name{};
SystemStringType property_class_name{};
if (enable_forward_declarations == EnableForwardDeclarations::Yes)
{
property_class_name = SYSSTR("class ");
Expand Down Expand Up @@ -352,7 +352,7 @@ namespace RC::UEGenerator
return SYSSTR("FScriptInterface");
}

File::StringType interface_class_name{};
SystemStringType interface_class_name{};
if (enable_forward_declarations == EnableForwardDeclarations::Yes)
{
interface_class_name = SYSSTR("class ");
Expand Down Expand Up @@ -418,7 +418,7 @@ namespace RC::UEGenerator
FArrayProperty* array_property = static_cast<FArrayProperty*>(property);
FProperty* inner_property = array_property->GetInner();

File::StringType inner_property_type{};
SystemStringType inner_property_type{};
if (enable_forward_declarations == EnableForwardDeclarations::Yes && !is_integral_type(inner_property))
{
if (inner_property->IsA<FObjectProperty>())
Expand Down Expand Up @@ -446,8 +446,8 @@ namespace RC::UEGenerator
FProperty* key_property = map_property->GetKeyProp();
FProperty* value_property = map_property->GetValueProp();

File::StringType key_type{};
File::StringType value_type{};
SystemStringType key_type{};
SystemStringType value_type{};
if (enable_forward_declarations == EnableForwardDeclarations::Yes && !is_integral_type(key_property) && !is_integral_type(value_property))
{
if (!key_property->IsA<FClassPtrProperty>())
Expand Down Expand Up @@ -482,7 +482,7 @@ namespace RC::UEGenerator
throw std::runtime_error(RC::fmt("Unsupported property class " SystemStringPrint, field_class_name));
}

auto generate_property_lua_name(FProperty* property, bool is_top_level_declaration, UObject* class_context) -> File::StringType
auto generate_property_lua_name(FProperty* property, bool is_top_level_declaration, UObject* class_context) -> SystemStringType
{
const auto field_class_name = to_system(property->GetClass().GetName());

Expand Down Expand Up @@ -602,7 +602,7 @@ namespace RC::UEGenerator
return SYSSTR("TWeakObjectPtr<UObject>");
}

File::StringType property_class_name{};
SystemStringType property_class_name{};
property_class_name.append(get_native_class_name(property_class, false));
return std::format(SYSSTR("TWeakObjectPtr<{}>"), property_class_name);
}
Expand All @@ -617,7 +617,7 @@ namespace RC::UEGenerator
return SYSSTR("TLazyObjectPtr<UObject>");
}

File::StringType property_class_name{};
SystemStringType property_class_name{};
property_class_name.append(get_native_class_name(property_class, false));
return std::format(SYSSTR("TLazyObjectPtr<{}>"), property_class_name);
}
Expand Down Expand Up @@ -647,7 +647,7 @@ namespace RC::UEGenerator
return SYSSTR("UClass");
}

File::StringType meta_class_name{};
SystemStringType meta_class_name{};
meta_class_name.append(get_native_class_name(meta_class, false));
return std::format(SYSSTR("TSubclassOf<{}>"), meta_class_name);
}
Expand Down Expand Up @@ -683,7 +683,7 @@ namespace RC::UEGenerator
return SYSSTR("FScriptInterface");
}

File::StringType interface_class_name{};
SystemStringType interface_class_name{};
interface_class_name.append(get_native_class_name(interface_class, true));
return std::format(SYSSTR("TScriptInterface<{}>"), interface_class_name);
}
Expand Down Expand Up @@ -745,7 +745,7 @@ namespace RC::UEGenerator
FArrayProperty* array_property = static_cast<FArrayProperty*>(property);
FProperty* inner_property = array_property->GetInner();

File::StringType inner_property_type{};
SystemStringType inner_property_type{};
inner_property_type.append(generate_property_lua_name(inner_property, is_top_level_declaration, class_context));
return std::format(SYSSTR("TArray<{}>"), inner_property_type);
}
Expand All @@ -766,8 +766,8 @@ namespace RC::UEGenerator
FProperty* key_property = map_property->GetKeyProp();
FProperty* value_property = map_property->GetValueProp();

File::StringType key_type{};
File::StringType value_type{};
SystemStringType key_type{};
SystemStringType value_type{};
key_type.append(generate_property_lua_name(key_property, is_top_level_declaration, class_context));
value_type.append(generate_property_lua_name(value_property, is_top_level_declaration, class_context));

Expand All @@ -790,15 +790,15 @@ namespace RC::UEGenerator
throw std::runtime_error(RC::fmt("Unsupported property class {}", field_class_name));
}

auto get_native_delegate_type_name(Unreal::UFunction* signature_function, Unreal::UClass* current_class, bool strip_outer_name) -> File::StringType
auto get_native_delegate_type_name(Unreal::UFunction* signature_function, Unreal::UClass* current_class, bool strip_outer_name) -> SystemStringType
{
if (!is_delegate_signature_function(signature_function))
{
throw std::runtime_error(RC::fmt("Function {} is not a delegate signature function", signature_function->GetName()));
}

// Delegate names always start with F and have __DelegateSignature postfix
File::StringType delegate_type_name = strip_delegate_signature_postfix(signature_function);
SystemStringType delegate_type_name = strip_delegate_signature_postfix(signature_function);
delegate_type_name.insert(0, SYSSTR("F"));

// Return the delegate name without the outer name if we have been requested to strip it
Expand All @@ -818,7 +818,7 @@ namespace RC::UEGenerator
{
// For interface, delegates are declared inside the interface definition
bool is_class_interface = delegate_outer_class->IsChildOf<UInterface>();
const File::StringType outer_class_name = get_native_class_name(delegate_outer_class, is_class_interface);
const SystemStringType outer_class_name = get_native_class_name(delegate_outer_class, is_class_interface);

delegate_type_name.insert(0, SYSSTR("::"));
delegate_type_name.insert(0, outer_class_name);
Expand All @@ -837,7 +837,7 @@ namespace RC::UEGenerator
return (function->GetFunctionFlags() & Unreal::FUNC_Delegate) != 0 && function->GetName().ends_with(DELEGATE_SIGNATURE_POSTFIX);
}

auto strip_delegate_signature_postfix(Unreal::UFunction* signature_function) -> File::StringType
auto strip_delegate_signature_postfix(Unreal::UFunction* signature_function) -> SystemStringType
{
if (!is_delegate_signature_function(signature_function))
{
Expand Down
Loading

0 comments on commit e9cdac6

Please sign in to comment.