diff --git a/Assets/Dumper/DumpLib.dll b/Assets/Dumper/DumpLib.dll index 974ac83..174363b 100644 Binary files a/Assets/Dumper/DumpLib.dll and b/Assets/Dumper/DumpLib.dll differ diff --git a/RecodeItLib/Dumper/DumperClass.cs b/RecodeItLib/Dumper/DumperClass.cs index 9cc30f6..f936de5 100644 --- a/RecodeItLib/Dumper/DumperClass.cs +++ b/RecodeItLib/Dumper/DumperClass.cs @@ -34,8 +34,8 @@ public class DumperClass // will explode if they are not there? // TODO: [CWX] TRIED OVERRDING - _gameModule = DataProvider.LoadModule(_assemblyPath, _managedPath); - _checkerModule = DataProvider.LoadModule(_fileCheckerPath, _managedPath); + _gameModule = DataProvider.LoadModule(_assemblyPath); + _checkerModule = DataProvider.LoadModule(_fileCheckerPath); _gameTypes = _gameModule.GetTypes().ToList(); _checkerTypes = _checkerModule.GetTypes().ToList(); } @@ -74,7 +74,6 @@ public class DumperClass SetDumpyTaskCode(dumpyTaskType[0]); // TODO: Write game assembly to file - _gameModule.Write(Path.Combine(_managedPath, "Assembly-CSharp-dumper.dll")); // get types @@ -93,7 +92,7 @@ public class DumperClass public void CreateDumpFolders() { - // create dumper folders + // TODO: create dumper folders } /// @@ -302,7 +301,7 @@ public class DumperClass foreach (var li in liList) { - method.Body.Instructions.Append(li); + method.Body.Instructions.Add(li); } } @@ -331,7 +330,7 @@ public class DumperClass foreach (var li in liList) { - method.Body.Instructions.Append(li); + method.Body.Instructions.Add(li); } } } \ No newline at end of file diff --git a/RecodeItLib/Dumper/DumpyInstructionsHelper.cs b/RecodeItLib/Dumper/DumpyInstructionsHelper.cs index 7c65786..d03c783 100644 --- a/RecodeItLib/Dumper/DumpyInstructionsHelper.cs +++ b/RecodeItLib/Dumper/DumpyInstructionsHelper.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using dnlib.DotNet; using dnlib.DotNet.Emit; using DumpLib; +using ReCodeIt.Utils; namespace ReCodeItLib.Dumper; @@ -41,6 +42,7 @@ public static class DumpyInstructionsHelper { // TODO: [CWX] TRIED CHANGING OPTIONS var importer = new Importer(assembly, ImporterOptions.TryToUseExistingAssemblyRefs); + var test = ModuleDefMD.Load("C:\\Battlestate Games\\Escape from Tarkov\\EscapeFromTarkov_Data\\Managed\\mscorlib.dll"); // Add our own local variables @@ -51,9 +53,9 @@ public static class DumpyInstructionsHelper // var2 index1 ExceptionType // TODO: [CWX] this is the problem, Exception is being imported via System.Private.CoreLib... Needs to come from MsCorLib in EFT managed Dir - var typer = typeof(System.Exception); + var typer = test.GetTypes().First(x => x.Name.ToLower() == "exception"); var sptExceptionType = importer.Import(typer); - var sptException = new Local(sptExceptionType.ToTypeSig(true)); + var sptException = new Local(sptExceptionType.ToTypeSig()); method.Body.Variables.Add(sptException); return new List @@ -101,23 +103,24 @@ public static class DumpyInstructionsHelper public static List GetEnsureConsistencyInstructions(ModuleDefMD assembly, ModuleDefMD fileChecker, MethodDef method) { var importer = new Importer(assembly); - + var test = ModuleDefMD.Load("C:\\Battlestate Games\\Escape from Tarkov\\EscapeFromTarkov_Data\\Managed\\mscorlib.dll"); + // init local vars // var1 index0 TimeSpan type - var sptTimeSpanType = importer.Import(typeof(TimeSpan)); + var sptTimeSpanType = importer.Import(test.GetTypes().First(x => x.Name == "TimeSpan")); var sptClass = new Local(sptTimeSpanType.ToTypeSig()); method.Body.Variables.Add(sptClass); // Create genericInstance of a method var type = fileChecker.GetTypes().First(DumpyTypeHelper.GetEnsureConsistencyType).NestedTypes[0].Interfaces[0].Interface; - var typeMethod = importer.Import(typeof(Task).GetMethod("FromResult")); - var generac = new MethodSpecUser(typeMethod.ResolveMethodDef(), new GenericInstMethodSig(type.ToTypeSig())); + var typeMethod = importer.Import(test.GetTypes().First(x => x.Name == "Task").Methods.First(x => x.Name == "FromResult")); + var generac = new MethodSpecUser(typeMethod as IMethodDefOrRef, new GenericInstMethodSig(type.ToTypeSig())); return new List { // return Task.FromResult(ConsistencyController.CheckResult.Succeed(default(TimeSpan))); Instruction.Create(OpCodes.Ldloca_S, method.Body.Variables[0]), - Instruction.Create(OpCodes.Initobj, importer.Import(typeof(TimeSpan))), + Instruction.Create(OpCodes.Initobj, sptTimeSpanType), Instruction.Create(OpCodes.Ldloc_0), Instruction.Create(OpCodes.Call, fileChecker.GetTypes().First(DumpyTypeHelper.GetEnsureConsistencyType).NestedTypes[0].Methods.First(x => x.Name == "Succeed")), Instruction.Create(OpCodes.Call, generac), @@ -135,10 +138,11 @@ public static class DumpyInstructionsHelper public static List GetRunValidationInstructions(ModuleDefMD assembly, MethodDef method) { var importer = new Importer(assembly); + var test = ModuleDefMD.Load("C:\\Battlestate Games\\Escape from Tarkov\\EscapeFromTarkov_Data\\Managed\\mscorlib.dll"); // Create genericInstance of a method var type = assembly.GetTypes().First(DumpyTypeHelper.GetRunValidationType).NestedTypes[0]; - var typeMethod = importer.Import(typeof(AsyncTaskMethodBuilder).GetMethod("Start")); + var typeMethod = importer.Import(test.GetTypes().First(x => x.Name == "AsyncTaskMethodBuilder").Methods.First(x => x.Name == "Start")); var generac = new MethodSpecUser(typeMethod as IMethodDefOrRef, new GenericInstMethodSig(type.ToTypeSig())); return new List diff --git a/RecodeItLib/Dumper/TestAssResolver.cs b/RecodeItLib/Dumper/TestAssResolver.cs deleted file mode 100644 index a8e228a..0000000 --- a/RecodeItLib/Dumper/TestAssResolver.cs +++ /dev/null @@ -1,27 +0,0 @@ -using dnlib.DotNet; - -namespace ReCodeItLib.Dumper; - -public class TestAssResolver : AssemblyResolver -{ - // TODO: [CWX] tried overriding a few things, even passing back all assemblies from managed folder - public TestAssResolver(string path, ModuleContext context = null) : base(context) - { - ManagedPath = path; - } - - public string? ManagedPath { get; set; } - - protected override IEnumerable PreFindAssemblies(IAssembly assembly, ModuleDef sourceModule, bool matchExactly) - { - // get all files in dir - // return them as list of strings - Console.WriteLine("FUCKING HELL"); - - var array = Directory.GetFiles(ManagedPath, "*.dll"); - var array2 = base.PreFindAssemblies(assembly, sourceModule, matchExactly).ToArray(); - Array.Copy(array2, array, array2.Length); - - return array; - } -} \ No newline at end of file diff --git a/RecodeItLib/Utils/DataProvider.cs b/RecodeItLib/Utils/DataProvider.cs index 8612875..91c4159 100644 --- a/RecodeItLib/Utils/DataProvider.cs +++ b/RecodeItLib/Utils/DataProvider.cs @@ -127,32 +127,4 @@ public static class DataProvider return module; } - - public static ModuleDefMD LoadModule(string path, string dir) - { - var mcOptions = new ModuleCreationOptions(CreateModuleContext(path, dir)); - ModuleDefMD module = ModuleDefMD.Load(path, mcOptions); - - module.Context = mcOptions.Context; - - if (module is null) - { - throw new NullReferenceException("Module is null..."); - } - - return module; - } - - public static ModuleContext CreateModuleContext(string path, string dir) { - var ctx = new ModuleContext(); - var asmRe = new TestAssResolver(dir, ctx); - asmRe.EnableFrameworkRedirect = false; - asmRe.FindExactMatch = false; - var res = new Resolver(asmRe); - res.ProjectWinMDRefs = false; - ctx.AssemblyResolver = asmRe; - ctx.Resolver = res; - asmRe.DefaultModuleContext = ctx; - return ctx; - } } \ No newline at end of file