Browse Source

Worked further towards the goal of a debuggable Beat Saber

Upgraded Mono.Cecil to 0.10.1
Removed some unneeded files from repo
pull/1/head
Anairkoen Schno 6 years ago
parent
commit
993ba98752
15 changed files with 189 additions and 57 deletions
  1. +2
    -0
      BSIPA.sln.DotSettings
  2. +56
    -42
      CollectDependencies/Program.cs
  3. +3
    -0
      IPA.Injector/IPA.Injector.csproj
  4. +6
    -1
      IPA.Injector/Injector.cs
  5. +3
    -0
      IPA.Injector/PostBuild.msbuild
  6. +11
    -1
      IPA.Injector/Virtualizer.cs
  7. +0
    -3
      IPA.Loader/IPA.Loader.csproj
  8. BIN
      Libs/UnityEngine.CoreModule.dll
  9. BIN
      Libs/UnityEngine.dll
  10. +12
    -1
      MSBuildTasks/AssemblyRenameTask.cs
  11. +16
    -8
      MSBuildTasks/MSBuildTasks.csproj
  12. +79
    -0
      MSBuildTasks/Pdb2Mdb.cs
  13. +1
    -1
      MSBuildTasks/packages.config
  14. BIN
      MSBuildTasks/pdb2mdb.exe
  15. BIN
      Refs/UnityEngine.CoreModule.dll

+ 2
- 0
BSIPA.sln.DotSettings View File

@ -5,7 +5,9 @@
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb"&gt;&lt;ExtraRule Prefix="" Suffix="" Style="aaBb" /&gt;&lt;/Policy&gt;</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=beatsaber/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Coroutine/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=deps/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Modsaber/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Pdbs/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Prefs/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=unpatch/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Virtualize/@EntryIndexedValue">True</s:Boolean>

+ 56
- 42
CollectDependencies/Program.cs View File

@ -10,21 +10,21 @@ namespace CollectDependencies
{
static void Main(string[] args)
{
string depsfile = File.ReadAllText(args[0]);
string fdir = Path.GetDirectoryName(args[0]);
List<string> files = new List<string>();
var depsFile = File.ReadAllText(args[0]);
var directoryName = Path.GetDirectoryName(args[0]);
var files = new List<Tuple<string, int>>();
{ // Create files from stuff in depsfile
Stack<string> fstack = new Stack<string>();
var stack = new Stack<string>();
void Push(string val)
{
string pre = "";
if (fstack.Count > 0)
pre = fstack.First();
fstack.Push(pre + val);
if (stack.Count > 0)
pre = stack.First();
stack.Push(pre + val);
}
string Pop() => fstack.Pop();
string Pop() => stack.Pop();
string Replace(string val)
{
var v2 = Pop();
@ -32,7 +32,8 @@ namespace CollectDependencies
return v2;
}
foreach (var line in depsfile.Split(new[] { Environment.NewLine }, StringSplitOptions.None))
var lineNo = 0;
foreach (var line in depsFile.Split(new[] { Environment.NewLine }, StringSplitOptions.None))
{
var parts = line.Split('"');
var path = parts.Last();
@ -46,7 +47,7 @@ namespace CollectDependencies
var arglist = string.Join(" ", parts);
if (command == "from")
{ // an "import" type command
path = File.ReadAllText(Path.Combine(fdir ?? throw new InvalidOperationException(), arglist));
path = File.ReadAllText(Path.Combine(directoryName ?? throw new InvalidOperationException(), arglist));
}
else if (command == "prompt")
{
@ -60,59 +61,72 @@ namespace CollectDependencies
}
}
if (level > fstack.Count - 1)
if (level > stack.Count - 1)
Push(path);
else if (level == fstack.Count - 1)
files.Add(Replace(path));
else if (level < fstack.Count - 1)
else if (level == stack.Count - 1)
files.Add(new Tuple<string, int>(Replace(path), lineNo));
else if (level < stack.Count - 1)
{
files.Add(Pop());
while (level < fstack.Count)
files.Add(new Tuple<string, int>(Pop(), lineNo));
while (level < stack.Count)
Pop();
Push(path);
}
lineNo++;
}
files.Add(Pop());
files.Add(new Tuple<string, int>(Pop(), lineNo));
}
foreach (var file in files)
{
var fparts = file.Split('?');
var fname = fparts[0];
try
{
var fparts = file.Item1.Split('?');
var fname = fparts[0];
if (fname == "") continue;
if (fname == "") continue;
var outp = Path.Combine(fdir ?? throw new InvalidOperationException(), Path.GetFileName(fname) ?? throw new InvalidOperationException());
Console.WriteLine($"Copying \"{fname}\" to \"{outp}\"");
if (File.Exists(outp)) File.Delete(outp);
var outp = Path.Combine(directoryName ?? throw new InvalidOperationException(),
Path.GetFileName(fname) ?? throw new InvalidOperationException());
Console.WriteLine($"Copying \"{fname}\" to \"{outp}\"");
if (File.Exists(outp)) File.Delete(outp);
if (Path.GetExtension(fname)?.ToLower() == ".dll")
{
// ReSharper disable once StringLiteralTypo
if (fparts.Length > 1 && fparts[1] == "virt")
{
var module = VirtualizedModule.Load(fname);
module.Virtualize(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName(), Path.GetFileName(fname) ?? throw new InvalidOperationException()));
}
var modl = ModuleDefinition.ReadModule(fparts[0]);
foreach (var t in modl.Types)
if (Path.GetExtension(fname)?.ToLower() == ".dll")
{
foreach (var m in t.Methods)
// ReSharper disable once StringLiteralTypo
if (fparts.Length > 1 && fparts[1] == "virt")
{
if (m.Body != null)
var module = VirtualizedModule.Load(fname);
module.Virtualize(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName(),
Path.GetFileName(fname) ?? throw new InvalidOperationException()));
}
var modl = ModuleDefinition.ReadModule(fparts[0]);
foreach (var t in modl.Types)
{
foreach (var m in t.Methods)
{
m.Body.Instructions.Clear();
m.Body.InitLocals = false;
m.Body.Variables.Clear();
if (m.Body != null)
{
m.Body.Instructions.Clear();
m.Body.InitLocals = false;
m.Body.Variables.Clear();
}
}
}
modl.Write(outp);
}
else
{
File.Copy(fname, outp);
}
modl.Write(outp);
}
else
catch (Exception e)
{
File.Copy(fname, outp);
Console.WriteLine($"{args[0]}({file.Item2}): error: {e}");
}
}


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

