From 5c1963b95fe873780e7642706c56177c23470d28 Mon Sep 17 00:00:00 2001 From: CosmosXIII Date: Sun, 29 Sep 2024 23:43:00 +0900 Subject: [PATCH] Fixed loading text box size --- src/ff7.h | 2 + src/ff7/defs.h | 1 + src/ff7/japanese_text.cpp | 105 +++++++++++++++++++++++++++++++++++++- src/ff7_data.h | 86 ++++++++++++++++--------------- src/ff7_opengl.cpp | 2 + 5 files changed, 153 insertions(+), 43 deletions(-) diff --git a/src/ff7.h b/src/ff7.h index 33994326..32e18ad4 100644 --- a/src/ff7.h +++ b/src/ff7.h @@ -3894,6 +3894,8 @@ struct ff7_externals ff7_graphics_object* menu_jafont_4_graphics_object; ff7_graphics_object* menu_jafont_5_graphics_object; ff7_graphics_object* menu_jafont_6_graphics_object; + + uint32_t sub_6F54A2; }; uint32_t ff7gl_load_group(uint32_t group_num, struct matrix_set *matrix_set, struct p_hundred *hundred_data, struct p_group *group_data, struct polygon_data *polygon_data, struct ff7_polygon_set *polygon_set, struct ff7_game_obj *game_object); diff --git a/src/ff7/defs.h b/src/ff7/defs.h index 009079c1..bd49084c 100644 --- a/src/ff7/defs.h +++ b/src/ff7/defs.h @@ -128,3 +128,4 @@ void draw_text_top_display_6D1CC0_jp(int a1, __int16 menu_box_idx, char a3, unsi void main_menu_draw_everything_maybe_6C0B91_jp(); void field_text_box_window_paging_631945_jp(short); void field_text_box_window_opening_6317A9_jp(short); +int sub_6F54A2_jp(byte *a1); diff --git a/src/ff7/japanese_text.cpp b/src/ff7/japanese_text.cpp index 2e6f9eaa..b4c01149 100644 --- a/src/ff7/japanese_text.cpp +++ b/src/ff7/japanese_text.cpp @@ -314,7 +314,7 @@ int charWidthData[6][256] = 30, 30, 28, 31, 30, 30, 29, 29, 30, 30, 29, 30, 31, 30, 29, 27, 30, 29, 29, 29, 31, 30, 28, 23, 30, 30, 30, 31, 29, 31, 30, 30, 31, 30, 30, 31, 31, 29, 21, 28, 29, 30, 30, 27, 31, 30, 30, 29, - 29, 30, 30, 22, 22, 22, 22, 23, 22, 22, 22, 22, 22, 51, 53, 16, + 29, 30, 30, 22, 22, 22, 22, 23, 22, 22, 22, 22, 22, 51, 62, 16, 28, 29, 24, 30, 26, 29, 29, 29, 28, 29, 26, 29, 29, 28, 25, 23, 28, 28, 25, 25, 30, 28, 28, 23, 27, 29, 28, 30, 25, 28, 26, 28, 29, 28, 26, 28, 29, 28, 20, 25, 25, 24, 28, 28, 24, 27, 28, 28, @@ -2270,4 +2270,107 @@ void field_text_box_window_opening_6317A9_jp(short WINDOW_ID) ff7_externals.text_box_window_data_array_CFF5B8[WINDOW_ID].window_mode = 2; } } +} + +int sub_6F54A2_jp(byte *a1) +{ + int v2; // [esp+Ch] [ebp-Ch] + int v3; // [esp+10h] [ebp-8h] + int v4; // [esp+14h] [ebp-4h] + + v3 = 0; + v2 = 0; + bool kanjiDetected = false; + int charWidth = 0; + int leftPadding = 0; + while ( v3 < 64 /*ff7_externals.g_max_string_length_91F034*/ && a1 && (unsigned __int8)*a1 != 255 ) + { + /*switch ( *a1 ) + { + case 250: + ++a1; + v4 = 231; + break; + case 251: + ++a1; + v4 = 441; + break; + case 252: + ++a1; + v4 = 672; + break; + case 253: + ++a1; + v4 = 882; + break; + case 254: + ++a1; + v4 = 1092; + break; + default: + v4 = 0; + break; + }*/ + + auto next_char = a1 + 1; + switch ( *a1 ) + { + case 0xFAu: + kanjiDetected = true; + charWidth = charWidthData[1][*next_char] & 0x1F; + leftPadding = charWidthData[1][*next_char] >> 5; + ++a1; + ++v3; + continue; + case 0xFBu: + kanjiDetected = true; + charWidth = charWidthData[2][*next_char] & 0x1F; + leftPadding = charWidthData[2][*next_char] >> 5; + ++a1; + ++v3; + continue; + case 0xFCu: + kanjiDetected = true; + charWidth = charWidthData[3][*next_char] & 0x1F; + leftPadding = charWidthData[3][*next_char] >> 5; + ++a1; + ++v3; + continue; + case 0xFDu: + kanjiDetected = true; + charWidth = charWidthData[4][*next_char] & 0x1F; + leftPadding = charWidthData[4][*next_char] >> 5; + ++a1; + ++v3; + continue; + case 0xFEu: + + kanjiDetected = true; + charWidth = charWidthData[5][*next_char] & 0x1F; + leftPadding = charWidthData[5][*next_char] >> 5; + ++a1; + ++v3; + continue; + default: + if(!kanjiDetected) + { + charWidth = charWidthData[0][*a1] & 0x1F; + leftPadding = charWidthData[0][*a1] >> 5; + } + kanjiDetected = false; + break; + } + + /*if ( ff7_externals.dword_DC12DC ) + v2 += (__int64)((double)(*(byte *)(ff7_externals.g_text_spacing_DB958C + v4 + (unsigned __int8)*a1) & 0x1F) * 1.6666666) + + (__int64)((double)((int)*(unsigned __int8 *)(ff7_externals.g_text_spacing_DB958C + v4 + (unsigned __int8)*a1) >> 5) + * 1.6666666); + else + v2 += 2 * ((int)*(unsigned __int8 *)(ff7_externals.g_text_spacing_DB958C + v4 + (unsigned __int8)*a1) >> 5) + + 2 * (*(byte *)(ff7_externals.g_text_spacing_DB958C + v4 + (unsigned __int8)*a1) & 0x1F);*/ + v2 += leftPadding + std::ceil(0.5f * charWidth); + ++a1; + ++v3; + } + return v2; } \ No newline at end of file diff --git a/src/ff7_data.h b/src/ff7_data.h index ea666edd..976b9174 100644 --- a/src/ff7_data.h +++ b/src/ff7_data.h @@ -1409,6 +1409,49 @@ inline void ff7_find_externals(struct ff7_game_obj* game_object) ff7_externals.snowboard_global_object_off_926290 = (DWORD*)get_absolute_value(ff7_externals.snowboard_parse_model_vertices_732159, 0x55); // -------------------------------- + // Steam achievement + uint32_t sub_434347 = get_relative_call(ff7_externals.battle_loop, 0x484); + uint32_t* pointer_functions_7C2980 = (uint32_t*)get_absolute_value(sub_434347, 0x19C); + ff7_externals.battle_enemy_killed_sub_433BD2 = pointer_functions_7C2980[0]; + ff7_externals.battle_sub_5C7F94 = get_relative_call(ff7_externals.battle_enemy_killed_sub_433BD2, 0x2AF); + ff7_externals.menu_battle_end_mode = (uint16_t*)get_absolute_value(ff7_externals.menu_battle_end_sub_6C9543, 0x2C); + uint32_t menu_sub_6CBD54 = get_relative_call(ff7_externals.menu_sub_6CDA83, 0xC1); + ff7_externals.menu_sub_71FF95 = get_relative_call(menu_sub_6CBD54, 0x7); + ff7_externals.menu_shop_loop = get_relative_call(ff7_externals.menu_sub_71FF95, 0x84); + if (version == VERSION_FF7_102_US) { + ff7_externals.get_materia_gil = get_relative_call(ff7_externals.menu_shop_loop, 0x548); + } else { + ff7_externals.get_materia_gil = get_relative_call(ff7_externals.menu_shop_loop, 0x5C4); + } + ff7_externals.opcode_increase_gil_call = get_relative_call(ff7_externals.opcode_goldu, 0x38); + + ff7_externals.display_battle_action_text_sub_6D71FA = get_relative_call(ff7_externals.display_battle_action_text_42782A, 0x77); + + ff7_externals.opcode_add_materia_inventory_call = get_relative_call(ff7_externals.opcode_smtra, 0x72); + ff7_externals.menu_sub_6CBCF3 = get_relative_call(ff7_externals.opcode_add_materia_inventory_call, 0x43); + ff7_externals.menu_sub_705D16 = ff7_externals.menu_subs_call_table[4]; + ff7_externals.menu_sub_6CC17F = get_relative_call(ff7_externals.menu_sub_705D16, 0x1729); + + ff7_externals.menu_decrease_item_quantity = get_relative_call(ff7_externals.opcode_dlitm, 0x38); + + ff7_externals.sub_60FA7D = get_relative_call(ff7_externals.opcode_setbyte, 0x14); + + uint32_t menu_sub_6CBD65 = get_relative_call(ff7_externals.menu_sub_6CDA83, 0x54); + uint32_t menu_sub_722393 = get_relative_call(menu_sub_6CBD65, 0x4); + ff7_externals.menu_sub_7212FB = get_relative_call(menu_sub_722393, 0x8B); + switch(version) { + case VERSION_FF7_102_US: + case VERSION_FF7_102_SP: + ff7_externals.load_save_file = get_relative_call(ff7_externals.menu_sub_7212FB, 0xE9D); + break; + case VERSION_FF7_102_DE: + case VERSION_FF7_102_FR: + ff7_externals.load_save_file = get_relative_call(ff7_externals.menu_sub_7212FB, 0xEC5); + break; + } + + // -------------------------------- + // japanese ff7_externals.engine_loop_main_loop_sub_4090E6 = get_absolute_value(ff7_externals.swirl_loop_sub_4026D4, 0x11E); ff7_externals.menu_enter_sub_6CD3B0 = get_absolute_value(ff7_externals.engine_loop_main_loop_sub_4090E6, 0x627); @@ -1558,48 +1601,7 @@ inline void ff7_find_externals(struct ff7_game_obj* game_object) ff7_externals.field_text_box_window_entity_id_CC0960 = (byte*)get_absolute_value((uint32_t)ff7_externals.field_text_box_window_opening_6317A9, 0xB); ff7_externals.current_entity_id_byte_CC0964 = (byte*)get_absolute_value((uint32_t)ff7_externals.field_text_box_window_opening_6317A9, 0x13); - // Steam achievement - uint32_t sub_434347 = get_relative_call(ff7_externals.battle_loop, 0x484); - uint32_t* pointer_functions_7C2980 = (uint32_t*)get_absolute_value(sub_434347, 0x19C); - ff7_externals.battle_enemy_killed_sub_433BD2 = pointer_functions_7C2980[0]; - ff7_externals.battle_sub_5C7F94 = get_relative_call(ff7_externals.battle_enemy_killed_sub_433BD2, 0x2AF); - ff7_externals.menu_battle_end_mode = (uint16_t*)get_absolute_value(ff7_externals.menu_battle_end_sub_6C9543, 0x2C); - uint32_t menu_sub_6CBD54 = get_relative_call(ff7_externals.menu_sub_6CDA83, 0xC1); - ff7_externals.menu_sub_71FF95 = get_relative_call(menu_sub_6CBD54, 0x7); - ff7_externals.menu_shop_loop = get_relative_call(ff7_externals.menu_sub_71FF95, 0x84); - if (version == VERSION_FF7_102_US) { - ff7_externals.get_materia_gil = get_relative_call(ff7_externals.menu_shop_loop, 0x548); - } else { - ff7_externals.get_materia_gil = get_relative_call(ff7_externals.menu_shop_loop, 0x5C4); - } - ff7_externals.opcode_increase_gil_call = get_relative_call(ff7_externals.opcode_goldu, 0x38); - - ff7_externals.display_battle_action_text_sub_6D71FA = get_relative_call(ff7_externals.display_battle_action_text_42782A, 0x77); - - ff7_externals.opcode_add_materia_inventory_call = get_relative_call(ff7_externals.opcode_smtra, 0x72); - ff7_externals.menu_sub_6CBCF3 = get_relative_call(ff7_externals.opcode_add_materia_inventory_call, 0x43); - ff7_externals.menu_sub_705D16 = ff7_externals.menu_subs_call_table[4]; - ff7_externals.menu_sub_6CC17F = get_relative_call(ff7_externals.menu_sub_705D16, 0x1729); - - ff7_externals.menu_decrease_item_quantity = get_relative_call(ff7_externals.opcode_dlitm, 0x38); - - ff7_externals.sub_60FA7D = get_relative_call(ff7_externals.opcode_setbyte, 0x14); - - uint32_t menu_sub_6CBD65 = get_relative_call(ff7_externals.menu_sub_6CDA83, 0x54); - uint32_t menu_sub_722393 = get_relative_call(menu_sub_6CBD65, 0x4); - ff7_externals.menu_sub_7212FB = get_relative_call(menu_sub_722393, 0x8B); - switch(version) { - case VERSION_FF7_102_US: - case VERSION_FF7_102_SP: - ff7_externals.load_save_file = get_relative_call(ff7_externals.menu_sub_7212FB, 0xE9D); - break; - case VERSION_FF7_102_DE: - case VERSION_FF7_102_FR: - ff7_externals.load_save_file = get_relative_call(ff7_externals.menu_sub_7212FB, 0xEC5); - break; - } - - // -------------------------------- + ff7_externals.sub_6F54A2 = get_relative_call(ff7_externals.menu_sub_7212FB, 0x14F); } inline void ff7_data(struct ff7_game_obj* game_object) diff --git a/src/ff7_opengl.cpp b/src/ff7_opengl.cpp index c4359468..a91650d8 100644 --- a/src/ff7_opengl.cpp +++ b/src/ff7_opengl.cpp @@ -383,6 +383,8 @@ void ff7_init_hooks(struct game_obj *_game_object) patch_code_byte(0x632C4E + 0x2, 0xC); patch_code_byte(0x632C4E + 0x3, 0xC); patch_code_byte(0x632C4E + 0x4, 0xC); + + replace_function(ff7_externals.sub_6F54A2, sub_6F54A2_jp); } //######################