Skip to content

Commit

Permalink
Get rid of some more overzealous enum _MAX entries
Browse files Browse the repository at this point in the history
  • Loading branch information
narknon committed Nov 9, 2023
1 parent dd124af commit 8cda919
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions UE4SS/src/SDKGenerator/UEHeaderGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,14 +639,18 @@ namespace RC::UEGenerator
}
expected_next_enum_value = Value + 1;

if (pre_append_result_line.ends_with(STR("_MAX")))
StringType pre_append_result_line_lower = pre_append_result_line;
std::transform(pre_append_result_line_lower.begin(), pre_append_result_line_lower.end(), pre_append_result_line_lower.begin(), ::towlower);
if (pre_append_result_line_lower.ends_with(STR("_max")))
{
const StringType expected_full_constant_name = std::format(STR("{}_MAX"), enum_prefix);

StringType expected_full_constant_name_lower = expected_full_constant_name;
std::transform(expected_full_constant_name_lower.begin(), expected_full_constant_name_lower.end(), expected_full_constant_name_lower.begin(), ::towlower);

int64_t expected_max_value = highest_enum_value + 1;

// Skip enum _MAX constant if it has a matching name and is 1 greater than the highest value used, which means it has been autogenerated
if ((pre_append_result_line == expected_full_constant_name || pre_append_result_line == sanitize_enumeration_name(expected_full_constant_name)) &&
if ((pre_append_result_line_lower == expected_full_constant_name_lower || pre_append_result_line_lower == sanitize_enumeration_name(expected_full_constant_name_lower)) &&
Value == expected_max_value)
{
continue;
Expand Down Expand Up @@ -2922,11 +2926,15 @@ namespace RC::UEGenerator
int64 highest_enum_value = 0;
const StringType enum_prefix = uenum->GenerateEnumPrefix();
const StringType expected_max_name = std::format(STR("{}_MAX"), enum_prefix);

StringType expected_max_name_lower = expected_max_name;
std::transform(expected_max_name_lower.begin(), expected_max_name_lower.end(), expected_max_name_lower.begin(), ::towlower);

for (auto [Name, Value] : uenum->ForEachName())
{
StringType enum_name = sanitize_enumeration_name(Name.ToString());
if ((enum_name != expected_max_name && enum_name != sanitize_enumeration_name(expected_max_name)) && Value > highest_enum_value)
StringType enum_name_lower = enum_name;
std::transform(enum_name_lower.begin(), enum_name_lower.end(), enum_name_lower.begin(), ::towlower);
if ((enum_name_lower != expected_max_name_lower && enum_name_lower != sanitize_enumeration_name(expected_max_name_lower)) && Value > highest_enum_value)
{
highest_enum_value = Value;
}
Expand Down

0 comments on commit 8cda919

Please sign in to comment.