/// <summary>
        /// Fixes the graphical bug where the enemy ship is "spawned" beneath the player ship after it is destroyed.
        /// </summary>
        private void Structures_resetShipDataCoroutine_Fix()
        {
            ModuleDefinition unityModule = Injector.GetModuleZ("UnityEngine.dll");

            TypeDefinition structuresDef          = GameModule.GetTypeByName("Structures");
            TypeDefinition resetShipDataCoroutine = structuresDef.NestedTypes.Where(t => t.Name.Contains("resetShipDataCoroutine")).FirstOrDefault();

            MethodDefinition toggleShipVisual = structuresDef.GetMethodByName("toggleShipVisual");

            MethodDefinition moveNextMethod      = resetShipDataCoroutine.GetMethodByName("MoveNext");
            FieldDefinition  f_thisField         = resetShipDataCoroutine.GetFieldByName("<>f__this");
            MethodDefinition gameObjectGetMethod = unityModule.GetTypeByName("Component").GetPropertyByName("gameObject").GetMethod;



            Instruction[] instructions = new Instruction[] {
                Instruction.Create(OpCodes.Ldarg_0),
                Instruction.Create(OpCodes.Ldfld, GameModule.Import(f_thisField)),
                Instruction.Create(OpCodes.Ldc_I4_0),
                Instruction.Create(OpCodes.Callvirt, GameModule.Import(toggleShipVisual))
            };

            ILProcessor processor = moveNextMethod.Body.GetILProcessor();

            Instruction lastInstruction = moveNextMethod.Body.Instructions.Where(i => i.OpCode == OpCodes.Callvirt && ((MethodReference)i.Operand).Name.Contains("set_position")).FirstOrDefault();

            foreach (Instruction ins in instructions)
            {
                processor.InsertAfter(lastInstruction, ins);
                lastInstruction = ins;
            }
        }
        /// <summary>
        /// Fixes the graphical bug where the enemy ship is "spawned" beneath the player ship after it is destroyed.
        /// </summary>
        private void ManagerOptions_flyEnemyOutOfSceneCR_Fix()
        {
            TypeDefinition managerOptions       = GameModule.GetTypeByName("ManagerOptions");
            TypeDefinition flyEnemyOutOfSceneCR = managerOptions.NestedTypes.Where(t => t.Name.Contains("flyEnemyOutOfSceneCR")).FirstOrDefault();

            TypeDefinition   bugFixes         = ModLibModule.GetTypeByName("__BugFixes");
            MethodDefinition toggleShipVisual = bugFixes.GetMethodByName("ToggleShipVisual");

            MethodDefinition moveNextMethod = flyEnemyOutOfSceneCR.GetMethodByName("MoveNext");
            FieldDefinition  f_thisField    = flyEnemyOutOfSceneCR.GetFieldByName("<>f__this");
            FieldDefinition  enemyShipField = f_thisField.FieldType.Resolve().GetFieldByName("EnemyShip");

            Instruction[] instructions = new Instruction[] {
                Instruction.Create(OpCodes.Ldarg_0),
                Instruction.Create(OpCodes.Ldfld, GameModule.Import(f_thisField)),
                Instruction.Create(OpCodes.Ldfld, GameModule.Import(enemyShipField)),
                Instruction.Create(OpCodes.Ldc_I4_0),
                Instruction.Create(OpCodes.Callvirt, GameModule.Import(toggleShipVisual))
            };

            ILProcessor processor = moveNextMethod.Body.GetILProcessor();

            Instruction lastInstruction = moveNextMethod.Body.Instructions.Where(i => i.OpCode == OpCodes.Callvirt && ((MethodReference)i.Operand).Name.Contains("playSoundEnemyWarpOut")).FirstOrDefault();

            foreach (Instruction ins in instructions)
            {
                processor.InsertAfter(lastInstruction, ins);
                lastInstruction = ins;
            }
        }
