Browse Source

Completely moved virtualization to the loader

piracy-check
Anairkoen Schno 6 years ago
parent
commit
f1a6583bcb
5 changed files with 130 additions and 2 deletions
  1. +1
    -1
      Doorstop
  2. +1
    -0
      IPA.Injector/IPA.Injector.csproj
  3. +9
    -0
      IPA.Injector/Injector.cs
  4. +118
    -0
      IPA.Injector/Virtualizer.cs
  5. +1
    -1
      IPA/Program.cs

+ 1
- 1
Doorstop

@ -1 +1 @@
Subproject commit c5072722ea34f4c45a5f1fcabb3d9a46d1bf5eb4
Subproject commit 52dae348cf4355cf9687a32aa90e5bcdfc102b11

+ 1
- 0
IPA.Injector/IPA.Injector.csproj View File

@ -56,6 +56,7 @@
<Compile Include="Injector.cs" />
<Compile Include="LibLoader.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Virtualizer.cs" />
<Compile Include="WtfThisDoesntNeedToExist.cs" />
</ItemGroup>
<ItemGroup>


+ 9
- 0
IPA.Injector/Injector.cs View File

@ -50,6 +50,7 @@ namespace IPA.Injector
{
var cAsmName = Assembly.GetExecutingAssembly().GetName();
loader.Debug("Ensuring patch on UnityEngine.CoreModule exists");
#region Insert patch into UnityEngine.CoreModule.dll
var unityPath = Path.Combine(Environment.CurrentDirectory, "Beat Saber_Data", "Managed", "UnityEngine.CoreModule.dll");
@ -110,6 +111,14 @@ namespace IPA.Injector
if (modified)
unityAsmDef.Write(unityPath);
#endregion
loader.Debug("Ensuring Assembly-CSharp is virtualized");
#region Virtualize Assembly-CSharp.dll
var ascPath = Path.Combine(Environment.CurrentDirectory, "Beat Saber_Data", "Managed", "Assembly-CSharp.dll");
var ascModule = VirtualizedModule.Load(ascPath);
ascModule.Virtualize(cAsmName);
#endregion
}
private static bool bootstrapped = false;


+ 118
- 0
IPA.Injector/Virtualizer.cs View File

@ -0,0 +1,118 @@
using Mono.Cecil;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
namespace IPA.Injector
{
internal class VirtualizedModule
{
private const string ENTRY_TYPE = "Display";
public FileInfo file;
public ModuleDefinition module;
public static VirtualizedModule Load(string engineFile)
{
return new VirtualizedModule(engineFile);
}
private VirtualizedModule(string assemblyFile)
{
file = new FileInfo(assemblyFile);
LoadModules();
}
private void LoadModules()
{
module = ModuleDefinition.ReadModule(file.FullName);
}
/// <summary>
///
/// </summary>
/// <param name="module"></param>
public void Virtualize(AssemblyName selfName)
{
bool changed = false;
bool virtualize = true;
foreach (var r in module.AssemblyReferences)
{
if (r.Name == selfName.Name)
{
virtualize = false;
if (r.Version != selfName.Version)
{
r.Version = selfName.Version;
changed = true;
}
}
}
if (virtualize)
{
changed = true;
module.AssemblyReferences.Add(new AssemblyNameReference(selfName.Name, selfName.Version));
foreach (var type in module.Types)
{
VirtualizeType(type);
}
}
if (changed)
module.Write(file.FullName);
}
private void VirtualizeType(TypeDefinition type)
{
if(type.IsSealed)
{
// Unseal
type.IsSealed = false;
}
if (type.IsInterface) return;
if (type.IsAbstract) return;
// These two don't seem to work.
if (type.Name == "SceneControl" || type.Name == "ConfigUI") return;
// Take care of sub types
foreach (var subType in type.NestedTypes)
{
VirtualizeType(subType);
}
foreach (var method in type.Methods)
{
if (method.IsManaged
&& method.IsIL
&& !method.IsStatic
&& !method.IsVirtual
&& !method.IsAbstract
&& !method.IsAddOn
&& !method.IsConstructor
&& !method.IsSpecialName
&& !method.IsGenericInstance
&& !method.HasOverrides)
{
method.IsVirtual = true;
method.IsPublic = true;
method.IsPrivate = false;
method.IsNewSlot = true;
method.IsHideBySig = true;
}
}
foreach (var field in type.Fields)
{
if (field.IsPrivate) field.IsFamily = true;
}
}
}
}

+ 1
- 1
IPA/Program.cs View File

@ -270,7 +270,7 @@ namespace IPA
#region Virtualizing
if (File.Exists(context.AssemblyFile))
if (ArgDestructive && File.Exists(context.AssemblyFile))
{
var virtualizedModule = VirtualizedModule.Load(context.AssemblyFile);
if (!virtualizedModule.IsVirtualized)


Loading…
Cancel
Save