using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using AccurateCrosshair.CrosshairPatches;
using AccurateCrosshair.PluginDependencies;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using ColorCrosshair.API;
using GTFO.API;
using GameData;
using Gear;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppSystem;
using Microsoft.CodeAnalysis;
using Player;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("AccurateCrosshair")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("AccurateCrosshair")]
[assembly: AssemblyTitle("AccurateCrosshair")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.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]
[Microsoft.CodeAnalysis.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;
}
}
}
namespace AccurateCrosshair
{
public static class Configuration
{
public static bool followsRecoil = true;
public static FirstShotType firstShotType = FirstShotType.Inner;
public static float firstShotMinDelay = 0.15f;
public static bool popEnabled = false;
public static float minSize = 10f;
public static float speedScalar = 1f;
public static void CreateAndBindAll()
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Expected O, but got Unknown
BindAll(new ConfigFile(Path.Combine(Paths.ConfigPath, "AccurateCrosshair.cfg"), true));
}
private static void BindAll(ConfigFile config)
{
BindCrosshairPopEnabled(config);
}
private static void BindCrosshairPopEnabled(ConfigFile config)
{
//IL_0015: 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_0030: Expected O, but got Unknown
//IL_0030: Expected O, but got Unknown
//IL_0049: 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_0064: Expected O, but got Unknown
//IL_0064: Expected O, but got Unknown
//IL_007d: 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_0098: Expected O, but got Unknown
//IL_0098: Expected O, but got Unknown
//IL_00b1: 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)
//IL_00cc: Expected O, but got Unknown
//IL_00cc: Expected O, but got Unknown
//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_0100: Expected O, but got Unknown
//IL_0100: Expected O, but got Unknown
//IL_0119: 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)
//IL_0134: Expected O, but got Unknown
//IL_0134: Expected O, but got Unknown
string text = "General Settings";
string text2 = "Follow Recoil";
string text3 = "Enables or disables the crosshair moving to match weapon recoil that is independent of your aim.";
followsRecoil = config.Bind<bool>(new ConfigDefinition(text, text2), followsRecoil, new ConfigDescription(text3, (AcceptableValueBase)null, Array.Empty<object>())).Value;
text2 = "First Shot Display Mode";
text3 = "Determines how the crosshair shows the hidden bonus accuracy after waiting 2 seconds to shoot.\r\nInner: Shows another circle. Match: Reduces crosshair size to match. None: Turns this off.";
firstShotType = config.Bind<FirstShotType>(new ConfigDefinition(text, text2), firstShotType, new ConfigDescription(text3, (AcceptableValueBase)null, Array.Empty<object>())).Value;
text2 = "First Shot Min Delay";
text3 = "If First Shot Display Mode is set to Match, the minimum shot delay non-semi automatic weapons need for the first shot effect to appear.";
firstShotMinDelay = config.Bind<float>(new ConfigDefinition(text, text2), firstShotMinDelay, new ConfigDescription(text3, (AcceptableValueBase)null, Array.Empty<object>())).Value;
text2 = "Pop Enabled";
text3 = "Enables or disables the visual crosshair bloom when shooting.\r\nNote: Pop is not scaled to the accurate size and may be disproportionately large.";
popEnabled = config.Bind<bool>(new ConfigDefinition(text, text2), popEnabled, new ConfigDescription(text3, (AcceptableValueBase)null, Array.Empty<object>())).Value;
text2 = "Minimum Size";
text3 = "The minimum size of the reticle. Does not scale with field of view.\r\nNote: Cannot be smaller than 10.";
minSize = config.Bind<float>(new ConfigDefinition(text, text2), minSize, new ConfigDescription(text3, (AcceptableValueBase)null, Array.Empty<object>())).Value;
text2 = "Resize Modifier";
text3 = "Scalar applied to the speed at which the crosshair resizes to its target spread.\r\nNote: Must be larger than 0. Does not affect the resize speed of pop.";
speedScalar = config.Bind<float>(new ConfigDefinition(text, text2), speedScalar, new ConfigDescription(text3, (AcceptableValueBase)null, Array.Empty<object>())).Value;
if (speedScalar <= 0f)
{
speedScalar = 1f;
}
}
}
[BepInPlugin("Dinorush.AccurateCrosshair", "AccurateCrosshair", "1.3.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
internal sealed class Loader : BasePlugin
{
public const string MODNAME = "AccurateCrosshair";
[Conditional("DEBUG")]
public static void DebugLog(object data)
{
}
public override void Load()
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Expected O, but got Unknown
((BasePlugin)this).Log.LogMessage((object)"Loading AccurateCrosshair");
Configuration.CreateAndBindAll();
Harmony val = new Harmony("AccurateCrosshair");
val.PatchAll(typeof(SpreadPatches));
if (!Configuration.popEnabled)
{
val.PatchAll(typeof(PopPatches));
}
if (Configuration.followsRecoil)
{
val.PatchAll(typeof(RecoilPatches));
}
if (Configuration.firstShotType != 0)
{
val.PatchAll(typeof(FirstShotPatches));
}
if (Configuration.firstShotType == FirstShotType.Inner)
{
val.PatchAll(typeof(FirstShotGuiPatches));
}
AssetAPI.OnStartupAssetsLoaded += AssetAPI_OnStartupAssetsLoaded;
((BasePlugin)this).Log.LogMessage((object)"Loaded AccurateCrosshair");
}
private void AssetAPI_OnStartupAssetsLoaded()
{
ColorCrosshairDependency.Init();
}
}
}
namespace AccurateCrosshair.PluginDependencies
{
internal static class ColorCrosshairDependency
{
public static bool HasColorCrosshair => ((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins.ContainsKey("Dinorush.ColorCrosshair");
public static Color DefaultColor => ColorCrosshairAPI.DefaultColor;
public static Color ChargeColor => ColorCrosshairAPI.ChargeColor;
public static Color ChargeBlinkColor => ColorCrosshairAPI.ChargeBlinkColor;
public static Color ChargeWarningColor => ColorCrosshairAPI.ChargeWarningColor;
public static Color EnemyBlinkColor => ColorCrosshairAPI.EnemyBlinkColor;
public static void Init()
{
if (HasColorCrosshair && Configuration.firstShotType == FirstShotType.Inner)
{
UnsafeInit();
}
}
private static void UnsafeInit()
{
FirstShotGuiPatches.RefreshCrosshairColor();
ColorCrosshairAPI.OnReload += ApplyColorChanges;
}
private static void ApplyColorChanges()
{
FirstShotGuiPatches.RefreshCrosshairColor();
}
}
}
namespace AccurateCrosshair.CrosshairPatches
{
internal sealed class FirstShotGui : GuiLayer
{
private CircleCrosshair? smallCrosshair;
public override void OnLevelCleanup()
{
CircleCrosshair? obj = smallCrosshair;
if (obj != null)
{
((GuiLayerComp)obj).SetVisible(false, false);
}
}
public override void Setup(Transform root, string name)
{
//IL_0011: 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)
((GuiLayer)this).Setup(root, name);
GuiLayerComp val = ((GuiLayer)this).AddComp("Gui/Crosshairs/CanvasCircleCrosshair", (GuiAnchor)3, default(Vector2), (Transform)null);
smallCrosshair = ((Il2CppObjectBase)val).TryCast<CircleCrosshair>();
if ((Object)(object)smallCrosshair != (Object)null)
{
smallCrosshair.UpdateAlphaMul(CellSettingsManager.SettingsData.HUD.Player_CrosshairOpacity.Value);
RefreshColor();
((GuiLayerComp)smallCrosshair).SetVisible(false, false);
}
}
public void Disable()
{
CircleCrosshair? obj = smallCrosshair;
if (obj != null)
{
((GuiLayerComp)obj).SetVisible(false, false);
}
}
public void Enable(float size)
{
if (!((Object)(object)smallCrosshair == (Object)null) && !(size < 0f) && !(size <= Configuration.minSize))
{
float num = Math.Max(size * 0.2f, Configuration.minSize);
((GuiLayerComp)smallCrosshair).SetVisible(true, false);
smallCrosshair.SetScale(num / smallCrosshair.m_circleRadius);
}
}
public void RefreshAlpha()
{
CircleCrosshair? obj = smallCrosshair;
if (obj != null)
{
obj.UpdateAlphaMul(CellSettingsManager.SettingsData.HUD.Player_CrosshairOpacity.Value);
}
}
public void RefreshColor()
{
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: 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)
if (!((Object)(object)smallCrosshair == (Object)null) && ColorCrosshairDependency.HasColorCrosshair)
{
CircleCrosshair? obj = smallCrosshair;
Color color = (smallCrosshair.m_crosshairColOrg = ColorCrosshairDependency.DefaultColor);
obj.SetColor(color);
}
}
}
internal static class FirstShotGuiPatches
{
public static FirstShotGui crosshairGui = new FirstShotGui();
public static void Disable()
{
crosshairGui.Disable();
}
public static void Enable(float size, bool forceOn = false)
{
if (forceOn || ((GuiLayerComp)GuiManager.CrosshairLayer.m_circleCrosshair).GetVisible())
{
crosshairGui.Enable(size);
}
}
public static void RefreshCrosshairColor()
{
crosshairGui.RefreshColor();
}
[HarmonyPatch(typeof(GuiManager), "Setup")]
[HarmonyWrapSafe]
[HarmonyPostfix]
private static void SetupSmallCrosshair(GuiManager __instance)
{
((GuiLayer)crosshairGui).Setup(__instance.m_root, "SmallCrosshairLayer");
}
[HarmonyPatch(typeof(CrosshairGuiLayer), "OnSetVisible")]
[HarmonyWrapSafe]
[HarmonyPostfix]
private static void MatchLayerVisibility(CrosshairGuiLayer __instance, bool visible)
{
((GuiLayer)crosshairGui).SetVisible(visible);
}
[HarmonyPatch(typeof(CrosshairGuiLayer), "HideCircleCrosshair")]
[HarmonyWrapSafe]
[HarmonyPostfix]
private static void MatchCrosshairVisibility(CrosshairGuiLayer __instance)
{
crosshairGui.Disable();
}
[HarmonyPatch(typeof(CrosshairGuiLayer), "UpdateAlphaFromSettings")]
[HarmonyWrapSafe]
[HarmonyPostfix]
private static void MatchCrosshairAlpha(CrosshairGuiLayer __instance)
{
crosshairGui.RefreshAlpha();
}
}
internal static class FirstShotPatches
{
private static Coroutine? firstShotRoutine = null;
private static float firstShotTime = 0f;
private static float fireRecoilCooldown = 2f;
private static float storedCrosshairSize = -1f;
private static void EnableSmallCrosshair(bool forceGuiOn = false)
{
if (Configuration.firstShotType == FirstShotType.Match)
{
SpreadPatches.SetCrosshairSize(storedCrosshairSize * 0.2f);
}
else if (Configuration.firstShotType == FirstShotType.Inner)
{
FirstShotGuiPatches.Enable(storedCrosshairSize, forceGuiOn);
}
}
private static IEnumerator MinimizeAfterDelay()
{
while (firstShotTime > Clock.Time)
{
yield return (object)new WaitForSeconds(firstShotTime - Clock.Time);
}
firstShotRoutine = null;
if (!(storedCrosshairSize < 0f))
{
EnableSmallCrosshair();
}
}
public static void SetStoredCrosshair(BulletWeapon weapon, ref float crosshairSize)
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
ArchetypeDataBlock archetypeData = ((ItemEquippable)weapon).ArchetypeData;
if (Configuration.firstShotType == FirstShotType.Match && (int)archetypeData.FireMode != 0 && archetypeData.ShotDelay < Configuration.firstShotMinDelay)
{
return;
}
storedCrosshairSize = crosshairSize;
fireRecoilCooldown = weapon.m_fireRecoilCooldown;
firstShotTime = weapon.m_lastFireTime + fireRecoilCooldown;
if (firstShotTime > Clock.Time)
{
if (firstShotRoutine == null)
{
firstShotRoutine = CoroutineManager.StartCoroutine(CollectionExtensions.WrapToIl2Cpp(MinimizeAfterDelay()), (Action)null);
}
return;
}
if (Configuration.firstShotType == FirstShotType.Match)
{
crosshairSize = Math.Max(crosshairSize * 0.2f, Configuration.minSize);
}
EnableSmallCrosshair(forceGuiOn: true);
}
public static void ResetStoredCrosshair()
{
storedCrosshairSize = -1f;
FirstShotGuiPatches.Disable();
}
[HarmonyPatch(typeof(BulletWeapon), "Fire")]
[HarmonyWrapSafe]
[HarmonyPostfix]
private static void ResetFirstShotTimer(BulletWeapon __instance)
{
firstShotTime = Clock.Time + fireRecoilCooldown;
SpreadPatches.SetCrosshairSize(storedCrosshairSize);
FirstShotGuiPatches.Disable();
if (firstShotRoutine == null)
{
firstShotRoutine = CoroutineManager.StartCoroutine(CollectionExtensions.WrapToIl2Cpp(MinimizeAfterDelay()), (Action)null);
}
}
}
public enum FirstShotType
{
None,
Match,
Inner
}
internal static class PopPatches
{
[HarmonyPatch(typeof(CrosshairGuiLayer), "PopCircleCrosshair")]
[HarmonyPrefix]
public static bool CancelRecoilPop(CrosshairGuiLayer __instance, float pop, float sizeMax)
{
return false;
}
}
internal static class RecoilPatches
{
[HarmonyPatch(typeof(CrosshairGuiLayer), "ShowSpreadCircle")]
[HarmonyWrapSafe]
[HarmonyPostfix]
private static void EnableCrosshairMovement(CrosshairGuiLayer __instance, ref float crosshairSize)
{
__instance.m_moveCircleCrosshair = !SpreadPatches.isShotgun;
}
[HarmonyPatch(typeof(FPS_RecoilSystem), "FPS_Update")]
[HarmonyWrapSafe]
[HarmonyPostfix]
private static void TightCrosshairMovement(FPS_RecoilSystem __instance)
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//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_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: 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_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
float scale = GuiManager.CrosshairLayer.m_circleCrosshair.GetScale();
Vector2 val = __instance.CurrentVSPos - new Vector2(0.5f, 0.5f);
val.y *= 0.78f;
GuiManager.CrosshairLayer.SetCrosshairPosition(val / scale + new Vector2(0.5f, 0.5f));
}
}
internal static class SpreadPatches
{
private const float BASE_CROSSHAIR_SIZE = 20f;
private const float EXTRA_BUFFER_SIZE = 10f;
public static bool isShotgun;
public static void SetCrosshairSize(float crosshairSize)
{
if (Configuration.firstShotType == FirstShotType.Match && !(crosshairSize < 0f))
{
crosshairSize = Math.Max(Configuration.minSize, crosshairSize);
CrosshairGuiLayer crosshairLayer = GuiManager.CrosshairLayer;
float num2 = (GuiManager.CrosshairLayer.m_neutralCircleSize = crosshairSize);
crosshairLayer.ScaleToSize(num2);
}
}
[HarmonyPatch(typeof(CrosshairGuiLayer), "ShowSpreadCircle")]
[HarmonyWrapSafe]
[HarmonyPrefix]
private static void AdjustCrosshairSize(CrosshairGuiLayer __instance, ref float crosshairSize)
{
if (Configuration.firstShotType != 0)
{
FirstShotPatches.ResetStoredCrosshair();
}
BulletWeapon val = ((Il2CppObjectBase)PlayerManager.GetLocalPlayerAgent().Inventory.m_wieldedItem).TryCast<BulletWeapon>();
if ((Object)(object)val == (Object)null)
{
return;
}
isShotgun = (Object)(object)((Il2CppObjectBase)val).TryCast<Shotgun>() != (Object)null;
float num = CellSettingsManager.SettingsData.Video.Fov.Value;
ArchetypeDataBlock archetypeData = ((ItemEquippable)val).ArchetypeData;
if (archetypeData != null)
{
float num2 = (float)(20.0 / Math.Tan(Math.PI / 180.0 * (double)num / 2.0));
float num3 = (isShotgun ? ((float)(archetypeData.ShotgunConeSize + archetypeData.ShotgunBulletSpread)) : archetypeData.HipFireSpread);
float num4 = Math.Max(Configuration.minSize, num3 * num2 + 10f);
crosshairSize = num4;
if (!isShotgun && Configuration.firstShotType != 0)
{
FirstShotPatches.SetStoredCrosshair(val, ref crosshairSize);
}
}
}
[HarmonyPatch(typeof(CrosshairGuiLayer), "Setup")]
[HarmonyWrapSafe]
[HarmonyPostfix]
private static void AdjustResizeSpeed(CrosshairGuiLayer __instance)
{
__instance.m_circleSpeed *= Configuration.speedScalar;
}
}
}