Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
238 changes: 200 additions & 38 deletions d3d9ex/AutoFix.cpp

Large diffs are not rendered by default.

34 changes: 26 additions & 8 deletions d3d9ex/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "XInputManager.h"

static const char* inifilename = "FF13Fix.ini";
#define CONFIG_VERSION 7
#define CONFIG_VERSION 8

class Config
{
Expand Down Expand Up @@ -57,6 +57,7 @@ class MainContext
void ApplyBehaviorFlagsFix(DWORD* flags);
HRESULT SetScissorRect(IDirect3DDevice9* pIDirect3DDevice9, CONST RECT* rect);
HRESULT CreateVertexBuffer(IDirect3DDevice9* pIDirect3DDevice9, UINT Length, DWORD Usage, DWORD FVF, D3DPOOL Pool, IDirect3DVertexBuffer9** ppVertexBuffer, HANDLE* pSharedHandle);
void HookPresent(IDirect3DSwapChain9** swapChain);
HRESULT DrawPrimitiveUP(IDirect3DDevice9* pIDirect3DDevice9, D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride);
bool BehaviorFlagsToString(DWORD BehaviorFlags, std::string* BehaviorFlagsString);

Expand All @@ -69,7 +70,6 @@ class MainContext

void OneTimeFix();
bool IsDXVK();

private:
enum class AutoFixes : u32
{
Expand All @@ -94,8 +94,6 @@ class MainContext
uint8_t* ff13_continuous_scan_instruction_address = NULL;
uint8_t* ff13_enemy_scan_box_code_address = NULL;
uint8_t** ff13_base_controller_input_address_ptr = NULL;
uint8_t* ff13_vibration_high_set_zero_address = NULL;
uint8_t* ff13_vibration_low_set_zero_address = NULL;
uint8_t* ff13_loading_screen_scissor_scaling_factor_1 = NULL;
uint8_t* ff13_loading_screen_scissor_scaling_factor_2 = NULL;
uint8_t* ff13_loading_screen_scissor_scaling_factor_3 = NULL;
Expand All @@ -109,17 +107,24 @@ class MainContext
uint8_t* ff13_message_box_call_address = NULL;
uint8_t* ff13_exe_large_address_aware_flag_address = NULL;
uint32_t* ff13_exe_checksum_address = NULL;
uint8_t* ff13_or_pressed_buttons_instruction_address = NULL;
uint8_t* ff13_set_eax_to_left_analog_pointer_instruction_address = NULL;
uint8_t* ff13_set_eax_to_right_analog_pointer_instruction_address = NULL;
uint32_t* ff13_internal_res_w;
uint32_t* ff13_internal_res_h;

uint8_t* FF13_2_SET_FRAME_RATE_INJECTED_CODE = NULL;
uint8_t* FF13_2_SET_PRESSED_BUTTONS_INJECTED_CODE = NULL;
uint8_t* FF13_2_SET_LEFT_ANALOG_INJECTED_CODE = NULL;
uint8_t* FF13_2_SET_RIGHT_ANALOG_INJECTED_CODE = NULL;
uint8_t* ff13_2_continuous_scan_instruction_address;
uint8_t* ff13_2_set_frame_rate_address;
uint8_t* ff13_2_pressed_buttons_instruction_jump_injected_address = NULL;
uint8_t* ff13_2_right_analog_instruction_jump_injected_address = NULL;
uint8_t* ff13_2_left_analog_instruction_jump_injected_address = NULL;
float** ff13_2_frame_pacer_ptr_address;
float ff13_2_targetFrameRate;
uint8_t** ff13_2_base_controller_input_address_ptr = NULL;
uint8_t* ff13_2_vibration_high_set_zero_address = NULL;
uint8_t* ff13_2_vibration_low_set_zero_address = NULL;
uint8_t* ff13_2_message_box_stack_push_address = NULL;
uint8_t* ff13_2_message_box_call_address = NULL;
uint32_t* ff13_2_internal_res_w;
Expand All @@ -139,6 +144,10 @@ class MainContext
-1.00f, -1.00f, 0.0f, 0.0f, 1.0f
};


uint32_t ff13ButtonsPressed = 0;
float ff13AnalogValues[8] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};

const float FF13_2_30_FPS = 30.0F;
const float FF13_2_MAX_FRAME_CAP = 1000.0F;

Expand All @@ -157,7 +166,6 @@ class MainContext
void PrintVersionInfo();

void FF13_InitializeGameAddresses();

void FF13_OneTimeFixes();
void FF13_PatchMessageBox();
void FF13_EnableControllerVibration();
Expand All @@ -166,14 +174,24 @@ class MainContext
void FF13_FixScissorRect();
void FF13_RemoveContinuousControllerScan();
void FF13_HandleLargeAddressAwarePatch();
void FF13_DisableInternalGamepadInput();

