Skip to content

Commit

Permalink
FF8: Ability to use app_path config for the Steam version (julianxhok…
Browse files Browse the repository at this point in the history
…axhiu#714)

Additionally, fix music not starting on Worldmap with the original MIDIs and ff8_fps_limiter config != 0
  • Loading branch information
myst6re authored Aug 9, 2024
1 parent 535d4bb commit a7d0f11
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 41 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ foreach(FFNX_SHADER IN LISTS FFNX_SHADERS)
endforeach()
endforeach()

# List .gitkeep files to remove them on INSTALL
FILE(GLOB_RECURSE HEXT_GIT_KEEP_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/misc/ ${CMAKE_CURRENT_SOURCE_DIR}/misc/hext/ff8/**/.gitkeep)
LIST(TRANSFORM HEXT_GIT_KEEP_FILES PREPEND ${CMAKE_BINARY_DIR}/bin/)

# INSTALL
add_custom_command(
TARGET ${RELEASE_NAME}
Expand Down Expand Up @@ -278,6 +282,8 @@ add_custom_command(
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/misc/hext
${CMAKE_BINARY_DIR}/bin/hext
COMMAND ${CMAKE_COMMAND} -E rm ${HEXT_GIT_KEEP_FILES}

# ambient .toml
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/misc/${RELEASE_NAME}.ambient.toml
Expand Down
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
- SFX: Add missing support for audio effects to be stopped in time
- Speedhack: Fix support in field which were not getting the real speed up despite FFNx prompting it on screen.

# FF8 Steam

- Files: Fix `app_path` option support ( https://github.com/julianxhokaxhiu/FFNx/pull/714 )

# 1.19.1

Expand Down
5 changes: 3 additions & 2 deletions src/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2585,7 +2585,7 @@ time_t qpc_diff_time(time_t* t1, time_t* t2, time_t* out)

if (ff8) ret *= gamehacks.getCurrentSpeedhack();

if (out != NULL) *out = ret;
if (out != nullptr) *out = ret;

return ret;
}
Expand Down Expand Up @@ -2703,7 +2703,7 @@ uint32_t get_version()

void get_data_lang_path(PCHAR buffer)
{
strcpy(buffer, basedir);
strcpy(buffer, ff8 ? ff8_externals.app_path : basedir);
PathAppendA(buffer, R"(data\lang-)");
switch (version)
{
Expand Down Expand Up @@ -3282,6 +3282,7 @@ __declspec(dllexport) HANDLE __stdcall dotemuCreateFileA(LPCSTR lpFileName, DWOR

if (strstr(lpFileName, "DISK1") != NULL || strstr(lpFileName, "DISK2") != NULL || strstr(lpFileName, "DISK3") != NULL || strstr(lpFileName, "DISK4") != NULL)
{
PathAppendA(newPath, ff8_externals.app_path);
PathAppendA(newPath, R"(data\disk)");
PathAppendA(newPath, pos);

Expand Down
27 changes: 14 additions & 13 deletions src/ff7/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void ff7_use_analogue_controls(float analog_threshold)
float horizontalRotSpeed = 0.0f;
const float zoomSpeedMax = 1000.0f;
float zoomSpeed = 0.0f;

float invertedVerticalCameraScale = -1.0;
if(enable_inverted_vertical_camera_controls) invertedVerticalCameraScale = 1.0;

Expand Down Expand Up @@ -181,17 +181,17 @@ void ff7_use_analogue_controls(float analog_threshold)
else if(gamepad.leftStickY < -analog_threshold && !(gamepad.leftStickX < -analog_threshold || gamepad.leftStickX > analog_threshold))
inputDir = {0.0f, -1.0f, 0.0f};

if (gamepad.IsPressed(XINPUT_GAMEPAD_RIGHT_THUMB)
if (gamepad.IsPressed(XINPUT_GAMEPAD_RIGHT_THUMB)
&& std::abs(gamepad.rightStickX) < right_analog_stick_deadzone
&& std::abs(gamepad.rightStickY) < right_analog_stick_deadzone)
&& std::abs(gamepad.rightStickY) < right_analog_stick_deadzone)
{
if(!isCameraReset)
{
ff7::world::camera.requestResetCameraRotation(true);
ff7::battle::camera.reset();
isCameraReset = true;
}
} else
} else
{
isCameraReset = false;

Expand Down Expand Up @@ -246,28 +246,28 @@ void ff7_use_analogue_controls(float analog_threshold)
inputDir = {0.707f, -0.707f, 0.0f};
else if(joystick.GetState()->lY > joystick.GetDeadZone(analog_threshold) &&
!(joystick.GetState()->lX < joystick.GetDeadZone(-analog_threshold) || joystick.GetState()->lX > joystick.GetDeadZone(analog_threshold)))
inputDir = {0.0f, -1.0f, 0.0f};
inputDir = {0.0f, -1.0f, 0.0f};

if ((joystick.GetState()->rgbButtons[11] & 0x80)
if ((joystick.GetState()->rgbButtons[11] & 0x80)
&& std::abs(joystick.GetState()->lRz) < joystick.GetDeadZone(right_analog_stick_deadzone)
&& std::abs(joystick.GetState()->lZ) < joystick.GetDeadZone(right_analog_stick_deadzone))
&& std::abs(joystick.GetState()->lZ) < joystick.GetDeadZone(right_analog_stick_deadzone))
{
if(!isCameraReset)
{
ff7::world::camera.requestResetCameraRotation(true);
ff7::battle::camera.reset();
isCameraReset = true;
}
} else
{
} else
{
isCameraReset = false;

bx::Vec3 rightAnalogDir(
static_cast<float>(joystick.GetState()->lZ) / static_cast<float>(SHRT_MAX),
static_cast<float>(joystick.GetState()->lRz) / static_cast<float>(SHRT_MAX), 0.0f);
float length = std::min(bx::length(rightAnalogDir), 1.0f);
if(length > right_analog_stick_deadzone)
{
{
rightAnalogDir = bx::normalize(rightAnalogDir);
float scale = (length - right_analog_stick_deadzone) / (1.0 - right_analog_stick_deadzone);
rightAnalogDir.x *= scale;
Expand Down Expand Up @@ -340,7 +340,7 @@ struct ff7_gamepad_status* ff7_update_gamepad_status()
{
float analog_threshold = enable_auto_run ? left_analog_stick_deadzone + 0.25f * (1.0f - left_analog_stick_deadzone) : 0.5f;
float run_threshold = left_analog_stick_deadzone + 0.75f * (1.0f - left_analog_stick_deadzone);

// Reset
ZeroMemory(ff7_externals.gamepad_status, sizeof(ff7_gamepad_status));
gamepad_analogue_intent = INTENT_NONE;
Expand Down Expand Up @@ -420,7 +420,7 @@ struct ff7_gamepad_status* ff7_update_gamepad_status()
// Update the player intent based on the analogue movement
if (enable_auto_run)
{
bx::Vec3 joyDir = {static_cast<float>(joystick.GetState()->lX) / static_cast<float>(joystick.GetDeadZone(1.0f)),
bx::Vec3 joyDir = {static_cast<float>(joystick.GetState()->lX) / static_cast<float>(joystick.GetDeadZone(1.0f)),
static_cast<float>(joystick.GetState()->lY) / static_cast<float>(joystick.GetDeadZone(1.0f)), 0.0f};
auto joyLength = std::min(bx::length(joyDir), 1.0f);
if (joyLength > run_threshold) gamepad_analogue_intent = INTENT_RUN;
Expand Down Expand Up @@ -634,9 +634,10 @@ void ff7_limit_fps()
}

framerate *= gamehacks.getCurrentSpeedhack();
double frame_time = game_object->countspersecond / framerate;

do qpc_get_time(&gametime);
while ((gametime > last_gametime) && qpc_diff_time(&gametime, &last_gametime, NULL) < ((ff7_game_obj*)common_externals.get_game_object())->countspersecond / framerate);
while (gametime > last_gametime && qpc_diff_time(&gametime, &last_gametime, nullptr) < frame_time);

last_gametime = gametime;
}
Expand Down
1 change: 1 addition & 0 deletions src/ff8.h
Original file line number Diff line number Diff line change
Expand Up @@ -1507,6 +1507,7 @@ struct ff8_externals
uint32_t scan_text_data;
uint32_t scan_text_positions;
uint32_t fps_limiter;
double *time_volume_change_related_1A78BE0;
};

void ff8gl_field_78(struct ff8_polygon_set *polygon_set, struct ff8_game_obj *game_object);
Expand Down
1 change: 1 addition & 0 deletions src/ff8_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,7 @@ void ff8_find_externals()
ff8_externals.scan_text_data = get_absolute_value(ff8_externals.scan_get_text_sub_B687C0, 0x27);

ff8_externals.fps_limiter = get_relative_call(ff8_externals.field_main_loop, 0x261);
ff8_externals.time_volume_change_related_1A78BE0 = (double *)get_absolute_value(ff8_externals.fps_limiter, 0x3F);

// Required by Steam edition
switch (version)
Expand Down
21 changes: 5 additions & 16 deletions src/ff8_opengl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -905,21 +905,9 @@ int ff8_limit_fps()
struct ff8_game_obj *game_object = (ff8_game_obj *)common_externals.get_game_object();
struct game_mode *mode = getmode_cached();

switch(mode->driver_mode)
{
case MODE_FIELD:
if (ff8_externals.movie_object->movie_is_playing)
{
// Some movies do not expect to be frame limited
qpc_get_time(&last_gametime);
return 0;
}
break;
case MODE_GAMEOVER:
// Gameover screen has nothing to limit
qpc_get_time(&last_gametime);
return 0;
}
// For cross music play (vanilla music only)
qpc_get_time(&gametime);
*ff8_externals.time_volume_change_related_1A78BE0 = (1000.0 / game_object->countspersecond) * qpc_diff_time(&gametime, &last_gametime, nullptr);

if (ff8_fps_limiter < FPS_LIMITER_60FPS)
{
Expand Down Expand Up @@ -948,9 +936,10 @@ int ff8_limit_fps()
}

framerate *= gamehacks.getCurrentSpeedhack();
double frame_time = game_object->countspersecond / framerate;

do qpc_get_time(&gametime);
while ((gametime > last_gametime) && qpc_diff_time(&gametime, &last_gametime, NULL) < ((ff8_game_obj*)common_externals.get_game_object())->countspersecond / framerate);
while (gametime > last_gametime && qpc_diff_time(&gametime, &last_gametime, nullptr) < frame_time);

last_gametime = gametime;

Expand Down
11 changes: 3 additions & 8 deletions src/movies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,21 +196,16 @@ uint32_t ff8_movie_frames;

void ff8_prepare_movie(uint32_t disc, uint32_t movie)
{
char fmvName[260];
char camName[260];

char newFmvName[260];
char newCamName[260];

char fmvName[MAX_PATH], camName[MAX_PATH], newFmvName[MAX_PATH], newCamName[MAX_PATH];
uint32_t camOffset = 0;

// Unexpected cases default to current disk
if (disc >= 5u) {
disc = ff8_currentdisk - 1;
}

_snprintf(fmvName, sizeof(fmvName), "data/movies/disc%02i_%02ih.%s", disc, movie, ffmpeg_video_ext.c_str());
_snprintf(camName, sizeof(camName), "data/movies/disc%02i_%02i.cam", disc, movie);
_snprintf(fmvName, sizeof(fmvName), "%s/data/movies/disc%02i_%02ih.%s", ff8_externals.app_path, disc, movie, ffmpeg_video_ext.c_str());
_snprintf(camName, sizeof(camName), "%s/data/movies/disc%02i_%02i.cam", ff8_externals.app_path, disc, movie);

redirect_path_with_override(fmvName, newFmvName, sizeof(newFmvName));
redirect_path_with_override(camName, newCamName, sizeof(newCamName));
Expand Down
4 changes: 2 additions & 2 deletions src/sfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ void sfx_process_footstep(bool is_player_moving)
if (*ff7_externals.input_run_button_status != 0 || gamepad_analogue_intent == INTENT_RUN) pace = 0.30f;

qpc_get_time(&current_playback_time);
if (qpc_diff_time(&current_playback_time, &last_playback_time, NULL) >= ((ff7_game_obj*)common_externals.get_game_object())->countspersecond * pace)
if (qpc_diff_time(&current_playback_time, &last_playback_time, nullptr) >= ((ff7_game_obj*)common_externals.get_game_object())->countspersecond * pace)
{
if (use_external_sfx) ff7_sfx_play_layered(0.0f, 159, 7);
else common_externals.play_sfx(159);
Expand All @@ -686,7 +686,7 @@ void sfx_process_wm_footstep(int player_model_id, int player_walkmap_type)
pace = 0.5f;

qpc_get_time(&current_playback_time);
if (qpc_diff_time(&current_playback_time, &last_playback_time, NULL) >= ((ff7_game_obj*)common_externals.get_game_object())->countspersecond * pace)
if (qpc_diff_time(&current_playback_time, &last_playback_time, nullptr) >= ((ff7_game_obj*)common_externals.get_game_object())->countspersecond * pace)
{
char track_name[64];
if (use_external_sfx)
Expand Down

0 comments on commit a7d0f11

Please sign in to comment.