using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using FistVR;
using HarmonyLib;
using OtherLoader;
using UnityEngine;
using UnityEngine.Rendering;
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
namespace HomingRound
{
public class BoosterEffect : MonoBehaviour
{
[Tooltip("Where the thrust values come from. If empty, it is looked up on this object and its parents")]
public MonoBehaviour ThrustSourceBehaviour;
[Header("Side thrusters (turning only)")]
[Tooltip("Emissive yellow-white material for the side puffs")]
public Material ExhaustMaterial;
[Tooltip("Where the exhaust leaves the round, metres behind its centre")]
public float TailOffset = 0.008f;
[Tooltip("Puffs per second at full thrust")]
public float MaxEmitRate = 500f;
[Tooltip("How long a puff lives (seconds). Keep it tiny")]
public float ParticleLifetime = 0.07f;
public float MinSize = 0.008f;
public float MaxSize = 0.018f;
[Tooltip("Speed the puffs leave the round at, relative to it (m/s)")]
public float ExhaustSpeed = 7f;
[Tooltip("How much of the round's velocity the puffs take with them (0 to 1). Higher = shorter trail")]
[Range(0.9f, 1f)]
public float VelocityCompensation = 0.99f;
[Tooltip("How far the puffs fan out (0 = a straight jet)")]
public float Spread = 0.3f;
[Header("Rear booster (on while locked on)")]
[Tooltip("Emissive orange material for the rear jet. If empty, the side material is used")]
public Material MainExhaustMaterial;
[Tooltip("Where the rear jet leaves the round, metres behind its centre")]
public float MainTailOffset = 0.008f;
[Tooltip("Puffs per second")]
public float MainEmitRate = 600f;
public float MainParticleLifetime = 0.09f;
public float MainMinSize = 0.01f;
public float MainMaxSize = 0.024f;
[Tooltip("Speed the rear jet leaves the round at, relative to it, straight backwards (m/s)")]
public float MainExhaustSpeed = 16f;
[Tooltip("How far the rear jet fans out (0 = a straight jet)")]
public float MainSpread = 0.12f;
[Header("Sound")]
[Tooltip("Looping booster sound. If empty, a quiet rocket hiss is generated in code")]
public AudioClip BoosterSound;
[Tooltip("Loudness while the booster is on (0 to 1). Keep it low, the round is fast and there can be many of them")]
[Range(0f, 1f)]
public float BoosterVolume = 0.12f;
[Tooltip("Extra loudness (fraction of BoosterVolume) while the side thrusters fire as well")]
[Range(0f, 1f)]
public float SideThrusterVolumeBoost = 0.3f;
[Tooltip("Full volume closer than this (m)")]
public float SoundMinDistance = 1.5f;
[Tooltip("Silent further than this (m)")]
public float SoundMaxDistance = 25f;
[Tooltip("Seconds to fade the sound in or out, so it does not click")]
public float SoundFadeTime = 0.05f;
[Tooltip("How strong the Doppler pitch shift is (0 = none, 1 = realistic). The round is about as fast as sound, so expect a big pitch drop as it passes")]
[Range(0f, 5f)]
public float SoundDopplerLevel = 1f;
[Header("Light")]
[Tooltip("Colour of the light the booster gives off")]
public Color LightColor = new Color(1f, 0.6f, 0.22f, 1f);
[Tooltip("Brightness while the booster is on")]
public float LightIntensity = 3f;
[Tooltip("How far the light reaches (m). Big enough to light the walls of a corridor")]
public float LightRange = 14f;
[Tooltip("How much the light flickers, like a firework (0 = steady, 1 = wild)")]
[Range(0f, 1f)]
public float LightFlicker = 0.25f;
[Tooltip("Seconds to fade the light in or out")]
public float LightFadeTime = 0.04f;
private IThrustSource m_source;
private ParticleSystem m_sideParticles;
private ParticleSystem m_mainParticles;
private AudioSource m_audio;
private Light m_light;
private float m_lightLevel;
private float m_sideCarry;
private float m_mainCarry;
private static AudioClip s_generatedClip;
private void Awake()
{
if ((Object)(object)ThrustSourceBehaviour != (Object)null)
{
m_source = ThrustSourceBehaviour as IThrustSource;
}
if (m_source == null)
{
MonoBehaviour[] componentsInParent = ((Component)this).GetComponentsInParent<MonoBehaviour>(true);
for (int i = 0; i < componentsInParent.Length; i++)
{
if (componentsInParent[i] is IThrustSource source)
{
m_source = source;
break;
}
}
}
BuildParticles();
}
private void OnEnable()
{
m_sideCarry = 0f;
m_mainCarry = 0f;
if ((Object)(object)m_sideParticles != (Object)null)
{
m_sideParticles.Clear();
m_sideParticles.Play();
}
if ((Object)(object)m_mainParticles != (Object)null)
{
m_mainParticles.Clear();
m_mainParticles.Play();
}
if ((Object)(object)m_audio != (Object)null)
{
m_audio.Stop();
m_audio.volume = 0f;
}
m_lightLevel = 0f;
if ((Object)(object)m_light != (Object)null)
{
((Behaviour)m_light).enabled = false;
}
}
private void OnDisable()
{
if ((Object)(object)m_audio != (Object)null)
{
m_audio.Stop();
}
}
private void BuildParticles()
{
//IL_0153: Unknown result type (might be due to invalid IL or missing references)
m_sideParticles = CreateParticleSystem("TurnExhaust", ExhaustMaterial, ParticleLifetime, MaxSize);
Material material = ((!((Object)(object)MainExhaustMaterial != (Object)null)) ? ExhaustMaterial : MainExhaustMaterial);
m_mainParticles = CreateParticleSystem("MainExhaust", material, MainParticleLifetime, MainMaxSize);
m_audio = ((Component)m_mainParticles).gameObject.AddComponent<AudioSource>();
m_audio.clip = ((!((Object)(object)BoosterSound != (Object)null)) ? GetGeneratedClip() : BoosterSound);
m_audio.loop = true;
m_audio.playOnAwake = false;
m_audio.volume = 0f;
m_audio.spatialBlend = 1f;
m_audio.dopplerLevel = SoundDopplerLevel;
m_audio.velocityUpdateMode = (AudioVelocityUpdateMode)2;
m_audio.rolloffMode = (AudioRolloffMode)1;
m_audio.minDistance = SoundMinDistance;
m_audio.maxDistance = SoundMaxDistance;
m_light = ((Component)m_mainParticles).gameObject.AddComponent<Light>();
m_light.type = (LightType)2;
m_light.color = LightColor;
m_light.range = LightRange;
m_light.intensity = 0f;
m_light.shadows = (LightShadows)0;
((Behaviour)m_light).enabled = false;
}
private ParticleSystem CreateParticleSystem(string objectName, Material material, float lifetime, float startSize)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Expected O, but got Unknown
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_0103: Unknown result type (might be due to invalid IL or missing references)
//IL_0108: Unknown result type (might be due to invalid IL or missing references)
//IL_010d: Unknown result type (might be due to invalid IL or missing references)
//IL_0117: Expected O, but got Unknown
//IL_0112: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject(objectName);
val.transform.SetParent(((Component)this).transform, false);
ParticleSystem val2 = val.AddComponent<ParticleSystem>();
val2.Stop(true, (ParticleSystemStopBehavior)0);
MainModule main = val2.main;
((MainModule)(ref main)).playOnAwake = true;
((MainModule)(ref main)).loop = true;
((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(0f);
((MainModule)(ref main)).startLifetime = MinMaxCurve.op_Implicit(lifetime);
((MainModule)(ref main)).startSize = MinMaxCurve.op_Implicit(startSize);
((MainModule)(ref main)).maxParticles = 256;
EmissionModule emission = val2.emission;
((EmissionModule)(ref emission)).enabled = false;
ShapeModule shape = val2.shape;
((ShapeModule)(ref shape)).enabled = false;
SizeOverLifetimeModule sizeOverLifetime = val2.sizeOverLifetime;
((SizeOverLifetimeModule)(ref sizeOverLifetime)).enabled = true;
((SizeOverLifetimeModule)(ref sizeOverLifetime)).size = new MinMaxCurve(1f, new AnimationCurve((Keyframe[])(object)new Keyframe[3]
{
new Keyframe(0f, 1f),
new Keyframe(0.35f, 0.8f),
new Keyframe(1f, 0f)
}));
ParticleSystemRenderer component = val.GetComponent<ParticleSystemRenderer>();
component.renderMode = (ParticleSystemRenderMode)0;
((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
((Renderer)component).receiveShadows = false;
if ((Object)(object)material != (Object)null)
{
((Renderer)component).sharedMaterial = material;
}
val2.Play();
return val2;
}
private void LateUpdate()
{
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_0179: Unknown result type (might be due to invalid IL or missing references)
//IL_017e: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_0101: Unknown result type (might be due to invalid IL or missing references)
//IL_0115: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
//IL_0122: Unknown result type (might be due to invalid IL or missing references)
//IL_0124: Unknown result type (might be due to invalid IL or missing references)
//IL_012c: Unknown result type (might be due to invalid IL or missing references)
//IL_0131: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
//IL_01da: Unknown result type (might be due to invalid IL or missing references)
//IL_01df: Unknown result type (might be due to invalid IL or missing references)
//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0202: Unknown result type (might be due to invalid IL or missing references)
//IL_020d: Unknown result type (might be due to invalid IL or missing references)
//IL_0212: Unknown result type (might be due to invalid IL or missing references)
//IL_0217: Unknown result type (might be due to invalid IL or missing references)
//IL_021b: Unknown result type (might be due to invalid IL or missing references)
//IL_0226: Unknown result type (might be due to invalid IL or missing references)
//IL_023a: Unknown result type (might be due to invalid IL or missing references)
//IL_023f: Unknown result type (might be due to invalid IL or missing references)
//IL_0247: Unknown result type (might be due to invalid IL or missing references)
//IL_0249: Unknown result type (might be due to invalid IL or missing references)
//IL_0251: Unknown result type (might be due to invalid IL or missing references)
//IL_0256: Unknown result type (might be due to invalid IL or missing references)
//IL_0258: Unknown result type (might be due to invalid IL or missing references)
if (m_source == null)
{
return;
}
float mainThrust = m_source.MainThrust01;
float thrust = m_source.Thrust01;
bool flag = mainThrust >= 0.02f;
bool flag2 = thrust >= 0.02f;
Vector3 velocity = m_source.Velocity;
Vector3 val = ((!(((Vector3)(ref velocity)).sqrMagnitude > 0.01f)) ? ((Component)this).transform.forward : ((Vector3)(ref velocity)).normalized);
if (flag && (Object)(object)m_mainParticles != (Object)null)
{
int num = TakeWholePuffs(ref m_mainCarry, MainEmitRate * mainThrust);
if (num > 0)
{
Vector3 position = ((Component)this).transform.position - val * MainTailOffset;
for (int i = 0; i < num; i++)
{
Vector3 val2 = -val + Random.insideUnitSphere * MainSpread;
Vector3 val3 = ((Vector3)(ref val2)).normalized * MainExhaustSpeed * Random.Range(0.7f, 1f);
Emit(m_mainParticles, position, velocity * VelocityCompensation + val3, MainParticleLifetime, MainMinSize, MainMaxSize);
}
}
}
else
{
m_mainCarry = 0f;
}
Vector3 exhaustDirection = m_source.ExhaustDirection;
if (flag2 && (Object)(object)m_sideParticles != (Object)null && ((Vector3)(ref exhaustDirection)).sqrMagnitude >= 0.0001f)
{
int num2 = TakeWholePuffs(ref m_sideCarry, MaxEmitRate * thrust);
if (num2 > 0)
{
Vector3 position2 = ((Component)this).transform.position - val * TailOffset;
for (int j = 0; j < num2; j++)
{
Vector3 val4 = exhaustDirection - val * 0.25f + Random.insideUnitSphere * Spread;
val4 = ((Vector3)(ref val4)).normalized * ExhaustSpeed * Random.Range(0.6f, 1f);
Emit(m_sideParticles, position2, velocity * VelocityCompensation + val4, ParticleLifetime, MinSize, MaxSize);
}
}
}
else
{
m_sideCarry = 0f;
}
UpdateSound(flag || flag2, (!flag2) ? 0f : thrust);
UpdateLight(flag || flag2);
}
private void UpdateLight(bool anyActive)
{
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)m_light == (Object)null))
{
float num = Time.deltaTime / Mathf.Max(LightFadeTime, 0.001f);
m_lightLevel = Mathf.MoveTowards(m_lightLevel, (!anyActive) ? 0f : 1f, num);
if (m_lightLevel <= 0.001f)
{
((Behaviour)m_light).enabled = false;
return;
}
float num2 = 1f - LightFlicker * Random.Range(0f, 1f);
((Behaviour)m_light).enabled = true;
m_light.color = LightColor;
m_light.range = LightRange;
m_light.intensity = LightIntensity * m_lightLevel * num2;
}
}
private static int TakeWholePuffs(ref float carry, float perSecond)
{
carry += perSecond * Time.deltaTime;
int num = Mathf.FloorToInt(carry);
carry -= num;
return num;
}
private static void Emit(ParticleSystem system, Vector3 position, Vector3 velocity, float lifetime, float minSize, float maxSize)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
EmitParams val = default(EmitParams);
((EmitParams)(ref val)).position = position;
((EmitParams)(ref val)).velocity = velocity;
((EmitParams)(ref val)).startLifetime = lifetime * Random.Range(0.7f, 1f);
((EmitParams)(ref val)).startSize = Random.Range(minSize, maxSize);
((EmitParams)(ref val)).startColor = Color32.op_Implicit(Color.white);
system.Emit(val, 1);
}
private void UpdateSound(bool anyActive, float sideThrust)
{
if ((Object)(object)m_audio == (Object)null || (Object)(object)m_audio.clip == (Object)null)
{
return;
}
float num = ((!anyActive) ? 0f : (BoosterVolume * (1f + SideThrusterVolumeBoost * sideThrust)));
float num2 = Time.deltaTime * Mathf.Max(BoosterVolume, 0.01f) * (1f + SideThrusterVolumeBoost) / Mathf.Max(SoundFadeTime, 0.001f);
m_audio.volume = Mathf.MoveTowards(m_audio.volume, num, num2);
if (anyActive)
{
if (!m_audio.isPlaying)
{
m_audio.Play();
}
}
else if (m_audio.isPlaying && m_audio.volume <= 0.0005f)
{
m_audio.Stop();
}
}
private static AudioClip GetGeneratedClip()
{
if ((Object)(object)s_generatedClip != (Object)null)
{
return s_generatedClip;
}
Random random = new Random(9317);
float[] array = new float[24255];
float num = 0f;
float num2 = 0f;
float num3 = 0f;
float num4 = 0f;
for (int i = 0; i < array.Length; i++)
{
float num5 = (float)(random.NextDouble() * 2.0 - 1.0);
num += (num5 - num) * 0.45f;
num2 += (num - num2) * 0.04f;
float num6 = num - num2;
num3 += (num5 - num3) * 0.05f;
num4 += (num3 - num4) * 0.05f;
float num7 = num4 * 9f;
array[i] = num6 * 0.9f + num7 * 0.8f;
}
float[] array2 = new float[22050];
for (int j = 0; j < 22050; j++)
{
array2[j] = array[j];
}
for (int k = 0; k < 2205; k++)
{
float num8 = (float)k / 2205f;
array2[k] = array[k] * Mathf.Sqrt(num8) + array[22050 + k] * Mathf.Sqrt(1f - num8);
}
float num9 = 0.0001f;
for (int l = 0; l < 22050; l++)
{
float num10 = 1f + 0.18f * Mathf.Sin((float)Math.PI * 62f * (float)l / 22050f);
array2[l] *= num10;
float num11 = Mathf.Abs(array2[l]);
if (num11 > num9)
{
num9 = num11;
}
}
float num12 = 0.9f / num9;
for (int m = 0; m < 22050; m++)
{
array2[m] *= num12;
}
AudioClip val = AudioClip.Create("HomingBoosterLoop", 22050, 1, 22050, false);
val.SetData(array2, 0);
s_generatedClip = val;
return val;
}
}
[RequireComponent(typeof(BallisticProjectile))]
public class HomingProjectile : MonoBehaviour, IThrustSource
{
[Header("Seeking")]
[Tooltip("How far away a target can be picked up (metres)")]
public float SeekRange = 100f;
[Tooltip("Half-angle of the search cone around the round's heading (degrees). 90 = everything in the 180 degrees in front of it")]
public float AcquireConeAngle = 90f;
[Tooltip("Distance flown before the round looks for a target, so it does not steer inside the gun (metres). 0.3 = 30 cm")]
public float HomingStartDistance = 0.3f;
[Tooltip("The moment a target is found, point straight at it and keep pointing at it. Turn this off to use TurnRate instead")]
public bool InstantTurn = true;
[Tooltip("Only used when InstantTurn is off. How sharply the round can turn (degrees per second)")]
public float TurnRate = 1800f;
[Tooltip("How often the round looks for a target while it has none (seconds). 0 = every frame. At 350 m/s even 0.05 s is 17 m of flight, which is why it was missing targets before")]
public float RetargetInterval = 0f;
[Tooltip("Target is dropped when it is more than this many degrees away from the heading (it was passed)")]
public float LoseTargetAngle = 100f;
[Tooltip("Only lock onto targets that are not behind walls")]
public bool RequireLineOfSight = true;
[Tooltip("Aim for the head instead of the torso")]
public bool AimAtHead = false;
[Header("Side thrusters")]
[Tooltip("Turning rate (degrees per second) that counts as 'side thrusters at full power'")]
public float SideThrustFullRate = 1800f;
[Tooltip("How long the side puffs keep going after a turn (seconds), so a one-frame snap is still visible")]
public float SideThrustFadeTime = 0.12f;
private BallisticProjectile m_projectile;
private Transform m_target;
private Vector3 m_spawnPos;
private Vector3 m_startPos;
private bool m_started;
private bool m_searchedFromMuzzle;
private float m_retargetTimer;
private static bool s_resolved;
private static FieldInfo s_velocityField;
private static FieldInfo s_forwardField;
public float MainThrust01 { get; private set; }
public float Thrust01 { get; private set; }
public Vector3 ExhaustDirection { get; private set; }
public Vector3 Velocity { get; private set; }
public Transform CurrentTarget => m_target;
private void Awake()
{
m_projectile = ((Component)this).GetComponent<BallisticProjectile>();
ResolveFields();
}
private void OnEnable()
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
m_spawnPos = ((Component)this).transform.position;
m_started = false;
m_searchedFromMuzzle = false;
m_target = null;
m_retargetTimer = 0f;
MainThrust01 = 0f;
Thrust01 = 0f;
ExhaustDirection = Vector3.zero;
Velocity = Vector3.zero;
}
private static void ResolveFields()
{
if (!s_resolved)
{
s_resolved = true;
BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
s_velocityField = typeof(BallisticProjectile).GetField("m_velocity", bindingAttr);
s_forwardField = typeof(BallisticProjectile).GetField("m_forward", bindingAttr);
}
}
private void Update()
{
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
//IL_0100: Unknown result type (might be due to invalid IL or missing references)
//IL_0105: Unknown result type (might be due to invalid IL or missing references)
//IL_010a: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_0136: Unknown result type (might be due to invalid IL or missing references)
//IL_0138: Unknown result type (might be due to invalid IL or missing references)
//IL_013d: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_0170: Unknown result type (might be due to invalid IL or missing references)
//IL_0178: Unknown result type (might be due to invalid IL or missing references)
//IL_0183: Unknown result type (might be due to invalid IL or missing references)
//IL_0188: Unknown result type (might be due to invalid IL or missing references)
//IL_028e: Unknown result type (might be due to invalid IL or missing references)
//IL_0299: Unknown result type (might be due to invalid IL or missing references)
//IL_029e: Unknown result type (might be due to invalid IL or missing references)
//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
//IL_0228: Unknown result type (might be due to invalid IL or missing references)
//IL_022a: Unknown result type (might be due to invalid IL or missing references)
//IL_020d: Unknown result type (might be due to invalid IL or missing references)
//IL_0212: Unknown result type (might be due to invalid IL or missing references)
//IL_021a: Unknown result type (might be due to invalid IL or missing references)
//IL_021f: Unknown result type (might be due to invalid IL or missing references)
//IL_0224: Unknown result type (might be due to invalid IL or missing references)
//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
//IL_034f: Unknown result type (might be due to invalid IL or missing references)
//IL_0351: Unknown result type (might be due to invalid IL or missing references)
//IL_0353: Unknown result type (might be due to invalid IL or missing references)
//IL_0358: Unknown result type (might be due to invalid IL or missing references)
//IL_035a: Unknown result type (might be due to invalid IL or missing references)
//IL_035c: Unknown result type (might be due to invalid IL or missing references)
//IL_035e: Unknown result type (might be due to invalid IL or missing references)
//IL_0360: Unknown result type (might be due to invalid IL or missing references)
//IL_0367: Unknown result type (might be due to invalid IL or missing references)
//IL_036c: Unknown result type (might be due to invalid IL or missing references)
//IL_0371: Unknown result type (might be due to invalid IL or missing references)
//IL_03a1: Unknown result type (might be due to invalid IL or missing references)
//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
//IL_0387: Unknown result type (might be due to invalid IL or missing references)
//IL_038c: Unknown result type (might be due to invalid IL or missing references)
//IL_03da: Unknown result type (might be due to invalid IL or missing references)
//IL_03dc: Unknown result type (might be due to invalid IL or missing references)
//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)m_projectile == (Object)null || (object)s_velocityField == null)
{
return;
}
Vector3 val = (Vector3)s_velocityField.GetValue(m_projectile);
float magnitude = ((Vector3)(ref val)).magnitude;
if (magnitude < 1f)
{
MainThrust01 = 0f;
Thrust01 = 0f;
return;
}
Velocity = val;
float deltaTime = Time.deltaTime;
if (!m_started)
{
m_started = true;
Vector3 val2 = ((Component)this).transform.position - m_spawnPos;
m_startPos = ((!(((Vector3)(ref val2)).sqrMagnitude < 400f)) ? ((Component)this).transform.position : m_spawnPos);
}
Thrust01 = Mathf.Max(0f, Thrust01 - deltaTime / Mathf.Max(SideThrustFadeTime, 0.001f));
Vector3 val3 = ((Component)this).transform.position - m_startPos;
if (((Vector3)(ref val3)).sqrMagnitude < HomingStartDistance * HomingStartDistance)
{
MainThrust01 = 0f;
return;
}
Vector3 val4 = val / magnitude;
if ((Object)(object)m_target != (Object)null)
{
bool flag = HomingTargetRegistry.IsStillValid(m_target, m_projectile.Source_IFF);
if (flag && Vector3.Angle(val4, m_target.position - ((Component)this).transform.position) > LoseTargetAngle)
{
flag = false;
}
if (!flag)
{
m_target = null;
}
}
if ((Object)(object)m_target == (Object)null)
{
m_retargetTimer -= deltaTime;
if (m_retargetTimer <= 0f)
{
m_retargetTimer = RetargetInterval;
Vector3 origin = ((Component)this).transform.position;
if (!m_searchedFromMuzzle)
{
m_searchedFromMuzzle = true;
origin = m_startPos + val4 * HomingStartDistance;
}
m_target = HomingTargetRegistry.FindBest(origin, val4, SeekRange, AcquireConeAngle, m_projectile.Source_IFF, AimAtHead, RequireLineOfSight);
}
}
if ((Object)(object)m_target == (Object)null)
{
MainThrust01 = 0f;
return;
}
MainThrust01 = 1f;
Vector3 val5 = m_target.position - ((Component)this).transform.position;
Vector3 normalized = ((Vector3)(ref val5)).normalized;
Vector3 val6;
if (InstantTurn)
{
val6 = normalized;
}
else
{
float num = TurnRate * ((float)Math.PI / 180f) * deltaTime;
val6 = Vector3.RotateTowards(val4, normalized, num, 0f);
}
float num2 = Vector3.Angle(val4, val6) * ((float)Math.PI / 180f);
if (!(num2 < 1E-05f))
{
float num3 = num2 * 57.29578f / Mathf.Max(deltaTime, 0.0001f);
float num4 = Mathf.Clamp01(num3 / Mathf.Max(SideThrustFullRate, 1f));
if (num4 > Thrust01)
{
Thrust01 = num4;
}
Vector3 val7 = val6 - val4;
val7 -= val4 * Vector3.Dot(val7, val4);
if (((Vector3)(ref val7)).sqrMagnitude > 1E-12f)
{
ExhaustDirection = -((Vector3)(ref val7)).normalized;
}
s_velocityField.SetValue(m_projectile, val6 * magnitude);
if ((object)s_forwardField != null)
{
s_forwardField.SetValue(m_projectile, val6);
}
((Component)this).transform.rotation = Quaternion.LookRotation(val6);
}
}
}
public static class HomingTargetRegistry
{
private const float RefreshInterval = 0.25f;
private static readonly List<Sosig> s_sosigs = new List<Sosig>();
private static readonly List<AutoMeater> s_meaters = new List<AutoMeater>();
private static float s_lastRefresh = -100f;
private static int s_lastFrame = -1;
private static FieldInfo s_meaterState;
private static bool s_meaterStateResolved;
private const int MeaterDead = 4;
private const int SosigDead = 3;
private const int PartHead = 0;
private const int PartTorso = 1;
private const float LineOfSightIgnoreNear = 1f;
private static readonly RaycastHit[] s_hitBuffer = (RaycastHit[])(object)new RaycastHit[48];
private static void Refresh()
{
if (!(Time.time - s_lastRefresh < 0.25f) || s_lastFrame < 0)
{
s_lastRefresh = Time.time;
s_lastFrame = Time.frameCount;
s_sosigs.Clear();
s_meaters.Clear();
s_sosigs.AddRange(Object.FindObjectsOfType<Sosig>());
s_meaters.AddRange(Object.FindObjectsOfType<AutoMeater>());
}
}
private static bool IsMeaterAlive(AutoMeater meater)
{
if (!s_meaterStateResolved)
{
s_meaterStateResolved = true;
s_meaterState = typeof(AutoMeater).GetField("m_state", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
}
if ((object)s_meaterState == null)
{
return true;
}
object value = s_meaterState.GetValue(meater);
if (value == null)
{
return true;
}
return (int)value != 4;
}
private static Transform GetSosigAimPoint(Sosig sosig, bool aimAtHead)
{
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Invalid comparison between Unknown and I4
if (sosig.Links == null || sosig.Links.Count == 0)
{
return null;
}
int num = ((!aimAtHead) ? 1 : 0);
for (int i = 0; i < sosig.Links.Count; i++)
{
SosigLink val = sosig.Links[i];
if ((Object)(object)val != (Object)null && (int)val.BodyPart == num)
{
return ((Component)val).transform;
}
}
for (int j = 0; j < sosig.Links.Count; j++)
{
if ((Object)(object)sosig.Links[j] != (Object)null)
{
return ((Component)sosig.Links[j]).transform;
}
}
return null;
}
public static bool IsStillValid(Transform aimPoint, int sourceIFF)
{
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Invalid comparison between Unknown and I4
if ((Object)(object)aimPoint == (Object)null || !((Component)aimPoint).gameObject.activeInHierarchy)
{
return false;
}
SosigLink component = ((Component)aimPoint).GetComponent<SosigLink>();
if ((Object)(object)component != (Object)null)
{
if ((Object)(object)component.S == (Object)null)
{
return false;
}
if ((int)component.S.BodyState == 3)
{
return false;
}
if (component.S.GetIFF() == sourceIFF)
{
return false;
}
return true;
}
AutoMeater componentInParent = ((Component)aimPoint).GetComponentInParent<AutoMeater>();
if ((Object)(object)componentInParent != (Object)null)
{
return IsMeaterAlive(componentInParent);
}
return false;
}
public static Transform FindBest(Vector3 origin, Vector3 forward, float range, float coneAngleDeg, int sourceIFF, bool aimAtHead, bool requireLineOfSight)
{
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Invalid comparison between Unknown and I4
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
Refresh();
Transform best = null;
float bestScore = float.MaxValue;
float rangeSqr = range * range;
for (int i = 0; i < s_sosigs.Count; i++)
{
Sosig val = s_sosigs[i];
if (!((Object)(object)val == (Object)null) && (int)val.BodyState != 3 && val.GetIFF() != sourceIFF)
{
Transform sosigAimPoint = GetSosigAimPoint(val, aimAtHead);
Score(sosigAimPoint, origin, forward, rangeSqr, coneAngleDeg, requireLineOfSight, ref best, ref bestScore);
}
}
for (int j = 0; j < s_meaters.Count; j++)
{
AutoMeater val2 = s_meaters[j];
if (!((Object)(object)val2 == (Object)null) && IsMeaterAlive(val2))
{
Transform point = ((!((Object)(object)val2.TerminalHitZone != (Object)null)) ? ((Component)val2).transform : ((Component)val2.TerminalHitZone).transform);
Score(point, origin, forward, rangeSqr, coneAngleDeg, requireLineOfSight, ref best, ref bestScore);
}
}
return best;
}
private static bool HasLineOfSight(Vector3 origin, Transform point)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
Vector3 val = point.position - origin;
float magnitude = ((Vector3)(ref val)).magnitude;
if (magnitude < 0.5f)
{
return true;
}
int num = Physics.RaycastNonAlloc(origin, val / magnitude, s_hitBuffer, magnitude, -1, (QueryTriggerInteraction)1);
for (int i = 0; i < num; i++)
{
Collider collider = ((RaycastHit)(ref s_hitBuffer[i])).collider;
if (!((Object)(object)collider == (Object)null) && !(((RaycastHit)(ref s_hitBuffer[i])).distance < 1f) && !((Component)collider).transform.IsChildOf(point.root) && !((Object)(object)((Component)collider).GetComponentInParent<SosigLink>() != (Object)null) && !((Object)(object)((Component)collider).GetComponentInParent<AutoMeater>() != (Object)null) && !((Object)(object)((Component)collider).GetComponentInParent<FVRPhysicalObject>() != (Object)null) && (!((Object)(object)collider.attachedRigidbody != (Object)null) || !(collider.attachedRigidbody.mass < 2f)))
{
return false;
}
}
return true;
}
private static void Score(Transform point, Vector3 origin, Vector3 forward, float rangeSqr, float coneAngleDeg, bool requireLineOfSight, ref Transform best, ref float bestScore)
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)point == (Object)null)
{
return;
}
Vector3 val = point.position - origin;
float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
if (sqrMagnitude > rangeSqr || sqrMagnitude < 0.04f)
{
return;
}
float num = Vector3.Angle(forward, val);
if (!(num > coneAngleDeg))
{
float num2 = num * 10f + Mathf.Sqrt(sqrMagnitude) * 0.1f;
if (!(num2 >= bestScore) && (!requireLineOfSight || HasLineOfSight(origin, point)))
{
bestScore = num2;
best = point;
}
}
}
}
public interface IThrustSource
{
float MainThrust01 { get; }
float Thrust01 { get; }
Vector3 ExhaustDirection { get; }
Vector3 Velocity { get; }
}
}
namespace printerjoe.Homing9MM
{
[BepInPlugin("printerjoe.Homing9MM", "Homing9MM", "1.0.3")]
[BepInProcess("h3vr.exe")]
[Description("Built with MeatKit")]
[BepInDependency("h3vr.otherloader", "1.3.0")]
public class Homing9MMPlugin : BaseUnityPlugin
{
private static readonly string BasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
internal static ManualLogSource Logger;
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
LoadAssets();
}
private void LoadAssets()
{
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "printerjoe.Homing9MM");
OtherLoader.RegisterDirectLoad(BasePath, "printerjoe.Homing9MM", "", "", "homing9mm", "");
}
}
}