Decompiled source of ForgeSkin v1.0.1

plugins/ForgeSkin/ForgeSkin.Plugin.dll

Decompiled 2 hours ago
using System;
using System.Buffers.Binary;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Cryptography;
using System.Security.Permissions;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Agents;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Unity.IL2CPP;
using CellMenu;
using ForgeAudio;
using ForgeCore;
using ForgeSkin.Format;
using ForgeUI;
using ForgeVisual;
using GameData;
using Gear;
using HarmonyLib;
using Il2CppInterop.Common;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using Player;
using RootMotion.FinalIK;
using SNetwork;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("ForgeSkin.Plugin")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("ForgeSkin.Plugin")]
[assembly: AssemblyTitle("ForgeSkin.Plugin")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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 ForgeSkin.Plugin
{
	internal sealed class AmmoScreen
	{
		private const int Blank = 10;

		private const int Percent = 12;

		private const float Step = 0.0002f;

		private static readonly int[] Pow10 = new int[7] { 1, 10, 100, 1000, 10000, 100000, 1000000 };

		private readonly ScreenSource _source;

		private readonly bool _pad;

		private readonly MeshFilter[] _cells;

		private readonly Mesh?[] _glyphs = (Mesh?[])(object)new Mesh["0123456789 -%".Length];

		private readonly int _digits;

		private readonly Transform? _bar;

		private readonly float _barWidth;

		private readonly Material? _text;

		private readonly Material? _border;

		private readonly Material _template;

		private readonly Hologram? _hologram;

		private readonly float[] _textColor;

		private readonly float[]? _lowColor;

		private const float GlowUnit = 0.2f;

		private readonly float _gain;

		private readonly float _lowFraction;

		private readonly bool _gradient;

		private readonly float _gradientStart;

		private readonly bool _hasLow;

		private readonly SkinnedGear _gear;

		private PlayerAmmoStorage? _storage;

		private AmmoType _ammoType;

		private int _clipSize;

		private int _value = int.MinValue;

		private readonly string _label;

		public readonly List<Material> Surfaces = new List<Material>();

		private bool _low;

		private float _mix;

		private readonly float[] _mixed = new float[3];

		private readonly bool _grow;

		private readonly float _dw;

		private int _shown;

		public AmmoScreen(SkinnedGear gear, Skin skin, Screen s, Material template, GameObject root, Hologram? hologram)
		{
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_056b: Unknown result type (might be due to invalid IL or missing references)
			_hologram = hologram;
			_source = s.Source;
			_gear = gear;
			_label = gear.Label;
			_pad = s.PadZero;
			_template = template;
			_gain = (s.GlowInGame ? (s.Glow * 0.2f) : 0f);
			_textColor = s.TextColor;
			float num = s.Size[0];
			float num2 = s.Size[1];
			float num3 = Math.Min(s.BorderWidth, Math.Min(num, num2) * 0.5f);
			if (s.BorderColor[3] > 0.01f && s.BorderMesh != null)
			{
				((Component)gear.Child(root, "border", skin.Mesh(s.BorderMesh), _border = Surface(gear, s.BorderColor, _gain), -0.0002f)).transform.localScale = new Vector3(num2, num2, 1f);
			}
			else if (s.BorderColor[3] > 0.01f && num3 > 0f)
			{
				gear.Child(root, "border", gear.Own<Mesh>(Frame(num, num2, num3)), _border = Surface(gear, s.BorderColor, _gain), -0.0002f);
			}
			if (s.PanelColor[3] > 0.01f)
			{
				gear.Child(root, "panel", gear.Own<Mesh>(Quad(num - 2f * num3, num2 - 2f * num3)), Surface(gear, s.PanelColor, s.GlowInGame ? 0.01f : 0f), 0f);
			}
			_text = Surface(gear, s.TextColor, _gain);
			Surfaces.Remove(_text);
			_hasLow = s.LowAmmoColor != null && s.Source.IsAmmo();
			_lowColor = (_hasLow ? s.LowAmmoColor : null);
			_lowFraction = s.LowAmmoFraction;
			_gradient = s.LowAmmoGradient;
			_gradientStart = s.LowAmmoGradientStart;
			float num4 = (num - 2f * num3) * 0.95f;
			float num5 = num2 * s.TextScale;
			_cells = Array.Empty<MeshFilter>();
			if (s.Source == ScreenSource.Static)
			{
				if (s.TextMesh != null)
				{
					num5 *= Math.Min(1f, num4 / (num5 * s.TextAspect));
					((Component)gear.Child(root, "text", skin.Mesh(s.TextMesh), _text, -0.0004f)).transform.localScale = new Vector3(num5, num5, 1f);
				}
				return;
			}
			if (s.Source.IsAmmo())
			{
				_storage = gear.Storage(out _ammoType, out _clipSize);
			}
			if (s.Style == ScreenStyle.Bar && s.Source.Bounded())
			{
				_barWidth = num - 2f * num3;
				_bar = ((Component)gear.Child(root, "bar", gear.Own<Mesh>(Quad(1f, Math.Min(num5, num2 - 2f * num3), fromLeft: true)), _text, -0.0004f)).transform;
				_bar.localPosition = new Vector3((0f - _barWidth) * 0.5f, 0f, -0.0004f);
				_bar.localScale = new Vector3(0f, 1f, 1f);
			}
			else if (s.GlyphMeshes != null)
			{
				for (int i = 0; i < Math.Min(_glyphs.Length, s.GlyphMeshes.Length); i++)
				{
					Mesh?[] glyphs = _glyphs;
					int num6 = i;
					string text = s.GlyphMeshes[i];
					glyphs[num6] = ((text != null) ? skin.Mesh(text) : null);
				}
				_grow = s.Digits == 0 && !s.Source.Bounded();
				_digits = ((s.Digits > 0) ? s.Digits : ((!_grow) ? ((_storage != null) ? DigitCount(Max()) : 3) : ((s.Source == ScreenSource.Kills) ? 4 : 6)));
				int num7 = _digits + ((s.Source.IsPercent() && (Object)(object)_glyphs[12] != (Object)null) ? 1 : 0);
				_dw = num5 * s.GlyphAspect;
				float num8 = num4 / (_dw * (float)num7);
				if (num8 < 1f)
				{
					_dw *= num8;
					num5 *= num8;
				}
				_cells = (MeshFilter[])(object)new MeshFilter[num7];
				for (int j = 0; j < _cells.Length; j++)
				{
					_cells[j] = gear.Child(root, "digit" + j, (j < _digits) ? _glyphs[10] : _glyphs[12], _text, -0.0004f);
					((Component)_cells[j]).transform.localScale = new Vector3(num5, num5, 1f);
				}
				Place(num7);
			}
		}

		private static int DigitCount(int n)
		{
			int num = 1;
			for (n = Math.Max(0, n); n >= 10; n /= 10)
			{
				num++;
			}
			return Math.Min(num, Pow10.Length - 1);
		}

		private void Place(int shown)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			if (shown != _shown)
			{
				_shown = shown;
				for (int i = 0; i < shown; i++)
				{
					((Component)_cells[i]).transform.localPosition = new Vector3(_dw * ((float)i + 0.5f - (float)shown * 0.5f), 0f, -0.0004f);
				}
			}
		}

		private int Max()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			return _source switch
			{
				ScreenSource.AmmoClip => _clipSize, 
				ScreenSource.AmmoReserve => _storage.GetBulletMaxCap(_ammoType), 
				_ => _clipSize + _storage.GetBulletMaxCap(_ammoType), 
			};
		}

		private Material Surface(SkinnedGear gear, float[] c, float gain)
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Expected O, but got Unknown
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Expected O, but got Unknown
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			if (_hologram != null)
			{
				Material val = Holograms.Surface(gear, _template, null, new Color(c[0], c[1], c[2]), ((gain > 0f) ? gain : 0.3f) * _hologram.Opacity);
				Surfaces.Add(val);
				return val;
			}
			Material val2 = gear.Own<Material>(new Material(_template)
			{
				name = "ForgeSkin screen"
			});
			Surfaces.Add(val2);
			val2.SetTexture(SkinnedGear.MetallicGlossMap, (Texture)(object)Texture2D.blackTexture);
			val2.SetTexture(SkinnedGear.BumpMap, (Texture)null);
			val2.SetTexture(SkinnedGear.EmissiveMap, (Texture)(object)Texture2D.whiteTexture);
			val2.SetTexture(SkinnedGear.MainTex, (Texture)(object)gear.Own<Texture2D>(new Texture2D(1, 1, (TextureFormat)4, false)
			{
				name = "ForgeSkin screen colour"
			}));
			Paint(val2, c, gain);
			return val2;
		}

		private void Paint(Material m, float[] c, float gain)
		{
			//IL_005a: 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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			Color val = default(Color);
			((Color)(ref val))..ctor(c[0], c[1], c[2]);
			if (Holograms.Is(m))
			{
				Holograms.Paint(m, val, ((gain > 0f) ? gain : 0.3f) * (_hologram?.Opacity ?? 1f));
				return;
			}
			Texture2D obj = ((Il2CppObjectBase)m.GetTexture(SkinnedGear.MainTex)).Cast<Texture2D>();
			obj.SetPixel(0, 0, val);
			obj.Apply(false, false);
			if (gain > 0f)
			{
				SkinnedGear.SetEmission(m, val, gain);
				return;
			}
			Glow.SetColour(m, Color.black);
			SkinnedGear.SetEmissive(m, on: false);
		}

		private static Mesh Quad(float w, float h, bool fromLeft = false)
		{
			//IL_001f: 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_0030: Expected O, but got Unknown
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: 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_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: 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)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: 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_0106: 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_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			float num = (fromLeft ? 0f : ((0f - w) * 0.5f));
			float num2 = num + w;
			float num3 = h * 0.5f;
			Mesh val = new Mesh
			{
				name = "ForgeSkin quad"
			};
			val.vertices = Il2CppStructArray<Vector3>.op_Implicit((Vector3[])(object)new Vector3[4]
			{
				new Vector3(num, 0f - num3, 0f),
				new Vector3(num2, 0f - num3, 0f),
				new Vector3(num, num3, 0f),
				new Vector3(num2, num3, 0f)
			});
			val.uv = Il2CppStructArray<Vector2>.op_Implicit((Vector2[])(object)new Vector2[4]
			{
				new Vector2(0f, 0f),
				new Vector2(1f, 0f),
				new Vector2(0f, 1f),
				new Vector2(1f, 1f)
			});
			val.normals = Il2CppStructArray<Vector3>.op_Implicit((Vector3[])(object)new Vector3[4]
			{
				Vector3.back,
				Vector3.back,
				Vector3.back,
				Vector3.back
			});
			val.triangles = Il2CppStructArray<int>.op_Implicit(new int[6] { 0, 2, 3, 0, 3, 1 });
			val.RecalculateTangents();
			val.RecalculateBounds();
			return val;
		}

		private static Mesh Frame(float w, float h, float bw)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: 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_007e: 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_0092: 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_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_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: 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_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: 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_0250: Expected O, but got Unknown
			float num = w * 0.5f;
			float num2 = h * 0.5f;
			float num3 = num - bw;
			float num4 = num2 - bw;
			Vector3[] array = (Vector3[])(object)new Vector3[8]
			{
				new Vector3(0f - num, 0f - num2, 0f),
				new Vector3(num, 0f - num2, 0f),
				new Vector3(num, num2, 0f),
				new Vector3(0f - num, num2, 0f),
				new Vector3(0f - num3, 0f - num4, 0f),
				new Vector3(num3, 0f - num4, 0f),
				new Vector3(num3, num4, 0f),
				new Vector3(0f - num3, num4, 0f)
			};
			Vector2[] array2 = (Vector2[])(object)new Vector2[8];
			Vector3[] array3 = (Vector3[])(object)new Vector3[8];
			Vector2 val = default(Vector2);
			for (int i = 0; i < 8; i++)
			{
				ref Vector2 reference = ref array2[i];
				ref Vector3 reference2 = ref array3[i];
				((Vector2)(ref val))..ctor(array[i].x / w + 0.5f, array[i].y / h + 0.5f);
				Vector3 back = Vector3.back;
				reference = val;
				reference2 = back;
			}
			int[] array4 = new int[24];
			for (int j = 0; j < 4; j++)
			{
				int num5 = j;
				int num6 = (j + 1) % 4;
				int num7 = 4 + j;
				int num8 = 4 + (j + 1) % 4;
				ref int reference3 = ref array4[j * 6];
				ref int reference4 = ref array4[j * 6 + 1];
				ref int reference5 = ref array4[j * 6 + 2];
				int num9 = num5;
				int num10 = num7;
				int num11 = num8;
				reference3 = num9;
				reference4 = num10;
				reference5 = num11;
				reference4 = ref array4[j * 6 + 3];
				reference3 = ref array4[j * 6 + 4];
				ref int reference6 = ref array4[j * 6 + 5];
				num11 = num5;
				num10 = num8;
				num9 = num6;
				reference4 = num11;
				reference3 = num10;
				reference6 = num9;
			}
			Mesh val2 = new Mesh
			{
				name = "ForgeSkin frame",
				vertices = Il2CppStructArray<Vector3>.op_Implicit(array),
				uv = Il2CppStructArray<Vector2>.op_Implicit(array2),
				normals = Il2CppStructArray<Vector3>.op_Implicit(array3),
				triangles = Il2CppStructArray<int>.op_Implicit(array4)
			};
			val2.RecalculateTangents();
			val2.RecalculateBounds();
			return val2;
		}

		public string Describe()
		{
			return $"emission gain {_gain}, text [{M(_text)}]{(_low ? " (low)" : "")}, border [{M(_border)}], template {((Object)_template).name} / {((Object)_template.shader).name} keywords [{string.Join(" ", Il2CppArrayBase<string>.op_Implicit((Il2CppArrayBase<string>)(object)_template.shaderKeywords))}]";
			static string M(Material? m)
			{
				//IL_0044: 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_0099: Unknown result type (might be due to invalid IL or missing references)
				//IL_009e: Unknown result type (might be due to invalid IL or missing references)
				if (!((Object)(object)m == (Object)null))
				{
					DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(60, 4);
					defaultInterpolatedStringHandler.AppendLiteral("albedo ");
					Texture texture = m.GetTexture(SkinnedGear.MainTex);
					object obj;
					if (texture == null)
					{
						obj = null;
					}
					else
					{
						Texture2D obj2 = ((Il2CppObjectBase)texture).TryCast<Texture2D>();
						obj = ((obj2 != null) ? ((object)obj2.GetPixel(0, 0)/*cast due to .constrained prefix*/).ToString() : null);
					}
					if (obj == null)
					{
						obj = "?";
					}
					defaultInterpolatedStringHandler.AppendFormatted((string?)obj);
					defaultInterpolatedStringHandler.AppendLiteral(", ");
					defaultInterpolatedStringHandler.AppendLiteral("_EmissiveColor ");
					defaultInterpolatedStringHandler.AppendFormatted(m.HasProperty(SkinnedGear.EmissiveColor) ? ((object)m.GetColor(SkinnedGear.EmissiveColor)/*cast due to .constrained prefix*/).ToString() : "-");
					defaultInterpolatedStringHandler.AppendLiteral(", ");
					defaultInterpolatedStringHandler.AppendLiteral("_EnableEmissive ");
					defaultInterpolatedStringHandler.AppendFormatted(m.HasProperty(SkinnedGear.EnableEmissive) ? m.GetFloat(SkinnedGear.EnableEmissive) : (-1f));
					defaultInterpolatedStringHandler.AppendLiteral(", ENABLE_EMISSIVE ");
					defaultInterpolatedStringHandler.AppendFormatted(m.IsKeywordEnabled("ENABLE_EMISSIVE"));
					return defaultInterpolatedStringHandler.ToStringAndClear();
				}
				return "none";
			}
		}

		public void Update(int clip)
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			if ((_cells.Length == 0 && (Object)(object)_bar == (Object)null) || _source == ScreenSource.Static)
			{
				return;
			}
			int num2;
			if (_source.IsAmmo())
			{
				if (_storage == null && (_storage = _gear.Storage(out _ammoType, out _clipSize)) == null)
				{
					return;
				}
				int num = ((_source != ScreenSource.AmmoClip) ? _storage.GetBulletsInPack(_ammoType) : 0);
				num2 = _source switch
				{
					ScreenSource.AmmoClip => clip, 
					ScreenSource.AmmoReserve => num, 
					_ => clip + num, 
				};
			}
			else
			{
				num2 = _source switch
				{
					ScreenSource.Kills => _gear.Kills, 
					ScreenSource.DamageDealt => (int)_gear.Damage, 
					ScreenSource.DamageDealtAll => (int)SkinnedGear.DamageAll, 
					ScreenSource.DamageTaken => (int)SkinnedGear.DamageTaken, 
					ScreenSource.Accuracy => (_gear.Shots > 0) ? (_gear.ShotHits * 100 / _gear.Shots) : 0, 
					ScreenSource.Health => Mathf.RoundToInt(SkinnedGear.Health), 
					_ => Mathf.RoundToInt(SkinnedGear.Infection), 
				};
			}
			if (num2 == _value)
			{
				return;
			}
			bool flag = _value == int.MinValue;
			if (flag)
			{
				bool open;
				ForgeSkinPlugin.AuthorLine message = new ForgeSkinPlugin.AuthorLine(22, 3, out open);
				if (open)
				{
					message.AppendFormatted(_label);
					message.AppendLiteral(": screen ");
					message.AppendFormatted(_source);
					message.AppendLiteral(" first value ");
					message.AppendFormatted(num2);
				}
				ForgeSkinPlugin.Info(ref message);
			}
			_value = num2;
			int num3 = (_source.IsAmmo() ? Max() : 100);
			if ((Object)(object)_bar != (Object)null)
			{
				_bar.localScale = new Vector3((num3 > 0) ? (_barWidth * Mathf.Clamp01((float)num2 / (float)num3)) : 0f, 1f, 1f);
			}
			else
			{
				Show(num2);
			}
			if (_hasLow)
			{
				SetMix(Tint(num2, num3), num2, num3, flag);
			}
		}

		private void Show(int value)
		{
			int num = Math.Min(Math.Max(0, value), Pow10[_digits] - 1);
			int num2 = (_grow ? DigitCount(num) : _digits);
			Place(_grow ? num2 : _cells.Length);
			for (int num3 = _digits - 1; num3 >= 0; num3--)
			{
				if (num3 >= num2)
				{
					_cells[num3].sharedMesh = _glyphs[10];
				}
				else
				{
					int num4 = num % 10;
					num /= 10;
					bool flag = !_pad && num3 != num2 - 1 && num4 == 0 && num == 0;
					_cells[num3].sharedMesh = _glyphs[flag ? 10 : num4];
				}
			}
		}

		private float Tint(int value, int max)
		{
			if (max <= 0)
			{
				return 0f;
			}
			float num = Math.Min(1f, (float)value / (float)max);
			float num2 = (_gradient ? Math.Max(_lowFraction, _gradientStart) : _lowFraction);
			if (!(num2 <= _lowFraction))
			{
				return Mathf.Clamp01((num2 - num) / (num2 - _lowFraction));
			}
			if (!(num <= _lowFraction))
			{
				return 0f;
			}
			return 1f;
		}

		private void SetMix(float mix, int value, int max, bool first)
		{
			if ((first && mix == 0f) || (!first && mix == _mix))
			{
				return;
			}
			bool low = _low;
			bool flag = _mix > 0f;
			_mix = mix;
			_low = mix >= 1f;
			for (int i = 0; i < 3; i++)
			{
				_mixed[i] = Mathf.Lerp(_textColor[i], _lowColor[i], mix);
			}
			Paint(_text, _mixed, _gain);
			bool open;
			if (low != _low)
			{
				ForgeSkinPlugin.AuthorLine message = new ForgeSkinPlugin.AuthorLine(31, 6, out open);
				if (open)
				{
					message.AppendFormatted(_label);
					message.AppendLiteral(": screen ");
					message.AppendFormatted(_low ? "low" : "normal");
					message.AppendLiteral(" colour at ");
					message.AppendFormatted(value);
					message.AppendLiteral("/");
					message.AppendFormatted(max);
					message.AppendLiteral(" (tint ");
					message.AppendFormatted(mix.ToString("0.00", CultureInfo.InvariantCulture));
					message.AppendLiteral("): ");
					message.AppendFormatted(Describe());
				}
				ForgeSkinPlugin.Info(ref message);
			}
			else if (!flag && mix > 0f)
			{
				ForgeSkinPlugin.AuthorLine message2 = new ForgeSkinPlugin.AuthorLine(34, 3, out open);
				if (open)
				{
					message2.AppendFormatted(_label);
					message2.AppendLiteral(": screen low-ammo tint starts at ");
					message2.AppendFormatted(value);
					message2.AppendLiteral("/");
					message2.AppendFormatted(max);
				}
				ForgeSkinPlugin.Info(ref message2);
			}
		}
	}
	internal static class Characters
	{
		private sealed class Worn
		{
			public Skin Skin;

			public GameObject Root;

			public GameObject Model;

			public PoseCopy? Copy;

			public ToonDress? Toon;

			public readonly List<ChainBinding> Chains = new List<ChainBinding>();

			public PersonHide? Hide;

			public FirstPersonWear? Arms;

			public OwnBodyCut? Cut;

			public bool Released;

			public void Release()
			{
				if (Released)
				{
					return;
				}
				Released = true;
				OwnBodyCut? cut = Cut;
				if (cut != null)
				{
					cut.Dispose();
				}
				FirstPersonWear? arms = Arms;
				if (arms != null)
				{
					arms.Destroy();
				}
				foreach (ChainBinding chain in Chains)
				{
					chain.Release();
				}
				PoseCopy? copy = Copy;
				if (copy != null)
				{
					copy.Release();
				}
				ToonDress? toon = Toon;
				if (toon != null)
				{
					toon.Dispose();
				}
				PersonHide? hide = Hide;
				if (hide != null)
				{
					hide.Release();
				}
				if (!NativeObjects.Gone((Object)(object)Root))
				{
					Object.Destroy((Object)(object)Root);
				}
			}
		}

		private sealed class Dressed : ILookDress
		{
			public Worn? Person;

			public readonly Dictionary<string, Looks.Worn> Gear = new Dictionary<string, Looks.Worn>();

			public readonly List<SkinnedGear> Held = new List<SkinnedGear>();

			public bool Released;

			public void Hold(ItemEquippable item)
			{
				if (!Released && !((Object)(object)item == (Object)null))
				{
					string text = SkinnedGear.KeyOf(item);
					if (Gear.TryGetValue(text, out Looks.Worn value))
					{
						Held.Add(SkinnedGear.Dress(item, value));
					}
					else if (text == SkinTarget.GearKey(0u))
					{
						ForgeSkinPlugin.Fail("skin-look-gear-unknown", $"a stand-in's {((Item)item).PublicName}: its gear range matches no gear here, so the look's skins ({string.Join(", ", Gear.Keys)}) cannot be matched to it; shown in its original look");
					}
					else
					{
						ForgeSkinPlugin.Note($"a stand-in's {((Item)item).PublicName} ({text}): the look has no skin for it ({((Gear.Count == 0) ? "none" : string.Join(", ", Gear.Keys))}); shown in its original look");
					}
				}
			}

			public void Release()
			{
				if (Released)
				{
					return;
				}
				Released = true;
				Person?.Release();
				foreach (SkinnedGear item in Held)
				{
					SkinnedGear.Undress(item);
				}
			}
		}

		private sealed class Provider : IPlayerLookProvider
		{
			public byte[]? Describe(SNet_Player player)
			{
				if (!player.IsBot)
				{
					return Looks.Describe(player);
				}
				return null;
			}

			public ILookDress? Dress(byte[] description, Animator body)
			{
				Look look = Look.Decode(description);
				if (look == null || Pending(look))
				{
					return null;
				}
				Dressed dressed = new Dressed();
				Looks.Resolve(look, "a stand-in", dressed.Gear, new List<(string, string, string, uint)>());
				if (dressed.Gear.Remove("character", out Looks.Worn value))
				{
					Skin skin = value.Skin;
					if (skin.Doc.Character != null && !Broken.Contains(skin) && skin.Character != null)
					{
						dressed.Person = Wear(skin, body, null, "on a stand-in");
					}
				}
				if (dressed.Person != null)
				{
					StandIns.Add(dressed);
				}
				return (ILookDress?)(object)dressed;
			}

			private static bool Pending(Look look)
			{
				foreach (LookGear item in look.Gear)
				{
					Skin valueOrDefault = Skins.ByNumber.GetValueOrDefault(item.Skin);
					if (valueOrDefault != null && !valueOrDefault.ContentHash().HasValue)
					{
						return true;
					}
				}
				LookSkin character = look.Character;
				if (character != null)
				{
					Skin valueOrDefault2 = Skins.ByNumber.GetValueOrDefault(character.Skin);
					if (valueOrDefault2 != null)
					{
						if (!valueOrDefault2.ContentHash().HasValue)
						{
							return true;
						}
						if (valueOrDefault2.Doc.Character != null && !Broken.Contains(valueOrDefault2))
						{
							return !Skins.Ready(new List<Skin> { valueOrDefault2 }, Frame.UnscaledTime);
						}
						return false;
					}
				}
				return false;
			}
		}

		private const string Label = "ForgeSkin character";

		private static readonly Dictionary<IntPtr, (PlayerAgent Agent, Worn Worn)> ByAgent = new Dictionary<IntPtr, (PlayerAgent, Worn)>();

		private static readonly Dictionary<IntPtr, (Animator Body, Worn Worn)> InLobby = new Dictionary<IntPtr, (Animator, Worn)>();

		private static readonly List<Dressed> StandIns = new List<Dressed>();

		private static readonly HashSet<Skin> Broken = new HashSet<Skin>();

		private static bool _dirty = true;

		private static bool _waiting;

		private static float _next;

		private static PlayerLookProvision? _looks;

		private static bool _ownChanged;

		private const string ArmsLost = "its first-person arms are gone";

		private static readonly List<(IntPtr Bar, Animator Body, SNet_Player Player)> FiguresNow = new List<(IntPtr, Animator, SNet_Player)>();

		public static void Register()
		{
			_looks = PlayerLooks.Provide("ForgeSkin", (IPlayerLookProvider)(object)new Provider());
		}

		public static void Dirty()
		{
			_dirty = true;
		}

		public static void LookChanged(SNet_Player player)
		{
			PlayerLookProvision? looks = _looks;
			if (looks != null)
			{
				looks.Changed(player);
			}
		}

		public static void OwnLookChanged()
		{
			_ownChanged = (_dirty = true);
		}

		public static void InUse(HashSet<Skin> used)
		{
			Skin skin = Skins.Own("character");
			if (skin != null)
			{
				used.Add(skin);
			}
			Looks.Wearing("character", used);
			foreach (var value in ByAgent.Values)
			{
				Worn item = value.Worn;
				used.Add(item.Skin);
			}
			foreach (var value2 in InLobby.Values)
			{
				Worn item2 = value2.Worn;
				used.Add(item2.Skin);
			}
			StandIns.RemoveAll((Dressed d) => d.Released || d.Person == null || NativeObjects.Gone((Object)(object)d.Person.Model));
			foreach (Dressed standIn in StandIns)
			{
				used.Add(standIn.Person.Skin);
			}
		}

		public static void Tick(float now)
		{
			if (!(now < _next))
			{
				_next = now + 0.5f;
				if (_dirty || _waiting || Lost())
				{
					_dirty = false;
					Reconcile(now);
				}
			}
		}

		private static bool Lost()
		{
			foreach (var value in ByAgent.Values)
			{
				if (Loss(value.Worn) != null)
				{
					return true;
				}
			}
			foreach (var (val, worn) in InLobby.Values)
			{
				if (!NativeObjects.Gone((Object)(object)worn.Model) && !NativeObjects.Gone((Object)(object)val))
				{
					PersonHide hide = worn.Hide;
					if (hide == null || hide.Active)
					{
						continue;
					}
				}
				return true;
			}
			return false;
		}

		private static string? Loss(Worn worn)
		{
			if (!NativeObjects.Gone((Object)(object)worn.Model))
			{
				PersonHide hide = worn.Hide;
				if (hide != null && hide.Active)
				{
					FirstPersonWear arms = worn.Arms;
					if (arms == null || arms.Alive)
					{
						return null;
					}
					return "its first-person arms are gone";
				}
				return "the person's hold ended";
			}
			return "its model is gone";
		}

		private static List<(IntPtr Bar, Animator Body, SNet_Player Player)> Figures()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Invalid comparison between Unknown and I4
			FiguresNow.Clear();
			bool flag = (int)GameStateManager.CurrentStateName == 5;
			CM_PageLoadout current = CM_PageLoadout.Current;
			Il2CppReferenceArray<CM_PlayerLobbyBar> val = (((Object)(object)current == (Object)null || ((Il2CppObjectBase)current).WasCollected) ? null : current.m_playerLobbyBars);
			if (val == null)
			{
				_waiting |= flag;
				return FiguresNow;
			}
			for (int i = 0; i < ((Il2CppArrayBase<CM_PlayerLobbyBar>)(object)val).Length; i++)
			{
				CM_PlayerLobbyBar val2 = ((Il2CppArrayBase<CM_PlayerLobbyBar>)(object)val)[i];
				if (!((Object)(object)val2 == (Object)null) && !((Il2CppObjectBase)val2).WasCollected)
				{
					SNet_Player player = val2.m_player;
					if (player != null)
					{
						GameObject val3 = (val2.m_playerModelSpawned ? val2.m_playerModel : null);
						if (!((Object)(object)val3 == (Object)null) && !((Il2CppObjectBase)val3).WasCollected && val3.activeInHierarchy)
						{
							Animator componentInChildren = val3.GetComponentInChildren<Animator>();
							if (componentInChildren != null)
							{
								FiguresNow.Add((((Il2CppObjectBase)val2).Pointer, componentInChildren, player));
								continue;
							}
						}
						_waiting |= flag && Wanted(player) != null;
						continue;
					}
				}
				_waiting |= flag;
			}
			return FiguresNow;
		}

		internal static Animator? OriginalFigure()
		{
			foreach (var (key, result, _) in Figures())
			{
				if (!InLobby.ContainsKey(key))
				{
					return result;
				}
			}
			return null;
		}

		internal static Animator? AnyFigure()
		{
			using (List<(IntPtr, Animator, SNet_Player)>.Enumerator enumerator = Figures().GetEnumerator())
			{
				if (enumerator.MoveNext())
				{
					return enumerator.Current.Item2;
				}
			}
			return null;
		}

		private static void Lobby(float now)
		{
			HashSet<IntPtr> seen = new HashSet<IntPtr>();
			foreach (var (intPtr, val, player) in Figures())
			{
				seen.Add(intPtr);
				Skin skin = Wanted(player);
				if (InLobby.TryGetValue(intPtr, out (Animator, Worn) value))
				{
					if (value.Item2.Skin == skin && ((Il2CppObjectBase)value.Item1).Pointer == ((Il2CppObjectBase)val).Pointer && !NativeObjects.Gone((Object)(object)value.Item2.Model))
					{
						PersonHide hide = value.Item2.Hide;
						if (hide == null || hide.Active)
						{
							continue;
						}
					}
					value.Item2.Release();
					InLobby.Remove(intPtr);
				}
				if (skin == null)
				{
					continue;
				}
				if (!Skins.Ready(new List<Skin> { skin }, now))
				{
					_waiting = true;
					continue;
				}
				Worn worn = Wear(skin, val, null, "in the lobby");
				if (worn == null)
				{
					Broken.Add(skin);
				}
				else
				{
					InLobby[intPtr] = (val, worn);
				}
			}
			foreach (IntPtr item in InLobby.Keys.Where((IntPtr k) => !seen.Contains(k)).ToList())
			{
				InLobby[item].Worn.Release();
				InLobby.Remove(item);
			}
		}

		private static void Reconcile(float now)
		{
			_waiting = false;
			if (_ownChanged)
			{
				SNet_Player localPlayer = SNet.LocalPlayer;
				if (localPlayer != null)
				{
					_ownChanged = false;
					LookChanged(localPlayer);
				}
			}
			HashSet<IntPtr> seen = new HashSet<IntPtr>();
			for (int i = 0; Players.Readable && i < Players.Count; i++)
			{
				PlayerAgent val = Players.At(i);
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				seen.Add(((Il2CppObjectBase)val).Pointer);
				SNet_Player owner = val.Owner;
				if ((Object)(object)owner == (Object)null)
				{
					_waiting = true;
				}
				Skin skin = (((Object)(object)owner != (Object)null) ? Wanted(owner) : null);
				if (ByAgent.TryGetValue(((Il2CppObjectBase)val).Pointer, out (PlayerAgent, Worn) value))
				{
					string text = ((value.Item2.Skin == skin) ? Loss(value.Item2) : "another character is worn now");
					if (text == null)
					{
						continue;
					}
					bool open;
					if (text == "its first-person arms are gone")
					{
						value.Item2.Arms.Destroy();
						value.Item2.Arms = Arms(value.Item2.Skin, val, "ForgeSkin character " + value.Item2.Skin.Doc.Id);
						ForgeSkinPlugin.AuthorLine message = new ForgeSkinPlugin.AuthorLine(38, 3, out open);
						if (open)
						{
							message.AppendLiteral("character ");
							message.AppendFormatted(value.Item2.Skin.Doc.Id);
							message.AppendLiteral(" by ");
							SNet_Player owner2 = val.Owner;
							message.AppendFormatted((owner2 != null) ? owner2.NickName : null);
							message.AppendLiteral(": ");
							message.AppendFormatted(text);
							message.AppendLiteral(", worn on the new ones");
						}
						ForgeSkinPlugin.Info(ref message);
						continue;
					}
					ForgeSkinPlugin.AuthorLine message2 = new ForgeSkinPlugin.AuthorLine(26, 3, out open);
					if (open)
					{
						message2.AppendLiteral("character ");
						message2.AppendFormatted(value.Item2.Skin.Doc.Id);
						message2.AppendLiteral(" by ");
						SNet_Player owner3 = val.Owner;
						message2.AppendFormatted((owner3 != null) ? owner3.NickName : null);
						message2.AppendLiteral(" taken off: ");
						message2.AppendFormatted(text);
					}
					ForgeSkinPlugin.Info(ref message2);
					value.Item2.Release();
					ByAgent.Remove(((Il2CppObjectBase)val).Pointer);
				}
				if (skin == null)
				{
					continue;
				}
				if (!Skins.Ready(new List<Skin> { skin }, now) || (Object)(object)val.AnimatorBody == (Object)null)
				{
					_waiting = true;
					continue;
				}
				Animator animatorBody = val.AnimatorBody;
				SNet_Player owner4 = val.Owner;
				Worn worn = Wear(skin, animatorBody, val, "by " + ((owner4 != null) ? owner4.NickName : null));
				if (worn == null)
				{
					Broken.Add(skin);
				}
				else
				{
					ByAgent[((Il2CppObjectBase)val).Pointer] = (val, worn);
				}
			}
			foreach (IntPtr item in ByAgent.Keys.Where((IntPtr k) => !seen.Contains(k)).ToList())
			{
				ByAgent[item].Worn.Release();
				ByAgent.Remove(item);
			}
			Lobby(now);
		}

		private static Skin? Wanted(SNet_Player player)
		{
			if (player.IsBot)
			{
				return null;
			}
			Skin skin = (player.IsLocal ? Skins.Own("character") : Looks.WornBy(player.Lookup, "character")?.Skin);
			if (skin != null && !skin.Retired && !Broken.Contains(skin))
			{
				return skin;
			}
			return null;
		}

		private static Worn? Wear(Skin skin, Animator body, PlayerAgent? agent, string where)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_006a: 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_0081: 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_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_040e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0413: Unknown result type (might be due to invalid IL or missing references)
			//IL_041a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0423: Expected O, but got Unknown
			CharacterSkin character = skin.Doc.Character;
			Worn worn = new Worn
			{
				Skin = skin,
				Root = new GameObject("ForgeSkin character " + skin.Doc.Id)
			};
			try
			{
				Transform root = worn.Root.transform;
				PlayerLooks.Hang(worn.Root, body);
				float num = Fit(skin, body);
				root.localScale = Vector3.one * (num / ((Component)body).transform.lossyScale.x);
				worn.Model = skin.Character.Spawn(root, "ForgeSkin character");
				SkinnedMeshRenderer component = worn.Model.GetComponent<SkinnedMeshRenderer>();
				PlayerSyncModelData componentInParent = ((Component)body).GetComponentInParent<PlayerSyncModelData>();
				Il2CppReferenceArray<Renderer> ghosts = (((Object)(object)componentInParent != (Object)null) ? componentInParent.m_ghostRenderers : null);
				SkinnedMeshRenderer val = ((IEnumerable<SkinnedMeshRenderer>)((Component)body).GetComponentsInChildren<SkinnedMeshRenderer>(true)).FirstOrDefault((Func<SkinnedMeshRenderer, bool>)((SkinnedMeshRenderer r) => ((Component)r).gameObject.activeInHierarchy && !((Component)r).transform.IsChildOf(root) && !PlayerLooks.Worn(((Component)r).transform) && !Ghost((Renderer)(object)r)));
				if ((Object)(object)val != (Object)null)
				{
					worn.Model.layer = ((Component)val).gameObject.layer;
					((Renderer)component).shadowCastingMode = ((Renderer)val).shadowCastingMode;
				}
				else
				{
					ForgeSkinPlugin.Note($"character {skin.Doc.Id} {where}: the body shows none of its own meshes to take the drawing layer and shadow from; the model keeps layer {worn.Model.layer} and casts its shadow");
				}
				string text = "ForgeSkin character " + skin.Doc.Id;
				PoseTarget target = Models.ReadPoseTarget(worn.Model.transform, component, (IReadOnlyList<PoseLink>)skin.Links, text) ?? throw new InvalidOperationException("the model's skeleton does not take the pose (ForgeCore logged why)");
				Dictionary<string, Transform> bones = new Dictionary<string, Transform>(StringComparer.Ordinal);
				foreach (Transform item in (Il2CppArrayBase<Transform>)(object)component.bones)
				{
					if ((Object)(object)item != (Object)null)
					{
						bones.TryAdd(((Object)item).name, item);
					}
				}
				List<ChainCapsule> list = new List<ChainCapsule>();
				foreach (SpringCapsule capsule in character.Springs.Capsules)
				{
					Transform val2 = target.Bone(Array.IndexOf(ClipRig.Names, capsule.Joint));
					if (val2 != null)
					{
						list.Add(new ChainCapsule(val2, new Vector3(capsule.A[0], capsule.A[1], capsule.A[2]), new Vector3(capsule.B[0], capsule.B[1], capsule.B[2]), capsule.Radius * num));
					}
				}
				foreach (SpringChain chain in character.Springs.Chains)
				{
					ChainSpec val3 = chain.Spec();
					val3.Radius *= (double)num;
					val3.Gravity *= (double)num;
					worn.Chains.Add(Chains.Bind(bones[chain.Anchor], (IReadOnlyList<Transform[]>)chain.Strands.Select((List<string> s) => s.Select((string n) => bones[n]).ToArray()).ToList(), val3, (IReadOnlyList<ChainCapsule>)list, chain.LinkSide, chain.Loop, ((Object)(object)agent != (Object)null) ? ((Component)agent).transform : ((Component)body).transform, (Renderer)(object)component));
				}
				worn.Copy = Models.CopyPose(body, target, (IReadOnlyList<PoseReach>)HumanRig.ArmReach, text) ?? throw new InvalidOperationException("the body's pose cannot be copied (ForgeCore logged why)");
				worn.Copy.Follow();
				PersonHideOptions val4 = new PersonHideOptions
				{
					Held = false,
					Look = true
				};
				worn.Hide = (((Object)(object)agent != (Object)null) ? Persons.Hide(agent, "ForgeSkin character", val4) : Persons.Hide(body, "ForgeSkin character", val4));
				((Renderer)component).enabled = true;
				if (character.Materials.Exists((CharacterMaterial m) => m.Shader == "toon"))
				{
					IReadOnlyList<ImportedSubmesh> submeshes = skin.Character.Descriptor.Submeshes;
					bool[] array = new bool[submeshes.Count];
					IReadOnlyDictionary<string, float[]>[] array2 = new IReadOnlyDictionary<string, float[]>[submeshes.Count];
					for (int num2 = 0; num2 < array.Length; num2++)
					{
						if (submeshes[num2].Material < character.Materials.Count)
						{
							CharacterMaterial characterMaterial = character.Materials[submeshes[num2].Material];
							if (characterMaterial != null && characterMaterial.Shader == "toon")
							{
								ref bool reference = ref array[num2];
								IReadOnlyDictionary<string, float[]>[] array3 = array2;
								int num3 = num2;
								IReadOnlyDictionary<string, float[]> readOnlyDictionary = characterMaterial.Params;
								reference = true;
								array3[num3] = readOnlyDictionary;
							}
						}
					}
					worn.Toon = ToonDress.Wear((Renderer)(object)component, (IReadOnlyList<bool>)array, (IReadOnlyList<IReadOnlyDictionary<string, float[]>>)array2);
					ShowToon(worn, text);
				}
				if ((Object)(object)agent != (Object)null)
				{
					SNet_Player owner = agent.Owner;
					if (owner != null && owner.IsLocal)
					{
						worn.Arms = Arms(skin, agent, text);
						List<Transform> list2 = new string[3] { "head", "leftUpperArm", "rightUpperArm" }.Select((string j) => target.Bone(Array.IndexOf(ClipRig.Names, j))).OfType<Transform>().ToList();
						worn.Cut = Models.LeaveOutInFirstPerson(component, (IReadOnlyList<Transform>)list2);
					}
				}
				bool open;
				ForgeSkinPlugin.AuthorLine message = new ForgeSkinPlugin.AuthorLine(71, 9, out open);
				if (open)
				{
					message.AppendLiteral("character ");
					message.AppendFormatted(skin.Doc.Id);
					message.AppendLiteral(" worn ");
					message.AppendFormatted(where);
					message.AppendLiteral(":");
					message.AppendFormatted(target.Links.Count);
					message.AppendLiteral(" links, ");
					message.AppendFormatted(worn.Chains.Count);
					message.AppendLiteral(" spring chains, scale ");
					message.AppendFormatted(worn.Copy.Scale, "0.###");
					message.AppendLiteral(" (height ");
					message.AppendFormatted(character.Height, "0.###");
					message.AppendLiteral("), layer ");
					message.AppendFormatted(worn.Model.layer);
					message.AppendLiteral(" from ");
					message.AppendFormatted(((Object)(object)val != (Object)null) ? ((Object)val).name : "none");
					message.AppendFormatted((worn.Arms != null) ? ", own first-person arms" : "");
				}
				ForgeSkinPlugin.Info(ref message);
				return worn;
				bool Ghost(Renderer r)
				{
					if (ghosts != null)
					{
						foreach (Renderer item2 in (Il2CppArrayBase<Renderer>)(object)ghosts)
						{
							if ((Object)(object)item2 != (Object)null && ((Il2CppObjectBase)item2).Pointer == ((Il2CppObjectBase)r).Pointer)
							{
								return true;
							}
						}
					}
					return false;
				}
			}
			catch (Exception ex)
			{
				worn.Release();
				ForgeSkinPlugin.Fail("skin-character-failed", $"character {skin.Doc.Id}: {ex.Message}; the original person shows");
				return null;
			}
		}

		private static float Fit(Skin skin, Animator body)
		{
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: 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)
			float height = skin.Doc.Character.Height;
			float num = CharacterRig.Stature(skin.Doc.Character, skin.Character.Descriptor);
			Dictionary<IntPtr, Matrix4x4> rest = SkinRebind.BindRest(((Component)body).transform);
			if (num > 0f)
			{
				float? num2 = Y((HumanBodyBones)10);
				if (num2.HasValue)
				{
					float valueOrDefault = num2.GetValueOrDefault();
					num2 = Y((HumanBodyBones)5);
					if (num2.HasValue)
					{
						float valueOrDefault2 = num2.GetValueOrDefault();
						num2 = Y((HumanBodyBones)6);
						if (num2.HasValue)
						{
							float valueOrDefault3 = num2.GetValueOrDefault();
							if (valueOrDefault - (valueOrDefault2 + valueOrDefault3) / 2f > 0f)
							{
								return (valueOrDefault - (valueOrDefault2 + valueOrDefault3) / 2f) * ((Component)body).transform.lossyScale.y / num * height;
							}
						}
					}
				}
			}
			ForgeSkinPlugin.Fail("skin-character-part-skipped", $"character {skin.Doc.Id}: the {((num > 0f) ? "body's" : "model's")} height cannot be measured (the head must be mapped and rest above the feet, or above the model's floor without feet), so the model is not fitted to the body's height; it shows at its own size");
			return ((Component)body).transform.lossyScale.x / Math.Max(0.0001f, ((Component)body).transform.localScale.x) * height;
			float? Y(HumanBodyBones bone)
			{
				//IL_0006: 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)
				Transform boneTransform = body.GetBoneTransform(bone);
				if (boneTransform == null || !rest.TryGetValue(((Il2CppObjectBase)boneTransform).Pointer, out var value))
				{
					return null;
				}
				return value.m13;
			}
		}

		private static FirstPersonWear? Arms(Skin skin, PlayerAgent agent, string label)
		{
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Expected O, but got Unknown
			CharacterSkin character = skin.Doc.Character;
			ImportedModel character2 = skin.Character;
			if (character.Arms?.Model != null)
			{
				bool open;
				ForgeSkinPlugin.AuthorLine message = new ForgeSkinPlugin.AuthorLine(83, 1, out open);
				if (open)
				{
					message.AppendFormatted(skin.Doc.Id);
					message.AppendLiteral(": a separate first-person arms model is not read yet; the model's own arms are worn");
				}
				ForgeSkinPlugin.Warn(ref message);
			}
			WearBone[] array = CharacterRig.Arms(character, character2.Descriptor);
			if (array.Length == 0)
			{
				ForgeSkinPlugin.Fail("skin-character-part-skipped", "character " + skin.Doc.Id + " has no bone for one or both upper arms, which line its arms up with the game's first-person arms: the game's own arms show in first person");
				return null;
			}
			List<int> list = new List<int>();
			for (int i = 0; i < character2.Descriptor.Submeshes.Count; i++)
			{
				List<int>? hide = character.Hide;
				if (hide != null && hide.Contains(character2.Descriptor.Submeshes[i].Material))
				{
					list.Add(i);
				}
			}
			FirstPersonWear obj = Models.WearFirstPerson(agent, character2.Spawn((Transform)null, label + " arms"), new FirstPersonWearOptions
			{
				Bones = array,
				Hide = (BodyParts)8,
				Descendants = true,
				LeaveOut = list,
				Label = label + " arms"
			});
			if (obj != null)
			{
				obj.Activate();
				return obj;
			}
			return obj;
		}

		public static void ToonChanged()
		{
			foreach (var value in ByAgent.Values)
			{
				Worn item = value.Worn;
				ShowToon(item, "ForgeSkin character " + item.Skin.Doc.Id);
			}
			foreach (var value2 in InLobby.Values)
			{
				Worn item2 = value2.Worn;
				ShowToon(item2, "ForgeSkin character " + item2.Skin.Doc.Id + " in the lobby");
			}
			foreach (Dressed standIn in StandIns)
			{
				if (!standIn.Released)
				{
					Worn person = standIn.Person;
					if (person != null)
					{
						ShowToon(person, "ForgeSkin character " + person.Skin.Doc.Id + " on a stand-in");
					}
				}
			}
		}

		internal static string Toon(string mode)
		{
			if (!Enum.TryParse<ToonMode>(mode, ignoreCase: true, out var result))
			{
				return "toon: forward, deferred or off";
			}
			ForgeSkinPlugin.Toon.Value = result;
			return "toon " + result;
		}

		private static void ShowToon(Worn worn, string label)
		{
			if (worn.Released)
			{
				return;
			}
			ToonDress toon = worn.Toon;
			if (toon == null)
			{
				return;
			}
			if (!toon.Set(ForgeSkinPlugin.Toon.Value switch
			{
				ToonMode.Forward => (ToonLighting)0, 
				ToonMode.Deferred => (ToonLighting)1, 
				_ => null, 
			}))
			{
				ForgeSkinPlugin.Fail("skin-character-failed", label + ": ForgeCore's toon shader is not loaded; its toon materials draw lit");
			}
			else if (toon.Unknown.Count > 0)
			{
				bool open;
				ForgeSkinPlugin.AuthorLine message = new ForgeSkinPlugin.AuthorLine(44, 2, out open);
				if (open)
				{
					message.AppendFormatted(label);
					message.AppendLiteral(": toon parameters the shader does not have: ");
					message.AppendFormatted(string.Join(", ", toon.Unknown));
				}
				ForgeSkinPlugin.Warn(ref message);
			}
		}
	}
	internal sealed class CodeFx : ITriggered
	{
		public readonly CodeEffect Effect;

		public readonly ProceduralLook Look;

		private readonly string _skin;

		private readonly IReadOnlyDictionary<string, float[]>? _mate;

		private readonly CodeEffectValues _values = new CodeEffectValues();

		private float _start;

		private bool _started;

		private int _tweaks = -1;

		public CodeFx(string skin, CodeEffect effect, IReadOnlyDictionary<string, float[]>? mate)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			_skin = skin;
			_mate = mate;
			Effect = effect;
			CodeEffects.Resolve(effect, null, _values);
			Look = new ProceduralLook(_values.Program);
			Read();
		}

		public bool On(float time)
		{
			if (Effect.Trigger != Trigger.Always)
			{
				if (_started)
				{
					return time - _start < Effect.Seconds;
				}
				return false;
			}
			return true;
		}

		public float Clock(float time)
		{
			if (Effect.Trigger != Trigger.Always)
			{
				return time - _start;
			}
			return time;
		}

		public void Start(float time)
		{
			_start = time;
			_started = true;
		}

		public void Update(float time)
		{
			if (_mate == null && _tweaks != Skins.TweakVersion)
			{
				Read();
			}
		}

		private void Read()
		{
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			_tweaks = Skins.TweakVersion;
			CodeEffects.Resolve(Effect, _mate ?? Skins.ColoursOf(_skin), _values);
			for (int i = 0; i < _values.Program.Params.Count; i++)
			{
				Look.Set(i, _values.Params[i]);
			}
			for (int j = 0; j < _values.Program.Colours.Count; j++)
			{
				float[] array = _values.Colors[j];
				Look.SetColour(j, new Color(array[0], array[1], array[2], array[3]));
			}
			Look.Scale = _values.Transform[0];
			Look.Rotation = _values.Transform[1];
			Look.Spin = _values.Transform[2];
			Look.Intensity = _values.Transform[3];
		}
	}
	internal sealed class FxCanvas
	{
		private readonly Material _material;

		private readonly int _property;

		private readonly bool _albedo;

		private readonly LayerTarget? _layers;

		private readonly List<(CodeFx Fx, FxBlend Blend)> _effects = new List<(CodeFx, FxBlend)>();

		private readonly List<(Mesh Mesh, int Submesh)> _meshes;

		private readonly Renderer[] _renderers;

		private readonly List<ProceduralPainter> _painters = new List<ProceduralPainter>();

		private Texture? _source;

		private RenderTexture? _out;

		private bool _drawn;

		public Material Material => _material;

		public int Property => _property;

		public bool Live => (Object)(object)_out != (Object)null;

		public FxCanvas(Material material, int property, bool albedo, LayerTarget? layers, List<(Mesh, int)> meshes, Renderer[] renderers)
		{
			bool albedo2 = albedo;
			_material = material;
			_property = property;
			_albedo = albedo2;
			_layers = layers;
			_meshes = meshes;
			_renderers = renderers;
			_source = material.GetTexture(property);
		}

		public void Add(CodeFx fx, FxBlend blend)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			_effects.Add((fx, blend));
		}

		public void Rebase()
		{
			Texture texture = _material.GetTexture(_property);
			if (!((Object)(object)_out != (Object)null) || !((Object)(object)texture == (Object)(object)_out))
			{
				_source = texture;
				if ((Object)(object)_out != (Object)null)
				{
					_material.SetTexture(_property, (Texture)(object)_out);
				}
				_drawn = true;
			}
		}

		public bool Acquire(string label)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_out != (Object)null)
			{
				return true;
			}
			Texture? source = _source;
			int num = ((source != null) ? source.width : 1024);
			Texture? source2 = _source;
			RenderTexture val = new RenderTexture(num, (source2 != null) ? source2.height : 1024, 0, (RenderTextureFormat)0, (RenderTextureReadWrite)2)
			{
				useMipMap = true,
				autoGenerateMips = false,
				name = ((Object)_material).name + " code effects"
			};
			val.Create();
			foreach (var (codeFx, value) in _effects)
			{
				foreach (var mesh in _meshes)
				{
					Mesh item = mesh.Mesh;
					int item2 = mesh.Submesh;
					ProceduralPainter val2 = Procedural.Painter(item, item2, val, codeFx.Look, label + " " + codeFx.Effect.Id, (FxBlend?)value);
					if (val2 == null)
					{
						Free(val);
						return false;
					}
					_painters.Add(val2);
				}
			}
			_out = Assets.Keep<RenderTexture>(val);
			_material.SetTexture(_property, (Texture)(object)_out);
			_drawn = true;
			return true;
		}

		public void Release()
		{
			if (!((Object)(object)_out == (Object)null))
			{
				_material.SetTexture(_property, _source);
				Free(_out);
				_out = null;
			}
		}

		private void Free(RenderTexture rt)
		{
			foreach (ProceduralPainter painter in _painters)
			{
				painter.Dispose();
			}
			_painters.Clear();
			Object.Destroy((Object)(object)rt);
		}

		public void Update(float time)
		{
			if ((Object)(object)_out == (Object)null)
			{
				return;
			}
			bool flag = false;
			for (int i = 0; i < _effects.Count; i++)
			{
				if (flag)
				{
					break;
				}
				flag = _effects[i].Fx.On(time);
			}
			if (!flag && !_drawn)
			{
				LayerTarget? layers = _layers;
				if (layers == null || !layers.Dirty)
				{
					return;
				}
			}
			if (flag && !Seen())
			{
				return;
			}
			Graphics.Blit((Texture)(((Object)(object)_source != (Object)null) ? ((object)_source) : ((object)(_albedo ? Texture2D.whiteTexture : Texture2D.blackTexture))), _out);
			int num = 0;
			foreach (var effect in _effects)
			{
				CodeFx item = effect.Fx;
				bool flag2 = item.On(time);
				float num2 = item.Clock(time);
				int num3 = 0;
				while (num3 < _meshes.Count)
				{
					if (flag2)
					{
						_painters[num].Paint(num2);
					}
					num3++;
					num++;
				}
			}
			_out.GenerateMips();
			_drawn = flag;
		}

		private bool Seen()
		{
			for (int i = 0; i < _renderers.Length; i++)
			{
				if ((Object)(object)_renderers[i] != (Object)null && _renderers[i].isVisible)
				{
					return true;
				}
			}
			return false;
		}
	}
	internal sealed class FxShell
	{
		public const float Lift = 1.01f;

		private readonly CodeFx _fx;

		private readonly Renderer _model;

		private readonly Renderer _renderer;

		private readonly Material _material;

		private int _applied = -1;

		public FxShell(CodeFx fx, Renderer model, Renderer renderer, Material material)
		{
			_fx = fx;
			_model = model;
			_renderer = renderer;
			_material = material;
		}

		public void Update(float time, bool held)
		{
			bool flag = held && _fx.On(time) && _model.enabled;
			if (_renderer.enabled != flag)
			{
				_renderer.enabled = flag;
			}
			if (flag)
			{
				float num = _fx.Clock(time);
				if (_applied != _fx.Look.Version)
				{
					_fx.Look.Apply(_material, num);
					_applied = _fx.Look.Version;
				}
				else
				{
					Procedural.SetTime(_material, num);
				}
			}
		}
	}
	internal sealed class SkinnedGear
	{
		private readonly List<CodeFx> _fx = new List<CodeFx>();

		private readonly List<FxCanvas> _canvases = new List<FxCanvas>();

		private readonly List<FxShell> _shells = new List<FxShell>();

		private bool _fxHeld;

		private static IntPtr _keyOfPointer = (IntPtr)(-1);

		private static string? _wieldedKey;

		public static readonly int MainTex = Shader.PropertyToID("_MainTex");

		public static readonly int BumpMap = Shader.PropertyToID("_BumpMap");

		public static readonly int MetallicGlossMap = Shader.PropertyToID("_MetallicGlossMap");

		public static readonly int EmissiveMap = Shader.PropertyToID("_EmissiveMap");

		public static readonly int EnableEmissive = Shader.PropertyToID("_EnableEmissive");

		public static readonly int EmissiveColor = Shader.PropertyToID("_EmissiveColor");

		public static readonly int EmissionColor = Shader.PropertyToID("_EmissionColor");

		public static readonly int Color = Shader.PropertyToID("_Color");

		public static readonly int Metallic = Shader.PropertyToID("_Metallic");

		public static readonly int Glossiness = Shader.PropertyToID("_Glossiness");

		public static readonly int Smoothness = Shader.PropertyToID("_Smoothness");

		public static readonly int Cutoff = Shader.PropertyToID("_Cutoff");

		private static readonly List<SkinnedGear> Live = new List<SkinnedGear>();

		private static readonly List<(GearPartHolder Holder, ItemEquippable Item)> Pending = new List<(GearPartHolder, ItemEquippable)>();

		private static readonly HashSet<IntPtr> Reported = new HashSet<IntPtr>();

		private static float _nextPending;

		private static float _nextRelease;

		private static readonly HashSet<Skin> InUse = new HashSet<Skin>();

		private List<Skin> _shown = new List<Skin>();

		private List<Skin> _wanted = new List<Skin>();

		private bool _waiting;

		private readonly bool _icon;

		private readonly GearPartHolder? _holder;

		private readonly Component _root;

		private readonly uint _itemId;

		private readonly bool _world;

		private readonly bool _pickup;

		private readonly string? _fixedKey;

		private readonly ItemEquippable? _item;

		private readonly IntPtr _holderPointer;

		private readonly string _label;

		private readonly List<(Renderer Renderer, Il2CppReferenceArray<Material>? Original, Il2CppReferenceArray<Material> Mine)> _swaps = new List<(Renderer, Il2CppReferenceArray<Material>, Il2CppReferenceArray<Material>)>();

		private readonly HashSet<IntPtr> _dropped = new HashSet<IntPtr>();

		private readonly List<Object> _created = new List<Object>();

		private readonly List<Material> _held = new List<Material>();

		private readonly List<LayerTarget> _targets = new List<LayerTarget>();

		private readonly HashSet<IntPtr> _pictureGlows = new HashSet<IntPtr>();

		private readonly List<ITriggered> _animated = new List<ITriggered>();

		private readonly List<CharmLook> _charms = new List<CharmLook>();

		private List<(double[] Min, double[] Max)>? _body;

		private static readonly int TriggerCount = Enum.GetValues<Trigger>().Length;

		private readonly List<ITriggered>[] _on = new List<ITriggered>[TriggerCount];

		private readonly List<(ITriggered Handler, float Fraction)> _lowAmmo = new List<(ITriggered, float)>();

		private SoundGroup? _killSound;

		private Dictionary<uint, SoundGroup>? _killSoundOf;

		private readonly List<bool> _below = new List<bool>();

		private readonly bool[] _logged = new bool[TriggerCount];

		private readonly IntPtr _itemPointer;

		private int _layerCount;

		public int Kills;

		public int Shots;

		public int ShotHits;

		public float Damage;

		private readonly bool _gun;

		private int _shotFrame = -1;

		private int _hitFrame = -1;

		private readonly List<AmmoScreen> _screens = new List<AmmoScreen>();

		private readonly List<Transform> _faceCamera = new List<Transform>();

		private readonly List<PartPose> _poses = new List<PartPose>();

		private readonly List<(GameObject Root, string Id, Material Template)> _roots = new List<(GameObject, string, Material)>();

		private bool _equipped;

		private bool _flashlight;

		private bool _aiming;

		private int _lastClip = -1;

		private int _lastReserve = -1;

		private int _unequipFrame = -1;

		private Transform? _camera;

		private FirstPersonItemHolder? _hands;

		private static readonly int HandsWielded = NativeObjects.FieldOffset<FirstPersonItemHolder>("WieldedItem");

		private PlayerAmmoStorage? _storage;

		private AmmoType _ammoType;

		private int _clipSize;

		private readonly ulong _owner;

		private readonly Looks.Worn? _dressed;

		private Looks.Worn? _mate;

		private readonly PlayerAgent? _ownerAgent;

		private readonly IntPtr _ownerAgentPointer;

		private PlayerInventoryBase? _ownerInventory;

		private IntPtr _ownerWielded;

		private static readonly HashSet<Trigger> RemoteTriggers = new HashSet<Trigger>
		{
			Trigger.Fire,
			Trigger.Equip,
			Trigger.Unequip,
			Trigger.Downed,
			Trigger.Revived
		};

		private static readonly Dictionary<IntPtr, IntPtr> LastHeld = new Dictionary<IntPtr, IntPtr>();

		private int _fireFrame = -1;

		public static float DamageAll;

		public static float DamageTaken;

		public static float Health;

		public static float Infection;

		private static Dam_PlayerDamageBase? _playerDamage;

		private static float _lastHealth;

		private static readonly int HealthField = NativeObjects.FieldOffset<Dam_SyncedDamageBase>("<Health>k__BackingField");

		private static readonly int HealthMaxField = NativeObjects.FieldOffset<Dam_SyncedDamageBase>("<HealthMax>k__BackingField");

		private static IntPtr _wielded;

		private static IntPtr _lastWielded;

		private static readonly InventorySlot[] ItemSlots;

		private static PlayerInventoryBase? _inventory;

		private static IntPtr _local;

		private static readonly IntPtr WieldedGetter;

		private static IntPtr _wieldedOverride;

		internal static readonly InventorySlot[] GearSlots;

		private const string OfflinePrefix = "OfflineGear_ID_";

		private static readonly List<(Item Item, uint Id)> Pickups;

		private readonly Dictionary<IntPtr, Material> _worldLooks = new Dictionary<IntPtr, Material>();

		private readonly Dictionary<MaterialOverride, Material> _looks = new Dictionary<MaterialOverride, Material>();

		private readonly List<(Skin Skin, MaterialOverride Override, Material Look, string Key, WearStage Shown)> _worn = new List<(Skin, MaterialOverride, Material, string, WearStage)>();

		private string _key = "";

		private static readonly Regex CopySuffix;

		private const string BlendHS = "GTFO/BlendHS";

		private static readonly HashSet<string> Unset;

		public const string EmissiveKeyword = "ENABLE_EMISSIVE";

		private static bool _syncing;

		private bool? _fps;

		private static IntPtr _hitBy;

		public static readonly (string Id, Func<GearPartHolder, GameObject> Get)[] Parts;

		public string Label => _label;

		private bool Remote
		{
			get
			{
				if (_owner == 0L)
				{
					return _dressed != null;
				}
				return true;
			}
		}

		private static int CurrentFrame => Time.frameCount;

		private static IntPtr Credited
		{
			get
			{
				if (!(_hitBy != IntPtr.Zero))
				{
					return Wielded();
				}
				return _hitBy;
			}
		}

		private int AddCodeEffects(Skin skin, SkinDocument doc)
		{
			List<CodeEffect> codeEffects = doc.CodeEffects;
			if (codeEffects == null || codeEffects.Count <= 0 || _icon)
			{
				return 0;
			}
			bool open = default(bool);
			foreach (CodeEffect e in codeEffects)
			{
				if (!e.Visible)
				{
					continue;
				}
				if (e.Attachment != null)
				{
					Attachment attachment = doc.Attachments.Find((Attachment a) => a.Id == e.Attachment);
					if (attachment != null && !attachment.Visible)
					{
						ForgeSkinPlugin.AuthorLine message = new ForgeSkinPlugin.AuthorLine(53, 4, out open);
						if (open)
						{
							message.AppendFormatted(_label);
							message.AppendLiteral(": code effect ");
							message.AppendFormatted(e.Id);
							message.AppendLiteral(" (");
							message.AppendFormatted(e.Name);
							message.AppendLiteral("): skipped, its attachment ");
							message.AppendFormatted(e.Attachment);
							message.AppendLiteral(" is hidden");
						}
						ForgeSkinPlugin.Info(ref message);
						continue;
					}
				}
				try
				{
					CodeFx codeFx = new CodeFx(skin.Doc.Id, e, _mate?.Picks);
					if (e.Material != null)
					{
						PaintOver(codeFx, e);
					}
					else
					{
						DrawOn(codeFx, e);
					}
					_fx.Add(codeFx);
					_animated.Add(codeFx);
					On(e.Trigger, codeFx, e.LowAmmoFraction);
					ForgeSkinPlugin.AuthorLine message2 = new ForgeSkinPlugin.AuthorLine(26, 8, out open);
					if (open)
					{
						message2.AppendFormatted(_label);
						message2.AppendLiteral(": code effect ");
						message2.AppendFormatted(e.Id);
						message2.AppendLiteral(" (");
						message2.AppendFormatted(e.Name);
						message2.AppendLiteral(") ");
						message2.AppendFormatted(e.Program);
						message2.AppendLiteral(" on ");
						message2.AppendFormatted(e.Material ?? e.Attachment);
						message2.AppendFormatted((e.Material != null) ? (" " + e.Channel) : "");
						message2.AppendLiteral(", ");
						message2.AppendFormatted(e.Blend);
						message2.AppendLiteral(", ");
						message2.AppendFormatted(e.Trigger);
					}
					ForgeSkinPlugin.Info(ref message2);
				}
				catch (Exception ex) when (((Func<bool>)delegate
				{
					// Could not convert BlockContainer to single expression
					open = ((ex is InvalidOperationException || ex is SkinFormatException) ? true : false);
					return open;
				}).Invoke())
				{
					ForgeSkinPlugin.Fail("skin-fx-skipped", $"{_label}: code effect {e.Id} ({e.Name}): skipped, {ex.Message}", ex);
				}
			}
			return _fx.Count;
		}

		private void PaintOver(CodeFx fx, CodeEffect e)
		{
			Material look = _looks.FirstOrDefault<KeyValuePair<MaterialOverride, Material>>((KeyValuePair<MaterialOverride, Material> l) => l.Key.Material == e.Material).Value ?? throw new InvalidOperationException("material " + e.Material + " is on no renderer of this gear");
			int property = Property(e.Channel);
			FxCanvas fxCanvas = _canvases.Find((FxCanvas c) => (Object)(object)c.Material == (Object)(object)look && c.Property == property);
			if (fxCanvas == null)
			{
				List<(Mesh, int)> list = new List<(Mesh, int)>();
				List<Renderer> list2 = new List<Renderer>();
				HashSet<(IntPtr, int)> hashSet = new HashSet<(IntPtr, int)>();
				foreach (var swap in _swaps)
				{
					Renderer item = swap.Renderer;
					Il2CppReferenceArray<Material> item2 = swap.Mine;
					for (int num = 0; num < ((Il2CppArrayBase<Material>)(object)item2).Length; num++)
					{
						if ((Object)(object)((Il2CppArrayBase<Material>)(object)item2)[num] != (Object)(object)look)
						{
							continue;
						}
						Mesh val = MeshOf(item);
						if (val != null && num < val.subMeshCount)
						{
							if (hashSet.Add((((Il2CppObjectBase)val).Pointer, num)))
							{
								list.Add((val, num));
							}
							if (!list2.Contains(item))
							{
								list2.Add(item);
							}
						}
					}
				}
				if (list.Count == 0)
				{
					throw new InvalidOperationException("material " + e.Material + " is on no mesh of this gear");
				}
				if (e.Channel == TextureChannel.Emissive)
				{
					SetEmissive(look, on: true);
				}
				fxCanvas = new FxCanvas(look, property, e.Channel == TextureChannel.Albedo, _targets.Find((LayerTarget t) => (Object)(object)t.Material == (Object)(object)look && t.Property == property), list, list2.ToArray());
				_canvases.Add(fxCanvas);
			}
			fxCanvas.Add(fx, (FxBlend)(e.Blend == CodeEffectBlend.Additive));
		}

		private void DrawOn(CodeFx fx, CodeEffect e)
		{
			//IL_0132: 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_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			var (val, _, val2) = _roots.Find(((GameObject Root, string Id, Material Template) r) => r.Id == e.Attachment);
			if ((Object)(object)val == (Object)null)
			{
				throw new InvalidOperationException("attachment " + e.Attachment + " is not shown on this gear");
			}
			Transform? obj = Find(val.transform, "mesh");
			MeshRenderer val3 = ((obj != null) ? ((Component)obj).GetComponent<MeshRenderer>() : null) ?? throw new InvalidOperationException("attachment " + e.Attachment + " has no model");
			Mesh sharedMesh = ((Component)val3).GetComponent<MeshFilter>().sharedMesh;
			bool flag = LitMaterial.IsFirstPerson(val2);
			Material val4 = Procedural.CreateMaterial((FxBlend)(e.Blend == CodeEffectBlend.Additive), flag, "ForgeSkin code effect " + e.Id) ?? throw new InvalidOperationException("ForgeCore's shaders are not loaded");
			MeshFilter obj2 = Child(((Component)((Component)val3).transform.parent).gameObject, "code effect " + e.Id, sharedMesh, this.Own<Material>(val4), 0f);
			Transform transform = ((Component)obj2).transform;
			Vector3 localPosition = ((Component)val3).transform.localPosition;
			Bounds bounds = sharedMesh.bounds;
			transform.localPosition = localPosition + ((Bounds)(ref bounds)).center * -0.00999999f;
			transform.localRotation = ((Component)val3).transform.localRotation;
			transform.localScale = ((Component)val3).transform.localScale * 1.01f;
			MeshRenderer component = ((Component)obj2).GetComponent<MeshRenderer>();
			((Renderer)component).enabled = false;
			_shells.Add(new FxShell(fx, (Renderer)(object)val3, (Renderer)(object)component, val4));
		}

		private bool FxHeld()
		{
			if ((Object)(object)_item == (Object)null)
			{
				return !_icon;
			}
			if (Remote)
			{
				return OwnerWielded() == _itemPointer;
			}
			if (_wielded != _keyOfPointer)
			{
				_keyOfPointer = _wielded;
				_wieldedKey = null;
				foreach (SkinnedGear item in Live)
				{
					if (item._itemPointer == _wielded)
					{
						_wieldedKey = item._key;
						break;
					}
				}
			}
			if (!(_itemPointer == _wielded))
			{
				if (_wieldedKey != null)
				{
					return _wieldedKey == _key;
				}
				return false;
			}
			return true;
		}

		private void UpdateCodeEffects(float time)
		{
			if (_fx.Count == 0)
			{
				return;
			}
			bool flag = FxHeld();
			if (flag != _fxHeld)
			{
				_fxHeld = flag;
				foreach (FxCanvas canvase in _canvases)
				{
					if (!flag)
					{
						canvase.Release();
					}
					else if (!canvase.Acquire(_label))
					{
						ForgeSkinPlugin.Fail("skin-fx-skipped", _label + ": code effects on " + ((Object)canvase.Material).name + " not drawn, ForgeCore's shaders are not loaded");
					}
				}
				bool open;
				ForgeSkinPlugin.AuthorLine message = new ForgeSkinPlugin.AuthorLine(15, 2, out open);
				if (open)
				{
					message.AppendFormatted(_label);
					message.AppendLiteral(": code effects ");
					message.AppendFormatted(flag ? "drawing" : "released, not in hand");
				}
				ForgeSkinPlugin.Info(ref message);
			}
			for (int i = 0; i < _canvases.Count; i++)
			{
				_canvases[i].Update(time);
			}
			for (int j = 0; j < _shells.Count; j++)
			{
				_shells[j].Update(time, flag);
			}
		}

		private void RebaseCodeEffects(Material look)
		{
			foreach (FxCanvas canvase in _canvases)
			{
				if ((Object)(object)canvase.Material == (Object)(object)look)
				{
					canvase.Rebase();
				}
			}
		}

		private void ReleaseCodeEffects()
		{
			foreach (FxCanvas canvase in _canvases)
			{
				canvase.Release();
			}
			_canvases.Clear();
			_shells.Clear();
			_fx.Clear();
			_fxHeld = false;
		}

		public static GearIDRange? RangeOf(string key)
		{
			if (!key.StartsWith("gear:", StringComparison.Ordinal) || !uint.TryParse(key.AsSpan(5), out var result))
			{
				return null;
			}
			InventorySlot[] gearSlots = GearSlots;
			for (int i = 0; i < gearSlots.Length; i++)
			{
				Il2CppReferenceArray<GearIDRange> allGearForSlot = GearManager.GetAllGearForSlot(gearSlots[i]);
				if (allGearForSlot == null)
				{
					continue;
				}
				foreach (GearIDRange item in (Il2CppArrayBase<GearIDRange>)(object)allGearForSlot)
				{
					if (item != null && Offline(item.PlayfabItemInstanceId) == result)
					{
						return item;
					}
				}
			}
			return null;
		}

		private SkinnedGear(GearPartHolder? holder, ItemEquippable? item, uint itemId = 0u, bool icon = false, ulong owner = 0uL, PlayerAgent? ownerAgent = null, Looks.Worn? dressed = null)
		{
			_owner = owner;
			_dressed = dressed;
			_ownerAgent = ownerAgent;
			_ownerAgentPointer = ((ownerAgent != null) ? ((Il2CppObjectBase)ownerAgent).Pointer : IntPtr.Zero);
			_icon = icon;
			_holder = holder;
			_root = (Component)(((object)holder) ?? ((object)item));
			_itemId = itemId;
			_item = item;
			_holderPointer = ((Il2CppObjectBase)_root).Pointer;
			_itemPointer = ((item != null) ? ((Il2CppObjectBase)item).Pointer : IntPtr.Zero);
			_clipSize = ((item != null) ? item.ClipSize : 0);
			_gun = (Object)(object)item != (Object)null && NativeObjects.Is<BulletWeapon>((Il2CppObjectBase)(object)item);
			for (int i = 0; i < _on.Length; i++)
			{
				_on[i] = new List<ITriggered>();
			}
			object label;
			if (!((Object)(object)item == (Object)null))
			{
				label = $"{((Item)item).PublicName} [{View(item)}{(((Object)(object)holder == (Object)null) ? " item" : "")}{((owner != 0L) ? (" of player " + owner) : ((dressed != null) ? " of a stand-in" : ""))}]";
			}
			else
			{
				GearIDRange gearIDRange = holder.GearIDRange;
				label = ((gearIDRange != null) ? gearIDRange.PublicGearName : null) + " [" + (icon ? "icon" : "menu") + "]";
			}
			_label = (string)label;
		}

		private SkinnedGear(Item world, string key, bool pickup)
		{
			_root = (Component)(object)world;
			_world = true;
			_pickup = pickup;
			_fixedKey = key;
			_holderPointer = (_itemPointer = ((Il2CppObjectBase)world).Pointer);
			for (int i = 0; i < _on.Length; i++)
			{
				_on[i] = new List<ITriggered>();
			}
			_label = $"{world.PublicName} [{(pickup ? "pickup" : "placed")} {key}]";
		}

		private static string View(ItemEquippable item)
		{
			if (!NativeObjects.Is<SentryGunInstance>((Il2CppObjectBase)(object)item))
			{
				if (!item.m_isFirstPerson)
				{
					return "3P";
				}
				return "1P";
			}
			return "placed";
		}

		public static void Spawned(GearPartHolder holder)
		{
			try
			{
				ItemEquippable componentInParent = ((Component)holder).GetComponentInParent<ItemEquippable>();
				if (Forget(((Il2CppObjectBase)holder).Pointer))
				{
					Reported.Remove(((Il2CppObjectBase)holder).Pointer);
				}
				if ((Object)(object)componentInParent == (Object)null && Readback.Directory != null)
				{
					Readback.Write(holder, GearId(holder));
				}
				bool open;
				if ((Object)(object)componentInParent != (Object)null)
				{
					Consider(holder, componentInParent);
				}
				else if (holder.MenuMode)
				{
					if (Noting(holder))
					{
						ForgeSkinPlugin.AuthorLine message = new ForgeSkinPlugin.AuthorLine(19, 1, out open);
						if (open)
						{
							GearIDRange gearIDRange = holder.GearIDRange;
							message.AppendFormatted((gearIDRange != null) ? gearIDRange.PublicGearName : null);
							message.AppendLiteral(" [menu]: considered");
						}
						ForgeSkinPlugin.Info(ref message);
					}
					Track(holder, null);
				}
				else if (Icons.IsJob(holder))
				{
					if (Noting(holder))
					{
						ForgeSkinPlugin.AuthorLine message2 = new ForgeSkinPlugin.AuthorLine(29, 1, out open);
						if (open)
						{
							GearIDRange gearIDRange2 = holder.GearIDRange;
							message2.AppendFormatted((gearIDRange2 != null) ? gearIDRange2.PublicGearName : null);
							message2.AppendLiteral(" [icon]: skinned for its icon");
						}
						ForgeSkinPlugin.Info(ref message2);
					}
					Track(new SkinnedGear(holder, null, 0u, icon: true, 0uL));
				}
				else if (Noting(holder))
				{
					ForgeSkinPlugin.AuthorLine message3 = new ForgeSkinPlugin.AuthorLine(74, 1, out open);
					if (open)
					{
						GearIDRange gearIDRange3 = holder.GearIDRange;
						message3.AppendFormatted((gearIDRange3 != null) ? gearIDRange3.PublicGearName : null);
						message3.AppendLiteral(": parts spawned without an item and not in menu mode; waiting for the item");
					}
					ForgeSkinPlugin.Info(ref message3);
				}
			}
			catch (Exception ex)
			{
				ForgeSkinPlugin.Fail("skin-gear-spawn-failed", "gear spawn: " + ex.Message, ex);
			}
		}

		public static void BeforeItemSetup(ItemEquippable item)
		{
			if (Readback.Directory == null)
			{
				return;
			}
			try
			{
				GearPartHolder gearPartHolder = item.GearPartHolder;
				if ((Object)(object)gearPartHolder != (Object)null)
				{
					Readback.Write(gearPartHolder, GearId(gearPartHolder));
				}
			}
			catch (Exception ex)
			{
				ForgeSkinPlugin.Fail("skin-readback-failed", "readback: " + ex.Message, ex);
			}
		}

		public static void ItemReady(ItemEquippable item)
		{
			try
			{
				GearPartHolder gearPartHolder = item.GearPartHolder;
				if ((Object)(object)gearPartHolder != (Object)null)
				{
					Consider(gearPartHolder, item);
				}
			}
			catch (Exception ex)
			{
				ForgeSkinPlugin.Fail("skin-gear-spawn-failed", "gear spawn complete: " + ex.Message, ex);
			}
		}

		private static void Consider(GearPartHolder holder, ItemEquippable item)
		{
			IntPtr pointer = ((Il2CppObjectBase)holder).Pointer;
			foreach (var item2 in Pending)
			{
				if (((Il2CppObjectBase)item2.Holder).Pointer == pointer)
				{
					return;
				}
			}
			foreach (SkinnedGear item3 in Live)
			{
				if (item3._holderPointer == pointer)
				{
					return;
				}
			}
			bool open;
			if (Icons.IsJob(holder))
			{
				if (Noting(holder))
				{
					ForgeSkinPlugin.AuthorLine message = new ForgeSkinPlugin.AuthorLine(29, 1, out open);
					if (open)
					{
						message.AppendFormatted(((Item)item).PublicName);
						message.AppendLiteral(" [icon]: skinned for its icon");
					}
					ForgeSkinPlugin.Info(ref message);
				}
				Track(new SkinnedGear(holder, item, 0u, icon: true, 0uL));
				return;
			}
			if (Noting(holder))
			{
				ForgeSkinPlugin.AuthorLine message2 = new ForgeSkinPlugin.AuthorLine(15, 2, out open);
				if (open)
				{
					message2.AppendFormatted(((Item)item).PublicName);
					message2.AppendLiteral(" [");
					message2.AppendFormatted(View(item));
					message2.AppendLiteral("]: considered");
				}
				ForgeSkinPlugin.Info(ref message2);
			}
			Pending.Add((holder, item));
		}

		private static bool Noting(GearPartHolder holder)
		{
			if (ForgeSkinPlugin.Logging)
			{
				return Reported.Add(((Il2CppObjectBase)holder).Pointer);
			}
			return false;
		}

		public static void Tick(float now, float time)
		{
			if (Skins.Poll(now))
			{
				Looks.ResolveAll(refresh: false);
				Icons.SkinsChanged();
				Picker.Changed();
				foreach (SkinnedGear item in Live)
				{
					item.Refresh(now);
				}
				PickupsChanged();
				Characters.Dirty();
			}
			else if (Skins.Hashed())
			{
				Looks.ResolveAll();
			}
			Looks.Tick(now);
			Skins.Pump(now);
			if (Skins.Arrived())
			{
				Characters.Dirty();
				foreach (SkinnedGear item2 in Live)
				{
					if (item2._waiting)
					{
						item2.Refresh(now);
					}
				}
			}
			if (now >= _nextRelease)
			{
				_nextRelease = now + 1f;
				InUse.Clear();
				foreach (SkinnedGear item3 in Live)
				{
					InUse.UnionWith(item3._shown);
					InUse.UnionWith(item3._wanted);
				}
				Characters.InUse(InUse);
				Skins.Release(now, InUse);
			}
			Characters.Tick(now);
			if (Pending.Count > 0 && now >= _nextPending)
			{
				ResolvePending(now);
			}
			Icons.Tick();
			Wear.Save(now);
			PollWielded(time);
			PollPlayer();
			for (int num = Live.Count - 1; num >= 0; num--)
			{
				SkinnedGear skinnedGear = Live[num];
				if ((Object)(object)skinnedGear._root == (Object)null)
				{
					skinnedGear.Revert();
					Live.RemoveAt(num);
				}
				else
				{
					try
					{
						skinnedGear.Update(time);
					}
					catch (Exception ex)
					{
						skinnedGear.Revert();
						ForgeSkinPlugin.Fail("skin-gear-update-failed", skinnedGear._label + ": update failed: " + ex.Message + "; left vanilla", ex);
					}
				}
			}
			Previews.Tick();
		}

		public static void StateChanged(eGameStateName state)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			Characters.Dirty();
			if ((int)state != 6)
			{
				return;
			}
			LastHeld.Clear();
			Wear.Save(Time.unscaledTime, force: true);
			_wielded = (_lastWielded = (_hitBy = IntPtr.Zero));
			_inventory = null;
			_local = IntPtr.Zero;
			_playerDamage = null;
			Reported.Clear();
			Pickups.Clear();
			DamageAll = (DamageTaken = 0f);
			foreach (SkinnedGear item in Live)
			{
				item.Kills = (item.Shots = (item.ShotHits = 0));
				item.Damage = 0f;
				item._shotFrame = -1;
			}
		}

		private static void PollPlayer()
		{
			if (!((Object)(object)_playerDamage == (Object)null))
			{
				float num = Native.Float((Il2CppObjectBase)(object)_playerDamage, HealthField);
				float num2 = Native.Float((Il2CppObjectBase)(object)_playerDamage, HealthMaxField);
				if (_lastHealth >= 0f && num < _lastHealth)
				{
					DamageTaken += _lastHealth - num;
				}
				_lastHealth = num;
				Health = ((num2 > 0f) ? (num / num2 * 100f) : 0f);
				Infection = _playerDamage.Infection * 100f;
			}
		}

		private static void ResolvePending(float now)
		{
			_nextPending = now + 0.25f;
			for (int num = Pending.Count - 1; num >= 0; num--)
			{
				var (val, val2) = Pending[num];
				if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
				{
					Pending.RemoveAt(num);
					continue;
				}
				ulong num2 = 0uL;
				PlayerAgent val3 = null;
				if (!val2.m_isFirstPerson)
				{
					val3 = ((Item)val2).Owner;
					SNet_Player val4 = ((val3 != null) ? val3.Owner : null);
					if ((Object)(object)val4 == (Object)null)
					{
						continue;
					}
					if (val4.IsBot)
					{
						Pending.RemoveAt(num);
						Reported.Remove(((Il2CppObjectBase)val).Pointer);
						if (Noting(val))
						{
							bool open;
							ForgeSkinPlugin.AuthorLine message = new ForgeSkinPlugin.AuthorLine(42, 3, out open);
							if (open)
							{
								message.AppendFormatted(((Item)val2).PublicName);
								message.AppendLiteral(" [");
								message.AppendFormatted(View(val2));
								message.AppendLiteral("]: skipped, bot ");
								message.AppendFormatted(val4.NickName);
								message.AppendLiteral(" wears the original look");
							}
							ForgeSkinPlugin.Info(ref message);
						}
						continue;
					}
					if (!val4.IsLocal)
					{
						num2 = val4.Lookup;
					}
				}
				Pending.RemoveAt(num);
				Track(new SkinnedGear(val, val2, 0u, icon: false, num2, (num2 != 0L) ? val3 : null));
			}
		}

		public static void OwnerChanged(ulong owner)
		{
			float unscaledTime = Frame.UnscaledTime;
			foreach (SkinnedGear item in Live)
			{
				if (item._owner == owner && (item._waiting || item._key.Length == 0 || Looks.WornBy(owner, item._key) != item._mate))
				{
					item.Refresh(unscaledTime);
				}
			}
			Characters.Dirty();
		}

		private static void Track(GearPartHolder holder, ItemEquippable? item)
		{
			Track(new SkinnedGear(holder, item, 0u, icon: false, 0uL));
		}

		private static SkinnedGear Track(SkinnedGear gear)
		{
			Live.Add(gear);
			if ((Object)(object)gear._holder != (Object)null && !gear._icon && !gear.Remote)
			{
				Looks.GearSpawned();
			}
			float unscaledTime = Frame.UnscaledTime;
			gear.Refresh(unscaledTime);
			return gear;
		}

		private static IntPtr Wielded()
		{
			if (!((Object)(object)_inventory == (Object)null))
			{
				return Native.Call((Il2CppObjectBase)(object)_inventory, _wieldedOverride);
			}
			return IntPtr.Zero;
		}

		private IntPtr OwnerWielded()
		{
			if ((Object)(object)_ownerInventory == (Object)null)
			{
				PlayerAgent? ownerAgent = _ownerAgent;
				PlayerInventoryBase val = ((ownerAgent != null) ? ownerAgent.Inventory : null);
				if (val == null)
				{
					return IntPtr.Zero;
				}
				_ownerInventory = val;
				_ownerWielded = Native.Virtual((Il2CppObjectBase)(object)val, WieldedGetter);
			}
			return Native.Call((Il2CppObjectBase)(object)_ownerInventory, _ownerWielded);
		}

		private static void PollWielded(float time)
		{
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_inventory == (Object)null)
			{
				PlayerAgent localPlayerAgent = PlayerManager.GetLocalPlayerAgent();
				if (localPlayerAgent != null)
				{
					_inventory = localPlayerAgent.Inventory;
					if ((Object)(object)_inventory != (Object)null)
					{
						_wieldedOverride = Native.Virtual((Il2CppObjectBase)(object)_inventory, WieldedGetter);
					}
					_local = ((Il2CppObjectBase)localPlayerAgent).Pointer;
					_playerDamage = localPlayerAgent.Damage;
					_lastHealth = -1f;
				}
			}
			IntPtr intPtr = Wielded();
			if (intPtr == _wielded)
			{
				return;
			}
			try
			{
				ItemEquippable val = ((intPtr == IntPtr.Zero) ? ((ItemEquippable)null) : new ItemEquippable(intPtr));
				IntPtr wielded = _wielded;
				_wielded = intPtr;
				if (intPtr != IntPtr.Zero)
				{
					_lastWielded = intPtr;
				}
				foreach (SkinnedGear item in Live)
				{
					if ((Object)(object)item._holder == (Object)null && item._itemPointer == wielded)
					{
						item.Raise(Trigger.Unequip, item._on[8], time);
					}
				}
				if ((Object)(object)val == (Object)null || (Object)(object)val.GearPartHolder != (Object)null || !val.m_isFirstPerson)
				{
					return;
				}
				ItemDataBlock itemDataBlock = ((Item)val).ItemDataBlock;
				if (itemDataBlock == null || Array.IndexOf(ItemSlots, itemDataBlock.inventorySlot) < 0)
				{
					return;
				}
				SkinnedGear skinnedGear = null;
				for (int num = Live.Count - 1; num >= 0; num--)
				{
					if (!(Live[num]._itemPointer != intPtr))
					{
						if (Live[num]._itemId == ((GameDataBlockBase<ItemDataBlock>)(object)itemDataBlock).persistentID)
						{
							skinnedGear = Live[num];
						}
						else
						{
							Live[num].Revert();
							Live.RemoveAt(num);
						}
					}
				}
				if (skinnedGear == null)
				{
					skinnedGear = Track(new SkinnedGear(null, val, ((GameDataBlockBase<ItemDataBlock>)(object)itemDataBlock).persistentID, icon: false, 0uL));
				}
				skinnedGear.Equipped();
				skinnedGear.Raise(Trigger.Equip, skinnedGear._on[7], time);
			}
			catch (Exception ex)
			{
				ForgeSkinPlugin.Fail("skin-wielded-item-failed", "wielded item: " + ex.Message, ex);
			}
		}

		private static uint GearId(GearPartHolder holder)
		{
			GearIDRange gearIDRange = holder.GearIDRange;
			if (gearIDRange == null)
			{
				return 0u;
			}
			return GearIdOf(gearIDRange);
		}

		internal static uint GearIdOf(GearIDRange range)
		{
			uint? num = Offline(range.PlayfabItemInstanceId);
			if (num.HasValue)
			{
				return num.GetValueOrDefault();
			}
			InventorySlot[] gearSlots = GearSlots;
			for (int i = 0; i < gearSlots.Length; i++)
			{
				Il2CppReferenceArray<GearIDRange> allGearForSlot = GearManager.GetAllGearForSlot(gearSlots[i]);
				if (allGearForSlot == null)
				{
					continue;
				}
				foreach (GearIDRange item in (Il2CppArrayBase<GearIDRange>)(object)allGearForSlot)
				{
					if (item == null)
					{
						continue;
					}
					num = Offline(item.PlayfabItemInstanceId);
					if (num.HasValue)
					{
						uint valueOrDefault = num.GetValueOrDefault();
						if (SameComps(item, range))
						{
							return valueOrDefault;
						}
					}
				}
			}
			return 0u;
		}

		internal static uint? Offline(string? instance)
		{
			if (instance == null || !instance.StartsWith("OfflineGear_ID_", StringComparison.Ordinal) || !uint.TryParse(instance.AsSpan("OfflineGear_ID_".Length), out var result))
			{
				return null;
			}
			return result;
		}

		private static bool SameComps(GearIDRange a, GearIDRange b)
		{
			for (int i = 1; i <= 54; i++)
			{
				if (a.GetCompID((eGearComponent)(byte)i) != b.GetCompID((eGearComponent)(byte)i))
				{
					return false;
				}
			}
			return true;
		}

		public static void Mounting(GearPartHolder holder)
		{
			foreach (SkinnedGear item in Live)
			{
				if (item._holderPointer == ((Il2CppObjectBase)holder).Pointer)
				{
					item.Revert();
					bool open;
					ForgeSkinPlugin.AuthorLine message = new ForgeSkinPlugin.AuthorLine(48, 1, out open);
					if (open)
					{
						message.AppendFormatted(item._label);
						message.AppendLiteral(": left vanilla, another package mounts its model");
					}
					ForgeSkinPlugin.Info(ref message);
				}
			}
		}

		private static bool Forget(IntPtr holder)
		{
			for (int num = Live.Count - 1; num >= 0; num--)
			{
				if (Live[num]._holderPointer == holder)
				{
					Live[num].Revert();
					Live.RemoveAt(num);
					return true;
				}
			}
			return false;
		}

		public static SkinnedGear Dress(ItemEquippable item, Looks.Worn worn)
		{
			return Track(new SkinnedGear(item.GearPartHolder, item, ((GameDataBlockBase<ItemDataBlock>)(object)((Item)item).ItemDataBlock)?.persistentID ?? 0, icon: false, 0uL, null, worn));
		}

		public static void Undress(SkinnedGear gear)
		{
			gear.Revert();
			Live.Remove(gear);
		}

		public static string KeyOf(ItemEquippable item)
		{
			GearPartHolder gearPartHolder = item.GearPartHolder;
			if (gearPartHolder == null)
			{
				return SkinTarget.ItemKey(((GameDataBlockBase<ItemDataBlock>)(object)((Item)item).ItemDataBlock)?.persistentID ?? 0);
			}
			return SkinTarget.GearKey(GearId(gearPartHolder));
		}

		public static void Placed(ItemEquippable deployer, Item? mine)
		{
			try
			{
				if (!((Object)(object)mine == (Object)null) && IsLocal((Agent?)(object)((Item)deployer).Owner))
				{
					string text = KeyOf(deployer);
					Forget(((Il2CppObjectBase)mine).Pointer);
					bool open;
					ForgeSkinPlugin.AuthorLine message = new ForgeSkinPlugin.AuthorLine(30, 3, out open);
					if (open)
					{
						message.AppendFormatted(mine.PublicName);
						message.AppendLiteral(": placed by ");
						message.AppendFormatted(((Item)deployer).PublicName);
						message.AppendLiteral(" (");
						message.AppendFormatted(text);
						message.AppendLiteral("), skinned as it");
					}
					ForgeSkinPlugin.Info(ref message);
					Track(new SkinnedGear(mine, text, pickup: false));
				}
			}
			catch (Exception ex)
			{
				ForgeSkinPlugin.Fail("skin-placed-failed", "placed item: " + ex.Message, ex);
			}
		}

		public static void ItemSpawned(Item? item, uint id, ItemMode mode)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			if ((int)mode != 2 || (Object)(object)item == (Object)null)
			{
				return;
			}
			try
			{
				Pickups.Add((item, id));
				if (Skins.Targets.ContainsKey(SkinTarget.ItemKey(id)))
				{
					Track(new SkinnedGear(item, SkinTarget.ItemKey(id), pickup: true));
				}
			}
			catch (Exception ex)
			{
				ForgeSkinPlugin.Fail("skin-placed-failed", $"pickup {id}: {ex.Message}", ex);
			}
		}

		private static void PickupsChanged()
		{
			HashSet<IntPtr> hashSet = new HashSet<IntPtr>();
			for (int num = Live.Count - 1; num >= 0; num--)
			{
				SkinnedGear skinnedGear = Live[num];
				if (skinnedGear._pickup)
				{
					if (Skins.Targets.ContainsKey(skinnedGear._fixedKey))
					{
						hashSet.Add(skinnedGear._holderPointer);
					}
					else
					{
						skinnedGear.Revert();
						Live.RemoveAt(num);
					}
				}
			}
			for (int num2 = Pickups.Count - 1; num2 >= 0; num2--)
			{
				var (val, id) = Pickups[num2];
				if ((Object)(object)val == (Object)null)
				{
					Pickups.RemoveAt(num2);
				}
				else if (!hashSet.Contains(((Il2CppObjectBase)val).Pointer) && Skins.Targets.ContainsKey(SkinTarget.ItemKey(id)))
				{
					Track(new SkinnedGear(val, SkinTarget.ItemKey(id), pickup: true));
				}
			}
		}

		private void Refresh(float now)
		{
			if ((Object)(object)_root == (Object)null)
			{
				Revert();
				return;
			}
			_key = _fixedKey ?? (((Object)(object)_holder != (Object)null) ? SkinTarget.GearKey(GearId(_holder)) : SkinTarget.ItemKey(_itemId));
			List<Skin> list = ((GunMount.Of(_holder) != null) ? new List<Skin>() : ((_dressed != null) ? new List<Skin> { _dressed.Skin } : ((_owner != 0L) ? Looks.Wanted(_owner, _key) : Skins.Wanted(_key))));
			if (!Skins.Ready(list, now))
			{
				if (!_waiting)
				{
					bool open;
					ForgeSkinPlugin.AuthorLine message = new ForgeSkinPlugin.AuthorLine(46, 2, out open);
					if (open)
					{
						message.AppendFormatted(_label);
						message.AppendLiteral(": waiting for ");
						message.AppendFormatted(string.Join(", ", from s in list
							where s.State != SkinState.Ready
							select s.Doc.Id));
						message.AppendLiteral(" to load; keeps its current look");
					}
					ForgeSkinPlugin.Info(ref message);
				}
				if (_icon)
				{
					Icons.RenderedWithout(_key);
				}
				_waiting = true;
				_wanted = list;
			}
			else
			{
				_waiting = false;
				_wanted = new List<Skin>();
				Revert();
				TryApply();
				_shown = list;
			}
		}

		private void TryApply()
		{
			try
			{
				Apply();
			}
			catch (Exception ex)
			{
				Revert();
				ForgeSkinPlugin.Fail("skin-apply-failed", _label + ": " + ex.Message + "; left vanilla", ex);
			}
		}

		private void Apply()
		{
			bool open;
			if (GunMount.Of(_holder) != null)
			{
				ForgeSkinPlugin.AuthorLine message = new ForgeSkinPlugin.AuthorLine(44, 1, out open);
				if (open)
				{
					message.AppendFormatted(_label);
					message.AppendLiteral(": skipped, another package mounted its model");
				}
				ForgeSkinPlugin.Info(ref message);
				return;
			}
			string key = _key;
			Dictionary<string, (Skin, MaterialOverride)> dictionary = new Dictionary<string, (Skin, MaterialOverride)>();
			if (!Remote)
			{
				foreach (string global in Skins.Globals)
				{
					if (!Skins.ById.TryGetValue(global, out Skin value))
					{
						continue;
					}
					foreach (MaterialOverride material in Skins.Painted(value).Materials)
					{
						dictionary[material.Material] = (value, material);
					}
				}
			}
			Skin weapon = null;
			SkinDocument skinDocument = null;
			_mate = _dressed ?? (Remote ? Looks.WornBy(_owner, key) : null);
			string text = ((!Remote) ? Skins.Targets.GetValueOrDefault(key) : _mate?.Skin.Doc.Id);
			if (text != null)
			{
				if (!Skins.ById.TryGetValue(text, out weapon))
				{
					throw new InvalidOperationException("active skin " + text + " is not installed");
				}
				if (weapon.Doc.Target.Key() != key)
				{
					throw new InvalidOperationException($"skin {text} targets {weapon.Doc.Target.Key()}, not {key}");
				}
				skinDocument = ((_mate != null) ? weapon.Painted((_dressed != null) ? ulong.MaxValue : _owner, _mate.Picks, _mate.Version) : Skins.Painted(weapon));
				foreach (MaterialOverride material2 in skinDocument.Materials)
				{
					if (material2.Attached() == null)
					{
						dictionary[material2.Material] = (weapon, material2);
					}
				}
			}
			if (dictionary.Count == 0 && (skinDocument == null || (skinDocument.Attachments.Count == 0 && skinDocument.Parts.Count == 0 && skinDocument.Sounds.Count == 0)))
			{
				ForgeSkinPlugin.AuthorLine message2 = new ForgeSkinPlugin.AuthorLine(30, 2, out open);
				if (open)
				{
					message2.AppendFormatted(_label);
					message2.AppendLiteral(": skipped, no active skin for ");
					message2.AppendFormatted(key);
				}
				ForgeSkinPlugin.Info(ref message2);
				return;
			}
			ApplyMaterials(dictionary);
			if (_world)
			{
				ForgeSkinPlugin.Note($"{_label}: {key}, skin {weapon?.Doc.Id ?? "-"}, {_swaps.Count} renderers, materials only");
				return;
			}
			SkinCasings(dictionary);
			int num = 0;
			if (weapon != null)
			{
				foreach (Attachment a in skinDocument.Attachments)
				{
					if (a.Visible)
					{
						Attach(weapon, a, skinDocument.Materials.Find((MaterialOverride m) => m.Attached() == a.Id));
						num++;
					}
				}
			}
			int num2 = 0;
			if (weapon != null && (Object)(object)_item != (Object)null && (_item.m_isFirstPerson || Remote))
			{
				foreach (IGrouping<(Trigger, uint?), SkinSound> item3 in from s in skinDocument.Sounds
					group s by (Trigger: s.Trigger, EnemyId: s.EnemyId))
				{