Skip to content

Commit

Permalink
Elden ring versions are now retrieved via file properties. Fixed a ca…
Browse files Browse the repository at this point in the history
…che problem, process name is not unique enough to cache the data to pattern scan.
  • Loading branch information
FrankvdStam committed Mar 22, 2022
1 parent 90269ac commit 3decf90
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 78 deletions.
Binary file modified Components/SoulMemory.dll
Binary file not shown.
Binary file modified Components/SoulSplitter.dll
Binary file not shown.
10 changes: 10 additions & 0 deletions Components/Updates.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<updates>
<update version="0.0.14">
<files>
<file path="Components/SoulMemory.dll" status="changed" />
<file path="Components/SoulSplitter.dll" status="changed" />
</files>
<changelog>
<change>Fixed a bug where the game's version was incorrectly detected on the Japanese version</change>
<change>Fixed a bug where when running mixed versions of the game, a cache problem would lead to a crash</change>
</changelog>
</update>
<update version="0.0.13">
<files>
<file path="Components/SoulMemory.dll" status="changed" />
Expand Down
140 changes: 80 additions & 60 deletions src/SoulMemory/EldenRing/EldenRing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Runtime.Remoting.Channels;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using SoulMemory.DarkSouls1.Internal;
using SoulMemory.Memory;
Expand All @@ -17,38 +18,70 @@ public class EldenRing : ITimeable
public Exception Exception;

private Process _process = null;


private Pointer _igt;
private Pointer _playerIns;
private Pointer _playerChrPhysicsModule;
private Pointer _menuManIns;


private long _screenStateOffset;
private long _blackScreenOffset;

public EldenRing()
{
Refresh();
}


private bool InitPointers()

private bool Init()
{
try
{
//Arrange version specific offsets
if (!Version.TryParse(_process.MainModule.FileVersionInfo.ProductVersion, out Version v))
{
Exception = new Exception("Failed to determine game version");
return false;
}

var version = GetVersion(v);
switch (version)
{
default:
case EldenRingVersion.Unknown:
_screenStateOffset = 0x728;
_blackScreenOffset = 0x72c;
break;

case EldenRingVersion.V102:
_screenStateOffset = 0x718;
_blackScreenOffset = 0x71c;
break;

case EldenRingVersion.V103:
_screenStateOffset = 0x728;
_blackScreenOffset = 0x72c;
break;
}

//FD4Time
_process.ScanPatternRelative("48 8b 05 ? ? ? ? 4c 8b 40 08 4d 85 c0 74 0d 45 0f b6 80 be 00 00 00 e9 13 00 00 00", 3, 7)
.CreatePointer(out _igt, 0, 0xa0);

//WorldChrManImp
_process.ScanPatternRelative("48 8b 05 ? ? ? ? 48 89 98 70 84 01 00 4c 89 ab 74 06 00 00 4c 89 ab 7c 06 00 00 44 88 ab 84 06 00 00 41 83 7f 4c 00", 3, 7)
.CreatePointer(out _playerIns, 0, 0x18468)
.CreatePointer(out _playerChrPhysicsModule, 0, 0x18468, 0xf68);
.CreatePointer(out _playerChrPhysicsModule, 0, 0x18468, 0xF68);

//CSMenuManIns
_process.ScanPatternRelative("48 8b 0d ? ? ? ? 48 8b 53 08 48 8b 92 d8 00 00 00 48 83 c4 20 5b", 3, 7)
.CreatePointer(out _menuManIns, 0);

//GameMan 48 8b 15 . . . . 41 b0 01 48 8b 0d . . . . 48 81 c2 10 0e 00 00

if (!ApplyIgtFix())
{
Exception = new Exception("MIGT code injection failed");
return false;
}

return true;
Expand All @@ -59,12 +92,41 @@ private bool InitPointers()
return false;
}
}


public enum EldenRingVersion
{
V102,
V103,
Unknown,
};

public static EldenRingVersion GetVersion(Version v)
{
switch (v.Major)
{
default:
return EldenRingVersion.Unknown;

case 1:
switch (v.Minor)
{
default:
return EldenRingVersion.Unknown;

case 2:
return EldenRingVersion.V102;
case 3:
return EldenRingVersion.V103;
}
}
}


private void ResetPointers()
{
_igt = null;
_playerIns = null;
_playerChrPhysicsModule = null;
_menuManIns = null;
}

Expand Down Expand Up @@ -95,67 +157,20 @@ public float GetAngle()
}
return 0f;
}

public enum EldenRingVersion
{
v102,
v103,
unknown,
};

public EldenRingVersion GetVersion()
{
if (_process != null)
{
switch (_process.MainModule.ModuleMemorySize)
{
default:
return EldenRingVersion.v102;

case 92119040: //1.03
case 92141568: //1.03.1
return EldenRingVersion.v103;
}
}
return EldenRingVersion.unknown;
}

