Skip to content

Commit

Permalink
Fixed IsModified method to target injected methods, Decreased DLL dep…
Browse files Browse the repository at this point in the history
…endencies to run Installer.
  • Loading branch information
DragonFire47 committed Dec 10, 2023
1 parent fff4047 commit e9a8dd6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 21 deletions.
19 changes: 9 additions & 10 deletions PulsarInjector/InjectionTools.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Mono.Cecil;
using Mono.Cecil.Cil;
using PulsarModLoader.Utilities;
using System;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -34,7 +33,7 @@ public static void CreateMethod(string targetAssemblyPath, string className, str

public static void ShortCircuitMethod(string targetAssemblyPath, string targetClassName, string targetMethodName)
{
Logger.Info($"Attempting to short circuit method in {targetAssemblyPath}@{targetClassName}::{targetMethodName}");
Injector.PMLWriteLine($"Attempting to short circuit method in {targetAssemblyPath}@{targetClassName}::{targetMethodName}");

/* Load the assemblies */
AssemblyDefinition targetAssembly = LoadAssembly(targetAssemblyPath, null);
Expand All @@ -47,7 +46,7 @@ public static void ShortCircuitMethod(string targetAssemblyPath, string targetCl
throw new ArgumentNullException("Couldn't find method in target assembly!");
}

Logger.Info("Loaded relevant assemblies. Short circuiting method...");
Injector.PMLWriteLine("Loaded relevant assemblies. Short circuiting method...");

// Inject return at start of target method
ILProcessor targetProcessor = targetMethod.Body.GetILProcessor();
Expand All @@ -58,8 +57,8 @@ public static void ShortCircuitMethod(string targetAssemblyPath, string targetCl

public static bool IsModified(string targetAssemblyPath)
{
string targetClassName = "PLGameStatic";
string targetMethodName = "OnInjectionCheatDetected";
string targetClassName = "PLGlobal";
string targetMethodName = "Awake";

// Load the assemblies
AssemblyDefinition targetAssembly = LoadAssembly(targetAssemblyPath, null);
Expand All @@ -72,7 +71,7 @@ public static bool IsModified(string targetAssemblyPath)
throw new ArgumentNullException("Couldn't find method in target assembly!");
}

if (targetMethod.Body.Instructions[0].OpCode == OpCodes.Ret)
if (targetMethod.Body.Instructions[0].OpCode == OpCodes.Call)
{
return true;
}
Expand All @@ -81,7 +80,7 @@ public static bool IsModified(string targetAssemblyPath)

public static void PatchMethod(string targetAssemblyPath, string targetClassName, string targetMethodName, Type sourceClassType, string sourceMethodName)
{
Logger.Info($"Attempting to hook {targetAssemblyPath}");
Injector.PMLWriteLine($"Attempting to hook {targetAssemblyPath}");

// Load the assemblies
AssemblyDefinition targetAssembly = LoadAssembly(targetAssemblyPath, null);
Expand All @@ -95,7 +94,7 @@ public static void PatchMethod(string targetAssemblyPath, string targetClassName
throw new ArgumentNullException("Couldn't find method in target assembly!");
}

Logger.Info("Loaded relevant assemblies. Injecting hook...");
Injector.PMLWriteLine("Loaded relevant assemblies. Injecting hook...");

// Inject source method into front of target method
ILProcessor targetProcessor = targetMethod.Body.GetILProcessor();
Expand Down Expand Up @@ -133,14 +132,14 @@ private static AssemblyDefinition LoadAssembly(string assemblyPath, string[] dep

private static void SaveAssembly(AssemblyDefinition assembly, string assemblyPath)
{
Logger.Info($"Writing hooked {Path.GetFileName(assemblyPath)} to disk...");
Injector.PMLWriteLine($"Writing hooked {Path.GetFileName(assemblyPath)} to disk...");
try
{
assembly.Write(assemblyPath);
}
catch (Exception e) when (e is BadImageFormatException)
{
Logger.Info("Failed to modify corrupted assembly. Try again with a clean assembly (e.g., verify files on Steam)");
Injector.PMLWriteLine("Failed to modify corrupted assembly. Try again with a clean assembly (e.g., verify files on Steam)");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion PulsarInjector/Injector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ static string CheckForUpdates(string CurrentPMLDll)
}
}

static void PMLWriteLine(string text)
internal static void PMLWriteLine(string text)
{
Console.WriteLine("[PMLInstaller]>" + text);
}
Expand Down
16 changes: 6 additions & 10 deletions PulsarInjector/PulsarInjector.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<IsWebBootstrapper>false</IsWebBootstrapper>
<TargetFrameworkProfile />
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
Expand All @@ -23,10 +25,8 @@
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down Expand Up @@ -65,18 +65,14 @@
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.InteropServices.RuntimeInformation" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Windows.Forms">
<EmbedInteropTypes>False</EmbedInteropTypes>
<Private>False</Private>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine.TextRenderingModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\lib\UnityEngine.TextRenderingModule.dll</HintPath>
</Reference>
<Reference Include="Valve.Newtonsoft.Json">
<HintPath>..\lib\Valve.Newtonsoft.Json.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="InjectionTools.cs" />
Expand Down
1 change: 1 addition & 0 deletions PulsarInjector/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Mono.Cecil" version="0.11.5" targetFramework="net472" />
<package id="System.Runtime.Serialization.Primitives" version="4.3.0" targetFramework="net472" />
</packages>

0 comments on commit e9a8dd6

Please sign in to comment.