using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using System.Text.Json;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Gear;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.Attributes;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Microsoft.CodeAnalysis;
using Player;
using UnityEngine;
using UnityEngine.Rendering;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("YinhuaHELChargePulse")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.1")]
[assembly: AssemblyProduct("YinhuaHELChargePulse")]
[assembly: AssemblyTitle("YinhuaHELChargePulse")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace YinhuaHELChargePulse
{
internal sealed class MuzzleSurface
{
public string targetMaterial { get; set; } = "";
public int nativeVertexCount { get; set; }
public float[] vertices { get; set; } = Array.Empty<float>();
public float[] normals { get; set; } = Array.Empty<float>();
public float[] uv { get; set; } = Array.Empty<float>();
public int[] triangles { get; set; } = Array.Empty<int>();
}
internal static class Assets
{
internal const string SurfaceName = "YinhuaPulseMuzzle";
internal static MuzzleSurface Data = null;
internal static Mesh Surface = null;
private static Texture2D _albedo = null;
private static Texture2D _emission = null;
private static Texture2D _normal = null;
private static Texture2D _metal = null;
private static readonly string[] PaletteKeys = new string[5] { "_ColorA", "_ColorB", "_ColorC", "_ColorD", "_ColorE" };
private static byte[] Read(string name)
{
using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("PulseAssets." + name) ?? throw new FileNotFoundException(name);
using MemoryStream memoryStream = new MemoryStream();
stream.CopyTo(memoryStream);
return memoryStream.ToArray();
}
private static Texture2D LoadTexture(string name)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Expected O, but got Unknown
Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false, false);
if (!ImageConversion.LoadImage(val, new Il2CppStructArray<byte>(Read(name)), true))
{
Object.Destroy((Object)(object)val);
throw new InvalidDataException(name);
}
((Object)val).name = name;
((Object)val).hideFlags = (HideFlags)61;
((Texture)val).wrapMode = (TextureWrapMode)0;
((Texture)val).filterMode = (FilterMode)1;
return val;
}
private static Texture2D Flat(Color32 color)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Expected O, but got Unknown
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: 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_0035: Unknown result type (might be due to invalid IL or missing references)
Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false, true);
((Object)val).hideFlags = (HideFlags)61;
val.SetPixels32(new Il2CppStructArray<Color32>((Color32[])(object)new Color32[4] { color, color, color, color }));
val.Apply(false, true);
return val;
}
internal static void Load()
{
//IL_0121: Unknown result type (might be due to invalid IL or missing references)
//IL_0126: Unknown result type (might be due to invalid IL or missing references)
//IL_015f: Unknown result type (might be due to invalid IL or missing references)
//IL_0164: Unknown result type (might be due to invalid IL or missing references)
//IL_018c: Unknown result type (might be due to invalid IL or missing references)
//IL_0191: Unknown result type (might be due to invalid IL or missing references)
//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
//IL_01c6: Expected O, but got Unknown
//IL_0255: Unknown result type (might be due to invalid IL or missing references)
//IL_026b: Unknown result type (might be due to invalid IL or missing references)
Data = JsonSerializer.Deserialize<MuzzleSurface>(Read("muzzle.json")) ?? throw new InvalidDataException();
int count = Data.vertices.Length / 3;
if (count < 3 || Data.vertices.Length != count * 3 || Data.normals.Length != count * 3 || Data.uv.Length != count * 2 || Data.triangles.Length % 3 != 0 || Data.triangles.Any((int i) => i < 0 || i >= count))
{
throw new InvalidDataException("Invalid muzzle surface");
}
Vector3[] array = (Vector3[])(object)new Vector3[count];
Vector3[] array2 = (Vector3[])(object)new Vector3[count];
Vector2[] array3 = (Vector2[])(object)new Vector2[count];
for (int num = 0; num < count; num++)
{
array[num] = new Vector3(Data.vertices[num * 3], Data.vertices[num * 3 + 1], Data.vertices[num * 3 + 2]);
array2[num] = new Vector3(Data.normals[num * 3], Data.normals[num * 3 + 1], Data.normals[num * 3 + 2]);
array3[num] = new Vector2(Data.uv[num * 2], Data.uv[num * 2 + 1]);
}
Surface = new Mesh
{
name = "YinhuaPulseMuzzle",
hideFlags = (HideFlags)61
};
Surface.vertices = new Il2CppStructArray<Vector3>(array);
Surface.normals = new Il2CppStructArray<Vector3>(array2);
Surface.uv = new Il2CppStructArray<Vector2>(array3);
Surface.triangles = new Il2CppStructArray<int>(Data.triangles);
Surface.RecalculateBounds();
Surface.RecalculateTangents();
_albedo = LoadTexture("muzzle_albedo.png");
_emission = LoadTexture("muzzle_emission.png");
_normal = Flat(new Color32(byte.MaxValue, (byte)128, byte.MaxValue, (byte)128));
_metal = Flat(new Color32((byte)42, (byte)112, (byte)0, (byte)112));
}
internal static void OverrideSurface(MaterialPropertyBlock block, float gain)
{
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: 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_00d3: Unknown result type (might be due to invalid IL or missing references)
block.SetTexture("_MainTex", (Texture)(object)_albedo);
block.SetTexture("_EmissiveMap", (Texture)(object)_emission);
block.SetTexture("_BumpMap", (Texture)(object)_normal);
block.SetTexture("_MetallicGlossMap", (Texture)(object)_metal);
Vector4 val = default(Vector4);
((Vector4)(ref val))..ctor(1f, 1f, 0f, 0f);
block.SetVector("_MainTex_ST", val);
block.SetVector("_EmissiveMap_ST", val);
block.SetVector("_MetallicGlossMap_ST", val);
block.SetVector("_BumpMap_ST", val);
block.SetFloat("_ShadingType", 0f);
block.SetFloat("_EnableEmissive", 1f);
block.SetColor("_EmissiveColor", new Color(gain, gain, gain, 1f));
string[] paletteKeys = PaletteKeys;
foreach (string text in paletteKeys)
{
block.SetColor(text, Color.white);
}
}
internal static void Release()
{
Object[] array = (Object[])(object)new Object[5]
{
(Object)Surface,
(Object)_albedo,
(Object)_emission,
(Object)_normal,
(Object)_metal
};
foreach (Object val in array)
{
if (val != (Object)null)
{
Object.Destroy(val);
}
}
}
}
internal static class HELFilter
{
internal static bool Matches(uint baseItem, uint front, uint receiver, uint stock, uint mag)
{
if (baseItem == 109 && front == 27 && receiver == 10 && stock == 1)
{
return mag == 14;
}
return false;
}
}
[BepInPlugin("local.yinhua.hel.chargepulse", "Yinhua HEL Charge Pulse", "1.1.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public sealed class Plugin : BasePlugin
{
public const string Id = "local.yinhua.hel.chargepulse";
internal static ManualLogSource Logger;
internal static ConfigEntry<bool> Enabled;
internal static ConfigEntry<float> Idle;
internal static ConfigEntry<float> Peak;
internal static ConfigEntry<float> Cycles;
private Harmony? _harmony;
public override void Load()
{
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Expected O, but got Unknown
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Expected O, but got Unknown
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
//IL_00dd: Expected O, but got Unknown
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: Expected O, but got Unknown
//IL_019e: Unknown result type (might be due to invalid IL or missing references)
//IL_01ac: Expected O, but got Unknown
Logger = ((BasePlugin)this).Log;
Enabled = ((BasePlugin)this).Config.Bind<bool>("Visuals", "Enabled", true, "HEL 枪口脉冲材质开关。");
Idle = ((BasePlugin)this).Config.Bind<float>("Visuals", "IdleEmission", 0.065f, new ConfigDescription("开火或取消后的枪口发光强度。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
Peak = ((BasePlugin)this).Config.Bind<float>("Visuals", "ChargePeakEmission", 14f, new ConfigDescription("蓄力脉冲峰值HDR强度。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 40f), Array.Empty<object>()));
Cycles = ((BasePlugin)this).Config.Bind<float>("Visuals", "PulsesPerCharge", 1.5f, new ConfigDescription("每个实际蓄力时长内的脉冲周期数。自动适配0.1/0.2秒及其他正值。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 4f), Array.Empty<object>()));
Assets.Load();
_harmony = new Harmony("local.yinhua.hel.chargepulse");
_harmony.PatchAll(typeof(Plugin).Assembly);
Type type = (from a in AppDomain.CurrentDomain.GetAssemblies()
select a.GetType("EmissiveFX.BreathBehaviour", throwOnError: false)).FirstOrDefault((Type t) => t != null);
MethodInfo methodInfo = ((type == null) ? null : AccessTools.Method(type, "Accept", (Type[])null, (Type[])null));
if (methodInfo != null)
{
_harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(Plugin), "SkipMuzzle", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
((BasePlugin)this).AddComponent<PulseDriver>();
Logger.LogInfo((object)"HEL charge muzzle ready. Timing follows the active archetype. Direct local inventory; no scene searches; active only in level.");
}
private static bool SkipMuzzle(Renderer __0, ref bool __result)
{
if ((Object)(object)__0 != (Object)null && ((Object)((Component)__0).gameObject).name.Equals("YinhuaPulseMuzzle", StringComparison.Ordinal))
{
__result = false;
return false;
}
return true;
}
public override bool Unload()
{
PulseDriver.Instance?.Shutdown();
Harmony? harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
Assets.Release();
return true;
}
}
[HarmonyPatch(typeof(BulletWeapon), "TriggerAudioChargeup")]
internal static class BeginChargePatch
{
private static void Postfix(BulletWeapon __instance)
{
PulseDriver.Instance?.BeginCharge(__instance);
}
}
[HarmonyPatch(typeof(BulletWeapon), "Fire", new Type[] { typeof(bool) })]
internal static class ActualFirePatch
{
private static void Prefix(BulletWeapon __instance, out (int clip, float time) __state)
{
__state = (clip: __instance.m_clip, time: __instance.m_lastFireTime);
}
private static void Postfix(BulletWeapon __instance, (int clip, float time) __state)
{
if (__state.clip > 0 && (__instance.m_clip < __state.clip || __instance.m_lastFireTime != __state.time))
{
PulseDriver.Instance?.Fired(__instance);
}
}
}
[HarmonyPatch(typeof(BulletWeaponArchetype), "OnFireShot")]
internal static class FiredShotPatch
{
private static void Postfix(BulletWeaponArchetype __instance)
{
PulseDriver.Instance?.Fired(__instance.m_weapon);
}
}
[HarmonyPatch(typeof(BulletWeaponArchetype), "OnStopChargeup")]
internal static class CancelChargePatch
{
private static void Postfix(BulletWeaponArchetype __instance)
{
PulseDriver.Instance?.Cancel(__instance.m_weapon);
}
}
public sealed class PulseDriver : MonoBehaviour
{
internal static PulseDriver? Instance;
private PlayerInventoryLocal? _inventory;
private BulletWeapon? _weapon;
private MeshRenderer? _source;
private MeshRenderer? _surface;
private MeshFilter? _sourceFilter;
private Mesh? _sourceMesh;
private Material? _sourceMaterial;
private Material? _material;
private GameObject? _surfaceObject;
private int _slot;
private MaterialPropertyBlock _block;
private readonly PulseState _state = new PulseState();
private float _inventoryAt;
private float _attachAt;
private float _inspectAt;
private float _reportAt;
private bool _closed;
public PulseDriver(IntPtr pointer)
: base(pointer)
{
}
private void Awake()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
Instance = this;
_block = new MaterialPropertyBlock();
}
private void LateUpdate()
{
if (_closed)
{
return;
}
try
{
float time = Time.time;
if (!PrepareLocalInventory())
{
return;
}
object obj;
if (!Plugin.Enabled.Value || !((Object)(object)_inventory != (Object)null) || !((Component)_inventory).gameObject.activeInHierarchy)
{
obj = null;
}
else
{
ItemEquippable wieldedItem = ((PlayerInventoryBase)_inventory).WieldedItem;
obj = ((wieldedItem != null) ? ((Il2CppObjectBase)wieldedItem).TryCast<BulletWeapon>() : null);
}
BulletWeapon val = (BulletWeapon)obj;
if ((Object)(object)val != (Object)null && !IsHEL(val))
{
val = null;
}
if ((Object)(object)val != (Object)(object)_weapon || ((Object)(object)val == (Object)null && (Object)(object)_surfaceObject != (Object)null))
{
ReleaseSurface();
_weapon = val;
_attachAt = time;
}
if ((Object)(object)_weapon == (Object)null)
{
return;
}
if (time >= _inspectAt)
{
_inspectAt = time + 0.25f;
if ((Object)(object)_source != (Object)null && !CurrentSurfaceIsValid())
{
ReleaseSurface();
}
}
if ((Object)(object)_source == (Object)null && time >= _attachAt)
{
ReleaseSurface();
_attachAt = time + 0.25f;
Attach();
}
if (!((Object)(object)_surface == (Object)null) && !((Object)(object)_source == (Object)null))
{
BulletWeaponArchetype archeType = _weapon.m_archeType;
_state.Sync(archeType != null && archeType.m_inChargeup, time, ReadDuration());
Apply(time);
}
}
catch (Exception error)
{
Report(error);
ReleaseSurface();
_attachAt = Time.time + 0.5f;
}
}
[HideFromIl2Cpp]
private void ClearLocalInventory()
{
if (_inventory != null || _weapon != null || _surfaceObject != null || _source != null || _surface != null || _material != null)
{
ReleaseSurface();
}
_inventory = null;
_weapon = null;
_attachAt = (_inspectAt = 0f);
}
[HideFromIl2Cpp]
private bool PrepareLocalInventory()
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Invalid comparison between Unknown and I4
if ((int)GameStateManager.CurrentStateName != 10 || !Plugin.Enabled.Value)
{
ClearLocalInventory();
_inventoryAt = 0f;
return false;
}
float unscaledTime = Time.unscaledTime;
if (unscaledTime < _inventoryAt)
{
if (Object.op_Implicit((Object)(object)_inventory) && ((Component)_inventory).gameObject.activeInHierarchy)
{
return true;
}
ClearLocalInventory();
return false;
}
_inventoryAt = unscaledTime + 0.25f;
PlayerAgent localPlayerAgent = PlayerManager.GetLocalPlayerAgent();
if (!Object.op_Implicit((Object)(object)localPlayerAgent))
{
ClearLocalInventory();
return false;
}
PlayerInventoryBase inventory = localPlayerAgent.Inventory;
if (!Object.op_Implicit((Object)(object)inventory))
{
ClearLocalInventory();
return false;
}
PlayerInventoryLocal val = ((Il2CppObjectBase)inventory).TryCast<PlayerInventoryLocal>();
if (!Object.op_Implicit((Object)(object)val) || !((Component)val).gameObject.activeInHierarchy)
{
ClearLocalInventory();
return false;
}
if ((Object)(object)val == (Object)(object)_inventory)
{
return true;
}
ClearLocalInventory();
_inventory = val;
return true;
}
[HideFromIl2Cpp]
private static bool IsHEL(BulletWeapon weapon)
{
GearIDRange gearIDRange = ((ItemEquippable)weapon).GearIDRange;
if (gearIDRange != null)
{
return HELFilter.Matches(gearIDRange.GetCompID((eGearComponent)3), gearIDRange.GetCompID((eGearComponent)12), gearIDRange.GetCompID((eGearComponent)16), gearIDRange.GetCompID((eGearComponent)19), gearIDRange.GetCompID((eGearComponent)23));
}
return false;
}
[HideFromIl2Cpp]
private bool CurrentSurfaceIsValid()
{
if ((Object)(object)_source == (Object)null || !((Component)_source).gameObject.activeInHierarchy || !((Renderer)_source).enabled || (Object)(object)_surface == (Object)null || (Object)(object)_sourceFilter == (Object)null || (Object)(object)_sourceFilter.sharedMesh != (Object)(object)_sourceMesh)
{
return false;
}
Il2CppReferenceArray<Material> sharedMaterials = ((Renderer)_source).sharedMaterials;
if (_slot < ((Il2CppArrayBase<Material>)(object)sharedMaterials).Length)
{
return (Object)(object)((Il2CppArrayBase<Material>)(object)sharedMaterials)[_slot] == (Object)(object)_sourceMaterial;
}
return false;
}
[HideFromIl2Cpp]
private float ReadDuration()
{
BulletWeapon? weapon = _weapon;
BulletWeaponArchetype val = ((weapon != null) ? weapon.m_archeType : null);
if (val != null)
{
return val.ChargeupDelay();
}
return 0f;
}
[HideFromIl2Cpp]
internal void BeginCharge(BulletWeapon weapon)
{
if (_closed || !Plugin.Enabled.Value || (Object)(object)weapon != (Object)(object)_weapon || (Object)(object)_surface == (Object)null)
{
return;
}
try
{
_state.Begin(Time.time, ReadDuration());
Apply(Time.time);
}
catch (Exception error)
{
Report(error);
}
}
[HideFromIl2Cpp]
internal void Cancel(BulletWeapon weapon)
{
if ((Object)(object)weapon != (Object)(object)_weapon)
{
return;
}
_state.Cancel();
try
{
Apply(Time.time);
}
catch (Exception error)
{
Report(error);
}
}
[HideFromIl2Cpp]
internal void Fired(BulletWeapon weapon)
{
if ((Object)(object)weapon != (Object)(object)_weapon)
{
return;
}
_state.Fire();
try
{
Apply(Time.time);
}
catch (Exception error)
{
Report(error);
}
}
[HideFromIl2Cpp]
private void Attach()
{
//IL_0141: Unknown result type (might be due to invalid IL or missing references)
//IL_014b: Expected O, but got Unknown
//IL_0190: Unknown result type (might be due to invalid IL or missing references)
//IL_0195: Unknown result type (might be due to invalid IL or missing references)
//IL_01a5: Expected O, but got Unknown
if ((Object)(object)_weapon == (Object)null)
{
return;
}
foreach (Component item in (Il2CppArrayBase<Component>)(object)((Component)_weapon).gameObject.GetComponentsInChildren(Il2CppType.Of<MeshRenderer>(), false))
{
MeshRenderer val = ((Il2CppObjectBase)item).TryCast<MeshRenderer>();
if ((Object)(object)val == (Object)null || !((Renderer)val).enabled)
{
continue;
}
MeshFilter component = ((Component)val).GetComponent<MeshFilter>();
Mesh val2 = ((component != null) ? component.sharedMesh : null);
if ((Object)(object)val2 == (Object)null || val2.vertexCount != Assets.Data.nativeVertexCount)
{
continue;
}
Il2CppReferenceArray<Material> sharedMaterials = ((Renderer)val).sharedMaterials;
for (int i = 0; i < ((Il2CppArrayBase<Material>)(object)sharedMaterials).Length; i++)
{
Material val3 = ((Il2CppArrayBase<Material>)(object)sharedMaterials)[i];
if (!((Object)(object)val3 == (Object)null) && val3.HasProperty("_EmissiveColor") && val3.HasProperty("_EmissiveMap") && (((Object)val3).name.Contains(Assets.Data.targetMaterial, StringComparison.OrdinalIgnoreCase) || (((Il2CppArrayBase<Material>)(object)sharedMaterials).Length == 1 && ((Object)val2).name.StartsWith(Assets.Data.targetMaterial, StringComparison.OrdinalIgnoreCase))))
{
_source = val;
_sourceFilter = component;
_sourceMesh = val2;
_sourceMaterial = val3;
_slot = i;
_surfaceObject = new GameObject("YinhuaPulseMuzzle");
_surfaceObject.layer = ((Component)val).gameObject.layer;
_surfaceObject.transform.SetParent(((Component)val).transform, false);
_surfaceObject.AddComponent<MeshFilter>().sharedMesh = Assets.Surface;
_material = new Material(val3)
{
name = "YinhuaPulseMuzzle"
};
_material.EnableKeyword("ENABLE_EMISSIVE");
_material.SetFloat("_EnableEmissive", 1f);
_material.SetFloat("_ShadingType", 0f);
_surface = _surfaceObject.AddComponent<MeshRenderer>();
((Renderer)_surface).sharedMaterial = _material;
((Renderer)_surface).shadowCastingMode = (ShadowCastingMode)0;
((Renderer)_surface).receiveShadows = ((Renderer)val).receiveShadows;
Apply(Time.time);
return;
}
}
}
}
[HideFromIl2Cpp]
private void Apply(float now)
{
if (!((Object)(object)_source == (Object)null) && !((Object)(object)_surface == (Object)null))
{
_block.Clear();
((Renderer)_source).GetPropertyBlock(_block, _slot);
if (_block.isEmpty)
{
((Renderer)_source).GetPropertyBlock(_block);
}
float gain = _state.Intensity(now, Plugin.Idle.Value, Plugin.Peak.Value, Plugin.Cycles.Value);
Assets.OverrideSurface(_block, gain);
((Renderer)_surface).SetPropertyBlock(_block);
((Renderer)_surface).enabled = ((Renderer)_source).enabled;
}
}
[HideFromIl2Cpp]
private void ReleaseSurface()
{
_state.Sync(charging: false, 0f, 0f);
if ((Object)(object)_surfaceObject != (Object)null)
{
_surfaceObject.SetActive(false);
Object.Destroy((Object)(object)_surfaceObject);
}
if ((Object)(object)_material != (Object)null)
{
Object.Destroy((Object)(object)_material);
}
_source = (_surface = null);
_sourceFilter = null;
_sourceMesh = null;
_sourceMaterial = (_material = null);
_surfaceObject = null;
}
[HideFromIl2Cpp]
internal void Shutdown()
{
if (!_closed)
{
_closed = true;
ReleaseSurface();
if ((Object)(object)Instance == (Object)(object)this)
{
Instance = null;
}
Object.Destroy((Object)(object)this);
}
}
private void OnDestroy()
{
ReleaseSurface();
if ((Object)(object)Instance == (Object)(object)this)
{
Instance = null;
}
}
private void OnDisable()
{
ReleaseSurface();
_attachAt = 0f;
}
[HideFromIl2Cpp]
private void Report(Exception error)
{
if (!(Time.realtimeSinceStartup < _reportAt))
{
_reportAt = Time.realtimeSinceStartup + 5f;
Plugin.Logger.LogWarning((object)("HEL muzzle pulse: " + error.Message));
}
}
}
public sealed class PulseState
{
public bool Active { get; private set; }
public bool AwaitingNewCharge { get; private set; }
public float StartedAt { get; private set; }
public float Duration { get; private set; }
public void Begin(float now, float duration)
{
if (!Valid(duration))
{
Cancel();
return;
}
StartedAt = now;
Duration = duration;
Active = true;
AwaitingNewCharge = false;
}
public void Sync(bool charging, float now, float duration)
{
if (!charging || !Valid(duration))
{
Active = false;
AwaitingNewCharge = false;
}
else if (!AwaitingNewCharge)
{
if (!Active)
{
Begin(now, duration);
}
Duration = duration;
}
}
public void Fire()
{
Active = false;
AwaitingNewCharge = true;
}
public void Cancel()
{
Active = false;
AwaitingNewCharge = true;
}
public float Progress(float now)
{
if (!Active)
{
return 0f;
}
return Math.Clamp((now - StartedAt) / Duration, 0f, 1f);
}
public float Intensity(float now, float idle, float peak, float cycles)
{
if (!Active)
{
return idle;
}
float num = Math.Max(0f, now - StartedAt);
float num2 = Progress(now);
float num3 = 0.15f + 0.85f * num2 * num2 * (3f - 2f * num2);
float num4 = MathF.Sin((float)Math.PI * (num / Duration * cycles));
return idle + (Math.Max(idle, peak) - idle) * num3 * (0.25f + 0.75f * num4 * num4);
}
private static bool Valid(float v)
{
if (float.IsFinite(v))
{
return v > 0f;
}
return false;
}
}
}