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 YouDidThisSam v1.0.0
YouDidThisSam/PlayerLister.dll
Decompiled 2 weeks agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("PlayerLister")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("PlayerLister")] [assembly: AssemblyTitle("PlayerLister")] [assembly: AssemblyVersion("1.0.0.0")] [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 PlayerLister { public class PicturePlayer : MonoBehaviour { public string ImagePath; public string AudioPath; public float Volume = 0.6f; public RawImage Target; public Action OnDone; public Action OnFail; private const float MaxWidth = 960f; private const float MaxHeight = 720f; private Texture2D _tex; private float _start; private float _length; private bool _done; private void Start() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Expected O, but got Unknown //IL_00d4: Unknown result type (might be due to invalid IL or missing references) try { _tex = new Texture2D(2, 2, (TextureFormat)4, false); if (!LoadImageBytes(_tex, File.ReadAllBytes(ImagePath))) { Fail("could not read image " + ImagePath); return; } AudioClip val = LoadWav(AudioPath); if ((Object)(object)val == (Object)null) { Fail("could not read audio (need 16-bit PCM .wav): " + AudioPath); return; } float num = Mathf.Min(960f / (float)((Texture)_tex).width, 720f / (float)((Texture)_tex).height); Target.texture = (Texture)(object)_tex; ((Graphic)Target).rectTransform.sizeDelta = new Vector2((float)((Texture)_tex).width * num, (float)((Texture)_tex).height * num); AudioSource obj = ((Component)this).gameObject.AddComponent<AudioSource>(); obj.spatialBlend = 0f; obj.volume = Volume; obj.clip = val; obj.Play(); _length = val.length; _start = Time.unscaledTime; PrankVideo.Log.LogInfo((object)$"PicturePlayer: showing {((Texture)_tex).width}x{((Texture)_tex).height} picture for {_length:F1}s"); } catch (Exception ex) { Fail(ex.ToString()); } } private void Update() { if (!_done && Time.unscaledTime - _start >= _length) { _done = true; OnDone?.Invoke(); } } private void OnDestroy() { if ((Object)(object)_tex != (Object)null) { Object.Destroy((Object)(object)_tex); } } private void Fail(string msg) { _done = true; PrankVideo.Log.LogError((object)("PicturePlayer failed: " + msg + " (not killing player).")); OnFail?.Invoke(); } private static bool LoadImageBytes(Texture2D tex, byte[] data) { MethodInfo method = typeof(ImageConversion).GetMethod("LoadImage", new Type[2] { typeof(Texture2D), typeof(byte[]) }); if (method != null) { return (bool)method.Invoke(null, new object[2] { tex, data }); } return false; } private static void SetClipData(AudioClip clip, float[] data) { typeof(AudioClip).GetMethod("SetData", new Type[2] { typeof(float[]), typeof(int) }).Invoke(clip, new object[2] { data, 0 }); } private static AudioClip LoadWav(string path) { byte[] array = File.ReadAllBytes(path); int i = 12; int num = 2; int num2 = 44100; int num3 = 16; int num4 = -1; int num5 = 0; int num6; for (; i + 8 <= array.Length; i += 8 + num6 + (num6 & 1)) { string text = Encoding.ASCII.GetString(array, i, 4); num6 = BitConverter.ToInt32(array, i + 4); if (text == "fmt ") { num = BitConverter.ToInt16(array, i + 10); num2 = BitConverter.ToInt32(array, i + 12); num3 = BitConverter.ToInt16(array, i + 22); } else if (text == "data") { num4 = i + 8; if (num6 < 0 || num6 > array.Length - num4) { num6 = array.Length - num4; } num5 = num6; break; } } if (num4 < 0 || num3 != 16 || num < 1) { return null; } int num7 = num5 / 2; float[] array2 = new float[num7]; for (int j = 0; j < num7; j++) { array2[j] = (float)BitConverter.ToInt16(array, num4 + j * 2) / 32768f; } AudioClip obj = AudioClip.Create("prank_audio", num7 / num, num, num2, false); SetClipData(obj, array2); return obj; } } [BepInPlugin("you.playerlister", "Player Lister", "1.0.0")] public class PlayerListerPlugin : BaseUnityPlugin { private ConfigEntry<KeyCode> _listKey; private void Awake() { PrankVideo.Init((BaseUnityPlugin)(object)this); _listKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "ListKey", (KeyCode)288, "Key that lists all players currently on the server."); } private void Update() { //IL_000b: Unknown result type (might be due to invalid IL or missing references) PrankVideo.HandleInput(); if (Input.GetKeyDown(_listKey.Value) && (!((Object)(object)Chat.instance != (Object)null) || !Chat.instance.HasFocus()) && !Console.IsVisible()) { ListPlayers(); } } private void ListPlayers() { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)ZNet.instance == (Object)null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"Not connected to a world yet."); return; } List<PlayerInfo> playerList = ZNet.instance.GetPlayerList(); List<string> list = new List<string>(); foreach (PlayerInfo item in playerList) { list.Add(item.m_name); } string text = $"Players online ({list.Count}):"; string text2 = ((list.Count > 0) ? string.Join(", ", list) : "(none)"); ((BaseUnityPlugin)this).Logger.LogInfo((object)(text + " " + text2)); if ((Object)(object)Console.instance != (Object)null) { Console.instance.Print(text); foreach (string item2 in list) { Console.instance.Print(" " + item2); } } if ((Object)(object)Player.m_localPlayer != (Object)null) { ((Character)Player.m_localPlayer).Message((MessageType)1, text + "\n" + string.Join("\n", list), 0, (Sprite)null, false); } } } public static class PrankVideo { [HarmonyPatch(typeof(Player), "StartEmote")] private static class EmotePatch { private static void Postfix(Player __instance, string emote) { if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer)) { Log.LogInfo((object)("Emote started: " + emote)); if (string.Equals(emote, _emoteName.Value, StringComparison.OrdinalIgnoreCase)) { OnEmote(); } } } } [HarmonyPatch(typeof(Game), "Start")] private static class RegisterRpcPatch { private static void Postfix() { if (ZRoutedRpc.instance != null) { ZRoutedRpc.instance.Register<string>("PlayerLister_Prank", (Action<long, string>)RPC_Prank); } } } private const string RpcName = "PlayerLister_Prank"; internal static readonly ManualLogSource Log = Logger.CreateLogSource("PrankVideo"); private static BaseUnityPlugin _plugin; private static ConfigEntry<KeyCode> _fireKey; private static ConfigEntry<string> _targetName; private static ConfigEntry<bool> _acceptPranks; private static ConfigEntry<string> _imageFile; private static ConfigEntry<string> _audioFile; private static ConfigEntry<float> _volume; private static ConfigEntry<string> _emoteName; private static ConfigEntry<float> _emoteCooldown; private static float _lastEmoteFire = -999f; private static GameObject _window; public static void Init(BaseUnityPlugin plugin) { //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Expected O, but got Unknown //IL_014f: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) _plugin = plugin; Log.LogInfo((object)"PrankVideo loaded (build marker 7: emote -> TargetName)"); _fireKey = plugin.Config.Bind<KeyCode>("Prank", "TestKey", (KeyCode)289, "Test hotkey: fires the prank at TargetName (the item will call the same code)."); _targetName = plugin.Config.Bind<string>("Prank", "TargetName", "", "In-game name of the player to prank (used by the test hotkey and the emote)."); _acceptPranks = plugin.Config.Bind<bool>("Prank", "AcceptPranks", true, "If false, this client ignores incoming pranks (opt-out)."); _imageFile = plugin.Config.Bind<string>("Prank", "ImageFile", "ApplebeesLogo.png", "Picture to show (png or jpg), placed in the same folder as the mod DLL."); _audioFile = plugin.Config.Bind<string>("Prank", "AudioFile", "Applebees.wav", "Audio to play (16-bit PCM .wav), same folder. The picture stays up for its length."); _volume = plugin.Config.Bind<float>("Prank", "Volume", 0.6f, new ConfigDescription("Audio volume (0 to 1).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>())); _emoteName = plugin.Config.Bind<string>("Emote", "EmoteName", "loveyou", "Emote that triggers the prank on TargetName (the emote's chat command, without the /). Works from the emote wheel and from chat."); _emoteCooldown = plugin.Config.Bind<float>("Emote", "CooldownSeconds", 30f, "Minimum seconds between emote-triggered pranks."); Harmony val = new Harmony("you.playerlister.prank"); val.PatchAll(typeof(RegisterRpcPatch)); val.PatchAll(typeof(EmotePatch)); } public static void HandleInput() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) if (Input.GetKeyDown(_fireKey.Value) && (!((Object)(object)Chat.instance != (Object)null) || !Chat.instance.HasFocus()) && !Console.IsVisible()) { Trigger(_targetName.Value); } } public static bool Trigger(string targetName) { if ((Object)(object)ZNet.instance == (Object)null || ZRoutedRpc.instance == null) { Log.LogWarning((object)"Not connected to a world."); return false; } if (!ZNet.instance.GetPlayerList().Exists((PlayerInfo p) => string.Equals(p.m_name, targetName, StringComparison.OrdinalIgnoreCase))) { Log.LogWarning((object)("No player named '" + targetName + "' is online.")); Player localPlayer = Player.m_localPlayer; if (localPlayer != null) { ((Character)localPlayer).Message((MessageType)1, "No player named '" + targetName + "' online", 0, (Sprite)null, false); } return false; } ZRoutedRpc.instance.InvokeRoutedRPC(0L, "PlayerLister_Prank", new object[1] { targetName }); Log.LogInfo((object)("Prank sent to " + targetName + ".")); return true; } private static void RPC_Prank(long sender, string targetName) { if (_acceptPranks.Value) { Player localPlayer = Player.m_localPlayer; if (!((Object)(object)localPlayer == (Object)null) && !((Character)localPlayer).IsDead() && string.Equals(localPlayer.GetPlayerName(), targetName, StringComparison.OrdinalIgnoreCase) && !((Object)(object)_window != (Object)null)) { Show(); } } } private static void Show() { //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Expected O, but got Unknown //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) string? directoryName = Path.GetDirectoryName(_plugin.Info.Location); string text = Path.Combine(directoryName, _imageFile.Value); string text2 = Path.Combine(directoryName, _audioFile.Value); if (!File.Exists(text) || !File.Exists(text2)) { Log.LogError((object)($"Missing file. Image: {text} (exists={File.Exists(text)}), " + $"audio: {text2} (exists={File.Exists(text2)}). Not killing player.")); return; } _window = new GameObject("PrankWindow"); Canvas obj = _window.AddComponent<Canvas>(); obj.renderMode = (RenderMode)0; obj.sortingOrder = 1000; GameObject val = new GameObject("Picture"); val.transform.SetParent(_window.transform, false); RawImage val2 = val.AddComponent<RawImage>(); RectTransform rectTransform = ((Graphic)val2).rectTransform; Vector2 val3 = default(Vector2); ((Vector2)(ref val3))..ctor(0.5f, 0.5f); rectTransform.pivot = val3; Vector2 anchorMin = (rectTransform.anchorMax = val3); rectTransform.anchorMin = anchorMin; rectTransform.anchoredPosition = Vector2.zero; rectTransform.sizeDelta = new Vector2(960f, 540f); PicturePlayer picturePlayer = _window.AddComponent<PicturePlayer>(); picturePlayer.ImagePath = text; picturePlayer.AudioPath = text2; picturePlayer.Volume = _volume.Value; picturePlayer.Target = val2; picturePlayer.OnDone = delegate { Cleanup(); Kill(); }; picturePlayer.OnFail = Cleanup; } private static void Cleanup() { if ((Object)(object)_window != (Object)null) { Object.Destroy((Object)(object)_window); } _window = null; } private static void Kill() { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Expected O, but got Unknown //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if (!((Object)(object)localPlayer == (Object)null) && !((Character)localPlayer).IsDead()) { HitData val = new HitData(); val.m_damage.m_damage = 99999f; val.m_point = ((Character)localPlayer).GetCenterPoint(); val.m_dir = Vector3.up; ((Character)localPlayer).Damage(val); if (!((Character)localPlayer).IsDead()) { ((Character)localPlayer).SetHealth(0f); } } } private static void OnEmote() { if (!(Time.unscaledTime - _lastEmoteFire < _emoteCooldown.Value)) { if (string.IsNullOrWhiteSpace(_targetName.Value)) { Log.LogWarning((object)"Emote used but TargetName is empty in the config."); } else if (Trigger(_targetName.Value)) { _lastEmoteFire = Time.unscaledTime; } } } } }