/// <summary>
/// Returns the screen state. Will falsely report InGame when the game is starting up.
/// </summary>
/// <returns></returns>

public ScreenState GetScreenState()
{
if (_menuManIns != null)
var screenState = _menuManIns?.ReadInt32(_screenStateOffset) ?? (int)ScreenState.Unknown;
if (screenState.TryParseEnum(out ScreenState s))
{
var version = GetVersion();
var offset = 0x728;

if(version == EldenRingVersion.v102)
{
offset = 0x718;
}

var screenState = _menuManIns.ReadInt32(offset);
if (screenState.TryParseEnum(out ScreenState s))
{
return s;
}
return s;
}
return ScreenState.Unknown;
}

private bool NoCutsceneOrBlackscreen()
{
var version = GetVersion();
var offset = 0x72c;

if (version == EldenRingVersion.v102)
{
offset = 0x71c;
}

var flag = _menuManIns?.ReadInt32(offset);
var flag = _menuManIns?.ReadInt32(_blackScreenOffset);
return flag.HasValue && flag.Value == 16;
}

Expand All @@ -169,7 +184,7 @@ public bool Refresh()

if (_process != null)
{
if (InitPointers())
if (Init())
{
_pointersInitialized = true;
return true;
Expand Down Expand Up @@ -205,6 +220,11 @@ public bool Refresh()
}
}

public int GetTestValue()
{
return _menuManIns?.ReadInt32(_blackScreenOffset) ?? 0;
}

public bool Attached => _process != null;

#region Timeable
Expand Down
2 changes: 1 addition & 1 deletion src/SoulMemory/Memory/PatternScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static class PatternScanner
private static Dictionary<string, byte[]> _memoryCache = new Dictionary<string, byte[]>();
private static byte[] GetCodeMemory(Process p)
{
var name = p.ProcessName;
var name = p.ProcessName + p.MainModule.FileName + p.MainModule.FileVersionInfo.ProductVersion + p.MainModule.ModuleMemorySize;
byte[] buffer;

if (!_memoryCache.TryGetValue(name, out buffer))
Expand Down
4 changes: 3 additions & 1 deletion src/SoulMemory/Memory/Pointer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public override string ToString()
#region Read/write memory

private byte[] ReadMemory(long? offset, int length)
{
{
int bytesRead = 0;
byte[] buffer = new byte[length];

Expand Down Expand Up @@ -202,6 +202,8 @@ public void WriteBytes(long? offset, byte[] value)
WriteMemory(offset, value);
}

public void WriteFloat(float value) => WriteFloat(null, value);

public void WriteFloat(long? offset, float value)
{
WriteMemory(offset, BitConverter.GetBytes(value));
Expand Down
4 changes: 2 additions & 2 deletions src/SoulMemory/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.0.13")]
[assembly: AssemblyFileVersion("0.0.13")]
[assembly: AssemblyVersion("0.0.14")]
[assembly: AssemblyFileVersion("0.0.14")]
4 changes: 2 additions & 2 deletions src/SoulSplitter/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.0.13")]
[assembly: AssemblyFileVersion("0.0.13")]
[assembly: AssemblyVersion("0.0.14")]
[assembly: AssemblyFileVersion("0.0.14")]
2 changes: 1 addition & 1 deletion src/SoulSplitter/VersionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ namespace SoulSplitter
{
internal static class VersionHelper
{
public static Version Version => new Version(0, 0, 13);
public static Version Version => new Version(0, 0, 14);
}
}
28 changes: 17 additions & 11 deletions src/cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,37 @@ internal class Program
[STAThread]
static void Main(string[] args)
{

//Testy2();
var er = new EldenRing();

for (;;)
{
Console.Clear();
Console.WriteLine(er.GetScreenState());
Thread.Sleep(50);

Console.WriteLine(er.GetTestValue());

Thread.Sleep(100);
er.Refresh();
}
}


private static void Testy2()
{
var er = new DarkSouls3();
var er = new DarkSouls1();
er.Refresh();

for (; ; )
{
//Console.Clear();
Console.WriteLine(er.IsInGame() + " " + er.GetInGameTimeMilliseconds());
Thread.Sleep(10);
var isKill = er.IsBossDefeated(BossType.AsylumDemon);

er.Refresh();
}

//for (; ; )
//{
// //Console.Clear();
// Console.WriteLine(er.IsInGame() + " " + er.GetInGameTimeMilliseconds());
// Thread.Sleep(10);
//
// er.Refresh();
//}
}


Expand Down

0 comments on commit 3decf90

Please sign in to comment.