Skip to content

Commit

Permalink
FF7: Minor widescreen and external mesh fixes (#635)
Browse files Browse the repository at this point in the history
  • Loading branch information
CosmosXIII committed Jan 11, 2024
1 parent 0cc1edb commit 3857d23
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .vcpkg/ports/bgfx/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ file(RENAME ${BIMG_SOURCE_DIR} "${BIMG_DIR}")
set(ENV{BIMG_DIR} ${BIMG_DIR})

# Set custom BGFX configuration
set(ENV{BGFX_CONFIG} "DEBUG=1:PREFER_DISCRETE_GPU=0:DYNAMIC_INDEX_BUFFER_SIZE=10485760:DYNAMIC_VERTEX_BUFFER_SIZE=31457280")
set(ENV{BGFX_CONFIG} "DEBUG=1:PREFER_DISCRETE_GPU=0:DYNAMIC_INDEX_BUFFER_SIZE=10485760:DYNAMIC_VERTEX_BUFFER_SIZE=31457280:MAX_RECT_CACHE=8192")

# Set up GENie (custom project generator)
set(GENIE_OPTIONS --with-tools)
Expand Down
8 changes: 8 additions & 0 deletions src/ff7/field/background.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,10 @@ namespace ff7::field
{
camera_range = widescreen.getCameraRange();

// Adjustment to prevent scrolling stopping one pixel too early
camera_range.left += 1;
camera_range.right -= 1;

// This centers the background if necessary
int cameraRangeSize = camera_range.right - camera_range.left;
half_width = 160 + std::min(53, cameraRangeSize / 2 - 160);
Expand Down Expand Up @@ -496,6 +500,10 @@ namespace ff7::field
void field_widescreen_width_clip_with_camera_range(vector2<short>* point)
{
auto camera_range = widescreen.getCameraRange();

// Adjustment to prevent scrolling stopping one pixel too early
camera_range.left += 1;
camera_range.right -= 1;

// This centers the background if necessary
int cameraRangeSize = camera_range.right - camera_range.left;
Expand Down
3 changes: 3 additions & 0 deletions src/ff7/world/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ namespace ff7::world {
}
}

newRenderer.setInterpolationQualifier(SMOOTH);
newRenderer.setPrimitiveType();
newRenderer.isTLVertex(false);
newRenderer.setBlendMode(RendererBlendMode::BLEND_NONE);
Expand Down Expand Up @@ -633,6 +634,7 @@ namespace ff7::world {

}

newRenderer.setInterpolationQualifier(SMOOTH);
newRenderer.setPrimitiveType();
newRenderer.isTLVertex(false);
newRenderer.setBlendMode(RendererBlendMode::BLEND_ADD);
Expand Down Expand Up @@ -779,6 +781,7 @@ namespace ff7::world {

multiply_matrix(&worldMatrix, &viewMatrix, &worldViewMatrix);

newRenderer.setInterpolationQualifier(SMOOTH);
newRenderer.setPrimitiveType();
newRenderer.isTLVertex(false);
newRenderer.setBlendMode(RendererBlendMode::BLEND_ADD);
Expand Down
79 changes: 41 additions & 38 deletions src/ff7/world/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,44 +144,47 @@ namespace ff7::world

void world_hook_init()
{
// World init
replace_call_function(ff7_externals.world_mode_loop_sub_74DB8C + 0x108, world_init_variables);

// Movement related fix
patch_divide_code<DWORD>(ff7_externals.world_init_variables_74E1E9 + 0x15D, common_frame_multiplier);
replace_call_function(ff7_externals.run_world_event_scripts_system_operations + 0x172, pop_world_stack_divide_wrapper);
replace_call_function(ff7_externals.run_world_event_scripts_system_operations + 0x14B, pop_world_stack_divide_wrapper);
replace_call_function(ff7_externals.run_world_event_scripts_system_operations + 0x55D, pop_world_stack_divide_wrapper);
replace_call_function(ff7_externals.run_world_event_scripts_system_operations + 0x584, pop_world_stack_divide_wrapper);

// Camera related fix
replace_call_function(ff7_externals.run_world_event_scripts_system_operations + 0x7DC, pop_world_stack_divide_wrapper);

// Midgar zolom (snake) movement fix
replace_call_function(ff7_externals.update_world_snake_position_7564CD + 0x26, world_snake_compute_delta_position);
replace_call_function(ff7_externals.update_world_snake_position_7564CD + 0x195, world_snake_compute_delta_position);
replace_call_function(ff7_externals.update_world_snake_position_7564CD + 0x2B4, world_snake_compute_delta_position);

// World Encounter rate fix
replace_call_function(ff7_externals.world_sub_767641 + 0x110, get_world_encounter_rate);

// Text box message fix
patch_code_byte(ff7_externals.world_text_box_window_paging_769C02 + 0xF6, 0x5 + common_frame_multiplier / 2);
patch_divide_code<byte>(ff7_externals.world_text_box_window_paging_769C02 + 0xF9, common_frame_multiplier);
patch_divide_code<WORD>(ff7_externals.world_text_box_window_paging_769C02 + 0x10A, common_frame_multiplier);
patch_code_byte(ff7_externals.world_text_box_window_paging_769C02 + 0x13A, 0x4 + common_frame_multiplier / 2);
patch_code_byte(ff7_externals.world_text_box_window_opening_769A66 + 0x3D, 0x2 + common_frame_multiplier / 2);
patch_code_byte(ff7_externals.world_text_box_window_opening_769A66 + 0xD2, 0x2 + common_frame_multiplier / 2);
patch_code_byte(ff7_externals.world_text_box_window_closing_76ADF7 + 0x67, 0x2 + common_frame_multiplier / 2);
patch_code_byte(ff7_externals.world_text_box_window_closing_76ADF7 + 0xC2, 0x2 + common_frame_multiplier / 2);
patch_divide_code<short>(ff7_externals.world_text_box_reverse_paging_76ABE9 + 0x42, common_frame_multiplier);
patch_divide_code<short>(ff7_externals.world_opcode_message + 0x1AC, common_frame_multiplier);
patch_divide_code<short>(ff7_externals.world_opcode_message + 0x2CF, common_frame_multiplier);
patch_divide_code<short>(ff7_externals.world_opcode_ask + 0x1AC, common_frame_multiplier);
patch_divide_code<byte>(ff7_externals.world_opcode_ask + 0x3CC, common_frame_multiplier);

// Wait frames decrease delayed
replace_call_function(ff7_externals.run_world_event_scripts + 0xC7, run_world_script_system_operations);
if(ff7_fps_limiter == FF7_LIMITER_60FPS)
{
// World init
replace_call_function(ff7_externals.world_mode_loop_sub_74DB8C + 0x108, world_init_variables);

// Movement related fix
patch_divide_code<DWORD>(ff7_externals.world_init_variables_74E1E9 + 0x15D, common_frame_multiplier);
replace_call_function(ff7_externals.run_world_event_scripts_system_operations + 0x172, pop_world_stack_divide_wrapper);
replace_call_function(ff7_externals.run_world_event_scripts_system_operations + 0x14B, pop_world_stack_divide_wrapper);
replace_call_function(ff7_externals.run_world_event_scripts_system_operations + 0x55D, pop_world_stack_divide_wrapper);
replace_call_function(ff7_externals.run_world_event_scripts_system_operations + 0x584, pop_world_stack_divide_wrapper);

// Camera related fix
replace_call_function(ff7_externals.run_world_event_scripts_system_operations + 0x7DC, pop_world_stack_divide_wrapper);

// Midgar zolom (snake) movement fix
replace_call_function(ff7_externals.update_world_snake_position_7564CD + 0x26, world_snake_compute_delta_position);
replace_call_function(ff7_externals.update_world_snake_position_7564CD + 0x195, world_snake_compute_delta_position);
replace_call_function(ff7_externals.update_world_snake_position_7564CD + 0x2B4, world_snake_compute_delta_position);

// World Encounter rate fix
replace_call_function(ff7_externals.world_sub_767641 + 0x110, get_world_encounter_rate);

// Text box message fix
patch_code_byte(ff7_externals.world_text_box_window_paging_769C02 + 0xF6, 0x5 + common_frame_multiplier / 2);
patch_divide_code<byte>(ff7_externals.world_text_box_window_paging_769C02 + 0xF9, common_frame_multiplier);
patch_divide_code<WORD>(ff7_externals.world_text_box_window_paging_769C02 + 0x10A, common_frame_multiplier);
patch_code_byte(ff7_externals.world_text_box_window_paging_769C02 + 0x13A, 0x4 + common_frame_multiplier / 2);
patch_code_byte(ff7_externals.world_text_box_window_opening_769A66 + 0x3D, 0x2 + common_frame_multiplier / 2);
patch_code_byte(ff7_externals.world_text_box_window_opening_769A66 + 0xD2, 0x2 + common_frame_multiplier / 2);
patch_code_byte(ff7_externals.world_text_box_window_closing_76ADF7 + 0x67, 0x2 + common_frame_multiplier / 2);
patch_code_byte(ff7_externals.world_text_box_window_closing_76ADF7 + 0xC2, 0x2 + common_frame_multiplier / 2);
patch_divide_code<short>(ff7_externals.world_text_box_reverse_paging_76ABE9 + 0x42, common_frame_multiplier);
patch_divide_code<short>(ff7_externals.world_opcode_message + 0x1AC, common_frame_multiplier);
patch_divide_code<short>(ff7_externals.world_opcode_message + 0x2CF, common_frame_multiplier);
patch_divide_code<short>(ff7_externals.world_opcode_ask + 0x1AC, common_frame_multiplier);
patch_divide_code<byte>(ff7_externals.world_opcode_ask + 0x3CC, common_frame_multiplier);

// Wait frames decrease delayed
replace_call_function(ff7_externals.run_world_event_scripts + 0xC7, run_world_script_system_operations);
}

if (enable_time_cycle)
{
Expand Down
6 changes: 4 additions & 2 deletions src/ff7_opengl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,7 @@ void ff7_init_hooks(struct game_obj *_game_object)
if(ff7_fps_limiter == FF7_LIMITER_60FPS)
{
common_frame_multiplier = 2;
ff7::world::world_hook_init();


// Swirl mode 60FPS fix
patch_multiply_code<byte>(ff7_externals.swirl_main_loop + 0x184, common_frame_multiplier); // wait frames before swirling
patch_multiply_code<byte>(ff7_externals.swirl_loop_sub_4026D4 + 0x3E, common_frame_multiplier);
Expand All @@ -268,6 +267,9 @@ void ff7_init_hooks(struct game_obj *_game_object)
}
}

// World fix (60 FPS, night cycle, external mesh)
ff7::world::world_hook_init();

// Field FPS fix (60FPS, 30FPS movies)
ff7::field::ff7_field_hook_init();

Expand Down

0 comments on commit 3857d23

Please sign in to comment.