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

change delivery of injectable dll's #73

Merged
merged 16 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 20 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ jobs:
name: build
runs-on: windows-latest
steps:

#clone, setup dotnet, restore packages
- name: Checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -64,18 +63,32 @@ jobs:
copy src\SoulSplitter\bin\x64\Release\net481\SoulMemory.dll artifact
copy src\SoulSplitter\bin\x64\Release\net481\MaterialDesignColors.dll artifact
copy src\SoulSplitter\bin\x64\Release\net481\MaterialDesignThemes.Wpf.dll artifact
copy src\SoulMemory\soulmods\x86\soulmods.dll artifact\soulmods_x86.dll
copy src\SoulMemory\soulmods\x64\soulmods.dll artifact\soulmods_x64.dll
copy src\SoulSplitter\soulmemory-rs\x86\soulmemory_rs.dll artifact\soulmemory_rs_x86.dll
copy src\SoulSplitter\soulmemory-rs\x64\soulmemory_rs.dll artifact\soulmemory_rs_x64.dll
copy src\SoulSplitter\soulmemory-rs\x86\launcher.exe artifact\launcher_x86.dll
copy src\SoulSplitter\soulmemory-rs\x64\launcher.exe artifact\launcher_x64.dll
copy src\SoulSplitter\bin\x64\Release\net481\soulmods_x86.dll artifact
copy src\SoulSplitter\bin\x64\Release\net481\soulmods_x64.dll artifact
copy src\SoulSplitter\bin\x64\Release\net481\soulmemory_rs_x86.dll artifact
copy src\SoulSplitter\bin\x64\Release\net481\soulmemory_rs_x64.dll artifact
copy src\SoulSplitter\bin\x64\Release\net481\launcher_x86.exe artifact
copy src\SoulSplitter\bin\x64\Release\net481\launcher_x64.exe artifact
copy LICENSE artifact
copy src\SoulMemory\bin\x64\Release\*.nupkg artifact
copy src\CliTimer\bin\x64\release\net481\CliTimer.exe artifact\CliTimer
copy src\CliTimer\bin\x64\release\net481\CliTimer.exe.config artifact\CliTimer
copy src\CliTimer\bin\x64\release\net481\SoulMemory.dll artifact\CliTimer

- name: sign artifacts
run: |
$bytes = [Convert]::FromBase64String("${{SECRETS.CERT_PFX_BASE64}}")
[IO.File]::WriteAllBytes("SoulSplitter.pfx", $bytes)
$signtool = "C:\Program Files (x86)\Microsoft SDKs\ClickOnce\SignTool\signtool.exe"
& $signtool sign /fd sha256 /f SoulSplitter.pfx /d "SoulSplitter" /t http://timestamp.digicert.com "artifact\SoulSplitter.dll"
& $signtool sign /fd sha256 /f SoulSplitter.pfx /d "SoulSplitter" /t http://timestamp.digicert.com "artifact\SoulMemory.dll"
& $signtool sign /fd sha256 /f SoulSplitter.pfx /d "SoulSplitter" /t http://timestamp.digicert.com "artifact\soulmods_x86.dll"
& $signtool sign /fd sha256 /f SoulSplitter.pfx /d "SoulSplitter" /t http://timestamp.digicert.com "artifact\soulmods_x64.dll"
& $signtool sign /fd sha256 /f SoulSplitter.pfx /d "SoulSplitter" /t http://timestamp.digicert.com "artifact\soulmemory_rs_x86.dll"
& $signtool sign /fd sha256 /f SoulSplitter.pfx /d "SoulSplitter" /t http://timestamp.digicert.com "artifact\soulmemory_rs_x64.dll"
& $signtool sign /fd sha256 /f SoulSplitter.pfx /d "SoulSplitter" /t http://timestamp.digicert.com "artifact\launcher_x86.exe"
& $signtool sign /fd sha256 /f SoulSplitter.pfx /d "SoulSplitter" /t http://timestamp.digicert.com "artifact\launcher_x64.exe"

