using System; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Logging; using FMOD; using FMODUnity; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyCompany("NowWatchThisDrive")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+e5329b55840de19d8cac5cc7a97dda62e4ca2382")] [assembly: AssemblyProduct("NowWatchThisDrive")] [assembly: AssemblyTitle("NowWatchThisDrive")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace NowWatchThisDrive { [BepInPlugin("sbg.nowwatchthisdrive", "NowWatchThisDrive", "0.4.1")] public class Plugin : BaseUnityPlugin { [HarmonyPatch(typeof(CourseManager), "PlayAnnouncerLineLocalOnly")] internal static class Patch_CourseManager_PlayAnnouncerLineLocalOnly { private static bool Prefix(AnnouncerLine line) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Invalid comparison between Unknown and I4 if ((int)line != 12) { return true; } ManualLogSource log = Log; if (log != null) { log.LogInfo((object)$"NiceShot intercept fired (soundReady={_soundReady})."); } if (!_soundReady) { return true; } PlayLocal2D(); return false; } } [HarmonyPatch(typeof(VfxManager), "PlayPooledVfxLocalOnlyInternal", new Type[] { typeof(VfxType), typeof(Vector3), typeof(Quaternion), typeof(Vector3), typeof(uint), typeof(bool), typeof(float), typeof(Action) })] internal static class Patch_VfxManager_PlayPooledVfxLocalOnlyInternal { private static void Prefix(VfxType vfxType, Vector3 position) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Invalid comparison between Unknown and I4 //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0024: 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_0048: 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_0057: Unknown result type (might be due to invalid IL or missing references) if ((int)vfxType == 69 && _soundReady) { bool flag = IsLocalPlayerSwingPosition(position); ManualLogSource log = Log; if (log != null) { log.LogInfo((object)string.Format("SwingNiceShot VFX at {0}, treated as {1}.", position, flag ? "local (skip 3D)" : "remote (play 3D)")); } if (!flag) { PlayRemote3D(position + Vector3.up * 0.9f); } } } } public const string ModGuid = "sbg.nowwatchthisdrive"; public const string ModName = "NowWatchThisDrive"; public const string ModVersion = "0.4.1"; private const string AudioFileName = "NowWatchThisDrive.wav"; private const float Audio3DMinDistance = 8f; private const float Audio3DMaxDistance = 60f; private const float AudioHeightOffset = 0.9f; private const float LocalSwingProximitySquared = 36f; private const float DuplicateWindowSeconds = 0.25f; private const float DuplicateDistanceSquared = 0.25f; internal static ManualLogSource Log; private static Sound _sound2D; private static Sound _sound3D; private static bool _soundReady; private static float _last3DPlayTime; private static Vector3 _last3DPlayPosition; private void Awake() { //IL_0010: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; new Harmony("sbg.nowwatchthisdrive").PatchAll(); Log.LogInfo((object)"NowWatchThisDrive v0.4.1 loaded (sound loads in Start)."); } private void Start() { //IL_003d: 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_0050: 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_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0085: 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_008b: 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_00b9: 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_0098: Unknown result type (might be due to invalid IL or missing references) try { string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "NowWatchThisDrive.wav"); if (!File.Exists(text)) { Log.LogError((object)("Audio file missing: " + text)); return; } System coreSystem = RuntimeManager.CoreSystem; RESULT val = ((System)(ref coreSystem)).createSound(text, (MODE)256, ref _sound2D); if ((int)val != 0) { Log.LogError((object)$"FMOD createSound (2D) failed: {val}"); return; } RESULT val2 = ((System)(ref coreSystem)).createSound(text, (MODE)2097424, ref _sound3D); if ((int)val2 != 0) { Log.LogError((object)$"FMOD createSound (3D) failed: {val2}"); return; } ((Sound)(ref _sound3D)).set3DMinMaxDistance(8f, 60f); uint num = default(uint); ((Sound)(ref _sound2D)).getLength(ref num, (TIMEUNIT)1); _soundReady = true; Log.LogInfo((object)$"FMOD sounds loaded ({num} ms): {text}"); } catch (Exception arg) { Log.LogError((object)$"Start failed: {arg}"); } } private unsafe static void PlayLocal2D() { //IL_0032: 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_003b: 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_0048: 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) //IL_0052: 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_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) if (!_soundReady) { return; } ManualLogSource log = Log; if (log != null) { log.LogInfo((object)$"PlayLocal2D: entering, sound2D.hasHandle={((Sound)(ref _sound2D)).hasHandle()}"); } try { System coreSystem = RuntimeManager.CoreSystem; Channel val2 = default(Channel); RESULT val = ((System)(ref coreSystem)).playSound(_sound2D, default(ChannelGroup), false, ref val2); if ((int)val != 0) { ManualLogSource log2 = Log; if (log2 != null) { log2.LogWarning((object)$"playSound 2D: {val}"); } return; } bool flag = ((Channel)(ref val2)).hasHandle(); string arg = "n/a"; if (flag) { float num = default(float); RESULT volume = ((Channel)(ref val2)).getVolume(ref num); arg = (((int)volume == 0) ? num.ToString("0.###") : ((object)(*(RESULT*)(&volume))/*cast due to .constrained prefix*/).ToString()); } ManualLogSource log3 = Log; if (log3 != null) { log3.LogInfo((object)$"PlayLocal2D: playSound OK, channel.hasHandle={flag}, volume={arg}"); } } catch (Exception arg2) { ManualLogSource log4 = Log; if (log4 != null) { log4.LogError((object)$"PlayLocal2D failed: {arg2}"); } } } private static void PlayRemote3D(Vector3 worldPosition) { //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_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: 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_003e: 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_004b: 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_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0056: 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_0094: 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_009b: 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) //IL_00a2: 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_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: 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_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: 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) if (!_soundReady) { return; } if (Time.unscaledTime - _last3DPlayTime < 0.25f) { Vector3 val = worldPosition - _last3DPlayPosition; if (((Vector3)(ref val)).sqrMagnitude < 0.25f) { return; } } try { System coreSystem = RuntimeManager.CoreSystem; Channel val3 = default(Channel); RESULT val2 = ((System)(ref coreSystem)).playSound(_sound3D, default(ChannelGroup), true, ref val3); if ((int)val2 != 0) { ManualLogSource log = Log; if (log != null) { log.LogWarning((object)$"playSound 3D: {val2}"); } return; } ((Channel)(ref val3)).setMode((MODE)2097168); ((Channel)(ref val3)).set3DMinMaxDistance(8f, 60f); VECTOR val4 = RuntimeUtils.ToFMODVector(worldPosition); VECTOR val5 = RuntimeUtils.ToFMODVector(Vector3.zero); ((Channel)(ref val3)).set3DAttributes(ref val4, ref val5); ((Channel)(ref val3)).setPaused(false); _last3DPlayTime = Time.unscaledTime; _last3DPlayPosition = worldPosition; } catch (Exception arg) { ManualLogSource log2 = Log; if (log2 != null) { log2.LogError((object)$"PlayRemote3D failed: {arg}"); } } } private static bool IsLocalPlayerSwingPosition(Vector3 position) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //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) PlayerGolfer localPlayerAsGolfer = GameManager.LocalPlayerAsGolfer; if ((Object)(object)localPlayerAsGolfer == (Object)null) { return false; } Vector3 val = ((Component)localPlayerAsGolfer).transform.position - position; return ((Vector3)(ref val)).sqrMagnitude <= 36f; } } }