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 ToggleHourglassEffect v1.0.0
ToggleHourglassEffect.dll
Decompiled 2 months agousing System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Microsoft.CodeAnalysis; using Photon.Pun; 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(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: IgnoresAccessChecksTo("")] [assembly: AssemblyCompany("SEAL")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("ToggleHourglassEffect")] [assembly: AssemblyTitle("ToggleHourglassEffect")] [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; } } } public class HourglassSynchronizer : MonoBehaviourPun { private bool remotePitchActive = false; [PunRPC] private void RPC_SyncVoicePitch(bool state) { remotePitchActive = state; Debug.Log((object)$"\ud83d\udce1 [Hourglass] RPC ricevuto pitch: {state}"); } public void SyncVoicePitch(bool state) { if (((MonoBehaviourPun)this).photonView.IsMine) { ((MonoBehaviourPun)this).photonView.RPC("RPC_SyncVoicePitch", (RpcTarget)1, new object[1] { state }); Debug.Log((object)$"\ud83d\udce4 [Hourglass] RPC inviato pitch: {state}"); } } private void Update() { if (remotePitchActive) { ApplyRemotePitch(); } } private void ApplyRemotePitch() { Type type = Type.GetType("PlayerVoiceChat, Assembly-CSharp"); if (type == null) { return; } Object[] array = Object.FindObjectsOfType(type); foreach (Object val in array) { Object obj = ((val is MonoBehaviour) ? val : null); PhotonView val2 = ((obj != null) ? ((Component)obj).GetComponent<PhotonView>() : null); if (!((Object)(object)val2 == (Object)null) && val2.Owner == ((MonoBehaviourPun)this).photonView.Owner) { type.GetMethod("OverridePitch", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.Invoke(val, new object[6] { 0.65f, 1f, 2f, 0.1f, 0f, 0f }); break; } } } } namespace ToggleHourglassEffect { [BepInPlugin("com.seal.togglehourglass", "Toggle Hourglass", "1.4.0")] public class ToggleHourglass : BaseUnityPlugin { public static ToggleHourglass? Instance; private ConfigEntry<string>? keyString; private ConfigEntry<bool>? toggleMode; private KeyCode key = (KeyCode)104; public bool effectActive = false; private MonoBehaviour? playerAvatar; private object? playerVoice; private MethodInfo? overridePitchMethod; private MethodInfo? overridePupilMethod; private MonoBehaviour? playerController; private float searchTimer = 0f; private void Awake() { //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Expected O, but got Unknown //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Expected O, but got Unknown //IL_00a3: Unknown result type (might be due to invalid IL or missing references) Instance = this; keyString = ((BaseUnityPlugin)this).Config.Bind<string>("Controls", "ActivationKey", "H", new ConfigDescription("Tasto per attivare la clessidra", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[4] { "H", "V", "X", "Z" }), Array.Empty<object>())); toggleMode = ((BaseUnityPlugin)this).Config.Bind<bool>("Controls", "ToggleMode", true, "True = toggle, False = hold"); if (!Enum.TryParse<KeyCode>(keyString.Value, ignoreCase: true, out key)) { key = (KeyCode)104; } Harmony val = new Harmony("com.seal.togglehourglass"); val.PatchAll(typeof(EyesPatch)); val.PatchAll(typeof(PlayerAvatarPatch)); ((BaseUnityPlugin)this).Logger.LogInfo((object)"╔═══════════════════════════════════════╗"); ((BaseUnityPlugin)this).Logger.LogInfo((object)"║ HOURGLASS v1.4.0 FIXED ║"); ((BaseUnityPlugin)this).Logger.LogInfo((object)"╚═══════════════════════════════════════╝"); } private void Update() { //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)playerAvatar == (Object)null || (Object)(object)playerController == (Object)null) { searchTimer += Time.deltaTime; if (searchTimer >= 1f) { searchTimer = 0f; if ((Object)(object)playerAvatar == (Object)null) { FindPlayerAvatar(); } if ((Object)(object)playerController == (Object)null) { FindPlayerController(); } } return; } if (playerVoice == null) { FindPlayerVoice(); } bool flag = effectActive; ConfigEntry<bool>? obj = toggleMode; if (obj != null && obj.Value) { if (Input.GetKeyDown(key)) { effectActive = !effectActive; ((BaseUnityPlugin)this).Logger.LogInfo((object)("\ud83c\udfaf Toggle: " + (effectActive ? "ON" : "OFF"))); } } else { effectActive = Input.GetKey(key); } if (flag != effectActive && SemiFunc.IsMultiplayer()) { MonoBehaviour? obj2 = playerAvatar; HourglassSynchronizer hourglassSynchronizer = ((obj2 != null) ? ((Component)obj2).GetComponent<HourglassSynchronizer>() : null); if ((Object)(object)hourglassSynchronizer != (Object)null) { hourglassSynchronizer.SyncVoicePitch(effectActive); } } if (effectActive) { ApplyEffects(); } } private void FindPlayerAvatar() { try { Type type = Type.GetType("PlayerAvatar, Assembly-CSharp"); if (type != null) { PropertyInfo property = type.GetProperty("instance", BindingFlags.Static | BindingFlags.Public); if (property != null) { ref MonoBehaviour? reference = ref playerAvatar; object? value = property.GetValue(null); reference = (MonoBehaviour?)((value is MonoBehaviour) ? value : null); if ((Object)(object)playerAvatar != (Object)null) { ((BaseUnityPlugin)this).Logger.LogInfo((object)"✅ PlayerAvatar.instance trovato"); FindPlayerVoice(); FindPupilMethod(); return; } } } MonoBehaviour[] array = Object.FindObjectsOfType<MonoBehaviour>(); MonoBehaviour[] array2 = array; foreach (MonoBehaviour val in array2) { if (!((Object)(object)val == (Object)null) && !(((object)val).GetType().Name != "PlayerAvatar")) { FieldInfo field = ((object)val).GetType().GetField("isLocal", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field != null && (bool)field.GetValue(val)) { playerAvatar = val; ((BaseUnityPlugin)this).Logger.LogInfo((object)"✅ PlayerAvatar trovato (manual)"); FindPlayerVoice(); FindPupilMethod(); break; } } } } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)("Errore FindPlayerAvatar: " + ex.Message)); } } private void FindPlayerController() { try { Type type = Type.GetType("PlayerController, Assembly-CSharp"); if (type != null) { PropertyInfo property = type.GetProperty("instance", BindingFlags.Static | BindingFlags.Public); if (property != null) { ref MonoBehaviour? reference = ref playerController; object? value = property.GetValue(null); reference = (MonoBehaviour?)((value is MonoBehaviour) ? value : null); if ((Object)(object)playerController != (Object)null) { ((BaseUnityPlugin)this).Logger.LogInfo((object)"✅ PlayerController.instance trovato"); return; } } } MonoBehaviour[] array = Object.FindObjectsOfType<MonoBehaviour>(); MonoBehaviour[] array2 = array; foreach (MonoBehaviour val in array2) { if ((Object)(object)val != (Object)null && ((object)val).GetType().Name == "PlayerController") { playerController = val; ((BaseUnityPlugin)this).Logger.LogInfo((object)"✅ PlayerController trovato (manual)"); break; } } } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)("Errore FindPlayerController: " + ex.Message)); } } private void FindPlayerVoice() { try { if ((Object)(object)playerAvatar == (Object)null) { return; } FieldInfo field = ((object)playerAvatar).GetType().GetField("voiceChat", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (!(field != null)) { return; } playerVoice = field.GetValue(playerAvatar); if (playerVoice != null) { overridePitchMethod = playerVoice.GetType().GetMethod("OverridePitch", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (overridePitchMethod != null) { ((BaseUnityPlugin)this).Logger.LogInfo((object)"✅ OverridePitch trovato"); } } } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)("Errore FindPlayerVoice: " + ex.Message)); } } private void FindPupilMethod() { try { if (!((Object)(object)playerAvatar == (Object)null)) { overridePupilMethod = ((object)playerAvatar).GetType().GetMethod("OverridePupilSize", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (overridePupilMethod != null) { ((BaseUnityPlugin)this).Logger.LogInfo((object)"✅ OverridePupilSize trovato"); } } } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogError((object)("Errore FindPupilMethod: " + ex.Message)); } } private void ApplyEffects() { if ((Object)(object)PlayerVoiceChat.instance != (Object)null) { PlayerVoiceChat.instance.OverridePitch(0.65f, 1f, 2f, 0.1f, 0f, 0f); } if (overridePupilMethod != null && (Object)(object)playerAvatar != (Object)null) { try { overridePupilMethod.Invoke(playerAvatar, new object[7] { 3f, 4, 1f, 1f, 5f, 0.5f, 0.1f }); } catch { } } try { CameraZoom val = Object.FindObjectOfType<CameraZoom>(); if ((Object)(object)val != (Object)null && (Object)(object)playerAvatar != (Object)null) { MethodInfo method = ((object)val).GetType().GetMethod("OverrideZoomSet", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (method != null) { method.Invoke(val, new object[6] { 50f, 0.1f, 0.5f, 1f, ((Component)playerAvatar).gameObject, 0 }); } } } catch (Exception arg) { ((BaseUnityPlugin)this).Logger.LogError((object)$"[Hourglass] Errore OverrideZoomSet: {arg}"); } if (!((Object)(object)playerController != (Object)null)) { return; } try { Type type = ((object)playerController).GetType(); MethodInfo method2 = type.GetMethod("OverrideSpeed", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (method2 != null) { method2.Invoke(playerController, new object[2] { 0.5f, 0.1f }); } MethodInfo method3 = type.GetMethod("OverrideLookSpeed", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (method3 != null) { method3.Invoke(playerController, new object[4] { 0.5f, 2f, 1f, 0.1f }); } MethodInfo method4 = type.GetMethod("OverrideAnimationSpeed", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (method4 != null) { method4.Invoke(playerController, new object[4] { 0.2f, 1f, 2f, 0.1f }); } MethodInfo method5 = type.GetMethod("OverrideTimeScale", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (method5 != null) { method5.Invoke(playerController, new object[2] { 0.1f, 0.1f }); } } catch { } } } [HarmonyPatch] internal class EyesPatch { private static MethodBase? TargetMethod() { return AccessTools.Method("PlayerEyes:Update", (Type[])null, (Type[])null); } private static void Postfix(MonoBehaviour __instance) { if ((Object)(object)ToggleHourglass.Instance == (Object)null) { return; } try { FieldInfo field = ((object)__instance).GetType().GetField("pupilSizeMultiplier", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field != null) { float num = (float)field.GetValue(__instance); float num2 = (ToggleHourglass.Instance.effectActive ? 3f : 1f); float num3 = Mathf.Lerp(num, num2, Time.deltaTime * 2f); field.SetValue(__instance, num3); } } catch { } } } [HarmonyPatch(typeof(PlayerAvatar))] internal class PlayerAvatarPatch { [HarmonyPostfix] [HarmonyPatch("Start")] private static void AddSynchronizer(PlayerAvatar __instance) { if (SemiFunc.IsMultiplayer()) { PhotonView component = ((Component)__instance).GetComponent<PhotonView>(); if (!((Object)(object)component == (Object)null) && (Object)(object)((Component)__instance).GetComponent<HourglassSynchronizer>() == (Object)null) { ((Component)__instance).gameObject.AddComponent<HourglassSynchronizer>(); Debug.Log((object)"✅ HourglassSynchronizer aggiunto"); } } } } }