Beispiel #1
0
        public void AddWeapon(ModuleWeaponGun weapon)
        {
            this.weaponListGeneric.Add(weapon);
            this.weaponList.Add(weapon);

            this.allSegments["WeaponCooldown"].ManipulateObj(new List <object> {
                weapon
            }, "SAVE");
            this.allSegments["WeaponRotation"].ManipulateObj(new List <object> {
                weapon
            }, "SAVE");
            this.allSegments["WeaponSpread"].ManipulateObj(new List <object> {
                weapon
            }, "SAVE");
            this.allSegments["WeaponVelocity"].ManipulateObj(new List <object> {
                weapon
            }, "SAVE");

            this.ManipulateBarrels(new List <ModuleWeaponGun> {
                weapon
            }, "SAVE");

            this.ManipulateBarrels(new List <ModuleWeaponGun> {
                weapon
            }, "UPDATE");
        }
Beispiel #2
0
        public static bool Prefix(ref ModuleWeaponGun __instance, ref bool firing)
        {
            ModuleParticleManager newModule = __instance.GetComponent <ModuleParticleManager>();

            if (newModule != null)
            {
                if (newModule.beforeBarrelFired != null || newModule.onWeaponCharge != null)
                {
                    FieldInfo m_NextBarrelToFire = typeof(ModuleWeaponGun).GetField("m_NextBarrelToFire", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                    FieldInfo m_ShotTimer        = typeof(ModuleWeaponGun).GetField("m_ShotTimer", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

                    int __m_NextBarrelToFire = (int)m_NextBarrelToFire.GetValue((object)__instance);
                    //float __m_ShotTimer = (float)m_ShotTimer.GetValue((object)__instance);

                    float to_set = newModule.ProcessFiring(firing, __m_NextBarrelToFire);

                    if (to_set > 0.0f)
                    {
                        Console.WriteLine("Attempting to set shotTimer to: " + to_set.ToString());
                        m_ShotTimer.SetValue(__instance, to_set);
                        firing = false;
                    }
                }
            }

            return(true);
        }
Beispiel #3
0
        public static void AddAutoSetFuse(ModuleWeaponGun __instance)
        {
            TimedFuseData timedFuse = __instance.GetComponentInParent <TimedFuseData>();

            if (timedFuse == null)
            {
                FireData fireData = (FireData)m_FiringData.GetValue(__instance);
                if (fireData == null)
                {
                    fireData = __instance.GetComponent <FireData>();
                    m_FiringData.SetValue(__instance, fireData);
                }
                if (fireData != null)
                {
                    WeaponRound round = fireData.m_BulletPrefab;
                    if (round != null && round is Projectile projectile)
                    {
                        float lifetime             = (float)m_LifeTime.GetValue(projectile);
                        bool  explodeAfterLifetime = (bool)m_ExplodeAfterLifetime.GetValue(projectile);

                        // We check if projectile has a lifetime, and it explodes after it (no use setting fuse if fixed lifetime anyway)
                        if (explodeAfterLifetime && lifetime > 0f)
                        {
                            timedFuse = __instance.gameObject.AddComponent <TimedFuseData>();
                            timedFuse.always_present = false;
                        }
                    }
                }
            }
        }
Beispiel #4
0
            static bool Prefix(ref ModuleWeaponGun __instance)
            {
                BuffController buff = BuffController.MakeNewIfNone(__instance.block.tank);

                buff.AddWeapon(__instance);
                return(true);
            }
Beispiel #5
0
 private static void Postfix(ref ModuleWeaponGun __instance)
 {
     // Do timed fuse setting
     if (WeaponAimSettings.AutoSetFuse)
     {
         AddAutoSetFuse(__instance);
     }
 }
Beispiel #6
0
 private static void Postfix(ref ModuleWeaponGun __instance)
 {
     CannonBarrel[] cannonBarrels = (CannonBarrel[])m_CannonBarrels.GetValue(__instance);
     if (cannonBarrels != null)
     {
         foreach (CannonBarrel cannonBarrel in cannonBarrels)
         {
             if (cannonBarrel.beamWeapon)
             {
                 FireData fireData = (FireData)m_FiringData.GetValue(__instance);
                 if (fireData != null)
                 {
                     fireData.m_MuzzleVelocity = 0f;
                 }
                 return;
             }
         }
     }
     return;
 }
Beispiel #7
0
        public void RemoveWeapon(ModuleWeaponGun weapon)
        {
            this.allSegments["WeaponCooldown"].ManipulateObj(new List <object> {
                weapon
            }, "CLEAN");
            this.allSegments["WeaponRotation"].ManipulateObj(new List <object> {
                weapon
            }, "CLEAN");
            this.allSegments["WeaponSpread"].ManipulateObj(new List <object> {
                weapon
            }, "CLEAN");
            this.allSegments["WeaponVelocity"].ManipulateObj(new List <object> {
                weapon
            }, "CLEAN");

            this.ManipulateBarrels(new List <ModuleWeaponGun> {
                weapon
            }, "CLEAN");

            this.weaponListGeneric.Remove(weapon);
            this.weaponList.Remove(weapon);
        }
Beispiel #8
0
        private void OnPool()
        {
            this.DebugPrint("<MPM> OnPool");
            this.GetComponentsInChildren <CannonBarrel>(true);

            // hook up the functions to the events (OnAttach, OnDetach, OnAnchorStatusChanged)
            this.block.AttachEvent.Subscribe(new System.Action(this.OnAttach));
            this.block.DetachEvent.Subscribe(new System.Action(this.OnDetach));
            this.DebugPrint("<MPM> Pool subscribe block attachments");

            this.m_ModuleWeaponGun = this.GetComponent <ModuleWeaponGun>();
            if (this.m_ModuleWeaponGun == null)
            {
                this.DebugPrint("<MPM> DID NOT FIND MODULEWEAPONGUN");
                // this.onSpacePress = null;
                // this.onSpaceRelease = null;
                this.beforeBarrelFired = null;
                this.defaultTimeNeeded = null;
            }

            this.DebugPrint("<MPM> OnPool Complete");
        }
Beispiel #9
0
        public static void ManipulateBarrels(List <TankBlock> blockList, string request, Dictionary <CannonBarrel, float> memory, float average)
        {
            FieldInfo field_NumCannonBarrels = typeof(ModuleWeaponGun) // Holy mess!
                                               .GetField("m_NumCannonBarrels", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            FieldInfo field_CannonBarrels = typeof(ModuleWeaponGun)
                                            .GetField("m_CannonBarrels", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            FieldInfo field_BarrelTransform = typeof(ModuleWeaponGun)
                                              .GetField("m_BarrelTransform", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            FieldInfo field_FiringData = typeof(ModuleWeaponGun)
                                         .GetField("m_FiringData", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            FieldInfo field_WeaponModule = typeof(ModuleWeaponGun)
                                           .GetField("m_WeaponModule", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            FieldInfo field_ShotCooldown = typeof(ModuleWeaponGun)
                                           .GetField("m_ShotCooldown", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            FieldInfo field_transform = typeof(Transform)
                                        .GetField("transform", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            FieldInfo field_AnimState = typeof(CannonBarrel)
                                        .GetField("animState", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            /*MethodInfo method_Setup = typeof(CannonBarrel)
             *  .GetMethod("Setup", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
             * MethodInfo method_CapRecoilDuration = typeof(CannonBarrel)
             *  .GetMethod("CapRecoilDuration", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);*/

            foreach (TankBlock block in blockList)
            {
                ModuleWeaponGun weapon = block.GetComponent <ModuleWeaponGun>();
                int             value_NumCannonBarrels = (int)field_NumCannonBarrels.GetValue(weapon);
                if (value_NumCannonBarrels != 0)
                {
                    Array value_CannonBarrels = (Array)field_CannonBarrels.GetValue(weapon);
                    for (int i = 0; i < value_CannonBarrels.Length; i++)
                    {
                        /*Transform value_BarrelTransform = (Transform)field_BarrelTransform.GetValue(weapon);
                         * if (value_BarrelTransform == null) // Will this ever check true?
                         * {
                         *  field_BarrelTransform.SetValue(weapon, field_transform.GetValue(value_CannonBarrels.GetValue(i)));
                         * }*/
                        CannonBarrel thisBarrel         = (CannonBarrel)value_CannonBarrels.GetValue(i);
                        FireData     value_FiringData   = (FireData)field_FiringData.GetValue(weapon);
                        ModuleWeapon value_WeaponModule = (ModuleWeapon)field_WeaponModule.GetValue(weapon);
                        float        value_ShotCooldown = (float)field_ShotCooldown.GetValue(weapon);
                        //method_Setup.Invoke(value_CannonBarrels.GetValue(i), new object[] { value_FiringData, value_WeaponModule });
                        //method_CapRecoilDuration.Invoke(value_CannonBarrels.GetValue(i), new object[] { value_ShotCooldown });
                        object value_AnimState = field_AnimState.GetValue(thisBarrel);
                        if (value_AnimState != null)
                        {
                            PropertyInfo prop_GetSpeed = value_AnimState.GetType()
                                                         .GetProperty("speed", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetProperty);
                            PropertyInfo prop_SetSpeed = value_AnimState.GetType()
                                                         .GetProperty("speed", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty);
                            PropertyInfo prop_GetLength = value_AnimState.GetType()
                                                          .GetProperty("length", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetProperty);
                            PropertyInfo prop_SetLength = value_AnimState.GetType()
                                                          .GetProperty("length", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty);
                            if (request == "SAVE")
                            {
                                memory.Add(thisBarrel, (float)prop_GetSpeed.GetValue(value_AnimState));
                            }
                            else if (request == "UPDATE")
                            {
                                prop_SetSpeed.SetValue(value_AnimState, memory[thisBarrel] / average);
                            }
                            else if (request == "CLEAN")
                            {
                                prop_SetSpeed.SetValue(value_AnimState, memory[thisBarrel]);
                                memory.Remove(thisBarrel);
                            }
                        }
                    }
                }
            }
        }
Beispiel #10
0
        public static void Postfix(ref ModuleWeaponGun __instance)
        {
            ModuleParticleManager newModule = __instance.GetComponent <ModuleParticleManager>();

            if (newModule != null)
            {
                FieldInfo m_CannonBarrels         = typeof(ModuleWeaponGun).GetField("m_CannonBarrels", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                FieldInfo m_NumCannonBarrels      = typeof(ModuleWeaponGun).GetField("m_NumCannonBarrels", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                FieldInfo m_BurstShotCount        = typeof(ModuleWeaponGun).GetField("m_BurstShotCount", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                FieldInfo m_BurstCooldown         = typeof(ModuleWeaponGun).GetField("m_BurstCooldown", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                FieldInfo m_ShotCooldown          = typeof(ModuleWeaponGun).GetField("m_ShotCooldown", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                FieldInfo m_FireControlMode       = typeof(ModuleWeaponGun).GetField("m_FireControlMode", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                FieldInfo m_ResetBurstOnInterrupt = typeof(ModuleWeaponGun).GetField("m_ResetBurstOnInterrupt", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                FieldInfo m_CooldownVariancePct   = typeof(ModuleWeaponGun).GetField("m_CooldownVariancePct", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

                CannonBarrel[] __m_CannonBarrels    = (CannonBarrel[])m_CannonBarrels.GetValue((object)__instance);
                int            __m_NumCannonBarrels = (int)m_NumCannonBarrels.GetValue((object)__instance);
                int            __m_BurstShotCount   = (int)m_BurstShotCount.GetValue((object)__instance);
                float          __m_BurstCooldown    = (float)m_BurstCooldown.GetValue((object)__instance);
                float          __m_ShotCooldown     = (float)m_ShotCooldown.GetValue((object)__instance);
                ModuleWeaponGun.FireControlMode __m_FireControlMode = (ModuleWeaponGun.FireControlMode)m_FireControlMode.GetValue((object)__instance);
                // bool __m_ResetBurstOnInterrupt = (bool) m_ResetBurstOnInterrupt.GetValue((object)__instance);
                float __m_CooldownVariancePct = (float)m_CooldownVariancePct.GetValue((object)__instance);

                // do Module-Specific NewModule hookups
                newModule.m_CannonBarrels  = __m_CannonBarrels;
                newModule.m_BarrelFired    = new bool[__m_NumCannonBarrels];
                newModule.m_BurstShotCount = __m_BurstShotCount;
                for (int i = 0; i < __m_NumCannonBarrels; i++)
                {
                    newModule.m_BarrelFired[i] = false;
                }

                // handle WeaponCharge first
                if (newModule.onWeaponCharge != null)
                {
                    float spinUpTime = 0.0f;
                    // if __result != preparefiring, then either spinner is charging.
                    // if __result == preparefiring, then either no spinner, or spinner is charged
                    FieldInfo m_FireSpinner = typeof(CannonBarrel).GetField("m_FireSpinner", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                    FieldInfo m_SpinUpTime  = typeof(Spinner).GetField("m_SpinUpTime", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                    foreach (CannonBarrel barrel in __m_CannonBarrels)
                    {
                        Spinner spinner = (Spinner)m_FireSpinner.GetValue(barrel);
                        if (spinner != null)
                        {
                            float instanceSpinUpTime = (float)m_SpinUpTime.GetValue(spinner);
                            spinUpTime = Mathf.Max(spinUpTime, instanceSpinUpTime);
                        }
                    }
                    float incrStartDelay = spinUpTime - newModule.maxWeaponChargeTime;
                    if (incrStartDelay <= 0.0f)
                    {
                        newModule.maxWeaponChargeTime = -incrStartDelay;
                    }
                    else
                    {
                        foreach (ParticleSystem system in newModule.onWeaponCharge)
                        {
                            var main = system.main;
                            ParticleSystem.MinMaxCurve startDelay = main.startDelay;
                            main.startDelay = startDelay.constant + incrStartDelay;
                        }
                    }
                }

                // align CannonBarrel arrays. If no effects are present and tied to it, end immediately, we don't care
                if (__m_FireControlMode == ModuleWeaponGun.FireControlMode.AllAtOnce)
                {
                    newModule.AllAtOnce = true;
                }
                if (!newModule.AlignCannonBarrels(__m_CannonBarrels))
                {
                    return;
                }

                // since we want good charge timing, no variance is allowed
                __m_CooldownVariancePct = 0.0f;

                // Get info on what to do based on reload times:

                // if AllAtOnce, then we simplify, just use shotCoolDown, forcibly floor cooldown to the minimum of reload
                if (__m_FireControlMode == ModuleWeaponGun.FireControlMode.AllAtOnce)
                {
                    newModule.AllAtOnce = true;

                    PatchModuleWeaponGunPool.OnPoolAllAtOnce(__m_ShotCooldown, __m_BurstCooldown, __m_BurstShotCount, __m_NumCannonBarrels, newModule);
                }
                // handle burst fire. burst > 1 means it's actual burst fire. burst == 1 means it's sequential fire, with burst cooldown overriding shot cooldown
                else if (__m_BurstShotCount > 1)
                {
                    // newModule.m_ResetBurstOnInterrupt = m_ResetBurstOnInterrupt;
                    // reset on interrupt isn't dynamic, but breaks assumptions used in start-barrel calculations, so we forcibly set it to true
                    m_ResetBurstOnInterrupt.SetValue(__instance, true);

                    // if this is true, can be safe in knowledge that existing cycle_timer stuff is good
                    // we don't care. we solve this by using ModuleParticleManager.HandleFirst(m_currentBarrelInd) or thereabouts

                    /* if (m_ResetBurstOnInterrupt)
                     * {
                     *
                     * } */

                    PatchModuleWeaponGunPool.OnPoolBurst(__m_ShotCooldown, __m_BurstCooldown, __m_BurstShotCount, __m_NumCannonBarrels, newModule);
                }
                // Plain-old sequential fire (burst count == 1 is also sequential)
                else
                {
                    PatchModuleWeaponGunPool.OnPoolSequential(__m_ShotCooldown, __m_BurstCooldown, __m_BurstShotCount, __m_NumCannonBarrels, newModule);
                }
            }
            return;
        }
Beispiel #11
0
            static void Postfix(ref ModuleWeaponGun __instance)
            {
                BuffController buff = BuffController.MakeNewIfNone(__instance.block.tank);

                buff.RemoveWeapon(__instance);
            }