Exemplo n.º 1
0
        public static void Init(string directory, string settingsJSON)
        {
            Log = HBS.Logging.Logger.GetLogger("BTX_CAC_Compatibility");
            try
            {
                Sett = JsonConvert.DeserializeObject <Settings>(settingsJSON);
            }
            catch (Exception e)
            {
                Sett = new Settings();
                Log.LogException(e);
            }
            if (Sett.LogLevelLog)
            {
                HBS.Logging.Logger.SetLoggerLevel("BTX_CAC_Compatibility", LogLevel.Log);
            }
            HarmonyInstance harmony = HarmonyInstance.Create("com.github.mcb5637.BTX_CAC_Compatibility");

            harmony.PatchAll(Assembly.GetExecutingAssembly());
            AccessExtensionPatcher.PatchAll(harmony, Assembly.GetExecutingAssembly());
            AbstractActor_InitStats.Patch(harmony);
            AbstractActor_IndirectImmune.Patch(harmony);
            //harmony.Patch(
            //    AccessTools.Method(typeof(EffectManager), "CreateEffect", new Type[] { typeof(EffectData), typeof(string), typeof(int), typeof(ICombatant), typeof(ICombatant), typeof(WeaponHitInfo), typeof(int), typeof(bool) }),
            //    null, new HarmonyMethod(AccessTools.Method(typeof(MarkEffects_Patch), "Postfix")), null);
            //harmony.Patch(AccessTools.DeclaredMethod(typeof(Mech), "DamageLocation"), new HarmonyMethod(AccessTools.Method(typeof(Main), "LogDamageLoc")), null, null);


            if (Sett.MECompat)
            {
                return;
            }

            InfernoExplode.Patch(harmony);

            try
            {
                // artemis
                //Unpatch(harmony, AccessTools.DeclaredMethod(typeof(AttackDirector.AttackSequence), "GetClusteredHits"), "BEX.BattleTech.Extended_CE");
                //Type[] ptypes = new Type[] { typeof(Vector3), typeof(Mech), typeof(float), typeof(ArmorLocation), typeof(float), typeof(float), typeof(ArmorLocation), typeof(float) };
                //Unpatch(harmony, AccessTools.DeclaredMethod(typeof(HitLocation), "GetAdjacentHitLocation", ptypes), "BEX.BattleTech.Extended_CE");
                //ptypes = new Type[] { typeof(Vector3), typeof(Vehicle), typeof(float), typeof(VehicleChassisLocations), typeof(float), typeof(float), typeof(VehicleChassisLocations), typeof(float) };
                //Unpatch(harmony, AccessTools.DeclaredMethod(typeof(HitLocation), "GetAdjacentHitLocation", ptypes), "BEX.BattleTech.Extended_CE");
                // streak
                Unpatch(harmony, AccessTools.DeclaredMethod(typeof(MissileLauncherEffect), "AllMissilesComplete"), "BEX.BattleTech.Extended_CE");
                Unpatch(harmony, AccessTools.DeclaredMethod(typeof(MissileLauncherEffect), "LaunchMissile"), "BEX.BattleTech.Extended_CE");
                Unpatch(harmony, AccessTools.DeclaredMethod(typeof(AttackDirector.AttackSequence), "GetIndividualHits"), "BEX.BattleTech.Extended_CE");
                // stepped hit chance
                Unpatch(harmony, AccessTools.DeclaredMethod(typeof(ToHit), "GetUMChance"), "BEX.BattleTech.Extended_CE");
                // called shot nerf
                //Unpatch(harmony, AccessTools.DeclaredMethod(typeof(Pilot), "InitAbilities"), "BEX.BattleTech.Extended_CE", false, true, false);
                // TSM
                Unpatch(harmony, AccessTools.DeclaredMethod(typeof(Mech), "OnActivationEnd"), "BEX.BattleTech.Extended_CE", false, true, false); // prefix is heat shutdown
                // lbx/uac
                Unpatch(harmony, AccessTools.DeclaredMethod(typeof(Contract), "CompleteContract"), "BEX.BattleTech.Extended_CE", true, true, true,
                        "System.Void Extended_CE.WeaponModes+Contract_CompleteContract.Prefix(BattleTech.Contract __instance)");

                Unpatch(harmony, AccessTools.DeclaredMethod(typeof(AttackEvaluator), "MakeAttackOrder"), "BEX.BattleTech.Extended_CE");
                Unpatch(harmony, AccessTools.DeclaredMethod(typeof(AITeam), "TurnActorProcessActivation"), "BEX.BattleTech.Extended_CE");
                Unpatch(harmony, AccessTools.DeclaredMethod(typeof(CombatHUDWeaponSlot), "OnPointerUp"), "BEX.BattleTech.Extended_CE");
                Unpatch(harmony, AccessTools.DeclaredMethod(typeof(Weapon), "get_AmmoCategoryValue"), "BEX.BattleTech.Extended_CE");
                Unpatch(harmony, AccessTools.DeclaredMethod(typeof(CombatHUDWeaponSlot), "RefreshDisplayedWeapon"), "BEX.BattleTech.Extended_CE", true, false, false); // transpiler is coil fix
                Unpatch(harmony, AccessTools.DeclaredMethod(typeof(MechValidationRules), "ValidateMechHasAppropriateAmmo"), "BEX.BattleTech.Extended_CE");
            }
            catch (Exception e)
            {
                FileLog.Log(e.ToString());
            }

            try
            {
                foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies())
                {
                    if (a.GetName().Name.Equals("MechQuirks"))
                    {
                        Type t = a.GetType("Quirks.Tooltips.QuirkToolTips");
                        harmony.Patch(t.GetMethod("DetailMechQuirks", BindingFlags.Static | BindingFlags.NonPublic), null, new HarmonyMethod(typeof(QuirkToolTips_DetailMechQuirks), "Postfix"), null);
                    }
                }
            }
            catch (Exception e)
            {
                FileLog.Log(e.ToString());
            }

            ToHitModifiersHelper.registerModifier("BTX_CAC_Compatibility_CounterNarc", "Counter NARC", true, true, CounterNarc, null);
        }
        public static float GetRangeModifier(ToHit instance, AbstractActor attacker, Weapon weapon, ICombatant target, Vector3 attackPosition, Vector3 targetPosition, LineOfFireLevel lofLevel, MeleeAttackType meleeAttackType, bool isCalledShot)
        {
            if (attacker.EncounterTags.ContainsAny(Core.Settings._C3NetworkEncounterTags) == false)
            {
                return(ToHitModifiersHelper.GetRangeModifier(instance, attacker, weapon, target, attackPosition, targetPosition, lofLevel, meleeAttackType, isCalledShot));
            }
            float   realDist           = Vector3.Distance(attackPosition, targetPosition);
            float   distance           = realDist;
            float   distMod            = 0f;
            float   minRange           = weapon.MinRange;
            float   shortRange         = weapon.ShortRange;
            float   medRange           = weapon.MediumRange;
            float   longRange          = weapon.LongRange;
            float   maxRange           = weapon.MaxRange;
            Vector3 alternateAttackPos = GetC3CachedPos(attacker, target);

            if (alternateAttackPos != Vector3.zero)
            {
                float alternateDist = Vector3.Distance(alternateAttackPos, targetPosition);
                if (alternateDist < realDist)
                {
                    if (alternateDist < minRange)
                    {
                        distance = minRange;
                    }
                    else
                    {
                        distance = alternateDist;
                    }
                }
            }
            if (distance < minRange)
            {
                distMod = weapon.parent.MinRangeAccMod();
                //Log.LogWrite(" minRange ");
            }
            else
            if (distance < shortRange)
            {
                distMod = weapon.parent.ShortRangeAccMod();
                //Log.LogWrite(" shortRange ");
            }
            else
            if (distance < medRange)
            {
                distMod = weapon.parent.MediumRangeAccMod();
                //Log.LogWrite(" medRange ");
            }
            else
            if (distance < longRange)
            {
                distMod = weapon.parent.LongRangeRangeAccMod();
                //Log.LogWrite(" longRange ");
            }
            else
            if (distance < maxRange)
            {
                distMod = weapon.parent.ExtraLongRangeAccMod();
                //Log.LogWrite(" extraRange ");
            }
            ;
            //return distMod;
            return(distMod + instance.GetRangeModifierForDist(weapon, distance));
        }
        public static string GetRangeModifierName(ToHit instance, AbstractActor attacker, Weapon w, ICombatant target, Vector3 attackPosition, Vector3 targetPosition, LineOfFireLevel lofLevel, MeleeAttackType meleeAttackType, bool isCalledShot, int modifier)
        {
            if (attacker.EncounterTags.ContainsAny(Core.Settings._C3NetworkEncounterTags) == false)
            {
                if (modifier == 0)
                {
                    return(string.Empty);
                }
                return(ToHitModifiersHelper.GetRangeModifierName(instance, attacker, w, target, attackPosition, targetPosition, lofLevel, meleeAttackType, isCalledShot));
            }
            float   real_range         = Vector3.Distance(attackPosition, targetPosition);
            float   range              = real_range;
            float   MinRange           = w.MinRange;
            float   ShortRange         = w.ShortRange;
            float   MediumRange        = w.MediumRange;
            float   LongRange          = w.LongRange;
            float   MaxRange           = w.MaxRange;
            string  c3_prefix          = string.Empty;
            Vector3 alternateAttackPos = GetC3CachedPos(attacker, target);

            if (alternateAttackPos != Vector3.zero)
            {
                float alternateDist = Vector3.Distance(alternateAttackPos, targetPosition);
                //Log.Debug?.TWL(0, "GetRangeModifierName "+attacker.PilotableActorDef.ChassisID+" weapon:"+w.defId+" target:"+target.PilotableActorDef.ChassisID+" real_dist:"+ real_range+" alt dist:"+ alternateDist+" max range:"+MaxRange+" modifier:"+modifier);
                if ((alternateDist < real_range) && (alternateDist < MaxRange))
                {
                    c3_prefix = "(C3)";
                    if (alternateDist < MinRange)
                    {
                        range = MinRange;
                    }
                    else
                    {
                        range = alternateDist;
                    }
                }
            }
            if (string.IsNullOrEmpty(c3_prefix))
            {
                if (modifier == 0)
                {
                    return(string.Empty);
                }
            }
            if (range < MinRange)
            {
                return(c3_prefix + "__/AIM.MIN_RANGE/__ (<" + MinRange + "m)");
            }
            if (range < ShortRange)
            {
                return(c3_prefix + "__/AIM.SHORT_RANGE/__" + SmartRange(MinRange, range, ShortRange));
            }
            if (range < MediumRange)
            {
                return(c3_prefix + "__/AIM.MED_RANGE/__" + SmartRange(ShortRange, range, MediumRange));
            }
            if (range < LongRange)
            {
                return(c3_prefix + "__/AIM.LONG_RANGE/__" + SmartRange(MediumRange, range, LongRange));
            }
            if (range < MaxRange)
            {
                return(c3_prefix + "__/AIM.MAX_RANGE/__" + SmartRange(LongRange, range, MaxRange));
            }
            return(c3_prefix + "__/AIM.OUT_OF_RANGE/__ (>" + MaxRange + "m)");
        }
 public static void Init()
 {
     ToHitModifiersHelper.registerModifier2("RANGE", "RANGE", true, false, C3Helper.GetRangeModifier, C3Helper.GetRangeModifierName);
 }