示例#3
0
        public override void Inject()
        {
            TypeDefinition ManagerDef = GameModule.GetTypeByName("ManagerOptions");

            TypeDefinition   ModGUIDef          = ModLibModule.GetTypeByName("ModGUI");
            MethodDefinition CreateModGUIMethod = ModGUIDef.GetMethodByName("__Create");
            MethodDefinition ManagerStartMethod = ManagerDef.GetMethodByName("Start");

            ManagerStartMethod.Body.GetILProcessor().InjectInstructionsToEnd(new Instruction[] {
                Instruction.Create(OpCodes.Callvirt, GameModule.Import(CreateModGUIMethod)),
            });
        }
        private void InjectModLoaderGameSaved(TypeDefinition gameEventsDef, TypeDefinition managerDef)
        {
            MethodDefinition GameSavedMethod = gameEventsDef.GetMethodByName("__OnGameSaved");
            MethodDefinition ManagerSaveGameIntoSlotMethod = managerDef.GetMethodByName("saveGameIntoSlot");

            List <Instruction> Instructions = new List <Instruction>()
            {
                Instruction.Create(OpCodes.Ldarg_1),
                Instruction.Create(OpCodes.Callvirt, GameModule.Import(GameSavedMethod))
            };

            ManagerSaveGameIntoSlotMethod.Body.GetILProcessor().InjectInstructionsToEnd(Instructions);
        }
示例#5
0
        public override void Inject()
        {
            TypeDefinition   saveLoadDataType   = ModLibModule.GetTypeByName("SaveLoadData");
            MethodDefinition saveLoadInitMethod = saveLoadDataType.GetMethodByName("__Init");

            TypeDefinition   ES2InitType   = GameModule.GetTypeByName("ES2Init");
            MethodDefinition ES2InitMethod = ES2InitType.GetMethodByName("Init");

            Instruction insertAfter = ES2InitMethod.Body.Instructions[ES2InitMethod.Body.Instructions.Count - 4];

            ES2InitMethod.Body.GetILProcessor().InsertAfter(insertAfter, new Instruction[] {
                Instruction.Create(OpCodes.Callvirt, GameModule.Import(saveLoadInitMethod))
            });
        }
        private void InjectModLoaderLoadMods(TypeDefinition ModLoaderDef, TypeDefinition ManagerDef)
        {
            FieldDefinition  ModLoaderFieldDef       = ManagerDef.GetFieldByName("ModLoader");
            MethodDefinition ModLoaderLoadModsMethod = ModLoaderDef.GetMethodByName("__LoadMods");
            MethodDefinition ManagerStartMethod      = ManagerDef.GetMethodByName("Start");

            List <Instruction> Instructions = new List <Instruction>()
            {
                Instruction.Create(OpCodes.Ldsfld, GameModule.Import(ModLoaderFieldDef)),
                Instruction.Create(OpCodes.Callvirt, GameModule.Import(ModLoaderLoadModsMethod))
            };

            ManagerStartMethod.Body.GetILProcessor().InjectInstructionsToEnd(Instructions);
        }
        private void InjectModLoaderGameStarted(TypeDefinition gameEventsDef, TypeDefinition managerDef)
        {
            MethodDefinition GameStartedMethod = gameEventsDef.GetMethodByName("__OnGameStarted");
            MethodDefinition ManagerLoadDefaultPlayerShipMethod = managerDef.GetMethodByName("loadDefaultPlayerShip");

            Instruction loadText   = ManagerLoadDefaultPlayerShipMethod.Body.Instructions.Where(i => i.OpCode == OpCodes.Ldstr && i.Operand.ToString() == "loading default from script").FirstOrDefault();
            Instruction beforeText = loadText.Previous;

            Instruction endText = beforeText.Operand as Instruction;

            List <Instruction> Instructions = new List <Instruction>()
            {
                Instruction.Create(OpCodes.Callvirt, GameModule.Import(GameStartedMethod))
            };

            ManagerLoadDefaultPlayerShipMethod.Body.GetILProcessor().InsertBefore(endText, Instructions);
        }
