Пример #1
0
        static IEnumerable <Harmony12.CodeInstruction> Transpiler(IEnumerable <Harmony12.CodeInstruction> instructions)
        {
            var codes        = instructions.ToList();
            var check_shield = codes.FindIndex(x => x.opcode == System.Reflection.Emit.OpCodes.Callvirt && x.operand.ToString().Contains("HasShield"));

            codes[check_shield] = new Harmony12.CodeInstruction(System.Reflection.Emit.OpCodes.Call, new Func <HandSlot, bool>(Helpers.hasShield2).Method);
            return(codes.AsEnumerable());
        }
        static IEnumerable <Harmony12.CodeInstruction> Transpiler(IEnumerable <Harmony12.CodeInstruction> instructions)
        {
            var codes            = instructions.ToList();
            var check_is_unarmed = codes.FindIndex(x => x.opcode == System.Reflection.Emit.OpCodes.Callvirt && x.operand.ToString().Contains("IsUnarmed")); //checking is unarmed on weapon on primary hand

            codes[check_is_unarmed] = new Harmony12.CodeInstruction(System.Reflection.Emit.OpCodes.Ldarg_1);
            codes.Insert(check_is_unarmed + 1, new Harmony12.CodeInstruction(System.Reflection.Emit.OpCodes.Call, new Func <BlueprintItemWeapon, UnitDescriptor, bool>(considerUnarmedAndIgnore).Method));

            check_is_unarmed        = codes.FindIndex(x => x.opcode == System.Reflection.Emit.OpCodes.Callvirt && x.operand.ToString().Contains("IsUnarmed")); //checking is unarmed on weapon on secondary hand
            codes[check_is_unarmed] = new Harmony12.CodeInstruction(System.Reflection.Emit.OpCodes.Ldarg_1);
            codes.Insert(check_is_unarmed + 1, new Harmony12.CodeInstruction(System.Reflection.Emit.OpCodes.Call, new Func <BlueprintItemWeapon, UnitDescriptor, bool>(considerUnarmedAndIgnoreOffHand).Method));
            return(codes.AsEnumerable());
        }
        static IEnumerable <Harmony12.CodeInstruction> Transpiler(IEnumerable <Harmony12.CodeInstruction> instructions)
        {
            List <Harmony12.CodeInstruction> codes = new List <Harmony12.CodeInstruction>();

            try
            {
                codes = instructions.ToList();
                var trigger_attack_idx = codes.FindIndex(x => x.opcode == System.Reflection.Emit.OpCodes.Call && x.operand.ToString().Contains("Trigger"));
                codes[trigger_attack_idx] = new Harmony12.CodeInstruction(System.Reflection.Emit.OpCodes.Call, new Func <RuleAttackWithWeapon, RuleAttackWithWeapon>(performAttackOrManeuver).Method);
            }
            catch (Exception ex)
            {
                Main.logger.Log(ex.ToString());
            }

            return(codes.AsEnumerable());
        }
Пример #4
0
        public static IEnumerable <Harmony12.CodeInstruction> Deliver_Transpiler(IEnumerable <Harmony12.CodeInstruction> instructions)
        {
            List <Harmony12.CodeInstruction> codes = new List <Harmony12.CodeInstruction>();

            try
            {
                codes = instructions.ToList();
                var load_this        = codes.Find(x => x.opcode == System.Reflection.Emit.OpCodes.Ldfld && x.operand.ToString().Contains("this"));
                var find_threat_hand = codes.FindIndex(x => x.opcode == System.Reflection.Emit.OpCodes.Call && x.operand.ToString().Contains("GetThreatHand"));
                codes[find_threat_hand] = new Harmony12.CodeInstruction(System.Reflection.Emit.OpCodes.Call, new Func <UnitEntityData, AbilityCustomMeleeAttack, WeaponSlot>(getWeaponSlot).Method);
                codes.InsertRange(find_threat_hand, new Harmony12.CodeInstruction[] { new Harmony12.CodeInstruction(System.Reflection.Emit.OpCodes.Ldarg_0), load_this });
            }
            catch (Exception ex)
            {
                Main.logger.Log(ex.ToString());
            }

            return(codes.AsEnumerable());
        }
        static IEnumerable <Harmony12.CodeInstruction> Transpiler(IEnumerable <Harmony12.CodeInstruction> instructions)
        {
            List <Harmony12.CodeInstruction> codes = new List <Harmony12.CodeInstruction>();

            try
            {
                codes = instructions.ToList();
                var immune_to_visual_idx = codes.FindIndex(x => x.opcode == System.Reflection.Emit.OpCodes.Callvirt && x.operand.ToString().Contains("IsImmuneToVisualEffects"));
                codes[immune_to_visual_idx - 1] = new Harmony12.CodeInstruction(System.Reflection.Emit.OpCodes.Ldarg_0); //add this == RuleAttackRoll (instead of Initiator.getDescriptor)
                codes[immune_to_visual_idx]     = new Harmony12.CodeInstruction(System.Reflection.Emit.OpCodes.Call,
                                                                                new Func <UnitEntityData, RuleAttackRoll, bool>(ignoreMirrorImage).Method
                                                                                );
            }
            catch (Exception ex)
            {
                Main.logger.Log(ex.ToString());
            }

            return(codes.AsEnumerable());
        }
