using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Logging; using GameNetcodeStuff; using GuodaLight.Utils; using HarmonyLib; using LethalCompanyInputUtils.Api; using Microsoft.CodeAnalysis; using Unity.Netcode; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.Rendering; using UnityEngine.Rendering.HighDefinition; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("Tomatobird.GuodaLight")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("0.2.1.0")] [assembly: AssemblyInformationalVersion("0.2.1+509a4f1a00fb9d1eae15dc44469425ccae39fba3")] [assembly: AssemblyProduct("GuodaLight")] [assembly: AssemblyTitle("Tomatobird.GuodaLight")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.2.1.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } [HarmonyPatch(typeof(NetworkManager))] internal static class RegisterNetworkPrefabPatch { private static readonly string MOD_GUID = "Tomatobird.GuodaLight"; [HarmonyPatch("SetSingleton")] [HarmonyPostfix] private static void RegisterPrefab() { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown //IL_0018: 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) GameObject val = new GameObject(MOD_GUID + " Prefab"); ((Object)val).hideFlags = (HideFlags)(((Object)val).hideFlags | 0x3D); Object.DontDestroyOnLoad((Object)(object)val); NetworkObject obj = val.AddComponent(); FieldInfo field = typeof(NetworkObject).GetField("GlobalObjectIdHash", BindingFlags.Instance | BindingFlags.NonPublic); field.SetValue(obj, GetHash(MOD_GUID)); NetworkManager.Singleton.PrefabHandler.AddNetworkPrefab(val); static uint GetHash(string value) { return value?.Aggregate(17u, (uint current, char c) => (current * 31) ^ c) ?? 0; } } } namespace GuodaLight { [BepInPlugin("Tomatobird.GuodaLight", "GuodaLight", "0.2.1")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class GuodaLight : BaseUnityPlugin { internal static LightKey InputActionInstance = new LightKey(); public static float lightIntensity = 486.8536f; public static float lightRange = 55f; public static float lightColorTemperature = 8371f; public static bool lightOnByDefault = true; public static bool silentLight = false; public static float clickVolume = 0.5f; public static GuodaLight Instance { get; private set; } = null; internal static ManualLogSource Logger { get; private set; } = null; internal static Harmony? Harmony { get; set; } private void Awake() { Logger = ((BaseUnityPlugin)this).Logger; Instance = this; lightIntensity = ((BaseUnityPlugin)this).Config.Bind("General", "LightIntensity", 486.8536f, "Intensity of the light").Value; lightRange = ((BaseUnityPlugin)this).Config.Bind("General", "LightRange", 55f, "Light reach distance").Value; lightColorTemperature = ((BaseUnityPlugin)this).Config.Bind("General", "lightColorTemperature", 8371f, "Color temperature of the light").Value; lightOnByDefault = ((BaseUnityPlugin)this).Config.Bind("General", "lightOnByDefault", true, "Should the light default to being on when player joins?").Value; silentLight = ((BaseUnityPlugin)this).Config.Bind("General", "SilentLight", false, "Should toggling the light be silent?").Value; clickVolume = ((BaseUnityPlugin)this).Config.Bind("General", "ClickVolume", 0.5f, "Audio volume of the flashlight toggle click.").Value; Patch(); Logger.LogInfo((object)"Tomatobird.GuodaLight v0.2.1 has loaded!"); } internal static void Patch() { //IL_000d: 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: Expected O, but got Unknown if (Harmony == null) { Harmony = new Harmony("Tomatobird.GuodaLight"); } Logger.LogDebug((object)"Patching..."); Harmony.PatchAll(); Logger.LogDebug((object)"Finished patching!"); } internal static void Unpatch() { Logger.LogDebug((object)"Unpatching..."); Harmony? harmony = Harmony; if (harmony != null) { harmony.UnpatchSelf(); } Logger.LogDebug((object)"Finished unpatching!"); } } public class LightKey : LcInputActions { [InputAction(/*Could not decode attribute arguments.*/)] public InputAction? LightButton { get; set; } } public static class MyPluginInfo { public const string PLUGIN_GUID = "Tomatobird.GuodaLight"; public const string PLUGIN_NAME = "GuodaLight"; public const string PLUGIN_VERSION = "0.2.1"; } } namespace GuodaLight.Utils { internal class FlashKeyPressListener : MonoBehaviour { [CompilerGenerated] private sealed class d__5 : IEnumerator, IEnumerator, IDisposable { private int <>1__state; private object <>2__current; public FlashKeyPressListener <>4__this; private int 5__1; private float 5__2; private float 5__3; private bool 5__4; private Texture 5__5; object? IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object? IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__5(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { 5__5 = null; <>1__state = -2; } private bool MoveNext() { //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Expected O, but got Unknown //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Expected O, but got Unknown //IL_02bf: Unknown result type (might be due to invalid IL or missing references) //IL_02c9: Expected O, but got Unknown switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>2__current = (object)new WaitForEndOfFrame(); <>1__state = 1; return true; case 1: <>1__state = -1; 5__1 = 0; 5__2 = 1f; 5__3 = 0.2f; 5__4 = false; goto IL_029f; case 2: <>1__state = -1; goto IL_00aa; case 3: { <>1__state = -1; GuodaLight.Logger.LogDebug((object)$"All components were found: {5__4}. Iterations: {5__1}"); return false; } IL_029f: if (5__1 < 10 && !5__4) { goto IL_00aa; } <>2__current = (object)new WaitForEndOfFrame(); <>1__state = 3; return true; IL_00aa: if (5__3 > 0f) { 5__3 -= Time.deltaTime; <>2__current = (object)new WaitForEndOfFrame(); <>1__state = 2; return true; } 5__3 = 5__2; if ((Object)(object)<>4__this.light == (Object)null) { <>4__this.light = ((Component)<>4__this).GetComponent(); if ((Object)(object)<>4__this.light != (Object)null) { GuodaLight.Logger.LogDebug((object)"Got component light"); 5__5 = StartOfRound.Instance.allPlayerScripts[0].allHelmetLights[0].cookie; <>4__this.light.cookie = 5__5; 5__5 = null; } } if ((Object)(object)<>4__this.audio == (Object)null) { <>4__this.audio = ((Component)<>4__this).GetComponent(); if ((Object)(object)<>4__this.audio != (Object)null) { GuodaLight.Logger.LogDebug((object)"Got component audio"); } } if ((Object)(object)<>4__this.lightdata == (Object)null) { <>4__this.lightdata = ((Component)<>4__this).GetComponent(); if ((Object)(object)<>4__this.lightdata != (Object)null) { GuodaLight.Logger.LogDebug((object)"Got component lightdata"); <>4__this.lightdata.fadeDistance = 1000f; <>4__this.lightdata.shadowFadeDistance = 1000f; <>4__this.lightdata.shadowNearPlane = 0.66f; } } 5__4 = (Object)(object)<>4__this.light != (Object)null && (Object)(object)<>4__this.audio != (Object)null && (Object)(object)<>4__this.lightdata != (Object)null; 5__1++; goto IL_029f; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } internal List? flashlightClips; private Light? light; private AudioSource? audio; private HDAdditionalLightData? lightdata; public void Awake() { if (GuodaLight.InputActionInstance.LightButton != null) { GuodaLight.InputActionInstance.LightButton.performed += OnActionPerformed; light = ((Component)this).GetComponent(); if ((Object)(object)light != (Object)null) { Texture cookie = StartOfRound.Instance.allPlayerScripts[0].allHelmetLights[0].cookie; light.cookie = cookie; } ((MonoBehaviour)this).StartCoroutine(WaitForComponents()); } } [IteratorStateMachine(typeof(d__5))] private IEnumerator WaitForComponents() { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__5(0) { <>4__this = this }; } public void OnActionPerformed(CallbackContext context) { if (!((Object)(object)light == (Object)null) && Application.isFocused && !((Object)(object)GameNetworkManager.Instance?.localPlayerController == (Object)null) && !GameNetworkManager.Instance.localPlayerController.isPlayerDead && !GameNetworkManager.Instance.localPlayerController.isTypingChat && !GameNetworkManager.Instance.localPlayerController.inTerminalMenu && !GameNetworkManager.Instance.localPlayerController.quickMenuManager.isMenuOpen) { ((Behaviour)light).enabled = !((Behaviour)light).enabled; if (!((Object)(object)audio == (Object)null) && flashlightClips != null) { audio.PlayOneShot(((Behaviour)light).enabled ? flashlightClips[0] : flashlightClips[1]); } } } } } namespace GuodaLight.Patches { [HarmonyPatch(typeof(PlayerControllerB))] public class AddLightObject { [HarmonyPatch("ConnectClientToPlayerObject")] [HarmonyPostfix] public static void AddLightObjectPatch(PlayerControllerB __instance) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Expected O, but got Unknown //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_017e: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject { name = "GuodaLight" }; Light val2 = val.AddComponent(); ((Behaviour)val2).enabled = GuodaLight.lightOnByDefault; val2.boundingSphereOverride = new Vector4(0f, 0f, 0f, 0f); val2.bounceIntensity = 0f; val2.colorTemperature = GuodaLight.lightColorTemperature; val2.cookieSize = 10f; val2.cullingMask = -1; val2.innerSpotAngle = 21.8021f; val2.intensity = GuodaLight.lightIntensity; val2.lightShadowCasterMode = (LightShadowCasterMode)2; val2.range = GuodaLight.lightRange; val2.renderingLayerMask = 1; val2.shadowBias = 0.05f; val2.shadowNearPlane = 0.2f; val2.shadowNormalBias = 0.4f; val2.shadowResolution = (LightShadowResolution)(-1); val2.shadows = (LightShadows)1; val2.shadowStrength = 1f; val2.shape = (LightShape)0; val2.spotAngle = 73f; val2.type = (LightType)0; val2.useBoundingSphereOverride = false; val2.useColorTemperature = true; val2.useShadowMatrixOverride = false; val2.useViewFrustumForShadowCasterCull = true; val.transform.SetParent(((Component)__instance.gameplayCamera).transform); val.transform.localScale = new Vector3(0.3627f, 0.4234f, 0.4918f); val.transform.SetPositionAndRotation(((Component)__instance.allHelmetLights[0]).transform.position, ((Component)__instance.allHelmetLights[0]).transform.rotation); FlashKeyPressListener flashKeyPressListener = val.AddComponent(); if (GuodaLight.silentLight) { return; } AudioSource val3 = val.AddComponent(); val3.dopplerLevel = 0.3f; val3.maxDistance = 18f; val3.minDistance = 4f; val3.playOnAwake = false; val3.loop = false; val3.rolloffMode = (AudioRolloffMode)1; val3.volume = GuodaLight.clickVolume; val3.priority = 128; val3.spread = 71f; val3.spatialBlend = 1f; val3.outputAudioMixerGroup = SoundManager.Instance.ambienceAudio.outputAudioMixerGroup; Item[] buyableItemsList = HUDManager.Instance.terminalScript.buyableItemsList; foreach (Item val4 in buyableItemsList) { if (((Object)val4).name == "ProFlashlight") { flashKeyPressListener.flashlightClips = val4.spawnPrefab.GetComponent().flashlightClips.ToList(); break; } } } } }