Optimizations in ProcessEvent and cheats. Ultrawide fix improvement.
This commit is contained in:
@@ -19,7 +19,6 @@ static int screenHeight = GetSystemMetrics(SM_CYSCREEN);
|
||||
static int maxScreeHeight = screenHeight;
|
||||
static float g_AspectRatio = (float)screenWidth / screenHeight;
|
||||
float g_BaseAspectRatio = 1.777778f;
|
||||
|
||||
// Plugin states
|
||||
static bool AOBScanDone = false;
|
||||
static bool g_Console = false;
|
||||
@@ -46,24 +45,20 @@ static float g_WorldTimeDilationValue = 1.f;
|
||||
static float g_AITimeDilationValue = 1.f;
|
||||
static bool user_inputs_logged = false;
|
||||
static bool bHasToModifyFOV = true;
|
||||
|
||||
// Shared values
|
||||
static float g_FOV_In = 80.f;
|
||||
static float g_CompensatedFOV = 80.f;
|
||||
static float g_FOV_Out = 80.f;
|
||||
static float g_Camera_In = 280.f;
|
||||
static float g_Camera_Out = 280.f;
|
||||
|
||||
// AOB Scan pointers
|
||||
static uint8_t* FOVaddress = nullptr;
|
||||
static uint8_t* HorPlusaddress = nullptr;
|
||||
static uint8_t* CameraComponentaddress = nullptr;
|
||||
static uint8_t* Cameraaddress = nullptr;
|
||||
static uint8_t* CutscenesFPSaddress1 = nullptr;
|
||||
static uint8_t* CutscenesFPSaddress2 = nullptr;
|
||||
static uint8_t* WorldTimedilationaddress = nullptr;
|
||||
static uint8_t* Timedilationaddress = nullptr;
|
||||
static uint8_t* CameraStructaddress = nullptr;
|
||||
|
||||
// Hooking
|
||||
static SafetyHookMid FOVHook{};
|
||||
static SafetyHookMid CameraHook{};
|
||||
@@ -72,7 +67,6 @@ static SafetyHookMid PEHook{};
|
||||
static SafetyHookMid WorldTimeDilationHook{};
|
||||
static SafetyHookMid TimeDilationHook{};
|
||||
static SafetyHookMid UltraWideHook{};
|
||||
|
||||
// Prototypes
|
||||
static void FOVFixEnabled();
|
||||
static void UltraWideFixEnabled();
|
||||
@@ -92,10 +86,9 @@ extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled, bool init) {
|
||||
if (!AOBScanDone) { // Unreal Engine 5.4.4
|
||||
logger->info("--------------- AOB scan started ---------------");
|
||||
constexpr auto CameraComponentStringObfuscated = make_obfuscated<0xF3>("EB ?? F3 0F ?? ?? ?? ?? ?? ?? F3 0F ?? ?? ?? 8B 83");
|
||||
constexpr auto FOVStringObfuscated = make_obfuscated<0xF3>("77 ?? 48 ?? ?? FF 90 ?? ?? ?? ?? F3 0F ?? ?? ?? 48 83 ?? ?? C3");
|
||||
constexpr auto CutscenesFPS1StringObfuscated = make_obfuscated<0x0F>("EB ?? 0F ?? ?? 48 8B ?? ?? ?? 0F 28 ?? ?? ?? 44 0F ?? ?? ?? ?? 44 0F");
|
||||
constexpr auto CutscenesFPS2StringObfuscated = make_obfuscated<0x0F>("0F 84 ?? ?? ?? ?? 48 8D ?? ?? ?? 48 89 ?? ?? ?? E8 ?? ?? ?? ?? 83 78");
|
||||
constexpr auto CameraStruct1StringObfuscated = make_obfuscated<0x48>("48 89 ?? ?? ?? 57 48 83 ?? ?? 0F ?? ?? 48 8B FA 48 ?? ?? 0F ?? ?? F2 0F 10");
|
||||
constexpr auto HORPlusStringObfuscated = make_obfuscated<0x97>("41 0F ?? ?? ?? ?? ?? ?? 48 8D ?? ?? ?? ?? ?? 4C ?? ?? 4D ?? ?? E8");
|
||||
constexpr auto CameraStringObfuscated = make_obfuscated<0x28>("F2 0F 10 ?? ?? ?? 0F 28 ?? ?? ?? ?? ?? F2 0F ?? ?? ?? F2 0F ?? ?? ?? 0F ?? ?? 0F");
|
||||
constexpr auto WorldTimeDilationStringObfuscated = make_obfuscated<0x59>("F3 0F 10 ?? ?? ?? ?? ?? F3 0F 59 ?? ?? ?? ?? ?? F3 0F 59 ?? ?? ?? ?? ?? C3");
|
||||
constexpr auto TimeDilationStringObfuscated = make_obfuscated<0x59>("F3 0F ?? ?? ?? EB ?? F3 0F ?? ?? ?? ?? ?? ?? 48 8B ?? ?? 4C ?? ?? F3 0F ?? ?? 44");
|
||||
@@ -105,10 +98,9 @@ extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled, bool init) {
|
||||
// Prepare all data for scanning
|
||||
std::vector<AOBScanEntry> signatures = {
|
||||
Make(&CameraComponentaddress, CameraComponentStringObfuscated, "Camera component"),
|
||||
Make(&FOVaddress, FOVStringObfuscated, "FOV"),
|
||||
Make(&HorPlusaddress, HORPlusStringObfuscated, "HOR +"),
|
||||
Make(&CutscenesFPSaddress1, CutscenesFPS1StringObfuscated, "FPS unlock"),
|
||||
Make(&CutscenesFPSaddress2, CutscenesFPS2StringObfuscated, "FPS unlock"),
|
||||
Make(&CameraStructaddress, CameraStruct1StringObfuscated, "Camera struct"),
|
||||
Make(&Cameraaddress, CameraStringObfuscated, "Camera"),
|
||||
Make(&WorldTimedilationaddress, WorldTimeDilationStringObfuscated, "World time dilation"),
|
||||
Make(&Timedilationaddress, TimeDilationStringObfuscated, "AI time dilation"),
|
||||
@@ -116,8 +108,8 @@ extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled, bool init) {
|
||||
// Scan all signature in a batch
|
||||
Memory::AOBScanBatch(signatures, logger);
|
||||
|
||||
if (FOVaddress && WorldTimedilationaddress && Timedilationaddress && CutscenesFPSaddress1 &&
|
||||
CutscenesFPSaddress2 && CameraComponentaddress && CameraStructaddress && Cameraaddress)
|
||||
if (WorldTimedilationaddress && Timedilationaddress && CutscenesFPSaddress1 &&
|
||||
CutscenesFPSaddress2 && CameraComponentaddress && HorPlusaddress && Cameraaddress)
|
||||
logger->info("All AOB signatures found. Ready to patch...");
|
||||
|
||||
if (!GObjectsaddress || !AppendStringaddress || !ProcessEventaddress) {
|
||||
@@ -150,9 +142,7 @@ extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled, bool init) {
|
||||
CutscenesFPSFixEnabled();
|
||||
CameraFixEnabled();
|
||||
HUDUpdate(true);
|
||||
gPendingDOF = true;
|
||||
gPendingCA = true;
|
||||
gPendingFog = true;
|
||||
SetAllEffectsToBeToggled();
|
||||
LogFixToggle(GameFixes::None, g_fix_enabled);
|
||||
}
|
||||
|
||||
@@ -215,13 +205,17 @@ static USizeBox* g_MainMenu = nullptr;
|
||||
static USizeBox* g_HUDBattle = nullptr;
|
||||
static USizeBox* g_merchantPanel = nullptr;
|
||||
static USizeBox* g_pauseMenu = nullptr;
|
||||
static ABP_jRPG_GM_Bootstrap_C* bootStrap = nullptr;
|
||||
static ULONGLONG lastScanTick = 0; // Last time tick was called
|
||||
static UC::int32 NAME_FindPlayerStart = -1;
|
||||
static void ProcessEvent() {
|
||||
if (!PEHook && ProcessEventaddress) {
|
||||
PEHook = safetyhook::create_mid(ProcessEventaddress + 0xc,
|
||||
[](SafetyHookContext& ctx) {
|
||||
static ABP_jRPG_GM_Bootstrap_C* bootStrap = nullptr;
|
||||
static ULONGLONG lastScanTick = 0; // Last time tick was called
|
||||
static UC::int32 NAME_FindPlayerStart = -1;
|
||||
static UC::int32 NAME_Construct = -1;
|
||||
static UC::int32 NAME_Destruct = -1;
|
||||
static UC::int32 NAME_Splash = -1;
|
||||
static bool splashResolved = false;
|
||||
UObject* object = (UObject*)ctx.rcx;
|
||||
UFunction* func = (UFunction*)ctx.rdx;
|
||||
|
||||
@@ -242,40 +236,45 @@ static void ProcessEvent() {
|
||||
if (!bootStrap && NAME_FindPlayerStart == comparisonIndex && object->IsA(ABP_jRPG_GM_Bootstrap_C::StaticClass()))
|
||||
bootStrap = static_cast<ABP_jRPG_GM_Bootstrap_C*>(object); // find bootstrap to skip disclaimers
|
||||
else if (object->IsA(UUserWidget::StaticClass())) {
|
||||
std::string funcName = func->GetName();
|
||||
std::string objectName = object->GetName();
|
||||
if (funcName == "Construct" || funcName == "Destruct" || funcName == "BP_OnActivated" || funcName == "BP_OnDeactivated") {
|
||||
auto HandleWidget = [&](auto* typedWidget, auto*& gWidgetPtr, bool forceModifyFOV = false) { // Lambda to initialize pointers on Construct and nullify them on Destruct
|
||||
if (funcName == "Construct") {
|
||||
|
||||
if (NAME_Construct == -1 && func->Name.ToString() == "Construct") NAME_Construct = func->Name.ComparisonIndex;
|
||||
if (NAME_Destruct == -1 && func->Name.ToString() == "Destruct") NAME_Destruct = func->Name.ComparisonIndex;
|
||||
if (!splashResolved) {
|
||||
std::string name = object->GetName();
|
||||
if (name.find("WBP_SplashScreen_Epilepsy_C") != std::string::npos) {
|
||||
NAME_Splash = object->Name.ComparisonIndex;
|
||||
splashResolved = true;
|
||||
}
|
||||
}
|
||||
if (NAME_Construct == comparisonIndex || NAME_Destruct == comparisonIndex) {
|
||||
auto HandleWidget = [&](auto* typedWidget, auto*& gWidgetPtr) { // Lambda to initialize pointers on Construct and nullify them on Destruct
|
||||
if (NAME_Construct == comparisonIndex) {
|
||||
if (typedWidget) gWidgetPtr = typedWidget;
|
||||
HUDUpdate(false);
|
||||
}
|
||||
else if (funcName == "Destruct") gWidgetPtr = nullptr;
|
||||
if (forceModifyFOV) { bHasToModifyFOV = true; return; }
|
||||
if (funcName == "BP_OnActivated") bHasToModifyFOV = false;
|
||||
if (funcName == "BP_OnDeactivated") bHasToModifyFOV = true;
|
||||
else if (NAME_Destruct == comparisonIndex) gWidgetPtr = nullptr;
|
||||
};
|
||||
|
||||
if (g_SkipIntros_enabled && funcName == "Construct" && bootStrap && objectName.rfind("WBP_SplashScreen_Epilepsy_C", 0) == 0)
|
||||
if (g_SkipIntros_enabled && NAME_Construct == comparisonIndex && bootStrap && NAME_Splash == object->Name.ComparisonIndex)
|
||||
bootStrap->LoadMainMenuLevel(); // Skip intros
|
||||
else if (object->IsA(UWBP_DialogNotifBox_C::StaticClass()))
|
||||
HandleWidget(static_cast<UUserWidget*>(object), g_PopupWidget);
|
||||
else if (object->IsA(UWBP_Exploration_HUD_C::StaticClass())) {
|
||||
HandleWidget(static_cast<UWBP_Exploration_HUD_C*>(object)->WBP_PromptContainer, g_PromptWidget, true);
|
||||
HandleWidget(static_cast<UWBP_Exploration_HUD_C*>(object), g_ExplorationHUDWidget, true);
|
||||
HandleWidget(static_cast<UWBP_Exploration_HUD_C*>(object)->WBP_PromptContainer, g_PromptWidget);
|
||||
HandleWidget(static_cast<UWBP_Exploration_HUD_C*>(object), g_ExplorationHUDWidget);
|
||||
}
|
||||
else if (object->IsA(UWBP_HUD_BattleScreen_C::StaticClass()))
|
||||
HandleWidget(static_cast<UWBP_HUD_BattleScreen_C*>(object)->WBP_WidescreenRatioBox->ConstrainSizeBox, g_HUDBattle, true);
|
||||
HandleWidget(static_cast<UWBP_HUD_BattleScreen_C*>(object)->WBP_WidescreenRatioBox->ConstrainSizeBox, g_HUDBattle);
|
||||
else if (object->IsA(UWBP_GameMenu_v3_C::StaticClass()))
|
||||
HandleWidget(static_cast<UWBP_GameMenu_v3_C*>(object)->WBP_WidescreenRatioBox->ConstrainSizeBox, g_gameMenu);
|
||||
else if (object->IsA(UWBP_GM_CharacterMenuContainer_C::StaticClass()))
|
||||
HandleWidget(static_cast<UWBP_GM_CharacterMenuContainer_C*>(object)->WBP_WidescreenRatioBox->ConstrainSizeBox, g_characterMenu, true);
|
||||
HandleWidget(static_cast<UWBP_GM_CharacterMenuContainer_C*>(object)->WBP_WidescreenRatioBox->ConstrainSizeBox, g_characterMenu);
|
||||
else if (object->IsA(UWBP_GM_MainMenuContainer_C::StaticClass()))
|
||||
HandleWidget(static_cast<UWBP_GM_MainMenuContainer_C*>(object)->WBP_WidescreenRatioBox->ConstrainSizeBox, g_MainMenu);
|
||||
else if (object->IsA(UWBP_Merchant_Panel_C::StaticClass()))
|
||||
HandleWidget(static_cast<UWBP_Merchant_Panel_C*>(object)->WBP_WidescreenRatioBox->ConstrainSizeBox, g_merchantPanel);
|
||||
else if (object->IsA(UWBP_PauseMenu_C::StaticClass()))
|
||||
HandleWidget(static_cast<UWBP_PauseMenu_C*>(object)->WBP_WidescreenRatioBox->ConstrainSizeBox, g_pauseMenu, true);
|
||||
HandleWidget(static_cast<UWBP_PauseMenu_C*>(object)->WBP_WidescreenRatioBox->ConstrainSizeBox, g_pauseMenu);
|
||||
else if (object->IsA(UWBP_CinematicTransition_C::StaticClass())) { // Remove aspect constrain from cinematics
|
||||
auto* cinematicTransition = static_cast<UWBP_CinematicTransition_C*>(object);
|
||||
if (g_ultrawide_fix_enabled && cinematicTransition) cinematicTransition->ScreenRatio = (double)g_AspectRatio;
|
||||
@@ -303,37 +302,27 @@ static void HUDUpdate(bool writeLog) {
|
||||
}
|
||||
|
||||
static void FOVFixEnabled() {
|
||||
if (FOVaddress) {
|
||||
if (!FOVHook) { // Hook only once
|
||||
FOVHook = safetyhook::create_mid(FOVaddress + 0x10,
|
||||
[](SafetyHookContext& ctx) {
|
||||
bool alterFOV = g_fix_enabled && g_fov_fix_enabled && bHasToModifyFOV;
|
||||
bool compensateFOV = g_fix_enabled && g_ultrawide_fix_enabled && bHasToModifyFOV;
|
||||
g_FOV_In = ctx.xmm0.f32[0];
|
||||
g_CompensatedFOV = ctx.xmm0.f32[0];
|
||||
if (compensateFOV)
|
||||
g_CompensatedFOV = ctx.xmm0.f32[0] = Maths::CompensateHorizontalFOV(g_FOV_In, g_BaseAspectRatio, g_AspectRatio);
|
||||
ctx.xmm0.f32[0] += (alterFOV ? g_AdditionalFOVValue : 0);
|
||||
g_FOV_Out = ctx.xmm0.f32[0];
|
||||
});
|
||||
}
|
||||
if (!CameraComponentaddress) return;
|
||||
if (!FOVHook) { // Hook only once
|
||||
FOVHook = safetyhook::create_mid(CameraComponentaddress + 0xa,
|
||||
[](SafetyHookContext& ctx) {
|
||||
g_FOV_In = ctx.xmm0.f32[0];
|
||||
g_CompensatedFOV = ctx.xmm0.f32[0];
|
||||
ctx.xmm0.f32[0] += g_fix_enabled && g_fov_fix_enabled ? g_AdditionalFOVValue : 0.f;
|
||||
g_FOV_Out = ctx.xmm0.f32[0];
|
||||
if (!ctx.rbx) return;
|
||||
if (auto cameraComponent = (UCameraComponent*)(ctx.rbx))
|
||||
if (g_fix_enabled && g_ultrawide_fix_enabled) cameraComponent->bConstrainAspectRatio = 0;
|
||||
});
|
||||
}
|
||||
logger->info("FOV fix {}", g_fix_enabled && g_fov_fix_enabled ? "enabled" : "disabled");
|
||||
}
|
||||
|
||||
static void UltraWideFixEnabled() {
|
||||
if (g_fix_enabled && g_ultrawide_fix_enabled && CameraComponentaddress && CameraStructaddress) { // Taken FROM UUU
|
||||
if (!UltraWideHook) { // Hook only once
|
||||
UltraWideHook = safetyhook::create_mid(CameraComponentaddress + 0x15,
|
||||
[](SafetyHookContext& ctx) {
|
||||
g_BaseAspectRatio = std::bit_cast<float>(static_cast<uint32_t>(ctx.rax)); // Retrieve in real time desired aspect ratio
|
||||
ctx.rax = std::bit_cast<uint32_t>(g_AspectRatio); // Force our aspect ratio
|
||||
});
|
||||
}
|
||||
Memory::PatchBytes(CameraComponentaddress + 0x1f, "\x31\xC9\x90", 3); // bConstrainAspectRatio = 0
|
||||
}
|
||||
if (!(g_fix_enabled && g_ultrawide_fix_enabled) && CameraComponentaddress && CameraStructaddress)
|
||||
Memory::RestoreBytes(CameraComponentaddress + 0x1f);
|
||||
if (!HorPlusaddress) return;
|
||||
if (g_fix_enabled && g_ultrawide_fix_enabled)
|
||||
Memory::PatchBytes(HorPlusaddress, "\x31\xD2\x90\x90\x90\x90\x90\x90", 8);
|
||||
else Memory::RestoreBytes(HorPlusaddress);
|
||||
|
||||
logger->info("Ultrawide fix {}", g_fix_enabled && g_ultrawide_fix_enabled ? "enabled" : "disabled");
|
||||
}
|
||||
@@ -403,14 +392,15 @@ static void EnableCheats(Cheat cheat) {
|
||||
UObject* object = (UObject*)ctx.rbx;
|
||||
if (!object || !object->Class) return;
|
||||
|
||||
auto* actor = static_cast<AActor*>(object);
|
||||
if (actor && actor->IsA(ABP_jRPG_Enemy_World_Base_Seamless_C::StaticClass()))
|
||||
actor->CustomTimeDilation = g_TimeDilation_fix_enabled ? g_AITimeDilationValue : 1.f;
|
||||
|
||||
auto* pawn = GetPawnFromObject(object);
|
||||
if (!pawn) return;
|
||||
ULONGLONG now = GetTickCount64();
|
||||
if (now - lastActorScanTick >= DEFAULT_ACTORS_SCAN_BETWEEN_TICKS) {
|
||||
auto* actor = static_cast<AActor*>(object);
|
||||
if (actor && actor->IsA(ABP_jRPG_Enemy_World_Base_Seamless_C::StaticClass()))
|
||||
actor->CustomTimeDilation = g_TimeDilation_fix_enabled ? g_AITimeDilationValue : 1.f;
|
||||
|
||||
auto* pawn = GetPawnFromObject(object);
|
||||
if (!pawn) return;
|
||||
|
||||
lastActorScanTick = now;
|
||||
if (pawn->IsA(ABP_jRPG_Character_Battle_Base_C::StaticClass())) {
|
||||
auto* playerBattle = static_cast<ABP_jRPG_Character_Battle_Base_C*>(pawn);
|
||||
|
||||
Reference in New Issue
Block a user