Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of FlashlightToolLoader v1.0.3
Sniper1_1.FlashlightToolLoader.dll
Decompiled 7 months agousing 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.3.0")] [assembly: AssemblyInformationalVersion("1.0.3+c69a55d72dd9490637f21def838c8da9cb112659")] [assembly: AssemblyProduct("FlashlightToolLoader")] [assembly: AssemblyTitle("Sniper1_1.FlashlightToolLoader")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.3.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.3")] [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.3 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<string> Blacklist; public FlashlightToolLoaderConfig(ConfigFile config) { Blacklist = config.Bind<string>("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.3"; } } 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<GameObject, int> LightToID = new Dictionary<GameObject, int>(); public static void InitiateHelmetLights(PlayerControllerB __instance) { //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) FlashlightToolLoader.Logger.LogDebug((object)("InitiateHelmetLight called on player: " + (object)__instance)); List<Item> 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)); Light[] array = (Light[])(object)new Light[validItems.Count]; LightToID.Clear(); for (int i = 0; i < validItems.Count; i++) { array[i] = CreateLight(validItems[i]); validItems[i].spawnPrefab.GetComponent<FlashlightItem>().flashlightTypeID = i + num; FlashlightToolLoader.Logger.LogDebug((object)("Flashlight Type ID: " + validItems[i].spawnPrefab.GetComponent<FlashlightItem>().flashlightTypeID)); try { ((Component)array[i]).transform.SetParent(((Component)((Component)__instance.helmetLight).transform.parent).transform, false); ((Component)array[i]).transform.localPosition = FlashlightToolLoader.vanillaLightPos; ((Component)array[i]).transform.localRotation = FlashlightToolLoader.vanillaLightRot; FlashlightToolLoader.Logger.LogDebug((object)("Set parent of light: " + ((Object)array[i]).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] = i + num; FlashlightToolLoader.Logger.LogDebug((object)("Added light: " + ((Object)array[i]).name + " to dictionary with ID: " + validItems[i].spawnPrefab.GetComponent<FlashlightItem>().flashlightTypeID)); } __instance.allHelmetLights = CollectionExtensions.AddRangeToArray<Light>(__instance.allHelmetLights, array); 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<Item> GetValidItems() { List<string> list = new List<string>(FlashlightToolLoader.BoundConfig.Blacklist.Value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries)); List<Item> list2 = new List<Item>(); 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<FlashlightItem>() != (Object)null) { FlashlightToolLoader.Logger.LogDebug((object)("Item is a flashlight: " + (object)item)); 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<Transform>(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<GameObject>(((Component)val).gameObject); Light component = val3.GetComponent<Light>(); ((Object)component).name = ((Object)item.spawnPrefab).name + " Light"; FlashlightToolLoader.Logger.LogDebug((object)("Instantiated Light: " + ((Object)val3).name + " of item: " + (object)item)); return component; } FlashlightToolLoader.Logger.LogDebug((object)"No Light found"); return null; } public static void FixShipItems() { List<GrabbableObject> list = new List<GrabbableObject>(Object.FindObjectsOfType<GrabbableObject>()); 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<FlashlightItem>() != (Object)null && LightToID.TryGetValue(item.itemProperties.spawnPrefab, out var value)) { ((Component)item).GetComponent<FlashlightItem>().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; } } }