using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnboundLib;
using UnboundLib.Utils.UI;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[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 AmmoNumbers
{
[BepInPlugin("com.mrnoa.rounds.ammonumbers", "AmmoNumbers", "1.1.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInProcess("Rounds.exe")]
public class AmmoNumbersPlugin : BaseUnityPlugin
{
[Serializable]
[CompilerGenerated]
private sealed class <>c
{
public static readonly <>c <>9 = new <>c();
public static EventHandler<SettingChangedEventArgs> <>9__24_0;
public static UnityAction <>9__25_0;
public static Action<GameObject> <>9__25_1;
public static UnityAction <>9__33_0;
internal void <Awake>b__24_0(object _, SettingChangedEventArgs e)
{
SettingsVersion++;
RefreshColors();
if ((object)e.ChangedSetting == HealthColor)
{
TooMuchHudHooks.RefreshHealthTexts();
}
}
internal void <Start>b__25_0()
{
}
internal void <Start>b__25_1(GameObject m)
{
BuildMenu(m, nested: false);
}
internal void <BuildMenu>b__33_0()
{
ConfigEntryBase[] array = (ConfigEntryBase[])(object)new ConfigEntryBase[8]
{
(ConfigEntryBase)FontSize,
(ConfigEntryBase)OffsetY,
(ConfigEntryBase)OffsetX,
(ConfigEntryBase)CountDownStep,
(ConfigEntryBase)HideBlocks,
(ConfigEntryBase)ShowMax,
(ConfigEntryBase)HideWhenEmpty,
(ConfigEntryBase)Animate
};
foreach (ConfigEntryBase obj in array)
{
obj.BoxedValue = obj.DefaultValue;
}
foreach (KeyValuePair<ConfigEntry<float>, Slider> slider in sliders)
{
if ((Object)(object)slider.Value != (Object)null)
{
slider.Value.value = (float)((ConfigEntryBase)slider.Key).BoxedValue;
}
}
foreach (KeyValuePair<ConfigEntry<bool>, Toggle> toggle in toggles)
{
if ((Object)(object)toggle.Value != (Object)null)
{
toggle.Value.isOn = (bool)((ConfigEntryBase)toggle.Key).BoxedValue;
}
}
}
}
public const string Guid = "com.mrnoa.rounds.ammonumbers";
public const string Name = "AmmoNumbers";
public const string Version = "1.1.1";
internal const string TooMuchHudGuid = "com.Xomik.TooMuchHUD";
internal static ConfigEntry<bool> HideBlocks;
internal static ConfigEntry<bool> ShowMax;
internal static ConfigEntry<float> FontSize;
internal static ConfigEntry<float> OffsetY;
internal static ConfigEntry<float> OffsetX;
internal static ConfigEntry<Color> EmptyColor;
internal static ConfigEntry<bool> HideWhenEmpty;
internal static ConfigEntry<bool> Animate;
internal static ConfigEntry<float> CountDownStep;
internal static ConfigEntry<string> AmmoColor;
internal static ConfigEntry<string> DamageColor;
internal static ConfigEntry<string> HealColor;
internal static ConfigEntry<string> HealthColor;
internal static int SettingsVersion;
internal static Color? AmmoOverride;
internal static Color? DamageOverride;
internal static Color? HealOverride;
internal static Color? HealthOverride;
internal static bool HasTooMuchHud;
private static bool menuInTooMuchHud;
private static readonly (string name, string hex)[] Presets = new(string, string)[10]
{
("Default", null),
("Red", "#FF3B30"),
("Orange", "#FF9500"),
("Yellow", "#FFCC00"),
("Green", "#34C759"),
("Cyan", "#32D7FF"),
("Blue", "#3B82F6"),
("Purple", "#AF52DE"),
("Pink", "#FF5FA2"),
("White", "#FFFFFF")
};
private static readonly Dictionary<ConfigEntry<float>, Slider> sliders = new Dictionary<ConfigEntry<float>, Slider>();
private static readonly Dictionary<ConfigEntry<bool>, Toggle> toggles = new Dictionary<ConfigEntry<bool>, Toggle>();
private void Awake()
{
//IL_010f: Unknown result type (might be due to invalid IL or missing references)
//IL_0207: Unknown result type (might be due to invalid IL or missing references)
//IL_020d: Expected O, but got Unknown
HideBlocks = ((BaseUnityPlugin)this).Config.Bind<bool>("Display", "HideBlocks", true, "Hide the vanilla ammo blocks.");
ShowMax = ((BaseUnityPlugin)this).Config.Bind<bool>("Display", "ShowMax", false, "Show max ammo, e.g. 12 / 30 instead of 12.");
CountDownStep = ((BaseUnityPlugin)this).Config.Bind<float>("Display", "CountDownStep", 0.06f, "Seconds per tick when the number counts down (lower = faster).");
FontSize = ((BaseUnityPlugin)this).Config.Bind<float>("Display", "TextScale", 1f, "Size of the number. 1 = about twice the height of one vanilla ammo block.");
OffsetY = ((BaseUnityPlugin)this).Config.Bind<float>("Display", "NumberUpDown", 0f, "Move the number up (+) or down (-) from where the ammo blocks sat, in ammo-block heights.");
OffsetX = ((BaseUnityPlugin)this).Config.Bind<float>("Display", "NumberLeftRight", 0f, "Move the number left (-) or right (+), in ammo-block widths.");
HideWhenEmpty = ((BaseUnityPlugin)this).Config.Bind<bool>("Display", "HideWhenEmpty", true, "Never show 0: the number disappears after your last bullet, leaving only the reload ring.");
EmptyColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Display", "EmptyColor", new Color(1f, 0.35f, 0.35f), "Color of the 0 while reloading (only used when HideWhenEmpty is off).");
Animate = ((BaseUnityPlugin)this).Config.Bind<bool>("Display", "Animate", true, "Count-down animation and punch on each tick.");
AmmoColor = ((BaseUnityPlugin)this).Config.Bind<string>("Colors", "AmmoNumber", "Default", "Colour of the ammo number. Default = the game's own ammo yellow. Use Default, or a hex colour such as #FF3B30.");
DamageColor = ((BaseUnityPlugin)this).Config.Bind<string>("Colors", "DamageNumbers", "Default", "Colour of TooMuchHUD's floating damage numbers. Default = TooMuchHUD's own colours. Use Default, or a hex colour such as #FF3B30.");
HealColor = ((BaseUnityPlugin)this).Config.Bind<string>("Colors", "HealingNumbers", "Default", "Colour of TooMuchHUD's floating healing numbers. Default = TooMuchHUD's own colours. Use Default, or a hex colour such as #FF3B30.");
HealthColor = ((BaseUnityPlugin)this).Config.Bind<string>("Colors", "HealthNumbers", "Default", "Colour of TooMuchHUD's health numbers above players. Default = red to green by health. Use Default, or a hex colour such as #FF3B30.");
((BaseUnityPlugin)this).Config.SettingChanged += delegate(object _, SettingChangedEventArgs e)
{
SettingsVersion++;
RefreshColors();
if ((object)e.ChangedSetting == HealthColor)
{
TooMuchHudHooks.RefreshHealthTexts();
}
};
RefreshColors();
Harmony val = new Harmony("com.mrnoa.rounds.ammonumbers");
val.PatchAll();
if (Chainloader.PluginInfos.ContainsKey("com.Xomik.TooMuchHUD"))
{
menuInTooMuchHud = TooMuchHudHooks.Apply(val, ((BaseUnityPlugin)this).Logger);
}
((BaseUnityPlugin)this).Logger.LogInfo((object)"AmmoNumbers 1.1.1 loaded.");
}
private void Start()
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Expected O, but got Unknown
if (!menuInTooMuchHud)
{
object obj = <>c.<>9__25_0;
if (obj == null)
{
UnityAction val = delegate
{
};
<>c.<>9__25_0 = val;
obj = (object)val;
}
Unbound.RegisterMenu("AmmoNumbers", (UnityAction)obj, (Action<GameObject>)delegate(GameObject m)
{
BuildMenu(m, nested: false);
}, (GameObject)null, true);
}
}
private static void RefreshColors()
{
AmmoOverride = Parse(AmmoColor.Value);
DamageOverride = Parse(DamageColor.Value);
HealOverride = Parse(HealColor.Value);
HealthOverride = Parse(HealthColor.Value);
}
private static Color? Parse(string value)
{
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
if (string.IsNullOrWhiteSpace(value))
{
return null;
}
value = value.Trim();
if (value.Equals("Default", StringComparison.OrdinalIgnoreCase))
{
return null;
}
(string, string)[] presets = Presets;
for (int i = 0; i < presets.Length; i++)
{
(string, string) tuple = presets[i];
if (tuple.Item2 != null && tuple.Item1.Equals(value, StringComparison.OrdinalIgnoreCase))
{
value = tuple.Item2;
break;
}
}
if (!value.StartsWith("#"))
{
value = "#" + value;
}
Color value2 = default(Color);
if (!ColorUtility.TryParseHtmlString(value, ref value2))
{
return null;
}
value2.a = 1f;
return value2;
}
private static int PresetIndex(string value)
{
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
Color? val = Parse(value);
if (!val.HasValue)
{
return 0;
}
for (int i = 1; i < Presets.Length; i++)
{
Color? val2 = Parse(Presets[i].hex);
if (val2.HasValue && Color.op_Implicit(val2.Value) == Color.op_Implicit(val.Value))
{
return i;
}
}
return -1;
}
private static string ColorLabel(string label, string value)
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
int num = PresetIndex(value);
if (num == 0)
{
return label.ToUpperInvariant() + ": DEFAULT";
}
string text = ((num > 0) ? Presets[num].hex : ("#" + ColorUtility.ToHtmlStringRGB(Parse(value).Value)));
string text2 = ((num > 0) ? Presets[num].name.ToUpperInvariant() : text);
return label.ToUpperInvariant() + ": <color=" + text + ">" + text2 + "</color>";
}
internal static void BuildMenu(GameObject menu, bool nested)
{
//IL_0236: Unknown result type (might be due to invalid IL or missing references)
//IL_023b: Unknown result type (might be due to invalid IL or missing references)
//IL_0241: Expected O, but got Unknown
TextMeshProUGUI val = default(TextMeshProUGUI);
if (nested)
{
MenuHandler.CreateText(" ", menu, ref val, 30, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
MenuHandler.CreateText("Ammo Number", menu, ref val, 45, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
}
else
{
MenuHandler.CreateText("AmmoNumbers", menu, ref val, 60, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
}
MenuHandler.CreateText(" ", menu, ref val, 20, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
AddSlider("Ammo Text Size", menu, 0.2f, 3f, FontSize);
AddSlider("Ammo Up / Down", menu, -4f, 4f, OffsetY);
AddSlider("Ammo Left / Right", menu, -8f, 8f, OffsetX);
AddSlider("Ammo Seconds Per Tick", menu, 0.01f, 0.25f, CountDownStep);
AddToggle("Hide Ammo Blocks", menu, HideBlocks);
AddToggle("Show Max Ammo (12 / 30)", menu, ShowMax);
AddToggle("Hide Ammo Number When Empty", menu, HideWhenEmpty);
AddToggle("Animate Ammo Number", menu, Animate);
MenuHandler.CreateText(" ", menu, ref val, 30, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
MenuHandler.CreateText("Text Colors", menu, ref val, 45, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
MenuHandler.CreateText("click a line to change its color", menu, ref val, 20, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
AddColor("Ammo Number", menu, AmmoColor);
if (HasTooMuchHud)
{
AddColor("Damage Numbers", menu, DamageColor);
AddColor("Healing Numbers", menu, HealColor);
AddColor("Health Numbers", menu, HealthColor);
}
MenuHandler.CreateText(" ", menu, ref val, 20, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
object obj = <>c.<>9__33_0;
if (obj == null)
{
UnityAction val2 = delegate
{
ConfigEntryBase[] array = (ConfigEntryBase[])(object)new ConfigEntryBase[8]
{
(ConfigEntryBase)FontSize,
(ConfigEntryBase)OffsetY,
(ConfigEntryBase)OffsetX,
(ConfigEntryBase)CountDownStep,
(ConfigEntryBase)HideBlocks,
(ConfigEntryBase)ShowMax,
(ConfigEntryBase)HideWhenEmpty,
(ConfigEntryBase)Animate
};
foreach (ConfigEntryBase obj2 in array)
{
obj2.BoxedValue = obj2.DefaultValue;
}
foreach (KeyValuePair<ConfigEntry<float>, Slider> slider in sliders)
{
if ((Object)(object)slider.Value != (Object)null)
{
slider.Value.value = (float)((ConfigEntryBase)slider.Key).BoxedValue;
}
}
foreach (KeyValuePair<ConfigEntry<bool>, Toggle> toggle in toggles)
{
if ((Object)(object)toggle.Value != (Object)null)
{
toggle.Value.isOn = (bool)((ConfigEntryBase)toggle.Key).BoxedValue;
}
}
};
<>c.<>9__33_0 = val2;
obj = (object)val2;
}
MenuHandler.CreateButton("Reset Ammo Number Settings", menu, (UnityAction)obj, 30, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
}
private static void AddSlider(string label, GameObject menu, float min, float max, ConfigEntry<float> entry)
{
Slider value = default(Slider);
MenuHandler.CreateSlider(label, menu, 30, min, max, entry.Value, (UnityAction<float>)delegate(float v)
{
entry.Value = v;
}, ref value, false, (Color?)null, (Direction)0, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
sliders[entry] = value;
}
private static void AddToggle(string label, GameObject menu, ConfigEntry<bool> entry)
{
Toggle componentInChildren = MenuHandler.CreateToggle(entry.Value, label, menu, (UnityAction<bool>)delegate(bool v)
{
entry.Value = v;
}, 30, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null).GetComponentInChildren<Toggle>(true);
if ((Object)(object)componentInChildren != (Object)null)
{
toggles[entry] = componentInChildren;
}
}
private static void AddColor(string label, GameObject menu, ConfigEntry<string> entry)
{
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Expected O, but got Unknown
TextMeshProUGUI tmp = null;
GameObject val = MenuHandler.CreateButton(ColorLabel(label, entry.Value), menu, (UnityAction)delegate
{
int num = PresetIndex(entry.Value);
int num2 = ((num >= 0) ? ((num + 1) % Presets.Length) : 0);
entry.Value = ((num2 == 0) ? "Default" : Presets[num2].hex);
if ((Object)(object)tmp != (Object)null)
{
((TMP_Text)tmp).text = ColorLabel(label, entry.Value);
}
}, 30, false, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
tmp = val.GetComponentInChildren<TextMeshProUGUI>(true);
if ((Object)(object)tmp != (Object)null)
{
((TMP_Text)tmp).richText = true;
((TMP_Text)tmp).text = ColorLabel(label, entry.Value);
}
}
}
internal static class TooMuchHudHooks
{
private static Type healthType;
private static FieldInfo lastHealthField;
internal static bool Apply(Harmony harmony, ManualLogSource log)
{
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Expected O, but got Unknown
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Expected O, but got Unknown
//IL_011f: Unknown result type (might be due to invalid IL or missing references)
//IL_012c: Expected O, but got Unknown
bool flag = false;
bool flag2 = false;
bool flag3 = false;
try
{
MethodInfo methodInfo = AccessTools.Method(AccessTools.TypeByName("TooMuchHUD.HUDText"), "Setup", (Type[])null, (Type[])null);
if (methodInfo != null)
{
harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(TooMuchHudHooks), "SetupPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
flag2 = true;
}
}
catch (Exception ex)
{
log.LogWarning((object)("TooMuchHUD damage/heal colour hook failed: " + ex.Message));
}
try
{
healthType = AccessTools.TypeByName("TooMuchHUD.HealthBarText");
MethodInfo methodInfo2 = AccessTools.Method(healthType, "Update", (Type[])null, (Type[])null);
if (methodInfo2 != null)
{
harmony.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, new HarmonyMethod(typeof(TooMuchHudHooks), "HealthPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
lastHealthField = AccessTools.Field(healthType, "lastHealth");
flag3 = true;
}
}
catch (Exception ex2)
{
log.LogWarning((object)("TooMuchHUD health colour hook failed: " + ex2.Message));
}
try
{
MethodInfo methodInfo3 = AccessTools.Method(AccessTools.TypeByName("TooMuchHUD.StatusHUDMod"), "CreateSettingsMenu", (Type[])null, (Type[])null);
if (methodInfo3 != null)
{
harmony.Patch((MethodBase)methodInfo3, (HarmonyMethod)null, new HarmonyMethod(typeof(TooMuchHudHooks), "MenuPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
flag = true;
}
}
catch (Exception ex3)
{
log.LogWarning((object)("TooMuchHUD menu hook failed: " + ex3.Message));
}
AmmoNumbersPlugin.HasTooMuchHud = flag2 || flag3;
log.LogInfo((object)("TooMuchHUD found: damage/heal colours " + (flag2 ? "hooked" : "NOT hooked") + ", health colour " + (flag3 ? "hooked" : "NOT hooked") + ", settings menu " + (flag ? "shared" : "separate") + "."));
return flag;
}
private static void SetupPrefix(ref Color c, bool isHealing)
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
Color? val = (isHealing ? AmmoNumbersPlugin.HealOverride : AmmoNumbersPlugin.DamageOverride);
if (val.HasValue)
{
c = val.Value;
}
}
private static void HealthPostfix(TextMeshProUGUI ___tm)
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
Color? healthOverride = AmmoNumbersPlugin.HealthOverride;
if (healthOverride.HasValue && (Object)(object)___tm != (Object)null)
{
((Graphic)___tm).color = healthOverride.Value;
}
}
private static void MenuPostfix(GameObject menu)
{
try
{
AmmoNumbersPlugin.BuildMenu(menu, nested: true);
}
catch (Exception ex)
{
Debug.LogWarning("[AmmoNumbers] could not add settings to the TooMuchHUD menu: " + ex);
}
}
internal static void RefreshHealthTexts()
{
if (healthType == null || lastHealthField == null)
{
return;
}
try
{
Object[] array = Object.FindObjectsOfType(healthType);
foreach (Object obj in array)
{
lastHealthField.SetValue(obj, -99999f);
}
}
catch (Exception)
{
}
}
}
[HarmonyPatch(typeof(GunAmmo), "Start")]
internal static class GunAmmoStartPatch
{
private static void Postfix(GunAmmo __instance)
{
if ((Object)(object)((Component)__instance).GetComponent<AmmoNumberDisplay>() == (Object)null)
{
((Component)__instance).gameObject.AddComponent<AmmoNumberDisplay>();
}
}
}
internal class AmmoNumberDisplay : MonoBehaviour
{
private static readonly FieldRef<GunAmmo, int> CurrentAmmo = AccessTools.FieldRefAccess<GunAmmo, int>("currentAmmo");
private static readonly FieldRef<GunAmmo, Image> ReloadRingRef = AccessTools.FieldRefAccess<GunAmmo, Image>("reloadRing");
private static readonly ManualLogSource Log = Logger.CreateLogSource("AmmoNumbers.Place");
private static readonly Color FallbackYellow = new Color(1f, 0.85f, 0.1f);
private static Transform holder;
private static int placeLogs;
private GunAmmo ammo;
private Transform blocks;
private Canvas gunCanvas;
private Transform gunRoot;
private CanvasGroup blocksGroup;
private GameObject rootGo;
private Transform rootT;
private RectTransform textRt;
private TextMeshProUGUI text;
private float blockHeight = 80f;
private float unit = 0.001842f;
private float along = 0.4f;
private float perp = 0.41f;
private float alongTarget = 0.4f;
private float perpTarget = 0.41f;
private bool measured;
private int lastChildCount = -1;
private int skipFrames;
private int measureFrames;
private float candPerp = -1f;
private float candAlong;
private int lastCur = -1;
private int lastMax = -1;
private int shown;
private int seenVersion;
private bool lastShowMax;
private float tickTimer;
private float punch;
private float colorT;
private bool animating = true;
private Color gameColor;
private bool hasGameColor;
private const float ShotPunch = 0.25f;
private const float ReloadPunch = 0.45f;
private const float PunchDecay = 14f;
private const float ColorSpeed = 10f;
private float sideSmooth = 1f;
private float sideTarget = 1f;
private int shownChars = 1;
private void Start()
{
//IL_00fc: 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_0103: Unknown result type (might be due to invalid IL or missing references)
//IL_010f: Unknown result type (might be due to invalid IL or missing references)
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
//IL_0180: Unknown result type (might be due to invalid IL or missing references)
//IL_018a: Expected O, but got Unknown
//IL_0145: Unknown result type (might be due to invalid IL or missing references)
//IL_014a: Unknown result type (might be due to invalid IL or missing references)
//IL_0150: Expected O, but got Unknown
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_023e: Unknown result type (might be due to invalid IL or missing references)
//IL_025b: Unknown result type (might be due to invalid IL or missing references)
//IL_026b: Unknown result type (might be due to invalid IL or missing references)
//IL_028d: Unknown result type (might be due to invalid IL or missing references)
//IL_02af: Unknown result type (might be due to invalid IL or missing references)
//IL_02b5: Expected O, but got Unknown
//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
//IL_02d7: Expected O, but got Unknown
//IL_030c: Unknown result type (might be due to invalid IL or missing references)
//IL_0313: Unknown result type (might be due to invalid IL or missing references)
//IL_0315: Unknown result type (might be due to invalid IL or missing references)
//IL_0316: Unknown result type (might be due to invalid IL or missing references)
//IL_031d: Unknown result type (might be due to invalid IL or missing references)
//IL_032a: Unknown result type (might be due to invalid IL or missing references)
//IL_0352: Unknown result type (might be due to invalid IL or missing references)
//IL_03c6: Unknown result type (might be due to invalid IL or missing references)
ammo = ((Component)this).GetComponent<GunAmmo>();
if ((Object)(object)ammo == (Object)null || (Object)(object)ammo.populate == (Object)null)
{
((Behaviour)this).enabled = false;
return;
}
blocks = ((Component)ammo.populate).transform;
gunCanvas = ((Component)blocks).GetComponentInParent<Canvas>();
gunRoot = ((Component)ammo).transform.root;
blocksGroup = ((Component)blocks).GetComponent<CanvasGroup>() ?? ((Component)blocks).gameObject.AddComponent<CanvasGroup>();
if (blocks.childCount > 0)
{
Transform child = blocks.GetChild(0);
RectTransform val = (RectTransform)(object)((child is RectTransform) ? child : null);
if (val != null)
{
Rect rect = val.rect;
if (((Rect)(ref rect)).height > 1f)
{
rect = val.rect;
blockHeight = ((Rect)(ref rect)).height;
}
}
}
if ((Object)(object)gunCanvas != (Object)null)
{
Vector3 lossyScale = ((Component)gunCanvas).transform.lossyScale;
float num = Mathf.Max(Mathf.Abs(lossyScale.x), Mathf.Abs(lossyScale.y));
if (num > 1E-06f)
{
unit = num;
}
}
if ((Object)(object)holder == (Object)null)
{
GameObject val2 = new GameObject("AmmoNumbers");
Object.DontDestroyOnLoad((Object)val2);
holder = val2.transform;
}
rootGo = new GameObject("AmmoNumber", new Type[2]
{
typeof(RectTransform),
typeof(Canvas)
});
rootGo.layer = (((Object)(object)gunCanvas != (Object)null) ? ((Component)gunCanvas).gameObject.layer : ((Component)this).gameObject.layer);
rootT = rootGo.transform;
rootT.SetParent(holder, false);
Canvas component = rootGo.GetComponent<Canvas>();
component.renderMode = (RenderMode)2;
if ((Object)(object)gunCanvas != (Object)null)
{
component.worldCamera = gunCanvas.worldCamera;
component.sortingLayerID = gunCanvas.sortingLayerID;
component.sortingOrder = gunCanvas.sortingOrder + 1;
}
((RectTransform)rootT).sizeDelta = new Vector2(blockHeight * 8f, blockHeight * 3f);
rootT.rotation = Quaternion.identity;
rootT.localScale = new Vector3(unit, unit, unit);
GameObject val3 = new GameObject("Text", new Type[1] { typeof(RectTransform) });
val3.layer = rootGo.layer;
textRt = (RectTransform)val3.transform;
((Transform)textRt).SetParent(rootT, false);
RectTransform obj = textRt;
RectTransform obj2 = textRt;
RectTransform obj3 = textRt;
Vector2 val4 = default(Vector2);
((Vector2)(ref val4))..ctor(0.5f, 0.5f);
obj3.pivot = val4;
Vector2 anchorMin = (obj2.anchorMax = val4);
obj.anchorMin = anchorMin;
textRt.anchoredPosition = Vector2.zero;
textRt.sizeDelta = new Vector2(blockHeight * 8f, blockHeight * 3f);
text = val3.AddComponent<TextMeshProUGUI>();
((TMP_Text)text).alignment = (TextAlignmentOptions)514;
((TMP_Text)text).enableWordWrapping = false;
((TMP_Text)text).overflowMode = (TextOverflowModes)0;
((Graphic)text).raycastTarget = false;
((TMP_Text)text).fontStyle = (FontStyles)1;
((TMP_Text)text).outlineWidth = 0.2f;
((TMP_Text)text).outlineColor = new Color32((byte)0, (byte)0, (byte)0, (byte)200);
SampleGameColor();
}
private void LateUpdate()
{
//IL_024d: Unknown result type (might be due to invalid IL or missing references)
//IL_0258: Unknown result type (might be due to invalid IL or missing references)
//IL_025d: Unknown result type (might be due to invalid IL or missing references)
//IL_0297: Unknown result type (might be due to invalid IL or missing references)
//IL_029e: Unknown result type (might be due to invalid IL or missing references)
//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
//IL_0288: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)ammo == (Object)null || (Object)(object)text == (Object)null)
{
return;
}
int num = CurrentAmmo.Invoke(ammo);
int maxAmmo = ammo.maxAmmo;
bool value = AmmoNumbersPlugin.ShowMax.Value;
float unscaledDeltaTime = Time.unscaledDeltaTime;
bool num2 = lastCur < 0;
bool flag = maxAmmo != lastMax || value != lastShowMax || seenVersion != AmmoNumbersPlugin.SettingsVersion;
seenVersion = AmmoNumbersPlugin.SettingsVersion;
lastCur = num;
lastMax = maxAmmo;
lastShowMax = value;
if (num2)
{
shown = num;
}
if (num2 || flag)
{
ApplyLayout();
SetText(maxAmmo);
}
if (shown != num)
{
if (!AmmoNumbersPlugin.Animate.Value)
{
shown = num;
SetText(maxAmmo);
}
else
{
int num3 = Mathf.Abs(num - shown);
float value2 = AmmoNumbersPlugin.CountDownStep.Value;
float num4 = ((num < shown) ? value2 : (value2 * 0.35f)) / Mathf.Max(1f, (float)num3 / 8f);
tickTimer += unscaledDeltaTime;
while (tickTimer >= num4 && shown != num)
{
tickTimer -= num4;
bool flag2 = num < shown;
shown += ((!flag2) ? 1 : (-1));
punch = Mathf.Max(punch, flag2 ? 0.25f : 0.225f);
SetText(maxAmmo);
}
}
animating = true;
}
else
{
tickTimer = 0f;
}
Measure(unscaledDeltaTime);
Place(unscaledDeltaTime);
if (animating)
{
float num5 = ((shown <= 0) ? 1f : 0f);
colorT = Mathf.MoveTowards(colorT, num5, unscaledDeltaTime * 10f);
punch *= Mathf.Exp(-14f * unscaledDeltaTime);
if (punch < 0.002f)
{
punch = 0f;
}
float num6 = 1f + punch;
((Transform)textRt).localScale = new Vector3(num6, num6, 1f);
Color val = BaseColor();
if (AmmoNumbersPlugin.HideWhenEmpty.Value)
{
val.a *= 1f - colorT;
((Graphic)text).color = val;
}
else
{
((Graphic)text).color = Color.Lerp(val, AmmoNumbersPlugin.EmptyColor.Value, colorT);
}
animating = punch > 0f || colorT != num5 || shown != num;
}
}
private Color BaseColor()
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
Color? ammoOverride = AmmoNumbersPlugin.AmmoOverride;
if (!ammoOverride.HasValue)
{
if (!hasGameColor)
{
return FallbackYellow;
}
return gameColor;
}
return ammoOverride.GetValueOrDefault();
}
private void SetText(int max)
{
if (shown > 0 || !AmmoNumbersPlugin.HideWhenEmpty.Value)
{
string text = (lastShowMax ? $"{shown} / {max}" : shown.ToString());
((TMP_Text)this.text).text = text;
shownChars = text.Length;
}
}
private void ApplyLayout()
{
blocksGroup.alpha = (AmmoNumbersPlugin.HideBlocks.Value ? 0f : 1f);
((TMP_Text)text).fontSize = blockHeight * 2f * AmmoNumbersPlugin.FontSize.Value;
animating = true;
}
private void Measure(float dt)
{
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: 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_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
//IL_00e7: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0108: Unknown result type (might be due to invalid IL or missing references)
//IL_010f: Unknown result type (might be due to invalid IL or missing references)
//IL_0116: Unknown result type (might be due to invalid IL or missing references)
//IL_011d: Unknown result type (might be due to invalid IL or missing references)
//IL_026e: Unknown result type (might be due to invalid IL or missing references)
int childCount = blocks.childCount;
if (childCount != lastChildCount)
{
lastChildCount = childCount;
skipFrames = 3;
measureFrames = 45;
candPerp = -1f;
}
if (skipFrames > 0)
{
skipFrames--;
}
else if (measureFrames > 0)
{
measureFrames--;
Vector3 position = gunRoot.position;
Vector3 up = gunRoot.up;
Vector3 val = default(Vector3);
((Vector3)(ref val))..ctor(0f - up.y, up.x, 0f);
float num = float.MaxValue;
float num2 = float.MinValue;
float num3 = float.MaxValue;
int num4 = 0;
for (int i = 0; i < childCount; i++)
{
Transform child = blocks.GetChild(i);
if (((Component)child).gameObject.activeSelf)
{
Vector3 val2 = child.position - position;
float num5 = val2.x * up.x + val2.y * up.y;
float num6 = Mathf.Abs(val2.x * val.x + val2.y * val.y);
if (num5 < num)
{
num = num5;
}
if (num5 > num2)
{
num2 = num5;
}
if (num6 < num3)
{
num3 = num6;
}
num4++;
}
}
if (num4 > 0)
{
float num7 = (num + num2) * 0.5f;
if (num3 > candPerp && num3 < 2f && Mathf.Abs(num7) < 2f)
{
candPerp = num3;
candAlong = num7;
}
if (candPerp >= 0f)
{
alongTarget = candAlong;
perpTarget = candPerp;
if (!measured)
{
measured = true;
along = alongTarget;
perp = perpTarget;
}
}
}
if (measureFrames == 0 && placeLogs++ < 3)
{
Log.LogInfo((object)$"gun '{((Object)gunRoot).name}': blocks sit {alongTarget:F3} along the barrel, {perpTarget:F3} off it (from {num4} blocks); unit={unit:G4}, block={blockHeight}, colour #{ColorUtility.ToHtmlStringRGB(BaseColor())}");
}
}
if (along != alongTarget)
{
along = Mathf.MoveTowards(along, alongTarget, dt * 3f);
}
if (perp != perpTarget)
{
perp = Mathf.MoveTowards(perp, perpTarget, dt * 3f);
}
}
private void Place(float dt)
{
//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_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: 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_00f3: Unknown result type (might be due to invalid IL or missing references)
//IL_012d: Unknown result type (might be due to invalid IL or missing references)
//IL_0147: Unknown result type (might be due to invalid IL or missing references)
//IL_010f: Unknown result type (might be due to invalid IL or missing references)
//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
//IL_0198: Unknown result type (might be due to invalid IL or missing references)
//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
bool flag = (Object)(object)gunCanvas == (Object)null || ((Behaviour)gunCanvas).isActiveAndEnabled;
if (rootGo.activeSelf != flag)
{
rootGo.SetActive(flag);
}
if (flag)
{
Vector3 up = gunRoot.up;
float num = blockHeight * unit;
float num2 = Mathf.Max(perp, num * 1.2f);
Vector3 position = gunRoot.position;
float num3 = position.x + up.x * along;
float num4 = position.y + up.y * along;
if (up.x > 0.2f)
{
sideTarget = 1f;
}
else if (up.x < -0.2f)
{
sideTarget = -1f;
}
sideSmooth = Mathf.MoveTowards(sideSmooth, sideTarget, dt * 8f);
Vector3 position2 = default(Vector3);
if (up.y >= 0f)
{
position2.x = num3;
position2.y = num4 + num2 + up.y * Mathf.Abs(along);
}
else
{
position2.x = num3 + (0f - up.y) * sideSmooth * num2;
position2.y = num4 + Mathf.Abs(up.x) * num2;
}
position2.x += AmmoNumbersPlugin.OffsetX.Value * num;
position2.y += AmmoNumbersPlugin.OffsetY.Value * num;
position2.z = (((Object)(object)gunCanvas != (Object)null) ? ((Component)gunCanvas).transform.position.z : position.z);
rootT.position = position2;
}
}
private void SampleGameColor()
{
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
Image val = null;
for (int i = 0; i < blocks.childCount; i++)
{
if (!((Object)(object)val == (Object)null))
{
break;
}
val = ((Component)blocks.GetChild(i)).GetComponentInChildren<Image>(true);
}
if ((Object)(object)val != (Object)null && IsColored(((Graphic)val).color))
{
Use(((Graphic)val).color);
return;
}
Image val2 = ReloadRingRef.Invoke(ammo);
if ((Object)(object)val2 != (Object)null && IsColored(((Graphic)val2).color))
{
Use(((Graphic)val2).color);
}
else if ((Object)(object)ammo.cooldownRing != (Object)null && IsColored(((Graphic)ammo.cooldownRing).color))
{
Use(((Graphic)ammo.cooldownRing).color);
}
}
private static bool IsColored(Color c)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
float num = default(float);
float num2 = default(float);
float num3 = default(float);
Color.RGBToHSV(c, ref num, ref num2, ref num3);
if (num2 > 0.2f && num3 > 0.2f)
{
return c.a > 0.05f;
}
return false;
}
private void Use(Color c)
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
c.a = 1f;
gameColor = c;
hasGameColor = true;
}
private void OnEnable()
{
animating = true;
if ((Object)(object)rootGo != (Object)null)
{
rootGo.SetActive(true);
}
}
private void OnDisable()
{
if ((Object)(object)rootGo != (Object)null)
{
rootGo.SetActive(false);
}
}
private void OnDestroy()
{
if ((Object)(object)rootGo != (Object)null)
{
Object.Destroy((Object)(object)rootGo);
}
if ((Object)(object)blocksGroup != (Object)null)
{
blocksGroup.alpha = 1f;
}
}
}
}