game: move pc-encode-utf8-string to common kmachine code (#3742)

Also adds formatter rules for a couple of macros.
This commit is contained in:
Hat Kid
2024-11-03 01:28:48 +01:00
committed by GitHub
parent ba9085fee0
commit 10d7dabfd7
8 changed files with 53 additions and 17 deletions
+12
View File
@@ -904,6 +904,15 @@ void pc_register_screen_shot_settings(u32 ptr) {
register_screen_shot_settings(Ptr<ScreenShotSettings>(ptr).c());
}
void pc_encode_utf8_string(u32 src_str_ptr, u32 str_dest_ptr) {
auto str = std::string(Ptr<String>(src_str_ptr).c()->data());
std::string version = version_to_game_name(g_game_version);
const std::string font_bank_name = version == "jak1" ? "jak1-v2" : version;
std::string converted =
get_font_bank(get_text_version_from_name(font_bank_name))->convert_utf8_to_game(str);
strcpy(Ptr<String>(str_dest_ptr).c()->data(), converted.c_str());
}
/// Initializes all functions that are common across all game versions
/// These functions have the same implementation and do not use any game specific functions (other
/// than the one to create a function in the first place)
@@ -1005,6 +1014,9 @@ void init_common_pc_port_functions(
// RNG
make_func_symbol_func("pc-rand", (void*)pc_rand);
// text
make_func_symbol_func("pc-encode-utf8-string", (void*)pc_encode_utf8_string);
// debugging tools
make_func_symbol_func("pc-filter-debug-string?", (void*)pc_filter_debug_string);
make_func_symbol_func("pc-screen-shot", (void*)pc_screen_shot);