Exemple #1
0
        private void InjectOnionDoWorldGen()
        {
            try
            {
                var doWorldGenInitialiseBody = CecilHelper.GetMethodDefinition(_csharpModule, "OfflineWorldGen", "DoWordGenInitialise").Body;

                var callResetInstruction = doWorldGenInitialiseBody
                                           .Instructions
                                           .Where(instruction => instruction.OpCode == OpCodes.Call)
                                           .Reverse()
                                           .Skip(3)
                                           .First();

                var instructionInserter = new InstructionInserter(doWorldGenInitialiseBody);

                instructionInserter.InsertBefore(callResetInstruction, Instruction.Create(OpCodes.Pop));
                instructionInserter.InsertBefore(callResetInstruction, Instruction.Create(OpCodes.Pop));

                _onionToCSharpInjector.InjectBefore(
                    "Hooks", "OnDoOfflineWorldGen",
                    doWorldGenInitialiseBody,
                    callResetInstruction);

                _csharpInstructionRemover.ReplaceByNop(doWorldGenInitialiseBody, callResetInstruction);
            }
            catch (Exception e)
            {
                Logger.Log("World generation injection failed");
                Logger.Log(e);

                Failed = true;
            }
        }
Exemple #2
0
        private void AddOverlayButtonSprite()
        {
            try
            {
                MethodBody body = this._csharpModule.Types.FirstOrDefault(t => t.Name == "KIconToggleMenu")?.Methods
                                  .FirstOrDefault(m => m.Name == "RefreshButtons")?.Body;
                Instruction targetInstruction =
                    body?.Instructions.Reverse().Skip(5).FirstOrDefault(i => i.OpCode == OpCodes.Callvirt);

                InstructionInserter inserter = new InstructionInserter(body);

                inserter.InsertBefore(targetInstruction, Instruction.Create(OpCodes.Ldloc, body?.Variables[5]));

                this._onionToCSharpInjector.InjectBefore(
                    "OverlayMenuManager",
                    "EnterToggleSprite",
                    body,
                    targetInstruction,
                    includeCallingObject: true);
            }
            catch (Exception e)
            {
                Console.WriteLine("Toggle change sprite failed");
                Console.WriteLine(e);

                this.Failed = true;
            }
        }
Exemple #3
0
        private void InjectCellColorHandling()
        {
            _csharpInstructionRemover.ClearAllButLast("BlockTileRenderer", "GetCellColour");

            _materialToCSharpInjector.InjectAsFirst(
                "InjectionEntry", "EnterCell",
                "BlockTileRenderer", "GetCellColour",
                true, 1);

            _csharpPublisher.MakeFieldPublic("BlockTileRenderer", "selectedCell");
            _csharpPublisher.MakeFieldPublic("BlockTileRenderer", "highlightCell");
            _csharpPublisher.MakeFieldPublic("BlockTileRenderer", "invalidPlaceCell");

            var deconstructable = _csharpModule.Types.FirstOrDefault(t => t.Name == "Deconstructable");

            if (deconstructable != null)
            {
                var onCompleteWorkBody = deconstructable.Methods.FirstOrDefault(m => m.Name == "OnCompleteWork").Body;

                if (onCompleteWorkBody != null)
                {
                    var lastInstruction = onCompleteWorkBody.Instructions.LastOrDefault();

                    if (lastInstruction != null)
                    {
                        var inserter = new InstructionInserter(onCompleteWorkBody);

                        inserter.InsertBefore(lastInstruction, Instruction.Create(OpCodes.Ldloc_3));
                        _materialToCSharpInjector.InjectBefore("InjectionEntry", "ResetCell", onCompleteWorkBody, lastInstruction);
                    }
                    else
                    {
                        Logger.Log("Couldn't find last instruction at Deconstructable.OnCompleteWork method");

                        Failed = true;
                    }
                }
                else
                {
                    Logger.Log("Couldn't find method at Deconstructable.OnCompleteWork");

                    Failed = true;
                }
            }
            else
            {
                Logger.Log("Couldn't find type: Deconstructable");

                Failed = true;
            }
        }