- name: Publish SoulSplitter
uses: actions/upload-artifact@v4
with:
Expand Down
Binary file added Components/launcher_x64.exe
Binary file not shown.
Binary file added Components/launcher_x86.exe
Binary file not shown.
Binary file added Components/soulmemory_rs_x64.dll
Binary file not shown.
Binary file added Components/soulmemory_rs_x86.dll
Binary file not shown.
Binary file added Components/soulmods_x64.dll
Binary file not shown.
Binary file added Components/soulmods_x86.dll
Binary file not shown.
6 changes: 6 additions & 0 deletions SoulSplitter.sln
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Components", "Components", "{622B105C-C5BF-49B3-BEBD-FC5845B27CA0}"
ProjectSection(SolutionItems) = preProject
Components\launcher_x64.exe = Components\launcher_x64.exe
Components\launcher_x86.exe = Components\launcher_x86.exe
Components\MaterialDesignColors.dll = Components\MaterialDesignColors.dll
Components\MaterialDesignThemes.Wpf.dll = Components\MaterialDesignThemes.Wpf.dll
Components\MaterialDesignThemes.Wpf.xml = Components\MaterialDesignThemes.Wpf.xml
Components\SoulMemory.dll = Components\SoulMemory.dll
Components\soulmemory_rs_x64.dll = Components\soulmemory_rs_x64.dll
Components\soulmemory_rs_x86.dll = Components\soulmemory_rs_x86.dll
Components\soulmods_x64.dll = Components\soulmods_x64.dll
Components\soulmods_x86.dll = Components\soulmods_x86.dll
Components\SoulSplitter.dll = Components\SoulSplitter.dll
Components\Updates.xml = Components\Updates.xml
EndProjectSection
Expand Down
2 changes: 2 additions & 0 deletions SoulSplitter.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Dectus/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Deeproot/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Demi/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=dllpath/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Draconic/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Dragonbarrow/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Dragonkin/@EntryIndexedValue">True</s:Boolean>
Expand Down Expand Up @@ -202,6 +203,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Ornstein/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Penisula/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Placidusax/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=processname/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=PTDE/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Pumpkinhead/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Quelaag/@EntryIndexedValue">True</s:Boolean>
Expand Down
21 changes: 10 additions & 11 deletions src/SoulMemory/SoulMemory.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
<PackageIcon>soulsplitter.png</PackageIcon>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<OutDir>..\..\..\LiveSplit\LiveSplit\bin\Debug\Components\</OutDir>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<NoWarn>1701;1702;NU5100</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<NoWarn>1701;1702;NU5100</NoWarn>
</PropertyGroup>
<ItemGroup>
<SonarQubeSetting Include="sonar.cpd.exclusions">
Expand All @@ -42,16 +43,18 @@
<EmbeddedResource Remove="resources\**" />
<None Remove="resources\**" />
</ItemGroup>
<ItemGroup>
<None Remove="soulmods\x64\soulmods.dll" />
<None Remove="soulmods\x86\soulmods.dll" />
</ItemGroup>
<ItemGroup>
<Content Include="soulsplitter.ico" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="soulmods\x64\soulmods.dll" />
<EmbeddedResource Include="soulmods\x86\soulmods.dll" />
<ContentWithTargetPath Include="soulmods\x64\soulmods.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<TargetPath>soulmods_x64.dll</TargetPath>
</ContentWithTargetPath>
<ContentWithTargetPath Include="soulmods\x86\soulmods.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<TargetPath>soulmods_x86.dll</TargetPath>
</ContentWithTargetPath>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
Expand All @@ -72,10 +75,6 @@
<PackagePath>\</PackagePath>
</None>
</ItemGroup>
<ItemGroup>
<Folder Include="soulmods\x64\" />
<Folder Include="soulmods\x86\" />
</ItemGroup>

