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 FredianCustomVideos v0.1.0
FredCustomMod.dll
Decompiled 2 years agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Logging; using HarmonyLib; using UnityEngine; using UnityEngine.Video; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("FredCustomMod")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("FredCustomMod")] [assembly: AssemblyCopyright("Copyright © 2024")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("65b35165-f376-4e73-893a-a78b65ff622a")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.0.0.0")] internal static class VideoManager { private static List<string> shuffledVideos = new List<string>(); private static int currentIndex = 0; public static List<string> Videos = new List<string>(); public static void Load() { Videos = LoadVideos(); shuffledVideos = Shuffle(Videos); } public static string GetNextVideo() { int count = shuffledVideos.Count; if (currentIndex >= count) { shuffledVideos = Shuffle(Videos); currentIndex = 0; } return shuffledVideos[currentIndex++]; } private static List<string> LoadVideos() { List<string> list = new List<string>(); string[] directories = Directory.GetDirectories(Paths.PluginPath); string[] array = directories; foreach (string text in array) { string path = Path.Combine(Paths.PluginPath, text, "Television Videos"); if (Directory.Exists(path)) { string[] files = Directory.GetFiles(path, "*.mp4"); list.AddRange(files); TVLoaderPlugin.Log.LogInfo((object)$"{text} has {files.Length} videos."); } } string path2 = Path.Combine(Paths.PluginPath, "Television Videos"); if (!Directory.Exists(path2)) { Directory.CreateDirectory(path2); } string[] files2 = Directory.GetFiles(path2, "*.mp4"); list.AddRange(files2); TVLoaderPlugin.Log.LogInfo((object)$"Global has {files2.Length} videos."); TVLoaderPlugin.Log.LogInfo((object)$"Loaded {list.Count} total."); return list; } private static List<T> Shuffle<T>(List<T> list) { List<T> list2 = new List<T>(list); int num = list2.Count; while (num > 1) { num--; int index = Random.Range(0, num + 1); T value = list2[index]; list2[index] = list2[num]; list2[num] = value; } return list2; } } [HarmonyPatch(typeof(TVScript))] internal class TVScriptPatches { [Serializable] [CompilerGenerated] private sealed class <>c { public static readonly <>c <>9 = new <>c(); public static EventHandler <>9__13_0; internal void <PrepareVideo>b__13_0(VideoPlayer <p0>) { TVLoaderPlugin.Log.LogInfo((object)"Prepared next video!"); TVLoaderPlugin.Log.LogInfo((object)nextVideoPlayer.url); } } private static FieldInfo currentClipProperty = typeof(TVScript).GetField("currentClip", BindingFlags.Instance | BindingFlags.NonPublic); private static FieldInfo currentTimeProperty = typeof(TVScript).GetField("currentClipTime", BindingFlags.Instance | BindingFlags.NonPublic); private static FieldInfo wasTvOnLastFrameProp = typeof(TVScript).GetField("wasTvOnLastFrame", BindingFlags.Instance | BindingFlags.NonPublic); private static FieldInfo timeSinceTurningOffTVProp = typeof(TVScript).GetField("timeSinceTurningOffTV", BindingFlags.Instance | BindingFlags.NonPublic); private static MethodInfo setMatMethod = typeof(TVScript).GetMethod("SetTVScreenMaterial", BindingFlags.Instance | BindingFlags.NonPublic); private static MethodInfo onEnableMethod = typeof(TVScript).GetMethod("OnEnable", BindingFlags.Instance | BindingFlags.NonPublic); private static bool tvHasPlayedBefore = false; private static RenderTexture renderTexture; private static VideoPlayer currentVideoPlayer; private static VideoPlayer nextVideoPlayer; [HarmonyPrefix] [HarmonyPatch("Update")] public static bool Update(TVScript __instance) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)currentVideoPlayer == (Object)null) { currentVideoPlayer = ((Component)__instance).GetComponent<VideoPlayer>(); renderTexture = currentVideoPlayer.targetTexture; PrepareVideo(__instance); } return false; } [HarmonyPrefix] [HarmonyPatch("TurnTVOnOff")] public static bool TurnTVOnOff(TVScript __instance, bool on) { TVLoaderPlugin.Log.LogInfo((object)$"TVOnOff: {on}"); if (VideoManager.Videos.Count == 0) { return false; } int num = (int)currentClipProperty.GetValue(__instance); if (on && tvHasPlayedBefore) { num = (num + 1) % VideoManager.Videos.Count; currentClipProperty.SetValue(__instance, num); } __instance.tvOn = on; if (on) { PlayVideo(__instance); __instance.tvSFX.PlayOneShot(__instance.switchTVOn); WalkieTalkie.TransmitOneShotAudio(__instance.tvSFX, __instance.switchTVOn, 1f); } else { __instance.video.Stop(); __instance.tvSFX.PlayOneShot(__instance.switchTVOff); WalkieTalkie.TransmitOneShotAudio(__instance.tvSFX, __instance.switchTVOff, 1f); } setMatMethod.Invoke(__instance, new object[1] { on }); return false; } [HarmonyPrefix] [HarmonyPatch("TVFinishedClip")] public static bool TVFinishedClip(TVScript __instance, VideoPlayer source) { if (!__instance.tvOn || GameNetworkManager.Instance.localPlayerController.isInsideFactory) { return false; } TVLoaderPlugin.Log.LogInfo((object)"TVFinishedClip"); int num = (int)currentClipProperty.GetValue(__instance); if (VideoManager.Videos.Count > 0) { num = (num + 1) % VideoManager.Videos.Count; } currentTimeProperty.SetValue(__instance, 0f); currentClipProperty.SetValue(__instance, num); PlayVideo(__instance); return false; } private static void PrepareVideo(TVScript instance) { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Expected O, but got Unknown string nextVideo = VideoManager.GetNextVideo(); if ((Object)(object)nextVideoPlayer != (Object)null && ((Component)nextVideoPlayer).gameObject.activeInHierarchy) { Object.Destroy((Object)(object)nextVideoPlayer); } nextVideoPlayer = ((Component)instance).gameObject.AddComponent<VideoPlayer>(); nextVideoPlayer.playOnAwake = false; nextVideoPlayer.isLooping = false; nextVideoPlayer.source = (VideoSource)1; nextVideoPlayer.controlledAudioTrackCount = 1; nextVideoPlayer.audioOutputMode = (VideoAudioOutputMode)1; nextVideoPlayer.SetTargetAudioSource((ushort)0, instance.tvSFX); nextVideoPlayer.url = "file://" + nextVideo; nextVideoPlayer.Prepare(); VideoPlayer obj = nextVideoPlayer; object obj2 = <>c.<>9__13_0; if (obj2 == null) { EventHandler val = delegate { TVLoaderPlugin.Log.LogInfo((object)"Prepared next video!"); TVLoaderPlugin.Log.LogInfo((object)nextVideoPlayer.url); }; <>c.<>9__13_0 = val; obj2 = (object)val; } obj.prepareCompleted += (EventHandler)obj2; } private static void PlayVideo(TVScript instance) { tvHasPlayedBefore = true; if (VideoManager.Videos.Count != 0) { if ((Object)(object)nextVideoPlayer != (Object)null) { VideoPlayer val = currentVideoPlayer; instance.video = (currentVideoPlayer = nextVideoPlayer); nextVideoPlayer = null; TVLoaderPlugin.Log.LogInfo((object)$"Destroy {val}"); Object.Destroy((Object)(object)val); onEnableMethod.Invoke(instance, new object[0]); } currentTimeProperty.SetValue(instance, 0f); instance.video.targetTexture = renderTexture; instance.video.Play(); PrepareVideo(instance); } } } [BepInPlugin("frediancustom.tvpack", "tvpack", "1.1.1")] public class TVLoaderPlugin : BaseUnityPlugin { private const string MyGUID = "frediancustom.tvpack"; private const string PluginName = "TVLoader"; private const string VersionString = "0.1.0"; private static readonly Harmony Harmony = new Harmony("frediancustom.tvpack"); public static ManualLogSource Log = new ManualLogSource("tvpack"); private void Awake() { Log = ((BaseUnityPlugin)this).Logger; Harmony.PatchAll(); VideoManager.Load(); ((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("PluginName: {0}, VersionString: {1} is loaded. Video Count: {2}", "tvpack", "1.1.1", VideoManager.Videos.Count)); ((BaseUnityPlugin)this).Logger.LogMessage((object)" . \r\n . ; \r\n . . ;% ;; \r\n , , :;% %; \r\n : ; :;%;' ., \r\n ,. %; %; ; %;' ,;\r\n ; ;%; %%; , %; ;%; ,%'\r\n %; %;%; , ; %; ;%; ,%;' \r\n ;%; %; ;%; % ;%; ,%;'\r\n ;%; %; ;%; % ;%; ,%;'\r\n `%;. ;%; %;' `;%%;.%;'\r\n `:;%. ;%%. %@; %; ;@%;%'\r\n `:%;. :;bd%; %;@%;'\r\n `@%:. :;%. ;@@%;' \r\n `@%. `;@%. ;@@%; \r\n `@%%. `@%% ;@@%; \r\n ;@%. :@%% %@@%; \r\n %@bd%%%bd%%:; \r\n #@%%%%%:;;\r\n %@@%%%::;\r\n %@@@%(o); . ' \r\n %@@@o%;:(.,' \r\n `.. %@@@o%::; \r\n `)@@@o%::; \r\n %@@(o)::; \r\n .%@@@@%::; \r\n ;%@@@@%::;. \r\n ;%@@@@%%:;;;. \r\n ...;%@@@@@%%:;;;;,.. Gilo97"); } }