Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
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);
            }
        }