attempt at fixing imports
This commit is contained in:
parent
c32163404c
commit
1b780b3330
@ -1,4 +1,5 @@
|
||||
using System.Collections;
|
||||
using System.Runtime.CompilerServices;
|
||||
using dnlib.DotNet;
|
||||
using dnlib.DotNet.Emit;
|
||||
using ReCodeIt.Utils;
|
||||
@ -32,8 +33,9 @@ public class DumperClass
|
||||
}
|
||||
|
||||
// will explode if they are not there?
|
||||
_gameModule = DataProvider.LoadModule(_assemblyPath);
|
||||
_checkerModule = DataProvider.LoadModule(_fileCheckerPath);
|
||||
// TODO: [CWX] TRIED OVERRDING
|
||||
_gameModule = DataProvider.LoadModule(_assemblyPath, _managedPath);
|
||||
_checkerModule = DataProvider.LoadModule(_fileCheckerPath, _managedPath);
|
||||
_gameTypes = _gameModule.GetTypes().ToList();
|
||||
_checkerTypes = _checkerModule.GetTypes().ToList();
|
||||
}
|
||||
@ -72,6 +74,7 @@ public class DumperClass
|
||||
SetDumpyTaskCode(dumpyTaskType[0]);
|
||||
|
||||
// TODO: Write game assembly to file
|
||||
|
||||
_gameModule.Write(Path.Combine(_managedPath, "Assembly-CSharp-dumper.dll"));
|
||||
|
||||
// get types
|
||||
|
@ -39,7 +39,8 @@ public static class DumpyInstructionsHelper
|
||||
/// <returns>List<Instruction></returns>
|
||||
public static List<Instruction> GetRunValidationInstructionsMoveNext(ModuleDefMD assembly, MethodDef method)
|
||||
{
|
||||
var importer = new Importer(assembly);
|
||||
// TODO: [CWX] TRIED CHANGING OPTIONS
|
||||
var importer = new Importer(assembly, ImporterOptions.TryToUseExistingAssemblyRefs);
|
||||
|
||||
// Add our own local variables
|
||||
|
||||
@ -49,8 +50,10 @@ public static class DumpyInstructionsHelper
|
||||
method.Body.Variables.Add(sptClass);
|
||||
|
||||
// var2 index1 ExceptionType
|
||||
var sptExceptionType = importer.Import(typeof(Exception));
|
||||
var sptException = new Local(sptExceptionType.ToTypeSig());
|
||||
// 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 sptExceptionType = importer.Import(typer);
|
||||
var sptException = new Local(sptExceptionType.ToTypeSig(true));
|
||||
method.Body.Variables.Add(sptException);
|
||||
|
||||
return new List<Instruction>
|
||||
|
27
RecodeItLib/Dumper/TestAssResolver.cs
Normal file
27
RecodeItLib/Dumper/TestAssResolver.cs
Normal file
@ -0,0 +1,27 @@
|
||||
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<string> 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;
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
using dnlib.DotNet;
|
||||
using Newtonsoft.Json;
|
||||
using ReCodeIt.Models;
|
||||
using ReCodeItLib.Dumper;
|
||||
|
||||
namespace ReCodeIt.Utils;
|
||||
|
||||
@ -126,4 +127,32 @@ 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;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user