using System.Collections;
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;
[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 FrostFlame
{
public sealed class FrostSprayer : FVRAlternateGrip
{
public const string DonorId = "JunkyardFlameThrower";
public Transform Nozzle;
public Material JetMaterial;
private AudioSource loop;
private AudioEvent ignite;
private AudioEvent extinguish;
private bool armed;
private ParticleSystemRenderer streamRenderer;
private MaterialPropertyBlock clipProperties;
public ParticleSystem Stream { get; private set; }
public bool Spraying { get; private set; }
public override void Start()
{
((FVRInteractiveObject)this).Start();
((MonoBehaviour)this).StartCoroutine(LoadStockEmitter());
}
private IEnumerator LoadStockEmitter()
{
FVRObject entry = null;
float deadline = Time.realtimeSinceStartup + 15f;
while (Time.realtimeSinceStartup < deadline && (IM.OD == null || !IM.OD.TryGetValue("JunkyardFlameThrower", out entry)))
{
yield return null;
}
if ((Object)(object)entry == (Object)null)
{
Debug.LogError((object)"FROST_FLAME_SPRAYER_FAILED: stock flamethrower not registered");
yield break;
}
AnvilCallback<GameObject> request = ((AnvilAsset)entry).GetGameObjectAsync();
yield return request;
FlameThrower donor = ((!((Object)(object)request.Result == (Object)null)) ? request.Result.GetComponent<FlameThrower>() : null);
if ((Object)(object)donor == (Object)null || (Object)(object)donor.FireParticles == (Object)null || (Object)(object)Nozzle == (Object)null || (Object)(object)donor.AudSource_FireLoop == (Object)null || (Object)(object)JetMaterial == (Object)null)
{
Debug.LogError((object)"FROST_FLAME_SPRAYER_FAILED: stock emitter or nozzle missing");
yield break;
}
ParticleSystem stream = Object.Instantiate<ParticleSystem>(donor.FireParticles, Nozzle, false);
((Component)stream).transform.localPosition = Vector3.zero;
((Component)stream).transform.localRotation = Quaternion.identity;
((Component)stream).gameObject.tag = "IgnitorSystem";
stream.Stop(false, (ParticleSystemStopBehavior)0);
MainModule main = stream.main;
((MainModule)(ref main)).playOnAwake = false;
((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
((MainModule)(ref main)).startLifetime = new MinMaxCurve(0.28f, 0.43f);
((MainModule)(ref main)).startSpeed = new MinMaxCurve(13f, 17f);
((MainModule)(ref main)).startSize = new MinMaxCurve(0.155f, 0.274f);
((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(Color.white);
ShapeModule shape = stream.shape;
((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)4;
((ShapeModule)(ref shape)).radius = 0.012f;
((ShapeModule)(ref shape)).angle = 6f;
((ShapeModule)(ref shape)).randomDirectionAmount = 0f;
((ShapeModule)(ref shape)).sphericalDirectionAmount = 0f;
ForceOverLifetimeModule force = stream.forceOverLifetime;
((ForceOverLifetimeModule)(ref force)).enabled = false;
EmissionModule emission = stream.emission;
((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(105f);
streamRenderer = ((Component)stream).GetComponent<ParticleSystemRenderer>();
streamRenderer.renderMode = (ParticleSystemRenderMode)1;
streamRenderer.lengthScale = 2.7f;
streamRenderer.velocityScale = 0.02f;
((Renderer)streamRenderer).sharedMaterials = (Material[])(object)new Material[1] { JetMaterial };
clipProperties = new MaterialPropertyBlock();
UpdateNozzlePlane();
Gradient gradient = new Gradient();
gradient.SetKeys((GradientColorKey[])(object)new GradientColorKey[4]
{
new GradientColorKey(new Color(0.42f, 0.85f, 1f), 0f),
new GradientColorKey(new Color(0.08f, 0.54f, 1f), 0.22f),
new GradientColorKey(new Color(0.035f, 0.24f, 1f), 0.63f),
new GradientColorKey(new Color(0.12f, 0.22f, 0.78f), 1f)
}, (GradientAlphaKey[])(object)new GradientAlphaKey[4]
{
new GradientAlphaKey(0.83f, 0f),
new GradientAlphaKey(0.64f, 0.28f),
new GradientAlphaKey(0.26f, 0.7f),
new GradientAlphaKey(0f, 1f)
});
ColorOverLifetimeModule color = stream.colorOverLifetime;
((ColorOverLifetimeModule)(ref color)).enabled = true;
((ColorOverLifetimeModule)(ref color)).color = new MinMaxGradient(gradient);
SizeOverLifetimeModule size = stream.sizeOverLifetime;
((SizeOverLifetimeModule)(ref size)).enabled = true;
((SizeOverLifetimeModule)(ref size)).size = new MinMaxCurve(1f, AnimationCurve.Linear(0f, 0.58f, 1f, 1.7f));
loop = ((Component)Nozzle).gameObject.AddComponent<AudioSource>();
loop.playOnAwake = false;
loop.clip = donor.AudSource_FireLoop.clip;
loop.outputAudioMixerGroup = donor.AudSource_FireLoop.outputAudioMixerGroup;
loop.loop = true;
loop.spatialBlend = 1f;
loop.volume = 0.58f;
loop.pitch = 1.13f;
loop.maxDistance = 22f;
ignite = donor.AudEvent_Ignite;
extinguish = donor.AudEvent_Extinguish;
Stream = stream;
Debug.Log((object)"FROST_FLAME_SPRAYER_READY");
}
private void UpdateNozzlePlane()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: 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)
Vector3 forward = Nozzle.forward;
clipProperties.SetVector("_NozzlePlane", new Vector4(forward.x, forward.y, forward.z, 0f - Vector3.Dot(forward, Nozzle.position)));
((Renderer)streamRenderer).SetPropertyBlock(clipProperties);
}
private void LateUpdate()
{
if ((Object)(object)Stream != (Object)null && (Spraying || Stream.particleCount > 0))
{
UpdateNozzlePlane();
}
}
public void SetTrigger(bool gripHeld, float pressure)
{
if (!gripHeld)
{
armed = false;
}
else if (pressure < 0.2f)
{
armed = true;
}
SetSpraying(gripHeld && armed && pressure >= 0.68f && ((Behaviour)this).isActiveAndEnabled && (Object)(object)Stream != (Object)null);
}
private void SetSpraying(bool active)
{
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
if (Spraying == active)
{
return;
}
Spraying = active;
if (active)
{
UpdateNozzlePlane();
Stream.Play(false);
if ((Object)(object)loop.clip != (Object)null)
{
loop.Play();
}
if (ignite != null)
{
SM.PlayGenericSound(ignite, Nozzle.position);
}
return;
}
if ((Object)(object)Stream != (Object)null)
{
Stream.Stop(false, (ParticleSystemStopBehavior)1);
}
if ((Object)(object)loop != (Object)null)
{
loop.Stop();
}
if (((Behaviour)this).isActiveAndEnabled && extinguish != null)
{
SM.PlayGenericSound(extinguish, Nozzle.position);
}
}
public override void BeginInteraction(FVRViveHand hand)
{
((FVRAlternateGrip)this).BeginInteraction(hand);
armed = false;
SetTrigger(((FVRInteractiveObject)this).IsHeld && ((FVRInteractiveObject)base.PrimaryObject).IsHeld, hand.Input.TriggerFloat);
}
public override void UpdateInteraction(FVRViveHand hand)
{
((FVRAlternateGrip)this).UpdateInteraction(hand);
SetTrigger(((FVRInteractiveObject)this).IsHeld && ((FVRInteractiveObject)base.PrimaryObject).IsHeld, hand.Input.TriggerFloat);
}
public override void EndInteraction(FVRViveHand hand)
{
SetTrigger(gripHeld: false, 0f);
((FVRAlternateGrip)this).EndInteraction(hand);
}
private void OnDisable()
{
SetTrigger(gripHeld: false, 0f);
if ((Object)(object)Stream != (Object)null)
{
Stream.Stop(false, (ParticleSystemStopBehavior)0);
}
}
public override void OnDestroy()
{
if ((Object)(object)Stream != (Object)null)
{
Object.Destroy((Object)(object)((Component)Stream).gameObject);
}
((FVRInteractiveObject)this).OnDestroy();
}
}
}
namespace LocalTest.NZFrostFlame
{
[BepInPlugin("LocalTest.NZFrostFlame", "NZFrostFlame", "0.1.2")]
[BepInProcess("h3vr.exe")]
[Description("Built with MeatKit")]
[BepInDependency("h3vr.otherloader", "1.3.0")]
public class NZFrostFlamePlugin : 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(), "LocalTest.NZFrostFlame");
OtherLoader.RegisterDirectLoad(BasePath, "LocalTest.NZFrostFlame", "", "", "nz_frost_flame", "");
}
}
}