using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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: AssemblyCompany("SoDDiskLabels")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("SoDDiskLabels")]
[assembly: AssemblyTitle("SoDDiskLabels")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
[module: UnverifiableCode]
[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 SoDDiskLabels
{
[BepInPlugin("ta.sod.disklabels", "Sync Disk Labels", "0.1.0")]
public class Plugin : BasePlugin
{
public const string VER = "0.1.0";
internal static ManualLogSource L;
public override void Load()
{
L = ((BasePlugin)this).Log;
Harmony.CreateAndPatchAll(typeof(UpdateContentPatch), (string)null);
Harmony.CreateAndPatchAll(typeof(SetupPatch), (string)null);
Harmony.CreateAndPatchAll(typeof(HoverStartPatch), (string)null);
Harmony.CreateAndPatchAll(typeof(HoverEndPatch), (string)null);
L.LogInfo((object)"Sync Disk Labels 0.1.0 loaded, 4 hooks registered.");
}
}
internal static class Labeler
{
private const string Dict = "evidence.syncdisks";
private static readonly Dictionary<string, string> Cache = new Dictionary<string, string>();
private static readonly HashSet<string> FiredHooks = new HashSet<string>();
internal static void Apply(InventorySquareController sq, string hook)
{
try
{
if (FiredHooks.Add(hook))
{
Plugin.L.LogInfo((object)("[LABEL] hook " + hook + " fired for the first time"));
}
if ((Object)(object)sq == (Object)null)
{
return;
}
InventorySlot slot = sq.slot;
if (slot == null)
{
return;
}
Interactable interactable = slot.GetInteractable();
if (interactable == null)
{
return;
}
SyncDiskPreset syncDisk = interactable.syncDisk;
if ((SoCustomComparison)(object)syncDisk == (SoCustomComparison)null)
{
return;
}
string text = Lookup(((Object)syncDisk).name);
if (text == null)
{
return;
}
object prop = GetProp(sq, "text");
if (prop == null)
{
return;
}
PropertyInfo property = prop.GetType().GetProperty("text", BindingFlags.Instance | BindingFlags.Public);
if (!(property == null) && property.CanWrite)
{
string text2 = property.GetValue(prop, null) as string;
string name = interactable.GetName();
if (!string.IsNullOrEmpty(text2) && !string.IsNullOrEmpty(name) && text2.Contains(name))
{
property.SetValue(prop, text2.Replace(name, text), null);
}
}
}
catch (Exception ex)
{
Plugin.L.LogWarning((object)("[LABEL] error in " + hook + ": " + ex.GetType().Name + ": " + ex.Message));
}
}
private static string Lookup(string key)
{
if (string.IsNullOrEmpty(key))
{
return null;
}
if (Cache.TryGetValue(key, out var value))
{
return value;
}
string text = null;
try
{
text = Strings.Get("evidence.syncdisks", key, (Casing)0, false, true, false, (Human)null);
}
catch (Exception ex)
{
Plugin.L.LogWarning((object)("[LABEL] Strings.Get threw for " + key + ": " + ex.GetType().Name + ": " + ex.Message));
}
string text2 = ((string.IsNullOrEmpty(text) || text == key || text.Contains(key)) ? null : text);
Cache[key] = text2;
Plugin.L.LogInfo((object)("[LABEL] lookup evidence.syncdisks / " + key + " -> '" + (text ?? "null") + "'" + ((text2 == null) ? " (not used, label left as is)" : "")));
return text2;
}
private static object GetProp(object o, string prop)
{
if (o == null)
{
return null;
}
PropertyInfo property = o.GetType().GetProperty(prop, BindingFlags.Instance | BindingFlags.Public);
if (!(property == null))
{
return property.GetValue(o, null);
}
return null;
}
}
[HarmonyPatch(typeof(InventorySquareController), "OnUpdateContent")]
public static class UpdateContentPatch
{
private static void Postfix(InventorySquareController __instance)
{
Labeler.Apply(__instance, "OnUpdateContent");
}
}
[HarmonyPatch(typeof(InventorySquareController), "Setup")]
public static class SetupPatch
{
private static void Postfix(InventorySquareController __instance)
{
Labeler.Apply(__instance, "Setup");
}
}
[HarmonyPatch(typeof(InventorySquareController), "OnHoverStart")]
public static class HoverStartPatch
{
private static void Postfix(InventorySquareController __instance)
{
Labeler.Apply(__instance, "OnHoverStart");
}
}
[HarmonyPatch(typeof(InventorySquareController), "OnHoverEnd")]
public static class HoverEndPatch
{
private static void Postfix(InventorySquareController __instance)
{
Labeler.Apply(__instance, "OnHoverEnd");
}
}
}