using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using BepInEx; using BepInEx.Logging; using FMOD; using FMOD.Studio; using FMODUnity; using HarmonyLib; using TurronishMod.Logger; using UnityEngine; using UnityEngine.Playables; using UnityEngine.Rendering; using UnityEngine.SceneManagement; 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: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("0.0.0.0")] namespace ControlDoblaje; internal static class ListenerCache { private static StudioListener _cache; public static StudioListener Get() { if ((Object)(object)_cache == (Object)null) { Object obj = Object.FindObjectOfType(typeof(StudioListener)); _cache = (StudioListener)(object)((obj is StudioListener) ? obj : null); } return _cache; } } internal static class AudioPack { public unsafe static RESULT CrearSound(System sys, string ruta, MODE modo, ref CREATESOUNDEXINFO ex, out Sound sound) { //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_004f: 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) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Invalid comparison between Unknown and I4 //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) if (AssetPack.EstaEnPack(ruta)) { try { byte[] array = AssetPack.LeerBytes(ruta); if (ex.cbsize == 0) { ex.cbsize = Marshal.SizeOf(typeof(CREATESOUNDEXINFO)); } ex.length = (uint)array.Length; MODE val = (MODE)(modo | 0x800); RESULT val2 = ((System)(ref sys)).createSound(array, val, ref ex, ref sound); if ((int)val2 == 0) { return val2; } ControlDoblajePlugin.Log.LogWarning((object)("[AudioPack] createSound memoria falló (" + ((object)(*(RESULT*)(&val2))/*cast due to .constrained prefix*/).ToString() + ") " + Path.GetFileName(ruta) + " — fallback disco")); } catch (Exception ex2) { ControlDoblajePlugin.Log.LogWarning((object)("[AudioPack] excepción memoria " + ex2.Message + " — fallback disco")); } } return ((System)(ref sys)).createSound(ruta, modo, ref ex, ref sound); } } [BepInPlugin("com.turronish.audio", "Turronish Audio", "1.1.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class TurronishAudioPlugin : BaseUnityPlugin { private void Awake() { //IL_0148: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Expected O, but got Unknown ControlDoblajePlugin.InstalarAudioScanners = (Action)Delegate.Combine(ControlDoblajePlugin.InstalarAudioScanners, new Action(AudioNuclearScannerInstaller.Instalar)); ControlDoblajePlugin.PatchAudioExtra = (Action)Delegate.Combine(ControlDoblajePlugin.PatchAudioExtra, (Action)delegate(Harmony h) { FMODPatchInstaller.InstalarSiNoEsta(h); PhoneCallPatcher.TryInstalar(h); }); ControlDoblajePlugin.SceneLoadedAudio = (Action)Delegate.Combine(ControlDoblajePlugin.SceneLoadedAudio, (Action)delegate { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Expected O, but got Unknown if ((Object)(object)Object.FindObjectOfType() == (Object)null && (Object)(object)GameObject.Find("_VideoTimescaleWatcher") == (Object)null) { GameObject val2 = new GameObject("_VideoTimescaleWatcher"); Object.DontDestroyOnLoad((Object)(object)val2); val2.AddComponent(); } CinematicaMultiPistaPlayer.RefrescarCacheWAV(); CinematicaMultiPistaPlayer.CargarBanksTurronish(); WandererGestor.LimpiarInstancia(); WandererGestor.DesmuteearRadio(); HeadtombsGestor.LimpiarInstancia(); WandererCutscenePlayer.UltimoDisparo = -999f; WandererAttackPlayer.DetenerSiActivo(); ExtrasVideoDuckingManager.RestaurarSiNecesario(); if ((Object)(object)CinematicaMultiPistaPlayer.RunnerActivo != (Object)null) { ControlDoblajePlugin.Log.LogInfo((object)"[SceneLoad] Runner activo tras cambio escena — limpiando"); try { CinematicaMultiPistaPlayer.RunnerActivo.Detener(); } catch { } CinematicaMultiPistaPlayer.RunnerActivo = null; } if ((Object)(object)CinematicaMultiPistaPlayer.AmbienterRunnerActivo != (Object)null) { try { CinematicaMultiPistaPlayer.AmbienterRunnerActivo.Detener(); } catch { } CinematicaMultiPistaPlayer.AmbienterRunnerActivo = null; } CinematicaMultiPistaPlayer.LimpiarInstanciaFMOD(); FMODStopHelper.NPCVideoRegistrado = false; }); ControlDoblajePlugin.AplicarModelosCallback = AplicarModelos3DDespues; ControlDoblajePlugin.WandererRadioMute = (Action)Delegate.Combine(ControlDoblajePlugin.WandererRadioMute, (Action)delegate(bool mute) { if (mute) { WandererGestor.MutearRadio(); } else { WandererGestor.DesmuteearRadio(); } }); ControlDoblajePlugin.ModelosAplicar = ModelosGestor.AplicarEnEscena; ControlDoblajePlugin.ModelosRestaurar = ModelosGestor.RestaurarMeshesOriginales; ControlDoblajePlugin.VideoExtrasInicio = ExtrasVideoDuckingManager.Inicio; ControlDoblajePlugin.VideoExtrasFin = ExtrasVideoDuckingManager.Fin; ControlDoblajePlugin.SoundPlayRandom = TurronishSoundPlayer.PlayRandom; ControlDoblajePlugin.AudioObtenerPersonajesDeBank = TurronishBankLoader.ObtenerPersonajesDeBank; ControlDoblajePlugin.AudioForzarCargaBanks = TurronishBankLoader.LoadIfNeeded; Harmony val = new Harmony("com.turronish.audio"); int num = 0; int num2 = 0; Type[] types = Assembly.GetExecutingAssembly().GetTypes(); foreach (Type type in types) { if (type.GetCustomAttributes(typeof(HarmonyPatch), inherit: false).Length != 0) { try { val.CreateClassProcessor(type).Patch(); num++; } catch (Exception ex) { ControlDoblajePlugin.Log.LogError((object)("[Audio] Patch FAILED '" + type.Name + "': " + ex.GetType().Name + " — " + ex.Message)); num2++; } } } ControlDoblajePlugin.Log.LogInfo((object)$"[Audio] PatchAllSafe: {num} ok, {num2} fallidos"); TurronishDiagLogger.Info("[Audio]", "TurronishAudio cargado OK."); ((BaseUnityPlugin)this).Logger.LogInfo((object)"[Audio] TurronishAudio cargado."); } private static IEnumerator AplicarModelos3DDespues() { for (int i = 0; i < 8; i++) { yield return null; } ModelosGestor.AplicarEnEscena(); } } public static class AudioLogTracker { private static readonly HashSet _vistos = new HashSet(StringComparer.OrdinalIgnoreCase); public static void Registrar(string clipName, string goName = null) { if (string.IsNullOrEmpty(clipName)) { return; } if (!ControlDoblajePlugin.LogVerboso) { _vistos.Add(clipName); return; } string text = (string.IsNullOrEmpty(goName) ? clipName : (clipName + " [GO:" + goName + "]")); if (_vistos.Add(clipName)) { ControlDoblajePlugin.Log.LogInfo((object)("[AUDIO_NEW] " + text)); } } public static void RegistrarSiempre(string clipName, string goName = null) { if (!string.IsNullOrEmpty(clipName)) { Registrar(clipName, goName); if (ControlDoblajePlugin.LogVerboso) { string text = (string.IsNullOrEmpty(goName) ? clipName : (clipName + " [GO:" + goName + "]")); ControlDoblajePlugin.Log.LogInfo((object)("[AUDIO_PLAY] " + text)); } } } } public class AudioNuclearScanner : MonoBehaviour { private static readonly HashSet _scannedClips = new HashSet(StringComparer.OrdinalIgnoreCase); private static readonly HashSet _scannedGOs = new HashSet(StringComparer.OrdinalIgnoreCase); private float _timer = 0f; private const float INTERVAL = 0.5f; private void Update() { if (!ControlDoblajePlugin.LogVerboso) { return; } _timer -= Time.unscaledDeltaTime; if (_timer > 0f) { return; } _timer = 0.5f; try { AudioSource[] array = Object.FindObjectsOfType(); AudioSource[] array2 = array; foreach (AudioSource val in array2) { if ((Object)(object)val == (Object)null || !val.isPlaying || (Object)(object)val.clip == (Object)null) { continue; } string name = ((Object)val.clip).name; GameObject gameObject = ((Component)val).gameObject; string text = ((gameObject != null) ? ((Object)gameObject).name : null) ?? "?"; string item = name + "|" + text; if (_scannedGOs.Add(item)) { if (ControlDoblajePlugin.LogVerboso) { ControlDoblajePlugin.Log.LogInfo((object)$"[SCAN_NEW] clip={name} GO={text} loop={val.loop} vol={val.volume:F2} spatial={val.spatialBlend:F1}"); } } else if (ControlDoblajePlugin.LogVerboso && (name.IndexOf("wander", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("USB", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("LP", StringComparison.OrdinalIgnoreCase) >= 0)) { ControlDoblajePlugin.Log.LogInfo((object)("[SCAN_LOOP] clip=" + name + " GO=" + text)); } } } catch { } } public void ResetarGOs() { _scannedGOs.Clear(); } } public static class AudioNuclearScannerInstaller { private static GameObject _go; public static void Instalar() { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown if (!((Object)(object)_go != (Object)null)) { _go = new GameObject("_AudioNuclearScanner"); Object.DontDestroyOnLoad((Object)(object)_go); _go.AddComponent(); ControlDoblajePlugin.Log.LogInfo((object)"[AUDIO] Scanner nuclear instalado."); } } } public static class FMODLogTracker { private static readonly HashSet _vistos = new HashSet(StringComparer.OrdinalIgnoreCase); public static void Log(string path, string via) { if (string.IsNullOrEmpty(path)) { return; } if (_vistos.Add(path)) { ControlDoblajePlugin.Log.LogInfo((object)("[FMOD_NEW] " + path)); if (ControlDoblajePlugin.LogVerboso) { LogBusDeEvento(path); } } if (ControlDoblajePlugin.LogVerboso) { ControlDoblajePlugin.Log.LogInfo((object)("[FMOD:" + via + "] " + path)); } } private static void LogBusDeEvento(string path) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Invalid comparison between Unknown and I4 //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Invalid comparison between Unknown and I4 //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) try { System studioSystem = RuntimeManager.StudioSystem; EventDescription val = default(EventDescription); EventInstance val2 = default(EventInstance); if ((int)((System)(ref studioSystem)).getEvent(path, ref val) > 0 || (int)((EventDescription)(ref val)).createInstance(ref val2) > 0) { return; } ChannelGroup val3 = default(ChannelGroup); if ((int)((EventInstance)(ref val2)).getChannelGroup(ref val3) == 0 && ((ChannelGroup)(ref val3)).hasHandle()) { string text = "?"; string[] array = new string[10] { "bus:/SFX", "bus:/SFX/Dialogue", "bus:/SFX/NPC", "bus:/Voice", "bus:/Voices", "bus:/NPCs", "bus:/Music", "bus:/Ambience", "bus:/UI", "bus:/" }; string[] array2 = array; Bus val4 = default(Bus); ChannelGroup val5 = default(ChannelGroup); foreach (string text2 in array2) { studioSystem = RuntimeManager.StudioSystem; if ((int)((System)(ref studioSystem)).getBus(text2, ref val4) == 0 && (int)((Bus)(ref val4)).getChannelGroup(ref val5) == 0 && ((ChannelGroup)(ref val5)).hasHandle() && val5.handle == val3.handle) { text = text2; break; } } ControlDoblajePlugin.Log.LogInfo((object)("[FMOD_BUS] " + path + " → " + text)); } ((EventInstance)(ref val2)).release(); } catch { } } public static void Registrar(string path) { Log(path, "?"); } } public class AudioSourcePlayPatch { private static void Prefix(AudioSource __instance) { if (!((Object)(object)((__instance != null) ? __instance.clip : null) == (Object)null)) { string name = ((Object)__instance.clip).name; GameObject gameObject = ((Component)__instance).gameObject; AudioLogTracker.RegistrarSiempre(name, (gameObject != null) ? ((Object)gameObject).name : null); } } } [HarmonyPatch(typeof(AudioSource), "PlayDelayed", new Type[] { typeof(float) })] public class AudioSourcePlayDelayedPatch { private static void Prefix(AudioSource __instance) { if (!((Object)(object)((__instance != null) ? __instance.clip : null) == (Object)null)) { string name = ((Object)__instance.clip).name; GameObject gameObject = ((Component)__instance).gameObject; AudioLogTracker.RegistrarSiempre(name, "delayed|" + ((gameObject != null) ? ((Object)gameObject).name : null)); } } } [HarmonyPatch(typeof(AudioSource), "PlayOneShot", new Type[] { typeof(AudioClip) })] public class AudioSourcePlayOneShotPatch { private static void Prefix(AudioSource __instance, AudioClip clip) { if (!((Object)(object)clip == (Object)null)) { string name = ((Object)clip).name; object goName; if (__instance == null) { goName = null; } else { GameObject gameObject = ((Component)__instance).gameObject; goName = ((gameObject != null) ? ((Object)gameObject).name : null); } AudioLogTracker.RegistrarSiempre(name, (string)goName); } } } [HarmonyPatch(typeof(AudioSource), "PlayOneShot", new Type[] { typeof(AudioClip), typeof(float) })] public class AudioSourcePlayOneShotVolPatch { private static void Prefix(AudioSource __instance, AudioClip clip) { if (!((Object)(object)clip == (Object)null)) { string name = ((Object)clip).name; object goName; if (__instance == null) { goName = null; } else { GameObject gameObject = ((Component)__instance).gameObject; goName = ((gameObject != null) ? ((Object)gameObject).name : null); } AudioLogTracker.RegistrarSiempre(name, (string)goName); } } } [HarmonyPatch(typeof(AudioSource), "PlayClipAtPoint", new Type[] { typeof(AudioClip), typeof(Vector3) })] public class AudioSourcePlayClipAtPointPatch { private static void Prefix(AudioClip clip, Vector3 position) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)clip == (Object)null)) { AudioLogTracker.RegistrarSiempre(((Object)clip).name, $"AtPoint:{position:F0}"); } } } [HarmonyPatch(typeof(AudioSource), "PlayClipAtPoint", new Type[] { typeof(AudioClip), typeof(Vector3), typeof(float) })] public class AudioSourcePlayClipAtPointVolPatch { private static void Prefix(AudioClip clip, Vector3 position) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)clip == (Object)null)) { AudioLogTracker.RegistrarSiempre(((Object)clip).name, $"AtPoint:{position:F0}"); } } } [HarmonyPatch(/*Could not decode attribute arguments.*/)] public class AudioSourceClipSetterPatch { private static void Prefix(AudioSource __instance, AudioClip value) { if (!((Object)(object)value == (Object)null)) { string name = ((Object)value).name; object obj; if (__instance == null) { obj = null; } else { GameObject gameObject = ((Component)__instance).gameObject; obj = ((gameObject != null) ? ((Object)gameObject).name : null); } AudioLogTracker.Registrar(name, "clipset|" + (string?)obj); } } } public class VideoTimescaleWatcher : MonoBehaviour { private float _lastScale = 1f; private readonly HashSet _pausadosPorNosotros = new HashSet(); private VideoPlayer[] _vpCache = null; private float _cacheTimer = 0f; private const float CACHE_INTERVAL = 2f; private void Update() { float timeScale = Time.timeScale; bool flag = timeScale == 0f; bool flag2 = timeScale != _lastScale; _lastScale = timeScale; if (!flag && !flag2) { return; } _cacheTimer -= Time.unscaledDeltaTime; if (_vpCache == null || _cacheTimer <= 0f) { _vpCache = Object.FindObjectsOfType(); _cacheTimer = 2f; } VideoPlayer[] vpCache = _vpCache; foreach (VideoPlayer val in vpCache) { if ((Object)(object)val == (Object)null) { continue; } if (flag) { if (val.isPlaying) { _pausadosPorNosotros.Add(((Object)val).GetInstanceID()); val.Pause(); } } else if (flag2) { int instanceID = ((Object)val).GetInstanceID(); if (val.isPaused && _pausadosPorNosotros.Contains(instanceID)) { _pausadosPorNosotros.Remove(instanceID); val.Play(); } } } if (!flag && flag2) { _pausadosPorNosotros.Clear(); } } } public static class CinematicaDuckingManager { public class DuckingSegmento { public uint FadeOutInicioMs; public uint SilencioDesdeMs; public uint RestoreDesdeMs; public uint RestoreFinMs; public bool Instantaneo; } public class DuckingConfig { public string WavPattern; public uint InicioMs; public uint FinMs; public float FadeDuckSec; public float FadeRestoreSec; public bool DuckearWanderers; public bool PreservarFX; public List Segmentos; } internal static readonly byte[] CurvaAtenuacion = new byte[16] { 0, 10, 20, 29, 51, 54, 39, 46, 21, 62, 41, 71, 92, 120, 158, 255 }; public static readonly List Configs = new List { new DuckingConfig { WavPattern = "VL_Mitu_1I_CS_Intro", InicioMs = 35170u, FinMs = 54890u, FadeDuckSec = 0.5f, FadeRestoreSec = 1.5f, DuckearWanderers = true, PreservarFX = false }, new DuckingConfig { WavPattern = "TaskiMaiden_01", InicioMs = 34450u, FinMs = 45000u, FadeDuckSec = 0.5f, FadeRestoreSec = 0.8f, DuckearWanderers = true, PreservarFX = true }, new DuckingConfig { WavPattern = "VL_VendingMachine_1I_CS_Intro", DuckearWanderers = true, PreservarFX = false, Segmentos = new List { new DuckingSegmento { FadeOutInicioMs = 22470u, SilencioDesdeMs = 23550u, RestoreDesdeMs = 27070u, RestoreFinMs = 27410u, Instantaneo = false }, new DuckingSegmento { FadeOutInicioMs = 28170u, SilencioDesdeMs = 28170u, RestoreDesdeMs = 32000u, RestoreFinMs = 35000u, Instantaneo = true } } } }; public static float WandererDuckFactor = 1f; private static DuckingConfig _cfgActiva = null; private static float _nivelDuck = 1f; private static bool _resetPendiente = false; private static readonly Dictionary _volsCapturados = new Dictionary(); public static void Tick(string wavFileName, uint posMs) { DuckingConfig duckingConfig = null; foreach (DuckingConfig config in Configs) { if (wavFileName.IndexOf(config.WavPattern, StringComparison.OrdinalIgnoreCase) >= 0) { duckingConfig = config; break; } } if (duckingConfig == null) { return; } if (_cfgActiva == null) { CapturarVolumenes(duckingConfig); } _cfgActiva = duckingConfig; _resetPendiente = true; float num; float num2; if (duckingConfig.Segmentos != null && duckingConfig.Segmentos.Count > 0) { num = 1f; num2 = 5f; foreach (DuckingSegmento segmento in duckingConfig.Segmentos) { if (posMs >= segmento.FadeOutInicioMs) { if (posMs < segmento.SilencioDesdeMs) { num = 0f; float num3 = (float)(segmento.SilencioDesdeMs - segmento.FadeOutInicioMs) / 1000f; num2 = (segmento.Instantaneo ? 100f : ((num3 > 0.01f) ? (1f / num3) : 100f)); break; } if (posMs < segmento.RestoreDesdeMs) { num = 0f; num2 = 100f; break; } if (posMs < segmento.RestoreFinMs) { num = 1f; float num4 = (float)(segmento.RestoreFinMs - segmento.RestoreDesdeMs) / 1000f; num2 = ((num4 > 0.01f) ? (1f / num4) : 100f); break; } } } } else { bool flag = posMs >= duckingConfig.InicioMs && posMs < duckingConfig.FinMs; num = (flag ? 0f : 1f); num2 = (flag ? (1f / duckingConfig.FadeDuckSec) : (1f / duckingConfig.FadeRestoreSec)); } float num5 = Mathf.MoveTowards(_nivelDuck, num, num2 * Time.unscaledDeltaTime); if (!Mathf.Approximately(num5, _nivelDuck)) { _nivelDuck = num5; AplicarBuses(duckingConfig, _nivelDuck); WandererDuckFactor = (duckingConfig.DuckearWanderers ? _nivelDuck : 1f); } } public static void Reset() { if (_resetPendiente || !(_nivelDuck >= 1f)) { _resetPendiente = false; _nivelDuck = 1f; WandererDuckFactor = 1f; if (_cfgActiva != null) { AplicarBuses(_cfgActiva, 1f); _cfgActiva = null; } _volsCapturados.Clear(); } } private static void CapturarVolumenes(DuckingConfig cfg) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Invalid comparison between Unknown and I4 //IL_0042: Unknown result type (might be due to invalid IL or missing references) _volsCapturados.Clear(); string[] array = ObtenerBuses(cfg); Bus val = default(Bus); foreach (string text in array) { float value = 1f; try { System studioSystem = RuntimeManager.StudioSystem; if ((int)((System)(ref studioSystem)).getBus(text, ref val) == 0) { ((Bus)(ref val)).getVolume(ref value); } } catch { } _volsCapturados[text] = value; } } private static string[] ObtenerBuses(DuckingConfig cfg) { if (cfg.PreservarFX) { return new string[2] { "bus:/Music", "bus:/SFX/Music" }; } return new string[6] { "bus:/Music", "bus:/Ambience", "bus:/SFX/Ambience", "bus:/SFX/Music", "bus:/SFX", "bus:/FX" }; } private static void AplicarBuses(DuckingConfig cfg, float duckFactor) { string[] array = ObtenerBuses(cfg); foreach (string busPath in array) { SetBusVol(busPath, duckFactor); } } private static void SetBusVol(string busPath, float duckFactor) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Invalid comparison between Unknown and I4 //IL_003a: Unknown result type (might be due to invalid IL or missing references) if (!_volsCapturados.TryGetValue(busPath, out var value)) { value = 1f; } try { System studioSystem = RuntimeManager.StudioSystem; Bus val = default(Bus); if ((int)((System)(ref studioSystem)).getBus(busPath, ref val) == 0) { ((Bus)(ref val)).setVolume(value * duckFactor); } } catch { } } } public class WandererGestor : MonoBehaviour { private static WandererGestor _instancia = null; private readonly HashSet _yaReemplazados = new HashSet(); private int _frame = 0; private static readonly Dictionary _posicionGuardada = new Dictionary(); private static readonly Dictionary _posNativoTakeover = new Dictionary(); private static readonly Dictionary _tiempoTakeover = new Dictionary(); private static readonly List<(Sound s, Channel c)> _todosLosCanales = new List<(Sound, Channel)>(); private static bool _muteado = false; public static readonly HashSet _nativosDetenidos = new HashSet(); public static string BuscarWAV(string pathSinExt) { string text = pathSinExt + "_es.wav"; if (AssetPack.Existe(text)) { return text; } string text2 = pathSinExt + "_es.ogg"; if (AssetPack.Existe(text2)) { return text2; } string text3 = pathSinExt + ".wav"; if (AssetPack.Existe(text3)) { return text3; } string text4 = pathSinExt + ".ogg"; if (AssetPack.Existe(text4)) { return text4; } return null; } internal static bool PosicionNatural(int emitterId, out uint posMs) { posMs = 0u; if (!_posNativoTakeover.TryGetValue(emitterId, out var value) || !_tiempoTakeover.TryGetValue(emitterId, out var value2)) { return false; } posMs = value + (uint)((Time.realtimeSinceStartup - value2) * 1000f); return true; } public static void MutearRadio() { _muteado = true; if ((Object)(object)_instancia != (Object)null) { _instancia.RestaurarEmittersAhora(); } } public static void DesmuteearRadio() { _muteado = false; } public void RestaurarEmittersAhora() { StudioEventEmitter[] array = Object.FindObjectsOfType(); foreach (StudioEventEmitter val in array) { if (!((Object)(object)val == (Object)null) && !(((Object)((Component)val).gameObject).name != "FMOD Emitter - Wanderer")) { ReanudarEmitterNativo(val); } } } public unsafe static void ReanudarEmitterNativo(StudioEventEmitter em) { //IL_03ae: Unknown result type (might be due to invalid IL or missing references) //IL_03b8: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_026e: Unknown result type (might be due to invalid IL or missing references) //IL_0273: Unknown result type (might be due to invalid IL or missing references) //IL_03bf: Unknown result type (might be due to invalid IL or missing references) //IL_03c2: Invalid comparison between Unknown and I4 //IL_017f: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0282: Unknown result type (might be due to invalid IL or missing references) //IL_03c4: Unknown result type (might be due to invalid IL or missing references) //IL_03c7: Invalid comparison between Unknown and I4 //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Invalid comparison between Unknown and I4 //IL_0289: Unknown result type (might be due to invalid IL or missing references) //IL_028c: Invalid comparison between Unknown and I4 //IL_03e8: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Unknown result type (might be due to invalid IL or missing references) //IL_019c: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Invalid comparison between Unknown and I4 //IL_028e: Unknown result type (might be due to invalid IL or missing references) //IL_0291: Invalid comparison between Unknown and I4 //IL_01b3: Unknown result type (might be due to invalid IL or missing references) //IL_01bb: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_01c5: Invalid comparison between Unknown and I4 //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_01d2: Unknown result type (might be due to invalid IL or missing references) //IL_034a: Unknown result type (might be due to invalid IL or missing references) //IL_034f: Unknown result type (might be due to invalid IL or missing references) //IL_01d9: Unknown result type (might be due to invalid IL or missing references) //IL_01dc: Invalid comparison between Unknown and I4 //IL_01de: Unknown result type (might be due to invalid IL or missing references) //IL_01e1: Invalid comparison between Unknown and I4 //IL_036d: Unknown result type (might be due to invalid IL or missing references) //IL_0381: 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_0106: 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) if ((Object)(object)em == (Object)null) { return; } try { bool flag = false; FieldInfo field = typeof(StudioEventEmitter).GetField("instance", BindingFlags.Instance | BindingFlags.NonPublic); if (field != null) { EventInstance val = (EventInstance)field.GetValue(em); PLAYBACK_STATE val2 = default(PLAYBACK_STATE); if (((EventInstance)(ref val)).isValid() && (int)((EventInstance)(ref val)).getPlaybackState(ref val2) == 0 && (int)val2 != 2 && (int)val2 != 4) { flag = true; ((EventInstance)(ref val)).setPaused(false); ((EventInstance)(ref val)).setVolume(1f); if (_nativosDetenidos.Contains(((Object)em).GetInstanceID())) { try { if (!_posicionGuardada.TryGetValue(((Object)em).GetInstanceID(), out var value) || value == 0) { PosicionNatural(((Object)em).GetInstanceID(), out value); } EventDescription val3 = default(EventDescription); int num = default(int); if (value != 0 && (int)((EventInstance)(ref val)).getDescription(ref val3) == 0 && ((EventDescription)(ref val3)).isValid() && (int)((EventDescription)(ref val3)).getLength(ref num) == 0 && num > 500) { ((EventInstance)(ref val)).setTimelinePosition((int)(value % (uint)num)); } } catch { } _nativosDetenidos.Remove(((Object)em).GetInstanceID()); ControlDoblajePlugin.Log.LogInfo((object)("[WandererGestor] Nativo despertado (unpause): " + ((Object)((Component)em).gameObject).name)); } } } if (flag) { return; } bool flag2 = false; RESULT val4 = (RESULT)30; if (field != null) { try { EventInstance val5 = (EventInstance)field.GetValue(em); if (((EventInstance)(ref val5)).isValid()) { ((EventInstance)(ref val5)).setVolume(1f); val4 = ((EventInstance)(ref val5)).start(); PLAYBACK_STATE val6 = default(PLAYBACK_STATE); if ((int)val4 == 0 && (int)((EventInstance)(ref val5)).getPlaybackState(ref val6) == 0 && (int)val6 != 2 && (int)val6 != 4) { flag2 = true; } } } catch { } } if (!flag2) { try { try { em.Stop(); } catch { } FieldInfo field2 = typeof(StudioEventEmitter).GetField("hasTriggered", BindingFlags.Instance | BindingFlags.NonPublic); if (field2 != null) { field2.SetValue(em, false); } em.Play(); if (field != null) { EventInstance val7 = (EventInstance)field.GetValue(em); PLAYBACK_STATE val8 = default(PLAYBACK_STATE); if (((EventInstance)(ref val7)).isValid() && (int)((EventInstance)(ref val7)).getPlaybackState(ref val8) == 0 && (int)val8 != 2 && (int)val8 != 4) { flag2 = true; } } } catch { } } if (!flag2) { ControlDoblajePlugin.Log.LogWarning((object)("[WandererGestor] Relanzamiento FALLÓ (" + ((Object)((Component)em).gameObject).name + ") start=" + ((object)(*(RESULT*)(&val4))/*cast due to .constrained prefix*/).ToString() + " — reintentará")); } else { if (!flag2) { return; } try { if (_posicionGuardada.TryGetValue(((Object)em).GetInstanceID(), out var value2) && value2 != 0 && field != null) { EventInstance val9 = (EventInstance)field.GetValue(em); if (((EventInstance)(ref val9)).isValid()) { int num2 = 0; bool flag3 = false; try { EventDescription val10 = default(EventDescription); flag3 = (int)((EventInstance)(ref val9)).getDescription(ref val10) == 0 && ((EventDescription)(ref val10)).isValid() && (int)((EventDescription)(ref val10)).getLength(ref num2) == 0 && num2 > 500; } catch { } if (flag3) { ((EventInstance)(ref val9)).setTimelinePosition((int)(value2 % (uint)num2)); PLAYBACK_STATE val11 = default(PLAYBACK_STATE); if ((int)((EventInstance)(ref val9)).getPlaybackState(ref val11) == 0 && ((int)val11 == 2 || (int)val11 == 4)) { ControlDoblajePlugin.Log.LogWarning((object)"[WandererGestor] seek de continuidad mató el evento — reviviendo SIN seek"); ((EventInstance)(ref val9)).start(); } } } } } catch { } _nativosDetenidos.Remove(((Object)em).GetInstanceID()); ControlDoblajePlugin.Log.LogInfo((object)("[WandererGestor] Nativo relanzado: " + ((Object)((Component)em).gameObject).name)); } } catch { } } public static bool NativoDetenido(int id) { return _nativosDetenidos.Contains(id); } public static void InyectarSiNecesario() { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Expected O, but got Unknown if (!((Object)(object)_instancia != (Object)null)) { GameObject val = new GameObject("_WandererGestor"); Object.DontDestroyOnLoad((Object)(object)val); _instancia = val.AddComponent(); ControlDoblajePlugin.Log.LogInfo((object)"[WandererGestor] Inyectado correctamente."); } } private static void SilenciarEmitter(StudioEventEmitter emitter) { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) if (_muteado) { return; } try { FieldInfo field = typeof(StudioEventEmitter).GetField("instance", BindingFlags.Instance | BindingFlags.NonPublic); if (!(field == null)) { EventInstance val = (EventInstance)field.GetValue(emitter); if (((EventInstance)(ref val)).isValid()) { ((EventInstance)(ref val)).setVolume(0f); ((EventInstance)(ref val)).setPaused(true); _nativosDetenidos.Add(((Object)emitter).GetInstanceID()); } } } catch { } } private void Update() { //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0239: Unknown result type (might be due to invalid IL or missing references) //IL_023e: Unknown result type (might be due to invalid IL or missing references) //IL_024d: Unknown result type (might be due to invalid IL or missing references) if (++_frame % 15 != 0) { return; } WandererAttackSoundRunner runnerActivo = WandererAttackPlayer.RunnerActivo; if ((Object)(object)runnerActivo != (Object)null && runnerActivo.IsListo) { try { StudioListener val = ListenerCache.Get(); Vector3 posListener = (((Object)(object)val != (Object)null) ? ((Component)val).transform.position : (((Object)(object)Camera.main != (Object)null) ? ((Component)Camera.main).transform.position : Vector3.zero)); runnerActivo.ActualizarVolumen(posListener); } catch { } } StudioEventEmitter[] array = Object.FindObjectsOfType(); int num = default(int); foreach (StudioEventEmitter val2 in array) { if ((Object)(object)val2 == (Object)null || ((Object)((Component)val2).gameObject).name != "FMOD Emitter - Wanderer") { continue; } int instanceID = ((Object)val2).GetInstanceID(); bool flag = val2.IsPlaying(); if (!ControlDoblajePlugin.PersonajeActivo.TryGetValue("Wanderer", out var value) || !value) { if (_muteado) { ReanudarEmitterNativo(val2); continue; } if (!flag && NativoDetenido(instanceID)) { ReanudarEmitterNativo(val2); } _yaReemplazados.Remove(instanceID); continue; } if (_yaReemplazados.Contains(instanceID)) { if (flag) { SilenciarEmitter(val2); } continue; } if (!flag) { if (NativoDetenido(instanceID)) { ReanudarEmitterNativo(val2); } continue; } string path = Path.Combine(ControlDoblajePlugin.VoicesPath, "Wanderer"); string text = BuscarWAV(Path.Combine(path, "USB_LP_Wanderer_RadioDry")); string text2 = BuscarWAV(Path.Combine(path, "USB_LP_Wanderer_RadioWet")); if (text == null && text2 == null) { continue; } _yaReemplazados.Add(instanceID); try { FieldInfo field = typeof(StudioEventEmitter).GetField("instance", BindingFlags.Instance | BindingFlags.NonPublic); if (field != null) { EventInstance val3 = (EventInstance)field.GetValue(val2); if (((EventInstance)(ref val3)).isValid() && (int)((EventInstance)(ref val3)).getTimelinePosition(ref num) == 0 && num > 0) { _posicionGuardada[instanceID] = (uint)num; if (!_posNativoTakeover.ContainsKey(instanceID)) { _posNativoTakeover[instanceID] = (uint)num; _tiempoTakeover[instanceID] = Time.realtimeSinceStartup; } } } } catch { } SilenciarEmitter(val2); ManualLogSource log = ControlDoblajePlugin.Log; string name = ((Object)((Component)val2).gameObject).name; Transform parent = ((Component)val2).transform.parent; log.LogInfo((object)("[WandererRadio] Emitter detectado playing: " + name + " parent=" + ((parent != null) ? ((Object)parent).name : null))); ((MonoBehaviour)this).StartCoroutine(RadioLoop(val2, text, text2)); } } private unsafe IEnumerator RadioLoop(StudioEventEmitter emitter, string rutaDryR, string rutaWetR) { bool tieneDry = rutaDryR != null; bool tieneWet = rutaWetR != null; ControlDoblajePlugin.Log.LogInfo((object)("[WandererRadio] Iniciando loop para " + ((Object)((Component)emitter).gameObject).name)); Sound sDry = default(Sound); Sound sWet = default(Sound); Channel cDry = default(Channel); Channel cWet = default(Channel); MODE modo = (MODE)524434; System coreSystem = RuntimeManager.CoreSystem; ChannelGroup grupo = default(ChannelGroup); ((System)(ref coreSystem)).getMasterChannelGroup(ref grupo); ControlDoblajePlugin.Log.LogInfo((object)"[WandererRadio] Bus=CoreMaster (stable root)"); if (tieneDry) { CREATESOUNDEXINFO ex = default(CREATESOUNDEXINFO); ex.cbsize = Marshal.SizeOf(ex); RESULT r = AudioPack.CrearSound(RuntimeManager.CoreSystem, rutaDryR, modo, ref ex, out sDry); ControlDoblajePlugin.Log.LogInfo((object)("[WandererRadio] createSound Dry=" + ((object)(*(RESULT*)(&r))/*cast due to .constrained prefix*/).ToString())); if ((int)r == 0) { coreSystem = RuntimeManager.CoreSystem; ((System)(ref coreSystem)).playSound(sDry, grupo, false, ref cDry); ((Channel)(ref cDry)).setVolume(0f); ((Channel)(ref cDry)).set3DMinMaxDistance(100f, 10000f); _todosLosCanales.Add((sDry, cDry)); int emId2 = ((Object)emitter).GetInstanceID(); bool posRestaurada = false; if (!_posicionGuardada.TryGetValue(emId2, out var posSaved) || posSaved == 0) { PosicionNatural(emId2, out posSaved); } if (posSaved != 0) { try { uint lenD = 0u; ((Sound)(ref sDry)).getLength(ref lenD, (TIMEUNIT)1); uint posSeed = ((lenD > 500) ? (posSaved % lenD) : posSaved); ((Channel)(ref cDry)).setPosition(posSeed, (TIMEUNIT)1); posRestaurada = true; } catch { } } if (!posRestaurada) { try { FieldInfo fi = typeof(StudioEventEmitter).GetField("instance", BindingFlags.Instance | BindingFlags.NonPublic); if (fi != null) { EventInstance inst = (EventInstance)fi.GetValue(emitter); if (((EventInstance)(ref inst)).isValid()) { int posMs = 0; ((EventInstance)(ref inst)).getTimelinePosition(ref posMs); if (posMs > 0) { ((Channel)(ref cDry)).setPosition((uint)posMs, (TIMEUNIT)1); } } } } catch { } } } else { tieneDry = false; } } if (tieneWet) { CREATESOUNDEXINFO ex2 = default(CREATESOUNDEXINFO); ex2.cbsize = Marshal.SizeOf(ex2); RESULT r2 = AudioPack.CrearSound(RuntimeManager.CoreSystem, rutaWetR, modo, ref ex2, out sWet); ControlDoblajePlugin.Log.LogInfo((object)("[WandererRadio] createSound Wet=" + ((object)(*(RESULT*)(&r2))/*cast due to .constrained prefix*/).ToString())); if ((int)r2 == 0) { coreSystem = RuntimeManager.CoreSystem; ((System)(ref coreSystem)).playSound(sWet, grupo, false, ref cWet); ((Channel)(ref cWet)).setVolume(0f); ((Channel)(ref cWet)).set3DMinMaxDistance(100f, 10000f); _todosLosCanales.Add((sWet, cWet)); try { if (tieneDry) { uint posDry = 0u; ((Channel)(ref cDry)).getPosition(ref posDry, (TIMEUNIT)1); if (posDry != 0) { ((Channel)(ref cWet)).setPosition(posDry, (TIMEUNIT)1); } } } catch { } } else { tieneWet = false; } } if (!tieneDry && !tieneWet) { _yaReemplazados.Remove(((Object)emitter).GetInstanceID()); yield break; } ControlDoblajePlugin.Log.LogInfo((object)("[WandererRadio] Loop activo dry=" + tieneDry + " wet=" + tieneWet)); try { uint lenD9 = 0u; if (tieneDry) { ((Sound)(ref sDry)).getLength(ref lenD9, (TIMEUNIT)1); } else if (tieneWet) { ((Sound)(ref sWet)).getLength(ref lenD9, (TIMEUNIT)1); } int lenN9 = 0; FieldInfo fi9 = typeof(StudioEventEmitter).GetField("instance", BindingFlags.Instance | BindingFlags.NonPublic); if (fi9 != null) { EventInstance i9 = (EventInstance)fi9.GetValue(emitter); EventDescription d9 = default(EventDescription); if (((EventInstance)(ref i9)).isValid() && (int)((EventInstance)(ref i9)).getDescription(ref d9) == 0 && ((EventDescription)(ref d9)).isValid()) { ((EventDescription)(ref d9)).getLength(ref lenN9); } } ControlDoblajePlugin.Log.LogInfo((object)("[WandererRadio-DIAG] lenDub=" + lenD9 + "ms lenEventoNativo=" + lenN9 + "ms")); } catch { } bool estabaPausado = false; bool muteAnterior = _muteado; int tick = 0; float rampElapsed = 0f; int posNms = default(int); uint pd = default(uint); uint pw = default(uint); while ((Object)(object)emitter != (Object)null && ((Component)emitter).gameObject.activeInHierarchy && _yaReemplazados.Contains(((Object)emitter).GetInstanceID())) { SilenciarEmitter(emitter); bool pausar = Time.timeScale == 0f; if (pausar != estabaPausado) { if (tieneDry) { ((Channel)(ref cDry)).setPaused(pausar); } if (tieneWet) { ((Channel)(ref cWet)).setPaused(pausar); } estabaPausado = pausar; } if (muteAnterior && !_muteado) { try { uint posNat = 0u; bool anclado = false; FieldInfo fiN = typeof(StudioEventEmitter).GetField("instance", BindingFlags.Instance | BindingFlags.NonPublic); if (fiN != null) { EventInstance instN = (EventInstance)fiN.GetValue(emitter); if (((EventInstance)(ref instN)).isValid() && (int)((EventInstance)(ref instN)).getTimelinePosition(ref posNms) == 0 && posNms > 0) { posNat = (uint)posNms; anclado = true; } } if (!anclado) { PosicionNatural(((Object)emitter).GetInstanceID(), out posNat); } if (posNat != 0) { uint lenRef = 0u; if (tieneDry) { ((Sound)(ref sDry)).getLength(ref lenRef, (TIMEUNIT)1); } else if (tieneWet) { ((Sound)(ref sWet)).getLength(ref lenRef, (TIMEUNIT)1); } uint dest = ((lenRef > 500) ? (posNat % lenRef) : posNat); if (tieneDry) { ((Channel)(ref cDry)).setPosition(dest, (TIMEUNIT)1); } if (tieneWet) { ((Channel)(ref cWet)).setPosition(dest, (TIMEUNIT)1); } _posicionGuardada[((Object)emitter).GetInstanceID()] = dest; ControlDoblajePlugin.Log.LogInfo((object)("[WandererRadio] Dub anclado al handoff: " + dest + "ms (fuente=" + (anclado ? "nativo" : "reloj") + ")")); } } catch { } rampElapsed = 0f; } muteAnterior = _muteado; if (!pausar) { rampElapsed += 0.1f; float rampFactor = ((rampElapsed < 1f) ? Mathf.SmoothStep(0f, 1f, rampElapsed / 1f) : 1f); Vector3 posEm = ((Component)emitter).transform.position; VECTOR pos3D = new VECTOR { x = posEm.x, y = posEm.y, z = posEm.z }; VECTOR vel3D = new VECTOR { x = 0f, y = 0f, z = 0f }; if (tieneDry) { ((Channel)(ref cDry)).set3DAttributes(ref pos3D, ref vel3D); } if (tieneWet) { ((Channel)(ref cWet)).set3DAttributes(ref pos3D, ref vel3D); } StudioListener listener2 = ListenerCache.Get(); Vector3 posL = (((Object)(object)listener2 != (Object)null) ? ((Component)listener2).transform.position : (((Object)(object)Camera.main != (Object)null) ? ((Component)Camera.main).transform.position : posEm)); float dist = Vector3.Distance(posL, posEm); float wetT = Mathf.Clamp01((dist - 5f) / 25f); float falloff = Mathf.Clamp01(5f / Mathf.Max(dist, 0.1f)); if (falloff > 0.05f && dist > 1f) { try { Vector3 rayOrig = posL + Vector3.up * 0.5f; Vector3 val = posEm - rayOrig; Vector3 rayDir = ((Vector3)(ref val)).normalized; float rayDist = Mathf.Max(dist - 0.5f, 0.1f); RaycastHit[] hits = Physics.RaycastAll(rayOrig, rayDir, rayDist); int solidWalls = 0; RaycastHit[] array = hits; for (int j = 0; j < array.Length; j++) { RaycastHit h = array[j]; if (!((Object)(object)((RaycastHit)(ref h)).collider == (Object)null) && !((RaycastHit)(ref h)).collider.isTrigger) { Bounds bounds = ((RaycastHit)(ref h)).collider.bounds; float maxSize = Mathf.Max(new float[3] { ((Bounds)(ref bounds)).size.x, ((Bounds)(ref bounds)).size.y, ((Bounds)(ref bounds)).size.z }); if (maxSize > 1f) { solidWalls++; } } } if (solidWalls > 0) { falloff *= Mathf.Pow(0.5f, (float)solidWalls); } } catch { } } float busRadio = MultiPistaRunner.LeerVolBus("bus:/Ambience") * MultiPistaRunner.LeerVolBus("bus:/"); float comp = (_muteado ? 0f : (busRadio * CinematicaDuckingManager.WandererDuckFactor)); if (dist > 45f) { falloff *= Mathf.Clamp01((55f - dist) / 10f); } float volDry = (tieneDry ? (falloff * (1f - wetT) * comp * rampFactor) : 0f); float volWet = (tieneWet ? (falloff * wetT * comp * rampFactor) : 0f); if (tieneDry) { ((Channel)(ref cDry)).setVolume(volDry * 2.4f); } if (tieneWet) { ((Channel)(ref cWet)).setVolume(volWet * 2.4f); } if (tieneDry) { try { if ((int)((Channel)(ref cDry)).getPosition(ref pd, (TIMEUNIT)1) == 0 && pd != 0) { _posicionGuardada[((Object)emitter).GetInstanceID()] = pd; if (tieneWet && tick % 10 == 0 && (int)((Channel)(ref cWet)).getPosition(ref pw, (TIMEUNIT)1) == 0) { long drift = (long)pd - (long)pw; if (drift < 0) { drift = -drift; } if (drift > 60) { ((Channel)(ref cWet)).setPosition(pd, (TIMEUNIT)1); } } } } catch { } } if (tick % 30 == 0) { bool ipD = false; bool ipW = false; float audD = -1f; float audW = -1f; try { if (tieneDry) { ((Channel)(ref cDry)).isPlaying(ref ipD); ((Channel)(ref cDry)).getAudibility(ref audD); } } catch { } try { if (tieneWet) { ((Channel)(ref cWet)).isPlaying(ref ipW); ((Channel)(ref cWet)).getAudibility(ref audW); } } catch { } ControlDoblajePlugin.Log.LogInfo((object)("[WandererRadio-DIAG] dist=" + dist.ToString("F1") + " wetT=" + wetT.ToString("F2") + " volDry=" + volDry.ToString("F2") + " volWet=" + volWet.ToString("F2") + " bus=" + busRadio.ToString("F2") + " duck=" + CinematicaDuckingManager.WandererDuckFactor.ToString("F2") + " mute=" + _muteado + " dry[play=" + ipD + " aud=" + audD.ToString("F2") + "] wet[play=" + ipW + " aud=" + audW.ToString("F2") + "]")); if ((tieneDry || tieneWet) && !ipD && !ipW) { ControlDoblajePlugin.Log.LogWarning((object)"[WandererRadio] canales muertos — reiniciando takeover"); _yaReemplazados.Remove(((Object)emitter).GetInstanceID()); break; } } } tick++; yield return (object)new WaitForSecondsRealtime(0.1f); } ControlDoblajePlugin.Log.LogInfo((object)("[WandererRadio] Loop terminado " + (((Object)(object)emitter != (Object)null) ? ((Object)((Component)emitter).gameObject).name : "null"))); if ((Object)(object)emitter != (Object)null) { int emId3 = ((Object)emitter).GetInstanceID(); try { uint posMs2 = 0u; if (tieneDry) { ((Channel)(ref cDry)).getPosition(ref posMs2, (TIMEUNIT)1); } if (posMs2 != 0) { _posicionGuardada[emId3] = posMs2; } } catch { } } _yaReemplazados.Remove(((Object)(object)emitter != (Object)null) ? ((Object)emitter).GetInstanceID() : (-1)); for (int _ci = _todosLosCanales.Count - 1; _ci >= 0; _ci--) { (Sound s, Channel c) e = _todosLosCanales[_ci]; if ((tieneDry && e.s.handle == sDry.handle) || (tieneWet && e.s.handle == sWet.handle)) { _todosLosCanales.RemoveAt(_ci); } } try { if (tieneDry) { ((Channel)(ref cDry)).stop(); ((Sound)(ref sDry)).release(); } } catch { } try { if (tieneWet) { ((Channel)(ref cWet)).stop(); ((Sound)(ref sWet)).release(); } } catch { } if ((Object)(object)emitter != (Object)null) { ReanudarEmitterNativo(emitter); ControlDoblajePlugin.Log.LogInfo((object)"[WandererRadio] Emitter nativo reanudado (vol 1 / re-Play)"); } } public static void LimpiarInstancia() { //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0036: 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) if ((Object)(object)_instancia == (Object)null) { return; } foreach (var todosLosCanale in _todosLosCanales) { var (val, val2) = todosLosCanale; try { ((Channel)(ref val2)).stop(); } catch { } try { ((Sound)(ref val)).release(); } catch { } } _todosLosCanales.Clear(); ((MonoBehaviour)_instancia).StopAllCoroutines(); _instancia._yaReemplazados.Clear(); } private void OnDestroy() { if ((Object)(object)_instancia == (Object)(object)this) { _instancia = null; } } } public class HeadtombsGestor : MonoBehaviour { private static HeadtombsGestor _instancia = null; private readonly HashSet _yaReemplazados = new HashSet(); private int _frame = 0; private static readonly List<(Sound s, Channel c)> _todosLosCanales = new List<(Sound, Channel)>(); private const string EMITTER_GO_NAME = "GR1_L_HeadtombRamble"; private const string WAV_CARPETA = "HeadTombs"; private const string WAV_NOMBRE = "D1G_Headtombs_Mumble.wav"; private const string PERSONAJE_KEY = "HeadTombs"; private const float MIN_DIST = 12.25f; private const float MAX_DIST = 24.84f; public static void InyectarSiNecesario() { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Expected O, but got Unknown if (!((Object)(object)_instancia != (Object)null)) { GameObject val = new GameObject("_HeadtombsGestor"); Object.DontDestroyOnLoad((Object)(object)val); _instancia = val.AddComponent(); ControlDoblajePlugin.Log.LogInfo((object)"[HeadtombsGestor] Inyectado."); } } public static void LimpiarInstancia() { //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0036: 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) if ((Object)(object)_instancia == (Object)null) { return; } foreach (var todosLosCanale in _todosLosCanales) { var (val, val2) = todosLosCanale; try { ((Channel)(ref val2)).stop(); } catch { } try { ((Sound)(ref val)).release(); } catch { } } _todosLosCanales.Clear(); ((MonoBehaviour)_instancia).StopAllCoroutines(); _instancia._yaReemplazados.Clear(); } private static void SilenciarEmitter(StudioEventEmitter emitter) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) try { FieldInfo field = typeof(StudioEventEmitter).GetField("instance", BindingFlags.Instance | BindingFlags.NonPublic); if (!(field == null)) { EventInstance val = (EventInstance)field.GetValue(emitter); if (((EventInstance)(ref val)).isValid()) { ((EventInstance)(ref val)).setVolume(0f); ((EventInstance)(ref val)).setPaused(true); WandererGestor._nativosDetenidos.Add(((Object)emitter).GetInstanceID()); } } } catch { } } private void Update() { if (++_frame % 15 != 0) { return; } StudioEventEmitter[] array = Object.FindObjectsOfType(); foreach (StudioEventEmitter val in array) { if ((Object)(object)val == (Object)null || !((Object)((Component)val).gameObject).name.EndsWith("GR1_L_HeadtombRamble", StringComparison.OrdinalIgnoreCase)) { continue; } int instanceID = ((Object)val).GetInstanceID(); bool flag = val.IsPlaying(); if (!ControlDoblajePlugin.PersonajeActivo.TryGetValue("HeadTombs", out var value) || !value) { if (!flag && WandererGestor.NativoDetenido(instanceID)) { WandererGestor.ReanudarEmitterNativo(val); } _yaReemplazados.Remove(instanceID); continue; } if (_yaReemplazados.Contains(instanceID)) { if (flag) { SilenciarEmitter(val); } continue; } if (!flag) { if (WandererGestor.NativoDetenido(instanceID)) { WandererGestor.ReanudarEmitterNativo(val); } continue; } string text = WandererGestor.BuscarWAV(Path.Combine(ControlDoblajePlugin.VoicesPath, "HeadTombs", Path.GetFileNameWithoutExtension("D1G_Headtombs_Mumble.wav"))); if (text != null) { _yaReemplazados.Add(instanceID); SilenciarEmitter(val); ManualLogSource log = ControlDoblajePlugin.Log; string name = ((Object)((Component)val).gameObject).name; Transform parent = ((Component)val).transform.parent; log.LogInfo((object)("[HeadtombsGestor] Emitter detectado: " + name + " parent=" + ((parent != null) ? ((Object)parent).name : null))); ((MonoBehaviour)this).StartCoroutine(MumbleLoop(val, text)); } } } private unsafe IEnumerator MumbleLoop(StudioEventEmitter emitter, string wavPath) { ControlDoblajePlugin.Log.LogInfo((object)("[HeadtombsGestor] Iniciando loop: " + wavPath)); System coreSystem = RuntimeManager.CoreSystem; ChannelGroup grupo = default(ChannelGroup); ((System)(ref coreSystem)).getMasterChannelGroup(ref grupo); ControlDoblajePlugin.Log.LogInfo((object)"[HeadtombsGestor] Bus=CoreMaster (stable root)"); MODE modo = (MODE)524562; CREATESOUNDEXINFO ex = default(CREATESOUNDEXINFO); ex.cbsize = Marshal.SizeOf(ex); Sound sound; RESULT r = AudioPack.CrearSound(RuntimeManager.CoreSystem, wavPath, modo, ref ex, out sound); ControlDoblajePlugin.Log.LogInfo((object)("[HeadtombsGestor] createSound=" + ((object)(*(RESULT*)(&r))/*cast due to .constrained prefix*/).ToString())); if ((int)r > 0) { _yaReemplazados.Remove(((Object)emitter).GetInstanceID()); yield break; } coreSystem = RuntimeManager.CoreSystem; Channel canal = default(Channel); ((System)(ref coreSystem)).playSound(sound, grupo, false, ref canal); ((Channel)(ref canal)).setVolume(0f); ((Channel)(ref canal)).set3DMinMaxDistance(100f, 10000f); _todosLosCanales.Add((sound, canal)); try { FieldInfo fi = typeof(StudioEventEmitter).GetField("instance", BindingFlags.Instance | BindingFlags.NonPublic); if (fi != null) { EventInstance inst = (EventInstance)fi.GetValue(emitter); if (((EventInstance)(ref inst)).isValid()) { int posMs = 0; ((EventInstance)(ref inst)).getTimelinePosition(ref posMs); if (posMs > 0) { ((Channel)(ref canal)).setPosition((uint)posMs, (TIMEUNIT)1); } } } } catch { } ControlDoblajePlugin.Log.LogInfo((object)"[HeadtombsGestor] Loop activo"); bool estabaPausado = false; int tick = 0; float rampElapsed = 0f; while ((Object)(object)emitter != (Object)null && ((Component)emitter).gameObject.activeInHierarchy && _yaReemplazados.Contains(((Object)emitter).GetInstanceID())) { SilenciarEmitter(emitter); bool pausar = Time.timeScale == 0f; if (pausar != estabaPausado) { ((Channel)(ref canal)).setPaused(pausar); estabaPausado = pausar; } if (!pausar) { rampElapsed += 0.1f; float rampFactor = ((rampElapsed < 0.5f) ? Mathf.SmoothStep(0f, 1f, rampElapsed / 0.5f) : 1f); Vector3 posEm = ((Component)emitter).transform.position; VECTOR pos3D = new VECTOR { x = posEm.x, y = posEm.y, z = posEm.z }; VECTOR vel3D = new VECTOR { x = 0f, y = 0f, z = 0f }; ((Channel)(ref canal)).set3DAttributes(ref pos3D, ref vel3D); StudioListener listener = ListenerCache.Get(); Vector3 posL = (((Object)(object)listener != (Object)null) ? ((Component)listener).transform.position : (((Object)(object)Camera.main != (Object)null) ? ((Component)Camera.main).transform.position : posEm)); float dist = Vector3.Distance(posL, posEm); float vol = ((dist <= 12.25f) ? 1f : ((!(dist >= 24.84f)) ? (1f - (dist - 12.25f) / 12.59f) : 0f)); float busHT = MultiPistaRunner.LeerVolBus("bus:/Ambience") * MultiPistaRunner.LeerVolBus("bus:/"); ((Channel)(ref canal)).setVolume(vol * rampFactor * 1f * busHT); if (tick % 30 == 0 && ControlDoblajePlugin.LogVerboso) { ControlDoblajePlugin.Log.LogInfo((object)("[HeadtombsGestor] dist=" + dist.ToString("F1") + " vol=" + vol.ToString("F2"))); } } tick++; yield return (object)new WaitForSecondsRealtime(0.1f); } ControlDoblajePlugin.Log.LogInfo((object)"[HeadtombsGestor] Loop terminado"); _yaReemplazados.Remove(((Object)(object)emitter != (Object)null) ? ((Object)emitter).GetInstanceID() : (-1)); for (int ci = _todosLosCanales.Count - 1; ci >= 0; ci--) { if (_todosLosCanales[ci].s.handle == sound.handle) { _todosLosCanales.RemoveAt(ci); } } try { ((Channel)(ref canal)).stop(); ((Sound)(ref sound)).release(); } catch { } if ((Object)(object)emitter != (Object)null) { WandererGestor.ReanudarEmitterNativo(emitter); } } private void OnDestroy() { if ((Object)(object)_instancia == (Object)(object)this) { _instancia = null; } } } public static class ObjCargador { private static float Pf(string s) { return float.Parse(s, CultureInfo.InvariantCulture); } public static Mesh Cargar(string ruta) { //IL_0746: Unknown result type (might be due to invalid IL or missing references) //IL_074d: Expected O, but got Unknown //IL_016b: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_01e5: Unknown result type (might be due to invalid IL or missing references) //IL_0308: Unknown result type (might be due to invalid IL or missing references) //IL_0327: Unknown result type (might be due to invalid IL or missing references) //IL_0322: Unknown result type (might be due to invalid IL or missing references) //IL_0353: Unknown result type (might be due to invalid IL or missing references) //IL_0372: Unknown result type (might be due to invalid IL or missing references) //IL_036d: Unknown result type (might be due to invalid IL or missing references) //IL_039e: Unknown result type (might be due to invalid IL or missing references) //IL_03bd: Unknown result type (might be due to invalid IL or missing references) //IL_03b8: Unknown result type (might be due to invalid IL or missing references) //IL_03e9: Unknown result type (might be due to invalid IL or missing references) //IL_0408: Unknown result type (might be due to invalid IL or missing references) //IL_040a: Unknown result type (might be due to invalid IL or missing references) //IL_040c: Unknown result type (might be due to invalid IL or missing references) //IL_040e: Unknown result type (might be due to invalid IL or missing references) //IL_0413: Unknown result type (might be due to invalid IL or missing references) //IL_0415: Unknown result type (might be due to invalid IL or missing references) //IL_0417: Unknown result type (might be due to invalid IL or missing references) //IL_041c: Unknown result type (might be due to invalid IL or missing references) //IL_0421: Unknown result type (might be due to invalid IL or missing references) //IL_0423: Unknown result type (might be due to invalid IL or missing references) //IL_0425: Unknown result type (might be due to invalid IL or missing references) //IL_0427: Unknown result type (might be due to invalid IL or missing references) //IL_042c: Unknown result type (might be due to invalid IL or missing references) //IL_042e: Unknown result type (might be due to invalid IL or missing references) //IL_0430: Unknown result type (might be due to invalid IL or missing references) //IL_0435: Unknown result type (might be due to invalid IL or missing references) //IL_043a: Unknown result type (might be due to invalid IL or missing references) //IL_043c: Unknown result type (might be due to invalid IL or missing references) //IL_043e: Unknown result type (might be due to invalid IL or missing references) //IL_0403: Unknown result type (might be due to invalid IL or missing references) if (!AssetPack.Existe(ruta)) { return null; } List posG = new List(); List normG = new List(); List uvG = new List(); List> subCaras = new List>(); List subNombres = new List(); NuevaSub("default"); int num = 0; int num2 = 0; int num3 = 0; int num4 = 0; string[] array = AssetPack.LeerLineas(ruta); foreach (string text in array) { string text2 = text.Trim(); if (text2.Length == 0 || text2[0] == '#') { continue; } string[] array2 = text2.Split(new char[2] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); if (array2.Length == 0) { continue; } switch (array2[0]) { case "v": if (array2.Length >= 4) { posG.Add(new Vector3(Pf(array2[1]), Pf(array2[2]), 0f - Pf(array2[3]))); } break; case "vt": if (array2.Length >= 3) { uvG.Add(new Vector2(Pf(array2[1]), Pf(array2[2]))); } break; case "vn": if (array2.Length >= 4) { normG.Add(new Vector3(Pf(array2[1]), Pf(array2[2]), 0f - Pf(array2[3]))); } break; case "usemtl": NuevaSub((array2.Length >= 2) ? array2[1] : "mat"); break; case "f": { (int, int, int)[] array3 = new(int, int, int)[array2.Length - 1]; for (int j = 1; j < array2.Length; j++) { string[] array4 = array2[j].Split(new char[1] { '/' }); array3[j - 1] = (int.Parse(array4[0]) - 1, (array4.Length > 1 && array4[1].Length > 0) ? (int.Parse(array4[1]) - 1) : (-1), (array4.Length > 2 && array4[2].Length > 0) ? (int.Parse(array4[2]) - 1) : (-1)); } List<(int, int, int)[]> list = subCaras[subCaras.Count - 1]; if (array3.Length == 4) { Vector3 val = ((array3[0].Item1 >= 0 && array3[0].Item1 < posG.Count) ? posG[array3[0].Item1] : Vector3.zero); Vector3 val2 = ((array3[1].Item1 >= 0 && array3[1].Item1 < posG.Count) ? posG[array3[1].Item1] : Vector3.zero); Vector3 val3 = ((array3[2].Item1 >= 0 && array3[2].Item1 < posG.Count) ? posG[array3[2].Item1] : Vector3.zero); Vector3 val4 = ((array3[3].Item1 >= 0 && array3[3].Item1 < posG.Count) ? posG[array3[3].Item1] : Vector3.zero); Vector3 val5 = Vector3.Cross(val2 - val, val3 - val); Vector3 val6 = Vector3.Cross(val3 - val, val4 - val); if (Vector3.Dot(val5, val6) >= 0f) { list.Add(new(int, int, int)[3] { array3[0], array3[2], array3[1] }); list.Add(new(int, int, int)[3] { array3[0], array3[3], array3[2] }); num2++; } else { list.Add(new(int, int, int)[3] { array3[0], array3[3], array3[1] }); list.Add(new(int, int, int)[3] { array3[1], array3[3], array3[2] }); num3++; } } else { for (int k = 1; k < array3.Length - 1; k++) { list.Add(new(int, int, int)[3] { array3[0], array3[k + 1], array3[k] }); } if (array3.Length == 3) { num++; } else { num4++; } } break; } } } List verts = new List(); List norms = new List(); List uvLst = new List(); Dictionary<(int, int, int), int> mapa = new Dictionary<(int, int, int), int>(); List list2 = new List(); List list3 = new List(); for (int l = 0; l < subCaras.Count; l++) { List<(int, int, int)[]> list4 = subCaras[l]; if (list4.Count == 0) { continue; } List list5 = new List(list4.Count * 3); foreach ((int, int, int)[] item in list4) { (int, int, int)[] array5 = item; foreach ((int, int, int) k2 in array5) { list5.Add(GetIdx(k2)); } } list2.Add(list5.ToArray()); list3.Add(subNombres[l]); } if (verts.Count == 0 || list2.Count == 0) { ControlDoblajePlugin.Log.LogWarning((object)("[OBJ] '" + Path.GetFileName(ruta) + "': sin geometría")); return null; } Mesh val7 = new Mesh(); ((Object)val7).name = Path.GetFileNameWithoutExtension(ruta); if (verts.Count > 65535) { val7.indexFormat = (IndexFormat)1; } val7.SetVertices(verts); val7.SetUVs(0, uvLst); val7.subMeshCount = list2.Count; for (int n = 0; n < list2.Count; n++) { val7.SetTriangles(list2[n], n); } val7.RecalculateNormals(); val7.RecalculateTangents(); val7.RecalculateBounds(); ControlDoblajePlugin.Log.LogInfo((object)($"[OBJ] '{((Object)val7).name}' cargado: {verts.Count} verts, " + $"{list2.Sum((int[] s) => s.Length / 3)} tris, " + $"{list2.Count} sub-malla(s) " + $"[caras: tri={num} quadAC={num2} quadBD={num3} ngon={num4}]")); return val7; int GetIdx((int v, int vt, int vn) key) { //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0069: 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) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) if (mapa.TryGetValue(key, out var value)) { return value; } value = verts.Count; mapa[key] = value; verts.Add((key.v >= 0 && key.v < posG.Count) ? posG[key.v] : Vector3.zero); norms.Add((key.vn >= 0 && key.vn < normG.Count) ? normG[key.vn] : Vector3.up); uvLst.Add((key.vt >= 0 && key.vt < uvG.Count) ? uvG[key.vt] : Vector2.zero); return value; } void NuevaSub(string nombre) { if (subCaras.Count == 0 || subCaras[subCaras.Count - 1].Count > 0) { subCaras.Add(new List<(int, int, int)[]>()); subNombres.Add(nombre); } else { subNombres[subNombres.Count - 1] = nombre; } } } } public static class ModelosGestor { private struct BoneDataEntry { public Vector3 pos; public int boneIdx; } private struct BoneDataFile { public Matrix4x4[] bindposes; public BoneDataEntry[] vertices; } private static readonly Dictionary _cache = new Dictionary(StringComparer.OrdinalIgnoreCase); private static readonly Dictionary _originalMeshFilters = new Dictionary(); private static readonly Dictionary _originalSMRs = new Dictionary(); private static readonly Dictionary _bonedataCache = new Dictionary(StringComparer.OrdinalIgnoreCase); public static void LimpiarCache() { _cache.Clear(); } public static void RestaurarMeshesOriginales() { MeshFilter[] array = Resources.FindObjectsOfTypeAll(); SkinnedMeshRenderer[] array2 = Resources.FindObjectsOfTypeAll(); int num = 0; MeshFilter[] array3 = array; foreach (MeshFilter val in array3) { if (!((Object)(object)val == (Object)null) && _originalMeshFilters.TryGetValue(((Object)val).GetInstanceID(), out var value) && (Object)(object)value != (Object)null) { val.sharedMesh = value; num++; } } SkinnedMeshRenderer[] array4 = array2; foreach (SkinnedMeshRenderer val2 in array4) { if (!((Object)(object)val2 == (Object)null) && _originalSMRs.TryGetValue(((Object)val2).GetInstanceID(), out var value2) && (Object)(object)value2 != (Object)null) { val2.sharedMesh = value2; num++; } } ControlDoblajePlugin.Log.LogInfo((object)$"[Modelos] Meshes originales restaurados: {num}"); } private static BoneDataFile? CargarBoneData(string rutaOBJ) { //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_027c: Unknown result type (might be due to invalid IL or missing references) //IL_027e: Unknown result type (might be due to invalid IL or missing references) //IL_0348: Unknown result type (might be due to invalid IL or missing references) //IL_034d: Unknown result type (might be due to invalid IL or missing references) string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(rutaOBJ); if (_bonedataCache.TryGetValue(fileNameWithoutExtension, out var value)) { return value; } string text = Path.ChangeExtension(rutaOBJ, ".bonedata"); if (!AssetPack.Existe(text)) { _bonedataCache[fileNameWithoutExtension] = null; return null; } try { string[] array = AssetPack.LeerLineas(text); int num = 0; if (array[num].Trim() != "BONEDATA") { _bonedataCache[fileNameWithoutExtension] = null; return null; } num++; string[] array2 = array[num].Trim().Split(new char[1] { ' ' }); int num2 = int.Parse(array2[1]); num++; Matrix4x4[] array3 = (Matrix4x4[])(object)new Matrix4x4[num2]; for (int i = 0; i < num2; i++) { string[] array4 = array[num++].Trim().Split(new char[1] { ' ' }); array3[i] = new Matrix4x4 { m00 = float.Parse(array4[0], CultureInfo.InvariantCulture), m01 = float.Parse(array4[1], CultureInfo.InvariantCulture), m02 = float.Parse(array4[2], CultureInfo.InvariantCulture), m03 = float.Parse(array4[3], CultureInfo.InvariantCulture), m10 = float.Parse(array4[4], CultureInfo.InvariantCulture), m11 = float.Parse(array4[5], CultureInfo.InvariantCulture), m12 = float.Parse(array4[6], CultureInfo.InvariantCulture), m13 = float.Parse(array4[7], CultureInfo.InvariantCulture), m20 = float.Parse(array4[8], CultureInfo.InvariantCulture), m21 = float.Parse(array4[9], CultureInfo.InvariantCulture), m22 = float.Parse(array4[10], CultureInfo.InvariantCulture), m23 = float.Parse(array4[11], CultureInfo.InvariantCulture), m30 = float.Parse(array4[12], CultureInfo.InvariantCulture), m31 = float.Parse(array4[13], CultureInfo.InvariantCulture), m32 = float.Parse(array4[14], CultureInfo.InvariantCulture), m33 = float.Parse(array4[15], CultureInfo.InvariantCulture) }; } array2 = array[num].Trim().Split(new char[1] { ' ' }); int num3 = int.Parse(array2[1]); num++; BoneDataEntry[] array5 = new BoneDataEntry[num3]; for (int j = 0; j < num3; j++) { string[] array6 = array[num++].Trim().Split(new char[1] { ' ' }); float num4 = float.Parse(array6[0], CultureInfo.InvariantCulture); float num5 = float.Parse(array6[1], CultureInfo.InvariantCulture); float num6 = float.Parse(array6[2], CultureInfo.InvariantCulture); int boneIdx = int.Parse(array6[3]); array5[j] = new BoneDataEntry { pos = new Vector3(num4, num5, num6), boneIdx = boneIdx }; } BoneDataFile value2 = new BoneDataFile { bindposes = array3, vertices = array5 }; _bonedataCache[fileNameWithoutExtension] = value2; ControlDoblajePlugin.Log.LogInfo((object)$"[Modelos] .bonedata cargado: {num2} bindposes, {num3} verts originales"); return value2; } catch (Exception ex) { ControlDoblajePlugin.Log.LogWarning((object)("[Modelos] Error leyendo .bonedata: " + ex.Message)); _bonedataCache[fileNameWithoutExtension] = null; return null; } } public static void AplicarEnEscena() { //IL_098e: Unknown result type (might be due to invalid IL or missing references) //IL_0993: Unknown result type (might be due to invalid IL or missing references) //IL_0995: Unknown result type (might be due to invalid IL or missing references) //IL_099a: Unknown result type (might be due to invalid IL or missing references) //IL_09c5: Unknown result type (might be due to invalid IL or missing references) //IL_09ca: Unknown result type (might be due to invalid IL or missing references) //IL_09cc: Unknown result type (might be due to invalid IL or missing references) //IL_09e6: Unknown result type (might be due to invalid IL or missing references) //IL_0a01: Unknown result type (might be due to invalid IL or missing references) //IL_085c: Unknown result type (might be due to invalid IL or missing references) //IL_0861: Unknown result type (might be due to invalid IL or missing references) //IL_0863: Unknown result type (might be due to invalid IL or missing references) //IL_0868: Unknown result type (might be due to invalid IL or missing references) //IL_07de: Unknown result type (might be due to invalid IL or missing references) //IL_07e7: Unknown result type (might be due to invalid IL or missing references) //IL_07ec: Unknown result type (might be due to invalid IL or missing references) //IL_07f1: Unknown result type (might be due to invalid IL or missing references) //IL_089b: Unknown result type (might be due to invalid IL or missing references) //IL_08a1: Unknown result type (might be due to invalid IL or missing references) //IL_08a6: Unknown result type (might be due to invalid IL or missing references) //IL_08ab: Unknown result type (might be due to invalid IL or missing references) //IL_087f: Unknown result type (might be due to invalid IL or missing references) //IL_0885: Unknown result type (might be due to invalid IL or missing references) //IL_088a: Unknown result type (might be due to invalid IL or missing references) //IL_088f: Unknown result type (might be due to invalid IL or missing references) //IL_08d4: Unknown result type (might be due to invalid IL or missing references) //IL_08d9: Unknown result type (might be due to invalid IL or missing references) //IL_08de: Unknown result type (might be due to invalid IL or missing references) //IL_0913: Unknown result type (might be due to invalid IL or missing references) //IL_0922: Unknown result type (might be due to invalid IL or missing references) //IL_093b: Unknown result type (might be due to invalid IL or missing references) //IL_094a: Unknown result type (might be due to invalid IL or missing references) //IL_08eb: Unknown result type (might be due to invalid IL or missing references) //IL_08f0: Unknown result type (might be due to invalid IL or missing references) //IL_08f5: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) //IL_12ef: Unknown result type (might be due to invalid IL or missing references) //IL_12f9: Unknown result type (might be due to invalid IL or missing references) //IL_12fe: Unknown result type (might be due to invalid IL or missing references) //IL_1303: Unknown result type (might be due to invalid IL or missing references) //IL_130e: Unknown result type (might be due to invalid IL or missing references) //IL_1318: Unknown result type (might be due to invalid IL or missing references) //IL_131d: Unknown result type (might be due to invalid IL or missing references) //IL_1322: Unknown result type (might be due to invalid IL or missing references) //IL_02b0: Unknown result type (might be due to invalid IL or missing references) //IL_02b5: Unknown result type (might be due to invalid IL or missing references) //IL_0d8c: Unknown result type (might be due to invalid IL or missing references) //IL_0d91: Unknown result type (might be due to invalid IL or missing references) //IL_0d93: Unknown result type (might be due to invalid IL or missing references) //IL_0d98: Unknown result type (might be due to invalid IL or missing references) //IL_13e1: Unknown result type (might be due to invalid IL or missing references) //IL_13fe: Unknown result type (might be due to invalid IL or missing references) //IL_1400: Unknown result type (might be due to invalid IL or missing references) //IL_1582: Unknown result type (might be due to invalid IL or missing references) //IL_1587: Unknown result type (might be due to invalid IL or missing references) //IL_158e: Unknown result type (might be due to invalid IL or missing references) //IL_03d4: Unknown result type (might be due to invalid IL or missing references) //IL_03db: Unknown result type (might be due to invalid IL or missing references) //IL_03e0: Unknown result type (might be due to invalid IL or missing references) //IL_03ad: Unknown result type (might be due to invalid IL or missing references) //IL_11f8: Unknown result type (might be due to invalid IL or missing references) //IL_11fd: Unknown result type (might be due to invalid IL or missing references) //IL_11ff: Unknown result type (might be due to invalid IL or missing references) //IL_1204: Unknown result type (might be due to invalid IL or missing references) //IL_0db6: Unknown result type (might be due to invalid IL or missing references) //IL_0dbc: Unknown result type (might be due to invalid IL or missing references) //IL_0dc1: Unknown result type (might be due to invalid IL or missing references) //IL_0dc6: Unknown result type (might be due to invalid IL or missing references) //IL_0e1a: Unknown result type (might be due to invalid IL or missing references) //IL_0e1f: Unknown result type (might be due to invalid IL or missing references) //IL_0e24: Unknown result type (might be due to invalid IL or missing references) //IL_0de1: Unknown result type (might be due to invalid IL or missing references) //IL_0de7: Unknown result type (might be due to invalid IL or missing references) //IL_0dec: Unknown result type (might be due to invalid IL or missing references) //IL_0df1: Unknown result type (might be due to invalid IL or missing references) //IL_0e31: Unknown result type (might be due to invalid IL or missing references) //IL_0e36: Unknown result type (might be due to invalid IL or missing references) //IL_0e3b: Unknown result type (might be due to invalid IL or missing references) //IL_1128: Unknown result type (might be due to invalid IL or missing references) //IL_112d: Unknown result type (might be due to invalid IL or missing references) //IL_1130: Unknown result type (might be due to invalid IL or missing references) //IL_113a: Unknown result type (might be due to invalid IL or missing references) //IL_1147: Unknown result type (might be due to invalid IL or missing references) //IL_1151: Unknown result type (might be due to invalid IL or missing references) //IL_15d8: Unknown result type (might be due to invalid IL or missing references) //IL_15dd: Unknown result type (might be due to invalid IL or missing references) //IL_15df: Unknown result type (might be due to invalid IL or missing references) //IL_15e4: Unknown result type (might be due to invalid IL or missing references) //IL_046f: Unknown result type (might be due to invalid IL or missing references) //IL_0483: Unknown result type (might be due to invalid IL or missing references) //IL_1186: Unknown result type (might be due to invalid IL or missing references) //IL_1170: Unknown result type (might be due to invalid IL or missing references) //IL_1250: Unknown result type (might be due to invalid IL or missing references) //IL_1256: Unknown result type (might be due to invalid IL or missing references) //IL_125b: Unknown result type (might be due to invalid IL or missing references) //IL_1260: Unknown result type (might be due to invalid IL or missing references) //IL_122e: Unknown result type (might be due to invalid IL or missing references) //IL_1234: Unknown result type (might be due to invalid IL or missing references) //IL_1239: Unknown result type (might be due to invalid IL or missing references) //IL_123e: Unknown result type (might be due to invalid IL or missing references) //IL_1289: Unknown result type (might be due to invalid IL or missing references) //IL_128e: Unknown result type (might be due to invalid IL or missing references) //IL_1293: Unknown result type (might be due to invalid IL or missing references) //IL_0ed7: Unknown result type (might be due to invalid IL or missing references) //IL_0edc: Unknown result type (might be due to invalid IL or missing references) //IL_0ede: Unknown result type (might be due to invalid IL or missing references) //IL_0ee3: Unknown result type (might be due to invalid IL or missing references) //IL_16a9: Unknown result type (might be due to invalid IL or missing references) //IL_16b2: Unknown result type (might be due to invalid IL or missing references) //IL_16b7: Unknown result type (might be due to invalid IL or missing references) //IL_1682: Unknown result type (might be due to invalid IL or missing references) //IL_12a0: Unknown result type (might be due to invalid IL or missing references) //IL_12a5: Unknown result type (might be due to invalid IL or missing references) //IL_12aa: Unknown result type (might be due to invalid IL or missing references) //IL_0e73: Unknown result type (might be due to invalid IL or missing references) //IL_0e79: Unknown result type (might be due to invalid IL or missing references) //IL_0e7e: Unknown result type (might be due to invalid IL or missing references) //IL_0e83: Unknown result type (might be due to invalid IL or missing references) //IL_0e8e: Unknown result type (might be due to invalid IL or missing references) //IL_0e94: Unknown result type (might be due to invalid IL or missing references) //IL_0e99: Unknown result type (might be due to invalid IL or missing references) //IL_0e9e: Unknown result type (might be due to invalid IL or missing references) //IL_171d: Unknown result type (might be due to invalid IL or missing references) //IL_1731: Unknown result type (might be due to invalid IL or missing references) //IL_0f16: Unknown result type (might be due to invalid IL or missing references) //IL_0f1c: Unknown result type (might be due to invalid IL or missing references) //IL_0f21: Unknown result type (might be due to invalid IL or missing references) //IL_0f26: Unknown result type (might be due to invalid IL or missing references) //IL_0efa: Unknown result type (might be due to invalid IL or missing references) //IL_0f00: Unknown result type (might be due to invalid IL or missing references) //IL_0f05: Unknown result type (might be due to invalid IL or missing references) //IL_0f0a: Unknown result type (might be due to invalid IL or missing references) //IL_0f4f: Unknown result type (might be due to invalid IL or missing references) //IL_0f54: Unknown result type (might be due to invalid IL or missing references) //IL_0f59: Unknown result type (might be due to invalid IL or missing references) //IL_0536: Unknown result type (might be due to invalid IL or missing references) //IL_053b: Unknown result type (might be due to invalid IL or missing references) //IL_0559: Unknown result type (might be due to invalid IL or missing references) //IL_0568: Unknown result type (might be due to invalid IL or missing references) //IL_0577: Unknown result type (might be due to invalid IL or missing references) //IL_04dd: Unknown result type (might be due to invalid IL or missing references) //IL_04f1: Unknown result type (might be due to invalid IL or missing references) //IL_0f8e: Unknown result type (might be due to invalid IL or missing references) //IL_0f9d: Unknown result type (might be due to invalid IL or missing references) //IL_0fb6: Unknown result type (might be due to invalid IL or missing references) //IL_0fc5: Unknown result type (might be due to invalid IL or missing references) //IL_0fdd: Unknown result type (might be due to invalid IL or missing references) //IL_0fe4: Unknown result type (might be due to invalid IL or missing references) //IL_0f66: Unknown result type (might be due to invalid IL or missing references) //IL_0f6b: Unknown result type (might be due to invalid IL or missing references) //IL_0f70: Unknown result type (might be due to invalid IL or missing references) //IL_1008: Unknown result type (might be due to invalid IL or missing references) //IL_100f: Unknown result type (might be due to invalid IL or missing references) //IL_17de: Unknown result type (might be due to invalid IL or missing references) //IL_17e7: Unknown result type (might be due to invalid IL or missing references) //IL_17ec: Unknown result type (might be due to invalid IL or missing references) //IL_17f1: Unknown result type (might be due to invalid IL or missing references) //IL_06e5: Unknown result type (might be due to invalid IL or missing references) //IL_1915: Unknown result type (might be due to invalid IL or missing references) //IL_191e: Unknown result type (might be due to invalid IL or missing references) //IL_1927: Unknown result type (might be due to invalid IL or missing references) //IL_192c: Unknown result type (might be due to invalid IL or missing references) //IL_1931: Unknown result type (might be due to invalid IL or missing references) //IL_1936: Unknown result type (might be due to invalid IL or missing references) //IL_1b77: Unknown result type (might be due to invalid IL or missing references) //IL_1b84: Unknown result type (might be due to invalid IL or missing references) //IL_1b89: Unknown result type (might be due to invalid IL or missing references) //IL_1bac: Unknown result type (might be due to invalid IL or missing references) //IL_1bb9: Unknown result type (might be due to invalid IL or missing references) //IL_1bbe: Unknown result type (might be due to invalid IL or missing references) //IL_1b31: Unknown result type (might be due to invalid IL or missing references) //IL_1b50: Unknown result type (might be due to invalid IL or missing references) //IL_1a2e: Unknown result type (might be due to invalid IL or missing references) //IL_1c48: Unknown result type (might be due to invalid IL or missing references) //IL_1c68: Unknown result type (might be due to invalid IL or missing references) //IL_1c87: Unknown result type (might be due to invalid IL or missing references) //IL_1ca7: Unknown result type (might be due to invalid IL or missing references) //IL_1cc6: Unknown result type (might be due to invalid IL or missing references) //IL_1ce6: Unknown result type (might be due to invalid IL or missing references) //IL_1a57: Unknown result type (might be due to invalid IL or missing references) //IL_1a50: Unknown result type (might be due to invalid IL or missing references) //IL_1e04: Unknown result type (might be due to invalid IL or missing references) //IL_1e0f: Unknown result type (might be due to invalid IL or missing references) //IL_1e14: Unknown result type (might be due to invalid IL or missing references) //IL_1e37: Unknown result type (might be due to invalid IL or missing references) //IL_1e42: Unknown result type (might be due to invalid IL or missing references) //IL_1e47: Unknown result type (might be due to invalid IL or missing references) //IL_1dc0: Unknown result type (might be due to invalid IL or missing references) //IL_1ddd: Unknown result type (might be due to invalid IL or missing references) //IL_1ec7: Unknown result type (might be due to invalid IL or missing references) //IL_1ee7: Unknown result type (might be due to invalid IL or missing references) //IL_1f06: Unknown result type (might be due to invalid IL or missing references) //IL_1f26: Unknown result type (might be due to invalid IL or missing references) //IL_1f45: Unknown result type (might be due to invalid IL or missing references) //IL_1f65: Unknown result type (might be due to invalid IL or missing references) if (!ControlDoblajePlugin.ModelosActivos) { ControlDoblajePlugin.Log.LogInfo((object)"[Modelos] Modelos3D inactivo — saltando"); return; } string meshPath = ControlDoblajePlugin.MeshPath; if (!AssetPack.CarpetaExiste(meshPath)) { ControlDoblajePlugin.Log.LogInfo((object)"[Modelos] Carpeta Mesh no encontrada (ni disco ni pack), saltando"); return; } string[] array = AssetPack.ListarArchivos(meshPath, ".obj").ToArray(); if (array.Length == 0) { return; } Stopwatch stopwatch = Stopwatch.StartNew(); ControlDoblajePlugin.Log.LogInfo((object)$"[Modelos] Escaneando escena — {array.Length} OBJ disponible(s)"); _originalMeshFilters.Clear(); _originalSMRs.Clear(); MeshFilter[] array2 = Resources.FindObjectsOfTypeAll(); SkinnedMeshRenderer[] array3 = Resources.FindObjectsOfTypeAll(); int num = 0; string[] array4 = array; foreach (string text in array4) { string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(text); if (!_cache.TryGetValue(fileNameWithoutExtension, out var value) || (Object)(object)value == (Object)null) { value = ObjCargador.Cargar(text); if ((Object)(object)value == (Object)null) { continue; } _cache[fileNameWithoutExtension] = value; } MeshFilter[] array5 = array2; Scene scene; foreach (MeshFilter val in array5) { if ((Object)(object)val == (Object)null || (Object)(object)val.sharedMesh == (Object)null) { continue; } scene = ((Component)val).gameObject.scene; if (((Scene)(ref scene)).IsValid() && ((Object)val.sharedMesh).name.Equals(fileNameWithoutExtension, StringComparison.OrdinalIgnoreCase)) { int instanceID = ((Object)val).GetInstanceID(); if (!_originalMeshFilters.ContainsKey(instanceID)) { _originalMeshFilters[instanceID] = val.sharedMesh; } AjustarMateriales(((Component)val).GetComponent(), value.subMeshCount); val.sharedMesh = value; num++; ControlDoblajePlugin.Log.LogInfo((object)("[Modelos] MeshFilter '" + ((Object)((Component)val).gameObject).name + "' → " + fileNameWithoutExtension + " " + $"({value.vertexCount} verts)")); } } BoneDataFile? boneDataFile = CargarBoneData(text); SkinnedMeshRenderer[] array6 = array3; foreach (SkinnedMeshRenderer val2 in array6) { if ((Object)(object)val2 == (Object)null || (Object)(object)val2.sharedMesh == (Object)null) { continue; } scene = ((Component)val2).gameObject.scene; if (!((Scene)(ref scene)).IsValid() || !((Object)val2.sharedMesh).name.Equals(fileNameWithoutExtension, StringComparison.OrdinalIgnoreCase)) { continue; } if (value.bindposes == null || value.bindposes.Length == 0) { if (boneDataFile.HasValue) { BoneDataFile value2 = boneDataFile.Value; value.bindposes = value2.bindposes; Vector3[] vertices = value.vertices; BoneWeight[] array7 = (BoneWeight[])(object)new BoneWeight[vertices.Length]; int num2 = val2.bones.Length - 1; Dictionary dictionary = new Dictionary(); Dictionary dictionary2 = new Dictionary(); BoneDataEntry[] vertices2 = value2.vertices; for (int l = 0; l < vertices2.Length; l++) { BoneDataEntry boneDataEntry = vertices2[l]; int num3 = Mathf.Clamp(boneDataEntry.boneIdx, 0, num2); if (!dictionary.ContainsKey(num3)) { dictionary[num3] = Vector3.zero; dictionary2[num3] = 0; } Dictionary dictionary3 = dictionary; int key = num3; dictionary3[key] += boneDataEntry.pos; dictionary2[num3]++; } int num4 = Mathf.Max(2, value2.vertices.Length / 20); List<(int, Vector3)> list = new List<(int, Vector3)>(); foreach (KeyValuePair item2 in dictionary) { if (dictionary2[item2.Key] >= num4) { list.Add((item2.Key, item2.Value / (float)dictionary2[item2.Key])); } } if (list.Count == 0) { foreach (KeyValuePair item3 in dictionary) { list.Add((item3.Key, item3.Value / (float)dictionary2[item3.Key])); } } foreach (var (num5, val3) in list) { ControlDoblajePlugin.Log.LogInfo((object)$"[Modelos] Centroide hueso {num5}: ({val3.x:F3},{val3.y:F3},{val3.z:F3}) n={dictionary2[num5]}"); } List list2 = new List(); List list3 = new List(); int num6 = -1; bool flag = false; try { foreach (string item4 in File.ReadLines(text)) { string text2 = item4.Trim(); if ((text2.StartsWith("o ") || text2.StartsWith("g ")) && text2.Length > 2) { num6 = (flag ? (num6 + 1) : 0); flag = true; } else if (text2.Length > 2 && text2[0] == 'v' && text2[1] == ' ') { string[] array8 = text2.Split(new char[2] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); if (array8.Length >= 4 && float.TryParse(array8[1], NumberStyles.Float, CultureInfo.InvariantCulture, out var result) && float.TryParse(array8[2], NumberStyles.Float, CultureInfo.InvariantCulture, out var result2) && float.TryParse(array8[3], NumberStyles.Float, CultureInfo.InvariantCulture, out var result3)) { list2.Add(new Vector3(result, result2, 0f - result3)); list3.Add(Math.Max(0, num6)); } } } } catch (Exception ex) { ControlDoblajePlugin.Log.LogWarning((object)("[Modelos] Error leyendo OBJ: " + ex.Message)); } int num7 = ((list2.Count > 0) ? ((list3.Count <= 0) ? 1 : (list3[list3.Count - 1] + 1)) : 0); ControlDoblajePlugin.Log.LogInfo((object)$"[Modelos] OBJ parser: {list2.Count} verts, {num7} grupos ('o' markers)"); int[] array9 = new int[vertices.Length]; Vector3 val4; Vector3 val5; if (num7 >= 2 && list2.Count > 0) { for (int m = 0; m < vertices.Length; m++) { float num8 = float.MaxValue; int num9 = 0; for (int n = 0; n < list2.Count; n++) { val4 = vertices[m] - list2[n]; float sqrMagnitude = ((Vector3)(ref val4)).sqrMagnitude; if (sqrMagnitude < num8) { num8 = sqrMagnitude; num9 = list3[n]; } } array9[m] = ((num9 != 0) ? 1 : 0); } int num10 = 0; int num11 = 0; val5 = Vector3.zero; Vector3 val6 = Vector3.zero; for (int num12 = 0; num12 < vertices.Length; num12++) { if (array9[num12] == 0) { val5 += vertices[num12]; num10++; } else { val6 += vertices[num12]; num11++; } } if (num10 > 0) { val5 /= (float)num10; } if (num11 > 0) { val6 /= (float)num11; } ControlDoblajePlugin.Log.LogInfo((object)$"[Modelos] OBJ grupos: grp0={num10} cent=({val5.x:F4},{val5.y:F4}) | grp1={num11} cent=({val6.x:F4},{val6.y:F4})"); } else { ControlDoblajePlugin.Log.LogInfo((object)$"[Modelos] Sin grupos OBJ (numGrps={num7}) — intentando BFS"); bool flag2 = false; int num10 = 0; int num11 = 0; val5 = Vector3.zero; Vector3 val6 = Vector3.zero; int[] triangles = value.triangles; int[] array10 = new int[vertices.Length]; Dictionary dictionary4 = new Dictionary(); for (int num13 = 0; num13 < vertices.Length; num13++) { Vector3 val7 = vertices[num13]; long key2 = ((long)Mathf.RoundToInt(val7.x * 100000f) * 73856093L) ^ ((long)Mathf.RoundToInt(val7.y * 100000f) * 19349663L) ^ ((long)Mathf.RoundToInt(val7.z * 100000f) * 83492791L); if (!dictionary4.TryGetValue(key2, out var value3)) { value3 = num13; dictionary4[key2] = num13; } array10[num13] = value3; } List[] array11 = new List[vertices.Length]; for (int num14 = 0; num14 < vertices.Length; num14++) { array11[num14] = new List(8); } for (int num15 = 0; num15 < triangles.Length; num15 += 3) { int num16 = array10[triangles[num15]]; int num17 = array10[triangles[num15 + 1]]; int num18 = array10[triangles[num15 + 2]]; if (num16 != num17 && !array11[num16].Contains(num17)) { array11[num16].Add(num17); array11[num17].Add(num16); } if (num16 != num18 && !array11[num16].Contains(num18)) { array11[num16].Add(num18); array11[num18].Add(num16); } if (num17 != num18 && !array11[num17].Contains(num18)) { array11[num17].Add(num18); array11[num18].Add(num17); } } int[] array12 = new int[vertices.Length]; for (int num19 = 0; num19 < array12.Length; num19++) { array12[num19] = -1; } int num20 = 0; List list4 = new List(); Queue queue = new Queue(); for (int num21 = 0; num21 < vertices.Length; num21++) { if (array10[num21] != num21 || array12[num21] >= 0) { continue; } queue.Clear(); queue.Enqueue(num21); array12[num21] = num20; int num22 = 0; while (queue.Count > 0) { int num23 = queue.Dequeue(); num22++; foreach (int item5 in array11[num23]) { if (array12[item5] < 0) { array12[item5] = num20; queue.Enqueue(item5); } } } list4.Add(num22); num20++; } for (int num24 = 0; num24 < vertices.Length; num24++) { if (array10[num24] != num24) { array12[num24] = array12[array10[num24]]; } } ControlDoblajePlugin.Log.LogInfo((object)string.Format("[Modelos] BFS: {0} comp, sz=[{1}]", num20, string.Join(",", list4))); if (num20 >= 2) { int num25 = -1; int num26 = -1; int num27 = 0; int num28 = 0; for (int num29 = 0; num29 < num20; num29++) { if (list4[num29] > num27) { num28 = num27; num26 = num25; num27 = list4[num29]; num25 = num29; } else if (list4[num29] > num28) { num28 = list4[num29]; num26 = num29; } } Vector3 val8 = Vector3.zero; Vector3 val9 = Vector3.zero; int num30 = 0; int num31 = 0; for (int num32 = 0; num32 < vertices.Length; num32++) { if (array12[num32] == num25) { val8 += vertices[num32]; num30++; } else if (array12[num32] == num26) { val9 += vertices[num32]; num31++; } } if (num30 > 0) { val8 /= (float)num30; } if (num31 > 0) { val9 /= (float)num31; } for (int num33 = 0; num33 < vertices.Length; num33++) { int num34 = array12[num33]; if (num34 == num25) { array9[num33] = 0; continue; } if (num34 == num26) { array9[num33] = 1; continue; } val4 = val8 - vertices[num33]; float sqrMagnitude2 = ((Vector3)(ref val4)).sqrMagnitude; val4 = val9 - vertices[num33]; float sqrMagnitude3 = ((Vector3)(ref val4)).sqrMagnitude; array9[num33] = ((!(sqrMagnitude2 <= sqrMagnitude3)) ? 1 : 0); } num10 = 0; num11 = 0; val5 = Vector3.zero; val6 = Vector3.zero; for (int num35 = 0; num35 < vertices.Length; num35++) { if (array9[num35] == 0) { val5 += vertices[num35]; num10++; } else { val6 += vertices[num35]; num11++; } } if (num10 > 0) { val5 /= (float)num10; } if (num11 > 0) { val6 /= (float)num11; } ControlDoblajePlugin.Log.LogInfo((object)$"[Modelos] BFS: grp0={num10} cent=({val5.x:F4},{val5.y:F4}) | grp1={num11} cent=({val6.x:F4},{val6.y:F4})"); if (Mathf.Abs(val5.x - val6.x) < 0.008f) { ControlDoblajePlugin.Log.LogWarning((object)$"[Modelos] BFS rechazado: split por Y (Δx={Mathf.Abs(val5.x - val6.x):F4} < 0.008) → k-means1D"); } else { flag2 = true; } } if (!flag2) { ControlDoblajePlugin.Log.LogWarning((object)"[Modelos] BFS no separó — fallback k-means1D"); int num36 = 0; int num37 = 0; float num38 = float.MaxValue; float num39 = float.MinValue; for (int num40 = 0; num40 < vertices.Length; num40++) { if (vertices[num40].x < num38) { num38 = vertices[num40].x; num36 = num40; } if (vertices[num40].x > num39) { num39 = vertices[num40].x; num37 = num40; } } float num41 = vertices[num36].x; float num42 = vertices[num37].x; for (int num43 = 0; num43 < 15; num43++) { float num44 = 0f; float num45 = 0f; int num46 = 0; int num47 = 0; Vector3[] array13 = vertices; foreach (Vector3 val10 in array13) { float num49 = (val10.x - num41) * (val10.x - num41); float num50 = (val10.x - num42) * (val10.x - num42); if (num49 <= num50) { num44 += val10.x; num46++; } else { num45 += val10.x; num47++; } } if (num46 > 0) { num41 = num44 / (float)num46; } if (num47 > 0) { num42 = num45 / (float)num47; } } float num51 = (num41 + num42) * 0.5f; num10 = 0; num11 = 0; val5 = Vector3.zero; val6 = Vector3.zero; for (int num52 = 0; num52 < vertices.Length; num52++) { if (vertices[num52].x <= num51) { array9[num52] = 0; val5 += vertices[num52]; num10++; } else { array9[num52] = 1; val6 += vertices[num52]; num11++; } } if (num10 > 0) { val5 /= (float)num10; } if (num11 > 0) { val6 /= (float)num11; } ControlDoblajePlugin.Log.LogInfo((object)$"[Modelos] K-means1D fallback: splitX={num51:F4} n0={num10} n1={num11}"); } } int num53; int num54; if (list.Count >= 2) { val4 = val5 - list[0].Item2; float sqrMagnitude4 = ((Vector3)(ref val4)).sqrMagnitude; val4 = val5 - list[1].Item2; float sqrMagnitude5 = ((Vector3)(ref val4)).sqrMagnitude; if (sqrMagnitude4 <= sqrMagnitude5) { num53 = list[0].Item1; num54 = list[1].Item1; } else { num53 = list[1].Item1; num54 = list[0].Item1; } } else { num53 = ((list.Count > 0) ? list[0].Item1 : 0); num54 = num53; } ControlDoblajePlugin.Log.LogInfo((object)$"[Modelos] Asignación: grp0→hueso{num53} grp1→hueso{num54}"); for (int num55 = 0; num55 < vertices.Length; num55++) { int boneIndex = ((array9[num55] == 0) ? num53 : num54); int num56 = num55; BoneWeight val11 = default(BoneWeight); ((BoneWeight)(ref val11)).boneIndex0 = boneIndex; ((BoneWeight)(ref val11)).weight0 = 1f; array7[num56] = val11; } if (num2 >= 16) { for (int num57 = 0; num57 < array7.Length; num57++) { switch (((BoneWeight)(ref array7[num57])).boneIndex0) { case 3: ((BoneWeight)(ref array7[num57])).boneIndex0 = 4; break; case 4: ((BoneWeight)(ref array7[num57])).boneIndex0 = 3; break; case 7: ((BoneWeight)(ref array7[num57])).boneIndex0 = 8; break; case 8: ((BoneWeight)(ref array7[num57])).boneIndex0 = 7; break; case 11: ((BoneWeight)(ref array7[num57])).boneIndex0 = 12; break; case 12: ((BoneWeight)(ref array7[num57])).boneIndex0 = 11; break; case 15: ((BoneWeight)(ref array7[num57])).boneIndex0 = 16; break; case 16: ((BoneWeight)(ref array7[num57])).boneIndex0 = 15; break; } } } Dictionary dictionary5 = new Dictionary(); Dictionary dictionary6 = new Dictionary(); foreach (var item6 in list) { var (num58, _) = item6; Vector3 val12 = (dictionary5[num58] = item6.Item2); float num59 = 0f; int num60 = 0; BoneDataEntry[] vertices3 = value2.vertices; for (int num61 = 0; num61 < vertices3.Length; num61++) { BoneDataEntry boneDataEntry2 = vertices3[num61]; if (Mathf.Clamp(boneDataEntry2.boneIdx, 0, num2) == num58) { float num62 = num59; val4 = boneDataEntry2.pos - val12; num59 = num62 + ((Vector3)(ref val4)).sqrMagnitude; num60++; } } dictionary6[num58] = ((num60 > 0) ? Mathf.Sqrt(num59 / (float)num60) : 1f); } Dictionary dictionary7 = new Dictionary(); Dictionary dictionary8 = new Dictionary(); for (int num63 = 0; num63 < vertices.Length; num63++) { int boneIndex2 = ((BoneWeight)(ref array7[num63])).boneIndex0; if (!dictionary7.ContainsKey(boneIndex2)) { dictionary7[boneIndex2] = Vector3.zero; dictionary8[boneIndex2] = 0; } Dictionary dictionary3 = dictionary7; int key3 = boneIndex2; dictionary3[key3] += vertices[num63]; dictionary8[boneIndex2]++; } Dictionary dictionary9 = new Dictionary(); foreach (KeyValuePair item7 in dictionary7) { dictionary9[item7.Key] = item7.Value / (float)dictionary8[item7.Key]; } Dictionary dictionary10 = new Dictionary(); foreach (KeyValuePair item8 in dictionary9) { dictionary10[item8.Key] = 0f; } for (int num64 = 0; num64 < vertices.Length; num64++) { int boneIndex3 = ((BoneWeight)(ref array7[num64])).boneIndex0; if (dictionary10.ContainsKey(boneIndex3)) { Dictionary dictionary11 = dictionary10; int key = boneIndex3; int key4 = key; float num65 = dictionary11[key]; val4 = vertices[num64] - dictionary9[boneIndex3]; dictionary11[key4] = num65 + ((Vector3)(ref val4)).sqrMagnitude; } } foreach (KeyValuePair item9 in dictionary8) { if (dictionary10.ContainsKey(item9.Key)) { dictionary10[item9.Key] = Mathf.Sqrt(dictionary10[item9.Key] / (float)item9.Value); } } for (int num66 = 0; num66 < vertices.Length; num66++) { int boneIndex4 = ((BoneWeight)(ref array7[num66])).boneIndex0; if (dictionary5.ContainsKey(boneIndex4) && dictionary9.ContainsKey(boneIndex4)) { float value4; float num67 = (dictionary10.TryGetValue(boneIndex4, out value4) ? value4 : 0f); float value5; float num68 = (dictionary6.TryGetValue(boneIndex4, out value5) ? value5 : 0f); vertices[num66] = dictionary5[boneIndex4] + (vertices[num66] - dictionary9[boneIndex4]); } } foreach (KeyValuePair item10 in dictionary9) { int key5 = item10.Key; float value6; float num69 = (dictionary10.TryGetValue(key5, out value6) ? value6 : 0f); float value7; float num70 = (dictionary6.TryGetValue(key5, out value7) ? value7 : 0f); float num71 = ((num69 > 1E-06f) ? (num70 / num69) : 0f); ControlDoblajePlugin.Log.LogInfo((object)$"[Modelos] Alin hueso {key5}: objCent={item10.Value:F4} bdCent={(dictionary5.TryGetValue(key5, out var value8) ? value8 : Vector3.zero):F4} objRMS={num69:F4} bdRMS={num70:F4} sc(ref)={num71:F3}"); } Dictionary dictionary12 = new Dictionary(); Dictionary dictionary13 = new Dictionary(); for (int num72 = 0; num72 < vertices.Length; num72++) { int boneIndex5 = ((BoneWeight)(ref array7[num72])).boneIndex0; if (!dictionary12.ContainsKey(boneIndex5)) { dictionary12[boneIndex5] = vertices[num72]; dictionary13[boneIndex5] = vertices[num72]; } else { dictionary12[boneIndex5] = Vector3.Min(dictionary12[boneIndex5], vertices[num72]); dictionary13[boneIndex5] = Vector3.Max(dictionary13[boneIndex5], vertices[num72]); } } foreach (KeyValuePair item11 in dictionary12) { ControlDoblajePlugin.Log.LogInfo((object)($"[Modelos] Rango post-alin hueso {item11.Key}: " + $"X[{item11.Value.x:F4},{dictionary13[item11.Key].x:F4}] " + $"Y[{item11.Value.y:F4},{dictionary13[item11.Key].y:F4}] " + $"Z[{item11.Value.z:F4},{dictionary13[item11.Key].z:F4}]")); } Dictionary dictionary14 = new Dictionary(); Dictionary dictionary15 = new Dictionary(); BoneDataEntry[] vertices4 = value2.vertices; for (int num73 = 0; num73 < vertices4.Length; num73++) { BoneDataEntry boneDataEntry3 = vertices4[num73]; int key6 = Mathf.Clamp(boneDataEntry3.boneIdx, 0, num2); if (!dictionary14.ContainsKey(key6)) { dictionary14[key6] = boneDataEntry3.pos; dictionary15[key6] = boneDataEntry3.pos; } else { dictionary14[key6] = Vector3.Min(dictionary14[key6], boneDataEntry3.pos); dictionary15[key6] = Vector3.Max(dictionary15[key6], boneDataEntry3.pos); } } foreach (KeyValuePair item12 in dictionary14) { ControlDoblajePlugin.Log.LogInfo((object)($"[Modelos] Rango bonedata hueso {item12.Key}: " + $"X[{item12.Value.x:F4},{dictionary15[item12.Key].x:F4}] " + $"Y[{item12.Value.y:F4},{dictionary15[item12.Key].y:F4}] " + $"Z[{item12.Value.z:F4},{dictionary15[item12.Key].z:F4}]")); } value.vertices = vertices; value.boneWeights = array7; ControlDoblajePlugin.Log.LogInfo((object)$"[Modelos] Skinning kmeans+swap+align ({vertices.Length} verts, {list.Count} grupos, {value2.bindposes.Length} bindposes) → {fileNameWithoutExtension}"); } else { ControlDoblajePlugin.Log.LogWarning((object)("[Modelos] Sin .bonedata para " + fileNameWithoutExtension + " — sin animacion de huesos")); } } int instanceID2 = ((Object)val2).GetInstanceID(); if (!_originalSMRs.ContainsKey(instanceID2)) { _originalSMRs[instanceID2] = val2.sharedMesh; } AjustarMateriales((Renderer)(object)val2, value.subMeshCount); val2.sharedMesh = value; num++; ControlDoblajePlugin.Log.LogInfo((object)("[Modelos] SMR '" + ((Object)((Component)val2).gameObject).name + "' → " + fileNameWithoutExtension + " " + $"(verts={value.vertexCount} huesos={val2.bones.Length})")); } } stopwatch.Stop(); ControlDoblajePlugin.Log.LogInfo((object)$"[Modelos] Reemplazos aplicados: {num}"); ControlDoblajePlugin.Log.LogWarning((object)$"[PERF] ModelosGestor.AplicarEnEscena = {stopwatch.ElapsedMilliseconds}ms ({array.Length} OBJ, {array2.Length} MF, {array3.Length} SMR)"); } private static void AjustarMateriales(Renderer rend, int subMeshCount) { if ((Object)(object)rend == (Object)null || subMeshCount <= 1) { return; } Material[] sharedMaterials = rend.sharedMaterials; if (sharedMaterials.Length < subMeshCount) { Material[] array = (Material[])(object)new Material[subMeshCount]; for (int i = 0; i < subMeshCount; i++) { array[i] = ((i < sharedMaterials.Length) ? sharedMaterials[i] : sharedMaterials[^1]); } rend.sharedMaterials = array; } } } public class AlexScreamMonitor : MonoBehaviour { private static AlexScreamMonitor _runner; private Channel _chGrito; private bool _tieneGrito; public static void Vigilar(EventInstance inst, string wavEs) { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected O, but got Unknown if ((Object)(object)_runner == (Object)null) { GameObject val = new GameObject("_AlexScreamMonitor"); Object.DontDestroyOnLoad((Object)(object)val); _runner = val.AddComponent(); } ((MonoBehaviour)_runner).StartCoroutine(_runner.Monitor(inst, wavEs)); } private IEnumerator Monitor(EventInstance inst, string wavEs) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) ControlDoblajePlugin.Log.LogInfo((object)"[AlexScream] monitor iniciado (reemplazo por-canal)"); HashSet vistos = new HashSet(); bool reproducido = false; _tieneGrito = false; float t0 = Time.realtimeSinceStartup; PLAYBACK_STATE st = default(PLAYBACK_STATE); ChannelGroup grp = default(ChannelGroup); while (Time.realtimeSinceStartup - t0 < 20f) { bool valido; try { valido = ((EventInstance)(ref inst)).isValid(); if (valido && Time.realtimeSinceStartup - t0 > 1f && (int)((EventInstance)(ref inst)).getPlaybackState(ref st) == 0 && (int)st == 2) { valido = false; } } catch { valido = false; } if (!valido) { break; } try { if ((int)((EventInstance)(ref inst)).getChannelGroup(ref grp) == 0) { BuscarYMutear(grp, vistos, wavEs, ref reproducido); } } catch { } yield return (object)new WaitForSecondsRealtime(0.03f); } if (_tieneGrito) { try { bool sonando = default(bool); if ((int)((Channel)(ref _chGrito)).isPlaying(ref sonando) == 0 && sonando) { ((Channel)(ref _chGrito)).stop(); ControlDoblajePlugin.Log.LogInfo((object)"[AlexScream] grito ES cortado (skip de la cinemática)."); } } catch { } _tieneGrito = false; } ControlDoblajePlugin.Log.LogInfo((object)("[AlexScream] monitor fin. samples vistos: " + ((vistos.Count > 0) ? string.Join(" | ", vistos.ToArray()) : "(ninguno)"))); } private void BuscarYMutear(ChannelGroup grp, HashSet vistos, string wavEs, ref bool reproducido) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Invalid comparison between Unknown and I4 //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Invalid comparison between Unknown and I4 //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Invalid comparison between Unknown and I4 //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Invalid comparison between Unknown and I4 //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Invalid comparison between Unknown and I4 //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) int num = default(int); if ((int)((ChannelGroup)(ref grp)).getNumChannels(ref num) == 0) { Channel val = default(Channel); Sound val2 = default(Sound); string text = default(string); for (int i = 0; i < num; i++) { if ((int)((ChannelGroup)(ref grp)).getChannel(i, ref val) > 0 || (int)((Channel)(ref val)).getCurrentSound(ref val2) > 0 || (int)((Sound)(ref val2)).getName(ref text, 128) != 0 || string.IsNullOrEmpty(text)) { continue; } if (vistos.Add(text)) { ControlDoblajePlugin.Log.LogInfo((object)("[AlexScream] sample en evento: '" + text + "'")); } if (text.IndexOf("Scream", StringComparison.OrdinalIgnoreCase) >= 0) { ((Channel)(ref val)).setVolume(0f); if (!reproducido) { reproducido = true; ReproducirGritoES(wavEs); } } } } int num2 = default(int); if ((int)((ChannelGroup)(ref grp)).getNumGroups(ref num2) != 0) { return; } ChannelGroup grp2 = default(ChannelGroup); for (int j = 0; j < num2; j++) { if ((int)((ChannelGroup)(ref grp)).getGroup(j, ref grp2) == 0) { BuscarYMutear(grp2, vistos, wavEs, ref reproducido); } } } private void ReproducirGritoES(string wavEs) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Invalid comparison between Unknown and I4 //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_0036: 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_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Invalid comparison between Unknown and I4 //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) try { CREATESOUNDEXINFO ex = default(CREATESOUNDEXINFO); ex.cbsize = Marshal.SizeOf(ex); if ((int)AudioPack.CrearSound(RuntimeManager.CoreSystem, wavEs, (MODE)265, ref ex, out var sound) != 0) { return; } System coreSystem = RuntimeManager.CoreSystem; ChannelGroup val = default(ChannelGroup); ((System)(ref coreSystem)).getMasterChannelGroup(ref val); coreSystem = RuntimeManager.CoreSystem; Channel chGrito = default(Channel); if ((int)((System)(ref coreSystem)).playSound(sound, val, false, ref chGrito) == 0) { float volume = MultiPistaRunner.LeerVolBus("bus:/SFX") * MultiPistaRunner.LeerVolBus("bus:/"); ((Channel)(ref chGrito)).setVolume(volume); try { ((Channel)(ref chGrito)).setPriority(0); } catch { } _chGrito = chGrito; _tieneGrito = true; ControlDoblajePlugin.Log.LogInfo((object)("[AlexScream] grito ES → " + Path.GetFileName(wavEs))); } } catch (Exception ex2) { ControlDoblajePlugin.Log.LogInfo((object)("[AlexScream] error grito ES: " + ex2.Message)); } } } [HarmonyPatch(typeof(EventInstance), "start")] public static class FMODDirectStartPatch { private static readonly string ATTACK_PATH = "event:/SFX/USBright/WandererAttack_Prox"; private static readonly string CUTSCENE_PATH = "event:/SFX/USBright/USB_CS_WindowRevealFlyby"; private static readonly string BUILDING_PATH = "event:/SFX/USDark/BuildingFall_01"; private static readonly string[] CALL_STOP_PATHS = new string[3] { "event:/UI/Overlays/Froggy_Calls/FroggyCall_Hangup", "event:/UI/Overlays/Froggy_Calls/FroggyCall_Skip", "event:/UI/Overlays/Froggy_Calls/FroggyCall_End" }; private static Vector3 ObtenerPosicion(EventInstance inst) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Invalid comparison between Unknown and I4 //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) try { ATTRIBUTES_3D val = default(ATTRIBUTES_3D); if ((int)((EventInstance)(ref inst)).get3DAttributes(ref val) == 0) { Vector3 result = default(Vector3); ((Vector3)(ref result))..ctor(val.position.x, val.position.y, val.position.z); if (((Vector3)(ref result)).sqrMagnitude > 0.01f) { return result; } } } catch { } StudioListener val2 = ListenerCache.Get(); return ((Object)(object)val2 != (Object)null) ? ((Component)val2).transform.position : (((Object)(object)Camera.main != (Object)null) ? ((Component)Camera.main).transform.position : Vector3.zero); } private static bool Prefix(EventInstance __instance) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Invalid comparison between Unknown and I4 //IL_08e7: Unknown result type (might be due to invalid IL or missing references) //IL_08e8: Unknown result type (might be due to invalid IL or missing references) //IL_08ed: Unknown result type (might be due to invalid IL or missing references) //IL_0bb9: Unknown result type (might be due to invalid IL or missing references) //IL_0bba: Unknown result type (might be due to invalid IL or missing references) //IL_0bbf: Unknown result type (might be due to invalid IL or missing references) //IL_1166: Unknown result type (might be due to invalid IL or missing references) //IL_0246: Unknown result type (might be due to invalid IL or missing references) //IL_024b: Unknown result type (might be due to invalid IL or missing references) //IL_0256: Unknown result type (might be due to invalid IL or missing references) //IL_025c: Invalid comparison between Unknown and I4 //IL_030a: Unknown result type (might be due to invalid IL or missing references) //IL_056c: Unknown result type (might be due to invalid IL or missing references) //IL_0574: Unknown result type (might be due to invalid IL or missing references) //IL_0580: Unknown result type (might be due to invalid IL or missing references) //IL_0590: Unknown result type (might be due to invalid IL or missing references) //IL_0596: Invalid comparison between Unknown and I4 //IL_0929: Unknown result type (might be due to invalid IL or missing references) //IL_095b: Unknown result type (might be due to invalid IL or missing references) //IL_09c3: Unknown result type (might be due to invalid IL or missing references) //IL_0bab: Unknown result type (might be due to invalid IL or missing references) //IL_0bfb: Unknown result type (might be due to invalid IL or missing references) //IL_0d66: Unknown result type (might be due to invalid IL or missing references) //IL_0d6e: Unknown result type (might be due to invalid IL or missing references) //IL_0d7a: Unknown result type (might be due to invalid IL or missing references) //IL_0d8a: Unknown result type (might be due to invalid IL or missing references) //IL_0d90: Invalid comparison between Unknown and I4 //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_026e: Unknown result type (might be due to invalid IL or missing references) //IL_0273: Unknown result type (might be due to invalid IL or missing references) //IL_027e: Unknown result type (might be due to invalid IL or missing references) //IL_0284: Invalid comparison between Unknown and I4 //IL_0268: Unknown result type (might be due to invalid IL or missing references) //IL_059f: Unknown result type (might be due to invalid IL or missing references) //IL_05a4: Unknown result type (might be due to invalid IL or missing references) //IL_05aa: Unknown result type (might be due to invalid IL or missing references) //IL_05b0: Unknown result type (might be due to invalid IL or missing references) //IL_05b5: Unknown result type (might be due to invalid IL or missing references) //IL_05b9: Unknown result type (might be due to invalid IL or missing references) //IL_05bb: Unknown result type (might be due to invalid IL or missing references) //IL_05c0: Unknown result type (might be due to invalid IL or missing references) //IL_05c6: Invalid comparison between Unknown and I4 //IL_092e: Unknown result type (might be due to invalid IL or missing references) //IL_0930: Unknown result type (might be due to invalid IL or missing references) //IL_0932: Unknown result type (might be due to invalid IL or missing references) //IL_091b: Unknown result type (might be due to invalid IL or missing references) //IL_090d: Unknown result type (might be due to invalid IL or missing references) //IL_0c00: Unknown result type (might be due to invalid IL or missing references) //IL_0c02: Unknown result type (might be due to invalid IL or missing references) //IL_0c04: Unknown result type (might be due to invalid IL or missing references) //IL_0bed: Unknown result type (might be due to invalid IL or missing references) //IL_0bdf: Unknown result type (might be due to invalid IL or missing references) //IL_0d99: Unknown result type (might be due to invalid IL or missing references) //IL_0d9e: Unknown result type (might be due to invalid IL or missing references) //IL_0da4: Unknown result type (might be due to invalid IL or missing references) //IL_0daa: Unknown result type (might be due to invalid IL or missing references) //IL_0daf: Unknown result type (might be due to invalid IL or missing references) //IL_0db3: Unknown result type (might be due to invalid IL or missing references) //IL_0db5: Unknown result type (might be due to invalid IL or missing references) //IL_0dba: Unknown result type (might be due to invalid IL or missing references) //IL_0dc0: Invalid comparison between Unknown and I4 //IL_0296: Unknown result type (might be due to invalid IL or missing references) //IL_029b: Unknown result type (might be due to invalid IL or missing references) //IL_02a6: Unknown result type (might be due to invalid IL or missing references) //IL_02ac: Invalid comparison between Unknown and I4 //IL_0290: Unknown result type (might be due to invalid IL or missing references) //IL_05ea: Unknown result type (might be due to invalid IL or missing references) //IL_0862: Unknown result type (might be due to invalid IL or missing references) //IL_0868: Invalid comparison between Unknown and I4 //IL_0943: Unknown result type (might be due to invalid IL or missing references) //IL_0c1d: Unknown result type (might be due to invalid IL or missing references) //IL_0c1f: Unknown result type (might be due to invalid IL or missing references) //IL_0c21: Unknown result type (might be due to invalid IL or missing references) //IL_0de4: Unknown result type (might be due to invalid IL or missing references) //IL_0ded: Unknown result type (might be due to invalid IL or missing references) //IL_02b8: Unknown result type (might be due to invalid IL or missing references) //IL_0a7e: Unknown result type (might be due to invalid IL or missing references) //IL_0e2b: Unknown result type (might be due to invalid IL or missing references) //IL_0d54: Unknown result type (might be due to invalid IL or missing references) //IL_0760: Unknown result type (might be due to invalid IL or missing references) //IL_06e7: Unknown result type (might be due to invalid IL or missing references) //IL_04e9: Unknown result type (might be due to invalid IL or missing references) //IL_021c: Unknown result type (might be due to invalid IL or missing references) //IL_0782: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_0b93: Unknown result type (might be due to invalid IL or missing references) //IL_01c7: Unknown result type (might be due to invalid IL or missing references) //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_0cad: Unknown result type (might be due to invalid IL or missing references) //IL_0c8e: Unknown result type (might be due to invalid IL or missing references) //IL_079e: Unknown result type (might be due to invalid IL or missing references) //IL_07a4: Invalid comparison between Unknown and I4 //IL_055a: Unknown result type (might be due to invalid IL or missing references) //IL_07bd: Unknown result type (might be due to invalid IL or missing references) //IL_07bf: Unknown result type (might be due to invalid IL or missing references) //IL_07c8: Unknown result type (might be due to invalid IL or missing references) //IL_1158: Unknown result type (might be due to invalid IL or missing references) //IL_07ed: Unknown result type (might be due to invalid IL or missing references) //IL_07ef: Unknown result type (might be due to invalid IL or missing references) string text = ""; try { EventDescription val = default(EventDescription); RESULT description = ((EventInstance)(ref __instance)).getDescription(ref val); if ((int)description > 0) { return true; } if (!((EventDescription)(ref val)).isValid()) { return true; } ((EventDescription)(ref val)).getPath(ref text); FMODLogTracker.Log(text, "start"); if (string.IsNullOrEmpty(text)) { return true; } bool flag = text.Equals("event:/NPCs/Voicelines/NPC_Video", StringComparison.OrdinalIgnoreCase); bool flag2 = text.Equals("event:/NPCs/Voicelines/NPC_Voiceline", StringComparison.OrdinalIgnoreCase); if (flag || flag2) { bool flag3 = (Object)(object)CinematicaMultiPistaPlayer.RunnerActivo != (Object)null && !CinematicaMultiPistaPlayer.RunnerActivo.EsAjena && !CinematicaMultiPistaPlayer.RunnerActivo.FueSoltado && CinematicaMultiPistaPlayer.RunnerActivo.TieneCanalesActivos; if (Time.realtimeSinceStartup < CinematicaMultiPistaPlayer.SilenciarVoicelineHasta || flag3 || CinematicaMultiPistaPlayer.HayCinematicaActiva) { if (flag2) { if (PlayVoiceoverPatch.UltimoDoblajeEsNuestro) { try { ((EventInstance)(ref __instance)).setVolume(CinematicaMultiPistaPlayer.VolumenCompensacionEvento); } catch { } PlayVoiceoverPatch.UltimoDoblajeEsNuestro = false; ControlDoblajePlugin.Log.LogInfo((object)("[CineMulti] NPC_Voiceline doblaje propio → boost vol=" + CinematicaMultiPistaPlayer.VolumenCompensacionEvento)); } else if (flag3) { try { ((EventInstance)(ref __instance)).setVolume(0f); } catch { } ControlDoblajePlugin.Log.LogInfo((object)"[CineMulti] NPC_Voiceline silenciado (runner propio activo suena)"); } else { ControlDoblajePlugin.Log.LogInfo((object)"[CineMulti] NPC_Voiceline sin dub propio → original intacto (fallback nativo)"); } } else if (PlayVoiceoverPatch.UltimoDoblajeEsNuestro) { PlayVoiceoverPatch.UltimoDoblajeEsNuestro = false; ControlDoblajePlugin.Log.LogInfo((object)"[CineMulti] NPC_Video activo — voz = WAV propio (programmer sound)"); } else if ((Object)(object)CinematicaMultiPistaPlayer.RunnerActivo != (Object)null) { try { ((EventInstance)(ref __instance)).setVolume(0f); } catch { } ControlDoblajePlugin.Log.LogInfo((object)"[CineMulti] NPC_Video original SILENCIADO (dub propio activo; música/FX en nuestro OGG) — como el hub"); } else { ControlDoblajePlugin.Log.LogInfo((object)"[CineMulti] NPC_Video activo — sin runner propio, original intacto (vol≈1)"); } } else if (PlayVoiceoverPatch.UltimoDoblajeEsNuestro) { float volumenCompensacionEvento = CinematicaMultiPistaPlayer.VolumenCompensacionEvento; try { ((EventInstance)(ref __instance)).setVolume(volumenCompensacionEvento); } catch { } PlayVoiceoverPatch.UltimoDoblajeEsNuestro = false; float num = 1f; float num2 = 1f; float num3 = 1f; try { System studioSystem = RuntimeManager.StudioSystem; Bus val2 = default(Bus); if ((int)((System)(ref studioSystem)).getBus("bus:/Voicelines", ref val2) == 0) { ((Bus)(ref val2)).getVolume(ref num); } studioSystem = RuntimeManager.StudioSystem; Bus val3 = default(Bus); if ((int)((System)(ref studioSystem)).getBus("bus:/SFX", ref val3) == 0) { ((Bus)(ref val3)).getVolume(ref num2); } studioSystem = RuntimeManager.StudioSystem; Bus val4 = default(Bus); if ((int)((System)(ref studioSystem)).getBus("bus:/", ref val4) == 0) { ((Bus)(ref val4)).getVolume(ref num3); } } catch { } ControlDoblajePlugin.Log.LogInfo((object)$"[VOL] EventInstance vol={volumenCompensacionEvento:F2} | buses: Voicelines={num:F2} SFX={num2:F2} Master={num3:F2}"); } FMODStopHelper.RegistrarNPCVideo(__instance, flag); } string[] cALL_STOP_PATHS = CALL_STOP_PATHS; foreach (string value in cALL_STOP_PATHS) { if (!text.Equals(value, StringComparison.OrdinalIgnoreCase)) { continue; } if ((Object)(object)CinematicaMultiPistaPlayer.RunnerActivo != (Object)null) { MultiPistaRunner runnerActivo = CinematicaMultiPistaPlayer.RunnerActivo; if (runnerActivo.ContieneNombre("FroggyCall") || runnerActivo.ContieneNombre("VL_Froggy")) { ControlDoblajePlugin.Log.LogInfo((object)("[PhoneCall] Fin/skip detectado (" + text + ") — deteniendo runner Froggy ✓")); runnerActivo.Detener(); CinematicaMultiPistaPlayer.RunnerActivo = null; } else { ControlDoblajePlugin.Log.LogInfo((object)("[PhoneCall] Fin/skip (" + text + ") — RunnerActivo no es FroggyCall, preservado")); } } break; } if (text.IndexOf("GreyDoors/", StringComparison.OrdinalIgnoreCase) >= 0) { if ((Object)(object)CinematicaMultiPistaPlayer.AmbienterRunnerActivo != (Object)null) { ControlDoblajePlugin.Log.LogInfo((object)("[Transicion] " + text + " — deteniendo AmbienterRunner pre-escena")); try { CinematicaMultiPistaPlayer.AmbienterRunnerActivo.Detener(); } catch { } CinematicaMultiPistaPlayer.AmbienterRunnerActivo = null; } CinematicaMultiPistaPlayer.LimpiarInstanciaFMOD(); FMODStopHelper.NPCVideoRegistrado = false; } if (text.IndexOf("item_acquired", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("Item_Popup", StringComparison.OrdinalIgnoreCase) >= 0) { SpriteRendererScanner.EscanearConReintentos(); } } catch { return true; } System coreSystem; try { if (ControlDoblajePlugin.PersonajeActivo.TryGetValue("HoarderAlex", out var value2) && value2) { if (text.IndexOf("AlexExplodesBehindYou", StringComparison.OrdinalIgnoreCase) >= 0) { string text2 = WandererGestor.BuscarWAV(Path.Combine(ControlDoblajePlugin.VoicesPath, "HoarderAlex", "USB_S_AlexScream")); if (text2 != null) { AlexScreamMonitor.Vigilar(__instance, text2); } return true; } if (text.IndexOf("Alex_Scream", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("USB_S_AlexScream", StringComparison.OrdinalIgnoreCase) >= 0) { string text3 = WandererGestor.BuscarWAV(Path.Combine(ControlDoblajePlugin.VoicesPath, "HoarderAlex", "USB_S_AlexScream")); if (text3 != null) { try { ((EventInstance)(ref __instance)).setVolume(0f); } catch { } try { CREATESOUNDEXINFO ex = default(CREATESOUNDEXINFO); ex.cbsize = Marshal.SizeOf(ex); if ((int)AudioPack.CrearSound(RuntimeManager.CoreSystem, text3, (MODE)265, ref ex, out var sound) == 0) { coreSystem = RuntimeManager.CoreSystem; ChannelGroup val5 = default(ChannelGroup); ((System)(ref coreSystem)).getMasterChannelGroup(ref val5); coreSystem = RuntimeManager.CoreSystem; Channel val6 = default(Channel); if ((int)((System)(ref coreSystem)).playSound(sound, val5, false, ref val6) == 0) { float volume = MultiPistaRunner.LeerVolBus("bus:/SFX") * MultiPistaRunner.LeerVolBus("bus:/"); ((Channel)(ref val6)).setVolume(volume); } } } catch { } ControlDoblajePlugin.Log.LogInfo((object)("[AlexScream] Evento interceptado (pre-guard) → Core channel: " + Path.GetFileName(text3))); } return true; } } } catch (Exception ex2) { ControlDoblajePlugin.Log.LogInfo((object)("[AlexScream] excepcion pre-guard: " + ex2.Message)); } try { if (!ControlDoblajePlugin.PersonajeActivo.TryGetValue("Wanderer", out var value3) || !value3) { return true; } if (text.Equals(CUTSCENE_PATH, StringComparison.OrdinalIgnoreCase)) { string text4 = WandererGestor.BuscarWAV(Path.Combine(ControlDoblajePlugin.VoicesPath, "Wanderer", "USB_CS_WindowRevealFlyby")); if (text4 == null) { return true; } float realtimeSinceStartup = Time.realtimeSinceStartup; if (realtimeSinceStartup - WandererCutscenePlayer.UltimoDisparo < 2f) { return true; } WandererCutscenePlayer.UltimoDisparo = realtimeSinceStartup; try { ((EventInstance)(ref __instance)).setVolume(0f); } catch { } ControlDoblajePlugin.Log.LogInfo((object)"[WandererCS] Interceptado"); WandererCutscenePlayer.Reproducir(text4); return true; } if (text.Equals(ATTACK_PATH, StringComparison.OrdinalIgnoreCase)) { string text5 = Path.Combine(ControlDoblajePlugin.VoicesPath, "Wanderer"); if (!AssetPack.CarpetaExiste(text5)) { return true; } string text6 = ""; try { EventDescription val7 = default(EventDescription); if ((int)((EventInstance)(ref __instance)).getDescription(ref val7) == 0 && ((EventDescription)(ref val7)).isValid()) { int num4 = 0; ((EventDescription)(ref val7)).getParameterDescriptionCount(ref num4); StringBuilder stringBuilder = new StringBuilder(); PARAMETER_DESCRIPTION val8 = default(PARAMETER_DESCRIPTION); for (int j = 0; j < num4; j++) { if ((int)((EventDescription)(ref val7)).getParameterDescriptionByIndex(j, ref val8) == 0) { float num5 = 0f; float num6 = 0f; ((EventInstance)(ref __instance)).getParameterByID(val8.id, ref num5, ref num6); if (stringBuilder.Length > 0) { stringBuilder.Append(", "); } stringBuilder.Append(StringWrapper.op_Implicit(val8.name)).Append('=').Append(num5.ToString("F2")); } } text6 = stringBuilder.ToString(); } } catch { } bool flag4 = false; string text7 = ""; try { PlayableDirector[] array = Object.FindObjectsOfType(); foreach (PlayableDirector val9 in array) { if ((int)val9.state == 1 && (Object)(object)val9.playableAsset != (Object)null && ((Object)val9.playableAsset).name.IndexOf("AttackBuilding", StringComparison.OrdinalIgnoreCase) >= 0 && ((Object)val9.playableAsset).name.IndexOf("Wanderer", StringComparison.OrdinalIgnoreCase) >= 0) { flag4 = true; text7 = ((Object)val9.playableAsset).name; break; } } } catch { } Vector3 val10 = ObtenerPosicion(__instance); StudioListener val11 = ListenerCache.Get(); Vector3 val12 = (((Object)(object)val11 != (Object)null) ? ((Component)val11).transform.position : (((Object)(object)Camera.main != (Object)null) ? ((Component)Camera.main).transform.position : val10)); float num7 = Vector3.Distance(val12, val10); try { ((EventInstance)(ref __instance)).setVolume(0f); } catch { } try { ((EventInstance)(ref __instance)).setReverbLevel(0, 0f); } catch { } if (flag4) { ControlDoblajePlugin.Log.LogInfo((object)("[WandererAttack] BuildingAtaque dist=" + num7.ToString("F1") + " edif=" + text7 + " params=[" + text6 + "]")); WandererAttackPlayer.ReproducirSecuencia(text5, val10, num7); } else { string[] audioFiles = CinematicaMultiPistaPlayer.GetAudioFiles(text5, "USB_SP_Wanderer_Grumble_0?_es.wav"); if (audioFiles.Length == 0) { audioFiles = CinematicaMultiPistaPlayer.GetAudioFiles(text5, "USB_SP_Wanderer_Grumble_0?.wav"); } if (audioFiles.Length == 0) { return true; } ControlDoblajePlugin.Log.LogInfo((object)("[WandererAttack] Grumble(prox) dist=" + num7.ToString("F1") + " wavs=" + audioFiles.Length + " params=[" + text6 + "]")); if (num7 <= 40f) { WandererAttackPlayer.ReproducirWav(audioFiles, val10, num7); } } return true; } if ((text.IndexOf("Wanderer", StringComparison.OrdinalIgnoreCase) >= 0 && text.IndexOf("/SFX/", StringComparison.OrdinalIgnoreCase) >= 0) || text.IndexOf("USB_SP_Wanderer", StringComparison.OrdinalIgnoreCase) >= 0) { string text8 = text.Substring(text.LastIndexOf('/') + 1); string text9 = Path.Combine(ControlDoblajePlugin.VoicesPath, "Wanderer"); ControlDoblajePlugin.Log.LogInfo((object)("[WandererSFX] evento: " + text + " (nombre=" + text8 + ")")); if (!AssetPack.CarpetaExiste(text9)) { return true; } string[] audioFiles2 = CinematicaMultiPistaPlayer.GetAudioFiles(text9, text8 + "*.wav"); if (audioFiles2.Length == 0) { return true; } ControlDoblajePlugin.Log.LogInfo((object)("[WandererSFX] WAVs: " + audioFiles2.Length)); try { ((EventInstance)(ref __instance)).setVolume(0f); } catch { } try { ((EventInstance)(ref __instance)).setReverbLevel(0, 0f); } catch { } Vector3 val13 = ObtenerPosicion(__instance); StudioListener val14 = ListenerCache.Get(); Vector3 val15 = (((Object)(object)val14 != (Object)null) ? ((Component)val14).transform.position : (((Object)(object)Camera.main != (Object)null) ? ((Component)Camera.main).transform.position : val13)); if (Vector3.Distance(val15, val13) <= 40f) { WandererAttackPlayer.ReproducirWav(audioFiles2, val13, Vector3.Distance(val15, val13)); } return true; } if (text.Equals(BUILDING_PATH, StringComparison.OrdinalIgnoreCase)) { string text10 = WandererGestor.BuscarWAV(Path.Combine(ControlDoblajePlugin.VoicesPath, "Wanderer", "USD_C_BuildingFall_01_Detach")); if (text10 == null) { return true; } if (WandererCutscenePlayer.Reproduciendo) { try { ((EventInstance)(ref __instance)).setVolume(0f); } catch { } return true; } try { ((EventInstance)(ref __instance)).setVolume(0f); } catch { } ControlDoblajePlugin.Log.LogInfo((object)("[BuildingFall] Interceptado path=" + text)); WandererCutscenePlayer.Reproducir(text10); return true; } } catch (Exception ex3) { ControlDoblajePlugin.Log.LogInfo((object)("[FMOD:start] excepcion: " + ex3.Message)); } try { if (PlayVoiceoverPatch.EsEventoHorneado(text)) { string poolDirectoRuta = PlayVoiceoverPatch.PoolDirectoRuta; if (poolDirectoRuta != null && Time.realtimeSinceStartup - PlayVoiceoverPatch.PoolDirectoTiempo < 5f) { PlayVoiceoverPatch.PoolDirectoRuta = null; try { ((EventInstance)(ref __instance)).setVolume(0f); } catch { } try { CREATESOUNDEXINFO ex4 = default(CREATESOUNDEXINFO); ex4.cbsize = Marshal.SizeOf(ex4); if ((int)AudioPack.CrearSound(RuntimeManager.CoreSystem, poolDirectoRuta, (MODE)265, ref ex4, out var sound2) == 0) { coreSystem = RuntimeManager.CoreSystem; ChannelGroup val16 = default(ChannelGroup); ((System)(ref coreSystem)).getMasterChannelGroup(ref val16); coreSystem = RuntimeManager.CoreSystem; Channel val17 = default(Channel); if ((int)((System)(ref coreSystem)).playSound(sound2, val16, false, ref val17) == 0) { float volume2 = MultiPistaRunner.LeerVolBus("bus:/Voicelines") * MultiPistaRunner.LeerVolBus("bus:/"); ((Channel)(ref val17)).setVolume(volume2); ((Channel)(ref val17)).setPriority(0); } } } catch { } ControlDoblajePlugin.Log.LogInfo((object)("[Horneado] " + text + " interceptado → Core: " + Path.GetFileName(poolDirectoRuta))); } else { try { ((EventInstance)(ref __instance)).setVolume(1f); } catch { } } return true; } } catch (Exception ex5) { ControlDoblajePlugin.Log.LogInfo((object)("[Horneado] excepcion: " + ex5.Message)); } try { foreach (KeyValuePair cinematicasRegistrada in CinematicaMultiPistaPlayer.CinematicasRegistradas) { bool flag5 = text.Equals(cinematicasRegistrada.Key, StringComparison.OrdinalIgnoreCase); if (!flag5) { string text11 = cinematicasRegistrada.Key.Substring(cinematicasRegistrada.Key.LastIndexOf('/')); flag5 = text.EndsWith(text11, StringComparison.OrdinalIgnoreCase) && text.Length > text11.Length; } if (!flag5) { continue; } string text12 = CinematicaMultiPistaPlayer.ObtenerPrefijo(cinematicasRegistrada.Key); bool flag6 = false; string[] value4 = cinematicasRegistrada.Value; foreach (string text13 in value4) { string path = Path.Combine(ControlDoblajePlugin.VoicesPath, text13); string pathSinExt = Path.Combine(path, text12 + "_" + text13); string pathSinExt2 = Path.Combine(path, text12 + "_" + text13 + "_orig"); if (CinematicaMultiPistaPlayer.ElegirVariante(pathSinExt) != null || CinematicaMultiPistaPlayer.ElegirVariante(pathSinExt2) != null) { flag6 = true; break; } } if (!flag6) { return true; } List list = new List(); string[] value5 = cinematicasRegistrada.Value; foreach (string text14 in value5) { string path2 = Path.Combine(ControlDoblajePlugin.VoicesPath, text14); ControlDoblajePlugin.PersonajeActivo.TryGetValue(text14, out var value6); string pathSinExt3 = Path.Combine(path2, text12 + "_" + text14); string pathSinExt4 = Path.Combine(path2, text12 + "_" + text14 + "_orig"); string text15 = null; if (value6) { text15 = CinematicaMultiPistaPlayer.ElegirVariante(pathSinExt3); } if (text15 == null) { text15 = CinematicaMultiPistaPlayer.ElegirVariante(pathSinExt4); } if (text15 != null) { list.Add(text15); ControlDoblajePlugin.Log.LogInfo((object)("[CineMulti] " + text14 + " → " + Path.GetFileName(text15))); } else { ControlDoblajePlugin.Log.LogInfo((object)("[CineMulti] " + text14 + " → sin audio")); } } if (list.Count < cinematicasRegistrada.Value.Length) { ControlDoblajePlugin.Log.LogInfo((object)("[CineMulti] multipista incompleta (" + list.Count + "/" + cinematicasRegistrada.Value.Length + " pistas) → nativo intacto (capadas juntas)")); return true; } ControlDoblajePlugin.Log.LogInfo((object)("[CineMulti] Interceptado " + text + " pistas=" + list.Count)); if (list.Count > 0) { try { ((EventInstance)(ref __instance)).setVolume(0f); } catch { } CinematicaMultiPistaPlayer.RegistrarInstanciaFMOD(__instance); CinematicaMultiPistaPlayer.MarcarCinematicaActiva(text); bool esCinematica = text.StartsWith("event:/NPCs/", StringComparison.OrdinalIgnoreCase); CinematicaMultiPistaPlayer.ReproducirSecundarias(list, esCinematica); CinematicaMultiPistaPlayer.SilenciarVoicelinesActivos(); CinematicaMultiPistaPlayer.ActivarSilencioVoiceline(); } return true; } } catch (Exception ex6) { ControlDoblajePlugin.Log.LogInfo((object)("[CineMulti] excepcion: " + ex6.Message)); } return true; } } public static class FMODStopHelper { public static EventInstance NPCVideoActivo; public static bool NPCVideoRegistrado = false; public static float NPCVideoStartTime = -999f; public static int UltimoPosicionSkipMs = 0; public static float UltimoStopTime = -999f; public static int CicloInternoWatchdogGen = 0; public static void RegistrarNPCVideo(EventInstance inst, bool esNPCVideoReal = false) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) NPCVideoActivo = inst; NPCVideoRegistrado = true; NPCVideoStartTime = Time.realtimeSinceStartup; if (esNPCVideoReal) { CicloInternoWatchdogGen++; } ControlDoblajePlugin.Log.LogInfo((object)("[CineMulti] NPC_Video registrado para detección de skip (esNPCVideoReal=" + esNPCVideoReal + ")")); if ((Object)(object)CinematicaMultiPistaPlayer.RunnerActivo != (Object)null && !CinematicaMultiPistaPlayer.RunnerActivo.FueSoltado && UltimoStopTime > 0f && Time.realtimeSinceStartup - UltimoStopTime < 0.3f && UltimoPosicionSkipMs > 0) { ControlDoblajePlugin.Log.LogInfo((object)("[CineMulti] Skip-resume: buscando pos=" + UltimoPosicionSkipMs + "ms en runner activo")); CinematicaMultiPistaPlayer.RunnerActivo.BuscarPosicion((uint)UltimoPosicionSkipMs); } } private static IEnumerator WatchdogCicloInterno(int gen) { yield return (object)new WaitForSecondsRealtime(0.8f); if (gen != CicloInternoWatchdogGen || (Object)(object)CinematicaMultiPistaPlayer.RunnerActivo == (Object)null) { yield break; } ControlDoblajePlugin.Log.LogInfo((object)"[CineMulti] Watchdog ciclo interno: sin NPC_Video nuevo en 2.5 s — deteniendo runner"); if (CinematicaMultiPistaPlayer.RunnerActivo.TieneCanalesActivos) { if (CinematicaMultiPistaPlayer.RunnerActivo.FueSoltado) { ControlDoblajePlugin.Log.LogInfo((object)"[CineMulti] Watchdog ciclo interno: runner ya soltado, WAV terminando solo — ignorar"); } else if (!CinematicaMultiPistaPlayer.RunnerActivo.EsCinematica) { ControlDoblajePlugin.Log.LogInfo((object)"[CineMulti] Watchdog ciclo interno: runner no-cinémático (voiceline+bus) — ignorar, Update() lo destruye solo"); } else { CinematicaMultiPistaPlayer.RunnerActivo.DetenerInteligente(); } } else if (CinematicaMultiPistaPlayer.RunnerActivo.EsCinematica) { CinematicaMultiPistaPlayer.RunnerActivo = null; } } public static bool OnInstanceDetenida(EventInstance inst, bool incluyeNPCVideo = true) { //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0275: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) try { if ((Object)(object)CinematicaMultiPistaPlayer.RunnerActivo == (Object)null && (Object)(object)WandererCutscenePlayer.RunnerActivo == (Object)null) { return true; } EventDescription val = default(EventDescription); ((EventInstance)(ref inst)).getDescription(ref val); string text = ""; ((EventDescription)(ref val)).getPath(ref text); if (string.IsNullOrEmpty(text)) { return true; } if ((Object)(object)WandererCutscenePlayer.RunnerActivo != (Object)null && (text.Equals("event:/SFX/USBright/USB_CS_WindowRevealFlyby", StringComparison.OrdinalIgnoreCase) || text.Equals("event:/SFX/USDark/BuildingFall_01", StringComparison.OrdinalIgnoreCase))) { ControlDoblajePlugin.Log.LogInfo((object)("[WandererCS] Skip/fin detectado en " + text + " — deteniendo runner")); WandererCutscenePlayer.RunnerActivo.Detener(); WandererCutscenePlayer.RunnerActivo = null; } if ((Object)(object)CinematicaMultiPistaPlayer.RunnerActivo == (Object)null) { return true; } bool flag = CinematicaMultiPistaPlayer.CinematicasRegistradas.ContainsKey(text) && CinematicaMultiPistaPlayer.TieneInstanciaFMOD && inst.handle == CinematicaMultiPistaPlayer.InstanciaFMODActiva.handle; bool flag2 = incluyeNPCVideo && NPCVideoRegistrado && (text.Equals("event:/NPCs/Voicelines/NPC_Video", StringComparison.OrdinalIgnoreCase) || text.Equals("event:/NPCs/Voicelines/NPC_Voiceline", StringComparison.OrdinalIgnoreCase)) && inst.handle == NPCVideoActivo.handle; if (flag || flag2) { int num = -1; if (flag2) { try { ((EventInstance)(ref inst)).getTimelinePosition(ref num); } catch { num = -1; } } if (Time.realtimeSinceStartup - NPCVideoStartTime < 0.35f && num >= 0 && num < 2000) { ControlDoblajePlugin.Log.LogInfo((object)("[CineMulti] stop() ignorado para runner (ciclo interno) pos=" + num + "ms t=" + (Time.realtimeSinceStartup - NPCVideoStartTime).ToString("F2") + "s en " + text)); CoroutineHolder.Inicia(WatchdogCicloInterno(++CicloInternoWatchdogGen)); return true; } if (flag2 && num >= 0) { UltimoPosicionSkipMs = num; UltimoStopTime = Time.realtimeSinceStartup; ControlDoblajePlugin.Log.LogInfo((object)("[CineMulti] Stop en pos=" + num + "ms")); } else if (flag2) { try { int ultimoPosicionSkipMs = 0; ((EventInstance)(ref inst)).getTimelinePosition(ref ultimoPosicionSkipMs); UltimoPosicionSkipMs = ultimoPosicionSkipMs; UltimoStopTime = Time.realtimeSinceStartup; ControlDoblajePlugin.Log.LogInfo((object)("[CineMulti] Stop en pos=" + ultimoPosicionSkipMs + "ms")); } catch { } } NPCVideoRegistrado = false; ControlDoblajePlugin.Log.LogInfo((object)("[CineMulti] Fin/skip detectado pos=" + num + "ms — evaluando runner")); if (CinematicaMultiPistaPlayer.RunnerActivo.TieneCanalesActivos) { if (CinematicaMultiPistaPlayer.RunnerActivo.FueSoltado) { ControlDoblajePlugin.Log.LogInfo((object)"[CineMulti] stop() ignorado — runner ya soltado, dejando terminar WAV"); } else { CinematicaMultiPistaPlayer.RunnerActivo.DetenerInteligente(); if (!CinematicaMultiPistaPlayer.RunnerActivo.FueSoltado && (Object)(object)CinematicaMultiPistaPlayer.AmbienterRunnerActivo != (Object)null) { CinematicaMultiPistaPlayer.AmbienterRunnerActivo.Detener(); CinematicaMultiPistaPlayer.AmbienterRunnerActivo = null; ControlDoblajePlugin.Log.LogInfo((object)"[CineMulti] Skip → AmbienterRunner detenido"); } } } else { CinematicaMultiPistaPlayer.RunnerActivo.Detener(); CinematicaMultiPistaPlayer.RunnerActivo = null; if ((Object)(object)CinematicaMultiPistaPlayer.AmbienterRunnerActivo != (Object)null) { CinematicaMultiPistaPlayer.AmbienterRunnerActivo.Detener(); CinematicaMultiPistaPlayer.AmbienterRunnerActivo = null; ControlDoblajePlugin.Log.LogInfo((object)"[CineMulti] Runner terminado → AmbienterRunner detenido"); } } } } catch { } return true; } } [HarmonyPatch(typeof(EventInstance), "stop")] public static class FMODDirectStopPatch { private static bool Prefix(EventInstance __instance) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) return FMODStopHelper.OnInstanceDetenida(__instance); } } [HarmonyPatch(typeof(EventInstance), "release")] public static class FMODDirectReleasePatch { private static void Prefix(EventInstance __instance) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) FMODStopHelper.OnInstanceDetenida(__instance, incluyeNPCVideo: false); } } [HarmonyPatch(typeof(System), "getSoundInfo")] public static class FMODGetSoundInfoPatch { private static string _lastWavPath; private static float _lastWavTime; private const float WAV_RETRIGGER_COOLDOWN = 30f; private static GCHandle _handle; private static bool _handleActivo = false; private static readonly List> _pinnedPaths = new List>(); private const float PIN_TTL = 120f; private static IntPtr PinPath(string path) { float realtimeSinceStartup = Time.realtimeSinceStartup; for (int num = _pinnedPaths.Count - 1; num >= 0; num--) { if (realtimeSinceStartup - _pinnedPaths[num].Value > 120f) { try { if (_pinnedPaths[num].Key.IsAllocated) { _pinnedPaths[num].Key.Free(); } } catch { } _pinnedPaths.RemoveAt(num); } } byte[] bytes = Encoding.UTF8.GetBytes(path + "\0"); GCHandle key = GCHandle.Alloc(bytes, GCHandleType.Pinned); _pinnedPaths.Add(new KeyValuePair(key, realtimeSinceStartup)); return key.AddrOfPinnedObject(); } private static void LlenarInfoAudio(string ruta, out SOUND_INFO info) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) info = default(SOUND_INFO); info.exinfo = default(CREATESOUNDEXINFO); info.exinfo.cbsize = Marshal.SizeOf(typeof(CREATESOUNDEXINFO)); info.subsoundindex = -1; if (AssetPack.EstaEnPack(ruta)) { byte[] array = AssetPack.LeerBytes(ruta); info.name_or_data = PinBytes(array); info.exinfo.length = (uint)array.Length; info.mode = (MODE)((array.Length < 1500000) ? 2049 : 2177); } else { info.name_or_data = PinPath(ruta); info.mode = (MODE)129; } } private static IntPtr PinBytes(byte[] datos) { float realtimeSinceStartup = Time.realtimeSinceStartup; for (int num = _pinnedPaths.Count - 1; num >= 0; num--) { if (realtimeSinceStartup - _pinnedPaths[num].Value > 120f) { try { if (_pinnedPaths[num].Key.IsAllocated) { _pinnedPaths[num].Key.Free(); } } catch { } _pinnedPaths.RemoveAt(num); } } GCHandle key = GCHandle.Alloc(datos, GCHandleType.Pinned); _pinnedPaths.Add(new KeyValuePair(key, realtimeSinceStartup)); return key.AddrOfPinnedObject(); } private static bool Prefix(string key, out SOUND_INFO info, ref RESULT __result) { //IL_0489: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_05dc: Unknown result type (might be due to invalid IL or missing references) //IL_03df: Unknown result type (might be due to invalid IL or missing references) //IL_03e4: Unknown result type (might be due to invalid IL or missing references) //IL_03ea: Unknown result type (might be due to invalid IL or missing references) //IL_03f0: Invalid comparison between Unknown and I4 //IL_03fe: Unknown result type (might be due to invalid IL or missing references) //IL_041a: Unknown result type (might be due to invalid IL or missing references) //IL_0427: Unknown result type (might be due to invalid IL or missing references) //IL_042d: Invalid comparison between Unknown and I4 //IL_043a: Unknown result type (might be due to invalid IL or missing references) //IL_0442: Unknown result type (might be due to invalid IL or missing references) //IL_0444: Unknown result type (might be due to invalid IL or missing references) //IL_0449: Unknown result type (might be due to invalid IL or missing references) //IL_044f: Invalid comparison between Unknown and I4 //IL_0264: Unknown result type (might be due to invalid IL or missing references) //IL_0269: Unknown result type (might be due to invalid IL or missing references) //IL_026f: Unknown result type (might be due to invalid IL or missing references) //IL_0275: Invalid comparison between Unknown and I4 //IL_0477: Unknown result type (might be due to invalid IL or missing references) //IL_0283: Unknown result type (might be due to invalid IL or missing references) //IL_029f: Unknown result type (might be due to invalid IL or missing references) //IL_02ac: Unknown result type (might be due to invalid IL or missing references) //IL_02b2: Invalid comparison between Unknown and I4 //IL_02bf: Unknown result type (might be due to invalid IL or missing references) //IL_02c7: Unknown result type (might be due to invalid IL or missing references) //IL_02c9: Unknown result type (might be due to invalid IL or missing references) //IL_02ce: Unknown result type (might be due to invalid IL or missing references) //IL_02d4: Invalid comparison between Unknown and I4 //IL_02e4: Unknown result type (might be due to invalid IL or missing references) //IL_0591: Unknown result type (might be due to invalid IL or missing references) if (key != null) { bool flag = key.EndsWith(".wav", StringComparison.OrdinalIgnoreCase) || key.EndsWith(".ogg", StringComparison.OrdinalIgnoreCase); ControlDoblajePlugin.Log.LogInfo((object)("[getSoundInfo_KEY]" + (flag ? "[AUDIO] " : " ") + "\"" + key + "\"")); } if (key != null && PlayVoiceoverPatch.DubDialogo.TryGetValue(key, out var value)) { string text = CinematicaMultiPistaPlayer.ResolverAudio(value); if (AssetPack.Existe(text)) { info = default(SOUND_INFO); info.exinfo = default(CREATESOUNDEXINFO); info.exinfo.cbsize = Marshal.SizeOf(typeof(CREATESOUNDEXINFO)); info.subsoundindex = -1; if (AssetPack.EstaEnPack(text)) { byte[] array = AssetPack.LeerBytes(text); info.name_or_data = PinBytes(array); info.exinfo.length = (uint)array.Length; info.mode = (MODE)((array.Length < 1500000) ? 2049 : 2177); } else { info.name_or_data = PinPath(text); info.mode = (MODE)129; } __result = (RESULT)0; ControlDoblajePlugin.Log.LogInfo((object)("[FMOD] getSoundInfo dub-dialogo → " + Path.GetFileName(text))); return false; } } System studioSystem; if (key != null && key.IndexOf("D1G_Ending_05_ENAWillBeReturningIn", StringComparison.OrdinalIgnoreCase) >= 0 && !key.EndsWith(".wav", StringComparison.OrdinalIgnoreCase) && !key.EndsWith(".ogg", StringComparison.OrdinalIgnoreCase)) { bool value2 = false; bool value3 = false; ControlDoblajePlugin.PersonajeActivo.TryGetValue("Froggy", out value2); ControlDoblajePlugin.PersonajeActivo.TryGetValue("Dratula", out value3); string text2 = null; string text3 = null; if (value2) { text2 = WandererGestor.BuscarWAV(Path.Combine(ControlDoblajePlugin.VoicesPath, "Froggy", "D1G_Ending_05_ENAWillBeReturningIn_Froggy")); } if (value3) { text3 = WandererGestor.BuscarWAV(Path.Combine(ControlDoblajePlugin.VoicesPath, "Dratula", "D1G_Ending_05_ENAWillBeReturningIn_Dratula")); } string text4 = text2 ?? text3; string text5 = ((text2 != null && text3 != null) ? text3 : null); if (text4 != null) { LlenarInfoAudio(text4, out info); __result = (RESULT)0; if (text5 != null) { try { studioSystem = RuntimeManager.StudioSystem; System sys = default(System); if ((int)((System)(ref studioSystem)).getCoreSystem(ref sys) == 0) { CREATESOUNDEXINFO ex = new CREATESOUNDEXINFO { cbsize = Marshal.SizeOf(typeof(CREATESOUNDEXINFO)) }; if ((int)AudioPack.CrearSound(sys, text5, (MODE)264, ref ex, out var sound) == 0) { ChannelGroup val = default(ChannelGroup); ((System)(ref sys)).getMasterChannelGroup(ref val); Channel val2 = default(Channel); if ((int)((System)(ref sys)).playSound(sound, val, false, ref val2) == 0) { ((Channel)(ref val2)).setVolume(0.75f); ControlDoblajePlugin.Log.LogInfo((object)("[D1GEnding] Secundario Core: " + Path.GetFileName(text5))); } } } } catch (Exception ex2) { ControlDoblajePlugin.Log.LogInfo((object)("[D1GEnding] Secundario excepcion: " + ex2.Message)); } } ControlDoblajePlugin.Log.LogInfo((object)("[D1GEnding] getSoundInfo interceptado: key=" + key + " primary=" + Path.GetFileName(text4))); return false; } } if (key != null && key.IndexOf("USB_S_AlexScream", StringComparison.OrdinalIgnoreCase) >= 0 && !key.EndsWith(".wav", StringComparison.OrdinalIgnoreCase) && !key.EndsWith(".ogg", StringComparison.OrdinalIgnoreCase) && ControlDoblajePlugin.PersonajeActivo.TryGetValue("HoarderAlex", out var value4) && value4) { string text6 = WandererGestor.BuscarWAV(Path.Combine(ControlDoblajePlugin.VoicesPath, "HoarderAlex", "USB_S_AlexScream")); if (text6 != null) { try { studioSystem = RuntimeManager.StudioSystem; System sys2 = default(System); if ((int)((System)(ref studioSystem)).getCoreSystem(ref sys2) == 0) { CREATESOUNDEXINFO ex3 = new CREATESOUNDEXINFO { cbsize = Marshal.SizeOf(typeof(CREATESOUNDEXINFO)) }; if ((int)AudioPack.CrearSound(sys2, text6, (MODE)265, ref ex3, out var sound2) == 0) { ChannelGroup val3 = default(ChannelGroup); ((System)(ref sys2)).getMasterChannelGroup(ref val3); Channel val4 = default(Channel); if ((int)((System)(ref sys2)).playSound(sound2, val3, false, ref val4) == 0) { float num = MultiPistaRunner.LeerVolBus("bus:/"); float num2 = MultiPistaRunner.LeerVolBus("bus:/SFX"); ((Channel)(ref val4)).setVolume(num2 * num); } } } } catch { } info = default(SOUND_INFO); __result = (RESULT)31; ControlDoblajePlugin.Log.LogInfo((object)("[AlexScream] getSoundInfo → Core channel directo: " + Path.GetFileName(text6))); return false; } } if (key != null && (key.EndsWith(".wav", StringComparison.OrdinalIgnoreCase) || key.EndsWith(".ogg", StringComparison.OrdinalIgnoreCase))) { string wavPath = key; if (key.StartsWith("Voices/", StringComparison.OrdinalIgnoreCase) || key.StartsWith("Voices\\", StringComparison.OrdinalIgnoreCase)) { string directoryName = Path.GetDirectoryName(ControlDoblajePlugin.VoicesPath); wavPath = Path.Combine(directoryName, key.Replace('/', Path.DirectorySeparatorChar)); } wavPath = CinematicaMultiPistaPlayer.ResolverAudio(wavPath); if (AssetPack.Existe(wavPath)) { if (wavPath == _lastWavPath && Time.realtimeSinceStartup - _lastWavTime < 30f) { ControlDoblajePlugin.Log.LogInfo((object)("[FMOD] getSoundInfo anti-retrigger: " + Path.GetFileName(wavPath))); info = default(SOUND_INFO); return true; } _lastWavPath = wavPath; _lastWavTime = Time.realtimeSinceStartup; LlenarInfoAudio(wavPath, out info); __result = (RESULT)0; ControlDoblajePlugin.Log.LogInfo((object)("[FMOD] getSoundInfo → " + Path.GetFileName(wavPath))); return false; } } info = default(SOUND_INFO); return true; } } public static class WandererCutscenePlayer { public static float UltimoDisparo = -999f; public static bool Reproduciendo = false; public static WandererCSSoundRunner RunnerActivo = null; public unsafe static void Reproducir(string ruta) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_002c: 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) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Invalid comparison between Unknown and I4 //IL_007b: 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_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Invalid comparison between Unknown and I4 //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Unknown result type (might be due to invalid IL or missing references) //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) //IL_0177: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Invalid comparison between Unknown and I4 //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_0110: 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) //IL_0199: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_01cf: Unknown result type (might be due to invalid IL or missing references) //IL_01da: Unknown result type (might be due to invalid IL or missing references) //IL_01e1: Expected O, but got Unknown //IL_01ec: 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_0184: Unknown result type (might be due to invalid IL or missing references) if (Reproduciendo) { return; } Reproduciendo = true; CREATESOUNDEXINFO ex = default(CREATESOUNDEXINFO); ex.cbsize = Marshal.SizeOf(ex); RESULT val = AudioPack.CrearSound(RuntimeManager.CoreSystem, ruta, (MODE)256, ref ex, out var sound); ControlDoblajePlugin.Log.LogInfo((object)("[WandererCS] createSound=" + ((object)(*(RESULT*)(&val))/*cast due to .constrained prefix*/).ToString())); if ((int)val > 0) { Reproduciendo = false; return; } ChannelGroup val2 = default(ChannelGroup); bool flag = false; string[] array = new string[5] { "bus:/Voice", "bus:/Voices", "bus:/Characters", "bus:/SFX", "bus:/" }; Bus val3 = default(Bus); foreach (string text in array) { System studioSystem = RuntimeManager.StudioSystem; if ((int)((System)(ref studioSystem)).getBus(text, ref val3) == 0 && (int)((Bus)(ref val3)).getChannelGroup(ref val2) == 0) { flag = true; break; } } System coreSystem; if (!flag) { coreSystem = RuntimeManager.CoreSystem; ((System)(ref coreSystem)).getMasterChannelGroup(ref val2); } ControlDoblajePlugin.Log.LogInfo((object)("[WandererCS] grupo valido=" + ((ChannelGroup)(ref val2)).hasHandle())); coreSystem = RuntimeManager.CoreSystem; Channel c = default(Channel); val = ((System)(ref coreSystem)).playSound(sound, val2, true, ref c); ControlDoblajePlugin.Log.LogInfo((object)("[WandererCS] playSound=" + ((object)(*(RESULT*)(&val))/*cast due to .constrained prefix*/).ToString())); if ((int)val > 0) { ((Sound)(ref sound)).release(); Reproduciendo = false; return; } ((Channel)(ref c)).setVolume(1f); float num = 0f; ((Channel)(ref c)).getVolume(ref num); ControlDoblajePlugin.Log.LogInfo((object)("[WandererCS] vol=" + num)); ((Channel)(ref c)).setPaused(false); GameObject val4 = new GameObject("_WandererCS"); WandererCSSoundRunner wandererCSSoundRunner = val4.AddComponent(); wandererCSSoundRunner.Init(sound, c); RunnerActivo = wandererCSSoundRunner; } } public class WandererCSSoundRunner : MonoBehaviour { private Sound _sound; private Channel _channel; private float _duracion = -1f; private float _inicio = -1f; private bool _listo = false; public void Init(Sound s, Channel c) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) _sound = s; _channel = c; uint num = 0u; if ((int)((Sound)(ref s)).getLength(ref num, (TIMEUNIT)1) == 0 && num != 0) { _duracion = (float)num / 1000f; } else { _duracion = 30f; } ControlDoblajePlugin.Log.LogInfo((object)("[WandererCS] duracion=" + _duracion.ToString("F2") + "s")); _inicio = Time.realtimeSinceStartup; _listo = true; } private void Update() { //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) if (!_listo) { return; } float num = Time.realtimeSinceStartup - _inicio; if (!(num < _duracion)) { try { ((Channel)(ref _channel)).stop(); } catch { } WandererCutscenePlayer.Reproduciendo = false; if ((Object)(object)WandererCutscenePlayer.RunnerActivo == (Object)(object)this) { WandererCutscenePlayer.RunnerActivo = null; } ((Sound)(ref _sound)).release(); Object.Destroy((Object)(object)((Component)this).gameObject); } } public void Detener() { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) try { ((Channel)(ref _channel)).stop(); } catch { } try { ((Sound)(ref _sound)).release(); } catch { } WandererCutscenePlayer.Reproduciendo = false; if ((Object)(object)WandererCutscenePlayer.RunnerActivo == (Object)(object)this) { WandererCutscenePlayer.RunnerActivo = null; } Object.Destroy((Object)(object)((Component)this).gameObject); } } public static class WandererAttackPlayer { public const float DIST_MAX = 40f; public const float DRY_START = 17f; public const float ATAQUE_VOL_BASE = 0.6f; private static int _ultimoIndice = -1; public static WandererAttackSoundRunner RunnerActivo = null; public static WandererAttackSequenceRunner SequenceActiva = null; public const float DELAY_GRUMBLE = 0.7f; public const float DELAY_IMPACT = 4.9f; public const float DELAY_COMPLAIN = 6.8f; public static void DetenerSiActivo() { if ((Object)(object)RunnerActivo != (Object)null) { RunnerActivo.Detener(); RunnerActivo = null; } if ((Object)(object)SequenceActiva != (Object)null) { if ((Object)(object)((Component)SequenceActiva).gameObject != (Object)null) { Object.Destroy((Object)(object)((Component)SequenceActiva).gameObject); } SequenceActiva = null; } } public unsafe static void ReproducirWav(string[] wavs, Vector3 posWanderer, float dist) { //IL_0302: Unknown result type (might be due to invalid IL or missing references) //IL_030d: Unknown result type (might be due to invalid IL or missing references) //IL_0314: Expected O, but got Unknown //IL_031f: Unknown result type (might be due to invalid IL or missing references) //IL_0320: Unknown result type (might be due to invalid IL or missing references) //IL_0322: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Invalid comparison between Unknown and I4 //IL_0333: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: 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_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Invalid comparison between Unknown and I4 //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_0162: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Unknown result type (might be due to invalid IL or missing references) //IL_018e: Invalid comparison between Unknown and I4 //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_01ae: Unknown result type (might be due to invalid IL or missing references) //IL_01bb: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_01d3: Unknown result type (might be due to invalid IL or missing references) //IL_01d5: Unknown result type (might be due to invalid IL or missing references) //IL_01d9: 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_0205: Unknown result type (might be due to invalid IL or missing references) //IL_020d: Unknown result type (might be due to invalid IL or missing references) //IL_021f: Unknown result type (might be due to invalid IL or missing references) //IL_024d: Unknown result type (might be due to invalid IL or missing references) //IL_0255: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Unknown result type (might be due to invalid IL or missing references) //IL_02a7: Unknown result type (might be due to invalid IL or missing references) //IL_02ac: Unknown result type (might be due to invalid IL or missing references) //IL_02b4: Unknown result type (might be due to invalid IL or missing references) //IL_02b9: Unknown result type (might be due to invalid IL or missing references) //IL_02bb: Unknown result type (might be due to invalid IL or missing references) //IL_02be: Invalid comparison between Unknown and I4 //IL_02ca: Unknown result type (might be due to invalid IL or missing references) //IL_02cc: Unknown result type (might be due to invalid IL or missing references) //IL_02d8: Unknown result type (might be due to invalid IL or missing references) //IL_02e4: Unknown result type (might be due to invalid IL or missing references) //IL_02ed: Unknown result type (might be due to invalid IL or missing references) int num; if (wavs.Length == 1) { num = 0; } else { do { num = Random.Range(0, wavs.Length); } while (num == _ultimoIndice); } _ultimoIndice = num; string text = wavs[num]; ControlDoblajePlugin.Log.LogInfo((object)("[WandererAttack] -> " + Path.GetFileName(text) + " dist=" + dist.ToString("F1"))); CREATESOUNDEXINFO ex = default(CREATESOUNDEXINFO); ex.cbsize = Marshal.SizeOf(ex); RESULT val = AudioPack.CrearSound(RuntimeManager.CoreSystem, text, (MODE)524560, ref ex, out var sound); ControlDoblajePlugin.Log.LogInfo((object)("[WandererAttack] createSound=" + ((object)(*(RESULT*)(&val))/*cast due to .constrained prefix*/).ToString())); if ((int)val > 0) { return; } ChannelGroup val2 = default(ChannelGroup); string[] array = new string[3] { "bus:/SFX", "bus:/Ambience", "bus:/" }; Bus val3 = default(Bus); foreach (string text2 in array) { System studioSystem = RuntimeManager.StudioSystem; if ((int)((System)(ref studioSystem)).getBus(text2, ref val3) == 0 && (int)((Bus)(ref val3)).getChannelGroup(ref val2) == 0) { break; } } System coreSystem; if (!((ChannelGroup)(ref val2)).hasHandle()) { coreSystem = RuntimeManager.CoreSystem; ((System)(ref coreSystem)).getMasterChannelGroup(ref val2); } coreSystem = RuntimeManager.CoreSystem; Channel c = default(Channel); val = ((System)(ref coreSystem)).playSound(sound, val2, true, ref c); ControlDoblajePlugin.Log.LogInfo((object)("[WandererAttack] playSound=" + ((object)(*(RESULT*)(&val))/*cast due to .constrained prefix*/).ToString())); if ((int)val > 0) { ((Sound)(ref sound)).release(); return; } VECTOR val4 = new VECTOR { x = posWanderer.x, y = posWanderer.y, z = posWanderer.z }; VECTOR val5 = new VECTOR { x = 0f, y = 0f, z = 0f }; ((Channel)(ref c)).set3DAttributes(ref val4, ref val5); ((Channel)(ref c)).set3DMinMaxDistance(40f, 4000f); float num2 = Mathf.Pow(Mathf.Clamp01(1f - dist / 40f), 2f); ((Channel)(ref c)).setVolume(0.6f * num2); DSP val6 = default(DSP); bool flag = false; try { float num3 = Mathf.Clamp01(dist / 17f); float num4 = Mathf.Clamp01((dist - 17f) / 23f); float num5 = Mathf.Lerp(-16f, -2f, num3); float num6 = Mathf.Lerp(0f, -18f, num4); coreSystem = RuntimeManager.CoreSystem; RESULT val7 = ((System)(ref coreSystem)).createDSPByType((DSP_TYPE)19, ref val6); if ((int)val7 == 0) { ((Channel)(ref c)).addDSP(0, val6); ((DSP)(ref val6)).setParameterFloat(11, num5); ((DSP)(ref val6)).setParameterFloat(12, num6); ((DSP)(ref val6)).setActive(true); flag = true; } } catch { } ((Channel)(ref c)).setPaused(false); GameObject val8 = new GameObject("_WandererAttackSound"); WandererAttackSoundRunner wandererAttackSoundRunner = val8.AddComponent(); wandererAttackSoundRunner.Init(sound, c, posWanderer); if (flag) { wandererAttackSoundRunner.SetReverbDSP(val6); } RunnerActivo = wandererAttackSoundRunner; } public static void ReproducirSecuencia(string carpeta, Vector3 posW, float dist) { //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Expected O, but got Unknown //IL_0050: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)SequenceActiva != (Object)null) { if ((Object)(object)((Component)SequenceActiva).gameObject != (Object)null) { Object.Destroy((Object)(object)((Component)SequenceActiva).gameObject); } SequenceActiva = null; } GameObject val = new GameObject("_WandererAttackSeq"); WandererAttackSequenceRunner wandererAttackSequenceRunner = val.AddComponent(); wandererAttackSequenceRunner.Init(carpeta, posW, dist); SequenceActiva = wandererAttackSequenceRunner; } } public class WandererAttackSoundRunner : MonoBehaviour { private Sound _sound; private Channel _channel; private DSP _reverbDSP; private bool _hasReverb = false; private float _duracion = -1f; private float _inicio = -1f; private bool _listo = false; private Vector3 _posW; public bool IsListo => _listo; public void Init(Sound s, Channel c, Vector3 posW) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) _sound = s; _channel = c; _posW = posW; uint num = 0u; _duracion = (((int)((Sound)(ref s)).getLength(ref num, (TIMEUNIT)1) == 0 && num != 0) ? ((float)num / 1000f + 0.2f) : 8f); _inicio = Time.realtimeSinceStartup; _listo = true; } public void SetReverbDSP(DSP dsp) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Unknown result type (might be due to invalid IL or missing references) _reverbDSP = dsp; _hasReverb = true; } public void ActualizarVolumen(Vector3 posListener) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) if (!_listo) { return; } float num = Vector3.Distance(posListener, _posW); float num2 = Mathf.Pow(Mathf.Clamp01(1f - num / 40f), 2f); try { ((Channel)(ref _channel)).setVolume(0.6f * num2 * CinematicaDuckingManager.WandererDuckFactor); } catch { } if (!_hasReverb) { return; } try { float num3 = Mathf.Clamp01(num / 17f); float num4 = Mathf.Clamp01((num - 17f) / 23f); ((DSP)(ref _reverbDSP)).setParameterFloat(11, Mathf.Lerp(-16f, -2f, num3)); ((DSP)(ref _reverbDSP)).setParameterFloat(12, Mathf.Lerp(0f, -18f, num4)); } catch { } } private void Update() { //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) if (!_listo) { return; } if (Time.realtimeSinceStartup - _inicio >= _duracion) { Detener(); return; } try { StudioListener val = ListenerCache.Get(); Vector3 posListener = (((Object)(object)val != (Object)null) ? ((Component)val).transform.position : (((Object)(object)Camera.main != (Object)null) ? ((Component)Camera.main).transform.position : _posW)); ActualizarVolumen(posListener); } catch { } } public void Detener() { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) _listo = false; try { ((Channel)(ref _channel)).stop(); } catch { } if (_hasReverb) { _hasReverb = false; try { ((Channel)(ref _channel)).removeDSP(_reverbDSP); } catch { } try { ((DSP)(ref _reverbDSP)).release(); } catch { } } try { ((Sound)(ref _sound)).release(); } catch { } if ((Object)(object)WandererAttackPlayer.RunnerActivo == (Object)(object)this) { WandererAttackPlayer.RunnerActivo = null; } if ((Object)(object)((Component)this).gameObject != (Object)null) { Object.Destroy((Object)(object)((Component)this).gameObject); } } private void OnDestroy() { if ((Object)(object)WandererAttackPlayer.RunnerActivo == (Object)(object)this) { WandererAttackPlayer.RunnerActivo = null; } } } public class WandererAttackSequenceRunner : MonoBehaviour { private string _carpeta; private Vector3 _posW; private float _dist; private float _inicio; private bool _impactListo = false; private bool _grumbleListo = false; private bool _complainListo = false; public void Init(string carpeta, Vector3 posW, float dist) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) _carpeta = carpeta; _posW = posW; _dist = dist; _inicio = Time.realtimeSinceStartup; } private void Update() { //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_020b: Unknown result type (might be due to invalid IL or missing references) if (!ControlDoblajePlugin.PersonajeActivo.TryGetValue("Wanderer", out var value) || !value) { if ((Object)(object)WandererAttackPlayer.SequenceActiva == (Object)(object)this) { WandererAttackPlayer.SequenceActiva = null; } Object.Destroy((Object)(object)((Component)this).gameObject); return; } float num = Time.realtimeSinceStartup - _inicio; if (!_impactListo && num >= 4.9f) { _impactListo = true; string[] audioFiles = CinematicaMultiPistaPlayer.GetAudioFiles(_carpeta, "USB_SP_Wanderer_Impact_Long*_es.wav"); if (audioFiles.Length == 0) { audioFiles = CinematicaMultiPistaPlayer.GetAudioFiles(_carpeta, "USB_SP_Wanderer_Impact_Long*.wav"); } if (audioFiles.Length != 0) { ControlDoblajePlugin.Log.LogInfo((object)("[WandererSeq] Impact t=" + num.ToString("F2"))); WandererAttackPlayer.ReproducirWav(audioFiles, _posW, _dist); } } if (!_grumbleListo && num >= 0.7f) { _grumbleListo = true; string[] audioFiles2 = CinematicaMultiPistaPlayer.GetAudioFiles(_carpeta, "USB_SP_Wanderer_Grumble_0?_es.wav"); if (audioFiles2.Length == 0) { audioFiles2 = CinematicaMultiPistaPlayer.GetAudioFiles(_carpeta, "USB_SP_Wanderer_Grumble_0?.wav"); } if (audioFiles2.Length != 0) { ControlDoblajePlugin.Log.LogInfo((object)("[WandererSeq] Grumble t=" + num.ToString("F2"))); WandererAttackPlayer.ReproducirWav(audioFiles2, _posW, _dist); } } if (!_complainListo && num >= 6.8f) { _complainListo = true; string[] audioFiles3 = CinematicaMultiPistaPlayer.GetAudioFiles(_carpeta, "USB_SP_Wanderer_Complain_0?_es.wav"); if (audioFiles3.Length == 0) { audioFiles3 = CinematicaMultiPistaPlayer.GetAudioFiles(_carpeta, "USB_SP_Wanderer_Complain_0?.wav"); } if (audioFiles3.Length != 0) { ControlDoblajePlugin.Log.LogInfo((object)("[WandererSeq] Complain t=" + num.ToString("F2"))); WandererAttackPlayer.ReproducirWav(audioFiles3, _posW, _dist); } WandererAttackPlayer.SequenceActiva = null; Object.Destroy((Object)(object)((Component)this).gameObject); } } private void OnDestroy() { if ((Object)(object)WandererAttackPlayer.SequenceActiva == (Object)(object)this) { WandererAttackPlayer.SequenceActiva = null; } } } public static class CinematicaMultiPistaPlayer { public static readonly Dictionary CinematicasRegistradas = new Dictionary(StringComparer.OrdinalIgnoreCase) { { "event:/Cutscenes/CS_HubRendezvousSFX", new string[4] { "Dratula", "Froggy", "Meanie", "Salespersone" } }, { "event:/Cutscenes/CS_EndingLonelyDoor_03", new string[2] { "Froggy", "Dratula" } }, { "event:/NPCs/Voicelines/VL_CS_CoreEntrance_01", new string[1] { "Meanie" } }, { "event:/NPCs/Voicelines/VL_CS_CoreEntrance_02", new string[1] { "Meanie" } }, { "event:/NPCs/Voicelines/VL_CS_Theodora_1I_Part1", new string[3] { "Theodora", "Meanie", "Ambiente" } }, { "event:/NPCs/Voicelines/VL_CS_Theodora_1I_Part2", new string[3] { "Theodora", "Salespersone", "Ambiente" } }, { "event:/NPCs/Voicelines/VL_Suspicious_1I_CS", new string[1] { "SuspiciousMan" } }, { "event:/NPCs/Voicelines/VL_Mitu_1I_CS_Intro", new string[2] { "Mitu", "Meanie" } }, { "event:/NPCs/Voicelines/VL_Shoryo_1I_CS_Intro", new string[1] { "Shoryo" } }, { "event:/NPCs/Voicelines/VL_Shoryo_2I_CS_QuestComplete", new string[1] { "Shoryo" } }, { "event:/NPCs/Voicelines/VL_Shoryo_3I_CS_QuestCompleteBlind", new string[2] { "Shoryo", "Salespersone" } }, { "event:/NPCs/Voicelines/VL_Kane_1I_CS", new string[1] { "Kane" } }, { "event:/NPCs/Voicelines/VL_Shaman_1I_CS_Intro", new string[1] { "Shaman" } }, { "event:/NPCs/Voicelines/VL_Shaman_2I_CS_QuestComplete", new string[1] { "Shaman" } }, { "event:/NPCs/Voicelines/VL_Shaman_3I_CS_QuestComplete2", new string[1] { "Shaman" } }, { "event:/NPCs/Voicelines/VL_CoralGlasses_CS_Intro", new string[1] { "CoralGlasses" } } }; public static readonly Dictionary PrefijoArchivo = new Dictionary(StringComparer.OrdinalIgnoreCase) { { "event:/Cutscenes/CS_HubRendezvousSFX", "HUB_C_HubRendezvous_SFX" }, { "event:/Cutscenes/CS_EndingLonelyDoor_03", "D1G_Ending_05_ENAWillBeReturningIn" } }; public static readonly Dictionary> PrefijoPorPersonaje = new Dictionary>(StringComparer.OrdinalIgnoreCase) { { "VL_CS_Theodora_1I_Part1", new Dictionary(StringComparer.OrdinalIgnoreCase) { { "Meanie", "VL_Theodora_1I_CS_Part1" } } } }; public static float VolumenCompensacion = 1f; public static float VolumenCompensacionVoiceline = 1f; public static float VolumenCompensacionEvento = 1f; public static float VolumenCompensacionOrig = 1f; public static float VolumenAmbienteBoost = 1.8f; private static readonly Random _rngCine = new Random(); private static HashSet _wavCache = null; private static bool _banksLoaded = false; private static System _modStudio; public static MultiPistaRunner RunnerActivo = null; private static readonly Dictionary _tombstones = new Dictionary(); private const float TOMBSTONE_DURACION = 60f; private static readonly Dictionary _cooldownCinematicas = new Dictionary(StringComparer.OrdinalIgnoreCase); private const float DURACION_COOLDOWN = 15f; public static string CinematicaActiva = ""; public static float CinematicaActivaHasta = -1f; public static float VideoClipStartTime = -1f; public static EventInstance InstanciaFMODActiva; public static bool TieneInstanciaFMOD = false; public static readonly List InstanciasPrevias = new List(); public static float SilenciarVoicelineHasta = -1f; public const float VENTANA_SILENCIO_MS = 0.5f; public static float RunnerStartTime = -1f; public static MultiPistaRunner AmbienterRunnerActivo = null; public static bool BanksDisponibles => _banksLoaded; public static System ModStudio => _modStudio; public static bool HayCinematicaActiva => !string.IsNullOrEmpty(CinematicaActiva) && Time.realtimeSinceStartup < CinematicaActivaHasta; public static bool HayVideoClipActivo => VideoClipStartTime > 0f && Time.realtimeSinceStartup - VideoClipStartTime < 5f; public static string ObtenerPrefijo(string pathFMOD) { if (PrefijoArchivo.TryGetValue(pathFMOD, out var value)) { return value; } return pathFMOD.Substring(pathFMOD.LastIndexOf('/') + 1); } public static void CargarBanksTurronish() { ControlDoblajePlugin.Log.LogInfo((object)"[Banks] Carga de banks deshabilitada (modo OGG)"); } public static void RefrescarCacheWAV() { if (_wavCache != null) { return; } try { string voicesPath = ControlDoblajePlugin.VoicesPath; if (!string.IsNullOrEmpty(voicesPath)) { List list = AssetPack.Listar(voicesPath, new string[2] { ".wav", ".ogg" }, true); if (list.Count != 0 || Directory.Exists(voicesPath)) { _wavCache = new HashSet(list, StringComparer.OrdinalIgnoreCase); ControlDoblajePlugin.Log.LogInfo((object)$"[WAVCache] {list.Count} archivos indexados (disco+pack)"); } } } catch (Exception ex) { ControlDoblajePlugin.Log.LogWarning((object)("[WAVCache] Error al refrescar: " + ex.Message)); } } public static bool ExisteWAV(string path) { string text = path.Replace('/', Path.DirectorySeparatorChar); if (_wavCache != null) { if (_wavCache.Contains(text)) { return true; } if (text.EndsWith(".wav", StringComparison.OrdinalIgnoreCase)) { string item = text.Substring(0, text.Length - 4) + ".ogg"; if (_wavCache.Contains(item)) { return true; } } return File.Exists(text); } if (File.Exists(text)) { return true; } if (text.EndsWith(".wav", StringComparison.OrdinalIgnoreCase)) { string path2 = text.Substring(0, text.Length - 4) + ".ogg"; return File.Exists(path2); } return false; } public static string ResolverAudio(string wavPath) { if (AssetPack.Existe(wavPath)) { return wavPath; } if (wavPath.EndsWith(".wav", StringComparison.OrdinalIgnoreCase)) { string text = wavPath.Substring(0, wavPath.Length - 4) + ".ogg"; if (ExisteWAV(text)) { return text; } } return wavPath; } public static string[] GetAudioFiles(string dir, string pattern) { List list = AssetPack.Listar(dir, (string[])null, false); if (list.Count == 0) { return new string[0]; } List list2 = new List { pattern }; if (pattern.EndsWith(".wav", StringComparison.OrdinalIgnoreCase)) { list2.Add(pattern.Substring(0, pattern.Length - 4) + ".ogg"); } List rxs = list2.Select(GlobARegex).ToList(); return list.Where((string f) => rxs.Exists((Regex rx) => rx.IsMatch(Path.GetFileName(f)))).ToArray(); } private static Regex GlobARegex(string glob) { string pattern = "^" + Regex.Escape(glob).Replace("\\*", ".*").Replace("\\?", ".") + "$"; return new Regex(pattern, RegexOptions.IgnoreCase); } private static List CandidatosGlob(string dirG, string prefix) { if (_wavCache != null) { string text = dirG.TrimEnd('\\', '/'); char directorySeparatorChar = Path.DirectorySeparatorChar; string keyPre = (text + directorySeparatorChar + prefix).ToLowerInvariant(); return _wavCache.Where((string p) => p.ToLowerInvariant().StartsWith(keyPre) && !p.EndsWith("_orig.wav", StringComparison.OrdinalIgnoreCase) && !p.EndsWith("_orig.ogg", StringComparison.OrdinalIgnoreCase)).ToList(); } if (!Directory.Exists(dirG)) { return new List(); } List list = new List(from f in Directory.GetFiles(dirG, prefix + "*.wav") where !f.EndsWith("_orig.wav", StringComparison.OrdinalIgnoreCase) select f); list.AddRange(from f in Directory.GetFiles(dirG, prefix + "*.ogg") where !f.EndsWith("_orig.ogg", StringComparison.OrdinalIgnoreCase) select f); return list; } public unsafe static string ElegirVariante(string pathSinExt) { //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Unknown result type (might be due to invalid IL or missing references) //IL_01f7: Unknown result type (might be due to invalid IL or missing references) //IL_01fc: Unknown result type (might be due to invalid IL or missing references) //IL_020e: Unknown result type (might be due to invalid IL or missing references) //IL_0213: Unknown result type (might be due to invalid IL or missing references) //IL_023e: Unknown result type (might be due to invalid IL or missing references) //IL_02f1: Unknown result type (might be due to invalid IL or missing references) //IL_02f6: Unknown result type (might be due to invalid IL or missing references) //IL_0305: Unknown result type (might be due to invalid IL or missing references) //IL_036b: Unknown result type (might be due to invalid IL or missing references) //IL_0370: Unknown result type (might be due to invalid IL or missing references) //IL_0378: Unknown result type (might be due to invalid IL or missing references) if (_banksLoaded && !string.IsNullOrEmpty(pathSinExt)) { string fileName = Path.GetFileName(Path.GetDirectoryName(pathSinExt)); string fileName2 = Path.GetFileName(pathSinExt); if (!string.IsNullOrEmpty(fileName) && !string.IsNullOrEmpty(fileName2)) { string text = "event:/Turronish/" + fileName + "/" + fileName2; System studioSystem = RuntimeManager.StudioSystem; EventDescription val = default(EventDescription); if ((int)((System)(ref studioSystem)).getEvent(text + ".wav", ref val) == 0 && ((EventDescription)(ref val)).isValid()) { return text + ".wav"; } studioSystem = RuntimeManager.StudioSystem; if ((int)((System)(ref studioSystem)).getEvent(text + "_es.wav", ref val) == 0 && ((EventDescription)(ref val)).isValid()) { return text + "_es.wav"; } List list = new List(); string[] array = new string[14] { "_1_es", "_2_es", "_3_es", "_4_es", "_5_es", "_6_es", "_7_es", "_8_es", "_9_es", "_A_es", "_B_es", "_C_es", "_D_es", "_E_es" }; EventDescription val2 = default(EventDescription); foreach (string text2 in array) { studioSystem = RuntimeManager.StudioSystem; if ((int)((System)(ref studioSystem)).getEvent(text + text2, ref val2) == 0 && ((EventDescription)(ref val2)).isValid()) { list.Add(text + text2); } } if (list.Count > 0) { return list[_rngCine.Next(list.Count)]; } studioSystem = RuntimeManager.StudioSystem; EventDescription val4 = default(EventDescription); RESULT val3 = ((System)(ref studioSystem)).getEvent(text + "_es", ref val4); ControlDoblajePlugin.Log.LogInfo((object)("[ElegirV] bank try: " + text + "_es → " + ((object)(*(RESULT*)(&val3))/*cast due to .constrained prefix*/).ToString())); if ((int)val3 == 0 && ((EventDescription)(ref val4)).isValid()) { return text + "_es"; } string[] array2 = new string[14] { "_1", "_2", "_3", "_4", "_5", "_6", "_7", "_8", "_9", "_A", "_B", "_C", "_D", "_E" }; EventDescription val5 = default(EventDescription); foreach (string text3 in array2) { studioSystem = RuntimeManager.StudioSystem; if ((int)((System)(ref studioSystem)).getEvent(text + text3, ref val5) == 0 && ((EventDescription)(ref val5)).isValid()) { list.Add(text + text3); } } if (list.Count > 0) { return list[_rngCine.Next(list.Count)]; } studioSystem = RuntimeManager.StudioSystem; EventDescription val6 = default(EventDescription); if ((int)((System)(ref studioSystem)).getEvent(text, ref val6) == 0 && ((EventDescription)(ref val6)).isValid()) { return text; } } } string[] array3 = new string[14] { "_1", "_2", "_3", "_4", "_5", "_6", "_7", "_8", "_9", "_A", "_B", "_C", "_D", "_E" }; string text4 = "_es"; List list2 = new List(); string[] array4 = array3; foreach (string text5 in array4) { string text6 = pathSinExt + text5 + text4 + ".wav"; if (ExisteWAV(text6)) { list2.Add(text6); } } if (list2.Count > 0) { return list2[_rngCine.Next(list2.Count)]; } string text7 = pathSinExt + text4 + ".wav"; if (ExisteWAV(text7)) { return text7; } string[] array5 = array3; foreach (string text8 in array5) { string text9 = pathSinExt + text8 + ".wav"; if (ExisteWAV(text9)) { list2.Add(text9); } } if (list2.Count > 0) { return list2[_rngCine.Next(list2.Count)]; } string text10 = pathSinExt + ".wav"; if (ExisteWAV(text10)) { return text10; } string directoryName = Path.GetDirectoryName(pathSinExt); string fileName3 = Path.GetFileName(pathSinExt); if (directoryName != null) { List list3 = CandidatosGlob(directoryName, fileName3 + "_"); if (list3.Count > 0) { return list3[_rngCine.Next(list3.Count)]; } int num = fileName3.LastIndexOf('_'); if (num > 0) { List list4 = CandidatosGlob(directoryName, fileName3.Substring(0, num) + "_"); if (list4.Count > 0) { return list4[_rngCine.Next(list4.Count)]; } } } return null; } private static string GetTombstoneKey(List rutas) { if (rutas == null || rutas.Count == 0) { return ""; } List list = rutas.ConvertAll((string r) => Path.GetFileName(r).ToLowerInvariant()); list.Sort(); return string.Join("|", list); } public static void SetTombstone(List rutas) { if (rutas != null && rutas.Count != 0) { string tombstoneKey = GetTombstoneKey(rutas); if (!string.IsNullOrEmpty(tombstoneKey)) { _tombstones[tombstoneKey] = Time.realtimeSinceStartup + 60f; ControlDoblajePlugin.Log.LogInfo((object)("[MultiPista] Tombstone: " + tombstoneKey + " bloqueado por " + 60f + "s")); } } } private static string GetCooldownKey(List rutas) { if (rutas == null || rutas.Count == 0) { return ""; } return string.Join("|", rutas.ConvertAll((string r) => r.ToLowerInvariant())); } public static void EstablecerCooldown(List rutas) { if (rutas != null && rutas.Count != 0) { string cooldownKey = GetCooldownKey(rutas); if (!string.IsNullOrEmpty(cooldownKey)) { _cooldownCinematicas[cooldownKey] = Time.realtimeSinceStartup + 15f; ControlDoblajePlugin.Log.LogInfo((object)("[MultiPista] Cooldown " + 15f + "s → " + Path.GetFileName(rutas[0]))); } } } public static bool EstaBloqueadoPorCooldown(List rutas) { if (rutas == null || rutas.Count == 0) { return false; } string cooldownKey = GetCooldownKey(rutas); float value; return _cooldownCinematicas.TryGetValue(cooldownKey, out value) && Time.realtimeSinceStartup < value; } public static void MarcarCinematicaActiva(string path) { CinematicaActiva = path; CinematicaActivaHasta = Time.realtimeSinceStartup + 2f; } public static void SilenciarVoicelinesActivos() { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Invalid comparison between Unknown and I4 //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) try { System studioSystem = RuntimeManager.StudioSystem; EventDescription val = default(EventDescription); if ((int)((System)(ref studioSystem)).getEvent("event:/NPCs/Voicelines/NPC_Voiceline", ref val) != 0) { return; } int num = default(int); ((EventDescription)(ref val)).getInstanceCount(ref num); if (num == 0) { return; } EventInstance[] array = (EventInstance[])(object)new EventInstance[32]; ((EventDescription)(ref val)).getInstanceList(ref array); int num2 = ((array != null) ? array.Length : 0); for (int i = 0; i < num2; i++) { try { ((EventInstance)(ref array[i])).setVolume(0f); } catch { } } if (num2 > 0) { ControlDoblajePlugin.Log.LogInfo((object)("[CineMulti] Silenciadas " + num2 + " instancias de NPC_Voiceline")); } } catch (Exception ex) { ControlDoblajePlugin.Log.LogWarning((object)("[CineMulti] SilenciarVoicelinesActivos error: " + ex.Message)); } } public static void ActivarSilencioVoiceline() { SilenciarVoicelineHasta = Time.realtimeSinceStartup + 0.5f; } public static void RegistrarInstanciaFMOD(EventInstance inst) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) if (TieneInstanciaFMOD) { InstanciasPrevias.Add(InstanciaFMODActiva); } InstanciaFMODActiva = inst; TieneInstanciaFMOD = true; } public static void LimpiarInstanciaFMOD() { TieneInstanciaFMOD = false; InstanciasPrevias.Clear(); } public static List ResolverPistas(string keyBase, string[] personajes) { List list = new List(); foreach (string text in personajes) { string path = Path.Combine(ControlDoblajePlugin.VoicesPath, text); ControlDoblajePlugin.PersonajeActivo.TryGetValue(text, out var value); string text2 = keyBase; if (PrefijoPorPersonaje.TryGetValue(keyBase, out var value2) && value2.TryGetValue(text, out var value3)) { text2 = value3; } string pathSinExt = Path.Combine(path, text2 + "_" + text); string pathSinExt2 = Path.Combine(path, text2 + "_" + text + "_orig"); string text3 = null; if (value) { text3 = ElegirVariante(pathSinExt); } if (text3 == null) { text3 = ElegirVariante(pathSinExt2); } if (text3 == null) { string pathSinExt3 = Path.Combine(path, text2); string pathSinExt4 = Path.Combine(path, text2 + "_orig"); if (value) { text3 = ElegirVariante(pathSinExt3); } if (text3 == null) { text3 = ElegirVariante(pathSinExt4); } if (text3 != null) { ControlDoblajePlugin.Log.LogInfo((object)("[CineMulti] " + text + " → (sin sufijo) " + Path.GetFileName(text3))); } } if (text3 != null) { list.Add(text3); ControlDoblajePlugin.Log.LogInfo((object)("[CineMulti] " + text + " → " + Path.GetFileName(text3))); } else { ControlDoblajePlugin.Log.LogInfo((object)("[CineMulti] " + text + " → sin audio")); } } return list; } public static bool EsRutaAmbiente(string ruta) { char directorySeparatorChar = Path.DirectorySeparatorChar; string text = directorySeparatorChar.ToString(); directorySeparatorChar = Path.DirectorySeparatorChar; return ruta.IndexOf(text + "Ambiente" + directorySeparatorChar, StringComparison.OrdinalIgnoreCase) >= 0 || ruta.IndexOf("/Ambiente/", StringComparison.OrdinalIgnoreCase) >= 0; } public static void ReproducirAmbiente(List rutas) { //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Expected O, but got Unknown if (rutas != null && rutas.Count != 0) { if ((Object)(object)AmbienterRunnerActivo != (Object)null) { ControlDoblajePlugin.Log.LogInfo((object)"[Ambiente] Runner ya activo — retrigger ignorado (1 sola reproducción)"); return; } GameObject val = new GameObject("_MultiPistaAmbiente"); Object.DontDestroyOnLoad((Object)(object)val); MultiPistaRunner multiPistaRunner = val.AddComponent(); multiPistaRunner.Init(rutas); AmbienterRunnerActivo = multiPistaRunner; ControlDoblajePlugin.Log.LogInfo((object)$"[Ambiente] Runner iniciado con {rutas.Count} pista(s) — independiente de FMOD stop"); } } public static void ReproducirSecundarias(List rutas, bool esCinematica = false) { //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Expected O, but got Unknown if (EstaBloqueadoPorCooldown(rutas)) { ControlDoblajePlugin.Log.LogInfo((object)"[MultiPista] Cooldown activo — retrigger bloqueado"); return; } if ((Object)(object)RunnerActivo != (Object)null) { if (!RunnerActivo.EsCinematica && RunnerActivo.MismoContenido(rutas)) { ControlDoblajePlugin.Log.LogInfo((object)"[MultiPista] Retrigger del mismo audio bloqueado (anti-loop)"); return; } RunnerActivo.Detener(); RunnerActivo = null; } if (!esCinematica) { string tombstoneKey = GetTombstoneKey(rutas); if (!string.IsNullOrEmpty(tombstoneKey) && _tombstones.TryGetValue(tombstoneKey, out var value) && Time.realtimeSinceStartup < value) { ControlDoblajePlugin.Log.LogInfo((object)("[MultiPista] Tombstone activo — retrigger bloqueado: " + tombstoneKey)); return; } } GameObject val = new GameObject("_MultiPista"); Object.DontDestroyOnLoad((Object)(object)val); MultiPistaRunner multiPistaRunner = val.AddComponent(); multiPistaRunner.Init(rutas, esCinematica); RunnerActivo = multiPistaRunner; RunnerStartTime = Time.realtimeSinceStartup; } } public class MultiPistaRunner : MonoBehaviour { private List _rutas; private readonly List<(Sound s, Channel c)> _canales = new List<(Sound, Channel)>(); private readonly List _instancias = new List(); private bool _usarBanks = false; private readonly List<(float vol, string bus)> _volsBase = new List<(float, string)>(); private bool _pausado = false; private readonly List _posPausa = new List(); private readonly List<(Task<(RESULT, Sound)> tarea, string ruta)> _pendientesAsync = new List<(Task<(RESULT, Sound)>, string)>(); private ChannelGroup _grupoDefaultRunner; private float _t0Runner; private bool _asyncFinalizado = false; private uint _seekPendienteMs = 0u; private float _seekPendienteT = -1f; private bool _esCinematica = false; private bool _fueSoltado = false; private bool _esAjena = false; private float _esperandoFMODDesde = -1f; private int _diagCounter = 0; private int _volSyncCounter = 0; private bool _iniciado = false; private uint _cortarEnMs = 0u; private string _cortarEnMsKey = null; private uint _skipFloorMs = 0u; public bool EsCinematica => _esCinematica; public bool TieneCanalesActivos => _usarBanks ? (_instancias.Count > 0) : (_canales.Count > 0); public bool FueSoltado => _fueSoltado; public bool EsAjena => _esAjena; public void Init(List rutas, bool esCinematica = false) { _rutas = rutas; _esCinematica = esCinematica; } public bool ContieneNombre(string patron) { return _rutas != null && _rutas.Exists((string r) => r.IndexOf(patron, StringComparison.OrdinalIgnoreCase) >= 0); } private static ChannelGroup ObtenerGrupoVoces() { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: 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_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Invalid comparison between Unknown and I4 //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) ChannelGroup result = default(ChannelGroup); string[] array = new string[9] { "bus:/Voicelines", "bus:/NPCs/Voicelines", "bus:/NPCs/Voiceline", "bus:/NPCs", "bus:/SFX/Dialogue", "bus:/Dialogue", "bus:/Voice", "bus:/SFX", "bus:/" }; Bus val = default(Bus); foreach (string text in array) { System studioSystem = RuntimeManager.StudioSystem; if ((int)((System)(ref studioSystem)).getBus(text, ref val) == 0 && (int)((Bus)(ref val)).getChannelGroup(ref result) == 0) { ControlDoblajePlugin.Log.LogInfo((object)("[MultiPista] Bus=" + text)); return result; } } System coreSystem = RuntimeManager.CoreSystem; ((System)(ref coreSystem)).getMasterChannelGroup(ref result); ControlDoblajePlugin.Log.LogInfo((object)"[MultiPista] Bus=master (fallback)"); return result; } public static float LeerVolBus(string busPath) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Invalid comparison between Unknown and I4 //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Invalid comparison between Unknown and I4 try { System studioSystem = RuntimeManager.StudioSystem; Bus val = default(Bus); if ((int)((System)(ref studioSystem)).getBus(busPath, ref val) == 0) { float num = 1f; if ((int)((Bus)(ref val)).getVolume(ref num) == 0) { return Mathf.Clamp01(num); } } } catch { } return 1f; } private static ChannelGroup ObtenerGrupoParaRuta(string ruta, bool esCinematica, ChannelGroup defaultGrupo) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Invalid comparison between Unknown and I4 //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) if (TieneCarpeta("Ambiente")) { ChannelGroup result = default(ChannelGroup); System studioSystem = RuntimeManager.StudioSystem; Bus val = default(Bus); if ((int)((System)(ref studioSystem)).getBus("bus:/Music", ref val) == 0) { ((Bus)(ref val)).getChannelGroup(ref result); } if (((ChannelGroup)(ref result)).hasHandle()) { ControlDoblajePlugin.Log.LogInfo((object)"[MultiPista] Ambiente → bus:/Music"); return result; } } if (!esCinematica) { return defaultGrupo; } return defaultGrupo; bool TieneCarpeta(string nombre) { string text = ruta; char directorySeparatorChar = Path.DirectorySeparatorChar; string text2 = directorySeparatorChar.ToString(); directorySeparatorChar = Path.DirectorySeparatorChar; return text.IndexOf(text2 + nombre + directorySeparatorChar, StringComparison.OrdinalIgnoreCase) >= 0 || ruta.IndexOf("/" + nombre + "/", StringComparison.OrdinalIgnoreCase) >= 0; } } private unsafe void Start() { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) if (_esCinematica) { System coreSystem = RuntimeManager.CoreSystem; ChannelGroup grupoDefault = default(ChannelGroup); RESULT masterChannelGroup = ((System)(ref coreSystem)).getMasterChannelGroup(ref grupoDefault); bool flag = false; float num = -1f; ((ChannelGroup)(ref grupoDefault)).getPaused(ref flag); ((ChannelGroup)(ref grupoDefault)).getVolume(ref num); ControlDoblajePlugin.Log.LogInfo((object)("[MultiPista] Bus=CoreMaster res=" + ((object)(*(RESULT*)(&masterChannelGroup))/*cast due to .constrained prefix*/).ToString() + " handle=" + ((ChannelGroup)(ref grupoDefault)).hasHandle() + " paused=" + flag + " vol=" + num.ToString("F2") + " timeScale=" + Time.timeScale)); SetupCanales(grupoDefault); if ((_usarBanks ? _instancias.Count : _canales.Count) + _pendientesAsync.Count == 0) { ControlDoblajePlugin.Log.LogWarning((object)"[MultiPista] Sin canales tras SetupCanales (cinematica) — runner destruido para no bloquear audio"); Object.Destroy((Object)(object)((Component)this).gameObject); return; } _iniciado = true; if (_rutas != null && _rutas.Exists((string r) => r.IndexOf("VL_CS_Theodora_1I_Part2", StringComparison.OrdinalIgnoreCase) >= 0)) { _cortarEnMs = 49000u; _cortarEnMsKey = "VL_CS_Theodora_1I_Part2"; ControlDoblajePlugin.Log.LogInfo((object)"[MultiPista] Theodora Part2 detectada — corte programado a los 49 s de posición"); } if (_rutas != null && _rutas.Exists((string r) => r.IndexOf("VL_CS_Theodora_1I_Part1", StringComparison.OrdinalIgnoreCase) >= 0)) { _skipFloorMs = 83000u; ControlDoblajePlugin.Log.LogInfo((object)"[MultiPista] Theodora Part1 detectada — piso de skip a 1:23 (83000ms)"); } if (_rutas != null && _rutas.Exists((string r) => r.IndexOf("VL_Suspicious_1I_CS", StringComparison.OrdinalIgnoreCase) >= 0 && r.IndexOf("_Meanie", StringComparison.OrdinalIgnoreCase) < 0 && r.IndexOf("_Salespersone", StringComparison.OrdinalIgnoreCase) < 0)) { _skipFloorMs = 80000u; ControlDoblajePlugin.Log.LogInfo((object)"[MultiPista] SuspiciousMan CS detectada — piso de skip a 1:20 (80000ms)"); } } else { ((MonoBehaviour)this).StartCoroutine(IniciarVoicelines()); } } private IEnumerator IniciarVoicelines() { yield return null; System coreSystem = RuntimeManager.CoreSystem; ChannelGroup grupoDefault = default(ChannelGroup); ((System)(ref coreSystem)).getMasterChannelGroup(ref grupoDefault); ControlDoblajePlugin.Log.LogInfo((object)"[MultiPista] Bus=CoreMaster (voiceline — stable root)"); SetupCanales(grupoDefault); if ((_usarBanks ? _instancias.Count : _canales.Count) + _pendientesAsync.Count == 0) { ControlDoblajePlugin.Log.LogWarning((object)"[MultiPista] Sin canales tras SetupCanales (voiceline) — runner destruido"); CinematicaMultiPistaPlayer.SilenciarVoicelineHasta = -1f; if ((Object)(object)CinematicaMultiPistaPlayer.RunnerActivo == (Object)(object)this) { CinematicaMultiPistaPlayer.RunnerActivo = null; } Object.Destroy((Object)(object)((Component)this).gameObject); } else { _iniciado = true; } } private void SetupCanales(ChannelGroup grupoDefault) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_034e: Unknown result type (might be due to invalid IL or missing references) //IL_0353: Unknown result type (might be due to invalid IL or missing references) //IL_0355: Unknown result type (might be due to invalid IL or missing references) //IL_035a: Unknown result type (might be due to invalid IL or missing references) //IL_03cb: Unknown result type (might be due to invalid IL or missing references) //IL_03d0: Unknown result type (might be due to invalid IL or missing references) //IL_03d2: Unknown result type (might be due to invalid IL or missing references) //IL_03d7: Unknown result type (might be due to invalid IL or missing references) //IL_0366: Unknown result type (might be due to invalid IL or missing references) //IL_03de: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: 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_0389: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: 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_0138: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Invalid comparison between Unknown and I4 //IL_0203: Unknown result type (might be due to invalid IL or missing references) //IL_020b: Unknown result type (might be due to invalid IL or missing references) //IL_0217: Unknown result type (might be due to invalid IL or missing references) float realtimeSinceStartup = Time.realtimeSinceStartup; _grupoDefaultRunner = grupoDefault; _t0Runner = realtimeSinceStartup; bool flag = _rutas != null && _rutas.Count > 0 && (_rutas[0].IndexOf("Mitu", StringComparison.OrdinalIgnoreCase) >= 0 || _rutas[0].IndexOf("BunrakoMan", StringComparison.OrdinalIgnoreCase) >= 0 || _rutas[0].IndexOf("HehIto", StringComparison.OrdinalIgnoreCase) >= 0); if (flag) { ControlDoblajePlugin.Log.LogInfo((object)"[MultiPista] MODO LEGACY (escalera) — arranque por-pista sin sincronizar"); } EventDescription val2 = default(EventDescription); EventInstance item = default(EventInstance); foreach (string ruta in _rutas) { if (ruta.StartsWith("event:", StringComparison.OrdinalIgnoreCase)) { System val = CinematicaMultiPistaPlayer.ModStudio; if (val.handle == IntPtr.Zero) { val = RuntimeManager.StudioSystem; } if ((int)((System)(ref val)).getEvent(ruta, ref val2) != 0 || !((EventDescription)(ref val2)).isValid()) { ControlDoblajePlugin.Log.LogWarning((object)("[MultiPista] Bank getEvent FAIL: " + ruta)); continue; } if ((int)((EventDescription)(ref val2)).createInstance(ref item) > 0) { ControlDoblajePlugin.Log.LogWarning((object)("[MultiPista] Bank createInstance FAIL: " + ruta)); continue; } string text = ruta.Substring(ruta.LastIndexOf('/') + 1); bool flag2 = text.EndsWith("_orig", StringComparison.OrdinalIgnoreCase) || Regex.IsMatch(text, "_orig[_\\-]?[0-9A-Ea-e]$", RegexOptions.IgnoreCase); float num = (flag2 ? CinematicaMultiPistaPlayer.VolumenCompensacionOrig : (_esCinematica ? CinematicaMultiPistaPlayer.VolumenCompensacion : CinematicaMultiPistaPlayer.VolumenCompensacionVoiceline)); string text2 = ((ruta.IndexOf("/Ambiente/", StringComparison.OrdinalIgnoreCase) >= 0) ? "bus:/Music" : "bus:/Voicelines"); float num2 = LeerVolBus(text2); float num3 = LeerVolBus("bus:/"); float num4 = num * num2 * num3; ((EventInstance)(ref item)).setVolume(num4); ((EventInstance)(ref item)).start(); _instancias.Add(item); _volsBase.Add((num, text2)); _usarBanks = true; string arg = (flag2 ? "orig" : (_esCinematica ? "cine" : "voice")); ControlDoblajePlugin.Log.LogInfo((object)("[MultiPista] playing " + text + $" [ModSys {arg} vol={num4:F2}]")); continue; } string rutaResuelta = CinematicaMultiPistaPlayer.ResolverAudio(ruta); Task<(RESULT, Sound)> item2 = Task.Run(delegate { //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) try { CREATESOUNDEXINFO ex = default(CREATESOUNDEXINFO); ex.cbsize = Marshal.SizeOf(ex); Sound sound; RESULT item3 = AudioPack.CrearSound(RuntimeManager.CoreSystem, rutaResuelta, (MODE)265, ref ex, out sound); return (item3, sound); } catch { return ((RESULT, Sound))((RESULT)28, default(Sound)); } }); _pendientesAsync.Add((item2, ruta)); ControlDoblajePlugin.Log.LogInfo((object)("[MultiPista] decodificando (async): " + Path.GetFileName(ruta))); } if (flag || _canales.Count <= 0) { return; } float num5 = (Time.realtimeSinceStartup - realtimeSinceStartup) * 1000f; if (num5 > 20f) { foreach (var canale in _canales) { var (val3, val4) = canale; try { uint num6 = 0u; ((Sound)(ref val3)).getLength(ref num6, (TIMEUNIT)1); uint num7 = (uint)num5; if (num6 == 0 || num7 < num6) { ((Channel)(ref val4)).setPosition(num7, (TIMEUNIT)1); } } catch { } } } foreach (var canale2 in _canales) { var (val5, val6) = canale2; try { ((Channel)(ref val6)).setPaused(false); } catch { } } ControlDoblajePlugin.Log.LogInfo((object)$"[MultiPista] arranque sincronizado: {_canales.Count} pistas, comp={num5:F0}ms"); } private unsafe void PromoverPendientes() { //IL_03b6: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0427: Unknown result type (might be due to invalid IL or missing references) //IL_0433: Unknown result type (might be due to invalid IL or missing references) //IL_0434: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Invalid comparison between Unknown and I4 //IL_02a3: Unknown result type (might be due to invalid IL or missing references) //IL_03a4: Unknown result type (might be due to invalid IL or missing references) //IL_0302: Unknown result type (might be due to invalid IL or missing references) //IL_03ff: Unknown result type (might be due to invalid IL or missing references) //IL_037b: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0104: 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_012c: Unknown result type (might be due to invalid IL or missing references) //IL_0130: 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_013c: Invalid comparison between Unknown and I4 //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_0266: Unknown result type (might be due to invalid IL or missing references) //IL_0270: Unknown result type (might be due to invalid IL or missing references) Channel item = default(Channel); int num6 = default(int); for (int num = _pendientesAsync.Count - 1; num >= 0; num--) { (Task<(RESULT, Sound)>, string) tuple = _pendientesAsync[num]; if (!tuple.Item1.IsCompleted) { continue; } _pendientesAsync.RemoveAt(num); RESULT val; Sound val2; try { (val, val2) = tuple.Item1.Result; } catch { continue; } if ((int)val > 0) { ControlDoblajePlugin.Log.LogWarning((object)("[MultiPista] decode async FAIL " + Path.GetFileName(tuple.Item2) + " " + ((object)(*(RESULT*)(&val))/*cast due to .constrained prefix*/).ToString())); continue; } if (_asyncFinalizado || FueSoltado) { try { if (((Sound)(ref val2)).hasHandle()) { ((Sound)(ref val2)).release(); } } catch { } continue; } ChannelGroup val3 = ObtenerGrupoParaRuta(tuple.Item2, _esCinematica, _grupoDefaultRunner); System coreSystem; if (!((ChannelGroup)(ref val3)).hasHandle()) { coreSystem = RuntimeManager.CoreSystem; ((System)(ref coreSystem)).getMasterChannelGroup(ref val3); } coreSystem = RuntimeManager.CoreSystem; if ((int)((System)(ref coreSystem)).playSound(val2, val3, true, ref item) > 0) { ControlDoblajePlugin.Log.LogWarning((object)("[MultiPista] playSound (async) FAIL " + Path.GetFileName(tuple.Item2))); try { ((Sound)(ref val2)).release(); } catch { } continue; } string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(tuple.Item2); bool flag = fileNameWithoutExtension.EndsWith("_orig", StringComparison.OrdinalIgnoreCase) || Regex.IsMatch(fileNameWithoutExtension, "_orig[_\\-]?[0-9A-Ea-e]$", RegexOptions.IgnoreCase); float num2 = (flag ? CinematicaMultiPistaPlayer.VolumenCompensacionOrig : (_esCinematica ? CinematicaMultiPistaPlayer.VolumenCompensacion : CinematicaMultiPistaPlayer.VolumenCompensacionVoiceline)); string item2 = tuple.Item2; char directorySeparatorChar = Path.DirectorySeparatorChar; string text = directorySeparatorChar.ToString(); directorySeparatorChar = Path.DirectorySeparatorChar; bool flag2 = item2.IndexOf(text + "Ambiente" + directorySeparatorChar, StringComparison.OrdinalIgnoreCase) >= 0 || tuple.Item2.IndexOf("/Ambiente/", StringComparison.OrdinalIgnoreCase) >= 0; string text2 = (flag2 ? "bus:/Music" : "bus:/Voicelines"); if (flag2) { num2 *= CinematicaMultiPistaPlayer.VolumenAmbienteBoost; } float num3 = LeerVolBus(text2); float num4 = LeerVolBus("bus:/"); ((Channel)(ref item)).setVolume(flag2 ? num2 : (num2 * num3 * num4)); try { ((Channel)(ref item)).setPriority(0); } catch { } uint num5 = 0u; bool flag3 = false; if (_esCinematica && CinematicaMultiPistaPlayer.TieneInstanciaFMOD) { try { if ((int)((EventInstance)(ref CinematicaMultiPistaPlayer.InstanciaFMODActiva)).getTimelinePosition(ref num6) == 0 && num6 >= 0) { num5 = (uint)num6; flag3 = true; } } catch { } } if (!flag3 && _canales.Count > 0) { try { (Sound, Channel) tuple3 = _canales[0]; ((Channel)(ref tuple3.Item2)).getPosition(ref num5, (TIMEUNIT)1); flag3 = true; } catch { } } if (!flag3 && _seekPendienteT >= 0f) { num5 = _seekPendienteMs + (uint)((Time.realtimeSinceStartup - _seekPendienteT) * 1000f); flag3 = true; } if (!flag3) { num5 = (uint)((Time.realtimeSinceStartup - _t0Runner) * 1000f); } uint num7 = 0u; try { ((Sound)(ref val2)).getLength(ref num7, (TIMEUNIT)1); } catch { } if (num7 != 0 && num5 >= num7) { try { ((Channel)(ref item)).stop(); } catch { } try { ((Sound)(ref val2)).release(); } catch { } ControlDoblajePlugin.Log.LogInfo((object)("[MultiPista] pista async descartada (ya habría terminado): " + Path.GetFileName(tuple.Item2))); continue; } if (num5 > 150) { try { ((Channel)(ref item)).setPosition(num5, (TIMEUNIT)1); } catch { } } ((Channel)(ref item)).setPaused(_pausado || Time.timeScale == 0f); _canales.Add((val2, item)); _volsBase.Add((num2, text2)); string arg = (flag ? "orig" : (_esCinematica ? "cine" : "voice")); ControlDoblajePlugin.Log.LogInfo((object)("[MultiPista] pista LISTA (async) pos=" + num5 + "ms: " + Path.GetFileName(tuple.Item2) + $" [{arg} vol={num2:F2} busVol={num3:F2}]")); } } private void AbandonarPendientesAsync() { _asyncFinalizado = true; foreach (var item in _pendientesAsync) { item.tarea.ContinueWith(delegate(Task<(RESULT, Sound)> t) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) try { (RESULT, Sound) result = t.Result; if ((int)result.Item1 == 0 && ((Sound)(ref result.Item2)).hasHandle()) { ((Sound)(ref result.Item2)).release(); } } catch { } }); } _pendientesAsync.Clear(); } private void Update() { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0036: 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_003f: Unknown result type (might be due to invalid IL or missing references) //IL_03cf: Unknown result type (might be due to invalid IL or missing references) //IL_03e3: Unknown result type (might be due to invalid IL or missing references) //IL_03fe: Unknown result type (might be due to invalid IL or missing references) //IL_0404: Invalid comparison between Unknown and I4 //IL_081c: Unknown result type (might be due to invalid IL or missing references) //IL_0821: Unknown result type (might be due to invalid IL or missing references) //IL_08b2: Unknown result type (might be due to invalid IL or missing references) //IL_08b8: Invalid comparison between Unknown and I4 //IL_093e: Unknown result type (might be due to invalid IL or missing references) //IL_0943: Unknown result type (might be due to invalid IL or missing references) //IL_0414: Unknown result type (might be due to invalid IL or missing references) //IL_0420: Unknown result type (might be due to invalid IL or missing references) //IL_0827: Unknown result type (might be due to invalid IL or missing references) //IL_08c3: Unknown result type (might be due to invalid IL or missing references) //IL_0879: Unknown result type (might be due to invalid IL or missing references) //IL_087e: Unknown result type (might be due to invalid IL or missing references) //IL_0880: Unknown result type (might be due to invalid IL or missing references) //IL_0885: Unknown result type (might be due to invalid IL or missing references) //IL_0949: Unknown result type (might be due to invalid IL or missing references) //IL_09d9: Unknown result type (might be due to invalid IL or missing references) //IL_0a6a: Unknown result type (might be due to invalid IL or missing references) //IL_1155: Unknown result type (might be due to invalid IL or missing references) //IL_115a: Unknown result type (might be due to invalid IL or missing references) //IL_11be: Unknown result type (might be due to invalid IL or missing references) //IL_11c3: Unknown result type (might be due to invalid IL or missing references) //IL_11c5: Unknown result type (might be due to invalid IL or missing references) //IL_11ca: Unknown result type (might be due to invalid IL or missing references) //IL_0427: Unknown result type (might be due to invalid IL or missing references) //IL_077c: Unknown result type (might be due to invalid IL or missing references) //IL_0781: Unknown result type (might be due to invalid IL or missing references) //IL_0891: Unknown result type (might be due to invalid IL or missing references) //IL_098c: Unknown result type (might be due to invalid IL or missing references) //IL_0991: Unknown result type (might be due to invalid IL or missing references) //IL_0431: Unknown result type (might be due to invalid IL or missing references) //IL_0756: Unknown result type (might be due to invalid IL or missing references) //IL_0793: Unknown result type (might be due to invalid IL or missing references) //IL_0798: Unknown result type (might be due to invalid IL or missing references) //IL_07a1: Unknown result type (might be due to invalid IL or missing references) //IL_0998: Unknown result type (might be due to invalid IL or missing references) //IL_099e: Invalid comparison between Unknown and I4 //IL_0f97: Unknown result type (might be due to invalid IL or missing references) //IL_0f9d: Invalid comparison between Unknown and I4 //IL_116d: Unknown result type (might be due to invalid IL or missing references) //IL_11dd: Unknown result type (might be due to invalid IL or missing references) //IL_036e: Unknown result type (might be due to invalid IL or missing references) //IL_0373: Unknown result type (might be due to invalid IL or missing references) //IL_0375: Unknown result type (might be due to invalid IL or missing references) //IL_037a: Unknown result type (might be due to invalid IL or missing references) //IL_038e: Unknown result type (might be due to invalid IL or missing references) //IL_0398: Unknown result type (might be due to invalid IL or missing references) //IL_03a2: Unknown result type (might be due to invalid IL or missing references) //IL_09a9: Unknown result type (might be due to invalid IL or missing references) //IL_0eab: Unknown result type (might be due to invalid IL or missing references) //IL_0eb0: Unknown result type (might be due to invalid IL or missing references) //IL_0479: Unknown result type (might be due to invalid IL or missing references) //IL_03ba: Unknown result type (might be due to invalid IL or missing references) //IL_0edb: Unknown result type (might be due to invalid IL or missing references) //IL_0ee0: Unknown result type (might be due to invalid IL or missing references) //IL_0ee6: Unknown result type (might be due to invalid IL or missing references) //IL_0fbd: Unknown result type (might be due to invalid IL or missing references) //IL_0484: Unknown result type (might be due to invalid IL or missing references) //IL_0604: Unknown result type (might be due to invalid IL or missing references) //IL_0609: Unknown result type (might be due to invalid IL or missing references) //IL_0614: Unknown result type (might be due to invalid IL or missing references) //IL_061a: Invalid comparison between Unknown and I4 //IL_0df9: Unknown result type (might be due to invalid IL or missing references) //IL_0dff: Invalid comparison between Unknown and I4 //IL_0d8a: Unknown result type (might be due to invalid IL or missing references) //IL_0d8f: Unknown result type (might be due to invalid IL or missing references) //IL_0eed: Unknown result type (might be due to invalid IL or missing references) //IL_0ef0: Invalid comparison between Unknown and I4 //IL_062c: Unknown result type (might be due to invalid IL or missing references) //IL_0631: Unknown result type (might be due to invalid IL or missing references) //IL_063c: Unknown result type (might be due to invalid IL or missing references) //IL_0642: Invalid comparison between Unknown and I4 //IL_0626: Unknown result type (might be due to invalid IL or missing references) //IL_0e20: Unknown result type (might be due to invalid IL or missing references) //IL_0da7: Unknown result type (might be due to invalid IL or missing references) //IL_0dac: Unknown result type (might be due to invalid IL or missing references) //IL_0db1: Unknown result type (might be due to invalid IL or missing references) //IL_0dbf: Unknown result type (might be due to invalid IL or missing references) //IL_0dc4: Unknown result type (might be due to invalid IL or missing references) //IL_0dc8: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_0451: Unknown result type (might be due to invalid IL or missing references) //IL_0654: Unknown result type (might be due to invalid IL or missing references) //IL_0659: Unknown result type (might be due to invalid IL or missing references) //IL_0664: Unknown result type (might be due to invalid IL or missing references) //IL_066a: Invalid comparison between Unknown and I4 //IL_064e: Unknown result type (might be due to invalid IL or missing references) //IL_0e3e: Unknown result type (might be due to invalid IL or missing references) //IL_10b8: Unknown result type (might be due to invalid IL or missing references) //IL_10bd: Unknown result type (might be due to invalid IL or missing references) //IL_10bf: Unknown result type (might be due to invalid IL or missing references) //IL_10c4: Unknown result type (might be due to invalid IL or missing references) //IL_10ce: Unknown result type (might be due to invalid IL or missing references) //IL_1045: Unknown result type (might be due to invalid IL or missing references) //IL_104a: Unknown result type (might be due to invalid IL or missing references) //IL_01d3: Unknown result type (might be due to invalid IL or missing references) //IL_0180: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Unknown result type (might be due to invalid IL or missing references) //IL_0465: Unknown result type (might be due to invalid IL or missing references) //IL_067c: Unknown result type (might be due to invalid IL or missing references) //IL_0681: Unknown result type (might be due to invalid IL or missing references) //IL_068c: Unknown result type (might be due to invalid IL or missing references) //IL_0692: Invalid comparison between Unknown and I4 //IL_0676: Unknown result type (might be due to invalid IL or missing references) //IL_0f05: Unknown result type (might be due to invalid IL or missing references) //IL_0f0a: Unknown result type (might be due to invalid IL or missing references) //IL_0f0e: Unknown result type (might be due to invalid IL or missing references) //IL_1063: Unknown result type (might be due to invalid IL or missing references) //IL_0321: Unknown result type (might be due to invalid IL or missing references) //IL_0326: Unknown result type (might be due to invalid IL or missing references) //IL_032c: Unknown result type (might be due to invalid IL or missing references) //IL_0340: Unknown result type (might be due to invalid IL or missing references) //IL_034a: Unknown result type (might be due to invalid IL or missing references) //IL_06a4: Unknown result type (might be due to invalid IL or missing references) //IL_06a9: Unknown result type (might be due to invalid IL or missing references) //IL_06b4: Unknown result type (might be due to invalid IL or missing references) //IL_06ba: Invalid comparison between Unknown and I4 //IL_069e: Unknown result type (might be due to invalid IL or missing references) //IL_0b77: Unknown result type (might be due to invalid IL or missing references) //IL_0b1b: Unknown result type (might be due to invalid IL or missing references) //IL_0b20: Unknown result type (might be due to invalid IL or missing references) //IL_106a: Unknown result type (might be due to invalid IL or missing references) //IL_106d: Invalid comparison between Unknown and I4 //IL_06c6: Unknown result type (might be due to invalid IL or missing references) //IL_0b37: Unknown result type (might be due to invalid IL or missing references) //IL_0b3c: Unknown result type (might be due to invalid IL or missing references) //IL_0b42: Unknown result type (might be due to invalid IL or missing references) //IL_0b48: Invalid comparison between Unknown and I4 //IL_026e: Unknown result type (might be due to invalid IL or missing references) //IL_0273: Unknown result type (might be due to invalid IL or missing references) //IL_028b: Unknown result type (might be due to invalid IL or missing references) //IL_0295: Unknown result type (might be due to invalid IL or missing references) //IL_02a1: Unknown result type (might be due to invalid IL or missing references) //IL_02ae: Unknown result type (might be due to invalid IL or missing references) //IL_02b1: Invalid comparison between Unknown and I4 //IL_0c7f: Unknown result type (might be due to invalid IL or missing references) //IL_0c40: Unknown result type (might be due to invalid IL or missing references) //IL_0c45: Unknown result type (might be due to invalid IL or missing references) //IL_0c4b: Unknown result type (might be due to invalid IL or missing references) //IL_0c51: Invalid comparison between Unknown and I4 if (_pendientesAsync.Count > 0) { PromoverPendientes(); } System val; if (CinematicaMultiPistaPlayer.ModStudio.handle != IntPtr.Zero) { val = CinematicaMultiPistaPlayer.ModStudio; ((System)(ref val)).update(); } if (!_iniciado) { return; } _volSyncCounter++; int num = (_usarBanks ? _instancias.Count : _canales.Count); EventInstance val2; (Sound, Channel) tuple; if (num > 0 && _volsBase.Count == num && _volSyncCounter % 30 == 0 && Time.timeScale != 0f) { float num2 = LeerVolBus("bus:/"); for (int i = 0; i < num; i++) { try { bool flag = _volsBase[i].bus == "bus:/Music"; float num3 = (_esCinematica ? 1f : LeerVolBus(_volsBase[i].bus)); float volume = (flag ? _volsBase[i].vol : (_volsBase[i].vol * num3 * num2)); if (_usarBanks) { val2 = _instancias[i]; if (((EventInstance)(ref val2)).isValid()) { val2 = _instancias[i]; ((EventInstance)(ref val2)).setVolume(volume); } } else { tuple = _canales[i]; if (((Channel)(ref tuple.Item2)).hasHandle()) { tuple = _canales[i]; ((Channel)(ref tuple.Item2)).setVolume(volume); } } } catch { } } } _diagCounter++; int num4 = (_usarBanks ? _instancias.Count : _canales.Count); if (num4 > 0 && _diagCounter % 120 == 1) { try { string text = ""; if (_usarBanks) { PLAYBACK_STATE val3 = default(PLAYBACK_STATE); foreach (EventInstance instancia in _instancias) { EventInstance current = instancia; bool flag2 = false; float num5 = 0f; float num6 = 0f; ((EventInstance)(ref current)).getPlaybackState(ref val3); ((EventInstance)(ref current)).getPaused(ref flag2); ((EventInstance)(ref current)).getVolume(ref num5, ref num6); text += $" [Studio play={(int)val3 != 2} paused={flag2} vol={num5:F2}]"; } ControlDoblajePlugin.Log.LogInfo((object)("[MultiPista-DIAG] Studio mode timeScale=" + Time.timeScale + " instancias=" + text)); } else { System coreSystem = RuntimeManager.CoreSystem; ChannelGroup val4 = default(ChannelGroup); ((System)(ref coreSystem)).getMasterChannelGroup(ref val4); bool flag3 = false; float num7 = -1f; ((ChannelGroup)(ref val4)).getPaused(ref flag3); ((ChannelGroup)(ref val4)).getVolume(ref num7); int num8 = 0; DSP val5 = default(DSP); DSP_METERING_INFO val6 = default(DSP_METERING_INFO); DSP_METERING_INFO val7 = default(DSP_METERING_INFO); foreach (var canale in _canales) { Sound item = canale.s; Channel item2 = canale.c; bool flag4 = false; bool flag5 = false; float num9 = -1f; ((Channel)(ref item2)).isPlaying(ref flag4); ((Channel)(ref item2)).getPaused(ref flag5); ((Channel)(ref item2)).getVolume(ref num9); float num10 = -1f; uint num11 = 0u; int num12 = -1; try { ((Channel)(ref item2)).getAudibility(ref num10); } catch { } try { ((Channel)(ref item2)).getPosition(ref num11, (TIMEUNIT)1); } catch { } try { ((Channel)(ref item2)).getPriority(ref num12); } catch { } float num13 = -1f; try { if ((int)((Channel)(ref item2)).getDSP(-1, ref val5) == 0) { ((DSP)(ref val5)).setMeteringEnabled(false, true); if ((int)((DSP)(ref val5)).getMeteringInfo(ref val6, ref val7) == 0 && val7.numchannels > 0 && val7.rmslevel != null) { num13 = 0f; for (int j = 0; j < val7.numchannels && j < val7.rmslevel.Length; j++) { if (val7.rmslevel[j] > num13) { num13 = val7.rmslevel[j]; } } } } } catch { } text += $" [play={flag4} paused={flag5} vol={num9:F2} aud={num10:F2} rms={num13:F3} pos={num11}ms prio={num12}]"; if (flag4 && !flag5 && num9 > 0.05f && num10 >= 0f && num10 < 0.001f) { ControlDoblajePlugin.Log.LogWarning((object)$"[MultiPista] AUDIBILIDAD CERO canal {num8} (vol={num9:F2}, pos={num11}ms) — posible canal virtual/robado"); } num8++; } ControlDoblajePlugin.Log.LogInfo((object)("[MultiPista-DIAG] master_paused=" + flag3 + " master_vol=" + num7.ToString("F2") + " timeScale=" + Time.timeScale + " canales=" + text)); } float num14 = -1f; float num15 = -1f; float num16 = -1f; float num17 = -1f; float num18 = -1f; val = RuntimeManager.StudioSystem; Bus val8 = default(Bus); if ((int)((System)(ref val)).getBus("bus:/Voicelines", ref val8) == 0) { ((Bus)(ref val8)).getVolume(ref num14); } val = RuntimeManager.StudioSystem; if ((int)((System)(ref val)).getBus("bus:/Music", ref val8) == 0) { ((Bus)(ref val8)).getVolume(ref num15); } val = RuntimeManager.StudioSystem; if ((int)((System)(ref val)).getBus("bus:/SFX", ref val8) == 0) { ((Bus)(ref val8)).getVolume(ref num16); } val = RuntimeManager.StudioSystem; if ((int)((System)(ref val)).getBus("bus:/Ambience", ref val8) == 0) { ((Bus)(ref val8)).getVolume(ref num18); } val = RuntimeManager.StudioSystem; if ((int)((System)(ref val)).getBus("bus:/", ref val8) == 0) { ((Bus)(ref val8)).getVolume(ref num17); } ControlDoblajePlugin.Log.LogInfo((object)$"[VOL-BUSES] Voicelines={num14:F2} Music={num15:F2} SFX={num16:F2} Ambience={num18:F2} Master={num17:F2} duck={CinematicaDuckingManager.WandererDuckFactor:F2}"); } catch { } } if (CinematicaMultiPistaPlayer.TieneInstanciaFMOD) { try { if (((EventInstance)(ref CinematicaMultiPistaPlayer.InstanciaFMODActiva)).isValid()) { ((EventInstance)(ref CinematicaMultiPistaPlayer.InstanciaFMODActiva)).setVolume(0f); } } catch { } } List instanciasPrevias = CinematicaMultiPistaPlayer.InstanciasPrevias; for (int num19 = instanciasPrevias.Count - 1; num19 >= 0; num19--) { try { val2 = instanciasPrevias[num19]; if (((EventInstance)(ref val2)).isValid()) { val2 = instanciasPrevias[num19]; ((EventInstance)(ref val2)).setVolume(0f); } else { instanciasPrevias.RemoveAt(num19); } } catch { instanciasPrevias.RemoveAt(num19); } } bool flag6 = Time.timeScale == 0f; if (flag6 && !_pausado) { if (_usarBanks) { foreach (EventInstance instancia2 in _instancias) { EventInstance current3 = instancia2; try { ((EventInstance)(ref current3)).setPaused(true); } catch { } } } else { _posPausa.Clear(); bool flag7 = default(bool); foreach (var canale2 in _canales) { Sound item3 = canale2.s; Channel item4 = canale2.c; uint item5 = 0u; try { ((Channel)(ref item4)).getPosition(ref item5, (TIMEUNIT)1); } catch { } _posPausa.Add(item5); try { if ((int)((Channel)(ref item4)).isPlaying(ref flag7) == 0) { ((Channel)(ref item4)).setPaused(true); } } catch { } } } _pausado = true; ControlDoblajePlugin.Log.LogInfo((object)"[MultiPista] pausado"); } else if (!flag6 && _pausado) { if (_usarBanks) { foreach (EventInstance instancia3 in _instancias) { EventInstance current5 = instancia3; try { ((EventInstance)(ref current5)).setPaused(false); } catch { } } } else { bool flag8 = default(bool); for (int k = 0; k < _canales.Count; k++) { Channel item6 = _canales[k].c; try { if ((int)((Channel)(ref item6)).isPlaying(ref flag8) == 0) { ((Channel)(ref item6)).setPaused(false); } } catch { } if (k >= _posPausa.Count) { continue; } uint num20 = 0u; try { ((Channel)(ref item6)).getPosition(ref num20, (TIMEUNIT)1); } catch { } int num21 = (int)(num20 - _posPausa[k]); if (Math.Abs(num21) > 120) { ControlDoblajePlugin.Log.LogWarning((object)$"[MultiPista] DRIFT canal {k} en pausa: {_posPausa[k]}→{num20}ms ({num21:+#;-#;0}ms) — restaurado"); try { ((Channel)(ref item6)).setPosition(_posPausa[k], (TIMEUNIT)1); } catch { } } } } _pausado = false; ControlDoblajePlugin.Log.LogInfo((object)"[MultiPista] reanudado"); } int num22 = (_usarBanks ? _instancias.Count : _canales.Count); if (_esCinematica && num22 > 0 && _rutas != null && _rutas.Count > 0) { uint num23 = 0u; try { if (_usarBanks) { val2 = _instancias[0]; if (((EventInstance)(ref val2)).isValid()) { val2 = _instancias[0]; int val9 = default(int); if ((int)((EventInstance)(ref val2)).getTimelinePosition(ref val9) == 0) { num23 = (uint)Math.Max(0, val9); } } } else { tuple = _canales[0]; ((Channel)(ref tuple.Item2)).getPosition(ref num23, (TIMEUNIT)1); } } catch { } if (num23 != 0) { CinematicaDuckingManager.Tick(Path.GetFileNameWithoutExtension(_rutas[0]), num23); } } int num24 = (_usarBanks ? _instancias.Count : _canales.Count); if (_cortarEnMs != 0 && num24 > 0 && _rutas != null && _cortarEnMsKey != null) { uint num25 = 0u; int val10 = default(int); for (int l = 0; l < num24 && l < _rutas.Count; l++) { if (_rutas[l].IndexOf(_cortarEnMsKey, StringComparison.OrdinalIgnoreCase) < 0) { continue; } try { if (_usarBanks) { val2 = _instancias[l]; if ((int)((EventInstance)(ref val2)).getTimelinePosition(ref val10) == 0) { num25 = (uint)Math.Max(0, val10); } } else { tuple = _canales[l]; ((Channel)(ref tuple.Item2)).getPosition(ref num25, (TIMEUNIT)1); } } catch { } break; } if (num25 >= _cortarEnMs) { ControlDoblajePlugin.Log.LogInfo((object)("[MultiPista] Corte programado: pos=" + num25 + "ms >= " + _cortarEnMs + "ms — cortando " + _cortarEnMsKey)); _cortarEnMs = 0u; bool flag9 = default(bool); for (int num26 = num24 - 1; num26 >= 0; num26--) { if (num26 < _rutas.Count && _rutas[num26].IndexOf(_cortarEnMsKey, StringComparison.OrdinalIgnoreCase) >= 0) { try { if (_usarBanks) { val2 = _instancias[num26]; if (((EventInstance)(ref val2)).isValid()) { val2 = _instancias[num26]; ((EventInstance)(ref val2)).stop((STOP_MODE)1); val2 = _instancias[num26]; ((EventInstance)(ref val2)).release(); } _instancias.RemoveAt(num26); } else { tuple = _canales[num26]; if ((int)((Channel)(ref tuple.Item2)).isPlaying(ref flag9) == 0 && flag9) { tuple = _canales[num26]; ((Channel)(ref tuple.Item2)).stop(); } try { tuple = _canales[num26]; ((Sound)(ref tuple.Item1)).release(); } catch { } _canales.RemoveAt(num26); } } catch { } } } } } if (_usarBanks) { PLAYBACK_STATE val11 = default(PLAYBACK_STATE); for (int num27 = _instancias.Count - 1; num27 >= 0; num27--) { try { val2 = _instancias[num27]; if (!((EventInstance)(ref val2)).isValid()) { _instancias.RemoveAt(num27); } else { val2 = _instancias[num27]; if ((int)((EventInstance)(ref val2)).getPlaybackState(ref val11) == 0 && (int)val11 == 2) { try { val2 = _instancias[num27]; ((EventInstance)(ref val2)).release(); } catch { } _instancias.RemoveAt(num27); } } } catch { try { _instancias.RemoveAt(num27); } catch { } } } } else { bool flag10 = default(bool); for (int num28 = _canales.Count - 1; num28 >= 0; num28--) { try { tuple = _canales[num28]; if ((int)((Channel)(ref tuple.Item2)).isPlaying(ref flag10) > 0) { try { tuple = _canales[num28]; ((Sound)(ref tuple.Item1)).release(); } catch { } _canales.RemoveAt(num28); } } catch { try { _canales.RemoveAt(num28); } catch { } } } } if (_pausado) { return; } bool flag11 = false; if (_usarBanks) { PLAYBACK_STATE val12 = default(PLAYBACK_STATE); foreach (EventInstance instancia4 in _instancias) { EventInstance current6 = instancia4; if (!((EventInstance)(ref current6)).isValid() || (int)((EventInstance)(ref current6)).getPlaybackState(ref val12) != 0 || (int)val12 == 2) { continue; } flag11 = true; break; } } else { foreach (var canale3 in _canales) { Sound item7 = canale3.s; Channel item8 = canale3.c; bool flag12 = false; ((Channel)(ref item8)).isPlaying(ref flag12); if (flag12) { flag11 = true; break; } } } if (_pendientesAsync.Count > 0) { flag11 = true; } if (!flag11 && _esperandoFMODDesde <= 0f) { if (_usarBanks) { foreach (EventInstance instancia5 in _instancias) { EventInstance current8 = instancia5; try { if (((EventInstance)(ref current8)).isValid()) { ((EventInstance)(ref current8)).release(); } } catch { } } _instancias.Clear(); } else { foreach (var canale4 in _canales) { var (val13, val14) = canale4; try { if (((Sound)(ref val13)).hasHandle()) { ((Sound)(ref val13)).release(); } } catch { } } _canales.Clear(); } _volsBase.Clear(); if (_esCinematica) { _esperandoFMODDesde = Time.realtimeSinceStartup; ControlDoblajePlugin.Log.LogInfo((object)"[MultiPista] WAVs completados (cinemática) — runner en espera de fin FMOD"); return; } if (_rutas != null) { CinematicaMultiPistaPlayer.EstablecerCooldown(_rutas); } _esperandoFMODDesde = Time.realtimeSinceStartup; ControlDoblajePlugin.Log.LogInfo((object)"[MultiPista] WAVs completados (voiceline) — cooldown 15s + espera 5s"); } else { float num29 = (_esCinematica ? 300f : (_fueSoltado ? 30f : 5f)); if (_esperandoFMODDesde > 0f && Time.realtimeSinceStartup - _esperandoFMODDesde > num29) { ControlDoblajePlugin.Log.LogInfo((object)$"[MultiPista] Timeout {num29}s — destruyendo runner"); Object.Destroy((Object)(object)((Component)this).gameObject); } } } public void MarcarEsAjena() { _esAjena = true; } public void SoltarCinematica() { _esCinematica = false; _fueSoltado = true; _esperandoFMODDesde = -1f; CinematicaDuckingManager.Reset(); if (_rutas != null) { CinematicaMultiPistaPlayer.EstablecerCooldown(_rutas); } ControlDoblajePlugin.Log.LogInfo((object)"[MultiPista] SoltarCinematica — WAV continuará hasta fin natural, cooldown 15s"); } public bool MismoContenido(List rutas) { if (_rutas == null || rutas == null || _rutas.Count != rutas.Count) { return false; } for (int i = 0; i < _rutas.Count; i++) { if (!string.Equals(_rutas[i], rutas[i], StringComparison.OrdinalIgnoreCase)) { return false; } } return true; } public void DetenerInteligente() { //IL_027d: Unknown result type (might be due to invalid IL or missing references) //IL_0282: Unknown result type (might be due to invalid IL or missing references) //IL_0284: Unknown result type (might be due to invalid IL or missing references) //IL_0289: Unknown result type (might be due to invalid IL or missing references) //IL_0293: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_02b4: Unknown result type (might be due to invalid IL or missing references) //IL_02ba: Invalid comparison between Unknown and I4 //IL_02c3: Unknown result type (might be due to invalid IL or missing references) //IL_0176: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_0180: Invalid comparison between Unknown and I4 //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_01a0: Invalid comparison between Unknown and I4 //IL_01a8: Unknown result type (might be due to invalid IL or missing references) //IL_01b3: Unknown result type (might be due to invalid IL or missing references) if (_rutas != null && _rutas.Count > 0 && (_rutas[0].IndexOf("Theodora", StringComparison.OrdinalIgnoreCase) >= 0 || _rutas[0].IndexOf("Suspicious", StringComparison.OrdinalIgnoreCase) >= 0)) { ControlDoblajePlugin.Log.LogInfo((object)"[MultiPista] DetenerInteligente → excepción cola larga (Theodora/Suspicious) — SoltarCinematica (cola completa)"); SoltarCinematica(); return; } float num = ((_rutas != null && _rutas.Count > 0 && (_rutas[0].IndexOf("BunrakoMan", StringComparison.OrdinalIgnoreCase) >= 0 || _rutas[0].IndexOf("HehIto", StringComparison.OrdinalIgnoreCase) >= 0 || _rutas[0].IndexOf("Mitu", StringComparison.OrdinalIgnoreCase) >= 0)) ? 8f : 4f); int num2 = (_usarBanks ? _instancias.Count : _canales.Count); bool flag = num2 == 0; if (!flag) { flag = true; if (_usarBanks) { PLAYBACK_STATE val = default(PLAYBACK_STATE); EventDescription val2 = default(EventDescription); foreach (EventInstance instancia in _instancias) { EventInstance current = instancia; if (((EventInstance)(ref current)).isValid() && (int)((EventInstance)(ref current)).getPlaybackState(ref val) == 0 && (int)val != 2) { int num3 = 0; int num4 = 0; bool flag2 = (int)((EventInstance)(ref current)).getTimelinePosition(ref num3) == 0; bool flag3 = (int)((EventInstance)(ref current)).getDescription(ref val2) == 0 && (int)((EventDescription)(ref val2)).getLength(ref num4) == 0 && num4 > 0; if (!flag2 || !flag3) { flag = false; break; } float num5 = (float)(num4 - num3) / 1000f; ControlDoblajePlugin.Log.LogInfo((object)$"[MultiPista] DetInt(Studio): pos={num3}ms len={num4}ms restante={num5:F1}s umbral={num}s"); if (num5 > num) { flag = false; break; } } } } else { foreach (var canale in _canales) { Sound item = canale.s; Channel item2 = canale.c; bool flag4 = false; ((Channel)(ref item2)).isPlaying(ref flag4); if (flag4) { uint num6 = 0u; uint num7 = 0u; bool flag5 = (int)((Channel)(ref item2)).getPosition(ref num6, (TIMEUNIT)1) == 0; bool flag6 = (int)((Sound)(ref item)).getLength(ref num7, (TIMEUNIT)1) == 0 && num7 != 0; if (!flag5 || !flag6) { flag = false; break; } float num8 = (float)(num7 - num6) / 1000f; ControlDoblajePlugin.Log.LogInfo((object)("[MultiPista] DetInt: " + Path.GetFileName((_rutas != null && _rutas.Count > 0) ? _rutas[0] : "?") + " " + $"pos={num6}ms len={num7}ms restante={num8:F1}s umbral={num}s")); if (num8 > num) { flag = false; break; } } } } } if (flag) { ControlDoblajePlugin.Log.LogInfo((object)"[MultiPista] DetenerInteligente → fin natural — SoltarCinematica (la cola de reverb termina sola)"); SoltarCinematica(); return; } ControlDoblajePlugin.Log.LogInfo((object)"[MultiPista] DetenerInteligente → skip — cooldown 15s + Detener()"); if (_rutas != null) { CinematicaMultiPistaPlayer.EstablecerCooldown(_rutas); } Detener(); } public void Detener() { //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0064: 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_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_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Invalid comparison between Unknown and I4 //IL_010a: Unknown result type (might be due to invalid IL or missing references) AbandonarPendientesAsync(); CinematicaDuckingManager.Reset(); ((MonoBehaviour)this).StopAllCoroutines(); if (!_iniciado) { CinematicaMultiPistaPlayer.SilenciarVoicelineHasta = -1f; if ((Object)(object)CinematicaMultiPistaPlayer.RunnerActivo == (Object)(object)this) { CinematicaMultiPistaPlayer.RunnerActivo = null; } } if (_usarBanks) { foreach (EventInstance instancia in _instancias) { EventInstance current = instancia; try { if (((EventInstance)(ref current)).isValid()) { ((EventInstance)(ref current)).stop((STOP_MODE)1); ((EventInstance)(ref current)).release(); } } catch { } } _instancias.Clear(); } else { bool flag = default(bool); foreach (var canale in _canales) { var (val, val2) = canale; try { if (!((Channel)(ref val2)).hasHandle()) { continue; } if ((int)((Channel)(ref val2)).isPlaying(ref flag) == 0) { ((Channel)(ref val2)).stop(); } goto IL_0119; } catch { goto IL_0119; } IL_0119: try { if (((Sound)(ref val)).hasHandle()) { ((Sound)(ref val)).release(); } } catch { } } _canales.Clear(); } _volsBase.Clear(); Object.Destroy((Object)(object)((Component)this).gameObject); } private IEnumerator FadeYDetener(float duracion) { int fadeCount = (_usarBanks ? _instancias.Count : _canales.Count); float[] vols = new float[fadeCount]; EventInstance val; float fv = default(float); (Sound, Channel) tuple; for (int i = 0; i < fadeCount; i++) { float v = 1f; try { if (_usarBanks) { val = _instancias[i]; ((EventInstance)(ref val)).getVolume(ref v, ref fv); } else { tuple = _canales[i]; ((Channel)(ref tuple.Item2)).getVolume(ref v); } } catch { } vols[i] = v; } float elapsed = 0f; while (elapsed < duracion && (_usarBanks ? _instancias.Count : _canales.Count) > 0) { elapsed += Time.unscaledDeltaTime; float factor = Mathf.Clamp01(1f - elapsed / duracion); int fc2 = (_usarBanks ? _instancias.Count : _canales.Count); for (int j = 0; j < fc2 && j < vols.Length; j++) { try { if (_usarBanks) { val = _instancias[j]; ((EventInstance)(ref val)).setVolume(vols[j] * factor); } else { tuple = _canales[j]; ((Channel)(ref tuple.Item2)).setVolume(vols[j] * factor); } } catch { } } yield return null; } if (_usarBanks) { foreach (EventInstance instancia in _instancias) { EventInstance ins = instancia; try { if (((EventInstance)(ref ins)).isValid()) { ((EventInstance)(ref ins)).stop((STOP_MODE)1); ((EventInstance)(ref ins)).release(); } } catch { } } _instancias.Clear(); } else { foreach (var canale in _canales) { tuple = canale; var (s, c) = tuple; try { if (((Channel)(ref c)).hasHandle()) { ((Channel)(ref c)).stop(); } if (((Sound)(ref s)).hasHandle()) { ((Sound)(ref s)).release(); } } catch { } } _canales.Clear(); } _volsBase.Clear(); Object.Destroy((Object)(object)((Component)this).gameObject); } public void BuscarPosicion(uint posMs) { //IL_02d3: Unknown result type (might be due to invalid IL or missing references) //IL_02d8: Unknown result type (might be due to invalid IL or missing references) //IL_0335: Unknown result type (might be due to invalid IL or missing references) //IL_033a: Unknown result type (might be due to invalid IL or missing references) //IL_033c: Unknown result type (might be due to invalid IL or missing references) //IL_0341: Unknown result type (might be due to invalid IL or missing references) //IL_034c: Unknown result type (might be due to invalid IL or missing references) //IL_02eb: Unknown result type (might be due to invalid IL or missing references) //IL_0368: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: 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_00f8: Invalid comparison between Unknown and I4 //IL_01d5: Unknown result type (might be due to invalid IL or missing references) bool flag = _pausado || Time.timeScale == 0f; if (_skipFloorMs != 0 && posMs < _skipFloorMs && !flag) { ControlDoblajePlugin.Log.LogInfo((object)("[MultiPista] BuscarPosicion=" + posMs + "ms < piso skip " + _skipFloorMs + "ms → clamp a piso (silencio)")); posMs = _skipFloorMs; } int num = (_usarBanks ? _instancias.Count : _canales.Count); if (num > 0) { try { uint num2 = 0u; (Sound, Channel) tuple; if (_usarBanks) { EventInstance val = _instancias[0]; if (((EventInstance)(ref val)).isValid()) { val = _instancias[0]; int val2 = default(int); if ((int)((EventInstance)(ref val)).getTimelinePosition(ref val2) == 0) { num2 = (uint)Math.Max(0, val2); } } } else { tuple = _canales[0]; ((Channel)(ref tuple.Item2)).getPosition(ref num2, (TIMEUNIT)1); } if (posMs + 5000 < num2) { ControlDoblajePlugin.Log.LogInfo((object)("[MultiPista] BuscarPosicion=" + posMs + "ms IGNORADO (seek hacia atrás desde " + num2 + "ms)")); return; } if (posMs > num2 + 2000) { uint num3 = 0u; try { if (!_usarBanks && _canales.Count > 0) { tuple = _canales[0]; ((Sound)(ref tuple.Item1)).getLength(ref num3, (TIMEUNIT)1); } } catch { } ControlDoblajePlugin.Log.LogWarning((object)("[MultiPista] ⚠ SEEK ADELANTA " + (posMs - num2) + "ms (posible corte mid-word): " + num2 + "→" + posMs + "ms wavLen=" + num3 + "ms " + ((_rutas != null && _rutas.Count > 0) ? Path.GetFileName(_rutas[0]) : "?"))); } } catch { } } if (_pendientesAsync.Count > 0) { _seekPendienteMs = posMs; _seekPendienteT = Time.realtimeSinceStartup; } if (_usarBanks) { foreach (EventInstance instancia in _instancias) { EventInstance current = instancia; try { if (((EventInstance)(ref current)).isValid()) { ((EventInstance)(ref current)).setTimelinePosition((int)posMs); } } catch { } } } else { foreach (var canale in _canales) { var (val3, val4) = canale; try { uint num4 = 0u; ((Sound)(ref val3)).getLength(ref num4, (TIMEUNIT)1); if (num4 == 0 || posMs < num4) { ((Channel)(ref val4)).setPosition(posMs, (TIMEUNIT)1); continue; } ControlDoblajePlugin.Log.LogWarning((object)("[MultiPista] ⚠ seek " + posMs + "ms pasaba el fin de una pista (len=" + num4 + "ms) — NO seekeada (antes la mataba)")); } catch { } } } if (_posPausa.Count > 0) { for (int i = 0; i < _posPausa.Count; i++) { _posPausa[i] = posMs; } } ControlDoblajePlugin.Log.LogInfo((object)("[MultiPista] BuscarPosicion=" + posMs + "ms")); } private void OnDestroy() { //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) AbandonarPendientesAsync(); CinematicaDuckingManager.Reset(); if ((Object)(object)CinematicaMultiPistaPlayer.RunnerActivo == (Object)(object)this) { CinematicaMultiPistaPlayer.RunnerActivo = null; CinematicaMultiPistaPlayer.LimpiarInstanciaFMOD(); } if ((Object)(object)CinematicaMultiPistaPlayer.AmbienterRunnerActivo == (Object)(object)this) { CinematicaMultiPistaPlayer.AmbienterRunnerActivo = null; } if (_esAjena && _rutas != null) { CinematicaMultiPistaPlayer.SetTombstone(_rutas); } if (_usarBanks) { foreach (EventInstance instancia in _instancias) { EventInstance current = instancia; try { if (((EventInstance)(ref current)).isValid()) { ((EventInstance)(ref current)).stop((STOP_MODE)1); ((EventInstance)(ref current)).release(); } } catch { } } return; } foreach (var canale in _canales) { var (val, val2) = canale; try { ((Channel)(ref val2)).stop(); ((Sound)(ref val)).release(); } catch { } } } } [HarmonyPatch(typeof(RuntimeManager), "PlayOneShot", new Type[] { typeof(string), typeof(Vector3) })] public class FMODReemplazoPatch { private static bool Prefix(string path, Vector3 position) { if (path == null) { return true; } WandererGestor.InyectarSiNecesario(); HeadtombsGestor.InyectarSiNecesario(); return true; } } [HarmonyPatch(typeof(RuntimeManager), "CreateInstance", new Type[] { typeof(string) })] public class FMODCreateInstanceWavCheckPatch { private static readonly HashSet YaLogueados = new HashSet(StringComparer.OrdinalIgnoreCase); private static void Postfix(ref EventInstance __result, string path) { if (YaLogueados.Add(path) && ControlDoblajePlugin.LogVerboso) { ControlDoblajePlugin.Log.LogInfo((object)("[FMOD_CreateInstance] " + path)); } } } [HarmonyPatch(typeof(EventInstance), "setTimelinePosition")] public static class FMODSetTimelinePositionPatch { private static void Postfix(EventInstance __instance, int position) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) try { if (!((Object)(object)CinematicaMultiPistaPlayer.RunnerActivo == (Object)null) && FMODStopHelper.NPCVideoRegistrado && !(__instance.handle != FMODStopHelper.NPCVideoActivo.handle)) { if (CinematicaMultiPistaPlayer.RunnerActivo.FueSoltado) { ControlDoblajePlugin.Log.LogInfo((object)("[CineMulti] setTimelinePosition=" + position + "ms IGNORADO (runner soltado)")); return; } ControlDoblajePlugin.Log.LogInfo((object)("[CineMulti] setTimelinePosition=" + position + "ms → runner seek")); CinematicaMultiPistaPlayer.RunnerActivo.BuscarPosicion((uint)position); } } catch { } } } public class FMODPatchInstaller { private static bool _instalado; public static void InstalarSiNoEsta(Harmony harmony) { if (!_instalado) { _instalado = true; ControlDoblajePlugin.Log.LogInfo((object)"[FMOD] Patches activos: EventInstance.start + CreateInstance + PlayOneShot"); } } } [HarmonyPatch] public class PlayVoiceoverPatch { private static readonly Dictionary AmbientalMap = new Dictionary(StringComparer.OrdinalIgnoreCase) { { "USB_LP_Wanderer_RadioDry", "Wanderer" }, { "USB_LP_Wanderer_RadioWet", "Wanderer" } }; private static readonly Dictionary RandomPool = new Dictionary(StringComparer.OrdinalIgnoreCase) { { "event:/NPCs/Voicelines/VL_TheBus", ("TheBus", "VL_TheBus_??_ImTheBus") } }; private static readonly Random _rng = new Random(); public static bool UltimoDoblajeEsNuestro = false; public static string PoolDirectoRuta = null; public static float PoolDirectoTiempo = 0f; public static readonly Dictionary DubDialogo = new Dictionary(StringComparer.OrdinalIgnoreCase); private static string _lastVoiceKey; private static float _lastVoiceTime; private const float VOICE_RETRIGGER_COOLDOWN = 2f; private static MethodBase TargetMethod() { Assembly assembly = null; Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly2 in assemblies) { if (assembly2.GetName().Name == "JoelG.ENA4") { assembly = assembly2; break; } } return ((assembly?.GetType("JoelG.ENA4.UI.HUD.Dialogue.HUDDialogue"))?.GetNestedType("DialogueAudio", BindingFlags.NonPublic))?.GetMethod("PlayVoiceover", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); } public static bool EsEventoHorneado(string eventPath) { return eventPath != null && RandomPool.ContainsKey(eventPath); } private static string PromoverDub(string keyValida, string relVoices) { string directoryName = Path.GetDirectoryName(ControlDoblajePlugin.VoicesPath); string wavPath = Path.Combine(directoryName, relVoices.Replace('/', Path.DirectorySeparatorChar)); wavPath = CinematicaMultiPistaPlayer.ResolverAudio(wavPath); DubDialogo[keyValida] = wavPath; UltimoDoblajeEsNuestro = true; ControlDoblajePlugin.Log.LogInfo((object)("[PlayVoiceover] PromoverDub: " + keyValida + " → " + Path.GetFileName(wavPath))); return keyValida; } private static void Prefix(ref string key) { ControlDoblajePlugin.Log.LogInfo((object)("[PlayVoiceover] key=" + key)); UltimoDoblajeEsNuestro = false; string text = key; if (!string.IsNullOrEmpty(text)) { DubDialogo.Remove(text); } if (!string.IsNullOrEmpty(key) && key == _lastVoiceKey && Time.realtimeSinceStartup - _lastVoiceTime < 2f) { ControlDoblajePlugin.Log.LogInfo((object)("[PlayVoiceover] Anti-retrigger bloqueado: " + key)); key = "_silent_"; return; } _lastVoiceKey = key; _lastVoiceTime = Time.realtimeSinceStartup; bool flag = key.IndexOf("/SFX/", StringComparison.OrdinalIgnoreCase) >= 0; if (!flag) { string text2 = key; int num = text2.LastIndexOf('/'); if (num >= 0) { text2 = text2.Substring(num + 1); } flag = text2.StartsWith("USB_S_", StringComparison.OrdinalIgnoreCase) || text2.StartsWith("USB_SP_", StringComparison.OrdinalIgnoreCase) || text2.StartsWith("USB_Mayo", StringComparison.OrdinalIgnoreCase); } (string, string) value; if (flag) { ControlDoblajePlugin.Log.LogInfo((object)("[PlayVoiceover] SFX key → skip: " + key)); } else if (CinematicaMultiPistaPlayer.HayCinematicaActiva) { ControlDoblajePlugin.Log.LogInfo((object)"[PlayVoiceover] Cinemática activa → key silente"); key = "_silent_"; } else if (RandomPool.TryGetValue(key, out value)) { if (!(ControlDoblajePlugin.PersonajeActivo.TryGetValue(value.Item1, out var value2) && value2)) { return; } string text3 = Path.Combine(ControlDoblajePlugin.VoicesPath, value.Item1); if (AssetPack.CarpetaExiste(text3)) { string[] audioFiles = CinematicaMultiPistaPlayer.GetAudioFiles(text3, value.Item2 + ".wav"); if (audioFiles.Length == 0) { audioFiles = CinematicaMultiPistaPlayer.GetAudioFiles(text3, "*.wav"); } if (audioFiles.Length != 0) { string text4 = audioFiles[_rng.Next(audioFiles.Length)]; PoolDirectoRuta = CinematicaMultiPistaPlayer.ResolverAudio(text4); PoolDirectoTiempo = Time.realtimeSinceStartup; ControlDoblajePlugin.Log.LogInfo((object)("[PlayVoiceover] RandomPool (directo) -> " + Path.GetFileName(text4))); } } } else { if (string.IsNullOrEmpty(key)) { return; } bool flag2 = key.StartsWith("event:", StringComparison.OrdinalIgnoreCase); string text5 = (flag2 ? key : null); if (flag2) { int num2 = key.LastIndexOf('/'); string text6 = ((num2 >= 0) ? key.Substring(num2 + 1) : key); ControlDoblajePlugin.Log.LogInfo((object)("[PlayVoiceover] Normalizado FMOD path → keyNorm=" + text6)); foreach (KeyValuePair cinematicasRegistrada in CinematicaMultiPistaPlayer.CinematicasRegistradas) { string a = cinematicasRegistrada.Key.Substring(cinematicasRegistrada.Key.LastIndexOf('/') + 1); if (!string.Equals(a, text6, StringComparison.OrdinalIgnoreCase)) { continue; } List list = CinematicaMultiPistaPlayer.ResolverPistas(text6, cinematicasRegistrada.Value); if (list == null || list.Count == 0) { break; } ControlDoblajePlugin.Log.LogInfo((object)("[PlayVoiceover] Cinemática registrada via normalización: " + cinematicasRegistrada.Key)); List list2 = list.FindAll(CinematicaMultiPistaPlayer.EsRutaAmbiente); List list3 = list.FindAll((string r) => !CinematicaMultiPistaPlayer.EsRutaAmbiente(r)); if ((Object)(object)CinematicaMultiPistaPlayer.RunnerActivo != (Object)null) { CinematicaMultiPistaPlayer.RunnerActivo.Detener(); CinematicaMultiPistaPlayer.RunnerActivo = null; } if (list3.Count > 0) { CinematicaMultiPistaPlayer.ReproducirSecundarias(list3, esCinematica: true); } if (list2.Count > 0 && (Object)(object)CinematicaMultiPistaPlayer.AmbienterRunnerActivo == (Object)null) { CinematicaMultiPistaPlayer.ReproducirAmbiente(list2); } CinematicaMultiPistaPlayer.ActivarSilencioVoiceline(); key = "_silent_"; return; } ControlDoblajePlugin.Log.LogInfo((object)("[PlayVoiceover] FMOD path sin cinematica → keyNorm=" + text6 + " para matching normal")); key = text6; } if (key.Contains(".")) { return; } TurronishBankLoader.LoadIfNeeded(); if (TurronishBankLoader.BanksDisponibles) { foreach (string personajesDisponible in ControlDoblajePlugin.PersonajesDisponibles) { if (ControlDoblajePlugin.PersonajeActivo.TryGetValue(personajesDisponible, out var value3) && value3) { string filename = key + "_" + personajesDisponible; if (TurronishBankLoader.HasEvent(filename) && TurronishBankLoader.PlayEvent(filename)) { key = "_silent_"; UltimoDoblajeEsNuestro = true; return; } } } if (TurronishBankLoader.HasEvent(key) && TurronishBankLoader.PlayEvent(key)) { key = "_silent_"; UltimoDoblajeEsNuestro = true; return; } } string personaje; string text7; if (AmbientalMap.TryGetValue(key, out var value4)) { personaje = value4; text7 = value4 + "/" + key + ".wav"; ControlDoblajePlugin.PersonajeActivo.TryGetValue(personaje, out var value5); string path = Path.Combine(ControlDoblajePlugin.VoicesPath, text7); if (value5 && CinematicaMultiPistaPlayer.ExisteWAV(path)) { ControlDoblajePlugin.Log.LogInfo((object)("[PlayVoiceover] Ambiental activo: " + text7)); return; } string pathSinExt = Path.Combine(ControlDoblajePlugin.VoicesPath, personaje, key + "_orig"); string text8 = CinematicaMultiPistaPlayer.ElegirVariante(pathSinExt); if (text8 != null) { key = PromoverDub(text, "Voices/" + personaje + "/" + Path.GetFileName(text8)); ControlDoblajePlugin.Log.LogInfo((object)("[PlayVoiceover] Ambiental _orig (nativo) -> " + Path.GetFileName(text8))); } else { ControlDoblajePlugin.Log.LogInfo((object)"[PlayVoiceover] Ambiental sin archivo, dejando original FMOD"); } return; } if (key.Contains("/")) { string text9 = key; string[] partes = key.Split(new char[1] { '/' }); if (partes.Length >= 3 && ControlDoblajePlugin.PersonajesDisponibles.FindIndex((string p) => p.Equals(partes[0], StringComparison.OrdinalIgnoreCase)) < 0) { text9 = partes[1] + "/" + string.Join("/", partes, 2, partes.Length - 2); } personaje = text9.Split(new char[1] { '/' })[0]; text7 = text9 + ".wav"; int num3 = ControlDoblajePlugin.PersonajesDisponibles.FindIndex((string pp) => pp.Equals(personaje, StringComparison.OrdinalIgnoreCase)); if (num3 >= 0 && !string.Equals(ControlDoblajePlugin.PersonajesDisponibles[num3], personaje, StringComparison.Ordinal)) { personaje = ControlDoblajePlugin.PersonajesDisponibles[num3]; text7 = personaje + "/" + text9.Substring(text9.IndexOf('/') + 1) + ".wav"; } if (num3 < 0) { string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(text7); List list4 = new List(); foreach (string personajesDisponible2 in ControlDoblajePlugin.PersonajesDisponibles) { if (string.Equals(ControlDoblajePlugin.KeyDePersonaje(personajesDisponible2), personaje, StringComparison.OrdinalIgnoreCase) && ControlDoblajePlugin.PersonajeActivo.TryGetValue(personajesDisponible2, out var value6) && value6) { string fileNameWithoutExtension2 = Path.GetFileNameWithoutExtension(text9.Substring(text9.IndexOf('/') + 1)); string path2 = Path.Combine(ControlDoblajePlugin.VoicesPath, personajesDisponible2, fileNameWithoutExtension2 + ".wav"); if (CinematicaMultiPistaPlayer.ExisteWAV(path2)) { list4.Add(personajesDisponible2); } } } if (list4.Count <= 0) { foreach (string personajesDisponible3 in ControlDoblajePlugin.PersonajesDisponibles) { if (string.Equals(ControlDoblajePlugin.KeyDePersonaje(personajesDisponible3), personaje, StringComparison.OrdinalIgnoreCase)) { string fileNameWithoutExtension3 = Path.GetFileNameWithoutExtension(text9.Substring(text9.IndexOf('/') + 1)); string pathSinExt2 = Path.Combine(ControlDoblajePlugin.VoicesPath, personajesDisponible3, fileNameWithoutExtension3 + "_orig"); string text10 = CinematicaMultiPistaPlayer.ElegirVariante(pathSinExt2); if (text10 != null) { key = PromoverDub(text, "Voices/" + personajesDisponible3 + "/" + Path.GetFileName(text10)); ControlDoblajePlugin.Log.LogInfo((object)("[PlayVoiceover] KeyOverride _orig (nativo): " + Path.GetFileName(text10))); return; } } } string text11 = fileNameWithoutExtension; string text12 = null; List list5 = new List(); foreach (string personajesDisponible4 in ControlDoblajePlugin.PersonajesDisponibles) { string text13 = Path.Combine(ControlDoblajePlugin.VoicesPath, personajesDisponible4); if (!AssetPack.CarpetaExiste(text13)) { continue; } ControlDoblajePlugin.PersonajeActivo.TryGetValue(personajesDisponible4, out var value7); string text14 = (value7 ? CinematicaMultiPistaPlayer.ElegirVariante(Path.Combine(text13, text11 + "_" + personajesDisponible4)) : null); if (text14 == null) { text14 = CinematicaMultiPistaPlayer.ElegirVariante(Path.Combine(text13, text11 + "_" + personajesDisponible4 + "_orig")); } if (text14 == null && value7) { text14 = CinematicaMultiPistaPlayer.ElegirVariante(Path.Combine(text13, text11)); } if (text14 != null) { if (string.Equals(personajesDisponible4, "Salespersone", StringComparison.OrdinalIgnoreCase)) { text12 = text14; } else { list5.Add(text14); } } } if (text12 == null && list5.Count < 2) { foreach (string personajesDisponible5 in ControlDoblajePlugin.PersonajesDisponibles) { string text15 = Path.Combine(ControlDoblajePlugin.VoicesPath, personajesDisponible5); if (AssetPack.CarpetaExiste(text15)) { ControlDoblajePlugin.PersonajeActivo.TryGetValue(personajesDisponible5, out var value8); bool flag3 = CinematicaMultiPistaPlayer.ExisteWAV(Path.Combine(text15, text11 + "_" + personajesDisponible5 + ".wav")) || CinematicaMultiPistaPlayer.ExisteWAV(Path.Combine(text15, text11 + "_" + personajesDisponible5 + "_orig.wav")) || CinematicaMultiPistaPlayer.ExisteWAV(Path.Combine(text15, text11 + ".wav")); ControlDoblajePlugin.Log.LogInfo((object)$"[KeyAjena-DIAG] {personajesDisponible5}: activo={value8} tieneArchivo={flag3}"); } } } if (text12 == null && list5.Count <= 0) { return; } ControlDoblajePlugin.Log.LogInfo((object)("[MultiPista] key-ajena (slash): " + text11 + ((text12 != null) ? " Salespersone=principal" : "") + ((list5.Count > 0) ? (" otros=" + list5.Count) : ""))); if (text12 != null) { string name = new DirectoryInfo(Path.GetDirectoryName(text12)).Name; string text16 = Path.GetFileName(text12); if (!text16.EndsWith(".wav", StringComparison.OrdinalIgnoreCase) && !text16.EndsWith(".ogg", StringComparison.OrdinalIgnoreCase)) { text16 += ".wav"; } key = PromoverDub(text, "Voices/" + name + "/" + text16); ControlDoblajePlugin.Log.LogInfo((object)("[MultiPista] key-ajena → Salespersone principal (nativo): " + Path.GetFileName(text16))); if ((Object)(object)CinematicaMultiPistaPlayer.RunnerActivo != (Object)null) { CinematicaMultiPistaPlayer.RunnerActivo.Detener(); CinematicaMultiPistaPlayer.RunnerActivo = null; } if (list5.Count > 0) { CinematicaMultiPistaPlayer.ReproducirSecundarias(list5); if ((Object)(object)CinematicaMultiPistaPlayer.RunnerActivo != (Object)null) { CinematicaMultiPistaPlayer.RunnerActivo.MarcarEsAjena(); } } } else if (!CinematicaMultiPistaPlayer.HayVideoClipActivo && list5.Count > 0) { ControlDoblajePlugin.Log.LogInfo((object)("[MultiPista] key-ajena → sin Sales, reproduciendo " + list5.Count + " pista(s) via runner Core (anti-loop)")); if ((Object)(object)CinematicaMultiPistaPlayer.RunnerActivo != (Object)null) { CinematicaMultiPistaPlayer.RunnerActivo.Detener(); CinematicaMultiPistaPlayer.RunnerActivo = null; } CinematicaMultiPistaPlayer.ReproducirSecundarias(list5); if ((Object)(object)CinematicaMultiPistaPlayer.RunnerActivo != (Object)null) { CinematicaMultiPistaPlayer.RunnerActivo.MarcarEsAjena(); } key = "_silent_"; UltimoDoblajeEsNuestro = true; CinematicaMultiPistaPlayer.ActivarSilencioVoiceline(); } else { if (CinematicaMultiPistaPlayer.HayVideoClipActivo) { key = "_silent_"; } CinematicaMultiPistaPlayer.ReproducirSecundarias(list5); if ((Object)(object)CinematicaMultiPistaPlayer.RunnerActivo != (Object)null) { CinematicaMultiPistaPlayer.RunnerActivo.MarcarEsAjena(); } CinematicaMultiPistaPlayer.SilenciarVoicelinesActivos(); CinematicaMultiPistaPlayer.ActivarSilencioVoiceline(); } return; } personaje = list4[_rng.Next(list4.Count)]; text7 = personaje + "/" + Path.GetFileNameWithoutExtension(text9.Substring(text9.IndexOf('/') + 1)) + ".wav"; ControlDoblajePlugin.Log.LogInfo((object)("[PlayVoiceover] KeyOverride inverso: " + personaje + " <- " + key)); } } else { personaje = null; foreach (string personajesDisponible6 in ControlDoblajePlugin.PersonajesDisponibles) { if (key.IndexOf(personajesDisponible6, StringComparison.OrdinalIgnoreCase) >= 0) { personaje = personajesDisponible6; break; } } if (personaje == null) { foreach (KeyValuePair item in ControlDoblajePlugin.KeyOverride) { if (key.IndexOf(item.Value, StringComparison.OrdinalIgnoreCase) >= 0 && ControlDoblajePlugin.PersonajesDisponibles.Contains(item.Key)) { personaje = item.Key; break; } } } if (personaje == null) { foreach (KeyValuePair cinematicasRegistrada2 in CinematicaMultiPistaPlayer.CinematicasRegistradas) { string a2 = cinematicasRegistrada2.Key.Substring(cinematicasRegistrada2.Key.LastIndexOf('/') + 1); if (!string.Equals(a2, key, StringComparison.OrdinalIgnoreCase)) { continue; } List list6 = CinematicaMultiPistaPlayer.ResolverPistas(key, cinematicasRegistrada2.Value); if (list6 == null || list6.Count == 0) { break; } ControlDoblajePlugin.Log.LogInfo((object)("[PlayVoiceover] Cinemática plain-key: " + cinematicasRegistrada2.Key + " pistas=" + list6.Count)); List list7 = list6.FindAll(CinematicaMultiPistaPlayer.EsRutaAmbiente); List list8 = list6.FindAll((string r) => !CinematicaMultiPistaPlayer.EsRutaAmbiente(r)); if ((Object)(object)CinematicaMultiPistaPlayer.RunnerActivo != (Object)null) { CinematicaMultiPistaPlayer.RunnerActivo.Detener(); CinematicaMultiPistaPlayer.RunnerActivo = null; } if (list8.Count > 0) { CinematicaMultiPistaPlayer.ReproducirSecundarias(list8); } if (list7.Count > 0 && (Object)(object)CinematicaMultiPistaPlayer.AmbienterRunnerActivo == (Object)null) { CinematicaMultiPistaPlayer.ReproducirAmbiente(list7); } CinematicaMultiPistaPlayer.ActivarSilencioVoiceline(); key = "_silent_"; return; } string text17 = null; List list9 = new List(); foreach (string personajesDisponible7 in ControlDoblajePlugin.PersonajesDisponibles) { string text18 = Path.Combine(ControlDoblajePlugin.VoicesPath, personajesDisponible7); if (!Directory.Exists(text18)) { continue; } ControlDoblajePlugin.PersonajeActivo.TryGetValue(personajesDisponible7, out var value9); string text19 = (value9 ? CinematicaMultiPistaPlayer.ElegirVariante(Path.Combine(text18, key + "_" + personajesDisponible7)) : null); if (text19 == null) { text19 = CinematicaMultiPistaPlayer.ElegirVariante(Path.Combine(text18, key + "_" + personajesDisponible7 + "_orig")); } if (text19 == null && value9) { text19 = CinematicaMultiPistaPlayer.ElegirVariante(Path.Combine(text18, key)); } if (text19 != null) { if (string.Equals(personajesDisponible7, "Salespersone", StringComparison.OrdinalIgnoreCase)) { text17 = text19; } else { list9.Add(text19); } } } if (text17 == null && list9.Count < 2) { foreach (string personajesDisponible8 in ControlDoblajePlugin.PersonajesDisponibles) { string text20 = Path.Combine(ControlDoblajePlugin.VoicesPath, personajesDisponible8); if (Directory.Exists(text20)) { ControlDoblajePlugin.PersonajeActivo.TryGetValue(personajesDisponible8, out var value10); bool flag4 = CinematicaMultiPistaPlayer.ExisteWAV(Path.Combine(text20, key + "_" + personajesDisponible8 + ".wav")) || CinematicaMultiPistaPlayer.ExisteWAV(Path.Combine(text20, key + "_" + personajesDisponible8 + "_orig.wav")) || CinematicaMultiPistaPlayer.ExisteWAV(Path.Combine(text20, key + ".wav")); ControlDoblajePlugin.Log.LogInfo((object)$"[KeyAjena-DIAG] {personajesDisponible8}: activo={value10} tieneArchivo={flag4}"); } } } if (text17 != null || list9.Count > 0) { ControlDoblajePlugin.Log.LogInfo((object)("[MultiPista] key-ajena (sin personaje): " + key + ((text17 != null) ? " Salespersone=principal" : "") + ((list9.Count > 0) ? (" otros=" + list9.Count) : ""))); if (text17 != null) { string name2 = new DirectoryInfo(Path.GetDirectoryName(text17)).Name; string text21 = Path.GetFileName(text17); if (!text21.EndsWith(".wav", StringComparison.OrdinalIgnoreCase) && !text21.EndsWith(".ogg", StringComparison.OrdinalIgnoreCase)) { text21 += ".wav"; } key = PromoverDub(text, "Voices/" + name2 + "/" + text21); ControlDoblajePlugin.Log.LogInfo((object)("[MultiPista] key-ajena → Salespersone principal (nativo): " + Path.GetFileName(text21))); if ((Object)(object)CinematicaMultiPistaPlayer.RunnerActivo != (Object)null) { CinematicaMultiPistaPlayer.RunnerActivo.Detener(); CinematicaMultiPistaPlayer.RunnerActivo = null; } if (list9.Count > 0) { CinematicaMultiPistaPlayer.ReproducirSecundarias(list9); if ((Object)(object)CinematicaMultiPistaPlayer.RunnerActivo != (Object)null) { CinematicaMultiPistaPlayer.RunnerActivo.MarcarEsAjena(); } } } else if (!CinematicaMultiPistaPlayer.HayVideoClipActivo && list9.Count > 0) { ControlDoblajePlugin.Log.LogInfo((object)("[MultiPista] key-ajena (NS) → sin Sales, reproduciendo " + list9.Count + " pista(s) via runner Core (anti-loop)")); if ((Object)(object)CinematicaMultiPistaPlayer.RunnerActivo != (Object)null) { CinematicaMultiPistaPlayer.RunnerActivo.Detener(); CinematicaMultiPistaPlayer.RunnerActivo = null; } CinematicaMultiPistaPlayer.ReproducirSecundarias(list9); if ((Object)(object)CinematicaMultiPistaPlayer.RunnerActivo != (Object)null) { CinematicaMultiPistaPlayer.RunnerActivo.MarcarEsAjena(); } key = "_silent_"; UltimoDoblajeEsNuestro = true; CinematicaMultiPistaPlayer.ActivarSilencioVoiceline(); } else { if (CinematicaMultiPistaPlayer.HayVideoClipActivo) { key = "_silent_"; } CinematicaMultiPistaPlayer.ReproducirSecundarias(list9); if ((Object)(object)CinematicaMultiPistaPlayer.RunnerActivo != (Object)null) { CinematicaMultiPistaPlayer.RunnerActivo.MarcarEsAjena(); } CinematicaMultiPistaPlayer.SilenciarVoicelinesActivos(); CinematicaMultiPistaPlayer.ActivarSilencioVoiceline(); } } else if (text5 != null) { key = text5; } return; } text7 = personaje + "/" + key + ".wav"; } string fileNameWithoutExtension4 = Path.GetFileNameWithoutExtension(Path.Combine(ControlDoblajePlugin.VoicesPath, text7)); bool flag5 = false; foreach (string personajesDisponible9 in ControlDoblajePlugin.PersonajesDisponibles) { if (!string.Equals(personajesDisponible9, personaje, StringComparison.OrdinalIgnoreCase)) { string path3 = Path.Combine(ControlDoblajePlugin.VoicesPath, personajesDisponible9); if (CinematicaMultiPistaPlayer.ExisteWAV(Path.Combine(path3, fileNameWithoutExtension4 + "_" + personajesDisponible9 + ".wav"))) { flag5 = true; break; } if (CinematicaMultiPistaPlayer.ExisteWAV(Path.Combine(path3, fileNameWithoutExtension4 + "_" + personajesDisponible9 + "_orig.wav"))) { flag5 = true; break; } if (CinematicaMultiPistaPlayer.ElegirVariante(Path.Combine(path3, fileNameWithoutExtension4)) != null) { flag5 = true; break; } } } if (!flag5) { if (!ControlDoblajePlugin.PersonajeActivo.TryGetValue(personaje, out var value11) || !value11) { string pathSinExt3 = Path.Combine(ControlDoblajePlugin.VoicesPath, personaje, key + "_orig"); string text22 = CinematicaMultiPistaPlayer.ElegirVariante(pathSinExt3); if (text22 != null) { string text23 = CinematicaMultiPistaPlayer.ResolverAudio(text22); DubDialogo[key] = text23; UltimoDoblajeEsNuestro = true; ControlDoblajePlugin.Log.LogInfo((object)("[PlayVoiceover] Simple _orig (idioma original): " + key + " → " + Path.GetFileName(text23))); } return; } string path4 = Path.Combine(ControlDoblajePlugin.VoicesPath, text7); string pathSinExt4 = Path.Combine(Path.GetDirectoryName(path4), Path.GetFileNameWithoutExtension(path4)); string text24 = CinematicaMultiPistaPlayer.ElegirVariante(pathSinExt4); if (text24 == null) { string directoryName = Path.GetDirectoryName(path4); string fileNameWithoutExtension5 = Path.GetFileNameWithoutExtension(path4); string[] array = (from f in CinematicaMultiPistaPlayer.GetAudioFiles(directoryName, fileNameWithoutExtension5 + "_*.wav") where !Path.GetFileNameWithoutExtension(f).EndsWith("_orig", StringComparison.OrdinalIgnoreCase) select f).ToArray(); if (array.Length != 0) { text24 = array[_rng.Next(array.Length)]; } } if (text24 == null) { ControlDoblajePlugin.Log.LogWarning((object)("[PlayVoiceover] SIN WAV — " + personaje + " key=" + key)); return; } text24 = CinematicaMultiPistaPlayer.ResolverAudio(text24); DubDialogo[key] = text24; UltimoDoblajeEsNuestro = true; ControlDoblajePlugin.Log.LogInfo((object)("[PlayVoiceover] Dub via programmer sound nativo: " + key + " → " + Path.GetFileName(text24))); return; } ControlDoblajePlugin.Log.LogInfo((object)("[MultiPista] key=" + fileNameWithoutExtension4)); List list10 = new List(); bool flag6 = false; string path5 = Path.Combine(ControlDoblajePlugin.VoicesPath, text7); ControlDoblajePlugin.PersonajeActivo.TryGetValue(personaje, out var value12); string pathSinExt5 = Path.Combine(Path.GetDirectoryName(path5), Path.GetFileNameWithoutExtension(path5)); string text25 = null; if (value12) { text25 = CinematicaMultiPistaPlayer.ElegirVariante(pathSinExt5); } if (text25 == null) { string pathSinExt6 = Path.Combine(ControlDoblajePlugin.VoicesPath, personaje, fileNameWithoutExtension4 + "_orig"); text25 = CinematicaMultiPistaPlayer.ElegirVariante(pathSinExt6); } if (text25 != null) { flag6 = true; list10.Add(text25); ControlDoblajePlugin.Log.LogInfo((object)("[MultiPista] principal=" + Path.GetFileName(text25))); } foreach (string personajesDisponible10 in ControlDoblajePlugin.PersonajesDisponibles) { if (!string.Equals(personajesDisponible10, personaje, StringComparison.OrdinalIgnoreCase)) { string path6 = Path.Combine(ControlDoblajePlugin.VoicesPath, personajesDisponible10); ControlDoblajePlugin.PersonajeActivo.TryGetValue(personajesDisponible10, out var value13); string pathSinExt7 = Path.Combine(path6, fileNameWithoutExtension4 + "_" + personajesDisponible10); string pathSinExt8 = Path.Combine(path6, fileNameWithoutExtension4 + "_" + personajesDisponible10 + "_orig"); string text26 = null; if (value13) { text26 = CinematicaMultiPistaPlayer.ElegirVariante(pathSinExt7); } if (text26 == null) { text26 = CinematicaMultiPistaPlayer.ElegirVariante(pathSinExt8); } if (text26 != null) { list10.Add(text26); ControlDoblajePlugin.Log.LogInfo((object)("[MultiPista] sec=" + personajesDisponible10 + " → " + Path.GetFileName(text26))); } } } if (!flag6 && list10.Count > 0) { string text27 = null; int index = -1; for (int num4 = 0; num4 < list10.Count; num4++) { string name3 = new DirectoryInfo(Path.GetDirectoryName(list10[num4])).Name; if (string.Equals(name3, "Salespersone", StringComparison.OrdinalIgnoreCase)) { text27 = list10[num4]; index = num4; break; } } if (text27 != null) { list10.RemoveAt(index); string name4 = new DirectoryInfo(Path.GetDirectoryName(text27)).Name; key = PromoverDub(text, "Voices/" + name4 + "/" + Path.GetFileName(text27)); ControlDoblajePlugin.Log.LogInfo((object)("[MultiPista] Salespersone promovida (nativo): " + Path.GetFileName(text27))); if ((Object)(object)CinematicaMultiPistaPlayer.RunnerActivo != (Object)null) { CinematicaMultiPistaPlayer.RunnerActivo.Detener(); CinematicaMultiPistaPlayer.RunnerActivo = null; } if (list10.Count > 0) { CinematicaMultiPistaPlayer.ReproducirSecundarias(list10, flag2); if ((Object)(object)CinematicaMultiPistaPlayer.RunnerActivo != (Object)null) { CinematicaMultiPistaPlayer.RunnerActivo.MarcarEsAjena(); } } return; } } key = "_silent_"; if (list10.Count > 0) { CinematicaMultiPistaPlayer.ReproducirSecundarias(list10, flag2); CinematicaMultiPistaPlayer.SilenciarVoicelinesActivos(); CinematicaMultiPistaPlayer.ActivarSilencioVoiceline(); } else { ControlDoblajePlugin.Log.LogWarning((object)("[MultiPista] Sin pistas para key=" + fileNameWithoutExtension4)); } } } } public static class ExtrasVideoDuckingManager { private const float DUCK_FACTOR = 0.15f; private static readonly string[] BUSES = new string[4] { "bus:/Music", "bus:/SFX/Music", "bus:/Ambience", "bus:/SFX/Ambience" }; private static bool _ducked = false; private static readonly Dictionary _volsCapturados = new Dictionary(); public static void Inicio() { //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_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Invalid comparison between Unknown and I4 //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Invalid comparison between Unknown and I4 //IL_00d7: Unknown result type (might be due to invalid IL or missing references) if (_ducked) { return; } _ducked = true; _volsCapturados.Clear(); string[] bUSES = BUSES; System studioSystem; Bus val = default(Bus); foreach (string text in bUSES) { float value = 1f; try { studioSystem = RuntimeManager.StudioSystem; if ((int)((System)(ref studioSystem)).getBus(text, ref val) == 0) { ((Bus)(ref val)).getVolume(ref value); } } catch { } _volsCapturados[text] = value; } string[] bUSES2 = BUSES; Bus val2 = default(Bus); foreach (string text2 in bUSES2) { if (!_volsCapturados.TryGetValue(text2, out var value2)) { value2 = 1f; } try { studioSystem = RuntimeManager.StudioSystem; if ((int)((System)(ref studioSystem)).getBus(text2, ref val2) == 0) { ((Bus)(ref val2)).setVolume(value2 * 0.15f); } } catch { } } ControlDoblajePlugin.Log.LogInfo((object)"[VideoExtras] Ducking música → 15% del nivel del jugador"); } public static void Fin() { //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004c: 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) //IL_0059: Invalid comparison between Unknown and I4 //IL_0065: Unknown result type (might be due to invalid IL or missing references) if (!_ducked) { return; } _ducked = false; string[] bUSES = BUSES; Bus val = default(Bus); foreach (string text in bUSES) { if (!_volsCapturados.TryGetValue(text, out var value)) { value = 1f; } try { System studioSystem = RuntimeManager.StudioSystem; if ((int)((System)(ref studioSystem)).getBus(text, ref val) == 0) { ((Bus)(ref val)).setVolume(value); } } catch { } } _volsCapturados.Clear(); ControlDoblajePlugin.Log.LogInfo((object)"[VideoExtras] Música restaurada al nivel del jugador"); } public static void RestaurarSiNecesario() { if (_ducked) { Fin(); } } } [HarmonyPatch] public class RunVoiceOverPatch { private static float _d1gLastPlayed = -999f; private static MethodBase TargetMethod() { Assembly assembly = null; Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly2 in assemblies) { if (assembly2.GetName().Name == "JoelG.ENA4") { assembly = assembly2; break; } } if (assembly == null) { ControlDoblajePlugin.Log.LogInfo((object)"[RVO_PATCH] JoelG.ENA4 NO encontrado"); return null; } Type type = assembly.GetType("JoelG.ENA4.UI.HUD.Dialogue.HUDDialogue"); if (type == null) { ControlDoblajePlugin.Log.LogInfo((object)"[RVO_PATCH] HUDDialogue tipo NO encontrado"); return null; } MethodInfo method = type.GetMethod("RunVoiceOver", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); ControlDoblajePlugin.Log.LogInfo((object)("[RVO_PATCH] TargetMethod=" + ((method == null) ? "NULL" : (method.DeclaringType?.ToString() + "::" + method.Name)))); return method; } private static bool Prefix(ref string key) { //IL_0189: Unknown result type (might be due to invalid IL or missing references) //IL_018e: Unknown result type (might be due to invalid IL or missing references) //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Invalid comparison between Unknown and I4 //IL_01a8: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: Unknown result type (might be due to invalid IL or missing references) //IL_01d1: Unknown result type (might be due to invalid IL or missing references) //IL_01d7: Invalid comparison between Unknown and I4 //IL_01e4: Unknown result type (might be due to invalid IL or missing references) //IL_01ec: Unknown result type (might be due to invalid IL or missing references) //IL_01ee: Unknown result type (might be due to invalid IL or missing references) //IL_01f3: Unknown result type (might be due to invalid IL or missing references) //IL_01f9: Invalid comparison between Unknown and I4 //IL_0209: Unknown result type (might be due to invalid IL or missing references) ControlDoblajePlugin.Log.LogInfo((object)("[RVO] RunVoiceOver llamado key=" + key)); if (key == null || key.IndexOf("D1G_Ending_05_ENAWillBeReturningIn", StringComparison.OrdinalIgnoreCase) < 0) { return true; } float realtimeSinceStartup = Time.realtimeSinceStartup; if (realtimeSinceStartup - _d1gLastPlayed < 10f) { ControlDoblajePlugin.Log.LogInfo((object)("[D1GEnding_RVO] Dedup – repetición suprimida (key=" + key + ")")); return false; } bool value = false; bool value2 = false; ControlDoblajePlugin.PersonajeActivo.TryGetValue("Froggy", out value); ControlDoblajePlugin.PersonajeActivo.TryGetValue("Dratula", out value2); string text = null; string text2 = null; if (value) { string text3 = Path.Combine(ControlDoblajePlugin.VoicesPath, "Froggy", "D1G_Ending_05_ENAWillBeReturningIn_Froggy.wav"); if (CinematicaMultiPistaPlayer.ExisteWAV(text3)) { text = CinematicaMultiPistaPlayer.ResolverAudio(text3); } } if (value2) { string text4 = Path.Combine(ControlDoblajePlugin.VoicesPath, "Dratula", "D1G_Ending_05_ENAWillBeReturningIn_Dratula.wav"); if (CinematicaMultiPistaPlayer.ExisteWAV(text4)) { text2 = CinematicaMultiPistaPlayer.ResolverAudio(text4); } } string text5 = text ?? text2; if (text5 == null) { ControlDoblajePlugin.Log.LogInfo((object)"[D1GEnding_RVO] Sin archivos doblados → original"); return true; } _d1gLastPlayed = realtimeSinceStartup; key = text5; PlayVoiceoverPatch.UltimoDoblajeEsNuestro = true; ControlDoblajePlugin.Log.LogInfo((object)("[D1GEnding_RVO] Primary → " + Path.GetFileName(text5))); string text6 = ((text != null && text2 != null) ? text2 : null); if (text6 != null) { try { System studioSystem = RuntimeManager.StudioSystem; System sys = default(System); if ((int)((System)(ref studioSystem)).getCoreSystem(ref sys) == 0) { CREATESOUNDEXINFO ex = new CREATESOUNDEXINFO { cbsize = Marshal.SizeOf(typeof(CREATESOUNDEXINFO)) }; if ((int)AudioPack.CrearSound(sys, text6, (MODE)264, ref ex, out var sound) == 0) { ChannelGroup val = default(ChannelGroup); ((System)(ref sys)).getMasterChannelGroup(ref val); Channel val2 = default(Channel); if ((int)((System)(ref sys)).playSound(sound, val, false, ref val2) == 0) { ((Channel)(ref val2)).setVolume(0.75f); ControlDoblajePlugin.Log.LogInfo((object)("[D1GEnding_RVO] Secundario → " + Path.GetFileName(text6))); } } } } catch (Exception ex2) { ControlDoblajePlugin.Log.LogInfo((object)("[D1GEnding_RVO] Sec error: " + ex2.Message)); } } return true; } } public static class PhoneCallPatcher { private static bool _instalado; public static void TryInstalar(Harmony harmony) { if (_instalado) { return; } _instalado = true; Assembly assembly = null; Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly2 in assemblies) { if (assembly2.GetName().Name == "JoelG.ENA4") { assembly = assembly2; break; } } if (assembly == null) { ControlDoblajePlugin.Log.LogWarning((object)"[PhoneCall] No se encontro JoelG.ENA4"); return; } int num = 0; Type[] types = assembly.GetTypes(); foreach (Type type in types) { string text = type.FullName ?? ""; if (text.IndexOf("Phone", StringComparison.OrdinalIgnoreCase) < 0 && text.IndexOf("Call", StringComparison.OrdinalIgnoreCase) < 0 && text.IndexOf("Froggy", StringComparison.OrdinalIgnoreCase) < 0 && text.IndexOf("Voiceline", StringComparison.OrdinalIgnoreCase) < 0 && text.IndexOf("Dialogue", StringComparison.OrdinalIgnoreCase) < 0) { continue; } MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); foreach (MethodInfo methodInfo in methods) { ParameterInfo[] parameters = methodInfo.GetParameters(); if (parameters.Length >= 1 && parameters[0].ParameterType == typeof(string)) { num++; } } } ControlDoblajePlugin.Log.LogInfo((object)("[PhoneCall] Candidatos encontrados: " + num + " (stop via FMODDirectStartPatch)")); } } [HarmonyPatch] public static class HUDDialogue_DialogueComplete_StopAjena { private static MethodBase TargetMethod() { Assembly assembly = null; Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly2 in assemblies) { if (assembly2.GetName().Name == "JoelG.ENA4") { assembly = assembly2; break; } } return (assembly?.GetType("JoelG.ENA4.UI.HUD.Dialogue.HUDDialogue"))?.GetMethod("DialogueComplete", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); } private static void Postfix() { try { MultiPistaRunner runnerActivo = CinematicaMultiPistaPlayer.RunnerActivo; if ((Object)(object)runnerActivo != (Object)null && runnerActivo.EsAjena) { runnerActivo.Detener(); CinematicaMultiPistaPlayer.RunnerActivo = null; ControlDoblajePlugin.Log.LogInfo((object)"[Dialogo] DialogueComplete → runner ENA (ajena) detenido"); } } catch { } } } public static class TurronishPaths { public static string SoundsPath => Path.Combine(ControlDoblajePlugin.AssetsRoot, "TurronishSounds"); } public static class TurronishBankLoader { private static bool _loaded; private static readonly Dictionary _eventMap = new Dictionary(StringComparer.OrdinalIgnoreCase); private static readonly List _banks = new List(); public static bool BanksDisponibles => _eventMap.Count > 0; public static bool HasEvent(string filename) { return _eventMap.ContainsKey(filename); } public static string GetEventPath(string filename) { string value; return _eventMap.TryGetValue(filename, out value) ? value : null; } public static HashSet ObtenerPersonajesDeBank() { HashSet hashSet = new HashSet(StringComparer.OrdinalIgnoreCase); foreach (KeyValuePair item in _eventMap) { string value = item.Value; if (value.StartsWith("event:/Turronish/", StringComparison.OrdinalIgnoreCase)) { string text = value.Substring("event:/Turronish/".Length); int num = text.IndexOf('/'); if (num > 0) { hashSet.Add(text.Substring(0, num)); } } } if (hashSet.Count > 0) { return hashSet; } if (CinematicaMultiPistaPlayer.BanksDisponibles) { Dictionary nombresUI = ControlDoblajePlugin.NombresUI; if (nombresUI != null && nombresUI.Count > 0) { foreach (KeyValuePair item2 in nombresUI) { hashSet.Add(item2.Key); } ControlDoblajePlugin.Log.LogInfo((object)$"[Banks] {hashSet.Count} personajes desde personajes_config"); } } return hashSet; } public static void LoadIfNeeded() { _loaded = true; } public static bool PlayEvent(string filename) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Invalid comparison between Unknown and I4 //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Invalid comparison between Unknown and I4 //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) string eventPath = GetEventPath(filename); if (eventPath == null) { return false; } System studioSystem = RuntimeManager.StudioSystem; EventDescription val = default(EventDescription); if ((int)((System)(ref studioSystem)).getEvent(eventPath, ref val) > 0) { return false; } EventInstance val2 = default(EventInstance); if ((int)((EventDescription)(ref val)).createInstance(ref val2) > 0) { return false; } ((EventInstance)(ref val2)).start(); ChannelGroup val3 = default(ChannelGroup); if ((int)((EventInstance)(ref val2)).getChannelGroup(ref val3) == 0 && ((ChannelGroup)(ref val3)).hasHandle()) { System coreSystem = RuntimeManager.CoreSystem; ChannelGroup val4 = default(ChannelGroup); ((System)(ref coreSystem)).getMasterChannelGroup(ref val4); if (((ChannelGroup)(ref val4)).hasHandle()) { ((ChannelGroup)(ref val4)).addGroup(val3, true); } } ((EventInstance)(ref val2)).release(); ControlDoblajePlugin.Log.LogInfo((object)("[Banks] ▶ " + filename)); return true; } public static List GetEventNames(string pathContains) { List list = new List(); foreach (KeyValuePair item in _eventMap) { if (item.Value.IndexOf(pathContains, StringComparison.OrdinalIgnoreCase) >= 0) { list.Add(item.Key); } } return list; } } public static class TurronishSoundPlayer { private static readonly Random _rng = new Random(); private static readonly Queue _recientes = new Queue(); private const int COLA_NOREPETIR = 15; public static void PlayRandom() { TurronishBankLoader.LoadIfNeeded(); if (TurronishBankLoader.BanksDisponibles) { List eventNames = TurronishBankLoader.GetEventNames("TurronishSFX"); if (eventNames.Count > 0) { List list = eventNames; if (eventNames.Count > 15) { list = new List(); foreach (string item in eventNames) { if (!_recientes.Contains(item)) { list.Add(item); } } if (list.Count == 0) { list = eventNames; } } string text = list[_rng.Next(list.Count)]; _recientes.Enqueue(text); while (_recientes.Count > 15) { _recientes.Dequeue(); } ControlDoblajePlugin.Log.LogInfo((object)$"[Turronish] Bank SFX: {text} (pool={list.Count}/{eventNames.Count})"); TurronishBankLoader.PlayEvent(text); return; } } string soundsPath = TurronishPaths.SoundsPath; List list2 = AssetPack.Listar(soundsPath, new string[2] { ".wav", ".ogg" }, false); string[] array = list2.ToArray(); if (array.Length == 0) { ControlDoblajePlugin.Log.LogWarning((object)"[Turronish] No hay .wav/.ogg en TurronishSounds/"); return; } string[] array2 = array; if (array.Length > 15) { string[] array3 = Array.FindAll(array, (string w) => !_recientes.Contains(Path.GetFileName(w))); if (array3.Length != 0) { array2 = array3; } } string text2 = array2[_rng.Next(array2.Length)]; string fileName = Path.GetFileName(text2); _recientes.Enqueue(fileName); while (_recientes.Count > 15) { _recientes.Dequeue(); } ControlDoblajePlugin.Log.LogInfo((object)$"[Turronish] Reproduciendo: {fileName} (pool={array2.Length}/{array.Length})"); PlayWav(text2); } private static void PlayWav(string ruta) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Invalid comparison between Unknown and I4 //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Invalid comparison between Unknown and I4 //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Invalid comparison between Unknown and I4 //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_011e: 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_01af: Unknown result type (might be due to invalid IL or missing references) //IL_01b6: Expected O, but got Unknown //IL_01bd: Unknown result type (might be due to invalid IL or missing references) //IL_01be: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Unknown result type (might be due to invalid IL or missing references) try { CREATESOUNDEXINFO ex = default(CREATESOUNDEXINFO); ex.cbsize = Marshal.SizeOf(ex); RESULT val = AudioPack.CrearSound(RuntimeManager.CoreSystem, ruta, (MODE)9, ref ex, out var sound); if ((int)val > 0) { ControlDoblajePlugin.Log.LogWarning((object)$"[Turronish] createSound: {val}"); return; } ChannelGroup val2 = default(ChannelGroup); string[] array = new string[5] { "bus:/Voice", "bus:/Voices", "bus:/Characters", "bus:/SFX", "bus:/" }; Bus val3 = default(Bus); foreach (string text in array) { System studioSystem = RuntimeManager.StudioSystem; if ((int)((System)(ref studioSystem)).getBus(text, ref val3) == 0 && (int)((Bus)(ref val3)).getChannelGroup(ref val2) == 0) { break; } } System coreSystem; if (!((ChannelGroup)(ref val2)).hasHandle()) { coreSystem = RuntimeManager.CoreSystem; ((System)(ref coreSystem)).getMasterChannelGroup(ref val2); } coreSystem = RuntimeManager.CoreSystem; Channel c = default(Channel); val = ((System)(ref coreSystem)).playSound(sound, val2, true, ref c); if ((int)val > 0) { ControlDoblajePlugin.Log.LogWarning((object)$"[Turronish] playSound: {val}"); ((Sound)(ref sound)).release(); return; } ((Channel)(ref c)).setVolume(1f); ((Channel)(ref c)).setPaused(false); float num = -1f; ((Channel)(ref c)).getVolume(ref num); float num2 = -1f; if (((ChannelGroup)(ref val2)).hasHandle()) { ((ChannelGroup)(ref val2)).getVolume(ref num2); } ControlDoblajePlugin.Log.LogInfo((object)$"[VOL] SoundPlayer ch={num:F2} grupo={num2:F2} archivo={Path.GetFileName(ruta)}"); GameObject val4 = new GameObject("_TurronishSound"); val4.AddComponent().Init(sound, c); } catch (Exception ex2) { ControlDoblajePlugin.Log.LogError((object)("[Turronish] Error: " + ex2.Message)); } } } public class TurronishSoundRunner : MonoBehaviour { private static float _ultimoDisparo = -999f; private const float COOLDOWN = 0.05f; private Sound _sound; private Channel _channel; private float _duracion = -1f; private float _inicio; public static bool EstaReproduciendo() { return Time.realtimeSinceStartup - _ultimoDisparo < 0.05f; } public void Init(Sound s, Channel c) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) _ultimoDisparo = Time.realtimeSinceStartup; _sound = s; _channel = c; _inicio = Time.realtimeSinceStartup; uint num = 0u; if ((int)((Sound)(ref s)).getLength(ref num, (TIMEUNIT)1) == 0 && num != 0) { _duracion = (float)num / 1000f; } } private void Update() { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) bool flag = false; ((Channel)(ref _channel)).isPlaying(ref flag); bool flag2 = _duracion > 0f && Time.realtimeSinceStartup - _inicio > _duracion + 0.5f; if (!flag || flag2) { ((Sound)(ref _sound)).release(); Object.Destroy((Object)(object)((Component)this).gameObject); } } }