Esempio n. 1
0
        static IEnumerable <CodeInstruction> UpdateTranspiler(IEnumerable <CodeInstruction> instructions)
        {
            Debug.Log("UpdateTranspiler começou");

            List <int> indexesOfLandingCamSeq = new List <int>();

            var codes = new List <CodeInstruction>(instructions);

            //Achar a sequencia e colocar na lista
            for (var i = 0; i < codes.Count; i++)
            {
                if (codes[i].opcode == OpCodes.Ldarg_0 && codes[i + 1].opcode == OpCodes.Ldfld &&
                    codes[i + 2].opcode == OpCodes.Callvirt)
                {
                    if (codes[i + 1].LoadsField(AccessTools.Field(typeof(FlightConsole), "_landingCam")))
                    {
                        indexesOfLandingCamSeq.Add(i);
                    }

                    else
                    {
                        i += 2;
                    }
                }
            }

            if (indexesOfLandingCamSeq.Count > 0)
            {
                //Ir tirando e colocando de tras para frente na lista para uqe os valores adquiridos nela não fiquem atrasados

                for (int i = indexesOfLandingCamSeq.Count - 1; i > -1; i--)
                {
                    codes.RemoveRange(indexesOfLandingCamSeq[i], 3);

                    codes.Insert(indexesOfLandingCamSeq[i], HarmonyCodeInstructionsConstructors.Call(typeof(CoolerBottomCams), "IsShipCameraOn"));
                }

                Debug.Log("Criar os CodeInstructions de UpdateTranspiler foi um sucesso");
            }

            foreach (CodeInstruction ci in codes)
            {
                //Debug.Log($"Opcode: {ci.opcode} ; Operand: {ci.operand}");

                yield return(ci);
            }
        }
Esempio n. 2
0
        static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions)
        {
            Debug.Log("Transpiler de Marshmallow_ResetMarshmallowPatch começou");


            var codes = new List <CodeInstruction>(instructions);

            int index1 = -1;
            int index2 = codes.Count - 1;

            //Achar aonde colocar as instruções
            for (var i = 0; i < index2 + 1; i++)
            {
                if (codes[i].opcode == OpCodes.Ret)
                {
                    index1 = i - 1;
                    break;
                }
            }



            //Se achado colocar elas lá
            if (index1 > -1 && index2 > -1)
            {
                codes.Insert(index1, new CodeInstruction(OpCodes.Ldarg_0));
                codes.Insert(index1 + 1, HarmonyCodeInstructionsConstructors.LoadField(typeof(Marshmallow), "_mallowRenderer"));
                codes.Insert(index1 + 2, HarmonyCodeInstructionsConstructors.Call(typeof(EnhancedMallows), "DefaultMallowScale", new Type[] { typeof(Renderer) }));

                codes.Insert(index2, new CodeInstruction(OpCodes.Ldarg_0));
                codes.Insert(index2 + 1, HarmonyCodeInstructionsConstructors.LoadField(typeof(Marshmallow), "_mallowRenderer"));
                codes.Insert(index2 + 2, HarmonyCodeInstructionsConstructors.Call(typeof(EnhancedMallows), "DefaultMallowScale", new Type[] { typeof(Renderer) }));

                Debug.Log("Criar os CodeInstructions de Marshmallow_ResetMarshmallowPatch foi um sucesso");
            }



            foreach (CodeInstruction ci in codes)
            {
                //Debug.Log($"Opcode: {ci.opcode} ; Operand: {ci.operand}");
                yield return(ci);
            }
        }
Esempio n. 3
0
        static IEnumerable <CodeInstruction> ExitFlightConsoleTranspiler(IEnumerable <CodeInstruction> instructions)
        {
            Debug.Log("ExitFlightConsoleTranspiler começou");

            int index = -1;


            var codes = new List <CodeInstruction>(instructions);


            for (var i = 0; i < codes.Count; i++)
            {
                //Achar por essa sequencia
                if (codes[i].opcode == OpCodes.Ldfld && codes[i + 1].opcode == OpCodes.Callvirt && codes[i + 2].opcode == OpCodes.Brtrue)
                {
                    index = i - 1;

                    break;
                }
            }

            //Tirar a sequencia e adicionar o call que queremos
            if (index > -1)
            {
                codes.RemoveRange(index, 3);

                codes.Insert(index, HarmonyCodeInstructionsConstructors.Call(typeof(CoolerBottomCams), "IsShipCameraOn"));

                Debug.Log("Criar os CodeInstructions de ExitFlightConsoleTranspiler foi um sucesso");
            }

            foreach (CodeInstruction ci in codes)
            {
                //Debug.Log($"Opcode: {ci.opcode} ; Operand: {ci.operand}");

                yield return(ci);
            }
        }
