using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Mirror;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[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 CrackUVLight
{
[BepInPlugin("Grokent.CrackUVLight", "UV Light", "1.0.0")]
public sealed class UVLightPlugin : BaseUnityPlugin
{
public const string Guid = "Grokent.CrackUVLight";
public const string Version = "1.0.0";
private const string ItemId = "UV_Light";
private const string ItemName = "UV Light";
private const string Tagline = "When regular light is just too bright.";
private const string Footnote = "Do not eat";
private const string SpecialtyCatalog = "Shop_Catalog_Tier4";
private const string UVPrefabName = "PF_Item_UVLight";
internal static UVLightPlugin Instance;
internal static ManualLogSource Log;
private static ConfigEntry<int> _price;
private static ConfigEntry<int> _maxPurchases;
private static ConfigEntry<bool> _resetDaily;
private static ConfigEntry<bool> _verbose;
private static ShopItemData _item;
private static bool _renamed;
private void Awake()
{
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
Instance = this;
Log = ((BaseUnityPlugin)this).Logger;
_price = ((BaseUnityPlugin)this).Config.Bind<int>("Store", "Price", 2995, "Price in cents ($29.95).");
_maxPurchases = ((BaseUnityPlugin)this).Config.Bind<int>("Store", "MaxPurchases", 1, "Purchases allowed per restock.");
_resetDaily = ((BaseUnityPlugin)this).Config.Bind<bool>("Store", "ResetDaily", true, "Restock the purchase limit each day.");
_verbose = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "VerboseLogging", false, "Log catalog injection details.");
new Harmony("Grokent.CrackUVLight").PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"UV Light loaded.");
}
internal static void EnsureInstalled(ShopCatalog[] catalogs)
{
if (_price == null)
{
return;
}
ShopCatalog val = FindSpecialty(catalogs);
if ((Object)(object)val == (Object)null)
{
Verbose("[UVLight] Specialty catalog not loaded yet");
}
else
{
if ((Object)(object)FindExisting(val) != (Object)null)
{
return;
}
GameObject val2 = FindUVPrefab();
if ((Object)(object)val2 == (Object)null)
{
ManualLogSource log = Log;
if (log != null)
{
log.LogError((object)"[UVLight] could not find PF_Item_UVLight in NetworkClient.prefabs or loaded objects");
}
return;
}
Flashlight component = val2.GetComponent<Flashlight>();
if ((Object)(object)component == (Object)null)
{
ManualLogSource log2 = Log;
if (log2 != null)
{
log2.LogError((object)"[UVLight] PF_Item_UVLight has no Flashlight component");
}
return;
}
if (!_renamed)
{
RenameUVItems(component);
_renamed = true;
}
if ((Object)(object)_item == (Object)null)
{
_item = CreateItem(val2, component);
if ((Object)(object)_item == (Object)null)
{
return;
}
}
ShopItemData[] array = val.items ?? Array.Empty<ShopItemData>();
Array.Resize(ref array, array.Length + 1);
array[^1] = _item;
val.items = array;
ManualLogSource log3 = Log;
if (log3 != null)
{
log3.LogInfo((object)("[UVLight] added UV Light to " + val.catalogName + " at $" + ((float)_price.Value / 100f).ToString("0.00")));
}
}
}
private static ShopItemData FindExisting(ShopCatalog specialty)
{
if (specialty.items == null)
{
return null;
}
for (int i = 0; i < specialty.items.Length; i++)
{
ShopItemData val = specialty.items[i];
if ((Object)(object)val != (Object)null && ((Object)val).name == "UV_Light")
{
_item = val;
return val;
}
}
return null;
}
private static ShopCatalog FindSpecialty(ShopCatalog[] catalogs)
{
if (catalogs != null)
{
for (int i = 0; i < catalogs.Length; i++)
{
if (IsSpecialty(catalogs[i]))
{
return catalogs[i];
}
}
}
ShopCatalog[] array = Resources.FindObjectsOfTypeAll<ShopCatalog>();
for (int j = 0; j < array.Length; j++)
{
if (IsSpecialty(array[j]))
{
return array[j];
}
}
return null;
}
private static bool IsSpecialty(ShopCatalog catalog)
{
if ((Object)(object)catalog == (Object)null)
{
return false;
}
if (catalog.catalogName == "Shop_Catalog_Tier4")
{
return true;
}
if (catalog.items == null)
{
return false;
}
for (int i = 0; i < catalog.items.Length; i++)
{
ShopItemData val = catalog.items[i];
if ((Object)(object)val != (Object)null && val.itemName == "Item_Toolbox_Tier1_Name")
{
return true;
}
}
return false;
}
private static GameObject FindUVPrefab()
{
foreach (KeyValuePair<uint, GameObject> prefab in NetworkClient.prefabs)
{
if ((Object)(object)prefab.Value != (Object)null && ((Object)prefab.Value).name == "PF_Item_UVLight")
{
return prefab.Value;
}
}
GameObject[] array = Resources.FindObjectsOfTypeAll<GameObject>();
for (int i = 0; i < array.Length; i++)
{
if ((Object)(object)array[i] != (Object)null && ((Object)array[i]).name == "PF_Item_UVLight")
{
return array[i];
}
}
return null;
}
private static ShopItemData CreateItem(GameObject prefab, Flashlight flashlight)
{
ShopItemData val = ScriptableObject.CreateInstance<ShopItemData>();
((Object)val).name = "UV_Light";
val.itemName = "UV Light";
val.tagline = "When regular light is just too bright.";
val.footnote = "Do not eat";
val.price = _price.Value;
val.shippingCents = 0;
val.spawnPrefab = prefab;
val.features = Array.Empty<string>();
val.maxPurchases = _maxPurchases.Value;
val.resetDaily = _resetDaily.Value;
val.icon = AccessTools.FieldRefAccess<HeldItem, Sprite>("icon").Invoke((HeldItem)(object)flashlight);
if ((Object)(object)val.icon == (Object)null)
{
Sprite[] array = Resources.FindObjectsOfTypeAll<Sprite>();
for (int i = 0; i < array.Length; i++)
{
if ((Object)(object)array[i] != (Object)null && ((Object)array[i]).name == "Icon_UVLight")
{
val.icon = array[i];
break;
}
}
}
((Object)val).hideFlags = (HideFlags)32;
return val;
}
private static void RenameUVItems(Flashlight prefabFlashlight)
{
FieldRef<HeldItem, string> val = AccessTools.FieldRefAccess<HeldItem, string>("itemNameKey");
val.Invoke((HeldItem)(object)prefabFlashlight) = "UV Light";
Flashlight[] array = Object.FindObjectsByType<Flashlight>((FindObjectsInactive)1, (FindObjectsSortMode)0);
foreach (Flashlight val2 in array)
{
if ((Object)(object)val2 != (Object)null && (Object)(object)((Component)val2).GetComponentInChildren<UVLightSource>(true) != (Object)null)
{
val.Invoke((HeldItem)(object)val2) = "UV Light";
}
}
Verbose("[UVLight] renamed UV flashlight instances");
}
private static void Verbose(string message)
{
if (_verbose != null && _verbose.Value)
{
ManualLogSource log = Log;
if (log != null)
{
log.LogInfo((object)message);
}
}
}
}
[HarmonyPatch(typeof(ShopApp), "Awake")]
internal static class ShopAppAwakePatch
{
[HarmonyPrefix]
private static void Prefix(ShopApp __instance)
{
UVLightPlugin.EnsureInstalled(AccessTools.FieldRefAccess<ShopApp, ShopCatalog[]>("catalogs").Invoke(__instance));
}
}
[HarmonyPatch(typeof(ShopStateManager), "Awake")]
internal static class ShopStateManagerAwakePatch
{
[HarmonyPostfix]
private static void Postfix(ShopStateManager __instance)
{
UVLightPlugin.EnsureInstalled(AccessTools.FieldRefAccess<ShopStateManager, ShopCatalog[]>("_catalogs").Invoke(__instance));
}
}
}