public static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions, ILGenerator gen)
        {
            TranspilerHelper.CILProcessor       p       = TranspilerHelper.CreateProcessor(instructions, gen);
            TranspilerHelper.CILProcessor.ILRef loopRef = p.FindRefByInsns(new CodeInstruction[] {
                new CodeInstruction(OpCodes.Ldarg_0),
                new CodeInstruction(OpCodes.Ldfld, "System.Int32 exp"),
                new CodeInstruction(OpCodes.Ldc_I4_0),
                new CodeInstruction(OpCodes.Bgt)
            });
            TranspilerHelper.CILProcessor.ILRef branchRef = p.FindRefByInsn(new CodeInstruction(OpCodes.Br, p.GetInsn(loopRef).labels[0]));
            List <Label> labels = p.GetInsn(branchRef).labels;

            p.RemoveInsns(branchRef, loopRef.Index - branchRef.Index);
            TranspilerHelper.CILProcessor.ILRef newRef = p.InjectInsns(loopRef, new CodeInstruction[] {
                new CodeInstruction(OpCodes.Ldarg_0),
                new CodeInstruction(OpCodes.Ldfld, t),
                new CodeInstruction(OpCodes.Callvirt, get_position)
            });
            p.InjectInsns(loopRef.GetRefByOffset(2), new CodeInstruction[] {
                new CodeInstruction(OpCodes.Ldc_R4, 0f),
                new CodeInstruction(OpCodes.Call, SpawnExp)
            }, false);
            p.GetInsn(newRef).labels.AddRange(labels);
            return(p.Insns);
        }
        public static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions, ILGenerator gen)
        {
            TranspilerHelper.CILProcessor p = TranspilerHelper.CreateProcessor(instructions, gen);

            TranspilerHelper.CILProcessor.ILRef recordRef = p.FindRefByInsns(new CodeInstruction[] {
                new CodeInstruction(OpCodes.Ldsfld, "System.Int32[] record"),
                new CodeInstruction(OpCodes.Ldsfld, "System.Int32 curBiome"),
                new CodeInstruction(OpCodes.Ldelema, "System.Int32"),
                new CodeInstruction(OpCodes.Dup),
                new CodeInstruction(OpCodes.Ldind_I4),
                new CodeInstruction(OpCodes.Ldc_I4_1),
                new CodeInstruction(OpCodes.Add),
                new CodeInstruction(OpCodes.Stind_I4)
            });

            Label label = gen.DefineLabel();

            p.GetInsn(recordRef.GetRefByOffset(8)).labels.Add(label);
            p.InjectInsn(recordRef, p.GetInsn(recordRef.GetRefByOffset(1)));
            p.InjectInsn(recordRef, new CodeInstruction(OpCodes.Ldc_I4_8));
            p.InjectInsn(recordRef, new CodeInstruction(OpCodes.Bge, label));

            TranspilerHelper.CILProcessor.ILRef loopRef = p.FindRefByInsns(new CodeInstruction[] {
                new CodeInstruction(OpCodes.Ldarg_0),
                new CodeInstruction(OpCodes.Ldfld, "System.Int32 exp"),
                new CodeInstruction(OpCodes.Ldc_I4_0),
                new CodeInstruction(OpCodes.Bgt)
            });
            TranspilerHelper.CILProcessor.ILRef branchRef = p.FindRefByInsn(new CodeInstruction(OpCodes.Br, p.GetInsn(loopRef).labels[0]));
            List <Label> labels = p.GetInsn(branchRef).labels;

            p.RemoveInsns(branchRef, loopRef.Index - branchRef.Index);
            TranspilerHelper.CILProcessor.ILRef newRef = p.InjectInsns(loopRef, new CodeInstruction[] {
                new CodeInstruction(OpCodes.Ldarg_0),
                new CodeInstruction(OpCodes.Ldfld, t),
                new CodeInstruction(OpCodes.Callvirt, get_position)
            });
            p.InjectInsns(loopRef.GetRefByOffset(2), new CodeInstruction[] {
                new CodeInstruction(OpCodes.Ldc_R4, 0f),
                new CodeInstruction(OpCodes.Call, SpawnExp)
            }, false);
            p.GetInsn(newRef).labels.AddRange(labels);
            return(p.Insns);
        }