diff --git a/src/ObjLoading/Game/IW4/Menu/MenuConverterIW4.cpp b/src/ObjLoading/Game/IW4/Menu/MenuConverterIW4.cpp index 6aa08ac60..a2cae9a82 100644 --- a/src/ObjLoading/Game/IW4/Menu/MenuConverterIW4.cpp +++ b/src/ObjLoading/Game/IW4/Menu/MenuConverterIW4.cpp @@ -12,6 +12,7 @@ #include "Parsing/Simple/Expression/SimpleExpressionConditionalOperator.h" #include "Parsing/Simple/Expression/SimpleExpressionUnaryOperation.h" #include "Utils/ClassUtils.h" +#include "Utils/StringUtils.h" #include #include @@ -204,12 +205,15 @@ namespace IW4 const CommonMenuDef* menu, const CommonItemDef* item) const { - Statement_s* functionStatement = m_conversion_zone_state->FindFunction(functionCall->m_function_name); + std::string lowerCaseFunctionName(functionCall->m_function_name); + utils::MakeStringLowerCase(lowerCaseFunctionName); + + Statement_s* functionStatement = m_conversion_zone_state->FindFunction(lowerCaseFunctionName); if (functionStatement == nullptr) { // Function was not converted yet: Convert it now - const auto foundCommonFunction = m_parsing_zone_state->m_functions_by_name.find(functionCall->m_function_name); + const auto foundCommonFunction = m_parsing_zone_state->m_functions_by_name.find(lowerCaseFunctionName); if (foundCommonFunction == m_parsing_zone_state->m_functions_by_name.end()) throw MenuConversionException("Failed to find definition for custom function \"" + functionCall->m_function_name + "\"", menu, item); diff --git a/src/ObjLoading/Game/IW5/Menu/MenuConverterIW5.cpp b/src/ObjLoading/Game/IW5/Menu/MenuConverterIW5.cpp index 2da2a9da3..321146fcc 100644 --- a/src/ObjLoading/Game/IW5/Menu/MenuConverterIW5.cpp +++ b/src/ObjLoading/Game/IW5/Menu/MenuConverterIW5.cpp @@ -12,6 +12,7 @@ #include "Parsing/Simple/Expression/SimpleExpressionConditionalOperator.h" #include "Parsing/Simple/Expression/SimpleExpressionUnaryOperation.h" #include "Utils/ClassUtils.h" +#include "Utils/StringUtils.h" #include #include @@ -204,18 +205,21 @@ namespace IW5 const CommonMenuDef* menu, const CommonItemDef* item) const { - Statement_s* functionStatement = m_conversion_zone_state->FindFunction(functionCall->m_function_name); + std::string lowerCaseFunctionName(functionCall->m_function_name); + utils::MakeStringLowerCase(lowerCaseFunctionName); + + Statement_s* functionStatement = m_conversion_zone_state->FindFunction(lowerCaseFunctionName); if (functionStatement == nullptr) { // Function was not converted yet: Convert it now - const auto foundCommonFunction = m_parsing_zone_state->m_functions_by_name.find(functionCall->m_function_name); + const auto foundCommonFunction = m_parsing_zone_state->m_functions_by_name.find(lowerCaseFunctionName); if (foundCommonFunction == m_parsing_zone_state->m_functions_by_name.end()) throw MenuConversionException("Failed to find definition for custom function \"" + functionCall->m_function_name + "\"", menu, item); functionStatement = ConvertExpression(foundCommonFunction->second->m_value.get(), menu, item); - functionStatement = m_conversion_zone_state->AddFunction(foundCommonFunction->second->m_name, functionStatement); + functionStatement = m_conversion_zone_state->AddFunction(lowerCaseFunctionName, functionStatement); } expressionEntry functionEntry{}; diff --git a/src/ObjLoading/Parsing/Menu/Matcher/MenuExpressionMatchers.cpp b/src/ObjLoading/Parsing/Menu/Matcher/MenuExpressionMatchers.cpp index 9ec73c373..b5acb8acc 100644 --- a/src/ObjLoading/Parsing/Menu/Matcher/MenuExpressionMatchers.cpp +++ b/src/ObjLoading/Parsing/Menu/Matcher/MenuExpressionMatchers.cpp @@ -58,7 +58,11 @@ const std::map& MenuExpressionMatchers::GetBaseFunctionMapF if (!iw4FunctionMapInitialized) { for (size_t i = IW4::expressionFunction_e::EXP_FUNC_DYN_START; i < std::extent_v; i++) - iw4FunctionMap.emplace(std::make_pair(IW4::g_expFunctionNames[i], i)); + { + std::string functionName(IW4::g_expFunctionNames[i]); + utils::MakeStringLowerCase(functionName); + iw4FunctionMap.emplace(std::make_pair(functionName, i)); + } } return iw4FunctionMap; @@ -71,7 +75,11 @@ const std::map& MenuExpressionMatchers::GetBaseFunctionMapF if (!iw5FunctionMapInitialized) { for (size_t i = IW5::expressionFunction_e::EXP_FUNC_DYN_START; i < std::extent_v; i++) - iw5FunctionMap.emplace(std::make_pair(IW5::g_expFunctionNames[i], i)); + { + std::string functionName(IW5::g_expFunctionNames[i]); + utils::MakeStringLowerCase(functionName); + iw5FunctionMap.emplace(std::make_pair(std::move(functionName), i)); + } } return iw5FunctionMap; diff --git a/src/ObjLoading/Parsing/Menu/MenuAssetZoneState.cpp b/src/ObjLoading/Parsing/Menu/MenuAssetZoneState.cpp index 0b3a8eb9c..cf9c5191b 100644 --- a/src/ObjLoading/Parsing/Menu/MenuAssetZoneState.cpp +++ b/src/ObjLoading/Parsing/Menu/MenuAssetZoneState.cpp @@ -1,10 +1,15 @@ #include "MenuAssetZoneState.h" +#include "Utils/StringUtils.h" + using namespace menu; void MenuAssetZoneState::AddFunction(std::unique_ptr function) { - m_functions_by_name.emplace(std::make_pair(function->m_name, function.get())); + std::string lowerCaseFunctionName(function->m_name); + utils::MakeStringLowerCase(lowerCaseFunctionName); + + m_functions_by_name.emplace(std::make_pair(lowerCaseFunctionName, function.get())); m_functions.emplace_back(std::move(function)); } diff --git a/src/ObjLoading/Parsing/Menu/MenuFileParserState.cpp b/src/ObjLoading/Parsing/Menu/MenuFileParserState.cpp index 64fe0ffa9..9cb3af8ac 100644 --- a/src/ObjLoading/Parsing/Menu/MenuFileParserState.cpp +++ b/src/ObjLoading/Parsing/Menu/MenuFileParserState.cpp @@ -1,5 +1,7 @@ #include "MenuFileParserState.h" +#include "Utils/StringUtils.h" + using namespace menu; MenuFileParserState::EventHandlerConditionState::EventHandlerConditionState(CommonEventHandlerCondition* condition) @@ -32,7 +34,9 @@ MenuFileParserState::MenuFileParserState(const FeatureLevel featureLevel, const { for (const auto& function : zoneState->m_functions) { - m_functions_by_name.emplace(std::make_pair(function->m_name, function.get())); + std::string lowerCaseName(function->m_name); + utils::MakeStringLowerCase(lowerCaseName); + m_functions_by_name.emplace(std::make_pair(lowerCaseName, function.get())); } for (const auto& menu : zoneState->m_menus) diff --git a/src/ObjLoading/Parsing/Menu/MenuFileParserState.h b/src/ObjLoading/Parsing/Menu/MenuFileParserState.h index 7eedb75c5..719465241 100644 --- a/src/ObjLoading/Parsing/Menu/MenuFileParserState.h +++ b/src/ObjLoading/Parsing/Menu/MenuFileParserState.h @@ -36,7 +36,9 @@ namespace menu std::vector> m_functions; std::vector> m_menus; + // Function names are case-insensitive, therefore keys are always lowercase std::map m_functions_by_name; + std::map m_menus_by_name; bool m_in_global_scope; diff --git a/src/ObjLoading/Parsing/Menu/Sequence/FunctionScopeSequences.cpp b/src/ObjLoading/Parsing/Menu/Sequence/FunctionScopeSequences.cpp index 5459a3dd6..45655f96a 100644 --- a/src/ObjLoading/Parsing/Menu/Sequence/FunctionScopeSequences.cpp +++ b/src/ObjLoading/Parsing/Menu/Sequence/FunctionScopeSequences.cpp @@ -34,10 +34,13 @@ namespace menu::function_scope_sequences throw ParsingException(result.NextCapture(CAPTURE_TOKEN).GetPos(), ss.str()); } - const auto existingFunction = state->m_functions_by_name.find(state->m_current_function->m_name); + auto lowerCaseName = state->m_current_function->m_name; + utils::MakeStringLowerCase(lowerCaseName); + + const auto existingFunction = state->m_functions_by_name.find(lowerCaseName); if (existingFunction == state->m_functions_by_name.end()) { - state->m_functions_by_name.emplace(std::make_pair(state->m_current_function->m_name, state->m_current_function)); + state->m_functions_by_name.emplace(std::make_pair(lowerCaseName, state->m_current_function)); state->m_current_function = nullptr; } else if (!state->m_current_function->m_value->Equals(existingFunction->second->m_value.get()))