Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
myst6re committed Nov 16, 2024
1 parent dba87aa commit 858c8dc
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 10 deletions.
5 changes: 1 addition & 4 deletions src/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2866,11 +2866,8 @@ __declspec(dllexport) void *new_dll_graphics_driver(void *game_object)
// game-specific initialization
if(!ff8)
ret = ff7_load_driver(game_object);
else {
VOBJ(game_obj, game_object, game_object);
VRASS(game_object, current_gfx_driver, 1); // Force software rendering game hacks
else
ret = ff8_load_driver(game_object);
}

return ret;
}
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;
uint8_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
8 changes: 7 additions & 1 deletion 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 @@ -571,7 +576,8 @@ 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.ssigpu_init = get_absolute_value(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] = false;
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

0 comments on commit 858c8dc

Please sign in to comment.