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 WKTP v1.0.1
BepInEx/plugins/TheGreatestMilk-WKTP/WKTP.dll
Decompiled 32 minutes agousing System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Text; using System.Text.RegularExpressions; using BepInEx; using DunGen; using GameNetcodeStuff; using HarmonyLib; using TMPro; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; using UnityEngine.Video; [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: CompilationRelaxations(8)] [assembly: AssemblyVersion("0.0.0.0")] namespace WKTP; [BepInPlugin("thegreatestmilk.wktp", "WKTP", "1.0.1")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInIncompatibility("wesley.korean.scrapdisplay")] public sealed class ScrapDisplayPlugin : BaseUnityPlugin { private sealed class EventSpeech { internal AudioSource Source; internal AudioClip Clip; internal float Start; internal float Pitch; } private sealed class TextureRegistration { internal string Path; internal string Texture; internal int Width; internal int Height; internal bool ToyStore; } private static ScrapDisplayPlugin instance; private static TMP_FontAsset subtitleFont; private static AssetBundle subtitleFontBundle; private static bool triedSubtitleFont; private static MethodInfo subtitleCutsceneInstance; private static MethodInfo subtitleCutsceneCamera; private static MethodInfo subtitleCutscenePlaying; private readonly List<EventSpeech> eventSpeech = new List<EventSpeech>(); private readonly Dictionary<string, WesleySubtitleTrack> routeAudioSubtitles = new Dictionary<string, WesleySubtitleTrack>(StringComparer.Ordinal); private readonly List<AudioSource> routeSubtitleSources = new List<AudioSource>(); private float nextRouteSourceScan; private string selectedRouteSubtitleClip = ""; private static readonly Dictionary<string, TextureRegistration> WesleyTextureMaterials = ReadTextureRegistry(); private static readonly Dictionary<string, Texture2D> TranslatedTextures = new Dictionary<string, Texture2D>(StringComparer.Ordinal); private readonly Dictionary<string, WesleySubtitleTrack> videoSubtitles = new Dictionary<string, WesleySubtitleTrack>(StringComparer.Ordinal); private readonly List<VideoPlayer> subtitlePlayers = new List<VideoPlayer>(); private FieldInfo cassetteScreenPlayer; private GameObject subtitleCanvas; private GameObject subtitlePanel; private TextMeshProUGUI subtitleLabel; private string videoSubtitleStatus; private bool videoSubtitleHudTickStarted; private void Awake() { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Expected O, but got Unknown //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Expected O, but got Unknown instance = this; Harmony val = new Harmony("thegreatestmilk.wktp"); bool value = ((BaseUnityPlugin)this).Config.Bind<bool>("Features", "Textures", true, "Enable Wesley texture replacements. Restart after changing.").Value; bool value2 = ((BaseUnityPlugin)this).Config.Bind<bool>("Features", "Subtitles", true, "Enable Wesley video and voice subtitles. Restart after changing.").Value; if (value) { SceneManager.sceneLoaded += OnTextureSceneLoaded; Hook(val, typeof(StartOfRound), "Start", "RefreshTextureMaterials"); Hook(val, typeof(RoundManager), "GeneratedFloorPostProcessing", "RefreshDungeonTextures"); MethodInfo methodInfo = AccessTools.EnumeratorMoveNext((MethodBase)AccessTools.Method(typeof(StartOfRound), "openingDoorsSequence", (Type[])null, (Type[])null)); if (methodInfo != null) { val.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(ScrapDisplayPlugin), "RefreshTextureMaterials", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } string[] array = new string[4] { "Start", "GrabItem", "EquipItem", "LoadItemSaveData" }; foreach (string method in array) { Hook(val, typeof(GrabbableObject), method, "TranslateSpawnedItemLabels"); } Type type = AccessTools.TypeByName("WesleysInteriorTools.Features.AutopsyObjective"); MethodInfo methodInfo2 = ((type == null) ? null : AccessTools.Method(type, "SetupAutopsyValuesClientRpc", (Type[])null, (Type[])null)); if (methodInfo2 != null) { val.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(ScrapDisplayPlugin), "AutopsyTextureTranspiler", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null); } RefreshTextureMaterials(); GrabbableObject[] array2 = Object.FindObjectsOfType<GrabbableObject>(true); foreach (GrabbableObject _instance in array2) { TranslateSpawnedItemLabels(_instance); } } if (value2) { InitializeVideoSubtitles(val); } ((BaseUnityPlugin)this).Logger.LogInfo((object)"WKTP 1.0.1: independent Wesley textures/subtitles; no LCKP/LCMKP dependency."); } private static void Hook(Harmony harmony, Type type, string method, string postfix) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Expected O, but got Unknown MethodInfo methodInfo = AccessTools.Method(type, method, (Type[])null, (Type[])null); if (methodInfo != null) { harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(ScrapDisplayPlugin), postfix, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } } private static string TextureMoonName() { StartOfRound val = StartOfRound.Instance; string input = (((Object)(object)val == (Object)null || (Object)(object)val.currentLevel == (Object)null) ? "" : (val.currentLevel.PlanetName ?? "")); return Regex.Replace(input, "^\\s*[-–]?\\d+(?:[-–]\\d+)*(?:\\s*[-–]\\s*|\\s+)", "").Trim(); } private static void RefreshTextureMaterials() { string moon = TextureMoonName(); Material[] array = Resources.FindObjectsOfTypeAll<Material>(); foreach (Material material in array) { TranslateLocalizedMaterial(material, moon); } } private static void OnTextureSceneLoaded(Scene scene, LoadSceneMode mode) { RefreshTextureMaterials(); GameObject[] rootGameObjects = ((Scene)(ref scene)).GetRootGameObjects(); foreach (GameObject root in rootGameObjects) { TranslateCraftingBoards(root); } } private static void RefreshDungeonTextures(RoundManager __instance) { RefreshTextureMaterials(); RuntimeDungeon val = (((Object)(object)__instance == (Object)null) ? null : __instance.dungeonGenerator); GameObject val2 = (((Object)(object)val == (Object)null) ? null : val.Root); if ((Object)(object)val2 == (Object)null) { return; } Renderer[] componentsInChildren = val2.GetComponentsInChildren<Renderer>(true); foreach (Renderer val3 in componentsInChildren) { Material[] sharedMaterials = val3.sharedMaterials; foreach (Material material in sharedMaterials) { TranslateWesleyTextureMaterial(material, toyStoreBadge: true); } } } private static TMP_FontAsset GetWesleyHudFont() { if ((Object)(object)subtitleFont != (Object)null) { return subtitleFont; } TMP_FontAsset[] array = Resources.FindObjectsOfTypeAll<TMP_FontAsset>(); foreach (TMP_FontAsset val in array) { if ((Object)(object)val != (Object)null && val.HasCharacter('가', true, true) && val.HasCharacter('힣', true, true)) { if (!object.ReferenceEquals(instance, null)) { ((BaseUnityPlugin)instance).Logger.LogInfo((object)("WKTP subtitles: reusing loaded Korean font " + ((Object)val).name)); } return subtitleFont = val; } } if (triedSubtitleFont) { return null; } triedSubtitleFont = true; try { using (Stream stream = typeof(ScrapDisplayPlugin).Assembly.GetManifestResourceStream("WKTP.MaruBuri.bundle")) { using MemoryStream memoryStream = new MemoryStream(); stream.CopyTo(memoryStream); subtitleFontBundle = AssetBundle.LoadFromMemory(memoryStream.ToArray()); } if ((Object)(object)subtitleFontBundle != (Object)null) { TMP_FontAsset[] array2 = subtitleFontBundle.LoadAllAssets<TMP_FontAsset>(); foreach (TMP_FontAsset val2 in array2) { if (val2.HasCharacter('가', true, true) && val2.HasCharacter('힣', true, true)) { subtitleFont = val2; Object.DontDestroyOnLoad((Object)(object)subtitleFont); if (!object.ReferenceEquals(instance, null)) { ((BaseUnityPlugin)instance).Logger.LogInfo((object)("WKTP subtitles: loaded embedded Korean font " + ((Object)val2).name)); } return subtitleFont; } } } } catch (Exception ex) { if (!object.ReferenceEquals(instance, null)) { ((BaseUnityPlugin)instance).Logger.LogWarning((object)("WKTP subtitle font could not load: " + ex)); } } return null; } private void OnDestroy() { SceneManager.sceneLoaded -= OnTextureSceneLoaded; DestroyVideoSubtitles(); } private static Camera SelectSubtitleCamera(Camera gameplayCamera) { if ((Object)(object)gameplayCamera != (Object)null && ((Behaviour)gameplayCamera).isActiveAndEnabled) { return gameplayCamera; } object obj = ((subtitleCutsceneInstance == null) ? null : subtitleCutsceneInstance.Invoke(null, null)); if (obj == null || subtitleCutscenePlaying == null || subtitleCutsceneCamera == null || !(bool)subtitleCutscenePlaying.Invoke(obj, null)) { return null; } object? obj2 = subtitleCutsceneCamera.Invoke(obj, null); Camera val = (Camera)((obj2 is Camera) ? obj2 : null); if (!((Object)(object)val != (Object)null) || !((Behaviour)val).isActiveAndEnabled) { return null; } return val; } private void InitializeEventAudioSubtitles(Harmony harmony) { //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Expected O, but got Unknown Type type = AccessTools.TypeByName("LCCutscene.CutsceneManager"); if (type != null) { subtitleCutsceneInstance = AccessTools.PropertyGetter(type, "Instance"); subtitleCutsceneCamera = AccessTools.PropertyGetter(type, "CutsceneCamera"); subtitleCutscenePlaying = AccessTools.PropertyGetter(type, "cutscenePlaying"); } Type type2 = AccessTools.TypeByName("WesleysInteriorTools.Features.PlayerSpecificSound"); MethodInfo methodInfo = ((type2 == null) ? null : AccessTools.Method(type2, "PickAudioToPlay", (Type[])null, (Type[])null)); if (methodInfo != null) { harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(ScrapDisplayPlugin), "EventSpeechTranspiler", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null); } } private static IEnumerable<CodeInstruction> EventSpeechTranspiler(IEnumerable<CodeInstruction> instructions) { MethodInfo play = AccessTools.Method(typeof(AudioSource), "PlayOneShot", new Type[1] { typeof(AudioClip) }, (Type[])null); MethodInfo wrapper = AccessTools.Method(typeof(ScrapDisplayPlugin), "PlayEventSpeech", (Type[])null, (Type[])null); foreach (CodeInstruction instruction in instructions) { if (object.Equals(instruction.operand, play)) { instruction.opcode = OpCodes.Call; instruction.operand = wrapper; } yield return instruction; } } private static void PlayEventSpeech(AudioSource source, AudioClip clip) { source.PlayOneShot(clip); if (!object.ReferenceEquals(instance, null) && !((Object)(object)clip == (Object)null) && instance.routeAudioSubtitles.ContainsKey(AudioSubtitleKey(((Object)clip).name))) { instance.eventSpeech.RemoveAll((EventSpeech speech) => (Object)(object)speech.Source == (Object)null || (Object)(object)speech.Source == (Object)(object)source); instance.eventSpeech.Add(new EventSpeech { Source = source, Clip = clip, Start = Time.unscaledTime, Pitch = Mathf.Abs(source.pitch) }); } } private bool TrySelectEventSpeech(Camera camera, float competingDistance, out string text, out string clipName) { //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) text = ""; clipName = ""; float num = competingDistance; for (int num2 = this.eventSpeech.Count - 1; num2 >= 0; num2--) { EventSpeech eventSpeech = this.eventSpeech[num2]; float num3 = (Time.unscaledTime - eventSpeech.Start) * eventSpeech.Pitch; if ((Object)(object)eventSpeech.Source == (Object)null || (Object)(object)eventSpeech.Clip == (Object)null || !((Behaviour)eventSpeech.Source).isActiveAndEnabled || !eventSpeech.Source.isPlaying || num3 >= eventSpeech.Clip.length) { this.eventSpeech.RemoveAt(num2); } else { float num4; if (!(eventSpeech.Source.spatialBlend <= 0.001f)) { Vector3 val = ((Component)eventSpeech.Source).transform.position - ((Component)camera).transform.position; num4 = ((Vector3)(ref val)).sqrMagnitude; } else { num4 = 0f; } float num5 = num4; if (!(num5 > num) && routeAudioSubtitles.TryGetValue(AudioSubtitleKey(((Object)eventSpeech.Clip).name), out var value)) { num = num5; clipName = ((Object)eventSpeech.Clip).name; text = value.TextAt(num3); } } } return clipName.Length != 0; } private static string AudioSubtitleKey(string clipName) { if (clipName == null || !clipName.StartsWith("TheVoiceHelp_", StringComparison.Ordinal)) { return clipName; } return "TheVoiceHelp_Reg"; } private void InitializeRouteAudioSubtitles() { Assembly assembly = ((object)this).GetType().Assembly; using (Stream stream = assembly.GetManifestResourceStream("WesleyRouteAudioSubtitles.tsv")) { using StreamReader streamReader = new StreamReader(stream); string text; while ((text = streamReader.ReadLine()) != null) { if (text.Length == 0 || text.StartsWith("#", StringComparison.Ordinal)) { continue; } string[] array = text.Split(new char[1] { '\t' }); if (array.Length != 3) { throw new FormatException("Invalid route audio subtitle registration: " + text); } using Stream stream2 = assembly.GetManifestResourceStream(array[1]); using StreamReader reader = new StreamReader(stream2); routeAudioSubtitles.Add(array[0], WesleySubtitleTrack.Read(reader)); } } ((BaseUnityPlugin)this).Logger.LogInfo((object)("Wesley route audio subtitles loaded: " + routeAudioSubtitles.Count + " tracks.")); } private void RefreshRouteSubtitleSources() { if (routeAudioSubtitles.Count == 0 || Time.unscaledTime < nextRouteSourceScan) { return; } nextRouteSourceScan = Time.unscaledTime + 1f; AudioSource[] array = Object.FindObjectsOfType<AudioSource>(true); foreach (AudioSource val in array) { if ((Object)(object)val != (Object)null && (Object)(object)val.clip != (Object)null && routeAudioSubtitles.ContainsKey(AudioSubtitleKey(((Object)val.clip).name)) && !routeSubtitleSources.Contains(val)) { routeSubtitleSources.Add(val); } } } private bool TrySelectRouteAudioSubtitle(Camera camera, float competingDistance, out string text, out string clipName) { //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) RefreshRouteSubtitleSources(); AudioSource val = null; WesleySubtitleTrack wesleySubtitleTrack = null; float num = competingDistance; for (int num2 = routeSubtitleSources.Count - 1; num2 >= 0; num2--) { AudioSource val2 = routeSubtitleSources[num2]; WesleySubtitleTrack value; if ((Object)(object)val2 == (Object)null) { routeSubtitleSources.RemoveAt(num2); } else if (((Behaviour)val2).isActiveAndEnabled && val2.isPlaying && !((Object)(object)val2.clip == (Object)null) && routeAudioSubtitles.TryGetValue(AudioSubtitleKey(((Object)val2.clip).name), out value)) { float num3; if (!(val2.spatialBlend <= 0.001f)) { Vector3 val3 = ((Component)val2).transform.position - ((Component)camera).transform.position; num3 = ((Vector3)(ref val3)).sqrMagnitude; } else { num3 = 0f; } float num4 = num3; if (!(num4 > num)) { num = num4; val = val2; wesleySubtitleTrack = value; } } } if (TrySelectEventSpeech(camera, num, out text, out clipName)) { return true; } clipName = (((Object)(object)val == (Object)null) ? "" : ((Object)val.clip).name); double num5 = (((Object)(object)val == (Object)null) ? 0.0 : ((double)val.timeSamples / (double)val.clip.frequency)); text = (((Object)(object)val == (Object)null) ? "" : wesleySubtitleTrack.TextAt(num5)); if (selectedRouteSubtitleClip != clipName) { selectedRouteSubtitleClip = clipName; ((BaseUnityPlugin)this).Logger.LogInfo((object)("Wesley route audio subtitles: " + (((Object)(object)val == (Object)null) ? "inactive" : ("selected " + clipName + " at " + num5 + "s")))); } return (Object)(object)val != (Object)null; } private static Dictionary<string, TextureRegistration> ReadTextureRegistry() { Dictionary<string, TextureRegistration> dictionary = new Dictionary<string, TextureRegistration>(StringComparer.Ordinal); using Stream stream = typeof(ScrapDisplayPlugin).Assembly.GetManifestResourceStream("WesleyTextureMaterials.tsv"); using StreamReader streamReader = new StreamReader(stream); string text; while ((text = streamReader.ReadLine()) != null) { if (text.Length != 0 && !text.StartsWith("#")) { string[] array = text.Split(new char[1] { '\t' }); if (array.Length != 6 || !int.TryParse(array[3], out var result) || !int.TryParse(array[4], out var result2) || result <= 0 || result2 <= 0 || (array[5] != "global" && array[5] != "toystore")) { throw new InvalidDataException("Invalid texture registration: " + text); } dictionary.Add(array[0], new TextureRegistration { Path = array[1], Texture = array[2], Width = result, Height = result2, ToyStore = (array[5] == "toystore") }); } } return dictionary; } private static void TranslateSpawnedItemLabels(GrabbableObject __instance) { if ((Object)(object)__instance != (Object)null) { TranslateCraftingBoards(((Component)__instance).gameObject); } } private static void TranslateCraftingBoards(GameObject root) { if ((Object)(object)root == (Object)null) { return; } Renderer[] componentsInChildren = root.GetComponentsInChildren<Renderer>(true); foreach (Renderer val in componentsInChildren) { Material[] sharedMaterials = val.sharedMaterials; foreach (Material material in sharedMaterials) { TranslateLocalizedMaterial(material, ""); } } } private static void TranslateBoardMaterial(Material material, string moon) { if ((Object)(object)material == (Object)null) { return; } string text = ((Object)material).name; if (text.EndsWith(" (Instance)", StringComparison.Ordinal)) { text = text.Substring(0, text.Length - " (Instance)".Length); } bool flag = moon == "Trite"; bool flag2 = moon == "Etern"; bool flag3 = moon == "Centrus"; bool flag4 = moon == "Filitrios"; bool flag5 = moon == "Extort"; bool flag6 = moon == "Polarus"; bool flag7 = moon == "Gloom"; bool flag8 = moon == "Fission-C"; bool flag9 = moon == "Utril"; bool flag10 = text == "DonnahueNote"; bool flag11 = text == "Task2Mtl"; bool flag12 = text == "ChasmNoteMtl"; bool flag13 = moon == "Gratar" && text == "signmtl"; bool flag14 = moon == "Cubatres" && text == "Rusty1 2"; bool flag15 = text == "NoteMtl" || text == "BuymeSignButCool"; bool flag16 = text == "BattleBoardMtl" || text == "BattleBoardMtl 1"; bool flag17 = moon == "Empra" && (text == "Material" || text == "BetaBadgeTex"); bool flag18 = text == "Amber'sDiary" || Regex.IsMatch(text, "^GuidePage1(?: [1-3])?$"); bool flag19 = Regex.IsMatch(text, "^Prisonersnote[1-4]Mtl$"); bool flag20 = Regex.IsMatch(text, "^wetnote[1-4]mtl$"); bool flag21 = Regex.IsMatch(text, "^lostnote[1-4]$"); bool flag22 = text == "idkmanmtl"; bool flag23 = text == "WarningStickers"; bool flag24 = text == "BinStickers"; bool flag25 = (moon == "Motra" || moon == "Oldred") && text == "PosterMtl"; bool flag26 = moon == "Truth" && Regex.IsMatch(text, "^NoSignal [1-3]$"); bool flag27 = text == "NoSignalMtl"; bool flag28 = Regex.IsMatch(text, "^WhiteBoardMtl [1-3]$") && (moon == "Polarus" || moon == "Porcerin" || moon == "Infernis"); bool flag29 = Regex.IsMatch(text, "^Terminal[1-4]Mtl$"); bool num; if (!flag29 && !flag28 && !flag10 && !flag11 && !flag12 && !flag13 && !flag14 && !flag15 && !flag16 && !flag17 && !flag18 && !flag19 && !flag20 && !flag21 && !flag22 && !flag23 && !flag24 && !flag25 && !flag26 && !flag27) { if (!flag) { if (!flag2) { if (!flag3) { if (!flag4) { if (!flag5) { if (!flag6) { if (!flag7) { if (!flag8) { if (!flag9) { if (moon.Length != 0) { return; } num = text != "WhiteBoardMtl 1"; } else { num = text != "MapMtl"; } } else { num = text != "warningsignmtl"; } } else { num = text != "postermtl"; } goto IL_03f9; } } else if (text != "SignifiersMtl") { num = !Regex.IsMatch(text, "^ZoneSign(?: [1-5])?$"); goto IL_03f9; } goto IL_03fc; } num = !Regex.IsMatch(text, "^(poster_1mtl|poster_3mtl(?: 1)?)$"); } else { num = text != "SuitmanGraffitiMtl"; } } else { num = !Regex.IsMatch(text, "^(crazy_text[1-7]mtl|signmtl)$"); } } else { if (text.StartsWith("FloppyTerminal", StringComparison.Ordinal) || text.StartsWith("graffiti_", StringComparison.Ordinal)) { goto IL_03fc; } num = !Regex.IsMatch(text, "^(?:PosterMtl|(?:burnt_)?poster_[1-3]mtl)$"); } goto IL_03f9; } goto IL_03fc; IL_03fc: string[] texturePropertyNames = material.GetTexturePropertyNames(); foreach (string text2 in texturePropertyNames) { Texture texture = material.GetTexture(text2); if ((Object)(object)texture == (Object)null) { continue; } bool num2; if (!flag29) { if (!flag10) { if (!flag11) { if (!flag12) { if (!flag13) { if (!flag14) { if (!flag15) { if (!flag16) { if (!flag17) { if (!flag18) { if (!flag19) { if (!flag20) { if (!flag21) { if (!flag22) { if (!flag23) { if (!flag24) { if (!flag25) { if (!flag26) { if (!flag27) { if (!flag28) { if (!flag) { if (!flag2) { if (!flag3) { if (!flag5) { if (!flag6) { if (!flag7) { if (!flag8) { if (!flag9) { if (texture.width != 1024 || texture.height != 1024) { continue; } if (!flag4) { if (((Object)texture).name == "Whiteboard") { goto IL_0de4; } num2 = ((Object)texture).name == "Whiteboard2"; } else { num2 = Regex.IsMatch(((Object)texture).name, "^trite_poster_(1|3|3-1)$"); } } else { if (texture.width != 512 || texture.height != 512) { continue; } num2 = ((Object)texture).name == "Sign"; } } else { if (texture.width != 512 || texture.height != 256) { continue; } num2 = ((Object)texture).name == "warning_sign"; } } else { if (texture.width != 512 || texture.height != 1024) { continue; } num2 = ((Object)texture).name == "gloom poster"; } } else { if (texture.width == 1024 && texture.height == 512 && Regex.IsMatch(((Object)texture).name, "^(?:magosign(?:2|3|birthday)|quietsign)$")) { goto IL_0de4; } if (texture.width != 512 || texture.height != 1024) { continue; } num2 = Regex.IsMatch(((Object)texture).name, "^scribbled_note_[1-4]_texture$"); } } else { if (texture.width != 1024) { continue; } if (texture.height == 128 && Regex.IsMatch(((Object)texture).name, "^(forest|bushgrove|forklifts|rockdump|oldCabin|logstorage)sign$")) { goto IL_0de4; } if (texture.height != 1024 || !(((Object)texture).name == "signs")) { continue; } num2 = text == "SignifiersMtl"; } } else { if (texture.width != 512 || texture.height != 512) { continue; } num2 = ((Object)texture).name == "SuitmanGraffiti"; } } else { if (texture.width == 512 && ((texture.height == 512 && Regex.IsMatch(((Object)texture).name, "^writing_texture_[1-6]$")) || (texture.height == 256 && ((Object)texture).name == "sign_texture"))) { goto IL_0de4; } if (!(text == "crazy_text7mtl") || texture.width != 1024 || texture.height != 512) { continue; } num2 = ((Object)texture).name == "The eye in the sky"; } } else { if ((texture.width == 1024 && texture.height == 512 && Regex.IsMatch(((Object)texture).name, "^graffiti_[1-478]$")) || (texture.width == 256 && texture.height == 256 && Regex.IsMatch(((Object)texture).name, "^RouteDownloadTerminal[1-4]?$"))) { goto IL_0de4; } if (texture.width != 1024 || texture.height != 1024) { continue; } num2 = Regex.IsMatch(((Object)texture).name, "^(?:burnt_)?trite_poster_[1-3]$"); } } else { if (texture.width != 1024 || texture.height != 1024) { continue; } num2 = Regex.IsMatch(((Object)texture).name, "^CunninghamWhiteboard[1-3]$"); } } else { if (texture.width != 1024 || texture.height != 512) { continue; } num2 = ((Object)texture).name == "NoSignal"; } } else { if (texture.width != 128 || texture.height != 64) { continue; } num2 = ((Object)texture).name == "No Signal" + (text[9] - 48 + 1); } } else { if (texture.width != 1024 || texture.height != 1024) { continue; } num2 = ((Object)texture).name == "trite_poster_1"; } } else { if (texture.width != 412 || texture.height != 273) { continue; } num2 = ((Object)texture).name == "containerStickers"; } } else { if (texture.width != 256 || texture.height != 149) { continue; } num2 = ((Object)texture).name == "warningStickers"; } } else { if (texture.width != 512 || texture.height != 256) { continue; } num2 = ((Object)texture).name == "note"; } } else { if (texture.width != 512 || texture.height != 512) { continue; } num2 = ((Object)texture).name == "lostnote_" + text[8]; } } else { if (texture.width != 512 || texture.height != 512) { continue; } num2 = ((Object)texture).name == "wet_note_" + text[7]; } } else { if (texture.width != 1024 || texture.height != 1024) { continue; } num2 = ((Object)texture).name == ((text == "Prisonersnote4Mtl") ? "guardnote" : ("prisonernote" + text[13])); } } else if (!(text == "Amber'sDiary")) { if (texture.width != 1024 || texture.height != 2048) { continue; } num2 = ((Object)texture).name == "AmberNote" + ((text == "GuidePage1") ? 1 : (text[11] - 48 + 1)); } else { if (texture.width != 256 || texture.height != 128) { continue; } num2 = ((Object)texture).name == "Ambers diary name"; } } else if (!(text == "BetaBadgeTex")) { if (texture.width != 256 || texture.height != 512) { continue; } num2 = ((Object)texture).name == "PlayerLevelStickers"; } else { if (texture.width != 512 || texture.height != 128) { continue; } num2 = ((Object)texture).name == "PlayerLevelStickers 1"; } } else { if (texture.width != 512 || texture.height != 512) { continue; } num2 = ((Object)texture).name == ((text == "BattleBoardMtl") ? "BoardTexture2" : "BoardTexture"); } } else { if (texture.width != 512 || texture.height != 512) { continue; } num2 = ((Object)texture).name == ((text == "NoteMtl") ? "Note" : "BuymeSignButCool"); } } else { if (texture.width != 512 || texture.height != 512) { continue; } num2 = ((Object)texture).name == "rusty_metal_texture_warning"; } } else { if (texture.width != 512 || texture.height != 256) { continue; } num2 = ((Object)texture).name == "takerstsign_texture"; } } else { if (texture.width != 512 || texture.height != 1024) { continue; } num2 = ((Object)texture).name == "ChasmNote"; } } else { if (texture.width != 512 || texture.height != 1024) { continue; } num2 = ((Object)texture).name == "TravellersNote2"; } } else { if (texture.width != 1024 || texture.height != 2048) { continue; } num2 = ((Object)texture).name == "Donnahue'sNote"; } } else { if (texture.width != 256 || texture.height != 256) { continue; } num2 = ((Object)texture).name == "Ter_" + text[8]; } if (!num2) { continue; } goto IL_0de4; IL_0de4: string text3 = (flag28 ? "Cunningham." : ((flag2 || flag3 || flag4 || flag5 || flag6 || flag8 || flag9) ? (moon + ".") : "")); string resource = (flag29 ? ("LogReader." + ((Object)texture).name + ".png") : (flag10 ? "Cosmocos.DonnahueNote.png" : (flag11 ? "Faith.TravellersNote2.png" : (flag12 ? "Junic.ChasmNote.png" : (flag13 ? "Gratar.TakerstSign.png" : (flag14 ? "Cubatres.CrystalWarning.png" : ((flag15 || flag16) ? ("ArtMuseum." + ((Object)texture).name + ".png") : (flag17 ? ("Empra." + ((Object)texture).name + ".png") : (flag18 ? ("Empra.Diary." + ((Object)texture).name + ".png") : (flag19 ? ("Alcatras." + ((Object)texture).name + ".png") : (flag20 ? ("Atlantica." + ((Object)texture).name + ".png") : (flag21 ? ("Acidir." + ((Object)texture).name + ".png") : ((flag22 || flag23 || flag24) ? ("Repress." + ((Object)texture).name + ".png") : ((flag26 || flag27) ? ("Monitor." + ((Object)texture).name + ".png") : (flag7 ? "Gloom.Poster.png" : (text3 + ((Object)texture).name + ".png")))))))))))))))); if (TryLoadTranslatedTexture(texture, resource, out var translated)) { material.SetTexture(text2, (Texture)(object)translated); } } return; IL_03f9: if (num) { return; } goto IL_03fc; } private static bool TryLoadTranslatedTexture(Texture original, string resource, out Texture2D translated) { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Expected O, but got Unknown //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) if (TranslatedTextures.TryGetValue(resource, out translated)) { return true; } using (Stream stream = typeof(ScrapDisplayPlugin).Assembly.GetManifestResourceStream(resource)) { if (stream == null) { return false; } using MemoryStream memoryStream = new MemoryStream(); stream.CopyTo(memoryStream); translated = new Texture2D(2, 2, (TextureFormat)4, true); if (!ImageConversion.LoadImage(translated, memoryStream.ToArray(), true)) { Object.Destroy((Object)(object)translated); translated = null; return false; } } ((Object)translated).name = ((Object)original).name + " (Korean)"; ((Texture)translated).filterMode = original.filterMode; ((Texture)translated).wrapMode = original.wrapMode; TranslatedTextures.Add(resource, translated); return true; } private static void TranslateWesleyTextureMaterial(Material material, bool toyStoreBadge = false) { if ((Object)(object)material == (Object)null) { return; } string text = ((Object)material).name; if (text.EndsWith(" (Instance)", StringComparison.Ordinal)) { text = text.Substring(0, text.Length - " (Instance)".Length); } if (!WesleyTextureMaterials.TryGetValue(text, out var value) || value.ToyStore != toyStoreBadge) { return; } string path = value.Path; string texture = value.Texture; string[] array = new string[2] { "_BaseColorMap", "_MainTex" }; foreach (string text2 in array) { if (material.HasProperty(text2)) { Texture texture2 = material.GetTexture(text2); if ((Object)(object)texture2 != (Object)null && ((Object)texture2).name == texture && texture2.width == value.Width && texture2.height == value.Height && TryLoadTranslatedTexture(texture2, "WesleyTexture." + path + ".png", out var translated) && texture2.width == ((Texture)translated).width && texture2.height == ((Texture)translated).height) { material.SetTexture(text2, (Texture)(object)translated); } } } } private static void TranslateLocalizedMaterial(Material material, string moon) { TranslateBoardMaterial(material, moon); TranslateWesleyTextureMaterial(material); } private void ReportVideoSubtitleStatus(string status, string details) { if (!(videoSubtitleStatus == status)) { videoSubtitleStatus = status; ((BaseUnityPlugin)this).Logger.LogInfo((object)("Wesley video subtitles: " + status + " | " + details)); } } private void InitializeVideoSubtitles(Harmony harmony) { //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Expected O, but got Unknown //IL_0275: Unknown result type (might be due to invalid IL or missing references) //IL_0282: Expected O, but got Unknown //IL_0221: Unknown result type (might be due to invalid IL or missing references) //IL_022e: Expected O, but got Unknown InitializeRouteAudioSubtitles(); InitializeEventAudioSubtitles(harmony); harmony.Patch((MethodBase)AccessTools.Method(typeof(HUDManager), "Update", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(ScrapDisplayPlugin), "UpdateVideoSubtitlesFromHud", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Wesley subtitles: runtime r35-berunah-audio; HUD Update hook installed."); Type type = AccessTools.TypeByName("WesleyMoonScripts.Components.LevelCassetteLoader"); if (type == null) { ((BaseUnityPlugin)this).Logger.LogInfo((object)"Wesley video subtitles: cassette loader is not installed."); return; } cassetteScreenPlayer = AccessTools.Field(type, "screenPlayer"); if (cassetteScreenPlayer == null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"Wesley video subtitles: screenPlayer field was not found."); return; } Assembly assembly = ((object)this).GetType().Assembly; using (Stream stream = assembly.GetManifestResourceStream("WesleyVideoSubtitles.tsv")) { using StreamReader streamReader = new StreamReader(stream); string text; while ((text = streamReader.ReadLine()) != null) { if (text.Length == 0 || text.StartsWith("#", StringComparison.Ordinal)) { continue; } string[] array = text.Split(new char[1] { '\t' }); if (array.Length != 3 || array[1] == "-") { continue; } try { using Stream stream2 = assembly.GetManifestResourceStream(array[1]); using StreamReader reader = new StreamReader(stream2); videoSubtitles.Add(array[0], WesleySubtitleTrack.Read(reader)); } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not read video subtitles for " + array[0] + ": " + ex)); } } } string[] array2 = new string[2] { "OnNetworkSpawn", "LoadCassette" }; foreach (string text2 in array2) { MethodInfo methodInfo = AccessTools.Method(type, text2, (Type[])null, (Type[])null); if (methodInfo != null) { harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(ScrapDisplayPlugin), "RegisterSubtitlePlayer", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } else { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Wesley video subtitle hook was not found: " + text2)); } } harmony.Patch((MethodBase)AccessTools.Method(type, "Update", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(ScrapDisplayPlugin), "RegisterSubtitlePlayer", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Wesley video subtitles loaded: " + videoSubtitles.Count + " tracks.")); } private static void RegisterSubtitlePlayer(Component __instance) { //IL_0093: Unknown result type (might be due to invalid IL or missing references) if (!object.ReferenceEquals(instance, null) && !(instance.cassetteScreenPlayer == null)) { object? value = instance.cassetteScreenPlayer.GetValue(__instance); VideoPlayer val = (VideoPlayer)((value is VideoPlayer) ? value : null); if ((Object)(object)val != (Object)null && !instance.subtitlePlayers.Contains(val)) { instance.subtitlePlayers.Add(val); ((BaseUnityPlugin)instance).Logger.LogInfo((object)("Wesley video subtitles: registered player " + ((Object)val).name + " at " + ((Component)val).transform.position)); } } } private static void UpdateVideoSubtitlesFromHud() { if (!object.ReferenceEquals(instance, null)) { if (!instance.videoSubtitleHudTickStarted) { instance.videoSubtitleHudTickStarted = true; ((BaseUnityPlugin)instance).Logger.LogInfo((object)("Wesley video subtitles: HUD frame updates started; plugin Unity object alive=" + ((Object)(object)instance != (Object)null))); } instance.UpdateVideoSubtitles(); } } private void UpdateVideoSubtitles() { //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) GameNetworkManager val = GameNetworkManager.Instance; PlayerControllerB val2 = (((Object)(object)val == (Object)null) ? null : val.localPlayerController); Camera val3 = SelectSubtitleCamera(((Object)(object)val2 == (Object)null) ? null : val2.gameplayCamera); if ((Object)(object)val3 == (Object)null || !((Behaviour)val3).isActiveAndEnabled) { ReportVideoSubtitleStatus("waiting-camera", "local player or gameplay camera is unavailable"); ShowVideoSubtitle(""); return; } VideoPlayer val4 = null; WesleySubtitleTrack wesleySubtitleTrack = null; float num = 900f; int num2 = 0; string text = ""; float num3 = float.PositiveInfinity; for (int num4 = subtitlePlayers.Count - 1; num4 >= 0; num4--) { VideoPlayer val5 = subtitlePlayers[num4]; if ((Object)(object)val5 == (Object)null) { subtitlePlayers.RemoveAt(num4); } else if (((Behaviour)val5).isActiveAndEnabled && (val5.isPlaying || val5.isPaused) && !((Object)(object)val5.clip == (Object)null)) { num2++; if (!videoSubtitles.TryGetValue(((Object)val5.clip).name, out var value)) { text = ((Object)val5.clip).name; } else { Vector3 position = ((Component)val5).transform.position; Vector3 val6 = position - ((Component)val3).transform.position; float sqrMagnitude = ((Vector3)(ref val6)).sqrMagnitude; if (sqrMagnitude >= num) { num3 = Mathf.Min(num3, sqrMagnitude); } else { val4 = val5; wesleySubtitleTrack = value; num = sqrMagnitude; } } } } if (TrySelectRouteAudioSubtitle(val3, num, out var text2, out var clipName)) { if (text2.Length == 0) { ReportVideoSubtitleStatus("route-audio-gap", clipName); } ShowVideoSubtitle(text2); } else if ((Object)(object)val4 == (Object)null) { string status = ((subtitlePlayers.Count == 0) ? "waiting-player" : ((num2 == 0) ? "waiting-playback" : ((!float.IsPositiveInfinity(num3)) ? "outside-range" : "unmapped-clip"))); ReportVideoSubtitleStatus(status, "registered=" + subtitlePlayers.Count + ", playing=" + num2 + ", clip=" + text + ", nearest distance=" + Mathf.Sqrt(num3)); ShowVideoSubtitle(""); } else { string text3 = wesleySubtitleTrack.TextAt(val4.time); if (text3.Length == 0) { ReportVideoSubtitleStatus("subtitle-gap", ((Object)val4.clip).name); } ShowVideoSubtitle(text3); } } private void ShowVideoSubtitle(string text) { if (text.Length == 0) { if ((Object)(object)subtitlePanel != (Object)null) { subtitlePanel.SetActive(false); } return; } TMP_FontAsset wesleyHudFont = GetWesleyHudFont(); if ((Object)(object)wesleyHudFont == (Object)null) { ReportVideoSubtitleStatus("waiting-font", "HUD font is unavailable"); if ((Object)(object)subtitlePanel != (Object)null) { subtitlePanel.SetActive(false); } return; } if ((Object)(object)subtitleCanvas == (Object)null) { CreateVideoSubtitleCanvas(wesleyHudFont); } if ((Object)(object)((TMP_Text)subtitleLabel).font != (Object)(object)wesleyHudFont) { ((TMP_Text)subtitleLabel).font = wesleyHudFont; } if (((TMP_Text)subtitleLabel).text != text) { ((TMP_Text)subtitleLabel).text = text; } subtitlePanel.SetActive(true); ReportVideoSubtitleStatus("displaying", "canvas=" + subtitleCanvas.activeInHierarchy + ", label=" + ((Behaviour)subtitleLabel).isActiveAndEnabled + ", font=" + ((Object)wesleyHudFont).name); } private void CreateVideoSubtitleCanvas(TMP_FontAsset font) { //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Expected O, but got Unknown //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Expected O, but got Unknown //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Unknown result type (might be due to invalid IL or missing references) //IL_0174: Unknown result type (might be due to invalid IL or missing references) //IL_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01b7: Expected O, but got Unknown //IL_01cb: Unknown result type (might be due to invalid IL or missing references) //IL_01d7: Unknown result type (might be due to invalid IL or missing references) //IL_01ed: Unknown result type (might be due to invalid IL or missing references) //IL_0203: Unknown result type (might be due to invalid IL or missing references) //IL_023c: Unknown result type (might be due to invalid IL or missing references) subtitleCanvas = new GameObject("Wesley Korean Video Subtitles", new Type[3] { typeof(RectTransform), typeof(Canvas), typeof(CanvasScaler) }); Object.DontDestroyOnLoad((Object)(object)subtitleCanvas); Canvas component = subtitleCanvas.GetComponent<Canvas>(); component.renderMode = (RenderMode)0; component.sortingOrder = 150; CanvasScaler component2 = subtitleCanvas.GetComponent<CanvasScaler>(); component2.uiScaleMode = (ScaleMode)1; component2.referenceResolution = new Vector2(1920f, 1080f); component2.matchWidthOrHeight = 0.5f; subtitlePanel = new GameObject("Subtitle Background", new Type[2] { typeof(RectTransform), typeof(Image) }); RectTransform component3 = subtitlePanel.GetComponent<RectTransform>(); ((Transform)component3).SetParent(subtitleCanvas.transform, false); Vector2 anchorMin = (component3.anchorMax = new Vector2(0.5f, 0f)); component3.anchorMin = anchorMin; component3.pivot = new Vector2(0.5f, 0f); component3.anchoredPosition = new Vector2(0f, 75f); component3.sizeDelta = new Vector2(1560f, 180f); Image component4 = subtitlePanel.GetComponent<Image>(); ((Graphic)component4).color = new Color(0f, 0f, 0f, 0.7f); ((Graphic)component4).raycastTarget = false; GameObject val2 = new GameObject("WKTP Subtitle Text", new Type[2] { typeof(RectTransform), typeof(TextMeshProUGUI) }); RectTransform component5 = val2.GetComponent<RectTransform>(); ((Transform)component5).SetParent((Transform)(object)component3, false); component5.anchorMin = Vector2.zero; component5.anchorMax = Vector2.one; component5.offsetMin = new Vector2(24f, 10f); component5.offsetMax = new Vector2(-24f, -10f); subtitleLabel = val2.GetComponent<TextMeshProUGUI>(); ((TMP_Text)subtitleLabel).font = font; ((TMP_Text)subtitleLabel).fontSize = 40f; ((Graphic)subtitleLabel).color = Color.white; ((TMP_Text)subtitleLabel).alignment = (TextAlignmentOptions)514; ((TMP_Text)subtitleLabel).enableWordWrapping = true; ((TMP_Text)subtitleLabel).richText = false; ((Graphic)subtitleLabel).raycastTarget = false; } private void DestroyVideoSubtitles() { if ((Object)(object)subtitleCanvas != (Object)null) { Object.Destroy((Object)(object)subtitleCanvas); } subtitlePlayers.Clear(); routeSubtitleSources.Clear(); eventSpeech.Clear(); nextRouteSourceScan = 0f; selectedRouteSubtitleClip = ""; } private static IEnumerable<CodeInstruction> AutopsyTextureTranspiler(IEnumerable<CodeInstruction> instructions) { MethodInfo setTexture = AccessTools.Method(typeof(Material), "SetTexture", new Type[2] { typeof(string), typeof(Texture) }, (Type[])null); MethodInfo setTranslatedTexture = AccessTools.Method(typeof(ScrapDisplayPlugin), "SetAutopsyTexture", (Type[])null, (Type[])null); foreach (CodeInstruction instruction in instructions) { if ((instruction.opcode == OpCodes.Callvirt || instruction.opcode == OpCodes.Call) && object.Equals(instruction.operand, setTexture)) { instruction.opcode = OpCodes.Call; instruction.operand = setTranslatedTexture; } yield return instruction; } } private static void SetAutopsyTexture(Material material, string property, Texture texture) { Texture2D val = (Texture2D)(object)((texture is Texture2D) ? texture : null); if ((Object)(object)val != (Object)null && ((Object)val).name.StartsWith("Autopsy", StringComparison.Ordinal) && TryLoadTranslatedTexture((Texture)(object)val, "RubberRooms." + ((Object)val).name + ".png", out var translated)) { texture = (Texture)(object)translated; } material.SetTexture(property, texture); } } internal sealed class WesleySubtitleTrack { private sealed class Cue { internal double Start; internal double End; internal string Text; } private static readonly Regex Timing = new Regex("^(\\d{2}:\\d{2}:\\d{2}[,.]\\d{1,3})\\s+-->\\s+(\\d{2}:\\d{2}:\\d{2}[,.]\\d{1,3})$"); private readonly List<Cue> cues = new List<Cue>(); internal static WesleySubtitleTrack Read(TextReader reader) { WesleySubtitleTrack wesleySubtitleTrack = new WesleySubtitleTrack(); string input = reader.ReadToEnd().Trim().TrimStart(new char[1] { '\ufeff' }); string[] array = Regex.Split(input, "\\r?\\n[ \\t]*\\r?\\n"); foreach (string text in array) { string[] array2 = text.Split(new string[2] { "\r\n", "\n" }, StringSplitOptions.None); if (array2.Length < 3 || !int.TryParse(array2[0].Trim(), out var result)) { throw new FormatException("Invalid SRT cue number."); } Match match = Timing.Match(array2[1].Trim()); if (!match.Success) { throw new FormatException("Invalid SRT timestamp at cue " + result); } double num = ParseTime(match.Groups[1].Value); double num2 = ParseTime(match.Groups[2].Value); if (num2 <= num || (wesleySubtitleTrack.cues.Count > 0 && num < wesleySubtitleTrack.cues[wesleySubtitleTrack.cues.Count - 1].Start)) { throw new FormatException("Invalid SRT time range at cue " + result); } wesleySubtitleTrack.cues.Add(new Cue { Start = num, End = num2, Text = string.Join("\n", array2, 2, array2.Length - 2) }); } return wesleySubtitleTrack; } private static double ParseTime(string value) { string[] array = value.Split(':', ',', '.'); int num = int.Parse(array[0], CultureInfo.InvariantCulture); int num2 = int.Parse(array[1], CultureInfo.InvariantCulture); int num3 = int.Parse(array[2], CultureInfo.InvariantCulture); if (num2 > 59 || num3 > 59) { throw new FormatException("Invalid SRT minutes or seconds."); } int num4 = int.Parse(array[3].PadRight(3, '0'), CultureInfo.InvariantCulture); return (double)num * 3600.0 + (double)num2 * 60.0 + (double)num3 + (double)num4 / 1000.0; } internal string TextAt(double seconds) { StringBuilder stringBuilder = null; foreach (Cue cue in cues) { if (cue.Start > seconds) { break; } if (!(seconds >= cue.End)) { if (stringBuilder == null) { stringBuilder = new StringBuilder(cue.Text); } else { stringBuilder.Append('\n').Append(cue.Text); } } } if (stringBuilder != null) { return stringBuilder.ToString(); } return ""; } }