Skip to content

Commit

Permalink
FF8: SFX external
Browse files Browse the repository at this point in the history
  • Loading branch information
myst6re authored and julianxhokaxhiu committed Dec 3, 2022
1 parent 81b9472 commit c2f8fa1
Show file tree
Hide file tree
Showing 6 changed files with 229 additions and 22 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
- Voice: Add play voice for enemy actions during BATTLE mode ( https://github.com/julianxhokaxhiu/FFNx/pull/502 )
- Widescreen: Allow the buster sword image on new game screen to support 16:9 ratio ( https://github.com/julianxhokaxhiu/FFNx/pull/506 )

## FF8

- SFX: Add external SFX audio effects for modders ( https://github.com/julianxhokaxhiu/FFNx/pull/510 )

# 1.14.0

- Full commit list since last stable release: https://github.com/julianxhokaxhiu/FFNx/compare/1.13.0...1.14.0
Expand Down
5 changes: 5 additions & 0 deletions src/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ SoLoud::VGMStream* NxAudioEngine::loadSFX(int id, bool loop)
return nullptr;
}

int NxAudioEngine::getSFXIdFromChannel(int channel)
{
return _sfxChannels[channel].game_id;
}

void NxAudioEngine::unloadSFX(int id)
{
if (_sfxEffectsHandler.count(id) > 0)
Expand Down
1 change: 1 addition & 0 deletions src/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ class NxAudioEngine
void cleanup();

// SFX
int getSFXIdFromChannel(int channel);
void unloadSFX(int id);
bool canPlaySFX(int id);
bool playSFX(const char* name, int id, int channel, float panning, bool loop = false);
Expand Down
37 changes: 29 additions & 8 deletions src/ff8.h
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,19 @@ struct ff8_vibrate_struc
uint8_t field_23;
};

struct ff8_audio_fmt
{
uint32_t audio_data_length;
uint32_t audio_data_offset;
uint8_t is_looped;
uint8_t field_9;
uint8_t field_A;
uint8_t field_B;
uint32_t buffer_read_cursor;
uint32_t buffer_write_cursor;
LPWAVEFORMATEX wave_format;
};

struct ff8_game_obj
{
uint32_t do_quit;
Expand Down Expand Up @@ -930,6 +943,7 @@ struct ff8_externals
uint32_t sub_467C00;
uint32_t sub_468810;
uint32_t sub_468BD0;
uint32_t pubintro_cleanup;
uint32_t pubintro_exit;
uint32_t pubintro_main_loop;
uint32_t credits_main_loop;
Expand Down Expand Up @@ -999,7 +1013,6 @@ struct ff8_externals
DWORD* engine_mapped_buttons;
uint32_t draw_movie_frame;
struct ff8_movie_obj *movie_object;
uint32_t initialize_sound;
int (*sub_5304B0)();
uint32_t *enable_framelimiter;
unsigned char *byte_1CE4907;
Expand Down Expand Up @@ -1043,12 +1056,7 @@ struct ff8_externals
uint32_t sub_501B60;
uint32_t pause_music_and_sfx;
uint32_t restart_music_and_sfx;
uint32_t sub_4A6680;
uint32_t sub_4A6660;
uint32_t sub_4A3D20;
uint32_t sub_4A3EE0;
uint32_t sub_469C60;
uint32_t sub_46DDC0;
uint32_t directsound_create_secondary_buffer;
uint32_t start;
uint32_t battle_main_loop;
void (*show_vram_window)();
Expand Down Expand Up @@ -1077,7 +1085,6 @@ struct ff8_externals
uint32_t play_midi_segments;
uint32_t load_and_play_midi_segment;
uint32_t stop_midi_segments;
uint32_t sounds_cleanup;
uint32_t volume_update;
uint32_t volume_music_update;
uint32_t music_load;
Expand Down Expand Up @@ -1156,6 +1163,20 @@ struct ff8_externals
uint8_t *cardgame_tim_texture_cards;
uint8_t *cardgame_tim_texture_icons;
uint8_t *cardgame_tim_texture_font;
uint32_t sfx_play_to_current_playing_channel;
uint32_t sfx_unload_all;
uint32_t sfx_pause_all;
uint32_t sfx_resume_all;
uint32_t sfx_stop_all2;
uint32_t sfx_stop_all;
void(*sfx_set_master_volume)(uint32_t);
int(*sfx_get_master_volume)();
uint32_t sfx_set_volume;
uint32_t sfx_current_channel_is_playing;
uint32_t sfx_is_playing;
uint32_t sfx_set_panning;
uint16_t *sfx_sound_count;
ff8_audio_fmt **sfx_audio_fmt;
};

void ff8gl_field_78(struct ff8_polygon_set *polygon_set, struct ff8_game_obj *game_object);
Expand Down
47 changes: 33 additions & 14 deletions src/ff8_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ void ff8_find_externals()
ff8_externals.sub_468BD0 = get_relative_call(ff8_externals.sub_468810, 0x5B);
common_externals.dinput_hack1 = ff8_externals.sub_468BD0 + 0x64;

ff8_externals.pubintro_cleanup = get_absolute_value(ff8_externals.main_entry, 0x162);
ff8_externals.pubintro_exit = get_absolute_value(ff8_externals.main_entry, 0x176);
ff8_externals.pubintro_main_loop = get_absolute_value(ff8_externals.main_entry, 0x180);
ff8_externals.credits_main_loop = get_absolute_value(ff8_externals.pubintro_main_loop, 0x6D);
Expand Down Expand Up @@ -347,16 +348,16 @@ void ff8_find_externals()
common_externals.keyboard_device = (IDirectInputDeviceA**)get_absolute_value(common_externals.get_keyboard_state, 0x01);
common_externals.keyboard_connected = (uint32_t*)get_absolute_value(common_externals.get_keyboard_state, 0x2C);

ff8_externals.initialize_sound = get_relative_call(ff8_externals.pubintro_init, 0xD8); // sub_469640
common_externals.directsound_create = get_relative_call(ff8_externals.initialize_sound, 0x5D); // sub_46DBF0
common_externals.sfx_init = get_relative_call(ff8_externals.pubintro_init, 0xD8); // sub_469640
common_externals.directsound_create = get_relative_call(common_externals.sfx_init, 0x5D); // sub_46DBF0
common_externals.directsound = (LPLPDIRECTSOUND)get_absolute_value(common_externals.directsound_create, 0x26);
common_externals.directsound_release = get_relative_call(ff8_externals.initialize_sound, 0xD5);
common_externals.directsound_release = get_relative_call(common_externals.sfx_init, 0xD5);

common_externals.midi_init = get_relative_call(ff8_externals.pubintro_init, 0x130);
ff8_externals.music_path = (char*)get_absolute_value(ff8_externals.pubintro_init, 0x136);
common_externals.midi_cleanup = get_relative_call(ff8_externals.pubintro_init, 0x1B4);
ff8_externals.sounds_cleanup = get_relative_call(ff8_externals.pubintro_init, 0x1B9);
common_externals.wav_cleanup = get_relative_call(ff8_externals.sounds_cleanup, 0x0);
common_externals.midi_cleanup = get_relative_call(ff8_externals.pubintro_cleanup, 0x44);
common_externals.sfx_cleanup = get_relative_call(ff8_externals.pubintro_cleanup, 0x49);
common_externals.wav_cleanup = get_relative_call(common_externals.sfx_cleanup, 0x0);
ff8_externals.volume_update = get_relative_call(ff8_externals.field_main_loop, 0x28C);
ff8_externals.volume_music_update = get_relative_call(ff8_externals.volume_update, 0x6);

Expand Down Expand Up @@ -410,14 +411,32 @@ void ff8_find_externals()
common_externals.restart_wav = get_relative_call(ff8_externals.restart_music_and_sfx, 0xF);
common_externals.restart_midi = get_relative_call(ff8_externals.restart_music_and_sfx, 0x17);

// Search DirectSoundBuffer initilization
ff8_externals.sub_4A6680 = get_relative_call(ff8_externals.sub_47CCB0, 0xF6);
ff8_externals.sub_4A6660 = get_absolute_value(ff8_externals.sub_4A6680, 0x36F + 1);
ff8_externals.sub_4A3D20 = get_relative_call(ff8_externals.sub_4A6660, 0x00);
ff8_externals.sub_4A3EE0 = get_relative_call(ff8_externals.sub_4A3D20, 0x12A);
ff8_externals.sub_469C60 = get_relative_call(ff8_externals.sub_4A3EE0, 0x418);
ff8_externals.sub_46DDC0 = get_relative_call(ff8_externals.sub_469C60, 0x22A);
common_externals.directsound_buffer_flags_1 = ff8_externals.sub_46DDC0 + 0x34 - 2;
// SFX
ff8_externals.sfx_play_to_current_playing_channel = get_relative_call(ff8_externals.opcode_effectplay2, 0x5F);
common_externals.play_sfx_on_channel = get_relative_call(ff8_externals.sfx_play_to_current_playing_channel, 0x35);
common_externals.sfx_load = get_relative_call(common_externals.play_sfx_on_channel, 0x89);
ff8_externals.sfx_unload_all = get_relative_call(common_externals.sfx_cleanup, 0x5);
common_externals.sfx_unload = get_relative_call(ff8_externals.sfx_unload_all, 0x4);
ff8_externals.sfx_pause_all = get_relative_call(ff8_externals.pause_music_and_sfx, 0x1C);
common_externals.sfx_pause = get_relative_call(ff8_externals.sfx_pause_all, 0x1B);
ff8_externals.sfx_resume_all = get_relative_call(ff8_externals.restart_music_and_sfx, 0x1C);
common_externals.sfx_resume = get_relative_call(ff8_externals.sfx_resume_all, 0x1B);
ff8_externals.sfx_stop_all2 = get_relative_call(ff8_externals.sm_battle_sound, 0x18C);
ff8_externals.sfx_stop_all = get_relative_call(ff8_externals.sfx_stop_all2, 0x0);
common_externals.sfx_stop = get_relative_call(ff8_externals.sfx_stop_all, 0x1B);
ff8_externals.sfx_set_volume = get_relative_call(common_externals.play_sfx_on_channel, 0xA1);
ff8_externals.sfx_get_master_volume = (int(*)())(ff8_externals.sfx_set_volume - 0x10);
ff8_externals.sfx_set_master_volume = (void(*)(uint32_t))(uint32_t(ff8_externals.sfx_get_master_volume) - 0xE0);
common_externals.master_sfx_volume = (uint32_t *)get_absolute_value(uint32_t(ff8_externals.sfx_get_master_volume), 0x1);
ff8_externals.sfx_current_channel_is_playing = get_relative_call(ff8_externals.sfx_play_to_current_playing_channel, 0xB);
ff8_externals.sfx_is_playing = get_relative_call(ff8_externals.sfx_current_channel_is_playing - 0x88, 0x0);
ff8_externals.sfx_set_panning = get_relative_call(common_externals.play_sfx_on_channel, 0x115);
ff8_externals.sfx_audio_fmt = (ff8_audio_fmt **)get_absolute_value(common_externals.sfx_init, 0x21B);
ff8_externals.sfx_sound_count = (uint16_t *)get_absolute_value(common_externals.sfx_init, 0x22C);

// Search DirectSoundBuffer initialization
ff8_externals.directsound_create_secondary_buffer = get_relative_call(common_externals.sfx_load, 0x22A);
common_externals.directsound_buffer_flags_1 = ff8_externals.directsound_create_secondary_buffer + 0x34 - 2;

ff8_externals.sub_5304B0 = (int (*)())get_relative_call(common_externals.update_movie_sample, 0x3D9);

Expand Down

0 comments on commit c2f8fa1

Please sign in to comment.