Esempio n. 4
0
        /* static public AccessTools.FieldRef<Marshmallow, Renderer> mallowRenderer =
         *  AccessTools.FieldRefAccess<Marshmallow, Renderer>("_mallowRenderer");
         *
         * static public AccessTools.FieldRef<Marshmallow, float> toastLevel =
         *  AccessTools.FieldRefAccess<Marshmallow, float>("_toastLevel"); */


        static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions)
        {
            Debug.Log("Transpiler de Marshmallow_UpdatePatch começou");

            int index = -1;


            var codes = new List <CodeInstruction>(instructions);


            for (var i = 0; i < codes.Count; i++)
            {
                if (codes[i].opcode == OpCodes.Ldc_R4 && codes[i + 1].opcode == OpCodes.Add && codes[i + 2].opcode == OpCodes.Stfld)//ldc.r4
                {
                    index = i + 3;

                    break;
                }
            }
            if (index > -1)
            {
                codes.Insert(index, new CodeInstruction(OpCodes.Ldarg_0));
                codes.Insert(index + 1, HarmonyCodeInstructionsConstructors.LoadField(typeof(Marshmallow), "_mallowRenderer"));
                codes.Insert(index + 2, new CodeInstruction(OpCodes.Ldarg_0));
                codes.Insert(index + 3, HarmonyCodeInstructionsConstructors.LoadField(typeof(Marshmallow), "_toastLevel"));
                codes.Insert(index + 4, HarmonyCodeInstructionsConstructors.Call(typeof(EnhancedMallows), "ChangeMallowScale", new Type[] { typeof(Renderer), typeof(float) }));

                Debug.Log("Criar os CodeInstructions de Marshmallow_UpdatePatch foi um sucesso");
            }

            foreach (CodeInstruction ci in codes)
            {
                //Debug.Log($"Opcode: {ci.opcode} ; Operand: {ci.operand}");

                yield return(ci);
            }
        }
Esempio n. 5
0
        static IEnumerable <CodeInstruction> UpdateLandingModeTranspiler(IEnumerable <CodeInstruction> instructions)
        {
            Debug.Log("UpdateLandingModeTranspiler começou");

            List <int> indexesOfLandingCamSeq = new List <int>();

            int index1 = -1; // do _landingCam
            int index2 = -1; // do _playerCam

            var codes = new List <CodeInstruction>(instructions);

            //Achar o primeiro tipo de sequencia e dependedo do que ldfld está chamando, colcoar no index1 ou index2
            for (var i = 0; i < codes.Count; i++)
            {
                if (index1 == -1 || index2 == -1)
                {
                    if (codes[i].opcode == OpCodes.Ldarg_0 && codes[i + 1].opcode == OpCodes.Ldfld &&
                        codes[i + 3].opcode == OpCodes.Callvirt)
                    {
                        if (codes[i + 1].LoadsField(AccessTools.Field(typeof(FlightConsole), "_landingCam")))
                        {
                            index1 = i;
                        }

                        else if (codes[i + 1].LoadsField(AccessTools.Field(typeof(FlightConsole), "_playerCam")))
                        {
                            index2 = i;
                        }
                    }
                }

                else
                {
                    if (codes[i].opcode == OpCodes.Ldarg_0 && codes[i + 1].opcode == OpCodes.Ldfld &&
                        codes[i + 2].opcode == OpCodes.Callvirt)
                    {
                        if (codes[i + 1].LoadsField(AccessTools.Field(typeof(FlightConsole), "_landingCam")))
                        {
                            indexesOfLandingCamSeq.Add(i);
                        }

                        else
                        {
                            i += 2;
                        }
                    }
                }
            }
            if (index1 > -1 && index2 > -1 && indexesOfLandingCamSeq.Count > 0)
            {
                //Ir de tras para frente nos valores achados para que eles não percam sentido

                for (int i = indexesOfLandingCamSeq.Count - 1; i > -1; i--)
                {
                    codes.RemoveRange(indexesOfLandingCamSeq[i], 3);

                    codes.Insert(indexesOfLandingCamSeq[i], HarmonyCodeInstructionsConstructors.Call(typeof(CoolerBottomCams), "IsShipCameraOn"));
                }

                codes.RemoveRange(index2, 4);

                codes.RemoveRange(index1, 4);
                codes.Insert(index1, HarmonyCodeInstructionsConstructors.Call(typeof(CoolerBottomCams), "SetTrueRenderizarNaTela"));

                Debug.Log("Criar os CodeInstructions de UpdateLandingModeTranspiler foi um sucesso");
            }

            foreach (CodeInstruction ci in codes)
            {
                //Debug.Log($"Opcode: {ci.opcode} ; Operand: {ci.operand}");

                yield return(ci);
            }
        }