Skip to content

Instantly share code, notes, and snippets.

@j4cksw
Created May 30, 2020 22:31
Show Gist options
  • Select an option

  • Save j4cksw/7e64300e0ed46dbab2c0d8dc57643c1e to your computer and use it in GitHub Desktop.

Select an option

Save j4cksw/7e64300e0ed46dbab2c0d8dc57643c1e to your computer and use it in GitHub Desktop.
RE4 Ultra wide fix
require(GlobalDependencys:GetDependency("StandardBase"):GetPackageName())
--GAME VARS
fAdditionalFOV = 0
fDefaultEngineAspectRatio = 1.777777791
fDefaultAspectRatio = 1.333333373
fDefaultEngineWidthScale = 1280.0
fDefaultEngineHeightScale = 720.0
fDefaultEngineTextWidthScale = 512.0
fDefaultEngineTextHeightScale = 384.0
fDefaultEngineMenuWidthScale = 640.0
fDefaultEngineMenuHeightScale = 360.0
fDefaultEngineUnknown = 0.026666666
fFOVScale = 0.11805
fNewAspectRatio = 0
fNewEngineWidthScale = 0
fNewEngineHeightScale = 0
fNewEngineTextWidthScale = 0
fNewEngineTextHeightScale = 0
fNewEngineAspectRatio = 0
--ControlVars
bFixEnabled = true
bAspectRatio = true
bFOVFix = true
bHUDScaling = true
--PROCESS VARS
Process_FriendlyName = Module:GetFriendlyName()
Process_WindowName = "Resident Evil 4"
Process_ClassName = "RE4HDWnd"
Process_EXEName = "*"
--INJECTION BEHAVIOUR
InjectDelay = 250
WriteInterval = 100
SearchInterval = 50
SuspendThread = true
--Name Manual/Auto/Hybrid Steam/Origin/Any IncludeFile:Configure;Enable;Periodic;Disable;
SupportedVersions = {
{"Automatically Detect", "Hybrid", "Any", "Configure_SignatureScan;Enable_Inject;Periodic;Disable_Inject;"},
}
function Init_Controls()
DefaultControls.AddHeader("Header_FixesEnableDisable","Individual Fixes",245,70,210,17)
DefaultControls.AddFixToggle("CKAspectRatio_Enable","Aspect Ratio","CKAspectRatio_Changed",255,120,180,14)
DefaultControls.AddFixToggle("CKFOVFix_Enable","FOVFix","CKFOVFix_Changed",255,139,180,14)
DefaultControls.AddHeader("Header_FOV","FOV Fine adjustment",15,70,210,17)
DefaultControls.AddFOVSlider("FOVSlider","FOVSlider_Changed",55,100,125,35 )
end
function Configure_SignatureScan()
local tAddress = HackTool:AddAddress("FOVFix")
if HackTool:SignatureScan("DC ?? D9 ?? DE ?? D9 ?? D9 ?? ?? ?? ?? ?? D9 ?? ?? ?? ?? ?? DE",tAddress,PAGE_EXECUTE_READ,0xE,Process_EXEName) == 0 then
return ErrorOccurred(string.format(SigScanError,tAddress:GetName()))
else
print( tAddress:GetInfo(TYPE_ADDRESS) )
end
local tAddress = HackTool:AddAddress("EngineScale")
if HackTool:SignatureScan("DB 05 ?? ?? ?? ?? 85 ?? 79 ?? D8 05 ?? ?? ?? ?? DC 35 ?? ?? ?? ?? 8B",tAddress,PAGE_EXECUTE_READ,0x10,Process_EXEName) == 0 then
return ErrorOccurred(string.format(SigScanError,tAddress:GetName()))
else
tAddress:AcquireAddress(0x2)
print( tAddress:GetInfo(TYPE_ADDRESS) )
print( tAddress:AddSubOffset("Width",SIZE_DOUBLE*0):GetInfo(TYPE_DOUBLE) )
print( tAddress:AddSubOffset("Height",SIZE_DOUBLE*2):GetInfo(TYPE_DOUBLE) )
tAddress["Width"]:SetAutoUnprotect(true)
tAddress["Height"]:SetAutoUnprotect(true)
end
local tAddress = HackTool:AddAddress("AspectRatio")
if HackTool:SignatureScan("D9 5C ?? ?? C7 45 ?? ?? ?? ?? ?? D9 05 ?? ?? ?? ?? C7 45 ?? ?? ?? ?? ?? D9 5C ?? ?? C7",tAddress,PAGE_EXECUTE_READ,0xB,Process_EXEName) == 0 then
return ErrorOccurred(string.format(SigScanError,tAddress:GetName()))
else
print( tAddress:GetInfo(TYPE_ADDRESS) )
tAddress:AcquireAddress(0x2)
print( tAddress:GetInfo(TYPE_FLOAT) )
end
HUDScaleCount = HackTool:SignatureScanMulti("D95C????D95C????D905????????D95C????D905????????D95C????D905????????D95C????D905????????","tHUDScale",PAGE_EXECUTE_READ,0x8,Process_EXEName)
if HUDScaleCount == 0 then
return ErrorOccurred("Could not find HUD scale injection point, " .. Process_FriendlyName ..
" may have updated to a version that is no longer supported.\r\n\r\n" ..
"Try selecting a different version and re-enable the fix." )
end
return true
end
function Enable_Inject()
local Variables = HackTool:AllocateMemory("Variables",0)
Variables:PushFloat("FOV_Scale")
Variables:PushFloat("FOV_Additional")
Variables:Allocate()
ResolutionChanged()
local asm = [[
(codecave:jmp)FOVFix,FOVFix_cc:
%originalcode%
fld dword ptr [(allocation)Variables->FOV_Additional]
fld dword ptr [(allocation)Variables->FOV_Scale]
fmulp
faddp
jmp %returnaddress%
%end%
]]
if HackTool:CompileAssembly(asm,"Fixes") == nil then
return ErrorOccurred("Assembly compilation failed...")
else
Toggle_CodeCave("FOVFix_cc",bFOVFix)
end
end
function Periodic()
local AspectRatio = HackTool:GetAddress("AspectRatio")
if AspectRatio and bAspectRatio then
AspectRatio:WriteFloat(fNewAspectRatio)
else
AspectRatio:WriteFloat(fDefaultAspectRatio)
end
local EngineScale = HackTool:GetAddress("EngineScale")
if EngineScale and bHUDScaling then
EngineScale["Width"]:WriteDouble(fNewEngineWidthScale)
--EngineScale["Height"]:WriteDouble(fNewEngineHeightScale)
else
EngineScale["Width"]:WriteDouble(fDefaultEngineWidthScale)
--EngineScale["Height"]:WriteDouble(fDefaultEngineHeightScale)
end
if bFOVFix then
local Variables = HackTool:GetAllocation("Variables")
if Variables and Variables["FOV_Scale"] then
Variables["FOV_Additional"]:WriteFloat(fAdditionalFOV)
PluginViewport:AppendStatusMessage( string.format("\r\n (FOVFix) Additional FOV=%.2f",fAdditionalFOV) )
end
end
if bAspectRatio then
PluginViewport:AppendStatusMessage( string.format("\r\n (AspectRatio) AspectRatio=%.2f", fNewAspectRatio ))
end
end
function Disable_Inject()
Restore()
CleanUp()
end
function ResolutionChanged()
local DisplayGrid = nil
if DisplayInfo then
DisplayGrid = DisplayInfo:GetGridSize()
if DisplayGrid then
fNewAspectRatio = DisplayInfo:GetAspectRatio() / fDefaultAspectRatio
fNewEngineAspectRatio = (DisplayInfo:GetAspectRatio() / fDefaultEngineAspectRatio)
fNewEngineWidthScale = fNewEngineAspectRatio * fDefaultEngineWidthScale--DisplayGrid.GridXCoord * fDefaultEngineWidthScale
--fNewEngineHeightScale = DisplayGrid.GridYCoord * fDefaultEngineHeightScale
end
end
local Variables = HackTool:GetAllocation("Variables")
if Variables and Variables["FOV_Scale"] then
Variables["FOV_Scale"]:WriteFloat(fFOVScale)
end
end
function CKFOVFix_Changed(Sender)
bFOVFix = Toggle_CheckFix(Sender)
Toggle_CodeCave("FOVFix_cc",bFOVFix)
ForceUpdate()
end
function CKAspectRatio_Changed(Sender)
bAspectRatio = Toggle_CheckFix(Sender)
ForceUpdate()
end
function Restore()
local AspectRatio = HackTool:GetAddress("AspectRatio")
if AspectRatio then
AspectRatio:WriteFloat(fDefaultAspectRatio)
end
local EngineScale = HackTool:GetAddress("EngineScale")
if EngineScale then
EngineScale["Width"]:WriteDouble(fDefaultEngineWidthScale)
--EngineScale["Height"]:WriteDouble(fDefaultEngineHeightScale)
end
end
function HK_IncreaseFOV()
FOVSlider:OffsetPosition(1)
end
function HK_DecreaseFOV()
FOVSlider:OffsetPosition(-1)
end
function FOVSlider_Changed(Sender)
fAdditionalFOV = Sender:GetScaledFloat(2)
lblFOVSlider.Caption:SetCaption( string.format("Value: %.2f",fAdditionalFOV) )
ForceUpdate()
end
function Init()
Init_BaseControls()
Init_Controls()
end
function DeInit()
DisableFix()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment