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 InfinityFlashlight v0.1.5
BepInEx/plugins/InfinityFlashlight/InfinityFlashlight.dll
Decompiled 6 hours agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using GameNetcodeStuff; using HarmonyLib; using LethalLib.Modules; using Microsoft.CodeAnalysis; using Unity.Collections; using Unity.Netcode; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyVersion("0.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [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 HJM.InfinityLight { internal sealed class BeamSnapshot { private readonly Light light; private readonly Component hd; private readonly PropertyInfo physicalIntensity; private readonly float nativeIntensity; private readonly float hdIntensity; private readonly float nativeRange; internal BeamSnapshot(Light value) { light = value; nativeIntensity = value.intensity; nativeRange = value.range; hd = ((Component)value).GetComponent("HDAdditionalLightData"); if ((Object)(object)hd != (Object)null) { physicalIntensity = ((object)hd).GetType().GetProperty("intensity", BindingFlags.Instance | BindingFlags.Public); if (physicalIntensity != null) { hdIntensity = (float)physicalIntensity.GetValue(hd, null); } } } internal void Apply(float brightness, float distance) { if (!((Object)(object)light == (Object)null)) { if ((Object)(object)hd != (Object)null && physicalIntensity != null && physicalIntensity.CanWrite) { physicalIntensity.SetValue(hd, hdIntensity * brightness, null); } else { light.intensity = nativeIntensity * brightness; } light.range = nativeRange * distance; } } } internal static class BeamLighting { internal static bool IsInfinity(FlashlightItem lamp) { if ((Object)(object)lamp == (Object)null) { return false; } LightMarker component = ((Component)lamp).GetComponent<LightMarker>(); if ((Object)(object)component != (Object)null && component.IsVirtual) { return !component.Releasing; } return false; } internal static bool IsLamp(FlashlightItem lamp) { if ((Object)(object)lamp != (Object)null && ((GrabbableObject)lamp).isBeingUsed) { return (Object)(object)((GrabbableObject)lamp).itemProperties != (Object)(object)Content.SourceItem; } return false; } internal static void Configure(FlashlightItem lamp) { if ((Object)(object)lamp.flashlightBulb != (Object)null) { new BeamSnapshot(lamp.flashlightBulb).Apply(Plugin.Brightness.Value, Plugin.BeamRange.Value); } } internal static void Watch(PlayerControllerB player) { if ((Object)(object)player != (Object)null && (Object)(object)((Component)player).GetComponent<InfinityHelmetBeam>() == (Object)null) { ((Component)player).gameObject.AddComponent<InfinityHelmetBeam>(); } } } internal sealed class InfinityHelmetBeam : MonoBehaviour { private PlayerControllerB player; private Light observed; private BeamSnapshot baseline; private bool boosted; private void Awake() { player = ((Component)this).GetComponent<PlayerControllerB>(); } internal void Restore() { if (boosted) { baseline.Apply(1f, 1f); boosted = false; } } private void LateUpdate() { if ((Object)(object)player == (Object)null || (Object)(object)player.helmetLight == (Object)null) { return; } if ((Object)(object)observed != (Object)(object)player.helmetLight) { Restore(); observed = player.helmetLight; baseline = null; } GrabbableObject currentlyHeldObjectServer = player.currentlyHeldObjectServer; FlashlightItem val = (FlashlightItem)(object)((currentlyHeldObjectServer is FlashlightItem) ? currentlyHeldObjectServer : null); if (!BeamLighting.IsLamp(val)) { GrabbableObject pocketedFlashlight = player.pocketedFlashlight; val = (FlashlightItem)(object)((pocketedFlashlight is FlashlightItem) ? pocketedFlashlight : null); } if (!BeamLighting.IsLamp(val)) { GrabbableObject itemOnlySlot = player.ItemOnlySlot; val = (FlashlightItem)(object)((itemOnlySlot is FlashlightItem) ? itemOnlySlot : null); } if (player.isPlayerDead || !((Behaviour)observed).enabled || !((Object)(object)val != (Object)null) || !((GrabbableObject)val).isBeingUsed || !((Object)(object)((GrabbableObject)val).playerHeldBy == (Object)(object)player) || !BeamLighting.IsInfinity(val)) { Restore(); return; } if (baseline == null) { baseline = new BeamSnapshot(observed); } if (!boosted) { baseline.Apply(Plugin.Brightness.Value, Plugin.BeamRange.Value); boosted = true; } } internal void NativeChanged() { baseline = null; } private void OnDisable() { Restore(); } private void OnDestroy() { Restore(); } } [HarmonyPatch] internal static class BeamPatches { [HarmonyPatch(typeof(FlashlightItem), "SwitchFlashlight")] [HarmonyPostfix] private static void Switched(FlashlightItem __instance) { if (BeamLighting.IsInfinity(__instance)) { BeamLighting.Watch(((GrabbableObject)__instance).playerHeldBy); } } [HarmonyPatch(typeof(FlashlightItem), "PocketItem")] [HarmonyPostfix] private static void Pocketed(FlashlightItem __instance) { if (BeamLighting.IsInfinity(__instance)) { BeamLighting.Watch(((GrabbableObject)__instance).playerHeldBy); } } [HarmonyPatch(typeof(PlayerControllerB), "ChangeHelmetLight")] [HarmonyPrefix] private static void BeforeNative(PlayerControllerB __instance) { InfinityHelmetBeam component = ((Component)__instance).GetComponent<InfinityHelmetBeam>(); if ((Object)(object)component != (Object)null) { component.Restore(); } } [HarmonyPatch(typeof(PlayerControllerB), "ChangeHelmetLight")] [HarmonyPostfix] private static void AfterNative(PlayerControllerB __instance) { InfinityHelmetBeam component = ((Component)__instance).GetComponent<InfinityHelmetBeam>(); if ((Object)(object)component != (Object)null) { component.NativeChanged(); } } } public static class DawnCompatibility { public const string SourceKey = "infinityflashlight:infinity_source"; public const string VirtualKey = "infinityflashlight:infinity_virtual"; public static bool Install(Harmony harmony) { //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Expected O, but got Unknown //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Expected O, but got Unknown Type type = Type.GetType("Dawn.DawnItemInfo, com.github.teamxiaolan.dawnlib", throwOnError: false); if (type == null) { return true; } if (type.Assembly.GetName().Version != new Version(0, 9, 27, 0)) { Plugin.Log.LogError((object)"Infinity preview only supports DawnLib 0.9.27. Leaving the flashlight module disabled for an unverified save backend."); return false; } try { Assembly assembly = type.Assembly; MethodInfo methodInfo = AccessTools.DeclaredMethod(assembly.GetType("Dawn.ItemRegistrationHandler", throwOnError: true), "FreezeItemContent", (Type[])null, (Type[])null); MethodInfo methodInfo2 = AccessTools.DeclaredMethod(assembly.GetType("Dawn.Internal.ItemSaveDataHandler", throwOnError: true), "SaveAllItems", (Type[])null, (Type[])null); if (methodInfo == null || methodInfo2 == null) { throw new MissingMethodException("Dawn item/save interface changed"); } harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(DawnCompatibility), "StableKeyNames", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(Patches), "ExcludeVirtualFromSave", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null); Plugin.Log.LogInfo((object)"DawnLib 0.9.27 support: distinct stable item keys and virtual-item save exclusion enabled."); return true; } catch (Exception ex) { harmony.UnpatchSelf(); Plugin.Log.LogError((object)("Dawn save compatibility could not be installed; flashlight module disabled. " + ex)); return false; } } private static string KeyName(Item item) { LightMarker lightMarker = (((Object)(object)item.spawnPrefab == (Object)null) ? null : item.spawnPrefab.GetComponent<LightMarker>()); if (!((Object)(object)lightMarker == (Object)null)) { if (!lightMarker.IsVirtual) { return "infinity_source"; } return "infinity_virtual"; } return item.itemName; } private static IEnumerable<CodeInstruction> StableKeyNames(IEnumerable<CodeInstruction> source) { List<CodeInstruction> list = source.ToList(); int num = 0; for (int i = 0; i < list.Count; i++) { FieldInfo fieldInfo = list[i].operand as FieldInfo; if (list[i].opcode != OpCodes.Ldfld || fieldInfo == null || fieldInfo.DeclaringType != typeof(Item) || fieldInfo.Name != "itemName") { continue; } bool flag = false; for (int j = i + 1; j <= Math.Min(i + 2, list.Count - 1); j++) { MethodInfo methodInfo = list[j].operand as MethodInfo; if (methodInfo != null && methodInfo.DeclaringType.FullName.StartsWith("Dawn.NamespacedKey", StringComparison.Ordinal) && (methodInfo.Name == "From" || methodInfo.Name == "NormalizeStringForNamespacedKey")) { flag = true; } } if (flag) { list[i].opcode = OpCodes.Call; list[i].operand = AccessTools.Method(typeof(DawnCompatibility), "KeyName", (Type[])null, (Type[])null); num++; } } if (num != 4) { throw new MissingMethodException("Dawn 0.9.27 key derivation layout changed"); } return list; } } [BepInPlugin("hjm.infinityflashlight", "无尽手电筒", "0.1.5")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public sealed class Plugin : BaseUnityPlugin { public const string Guid = "hjm.infinityflashlight"; internal static ManualLogSource Log; internal static ConfigEntry<int> Price; internal static ConfigEntry<float> Brightness; internal static ConfigEntry<float> BeamRange; private void Awake() { //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Expected O, but got Unknown //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Expected O, but got Unknown //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Expected O, but got Unknown //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; Price = ((BaseUnityPlugin)this).Config.Bind<int>("商店", "本体价格", 500, new ConfigDescription("船内无尽手电本体售价。", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 10000), Array.Empty<object>())); Brightness = ((BaseUnityPlugin)this).Config.Bind<float>("照明", "亮度倍率", 1.0769231f, new ConfigDescription("相对于原版专业手电的亮度;手持和工具槽照明均生效。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 6f), Array.Empty<object>())); BeamRange = ((BaseUnityPlugin)this).Config.Bind<float>("照明", "距离倍率", 1.1f, new ConfigDescription("相对于原版专业手电的照明距离。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 2f), Array.Empty<object>())); ConfigEntry<int> val = ((BaseUnityPlugin)this).Config.Bind<int>("照明", "参数版本", 0, "用于一次性更新旧版默认照明参数。无需手动修改。"); if (val.Value < 1) { if (Mathf.Approximately(Brightness.Value, 2.5f)) { Brightness.Value = 1.0769231f; } if (Mathf.Approximately(BeamRange.Value, 1.35f)) { BeamRange.Value = 1.1f; } val.Value = 1; ((BaseUnityPlugin)this).Config.Save(); } Harmony val2 = new Harmony("hjm.infinityflashlight"); if (DawnCompatibility.Install(val2)) { Content.PreparePrefabs(); val2.PatchAll(typeof(Plugin).Assembly); } } } public static class Content { public static Item SourceItem; public static Item VirtualItem; public static bool Ready; private static GameObject sourcePrefab; private static GameObject virtualPrefab; public static void PreparePrefabs() { if (!((Object)(object)sourcePrefab != (Object)null)) { sourcePrefab = Empty("HJM_InfinitySource", temporary: false); virtualPrefab = Empty("HJM_InfinityVirtual", temporary: true); } } private static GameObject Empty(string name, bool temporary) { GameObject obj = NetworkPrefabs.CreateNetworkPrefab(name); obj.AddComponent<FlashlightItem>(); obj.AddComponent<LightMarker>().IsVirtual = temporary; obj.AddComponent<StarSurface>(); return obj; } public static void Register(IEnumerable<Item> available = null) { if (!Ready) { Item val = (available ?? Resources.FindObjectsOfTypeAll<Item>()).FirstOrDefault((Func<Item, bool>)((Item i) => (Object)(object)i.spawnPrefab != (Object)null && (Object)(object)i.spawnPrefab.GetComponent<FlashlightItem>() != (Object)null && (i.itemName == "Pro-flashlight" || ((Object)i).name.IndexOf("ProFlash", StringComparison.OrdinalIgnoreCase) >= 0))); if ((Object)(object)val == (Object)null) { Plugin.Log.LogError((object)"Professional flashlight prefab not found; custom content was not registered."); return; } PreparePrefabs(); SourceItem = Create(val, sourcePrefab, "HJM_InfinitySource", "无尽手电筒", ephemeral: false); VirtualItem = Create(val, virtualPrefab, "HJM_InfinityVirtual", "无尽手电筒", ephemeral: true); TerminalNode val2 = ShopText("HJM_Infinity_Confirm", "购买无尽手电筒本体,数量:[variableAmount]。\n总价:[totalCost]。\n\n输入 CONFIRM 确认,DENY 取消。\n\n"); TerminalNode val3 = ShopText("HJM_Infinity_Receipt", "已订购 [variableAmount] 个无尽手电筒本体。余额:[playerCredits]。\n本体由运输船送达,带回船内后可反复领取虚拟手电。\n\n"); TerminalNode val4 = ShopText("HJM_Infinity_Info", "无尽手电筒\n\n拿起本体,按使用键领取无限电量的手电,自动放入 TAB 工具槽并开灯。采用原版专业手电模型和无尽星空材质,照明更亮、更远,可正常开关。\n本体保留在普通物品栏;领取的手电丢弃后消失,工具槽空时可再次领取。已有物品时不会替换。搭配 HandyFlashlight 可按 F 开关。\n\n"); Items.RegisterShopItem(SourceItem, val2, val3, val4, Plugin.Price.Value); Items.RegisterItem(VirtualItem); Ready = true; Plugin.Log.LogInfo((object)"Registered infinity flashlight source and virtual light; original pro-flashlight model, enhanced handheld and helmet beams."); } } private static TerminalNode ShopText(string name, string text) { TerminalNode obj = ScriptableObject.CreateInstance<TerminalNode>(); ((Object)obj).name = name; obj.displayText = text; obj.clearPreviousText = true; obj.maxCharactersToType = 35; return obj; } private static Item Create(Item original, GameObject prefab, string id, string display, bool ephemeral) { //IL_008e: 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) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_024b: Unknown result type (might be due to invalid IL or missing references) //IL_0258: Unknown result type (might be due to invalid IL or missing references) //IL_0279: Unknown result type (might be due to invalid IL or missing references) //IL_02a7: Unknown result type (might be due to invalid IL or missing references) Item val = Object.Instantiate<Item>(original); ((Object)val).name = id; val.itemName = display; val.isScrap = false; val.creditsWorth = ((!ephemeral) ? Plugin.Price.Value : 0); val.requiresBattery = false; val.twoHanded = false; val.disallowUtilitySlot = !ephemeral; if (!ephemeral) { val.toolTips = new string[1] { "领取虚拟手电 : [LMB]" }; } val.canBeGrabbedBeforeGameStart = true; GameObject val2 = Object.Instantiate<GameObject>(original.spawnPrefab, prefab.transform); ((Object)val2).name = "ProfessionalLightVisuals"; val2.transform.localPosition = Vector3.zero; val2.transform.localRotation = Quaternion.identity; val2.transform.localScale = Vector3.one; prefab.transform.localScale = original.spawnPrefab.transform.localScale; prefab.tag = original.spawnPrefab.tag; prefab.layer = original.spawnPrefab.layer; AudioSource component = val2.GetComponent<AudioSource>(); if ((Object)(object)component != (Object)null) { AudioSource obj = prefab.AddComponent<AudioSource>(); obj.clip = component.clip; obj.volume = component.volume; obj.pitch = component.pitch; obj.spatialBlend = component.spatialBlend; obj.rolloffMode = component.rolloffMode; obj.minDistance = component.minDistance; obj.maxDistance = component.maxDistance; obj.dopplerLevel = component.dopplerLevel; obj.outputAudioMixerGroup = component.outputAudioMixerGroup; obj.playOnAwake = false; } FlashlightItem component2 = val2.GetComponent<FlashlightItem>(); FlashlightItem component3 = prefab.GetComponent<FlashlightItem>(); Type[] array = new Type[2] { typeof(GrabbableObject), typeof(FlashlightItem) }; for (int i = 0; i < array.Length; i++) { FieldInfo[] fields = array[i].GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (FieldInfo fieldInfo in fields) { if (!fieldInfo.IsInitOnly) { fieldInfo.SetValue(component3, fieldInfo.GetValue(component2)); } } } Collider[] components = val2.GetComponents<Collider>(); foreach (Collider val3 in components) { BoxCollider val4 = (BoxCollider)(object)((val3 is BoxCollider) ? val3 : null); SphereCollider val5 = (SphereCollider)(object)((val3 is SphereCollider) ? val3 : null); CapsuleCollider val6 = (CapsuleCollider)(object)((val3 is CapsuleCollider) ? val3 : null); Collider val7 = null; if ((Object)(object)val4 != (Object)null) { BoxCollider obj2 = prefab.AddComponent<BoxCollider>(); obj2.center = val4.center; obj2.size = val4.size; val7 = (Collider)(object)obj2; } else if ((Object)(object)val5 != (Object)null) { SphereCollider obj3 = prefab.AddComponent<SphereCollider>(); obj3.center = val5.center; obj3.radius = val5.radius; val7 = (Collider)(object)obj3; } else if ((Object)(object)val6 != (Object)null) { CapsuleCollider obj4 = prefab.AddComponent<CapsuleCollider>(); obj4.center = val6.center; obj4.radius = val6.radius; obj4.height = val6.height; obj4.direction = val6.direction; val7 = (Collider)(object)obj4; } if ((Object)(object)val7 == (Object)null) { throw new NotSupportedException("Unexpected professional-light root collider: " + ((object)val3).GetType().Name); } val7.isTrigger = val3.isTrigger; val7.sharedMaterial = val3.sharedMaterial; val7.enabled = val3.enabled; Object.DestroyImmediate((Object)(object)val3); } Object.DestroyImmediate((Object)(object)component2); Object.DestroyImmediate((Object)(object)val2.GetComponent<NetworkObject>()); ((GrabbableObject)component3).itemProperties = val; BeamLighting.Configure(component3); ScanNodeProperties[] componentsInChildren = prefab.GetComponentsInChildren<ScanNodeProperties>(); foreach (ScanNodeProperties obj5 in componentsInChildren) { obj5.headerText = display; obj5.subText = (ephemeral ? "无限电量 · 丢弃消失" : "船内领取源"); } val.spawnPrefab = prefab; return val; } } public sealed class LightMarker : MonoBehaviour { public bool IsVirtual; internal bool Releasing; internal bool EverHeld; internal ulong IntendedOwner; internal float Born; private GrabbableObject item; private void Awake() { ((Object)((Component)this).gameObject).hideFlags = (HideFlags)0; } private void Start() { item = ((Component)this).GetComponent<GrabbableObject>(); Born = Time.realtimeSinceStartup; } private void LateUpdate() { if (!((Object)(object)item == (Object)null) && ((NetworkBehaviour)item).NetworkObject.IsSpawned && IsVirtual) { if (item.insertedBattery != null) { item.insertedBattery.charge = 1f; item.insertedBattery.empty = false; } EverHeld |= item.isHeld || item.isPocketed; if (Releasing) { Silence(); } if (NetworkManager.Singleton.IsServer && !Releasing && ((EverHeld && !item.isHeld && !item.isPocketed) || (!EverHeld && Time.realtimeSinceStartup - Born > 10f))) { Service.Revoke(((NetworkBehaviour)item).NetworkObjectId); } } } internal void Silence() { GrabbableObject obj = item; FlashlightItem val = (FlashlightItem)(object)((obj is FlashlightItem) ? obj : null); if ((Object)(object)val != (Object)null) { val.SwitchFlashlight(false); ((Behaviour)val.flashlightBulb).enabled = false; ((Behaviour)val.flashlightBulbGlow).enabled = false; } if ((Object)(object)item != (Object)null) { item.EnableItemMeshes(false); } Collider[] componentsInChildren = ((Component)this).GetComponentsInChildren<Collider>(); for (int i = 0; i < componentsInChildren.Length; i++) { componentsInChildren[i].enabled = false; } } } public sealed class Service : MonoBehaviour { private const string RequestMessage = "hjm.infinity.request.v1"; private const string GrantMessage = "hjm.infinity.grant.v1"; private const string ReleaseMessage = "hjm.infinity.release.v1"; private const string ClearMessage = "hjm.infinity.clear.v1"; private static Service instance; private NetworkManager network; private readonly LeaseLedger ledger = new LeaseLedger(); private readonly Dictionary<ulong, ulong> objects = new Dictionary<ulong, ulong>(); internal static GrabbableObject PendingGrab; public static void Ensure() { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Expected O, but got Unknown if (!((Object)(object)instance != (Object)null)) { GameObject val = new GameObject("HJM_InfinityLight_Service"); Object.DontDestroyOnLoad((Object)val); instance = val.AddComponent<Service>(); } } private void Update() { //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Expected O, but got Unknown //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Expected O, but got Unknown //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Expected O, but got Unknown //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Expected O, but got Unknown NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)singleton == (Object)null || !singleton.IsListening || singleton.CustomMessagingManager == null) { if ((Object)(object)network != (Object)null) { Unhook(); } network = null; return; } if ((Object)(object)singleton != (Object)(object)network) { Unhook(); network = singleton; if ((Object)(object)network != (Object)null) { network.CustomMessagingManager.RegisterNamedMessageHandler("hjm.infinity.request.v1", new HandleNamedMessageDelegate(OnRequest)); network.CustomMessagingManager.RegisterNamedMessageHandler("hjm.infinity.grant.v1", new HandleNamedMessageDelegate(OnGrant)); network.CustomMessagingManager.RegisterNamedMessageHandler("hjm.infinity.release.v1", new HandleNamedMessageDelegate(OnRelease)); network.CustomMessagingManager.RegisterNamedMessageHandler("hjm.infinity.clear.v1", new HandleNamedMessageDelegate(OnClear)); } } if ((Object)(object)network == (Object)null || !network.IsListening || !network.IsServer) { return; } KeyValuePair<ulong, ulong>[] array = objects.ToArray(); for (int i = 0; i < array.Length; i++) { KeyValuePair<ulong, ulong> keyValuePair = array[i]; PlayerControllerB val = Player(keyValuePair.Value); if ((Object)(object)val == (Object)null || !val.isPlayerControlled || val.isPlayerDead || !network.SpawnManager.SpawnedObjects.ContainsKey(keyValuePair.Key)) { Revoke(keyValuePair.Key); } } } private void Unhook() { if ((Object)(object)network != (Object)null && network.CustomMessagingManager != null) { string[] array = new string[4] { "hjm.infinity.request.v1", "hjm.infinity.grant.v1", "hjm.infinity.release.v1", "hjm.infinity.clear.v1" }; foreach (string text in array) { network.CustomMessagingManager.UnregisterNamedMessageHandler(text); } } ledger.Clear(); objects.Clear(); PendingGrab = null; } private void OnDestroy() { Unhook(); if ((Object)(object)instance == (Object)(object)this) { instance = null; } } private PlayerControllerB Player(ulong client) { if (!((Object)(object)StartOfRound.Instance == (Object)null)) { return ((IEnumerable<PlayerControllerB>)StartOfRound.Instance.allPlayerScripts).FirstOrDefault((Func<PlayerControllerB, bool>)((PlayerControllerB p) => (Object)(object)p != (Object)null && p.actualClientId == client && p.isPlayerControlled)); } return null; } private unsafe static void Send(string message, ulong recipient, ulong objectId) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) FastBufferWriter val = default(FastBufferWriter); ((FastBufferWriter)(ref val))..ctor(8, (Allocator)2, -1); try { ((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref objectId, default(ForPrimitives)); NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage(message, recipient, val, (NetworkDelivery)3); } finally { ((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose(); } } public static void Request(GrabbableObject source) { Ensure(); if ((Object)(object)NetworkManager.Singleton == (Object)null || !NetworkManager.Singleton.IsListening) { return; } PlayerControllerB val = (((Object)(object)GameNetworkManager.Instance == (Object)null) ? null : GameNetworkManager.Instance.localPlayerController); if (!((Object)(object)val == (Object)null) && !val.isPlayerDead) { if ((Object)(object)val.ItemOnlySlot != (Object)null) { FullToolSlot(val); } else { Send("hjm.infinity.request.v1", 0uL, ((NetworkBehaviour)source).NetworkObjectId); } } } private static void FullToolSlot(PlayerControllerB player) { GrabbableObject val = (((Object)(object)player == (Object)null) ? null : player.ItemOnlySlot); string text = (((Object)(object)val != (Object)null && (Object)(object)val.itemProperties != (Object)null) ? val.itemProperties.itemName : "其他物品"); if ((Object)(object)HUDManager.Instance != (Object)null) { HUDManager.Instance.DisplayTip("工具栏已满", "工具栏已有“" + text + "”。请先腾出工具栏,再领取无尽手电筒。", false, false, "LC_Tip1"); } } private void OnRequest(ulong sender, FastBufferReader reader) { //IL_002d: 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_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_0177: Unknown result type (might be due to invalid IL or missing references) //IL_017c: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_0186: Unknown result type (might be due to invalid IL or missing references) if (!network.IsServer || !Content.Ready || ((FastBufferReader)(ref reader)).Length - ((FastBufferReader)(ref reader)).Position != 8) { return; } ulong key = default(ulong); ((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref key, default(ForPrimitives)); if (!network.SpawnManager.SpawnedObjects.TryGetValue(key, out var value)) { return; } GrabbableObject component = ((Component)value).GetComponent<GrabbableObject>(); LightMarker component2 = ((Component)value).GetComponent<LightMarker>(); PlayerControllerB val = Player(sender); if ((Object)(object)component == (Object)null || (Object)(object)component2 == (Object)null || component2.IsVirtual || (Object)(object)val == (Object)null || !ledger.CanRequest(sender, Time.realtimeSinceStartup, network.ConnectedClientsIds.Contains(sender), !val.isPlayerDead, !component.isHeld || (Object)(object)component.playerHeldBy == (Object)(object)val, (Object)(object)val.ItemOnlySlot == (Object)null, Vector3.Distance(((Component)val).transform.position, ((Component)component).transform.position))) { return; } if (ledger.TryGet(sender, out var objectId)) { if (network.SpawnManager.SpawnedObjects.TryGetValue(objectId, out var value2)) { LightMarker component3 = ((Component)value2).GetComponent<LightMarker>(); if ((Object)(object)component3 != (Object)null && !component3.EverHeld && Time.realtimeSinceStartup - component3.Born < 8f) { return; } } Revoke(objectId); } GameObject obj = Object.Instantiate<GameObject>(Content.VirtualItem.spawnPrefab, ((Component)val).transform.position + Vector3.up, Quaternion.identity); NetworkObject component4 = obj.GetComponent<NetworkObject>(); obj.GetComponent<LightMarker>().IntendedOwner = sender; component4.Spawn(false); if (!ledger.Reserve(sender, component4.NetworkObjectId)) { component4.Despawn(true); return; } objects.Add(component4.NetworkObjectId, sender); Send("hjm.infinity.grant.v1", sender, component4.NetworkObjectId); } private void OnGrant(ulong sender, FastBufferReader reader) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) if (sender == 0L && ((FastBufferReader)(ref reader)).Length - ((FastBufferReader)(ref reader)).Position == 8) { ulong id = default(ulong); ((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref id, default(ForPrimitives)); ((MonoBehaviour)this).StartCoroutine(ReceiveGrant(id)); } } private IEnumerator ReceiveGrant(ulong id) { float until = Time.realtimeSinceStartup + 8f; NetworkObject value; while (!network.SpawnManager.SpawnedObjects.TryGetValue(id, out value)) { if (Time.realtimeSinceStartup > until) { yield break; } yield return null; } GrabbableObject item = ((Component)value).GetComponent<GrabbableObject>(); PlayerControllerB player = GameNetworkManager.Instance.localPlayerController; if ((Object)(object)item == (Object)null || (Object)(object)player == (Object)null || (Object)(object)player.ItemOnlySlot != (Object)null || player.isPlayerDead) { if ((Object)(object)player != (Object)null && !player.isPlayerDead && (Object)(object)player.ItemOnlySlot != (Object)null) { FullToolSlot(player); } Send("hjm.infinity.release.v1", 0uL, id); yield break; } PendingGrab = item; try { AccessTools.Method(typeof(PlayerControllerB), "BeginGrabObject", (Type[])null, (Type[])null).Invoke(player, null); } finally { PendingGrab = null; } until = Time.realtimeSinceStartup + 8f; while ((Object)(object)player.ItemOnlySlot != (Object)(object)item || !((NetworkBehaviour)item).IsOwner || player.isGrabbingObjectAnimation) { if ((Object)(object)item == (Object)null || player.isPlayerDead || Time.realtimeSinceStartup > until) { yield break; } yield return null; } yield return null; if (!item.isBeingUsed) { item.UseItemOnClient(true); } } public static bool PrepareGrant(PlayerControllerB player) { if ((Object)(object)PendingGrab == (Object)null || !((NetworkBehaviour)player).IsOwner) { return false; } AccessTools.Field(typeof(PlayerControllerB), "currentlyGrabbingObject").SetValue(player, PendingGrab); return true; } public static void Dropped(GrabbableObject item) { LightMarker component = ((Component)item).GetComponent<LightMarker>(); if (!((Object)(object)component == (Object)null) && component.IsVirtual && !component.Releasing) { component.Releasing = true; component.Silence(); if ((Object)(object)instance != (Object)null && (NetworkManager.Singleton.IsServer || ((NetworkBehaviour)item).IsOwner)) { ((MonoBehaviour)instance).StartCoroutine(instance.ReleaseAfterNativeDrop(((NetworkBehaviour)item).NetworkObjectId)); } } } private IEnumerator ReleaseAfterNativeDrop(ulong id) { yield return null; if (!((Object)(object)network == (Object)null) && network.IsListening) { if (network.IsServer) { Revoke(id); } else { Send("hjm.infinity.release.v1", 0uL, id); } } } private void OnRelease(ulong sender, FastBufferReader reader) { //IL_0026: 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 (network.IsServer && ((FastBufferReader)(ref reader)).Length - ((FastBufferReader)(ref reader)).Position == 8) { ulong num = default(ulong); ((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref num, default(ForPrimitives)); if (ledger.Owns(sender, num)) { Revoke(num); } } } public static void Revoke(ulong id) { if ((Object)(object)instance == (Object)null || (Object)(object)instance.network == (Object)null || !instance.network.IsServer || !instance.objects.TryGetValue(id, out var value)) { return; } instance.objects.Remove(id); instance.ledger.Release(value, id); foreach (ulong connectedClientsId in instance.network.ConnectedClientsIds) { Send("hjm.infinity.clear.v1", connectedClientsId, id); } ((MonoBehaviour)instance).StartCoroutine(instance.Despawn(id)); } private IEnumerator Despawn(ulong id) { yield return (object)new WaitForSecondsRealtime(0.15f); if ((Object)(object)network != (Object)null && network.IsServer && network.SpawnManager.SpawnedObjects.TryGetValue(id, out var value)) { value.Despawn(true); } } private void OnClear(ulong sender, FastBufferReader reader) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) if (sender != 0L || ((FastBufferReader)(ref reader)).Length - ((FastBufferReader)(ref reader)).Position != 8) { return; } ulong key = default(ulong); ((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref key, default(ForPrimitives)); if (!network.SpawnManager.SpawnedObjects.TryGetValue(key, out var value)) { return; } GrabbableObject component = ((Component)value).GetComponent<GrabbableObject>(); LightMarker component2 = ((Component)value).GetComponent<LightMarker>(); if ((Object)(object)component == (Object)null || (Object)(object)component2 == (Object)null || !component2.IsVirtual) { return; } component2.Releasing = true; component2.Silence(); PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts; foreach (PlayerControllerB val in allPlayerScripts) { if ((Object)(object)val == (Object)null) { continue; } if ((Object)(object)val.ItemOnlySlot == (Object)(object)component) { val.ItemOnlySlot = null; ((Behaviour)val.helmetLight).enabled = false; } if ((Object)(object)val.currentlyHeldObjectServer == (Object)(object)component) { val.currentlyHeldObjectServer = null; val.isHoldingObject = false; val.twoHanded = false; ((Behaviour)val.helmetLight).enabled = false; if (((NetworkBehaviour)val).IsOwner) { AccessTools.Method(typeof(PlayerControllerB), "SwitchToItemSlot", (Type[])null, (Type[])null).Invoke(val, new object[2] { 0, null }); } } } } } [HarmonyPatch] public static class Patches { [HarmonyPatch(typeof(Terminal), "TextPostProcess")] [HarmonyPostfix] [HarmonyPriority(0)] private static void ShopPurchaseHint(ref string __result) { __result = InteractionHints.ShopText(__result); } [HarmonyPatch(typeof(Terminal), "Awake")] [HarmonyPostfix] private static void EnglishShopAliases(Terminal __instance) { //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Expected O, but got Unknown if (!Content.Ready || (Object)(object)__instance.terminalNodes == (Object)null) { return; } List<TerminalKeyword> list = __instance.terminalNodes.allKeywords.ToList(); TerminalKeyword val = ((IEnumerable<TerminalKeyword>)list).FirstOrDefault((Func<TerminalKeyword, bool>)((TerminalKeyword k) => (Object)(object)k != (Object)null && k.word == Content.SourceItem.itemName.ToLowerInvariant().Replace(" ", ""))); if ((Object)(object)val == (Object)null) { return; } string[] array = new string[2] { "infinity", "infinityflashlight" }; foreach (string name in array) { if (list.Any((TerminalKeyword k) => (Object)(object)k != (Object)null && k.word == name)) { continue; } TerminalKeyword val2 = Object.Instantiate<TerminalKeyword>(val); ((Object)val2).name = "HJM_" + name; val2.word = name; TerminalKeyword[] array2 = list.ToArray(); foreach (TerminalKeyword val3 in array2) { if ((Object)(object)val3 == (Object)null || val3.compatibleNouns == null) { continue; } List<CompatibleNoun> list2 = val3.compatibleNouns.ToList(); CompatibleNoun[] compatibleNouns = val3.compatibleNouns; foreach (CompatibleNoun val4 in compatibleNouns) { if ((Object)(object)val4.noun == (Object)(object)val) { list2.Add(new CompatibleNoun(val2, val4.result)); } } val3.compatibleNouns = list2.ToArray(); } list.Add(val2); } __instance.terminalNodes.allKeywords = list.ToArray(); } public static GrabbableObject[] PersistentOnly(GrabbableObject[] items) { return items.Where((GrabbableObject item) => (Object)(object)item != (Object)null && (Object)(object)item.itemProperties != (Object)(object)Content.VirtualItem).ToArray(); } [HarmonyPatch(typeof(GameNetworkManager), "SaveItemsInShip")] [HarmonyTranspiler] private static IEnumerable<CodeInstruction> ExcludeVirtualFromSave(IEnumerable<CodeInstruction> source) { bool found = false; foreach (CodeInstruction instruction in source) { yield return instruction; MethodInfo methodInfo = instruction.operand as MethodInfo; if (methodInfo != null && (methodInfo.Name == "FindObjectsByType" || methodInfo.Name == "FindObjectsOfType") && methodInfo.IsGenericMethod && methodInfo.GetGenericArguments()[0] == typeof(GrabbableObject)) { found = true; yield return new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(Patches), "PersistentOnly", (Type[])null, (Type[])null)); } } if (!found) { throw new MissingMethodException("SaveItemsInShip enumeration changed; cannot guarantee ephemeral item exclusion."); } } [HarmonyPatch(typeof(PlayerControllerB), "GrabObjectServerRpc")] [HarmonyPrefix] private static bool ValidateVirtualOwner(PlayerControllerB __instance, [HarmonyArgument(0)] NetworkObjectReference grabbedObject) { //IL_0077: Unknown result type (might be due to invalid IL or missing references) NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)singleton == (Object)null || !singleton.IsServer) { return true; } NetworkObject val = default(NetworkObject); if (!((NetworkObjectReference)(ref grabbedObject)).TryGet(ref val, singleton)) { return true; } LightMarker component = ((Component)val).GetComponent<LightMarker>(); if ((Object)(object)component == (Object)null || !component.IsVirtual || component.IntendedOwner == __instance.actualClientId) { return true; } AccessTools.Method(typeof(PlayerControllerB), "GrabObjectClientRpc", (Type[])null, (Type[])null).Invoke(__instance, new object[2] { false, grabbedObject }); return false; } [HarmonyPatch(typeof(GameNetworkManager), "Start")] [HarmonyPrefix] private static void Register() { Service.Ensure(); } [HarmonyPatch(typeof(StartOfRound), "Awake")] [HarmonyPrefix] private static void RegisterSceneItems(StartOfRound __instance) { try { Content.Register(__instance.allItemsList.itemsList); } catch (Exception ex) { Plugin.Log.LogError((object)("Infinity item setup failed; preserving vanilla scene initialization. " + ex)); } Service.Ensure(); } [HarmonyPatch(typeof(PlayerControllerB), "BeginGrabObject")] [HarmonyTranspiler] private static IEnumerable<CodeInstruction> GrantGrab(IEnumerable<CodeInstruction> source, ILGenerator generator) { List<CodeInstruction> code = source.ToList(); int num = code.FindIndex((CodeInstruction i) => i.opcode == OpCodes.Stfld && i.operand as FieldInfo != null && ((FieldInfo)i.operand).Name == "currentlyGrabbingObject"); if (num < 0 || num + 1 >= code.Count) { throw new MissingFieldException("BeginGrabObject shape changed"); } Label granted = generator.DefineLabel(); code[num + 1].labels.Add(granted); yield return new CodeInstruction(OpCodes.Ldarg_0, (object)null); yield return new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(Service), "PrepareGrant", (Type[])null, (Type[])null)); yield return new CodeInstruction(OpCodes.Brtrue, (object)granted); foreach (CodeInstruction item in code) { yield return item; } } [HarmonyPatch(typeof(PlayerControllerB), "FirstEmptyItemSlot")] [HarmonyPrefix] private static bool ToolSlot(PlayerControllerB __instance, [HarmonyArgument(0)] GrabbableObject itemToGrab, ref int __result) { if ((Object)(object)itemToGrab == (Object)null || (Object)(object)itemToGrab.itemProperties != (Object)(object)Content.VirtualItem) { return true; } __result = (((Object)(object)__instance.ItemOnlySlot == (Object)null) ? 50 : (-1)); return false; } [HarmonyPatch(typeof(FlashlightItem), "ItemActivate")] [HarmonyPrefix] private static bool Activate(FlashlightItem __instance) { if ((Object)(object)((GrabbableObject)__instance).itemProperties != (Object)(object)Content.SourceItem) { return true; } ((GrabbableObject)__instance).isBeingUsed = false; if (((NetworkBehaviour)__instance).IsOwner) { Service.Request((GrabbableObject)(object)__instance); } return false; } [HarmonyPatch(typeof(FlashlightItem), "DiscardItem")] [HarmonyPostfix] private static void Drop(FlashlightItem __instance) { if ((Object)(object)((GrabbableObject)__instance).itemProperties == (Object)(object)Content.VirtualItem) { Service.Dropped((GrabbableObject)(object)__instance); } } } public static class InteractionHints { public static string ShopText(string text) { if (string.IsNullOrEmpty(text)) { return text; } return Regex.Replace(text, "(?m)^(\\s*\\*\\s*无尽手电筒)([ \\t]*//)", "$1 (Infinity)$2"); } } public sealed class LeaseLedger { private readonly Dictionary<ulong, ulong> leases = new Dictionary<ulong, ulong>(); public bool CanRequest(ulong client, double now, bool connected, bool alive, bool sourceAvailable, bool toolSlotEmpty, double distance) { if (connected && alive && sourceAvailable && toolSlotEmpty && !double.IsNaN(distance) && distance >= 0.0) { return distance <= 3.25; } return false; } public bool Reserve(ulong client, ulong objectId) { if (leases.ContainsKey(client)) { return false; } leases.Add(client, objectId); return true; } public bool Owns(ulong client, ulong objectId) { if (leases.TryGetValue(client, out var value)) { return value == objectId; } return false; } public bool TryGet(ulong client, out ulong objectId) { return leases.TryGetValue(client, out objectId); } public bool Release(ulong client, ulong objectId) { if (!Owns(client, objectId)) { return false; } leases.Remove(client); return true; } public void Clear() { leases.Clear(); } } public sealed class StarSurface : MonoBehaviour { private static Texture2D surface; private static Texture2D stars; private readonly List<Material> owned = new List<Material>(); private readonly List<Material> instances = new List<Material>(); private static void BuildTextures() { //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_02ad: Unknown result type (might be due to invalid IL or missing references) //IL_02b7: Expected O, but got Unknown //IL_0300: Unknown result type (might be due to invalid IL or missing references) //IL_030a: Expected O, but got Unknown //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_01bc: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Unknown result type (might be due to invalid IL or missing references) //IL_01d5: Unknown result type (might be due to invalid IL or missing references) //IL_01da: Unknown result type (might be due to invalid IL or missing references) //IL_0208: Unknown result type (might be due to invalid IL or missing references) //IL_020d: Unknown result type (might be due to invalid IL or missing references) //IL_0249: Unknown result type (might be due to invalid IL or missing references) //IL_024e: Unknown result type (might be due to invalid IL or missing references) //IL_0284: Unknown result type (might be due to invalid IL or missing references) //IL_0289: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)surface != (Object)null && (Object)(object)stars != (Object)null) { return; } Color[] array = (Color[])(object)new Color[16384]; Color[] array2 = (Color[])(object)new Color[16384]; Random random = new Random(624853); for (int i = 0; i < array.Length; i++) { float num = (float)random.NextDouble() * 0.008f; float num2 = (float)(i % 128) / 128f; float num3 = (float)(i / 128) / 128f; Color val = Color.HSVToRGB(Mathf.Repeat(num2 * 0.75f + num3 * 0.35f, 1f), 0.65f, 1f); float num4 = Mathf.Pow(0.5f + 0.5f * Mathf.Sin((num2 * 2f + num3) * (float)Math.PI * 2f), 12f) * 0.07f; array[i] = new Color(0.04f + num + val.r * num4, 0.045f + num + val.g * num4, 0.064f + num + val.b * num4, 1f); array2[i] = Color.black; } for (int j = 0; j < 240; j++) { int num5 = random.Next(128); int num6 = random.Next(128); float num7 = 0.2f + (float)random.NextDouble() * 0.7f; Color val2 = (Color)((j % 3 == 0) ? Color.HSVToRGB((float)random.NextDouble(), 0.48f, 1f) : new Color(0.86f, 0.93f, 1f)); array2[num6 * 128 + num5] = new Color(val2.r * num7, val2.g * num7, val2.b * num7, 1f); array[num6 * 128 + num5] = new Color(num7 * 0.22f, num7 * 0.23f, num7 * 0.26f, 1f); if (j % 8 == 0) { array2[num6 * 128 + (num5 + 1) % 128] = new Color(num7 * 0.16f, num7 * 0.18f, num7 * 0.2f, 1f); array2[(num6 + 1) % 128 * 128 + num5] = new Color(num7 * 0.16f, num7 * 0.18f, num7 * 0.2f, 1f); } } surface = new Texture2D(128, 128, (TextureFormat)4, true, true); ((Object)surface).name = "HJM_Infinity_Original_DarkMetal"; ((Texture)surface).wrapMode = (TextureWrapMode)0; ((Texture)surface).filterMode = (FilterMode)1; surface.SetPixels(array); surface.Apply(true, true); stars = new Texture2D(128, 128, (TextureFormat)4, true, true); ((Object)stars).name = "HJM_Infinity_Original_FlowingStars"; ((Texture)stars).wrapMode = (TextureWrapMode)0; ((Texture)stars).filterMode = (FilterMode)1; stars.SetPixels(array2); stars.Apply(true, true); } private void Start() { //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_0221: Unknown result type (might be due to invalid IL or missing references) BuildTextures(); FlashlightItem component = ((Component)this).GetComponent<FlashlightItem>(); MeshRenderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<MeshRenderer>(); foreach (MeshRenderer val in componentsInChildren) { if ((Object)(object)((Component)val).GetComponentInParent<ScanNodeProperties>() != (Object)null) { continue; } Material[] materials = ((Renderer)val).materials; for (int j = 0; j < materials.Length; j++) { Material val2 = materials[j]; instances.Add(val2); if ((Object)(object)component != (Object)null && (Object)(object)val == (Object)(object)component.flashlightMesh && j == 1) { continue; } string text = ((Object)val2).name.ToLowerInvariant(); if (text.Contains("glass") || text.Contains("lens") || text.Contains("bulb") || (!val2.HasProperty("_BaseColorMap") && !val2.HasProperty("_MainTex"))) { continue; } if (val2.HasProperty("_BaseColorMap")) { val2.SetTexture("_BaseColorMap", (Texture)(object)surface); } if (val2.HasProperty("_MainTex")) { val2.SetTexture("_MainTex", (Texture)(object)surface); } if (val2.HasProperty("_BaseColor")) { val2.SetColor("_BaseColor", Color.white); } if (val2.HasProperty("_Metallic")) { val2.SetFloat("_Metallic", 0.4f); } if (val2.HasProperty("_Smoothness")) { val2.SetFloat("_Smoothness", 0.55f); } if (val2.HasProperty("_EmissiveColorMap")) { val2.SetTexture("_EmissiveColorMap", (Texture)(object)stars); val2.EnableKeyword("_EMISSIVE_COLOR_MAP"); if (val2.HasProperty("_AlbedoAffectEmissive")) { val2.SetFloat("_AlbedoAffectEmissive", 0f); } if (val2.HasProperty("_UseEmissiveIntensity")) { val2.SetFloat("_UseEmissiveIntensity", 0f); } if (val2.HasProperty("_UVEmissive")) { val2.SetFloat("_UVEmissive", 0f); } if (val2.HasProperty("_UVMappingMaskEmissive")) { val2.SetVector("_UVMappingMaskEmissive", new Vector4(1f, 0f, 0f, 0f)); } val2.DisableKeyword("_EMISSIVE_MAPPING_BASE"); val2.DisableKeyword("_EMISSIVE_MAPPING_PLANAR"); val2.DisableKeyword("_EMISSIVE_MAPPING_TRIPLANAR"); if (val2.HasProperty("_EmissiveExposureWeight")) { val2.SetFloat("_EmissiveExposureWeight", 0f); } } if (val2.HasProperty("_EmissionMap")) { val2.SetTexture("_EmissionMap", (Texture)(object)stars); val2.EnableKeyword("_EMISSION"); } owned.Add(val2); } } } private void Update() { //IL_007c: 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_00cd: 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) float realtimeSinceStartup = Time.realtimeSinceStartup; float num = 0.75f + Mathf.Sin(realtimeSinceStartup * 0.43f) * 0.08f; Vector2 val = default(Vector2); ((Vector2)(ref val))..ctor(realtimeSinceStartup * 0.006f % 1f, realtimeSinceStartup * 0.002f % 1f); Color val2 = default(Color); foreach (Material item in owned) { if (!((Object)(object)item == (Object)null)) { if (item.HasProperty("_EmissiveColorMap")) { item.SetTextureOffset("_EmissiveColorMap", val); } if (item.HasProperty("_EmissionMap")) { item.SetTextureOffset("_EmissionMap", val); } ((Color)(ref val2))..ctor(num * 0.9f, num * 0.95f, num, 1f); if (item.HasProperty("_EmissiveColor")) { item.SetColor("_EmissiveColor", val2); } if (item.HasProperty("_EmissionColor")) { item.SetColor("_EmissionColor", val2); } } } } private void OnDestroy() { foreach (Material instance in instances) { if ((Object)(object)instance != (Object)null) { Object.Destroy((Object)(object)instance); } } instances.Clear(); owned.Clear(); } } }