//Hook by replacing method body of ModuleScoop.ControlInputManual() internal static void ControlInputManual(ModuleWeapon module, int aim, int fire) { bool shouldFireDefault = (fire != 0) && (Time.timeScale != 0f); var shouldFireEvent = new CanFireEvent <ModuleWeapon>(module, shouldFireDefault); CanFire?.Invoke(shouldFireEvent); bool performBehaviour = true; if (shouldFireEvent.Fire) { var fireEvent = new FireEvent <ModuleWeapon>(module); OnFire?.Invoke(fireEvent); performBehaviour = fireEvent.PerformVanillaBehaviour; #warning Remove duplicate versions of this } if (performBehaviour) { module.AimControl = aim; module.FireControl = shouldFireEvent.Fire; module.m_TargetPosition = Vector3.zero; if (module.FireControl && module.block.tank && module.block.tank.beam.IsActive && !Mode <ModeMain> .inst.TutorialLockBeam) { module.block.tank.beam.EnableBeam(false, false); } } }
void On_WeaponChanged(ModuleWeapon newWeapon) { if (m_Weapon != null) { if (!M_Weapon.CardInfo.BaseInfo.IsTemp) { BattlePlayer.CardDeckManager.CardDeck.RecycleCardInstanceID(m_Weapon.OriginCardInstanceId); } m_Weapon.UnRegisterSideEffect(); } m_Weapon = newWeapon; BattlePlayer.GameManager.EventManager.Invoke(SideEffectExecute.TriggerTime.OnEquipEquiped, new ExecutorInfo(clientId: BattlePlayer.ClientId, mechId: M_MechID, equipId: m_Weapon.M_EquipID)); EquipWeaponServerRequest request = new EquipWeaponServerRequest(BattlePlayer.ClientId, (CardInfo_Equip)newWeapon.GetCurrentCardInfo(), M_MechID, m_Weapon.M_EquipID); BattlePlayer.MyClientProxy.BattleGameManager.Broadcast_AddRequestToOperationResponse(request); RefreshAttackTime(); int att_before = m_MechAttack; int we_before = m_MechWeaponEnergy; int weMax_before = m_MechWeaponEnergyMax; m_MechAttack = CardInfo.BattleInfo.BasicAttack + newWeapon.CardInfo.WeaponInfo.Attack; m_MechWeaponEnergyMax = newWeapon.CardInfo.WeaponInfo.EnergyMax; m_MechWeaponEnergy = newWeapon.CardInfo.WeaponInfo.Energy; if (m_MechWeaponEnergy == 0) { m_MechAttack = CardInfo.BattleInfo.BasicAttack; } MechAttributesChangeRequest request2 = new MechAttributesChangeRequest(BattlePlayer.ClientId, M_MechID, addAttack: m_MechAttack - att_before, addWeaponEnergy: m_MechWeaponEnergy - we_before, addWeaponEnergyMax: m_MechWeaponEnergyMax - weMax_before); BattlePlayer.MyClientProxy.BattleGameManager.Broadcast_AddRequestToOperationResponse(request2); }
public static void Postfix(ref ModuleWeapon __instance) { if (!__instance.FireControl && __instance.block.tank.IsAIControlled()) { TargetAimer targetAimer = (TargetAimer)m_TargetAimer.GetValue(__instance); if (targetAimer.HasTarget) { Vector3 actualTargetPosition = (Vector3)m_TargetPosition2.GetValue(targetAimer); m_TargetPosition.SetValue(__instance, actualTargetPosition); IModuleWeapon weaponComponent = (IModuleWeapon)m_WeaponComponent.GetValue(__instance); float range = weaponComponent.GetRange(); Transform fireTransform = weaponComponent.GetFireTransform(); Vector3 position = fireTransform.position; if ((actualTargetPosition - position).sqrMagnitude < range * range) { if (weaponComponent is ModuleWeaponGun && ((ModuleWeaponGun)weaponComponent).m_SeekingRounds) { __instance.FireControl = true; } else if (Vector3.Angle(fireTransform.forward, actualTargetPosition - __instance.block.trans.position) < tolerance) { __instance.FireControl = true; } } } } }
public void AddBlock(TankBlock block, IntVector3 pos, OrthoRotation rot) { blocks.Add(block); block.trans.parent = transform; block.trans.localPosition = pos; block.trans.localRotation = rot; Dirty = true; for (int ap = 0; ap < block.attachPoints.Length; ap++) { IntVector3 filledCellForAPIndex = block.GetFilledCellForAPIndex(ap); IntVector3 v3 = block.attachPoints[ap] * 2f - filledCellForAPIndex - filledCellForAPIndex; IntVector3 index = pos + rot * filledCellForAPIndex; byte b = (rot * v3).APHalfBits(); ClusterAPBitField.TryGetValue(index, out byte ptr); ptr |= b; ClusterAPBitField[index] = ptr; } ModuleWeapon weapon = block.GetComponent <ModuleWeapon>(); if (weapon != null) { blockWeapons.Add(weapon); } ModuleDrill drill = block.GetComponent <ModuleDrill>(); if (drill != null) { blockDrills.Add(drill); } return; }
void On_WeaponDown() { if (m_Weapon != null) { if (!M_Weapon.CardInfo.BaseInfo.IsTemp) { BattlePlayer.CardDeckManager.CardDeck.RecycleCardInstanceID(m_Weapon.OriginCardInstanceId); } BattlePlayer.GameManager.EventManager.Invoke(SideEffectExecute.TriggerTime.OnEquipDie, new ExecutorInfo(clientId: BattlePlayer.ClientId, mechId: M_MechID, equipId: m_Weapon.M_EquipID)); m_Weapon.UnRegisterSideEffect(); EquipWeaponServerRequest request = new EquipWeaponServerRequest(clientId: BattlePlayer.ClientId, cardInfo: null, mechId: M_MechID, equipID: m_Weapon.M_EquipID); BattlePlayer.MyClientProxy.BattleGameManager.Broadcast_AddRequestToOperationResponse(request); m_Weapon = null; int att_before = m_MechAttack; int we_before = m_MechWeaponEnergy; int weMax_before = m_MechWeaponEnergyMax; m_MechAttack = CardInfo.BattleInfo.BasicAttack; m_MechWeaponEnergy = 0; m_MechWeaponEnergyMax = 0; MechAttributesChangeRequest request2 = new MechAttributesChangeRequest(BattlePlayer.ClientId, M_MechID, addAttack: m_MechAttack - att_before, addWeaponEnergy: m_MechWeaponEnergy - we_before, addWeaponEnergyMax: m_MechWeaponEnergyMax - weMax_before); BattlePlayer.MyClientProxy.BattleGameManager.Broadcast_AddRequestToOperationResponse(request2); } }
public static bool Prefix(ref ModuleWeapon __instance) { IModuleWeapon moduleWeapon = (IModuleWeapon)m_WeaponComponent.GetValue(__instance); if (moduleWeapon == null) { Console.WriteLine($"NULL WeaponComponent for {__instance.block.name}"); } if (moduleWeapon != null && moduleWeapon is ModuleWeaponGun moduleWeaponGun) { if (WeaponAimSettings.AutoSetFuse) { AddAutoSetFuse(moduleWeaponGun); } else { TimedFuseData timedFuse = __instance.GetComponentInParent <TimedFuseData>(); if (timedFuse && !timedFuse.always_present) { RemoveAutoSetFuse(timedFuse); } } } return(true); }
public WeaponWrapper(TankBlock block) { this.block = block; this.weapon = block.gameObject.GetComponent <ModuleWeapon>(); this.drill = block.gameObject.GetComponent <ModuleDrill>(); this.hammer = block.gameObject.GetComponent <ModuleHammer>(); }
public override void OnStart(StartState state) { laser = GetLaser(); wm = GetWM(); camera = GetCamera(); Setup(); base.OnStart(state); }
private ModuleWeapon GetLaser() { ModuleWeapon l = null; l = part.FindModuleImplementing <ModuleWeapon>(); return(l); }
private ModuleWeapon weaponCheck() { ModuleWeapon weapon = null; weapon = part.FindModuleImplementing <ModuleWeapon>(); return(weapon); }
public WeaponRemovedEvent(ModuleWeapon Weapon) { if (Weapon == null) { throw new ArgumentNullException("Weapon"); } this.WeaponComponent = Weapon; }
public override void OnStart(StartState state) { if (HighLogic.LoadedSceneIsFlight) { weapon = weaponCheck(); turret = turretCheck(); } base.OnStart(state); }
public void EquipWeapon(CardInfo_Equip cardInfo, int equipId) { ModuleWeapon newWeapon = GameObjectPoolManager.Instance.PoolDict[GameObjectPoolManager.PrefabNames.ModuleWeapon].AllocateGameObject <ModuleWeapon>(transform); newWeapon.M_ModuleMech = Mech; newWeapon.Initiate(cardInfo, Mech.ClientPlayer); newWeapon.M_EquipID = equipId; newWeapon.transform.position = EquipPivots[0].position; M_Weapon = newWeapon; }
void OnPool() { WeaponModule = GetComponent <ModuleWeapon>(); if (WeaponModule == null) { Console.WriteLine($"{name}.ModuleWeaponWrapper.OnPool() : There is no ModuleWeapon here!"); Destroy(this); return; } WrapOnSpawn = true; GetTargetForWrap(); }
public void EquipWeapon(EquipWeaponRequest r, CardInfo_Base cardInfo) { ModuleWeapon weapon = new ModuleWeapon(); CardInfo_Equip cardInfo_Weapon = (CardInfo_Equip)cardInfo; ModuleMech mech = GetMech(r.mechId); weapon.M_ModuleMech = mech; weapon.M_EquipID = BattlePlayer.GameManager.GenerateNewEquipId(); weapon.Initiate(cardInfo_Weapon, BattlePlayer); weapon.OriginCardInstanceId = r.handCardInstanceId; mech.M_Weapon = weapon; BattlePlayer.CardDeckManager.CardDeck.AddCardInstanceId(cardInfo.CardID, r.handCardInstanceId); }
public void Open(ModuleWeapon weapon, Vector2 position) { open = true; selectedWeapon = weapon; windowLocation = position; AList = BDAcTools.ParseNames(weapon.bulletType); for (int a = 0; a < AList.Count; a++) { bulletInfo = BulletInfo.bullets[AList[a].ToString()]; guiAmmoTypeString = ""; if (bulletInfo.subProjectileCount > 1) { guiAmmoTypeString = Localizer.Format("#LOC_BDArmory_Ammo_Shot") + " "; } if (bulletInfo.apBulletMod >= 1.1) { guiAmmoTypeString += Localizer.Format("#LOC_BDArmory_Ammo_AP") + " "; } if (bulletInfo.apBulletMod < 1.1 && bulletInfo.apBulletMod > 0.8f) { guiAmmoTypeString += Localizer.Format("#LOC_BDArmory_Ammo_SAP") + " "; } if (bulletInfo.explosive) { if (bulletInfo.fuzeType.ToLower() != "none") { guiAmmoTypeString += Localizer.Format("#LOC_BDArmory_Ammo_Flak") + " "; } guiAmmoTypeString += Localizer.Format("#LOC_BDArmory_Ammo_Explosive") + " "; } if (bulletInfo.incendiary) { guiAmmoTypeString += Localizer.Format("#LOC_BDArmory_Ammo_Incendiary") + " "; } if (!bulletInfo.explosive && bulletInfo.apBulletMod <= 0.8) { guiAmmoTypeString += Localizer.Format("#LOC_BDArmory_Ammo_Slug"); } ammoDesc.Add(guiAmmoTypeString); } }
public static void AddWeapon(ModuleWeapon Module) { WeaponAddedEvent weaponAddedEvent = new WeaponAddedEvent(Module); WeaponAdded?.Invoke(weaponAddedEvent); }
public static void RemoveWeapon(ModuleWeapon Module) { WeaponRemovedEvent weaponRemovedEvent = new WeaponRemovedEvent(Module); WeaponRemoved?.Invoke(weaponRemovedEvent); }
void dumpParts() { String gunName = "bda_weapons_list.csv"; String missileName = "bda_missile_list.csv"; String radarName = "bda_radar_list.csv"; String jammerName = "bda_jammer_list.csv"; ModuleWeapon weapon = null; MissileLauncher missile = null; ModuleRadar radar = null; ModuleECMJammer jammer = null; // 1. create the file var fileguns = KSP.IO.TextWriter.CreateForType <BDAEditorCategory>(gunName); var filemissiles = KSP.IO.TextWriter.CreateForType <BDAEditorCategory>(missileName); var fileradars = KSP.IO.TextWriter.CreateForType <BDAEditorCategory>(radarName); var filejammers = KSP.IO.TextWriter.CreateForType <BDAEditorCategory>(jammerName); // 2. write header fileguns.WriteLine("NAME;TITLE;AUTHOR;MANUFACTURER;PART_MASS;PART_COST;PART_CRASHTOLERANCE;PART_MAXTEMP;WEAPON_RPM;WEAPON_DEVIATION;WEAPON_MAXEFFECTIVEDISTANCE;WEAPON_TYPE;WEAPON_BULLETTYPE;WEAPON_AMMONAME;WEAPON_BULLETMASS;WEAPON_BULLET_VELOCITY;WEAPON_MAXHEAT;WEAPON_HEATPERSHOT;WEAPON_HEATLOSS;CANNON_SHELLPOWER;CANNON_SHELLHEAT;CANNON_SHELLRADIUS;CANNON_AIRDETONATION"); filemissiles.WriteLine("NAME;TITLE;AUTHOR;MANUFACTURER;PART_MASS;PART_COST;PART_CRASHTOLERANCE;PART_MAXTEMP;" + "MISSILE_THRUST;MISSILE_BOOSTTIME;MISSILE_CRUISETHRUST;MISSILE_CRUISETIME;MISSILE_MAXTURNRATEDPS;MISSILE_BLASTPOWER;MISSILE_BLASTHEAT;MISSILE_BLASTRADIUS;MISSILE_GUIDANCEACTIVE;MISSILE_HOMINGTYPE;MISSILE_TARGETINGTYPE;MISSILE_MINLAUNCHSPEED;MISSILE_MINSTATICLAUNCHRANGE;MISSILE_MAXSTATICLAUNCHRANGE;MISSILE_OPTIMUMAIRSPEED;" + "CRUISE_TERMINALMANEUVERING; CRUISE_TERMINALGUIDANCETYPE; CRUISE_TERMINALGUIDANCEDISTANCE;" + "RADAR_ACTIVERADARRANGE;RADAR_RADARLOAL;" + "TRACK_MAXOFFBORESIGHT;TRACK_LOCKEDSENSORFOV;" + "HEAT_HEATTHRESHOLD;" + "LASER_BEAMCORRECTIONFACTOR; LASER_BEAMCORRECTIONDAMPING" ); fileradars.WriteLine("NAME;TITLE;AUTHOR;MANUFACTURER;PART_MASS;PART_COST;PART_CRASHTOLERANCE;PART_MAXTEMP;radar_name;rwrThreatType;omnidirectional;directionalFieldOfView;boresightFOV;" + "scanRotationSpeed;lockRotationSpeed;lockRotationAngle;showDirectionWhileScan;multiLockFOV;lockAttemptFOV;canScan;canLock;canTrackWhileScan;canRecieveRadarData;" + "DEPRECATED_minSignalThreshold;DEPRECATED_minLockedSignalThreshold;maxLocks;radarGroundClutterFactor;radarDetectionCurve;radarLockTrackCurve" ); filejammers.WriteLine("NAME;TITLE;AUTHOR;MANUFACTURER;PART_MASS;PART_COST;PART_CRASHTOLERANCE;PART_MAXTEMP;alwaysOn;rcsReduction;rcsReducationFactor;lockbreaker;lockbreak_strength;jammerStrength"); Debug.Log("Dumping parts..."); // 3. iterate weapons and write out fields foreach (var item in availableParts) { weapon = null; missile = null; radar = null; jammer = null; weapon = item.partPrefab.GetComponent <ModuleWeapon>(); missile = item.partPrefab.GetComponent <MissileLauncher>(); radar = item.partPrefab.GetComponent <ModuleRadar>(); jammer = item.partPrefab.GetComponent <ModuleECMJammer>(); if (weapon != null) { fileguns.WriteLine( item.name + ";" + item.title + ";" + item.author + ";" + item.manufacturer + ";" + item.partPrefab.mass + ";" + item.cost + ";" + item.partPrefab.crashTolerance + ";" + item.partPrefab.maxTemp + ";" + weapon.roundsPerMinute + ";" + weapon.maxDeviation + ";" + weapon.maxEffectiveDistance + ";" + weapon.weaponType + ";" + weapon.bulletType + ";" + weapon.ammoName + ";" + weapon.bulletMass + ";" + weapon.bulletVelocity + ";" + weapon.maxHeat + ";" + weapon.heatPerShot + ";" + weapon.heatLoss + ";" + weapon.cannonShellPower + ";" + weapon.cannonShellHeat + ";" + weapon.cannonShellRadius + ";" + weapon.airDetonation ); } if (missile != null) { filemissiles.WriteLine( item.name + ";" + item.title + ";" + item.author + ";" + item.manufacturer + ";" + item.partPrefab.mass + ";" + item.cost + ";" + item.partPrefab.crashTolerance + ";" + item.partPrefab.maxTemp + ";" + missile.thrust + ";" + missile.boostTime + ";" + missile.cruiseThrust + ";" + missile.cruiseTime + ";" + missile.maxTurnRateDPS + ";" + missile.blastPower + ";" + missile.blastHeat + ";" + missile.blastRadius + ";" + missile.guidanceActive + ";" + missile.homingType + ";" + missile.targetingType + ";" + missile.minLaunchSpeed + ";" + missile.minStaticLaunchRange + ";" + missile.maxStaticLaunchRange + ";" + missile.optimumAirspeed + ";" + missile.terminalManeuvering + ";" + missile.terminalGuidanceType + ";" + missile.terminalGuidanceDistance + ";" + missile.activeRadarRange + ";" + missile.radarLOAL + ";" + missile.maxOffBoresight + ";" + missile.lockedSensorFOV + ";" + missile.heatThreshold + ";" + missile.beamCorrectionFactor + ";" + missile.beamCorrectionDamping ); } if (radar != null) { fileradars.WriteLine( item.name + ";" + item.title + ";" + item.author + ";" + item.manufacturer + ";" + item.partPrefab.mass + ";" + item.cost + ";" + item.partPrefab.crashTolerance + ";" + item.partPrefab.maxTemp + ";" + radar.radarName + ";" + radar.getRWRType(radar.rwrThreatType) + ";" + radar.omnidirectional + ";" + radar.directionalFieldOfView + ";" + radar.boresightFOV + ";" + radar.scanRotationSpeed + ";" + radar.lockRotationSpeed + ";" + radar.lockRotationAngle + ";" + radar.showDirectionWhileScan + ";" + radar.multiLockFOV + ";" + radar.lockAttemptFOV + ";" + radar.canScan + ";" + radar.canLock + ";" + radar.canTrackWhileScan + ";" + radar.canRecieveRadarData + ";" + radar.maxLocks + ";" + radar.radarGroundClutterFactor + ";" + radar.radarDetectionCurve.Evaluate(radar.radarMaxDistanceDetect) + "@" + radar.radarMaxDistanceDetect + ";" + radar.radarLockTrackCurve.Evaluate(radar.radarMaxDistanceLockTrack) + "@" + radar.radarMaxDistanceLockTrack ); } if (jammer != null) { filejammers.WriteLine( item.name + ";" + item.title + ";" + item.author + ";" + item.manufacturer + ";" + item.partPrefab.mass + ";" + item.cost + ";" + item.partPrefab.crashTolerance + ";" + item.partPrefab.maxTemp + ";" + jammer.alwaysOn + ";" + jammer.rcsReduction + ";" + jammer.rcsReductionFactor + ";" + jammer.lockBreaker + ";" + jammer.lockBreakerStrength + ";" + jammer.jammerStrength ); } } // 4. close file fileguns.Close(); filemissiles.Close(); fileradars.Close(); filejammers.Close(); Debug.Log("...dumping parts complete."); }
public void ManipulateBarrels(List <ModuleWeaponGun> weaponList, string request) { 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 (ModuleWeaponGun weapon in weaponList) { 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") { this.weaponSpeedMemory.Add(thisBarrel, (float)prop_GetSpeed.GetValue(value_AnimState)); } else if (request == "UPDATE") { prop_SetSpeed.SetValue(value_AnimState, this.weaponSpeedMemory[thisBarrel] / this.allSegments["WeaponCooldown"].GetAverages()); } else if (request == "CLEAN") { prop_SetSpeed.SetValue(value_AnimState, this.weaponSpeedMemory[thisBarrel]); this.weaponSpeedMemory.Remove(thisBarrel); } //float value_length = (float)prop_GetLength.GetValue(value_AnimState); //Console.WriteLine("FFW! Pre. Length = " + (float)prop_GetLength.GetValue(value_AnimState) + " . Speed = " + (float)prop_GetSpeed.GetValue(value_AnimState)); /*float modifier = this.allSegments["WeaponCooldown"].GetAveragesByKey(weapon, 2); * if (modifier == 0.0f) * { * modifier = this.allSegments["WeaponCooldown"].GetAveragesByKey(weapon, 1); * } * if (value_length > modifier) * { * //prop_SetSpeed.SetValue(value_AnimState, value_length / modifier); * }*/ //Console.WriteLine("FFW! Post. Length = " + (float)prop_GetLength.GetValue(value_AnimState) + " . Speed = " + (float)prop_GetSpeed.GetValue(value_AnimState)); /*if (value_length > this.allSegments["WeaponCooldown"].GetAveragesByKey(weapon, 2)) * { * prop_SetSpeed.SetValue(value_AnimState, value_length / this.allSegments["WeaponCooldown"].GetAveragesByKey(weapon, 2)); * }*/ } } } } }
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); } } } } } }
static void Postfix(ref Projectile __instance, Vector3 fireDirection, FireData fireData, ModuleWeapon weapon, Tank shooter = null, bool seekingRounds = false, bool replayRounds = false) { FieldInfo field_LastFireDirection = typeof(Projectile) .GetField("m_LastFireDirection", BindingFlags.NonPublic | BindingFlags.Instance); Vector3 vector = fireDirection * fireData.m_MuzzleVelocity; if (!replayRounds) { field_LastFireDirection.SetValue(__instance, Random2(vector, fireData.m_BulletSprayVariance)); vector = (Vector3)field_LastFireDirection.GetValue(__instance); } else { vector = (Vector3)field_LastFireDirection.GetValue(__instance); } if (shooter != null) { vector += shooter.rbody.velocity; } __instance.rbody.velocity = vector; }