using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CrosshairOverlay")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A crosshair overlay mod for Straftat")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CrosshairOverlay")]
[assembly: AssemblyTitle("CrosshairOverlay")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.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 CrosshairOverlay
{
[BepInPlugin("kestrel.straftat.crosshairoverlay", "Crosshair Overlay", "1.0.1")]
public class Mod : BaseUnityPlugin
{
[HarmonyPatch(typeof(Crosshair))]
public static class CrosshairPatch
{
[HarmonyPatch("Start")]
[HarmonyPrefix]
public static void SetupCrosshairOverlay(Crosshair __instance)
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
if (configHideDefault.Value)
{
((Component)__instance).transform.localScale = Vector3.zero;
}
SetupCrosshair(((Component)__instance).transform.parent);
if (imageLoaded)
{
ReloadCrosshair();
}
}
[HarmonyPatch("Update")]
[HarmonyPrefix]
public static void UpdateOverlayVisibility(Crosshair __instance)
{
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
if (queueImageReload && imageLoaded)
{
ReloadCrosshair();
queueImageReload = false;
}
if (configHideInMenus.Value)
{
Scene activeScene = SceneManager.GetActiveScene();
if (((Scene)(ref activeScene)).name == "MainMenu")
{
root.SetActive(false);
return;
}
}
root.SetActive(true);
}
}
public const string pluginGuid = "kestrel.straftat.crosshairoverlay";
public const string pluginName = "Crosshair Overlay";
public const string pluginVersion = "1.0.1";
internal static ManualLogSource Logger;
private static string pluginPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
private static string imagePath;
private static Sprite overlaySprite;
private static GameObject root;
private static Image imageComponent;
private static RectTransform transformComponent;
private static bool queueImageReload;
private static bool imageLoaded;
public static ConfigEntry<FilterMode> configFilterMode;
public static ConfigEntry<float> configWidth;
public static ConfigEntry<float> configHeight;
public static ConfigEntry<float> configOffsetX;
public static ConfigEntry<float> configOffsetY;
public static ConfigEntry<bool> configOverlay;
public static ConfigEntry<bool> configHideDefault;
public static ConfigEntry<bool> configHideInMenus;
public static ConfigEntry<string> configFilename;
public static ConfigEntry<byte> configTintR;
public static ConfigEntry<byte> configTintG;
public static ConfigEntry<byte> configTintB;
public static ConfigEntry<byte> configTintA;
private static string loadBearingColonThree = ":3";
public static Mod Instance { get; private set; }
private void Awake()
{
//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
//IL_01b1: Expected O, but got Unknown
//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
//IL_01ea: Expected O, but got Unknown
//IL_0219: Unknown result type (might be due to invalid IL or missing references)
//IL_0223: Expected O, but got Unknown
//IL_0252: Unknown result type (might be due to invalid IL or missing references)
//IL_025c: Expected O, but got Unknown
//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
if (loadBearingColonThree != ":3")
{
Application.Quit();
}
((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
Instance = this;
Logger = ((BaseUnityPlugin)this).Logger;
configFilename = ((BaseUnityPlugin)this).Config.Bind<string>("General", "File name", "default-crosshair.png", "The name of the image file to load. png and jpeg formats are supported, and the file should be placed in the mod's directory. (" + pluginPath + ")");
configOverlay = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Overlay", true, "Wether the crosshair image should be on top of the UI. If disabled, the image will be under the UI. (NOTE: this does not include the 3D version of the player HUD~ the crosshair will always be above it.)");
configFilterMode = ((BaseUnityPlugin)this).Config.Bind<FilterMode>("General", "Image Filter Mode", (FilterMode)0, "The texture filtering mode to use for the crosshair image.");
configHideDefault = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Hide default crosshair", true, "Whether to hide the default crosshair~ this option uses the behaviour of ctrl+k, so the crosshair can be reenabled at any time.");
configHideInMenus = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Hide in menu", true, "Whether to hide the custom crosshair when in the main menu.");
configWidth = ((BaseUnityPlugin)this).Config.Bind<float>("Style.Size", "Width", 30f, "The width of the crosshair image.");
configHeight = ((BaseUnityPlugin)this).Config.Bind<float>("Style.Size", "Height", 30f, "The height of the crosshair image.");
configOffsetX = ((BaseUnityPlugin)this).Config.Bind<float>("Style.Offset", "X Offset", 0f, "The X offset of the crosshair image.");
configOffsetY = ((BaseUnityPlugin)this).Config.Bind<float>("Style.Offset", "Y Offset", 0f, "The Y offset of the crosshair image.");
configTintR = ((BaseUnityPlugin)this).Config.Bind<byte>("Style.Color", "1 Tint R", byte.MaxValue, new ConfigDescription("The red channel tint of the crosshair image.", (AcceptableValueBase)(object)new AcceptableValueRange<byte>((byte)0, byte.MaxValue), Array.Empty<object>()));
configTintG = ((BaseUnityPlugin)this).Config.Bind<byte>("Style.Color", "2 Tint G", byte.MaxValue, new ConfigDescription("The green channel tint of the crosshair image.", (AcceptableValueBase)(object)new AcceptableValueRange<byte>((byte)0, byte.MaxValue), Array.Empty<object>()));
configTintB = ((BaseUnityPlugin)this).Config.Bind<byte>("Style.Color", "3 Tint B", byte.MaxValue, new ConfigDescription("The blue channel tint of the crosshair image.", (AcceptableValueBase)(object)new AcceptableValueRange<byte>((byte)0, byte.MaxValue), Array.Empty<object>()));
configTintA = ((BaseUnityPlugin)this).Config.Bind<byte>("Style.Color", "4 Tint A", byte.MaxValue, new ConfigDescription("The alpha channel tint of the crosshair image.", (AcceptableValueBase)(object)new AcceptableValueRange<byte>((byte)0, byte.MaxValue), Array.Empty<object>()));
((BaseUnityPlugin)this).Config.SettingChanged += OnConfigChanged;
imagePath = Path.Combine(pluginPath, configFilename.Value);
if (!File.Exists(imagePath))
{
Logger.LogWarning((object)("No image file found at " + imagePath));
}
else
{
((MonoBehaviour)this).StartCoroutine(LoadCrosshairImage());
}
new Harmony("kestrel.straftat.crosshairoverlay").PatchAll();
Logger.LogInfo((object)"Hiiiiiiiiiiii :3");
}
private void OnConfigChanged(object sender, SettingChangedEventArgs e)
{
queueImageReload = true;
if (e.ChangedSetting == configFilename)
{
imagePath = Path.Combine(pluginPath, configFilename.Value);
if (!File.Exists(imagePath))
{
Logger.LogWarning((object)("No image file found at " + imagePath));
}
else
{
((MonoBehaviour)this).StartCoroutine(LoadCrosshairImage());
}
}
}
private static IEnumerator LoadCrosshairImage()
{
imageLoaded = false;
UnityWebRequest uwr = UnityWebRequestTexture.GetTexture("file:///" + Path.Combine(pluginPath, configFilename.Value));
try
{
yield return uwr.SendWebRequest();
if ((int)uwr.result != 1)
{
Logger.LogError((object)("Error while loading overlay image ~ " + uwr.error + "(the file at " + imagePath + " is probably invalid.)"));
}
else
{
Logger.LogInfo((object)"Found and loaded crosshair overlay!");
Texture2D texture = DownloadHandlerTexture.GetContent(uwr);
overlaySprite = Sprite.Create(texture, new Rect(0f, 0f, (float)((Texture)texture).width, (float)((Texture)texture).height), new Vector2(0.5f, 0.5f));
imageLoaded = true;
}
}
finally
{
((IDisposable)uwr)?.Dispose();
}
}
private static void SetupCrosshair(Transform uiRoot = null)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Expected O, but got Unknown
root = new GameObject("Crosshair Overlay");
transformComponent = root.AddComponent<RectTransform>();
CanvasGroup val = root.AddComponent<CanvasGroup>();
val.blocksRaycasts = false;
imageComponent = root.AddComponent<Image>();
if (Object.op_Implicit((Object)(object)uiRoot))
{
root.transform.SetParent(uiRoot, false);
}
}
private static void ReloadCrosshair()
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: 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_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
transformComponent.sizeDelta = new Vector2(configWidth.Value / 2f, configHeight.Value / 2f);
transformComponent.anchoredPosition = new Vector2(configOffsetX.Value, configOffsetY.Value);
((Graphic)imageComponent).color = Color32.op_Implicit(new Color32(configTintR.Value, configTintG.Value, configTintB.Value, configTintA.Value));
((Texture)overlaySprite.texture).filterMode = configFilterMode.Value;
imageComponent.sprite = overlaySprite;
if (!configOverlay.Value)
{
root.transform.SetAsFirstSibling();
}
else
{
root.transform.SetAsLastSibling();
}
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "CrosshairOverlay";
public const string PLUGIN_NAME = "CrosshairOverlay";
public const string PLUGIN_VERSION = "1.0.0";
}
}