Skip to content

Commit

Permalink
FF7: Add support for chunked scene.bin sections
Browse files Browse the repository at this point in the history
  • Loading branch information
julianxhokaxhiu committed Jan 26, 2023
1 parent 0c206d7 commit b559e6f
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- Core: Fix Barret's eyebrow not loading ( https://github.com/julianxhokaxhiu/FFNx/issues/107 )
- Modding: Added day-night time cycle system that can be controled from field scripts ( https://github.com/julianxhokaxhiu/FFNx/pull/511 )
- Modding: Add support for chunked kernel.bin/kernel2.bin sections
- Modding: Add support for chunked scene.bin sections
- Renderer: Fixed graphical glitch happening in battle when 3d models rendered in front of UI ( https://github.com/julianxhokaxhiu/FFNx/issues/131 )
- Voice: Add play voice for enemy actions during BATTLE mode ( https://github.com/julianxhokaxhiu/FFNx/pull/502 )
- Voice: Fix worldmap message opcode wrong dialog id
Expand Down
2 changes: 2 additions & 0 deletions src/ff7.h
Original file line number Diff line number Diff line change
Expand Up @@ -2368,6 +2368,8 @@ struct ff7_externals
uint32_t open_lgp_file;
FILE **lgp_fds;
uint32_t battle_sub_437DB0;
uint32_t battle_scene_bin_sub_5D1050;
int (*engine_load_bin_file_sub_419210)(char *filename, int offset, int size, char **out_buffer, void (*callback)(void));
uint32_t sub_5CB2CC;
uint32_t *midi_volume_control;
uint32_t *midi_initialized;
Expand Down
24 changes: 24 additions & 0 deletions src/ff7/battle/battle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,28 @@ namespace ff7::battle

g_FF7SteamAchievements->unlockFirstLimitBreakAchievement(command_id, action_id);
}

int load_scene_bin_chunk(char *filename, int offset, int size, char **out_buffer, void (*callback)(void))
{
int ret = ff7_externals.engine_load_bin_file_sub_419210(filename, offset, size, out_buffer, callback);

char chunk_file[1024]{0};
uint32_t chunk_size = 0;
FILE* fd;

_snprintf(chunk_file, sizeof(chunk_file), "%s/%s/battle/scene.bin.chunk.%i", basedir, direct_mode_path.c_str(), (offset >> 13) + 1);

if ((fd = fopen(chunk_file, "rb")) != NULL)
{
fseek(fd, 0L, SEEK_END);
chunk_size = ftell(fd);
fseek(fd, 0L, SEEK_SET);
fread(*out_buffer, sizeof(byte), chunk_size, fd);

ffnx_trace("scene section %i overridden with %s\n", (offset >> 13) + 1, chunk_file);
fclose(fd);
}

return ret;
}
}
1 change: 1 addition & 0 deletions src/ff7/battle/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace ff7::battle
void load_battle_stage(int param_1, int battle_location_id, int **param_3);
void battle_sub_5C7F94(int param_1, int param_2);
void display_battle_action_text_sub_6D71FA(short command_id, short action_id);
int load_scene_bin_chunk(char *filename, int offset, int size, char **out_buffer, void (*callback)(void));

// Menu
void battle_menu_enter();
Expand Down
2 changes: 2 additions & 0 deletions src/ff7_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ void ff7_find_externals(struct ff7_game_obj* game_object)
ff7_externals.battle_sub_437DB0 = get_absolute_value(ff7_externals.battle_loop, 0x8D);
ff7_externals.sub_5CB2CC = get_relative_call(ff7_externals.battle_sub_437DB0, 0x43);
ff7_externals.battle_formation_id = (WORD*)get_absolute_value(ff7_externals.battle_sub_437DB0, 0x1FD);
ff7_externals.battle_scene_bin_sub_5D1050 = get_relative_call(ff7_externals.battle_sub_437DB0, 0x15D);
ff7_externals.engine_load_bin_file_sub_419210 = (int (*)(char *filename, int offset, int size, char **out_buffer, void (*callback)(void)))(get_relative_call(ff7_externals.battle_scene_bin_sub_5D1050, 0x85));

ff7_externals.play_midi = (void (*)(uint32_t))common_externals.play_midi;
common_externals.master_midi_volume = (DWORD *)get_absolute_value(common_externals.set_master_midi_volume, 0x46);
Expand Down
1 change: 1 addition & 0 deletions src/ff7_opengl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ void ff7_init_hooks(struct game_obj *_game_object)
replace_function(ff7_externals.kernel2_get_text, kernel2_get_text);
patch_code_uint((uint32_t)ff7_externals.kernel_load_kernel2 + 0x1D, 20 * 65536);
replace_call_function(ff7_externals.kernel_init + 0x1FD, ff7_load_kernel2_wrapper);
replace_call_function(ff7_externals.battle_scene_bin_sub_5D1050 + 0x85, ff7::battle::load_scene_bin_chunk);

replace_function(ff7_externals.read_field_file, ff7_read_field_file);

Expand Down

0 comments on commit b559e6f

Please sign in to comment.