Add character camera height. Improved FOV control
This commit is contained in:
@@ -3,12 +3,13 @@
|
||||
#include <spdlog/sinks/rotating_file_sink.h>
|
||||
#include <filesystem>
|
||||
#include <safetyhook.hpp>
|
||||
#include "ObfuscateString.h"
|
||||
#include "Memory.hpp";
|
||||
#include "Maths.hpp";
|
||||
#include "UEngine.hpp";
|
||||
#include "SDK/Basic.hpp"
|
||||
#include "SDK/Engine_classes.hpp"
|
||||
#include "ObfuscateString.h"
|
||||
#include "SDK/Charlie_classes.hpp"
|
||||
|
||||
using namespace SDK;
|
||||
|
||||
@@ -18,6 +19,7 @@ const std::string PLUGIN_LOG = PLUGIN_NAME + ".log";
|
||||
const std::string gameExecutable = "HellIsUs-Win64-Shipping.exe";
|
||||
const float baseAspect = 1.777777791;
|
||||
const float PDA_FOV = 21; // FOV must not be modified when switching to PDA to keep reading possible
|
||||
const float WORLD_FOV = 70.f;
|
||||
|
||||
// Logger
|
||||
std::shared_ptr<spdlog::logger> logger;
|
||||
@@ -36,9 +38,10 @@ static bool g_DOF_fix_enabled = false;
|
||||
static bool g_CA_fix_enabled = false;
|
||||
static bool g_Vignetting_fix_enabled = false;
|
||||
static bool g_Fog_fix_enabled = false;
|
||||
static bool g_Camera_distance_fix_enabled = false;
|
||||
static bool g_Camera_fix_enabled = false;
|
||||
static int g_AdditionalFOVValue = 0;
|
||||
static float g_cameraDistanceMultiplier = 1.f;
|
||||
static float g_cameraHeight = -15.f;
|
||||
|
||||
// Shared values
|
||||
static float g_FOV_In = 0;
|
||||
@@ -54,28 +57,34 @@ static uint8_t* ProcessEventaddress = nullptr;
|
||||
|
||||
// AOB Scan pointers
|
||||
static uint8_t* FOVaddress = nullptr;
|
||||
static uint8_t* FOVOtheraddress = nullptr;
|
||||
static uint8_t* Aspectaddress = nullptr;
|
||||
static uint8_t* DOFaddress = nullptr;
|
||||
static uint8_t* CAaddress = nullptr;
|
||||
static uint8_t* Vignettingaddress = nullptr;
|
||||
static uint8_t* Fogaddress = nullptr;
|
||||
static uint8_t* CameraDistanceaddress = nullptr;
|
||||
static uint8_t* Cameraaddress = nullptr;
|
||||
|
||||
// Hooking
|
||||
static SafetyHookMid FOVHook{};
|
||||
static SafetyHookMid AspectHook{};
|
||||
static SafetyHookMid FogHook{};
|
||||
static SafetyHookMid CameraDistanceHook{};
|
||||
static SafetyHookMid CameraHook{};
|
||||
|
||||
// Prototypes
|
||||
// Camera Mode
|
||||
enum class ECharlieCameraMode : uint8_t
|
||||
{
|
||||
Camera = 1,
|
||||
FOV = 2
|
||||
};
|
||||
|
||||
// Prototypes
|
||||
static void FOVFixEnabled(bool fix_enabled);
|
||||
static void AspectFixEnabled(bool fix_enabled);
|
||||
static void DOFFixEnabled(bool fix_enabled);
|
||||
static void CAFixEnabled(bool fix_enabled);
|
||||
static void VignettingFixEnabled(bool fix_enabled);
|
||||
static void FogFixEnabled(bool fix_enabled);
|
||||
static void CameraDistanceFixEnabled(bool fix_enabled);
|
||||
static void CameraFixEnabled(bool fix_enabled, ECharlieCameraMode Mode);
|
||||
static void EnableConsole();
|
||||
|
||||
extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled)
|
||||
@@ -86,11 +95,11 @@ extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled)
|
||||
if (FOVaddress == nullptr) {
|
||||
constexpr auto FOVStringObfuscated = make_obfuscated<0x4A>("77 ?? 48 ?? ?? FF ?? ?? ?? ?? ?? F3 0F ?? ?? ?? 48");
|
||||
FOVaddress = Memory::AOBScan(gameExecutable, FOVStringObfuscated.decrypt(), PAGE_EXECUTE_READ);
|
||||
//"HellIsUs-Win64-Shipping.exe" + 3C8E924 - 48 8B 01 - mov rax, [rcx]
|
||||
//"HellIsUs-Win64-Shipping.exe" + 3C8E927 - FF 90 60 07 00 00 - call qword ptr[rax + 00000760]
|
||||
//"HellIsUs-Win64-Shipping.exe" + 3C8E92D - F3 0F 10 40 30 - movss xmm0, [rax + 30]
|
||||
//"HellIsUs-Win64-Shipping.exe" + 3C8E932 - 48 83 C4 28 - add rsp, 28
|
||||
//"HellIsUs-Win64-Shipping.exe" + 3C8E936 - C3 - ret
|
||||
//"HellIsUs-Win64-Shipping.exe" + 3C92144 - 48 8B 01 - mov rax, [rcx]
|
||||
//"HellIsUs-Win64-Shipping.exe" + 3C92147 - FF 90 60 07 00 00 - call qword ptr[rax + 00000760]
|
||||
//"HellIsUs-Win64-Shipping.exe" + 3C9214D - F3 0F 10 40 30 - movss xmm0, [rax + 30]
|
||||
//"HellIsUs-Win64-Shipping.exe" + 3C92152 - 48 83 C4 28 - add rsp, 28
|
||||
//"HellIsUs-Win64-Shipping.exe" + 3C92156 - C3 - ret
|
||||
|
||||
if (!FOVaddress)
|
||||
logger->warn("FOV signature not found. Maybe your game has been updated and is no more compatible with this plugin.");
|
||||
@@ -186,23 +195,23 @@ extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled)
|
||||
}
|
||||
}
|
||||
|
||||
if (CameraDistanceaddress == nullptr) {
|
||||
if (Cameraaddress == nullptr) {
|
||||
constexpr auto FogStringObfuscated = make_obfuscated<0x4A>("28 C3 48 83 ?? ?? 48 8B ?? ?? ?? ?? ?? 48 8B ?? 48 85 ?? 75");
|
||||
CameraDistanceaddress = Memory::AOBScan(gameExecutable, FogStringObfuscated.decrypt(), PAGE_EXECUTE_READ);
|
||||
Cameraaddress = Memory::AOBScan(gameExecutable, FogStringObfuscated.decrypt(), PAGE_EXECUTE_READ);
|
||||
//"HellIsUs-Win64-Shipping.exe" + 4E9D3F2 - 48 85 C0 - test rax, rax
|
||||
//"HellIsUs-Win64-Shipping.exe" + 4E9D3F5 - 74 0A - je "HellIsUs-Win64-Shipping.exe" + 4E9D401
|
||||
//"HellIsUs-Win64-Shipping.exe" + 4E9D3F7 - F3 0F 10 40 4C - movss xmm0, [rax + 4C]
|
||||
//"HellIsUs-Win64-Shipping.exe" + 4E9D3FC - 48 83 C4 28 - add rsp, 28
|
||||
//"HellIsUs-Win64-Shipping.exe" + 4E9D400 - C3 - ret
|
||||
|
||||
if (!CameraDistanceaddress)
|
||||
logger->warn("Camera distance signature not found. Maybe your game has been updated and is no more compatible with this plugin.");
|
||||
if (!Cameraaddress)
|
||||
logger->warn("Camera signature not found. Maybe your game has been updated and is no more compatible with this plugin.");
|
||||
else {
|
||||
logger->info("Camera distance signature found at address: 0x{:X}.", reinterpret_cast<uintptr_t>(CameraDistanceaddress));
|
||||
logger->info("Camera signature found at address: 0x{:X}.", reinterpret_cast<uintptr_t>(Cameraaddress));
|
||||
}
|
||||
}
|
||||
|
||||
if (FOVaddress && FOVOtheraddress && Aspectaddress && DOFaddress && CAaddress && Vignettingaddress && Fogaddress) {
|
||||
if (FOVaddress && Aspectaddress && DOFaddress && CAaddress && Vignettingaddress && Fogaddress && Cameraaddress) {
|
||||
logger->info("All AOB signatures found. Ready to patch...");
|
||||
AOBScanDone = true;
|
||||
}
|
||||
@@ -259,31 +268,33 @@ extern "C" __declspec(dllexport) void SetFixEnabled(bool enabled)
|
||||
logger->info("-------------- Fixes initialisation -------------");
|
||||
}
|
||||
if (g_fix_enabled) {
|
||||
if (FOVaddress) FOVFixEnabled(g_fov_fix_enabled || g_aspect_fix_enabled);
|
||||
if (FOVaddress) CameraFixEnabled(g_fov_fix_enabled, ECharlieCameraMode::FOV);
|
||||
if (Aspectaddress) AspectFixEnabled(g_aspect_fix_enabled);
|
||||
if (DOFaddress) DOFFixEnabled(g_DOF_fix_enabled);
|
||||
if (CAaddress) CAFixEnabled(g_CA_fix_enabled);
|
||||
if (Vignettingaddress) VignettingFixEnabled(g_Vignetting_fix_enabled);
|
||||
if (Fogaddress) FogFixEnabled(g_Fog_fix_enabled);
|
||||
if (CameraDistanceaddress) CameraDistanceFixEnabled(g_Camera_distance_fix_enabled);
|
||||
if (Cameraaddress) CameraFixEnabled(g_Camera_fix_enabled, ECharlieCameraMode::Camera);
|
||||
}
|
||||
else {
|
||||
if (FOVaddress) FOVFixEnabled(false);
|
||||
if (FOVaddress) CameraFixEnabled(false, ECharlieCameraMode::FOV);
|
||||
if (Aspectaddress) AspectFixEnabled(false);
|
||||
if (DOFaddress) DOFFixEnabled(false);
|
||||
if (CAaddress) CAFixEnabled(false);
|
||||
if (Vignettingaddress) VignettingFixEnabled(false);
|
||||
if (Fogaddress) FogFixEnabled(false);
|
||||
if (CameraDistanceaddress) CameraDistanceFixEnabled(false);
|
||||
if (Cameraaddress) CameraFixEnabled(false, ECharlieCameraMode::Camera);
|
||||
logger->info("All fixes disabled.");
|
||||
}
|
||||
if (!g_Console_Enabled && GObjectsaddress && GNamesaddress && AppendStringaddress && ProcessEventaddress)
|
||||
EnableConsole();
|
||||
}
|
||||
|
||||
// Setters for Reshade addon call
|
||||
extern "C" __declspec(dllexport) void SetFOVFixEnabled(bool enabled, bool init)
|
||||
{
|
||||
g_fov_fix_enabled = enabled;
|
||||
if (!init) FOVFixEnabled(g_fov_fix_enabled || g_aspect_fix_enabled);
|
||||
if (!init) CameraFixEnabled(g_fov_fix_enabled, ECharlieCameraMode::FOV);
|
||||
}
|
||||
|
||||
extern "C" __declspec(dllexport) void SetAspectRatioFixEnabled(bool enabled, bool init)
|
||||
@@ -316,10 +327,10 @@ extern "C" __declspec(dllexport) void SetFogFixEnabled(bool enabled, bool init)
|
||||
if (!init) FogFixEnabled(g_Fog_fix_enabled);
|
||||
}
|
||||
|
||||
extern "C" __declspec(dllexport) void SetCameraDistanceFixEnabled(bool enabled, bool init)
|
||||
extern "C" __declspec(dllexport) void SetCameraFixEnabled(bool enabled, bool init)
|
||||
{
|
||||
g_Camera_distance_fix_enabled = enabled;
|
||||
if (!init) CameraDistanceFixEnabled(g_Camera_distance_fix_enabled);
|
||||
g_Camera_fix_enabled = enabled;
|
||||
if (!init) CameraFixEnabled(g_Camera_fix_enabled, ECharlieCameraMode::Camera);
|
||||
}
|
||||
|
||||
extern "C" __declspec(dllexport) void SetFOV(int fov)
|
||||
@@ -332,11 +343,16 @@ extern "C" __declspec(dllexport) void SetCameraDistance(float cameraDistance)
|
||||
g_cameraDistanceMultiplier = cameraDistance;
|
||||
}
|
||||
|
||||
extern "C" __declspec(dllexport) void SetConsole()
|
||||
extern "C" __declspec(dllexport) void SetCameraHeight(int cameraHeight)
|
||||
{
|
||||
EnableConsole();
|
||||
g_cameraHeight = (float)cameraHeight;
|
||||
}
|
||||
|
||||
//extern "C" __declspec(dllexport) void SetConsole()
|
||||
//{
|
||||
// EnableConsole();
|
||||
//}
|
||||
|
||||
// Getters for Reshade addon call
|
||||
extern "C" __declspec(dllexport) float GetFOVIn() {
|
||||
return g_FOV_In;
|
||||
@@ -355,6 +371,7 @@ extern "C" __declspec(dllexport) bool GetConsoleEnabled() {
|
||||
}
|
||||
|
||||
// Code injection functions
|
||||
// FOV compensation only
|
||||
static void FOVFixEnabled(bool fix_enabled) {
|
||||
if (g_fix_enabled && fix_enabled && FOVaddress != nullptr) {
|
||||
if (!FOVHook) { // Hook only once
|
||||
@@ -365,18 +382,13 @@ static void FOVFixEnabled(bool fix_enabled) {
|
||||
g_Compensated_FOV = ctx.xmm0.f32[0] = Maths::CompensateHorizontalFOV(g_FOV_In, baseAspect, aspectRatio);
|
||||
else
|
||||
g_Compensated_FOV = ctx.xmm0.f32[0];
|
||||
if (g_FOV_In != PDA_FOV)
|
||||
g_FOV_Out = ctx.xmm0.f32[0] += (g_fov_fix_enabled ? g_AdditionalFOVValue : 0);
|
||||
else g_FOV_Out = ctx.xmm0.f32[0];
|
||||
g_FOV_Out = ctx.xmm0.f32[0];
|
||||
});
|
||||
}
|
||||
else FOVHook.enable();
|
||||
logger->info("FOV fix enabled");
|
||||
}
|
||||
if (!fix_enabled) {
|
||||
if (!fix_enabled && FOVHook)
|
||||
if (FOVHook) FOVHook.disable();
|
||||
logger->info("FOV fix disabled");
|
||||
}
|
||||
}
|
||||
|
||||
static void AspectFixEnabled(bool fix_enabled) {
|
||||
@@ -388,10 +400,12 @@ static void AspectFixEnabled(bool fix_enabled) {
|
||||
});
|
||||
}
|
||||
else AspectHook.enable();
|
||||
FOVFixEnabled(true);
|
||||
logger->info("Aspect fix enabled");
|
||||
}
|
||||
if (!fix_enabled) {
|
||||
if (AspectHook) AspectHook.disable();
|
||||
if (FOVHook && !g_fov_fix_enabled) FOVHook.disable();
|
||||
logger->info("Aspect ratio fix disabled");
|
||||
}
|
||||
}
|
||||
@@ -442,19 +456,30 @@ static void FogFixEnabled(bool fix_enabled) {
|
||||
}
|
||||
}
|
||||
|
||||
static void CameraDistanceFixEnabled(bool fix_enabled) {
|
||||
if (g_fix_enabled && fix_enabled && CameraDistanceaddress) {
|
||||
if (!CameraDistanceHook) { // Hook only once +0x4e or start to test +0x13
|
||||
CameraDistanceHook = safetyhook::create_mid(CameraDistanceaddress + 0x4e,
|
||||
static void CameraFixEnabled(bool fix_enabled, ECharlieCameraMode mode) {
|
||||
if (g_fix_enabled && fix_enabled && Cameraaddress) {
|
||||
if (!CameraHook) { // Hook only once +0x4e or start to test +0x13
|
||||
CameraHook = safetyhook::create_mid(Cameraaddress + 0x4e,
|
||||
[](SafetyHookContext& ctx) {
|
||||
ctx.xmm0.f32[0] *= g_cameraDistanceMultiplier;
|
||||
ctx.xmm0.f32[0] *= (g_Camera_fix_enabled ? g_cameraDistanceMultiplier : 1.f);
|
||||
// Retrieve player camera object
|
||||
auto* charlieCameraBaseConfig = reinterpret_cast<UCharlieCameraBaseConfig*>(ctx.rax);
|
||||
if (charlieCameraBaseConfig && charlieCameraBaseConfig->IsA(UCharlieCameraBaseConfig::StaticClass())) {
|
||||
// Camera height
|
||||
charlieCameraBaseConfig->DefaultHeightFromPlayer = (g_Camera_fix_enabled ? g_cameraHeight : -15.f);
|
||||
// World FOV
|
||||
charlieCameraBaseConfig->FieldOfView = (g_fov_fix_enabled ? WORLD_FOV + g_AdditionalFOVValue : WORLD_FOV);
|
||||
}
|
||||
});
|
||||
}
|
||||
logger->info("CameraDistance fix enabled");
|
||||
}
|
||||
if (!fix_enabled && CameraDistanceaddress) {
|
||||
if (CameraDistanceHook) CameraDistanceHook.disable();
|
||||
logger->info("Camera distance fix disabled");
|
||||
if (mode == ECharlieCameraMode::Camera) {
|
||||
if (g_Camera_fix_enabled) logger->info("Camera fix enabled");
|
||||
else logger->info("Camera fix disabled");
|
||||
}
|
||||
if (mode == ECharlieCameraMode::FOV) {
|
||||
if (g_fov_fix_enabled) logger->info("FOV fix enabled");
|
||||
else logger->info("FOV fix disabled");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user