diff --git a/BSIPA.sln.DotSettings b/BSIPA.sln.DotSettings index 34f7d9cd..5569d8b6 100644 --- a/BSIPA.sln.DotSettings +++ b/BSIPA.sln.DotSettings @@ -5,7 +5,9 @@ <Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb"><ExtraRule Prefix="" Suffix="" Style="aaBb" /></Policy> True True + True True + True True True True diff --git a/CollectDependencies/Program.cs b/CollectDependencies/Program.cs index 0e1da50c..e62d5e0c 100644 --- a/CollectDependencies/Program.cs +++ b/CollectDependencies/Program.cs @@ -10,21 +10,21 @@ namespace CollectDependencies { static void Main(string[] args) { - string depsfile = File.ReadAllText(args[0]); - string fdir = Path.GetDirectoryName(args[0]); - - List files = new List(); + var depsFile = File.ReadAllText(args[0]); + var directoryName = Path.GetDirectoryName(args[0]); + + var files = new List>(); { // Create files from stuff in depsfile - Stack fstack = new Stack(); + var stack = new Stack(); 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(Replace(path), lineNo)); + else if (level < stack.Count - 1) { - files.Add(Pop()); - while (level < fstack.Count) + files.Add(new Tuple(Pop(), lineNo)); + while (level < stack.Count) Pop(); Push(path); } + + lineNo++; } - files.Add(Pop()); + files.Add(new Tuple(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}"); } } diff --git a/IPA.Injector/IPA.Injector.csproj b/IPA.Injector/IPA.Injector.csproj index 3a622776..117be32f 100644 --- a/IPA.Injector/IPA.Injector.csproj +++ b/IPA.Injector/IPA.Injector.csproj @@ -91,6 +91,9 @@ + + 4.2.3.4 + 1.2.0 diff --git a/IPA.Injector/Injector.cs b/IPA.Injector/Injector.cs index 5dad80f4..f882f8a1 100644 --- a/IPA.Injector/Injector.cs +++ b/IPA.Injector/Injector.cs @@ -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; diff --git a/IPA.Injector/PostBuild.msbuild b/IPA.Injector/PostBuild.msbuild index 20f1fccb..930720a6 100644 --- a/IPA.Injector/PostBuild.msbuild +++ b/IPA.Injector/PostBuild.msbuild @@ -6,6 +6,7 @@ + @@ -29,7 +30,9 @@ + + \ No newline at end of file diff --git a/IPA.Injector/Virtualizer.cs b/IPA.Injector/Virtualizer.cs index 9aa04ae9..9afa0686 100644 --- a/IPA.Injector/Virtualizer.cs +++ b/IPA.Injector/Virtualizer.cs @@ -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(); } /// diff --git a/IPA.Loader/IPA.Loader.csproj b/IPA.Loader/IPA.Loader.csproj index 8017dc10..2d085e9d 100644 --- a/IPA.Loader/IPA.Loader.csproj +++ b/IPA.Loader/IPA.Loader.csproj @@ -99,9 +99,6 @@ 0.10.1 - - 4.2.3.4 - 11.0.2 diff --git a/Libs/UnityEngine.CoreModule.dll b/Libs/UnityEngine.CoreModule.dll deleted file mode 100644 index 30f76f4c..00000000 Binary files a/Libs/UnityEngine.CoreModule.dll and /dev/null differ diff --git a/Libs/UnityEngine.dll b/Libs/UnityEngine.dll deleted file mode 100644 index 2842b720..00000000 Binary files a/Libs/UnityEngine.dll and /dev/null differ diff --git a/MSBuildTasks/AssemblyRenameTask.cs b/MSBuildTasks/AssemblyRenameTask.cs index 486d8dd9..ad002073 100644 --- a/MSBuildTasks/AssemblyRenameTask.cs +++ b/MSBuildTasks/AssemblyRenameTask.cs @@ -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) { diff --git a/MSBuildTasks/MSBuildTasks.csproj b/MSBuildTasks/MSBuildTasks.csproj index c21cbf16..8d500d62 100644 --- a/MSBuildTasks/MSBuildTasks.csproj +++ b/MSBuildTasks/MSBuildTasks.csproj @@ -44,17 +44,21 @@ ..\packages\Microsoft.VisualStudio.Setup.Configuration.Interop.1.16.30\lib\net35\Microsoft.VisualStudio.Setup.Configuration.Interop.dll True - - ..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.dll + + ..\packages\Mono.Cecil.0.10.1\lib\net40\Mono.Cecil.dll - - ..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.Mdb.dll + + ..\packages\Mono.Cecil.0.10.1\lib\net40\Mono.Cecil.Mdb.dll - - ..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.Pdb.dll + + ..\packages\Mono.Cecil.0.10.1\lib\net40\Mono.Cecil.Pdb.dll - - ..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.Rocks.dll + + ..\packages\Mono.Cecil.0.10.1\lib\net40\Mono.Cecil.Rocks.dll + + + False + .\pdb2mdb.exe @@ -76,10 +80,14 @@ + + + + \ No newline at end of file diff --git a/MSBuildTasks/Pdb2Mdb.cs b/MSBuildTasks/Pdb2Mdb.cs new file mode 100644 index 00000000..ca99642e --- /dev/null +++ b/MSBuildTasks/Pdb2Mdb.cs @@ -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; + } + } +} \ No newline at end of file diff --git a/MSBuildTasks/packages.config b/MSBuildTasks/packages.config index 38b09985..3e14d277 100644 --- a/MSBuildTasks/packages.config +++ b/MSBuildTasks/packages.config @@ -3,7 +3,7 @@ - + \ No newline at end of file diff --git a/MSBuildTasks/pdb2mdb.exe b/MSBuildTasks/pdb2mdb.exe new file mode 100644 index 00000000..6571d192 Binary files /dev/null and b/MSBuildTasks/pdb2mdb.exe differ diff --git a/Refs/UnityEngine.CoreModule.dll b/Refs/UnityEngine.CoreModule.dll index 9a5dd7af..1eabb3ef 100644 Binary files a/Refs/UnityEngine.CoreModule.dll and b/Refs/UnityEngine.CoreModule.dll differ