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 Glow Steps v1.1.2
NicholaScott.LethalCompany.GlowSteps.dll
Decompiled 2 years agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using GameNetcodeStuff; using HarmonyLib; using NicholaScott.BepInEx.Utils.Configuration; using NicholaScott.BepInEx.Utils.Instancing; using NicholaScott.BepInEx.Utils.Patching; using NicholaScott.BepInEx.Utils.Resources; using NicholaScott.LethalCompany.GlowSteps.UnityScripts; using Unity.Netcode; using UnityEngine; using UnityEngine.Pool; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("NicholaScott.LethalCompany.GlowSteps")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("NicholaScott.LethalCompany.GlowSteps")] [assembly: AssemblyCopyright("Copyright © 2023")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("F0F641E1-26A9-4BAE-8411-9D3681207A6F")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("1.0.0.0")] namespace NicholaScott.LethalCompany.GlowSteps { public class FootstepManager : MonoBehaviour { public readonly List<GlowingFootstep.Data> FootstepData = new List<GlowingFootstep.Data>(); public readonly FootstepPool PooledObjects = new FootstepPool(); private static Material _catwalkMaterial; public static Material CatwalkMaterial { get { if ((Object)(object)_catwalkMaterial == (Object)null) { GameObject obj = GameObject.Find("Environment/HangarShip/CatwalkShip"); object catwalkMaterial; if (obj == null) { catwalkMaterial = null; } else { Renderer component = obj.GetComponent<Renderer>(); catwalkMaterial = ((component != null) ? component.material : null); } _catwalkMaterial = (Material)catwalkMaterial; } return _catwalkMaterial; } } public void Start() { ((MonoBehaviour)this).InvokeRepeating("UpdateAllFootstepData", 1f, Singleton<GlowSteps, GlowSteps.Configuration>.Configuration.UpdateRate); } public void AddNewFootstep(GlowingFootstep.Data footstepData) { FootstepData.Add(footstepData); } public void UpdateAllFootstepData() { if ((Object)(object)CatwalkMaterial == (Object)null) { return; } for (int i = 0; i < FootstepData.Count; i++) { GlowingFootstep.Data data = FootstepData[i]; data.UpdateFootstepData(Singleton<GlowSteps, GlowSteps.Configuration>.Configuration.UpdateRate); if (data.IsEnabled && data.ShouldDraw) { data.Linked.SyncColorIntensity(data); } if (!data.IsEnabled && data.ShouldDraw) { GlowingFootstep glowingFootstep = ((ObjectPool<GlowingFootstep>)PooledObjects).Get(); data.IsEnabled = true; data.Linked = glowingFootstep; glowingFootstep.SyncAll(data); } if (data.IsEnabled && !data.ShouldDraw) { ((ObjectPool<GlowingFootstep>)PooledObjects).Release(data.Linked); data.IsEnabled = false; } FootstepData[i] = data; } FootstepData.RemoveAll((GlowingFootstep.Data d) => !d.IsEnabled && !d.ShouldDraw && d.TimeLeftAlive <= 0f); } } [Production] public static class FootstepPatcher { private static Dictionary<ulong, float> _leftFoots = new Dictionary<ulong, float>(); [HarmonyPatch(typeof(Terminal), "Start")] [HarmonyPostfix] public static void CreateFootstepManager(Terminal __instance) { //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Expected O, but got Unknown if (!((Object)(object)Singleton<GlowSteps>.Instance.footyManager != (Object)null)) { GameObject val = new GameObject("Footstep Manager", new Type[1] { typeof(FootstepManager) }); Singleton<GlowSteps>.Instance.footyManager = val.GetComponent<FootstepManager>(); Object.DontDestroyOnLoad((Object)(object)((Component)Singleton<GlowSteps>.Instance.footyManager).gameObject); } } [HarmonyPatch(typeof(PlayerControllerB), "PlayFootstepSound")] [HarmonyPrefix] public static void AddPositionToTracking(PlayerControllerB __instance) { //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_0169: 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) //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Unknown result type (might be due to invalid IL or missing references) //IL_01af: Unknown result type (might be due to invalid IL or missing references) //IL_01c3: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_01cd: Unknown result type (might be due to invalid IL or missing references) //IL_01d9: Unknown result type (might be due to invalid IL or missing references) //IL_01e3: Unknown result type (might be due to invalid IL or missing references) //IL_01ea: Unknown result type (might be due to invalid IL or missing references) //IL_01ef: Unknown result type (might be due to invalid IL or missing references) //IL_01f4: Unknown result type (might be due to invalid IL or missing references) GlowSteps.Configuration configuration = Singleton<GlowSteps, GlowSteps.Configuration>.Configuration; int strength = ((!((NetworkBehaviour)__instance).IsOwner) ? 2 : (__instance.isSprinting ? 3 : ((__instance.isCrouching || __instance.isExhausted || __instance.isMovementHindered != 0) ? 1 : 2))); if ((!((NetworkBehaviour)__instance).IsOwner || __instance.isSprinting) && (__instance.isInsideFactory || !configuration.InFactory)) { if (!_leftFoots.ContainsKey(__instance.playerSteamId)) { _leftFoots.Add(__instance.playerSteamId, -1f); } float num = _leftFoots[__instance.playerSteamId]; Transform transform = ((Component)__instance).transform; Ray val = default(Ray); ((Ray)(ref val))..ctor(transform.position + transform.right * 0.2f * num, Vector3.down); RaycastHit val2 = default(RaycastHit); if (Physics.Raycast(val, ref val2, 10f, LayerMask.GetMask(new string[3] { "Room", "Railing", "Default" }))) { Vector3 val3 = new Vector3((float)((__instance.playerSteamId & 0xFF0000) >> 16), (float)((__instance.playerSteamId & 0xFF00) >> 8), (float)(__instance.playerSteamId & 0xFF)) / 255f; GlowingFootstep.Data footstepData = new GlowingFootstep.Data { Color = (((NetworkBehaviour)__instance).IsOwner ? configuration.Color : val3), LeftFoot = (num <= 0f), Strength = strength, TimeLeftAlive = configuration.SecondsUntilFade, Position = ((RaycastHit)(ref val2)).point + new Vector3(0f, 0.001f, 0f), Rotation = Quaternion.LookRotation(((Component)__instance).transform.forward * -1f, ((RaycastHit)(ref val2)).normal) }; Singleton<GlowSteps>.Instance.footyManager.AddNewFootstep(footstepData); _leftFoots[__instance.playerSteamId] *= -1f; } } } } public class FootstepPool : ObjectPool<GlowingFootstep> { public FootstepPool() : base((Func<GlowingFootstep>)CreateNewFootstep, (Action<GlowingFootstep>)delegate(GlowingFootstep fs) { ((Component)fs).gameObject.SetActive(true); }, (Action<GlowingFootstep>)delegate(GlowingFootstep fs) { ((Component)fs).gameObject.SetActive(false); }, (Action<GlowingFootstep>)DestroyFootstep, true, 10, 10000) { } private static GlowingFootstep CreateNewFootstep() { //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Expected O, but got Unknown Singleton<GlowSteps>.Logger.LogInfo((object)($"Creating new footstep object in pool. Object count {((ObjectPool<GlowingFootstep>)Singleton<GlowSteps>.Instance.footyManager.PooledObjects).CountAll} " + $"& active {((ObjectPool<GlowingFootstep>)Singleton<GlowSteps>.Instance.footyManager.PooledObjects).CountActive}")); GameObject val = new GameObject("Glow Step", new Type[1] { typeof(GlowingFootstep) }); val.transform.SetParent(((Component)Singleton<GlowSteps>.Instance.footyManager).transform); return val.GetComponent<GlowingFootstep>(); } private static void DestroyFootstep(GlowingFootstep footstep) { Singleton<GlowSteps>.Logger.LogInfo((object)($"Destroying footstep object in pool. Object count {((ObjectPool<GlowingFootstep>)Singleton<GlowSteps>.Instance.footyManager.PooledObjects).CountAll} " + $"& active {((ObjectPool<GlowingFootstep>)Singleton<GlowSteps>.Instance.footyManager.PooledObjects).CountActive}")); Object.Destroy((Object)(object)((Component)footstep).gameObject); } } [BepInDependency("NicholaScott.BepInEx.Utils", "1.2.0")] [BepInPlugin("NicholaScott.LethalCompany.GlowSteps", "Glow Steps", "1.1.2")] public class GlowSteps : BaseUnityPlugin { public struct Configuration { [ConfigEntryDefinition(Description = "The distance until footsteps are no longer visible.")] public float DistanceFalloff; public float SecondsUntilFade; [ConfigEntryDefinition(Description = "The rate to update footsteps. This should be kept <= 0.1")] public float UpdateRate; [ConfigEntryDefinition(Description = "Whether the footsteps show up only in the factory or outside as well.")] public bool InFactory; [ConfigEntryDefinition(Description = "Three normalized(0-1) numbers representing an RGB value.")] public Vector3 Color; } public readonly Dictionary<string, Texture2D> FootstepTexts = new Dictionary<string, Texture2D>(); public FootstepManager footyManager; public void Awake() { //IL_0046: 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_007e: 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_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) Singleton<GlowSteps>.Instance = this; Singleton<GlowSteps, Configuration>.Configuration = Extensions.BindStruct<Configuration>(((BaseUnityPlugin)this).Config, new Configuration { DistanceFalloff = 20f, SecondsUntilFade = 60f, InFactory = true, Color = new Vector3(0.1f, 1f, 0.1f), UpdateRate = 0.1f }); Vector2Int dimensions = default(Vector2Int); ((Vector2Int)(ref dimensions))..ctor(512, 512); LoadResource("LHeavy", dimensions); LoadResource("LMedium", dimensions); LoadResource("LLight", dimensions); LoadResource("RHeavy", dimensions); LoadResource("RMedium", dimensions); LoadResource("RLight", dimensions); Extensions.PatchAttribute<Production>(Assembly.GetExecutingAssembly(), ((BaseUnityPlugin)this).Info.Metadata.GUID, (Action<object>)((BaseUnityPlugin)this).Logger.LogInfo); } private void LoadResource(string resourceName, Vector2Int dimensions) { //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Expected O, but got Unknown Assembly executingAssembly = Assembly.GetExecutingAssembly(); string name = executingAssembly.GetName().Name + ".Images." + resourceName + ".png"; Texture2D val = new Texture2D(((Vector2Int)(ref dimensions)).x, ((Vector2Int)(ref dimensions)).y); ImageConversion.LoadImage(val, Extensions.ReadAllBytes(executingAssembly.GetManifestResourceStream(name))); FootstepTexts[resourceName] = val; } } } namespace NicholaScott.LethalCompany.GlowSteps.UnityScripts { public class GlowingFootstep : MonoBehaviour { public class Data : INetworkSerializable { public Vector3 Position; public Quaternion Rotation; public float TimeLeftAlive; public int Strength; public bool LeftFoot; public Vector3 Color; public bool ShouldDraw; public bool IsEnabled; public GlowingFootstep Linked; public float LastDistance; public void UpdateFootstepData(float delta) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)null) { LastDistance = Vector3.Distance(Position, GameNetworkManager.Instance.localPlayerController.playerEye.position); float distanceFalloff = Singleton<GlowSteps, GlowSteps.Configuration>.Configuration.DistanceFalloff; if (LastDistance <= distanceFalloff) { ShouldDraw = true; } if (LastDistance > distanceFalloff || TimeLeftAlive <= 0f) { ShouldDraw = false; } } else { ShouldDraw = false; } TimeLeftAlive -= delta; } public unsafe void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter { //IL_0027: 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) //IL_003e: 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_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) serializer.SerializeValue(ref Position); serializer.SerializeValue(ref Rotation); ((BufferSerializer<float>*)(&serializer))->SerializeValue<float>(ref TimeLeftAlive, default(ForPrimitives)); ((BufferSerializer<int>*)(&serializer))->SerializeValue<int>(ref Strength, default(ForPrimitives)); ((BufferSerializer<bool>*)(&serializer))->SerializeValue<bool>(ref LeftFoot, default(ForPrimitives)); serializer.SerializeValue(ref Color); } public static int SizeOf() { return 45; } } private Material _materialReference; private GameObject _subPlane; private static readonly int EmissiveExposureWeight = Shader.PropertyToID("_EmissiveExposureWeight"); private static readonly int EmissiveColorMode = Shader.PropertyToID("_EmissiveColorMode"); private static readonly int EmissiveColor = Shader.PropertyToID("_EmissiveColor"); private static readonly int BaseColorMap = Shader.PropertyToID("_BaseColorMap"); private static readonly int NormalMap = Shader.PropertyToID("_NormalMap"); private static readonly int MainTex = Shader.PropertyToID("_MainTex"); public void Awake() { //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) _materialReference = CreateNewMaterial(); _subPlane = GameObject.CreatePrimitive((PrimitiveType)4); _subPlane.GetComponent<Renderer>().material = _materialReference; _subPlane.GetComponent<Collider>().enabled = false; _subPlane.transform.SetParent(((Component)this).transform, false); _subPlane.transform.localScale = Vector3.one / 15f; } public void SyncAll(Data footstepData) { SyncTransform(footstepData); SyncMaterial(footstepData); SyncColorIntensity(footstepData); } private void SyncTransform(Data footstepData) { //IL_000a: 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) Transform transform = ((Component)this).transform; transform.position = footstepData.Position; transform.rotation = footstepData.Rotation; } private void SyncMaterial(Data footstepData) { string key = (footstepData.LeftFoot ? "L" : "R") + ((footstepData.Strength >= 3) ? "Heavy" : ((footstepData.Strength >= 2) ? "Medium" : "Light")); Texture2D val = Singleton<GlowSteps>.Instance.FootstepTexts[key]; _materialReference.SetTexture(MainTex, (Texture)(object)val); _materialReference.SetTexture(BaseColorMap, (Texture)(object)val); } public void SyncColorIntensity(Data footstepData) { //IL_0091: 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) float num = Mathf.Clamp(footstepData.TimeLeftAlive, 0f, 30f) / 30f; GlowSteps.Configuration configuration = Singleton<GlowSteps, GlowSteps.Configuration>.Configuration; num = Mathf.Min(num, Mathf.Pow(Mathf.Clamp(2f - footstepData.LastDistance / configuration.DistanceFalloff, 0f, 1f), 4f)); _subPlane.GetComponent<Renderer>().material.SetVector(EmissiveColor, new Vector4(footstepData.Color.x, footstepData.Color.y, footstepData.Color.z, 1f) * num); } private static Material CreateNewMaterial() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_003c: 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) Material val = new Material(FootstepManager.CatwalkMaterial); val.SetTexture(NormalMap, (Texture)null); val.SetFloat(EmissiveColorMode, 1f); val.SetFloat(EmissiveExposureWeight, 1f); val.mainTextureScale = Vector2.one; val.color = Color.white; return val; } } }