using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("TombstoneHelper")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TombstoneHelper")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = "")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.0")]
namespace TombstoneHelper;
internal class Assets
{
public static Sprite Tombstone { get; private set; }
public static string English { get; private set; }
public static string German { get; private set; }
public static void Init()
{
Tombstone = LoadSpriteFromTexture(LoadTextureFromRaw(Resources.Tombstone));
English = BytesToString(Resources.English);
German = BytesToString(Resources.German);
}
internal static Texture2D LoadTextureFromRaw(byte[] bytes)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Expected O, but got Unknown
//IL_0010: Expected O, but got Unknown
Texture2D val = new Texture2D(2, 2);
ImageConversion.LoadImage(val, bytes);
return val;
}
internal static Sprite LoadSpriteFromTexture(Texture2D SpriteTexture, float PixelsPerUnit = 100f)
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
if (!Object.op_Implicit((Object)(object)SpriteTexture))
{
return null;
}
return Sprite.Create(SpriteTexture, new Rect(0f, 0f, (float)((Texture)SpriteTexture).width, (float)((Texture)SpriteTexture).height), new Vector2(0f, 0f), PixelsPerUnit);
}
internal static string BytesToString(byte[] bytes)
{
return Encoding.UTF8.GetString(bytes);
}
}
[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[DebuggerNonUserCode]
[CompilerGenerated]
internal class Resources
{
private static ResourceManager resourceMan;
private static CultureInfo resourceCulture;
[EditorBrowsable(EditorBrowsableState.Advanced)]
internal static ResourceManager ResourceManager
{
get
{
if (resourceMan == null)
{
resourceMan = new ResourceManager("TombstoneHelper.Resources", typeof(Resources).Assembly);
}
return resourceMan;
}
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
internal static CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
internal static byte[] English => (byte[])ResourceManager.GetObject("English", resourceCulture);
internal static byte[] German => (byte[])ResourceManager.GetObject("German", resourceCulture);
internal static byte[] Tombstone => (byte[])ResourceManager.GetObject("Tombstone", resourceCulture);
internal Resources()
{
}
}
[BepInPlugin("com.userstorm.tombstonehelper", "TombstoneHelper", "1.1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
internal class TombstoneHelperPlugin : BaseUnityPlugin
{
public const string PluginGUID = "com.userstorm.tombstonehelper";
private static FieldInfo interactMaskField = AccessTools.Field(typeof(Player), "m_interactMask");
private ConfigEntry<float> InteractionRange;
private ConfigEntry<KeyboardShortcut> ShortcutConfig;
private ButtonConfig ShortcutButton;
private StatusEffect TombstoneNearbyStatusEffect;
private bool HasTombstoneNearbyStatusEffect;
private float CheckForNearbyTombstoneTimeDifference;
private void Awake()
{
Assets.Init();
CreateConfigValues();
AddInputs();
AddLocalizations();
AddStatusEffects();
}
private void Update()
{
HandleInput();
CheckForNearbyTombstoneTimeDifference += Time.deltaTime;
if (CheckForNearbyTombstoneTimeDifference > 0.2f)
{
CheckForNearbyTombstone();
CheckForNearbyTombstoneTimeDifference = 0f;
}
}
private void CreateConfigValues()
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Expected O, but got Unknown
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Expected O, but got Unknown
((BaseUnityPlugin)this).Config.SaveOnConfigSet = true;
ShortcutConfig = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("General", "Open tombstone", new KeyboardShortcut((KeyCode)101, (KeyCode[])(object)new KeyCode[1] { (KeyCode)304 }), new ConfigDescription("Open tombstone key combination", (AcceptableValueBase)null, Array.Empty<object>()));
InteractionRange = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Interaction range", 5f, new ConfigDescription("Interaction range", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 100f), Array.Empty<object>()));
}
private void AddInputs()
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Expected O, but got Unknown
ShortcutButton = new ButtonConfig
{
Name = "OpenTombstone",
ShortcutConfig = ShortcutConfig,
HintToken = "$open_tombstone"
};
InputManager.Instance.AddButton("com.userstorm.tombstonehelper", ShortcutButton);
}
private void AddLocalizations()
{
CustomLocalization localization = LocalizationManager.Instance.GetLocalization();
localization.AddJsonFile("English", Assets.English);
localization.AddJsonFile("German", Assets.German);
}
private void AddStatusEffects()
{
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
TombstoneNearbyStatusEffect = ScriptableObject.CreateInstance<StatusEffect>();
((Object)TombstoneNearbyStatusEffect).name = "TombstoneNearbyStatusEffect";
TombstoneNearbyStatusEffect.m_name = "$tombstone_nearby_effect_name";
TombstoneNearbyStatusEffect.m_icon = Assets.Tombstone;
TombstoneNearbyStatusEffect.m_startMessageType = (MessageType)2;
TombstoneNearbyStatusEffect.m_startMessage = "$tombstone_nearby_effect_start";
}
private void CheckForNearbyTombstone()
{
Player localPlayer = Player.m_localPlayer;
if (!((Object)(object)localPlayer == (Object)null))
{
TombStone val = FindTombstone();
if ((Object)(object)val != (Object)null && !HasTombstoneNearbyStatusEffect)
{
((Character)localPlayer).GetSEMan().AddStatusEffect(TombstoneNearbyStatusEffect, true, 0, 0f);
HasTombstoneNearbyStatusEffect = true;
}
else if ((Object)(object)val == (Object)null && HasTombstoneNearbyStatusEffect)
{
((Character)localPlayer).GetSEMan().RemoveStatusEffect(TombstoneNearbyStatusEffect, true);
HasTombstoneNearbyStatusEffect = false;
}
}
}
private TombStone FindTombstone()
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
Player localPlayer = Player.m_localPlayer;
int num = (int)interactMaskField.GetValue(localPlayer);
Collider[] array = Physics.OverlapSphere(((Component)localPlayer).transform.position, InteractionRange.Value, num);
foreach (Collider obj in array)
{
object obj2;
if (obj == null)
{
obj2 = null;
}
else
{
GameObject gameObject = ((Component)obj).gameObject;
obj2 = ((gameObject != null) ? gameObject.GetComponentInParent<TombStone>() : null);
}
TombStone val = (TombStone)obj2;
if (val != null)
{
return val;
}
}
return null;
}
private void HandleInput()
{
Player localPlayer = Player.m_localPlayer;
if (ZInput.instance == null || (Object)(object)localPlayer == (Object)null || ShortcutButton == null || !ZInput.GetButtonDown(ShortcutButton.Name))
{
return;
}
TombStone val = FindTombstone();
if ((Object)(object)val == (Object)null)
{
MessageHud instance = MessageHud.instance;
if (instance != null)
{
instance.ShowMessage((MessageType)2, "$no_tombstone_nearby", 0, (Sprite)null);
}
return;
}
Interactable componentInParent = ((Component)val).gameObject.GetComponentInParent<Interactable>();
if (componentInParent != null)
{
componentInParent.Interact((Humanoid)(object)localPlayer, false, false);
}
ZInput.ResetButtonStatus("Use");
ZInput.ResetButtonStatus("JoyUse");
}
}