void FF13_2_CreateSetFrameRateCodeBlock();
void FF13_2_InitializeGameAddresses();
void FF13_2_RemoveContinuousControllerScan();
void FF13_2_AddHookIngameFrameRateLimitSetter();
void FF13_2_CreateSetPressedButtonsCodeBlock();
void FF13_2_CreateSetRightAnalogCodeBlock();
void FF13_2_CreateSetLeftAnalogCodeBlock();
void FF13_2_AddHookPressedButtons();
void FF13_2_AddSetLeftAnalogHook();
void FF13_2_AddSetRightAnalogHook();
void AddJumpHook(uint8_t* addrToAddJump, const uint8_t* codeBlockAddr, const int& numberOfNops);
void FF13_2_OneTimeFixes();
void FF13_2_PatchMessageBox();
void FF13_2_EnableControllerVibration();
void FF13_2_EnableXInputImplementation();

void CheckAndEnableXInputImplementation(uint8_t** inputAddress);

void AdjustVertexData(const uint32_t width, const uint32_t height);
bool MatchesExpectedVertexStream(const float* pVertexStreamZeroData);
Expand Down
46 changes: 46 additions & 0 deletions d3d9ex/IDirect3DSwapChain9Hook.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#define CINTERFACE
#include <d3d9.h>

#include "spdlog/spdlog.h"
#include "MinHook.h"
#include "XInputManager.h"

namespace cinterface
{
static XInputManager* pXInputManager;
static uint32_t* pff13ButtonPressed;
static float* pff13AnalogValues;

HRESULT(STDMETHODCALLTYPE* TruePresent)(IDirect3DSwapChain9* This, CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion, DWORD dwFlags) = nullptr;

HRESULT STDMETHODCALLTYPE HookPresent(IDirect3DSwapChain9* This, CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion, DWORD dwFlags)
{
HRESULT result = TruePresent(This, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags);
if (pXInputManager != NULL) {
pXInputManager->ReadValues(pff13ButtonPressed, pff13AnalogValues);
pXInputManager->SendVibrationToController();
}
return result;
}

void InitHookPresent(IDirect3DSwapChain9* pDirect3DSwapChain9)
{
if (pDirect3DSwapChain9->lpVtbl->Present && TruePresent == nullptr)
{
spdlog::info("Enabling PresentHook!");
const MH_STATUS createHookPresent = MH_CreateHook(pDirect3DSwapChain9->lpVtbl->Present, HookPresent, reinterpret_cast<void**>(&TruePresent));
spdlog::info("CreateHookPresent= {}", createHookPresent);
const MH_STATUS enableHookPresent = MH_EnableHook(pDirect3DSwapChain9->lpVtbl->Present);
spdlog::info("EnableHookPresent = {}", enableHookPresent);

}
}

void ShareValuesWithSwapChainHook(XInputManager* xInputManager, uint32_t* ff13ButtonPressed, float* ff13AnalogValues) {
pXInputManager = xInputManager;
pff13ButtonPressed = ff13ButtonPressed;
pff13AnalogValues = ff13AnalogValues;
}
}


15 changes: 9 additions & 6 deletions d3d9ex/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,19 @@ SETTING(bool, BoolValue, DisableIngameControllerHotSwapping, FFXIII, true,
L"# DisableIngameControllerHotSwapping\n"
L"#\n"
L"# By default FF13Fix disables the game's continuous controller scanning that causes stuttering (especially if you do not have any controller connected)\n"
L"# If you with you can enable it again (by setting the config to 'false', so you can re-connect your controller while playing.\n"
L"# Note that EnableControllerVibration is incompatible with the controller hotswapping, \n"
L"# so it is automatically disabled if DisableIngameControllerHotSwapping is set to 'false'"
L"# Note that if you are using the FF13Fix XInput implementation, this setting is forced 'true', as hotswapping will work anyway even if the internal game scanning logic is disabled (FF13Fix will use its on hotswapping logic)"
);
SETTING(bool, BoolValue, EnableControllerVibration, FFXIII, true,
SETTING(bool, BoolValue, Enable, FFXIII_XInput, true,
L"# Replace the internal game controller input logic by FF13Fix XInput implementation\n"
L"#\n"
L"# Controller hotswapping/vibration works without impacting game performance."
);
SETTING(bool, BoolValue, EnableControllerVibration, FFXIII_XInput, true,
L"# EnableControllerVibration\n"
L"#\n"
L"# Enables controller vibration on the first connected XInput device."
L"# Enables controller vibration."
);
SETTING(bool, DoubleValue, VibrationStrengthFactor, FFXIII, 2.0,
SETTING(bool, DoubleValue, VibrationStrengthFactor, FFXIII_XInput, 1.0,
L"# VibrationStrengthFactor\n"
L"#\n"
L"# Higher numbers = stronger vibration"
Expand Down
Loading