using System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using FlashlightToolLoader.Patches; using GameNetcodeStuff; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; using huluobolightutility; [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("Sniper1_1.FlashlightToolLoader")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.4.0")] [assembly: AssemblyInformationalVersion("1.0.4+d8a51bc5ceb97b2df290d0d35083c01aadb989ab")] [assembly: AssemblyProduct("FlashlightToolLoader")] [assembly: AssemblyTitle("Sniper1_1.FlashlightToolLoader")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.4.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; } } } namespace FlashlightToolLoader { [BepInPlugin("Sniper1_1.FlashlightToolLoader", "FlashlightToolLoader", "1.0.4")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class FlashlightToolLoader : BaseUnityPlugin { public static Vector3 vanillaLightPos = new Vector3(0.20699994f, -0.5260004f, 0.47500026f); public static Quaternion vanillaLightRot = new Quaternion(0f, -0.020865021f, 0f, 0.9997824f); public static FlashlightToolLoader Instance { get; private set; } = null; internal static ManualLogSource Logger { get; private set; } = null; internal static Harmony? Harmony { get; set; } internal static FlashlightToolLoaderConfig BoundConfig { get; private set; } = null; private void Awake() { Logger = ((BaseUnityPlugin)this).Logger; Instance = this; BoundConfig = new FlashlightToolLoaderConfig(((BaseUnityPlugin)this).Config); Patch(); Logger.LogInfo((object)"Sniper1_1.FlashlightToolLoader v1.0.4 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("Sniper1_1.FlashlightToolLoader"); } Logger.LogDebug((object)"Patching..."); Harmony.PatchAll(typeof(StartOfRoundPatch)); try { Harmony.PatchAll(typeof(BlockLightUtilityPatch)); } catch { Logger.LogWarning((object)"Did not find Lightutility. Skipping compat patch."); } 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!"); } } internal class FlashlightToolLoaderConfig { public readonly ConfigEntry Blacklist; public FlashlightToolLoaderConfig(ConfigFile config) { Blacklist = config.Bind("FlashlightToolLoader", "Blacklist", "Flashlight,ProFlashlight,FlashLaserPointer", "List of flashlights to ignore (Do not remove vanilla lights). Separated by commas, no spaces. Example: ItemName1,ItemName2,ItemName3"); } } public static class MyPluginInfo { public const string PLUGIN_GUID = "Sniper1_1.FlashlightToolLoader"; public const string PLUGIN_NAME = "FlashlightToolLoader"; public const string PLUGIN_VERSION = "1.0.4"; } } namespace FlashlightToolLoader.Patches { [HarmonyPatch(typeof(StartOfRound))] public class StartOfRoundPatch { [HarmonyPostfix] [HarmonyPatch("Start")] public static void AfterStartOfRound() { FlashlightToolLoader.Logger.LogDebug((object)"StartOfRound.Start postfix: Initializing helmet lights for all players."); PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts; foreach (PlayerControllerB _instance in allPlayerScripts) { HelmetLightPatch.InitiateHelmetLights(_instance); } HelmetLightPatch.FixShipItems(); } } public class HelmetLightPatch { public static Dictionary LightToID = new Dictionary(); public static void InitiateHelmetLights(PlayerControllerB __instance) { //IL_014f: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Unknown result type (might be due to invalid IL or missing references) FlashlightToolLoader.Logger.LogDebug((object)("InitiateHelmetLight called on player: " + (object)__instance)); List validItems = GetValidItems(); foreach (Item item in validItems) { FlashlightToolLoader.Logger.LogDebug((object)("Flashlight to be made: " + ((Object)item).name)); } int num = __instance.allHelmetLights.Length; FlashlightToolLoader.Logger.LogDebug((object)("Vanilla Helmet Light Count: " + num)); List list = new List(); LightToID.Clear(); for (int i = 0; i < validItems.Count; i++) { Light val = CreateLight(validItems[i]); if ((Object)(object)val != (Object)null) { validItems[i].spawnPrefab.GetComponent().flashlightTypeID = list.Count + num; FlashlightToolLoader.Logger.LogDebug((object)("Flashlight Type ID: " + validItems[i].spawnPrefab.GetComponent().flashlightTypeID)); try { ((Component)val).transform.SetParent(((Component)((Component)__instance.helmetLight).transform.parent).transform, false); ((Component)val).transform.localPosition = FlashlightToolLoader.vanillaLightPos; ((Component)val).transform.localRotation = FlashlightToolLoader.vanillaLightRot; FlashlightToolLoader.Logger.LogDebug((object)("Set parent of light: " + ((Object)val).name + " to: " + ((Object)((Component)__instance.helmetLight).transform.parent).name)); } catch (Exception ex) { FlashlightToolLoader.Logger.LogError((object)("Failed to set parent of light: " + ex.Message)); } LightToID[validItems[i].spawnPrefab] = list.Count + num; FlashlightToolLoader.Logger.LogDebug((object)("Added light: " + ((Object)val).name + " to dictionary with ID: " + validItems[i].spawnPrefab.GetComponent().flashlightTypeID)); list.Add(val); } else { FlashlightToolLoader.Logger.LogWarning((object)("Light for flashlight: " + ((Object)validItems[i]).name + " was not created successfully and will be skipped.")); } } __instance.allHelmetLights = CollectionExtensions.AddRangeToArray(__instance.allHelmetLights, list.ToArray()); FlashlightToolLoader.Logger.LogDebug((object)("New allHelmetLights array size: " + __instance.allHelmetLights.Length)); for (int j = 0; j < __instance.allHelmetLights.Length; j++) { FlashlightToolLoader.Logger.LogDebug((object)("allHelmetLights[" + j + "]: " + ((Object)__instance.allHelmetLights[j]).name)); } } public static List GetValidItems() { List list = new List(FlashlightToolLoader.BoundConfig.Blacklist.Value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries)); List list2 = new List(); foreach (Item items in StartOfRound.Instance.allItemsList.itemsList) { FlashlightToolLoader.Logger.LogDebug((object)("Item: " + ((Object)items).name)); if (IsFlashlight(items) && !list.Contains(((Object)items).name)) { list2.Add(items); } } return list2; } public static bool IsFlashlight(Item item) { try { if ((Object)(object)item.spawnPrefab.GetComponent() != (Object)null) { FlashlightToolLoader.Logger.LogDebug((object)("Item is a flashlight: " + ((Object)item).name)); return true; } return false; } catch { FlashlightToolLoader.Logger.LogError((object)"Error checking if item is flashlight. It may be missing a prefab. If you are the dev, please fix! Otherwise, safe to ignore this."); return false; } } public static Light CreateLight(Item item) { Transform val = null; Transform[] componentsInChildren = item.spawnPrefab.GetComponentsInChildren(true); foreach (Transform val2 in componentsInChildren) { if (string.Equals(((Object)val2).name, "Light", StringComparison.OrdinalIgnoreCase)) { val = val2; break; } } if ((Object)(object)val != (Object)null) { GameObject val3 = Object.Instantiate(((Component)val).gameObject); Light component = val3.GetComponent(); ((Object)component).name = ((Object)item.spawnPrefab).name + " Light"; FlashlightToolLoader.Logger.LogDebug((object)("Instantiated Light: " + ((Object)val3).name + " of item: " + ((Object)item).name)); return component; } FlashlightToolLoader.Logger.LogDebug((object)("No Light found on item: " + ((Object)item).name)); return null; } public static void FixShipItems() { List list = new List(Object.FindObjectsOfType()); FlashlightToolLoader.Logger.LogDebug((object)("GrabbableObjects found: " + list.Count)); foreach (GrabbableObject item in list) { FlashlightToolLoader.Logger.LogDebug((object)("Item in ship: " + ((Object)item).name)); if ((Object)(object)((Component)item).GetComponent() != (Object)null && LightToID.TryGetValue(item.itemProperties.spawnPrefab, out var value)) { ((Component)item).GetComponent().flashlightTypeID = value; FlashlightToolLoader.Logger.LogDebug((object)$"Updated flashlightTypeID for {((Object)item).name} to {value}"); } } } } [HarmonyPatch(typeof(Huluobolightutility), "Playerlight")] public class BlockLightUtilityPatch { [HarmonyPrefix] public static bool StopLightUtility() { FlashlightToolLoader.Logger.LogDebug((object)"LightUtilityPatch: PlayerControllerB Awake prefix called. Disabling LightUtility mod functionality. YOU SHALL NOT PASS!"); return false; } } }