<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<CallTarget Targets="CargoRelease" Condition="'$(Configuration)'=='Release'" />
Expand Down
19 changes: 10 additions & 9 deletions src/SoulMemory/soulmods/Soulmods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,24 @@

public static class Soulmods
{


public static bool Inject(Process process)
{
var basePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "soulsplitter");

var dllPath64 = Path.Combine(basePath, @"x64\soulmods.dll");
OverwriteFile("SoulMemory.soulmods.x64.soulmods.dll", dllPath64);
var dir = Path.GetDirectoryName(typeof(Soulmods).Assembly.Location);
var x64path = Path.Combine(dir, @"soulmods_x64.dll");

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

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Possible 'null' assignment to non-nullable entity

Possible 'null' assignment to non-nullable entity

Check notice on line 53 in src/SoulMemory/soulmods/Soulmods.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant verbatim string prefix

Redundant verbatim string prefix
var x86path = Path.Combine(dir, @"soulmods_x86.dll");

Check notice on line 54 in src/SoulMemory/soulmods/Soulmods.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant verbatim string prefix

Redundant verbatim string prefix

if (process.Is64Bit())
if (process.Is64Bit().Unwrap())

Check notice on line 56 in src/SoulMemory/soulmods/Soulmods.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

'if' statement can be rewritten as '?:' expression

Convert into method call with '?:' expression inside
{
process.InjectDll(x64path);
}
else
{
process.InjectDll(dllPath64);
process.InjectDll(x86path);
}

foreach (ProcessModule processModule in process.Modules)
{
if (processModule.ModuleName == "soulmods.dll")
if (processModule.ModuleName == "soulmods_x64.dll" || processModule.ModuleName == "soulmods_x86.dll")
{
return true;
}
Expand All @@ -71,7 +72,7 @@
return false;
}

public static MorphemeMessageBuffer GetMorphemeMessages2(Process process) => process.RustCall<MorphemeMessageBuffer>("GetQueuedDarkSouls2MorphemeMessages2");

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

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Check .NET source code coverage

Method `GetMorphemeMessages2` coverage is below the threshold 50%



Expand Down Expand Up @@ -116,12 +117,12 @@
process.WriteProcessMemory(buffer.ToInt64(), BitConverter.GetBytes(requestedSize));
process.Execute((IntPtr)func, buffer);

var data = process.ReadProcessMemory(buffer.ToInt64(), totalSize).Unwrap();

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

View workflow job for this annotation

GitHub Actions / build

Remove the unused local variable 'data'. (https://rules.sonarsource.com/csharp/RSPEC-1481)

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

View workflow job for this annotation

GitHub Actions / build

Remove the unused local variable 'data'. (https://rules.sonarsource.com/csharp/RSPEC-1481)

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

View workflow job for this annotation

GitHub Actions / build

Remove the unused local variable 'data'. (https://rules.sonarsource.com/csharp/RSPEC-1481)
process.Free(buffer);
}
}

private static void OverwriteFile(string manifestResourceName, string path)

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

View workflow job for this annotation

GitHub Actions / build

Remove the unused private method 'OverwriteFile'. (https://rules.sonarsource.com/csharp/RSPEC-1144)

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

View workflow job for this annotation

GitHub Actions / build

Remove the unused private method 'OverwriteFile'. (https://rules.sonarsource.com/csharp/RSPEC-1144)

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

View workflow job for this annotation

GitHub Actions / build

Remove the unused private method 'OverwriteFile'. (https://rules.sonarsource.com/csharp/RSPEC-1144)

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

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Type member is never used (private accessibility)

Method 'OverwriteFile' is never used
{
byte[] buffer;
using (var stream = typeof(Soulmods).Assembly.GetManifestResourceStream(manifestResourceName))
Expand Down
9 changes: 7 additions & 2 deletions src/SoulSplitter/SoulComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
});
}

private void SetBitBlt()

Check warning on line 110 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 Expand Up @@ -379,9 +379,14 @@
{
"SoulSplitter.dll",
"SoulMemory.dll",
"MaterialDesignThemes.Wpf.xml",
"MaterialDesignThemes.Wpf.dll",
"MaterialDesignColors.dll",
"MaterialDesignThemes.Wpf.dll",
"soulmods_x64.dll",
"soulmods_x86.dll",
"soulmemory_rs_x64.dll",
"soulmemory_rs_x86.dll",
"launcher_x64.exe",
"launcher_x86.exe",
};

private void ThrowIfInstallationInvalid()
Expand Down
54 changes: 36 additions & 18 deletions src/SoulSplitter/SoulSplitter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,31 +56,49 @@
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="soulmemory-rs\x64\launcher.exe" />
<EmbeddedResource Include="soulmemory-rs\x64\soulmemory_rs.dll" />
<EmbeddedResource Include="soulmemory-rs\x86\launcher.exe" />
<EmbeddedResource Include="soulmemory-rs\x86\soulmemory_rs.dll" />
<ContentWithTargetPath Include="soulmemory-rs\x64\launcher.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<TargetPath>launcher_x64.exe</TargetPath>
</ContentWithTargetPath>
<ContentWithTargetPath Include="soulmemory-rs\x86\launcher.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<TargetPath>launcher_x86.exe</TargetPath>
</ContentWithTargetPath>
<ContentWithTargetPath Include="soulmemory-rs\x64\soulmemory_rs.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<TargetPath>soulmemory_rs_x64.dll</TargetPath>
</ContentWithTargetPath>
<ContentWithTargetPath Include="soulmemory-rs\x86\soulmemory_rs.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<TargetPath>soulmemory_rs_x86.dll</TargetPath>
</ContentWithTargetPath>
<EmbeddedResource Include="soulsplitter.ico" />
</ItemGroup>

<ItemGroup>
<Folder Include="soulmemory-rs\x64\" />
<Folder Include="soulmemory-rs\x86\" />
</ItemGroup>

<Target Name="Copy release artifacts" AfterTargets="Build" Condition="$(SolutionName) == 'SoulSplitter' And $(Configuration) == 'Release'">
<Copy SourceFiles="$(OutputPath)\SoulSplitter.dll" DestinationFolder="..\..\Components" />
<Copy SourceFiles="$(OutputPath)\SoulMemory.dll" DestinationFolder="..\..\Components" />
<Copy SourceFiles="$(OutputPath)\MaterialDesignColors.dll" DestinationFolder="..\..\Components" />
<Copy SourceFiles="$(OutputPath)\MaterialDesignThemes.Wpf.dll" DestinationFolder="..\..\Components" />
<!--<Copy SourceFiles="$(OutputPath)\MaterialDesignThemes.Wpf.xml" DestinationFolder="..\..\Components" />-->
<Copy DestinationFolder="..\..\Components" SourceFiles="$(OutputPath)\SoulSplitter.dll" />
<Copy DestinationFolder="..\..\Components" SourceFiles="$(OutputPath)\SoulMemory.dll" />
<Copy DestinationFolder="..\..\Components" SourceFiles="$(OutputPath)\MaterialDesignColors.dll" />
<Copy DestinationFolder="..\..\Components" SourceFiles="$(OutputPath)\MaterialDesignThemes.Wpf.dll"/>
<Copy DestinationFolder="..\..\Components" SourceFiles="$(OutputPath)\soulmemory_rs_x64.dll" />
<Copy DestinationFolder="..\..\Components" SourceFiles="$(OutputPath)\soulmemory_rs_x86.dll" />
<Copy DestinationFolder="..\..\Components" SourceFiles="$(OutputPath)\soulmods_x64.dll" />
<Copy DestinationFolder="..\..\Components" SourceFiles="$(OutputPath)\soulmods_x86.dll" />
<Copy DestinationFolder="..\..\Components" SourceFiles="$(OutputPath)\launcher_x64.exe" />
<Copy DestinationFolder="..\..\Components" SourceFiles="$(OutputPath)\launcher_x86.exe" />
</Target>

<Target Name="Copy debug artifacts to livesplit's debug folder" AfterTargets="Build" Condition="$(SolutionName) == 'LiveSplit'">
<Copy SourceFiles="$(OutputPath)\SoulSplitter.dll" DestinationFolder="..\..\..\LiveSplit\LiveSplit\bin\Debug\Components" />
<Copy SourceFiles="$(OutputPath)\SoulMemory.dll" DestinationFolder="..\..\..\LiveSplit\LiveSplit\bin\Debug\Components" />
<Copy SourceFiles="$(OutputPath)\MaterialDesignColors.dll" DestinationFolder="..\..\..\LiveSplit\LiveSplit\bin\Debug\Components" />
<Copy SourceFiles="$(OutputPath)\MaterialDesignThemes.Wpf.dll" DestinationFolder="..\..\..\LiveSplit\LiveSplit\bin\Debug\Components" />
<Copy DestinationFolder="..\..\..\LiveSplit\LiveSplit\bin\Debug\Components" SourceFiles="$(OutputPath)\SoulSplitter.dll" />
<Copy DestinationFolder="..\..\..\LiveSplit\LiveSplit\bin\Debug\Components" SourceFiles="$(OutputPath)\SoulMemory.dll" />
<Copy DestinationFolder="..\..\..\LiveSplit\LiveSplit\bin\Debug\Components" SourceFiles="$(OutputPath)\MaterialDesignColors.dll" />
<Copy DestinationFolder="..\..\..\LiveSplit\LiveSplit\bin\Debug\Components" SourceFiles="$(OutputPath)\MaterialDesignThemes.Wpf.dll" />
<Copy DestinationFolder="..\..\..\LiveSplit\LiveSplit\bin\Debug\Components" SourceFiles="$(OutputPath)\soulmemory_rs_x64.dll" />
<Copy DestinationFolder="..\..\..\LiveSplit\LiveSplit\bin\Debug\Components" SourceFiles="$(OutputPath)\soulmemory_rs_x86.dll" />
<Copy DestinationFolder="..\..\..\LiveSplit\LiveSplit\bin\Debug\Components" SourceFiles="$(OutputPath)\soulmods_x64.dll" />
<Copy DestinationFolder="..\..\..\LiveSplit\LiveSplit\bin\Debug\Components" SourceFiles="$(OutputPath)\soulmods_x86.dll" />
<Copy DestinationFolder="..\..\..\LiveSplit\LiveSplit\bin\Debug\Components" SourceFiles="$(OutputPath)\launcher_x64.dll" />
<Copy DestinationFolder="..\..\..\LiveSplit\LiveSplit\bin\Debug\Components" SourceFiles="$(OutputPath)\launcher_x86.dll" />
<!--<Copy SourceFiles="$(OutputPath)\MaterialDesignThemes.Wpf.xml" DestinationFolder="..\..\..\LiveSplit\LiveSplit\bin\Debug\Components"/>-->
</Target>

Expand Down
45 changes: 8 additions & 37 deletions src/SoulSplitter/soulmemory-rs/SoulMemoryRs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

using LiveSplit.ComponentUtil;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using SoulMemory.MemoryV2.Process;
using SoulMemory.soulmods;
using SoulMemory.Native;

namespace SoulSplitter.soulmemory_rs
{
Expand All @@ -40,46 +39,18 @@
};

var process = Process.GetProcesses().FirstOrDefault(p => games.Contains(p.ProcessName.ToLower()));
if(process == null)
if (process == null)
{
return;
}

//Make sure its not already loaded
var wrapper = new ProcessWrapper();
wrapper.TryRefresh(process.ProcessName, out Exception e);
if (e != null || wrapper.GetProcessModules().Any(i => i.ModuleName == "soulmemory_rs.dll"))
{
return;
}

var basePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "soulsplitter");

OverwriteFile("soulsplitter.soulmemory_rs.x64.launcher.exe", Path.Combine(basePath, @"x64\launcher.exe"));
OverwriteFile("soulsplitter.soulmemory_rs.x64.soulmemory_rs.dll", Path.Combine(basePath, @"x64\soulmemory_rs.dll"));
OverwriteFile("soulsplitter.soulmemory_rs.x86.launcher.exe", Path.Combine(basePath, @"x86\launcher.exe"));
OverwriteFile("soulsplitter.soulmemory_rs.x86.soulmemory_rs.dll", Path.Combine(basePath, @"x86\soulmemory_rs.dll"));

Process.Start(process.Is64Bit()
? Path.Combine(basePath, @"x64\launcher.exe")
: Path.Combine(basePath, @"x86\launcher.exe"));
}
var x64 = process.Is64Bit().Unwrap();

private static void OverwriteFile(string manifestResourceName, string path)
{
byte[] buffer;
using(var stream = typeof(SoulMemoryRs).Assembly.GetManifestResourceStream(manifestResourceName))
{
if (stream == null)
{
throw new ArgumentException($"{manifestResourceName} does not return valid resource stream. Valid resources are: {string.Join(",",typeof(SoulMemoryRs).Assembly.GetManifestResourceNames())}");
}
var launcherPath = Path.Combine(Path.GetDirectoryName(typeof(Soulmods).Assembly.Location), $"{(x64 ? "launcher_x64.exe" : "launcher_x86.exe")}");

Check warning on line 49 in src/SoulSplitter/soulmemory-rs/SoulMemoryRs.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Possible 'null' assignment to non-nullable entity

Possible 'null' assignment to non-nullable entity
var dllPath = Path.Combine(Path.GetDirectoryName(typeof(Soulmods).Assembly.Location), $"{(x64 ? "soulmemory_rs_x64.dll" : "soulmemory_rs_x86.dll")}");

Check warning on line 50 in src/SoulSplitter/soulmemory-rs/SoulMemoryRs.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Possible 'null' assignment to non-nullable entity

Possible 'null' assignment to non-nullable entity
var args = $"--processname={process.ProcessName} --dllpath=\"{dllPath}\"";

buffer = new byte[stream.Length];
var _ = stream.Read(buffer, 0, buffer.Length);
}
Directory.CreateDirectory(Path.GetDirectoryName(path));
File.WriteAllBytes(path, buffer);
Process.Start(launcherPath, args);
}
}
}
19 changes: 7 additions & 12 deletions src/cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
using SoulMemory.Parameters;
using SoulMemory.Sekiro;
using SoulSplitter.Hotkeys;
using SoulSplitter.soulmemory_rs;

#pragma warning disable CS0162

Expand All @@ -46,21 +47,15 @@ static void Main(string[] args)
GlobalHotKey.RegisterHotKey(ModifierKeys.Alt, Key.S, () =>{ Debug.WriteLine("S"); });
GlobalHotKey.RegisterHotKey(ModifierKeys.Alt, Key.D, () =>{ Debug.WriteLine("D"); });


//TestUi();
GameLoop<EldenRing>((e) =>
{
var versionString = e.GetProcess().MainModule?.FileVersionInfo.ProductVersion ?? "Failed to read ER version";
if(!Version.TryParse(versionString, out Version v))
GameLoop<EldenRing>(
(d) =>
{
Console.WriteLine("Failed to parse version string");
var igtElapsed = TimeSpan.FromMilliseconds(d.GetInGameTimeMilliseconds());
Console.WriteLine($"IGT: {igtElapsed}");
}

Console.WriteLine($"Raw version: {versionString}, ER version: {e.GetVersion(v)}");

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


Expand Down
Loading
Loading