Skip to content

Commit

Permalink
FF8: Fix ASK voice acting dialogs
Browse files Browse the repository at this point in the history
Ensure the default text plays first and choices afterwards
  • Loading branch information
julianxhokaxhiu committed Jul 9, 2023
1 parent 2c02a80 commit 8c6d806
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions src/voice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,7 @@ int ff8_opcode_voice_mes(int unk)
int message_current_opcode = win->state;
char* field_name = get_current_field_name();

current_opcode_message_status[window_id].is_message_ask = false;
current_opcode_message_status[window_id].message_dialog_id = dialog_id;

return ff8_opcode_old_mes(unk);
Expand All @@ -844,6 +845,7 @@ int ff8_opcode_voice_ames(int unk)
int message_current_opcode = win->state;
char* field_name = get_current_field_name();

current_opcode_message_status[window_id].is_message_ask = false;
current_opcode_message_status[window_id].message_dialog_id = dialog_id;

return ff8_opcode_old_ames(unk);
Expand All @@ -861,6 +863,7 @@ int ff8_opcode_voice_amesw(int unk)
int message_current_opcode = win->state;
char* field_name = get_current_field_name();

current_opcode_message_status[window_id].is_message_ask = false;
current_opcode_message_status[window_id].message_dialog_id = dialog_id;

return ff8_opcode_old_amesw(unk);
Expand All @@ -878,6 +881,7 @@ int ff8_opcode_voice_ramesw(int unk)
int message_current_opcode = win->state;
char* field_name = get_current_field_name();

current_opcode_message_status[window_id].is_message_ask = false;
current_opcode_message_status[window_id].message_dialog_id = dialog_id;

return ff8_opcode_old_ramesw(unk);
Expand All @@ -888,27 +892,22 @@ int ff8_opcode_voice_ask(int unk)
byte idx = *(byte *)(unk + 388);

idx--; // Line of cancel option
idx--; // Line of default option
int default_option = *(DWORD *)(unk + 4 * idx--); // Line of default option
idx--; // Line of last option
idx--; // Line of first option
int dialog_id = *(DWORD *)(unk + 4 * idx--);
int window_id = *(DWORD *)(unk + 4 * idx);
ff8_win_obj *win = ff8_externals.windows + window_id;
int message_current_opcode = win->state;
char* field_name = get_current_field_name();
opcode_ask_current_option = win->current_choice_question;

bool _is_dialog_option_changed = (current_opcode_message_status[window_id].message_last_option != opcode_ask_current_option);

if (_is_dialog_option_changed)
{
if (trace_all || trace_opcodes) ffnx_trace("opcode[ASK]: field=%s,window_id=%u,dialog_id=%u,option_id=%u,char=%X\n", field_name, window_id, dialog_id, opcode_ask_current_option,current_opcode_message_status[window_id].char_id);
play_option(field_name, window_id, dialog_id, opcode_ask_current_option);
}

current_opcode_message_status[window_id].is_message_ask = true;
current_opcode_message_status[window_id].message_dialog_id = dialog_id;
current_opcode_message_status[window_id].message_last_option = opcode_ask_current_option;

if (opcode_ask_current_option == 0)
current_opcode_message_status[window_id].message_last_option = opcode_ask_current_option = default_option;
else
opcode_ask_current_option = win->current_choice_question;

return ff8_opcode_old_ask(unk);
}
Expand All @@ -920,27 +919,22 @@ int ff8_opcode_voice_aask(int unk)
idx--; // Y Position of window
idx--; // X position of window
idx--; // Line of cancel option
idx--; // Line of default option
int default_option = *(DWORD *)(unk + 4 * idx--); // Line of default option
idx--; // Line of last option
idx--; // Line of first option
int dialog_id = *(DWORD *)(unk + 4 * idx--);
int window_id = *(DWORD *)(unk + 4 * idx);
ff8_win_obj *win = ff8_externals.windows + window_id;
int message_current_opcode = win->state;
char* field_name = get_current_field_name();
opcode_ask_current_option = win->current_choice_question;

bool _is_dialog_option_changed = (current_opcode_message_status[window_id].message_last_option != opcode_ask_current_option);

if (_is_dialog_option_changed)
{
if (trace_all || trace_opcodes) ffnx_trace("opcode[ASK]: field=%s,window_id=%u,dialog_id=%u,option_id=%u,char=%X\n", field_name, window_id, dialog_id, opcode_ask_current_option,current_opcode_message_status[window_id].char_id);
play_option(field_name, window_id, dialog_id, opcode_ask_current_option);
}

