Skip to content

Commit 01692cc

Browse files
committed
feat(LiveView): Added 'MaxValueSize' to filters list
This controls how many bytes a value can be in size before we stop rendering it for performance reasons.
1 parent 5114148 commit 01692cc

File tree

2 files changed

+72
-4
lines changed

2 files changed

+72
-4
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
3+
#include <string>
4+
#include <cstdint>
5+
6+
#include <String/StringType.hpp>
7+
8+
namespace RC::GUI::Filter
9+
{
10+
class MaxValueSize
11+
{
12+
public:
13+
static inline StringType s_debug_name{STR("MaxValueSize")};
14+
static inline int32_t s_value{500};
15+
static inline std::string s_value_buffer{fmt::format("{}", s_value)};
16+
};
17+
} // namespace RC::GUI::Filter

UE4SS/src/GUI/LiveView.cpp

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <GUI/LiveView/Filter/InstancesOnly.hpp>
2424
#include <GUI/LiveView/Filter/NonInstancesOnly.hpp>
2525
#include <GUI/LiveView/Filter/SearchFilter.hpp>
26+
#include <GUI/LiveView/Filter/MaxValueSize.hpp>
2627
#include <GUI/UFunctionCallerWidget.hpp>
2728
#include <Helpers/String.hpp>
2829
#include <JSON/JSON.hpp>
@@ -338,6 +339,14 @@ namespace RC::GUI
338339
filter_data.new_bool(STR("Enabled"), is_enabled);
339340
}
340341

342+
static auto add_int32_filter_to_json(JSON::Array& json_filters, const StringType& filter_name, int32_t value) -> void
343+
{
344+
auto& json_object = json_filters.new_object();
345+
json_object.new_string(STR("FilterName"), filter_name);
346+
auto& filter_data = json_object.new_object(STR("FilterData"));
347+
filter_data.new_number(STR("Value"), value);
348+
}
349+
341350
template <typename ContainerType>
342351
static auto add_array_filter_to_json(JSON::Array& json_filters, const StringType& filter_name, const ContainerType& container, const StringType& array_name)
343352
-> void
@@ -393,6 +402,9 @@ namespace RC::GUI
393402
add_array_filter_to_json(json_filters, Filter::HasPropertyType::s_debug_name, Filter::HasPropertyType::list_property_types, STR("PropertyTypes"));
394403
add_array_filter_to_json(json_filters, Filter::FunctionParamFlags::s_debug_name, Filter::FunctionParamFlags::s_checkboxes, STR("FunctionParamFlags"));
395404
}
405+
{
406+
add_int32_filter_to_json(json_filters, Filter::MaxValueSize::s_debug_name, Filter::MaxValueSize::s_value);
407+
}
396408

397409
auto json_file = File::open(StringType{UE4SSProgram::get_program().get_working_directory()} + fmt::format(STR("\\liveview\\filters.meta.json")),
398410
File::OpenFor::Writing,
@@ -532,6 +544,16 @@ namespace RC::GUI
532544
return LoopAction::Continue;
533545
});
534546
}
547+
else if (filter_name == Filter::MaxValueSize::s_debug_name)
548+
{
549+
auto number = filter_data.get<JSON::Number>(STR("Value")).get<int64_t>();
550+
if (number > std::numeric_limits<int32_t>::max())
551+
{
552+
number = std::numeric_limits<int32_t>::max();
553+
}
554+
Filter::MaxValueSize::s_value = static_cast<int32_t>(number);
555+
Filter::MaxValueSize::s_value_buffer = fmt::format("{}", Filter::MaxValueSize::s_value);
556+
}
535557

536558
return LoopAction::Continue;
537559
});
@@ -2200,15 +2222,14 @@ namespace RC::GUI
22002222
FString property_text{};
22012223
auto property_name = to_string(property->GetName());
22022224
auto container_ptr = property->ContainerPtrToValuePtr<void*>(container);
2203-
static constexpr int32 s_max_structure_size = 500;
22042225
auto as_struct_property = CastField<FStructProperty>(property);
22052226
static constexpr auto s_error_too_large = STR("Too large to display!");
22062227
bool editable = true;
22072228
if (auto as_map_property = CastField<FMapProperty>(property))
22082229
{
22092230
auto map = std::bit_cast<FScriptMap*>(container_ptr);
22102231
if (auto value_as_struct_property = CastField<FStructProperty>(as_map_property->GetValueProp());
2211-
value_as_struct_property && value_as_struct_property->GetStruct()->GetStructureSize() * map->Num() > s_max_structure_size)
2232+
value_as_struct_property && value_as_struct_property->GetStruct()->GetStructureSize() * map->Num() > Filter::MaxValueSize::s_value)
22122233
{
22132234
editable = false;
22142235
property_text = FString{s_error_too_large};
@@ -2219,12 +2240,12 @@ namespace RC::GUI
22192240
}
22202241
}
22212242
else if (auto as_array_property = CastField<FArrayProperty>(property);
2222-
as_array_property && as_array_property->GetSize() * std::bit_cast<FScriptArray*>(container_ptr)->Num() > s_max_structure_size)
2243+
as_array_property && as_array_property->GetSize() * std::bit_cast<FScriptArray*>(container_ptr)->Num() > Filter::MaxValueSize::s_value)
22232244
{
22242245
editable = false;
22252246
property_text = FString{s_error_too_large};
22262247
}
2227-
else if (as_struct_property && as_struct_property->GetStruct()->GetStructureSize() > s_max_structure_size)
2248+
else if (as_struct_property && as_struct_property->GetStruct()->GetStructureSize() > Filter::MaxValueSize::s_value)
22282249
{
22292250
editable = false;
22302251
property_text = FString{s_error_too_large};
@@ -3878,6 +3899,36 @@ namespace RC::GUI
38783899
}
38793900
}
38803901
}
3902+
// Row 8
3903+
ImGui::TableNextRow();
3904+
ImGui::TableNextColumn();
3905+
ImGui::Text("Maximum Value Size");
3906+
ImGui::TableNextColumn();
3907+
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
3908+
if (ImGui::InputText("##MaxValueSize", &Filter::MaxValueSize::s_value_buffer))
3909+
{
3910+
int32_t new_value{-1};
3911+
try
3912+
{
3913+
new_value = std::stoi(Filter::MaxValueSize::s_value_buffer);
3914+
}
3915+
catch (...)
3916+
{
3917+
if (Filter::MaxValueSize::s_value > 0)
3918+
{
3919+
new_value = std::numeric_limits<int32_t>::max();
3920+
}
3921+
else
3922+
{
3923+
new_value = 0;
3924+
}
3925+
}
3926+
if (new_value < 0)
3927+
{
3928+
new_value = Filter::MaxValueSize::s_value;
3929+
}
3930+
Filter::MaxValueSize::s_value_buffer = fmt::format("{}", Filter::MaxValueSize::s_value);
3931+
}
38813932

38823933
ImGui::TableNextRow();
38833934
ImGui::TableNextColumn();

0 commit comments

Comments
 (0)