Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

er fps patch #62

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0590c82
Initial FPS patch
Vinjul1704 Aug 23, 2024
c8bbdaf
Fix FPS patch + renaming/commenting
Vinjul1704 Aug 24, 2024
8f77549
Simple bool to control FPS patches
Vinjul1704 Aug 24, 2024
2e1965e
Fix int types
Vinjul1704 Aug 24, 2024
245da6f
merge main
FrankvdStam Aug 24, 2024
1ced3d0
Disable FPS patch by default
Vinjul1704 Aug 24, 2024
ae5ac05
Auto toggle FPS patch every 10 seconds for testing
Vinjul1704 Aug 24, 2024
f4b789a
Merge branch 'main' into feature/ER-fps-patch
FrankvdStam Aug 25, 2024
88c8228
Fix a couple warnings about paranthesis in if statements
FrankvdStam Aug 25, 2024
3b32318
Small cleanup. Move ER hook functions out of the init function.
FrankvdStam Aug 25, 2024
ea01696
Remove leftover date var
Vinjul1704 Aug 26, 2024
2faef61
Add version comparison and pre-/post-DLC check.
Vinjul1704 Aug 26, 2024
8e4bbb8
Fix warning in version.rs, implement FPS custom limit patch and fully…
Vinjul1704 Aug 26, 2024
d0ded19
Fix frame delta history offsets.
Vinjul1704 Aug 26, 2024
671fc73
Add basic FPS patch toggle to UI. Needs improvement.
Vinjul1704 Aug 26, 2024
79d2e73
Fix FPS history patch AoB
Vinjul1704 Aug 26, 2024
7afc9e0
Replace FPS patch enable/disable/toggle functions with get/set functions
Vinjul1704 Aug 27, 2024
2d462ce
Add FPS limit get/set functions.
Vinjul1704 Aug 27, 2024
67a16fa
Fix FPS patch hotkey in CLI, now that the functions are different.
Vinjul1704 Aug 27, 2024
27df1e6
Test stuff and hotkeys, minor fix in eldenring.rs, increase rust func…
Vinjul1704 Aug 31, 2024
801ae62
reuse allocated bool
FrankvdStam Aug 31, 2024
8dfae5b
Re-enable FPS patch hooks.
Vinjul1704 Sep 1, 2024
352f45c
Re-use float for fps limit.
Vinjul1704 Sep 1, 2024
d88f905
Cleanup.
Vinjul1704 Sep 1, 2024
0b15fd9
Test hotkeys for the FPS limit.
Vinjul1704 Sep 1, 2024
51639d5
Flip "hotkeysCreated" check to align with the name.
Vinjul1704 Sep 1, 2024
db3be7d
Remove old inject delay workaround
Vinjul1704 Sep 1, 2024
33cda2e
Fix crash when restarting the game while keeping livesplit open.
Vinjul1704 Sep 28, 2024
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
29 changes: 27 additions & 2 deletions src/SoulMemory/EldenRing/EldenRing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

Check warning on line 20 in src/SoulMemory/EldenRing/EldenRing.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant using directive

Using directive is not required by the code and can be safely removed
using SoulMemory.Memory;
using SoulMemory.Native;
using Pointer = SoulMemory.Memory.Pointer;
Expand All @@ -40,7 +41,7 @@
private long _positionOffset;
private long _mapIdOffset;
private long _playerInsOffset;

private Dictionary<string, long> _exportedFunctions;

#region Refresh/init/reset ================================================================================================
public Process GetProcess() => _process;
Expand Down Expand Up @@ -157,7 +158,8 @@
_igt.Clear();
return Result.Err(new RefreshError(RefreshErrorReason.UnknownException, "soulmods injection failed"));
}


_exportedFunctions = _process.GetModuleExportedFunctions("soulmods.dll");
return Result.Ok();
}
catch (Exception e)
Expand Down Expand Up @@ -577,5 +579,28 @@
}

#endregion

#region soulmods

public void FpsPatchDisable()
{
var address = _exportedFunctions["fps_patch_disable"];
_process.Execute((IntPtr)address);
}

public void FpsPatchEnable()
{
var address = _exportedFunctions["fps_patch_enable"];
_process.Execute((IntPtr)address);
}

public void FpsPatchToggle()
{
var address = _exportedFunctions["fps_patch_toggle"];
var ptr = (IntPtr)address;

Check warning on line 600 in src/SoulMemory/EldenRing/EldenRing.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Unused local variable

Local variable 'ptr' is never used
_process.Execute((IntPtr)address);
}

#endregion
}
}
10 changes: 5 additions & 5 deletions src/SoulMemory/Native/Kernel32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@



