using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
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.Configuration;
using BepInEx.Logging;
using CodeTalker.Networking;
using CodeTalker.Packets;
using HarmonyLib;
using Marioalexsan.Multitool.SaveUtils;
using Marioalexsan.Multitool.Utils;
using Microsoft.CodeAnalysis;
using Mirror;
using Newtonsoft.Json;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Marioalexsan.AllowAnyNames")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("2.0.3.0")]
[assembly: AssemblyInformationalVersion("2.0.3+43325bf9417a45cdf53d3fb751e45f525d241f82")]
[assembly: AssemblyProduct("AllowAnyNames")]
[assembly: AssemblyTitle("Marioalexsan.AllowAnyNames")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.0.3.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 Marioalexsan.AllowAnyNames
{
public class NameUpdatePacket : PacketBase
{
public static readonly NameUpdatePacket Instance = new NameUpdatePacket();
public override string PacketSourceGUID => "Marioalexsan.AllowAnyNames.NameUpdatePacket";
public int Version { get; set; } = 1;
public uint TargetNetId { get; set; } = 0u;
public string RichTextName { get; set; } = "";
}
[HarmonyPatch(typeof(Player), "OnGameConditionChange")]
internal static class SendNameUpdateOnPlayerJoinedForClients
{
private static void Postfix(CharacterSelectManager __instance)
{
if (!NetworkServer.activeHost && Object.op_Implicit((Object)(object)Player._mainPlayer))
{
AllowAnyNamesSave value;
string richTextName = (AllowAnyNames.CustomSaveData.TryGetValue(ProfileDataManager._current.SelectedFileIndex, out value) ? value.RichTextName : "NullAAN");
AllowAnyNames.SendNameUpdate(((NetworkBehaviour)Player._mainPlayer).netId, richTextName);
}
}
}
[HarmonyPatch(typeof(ProfileDataSender), "Assign_PlayerData")]
internal static class SendNameUpdateOnPlayerJoinedForServer
{
private static void Postfix(CharacterSelectManager __instance)
{
if (Object.op_Implicit((Object)(object)Player._mainPlayer))
{
AllowAnyNamesSave value;
string richTextName = (AllowAnyNames.CustomSaveData.TryGetValue(ProfileDataManager._current.SelectedFileIndex, out value) ? value.RichTextName : "NullAAN");
AllowAnyNames.SendNameUpdate(((NetworkBehaviour)Player._mainPlayer).netId, richTextName);
}
}
}
[HarmonyPatch]
internal static class HandleCharacterSelectionInputs
{
private static MethodInfo TargetMethod()
{
return AccessTools.FirstMethod(typeof(CharacterSelectManager), (Func<MethodInfo, bool>)((MethodInfo x) => x.Name.Contains("Handle_SelectionControl")));
}
private static bool Prefix(CharacterSelectManager __instance)
{
return !CreateRenameUserInteface.IsRenamePromptActive;
}
}
[HarmonyPatch(typeof(Player), "Update")]
internal static class ConnectedPlayers
{
private static void Postfix(Player __instance)
{
AllowAnyNames.Players.Add(__instance);
}
}
[HarmonyPatch]
internal static class HandleRenameInterface
{
private static MethodInfo TargetMethod()
{
return AccessTools.FirstMethod(typeof(CharacterSelectManager), (Func<MethodInfo, bool>)((MethodInfo x) => x.Name.Contains("Handle_ButtonControl")));
}
private static void Postfix(CharacterSelectManager __instance)
{
if (CreateRenameUserInteface.IsRenamePromptActive)
{
((Selectable)__instance._nextSlotPageButton).interactable = false;
((Selectable)__instance._previousSlotPageButton).interactable = false;
((Selectable)__instance._characterDeleteButton).interactable = false;
((Selectable)CreateRenameUserInteface.RenamePromptButton).interactable = false;
((Selectable)CreateRenameUserInteface.RenameButton).interactable = true;
((Selectable)CreateRenameUserInteface.ReturnButton).interactable = true;
bool enabled = false;
((Behaviour)CreateRenameUserInteface.GamepadIconInput).enabled = enabled;
((Behaviour)CreateRenameUserInteface.GamepadIconConfirm).enabled = enabled;
((Behaviour)CreateRenameUserInteface.GamepadIconReturn).enabled = enabled;
}
else
{
((Selectable)CreateRenameUserInteface.RenamePromptButton).interactable = !__instance._deleteCharacterPrompt && !ProfileDataManager._current._characterFile._isEmptySlot;
((Selectable)CreateRenameUserInteface.RenameButton).interactable = false;
((Selectable)CreateRenameUserInteface.ReturnButton).interactable = false;
CreateRenameUserInteface.RenameInputText.text = AllowAnyNames.GetRawCharacterRichTextName(ProfileDataManager._current._characterFile);
}
}
}
[HarmonyPatch(typeof(MainMenuManager), "Awake")]
internal static class CreateRenameUserInteface
{
[CompilerGenerated]
private static class <>O
{
public static UnityAction <0>__OpenRenameCharacterPromptClicked;
public static UnityAction <1>__RenameCharacterConfirmClicked;
public static UnityAction <2>__RenameCharacterReturnClicked;
}
internal static bool IsRenamePromptActive;
internal static MenuElement? RenameDolly;
internal static InputField? RenameInputText;
internal static Button? RenamePromptButton;
internal static Button? RenameButton;
internal static Button? ReturnButton;
internal static Image? GamepadIconInput;
internal static Image? GamepadIconConfirm;
internal static Image? GamepadIconReturn;
private static void Postfix(MainMenuManager __instance)
{
InputField characterNameInputField = __instance._characterCreationManager._characterNameInputField;
characterNameInputField.characterValidation = (CharacterValidation)0;
characterNameInputField.characterLimit = 512;
if (Object.op_Implicit((Object)(object)GameObject.Find("AAN_button_renameCharacter")))
{
return;
}
GameObject val = GameObject.Find("_button_deleteCharacter");
GameObject val2 = GameObject.Find("_dolly_characterDeletePrompt");
GameObject val3 = GameObject.Find("_input_@nickname");
if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val.GetComponentInChildren<Text>()) || !Object.op_Implicit((Object)(object)val.GetComponent<Button>()) || !Object.op_Implicit((Object)(object)val2) || !Object.op_Implicit((Object)(object)val3))
{
Logging.LogWarning("Couldn't find base UI elements to edit / instantiate from!");
return;
}
GameObject val4 = Object.Instantiate<GameObject>(val, val.transform.parent);
HierarchyTraverse.ForComponent<RectTransform>(val3, (Action<RectTransform>)delegate(RectTransform transform)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
((Transform)transform).localPosition = ((Transform)transform).localPosition + new Vector3(0f, 60f, 0f);
});
HierarchyTraverse.ForComponent<RectTransform>(HierarchyTraverse.GoToParent(val4), (Action<RectTransform>)delegate(RectTransform transform)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
((Transform)transform).localPosition = ((Transform)transform).localPosition + new Vector3(0f, 20f, 0f);
transform.sizeDelta += new Vector2(0f, transform.sizeDelta.y - 5f);
});
HierarchyTraverse.ForComponent<Button>(HierarchyTraverse.ForChildComponent<Text>(HierarchyTraverse.Rename(val4, "AAN_button_renameCharacter"), (Action<Text>)delegate(Text x)
{
x.text = "Rename Character";
}), (Action<Button>)delegate(Button x)
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Expected O, but got Unknown
RenamePromptButton = x;
x.onClick = new ButtonClickedEvent();
ButtonClickedEvent onClick3 = x.onClick;
object obj3 = <>O.<0>__OpenRenameCharacterPromptClicked;
if (obj3 == null)
{
UnityAction val8 = OpenRenameCharacterPromptClicked;
<>O.<0>__OpenRenameCharacterPromptClicked = val8;
obj3 = (object)val8;
}
((UnityEvent)onClick3).AddListener((UnityAction)obj3);
});
GameObject val5 = Object.Instantiate<GameObject>(val2, val2.transform.parent);
HierarchyTraverse.ForChild(HierarchyTraverse.ForChild(HierarchyTraverse.ForChild(HierarchyTraverse.ForChild(HierarchyTraverse.SaveComponentRef<MenuElement>(HierarchyTraverse.Rename(val5, "AAN_dolly_characterRenamePrompt"), ref RenameDolly), "_gamepadIco_input_deletePrompt", (Action<GameObject>)delegate(GameObject ico)
{
HierarchyTraverse.SaveComponentRef<Image>(ico, ref GamepadIconInput);
}), "_gamepadIco_confirm_deletePrompt", (Action<GameObject>)delegate(GameObject ico)
{
HierarchyTraverse.SaveComponentRef<Image>(ico, ref GamepadIconConfirm);
}), "_gamepadIco_return_deletePrompt", (Action<GameObject>)delegate(GameObject ico)
{
HierarchyTraverse.SaveComponentRef<Image>(ico, ref GamepadIconReturn);
}), "_backdrop_deleteCharacter", (Action<GameObject>)delegate(GameObject backdrop)
{
HierarchyTraverse.ForChild(HierarchyTraverse.ForChild(HierarchyTraverse.ForChild(HierarchyTraverse.ForChild(HierarchyTraverse.Rename(backdrop, "AAN_backdrop_renameCharacter"), "_text_characterDeletePrompt", (Action<GameObject>)delegate(GameObject prompt)
{
HierarchyTraverse.ForComponent<Text>(HierarchyTraverse.Rename(prompt, "AAN_text_characterRenamePrompt"), (Action<Text>)delegate(Text x)
{
x.text = "Type in the new name for the character";
});
}), "_input_characterDeleteConfirm", (Action<GameObject>)delegate(GameObject input)
{
HierarchyTraverse.ForComponent<InputField>(HierarchyTraverse.SaveComponentRef<InputField>(HierarchyTraverse.Rename(input, "AAN_input_characterRenameConfirm"), ref RenameInputText), (Action<InputField>)delegate(InputField input)
{
input.characterLimit = 512;
input.characterValidation = (CharacterValidation)0;
});
}), "_button_confirmDeleteCharacter", (Action<GameObject>)delegate(GameObject input)
{
HierarchyTraverse.ForChildComponent<Text>(HierarchyTraverse.ForComponent<Button>(HierarchyTraverse.Rename(input, "AAN_button_confirmRenameCharacter"), (Action<Button>)delegate(Button button)
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Expected O, but got Unknown
RenameButton = button;
button.onClick = new ButtonClickedEvent();
ButtonClickedEvent onClick2 = button.onClick;
object obj2 = <>O.<1>__RenameCharacterConfirmClicked;
if (obj2 == null)
{
UnityAction val7 = RenameCharacterConfirmClicked;
<>O.<1>__RenameCharacterConfirmClicked = val7;
obj2 = (object)val7;
}
((UnityEvent)onClick2).AddListener((UnityAction)obj2);
}), (Action<Text>)delegate(Text text)
{
text.text = "Rename Character";
});
}), "_button_deletePrompt_return", (Action<GameObject>)delegate(GameObject input)
{
HierarchyTraverse.ForComponent<Button>(HierarchyTraverse.Rename(input, "AAN_button_renamePrompt_return"), (Action<Button>)delegate(Button button)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Expected O, but got Unknown
button.onClick = new ButtonClickedEvent();
ButtonClickedEvent onClick = button.onClick;
object obj = <>O.<2>__RenameCharacterReturnClicked;
if (obj == null)
{
UnityAction val6 = RenameCharacterReturnClicked;
<>O.<2>__RenameCharacterReturnClicked = val6;
obj = (object)val6;
}
((UnityEvent)onClick).AddListener((UnityAction)obj);
ReturnButton = button;
});
});
});
}
private static void OpenRenameCharacterPromptClicked()
{
GameObject obj = GameObject.Find("_aSrc_menuDecline");
if (obj != null)
{
AudioSource component = obj.GetComponent<AudioSource>();
if (component != null)
{
component.Play();
}
}
IsRenamePromptActive = true;
RenameDolly.EnableElement(true);
RenameInputText.ActivateInputField();
}
private static void RenameCharacterConfirmClicked()
{
GameObject obj = GameObject.Find("_aSrc_menuAccept");
if (obj != null)
{
AudioSource component = obj.GetComponent<AudioSource>();
if (component != null)
{
component.Play();
}
}
RenameDolly.EnableElement(false);
IsRenamePromptActive = false;
string text = RenameInputText.text;
CharacterFile characterFile = ProfileDataManager._current._characterFile;
AllowAnyNames.SetCharacterRichTextName(text, characterFile);
QuickSaveCharacter();
}
private static void RenameCharacterReturnClicked()
{
RenameDolly.EnableElement(false);
IsRenamePromptActive = false;
}
private static void QuickSaveCharacter()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
MainMenuCondition mainMenuCondition = MainMenuManager._current._mainMenuCondition;
bool isNewCharacter = ProfileDataManager._current._characterFile._isNewCharacter;
MainMenuManager._current._mainMenuCondition = (MainMenuCondition)2;
ProfileDataManager._current.Save_ProfileData();
MainMenuManager._current._mainMenuCondition = mainMenuCondition;
ProfileDataManager._current._characterFile._isNewCharacter = isNewCharacter;
}
}
[HarmonyPatch]
internal static class FixCharacterNicknames
{
private static MethodInfo TargetMethod()
{
return AccessTools.GetDeclaredMethods(typeof(CharacterCreationManager)).First((MethodInfo x) => x.Name.Contains("Apply_CharacterBaseData"));
}
private static void Postfix(CharacterCreationManager __instance)
{
string text = __instance._characterNameInputField.text;
CharacterFile characterFile = ProfileDataManager._current._characterFile;
AllowAnyNames.SetCharacterRichTextName(text, characterFile);
}
}
[HarmonyPatch]
internal static class FullRichTextReplacements
{
[CompilerGenerated]
private sealed class <TargetMethods>d__1 : IEnumerable<MethodInfo>, IEnumerable, IEnumerator<MethodInfo>, IEnumerator, IDisposable
{
private int <>1__state;
private MethodInfo <>2__current;
private int <>l__initialThreadId;
private Dictionary<MethodInfo, HashSet<int>>.KeyCollection.Enumerator <>s__1;
private MethodInfo <method>5__2;
MethodInfo IEnumerator<MethodInfo>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <TargetMethods>d__1(int <>1__state)
{
this.<>1__state = <>1__state;
<>l__initialThreadId = Environment.CurrentManagedThreadId;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
int num = <>1__state;
if (num == -3 || num == 23)
{
try
{
}
finally
{
<>m__Finally1();
}
}
<>s__1 = default(Dictionary<MethodInfo, HashSet<int>>.KeyCollection.Enumerator);
<method>5__2 = null;
<>1__state = -2;
}
private bool MoveNext()
{
try
{
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = AccessTools.Method(typeof(StatusEntity), "Init_PvpFragMessage", (Type[])null, (Type[])null);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
<>2__current = AccessTools.Method(typeof(PartyUIDataEntry), "Update", (Type[])null, (Type[])null);
<>1__state = 2;
return true;
case 2:
<>1__state = -1;
<>2__current = AccessTools.FirstMethod(typeof(TargetInfoDisplayManager), (Func<MethodInfo, bool>)((MethodInfo method) => method.Name.Contains("Handle_PlayerInfoDisplay")));
<>1__state = 3;
return true;
case 3:
<>1__state = -1;
<>2__current = AccessTools.FirstMethod(typeof(StatsMenuCell), (Func<MethodInfo, bool>)((MethodInfo method) => method.Name.Contains("Handle_StatCounterDisplays")));
<>1__state = 4;
return true;
case 4:
<>1__state = -1;
<>2__current = AccessTools.Method(typeof(WhoMenuCell), "Init_MutePeer", (Type[])null, (Type[])null);
<>1__state = 5;
return true;
case 5:
<>1__state = -1;
<>2__current = AccessTools.Method(typeof(WhoListDataEntry), "Handle_WhoDataEntry", (Type[])null, (Type[])null);
<>1__state = 6;
return true;
case 6:
<>1__state = -1;
<>2__current = AccessTools.Method(typeof(ChatBehaviour), "On_ChannelSwitch", (Type[])null, (Type[])null);
<>1__state = 7;
return true;
case 7:
<>1__state = -1;
<>2__current = AccessTools.Method(typeof(ChatBehaviour), "UserCode_Cmd_SendChatMessage__String__ChatChannel", (Type[])null, (Type[])null);
<>1__state = 8;
return true;
case 8:
<>1__state = -1;
<>2__current = AccessTools.Method(typeof(ChatBehaviour), "UserCode_Rpc_RecieveChatMessage__String__Boolean__ChatChannel", (Type[])null, (Type[])null);
<>1__state = 9;
return true;
case 9:
<>1__state = -1;
<>2__current = AccessTools.Method(typeof(ConsoleCommandManager), "Init_BanClient", (Type[])null, (Type[])null);
<>1__state = 10;
return true;
case 10:
<>1__state = -1;
<>2__current = AccessTools.Method(typeof(ConsoleCommandManager), "Init_KickClient", (Type[])null, (Type[])null);
<>1__state = 11;
return true;
case 11:
<>1__state = -1;
<>2__current = AccessTools.Method(typeof(HC_PeerListEntry), "Apply_PeerDataEntry", (Type[])null, (Type[])null);
<>1__state = 12;
return true;
case 12:
<>1__state = -1;
<>2__current = AccessTools.Method(typeof(HostConsole), "Destroy_PeerListEntry", (Type[])null, (Type[])null);
<>1__state = 13;
return true;
case 13:
<>1__state = -1;
<>2__current = AccessTools.Method(typeof(Player), "Handle_ClientParameters", (Type[])null, (Type[])null);
<>1__state = 14;
return true;
case 14:
<>1__state = -1;
<>2__current = AccessTools.Method(typeof(Player), "Handle_PartyInviteStatus", (Type[])null, (Type[])null);
<>1__state = 15;
return true;
case 15:
<>1__state = -1;
<>2__current = AccessTools.Method(typeof(Player), "Pend_PartyInvite", (Type[])null, (Type[])null);
<>1__state = 16;
return true;
case 16:
<>1__state = -1;
<>2__current = AccessTools.Method(typeof(Player), "UserCode_Cmd_InviteToParty__Player", (Type[])null, (Type[])null);
<>1__state = 17;
return true;
case 17:
<>1__state = -1;
<>2__current = AccessTools.Method(typeof(PlayerStats), "OnLevelUp", (Type[])null, (Type[])null);
<>1__state = 18;
return true;
case 18:
<>1__state = -1;
<>2__current = AccessTools.Method(typeof(PlayerStats), "UserCode_Cmd_GainProfessionExp__ResourceEntity__Int32", (Type[])null, (Type[])null);
<>1__state = 19;
return true;
case 19:
<>1__state = -1;
<>2__current = AccessTools.Method(typeof(PlayerStats), "UserCode_Cmd_RequestClass__String", (Type[])null, (Type[])null);
<>1__state = 20;
return true;
case 20:
<>1__state = -1;
<>2__current = AccessTools.Method(typeof(PlayerStats), "UserCode_Cmd_RequestClassTier__Int32", (Type[])null, (Type[])null);
<>1__state = 21;
return true;
case 21:
<>1__state = -1;
<>2__current = AccessTools.FirstMethod(typeof(CharacterSelectListDataEntry), (Func<MethodInfo, bool>)((MethodInfo method) => method.Name.Contains("Handle_FilledSlotDisplay")));
<>1__state = 22;
return true;
case 22:
<>1__state = -1;
<>s__1 = OccurrenceMap.Keys.GetEnumerator();
<>1__state = -3;
break;
case 23:
<>1__state = -3;
<method>5__2 = null;
break;
}
if (<>s__1.MoveNext())
{
<method>5__2 = <>s__1.Current;
<>2__current = <method>5__2;
<>1__state = 23;
return true;
}
<>m__Finally1();
<>s__1 = default(Dictionary<MethodInfo, HashSet<int>>.KeyCollection.Enumerator);
return false;
}
catch
{
//try-fault
((IDisposable)this).Dispose();
throw;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
private void <>m__Finally1()
{
<>1__state = -1;
((IDisposable)<>s__1).Dispose();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
[DebuggerHidden]
IEnumerator<MethodInfo> IEnumerable<MethodInfo>.GetEnumerator()
{
if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
{
<>1__state = 0;
return this;
}
return new <TargetMethods>d__1(0);
}
[DebuggerHidden]
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable<MethodInfo>)this).GetEnumerator();
}
}
private static readonly Dictionary<MethodInfo, HashSet<int>> OccurrenceMap = new Dictionary<MethodInfo, HashSet<int>> { [AccessTools.FirstMethod(typeof(Player), (Func<MethodInfo, bool>)((MethodInfo method) => method.Name.Contains("Handle_NameTagDisplay")))] = new HashSet<int> { 3, 4 } };
[IteratorStateMachine(typeof(<TargetMethods>d__1))]
private static IEnumerable<MethodInfo> TargetMethods()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <TargetMethods>d__1(-2);
}
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> code, MethodBase original)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Expected O, but got Unknown
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Expected O, but got Unknown
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: Expected O, but got Unknown
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00dc: Expected O, but got Unknown
CodeMatcher val = new CodeMatcher(code, (ILGenerator)null);
int num = 0;
while (true)
{
val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
{
new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ins) => CodeInstructionExtensions.LoadsField(ins, AccessTools.Field(typeof(Player), "_nickname"), false) || CodeInstructionExtensions.LoadsField(ins, AccessTools.Field(typeof(CharacterFile), "_nickName"), false)), (string)null)
});
if (!val.IsValid)
{
break;
}
num++;
if (OccurrenceMap.TryGetValue((MethodInfo)original, out HashSet<int> value) && !value.Contains(num))
{
val.Advance(1);
}
else if (CodeInstructionExtensions.LoadsField(val.Instruction, AccessTools.Field(typeof(Player), "_nickname"), false))
{
val.SetInstructionAndAdvance(new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(AllowAnyNames), "GetPlayerRichTextName", (Type[])null, (Type[])null)));
}
else
{
val.SetInstructionAndAdvance(new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(AllowAnyNames), "GetCharacterRichTextName", (Type[])null, (Type[])null)));
}
}
return val.InstructionEnumeration();
}
}
internal class AllowAnyNamesSave
{
private string _richTextName = "";
public string RichTextName
{
get
{
return _richTextName;
}
set
{
_richTextName = value;
SanitizedRichTextName = AllowAnyNames.SanitizeRichTextName(value);
}
}
[JsonIgnore]
public string SanitizedRichTextName { get; private set; } = "";
}
[BepInPlugin("Marioalexsan.AllowAnyNames", "AllowAnyNames", "2.0.3")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class AllowAnyNames : BaseUnityPlugin
{
public struct MultiplayerPlayerData
{
public string SanitizedCustomName;
public DateTime LastUpdate;
}
[CompilerGenerated]
private static class <>O
{
public static PacketListener <0>__OnNameUpdate;
public static SaveProfileData<AllowAnyNamesSave> <1>__SaveProfileData;
public static LoadProfileData<AllowAnyNamesSave> <2>__LoadProfileData;
public static DeleteProfileData <3>__DeleteProfileData;
}
public const int MaxRichTextNameLength = 512;
public const string NullAAN = "NullAAN";
private readonly Harmony _harmony = new Harmony("Marioalexsan.AllowAnyNames");
internal static readonly Dictionary<uint, MultiplayerPlayerData> MultiplayerData = new Dictionary<uint, MultiplayerPlayerData>();
private static readonly Regex TagRegex = new Regex("<.*?>");
internal static readonly Dictionary<int, AllowAnyNamesSave> CustomSaveData = new Dictionary<int, AllowAnyNamesSave>();
private static TimeSpan NameUpdateCooldown;
internal static Queue<string> Notices = new Queue<string>();
private static readonly StringBuilder SanitizeBuilder = new StringBuilder(1024);
private static readonly List<(int Position, int Length)> InvalidTagsCache = new List<(int, int)>(128);
private static readonly Stack<string> TagStack = new Stack<string>(128);
private static readonly Regex TagMatcher = new Regex("<([^\\=>]*)(?:=([^>]*))?>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
internal static ManualLogSource Logger { get; private set; } = null;
internal static ConfigFile Config { get; private set; } = null;
internal static HashSet<Player> Players { get; } = new HashSet<Player>();
internal static void AddNotice(string msg)
{
if (Notices.Count < 5)
{
Notices.Enqueue(msg);
}
}
public void Awake()
{
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Expected O, but got Unknown
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Expected O, but got Unknown
Config = ((BaseUnityPlugin)this).Config;
Logger = ((BaseUnityPlugin)this).Logger;
_harmony.PatchAll();
object obj = <>O.<0>__OnNameUpdate;
if (obj == null)
{
PacketListener val = OnNameUpdate;
<>O.<0>__OnNameUpdate = val;
obj = (object)val;
}
CodeTalkerNetwork.RegisterListener<NameUpdatePacket>((PacketListener)obj);
SaveProfileData<AllowAnyNamesSave> obj2 = SaveProfileData;
LoadProfileData<AllowAnyNamesSave> obj3 = LoadProfileData;
object obj4 = <>O.<3>__DeleteProfileData;
if (obj4 == null)
{
DeleteProfileData val2 = DeleteProfileData;
<>O.<3>__DeleteProfileData = val2;
obj4 = (object)val2;
}
SaveUtilsAPI.RegisterProfileData<AllowAnyNamesSave>("Marioalexsan.AllowAnyNames", obj2, obj3, (DeleteProfileData)obj4);
}
private static void TestSanitization()
{
string[] array = new string[40]
{
"test123", "<color=blue>test123</color>", "<color=red><color=blue>test123</color></color>", "<color=blue>test123</color><b>test234</b>", "test123</b></color>", "<>test123</>", "<color=blue><b>test123", "<color =blue>test123</color>", "<color= blue>test123</color>", "<b=blue>test123</b>",
"<color=blue>test123</color=red>", "<size=1>test123</size>", "<size=7>test123</size>", "<size=8>test123</size>", "<size=30>test123</size>", "<size=31>test123</size>", "<size=999>test123</size>", "<size=123.45>test123</size>", "<size=big>test123</size>", "<color=#FFFFFF>test123</size>",
"<color=#000000FF>test123</size>", "<color=#000000AF>test123</size>", "<color=#0000009F>test123</size>", "<color=#0000002F>test123</size>", "<color=#00000020>test123</size>", "<color=#0000001F>test123</size>", "<color=#0000000F>test123</size>", "<color=#00000000>test123</size>", "<test123<", "<<test123<<",
"<<b>test123<</b>", "<<<b>test123<<</b>", "<b><test123</b><", "<b><<test123</b><<", ">test123>", ">>test123>>", "><b>test123></b>", ">><b>test123>></b>", "<b>>test123</b>>", "<b>>>test123</b>>>"
};
string[] array2 = array;
foreach (string text in array2)
{
Logger.LogInfo((object)("Name sanitization: " + text + " => " + SanitizeRichTextName(text)));
}
}
private static void SaveProfileData(CharacterFile file, int index, out AllowAnyNamesSave? saveData)
{
if (!CustomSaveData.TryGetValue(index, out saveData))
{
saveData = new AllowAnyNamesSave
{
RichTextName = file._nickName
};
}
}
private static void LoadProfileData(CharacterFile file, int index, AllowAnyNamesSave? saveData)
{
if (saveData == null)
{
saveData = new AllowAnyNamesSave
{
RichTextName = file._nickName
};
}
CustomSaveData[index] = saveData;
bool flag = saveData.SanitizedRichTextName == "NullAAN" || saveData.SanitizedRichTextName == "Null";
bool flag2 = file._nickName == "NullAAN" || file._nickName == "Null";
if (flag && flag2)
{
AddNotice($"Save number {index} had a null AAN and null vanilla name! Fix it by renaming the character.");
}
else if (flag)
{
AddNotice($"Save number {index} had a null AAN name! Fix it by renaming the character.");
}
else if (flag2)
{
AddNotice($"Save number {index} had a null vanilla name! Fix it by renaming the character.");
}
}
private static void DeleteProfileData(CharacterFile file, int index)
{
CustomSaveData.Remove(index);
}
public void Update()
{
foreach (Player player in Players)
{
if (!Object.op_Implicit((Object)(object)player))
{
MultiplayerData.Remove(((NetworkBehaviour)player).netId);
}
}
Players.RemoveWhere((Player player) => !Object.op_Implicit((Object)(object)player));
if (!NetworkServer.active && !NetworkClient.active)
{
NameUpdateCooldown = TimeSpan.FromSeconds(5.0);
}
else
{
NameUpdateCooldown -= TimeSpan.FromSeconds(Time.deltaTime);
if (NameUpdateCooldown < TimeSpan.Zero)
{
NameUpdateCooldown += TimeSpan.FromSeconds(60.0);
if (Object.op_Implicit((Object)(object)Player._mainPlayer))
{
AllowAnyNamesSave value;
string richTextName = (CustomSaveData.TryGetValue(ProfileDataManager._current.SelectedFileIndex, out value) ? value.RichTextName : "NullAAN");
SendNameUpdate(((NetworkBehaviour)Player._mainPlayer).netId, richTextName);
}
}
}
if (Notices.Count > 0 && HostConsole._current._currentNetworkStatusTimer <= 0f)
{
string text = Notices.Dequeue();
HostConsole._current.Init_NetworkStatusMessage(text);
}
}
public static bool ValidateName(string richTextName)
{
if (string.IsNullOrEmpty(richTextName))
{
return false;
}
if (richTextName.Length > 512)
{
return false;
}
return true;
}
public static string SanitizeRichTextName(string richTextName)
{
SanitizeBuilder.Clear();
SanitizeBuilder.Append(richTextName);
int num = -1;
for (int i = 0; i < SanitizeBuilder.Length; i++)
{
if (SanitizeBuilder[i] == '<')
{
if (num != -1)
{
SanitizeBuilder.Remove(num, 1);
i--;
}
num = i;
}
else if (SanitizeBuilder[i] == '>')
{
if (num == -1)
{
SanitizeBuilder.Remove(i--, 1);
}
else
{
num = -1;
}
}
}
if (num != -1)
{
SanitizeBuilder.Remove(num, 1);
}
InvalidTagsCache.Clear();
TagStack.Clear();
foreach (Match item in TagMatcher.Matches(SanitizeBuilder.ToString()))
{
string value = item.Groups[1].Value;
string param2 = (item.Groups[2].Success ? item.Groups[2].Value : null);
if (1 == 0)
{
}
bool flag = value switch
{
"align" => false,
"allcaps" => true,
"alpha" => false,
"b" => true,
"br" => false,
"color" => ValidateColor(param2),
"cspace" => false,
"font" => true,
"font-weight" => true,
"gradient" => false,
"i" => true,
"indent" => false,
"line-height" => false,
"link" => false,
"lowercase" => true,
"margin" => false,
"mark" => false,
"mspace" => true,
"nobr" => false,
"noparse" => true,
"page" => false,
"pos" => false,
"rotate" => true,
"s" => true,
"size" => ValidateSize(param2),
"smallcaps" => true,
"space" => false,
"sprite" => false,
"style" => false,
"sub" => true,
"sup" => true,
"u" => true,
"uppercase" => true,
"voffset" => false,
"width" => false,
_ => value.Length > 0 && value[0] == '/',
};
if (1 == 0)
{
}
bool flag2 = flag;
if (flag2)
{
if (value.StartsWith('/'))
{
if (TagStack.TryPeek(out string result))
{
ReadOnlySpan<char> readOnlySpan = value.AsSpan();
if (MemoryExtensions.Equals(readOnlySpan.Slice(1, readOnlySpan.Length - 1), result.AsSpan(), StringComparison.InvariantCulture))
{
TagStack.Pop();
goto IL_0899;
}
}
flag2 = false;
}
else
{
TagStack.Push(value);
}
}
goto IL_0899;
IL_0899:
if (!flag2)
{
InvalidTagsCache.Add(new(int, int)
{
Item1 = item.Index,
Item2 = item.Length
});
}
}
int num2 = 0;
for (int j = 0; j < InvalidTagsCache.Count; j++)
{
var (num3, num4) = InvalidTagsCache[j];
SanitizeBuilder.Remove(num3 - num2, num4);
num2 += num4;
}
string result2;
while (TagStack.TryPop(out result2))
{
SanitizeBuilder.Append("</").Append(result2).Append('>');
}
return SanitizeBuilder.ToString();
static bool ValidateColor(string? param)
{
if (!ValidateParam(param))
{
return false;
}
if (param.Length == 9 && param[0] == '#')
{
char c = char.ToLowerInvariant(param[7]);
return ('2' <= c && c <= '9') || ('a' <= c && c <= 'f');
}
return true;
}
static bool ValidateParam([NotNullWhen(true)] string? param)
{
if (param == null)
{
return false;
}
for (int k = 0; k < param.Length; k++)
{
if (char.IsWhiteSpace(param[k]))
{
return false;
}
}
return true;
}
static bool ValidateSize(string? param)
{
int result3;
return ValidateParam(param) && int.TryParse(param, out result3) && 8 <= result3 && result3 <= 30;
}
}
public static string StripToVanillaName(string richText)
{
string text = TagRegex.Replace(richText, "").Replace("<", "").Replace(">", "");
string text2 = text.Replace("/", "");
if (string.IsNullOrWhiteSpace(text2))
{
return "NullAAN";
}
if (text2.Length > 18)
{
text2 = text2.Trim().Substring(0, 18);
}
return text2;
}
internal static int GetFileIndex(CharacterFile file)
{
CharacterFile[] characterFiles = ProfileDataManager._current._characterFiles;
for (int i = 0; i < characterFiles.Length; i++)
{
if (characterFiles[i] == file)
{
return i;
}
}
return -1;
}
public static string GetPlayerRichTextName(Player player)
{
if ((Object)(object)player == (Object)null)
{
return "NullAAN";
}
AllowAnyNamesSave value;
if ((Object)(object)player == (Object)(object)Player._mainPlayer)
{
return CustomSaveData.TryGetValue(ProfileDataManager._current.SelectedFileIndex, out value) ? value.SanitizedRichTextName : player._nickname;
}
if (MultiplayerData.TryGetValue(((NetworkBehaviour)player).netId, out var value2))
{
return value2.SanitizedCustomName;
}
return player._nickname;
}
internal static string GetRawCharacterRichTextName(CharacterFile player)
{
if (player == null)
{
return "NullAAN";
}
if (CustomSaveData.TryGetValue(GetFileIndex(player), out AllowAnyNamesSave value))
{
return value.RichTextName;
}
return player._nickName;
}
internal static string GetCharacterRichTextName(CharacterFile player)
{
if (player == null)
{
return "NullAAN";
}
if (CustomSaveData.TryGetValue(GetFileIndex(player), out AllowAnyNamesSave value))
{
return value.SanitizedRichTextName;
}
return player._nickName;
}
public static void SetCharacterRichTextName(string rtfName, CharacterFile saveFile)
{
string nickName = StripToVanillaName(rtfName);
saveFile._nickName = nickName;
int fileIndex = GetFileIndex(saveFile);
if (!CustomSaveData.TryGetValue(fileIndex, out AllowAnyNamesSave value))
{
value = (CustomSaveData[fileIndex] = new AllowAnyNamesSave());
}
value.RichTextName = rtfName;
}
private static void OnNameUpdate(PacketHeader header, PacketBase packet)
{
if (!(packet is NameUpdatePacket nameUpdatePacket) || (MultiplayerData.TryGetValue(nameUpdatePacket.TargetNetId, out var value) && DateTime.Now < value.LastUpdate + TimeSpan.FromSeconds(15.0)) || !ValidateName(nameUpdatePacket.RichTextName))
{
return;
}
bool flag = false;
foreach (Player player in Players)
{
if (!Object.op_Implicit((Object)(object)player) || ((NetworkBehaviour)player).netId != nameUpdatePacket.TargetNetId || !(player._steamID == header.SenderID.ToString()))
{
continue;
}
flag = true;
break;
}
if (flag)
{
MultiplayerData[nameUpdatePacket.TargetNetId] = new MultiplayerPlayerData
{
SanitizedCustomName = SanitizeRichTextName(nameUpdatePacket.RichTextName),
LastUpdate = DateTime.Now
};
}
}
internal static void SendNameUpdate(uint netId, string richTextName)
{
NameUpdatePacket instance = NameUpdatePacket.Instance;
instance.Version = 1;
instance.TargetNetId = netId;
instance.RichTextName = richTextName;
CodeTalkerNetwork.SendNetworkPacket((PacketBase)(object)instance);
}
}
internal static class Logging
{
private static ManualLogSource InternalLogger => AllowAnyNames.Logger;
public static void LogFatal(object data, ConfigEntry<bool>? toggle = null)
{
Log(data, (LogLevel)1, toggle);
}
public static void LogError(object data, ConfigEntry<bool>? toggle = null)
{
Log(data, (LogLevel)2, toggle);
}
public static void LogWarning(object data, ConfigEntry<bool>? toggle = null)
{
Log(data, (LogLevel)4, toggle);
}
public static void LogMessage(object data, ConfigEntry<bool>? toggle = null)
{
Log(data, (LogLevel)8, toggle);
}
public static void LogInfo(object data, ConfigEntry<bool>? toggle = null)
{
Log(data, (LogLevel)16, toggle);
}
public static void LogDebug(object data, ConfigEntry<bool>? toggle = null)
{
Log(data, (LogLevel)32, toggle);
}
private static void Log(object data, LogLevel level = 16, ConfigEntry<bool>? toggle = null)
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
if (toggle == null || toggle.Value)
{
ManualLogSource internalLogger = InternalLogger;
if (internalLogger != null)
{
internalLogger.Log(level, data);
}
}
}
}
internal static class ModInfo
{
public const string GUID = "Marioalexsan.AllowAnyNames";
public const string NAME = "AllowAnyNames";
public const string VERSION = "2.0.3";
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}