Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of ExpressionConstant v1.0.1
plugins/ExpressionConstant.dll
Decompiled 5 months agousing System; using System.Collections; 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 BepInEx; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [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: IgnoresAccessChecksTo("")] [assembly: AssemblyCompany("NocturnalLyfe")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("ExpressionConstant")] [assembly: AssemblyTitle("ExpressionConstant")] [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.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 ExpressionConstant { [HarmonyPatch(typeof(PlayerController))] internal static class ExamplePlayerControllerPatch { [HarmonyPrefix] [HarmonyPatch("Start")] private static void Start_Prefix(PlayerController __instance) { ExpressionConstant.Logger.LogDebug((object)$"{__instance} Start Prefix"); } [HarmonyPostfix] [HarmonyPatch("Start")] private static void Start_Postfix(PlayerController __instance) { ExpressionConstant.Logger.LogDebug((object)$"{__instance} Start Postfix"); } } [BepInPlugin("NocturnalLyfe.ExpressionConstant", "ExpressionConstant", "1.0")] public class ExpressionConstant : BaseUnityPlugin { [HarmonyPatch(typeof(PlayerExpression))] internal class PlayerExpressionPatch { [CompilerGenerated] private sealed class <>c__DisplayClass2_0 { public int expressionIndex; internal bool <RestoreExpressionsDelayed>b__1(ToggleExpressionInput t) { return t.index == expressionIndex; } } [CompilerGenerated] private sealed class <RestoreExpressionsDelayed>d__2 : IEnumerator<object>, IEnumerator, IDisposable { private int <>1__state; private object <>2__current; public PlayerExpression instance; private float <timeout>5__1; private string <steamID>5__2; private List<int> <savedExpressions>5__3; private List<ToggleExpressionInput>.Enumerator <>s__4; private ToggleExpressionInput <toggle>5__5; private List<int>.Enumerator <>s__6; private <>c__DisplayClass2_0 <>8__7; private ToggleExpressionInput <toggleInput>5__8; object IEnumerator<object>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <RestoreExpressionsDelayed>d__2(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <steamID>5__2 = null; <savedExpressions>5__3 = null; <>s__4 = default(List<ToggleExpressionInput>.Enumerator); <toggle>5__5 = null; <>s__6 = default(List<int>.Enumerator); <>8__7 = null; <toggleInput>5__8 = null; <>1__state = -2; } private bool MoveNext() { //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Expected O, but got Unknown //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Expected O, but got Unknown //IL_0178: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Expected O, but got Unknown //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Expected O, but got Unknown switch (<>1__state) { default: return false; case 0: <>1__state = -1; <timeout>5__1 = 5f; goto IL_008a; case 1: <>1__state = -1; <timeout>5__1 -= 0.1f; goto IL_008a; case 2: <>1__state = -1; goto IL_0116; case 3: <>1__state = -1; goto IL_0149; case 4: <>1__state = -1; _initializedPlayers.Add(<steamID>5__2); if (_savedActiveExpressions.ContainsKey(<steamID>5__2) && _savedActiveExpressions[<steamID>5__2].Count > 0) { <savedExpressions>5__3 = new List<int>(_savedActiveExpressions[<steamID>5__2]); <>s__4 = instance.inputToggleList.GetEnumerator(); try { while (<>s__4.MoveNext()) { <toggle>5__5 = <>s__4.Current; <toggle>5__5.active = false; <toggle>5__5 = null; } } finally { ((IDisposable)<>s__4).Dispose(); } <>s__4 = default(List<ToggleExpressionInput>.Enumerator); <>2__current = null; <>1__state = 5; return true; } _lastSavedState[<steamID>5__2] = ""; break; case 5: { <>1__state = -1; <>s__6 = <savedExpressions>5__3.GetEnumerator(); try { while (<>s__6.MoveNext()) { <>8__7 = new <>c__DisplayClass2_0(); <>8__7.expressionIndex = <>s__6.Current; <toggleInput>5__8 = ((IEnumerable<ToggleExpressionInput>)instance.inputToggleList).FirstOrDefault((Func<ToggleExpressionInput, bool>)((ToggleExpressionInput t) => t.index == <>8__7.expressionIndex)); if (<toggleInput>5__8 != null) { <toggleInput>5__8.active = true; } <toggleInput>5__8 = null; <>8__7 = null; } } finally { ((IDisposable)<>s__6).Dispose(); } <>s__6 = default(List<int>.Enumerator); _lastSavedState[<steamID>5__2] = string.Join(",", <savedExpressions>5__3.OrderBy((int x) => x)); <savedExpressions>5__3 = null; break; } IL_0149: if (instance.inputToggleList == null || instance.inputToggleList.Count == 0) { <>2__current = (object)new WaitForSeconds(0.1f); <>1__state = 3; return true; } <>2__current = (object)new WaitForSeconds(1f); <>1__state = 4; return true; IL_0116: if (!LevelGenerator.Instance.Generated) { <>2__current = (object)new WaitForSeconds(0.1f); <>1__state = 2; return true; } goto IL_0149; IL_008a: if (string.IsNullOrEmpty(instance.playerAvatar?.steamID) && <timeout>5__1 > 0f) { <>2__current = (object)new WaitForSeconds(0.1f); <>1__state = 1; return true; } if (string.IsNullOrEmpty(instance.playerAvatar?.steamID)) { return false; } <steamID>5__2 = instance.playerAvatar.steamID; goto IL_0116; } return false; } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } [HarmonyPostfix] [HarmonyPatch("Update")] private static void Update_Postfix(PlayerExpression __instance) { PlayerExpression __instance2 = __instance; try { if (!Object.op_Implicit((Object)(object)__instance2.playerAvatar) || !__instance2.playerAvatar.isLocal) { return; } string steamID = __instance2.playerAvatar.steamID; if (string.IsNullOrEmpty(steamID) || !_initializedPlayers.Contains(steamID) || !Object.op_Implicit((Object)(object)LevelGenerator.Instance) || !LevelGenerator.Instance.Generated) { return; } List<int> list = new List<int>(); if (__instance2.inputToggleList != null) { foreach (ToggleExpressionInput inputToggle in __instance2.inputToggleList) { if (inputToggle.active) { list.Add(inputToggle.index); } } } string text = string.Join(",", list.OrderBy((int x) => x)); if ((!_lastSavedState.ContainsKey(steamID) || _lastSavedState[steamID] != text) && list.Count > 0) { _savedActiveExpressions[steamID] = list; _lastSavedState[steamID] = text; Logger.LogInfo((object)("Saved: " + string.Join(", ", list.Select((int i) => __instance2.expressions[i].expressionName)))); } } catch (Exception ex) { Logger.LogError((object)("Update error: " + ex.Message)); } } [HarmonyPostfix] [HarmonyPatch("Start")] private static void Start_Postfix(PlayerExpression __instance) { try { if (Object.op_Implicit((Object)(object)__instance.playerAvatar) && __instance.playerAvatar.isLocal) { ((MonoBehaviour)__instance).StartCoroutine(RestoreExpressionsDelayed(__instance)); } } catch (Exception ex) { Logger.LogError((object)("Start error: " + ex.Message)); } } [IteratorStateMachine(typeof(<RestoreExpressionsDelayed>d__2))] private static IEnumerator RestoreExpressionsDelayed(PlayerExpression instance) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <RestoreExpressionsDelayed>d__2(0) { instance = instance }; } } [HarmonyPatch(typeof(PlayerAvatar))] internal class PlayerAvatarPatch { [HarmonyPrefix] [HarmonyPatch("OnDestroy")] private static void OnDestroy_Prefix(PlayerAvatar __instance) { try { if (!__instance.isLocal || string.IsNullOrEmpty(__instance.steamID)) { return; } PlayerExpression playerExpression = __instance.playerExpression; if (playerExpression?.inputToggleList == null || !_initializedPlayers.Contains(__instance.steamID)) { return; } List<int> list = new List<int>(); foreach (ToggleExpressionInput inputToggle in playerExpression.inputToggleList) { if (inputToggle.active) { list.Add(inputToggle.index); } } if (list.Count > 0) { _savedActiveExpressions[__instance.steamID] = list; _lastSavedState[__instance.steamID] = string.Join(",", list.OrderBy((int x) => x)); } } catch (Exception ex) { Logger.LogError((object)("OnDestroy error: " + ex.Message)); } } } private static Dictionary<string, List<int>> _savedActiveExpressions = new Dictionary<string, List<int>>(); private static Dictionary<string, string> _lastSavedState = new Dictionary<string, string>(); private static HashSet<string> _initializedPlayers = new HashSet<string>(); internal static ExpressionConstant Instance { get; private set; } = null; internal static ManualLogSource Logger => Instance._logger; private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger; internal Harmony? Harmony { get; set; } private void Awake() { Instance = this; ((Component)this).gameObject.transform.parent = null; ((Object)((Component)this).gameObject).hideFlags = (HideFlags)61; Patch(); Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!"); } internal void Patch() { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown //IL_0026: Expected O, but got Unknown if (Harmony == null) { Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID); Harmony val2 = val; Harmony = val; } Harmony.PatchAll(); } internal void Unpatch() { Harmony? harmony = Harmony; if (harmony != null) { harmony.UnpatchSelf(); } } } }