示例#8
0
        private void NewPanelOpened()
        {
            TypeDefinition   MenuEventsDef        = ModLibModule.GetTypeByName("MenuEvents");
            MethodDefinition OnNewGamePanelOpened = MenuEventsDef.GetMethodByName("__OnNewGamePanelOpened");

            TypeDefinition   ManagerMenuDef = GameModule.GetTypeByName("ManagerMenu");
            MethodDefinition Method         = ManagerMenuDef.GetMethodByName("createNewGamePanel");

            FieldDefinition rightMenuFieldDef = ManagerMenuDef.GetFieldByName("mainMenuRight");

            Instruction[] instructions = new Instruction[] {
                Instruction.Create(OpCodes.Ldarg_0),
                Instruction.Create(OpCodes.Ldfld, GameModule.Import(rightMenuFieldDef)),
                Instruction.Create(OpCodes.Callvirt, GameModule.Import(OnNewGamePanelOpened))
            };

            Method.Body.GetILProcessor().InjectInstructionsToEnd(instructions);
        }
        private void InjectModLoaderField(TypeDefinition ModLoaderDef, TypeDefinition ManagerDef)
        {
            MethodDefinition ModLoaderCtor = ModLoaderDef.GetMethodByName(".ctor");

            MethodDefinition ManagerCctor = ManagerDef.GetMethodByName(".cctor");

            FieldDefinition ModLoaderFieldDef = new FieldDefinition("ModLoader", FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.InitOnly, GameModule.Import(ModLoaderDef));

            ManagerDef.Fields.Add(ModLoaderFieldDef);

            List <Instruction> Instructions = new List <Instruction>()
            {
                Instruction.Create(OpCodes.Newobj, GameModule.Import(ModLoaderCtor)),
                Instruction.Create(OpCodes.Stsfld, ModLoaderFieldDef)
            };

            ManagerCctor.Body.GetILProcessor().InjectInstructionsToEnd(Instructions);
        }
        public override void Inject()
        {
            TypeDefinition   CostsDef  = ModLibModule.GetTypeByName("Costs");
            MethodDefinition CostsCtor = CostsDef.GetMethodByName(".ctor");
            MethodDefinition CostsGetResourceRequirementsMethod = CostsDef.GetMethodByName("GetResourceRequirements");

            GameModule.Import(ModLibModule.GetTypeByName("EntityCost"));

            TypeDefinition   ManagerDef = GameModule.GetTypeByName("ManagerResources");
            MethodDefinition ManagerGetResourceRequirementsMethod = ManagerDef.GetMethodByName("getResourcesRequirement");
            FieldDefinition  CostsFieldDef = new FieldDefinition("Costs", FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.InitOnly, GameModule.Import(CostsDef));

            ManagerDef.Fields.Add(CostsFieldDef);

            MethodDefinition ManagerCtor = ManagerDef.GetMethodByName(".ctor");

            ManagerCtor.Body.GetILProcessor().InjectInstructionsToEnd(new Instruction[] {
                Instruction.Create(OpCodes.Newobj, GameModule.Import(CostsCtor)),
                Instruction.Create(OpCodes.Stsfld, GameModule.Import(CostsFieldDef))
            });

            MethodDefinition logMethod = Injector.GetModuleZ("UnityEngine.dll").GetTypeByName("Debug").GetMethodByName("Log", 1);

            TypeDefinition   stringType          = Injector.GetModuleZ("mscorlib.dll").GetTypeByName("String");
            MethodDefinition isNullOrEmptyMethod = stringType.GetMethodByName("IsNullOrEmpty");
            MethodDefinition concatMethod        = stringType.GetMethodByName("Concat", 4, GameModule.Import(stringType));

            ManagerGetResourceRequirementsMethod.Body.Instructions.Clear();
            ManagerGetResourceRequirementsMethod.Body.GetILProcessor().InjectInstructionsToEnd(new Instruction[] {
                Instruction.Create(OpCodes.Ldsfld, CostsFieldDef),
                Instruction.Create(OpCodes.Ldarg_1),
                Instruction.Create(OpCodes.Ldarg_2),
                Instruction.Create(OpCodes.Callvirt, GameModule.Import(CostsGetResourceRequirementsMethod)),
                Instruction.Create(OpCodes.Ret)
            });

            /*ManagerGetResourceRequirementsMethod.Body.Instructions.Clear();
             *
             * ManagerGetResourceRequirementsMethod.Body.Instructions.Add(Instruction.Create(OpCodes.Ldarg_1));
             * ManagerGetResourceRequirementsMethod.Body.Instructions.Add(Instruction.Create(OpCodes.Ldarg_2));
             * ManagerGetResourceRequirementsMethod.Body.Instructions.Add(Instruction.Create(OpCodes.Callvirt, GameModule.Import(CostsGetResourceRequirementsMethod)));
             * ManagerGetResourceRequirementsMethod.Body.Instructions.Add(Instruction.Create(OpCodes.Ret));*/
        }