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 Full Darkness v1.0.1
DiversityLib.dll
Decompiled 2 years agousing System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("DiversityLib")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("DiversityLib")] [assembly: AssemblyCopyright("Copyright © 2024")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("f3aa347e-bdfa-4c6a-b93f-1429e4f206c4")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("1.0.0.0")] 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; } } } namespace DiversityLib { public static class DiversityLib { public static Texture2D RenderToTexture2D(this RenderTexture rTex) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Expected O, but got Unknown //IL_0035: Unknown result type (might be due to invalid IL or missing references) Texture2D val = new Texture2D(((Texture)rTex).width, ((Texture)rTex).height, (TextureFormat)4, false); RenderTexture.active = rTex; val.ReadPixels(new Rect(0f, 0f, (float)((Texture)rTex).width, (float)((Texture)rTex).height), 0, 0); val.Apply(); return val; } public static Color[] GetPixels(this RenderTexture texture) { Texture2D val = texture.RenderToTexture2D(); return val.GetPixels(); } public static float CalculateAverageLuminance(this RenderTexture texture, bool useAlpha = false) { //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_0036: Unknown result type (might be due to invalid IL or missing references) Texture2D val = texture.RenderToTexture2D(); float num = ((Texture)val).width * ((Texture)val).height; float num2 = 0f; Color[] pixels = val.GetPixels(); foreach (Color color in pixels) { num2 += color.CalculateLuminance(useAlpha); } return num2 / num; } public static float CalculateAverageLuminance(this Texture2D texture, bool useAlpha = false) { //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_002d: Unknown result type (might be due to invalid IL or missing references) float num = ((Texture)texture).width * ((Texture)texture).height; float num2 = 0f; Color[] pixels = texture.GetPixels(); foreach (Color color in pixels) { num2 += color.CalculateLuminance(useAlpha); } return num2 / num; } public static float CalculateAverageLuminance(this Color[] colorArray, bool useAlpha = false) { //IL_0015: 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_001e: Unknown result type (might be due to invalid IL or missing references) float num = colorArray.Length; float num2 = 0f; foreach (Color color in colorArray) { num2 += color.CalculateLuminance(useAlpha); } return num2 / num; } public static Color AverageDifference(this Texture2D texture, Texture2D secondTexture) { //IL_00f9: 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_0102: 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_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004e: 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_0058: 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_007f: 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_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) float num = ((Texture)texture).width * ((Texture)texture).height; float num2 = 0f; float num3 = 0f; float num4 = 0f; float num5 = 0f; for (int i = 0; i < ((Texture)texture).width; i++) { for (int j = 0; j < ((Texture)texture).height; j++) { Color pixel = texture.GetPixel(i, j); Color pixel2 = secondTexture.GetPixel(i, j); num2 += Mathf.Abs(pixel.r - pixel2.r); num3 += Mathf.Abs(pixel.g - pixel2.g); num4 += Mathf.Abs(pixel.b - pixel2.b); num5 += Mathf.Abs(pixel.a - pixel2.a); } } num2 /= num; num3 /= num; num4 /= num; num5 /= num; return new Color(num2, num3, num4, num5); } public static float BW(this Color col) { //IL_0001: 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) return col.r + col.g + col.b; } public static float CalculateLuminance(this Color color, bool useAlpha = false) { //IL_0006: 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_0034: 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_0052: Unknown result type (might be due to invalid IL or missing references) return 0.299f * color.r * (useAlpha ? color.a : 1f) + 0.587f * color.g * (useAlpha ? color.a : 1f) + 0.114f * color.b * (useAlpha ? color.a : 1f); } public static Color GetAverageRGBA(this RenderTexture texture) { //IL_0009: 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_0011: Unknown result type (might be due to invalid IL or missing references) Texture2D texture2 = texture.RenderToTexture2D(); return texture2.GetAverageRGBA(); } public static Color GetAverageRGBA(this Texture2D texture) { //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_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004e: 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_0063: 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_0092: Unknown result type (might be due to invalid IL or missing references) float num = ((Texture)texture).width * ((Texture)texture).height; float num2 = 0f; float num3 = 0f; float num4 = 0f; float num5 = 0f; Color[] pixels = texture.GetPixels(); foreach (Color val in pixels) { num2 += val.r; num3 += val.g; num4 += val.b; num5 += val.a; } return new Color(num2 / num, num3 / num, num4 / num, num5 / num); } public static Color GetAverageRGBA(this Color[] colorArray) { //IL_002c: 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_0035: 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_0049: 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_007a: 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_0083: Unknown result type (might be due to invalid IL or missing references) float num = colorArray.Length; float num2 = 0f; float num3 = 0f; float num4 = 0f; float num5 = 0f; foreach (Color val in colorArray) { num2 += val.r; num3 += val.g; num4 += val.b; num5 += val.a; } return new Color(num2 / num, num3 / num, num4 / num, num5 / num); } public static float Remap(this float value, float from1, float to1, float from2, float to2) { return (value - from1) / (to1 - from1) * (to2 - from2) + from2; } public static float OneMinus(this float f) { return 1f - f; } public static float Negate(this float f) { return 0f - f; } public static uint Random(this uint u) { Random random = new Random(); uint num = (uint)random.Next(1073741824); uint num2 = (uint)random.Next(4); return (num << 2) | num2; } public static float Volume(this Vector3 v3) { //IL_0001: 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) return v3.x * v3.y * v3.z; } } }
Full Darkness.dll
Decompiled 2 years agousing System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using DiversityLib; using Full Darkness.NetcodePatcher; using Full_Darkness.Manager; using Full_Darkness.Patches; using GameNetcodeStuff; using HarmonyLib; using Unity.Netcode; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("Full Darkness")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Full Darkness")] [assembly: AssemblyCopyright("Copyright © 2024")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("1327764d-af71-48a4-ba41-6cbf7eed6d59")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: NetcodePatchedAssembly] internal class <Module> { static <Module>() { } } namespace Full_Darkness { public class Configuration { public static ConfigEntry<float> fullDarknessIntensity; public static void Load() { fullDarknessIntensity = Plugin.config.Bind<float>("Full Darkness", "Full Darkness Intensity", 1f, "How intense should full darkness be?"); } } [BepInPlugin("Chaos.FullDarkness", "Full Darkness", "1.0.1")] public class Plugin : BaseUnityPlugin { private const string modGUID = "Chaos.FullDarkness"; private const string modName = "Full Darkness"; private const string modVersion = "1.0.1"; private readonly Harmony harmony = new Harmony("Chaos.FullDarkness"); public static Plugin Instance; public static ManualLogSource mls; public static ConfigFile config; private void Awake() { if ((Object)(object)Instance == (Object)null) { Instance = this; } mls = ((BaseUnityPlugin)this).Logger; config = ((BaseUnityPlugin)this).Config; Configuration.Load(); mls.LogDebug((object)"Patching full darkness..."); harmony.PatchAll(typeof(FullDarknessPatch)); Type[] types = Assembly.GetExecutingAssembly().GetTypes(); Type[] array = types; foreach (Type type in array) { MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic); MethodInfo[] array2 = methods; foreach (MethodInfo methodInfo in array2) { object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false); if (customAttributes.Length != 0) { methodInfo.Invoke(null, null); } } } mls.LogInfo((object)"Full Darkness loaded."); } } } namespace Full_Darkness.Patches { [HarmonyPatch(typeof(StartOfRound))] internal class FullDarknessPatch { [HarmonyPatch(typeof(StartOfRound), "Awake")] [HarmonyPrefix] private static void Awake(StartOfRound __instance) { if (!Object.op_Implicit((Object)(object)((Component)__instance).gameObject.GetComponent<FullDarknessManager>())) { ((Component)__instance).gameObject.AddComponent<FullDarknessManager>(); } } } } namespace Full_Darkness.Manager { public class FullDarknessManager : NetworkBehaviour { public float intensityValue = 0f; public float nightVisionValue = 0f; public bool setup = false; public static FullDarknessManager Instance { get; private set; } private void Awake() { Instance = this; } private void Start() { //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) if (((NetworkBehaviour)this).IsOwner) { Plugin.mls.LogDebug((object)"I am the Host! Setting up full darkness locally..."); SetupFullDarkness(Configuration.fullDarknessIntensity.Value); } else { Plugin.mls.LogDebug((object)"I am not the Host! Requesting host's config..."); RequestDataServerRpc(); } } private void Update() { if (!setup) { return; } PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts; foreach (PlayerControllerB val in allPlayerScripts) { if (nightVisionValue * DiversityLib.OneMinus(intensityValue) != val.nightVision.intensity) { val.nightVision.intensity = nightVisionValue * DiversityLib.OneMinus(intensityValue); } } } [ServerRpc(RequireOwnership = false)] public void RequestDataServerRpc(ServerRpcParams serverRpcParams = default(ServerRpcParams)) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Invalid comparison between Unknown and I4 //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Invalid comparison between Unknown and I4 //IL_005f: 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_006d: 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_00bc: 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_00ca: 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_00eb: 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_00f1: 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_011f: Unknown result type (might be due to invalid IL or missing references) NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager; if (networkManager != null && networkManager.IsListening) { if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost)) { FastBufferWriter val = ((NetworkBehaviour)this).__beginSendServerRpc(1194691710u, serverRpcParams, (RpcDelivery)0); ((NetworkBehaviour)this).__endSendServerRpc(ref val, 1194691710u, serverRpcParams, (RpcDelivery)0); } if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost)) { ulong senderClientId = serverRpcParams.Receive.SenderClientId; ClientRpcParams val2 = default(ClientRpcParams); val2.Send = new ClientRpcSendParams { TargetClientIds = new ulong[1] { senderClientId } }; ClientRpcParams clientRpcParams = val2; Plugin.mls.LogDebug((object)("Client: " + senderClientId + " is requesting config data...")); RequestDataClientRpc(Configuration.fullDarknessIntensity.Value, clientRpcParams); } } } [ClientRpc] public void RequestDataClientRpc(float _intensityValue, ClientRpcParams clientRpcParams = default(ClientRpcParams)) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Invalid comparison between Unknown and I4 //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Invalid comparison between Unknown and I4 //IL_005f: 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_006d: Unknown result type (might be due to invalid IL or missing references) //IL_007d: 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_0097: Unknown result type (might be due to invalid IL or missing references) NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager; if (networkManager != null && networkManager.IsListening) { if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost)) { FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(2393552199u, clientRpcParams, (RpcDelivery)0); ((FastBufferWriter)(ref val)).WriteValueSafe<float>(ref _intensityValue, default(ForPrimitives)); ((NetworkBehaviour)this).__endSendClientRpc(ref val, 2393552199u, clientRpcParams, (RpcDelivery)0); } if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && !((NetworkBehaviour)this).IsOwner && !setup) { SetupFullDarkness(_intensityValue); } } } public void SetupFullDarkness(float _intensityValue) { Plugin.mls.LogDebug((object)"Setting up full darkness..."); intensityValue = _intensityValue; PlayerControllerB[] array = Object.FindObjectsOfType<PlayerControllerB>(); Plugin.mls.LogDebug((object)("Setting full darkness for the local player to " + intensityValue * 100f + "%.")); PlayerControllerB[] array2 = array; foreach (PlayerControllerB val in array2) { nightVisionValue = val.nightVision.intensity; Light nightVision = val.nightVision; nightVision.intensity *= DiversityLib.OneMinus(intensityValue); } setup = true; } protected override void __initializeVariables() { ((NetworkBehaviour)this).__initializeVariables(); } [RuntimeInitializeOnLoadMethod] internal static void InitializeRPCS_FullDarknessManager() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown NetworkManager.__rpc_func_table.Add(1194691710u, new RpcReceiveHandler(__rpc_handler_1194691710)); NetworkManager.__rpc_func_table.Add(2393552199u, new RpcReceiveHandler(__rpc_handler_2393552199)); } private static void __rpc_handler_1194691710(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams) { //IL_0023: 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_0029: 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_003e: 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) NetworkManager networkManager = target.NetworkManager; if (networkManager != null && networkManager.IsListening) { ServerRpcParams server = rpcParams.Server; target.__rpc_exec_stage = (__RpcExecStage)1; ((FullDarknessManager)(object)target).RequestDataServerRpc(server); target.__rpc_exec_stage = (__RpcExecStage)0; } } private static void __rpc_handler_2393552199(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams) { //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0035: 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_003f: 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_004e: 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_006c: Unknown result type (might be due to invalid IL or missing references) NetworkManager networkManager = target.NetworkManager; if (networkManager != null && networkManager.IsListening) { float num = default(float); ((FastBufferReader)(ref reader)).ReadValueSafe<float>(ref num, default(ForPrimitives)); ClientRpcParams client = rpcParams.Client; target.__rpc_exec_stage = (__RpcExecStage)2; ((FullDarknessManager)(object)target).RequestDataClientRpc(num, client); target.__rpc_exec_stage = (__RpcExecStage)0; } } protected internal override string __getTypeName() { return "FullDarknessManager"; } } } namespace Full Darkness.NetcodePatcher { [AttributeUsage(AttributeTargets.Module)] internal class NetcodePatchedAssemblyAttribute : Attribute { } }