Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FF8: Bring back shadows and tinted window #750

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Ambient: Fix Battle ID detection for random encounters in Field
- Modding: Allow modding card names hardcoded in exe ( https://github.com/julianxhokaxhiu/FFNx/pull/739 )
- Modding: Add compatibility to LZ4 compression in FS archives ( https://github.com/julianxhokaxhiu/FFNx/pull/741 https://github.com/julianxhokaxhiu/FFNx/pull/743/files )
- Rendering: Add support for substractive blending ( https://github.com/julianxhokaxhiu/FFNx/pull/750 )
- Voice: Add support for Worldmap question dialogs
- Voice: Add support for Auto text in World messages

Expand Down
5 changes: 5 additions & 0 deletions src/ff8.h
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,9 @@ struct ff8_externals
uint32_t get_disk_number;
char* disk_data_path;
const char *app_path;
uint32_t swirl_enter;
uint32_t swirl_main_loop;
uint32_t sub_460B60;
uint32_t field_main_loop;
uint32_t field_main_exit;
uint32_t psxvram_texture_pages_free;
Expand All @@ -1068,6 +1070,8 @@ struct ff8_externals
uint32_t engine_set_init_time;
uint32_t sub_4672C0;
uint32_t sub_471F70;
uint32_t field_fade_transition_sub_472990;
uint32_t sub_45CDD0;
uint32_t sub_4767B0;
uint32_t sub_4789A0;
char (*sub_47CA90)();
Expand Down Expand Up @@ -1214,6 +1218,7 @@ struct ff8_externals
uint32_t sub_45B310;
uint32_t sub_45B460;
uint32_t ssigpu_init;
uint32_t *sub_blending_capability;
uint32_t *d3dcaps;
uint32_t sub_53BB90;
uint32_t worldmap_fog_filter_polygons_in_block_1;
Expand Down
6 changes: 6 additions & 0 deletions src/ff8_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ void ff8_find_externals()
ff8_externals.battle_main_loop = get_absolute_value(ff8_externals.main_loop, 0x340 + 4);
// Search battle sound function to find play/stop midi related methods
ff8_externals.sm_battle_sound = get_relative_call(ff8_externals.main_loop, 0x487 + 5);
ff8_externals.swirl_enter = get_absolute_value(ff8_externals.main_loop, 0x493 + 5);
ff8_externals.swirl_main_loop = get_absolute_value(ff8_externals.main_loop, 0x4A3 + 5);
ff8_externals.sub_470250 = get_relative_call(ff8_externals.main_loop, 0x6E7 - 15);
}
Expand All @@ -140,6 +141,7 @@ void ff8_find_externals()
ff8_externals.battle_main_loop = get_absolute_value(ff8_externals.main_loop, 0x340);
// Search battle sound function to find play/stop midi related methods
ff8_externals.sm_battle_sound = get_relative_call(ff8_externals.main_loop, 0x487);
ff8_externals.swirl_enter = get_absolute_value(ff8_externals.main_loop, 0x493);
ff8_externals.swirl_main_loop = get_absolute_value(ff8_externals.main_loop, 0x4A3);
ff8_externals.sub_470250 = get_relative_call(ff8_externals.main_loop, 0x6E7);
}
Expand All @@ -149,6 +151,7 @@ void ff8_find_externals()
ff8_externals.psxvram_texture_page_free = get_relative_call(ff8_externals.psxvram_texture_pages_free, 0x21);
ff8_externals.psxvram_texture_page_tex_header_free = get_relative_call(ff8_externals.psxvram_texture_page_free, 0x98);
ff8_externals.engine_set_init_time = get_relative_call(ff8_externals.battle_enter, 0x35);
ff8_externals.sub_460B60 = get_relative_call(ff8_externals.swirl_enter, 0x9);

common_externals.debug_print2 = get_relative_call(uint32_t(ff8_externals.sm_pc_read), 0x16);
ff8_externals.moriya_filesystem_open = get_relative_call(uint32_t(ff8_externals.sm_pc_read), 0x21);
Expand Down Expand Up @@ -221,6 +224,8 @@ void ff8_find_externals()
common_externals.assert_malloc = (void* (*)(uint32_t, const char*, uint32_t))get_relative_call(ff8_externals.load_fonts, JP_VERSION ? 0x29 : 0x2A);

ff8_externals.sub_471F70 = get_relative_call(ff8_externals.field_main_loop, 0x148);
ff8_externals.field_fade_transition_sub_472990 = get_relative_call(ff8_externals.field_main_loop, 0x19E);
ff8_externals.sub_45CDD0 = get_relative_call(ff8_externals.field_fade_transition_sub_472990, 0x5C);

if (JP_VERSION)
{
Expand Down Expand Up @@ -572,6 +577,7 @@ void ff8_find_externals()
ff8_externals.sub_45B310 = get_relative_call(ff8_externals.pubintro_init, 0x91);
ff8_externals.sub_45B460 = get_relative_call(ff8_externals.sub_45B310, 0x0);
ff8_externals.ssigpu_init = get_relative_call(ff8_externals.sub_45B460, 0x26);
ff8_externals.sub_blending_capability = (uint32_t *)get_absolute_value(ff8_externals.sub_45B460, 0x19);
ff8_externals.d3dcaps = (uint32_t *)get_absolute_value(ff8_externals.ssigpu_init, 0x6C);

if(FF8_US_VERSION)
Expand Down
38 changes: 33 additions & 5 deletions src/ff8_opengl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,35 @@ void swirl_sub_56D390(uint32_t x, uint32_t y, uint32_t w, uint32_t h)

if(trace_all) ffnx_trace("swirl_sub_56D390: (%i, %i) %ix%i 0x%x (0x%x)\n", x, y, w, h, *ff8_externals.swirl_texture1, tex_header);

struct ff8_texture_set *texture_set = (struct ff8_texture_set *)(*ff8_externals.swirl_texture1)->hundred_data->texture_set;

common_unload_texture((*ff8_externals.swirl_texture1)->hundred_data->texture_set);
common_load_texture((*ff8_externals.swirl_texture1)->hundred_data->texture_set, tex_header, texture_format);
common_load_texture((*ff8_externals.swirl_texture1)->hundred_data->texture_set, tex_header, texture_set->texture_format);

last_tex_header = tex_header;
}

void ff8_wm_set_render_to_vram_current_screen_flag_before_battle()
{
if(trace_all) ffnx_trace("%s\n", __func__);

// There is currently an visual issue in the last worldmap frame before swirl if this flag is enabled
// We lose the shadows, but keep the full battle transition effect
*ff8_externals.sub_blending_capability = false;

// Disable software frame rendering to VRAM (by not doing anything here) because it is not needed anymore
}

void ff8_swirl_init(float a1)
{
if(trace_all) ffnx_trace("%s\n", __func__);

// Reenable the flag that was disabled in worldmap
*ff8_externals.sub_blending_capability = true;

((void(*)(float))ff8_externals.sub_460B60)(a1);
}

int ff8_init_gamepad()
{
if (xinput_connected)
Expand Down Expand Up @@ -987,6 +1010,8 @@ void ff8_init_hooks(struct game_obj *_game_object)
replace_function(ff8_externals.engine_eval_process_input, ff8_is_window_active);

replace_function(ff8_externals.swirl_sub_56D390, swirl_sub_56D390);
replace_call(ff8_externals.worldmap_with_fog_sub_53FAC0 + (FF8_US_VERSION ? 0xB3C: 0xB2F), ff8_wm_set_render_to_vram_current_screen_flag_before_battle);
replace_call(ff8_externals.swirl_enter + 0x9, ff8_swirl_init);

replace_function(common_externals.destroy_tex_header, ff8_destroy_tex_header);
replace_function(common_externals.load_tex_file, ff8_load_tex_file);
Expand Down Expand Up @@ -1024,10 +1049,13 @@ void ff8_init_hooks(struct game_obj *_game_object)
memset_code(ff8_externals.movie_hack1, 0x90, 14);
memset_code(ff8_externals.movie_hack2, 0x90, 8);

ff8_externals.d3dcaps[0] = true;
ff8_externals.d3dcaps[1] = true;
ff8_externals.d3dcaps[2] = true;
ff8_externals.d3dcaps[3] = true;
ff8_externals.d3dcaps[0] = true; // Has DDSCAPS_OVERLAY capability in Hardware Emulation Layer + Enable alpha on textures
ff8_externals.d3dcaps[1] = true; // Enable alpha on textures
ff8_externals.d3dcaps[2] = false; // Emulate substractive blending via non-paletted texture if enabled
ff8_externals.d3dcaps[3] = true; // Seems to divide by 2 one vertex if disabled
ff8_externals.d3dcaps[4] = false;
*ff8_externals.sub_blending_capability = true;
patch_code_byte(ff8_externals.sub_45CDD0 + 0x12, 2); // Force comparison to current driver, to enable substractive blending in field fade in/out

// Fix save format
if (version == VERSION_FF8_12_FR_NV || version == VERSION_FF8_12_SP_NV || version == VERSION_FF8_12_IT_NV)
Expand Down
8 changes: 4 additions & 4 deletions src/voice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1420,10 +1420,10 @@ void voice_init()
replace_call_function(ff8_externals.sub_54FDA0 + (FF8_US_VERSION ? 0xAE : 0xAC), ff8_world_dialog_assign_text);
replace_call_function(ff8_externals.sub_54FDA0 + (FF8_US_VERSION ? 0x178 : 0x175), ff8_world_dialog_assign_text);
replace_call_function(ff8_externals.sub_543CB0 + (FF8_US_VERSION ? 0x5EE : (FF8_SP_VERSION || FF8_IT_VERSION) ? 0x5D2 : 0x5BB), ff8_world_dialog_question_assign_text);
replace_call_function(ff8_externals.sub_5484B0 + (FF8_US_VERSION ? 0xBD : 0x96), ff8_world_dialog_question_assign_text);
replace_call_function(ff8_externals.sub_5484B0 + (FF8_US_VERSION ? 0x24F : 0x228), ff8_world_dialog_question_assign_text);
replace_call_function(ff8_externals.sub_5484B0 + (FF8_US_VERSION ? 0xBD : 0x131), ff8_world_dialog_question_assign_text);
replace_call_function(ff8_externals.sub_5484B0 + (FF8_US_VERSION ? 0x24F : 0x244), ff8_world_dialog_question_assign_text);
replace_call_function(ff8_externals.sub_54D7E0 + (FF8_US_VERSION ? 0x119 : 0x116), ff8_world_dialog_question_assign_text);
replace_call_function(ff8_externals.sub_54E9B0 + (FF8_US_VERSION ? 0x621 : (FF8_SP_VERSION ? 0x66E : 0x633)), ff8_world_dialog_question_assign_text);
replace_call_function(ff8_externals.sub_54E9B0 + (FF8_US_VERSION ? 0xBE4 : (FF8_SP_VERSION ? 0xC31 : 0xBF6)), ff8_world_dialog_question_assign_text);
replace_call_function(ff8_externals.sub_54E9B0 + (FF8_US_VERSION ? 0x621 : (FF8_SP_VERSION ? 0x66A : 0x62F)), ff8_world_dialog_question_assign_text);
replace_call_function(ff8_externals.sub_54E9B0 + (FF8_US_VERSION ? 0xBE4 : (FF8_SP_VERSION ? 0xC99 : 0xC5E)), ff8_world_dialog_question_assign_text);
}
}