Skip to content

Commit

Permalink
Move to using fmt lib
Browse files Browse the repository at this point in the history
  • Loading branch information
narknon committed Jun 18, 2024
1 parent d5eb2f5 commit 7b5ff7d
Show file tree
Hide file tree
Showing 29 changed files with 416 additions and 406 deletions.
4 changes: 2 additions & 2 deletions UE4SS/include/LuaType/LuaUObject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,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();
lua.throw_error(std::format(
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 Expand Up @@ -840,6 +840,6 @@ No overload found for function 'UObject.ProcessConsoleExec'.
break;
}

params.lua.throw_error(std::format("[push_integer] Unknown Operation ({}) not supported", static_cast<int32_t>(params.operation)));
params.lua.throw_error(fmt::format("[push_integer] Unknown Operation ({}) not supported", static_cast<int32_t>(params.operation)));
}
} // namespace RC::LuaType
12 changes: 5 additions & 7 deletions UE4SS/src/CrashDumper.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#include <CrashDumper.hpp>

#include <chrono>
#include <string>
#include <format>
#include <bit>

#include <fmt/chrono.h>
#include <UE4SSProgram.hpp>
#include <Unreal/Core/Windows/WindowsHWrapper.hpp>

Expand All @@ -27,13 +25,13 @@ namespace RC
LONG WINAPI ExceptionHandler(_EXCEPTION_POINTERS* exception_pointers)
{
const auto now = time_point_cast<seconds>(system_clock::now());
const std::wstring dump_path = std::format(L"{}\\crash_{:%Y_%m_%d_%H_%M_%S}.dmp", StringType{UE4SSProgram::get_program().get_working_directory()}, now);
const std::wstring dump_path = fmt::format(L"{}\\crash_{:%Y_%m_%d_%H_%M_%S}.dmp", StringType{UE4SSProgram::get_program().get_working_directory()}, now);

const HANDLE file = CreateFileW(dump_path.c_str(), GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

if (file == INVALID_HANDLE_VALUE)
{
const std::wstring message = std::format(L"Failed to create crashdump file, reason: {:x}", GetLastError());
const std::wstring message = fmt::format(L"Failed to create crashdump file, reason: {:x}", GetLastError());
MessageBoxW(NULL, message.c_str(), L"Fatal Error!", MB_OK);
return EXCEPTION_CONTINUE_SEARCH;
}
Expand All @@ -55,12 +53,12 @@ namespace RC

if (!ok)
{
const std::wstring message = std::format(L"Failed to write crashdump file, reason: {:x}", GetLastError());
const std::wstring message = fmt::format(L"Failed to write crashdump file, reason: {:x}", GetLastError());
MessageBoxW(NULL, message.c_str(), L"Fatal Error!", MB_OK);
return EXCEPTION_CONTINUE_SEARCH;
}

const std::wstring message = std::format(L"Crashdump written to: {}", dump_path);
const std::wstring message = fmt::format(L"Crashdump written to: {}", dump_path);
MessageBoxW(NULL, message.c_str(), L"Fatal Error!", MB_OK);

return EXCEPTION_EXECUTE_HANDLER;
Expand Down
6 changes: 3 additions & 3 deletions UE4SS/src/GUI/BPMods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ namespace RC::GUI::BPMods
auto mod_name_parts = explode_by_occurrence(mod_full_name, STR('/'));
mod_info.ModName = to_string(mod_name_parts[mod_name_parts.size() - 1 - 1]);

if (ImGui_TreeNodeEx(std::format("{}", mod_info.ModName).c_str(), std::format("{}_{}", mod_info.ModName, i).c_str(), ImGuiTreeNodeFlags_CollapsingHeader))
if (ImGui_TreeNodeEx(fmt::format("{}", mod_info.ModName).c_str(), fmt::format("{}_{}", mod_info.ModName, i).c_str(), ImGuiTreeNodeFlags_CollapsingHeader))
{
ImGui::Indent();
ImGui::Text("Author: %s", mod_info.ModAuthor.c_str());
ImGui::Text("Description: %s", mod_info.ModDescription.c_str());
ImGui::Text("Version: %s", mod_info.ModVersion.c_str());
if (ImGui_TreeNodeEx("Mod Buttons", std::format("{}_{}_ModButtons", mod_info.ModName, i).c_str(), ImGuiTreeNodeFlags_CollapsingHeader))
if (ImGui_TreeNodeEx("Mod Buttons", fmt::format("{}_{}_ModButtons", mod_info.ModName, i).c_str(), ImGuiTreeNodeFlags_CollapsingHeader))
{
ImGui::Indent();
for (size_t i2 = 0; i2 < mod_info.ModButtons.size(); ++i2)
Expand All @@ -111,7 +111,7 @@ namespace RC::GUI::BPMods
continue;
}
const auto& mod_button = mod_info.ModButtons[i2];
if (ImGui::Button(std::format("{}", mod_button).c_str()))
if (ImGui::Button(fmt::format("{}", mod_button).c_str()))
{
Output::send(STR("Mod button {} hit.\n"), to_wstring(mod_button));
mod_info.ModActor->ModMenuButtonPressed(static_cast<int32_t>(i2));
Expand Down
26 changes: 13 additions & 13 deletions UE4SS/src/GUI/Dumpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@ namespace RC::GUI::Dumpers
auto location = root_component->GetValuePtrByPropertyNameInChain<FVector>(STR("RelativeLocation"));
FString location_string{};
location_property->ExportTextItem(location_string, location, nullptr, nullptr, 0);
root_actor_buffer.append(std::format(STR("\"{}\","), location_string.GetCharArray()));
root_actor_buffer.append(fmt::format(STR("\"{}\","), location_string.GetCharArray()));

auto rotation = root_component->GetValuePtrByPropertyNameInChain<FRotator>(STR("RelativeRotation"));
FString rotation_string{};
rotation_property->ExportTextItem(rotation_string, rotation, nullptr, nullptr, 0);
root_actor_buffer.append(std::format(STR("\"{}\","), rotation_string.GetCharArray()));
root_actor_buffer.append(fmt::format(STR("\"{}\","), rotation_string.GetCharArray()));

auto scale = root_component->GetValuePtrByPropertyNameInChain<FVector>(STR("RelativeScale3D"));
FString scale_string{};
scale_property->ExportTextItem(scale_string, scale, nullptr, nullptr, 0);
root_actor_buffer.append(std::format(STR("\"{}\","), scale_string.GetCharArray()));
root_actor_buffer.append(fmt::format(STR("\"{}\","), scale_string.GetCharArray()));

return root_actor_buffer;
}
Expand Down Expand Up @@ -128,13 +128,13 @@ namespace RC::GUI::Dumpers

StringType actor_buffer{};

actor_buffer.append(std::format(STR("Row_{},"), actor_count));
actor_buffer.append(fmt::format(STR("Row_{},"), actor_count));

static auto game_mode_base = UObjectGlobals::FindFirstOf(STR("GameModeBase"));
static auto class_property = game_mode_base->GetPropertyByNameInChain(STR("GameStateClass"));
FString actor_class_string{};
class_property->ExportTextItem(actor_class_string, &actor->GetClassPrivate(), nullptr, nullptr, 0);
actor_buffer.append(std::format(STR("{},"), actor_class_string.GetCharArray()));
actor_buffer.append(fmt::format(STR("{},"), actor_class_string.GetCharArray()));

// TODO: build system to handle other types of components - possibly including a way to specify which components to dump and which properties are important via a config file
actor_buffer.append(generate_root_component_csv(*root_component));
Expand All @@ -157,7 +157,7 @@ namespace RC::GUI::Dumpers
static auto mesh_property = static_mesh_component_ptr->GetPropertyByNameInChain(STR("StaticMesh"));
FString mesh_string{};
mesh_property->ExportTextItem(mesh_string, &mesh, nullptr, nullptr, 0);
actor_buffer.append(std::format(STR("(StaticMesh={}',"), mesh_string.GetCharArray()));
actor_buffer.append(fmt::format(STR("(StaticMesh={}',"), mesh_string.GetCharArray()));

auto materials_for_each_body = [&](const UObject* material_interface) {
if (material_interface)
Expand All @@ -178,8 +178,8 @@ namespace RC::GUI::Dumpers
auto material_typeless_name = StringViewType{material_full_name.begin() + static_cast<long long>(material_type_space_location) + 1,
material_full_name.end()};

actor_buffer.append(std::format(STR("{}'"), material_interface->GetClassPrivate()->GetName()));
actor_buffer.append(std::format(STR("\"\"{}"), material_typeless_name));
actor_buffer.append(fmt::format(STR("{}'"), material_interface->GetClassPrivate()->GetName()));
actor_buffer.append(fmt::format(STR("\"\"{}"), material_typeless_name));
actor_buffer.append(STR("\"\"'"));
}
};
Expand Down Expand Up @@ -264,19 +264,19 @@ namespace RC::GUI::Dumpers

auto& actor_json_object = global_json_array.new_object();

actor_json_object.new_string(STR("Name"), std::format(STR("Row_{}"), actor_count));
actor_json_object.new_string(STR("Name"), fmt::format(STR("Row_{}"), actor_count));

static auto game_mode_base = UObjectGlobals::FindFirstOf(STR("GameModeBase"));
static auto class_property = game_mode_base->GetPropertyByNameInChain(STR("GameStateClass"));
FString actor_class_string{};
class_property->ExportTextItem(actor_class_string, &actor->GetClassPrivate(), nullptr, nullptr, 0);
actor_json_object.new_string(STR("Actor"), std::format(STR("{}"), StringViewType{actor_class_string.GetCharArray()}));
actor_json_object.new_string(STR("Actor"), fmt::format(STR("{}"), StringViewType{actor_class_string.GetCharArray()}));

auto& root_component_json_object = actor_json_object.new_object(STR("RootComponent"));

FString root_component_class_string{};
class_property->ExportTextItem(root_component_class_string, &(*root_component)->GetClassPrivate(), nullptr, nullptr, 0);
root_component_json_object.new_string(STR("SceneComponentClass"), std::format(STR("{}"), StringViewType{root_component_class_string.GetCharArray()}));
root_component_json_object.new_string(STR("SceneComponentClass"), fmt::format(STR("{}"), StringViewType{root_component_class_string.GetCharArray()}));

auto& location_json_object = root_component_json_object.new_object(STR("Location"));
auto location = (*root_component)->GetValuePtrByPropertyNameInChain<FVector>(STR("RelativeLocation"));
Expand Down Expand Up @@ -313,7 +313,7 @@ namespace RC::GUI::Dumpers
std::wstring file_buffer{};
file_buffer.append(generate_actors_csv_file(dump_actor_class));
auto file =
File::open(std::format(STR("{}\\{}-ue4ss_static_mesh_data.csv"), UE4SSProgram::get_program().get_working_directory(), long(std::time(nullptr))),
File::open(fmt::format(STR("{}\\{}-ue4ss_static_mesh_data.csv"), UE4SSProgram::get_program().get_working_directory(), long(std::time(nullptr))),
File::OpenFor::Writing,
File::OverwriteExistingFile::Yes,
File::CreateIfNonExistent::Yes);
Expand All @@ -326,7 +326,7 @@ namespace RC::GUI::Dumpers
Output::send(STR("Dumping CSV of all loaded actor types, positions and mesh properties\n"));
std::wstring file_buffer{};
file_buffer.append(generate_actors_csv_file(AActor::StaticClass()));
auto file = File::open(std::format(STR("{}\\{}-ue4ss_actor_data.csv"), UE4SSProgram::get_program().get_working_directory(), long(std::time(nullptr))),
auto file = File::open(fmt::format(STR("{}\\{}-ue4ss_actor_data.csv"), UE4SSProgram::get_program().get_working_directory(), long(std::time(nullptr))),
File::OpenFor::Writing,
File::OverwriteExistingFile::Yes,
File::CreateIfNonExistent::Yes);
Expand Down
Loading

0 comments on commit 7b5ff7d

Please sign in to comment.