Exemplo n.º 1
0
        public void ModifyGnomoria()
        {
            Reference.GnomodiaDirectory.GetFile(RuntimeModController.Log.LogfileName).Delete();

            var sourceExe = Reference.GameDirectory.GetFile(Reference.OriginalExecutable);
            var moddedExe = Reference.GnomodiaDirectory.GetFile(Reference.ModdedExecutable);
            var sourceLib = Reference.GameDirectory.GetFile(Reference.OriginalLibrary);
            var moddedLib = Reference.GnomodiaDirectory.GetFile(Reference.ModdedLibrary);

            var gameInjector = new GnomoriaExeInjector(sourceExe);
            var libInjector = new Injector(sourceLib);

            gameInjector.InitializeGnomodia(Reference.GnomodiaDirectory.GetFile(Reference.GnomodiaLibrary));
            gameInjector.InjectMapGenerationCalls();
            gameInjector.InjectSaveLoadCalls();
            //gameInjector.Debug_ManipulateStuff();

            foreach (var mod in ModManager.CreateOrGetAllMods())
            {
                var interceptedMethods =
                    from method in mod.GetType().GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static)
                    where method.GetCustomAttributes(typeof(InterceptMethodAttribute), false).Any()
                    select new { Method = method, Attribute = method.GetCustomAttributes(typeof(InterceptMethodAttribute), false).Cast<InterceptMethodAttribute>().Single() };

                foreach (var interceptedMethod in interceptedMethods)
                {
                    var attribute = interceptedMethod.Attribute;
                    IModification mh = new MethodHook(attribute.InterceptedMethod, interceptedMethod.Method, attribute.HookType, attribute.HookFlags);
                    if (gameInjector.AssemblyContainsType(mh.TargetType))
                    {
                        gameInjector.InjectModification(mh);
                    }
                    else if (libInjector.AssemblyContainsType(mh.TargetType))
                    {
                        libInjector.InjectModification(mh);
                    }
                    else
                    {
                        throw new InvalidOperationException(string.Format("Cannot change behavior of type {0}!", mh.TargetType));
                    }
                }
            }

            gameInjector.Write(moddedExe);
            libInjector.Write(moddedLib);
        }
Exemplo n.º 2
0
 public HookInjector(Injector injector, MethodDefinition originalMethod, MethodReference customMethodReference, MethodHookType hookType, MethodHookFlags hookFlags)
 {
     Injector = injector;
     OriginalMethod = originalMethod;
     CustomMethodReference = customMethodReference;
     HookType = hookType;
     HookFlags = hookFlags;
     GenericArguments = new TypeReference[originalMethod.GenericParameters.Count];
     if (originalMethod.HasGenericParameters)
     {
         //throw new NotImplementedException("Hooking generic instances? Never tested it yet. Contact creator, pls!");
         for (var i = 0; i < originalMethod.GenericParameters.Count; i++)
         {
             GenericArguments[i] = originalMethod.GenericParameters[i];
         }
     }
     originalMethod.Body.SimplifyMacros();
     ILGen = OriginalMethod.Body.GetILProcessor();
 }
Exemplo n.º 3
0
 public CustomLoadArgsHookInjector(Injector inj, List<Tuple<OpCode, byte?>> instructionData, MethodDefinition methodBase, MethodReference methodInfo, MethodHookType methodHookType, MethodHookFlags methodHookFlags)
     : base(inj, methodBase, methodInfo, methodHookType, methodHookFlags)
 {
     this.instructionData = instructionData;
 }