@ -91,6 +91,9 @@
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Mono.Unofficial.pdb2mdb">
<Version>4.2.3.4</Version>
</PackageReference>
<PackageReference Include="SemanticVersioning">
<Version>1.2.0</Version>
</PackageReference>


+ 6
- 1
IPA.Injector/Injector.cs View File

@ -58,7 +58,12 @@ namespace IPA.Injector
#region Insert patch into UnityEngine.CoreModule.dll
var unityPath = Path.Combine(Environment.CurrentDirectory, "Beat Saber_Data", "Managed", "UnityEngine.CoreModule.dll");
var unityAsmDef = AssemblyDefinition.ReadAssembly(unityPath);
var unityAsmDef = AssemblyDefinition.ReadAssembly(unityPath, new ReaderParameters
{
ReadWrite = false,
InMemory = true,
ReadingMode = ReadingMode.Immediate
});
var unityModDef = unityAsmDef.MainModule;
bool modified = false;


+ 3
- 0
IPA.Injector/PostBuild.msbuild View File

@ -6,6 +6,7 @@
</PropertyGroup>
<UsingTask TaskName="AssemblyRename" AssemblyFile="$(SolDir)MSBuildTasks\bin\$(Configuration)\MSBuildTasks.dll" />
<UsingTask TaskName="PdbToMdb" AssemblyFile="$(SolDir)MSBuildTasks\bin\$(Configuration)\MSBuildTasks.dll" />
<Target Name="PostBuild">
<Message Text="Relocating" Importance="normal" />
@ -29,7 +30,9 @@
<ItemGroup>
<ToRename Include="$(OPath)Libs\**\*.dll" />
<ToMdb Include="$(OPath)**\*.pdb" />
</ItemGroup>
<AssemblyRename Assemblies="@(ToRename)" />
<PdbToMdb Binaries="@(ToMdb)" />
</Target>
</Project>

+ 11
- 1
IPA.Injector/Virtualizer.cs View File

@ -24,7 +24,17 @@ namespace IPA.Injector
private void LoadModules()
{
module = ModuleDefinition.ReadModule(file.FullName);
module = ModuleDefinition.ReadModule(file.FullName, new ReaderParameters
{
ReadWrite = false,
InMemory = true,
ReadingMode = ReadingMode.Immediate
});
}
~VirtualizedModule()
{
module?.Dispose();
}
/// <summary>


+ 0
- 3
IPA.Loader/IPA.Loader.csproj View File

@ -99,9 +99,6 @@
<PackageReference Include="Mono.Cecil">
<Version>0.10.1</Version>
</PackageReference>
<PackageReference Include="Mono.Unofficial.pdb2mdb">
<Version>4.2.3.4</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>11.0.2</Version>
</PackageReference>


BIN
Libs/UnityEngine.CoreModule.dll View File


BIN
Libs/UnityEngine.dll View File


+ 12
- 1
MSBuildTasks/AssemblyRenameTask.cs View File

