warbler / SharpMonoInjector

A tool for injecting assemblies into Mono embedded applications, commonly Unity Engine based games
MIT License
308 stars 107 forks source link

Failed to inject assembly when there is a reference to another assembly #9

Open StandoffVenus opened 5 years ago

StandoffVenus commented 5 years ago

My current project always returns NULL from mono_class_from_name().

The project is built with .NET Framework v4.6.1 and for Any CPU (like the example assembly), and I've used the GUI app to test injecting it into a 32-bit Unity game. I've got the namespace (WhiteNoise.Cheat.Loader.Models), class name (Loader), and method (Load) correct, but the injection is never successful.

This is what my loading class looks like:

namespace WhiteNoise.Cheat.Loader.Models
{
    using UnityEngine;
    using WhiteNoise.Cheat.Common.Components;

    public class Loader
    {
        private static GameObject Object { get; set; }

        public static void Load()
        {
            Loader.Object = new GameObject();
            Loader.Object.AddComponent<CheatComponent>();
            UnityEngine.Object.DontDestroyOnLoad(Loader.Object);
        }

        public static void Unload()
        {
            UnityEngine.Object.Destroy(Loader.Object);
        }
    }
}
StandoffVenus commented 5 years ago

Not sure what I did, but I managed to fix the initial issue. The new issue I have is due to there being another .dll that my Loader assembly depends on that is not found by the injector. The error given is:

Failed to inject assembly: SharpMonoInjector.InjectorException: The managed method threw an
exception: (FileNotFoundException) Could not load file or assembly 'WhiteNoise.Cheat.Common,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
  at SharpMonoInjector.Injector.RuntimeInvoke(IntPtr method)
  at SharpMonoInjector.Injector.Inject(Byte[] rawAssembly, String namespace, String className, String methodName)
  at SharpMonoInjector.Console.Program.Inject(Injector injector, CommandLineArguments args)
warbler commented 5 years ago

Not sure what I did, but I managed to fix the initial issue. The new issue I have is due to there being another .dll that my Loader assembly depends on that is not found by the injector. The error given is:

Failed to inject assembly: SharpMonoInjector.InjectorException: The managed method threw an
exception: (FileNotFoundException) Could not load file or assembly 'WhiteNoise.Cheat.Common,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
  at SharpMonoInjector.Injector.RuntimeInvoke(IntPtr method)
  at SharpMonoInjector.Injector.Inject(Byte[] rawAssembly, String namespace, String className, String methodName)
  at SharpMonoInjector.Console.Program.Inject(Injector injector, CommandLineArguments args)

This can be temporarily resolved by placing your libraries in the directory in which the game libraries are. I will be updating the injector to automatically deal with dependencies.

safazi commented 5 years ago

Anything on this? I'm dealing with the same problem, using a library that the game does not use.

johmarjac commented 4 years ago

Got the same issue here, is the project dead?