Browse Source

Finished shift to stored references

Build project CollectDependencies to collect and process dependencies
pull/1/head
Anairkoen Schno 6 years ago
parent
commit
ef32b6bfd9
9 changed files with 158 additions and 5 deletions
  1. +3
    -0
      BSIPA.sln
  2. +8
    -0
      CollectDependencies/CollectDependencies.csproj
  3. +28
    -1
      CollectDependencies/Program.cs
  4. +115
    -0
      CollectDependencies/Virtualizer.cs
  5. +1
    -1
      IPA.Injector/IPA.Injector.csproj
  6. +2
    -2
      IPA.Loader/IPA.Loader.csproj
  7. +1
    -1
      IPA/obj/Debug/IPA.csproj.CoreCompileInputs.cache
  8. BIN
      Refs/UnityEngine.CoreModule.dll
  9. BIN
      Refs/UnityEngine.UnityWebRequestModule.dll

+ 3
- 0
BSIPA.sln View File

@ -20,6 +20,9 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "proxy", "Doorstop\Proxy\Proxy.vcxproj", "{88609E16-731F-46C9-8139-6B1A7A83240D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{C79C2C3A-A7FC-40D6-A5CC-9752A661AFA9}"
ProjectSection(SolutionItems) = preProject
Refs\refs.txt = Refs\refs.txt
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CollectDependencies", "CollectDependencies\CollectDependencies.csproj", "{5F33B310-DC8D-4C0D-877E-BAC3908DE10F}"
EndProject


+ 8
- 0
CollectDependencies/CollectDependencies.csproj View File

@ -35,15 +35,19 @@
<ItemGroup>
<Reference Include="Mono.Cecil, Version=0.10.1.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.10.1\lib\net40\Mono.Cecil.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Mono.Cecil.Mdb, Version=0.10.1.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.10.1\lib\net40\Mono.Cecil.Mdb.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Mono.Cecil.Pdb, Version=0.10.1.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.10.1\lib\net40\Mono.Cecil.Pdb.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Mono.Cecil.Rocks, Version=0.10.1.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.10.1\lib\net40\Mono.Cecil.Rocks.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
@ -57,10 +61,14 @@
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Virtualizer.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="AfterBuild">
<Exec Command="&quot;$(SolutionDir)$(AssemblyName)\$(OutputPath)$(AssemblyName).exe&quot; Refs/refs.txt" WorkingDirectory="$(SolutionDir)"></Exec>
</Target>
</Project>

+ 28
- 1
CollectDependencies/Program.cs View File

@ -1,4 +1,5 @@
using System;
using Mono.Cecil;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@ -77,6 +78,32 @@ namespace CollectDependencies
files.Add(Pop());
}
foreach (var file in files)
{
var fparts = file.Split('?');
if (fparts.Length > 1 && fparts[1] == "virt")
{
var module = VirtualizedModule.Load(fparts[0]);
module.Virtualize(fparts[0] = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName(), Path.GetFileName(fparts[0])));
}
var modl = ModuleDefinition.ReadModule(fparts[0]);
foreach(var t in modl.Types)
{
foreach (var m in t.Methods)
{
if (m.Body != null)
{
m.Body.Instructions.Clear();
m.Body.InitLocals = false;
m.Body.Variables.Clear();
}
}
}
var outp = Path.Combine(fdir, Path.GetFileName(fparts[0]));
Console.WriteLine($"Copying {fparts[0]} to {outp}");
modl.Write(outp);
}
}
}
}

+ 115
- 0
CollectDependencies/Virtualizer.cs View File

@ -0,0 +1,115 @@
using Mono.Cecil;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace CollectDependencies
{
class VirtualizedModule
{
private const string ENTRY_TYPE = "Display";
private FileInfo _File;
private ModuleDefinition _Module;
public static VirtualizedModule Load(string engineFile)
{
return new VirtualizedModule(engineFile);
}
private VirtualizedModule(string assemblyFile)
{
_File = new FileInfo(assemblyFile);
LoadModules();
}
private void LoadModules()
{
var resolver = new DefaultAssemblyResolver();
resolver.AddSearchDirectory(_File.DirectoryName);
var parameters = new ReaderParameters
{
AssemblyResolver = resolver,
};
_Module = ModuleDefinition.ReadModule(_File.FullName, parameters);
}
/// <summary>
///
/// </summary>
/// <param name="module"></param>
public void Virtualize(string targetfile)
{
foreach (var type in _Module.Types)
{
VirtualizeType(type);
}
_Module.Write(targetfile);
}
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;
}
}
public bool IsVirtualized
{
get
{
var awakeMethods = _Module.GetTypes().SelectMany(t => t.Methods.Where(m => m.Name == "Awake"));
if (awakeMethods.Count() == 0) return false;
return ((float)awakeMethods.Count(m => m.IsVirtual) / awakeMethods.Count()) > 0.5f;
}
}
}
}

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

@ -47,7 +47,7 @@
<Reference Include="System.Xml" />
<Reference Include="UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\..\GameLibrary\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
<HintPath>..\Refs\UnityEngine.CoreModule.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>


+ 2
- 2
IPA.Loader/IPA.Loader.csproj View File

@ -47,11 +47,11 @@
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine.CoreModule">
<HintPath>..\..\..\..\..\..\GameLibrary\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
<HintPath>..\Refs\UnityEngine.CoreModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.UnityWebRequestModule">
<HintPath>..\..\..\..\..\..\GameLibrary\Steam\steamapps\common\Beat Saber\Beat Saber_Data\Managed\UnityEngine.UnityWebRequestModule.dll</HintPath>
<HintPath>..\Refs\UnityEngine.UnityWebRequestModule.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>


+ 1
- 1
IPA/obj/Debug/IPA.csproj.CoreCompileInputs.cache View File

@ -1 +1 @@
de1a0105accb49be9027a1a26ea711a5ac5f69fd
1d38dd5b9139545c6bc300c735ca121563a74d20

BIN
Refs/UnityEngine.CoreModule.dll View File


BIN
Refs/UnityEngine.UnityWebRequestModule.dll View File


Loading…
Cancel
Save