current_opcode_message_status[window_id].is_message_ask = true;
current_opcode_message_status[window_id].message_dialog_id = dialog_id;
current_opcode_message_status[window_id].message_last_option = opcode_ask_current_option;

if (opcode_ask_current_option == 0)
current_opcode_message_status[window_id].message_last_option = opcode_ask_current_option = default_option;
else
opcode_ask_current_option = win->current_choice_question;

return ff8_opcode_old_aask(unk);
}
Expand All @@ -950,38 +944,47 @@ int ff8_show_dialog(int window_id, int state, int a3)
int dialog_id = current_opcode_message_status[window_id].message_dialog_id;
ff8_win_obj *win = ff8_externals.windows + window_id;
int message_current_opcode = win->state;
bool is_message_ask = current_opcode_message_status[window_id].is_message_ask;
char* field_name = get_current_field_name();

//ffnx_trace("ff8_show_dialog: field=%s,window_id=%u,dialog_id=%u,message_last_opcode=%u,message_current_opcode=%u,open_close_transition=%d\n", field_name, window_id, dialog_id, current_opcode_message_status[window_id].message_last_opcode, message_current_opcode, win->open_close_transition, win->field_1E);

bool _is_dialog_opening = is_dialog_opening(win->open_close_transition);
bool _is_dialog_starting = is_dialog_starting(current_opcode_message_status[window_id].message_last_transition, win->open_close_transition);
bool _is_dialog_paging = is_dialog_paging(current_opcode_message_status[window_id].message_last_opcode, message_current_opcode);
bool _is_dialog_closing = is_dialog_closing(current_opcode_message_status[window_id].message_last_transition, win->open_close_transition);
bool _is_dialog_closed = is_dialog_closed(current_opcode_message_status[window_id].message_last_transition, win->open_close_transition);
bool _is_dialog_option_changed = (current_opcode_message_status[window_id].message_last_option != opcode_ask_current_option);

if (_is_dialog_paging) current_opcode_message_status[window_id].message_page_count++;

if (_is_dialog_opening)
{
opcode_ask_current_option = 0;
begin_voice(window_id);
current_opcode_message_status[window_id].is_message_ask = is_message_ask;
current_opcode_message_status[window_id].message_dialog_id = dialog_id;
current_opcode_message_status[window_id].message_last_option = opcode_ask_current_option;
}
else if (_is_dialog_starting || _is_dialog_paging)
{
if (_is_dialog_starting) current_opcode_message_status[window_id].char_id = 0; // TODO
if (trace_all || trace_opcodes) ffnx_trace("opcode[MESSAGE]: field=%s,window_id=%u,dialog_id=%u,paging_id=%u,char=%X\n", field_name, window_id, dialog_id, current_opcode_message_status[window_id].message_page_count, current_opcode_message_status[window_id].char_id);
current_opcode_message_status[window_id].is_voice_acting = play_voice(field_name, window_id, current_opcode_message_status[window_id].message_dialog_id, current_opcode_message_status[window_id].message_page_count);
}
else if (_is_dialog_option_changed && is_message_ask)
{
if (trace_all || trace_opcodes) ffnx_trace("opcode[ASK]: field=%s,window_id=%u,dialog_id=%u,option_id=%u,char=%X\n", field_name, window_id, dialog_id, opcode_ask_current_option,current_opcode_message_status[window_id].char_id);
play_option(field_name, window_id, dialog_id, opcode_ask_current_option);
}
else if (_is_dialog_closing)
{
end_voice(window_id);
simulate_OK_disabled[window_id] = false;
current_opcode_message_status[window_id].is_voice_acting = false;
opcode_ask_current_option = 0;
}

// Auto close the message if it was voice acted and the audio file has finished playing
if (!current_opcode_message_status[window_id].is_message_ask)
if (!is_message_ask)
{
if (current_opcode_message_status[window_id].is_voice_acting && !nxAudioEngine.isVoicePlaying(window_id))
{
Expand All @@ -992,6 +995,7 @@ int ff8_show_dialog(int window_id, int state, int a3)

current_opcode_message_status[window_id].message_last_opcode = message_current_opcode;
current_opcode_message_status[window_id].message_last_transition = win->open_close_transition;
current_opcode_message_status[window_id].message_last_option = opcode_ask_current_option;

return ff8_externals.show_dialog(window_id, state, a3);
}
Expand Down

0 comments on commit 8c6d806

Please sign in to comment.