using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using System.Threading;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Mimics;
using UnityEngine;
using UnityEngine.InputSystem;
[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("TestAccount666.EntranceExitTipChanger")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Random chance to change the enter or exit tooltip")]
[assembly: AssemblyFileVersion("2.2.2.0")]
[assembly: AssemblyInformationalVersion("2.2.2")]
[assembly: AssemblyProduct("EntranceExitTipChanger")]
[assembly: AssemblyTitle("TestAccount666.EntranceExitTipChanger")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.2.2.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.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;
}
}
[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 EntranceExitTipChanger
{
public class ConfigManager
{
private static bool _changing = false;
internal readonly List<string> ExitTipList = new List<string>();
internal int ExitTipChangeChance = 5;
internal readonly List<string> EnterTipList = new List<string>();
internal int EnterTipChangeChance = 5;
private bool _enableMimicSupport = true;
private bool _appendInteractKeyAutomatically = true;
internal int TimeTillReset = 3;
internal RandomMode RandomMode = RandomMode.MapSeed;
private ConfigEntry<string> _exitTipListConfigEntry = null;
private ConfigEntry<int> _exitTipChangeChanceConfigEntry = null;
private ConfigEntry<string> _enterTipListConfigEntry = null;
private ConfigEntry<int> _enterTipChangeChanceConfigEntry = null;
private ConfigEntry<bool> _enableMimicSupportConfigEntry = null;
private ConfigEntry<bool> _appendInteractKeyAutomaticallyConfigEntry = null;
private ConfigEntry<int> _timeTillResetConfigEntry = null;
private ConfigEntry<RandomMode> _randomModeConfigEntry = null;
private readonly ConfigFile _config;
private static readonly object LockObject = new object();
private static readonly Regex OneOrMoreCommaRegex = new Regex(",+", RegexOptions.Compiled);
private static readonly Regex OnlySingularCommaRegex = new Regex("(?<!,),(?!,)", RegexOptions.Compiled);
private static readonly Regex DirtyInteractRegex = new Regex("Interact:<(Keyboard|Mouse)>/", RegexOptions.Compiled);
public ConfigManager(ConfigFile config)
{
_config = config;
}
internal void WaitAndHandleConfig()
{
Thread thread = new Thread(HandleConfigThread);
thread.Start();
}
private void HandleConfigThread()
{
try
{
WaitForInteractAction();
SetupConfig();
LoadConfig();
}
catch (Exception arg)
{
ManualLogSource? logger = EntranceExitTipChanger.Logger;
if (logger != null)
{
logger.LogError((object)$"An error occurred: {arg}");
}
}
}
private void WaitForInteractAction()
{
while (true)
{
try
{
if (IngamePlayerSettings.Instance.playerInput.actions.FindAction("Interact", false) != null)
{
break;
}
}
catch (NullReferenceException)
{
}
catch (Exception arg)
{
ManualLogSource? logger = EntranceExitTipChanger.Logger;
if (logger != null)
{
logger.LogError((object)$"An error occurred while waiting for the interact action: {arg}");
}
}
Thread.Sleep(1000);
}
}
private void SetupConfig()
{
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Expected O, but got Unknown
//IL_014a: Unknown result type (might be due to invalid IL or missing references)
//IL_0154: Expected O, but got Unknown
//IL_0195: Unknown result type (might be due to invalid IL or missing references)
//IL_019f: Expected O, but got Unknown
//IL_01df: Unknown result type (might be due to invalid IL or missing references)
//IL_01e9: Expected O, but got Unknown
ManualLogSource? logger = EntranceExitTipChanger.Logger;
if (logger != null)
{
logger.LogInfo((object)"Setting up Config...");
}
lock (LockObject)
{
_appendInteractKeyAutomaticallyConfigEntry = _config.Bind<bool>("General", "Append Interact Key Automatically", true, new ConfigDescription("If true, this will append : [E] to all tooltips you configure. Here, 'E' represents the actual interaction key in the game. Note that these tooltips will only reflect changes upon restarting the game.", (AcceptableValueBase)(object)new AcceptableValueRange<bool>(false, true), Array.Empty<object>()));
_appendInteractKeyAutomaticallyConfigEntry.SettingChanged += OnSettingChanged;
_exitTipListConfigEntry = _config.Bind<string>("General", "Exit Tips", "Feed, Feed Me, Exti, Enter, Die, Kill, Evaporate, Dissolve, Annihilate, Disintegrate", "This field accepts a comma-separated list of exit tooltips that this mod can display. To include a singular comma in a tooltip, use a double comma.");
_exitTipListConfigEntry.SettingChanged += OnSettingChanged;
_enterTipListConfigEntry = _config.Bind<string>("General", "Enter Tips", "Entre, Decend, Venture, Plunge, Penetrate, Engage, Enterize, Submerse, Substantiate, Infiltrate, Militarize, Explode", "This field accepts a comma-separated list of enter tooltips that this mod can display. To include a singular comma in a tooltip, use a double comma.");
_enterTipListConfigEntry.SettingChanged += OnSettingChanged;
_timeTillResetConfigEntry = _config.Bind<int>("General", "Time Till Reset", 3, "This setting determines the duration, measured in seconds, for which the tooltip remains unchanged after the player's camera shifts elsewhere, preventing excessive tooltip changes through rapid camera movement.");
_timeTillResetConfigEntry.SettingChanged += OnSettingChanged;
_exitTipChangeChanceConfigEntry = _config.Bind<int>("Chances", "Exit Tips", 5, new ConfigDescription("This setting determines the probability (in percentage) of displaying a random exit tooltip.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
_exitTipChangeChanceConfigEntry.SettingChanged += OnSettingChanged;
_enterTipChangeChanceConfigEntry = _config.Bind<int>("Chances", "Enter Tips", 5, new ConfigDescription("This setting determines the probability (in percentage) of displaying a random enter tooltip.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
_enterTipChangeChanceConfigEntry.SettingChanged += OnSettingChanged;
_enableMimicSupportConfigEntry = _config.Bind<bool>("Compatibility", "Enable Mimics Support", true, new ConfigDescription("If true, enables support for the x753.Mimics Mod.", (AcceptableValueBase)(object)new AcceptableValueRange<bool>(false, true), Array.Empty<object>()));
_enableMimicSupportConfigEntry.SettingChanged += OnSettingChanged;
_randomModeConfigEntry = _config.Bind<RandomMode>("Randomness", "Random Mode", RandomMode.MapSeed, "This setting determines the strategy for selecting the seed used to initialize randomness at the start of each round.");
_randomModeConfigEntry.SettingChanged += OnSettingChanged;
ManualLogSource? logger2 = EntranceExitTipChanger.Logger;
if (logger2 != null)
{
logger2.LogInfo((object)"Finished setting up Config!");
}
}
}
private void OnSettingChanged(object sender, EventArgs args)
{
ManualLogSource? logger = EntranceExitTipChanger.Logger;
if (logger != null)
{
logger.LogInfo((object)"Settings changed, reloading!");
}
if (_changing)
{
ManualLogSource? logger2 = EntranceExitTipChanger.Logger;
if (logger2 != null)
{
logger2.LogWarning((object)"Reload already in progress!");
}
}
else
{
LoadConfig();
}
}
private void LoadConfig()
{
ManualLogSource? logger = EntranceExitTipChanger.Logger;
if (logger != null)
{
logger.LogInfo((object)"Loading Config...");
}
lock (LockObject)
{
_appendInteractKeyAutomatically = _appendInteractKeyAutomaticallyConfigEntry.Value;
string text = _exitTipListConfigEntry.Value;
if (_appendInteractKeyAutomatically)
{
text = text.Replace(" : [E]", "");
}
IEnumerable<string> collection = CollectTooltipsIntoList(text, _appendInteractKeyAutomatically);
ExitTipList.Clear();
ExitTipList.AddRange(collection);
string text2 = _enterTipListConfigEntry.Value;
if (_appendInteractKeyAutomatically)
{
text2 = text2.Replace(" : [E]", "");
}
IEnumerable<string> collection2 = CollectTooltipsIntoList(text2, _appendInteractKeyAutomatically);
EnterTipList.AddRange(collection2);
TimeTillReset = _timeTillResetConfigEntry.Value;
ExitTipChangeChance = _exitTipChangeChanceConfigEntry.Value;
EnterTipChangeChance = _enterTipChangeChanceConfigEntry.Value;
_enableMimicSupport = _enableMimicSupportConfigEntry.Value;
RandomMode = _randomModeConfigEntry.Value;
if (DependencyChecker.IsMimicsModInstalled())
{
if (!_enableMimicSupport)
{
MimicSupport.Enabled = false;
}
else
{
ManualLogSource? logger2 = EntranceExitTipChanger.Logger;
if (logger2 != null)
{
logger2.LogInfo((object)"Found x753.Mimics Mod, enabled support for it :)");
}
MimicSupport.Enabled = true;
}
}
_changing = false;
ManualLogSource? logger3 = EntranceExitTipChanger.Logger;
if (logger3 != null)
{
logger3.LogInfo((object)"Finished loading Config!");
}
}
}
private static IEnumerable<string> CollectTooltipsIntoList(string input, bool appendInteractKey)
{
//IL_0124: Unknown result type (might be due to invalid IL or missing references)
//IL_0129: Unknown result type (might be due to invalid IL or missing references)
//IL_012e: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
MatchCollection matchCollection = OnlySingularCommaRegex.Matches(input);
List<string> list = new List<string>();
int num = 0;
foreach (Match item in matchCollection)
{
string input2 = input.Substring(num, item.Index - num).Trim();
input2 = OneOrMoreCommaRegex.Replace(input2, ",");
if (!string.IsNullOrEmpty(input2))
{
list.Add(input2);
}
num = item.Index + 1;
}
int num2 = num;
string input3 = input.Substring(num2, input.Length - num2).Trim();
input3 = OneOrMoreCommaRegex.Replace(input3, ",");
if (!string.IsNullOrEmpty(input3))
{
list.Add(input3);
}
if (!appendInteractKey)
{
return list;
}
for (int i = 0; i < list.Count; i++)
{
string text = list[i];
InputBinding val = IngamePlayerSettings.Instance.playerInput.actions.FindAction("Interact", false).bindings[0];
string input4 = ((object)(InputBinding)(ref val)).ToString();
input4 = DirtyInteractRegex.Replace(input4, "").ToUpper();
list[i] = text + " : [" + input4 + "]";
}
return list;
}
}
public class DefaultHoverTip : MonoBehaviour
{
public string? defaultTooltip;
public string? defaultHoldTooltip;
public long resetTimestamp = 0L;
}
[BepInPlugin("TestAccount666.EntranceExitTipChanger", "EntranceExitTipChanger", "2.2.2")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class EntranceExitTipChanger : BaseUnityPlugin
{
internal static ManualLogSource? Logger;
internal static Harmony? Harmony;
internal static ConfigManager ConfigManager;
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
ManualLogSource? logger = Logger;
if (logger != null)
{
logger.LogInfo((object)"TestAccount666.EntranceExitTipChanger v2.2.2 loading...");
}
ConfigManager = new ConfigManager(((BaseUnityPlugin)this).Config);
Patch();
ConfigManager.WaitAndHandleConfig();
ManualLogSource? logger2 = Logger;
if (logger2 != null)
{
logger2.LogInfo((object)"TestAccount666.EntranceExitTipChanger v2.2.2 has loaded!");
}
}
private void Patch()
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
if (Harmony == null)
{
Harmony = new Harmony("TestAccount666.EntranceExitTipChanger");
}
ManualLogSource? logger = Logger;
if (logger != null)
{
logger.LogDebug((object)"Patching...");
}
Harmony.PatchAll();
ManualLogSource? logger2 = Logger;
if (logger2 != null)
{
logger2.LogDebug((object)"Finished patching!");
}
}
}
public static class DependencyChecker
{
public static bool IsMimicsModInstalled()
{
return Chainloader.PluginInfos.Values.Any((PluginInfo metadata) => metadata.Metadata.GUID.Equals("x753.Mimics"));
}
}
public static class MimicSupport
{
internal static bool Enabled;
public static void SetRandomTooltips(InteractTrigger interactTrigger)
{
InteractTrigger interactTrigger2 = interactTrigger;
if (MimicDoor.allMimics == null || MimicDoor.allMimics.Count <= 0)
{
return;
}
MimicDoor val = ((IEnumerable<MimicDoor>)MimicDoor.allMimics).FirstOrDefault((Func<MimicDoor, bool>)((MimicDoor mimic) => (Object)(object)mimic.interactTrigger == (Object)(object)interactTrigger2));
if (Object.op_Implicit((Object)(object)val))
{
int exitTipChangeChance = EntranceExitTipChanger.ConfigManager.ExitTipChangeChance;
List<string> exitTipList = EntranceExitTipChanger.ConfigManager.ExitTipList;
if (TooltipManager.ShouldChangeTooltip(exitTipChangeChance, exitTipList))
{
TooltipManager.ChangeTooltip(interactTrigger2, exitTipList);
}
}
}
}
[HarmonyPatch(typeof(PlayerControllerB))]
public class PlayerControllerPatch
{
[HarmonyPatch("SetHoverTipAndCurrentInteractTrigger")]
[HarmonyPostfix]
public static void SetAndResetRandomTooltips(PlayerControllerB __instance)
{
TooltipManager.SetRandomTooltip(__instance.hoveringOverTrigger);
TooltipManager.ResetChangedTooltipsExceptHovering(__instance.hoveringOverTrigger);
}
}
public enum RandomMode
{
MapSeed,
CurrentDateMillis,
CurrentTimeMillis
}
[HarmonyPatch(typeof(RoundManager))]
public class RoundManagerPatch
{
[HarmonyPatch("GenerateNewLevelClientRpc")]
[HarmonyPostfix]
public static void OnNewRandomSeed(int randomSeed)
{
RandomMode randomMode = EntranceExitTipChanger.ConfigManager.RandomMode;
if (1 == 0)
{
}
long num = randomMode switch
{
RandomMode.MapSeed => randomSeed,
RandomMode.CurrentDateMillis => SystemClock.ToUnixTimeMilliseconds(SystemClock.now),
RandomMode.CurrentTimeMillis => (long)(TimeSpan.FromHours(SystemClock.now.Hour).TotalMilliseconds + TimeSpan.FromMinutes(SystemClock.now.Minute).TotalMilliseconds + TimeSpan.FromSeconds(SystemClock.now.Second).TotalMilliseconds + (double)SystemClock.now.Millisecond),
_ => throw new ArgumentOutOfRangeException(),
};
if (1 == 0)
{
}
long num2 = num;
TooltipManager.Random = new Random((int)num2);
ManualLogSource? logger = EntranceExitTipChanger.Logger;
if (logger != null)
{
logger.LogInfo((object)$"Chose new seed for random: {num2}");
}
}
}
public static class TooltipManager
{
private static readonly HashSet<InteractTrigger> ChangedInteractTriggers = new HashSet<InteractTrigger>();
public static Random? Random { get; internal set; }
public static void SetRandomTooltip(InteractTrigger hoveringOverTrigger)
{
if (!StartOfRound.Instance.shipHasLanded || !Object.op_Implicit((Object)(object)hoveringOverTrigger) || Object.op_Implicit((Object)(object)((Component)hoveringOverTrigger).gameObject.GetComponent<DefaultHoverTip>()))
{
return;
}
EntranceTeleport component = ((Component)hoveringOverTrigger).gameObject.GetComponent<EntranceTeleport>();
if (!Object.op_Implicit((Object)(object)component))
{
if (MimicSupport.Enabled)
{
AddDefaultHoverTipComponent(hoveringOverTrigger);
MimicSupport.SetRandomTooltips(hoveringOverTrigger);
}
return;
}
int tipChangeChance;
List<string> tipList;
if (component.isEntranceToBuilding)
{
tipChangeChance = EntranceExitTipChanger.ConfigManager.EnterTipChangeChance;
tipList = EntranceExitTipChanger.ConfigManager.EnterTipList;
}
else
{
tipChangeChance = EntranceExitTipChanger.ConfigManager.ExitTipChangeChance;
tipList = EntranceExitTipChanger.ConfigManager.ExitTipList;
}
AddDefaultHoverTipComponent(hoveringOverTrigger);
if (ShouldChangeTooltip(tipChangeChance, tipList))
{
ChangeTooltip(hoveringOverTrigger, tipList);
}
}
private static void RemoveTooltip(InteractTrigger interactTrigger)
{
if ((Object)(object)interactTrigger == (Object)null)
{
ChangedInteractTriggers.RemoveWhere((InteractTrigger trigger) => (Object)(object)trigger == (Object)null);
return;
}
DefaultHoverTip component = ((Component)interactTrigger).gameObject.GetComponent<DefaultHoverTip>();
if (Object.op_Implicit((Object)(object)component))
{
long num = SystemClock.ToUnixTimeMilliseconds(SystemClock.now);
if (component.resetTimestamp <= num)
{
ChangedInteractTriggers.Remove(interactTrigger);
interactTrigger.hoverTip = component.defaultTooltip;
interactTrigger.holdTip = component.defaultHoldTooltip;
Object.Destroy((Object)(object)component);
}
}
}
internal static bool ShouldChangeTooltip(int tipChangeChance, List<string>? tipList)
{
if (tipList == null || tipList.Count == 0)
{
return false;
}
if (Random == null)
{
ManualLogSource? logger = EntranceExitTipChanger.Logger;
if (logger != null)
{
logger.LogError((object)"Tooltip wants to change before Random is initialized?!");
}
return false;
}
int num = Random.Next(0, 101);
ManualLogSource? logger2 = EntranceExitTipChanger.Logger;
if (logger2 != null)
{
logger2.LogDebug((object)$"Chance: {tipChangeChance}");
}
ManualLogSource? logger3 = EntranceExitTipChanger.Logger;
if (logger3 != null)
{
logger3.LogDebug((object)$"Rolled: {num}");
}
return num <= tipChangeChance;
}
internal static void ChangeTooltip(InteractTrigger interactTrigger, List<string> tipList)
{
if (Random == null)
{
ManualLogSource? logger = EntranceExitTipChanger.Logger;
if (logger != null)
{
logger.LogError((object)"Tooltip wants to change before Random is initialized?!");
}
}
else
{
int index = Random.Next(0, tipList.Count);
interactTrigger.holdTip = (interactTrigger.hoverTip = tipList[index]);
}
}
private static void AddDefaultHoverTipComponent(InteractTrigger interactTrigger)
{
DefaultHoverTip component = ((Component)interactTrigger).gameObject.GetComponent<DefaultHoverTip>();
if (!Object.op_Implicit((Object)(object)component))
{
long resetTimestamp = CalculateResetTimer();
component = ((Component)interactTrigger).gameObject.AddComponent<DefaultHoverTip>();
component.defaultTooltip = interactTrigger.hoverTip;
component.defaultHoldTooltip = interactTrigger.holdTip;
component.resetTimestamp = resetTimestamp;
ChangedInteractTriggers.Add(interactTrigger);
}
}
public static void ResetChangedTooltipsExceptHovering(InteractTrigger hoveringOverTrigger)
{
foreach (InteractTrigger item in ChangedInteractTriggers.ToList())
{
if ((Object)(object)item != (Object)(object)hoveringOverTrigger)
{
RemoveTooltip(item);
continue;
}
if ((Object)(object)hoveringOverTrigger == (Object)null)
{
break;
}
long resetTimestamp = CalculateResetTimer();
((Component)hoveringOverTrigger).gameObject.GetComponent<DefaultHoverTip>().resetTimestamp = resetTimestamp;
}
}
private static long CalculateResetTimer()
{
long num = SystemClock.ToUnixTimeMilliseconds(SystemClock.now);
double totalMilliseconds = TimeSpan.FromSeconds(EntranceExitTipChanger.ConfigManager.TimeTillReset).TotalMilliseconds;
return (long)((double)num + totalMilliseconds);
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "TestAccount666.EntranceExitTipChanger";
public const string PLUGIN_NAME = "EntranceExitTipChanger";
public const string PLUGIN_VERSION = "2.2.2";
}
}