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 System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalConfig.ConfigItems.Options;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using com.github.zehsteam.PagicPesley.Dependencies;
using com.github.zehsteam.PagicPesley.Helpers;
using com.github.zehsteam.PagicPesley.Patches;
[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("com.github.zehsteam.PagicPesley")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("For the best Pagic Pesley experience.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PagicPesley")]
[assembly: AssemblyTitle("com.github.zehsteam.PagicPesley")]
[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 com.github.zehsteam.PagicPesley
{
internal class ConfigManager
{
public ConfigEntry<bool> TextReplacement_Enabled { get; private set; }
public ConfigEntry<bool> TextReplacement_ReplaceInputFields { get; private set; }
public ConfigEntry<bool> TextReplacement_ReplaceTerminalInputField { get; private set; }
public ConfigEntry<bool> TextReplacement_ReplaceChatInputField { get; private set; }
public ConfigManager()
{
BindConfigs();
ConfigHelper.ClearUnusedEntries();
}
private void BindConfigs()
{
ConfigHelper.SkipAutoGen();
TextReplacement_Enabled = ConfigHelper.Bind("Text Replacement", "Enabled", defaultValue: true, "If enabled, will replace all text.");
TextReplacement_ReplaceInputFields = ConfigHelper.Bind("Text Replacement", "ReplaceInputFields", defaultValue: false, "If enabled, will replace text in all input fields.");
TextReplacement_ReplaceTerminalInputField = ConfigHelper.Bind("Text Replacement", "ReplaceTerminalInputField", defaultValue: true, "If enabled, will replace text in the terminal.");
TextReplacement_ReplaceChatInputField = ConfigHelper.Bind("Text Replacement", "ReplaceChatInputField", defaultValue: true, "If enabled, will replace text in the chat.");
}
}
[BepInPlugin("com.github.zehsteam.PagicPesley", "PagicPesley", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
internal class Plugin : BaseUnityPlugin
{
private readonly Harmony _harmony = new Harmony("com.github.zehsteam.PagicPesley");
internal static Plugin Instance { get; private set; }
internal static ManualLogSource Logger { get; private set; }
internal static ConfigManager ConfigManager { get; private set; }
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
Logger = Logger.CreateLogSource("com.github.zehsteam.PagicPesley");
Logger.LogInfo((object)"PagicPesley has awoken!");
_harmony.PatchAll(typeof(HUDManagerPatch));
_harmony.PatchAll(typeof(TerminalPatch));
_harmony.PatchAll(typeof(TMP_TextPatch));
_harmony.PatchAll(typeof(TextMeshProUGUIPatch));
ConfigManager = new ConfigManager();
}
}
internal static class Utils
{
private static readonly Regex _pagicPesleyRegex = new Regex("(?<!\\p{L})([A-OQ-Za-oq-z])|(?<=[a-z])([A-OQ-Z])", RegexOptions.Compiled);
private static readonly Regex _richTextTagRegex = new Regex("<.*?>", RegexOptions.Compiled);
public static string GetPagicPesleyafiedText(string value)
{
if (string.IsNullOrEmpty(value))
{
return value;
}
StringBuilder stringBuilder = new StringBuilder();
int num = 0;
foreach (Match item in _richTextTagRegex.Matches(value))
{
int num2 = num;
string input = value.Substring(num2, item.Index - num2);
stringBuilder.Append(_pagicPesleyRegex.Replace(input, ReplaceFirstLetter));
stringBuilder.Append(item.Value);
num = item.Index + item.Length;
}
if (num < value.Length)
{
int num2 = num;
string input2 = value.Substring(num2, value.Length - num2);
stringBuilder.Append(_pagicPesleyRegex.Replace(input2, ReplaceFirstLetter));
}
return stringBuilder.ToString();
}
private static string ReplaceFirstLetter(Match match)
{
char c = match.Value[0];
return (char.IsUpper(c) ? 'P' : 'p').ToString();
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "com.github.zehsteam.PagicPesley";
public const string PLUGIN_NAME = "PagicPesley";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace com.github.zehsteam.PagicPesley.Patches
{
[HarmonyPatch(typeof(HUDManager))]
internal static class HUDManagerPatch
{
[HarmonyPatch("AddTextToChatOnServer")]
[HarmonyPrefix]
[HarmonyPriority(800)]
private static void AddTextToChatOnServerPatch(ref string chatMessage)
{
if (Plugin.ConfigManager.TextReplacement_Enabled.Value && Plugin.ConfigManager.TextReplacement_ReplaceChatInputField.Value)
{
chatMessage = Utils.GetPagicPesleyafiedText(chatMessage);
}
}
}
[HarmonyPatch(typeof(Terminal))]
internal static class TerminalPatch
{
[HarmonyPatch("Awake")]
[HarmonyPrefix]
private static void AwakePatch(ref Terminal __instance)
{
TerminalHelper.SetInstance(__instance);
}
}
[HarmonyPatch(typeof(TextMeshProUGUI))]
internal static class TextMeshProUGUIPatch
{
[HarmonyPatch("Awake")]
[HarmonyPostfix]
private static void AwakePatch(ref TextMeshProUGUI __instance)
{
((TMP_Text)__instance).text = ((TMP_Text)__instance).text;
}
}
[HarmonyPatch(typeof(TMP_Text))]
internal static class TMP_TextPatch
{
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
[HarmonyPrefix]
private static void TextPatch(ref TMP_Text __instance, ref string __0)
{
if (Plugin.ConfigManager.TextReplacement_Enabled.Value && IsAllowedTMP_Text(__instance))
{
__0 = Utils.GetPagicPesleyafiedText(__0);
}
}
private static bool IsAllowedTMP_Text(TMP_Text text)
{
TMP_InputField componentInParent = ((Component)text).GetComponentInParent<TMP_InputField>();
if ((Object)(object)componentInParent == (Object)null)
{
return true;
}
if ((Object)(object)componentInParent == (Object)(object)TerminalHelper.Instance?.screenText)
{
return Plugin.ConfigManager.TextReplacement_ReplaceTerminalInputField.Value;
}
if ((Object)(object)componentInParent == (Object)(object)HUDManager.Instance?.chatTextField)
{
return Plugin.ConfigManager.TextReplacement_ReplaceChatInputField.Value;
}
if ((Object)(object)componentInParent.textComponent == (Object)(object)text || (Object)(object)componentInParent.placeholder == (Object)(object)text)
{
return Plugin.ConfigManager.TextReplacement_ReplaceInputFields.Value;
}
return true;
}
}
}
namespace com.github.zehsteam.PagicPesley.Helpers
{
internal static class ConfigHelper
{
public static void SkipAutoGen()
{
if (LethalConfigProxy.Enabled)
{
LethalConfigProxy.SkipAutoGen();
}
}
public static void AddButton(string section, string name, string description, string buttonText, Action callback)
{
if (LethalConfigProxy.Enabled)
{
LethalConfigProxy.AddButton(section, name, description, buttonText, callback);
}
}
public static ConfigEntry<T> Bind<T>(string section, string key, T defaultValue, string description, bool requiresRestart = false, AcceptableValueBase acceptableValues = null, Action<T> settingChanged = null, ConfigFile configFile = null)
{
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Expected O, but got Unknown
if (configFile == null)
{
configFile = ((BaseUnityPlugin)Plugin.Instance).Config;
}
ConfigEntry<T> configEntry = ((acceptableValues == null) ? configFile.Bind<T>(section, key, defaultValue, description) : configFile.Bind<T>(section, key, defaultValue, new ConfigDescription(description, acceptableValues, Array.Empty<object>())));
if (settingChanged != null)
{
configEntry.SettingChanged += delegate
{
settingChanged?.Invoke(configEntry.Value);
};
}
if (LethalConfigProxy.Enabled)
{
LethalConfigProxy.AddConfig<T>(configEntry, requiresRestart);
}
return configEntry;
}
public static Dictionary<ConfigDefinition, string> GetOrphanedConfigEntries(ConfigFile configFile = null)
{
if (configFile == null)
{
configFile = ((BaseUnityPlugin)Plugin.Instance).Config;
}
PropertyInfo property = ((object)configFile).GetType().GetProperty("OrphanedEntries", BindingFlags.Instance | BindingFlags.NonPublic);
return (Dictionary<ConfigDefinition, string>)property.GetValue(configFile, null);
}
public static void SetConfigEntryValue<T>(ConfigEntry<T> configEntry, string value)
{
if (typeof(T) == typeof(int) && int.TryParse(value, out var result))
{
configEntry.Value = (T)(object)result;
return;
}
if (typeof(T) == typeof(float) && float.TryParse(value, out var result2))
{
configEntry.Value = (T)(object)result2;
return;
}
if (typeof(T) == typeof(double) && double.TryParse(value, out var result3))
{
configEntry.Value = (T)(object)result3;
return;
}
if (typeof(T) == typeof(bool) && bool.TryParse(value, out var result4))
{
configEntry.Value = (T)(object)result4;
return;
}
if (typeof(T) == typeof(string))
{
configEntry.Value = (T)(object)value;
return;
}
throw new InvalidOperationException($"Unsupported type: {typeof(T)}");
}
public static void ClearUnusedEntries(ConfigFile configFile = null)
{
if (configFile == null)
{
configFile = ((BaseUnityPlugin)Plugin.Instance).Config;
}
Dictionary<ConfigDefinition, string> orphanedConfigEntries = GetOrphanedConfigEntries(configFile);
if (orphanedConfigEntries != null)
{
orphanedConfigEntries.Clear();
configFile.Save();
}
}
}
internal static class TerminalHelper
{
public static Terminal Instance { get; private set; }
public static void SetInstance(Terminal instance)
{
Instance = instance;
}
}
}
namespace com.github.zehsteam.PagicPesley.Dependencies
{
internal static class LethalConfigProxy
{
public const string PLUGIN_GUID = "ainavt.lc.lethalconfig";
private static bool? _enabled;
public static bool Enabled
{
get
{
bool valueOrDefault = _enabled.GetValueOrDefault();
if (!_enabled.HasValue)
{
valueOrDefault = Chainloader.PluginInfos.ContainsKey("ainavt.lc.lethalconfig");
_enabled = valueOrDefault;
}
return _enabled.Value;
}
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void SkipAutoGen()
{
LethalConfigManager.SkipAutoGen();
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void AddConfig<T>(ConfigEntry<T> configEntry, bool requiresRestart = false)
{
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Expected O, but got Unknown
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Expected O, but got Unknown
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Expected O, but got Unknown
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Expected O, but got Unknown
AcceptableValueBase acceptableValues = ((ConfigEntryBase)configEntry).Description.AcceptableValues;
if (acceptableValues != null)
{
if (acceptableValues is AcceptableValueRange<float> || acceptableValues is AcceptableValueRange<int>)
{
AddConfigSlider<T>(configEntry, requiresRestart);
return;
}
if (acceptableValues is AcceptableValueList<string>)
{
AddConfigDropdown<T>(configEntry, requiresRestart);
return;
}
}
if (!(configEntry is ConfigEntry<string> val))
{
if (!(configEntry is ConfigEntry<bool> val2))
{
if (!(configEntry is ConfigEntry<float> val3))
{
if (!(configEntry is ConfigEntry<int> val4))
{
throw new NotSupportedException($"Unsupported type: {typeof(T)}");
}
LethalConfigManager.AddConfigItem((BaseConfigItem)new IntInputFieldConfigItem(val4, requiresRestart));
}
else
{
LethalConfigManager.AddConfigItem((BaseConfigItem)new FloatInputFieldConfigItem(val3, requiresRestart));
}
}
else
{
LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(val2, requiresRestart));
}
}
else
{
LethalConfigManager.AddConfigItem((BaseConfigItem)new TextInputFieldConfigItem(val, requiresRestart));
}
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void AddConfigSlider<T>(ConfigEntry<T> configEntry, bool requiresRestart = false)
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Expected O, but got Unknown
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Expected O, but got Unknown
if (!(configEntry is ConfigEntry<float> val))
{
if (!(configEntry is ConfigEntry<int> val2))
{
throw new NotSupportedException($"Slider not supported for type: {typeof(T)}");
}
LethalConfigManager.AddConfigItem((BaseConfigItem)new IntSliderConfigItem(val2, requiresRestart));
}
else
{
LethalConfigManager.AddConfigItem((BaseConfigItem)new FloatSliderConfigItem(val, requiresRestart));
}
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void AddConfigDropdown<T>(ConfigEntry<T> configEntry, bool requiresRestart = false)
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Expected O, but got Unknown
if (configEntry is ConfigEntry<string> val)
{
LethalConfigManager.AddConfigItem((BaseConfigItem)new TextDropDownConfigItem(val, requiresRestart));
return;
}
throw new NotSupportedException($"Dropdown not supported for type: {typeof(T)}");
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void AddButton(string section, string name, string description, string buttonText, Action callback)
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Expected O, but got Unknown
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Expected O, but got Unknown
LethalConfigManager.AddConfigItem((BaseConfigItem)new GenericButtonConfigItem(section, name, description, buttonText, (GenericButtonHandler)delegate
{
callback?.Invoke();
}));
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}