using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Microsoft.CodeAnalysis;
using SmolMods.Core;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("smolMods.Crosshair")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+a3231e664cf7d257a8601fb862a89ade69b41d83")]
[assembly: AssemblyProduct("smolMods.Crosshair")]
[assembly: AssemblyTitle("smolMods.Crosshair")]
[assembly: AssemblyVersion("1.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 SmolMods.Crosshair
{
internal static class CrosshairPreviewPanel
{
internal const float PreviewBaseFontSize = 72f;
private static readonly List<TMP_Text> Previews = new List<TMP_Text>();
internal static TMP_FontAsset PreviewFont;
internal static void Register()
{
ModSettingsApi.AddPanel(100, (Action<ModPanelContext>)Build);
ModSettingsApi.AddMenuTicker((Action)UpdatePreview);
}
private static void Build(ModPanelContext ctx)
{
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_0136: Unknown result type (might be due to invalid IL or missing references)
//IL_013d: Expected O, but got Unknown
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: 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_0094: Unknown result type (might be due to invalid IL or missing references)
try
{
GameObject noteGo = ctx.NoteGo;
GameObject val = Object.Instantiate<GameObject>(noteGo, noteGo.transform.parent);
((Object)val).name = "ModsCrosshairPreview";
RectTransform component = noteGo.GetComponent<RectTransform>();
RectTransform component2 = val.GetComponent<RectTransform>();
Vector2 val2 = ctx.NextSlot(new Vector2(380f, 200f), 0f, (float?)150f);
if ((Object)(object)component != (Object)null && (Object)(object)component2 != (Object)null)
{
component2.sizeDelta = new Vector2(Mathf.Max(component.sizeDelta.x, 380f), 200f);
component2.anchoredPosition = component.anchoredPosition + val2;
}
TMP_Text val3 = val.GetComponent<TMP_Text>() ?? val.GetComponentInChildren<TMP_Text>(true);
if (!((Object)(object)val3 == (Object)null))
{
val3.text = "( · )";
val3.fontSize = 72f;
val3.alignment = (TextAlignmentOptions)514;
val3.enableWordWrapping = false;
val3.overflowMode = (TextOverflowModes)0;
val3.fontStyle = (FontStyles)0;
PreviewFont = val3.font;
Previews.Add(val3);
ModSettingsApi.RegisterPreviewGraphic((Graphic)(object)val3);
ctx.RegisterPanel(val);
}
}
catch (Exception ex)
{
ManualLogSource logger = Plugin.Logger;
if (logger != null)
{
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val4 = new BepInExWarningLogInterpolatedStringHandler(35, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("Crosshair preview creation failed: ");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(ex.Message);
}
logger.LogWarning(val4);
}
}
}
private static void UpdatePreview()
{
//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
for (int num = Previews.Count - 1; num >= 0; num--)
{
TMP_Text val = Previews[num];
if ((Object)(object)val == (Object)null)
{
Previews.RemoveAt(num);
}
else if (((Component)val).gameObject.activeInHierarchy)
{
try
{
float num2 = Mathf.Clamp((float)CrosshairSizeFeature.CurrentPercent / 100f, 0f, 2f);
string text = CrosshairSizeFeature.VanillaCrosshairStyle();
if (text == "off" || num2 <= 0.001f)
{
val.text = "no crosshair";
val.fontSize = 32.399998f;
}
else
{
val.text = ((text == "small") ? "·" : "( · )");
val.fontSize = 72f * num2 * ((text == "small") ? 0.75f : 1f);
}
val.transform.localScale = Vector3.one;
}
catch
{
}
}
}
}
}
[HarmonyPatch]
internal static class CrosshairSizeFeature
{
private static ModRowDef _row;
private static ModRowDef _styleRow;
private static readonly Dictionary<int, Vector3> BaseScales = new Dictionary<int, Vector3>();
private static TextMeshProUGUI _slickText;
private const float SlickBaseFontSize = 72f;
private static Image _windupBar;
private const float WindupMaxWidth = 220f;
private const float WindupHeight = 6f;
private static bool _slickMirror;
private static float _factorMirror = 1f;
private static SettingsHanger _vanillaHanger;
private static bool _glyphShown;
private static string _glyphText;
private static float _glyphSize;
private static bool _barShown;
private static RectTransform _windupBarRt;
private static float _lastBarW = -1f;
private const string GlyphFullNormal = "( · )";
private const string GlyphSmallNormal = "·";
private static string _glyphFullOutline = "( o )";
private static string _outlineDot = "o";
private static bool SlickEnabled => _slickMirror;
internal static int CurrentPercent
{
get
{
ModRowDef row = _row;
if (row == null)
{
return 100;
}
return row.Value;
}
}
private static float Factor => _factorMirror;
internal static void Register()
{
_row = ModSettingsApi.AddSliderRow(100, "Crosshair size", "settings_mod_crosshairSize", 100, 0, 200, (Action<int>)delegate(int v)
{
_factorMirror = (float)v / 100f;
Apply();
}, (Func<int, string>)((int v) => $"{v}%"));
_styleRow = ModSettingsApi.AddArrayRow(100, "Crosshair style", "settings_mod_crosshairStyle", 0, new int[2] { 0, 1 }, (Func<int, string>)((int v) => (v != 1) ? "Normal" : "Slick"), (Action<int>)delegate(int v)
{
_slickMirror = v == 1;
Apply();
}, (Func<int, Color?>)null);
CrosshairPreviewPanel.Register();
ModSettingsApi.AddTicker((Action)TickSlick);
}
internal static string VanillaCrosshairStyle()
{
try
{
SettingsHanger val = _vanillaHanger;
if (val == null)
{
val = (_vanillaHanger = SettingsWardrobe.crosshairHanger);
}
if (val == null)
{
return "full";
}
return val.value switch
{
1 => "small",
2 => "off",
_ => "full",
};
}
catch
{
return "full";
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(Crosshair), "OnSettingsChange")]
private static void OnSettingsChange_Postfix()
{
Apply();
}
[HarmonyPostfix]
[HarmonyPatch(typeof(Crosshair), "SetCrosshairMode")]
private static void SetCrosshairMode_Postfix()
{
Apply();
}
internal static void Apply()
{
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Expected O, but got Unknown
try
{
Crosshair val;
try
{
val = Crosshair.instance;
}
catch
{
val = null;
}
if (val != null)
{
bool slickEnabled = SlickEnabled;
float factor = (slickEnabled ? 0f : Factor);
ScaleTransform(val.crosshairNormal, factor);
ScaleTransform(val.crosshairHolding, factor);
ScaleTransform((Transform)(object)val.crosshairWindup, factor);
ScaleTransform(val.wings, factor);
UpdateSlick(val, slickEnabled);
}
}
catch (Exception ex)
{
ManualLogSource logger = Plugin.Logger;
if (logger != null)
{
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(30, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Crosshair scale apply failed: ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
}
logger.LogWarning(val2);
}
}
}
private static void UpdateSlick(Crosshair crosshair, bool slick)
{
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Expected O, but got Unknown
try
{
if (!slick)
{
if (_glyphShown && (Object)(object)_slickText != (Object)null)
{
((Component)_slickText).gameObject.SetActive(false);
_glyphShown = false;
}
}
else if (!((Object)(object)_slickText == (Object)null) || CreateSlick(crosshair))
{
RefreshSlickVisual(crosshair);
}
}
catch (Exception ex)
{
ManualLogSource logger = Plugin.Logger;
if (logger != null)
{
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(31, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Slick crosshair update failed: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
}
logger.LogWarning(val);
}
_slickText = null;
_glyphShown = false;
_glyphText = null;
}
}
private static TMP_FontAsset FindSlickFont()
{
if ((Object)(object)CrosshairPreviewPanel.PreviewFont != (Object)null)
{
return CrosshairPreviewPanel.PreviewFont;
}
try
{
Il2CppReferenceArray<Object> obj = Resources.FindObjectsOfTypeAll(Il2CppType.Of<TMP_FontAsset>());
TMP_FontAsset val = null;
foreach (Object item in (Il2CppArrayBase<Object>)(object)obj)
{
TMP_FontAsset val2 = ((Il2CppObjectBase)item).TryCast<TMP_FontAsset>();
if (!((Object)(object)val2 == (Object)null) && ((Object)val2).name != null && ((Object)val2).name.Contains("Courier"))
{
if (((Object)val2).name.IndexOf("Italic", StringComparison.OrdinalIgnoreCase) < 0)
{
return val2;
}
if ((Object)(object)val == (Object)null)
{
val = val2;
}
}
}
return val;
}
catch
{
}
return null;
}
internal static void TickSlick()
{
try
{
if (!SlickEnabled)
{
if (_glyphShown)
{
if ((Object)(object)_slickText != (Object)null)
{
((Component)_slickText).gameObject.SetActive(false);
}
_glyphShown = false;
}
if (_barShown)
{
if ((Object)(object)_windupBar != (Object)null)
{
((Component)_windupBar).gameObject.SetActive(false);
}
_barShown = false;
}
}
else
{
Crosshair val;
try
{
val = Crosshair.instance;
}
catch
{
val = null;
}
if (val != null && (!((Object)(object)_slickText == (Object)null) || CreateSlick(val)))
{
RefreshSlickVisual(val);
TickWindupBar(val);
}
}
}
catch
{
_slickText = null;
_windupBar = null;
_windupBarRt = null;
_glyphShown = false;
_glyphText = null;
_barShown = false;
}
}
private static void TickWindupBar(Crosshair ch)
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Invalid comparison between Unknown and I4
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)_windupBar == (Object)null)
{
return;
}
if ((int)ch.crosshairMode != 2)
{
if (_barShown)
{
((Component)_windupBar).gameObject.SetActive(false);
_barShown = false;
}
return;
}
if (!_barShown)
{
((Component)_windupBar).gameObject.SetActive(true);
_barShown = true;
}
float num = Mathf.Clamp01(ch.windupPower);
float num2 = Mathf.Clamp(Factor, 0.5f, 2f);
float num3 = 220f * num2 * num;
if ((Object)(object)_windupBarRt != (Object)null && Mathf.Abs(num3 - _lastBarW) > 0.25f)
{
_windupBarRt.sizeDelta = new Vector2(num3, 6f * num2);
_lastBarW = num3;
}
}
private static void RefreshSlickVisual(Crosshair crosshair)
{
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Invalid comparison between Unknown and I4
string text = VanillaCrosshairStyle();
float factor = Factor;
bool flag = text != "off" && factor > 0.001f;
if (_glyphShown != flag)
{
((Component)_slickText).gameObject.SetActive(flag);
_glyphShown = flag;
}
if (flag)
{
bool flag2 = crosshair != null && (int)crosshair.crosshairMode == 1;
string text2 = ((!(text == "small")) ? (flag2 ? _glyphFullOutline : "( · )") : (flag2 ? _outlineDot : "·"));
if ((object)text2 != _glyphText)
{
((TMP_Text)_slickText).text = text2;
_glyphText = text2;
}
float num = 72f * factor * ((text == "small") ? 0.75f : 1f);
if (Mathf.Abs(num - _glyphSize) > 0.01f)
{
((TMP_Text)_slickText).fontSize = num;
_glyphSize = num;
}
}
}
private static string PickOutlineDot(TMP_FontAsset font)
{
char[] array = new char[4] { '◦', '○', '°', 'o' };
for (int i = 0; i < array.Length; i++)
{
char c = array[i];
try
{
if ((Object)(object)font != (Object)null && font.HasCharacter(c, false, false))
{
return c.ToString();
}
}
catch
{
}
}
return "o";
}
private static bool CreateSlick(Crosshair crosshair)
{
//IL_025c: Unknown result type (might be due to invalid IL or missing references)
//IL_0263: Expected O, but got Unknown
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: 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_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0173: Unknown result type (might be due to invalid IL or missing references)
//IL_0178: Unknown result type (might be due to invalid IL or missing references)
//IL_018a: Unknown result type (might be due to invalid IL or missing references)
//IL_0195: Unknown result type (might be due to invalid IL or missing references)
//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
try
{
Transform crosshairNormal = crosshair.crosshairNormal;
if ((Object)(object)crosshairNormal == (Object)null || (Object)(object)crosshairNormal.parent == (Object)null)
{
return false;
}
GameObject val = new GameObject("crosshair_slick");
val.transform.SetParent(crosshairNormal.parent, false);
RectTransform val2 = val.AddComponent<RectTransform>();
RectTransform component = ((Component)crosshairNormal).GetComponent<RectTransform>();
if ((Object)(object)component != (Object)null)
{
val2.anchorMin = component.anchorMin;
val2.anchorMax = component.anchorMax;
val2.pivot = component.pivot;
val2.anchoredPosition = component.anchoredPosition;
}
val2.sizeDelta = new Vector2(400f, 160f);
_slickText = val.AddComponent<TextMeshProUGUI>();
((TMP_Text)_slickText).alignment = (TextAlignmentOptions)514;
((TMP_Text)_slickText).enableWordWrapping = false;
((TMP_Text)_slickText).overflowMode = (TextOverflowModes)0;
((Graphic)_slickText).raycastTarget = false;
((TMP_Text)_slickText).text = "( · )";
((TMP_Text)_slickText).fontSize = 72f;
((TMP_Text)_slickText).fontStyle = (FontStyles)0;
TMP_FontAsset val3 = FindSlickFont();
if ((Object)(object)val3 != (Object)null)
{
((TMP_Text)_slickText).font = val3;
}
_outlineDot = PickOutlineDot(((TMP_Text)_slickText).font);
_glyphFullOutline = "( " + _outlineDot + " )";
_glyphShown = true;
_glyphText = null;
_glyphSize = 72f;
_barShown = false;
_lastBarW = -1f;
GameObject val4 = new GameObject("crosshair_slick_windup");
val4.transform.SetParent(crosshairNormal.parent, false);
RectTransform val5 = val4.AddComponent<RectTransform>();
val5.anchorMin = val2.anchorMin;
val5.anchorMax = val2.anchorMax;
val5.pivot = new Vector2(0.5f, 0.5f);
val5.anchoredPosition = val2.anchoredPosition + new Vector2(0f, -46f);
val5.sizeDelta = new Vector2(0f, 6f);
_windupBar = val4.AddComponent<Image>();
((Graphic)_windupBar).raycastTarget = false;
_windupBarRt = val5;
val4.SetActive(false);
ModSettingsApi.RegisterPreviewGraphic((Graphic)(object)_slickText);
ModSettingsApi.RegisterPreviewGraphic((Graphic)(object)_windupBar);
ManualLogSource logger = Plugin.Logger;
if (logger != null)
{
logger.LogInfo((object)"Slick crosshair created");
}
return true;
}
catch (Exception ex)
{
ManualLogSource logger2 = Plugin.Logger;
if (logger2 != null)
{
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val6 = new BepInExWarningLogInterpolatedStringHandler(33, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val6).AppendLiteral("Slick crosshair creation failed: ");
((BepInExLogInterpolatedStringHandler)val6).AppendFormatted<string>(ex.Message);
}
logger2.LogWarning(val6);
}
_slickText = null;
return false;
}
}
private static void ScaleTransform(Transform t, float factor)
{
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)t == (Object)null))
{
int instanceID = ((Object)t).GetInstanceID();
if (!BaseScales.TryGetValue(instanceID, out var value))
{
value = t.localScale;
BaseScales[instanceID] = value;
}
t.localScale = value * factor;
}
}
}
[BepInPlugin("com.smolmods.crosshair", "smolMods.Crosshair", "1.0.2")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BasePlugin
{
public const string PluginGuid = "com.smolmods.crosshair";
public const string PluginName = "smolMods.Crosshair";
public const string PluginVersion = "1.0.2";
internal static ManualLogSource Logger;
public override void Load()
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: 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_006e: Expected O, but got Unknown
Logger = ((BasePlugin)this).Log;
CrosshairSizeFeature.Register();
Harmony val = new Harmony("com.smolmods.crosshair");
val.PatchAll(typeof(Plugin).Assembly);
int num = 0;
foreach (MethodBase patchedMethod in val.GetPatchedMethods())
{
_ = patchedMethod;
num++;
}
ManualLogSource log = ((BasePlugin)this).Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(27, 3, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("smolMods.Crosshair");
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("1.0.2");
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" loaded, ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(num);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" methods patched.");
}
log.LogInfo(val2);
}
}
}