using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
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("YonDev.GhostMod4Lins")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3+4a04c2a25b94ce1b89426d605d26b0e58893202f")]
[assembly: AssemblyProduct("Ghost4Lins")]
[assembly: AssemblyTitle("YonDev.GhostMod4Lins")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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 GhostMod4Lins
{
[BepInPlugin("YonDev.GhostMod4Lins", "Ghost4Lins", "1.0.3")]
public class GhostMod : BaseUnityPlugin
{
[HarmonyPatch]
private static class Patches
{
[HarmonyPatch(typeof(PlayerGhost), "RPCA_InitGhost")]
[HarmonyPostfix]
private static void PlayerGhostPatch(PlayerGhost __instance)
{
if (hiddenGhosts.Contains(((MonoBehaviourPun)__instance.m_owner).photonView.OwnerActorNr))
{
ApplyVisibilitySettings(__instance, visible: false);
ApplySoundSettings(__instance, mute: true);
}
else
{
ApplyVisibilitySettings(__instance, GhostVisiblity.Value);
ApplySoundSettings(__instance, GhostMute.Value);
}
}
[HarmonyPatch(typeof(AudioLevelSlider), "Init")]
[HarmonyPostfix]
private static void AudioLevel_Init_Patch(AudioLevelSlider __instance)
{
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Expected O, but got Unknown
//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
//IL_0160: Unknown result type (might be due to invalid IL or missing references)
//IL_016a: Expected O, but got Unknown
if ((Object)(object)__instance == (Object)null || __instance.player == PhotonNetwork.LocalPlayer)
{
return;
}
Transform transform = ((Component)__instance).transform;
Transform val = ((transform != null) ? transform.Find("PlayerUI") : null);
if ((Object)(object)val == (Object)null)
{
return;
}
Transform val2 = val;
if ((Object)(object)val2.Find("CustomButton") != (Object)null || (Object)(object)val2.parent.Find("CustomButton") != (Object)null)
{
return;
}
Player player = __instance.player;
if (player == null)
{
return;
}
GameObject val3 = new GameObject("CustomButton");
val3.transform.SetParent(val2, false);
val3.transform.localScale = new Vector3(0.75f, 0.75f, 1f);
RectTransform val4 = val3.AddComponent<RectTransform>();
val4.anchoredPosition = new Vector2(-90f, 77.5f);
Image val5 = val3.AddComponent<Image>();
val5.sprite = LoadSprite();
Button val6 = val3.AddComponent<Button>();
((Selectable)val6).targetGraphic = (Graphic)(object)val5;
val3.transform.SetSiblingIndex(((Component)val2).transform.GetSiblingIndex() + 1);
log("Added it!");
((UnityEvent)val6.onClick).AddListener((UnityAction)delegate
{
Character val7 = null;
foreach (Character allCharacter in Character.AllCharacters)
{
if (((MonoBehaviourPun)allCharacter).photonView.Owner.ActorNumber == player.ActorNumber)
{
val7 = allCharacter;
break;
}
}
if (!((Object)(object)((val7 != null) ? val7.Ghost : null) == (Object)null))
{
int actorNumber = player.ActorNumber;
if (!hiddenGhosts.Contains(player.ActorNumber))
{
hiddenGhosts.Add(actorNumber);
}
else
{
hiddenGhosts.Remove(actorNumber);
}
bool flag = hiddenGhosts.Contains(actorNumber);
ApplyVisibilitySettings(val7.Ghost, !flag);
ApplySoundSettings(val7.Ghost, flag);
Notification(player.NickName + "'s ghost is now " + ((!flag) ? "visible" : "hidden"), "00FFFF", sound: true);
}
});
}
}
public static readonly Dictionary<int, float> ghostVolumes = new Dictionary<int, float>();
public static readonly List<int> hiddenGhosts = new List<int>();
public static ConfigEntry<KeyCode> VisibilityToggle;
public static ConfigEntry<KeyCode> MuteToggle;
public static ConfigEntry<bool> GhostVisiblity;
public static ConfigEntry<bool> GhostMute;
internal static ManualLogSource Logger;
private readonly Harmony harmony = new Harmony("YonDev.GhostMod4Lins");
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
Binds(((BaseUnityPlugin)this).Config);
Logger.LogInfo((object)"GhostMod4Lins v1.0.3 is loaded!");
harmony.PatchAll();
}
private void OnDestroy()
{
harmony.UnpatchSelf();
}
private static void Binds(ConfigFile config)
{
VisibilityToggle = config.Bind<KeyCode>("Ghosts", "Visible Key", (KeyCode)44, "Key to toggle the ghosts' visibility on/off.");
MuteToggle = config.Bind<KeyCode>("Ghosts", "Mute Key", (KeyCode)109, "Key to toggle the ghosts' mute on/off.");
GhostVisiblity = config.Bind<bool>("Ghosts", "Visible", true, "Toggle the ghosts' visibility on/off.");
GhostMute = config.Bind<bool>("Ghosts", "Mute", true, "Toggle the ghosts' mute on/off.");
GhostMute.Value = false;
GhostVisiblity.Value = true;
GhostVisiblity.SettingChanged += delegate
{
Notification("Ghost Visibility is " + (GhostVisiblity.Value ? "ON" : "OFF"));
ApplyGhostSettingsToAllCharacters();
};
GhostMute.SettingChanged += delegate
{
Notification("Ghost Mute is " + (GhostMute.Value ? "ON" : "OFF"));
ApplyGhostSettingsToAllCharacters();
};
}
private void Update()
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)GUIManager.instance != (Object)null) || !GUIManager.instance.windowBlockingInput)
{
if (Input.GetKeyDown(VisibilityToggle.Value))
{
GhostVisiblity.Value = !GhostVisiblity.Value;
}
if (Input.GetKeyDown(MuteToggle.Value))
{
GhostMute.Value = !GhostMute.Value;
}
}
}
private static void ApplyGhostSettingsToAllCharacters()
{
bool value = GhostVisiblity.Value;
bool value2 = GhostMute.Value;
foreach (Character allCharacter in Character.AllCharacters)
{
if (!hiddenGhosts.Contains(((MonoBehaviourPun)allCharacter).photonView.OwnerActorNr) && (Object)(object)allCharacter.Ghost != (Object)null)
{
ApplyVisibilitySettings(allCharacter.Ghost, value);
ApplySoundSettings(allCharacter.Ghost, value2);
}
}
}
private static void ApplyVisibilitySettings(PlayerGhost ghost, bool visible)
{
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Expected O, but got Unknown
if ((Object)(object)ghost.m_owner != (Object)null && ghost.m_owner.IsLocal)
{
return;
}
foreach (Transform item in ((Component)ghost).transform)
{
Transform val = item;
((Component)val).gameObject.SetActive(visible);
}
ManualLogSource logger = Logger;
Character owner = ghost.m_owner;
logger.LogDebug((object)$"Ghost '{((owner != null) ? owner.characterName : null)}' visibility set to {visible}.");
}
private static void ApplySoundSettings(PlayerGhost ghost, bool mute)
{
if ((Object)(object)ghost.m_owner == (Object)null || ghost.m_owner.IsLocal)
{
return;
}
AnimatedMouth animatedMouth = ghost.animatedMouth;
CharacterVoiceHandler val = ((animatedMouth != null) ? animatedMouth.VoiceHandler : null);
if ((Object)(object)val == (Object)null)
{
Logger.LogWarning((object)("Could not find AnimatedMouth or AudioSource for ghost of " + ghost.m_owner.characterName + "."));
return;
}
int ownerActorNr = ((MonoBehaviourPun)ghost.m_owner).photonView.OwnerActorNr;
if (!ghostVolumes.ContainsKey(ownerActorNr))
{
ghostVolumes.Add(ownerActorNr, val.audioLevel);
}
if (mute)
{
ghostVolumes[ownerActorNr] = val.audioLevel;
val.audioLevel = 0f;
}
else
{
val.audioLevel = ghostVolumes[ownerActorNr];
}
Logger.LogDebug((object)$"Ghost '{ghost.m_owner.characterName}' audio muted: {mute}.");
}
private static Sprite LoadSprite()
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Expected O, but got Unknown
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
Assembly executingAssembly = Assembly.GetExecutingAssembly();
using Stream stream = executingAssembly.GetManifestResourceStream("GhostMod4Lins.ghost.png");
byte[] array = new byte[stream.Length];
stream.Read(array, 0, array.Length);
Texture2D val = new Texture2D(2, 2);
ImageConversion.LoadImage(val, array);
val.Apply();
return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
}
public static void Notification(string message, string color = "FFFFFF", bool sound = false)
{
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
PlayerConnectionLog val = Object.FindAnyObjectByType<PlayerConnectionLog>();
if ((Object)(object)val == (Object)null)
{
return;
}
string text = "<color=#" + color + ">" + message + "</color>";
MethodInfo method = typeof(PlayerConnectionLog).GetMethod("AddMessage", BindingFlags.Instance | BindingFlags.NonPublic);
if (method != null)
{
method.Invoke(val, new object[1] { text });
if ((Object)(object)val.sfxJoin != (Object)null && sound)
{
val.sfxJoin.Play(default(Vector3));
}
}
else
{
Logger.LogMessage((object)"AddMessage method not found.");
}
}
public static void log(string c)
{
Logger.LogInfo((object)c);
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "YonDev.GhostMod4Lins";
public const string PLUGIN_NAME = "Ghost4Lins";
public const string PLUGIN_VERSION = "1.0.3";
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}