Пример #6
0
        static IEnumerable <Harmony12.CodeInstruction> Transpiler(IEnumerable <Harmony12.CodeInstruction> instructions)
        {
            List <Harmony12.CodeInstruction> codes = new List <Harmony12.CodeInstruction>();

            try
            {
                codes = instructions.ToList();
                var is_flanked_idx = codes.FindIndex(x => x.opcode == System.Reflection.Emit.OpCodes.Callvirt && x.operand.ToString().Contains("IsFlanked"));
                codes[is_flanked_idx] = new Harmony12.CodeInstruction(System.Reflection.Emit.OpCodes.Call, new Func <UnitEntityData, UnitEntityData, bool>(Flanking.isFlankedByAttacker).Method);
                codes.RemoveAt(is_flanked_idx - 1);
                codes.InsertRange(is_flanked_idx - 1, new Harmony12.CodeInstruction[] { new Harmony12.CodeInstruction(System.Reflection.Emit.OpCodes.Ldarg_0),
                                                                                        new Harmony12.CodeInstruction(System.Reflection.Emit.OpCodes.Ldfld,
                                                                                                                      typeof(Kingmaker.RuleSystem.RulebookEvent).GetField("Initiator")) }
                                  );
            }
            catch (Exception ex)
            {
                Main.logger.Log(ex.ToString());
            }

            return(codes.AsEnumerable());
        }
        public static IEnumerable <Harmony12.CodeInstruction> AnimateEquipmentChangeInCombat_Transpiler(IEnumerable <Harmony12.CodeInstruction> instructions)
        {
            List <Harmony12.CodeInstruction> codes = new List <Harmony12.CodeInstruction>();

            try
            {
                codes = instructions.ToList();
                var check_cooldown_idx = codes.FindIndex(x => x.opcode == System.Reflection.Emit.OpCodes.Callvirt && x.operand.ToString().Contains("HasCooldownForCommand"));
                codes[check_cooldown_idx - 1] = new Harmony12.CodeInstruction(System.Reflection.Emit.OpCodes.Call, new Func <Kingmaker.Controllers.Combat.UnitCombatState, bool>(cannotChangeEquipment).Method);
                codes[check_cooldown_idx]     = new Harmony12.CodeInstruction(System.Reflection.Emit.OpCodes.Nop); //to keep same length
                //codes.RemoveAt(check_cooldown_idx);
                //codes[check_cooldown_idx - 1].opcode = System.Reflection.Emit.OpCodes.Ldc_I4_3; //replace with move action

                var set_cooldown_idx = codes.FindIndex(x => x.opcode == System.Reflection.Emit.OpCodes.Callvirt && x.operand.ToString().Contains("set_StandardAction"));
                codes[set_cooldown_idx - 2] = new Harmony12.CodeInstruction(System.Reflection.Emit.OpCodes.Call, new Action <Kingmaker.Controllers.Combat.UnitCombatState>(consumeMoveAction).Method);
                codes[set_cooldown_idx - 1] = new Harmony12.CodeInstruction(System.Reflection.Emit.OpCodes.Nop);
                codes[set_cooldown_idx]     = new Harmony12.CodeInstruction(System.Reflection.Emit.OpCodes.Nop);
                codes.InsertRange(set_cooldown_idx, new Harmony12.CodeInstruction[] {
                    new Harmony12.CodeInstruction(System.Reflection.Emit.OpCodes.Nop),
                    new Harmony12.CodeInstruction(System.Reflection.Emit.OpCodes.Nop),
                    new Harmony12.CodeInstruction(System.Reflection.Emit.OpCodes.Nop),
                    new Harmony12.CodeInstruction(System.Reflection.Emit.OpCodes.Nop),
                    new Harmony12.CodeInstruction(System.Reflection.Emit.OpCodes.Nop),
                    new Harmony12.CodeInstruction(System.Reflection.Emit.OpCodes.Nop),
                    new Harmony12.CodeInstruction(System.Reflection.Emit.OpCodes.Nop),
                    new Harmony12.CodeInstruction(System.Reflection.Emit.OpCodes.Nop)
                });                                                                    // to keep the same size

                //codes[set_cooldown_idx].operand = typeof(Kingmaker.Controllers.Combat.UnitCombatState.Cooldowns).GetMethod("set_MoveAction");
                //codes[set_cooldown_idx - 1].operand = 3.0f;
            }
            catch (Exception ex)
            {
                Main.logger.Log(ex.ToString());
            }

            return(codes.AsEnumerable());
        }