Please disclose if your mod was created primarily 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 WeskerThumper v0.2.0
BepInEx/plugins/WeskerThumper.dll
Decompiled 4 months 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.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using NewerWeskerThumper; using Unity.Netcode; using UnityEngine; using UnityEngine.Networking; using UnityEngine.SceneManagement; using UnityEngine.Video; using WeskerThumper; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")] [assembly: AssemblyCompany("WeskerThumper")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.1.1.0")] [assembly: AssemblyInformationalVersion("0.1.1")] [assembly: AssemblyProduct("NexusRealities-WeskerThumper")] [assembly: AssemblyTitle("WeskerThumper")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.1.1.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.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace NewerWeskerThumper { public class mainmenu { private static AudioClip menuTheme; private static MenuManager mainMenuInstance; public static void Init() { Harmony.CreateAndPatchAll(typeof(mainmenu), (string)null); try { Plugin.MyLogger.LogInfo((object)"Logging custom music..."); ((AsyncOperation)UnityWebRequestMultimedia.GetAudioClip("file://" + Plugin.BuildSoundPath("Ambient/main_menu.ogg"), (AudioType)14).SendWebRequest()).completed += MainMenuMusic; } catch (Exception ex) { Plugin.MyLogger.LogInfo((object)("Error: " + ex.Message)); } } private static void MainMenuMusic(AsyncOperation operation) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) Plugin.MyLogger.LogInfo((object)"Attempt to patch in custom music"); menuTheme = DownloadHandlerAudioClip.GetContent(((UnityWebRequestAsyncOperation)operation).webRequest); Plugin.MyLogger.LogInfo((object)("Patching custom music " + (object)menuTheme)); if ((Object)(object)mainMenuInstance != (Object)null) { PatchMenuManager(mainMenuInstance); } Debug.Log((object)"Main menu music loaded!"); } private static void PatchMenuManager(MenuManager instance) { mainMenuInstance = instance; instance.menuMusic = menuTheme; if (!instance.isInitScene) { instance.MenuAudio = ((Component)instance).gameObject.AddComponent<AudioSource>(); instance.MenuAudio.volume = 0.3f; instance.MenuAudio.loop = true; instance.MenuAudio.spatialize = false; instance.MenuAudio.spatialBlend = 0f; instance.MenuAudio.clip = menuTheme; instance.MenuAudio.Play(); } } [HarmonyPatch(typeof(MenuManager), "Start")] [HarmonyPostfix] private static void Postfix_MenuManagerStart(MenuManager __instance) { PatchMenuManager(__instance); } } [BepInPlugin("WeskerThumper", "NexusRealities-WeskerThumper", "0.1.1")] public class Plugin : BaseUnityPlugin { public static ManualLogSource MyLogger = null; private static string AssemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); public static AssetBundle Assets { get; protected set; } private void Awake() { ((BaseUnityPlugin)this).Logger.LogInfo((object)("Loading assets : " + Path.Combine(AssemblyPath, "modassets"))); Assets = AssetBundle.LoadFromFile(Path.Combine(AssemblyPath, "modassets")); MyLogger = ((BaseUnityPlugin)this).Logger; mainmenu.Init(); LocalPlayer.Precache(); tv.Init(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin NexusRealities-WeskerThumper is loaded!"); SceneManager.sceneLoaded += OnSceneLoaded; } private void OnSceneLoaded(Scene scene, LoadSceneMode mode) { if ((Object)(object)LocalPlayer.Instance == (Object)null) { ((BaseUnityPlugin)this).Logger.LogInfo((object)"Creating local player..."); LocalPlayer.Init(); } } public static string BuildSoundPath(string path) { string text = Paths.PluginPath + "/NexusRealities-WeskerThumper/SFX/" + path; MyLogger.LogInfo((object)text); return text; } public static string BuildTVPath(string path) { string text = Paths.PluginPath + "/NexusRealities-WeskerThumper/TV/" + path + ".mp4"; MyLogger.LogInfo((object)("Video: " + text)); return text; } } public class TvCustomizer : MonoBehaviour { private static string[] videoslist = new string[25] { "ash_baby_1020", "baby_804", "blue_1305", "burp_1116", "caine_1609", "cat_800", "cat_815", "chug_810", "come_here_for_a_sec_219", "disease_circus_6812", "elephant_1308", "fnaf_1519", "foreshadowing_1013", "frog_1000", "gaster_315", "god_dam_820", "hydraulic_215", "l4d2_spitting_bitch_1208", "magnetic_506", "md_1119", "now_that_is_how_its_done_1001", "playing_1517", "rihanna_2401", "seal_1314", "snort_212" }; private static float[] videosTimelist = new float[25] { 10.2f, 8.04f, 13.05f, 11.16f, 16.09f, 8f, 8.15f, 8.1f, 2.19f, 68.12f, 13.08f, 15.19f, 10.13f, 10f, 3.15f, 8.2f, 2.15f, 12.08f, 5.06f, 11.19f, 10.01f, 15.17f, 24.01f, 13.14f, 2.12f }; private static string[] oldVideoslist = new string[25] { "gulp", "nooo", "cat", "p", "chicken", "dance", "horse", "sus_rage_cat", "fang", "fart", "coach", "wizardsinarbys", "markiplier", "catter", "heavy", "what_day_is_it", "iron", "hero", "fnaf", "bird", "oiiaoiia", "baby", "ceiling", "car", "ee" }; private static VideoClip[] _videoClips = (VideoClip[])(object)new VideoClip[videoslist.Length]; protected VideoPlayer[] videoPlayers = (VideoPlayer[])(object)new VideoPlayer[videoslist.Length]; protected AudioSource[] audioClips = (AudioSource[])(object)new AudioSource[videoslist.Length]; protected int lastPlayedClip; private bool _on; private Random _random; private float _nextplay; public static void Precache() { if (videosTimelist.Length != videoslist.Length) { throw new Exception("Videos time list length doesn't match videos list"); } for (int i = 0; i < videoslist.Length; i++) { string text = "Assets/New_Clips/" + videoslist[i] + ".mov"; _videoClips[i] = Plugin.Assets.LoadAsset<VideoClip>(text); if ((Object)(object)_videoClips[i] == (Object)null) { Plugin.MyLogger.LogError((object)("Failed to load : " + text)); } } } public void Start() { //IL_016b: Unknown result type (might be due to invalid IL or missing references) _on = false; TVScript component = ((Component)this).gameObject.GetComponent<TVScript>(); for (int i = 0; i < _videoClips.Length; i++) { VideoPlayer val = ((Component)this).gameObject.AddComponent<VideoPlayer>(); val.clip = _videoClips[i]; val.source = (VideoSource)0; val.controlledAudioTrackCount = 1; val.audioOutputMode = (VideoAudioOutputMode)1; val.isLooping = component.video.isLooping; AudioSource val2 = ((Component)this).gameObject.AddComponent<AudioSource>(); val2.outputAudioMixerGroup = component.tvSFX.outputAudioMixerGroup; val2.mute = component.tvSFX.mute; val2.spatialize = component.tvSFX.spatialize; val2.spatializePostEffects = component.tvSFX.spatializePostEffects; val2.bypassEffects = component.tvSFX.bypassEffects; val2.bypassListenerEffects = component.tvSFX.bypassListenerEffects; val2.bypassReverbZones = component.tvSFX.bypassReverbZones; val2.playOnAwake = component.tvSFX.playOnAwake; val2.loop = component.tvSFX.loop; val2.priority = component.tvSFX.priority; val2.volume = component.tvSFX.volume; val2.pitch = component.tvSFX.pitch; val2.panStereo = component.tvSFX.panStereo; val2.spatialBlend = component.tvSFX.spatialBlend; val2.reverbZoneMix = component.tvSFX.reverbZoneMix; val2.rolloffMode = component.tvSFX.rolloffMode; val2.spread = component.tvSFX.spread; val2.dopplerLevel = component.tvSFX.dopplerLevel; val2.minDistance = component.tvSFX.minDistance; val2.maxDistance = component.tvSFX.maxDistance; val.SetTargetAudioSource((ushort)0, val2); val.Stop(); val.Prepare(); val.Pause(); videoPlayers[i] = val; audioClips[i] = val2; Plugin.MyLogger.LogInfo((object)("E " + ((object)videoPlayers[i])?.ToString() + " " + (object)audioClips[i])); } } public void TurnOn(Random random) { _on = true; _random = random; _nextplay = Time.time; } public void TurnOff() { _on = false; _random = null; _StopClip(); } public void Update() { if (_on && _random != null && _nextplay <= Time.time) { _PlayClip(_random.Next() % videoslist.Length); _nextplay += videosTimelist[lastPlayedClip]; } } private void _PlayClip(int index) { _StopClip(); lastPlayedClip = index; TVScript component = ((Component)this).gameObject.GetComponent<TVScript>(); VideoPlayer obj = videoPlayers[index]; obj.Play(); obj.targetTexture = component.video.targetTexture; obj.targetMaterialRenderer = component.video.targetMaterialRenderer; obj.targetCameraAlpha = component.video.targetCameraAlpha; obj.targetCamera = component.video.targetCamera; SetTVScreenMaterial(component, b: true); component.tvSFX.PlayOneShot(component.switchTVOn); } private void _StopClip() { TVScript component = ((Component)this).gameObject.GetComponent<TVScript>(); for (int i = 1; i <= 2; i++) { VideoPlayer obj = videoPlayers[lastPlayedClip]; obj.Pause(); obj.time = 0.0; obj.frame = 0L; obj.time = 0.0; obj.targetTexture = null; obj.targetMaterialRenderer = null; obj.targetCamera = null; AudioSource obj2 = audioClips[lastPlayedClip]; obj2.Stop(true); obj2.Stop(); obj2.time = 0f; } component.tvSFX.Stop(); SetTVScreenMaterial(component, b: false); component.tvSFX.PlayOneShot(component.switchTVOff); } public static int PlayRandomClip() { return Random.Range(0, videoslist.Length); } protected static void SetTVScreenMaterial(TVScript instance, bool b) { ((object)instance).GetType().GetMethod("SetTVScreenMaterial", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(instance, new object[1] { b }); } } public class tv { public static void Init() { TvCustomizer.Precache(); Harmony.CreateAndPatchAll(typeof(tv), (string)null); } [HarmonyPatch(typeof(TVScript), "Update")] [HarmonyPrefix] public static bool Update(TVScript __instance) { if ((Object)(object)((Component)__instance).gameObject.GetComponent<TvCustomizer>() == (Object)null) { ((Component)__instance).gameObject.AddComponent<TvCustomizer>(); } return false; } [HarmonyPatch(typeof(TVScript), "TVFinishedClip")] [HarmonyPrefix] public static bool TVFinishedClip(VideoPlayer source) { return false; } [HarmonyPatch(typeof(TVScript), "TurnOnTVServerRpc")] [HarmonyPrefix] public static bool TurnOnTVServerRpc(TVScript __instance, ref int ___currentClip, ref float ___timeSinceTurningOffTV, int _____rpc_exec_stage) { if (_____rpc_exec_stage != 1 || (!((NetworkBehaviour)__instance).NetworkManager.IsServer && !((NetworkBehaviour)__instance).NetworkManager.IsHost)) { return true; } Plugin.MyLogger.LogInfo((object)("Clip state: " + _____rpc_exec_stage)); ___timeSinceTurningOffTV = 9999f; int num = Random.Range(0, 1294967295); ___currentClip = num; __instance.TurnOnTVAndSyncClientRpc(___currentClip, 9999f); return false; } [HarmonyPatch(typeof(TVScript), "TurnTVOnOff")] [HarmonyPrefix] public static bool TurnTVOnOff(bool on, TVScript __instance, int ___currentClip) { __instance.tvOn = on; TvCustomizer component = ((Component)__instance).gameObject.GetComponent<TvCustomizer>(); if (on) { Plugin.MyLogger.LogInfo((object)"Turning on TV"); Random random = new Random(___currentClip); component.TurnOn(random); WalkieTalkie.TransmitOneShotAudio(__instance.tvSFX, __instance.switchTVOn, 1f); } else { Plugin.MyLogger.LogInfo((object)"Turning off TV"); component.TurnOff(); WalkieTalkie.TransmitOneShotAudio(__instance.tvSFX, __instance.switchTVOff, 1f); } return false; } } public static class MyPluginInfo { public const string PLUGIN_GUID = "WeskerThumper"; public const string PLUGIN_NAME = "NexusRealities-WeskerThumper"; public const string PLUGIN_VERSION = "0.1.1"; } } namespace WeskerThumper { public static class CrawlerPatcher { private static Dictionary<UnityWebRequestAsyncOperation, int> requests = new Dictionary<UnityWebRequestAsyncOperation, int>(); public static AudioClip[] weskerSpotted = (AudioClip[])(object)new AudioClip[3]; public static AudioClip[] weskerBash = (AudioClip[])(object)new AudioClip[1]; public static void Init() { Harmony.CreateAndPatchAll(typeof(CrawlerPatcher), (string)null); for (int i = 0; i < 3; i++) { UnityWebRequestAsyncOperation val = UnityWebRequestMultimedia.GetAudioClip("file://" + Plugin.BuildSoundPath("Thumper/spotted_" + (i + 1) + ".ogg"), (AudioType)14).SendWebRequest(); requests[val] = i; ((AsyncOperation)val).completed += ThumperSpotted; } ((AsyncOperation)UnityWebRequestMultimedia.GetAudioClip("file://" + Plugin.BuildSoundPath("Thumper/bash.ogg"), (AudioType)14).SendWebRequest()).completed += ThumperBash; } private static void ThumperSpotted(AsyncOperation operation) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown UnityWebRequestAsyncOperation val = (UnityWebRequestAsyncOperation)operation; weskerSpotted[requests[val]] = DownloadHandlerAudioClip.GetContent(val.webRequest); Debug.Log((object)("Sppotted file (" + requests[val] + ") loaded!")); } private static void ThumperBash(AsyncOperation operation) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown UnityWebRequestAsyncOperation val = (UnityWebRequestAsyncOperation)operation; weskerBash[0] = DownloadHandlerAudioClip.GetContent(val.webRequest); Debug.Log((object)"Bash file loaded!"); } [HarmonyPatch(typeof(CrawlerAI), "CollideWithWallClientRpc")] [HarmonyPostfix] private static void Postfix_CollideWithWallClientRpc(CrawlerAI __instance) { RoundManager.PlayRandomClip(((EnemyAI)__instance).creatureVoice, weskerBash, true, 2f, 0, 1000); } [HarmonyPatch(typeof(CrawlerAI), "Start")] [HarmonyPostfix] private static void Postfix_Start(CrawlerAI __instance) { __instance.longRoarSFX = weskerSpotted; ((EnemyAI)__instance).creatureVoice.volume = 2f; } [HarmonyPatch(typeof(CrawlerAI), "MakeScreech")] [HarmonyPrefix] private static void Prefix_MakeScreech(CrawlerAI __instance) { ((EnemyAI)__instance).creatureVoice.volume = 2f; } [HarmonyPatch(typeof(CrawlerAI), "Update")] [HarmonyPostfix] private static void Postfix_Update(CrawlerAI __instance) { //IL_008b: 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) if (((EnemyAI)__instance).isEnemyDead) { return; } Type typeFromHandle = typeof(CrawlerAI); if ((bool)typeFromHandle.InvokeMember("hasEnteredChaseMode", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField, null, __instance, null) && !(bool)typeFromHandle.InvokeMember("lostPlayerInChase", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField, null, __instance, null)) { if ((Object)(object)((EnemyAI)__instance).targetPlayer == (Object)(object)GameNetworkManager.Instance.localPlayerController) { LocalPlayer.Instance.UpdateChase(EnemyType.Thumper); } else if ((double)Vector3.Distance(((Component)GameNetworkManager.Instance.localPlayerController.gameplayCamera).gameObject.transform.position, ((EnemyAI)__instance).eye.position) <= 200.0) { LocalPlayer.Instance.UpdateChase(EnemyType.Thumper); } } } } public enum EnemyType : uint { Thumper, Max } public class LocalPlayer : MonoBehaviour { public static LocalPlayer Instance = null; public AudioSource chaseAudio; private float[] lastChaseTime = new float[1]; private static AudioClip[] chaseMusic = (AudioClip[])(object)new AudioClip[1]; public static void Init() { //IL_0018: Unknown result type (might be due to invalid IL or missing references) new GameObject("LocalPlayer", new Type[1] { typeof(LocalPlayer) }).GetComponent<LocalPlayer>(); } public static void Precache() { ((AsyncOperation)UnityWebRequestMultimedia.GetAudioClip("file://" + Plugin.BuildSoundPath("Thumper/chase.ogg"), (AudioType)14).SendWebRequest()).completed += ThumperChase; } private static void ThumperChase(AsyncOperation operation) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) chaseMusic[0] = DownloadHandlerAudioClip.GetContent(((UnityWebRequestAsyncOperation)operation).webRequest); Debug.Log((object)"Thumper music loaded!"); } public virtual void Start() { if ((Object)(object)Instance != (Object)null) { Object.Destroy((Object)(object)((Component)Instance).gameObject); } Instance = this; chaseAudio = ((Component)this).gameObject.AddComponent<AudioSource>(); chaseAudio.loop = true; chaseAudio.spatialBlend = 0f; chaseAudio.spatialize = false; chaseAudio.volume = 0f; Object.DontDestroyOnLoad((Object)(object)this); Debug.Log((object)"Local player instantiated!"); } public void UpdateChase(EnemyType type) { lastChaseTime[(uint)type] = Time.time; } public virtual void Update() { float time = Time.time; if ((double)time <= 1.0) { return; } if ((double)(time - lastChaseTime[0]) <= 1.0) { if (!chaseAudio.isPlaying) { chaseAudio.clip = chaseMusic[0]; chaseAudio.volume = 0.1f; chaseAudio.Play(); } else if (chaseAudio.volume < 0.6f) { AudioSource obj = chaseAudio; obj.volume += 0.2f * Time.deltaTime; if (chaseAudio.volume > 0.6f) { chaseAudio.volume = 0.6f; } } } else if (chaseAudio.isPlaying && (double)chaseAudio.volume > 0.0) { AudioSource obj2 = chaseAudio; obj2.volume -= 0.2f * Time.deltaTime; if (chaseAudio.volume < 0f) { chaseAudio.volume = 0f; chaseAudio.Stop(); } } } } }