@ -42,12 +42,23 @@ namespace MSBuildTasks
var newFilen = $"{name}.{version}.dll";
var newFilePath = Path.Combine(Path.GetDirectoryName(assembly.ItemSpec) ?? throw new InvalidOperationException(), newFilen);
module.Dispose();
Log.LogMessage(MessageImportance.Normal, $"Old file: {assembly.ItemSpec}, new file: {newFilePath}");
if (File.Exists(newFilePath))
File.Delete(newFilePath);
File.Move(assembly.ItemSpec, newFilePath);
Log.LogMessage(MessageImportance.Normal, "Moving");
try
{
File.Move(assembly.ItemSpec, newFilePath);
}
catch (Exception)
{
File.Copy(assembly.ItemSpec, newFilePath);
File.Delete(assembly.ItemSpec);
}
}
catch (Exception e)
{


+ 16
- 8
MSBuildTasks/MSBuildTasks.csproj View File

@ -44,17 +44,21 @@
<HintPath>..\packages\Microsoft.VisualStudio.Setup.Configuration.Interop.1.16.30\lib\net35\Microsoft.VisualStudio.Setup.Configuration.Interop.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="Mono.Cecil, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.dll</HintPath>
<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>
</Reference>
<Reference Include="Mono.Cecil.Mdb, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.Mdb.dll</HintPath>
<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>
</Reference>
<Reference Include="Mono.Cecil.Pdb, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.Pdb.dll</HintPath>
<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>
</Reference>
<Reference Include="Mono.Cecil.Rocks, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.Rocks.dll</HintPath>
<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>
</Reference>
<Reference Include="pdb2mdb, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>.\pdb2mdb.exe</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Collections.Immutable, Version=1.2.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
@ -76,10 +80,14 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyRenameTask.cs" />
<Compile Include="Pdb2Mdb.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="pdb2mdb.exe" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

+ 79
- 0
MSBuildTasks/Pdb2Mdb.cs View File

@ -0,0 +1,79 @@
using System;
using System.IO;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
namespace MSBuildTasks
{
public class PdbToMdb : Task
{
[Required]
// ReSharper disable once UnusedAutoPropertyAccessor.Global
public ITaskItem[] Binaries { get; set; }
public override bool Execute()
{
//var readerProvider = new PdbReaderProvider();
//var writerProvider = new MdbWriterProvider();
foreach (ITaskItem dll in Binaries)
{
// ItemSpec holds the filename or path of an Item
if (dll.ItemSpec.Length > 0)
{
if (!File.Exists(dll.ItemSpec))
{
Log.LogMessage(MessageImportance.Normal, "No file at " + dll.ItemSpec);
continue;
}
if (Path.GetExtension(dll.ItemSpec) != ".dll" && Path.GetExtension(dll.ItemSpec) != ".pdb")
{
Log.LogMessage(MessageImportance.Normal, dll.ItemSpec + " not a DLL or PDB");
continue;
}
try
{
/*Log.LogMessage(MessageImportance.Normal, "Processing PDB for " + dll.ItemSpec);
var path = Path.ChangeExtension(dll.ItemSpec, ".dll");
var module = ModuleDefinition.ReadModule(path);
var reader = readerProvider.GetSymbolReader(module, path);
var writer = writerProvider.GetSymbolWriter(module, path);
foreach (var type in module.Types)
foreach (var method in type.Methods)
{
var read = reader.Read(method);
if (read == null) Log.LogWarning($"Method {module.FileName} -> {method.FullName} read from PDB as null");
else writer.Write(read);
}
writer.Dispose();
reader.Dispose();
module.Dispose();*/
var path = Path.ChangeExtension(dll.ItemSpec, ".dll");
Log.LogMessage(MessageImportance.Normal, "Processing PDB for " + path);
/*Process.Start(new ProcessStartInfo
{
WorkingDirectory = Path.GetDirectoryName(path) ?? throw new InvalidOperationException(),
FileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase) ?? throw new InvalidOperationException(), "pdb2mdb.exe"),
Arguments = Path.GetFileName(path)
});*/
//Pdb2Mdb.Converter.Convert(path);
}
catch (Exception e)
{
Log.LogErrorFromException(e);
Log.LogError(e.ToString());
}
}
}
return !Log.HasLoggedErrors;
}
}
}

+ 1
- 1
MSBuildTasks/packages.config View File

@ -3,7 +3,7 @@
<package id="Microsoft.Build.Framework" version="15.8.166" targetFramework="net46" />
<package id="Microsoft.Build.Utilities.Core" version="15.8.166" targetFramework="net46" />
<package id="Microsoft.VisualStudio.Setup.Configuration.Interop" version="1.16.30" targetFramework="net46" developmentDependency="true" />
<package id="Mono.Cecil" version="0.9.6.4" targetFramework="net46" />
<package id="Mono.Cecil" version="0.10.1" targetFramework="net46" />
<package id="System.Collections.Immutable" version="1.5.0" targetFramework="net46" />
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net46" />
</packages>

BIN
MSBuildTasks/pdb2mdb.exe View File


BIN
Refs/UnityEngine.CoreModule.dll View File


Loading…
Cancel
Save