using 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 BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using PlayerFlashlight.Configuration; using PlayerFlashlight.Localization; using PlayerFlashlight.Utils; using TMPro; using Unity.Collections; using Unity.Netcode; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.InputSystem; using UnityEngine.Localization; using UnityEngine.Localization.Settings; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("PlayerFlashlight")] [assembly: AssemblyDescription("PlayerFlashlight mod for Old Market Simulator by Ice Box Studio")] [assembly: AssemblyCompany("Ice Box Studio")] [assembly: AssemblyProduct("PlayerFlashlight")] [assembly: AssemblyCopyright("Copyright © 2025 Ice Box Studio All rights reserved.")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("C4F63A97-92D1-4D0B-A2BD-56A1B5706A9B")] [assembly: AssemblyFileVersion("1.0.2.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.0.2.0")] namespace PlayerFlashlight { [BepInPlugin("IceBoxStudio.PlayerFlashlight", "PlayerFlashlight", "1.0.2")] public class PlayerFlashlight : BaseUnityPlugin { private static PlayerFlashlight _instance; private Harmony _harmony; private bool patchesApplied; public static PlayerFlashlight Instance => _instance; internal static ManualLogSource Logger { get; private set; } private void Awake() { _instance = this; Logger = ((BaseUnityPlugin)this).Logger; try { Logger.LogInfo((object)"============================================="); Logger.LogInfo((object)("PlayerFlashlight " + LocalizationManager.Instance.GetLocalizedText("plugin.initializing"))); Logger.LogInfo((object)(LocalizationManager.Instance.GetLocalizedText("plugin.author_prefix") + "Ice Box Studio(https://steamcommunity.com/id/ibox666/)")); ConfigManager.Initialize(((BaseUnityPlugin)this).Config); ApplyPatches(); Logger.LogInfo((object)("PlayerFlashlight " + LocalizationManager.Instance.GetLocalizedText("plugin.initialized"))); Logger.LogInfo((object)"============================================="); } catch (Exception ex) { Logger.LogError((object)("PlayerFlashlight 初始化错误: " + ex.Message + "\n" + ex.StackTrace)); } } private void ApplyPatches() { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Expected O, but got Unknown if (!patchesApplied) { try { _harmony = new Harmony("IceBoxStudio.PlayerFlashlight"); _harmony.PatchAll(); patchesApplied = true; return; } catch (Exception ex) { Logger.LogError((object)("PlayerFlashlight 应用补丁错误: " + ex.Message + "\n" + ex.StackTrace)); return; } } Logger.LogInfo((object)LocalizationManager.Instance.GetLocalizedText("plugin.patches_skipped")); } } public static class PluginInfo { public const string PLUGIN_GUID = "IceBoxStudio.PlayerFlashlight"; public const string PLUGIN_NAME = "PlayerFlashlight"; public const string PLUGIN_VERSION = "1.0.2"; public const string PLUGIN_AUTHOR = "Ice Box Studio"; public const string PLUGIN_DESCRIPTION = "手电在手,天下我有。"; } } namespace PlayerFlashlight.Utils { public static class FlashlightManager { private const string TOGGLE_SOUND_NAME = "Pop sounds 18"; private static AudioClip _toggleClip; private const string MESSAGE_TOGGLE = "PlayerFlashlight_Toggle"; private const string MESSAGE_SYNC = "PlayerFlashlight_Sync"; private const string MESSAGE_ORIENTATION = "PlayerFlashlight_Orientation"; private const string MESSAGE_ORIENTATION_SYNC = "PlayerFlashlight_OrientationSync"; private static readonly Dictionary _states = new Dictionary(); private static readonly Dictionary _lights = new Dictionary(); private static readonly Dictionary _lightsByClient = new Dictionary(); private static readonly Dictionary _userToClient = new Dictionary(); private static readonly Dictionary _rotations = new Dictionary(); private static readonly Dictionary _predictedClientStates = new Dictionary(); public static void RegisterMessageHandlers() { //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Expected O, but got Unknown //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Expected O, but got Unknown //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Expected O, but got Unknown //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Expected O, but got Unknown NetworkManager singleton = NetworkManager.Singleton; if (!((Object)(object)singleton == (Object)null)) { singleton.CustomMessagingManager.RegisterNamedMessageHandler("PlayerFlashlight_Toggle", new HandleNamedMessageDelegate(OnToggleMessageReceived)); singleton.CustomMessagingManager.RegisterNamedMessageHandler("PlayerFlashlight_Sync", new HandleNamedMessageDelegate(OnSyncMessageReceived)); singleton.CustomMessagingManager.RegisterNamedMessageHandler("PlayerFlashlight_Orientation", new HandleNamedMessageDelegate(OnOrientationMessageReceived)); singleton.CustomMessagingManager.RegisterNamedMessageHandler("PlayerFlashlight_OrientationSync", new HandleNamedMessageDelegate(OnOrientationSyncReceived)); singleton.OnClientConnectedCallback -= OnClientConnected; singleton.OnClientConnectedCallback += OnClientConnected; singleton.OnClientDisconnectCallback -= OnClientDisconnected; singleton.OnClientDisconnectCallback += OnClientDisconnected; } } public static void SendToggle() { //IL_005d: Unknown result type (might be due to invalid IL or missing references) NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)singleton == (Object)null || !singleton.IsListening) { return; } if (singleton.IsServer || singleton.IsHost) { HandleToggleOnServer(singleton.LocalClientId); BroadcastSync(ulong.MaxValue); PlayToggleSoundForClient(singleton.LocalClientId); return; } FastBufferWriter val = default(FastBufferWriter); ((FastBufferWriter)(ref val))..ctor(0, (Allocator)2, -1); try { singleton.CustomMessagingManager.SendNamedMessage("PlayerFlashlight_Toggle", 0uL, val, (NetworkDelivery)3); } finally { ((IDisposable)(FastBufferWriter)(ref val)).Dispose(); } EnsureLightForClient(singleton.LocalClientId); bool flag = true; if (_lightsByClient.TryGetValue(singleton.LocalClientId, out var value) && (Object)(object)value != (Object)null) { flag = !((Behaviour)value).enabled; ApplyLightStateByClientId(singleton.LocalClientId, flag); } _predictedClientStates[singleton.LocalClientId] = flag; PlayToggleSoundForClient(singleton.LocalClientId); } private static void OnClientConnected(ulong clientId) { NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)singleton != (Object)null && (singleton.IsServer || singleton.IsHost)) { BroadcastSync(clientId); BroadcastAllOrientations(clientId); } } private static void OnClientDisconnected(ulong clientId) { ulong? num = GetUserIdByClientId(clientId) ?? FindCachedUserIdByClientId(clientId); Light value; if (num.HasValue) { RemoveUserState(num.Value); } else if (_lightsByClient.TryGetValue(clientId, out value)) { if ((Object)(object)value != (Object)null) { Object.Destroy((Object)(object)((Component)value).gameObject); } _lightsByClient.Remove(clientId); } _predictedClientStates.Remove(clientId); NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)singleton != (Object)null && (singleton.IsServer || singleton.IsHost)) { BroadcastSync(ulong.MaxValue); } } private static void HandleToggleOnServer(ulong senderClientId) { ulong? userIdByClientId = GetUserIdByClientId(senderClientId); if (userIdByClientId.HasValue) { bool value; bool flag = !_states.TryGetValue(userIdByClientId.Value, out value) || !value; _states[userIdByClientId.Value] = flag; EnsureLight(userIdByClientId.Value); ApplyLightState(userIdByClientId.Value, flag); } } private static void BroadcastSync(ulong targetClientId = ulong.MaxValue) { //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0085: 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_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009d: 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_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)singleton == (Object)null || !singleton.IsListening) { return; } FastBufferWriter val = default(FastBufferWriter); ((FastBufferWriter)(ref val))..ctor(4 + _states.Count * 17, (Allocator)2, -1); try { int count = _states.Count; ((FastBufferWriter)(ref val)).WriteValueSafe(ref count, default(ForPrimitives)); foreach (KeyValuePair state in _states) { ulong key = state.Key; ulong valueOrDefault = GetClientIdByUserId(key).GetValueOrDefault(); ((FastBufferWriter)(ref val)).WriteValueSafe(ref key, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe(ref valueOrDefault, default(ForPrimitives)); bool value = state.Value; ((FastBufferWriter)(ref val)).WriteValueSafe(ref value, default(ForPrimitives)); } if (targetClientId == ulong.MaxValue) { foreach (ulong connectedClientsId in singleton.ConnectedClientsIds) { singleton.CustomMessagingManager.SendNamedMessage("PlayerFlashlight_Sync", connectedClientsId, val, (NetworkDelivery)3); } return; } singleton.CustomMessagingManager.SendNamedMessage("PlayerFlashlight_Sync", targetClientId, val, (NetworkDelivery)3); } finally { ((IDisposable)(FastBufferWriter)(ref val)).Dispose(); } } private static void OnToggleMessageReceived(ulong senderClientId, FastBufferReader reader) { NetworkManager singleton = NetworkManager.Singleton; if (!((Object)(object)singleton == (Object)null) && singleton.IsListening && (singleton.IsServer || singleton.IsHost)) { HandleToggleOnServer(senderClientId); BroadcastSync(ulong.MaxValue); } } private static void OnSyncMessageReceived(ulong senderClientId, FastBufferReader reader) { //IL_000c: 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_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) //IL_0038: 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_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) HashSet hashSet = new HashSet(); int num = default(int); ((FastBufferReader)(ref reader)).ReadValueSafe(ref num, default(ForPrimitives)); ulong num2 = default(ulong); ulong num3 = default(ulong); bool flag = default(bool); for (int i = 0; i < num; i++) { ((FastBufferReader)(ref reader)).ReadValueSafe(ref num2, default(ForPrimitives)); ((FastBufferReader)(ref reader)).ReadValueSafe(ref num3, default(ForPrimitives)); ((FastBufferReader)(ref reader)).ReadValueSafe(ref flag, default(ForPrimitives)); hashSet.Add(num2); bool value; bool flag2 = _states.TryGetValue(num2, out value); if (_userToClient.TryGetValue(num2, out var value2) && value2 != num3) { RemoveUserState(num2); flag2 = false; value = false; } bool num4 = !flag2 || value != flag; _states[num2] = flag; _userToClient[num2] = num3; EnsureLightForClient(num3, num2); if (num4) { ApplyLightStateByClientId(num3, flag); } } List list = null; foreach (KeyValuePair state in _states) { if (!hashSet.Contains(state.Key)) { if (list == null) { list = new List(); } list.Add(state.Key); } } if (list != null) { for (int j = 0; j < list.Count; j++) { RemoveUserState(list[j]); } } } private static void EnsureLight(ulong userId) { //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Expected O, but got Unknown //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0175: 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_019e: Unknown result type (might be due to invalid IL or missing references) //IL_01a0: Unknown result type (might be due to invalid IL or missing references) //IL_01ab: Unknown result type (might be due to invalid IL or missing references) if (_lights.TryGetValue(userId, out var value) && (Object)(object)value != (Object)null) { return; } GameObject val = FindPlayerObjectByUserId(userId); if (!((Object)(object)val == (Object)null)) { Transform val2 = FindAttachPoint(val.transform); GameObject val3 = new GameObject("PlayerFlashlightLight"); val3.transform.SetParent(val2 ?? val.transform, false); Vector3 val4 = default(Vector3); ((Vector3)(ref val4))..ctor(0f, 0f, 0.25f); val3.transform.localPosition = val4; val3.transform.localRotation = Quaternion.identity; Light val5 = val3.AddComponent(); val5.type = (LightType)0; val5.intensity = Mathf.Max(0f, ConfigManager.Intensity.Value); val5.range = Mathf.Max(0.1f, ConfigManager.Range.Value); val5.spotAngle = Mathf.Clamp(ConfigManager.SpotAngle.Value, 1f, 170f); val5.color = Color.white; val5.shadows = ConfigManager.GetShadowMode(); ((Behaviour)val5).enabled = false; NetworkManager singleton = NetworkManager.Singleton; ulong? num = (((Object)(object)singleton != (Object)null) ? GetUserIdByClientId(singleton.LocalClientId) : null); FlashlightAligner flashlightAligner = val3.AddComponent(); flashlightAligner.AlignToCamera = num.HasValue && num.Value == userId; flashlightAligner.FollowPoint = val2 ?? val.transform; flashlightAligner.LocalOffset = val4; if (_rotations.TryGetValue(userId, out var value2) && !flashlightAligner.AlignToCamera) { flashlightAligner.UseRemoteRotation = true; flashlightAligner.RemoteRotation = value2; val3.transform.rotation = value2; } _lights[userId] = val5; ulong? clientIdByUserId = GetClientIdByUserId(userId); if (clientIdByUserId.HasValue) { _lightsByClient[clientIdByUserId.Value] = val5; _userToClient[userId] = clientIdByUserId.Value; } } } private static void ApplyLightState(ulong userId, bool on) { if (_lights.TryGetValue(userId, out var value) && (Object)(object)value != (Object)null) { ((Behaviour)value).enabled = on; } } private static GameObject FindPlayerObjectByUserId(ulong userId) { try { NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)singleton == (Object)null) { return null; } ulong? clientIdByUserId = GetClientIdByUserId(userId); if (!clientIdByUserId.HasValue) { return null; } if (singleton.ConnectedClients.TryGetValue(clientIdByUserId.Value, out var value)) { NetworkObject val = value?.PlayerObject; if ((Object)(object)val != (Object)null) { return ((Component)val).gameObject; } } HashSet hashSet = singleton.SpawnManager?.SpawnedObjectsList; if (hashSet == null) { return null; } foreach (NetworkObject item in hashSet) { if ((Object)(object)item != (Object)null && item.IsPlayerObject && item.OwnerClientId == clientIdByUserId.Value) { return ((Component)item).gameObject; } } } catch { } return null; } public static Light GetLightByClientId(ulong clientId) { _lightsByClient.TryGetValue(clientId, out var value); return value; } private static ulong? GetUserIdByClientId(ulong clientId) { //IL_0032: Unknown result type (might be due to invalid IL or missing references) try { GameManager instance = GameManager.Instance; if ((Object)(object)instance == (Object)null) { return null; } if (!instance.IsActivePlayer(clientId)) { return null; } return instance.GetPlayerFromClientId(clientId).userId; } catch { } return null; } private static Transform FindDeepChildByName(Transform parent, string targetName) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Expected O, but got Unknown if ((Object)(object)parent == (Object)null || string.IsNullOrEmpty(targetName)) { return null; } string text = targetName.ToLowerInvariant(); foreach (Transform item in parent) { Transform val = item; if (((Object)val).name != null && ((Object)val).name.ToLowerInvariant() == text) { return val; } Transform val2 = FindDeepChildByName(val, targetName); if ((Object)(object)val2 != (Object)null) { return val2; } } return null; } private static Transform FindAttachPoint(Transform root) { CustomCharacterController component = ((Component)root).GetComponent(); if ((Object)(object)component != (Object)null && (Object)(object)component.CameraFollowPoint != (Object)null) { return component.CameraFollowPoint; } return root; } public static void ReportLocalOrientation(Quaternion rot) { //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)singleton == (Object)null || !singleton.IsListening) { return; } if (singleton.IsServer || singleton.IsHost) { ulong? userIdByClientId = GetUserIdByClientId(singleton.LocalClientId); if (userIdByClientId.HasValue) { _rotations[userIdByClientId.Value] = rot; BroadcastOrientationToAll(userIdByClientId.Value, rot); } return; } FastBufferWriter val = default(FastBufferWriter); ((FastBufferWriter)(ref val))..ctor(16, (Allocator)2, -1); try { ((FastBufferWriter)(ref val)).WriteValueSafe(ref rot.x, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe(ref rot.y, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe(ref rot.z, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe(ref rot.w, default(ForPrimitives)); singleton.CustomMessagingManager.SendNamedMessage("PlayerFlashlight_Orientation", 0uL, val, (NetworkDelivery)3); } finally { ((IDisposable)(FastBufferWriter)(ref val)).Dispose(); } } private static void OnOrientationMessageReceived(ulong senderClientId, FastBufferReader reader) { //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_0042: 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) //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) //IL_0068: 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) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) NetworkManager singleton = NetworkManager.Singleton; if (!((Object)(object)singleton == (Object)null) && singleton.IsListening && (singleton.IsServer || singleton.IsHost)) { float num = default(float); ((FastBufferReader)(ref reader)).ReadValueSafe(ref num, default(ForPrimitives)); float num2 = default(float); ((FastBufferReader)(ref reader)).ReadValueSafe(ref num2, default(ForPrimitives)); float num3 = default(float); ((FastBufferReader)(ref reader)).ReadValueSafe(ref num3, default(ForPrimitives)); float num4 = default(float); ((FastBufferReader)(ref reader)).ReadValueSafe(ref num4, default(ForPrimitives)); Quaternion val = default(Quaternion); ((Quaternion)(ref val))..ctor(num, num2, num3, num4); ulong? userIdByClientId = GetUserIdByClientId(senderClientId); if (userIdByClientId.HasValue) { _rotations[userIdByClientId.Value] = val; BroadcastOrientationToAll(userIdByClientId.Value, val); } } } private static void OnOrientationSyncReceived(ulong senderClientId, FastBufferReader reader) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001f: 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) //IL_0032: 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_0045: 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) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) ulong key = default(ulong); ((FastBufferReader)(ref reader)).ReadValueSafe(ref key, default(ForPrimitives)); ulong clientId = default(ulong); ((FastBufferReader)(ref reader)).ReadValueSafe(ref clientId, default(ForPrimitives)); float num = default(float); ((FastBufferReader)(ref reader)).ReadValueSafe(ref num, default(ForPrimitives)); float num2 = default(float); ((FastBufferReader)(ref reader)).ReadValueSafe(ref num2, default(ForPrimitives)); float num3 = default(float); ((FastBufferReader)(ref reader)).ReadValueSafe(ref num3, default(ForPrimitives)); float num4 = default(float); ((FastBufferReader)(ref reader)).ReadValueSafe(ref num4, default(ForPrimitives)); Quaternion val = default(Quaternion); ((Quaternion)(ref val))..ctor(num, num2, num3, num4); _rotations[key] = val; ApplyOrientationToLightByClientId(clientId, val); } private static void BroadcastOrientationToAll(ulong userId, Quaternion rot) { //IL_0038: 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_004b: 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_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)singleton == (Object)null || !singleton.IsListening) { return; } FastBufferWriter val = default(FastBufferWriter); ((FastBufferWriter)(ref val))..ctor(32, (Allocator)2, -1); try { ulong valueOrDefault = GetClientIdByUserId(userId).GetValueOrDefault(); ((FastBufferWriter)(ref val)).WriteValueSafe(ref userId, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe(ref valueOrDefault, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe(ref rot.x, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe(ref rot.y, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe(ref rot.z, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe(ref rot.w, default(ForPrimitives)); foreach (ulong connectedClientsId in singleton.ConnectedClientsIds) { singleton.CustomMessagingManager.SendNamedMessage("PlayerFlashlight_OrientationSync", connectedClientsId, val, (NetworkDelivery)3); } } finally { ((IDisposable)(FastBufferWriter)(ref val)).Dispose(); } } private static void BroadcastAllOrientations(ulong targetClientId) { //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0074: 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_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: 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_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: 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_0111: Unknown result type (might be due to invalid IL or missing references) NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)singleton == (Object)null || !singleton.IsListening) { return; } FastBufferWriter val = default(FastBufferWriter); foreach (KeyValuePair rotation in _rotations) { ((FastBufferWriter)(ref val))..ctor(32, (Allocator)2, -1); try { ulong valueOrDefault = GetClientIdByUserId(rotation.Key).GetValueOrDefault(); ulong key = rotation.Key; ((FastBufferWriter)(ref val)).WriteValueSafe(ref key, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe(ref valueOrDefault, default(ForPrimitives)); Quaternion value = rotation.Value; ((FastBufferWriter)(ref val)).WriteValueSafe(ref value.x, default(ForPrimitives)); value = rotation.Value; ((FastBufferWriter)(ref val)).WriteValueSafe(ref value.y, default(ForPrimitives)); value = rotation.Value; ((FastBufferWriter)(ref val)).WriteValueSafe(ref value.z, default(ForPrimitives)); value = rotation.Value; ((FastBufferWriter)(ref val)).WriteValueSafe(ref value.w, default(ForPrimitives)); singleton.CustomMessagingManager.SendNamedMessage("PlayerFlashlight_OrientationSync", targetClientId, val, (NetworkDelivery)3); } finally { ((IDisposable)(FastBufferWriter)(ref val)).Dispose(); } } } private static void ApplyOrientationToLightByClientId(ulong clientId, Quaternion rot) { //IL_003d: 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_0049: Unknown result type (might be due to invalid IL or missing references) if (_lightsByClient.TryGetValue(clientId, out var value) && (Object)(object)value != (Object)null) { FlashlightAligner component = ((Component)value).gameObject.GetComponent(); if ((Object)(object)component != (Object)null && !component.AlignToCamera) { component.UseRemoteRotation = true; component.RemoteRotation = rot; ((Component)component).transform.rotation = rot; } } } private static ulong? GetClientIdByUserId(ulong userId) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_003c: 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) try { if (_userToClient.TryGetValue(userId, out var value)) { return value; } GameManager instance = GameManager.Instance; if ((Object)(object)instance == (Object)null) { return null; } PlayerClient playerFromUserId = instance.GetPlayerFromUserId(userId); if (playerFromUserId.userId != 0L) { return playerFromUserId.clientId; } } catch { } return null; } private static ulong? FindCachedUserIdByClientId(ulong clientId) { foreach (KeyValuePair item in _userToClient) { if (item.Value == clientId) { return item.Key; } } return null; } private static void RemoveUserState(ulong userId) { Light value = null; Light value2 = null; if (_lights.TryGetValue(userId, out value)) { _lights.Remove(userId); } if (_userToClient.TryGetValue(userId, out var value3)) { if (_lightsByClient.TryGetValue(value3, out value2)) { if ((Object)(object)value2 != (Object)null) { Object.Destroy((Object)(object)((Component)value2).gameObject); } _lightsByClient.Remove(value3); } _userToClient.Remove(userId); _predictedClientStates.Remove(value3); } else { _userToClient.Remove(userId); } if ((Object)(object)value != (Object)null && (Object)(object)value != (Object)(object)value2) { Object.Destroy((Object)(object)((Component)value).gameObject); } _states.Remove(userId); _rotations.Remove(userId); } public static void EnsureLightForClient(ulong clientId, ulong? userIdOpt = null) { //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Unknown result type (might be due to invalid IL or missing references) //IL_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_01dd: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Unknown result type (might be due to invalid IL or missing references) if (_lightsByClient.TryGetValue(clientId, out var value) && (Object)(object)value != (Object)null) { return; } NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)singleton == (Object)null) { return; } NetworkObject val = null; if (singleton.IsServer || singleton.IsHost) { if (!singleton.ConnectedClients.TryGetValue(clientId, out var value2)) { return; } val = value2.PlayerObject; } else { HashSet hashSet = singleton.SpawnManager?.SpawnedObjectsList; if (hashSet == null) { return; } foreach (NetworkObject item in hashSet) { if ((Object)(object)item != (Object)null && item.IsPlayerObject && item.OwnerClientId == clientId) { val = item; break; } } } if ((Object)(object)val == (Object)null) { return; } GameObject gameObject = ((Component)val).gameObject; Transform val2 = FindAttachPoint(gameObject.transform); GameObject val3 = new GameObject("PlayerFlashlightLight"); val3.transform.SetParent(val2 ?? gameObject.transform, false); Vector3 val4 = default(Vector3); ((Vector3)(ref val4))..ctor(0f, 0f, 0.25f); val3.transform.localPosition = val4; val3.transform.localRotation = Quaternion.identity; Light val5 = val3.AddComponent(); val5.type = (LightType)0; val5.intensity = Mathf.Max(0f, ConfigManager.Intensity.Value); val5.range = Mathf.Max(0.1f, ConfigManager.Range.Value); val5.spotAngle = Mathf.Clamp(ConfigManager.SpotAngle.Value, 1f, 170f); val5.color = Color.white; val5.shadows = ConfigManager.GetShadowMode(); ((Behaviour)val5).enabled = false; FlashlightAligner flashlightAligner = val3.AddComponent(); flashlightAligner.AlignToCamera = singleton.LocalClientId == clientId; flashlightAligner.FollowPoint = val2 ?? gameObject.transform; flashlightAligner.LocalOffset = val4; if (userIdOpt.HasValue) { _lights[userIdOpt.Value] = val5; _userToClient[userIdOpt.Value] = clientId; } _lightsByClient[clientId] = val5; if (_predictedClientStates.TryGetValue(clientId, out var value3)) { ApplyLightStateByClientId(clientId, value3); return; } ulong? num = userIdOpt ?? GetUserIdByClientId(clientId); bool value4 = false; if (num.HasValue) { _states.TryGetValue(num.Value, out value4); } ApplyLightStateByClientId(clientId, value4); } public static void ResetAll() { try { foreach (KeyValuePair light in _lights) { Light value = light.Value; if ((Object)(object)value != (Object)null) { Object.Destroy((Object)(object)((Component)value).gameObject); } } foreach (KeyValuePair item in _lightsByClient) { Light value2 = item.Value; if ((Object)(object)value2 != (Object)null) { Object.Destroy((Object)(object)((Component)value2).gameObject); } } _states.Clear(); _lights.Clear(); _lightsByClient.Clear(); _userToClient.Clear(); _rotations.Clear(); _predictedClientStates.Clear(); } catch { } } private static void ApplyLightStateByClientId(ulong clientId, bool on) { //IL_0073: Unknown result type (might be due to invalid IL or missing references) if (_lightsByClient.TryGetValue(clientId, out var value) && (Object)(object)value != (Object)null) { ((Behaviour)value).enabled = on; value.intensity = Mathf.Max(0f, ConfigManager.Intensity.Value); value.range = Mathf.Max(0.1f, ConfigManager.Range.Value); value.spotAngle = Mathf.Clamp(ConfigManager.SpotAngle.Value, 1f, 170f); value.shadows = ConfigManager.GetShadowMode(); } } private static void PlayToggleSoundForClient(ulong clientId) { //IL_0089: Unknown result type (might be due to invalid IL or missing references) try { if ((Object)(object)_toggleClip == (Object)null) { _toggleClip = FindAudioClipByName("Pop sounds 18"); } AudioClip toggleClip = _toggleClip; if (!((Object)(object)toggleClip == (Object)null)) { Transform val = null; if (_lightsByClient.TryGetValue(clientId, out var value) && (Object)(object)value != (Object)null) { val = ((Component)value).transform; } GameManager instance = GameManager.Instance; if ((Object)(object)instance != (Object)null && (Object)(object)instance.audioSource != (Object)null) { instance.audioSource.PlayOneShot(toggleClip, 0.2f); } else if ((Object)(object)val != (Object)null) { AudioSource.PlayClipAtPoint(toggleClip, val.position, 0.2f); } } } catch { } } private static AudioClip FindAudioClipByName(string name) { try { AudioClip[] array = Resources.FindObjectsOfTypeAll(); string b = (name ?? string.Empty).Trim(); foreach (AudioClip val in array) { if (!((Object)(object)val == (Object)null) && string.Equals(((Object)val).name ?? string.Empty, b, StringComparison.OrdinalIgnoreCase)) { return val; } } } catch { } return null; } } public class FlashlightAligner : MonoBehaviour { public bool AlignToCamera; public Transform FollowPoint; public Vector3 LocalOffset = new Vector3(0f, 0f, 0.25f); public bool UseRemoteRotation; public Quaternion RemoteRotation; private const float SendInterval = 0.05f; private const float AngleThreshold = 0.25f; private float _lastSentTime; private Quaternion _lastSentRot; private void LateUpdate() { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_00be: 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) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0079: 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_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)FollowPoint != (Object)null) { ((Component)this).transform.position = FollowPoint.TransformPoint(LocalOffset); } if (AlignToCamera) { Camera main = Camera.main; if ((Object)(object)main != (Object)null) { Quaternion rotation = ((Component)main).transform.rotation; ((Component)this).transform.rotation = rotation; float unscaledTime = Time.unscaledTime; if (unscaledTime - _lastSentTime >= 0.05f && (_lastSentRot == default(Quaternion) || Quaternion.Angle(_lastSentRot, rotation) >= 0.25f)) { FlashlightManager.ReportLocalOrientation(rotation); _lastSentRot = rotation; _lastSentTime = unscaledTime; } } } else if (UseRemoteRotation) { ((Component)this).transform.rotation = RemoteRotation; } } } public static class InputActionBindingHelper { public static InputAction CreateButtonAction(string actionName, string hotkey, Action onPerformed) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Expected O, but got Unknown string text = BuildBindingPath(hotkey); if (string.IsNullOrWhiteSpace(text)) { return null; } InputAction val = new InputAction(actionName, (InputActionType)1, text, (string)null, (string)null, (string)null); if (onPerformed != null) { val.performed += delegate { onPerformed(); }; } val.Enable(); return val; } public static string BuildBindingPath(string hotkey) { if (string.IsNullOrWhiteSpace(hotkey)) { return null; } string text = hotkey.Trim(); if (text.Contains("<") && text.Contains(">")) { return text; } string text2 = text.ToLowerInvariant(); return text2 switch { "leftbutton" => "/leftButton", "rightbutton" => "/rightButton", "middlebutton" => "/middleButton", "backbutton" => "/backButton", "forwardbutton" => "/forwardButton", "buttonsouth" => "/buttonSouth", "buttoneast" => "/buttonEast", "buttonwest" => "/buttonWest", "buttonnorth" => "/buttonNorth", "leftshoulder" => "/leftShoulder", "rightshoulder" => "/rightShoulder", "lefttrigger" => "/leftTrigger", "righttrigger" => "/rightTrigger", "dpadup" => "/dpad/up", "dpaddown" => "/dpad/down", "dpadleft" => "/dpad/left", "dpadright" => "/dpad/right", "startbutton" => "/start", "selectbutton" => "/select", "leftstickpress" => "/leftStickPress", "rightstickpress" => "/rightStickPress", _ => "/" + text2, }; } public static string FormatHotkeyForDisplay(string s) { if (string.IsNullOrWhiteSpace(s)) { return string.Empty; } s = s.Trim(); if (s.Length == 1) { return s.ToUpperInvariant(); } if (s[0] == 'f' || s[0] == 'F') { bool flag = true; for (int i = 1; i < s.Length; i++) { if (!char.IsDigit(s[i])) { flag = false; break; } } if (flag) { return ("F" + s.Substring(1)).ToUpperInvariant(); } } string text = s.ToLowerInvariant(); switch (text) { case "leftbutton": return "Mouse Left"; case "rightbutton": return "Mouse Right"; case "middlebutton": return "Mouse Middle"; case "backbutton": return "Mouse Back"; case "forwardbutton": return "Mouse Forward"; case "buttonsouth": return "Gamepad A"; case "buttoneast": return "Gamepad B"; case "buttonwest": return "Gamepad X"; case "buttonnorth": return "Gamepad Y"; case "leftshoulder": return "Gamepad LB"; case "rightshoulder": return "Gamepad RB"; case "lefttrigger": return "Gamepad LT"; case "righttrigger": return "Gamepad RT"; case "dpadup": return "D-Pad Up"; case "dpaddown": return "D-Pad Down"; case "dpadleft": return "D-Pad Left"; case "dpadright": return "D-Pad Right"; case "startbutton": return "Gamepad Start"; case "selectbutton": return "Gamepad Select"; case "leftstickpress": return "Left Stick Press"; case "rightstickpress": return "Right Stick Press"; default: switch (text.Length) { case 5: switch (text[0]) { case 's': if (!(text == "slash")) { break; } return "/"; case 'm': if (!(text == "minus")) { break; } return "-"; case 'c': if (!(text == "comma")) { break; } return ","; case 'q': if (!(text == "quote")) { break; } return "'"; } break; case 9: switch (text[4]) { case 's': if (!(text == "backslash")) { break; } return "\\"; case 'c': if (!(text == "semicolon")) { break; } return ";"; case 'q': if (!(text == "backquote")) { break; } return "`"; } break; case 6: switch (text[0]) { case 'e': if (!(text == "equals")) { break; } return "="; case 'p': if (!(text == "period")) { break; } return "."; } break; case 4: if (!(text == "plus")) { break; } return "+"; case 11: if (!(text == "leftbracket")) { break; } return "["; case 12: if (!(text == "rightbracket")) { break; } return "]"; } break; case null: break; } switch (text) { case "alt": case "ctrl": case "shift": case "enter": case "space": case "escape": case "esc": case "tab": case "backspace": case "capslock": return char.ToUpper(s[0]) + s.Substring(1).ToLowerInvariant(); case "leftalt": return "LeftAlt"; case "rightalt": return "RightAlt"; case "leftctrl": return "LeftCtrl"; case "rightctrl": return "RightCtrl"; case "leftshift": return "LeftShift"; case "rightshift": return "RightShift"; default: return char.ToUpper(s[0]) + s.Substring(1).ToLowerInvariant(); } } } } namespace PlayerFlashlight.Patches { [HarmonyPatch(typeof(GameManager))] public static class GameManagerPatch { [HarmonyPatch("OnNetworkSpawn")] [HarmonyPostfix] private static void OnNetworkSpawn_Postfix() { FlashlightManager.RegisterMessageHandlers(); } [HarmonyPatch("OnNetworkDespawn")] [HarmonyPostfix] private static void OnNetworkDespawn_Postfix() { FlashlightManager.ResetAll(); } } [HarmonyPatch(typeof(UIManager))] public static class UIManagerHotkeyPatch { private static InputAction _toggleAction; [HarmonyPatch("Awake")] [HarmonyPostfix] private static void Awake_Postfix() { InitializeHotkey(); } private static void InitializeHotkey() { try { if (_toggleAction != null) { _toggleAction.Disable(); _toggleAction.Dispose(); _toggleAction = null; } string value = ConfigManager.Hotkey.Value; _toggleAction = InputActionBindingHelper.CreateButtonAction("ToggleFlashlight", string.IsNullOrWhiteSpace(value) ? "l" : value, delegate { if (!IsAnyTextInputFocused()) { FlashlightManager.SendToggle(); } }); } catch (Exception ex) { ManualLogSource logger = PlayerFlashlight.Logger; if (logger != null) { logger.LogError((object)("初始化手电筒快捷键失败: " + ex.Message)); } } } private static bool IsAnyTextInputFocused() { EventSystem current = EventSystem.current; GameObject val = ((current != null) ? current.currentSelectedGameObject : null); if ((Object)(object)val != (Object)null) { if ((Object)(object)val.GetComponentInParent() != (Object)null) { return true; } if ((Object)(object)val.GetComponentInParent() != (Object)null) { return true; } } TMP_InputField[] array = Object.FindObjectsOfType(); foreach (TMP_InputField val2 in array) { if ((Object)(object)val2 != (Object)null && val2.isFocused) { return true; } } InputField[] array2 = Object.FindObjectsOfType(); foreach (InputField val3 in array2) { if ((Object)(object)val3 != (Object)null && val3.isFocused) { return true; } } return false; } } [HarmonyPatch(typeof(ExampleCharacterSetup))] public static class ExampleCharacterSetupPatch { [HarmonyPatch("OnNetworkSpawn")] [HarmonyPostfix] private static void OnNetworkSpawn_Postfix(ExampleCharacterSetup __instance) { NetworkObject networkObject = ((NetworkBehaviour)__instance).NetworkObject; if (!((Object)(object)networkObject == (Object)null)) { FlashlightManager.EnsureLightForClient(networkObject.OwnerClientId); } } } } namespace PlayerFlashlight.Localization { public static class LocalizationHelper { public static Dictionary GetDefaultTranslations(string language) { Dictionary dictionary = new Dictionary(); switch (language) { case "zh": dictionary.Add("plugin.initializing", "开始初始化..."); dictionary.Add("plugin.author_prefix", "作者:"); dictionary.Add("plugin.initialized", "初始化成功!"); dictionary.Add("plugin.patches_skipped", "补丁已应用,跳过..."); dictionary.Add("config.enable_mod_desc", "是否启用模组"); dictionary.Add("config.hotkey_desc", "手电筒开关快捷键"); dictionary.Add("config.intensity_desc", "手电筒亮度"); dictionary.Add("config.spot_angle_desc", "手电筒光锥角度"); dictionary.Add("config.range_desc", "手电筒照明范围(米)"); dictionary.Add("config.shadow_mode_desc", "阴影模式"); break; case "zh-Hant": dictionary.Add("plugin.initializing", "開始初始化..."); dictionary.Add("plugin.author_prefix", "作者:"); dictionary.Add("plugin.initialized", "初始化成功!"); dictionary.Add("plugin.patches_skipped", "補丁已應用,跳過..."); dictionary.Add("config.enable_mod_desc", "是否啟用模組"); dictionary.Add("config.hotkey_desc", "手電筒開關快捷鍵"); dictionary.Add("config.intensity_desc", "手電筒亮度"); dictionary.Add("config.spot_angle_desc", "手電筒光錐角度"); dictionary.Add("config.range_desc", "手電筒照明範圍(米)"); dictionary.Add("config.shadow_mode_desc", "陰影模式"); break; case "en": dictionary.Add("plugin.initializing", "is initializing..."); dictionary.Add("plugin.author_prefix", "Author: "); dictionary.Add("plugin.initialized", "initialized successfully!"); dictionary.Add("plugin.patches_skipped", "Patches already applied, skipping..."); dictionary.Add("config.enable_mod_desc", "Whether to enable mod"); dictionary.Add("config.hotkey_desc", "Flashlight toggle hotkey"); dictionary.Add("config.intensity_desc", "Flashlight intensity"); dictionary.Add("config.spot_angle_desc", "Flashlight spot angle"); dictionary.Add("config.range_desc", "Flashlight range (meters)"); dictionary.Add("config.shadow_mode_desc", "Shadow mode"); break; case "ja": dictionary.Add("plugin.initializing", "初期化中..."); dictionary.Add("plugin.author_prefix", "作者:"); dictionary.Add("plugin.initialized", "初期化に成功しました!"); dictionary.Add("plugin.patches_skipped", "パッチは既に適用されています。スキップします..."); dictionary.Add("config.enable_mod_desc", "MODを有効にするかどうか"); dictionary.Add("config.hotkey_desc", "懐中電灯の切り替えホットキー"); dictionary.Add("config.intensity_desc", "懐中電灯の明るさ"); dictionary.Add("config.spot_angle_desc", "懐中電灯の照射角度"); dictionary.Add("config.range_desc", "懐中電灯の照射範囲(メートル)"); dictionary.Add("config.shadow_mode_desc", "影モード"); break; } return dictionary; } } public class LocalizationManager { private static LocalizationManager _instance; private readonly Dictionary> _localizations = new Dictionary>(); private string _currentLocale = "zh"; public static readonly string[] SupportedLanguages = new string[12] { "zh", "zh-Hant", "en", "fr", "de", "ja", "ko", "pt", "ru", "es", "tr", "uk" }; public static LocalizationManager Instance => _instance ?? (_instance = new LocalizationManager()); private LocalizationManager() { Initialize(); } public void Initialize() { //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) if ((Object)(object)LocalizationSettings.SelectedLocale != (Object)null) { LocaleIdentifier identifier = LocalizationSettings.SelectedLocale.Identifier; _currentLocale = ((LocaleIdentifier)(ref identifier)).Code; } string[] supportedLanguages = SupportedLanguages; foreach (string text in supportedLanguages) { Dictionary defaultTranslations = LocalizationHelper.GetDefaultTranslations(text); if (defaultTranslations != null && defaultTranslations.Count > 0) { _localizations[text] = defaultTranslations; } } LocalizationSettings.SelectedLocaleChanged += OnGameLanguageChanged; } private void OnGameLanguageChanged(Locale locale) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)locale != (Object)null) { LocaleIdentifier identifier = locale.Identifier; string code = ((LocaleIdentifier)(ref identifier)).Code; if (_localizations.ContainsKey(code)) { _currentLocale = code; } else { _currentLocale = "en"; } } } public string GetLocalizedText(string key, params object[] args) { if (string.IsNullOrEmpty(_currentLocale) || !_localizations.ContainsKey(_currentLocale)) { _currentLocale = "en"; } if (_localizations.ContainsKey(_currentLocale) && _localizations[_currentLocale].TryGetValue(key, out var value)) { if (args.Length == 0) { return value; } return string.Format(value, args); } if (_currentLocale != "en" && _localizations.ContainsKey("en") && _localizations["en"].TryGetValue(key, out var value2)) { if (args.Length == 0) { return value2; } return string.Format(value2, args); } if (_localizations.ContainsKey("zh") && _localizations["zh"].TryGetValue(key, out var value3)) { if (args.Length == 0) { return value3; } return string.Format(value3, args); } return key; } } } namespace PlayerFlashlight.Configuration { public static class ConfigManager { public static ConfigEntry Hotkey { get; private set; } public static ConfigEntry Intensity { get; private set; } public static ConfigEntry Range { get; private set; } public static ConfigEntry SpotAngle { get; private set; } public static ConfigEntry ShadowMode { get; private set; } public static void Initialize(ConfigFile config) { //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Expected O, but got Unknown Hotkey = config.Bind("General", "Hotkey", "l", LocalizationManager.Instance.GetLocalizedText("config.hotkey_desc")); Intensity = config.Bind("Flashlight", "Intensity", 50f, LocalizationManager.Instance.GetLocalizedText("config.intensity_desc")); SpotAngle = config.Bind("Flashlight", "SpotAngle", 60f, LocalizationManager.Instance.GetLocalizedText("config.spot_angle_desc")); Range = config.Bind("Flashlight", "Range", 36f, LocalizationManager.Instance.GetLocalizedText("config.range_desc")); ShadowMode = config.Bind("Flashlight", "ShadowMode", "None", new ConfigDescription(LocalizationManager.Instance.GetLocalizedText("config.shadow_mode_desc"), (AcceptableValueBase)(object)new AcceptableValueList(new string[3] { "None", "Hard", "Soft" }), Array.Empty())); } public static LightShadows GetShadowMode() { string a = ShadowMode.Value?.Trim(); if (!string.Equals(a, "Hard", StringComparison.OrdinalIgnoreCase)) { if (!string.Equals(a, "Soft", StringComparison.OrdinalIgnoreCase)) { return (LightShadows)0; } return (LightShadows)2; } return (LightShadows)1; } } }