public static List<(string name, long address)> GetModuleExportedFunctions(this Process process, string hModuleName)
public static Dictionary<string, long> GetModuleExportedFunctions(this Process process, string hModuleName)
{
var modules = process.GetModulesViaSnapshot();
var module = modules.First(i => i.szModule.ToLowerInvariant() == hModuleName.ToLowerInvariant());
Expand Down Expand Up @@ -362,12 +362,12 @@
var ordinalTable = module.modBaseAddr.ToInt64() + exportTable.AddressOfNameOrdinals;
var functionOffsetTable = module.modBaseAddr.ToInt64() + exportTable.AddressOfFunctions;

var functions = new List<(string name, long address)>();
var functions = new Dictionary<string, long>();
for (var i = 0; i < exportTable.NumberOfNames; i++)
{
var EAT = module.modBaseAddr.ToInt64() + exportTable.AddressOfFunctions;
var eat = module.modBaseAddr.ToInt64() + exportTable.AddressOfFunctions;

var EATPtr = (IntPtr)EAT;
var eatPtr = (IntPtr)eat;

Check warning on line 370 in src/SoulMemory/Native/Kernel32.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Unused local variable

Local variable 'eatPtr' is never used

//Function name offset is an array of 4byte numbers
var functionNameOffset = process.ReadMemory<uint>(nameOffsetTable + i * sizeof(uint)).Unwrap();
Expand All @@ -380,7 +380,7 @@
var functionOffset = process.ReadMemory<uint>(functionOffsetTable + i * sizeof(uint)).Unwrap();
var functionAddress = module.modBaseAddr.ToInt64() + functionOffset;

functions.Add((functionName, functionAddress));
functions.Add(functionName, functionAddress);
}

return functions;
Expand Down
7 changes: 4 additions & 3 deletions src/SoulMemory/soulmods/Soulmods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

Check warning on line 21 in src/SoulMemory/soulmods/Soulmods.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant using directive

Using directive is not required by the code and can be safely removed
using System.Runtime.InteropServices;
using SoulMemory.Native;

Expand Down Expand Up @@ -75,14 +75,15 @@



private static List<(string name, long address)> _soulmodsMethods;
private static Dictionary<string, long> _soulmodsMethods;
public static TSized RustCall<TSized>(this Process process, string function, TSized? parameter = null) where TSized : struct
{
if (_soulmodsMethods == null)
{
_soulmodsMethods = process.GetModuleExportedFunctions("soulmods.dll");
}
var functionPtr = _soulmodsMethods.First(i => i.name == function).address;

var functionPtr = _soulmodsMethods[function];

var buffer = process.Allocate(Marshal.SizeOf<TSized>());
if (parameter.HasValue)
Expand All @@ -100,7 +101,7 @@
{
//Get function address
var soulmods = process.GetModuleExportedFunctions("soulmods.dll");
var func = soulmods.First(i => i.name == "GetQueuedDarkSouls2MorphemeMessages").address;
var func = soulmods["GetQueuedDarkSouls2MorphemeMessages"];

//Get buffer size
var buffer = process.Allocate(4);
Expand Down
1 change: 1 addition & 0 deletions src/SoulSplitter/SoulComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
using System.Reflection;
using System.Windows.Forms;
using SoulSplitter.Migrations;
using SoulMemory.Native;

Check warning on line 35 in src/SoulSplitter/SoulComponent.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant using directive

Using directive is not required by the code and can be safely removed

namespace SoulSplitter
{
Expand Down Expand Up @@ -107,7 +108,7 @@
});
}

private void SetBitBlt()

Check warning on line 111 in src/SoulSplitter/SoulComponent.cs

View workflow job for this annotation

GitHub Actions / build

Remove the unused private method 'SetBitBlt'. (https://rules.sonarsource.com/csharp/RSPEC-1144)
{
if (_game is SoulMemory.Sekiro.Sekiro sekiro)
{
Expand Down
14 changes: 11 additions & 3 deletions src/cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,21 @@ internal class Program
[STAThread]
static void Main(string[] args)
{
GlobalHotKey.RegisterHotKey(ModifierKeys.Alt, Key.A, () =>{ Debug.WriteLine("A"); });
GlobalHotKey.RegisterHotKey(ModifierKeys.Alt, Key.S, () =>{ Debug.WriteLine("S"); });
GlobalHotKey.RegisterHotKey(ModifierKeys.Alt, Key.D, () =>{ Debug.WriteLine("D"); });
//GlobalHotKey.RegisterHotKey(ModifierKeys.Alt, Key.A, () =>{ Debug.WriteLine("A"); });
//GlobalHotKey.RegisterHotKey(ModifierKeys.Alt, Key.S, () =>{ Debug.WriteLine("S"); });
//GlobalHotKey.RegisterHotKey(ModifierKeys.Alt, Key.D, () =>{ Debug.WriteLine("D"); });

//TestUi();

bool init = true;
GameLoop<EldenRing>((e) =>
{
if (init)
{
GlobalHotKey.RegisterHotKey(ModifierKeys.Alt, Key.A, e.FpsPatchToggle);
init = false;
}

var igtElapsed = TimeSpan.FromMilliseconds(e.GetInGameTimeMilliseconds());
Console.WriteLine($"IGT: {igtElapsed}");
});
Expand Down
Loading
Loading