Question C# Add System.Reflection assembly too Unity game

Hexui Undetected CSGO Cheats PUBG Accounts

xNyu

Trump Tier Donator
Full Member
Sep 9, 2020
3
422
0
Game Name
Minoria
Anticheat
N/A
How long you been coding/hacking?
a few years
Coding Language
Every which is needed
Hey guys,

there is this game I want to mod, at the moment I work on a dynamic mod loader, which is patched in Assembly-CSharp. It looks something like this:
Mod loader:
string curDir = (Directory.GetCurrentDirectory();
            if (Directory.Exists(curDir + @"\Mods")){
                string[] mods = Directory.GetFiles(Directory.GetParent(curDir) + @"\Mods", "*.dll", SearchOption.AllDirectories);
                if (mods.Length > 0) {
                    foreach (string mod in mods)
                    {
                        if (!mod.Contains("dont-load"))
                        {
                            IntPtr pDll = LoadLibrary(mod);
                            if (pDll != IntPtr.Zero)
                            {
                                IntPtr pAddressOfFunctionToCall = GetProcAddress(pDll, "Mod");
                                if (pAddressOfFunctionToCall != IntPtr.Zero)
                                {
                                    Mod runny = (Mod)Marshal.GetDelegateForFunctionPointer(pAddressOfFunctionToCall, typeof(Mod));
                                    runny();
                                }
                            }
                            FreeLibrary(pDll);
                        }
                    }
                }
            }
The mods getting loaded then and patching the games assembly via Lib.Harmony, a great framework for .NET runtime patching. Theonly clue here is that Harmony uses the System.Reflection.Emit assembly, which Unity stripped out of the game. I have to add/load it manually.

I searched in DnSpy but don't founf any option for add assembly reference, also anything I tried haven't worked yet. Decompiling the Assembly-CSharp.dll and exporting source with .NET Reflector doesn't work aswell, because I getting like 2k errors when trying to recompile.

I need a way to implement this assembly, like System.Text or System.IO is implemented.
 
Community Mods