diff --git a/src/strings.cpp b/src/strings.cpp --- a/src/strings.cpp +++ b/src/strings.cpp @@ -799,6 +799,9 @@ uint ConvertDisplaySpeedToKmhishSpeed(ui { return _units_velocity[_settings_game.locale.units_velocity].c.FromDisplay(speed * 16, true, 10); } + +static std::vector _game_script_raw_strings; + /** * Parse most format codes within a string and write the result to a buffer. * @param buff The buffer to write the final string to. @@ -932,6 +935,7 @@ static char *FormatString(char *buff, co sub_args_need_free[i] = true; sub_args.SetParam(i++, (uint64)(size_t)g); + _game_script_raw_strings.push_back(g); } } /* If we didn't error out, we can actually print the string. */ @@ -941,7 +945,10 @@ static char *FormatString(char *buff, co } for (i = 0; i < 20; i++) { - if (sub_args_need_free[i]) free((void *)sub_args.GetParam(i)); + if (sub_args_need_free[i]) { + free((void *)sub_args.GetParam(i)); + _game_script_raw_strings.pop_back(); + } } break; } @@ -1046,6 +1053,10 @@ static char *FormatString(char *buff, co case SCC_RAW_STRING_POINTER: { // {RAW_STRING} const char *raw_string = (const char *)(size_t)args->GetInt64(SCC_RAW_STRING_POINTER); + if (game_script && std::find(_game_script_raw_strings.begin(), _game_script_raw_strings.end(), raw_string) == _game_script_raw_strings.end()) { + buff = strecat(buff, "(invalid RAW_STRING parameter)", last); + break; + } buff = FormatString(buff, raw_string, args, last); break; }