Decompiled source of MorePlayers v1.0.0

BepInEx/plugins/MorePlayers.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppSystem.Collections.Generic;
using Mirror;
using MorePlayers.Configuration;
using MorePlayers.Localization;
using UnityEngine;
using UnityEngine.Localization;
using UnityEngine.Localization.Settings;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("MorePlayers")]
[assembly: AssemblyDescription("More Players mod for Island Market Simulator by Ice Box Studio")]
[assembly: AssemblyCompany("Ice Box Studio")]
[assembly: AssemblyProduct("MorePlayers")]
[assembly: AssemblyCopyright("Copyright © 2026 Ice Box Studio All rights reserved.")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("B4F2A1C9-3D7E-4A5B-8C6D-1234567890EF")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace MorePlayers
{
	[BepInPlugin("IceBoxStudio.IslandMarketSimulator.MorePlayers", "MorePlayers", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class MorePlayers : BasePlugin
	{
		public static MorePlayers _Instance;

		private Harmony _harmony;

		private bool patchesApplied;

		private const string ModConfigManagerApiTypeName = "ModConfigManager.Api.ModConfigManagerAPI";

		private const string ModConfigManagerRegisterMethodName = "RegisterPluginInfo";

		public static MorePlayers Instance => _Instance;

		internal static ManualLogSource Logger { get; private set; }

		public override void Load()
		{
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Expected O, but got Unknown
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Expected O, but got Unknown
			_Instance = this;
			Logger = ((BasePlugin)this).Log;
			bool flag = default(bool);
			try
			{
				Logger.LogInfo((object)"=============================================");
				ManualLogSource logger = Logger;
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(1, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("MorePlayers");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(LocalizationManager.Instance.GetLocalizedText("plugin.initializing"));
				}
				logger.LogInfo(val);
				ManualLogSource logger2 = Logger;
				val = new BepInExInfoLogInterpolatedStringHandler(54, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(LocalizationManager.Instance.GetLocalizedText("plugin.author_prefix"));
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Ice Box Studio(https://steamcommunity.com/id/ibox666/)");
				}
				logger2.LogInfo(val);
				ConfigManager.Initialize(((BasePlugin)this).Config);
				RegisterToModConfigManager();
				ApplyPatches();
				ManualLogSource logger3 = Logger;
				val = new BepInExInfoLogInterpolatedStringHandler(1, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("MorePlayers");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(LocalizationManager.Instance.GetLocalizedText("plugin.initialized"));
				}
				logger3.LogInfo(val);
				Logger.LogInfo((object)"=============================================");
			}
			catch (Exception ex)
			{
				ManualLogSource logger4 = Logger;
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(9, 3, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("MorePlayers");
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" 初始化错误: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("\n");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.StackTrace);
				}
				logger4.LogError(val2);
			}
		}

		private void ApplyPatches()
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			//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.IslandMarketSimulator.MorePlayers");
					_harmony.PatchAll();
					patchesApplied = true;
					return;
				}
				catch (Exception ex)
				{
					ManualLogSource logger = Logger;
					bool flag = default(bool);
					BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(10, 3, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("MorePlayers");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" 应用补丁错误: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("\n");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.StackTrace);
					}
					logger.LogError(val);
					return;
				}
			}
			Logger.LogInfo((object)LocalizationManager.Instance.GetLocalizedText("plugin.patches_skipped"));
		}

		private void RegisterToModConfigManager()
		{
			Type type = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly assembly) => assembly.GetType("ModConfigManager.Api.ModConfigManagerAPI") != null)?.GetType("ModConfigManager.Api.ModConfigManagerAPI");
			if (!(type == null))
			{
				MethodInfo method = type.GetMethod("RegisterPluginInfo", BindingFlags.Static | BindingFlags.Public);
				if (!(method == null))
				{
					method.Invoke(null, new object[5]
					{
						"IceBoxStudio.IslandMarketSimulator.MorePlayers",
						LocalizationManager.Instance.GetLocalizedText("plugin.name"),
						"1.0.0",
						"Ice Box Studio",
						LocalizationManager.Instance.GetLocalizedText("plugin.description")
					});
				}
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "IceBoxStudio.IslandMarketSimulator.MorePlayers";

		public const string PLUGIN_NAME = "MorePlayers";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace MorePlayers.Patches
{
	[HarmonyPatch(typeof(NetworkManager), "Start")]
	public static class NetworkManager_Start_Patch
	{
		public static void Postfix(NetworkManager __instance)
		{
			NetworkManagerPatchHelpers.ApplyConfiguredConnectionLimit(__instance, "Start");
		}
	}
	[HarmonyPatch(typeof(NetworkManager), "StartHost")]
	public static class NetworkManager_StartHost_Patch
	{
		public static void Prefix(NetworkManager __instance)
		{
			NetworkManagerPatchHelpers.ApplyConfiguredConnectionLimit(__instance, "StartHost");
		}
	}
	[HarmonyPatch(typeof(NetworkManager), "StartServer")]
	public static class NetworkManager_StartServer_Patch
	{
		public static void Prefix(NetworkManager __instance)
		{
			NetworkManagerPatchHelpers.ApplyConfiguredConnectionLimit(__instance, "StartServer");
		}
	}
	[HarmonyPatch(typeof(CustomNetworkManager), "OnServerAddPlayer")]
	public static class CustomNetworkManager_OnServerAddPlayer_Patch
	{
		public static void Postfix(CustomNetworkManager __instance, NetworkConnectionToClient conn)
		{
			//IL_0051: 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_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = (((Object)(object)((conn != null) ? ((NetworkConnection)conn).identity : null) != (Object)null) ? ((Component)((NetworkConnection)conn).identity).gameObject : null);
			if (!((Object)(object)val == (Object)null))
			{
				int playerIndex = (((Object)(object)__instance != (Object)null && ((NetworkManager)__instance).numPlayers > 0) ? (((NetworkManager)__instance).numPlayers - 1) : 0);
				Vector3 position = val.transform.position;
				Vector3 adjustedSpawnPosition = NetworkManagerPatchHelpers.GetAdjustedSpawnPosition((NetworkManager)(object)__instance, position, playerIndex);
				Vector3 val2 = adjustedSpawnPosition - position;
				if (((Vector3)(ref val2)).sqrMagnitude > 0.0001f)
				{
					val.transform.position = adjustedSpawnPosition;
				}
				if (conn != null)
				{
					_ = conn.connectionId;
				}
				if ((Object)(object)__instance != (Object)null)
				{
					_ = ((NetworkManager)__instance).numPlayers;
				}
			}
		}
	}
	internal static class NetworkManagerPatchHelpers
	{
		internal static void ApplyConfiguredConnectionLimit(NetworkManager networkManager, string source)
		{
			if (networkManager is CustomNetworkManager && ConfigManager.Instance != null)
			{
				int value = ConfigManager.Instance.MaxPlayers.Value;
				if (networkManager.maxConnections != value)
				{
					networkManager.maxConnections = value;
				}
			}
		}

		internal static Vector3 GetAdjustedSpawnPosition(NetworkManager networkManager, Vector3 basePosition, int playerIndex)
		{
			//IL_000a: 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)
			//IL_0056: 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_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			int spawnAnchorCount = GetSpawnAnchorCount();
			if (spawnAnchorCount <= 0)
			{
				return basePosition;
			}
			if (playerIndex < 0)
			{
				playerIndex = 0;
			}
			if (playerIndex < spawnAnchorCount)
			{
				return basePosition;
			}
			int num = playerIndex / spawnAnchorCount;
			int num2 = playerIndex % spawnAnchorCount;
			float num3 = 1.75f * (float)num;
			float num4 = 360f / (float)spawnAnchorCount * (float)num2 * Mathf.Deg2Rad;
			Vector3 val = new Vector3(Mathf.Cos(num4), 0f, Mathf.Sin(num4)) * num3;
			return basePosition + val;
		}

		private static int GetSpawnAnchorCount()
		{
			if (NetworkManager.startPositions != null && NetworkManager.startPositions.Count > 0)
			{
				return NetworkManager.startPositions.Count;
			}
			return 0;
		}
	}
	[HarmonyPatch(typeof(SteamLobby), "Start")]
	public static class SteamLobby_Start_Patch
	{
		public static void Prefix(SteamLobby __instance)
		{
			SteamLobbyPatchHelpers.ApplyConfiguredLobbyLimit(__instance, "Start");
		}
	}
	[HarmonyPatch(typeof(SteamLobby), "StartImmediateHost")]
	public static class SteamLobby_StartImmediateHost_Patch
	{
		public static void Prefix(SteamLobby __instance)
		{
			SteamLobbyPatchHelpers.ApplyConfiguredLobbyLimit(__instance, "StartImmediateHost");
		}
	}
	[HarmonyPatch(typeof(SteamLobby), "CreateLobbyAfterTutorial")]
	public static class SteamLobby_CreateLobbyAfterTutorial_Patch
	{
		public static void Prefix(SteamLobby __instance)
		{
			SteamLobbyPatchHelpers.ApplyConfiguredLobbyLimit(__instance, "CreateLobbyAfterTutorial");
		}
	}
	internal static class SteamLobbyPatchHelpers
	{
		internal static void ApplyConfiguredLobbyLimit(SteamLobby steamLobby, string source)
		{
			if (!((Object)(object)steamLobby == (Object)null) && ConfigManager.Instance != null)
			{
				int value = ConfigManager.Instance.MaxPlayers.Value;
				if (steamLobby.maxPlayers != value)
				{
					steamLobby.maxPlayers = value;
				}
				CustomNetworkManager val = Object.FindObjectOfType<CustomNetworkManager>();
				if ((Object)(object)val != (Object)null)
				{
					NetworkManagerPatchHelpers.ApplyConfiguredConnectionLimit((NetworkManager)(object)val, "SteamLobby." + source);
				}
			}
		}
	}
}
namespace MorePlayers.Localization
{
	public static class LocalizationHelper
	{
		public static Dictionary<string, string> GetDefaultTranslations(string language)
		{
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			switch (language)
			{
			case "zh":
				dictionary.Add("plugin.initializing", "开始初始化...");
				dictionary.Add("plugin.author_prefix", "作者:");
				dictionary.Add("plugin.initialized", "初始化成功!");
				dictionary.Add("plugin.patches_skipped", "补丁已应用,跳过...");
				dictionary.Add("plugin.name", "更多玩家");
				dictionary.Add("plugin.description", "提高玩家数量上限。");
				dictionary.Add("config.max_players", "最大玩家数量限制");
				break;
			case "zh-TW":
				dictionary.Add("plugin.initializing", "開始初始化...");
				dictionary.Add("plugin.author_prefix", "作者:");
				dictionary.Add("plugin.initialized", "初始化成功!");
				dictionary.Add("plugin.patches_skipped", "補丁已套用,略過...");
				dictionary.Add("plugin.name", "更多玩家");
				dictionary.Add("plugin.description", "提高玩家數量上限。");
				dictionary.Add("config.max_players", "最大玩家數量限制");
				break;
			case "en":
				dictionary.Add("plugin.initializing", "Initializing...");
				dictionary.Add("plugin.author_prefix", "Author: ");
				dictionary.Add("plugin.initialized", "Initialized successfully!");
				dictionary.Add("plugin.patches_skipped", "Patches already applied, skipping...");
				dictionary.Add("plugin.name", "More Players");
				dictionary.Add("plugin.description", "Increases the maximum number of players that can be in the game.");
				dictionary.Add("config.max_players", "Max Player Limit");
				break;
			case "ja":
				dictionary.Add("plugin.initializing", "初期化中...");
				dictionary.Add("plugin.author_prefix", "作者: ");
				dictionary.Add("plugin.initialized", "初期化に成功しました!");
				dictionary.Add("plugin.patches_skipped", "パッチは適用済みです。スキップします...");
				dictionary.Add("plugin.name", "より多くのプレイヤー");
				dictionary.Add("plugin.description", "ゲームに参加できるプレイヤー数の上限を増加します。");
				dictionary.Add("config.max_players", "最大プレイヤー数");
				break;
			}
			return dictionary;
		}
	}
	public class LocalizationManager
	{
		private static LocalizationManager _instance;

		private readonly Dictionary<string, Dictionary<string, string>> _localizations = new Dictionary<string, Dictionary<string, string>>();

		private string _currentLocale = "en";

		public static readonly string[] SupportedLanguages = new string[4] { "en", "zh", "zh-TW", "ja" };

		public static LocalizationManager Instance => _instance ?? (_instance = new LocalizationManager());

		private LocalizationManager()
		{
			string[] supportedLanguages = SupportedLanguages;
			foreach (string text in supportedLanguages)
			{
				Dictionary<string, string> defaultTranslations = LocalizationHelper.GetDefaultTranslations(text);
				if (defaultTranslations != null && defaultTranslations.Count > 0)
				{
					_localizations[text] = defaultTranslations;
				}
			}
		}

		private string GetCurrentLocale()
		{
			if (!PlayerPrefs.HasKey("Lang"))
			{
				return _currentLocale;
			}
			int @int = PlayerPrefs.GetInt("Lang");
			ILocalesProvider availableLocales = LocalizationSettings.AvailableLocales;
			List<Locale> val = ((availableLocales != null) ? availableLocales.Locales : null);
			if (val == null || @int < 0 || @int >= val.Count)
			{
				return _currentLocale;
			}
			string code = val[@int].Identifier.Code;
			_currentLocale = (_localizations.ContainsKey(code) ? code : "en");
			return _currentLocale;
		}

		public string GetLocalizedText(string key, params object[] args)
		{
			string currentLocale = GetCurrentLocale();
			if (_localizations.TryGetValue(currentLocale, out var value) && value.TryGetValue(key, out var value2))
			{
				return string.Format(value2, args);
			}
			if (currentLocale != "en" && _localizations.TryGetValue("en", out var value3) && value3.TryGetValue(key, out var value4))
			{
				return string.Format(value4, args);
			}
			return key;
		}
	}
}
namespace MorePlayers.Configuration
{
	public class ConfigManager
	{
		private static ConfigManager _instance;

		private readonly ConfigFile _configFile;

		private readonly Dictionary<string, ConfigEntry<bool>> _boolConfigs = new Dictionary<string, ConfigEntry<bool>>();

		private readonly Dictionary<string, ConfigEntry<string>> _stringConfigs = new Dictionary<string, ConfigEntry<string>>();

		private readonly Dictionary<string, ConfigEntry<int>> _intConfigs = new Dictionary<string, ConfigEntry<int>>();

		private readonly Dictionary<string, ConfigEntry<float>> _floatConfigs = new Dictionary<string, ConfigEntry<float>>();

		private readonly Dictionary<string, ConfigEntry<KeyCode>> _keyCodeConfigs = new Dictionary<string, ConfigEntry<KeyCode>>();

		public static ConfigManager Instance => _instance;

		public ConfigEntry<int> MaxPlayers { get; private set; }

		private ConfigManager(ConfigFile configFile)
		{
			_configFile = configFile;
			InitializeDefaultConfigs();
		}

		public static void Initialize(ConfigFile configFile)
		{
			if (_instance == null)
			{
				_instance = new ConfigManager(configFile);
			}
		}

		private void InitializeDefaultConfigs()
		{
			MaxPlayers = RegisterIntMax("General", "MaxPlayers", GetLocalizedDescription("config.max_players"), 10, 2, 10);
		}

		private string GetLocalizedDescription(string key)
		{
			return LocalizationManager.Instance?.GetLocalizedText(key) ?? key;
		}

		public ConfigEntry<bool> RegisterBool(string section, string key, string description, bool defaultValue)
		{
			ConfigEntry<bool> val = _configFile.Bind<bool>(section, key, defaultValue, description);
			_boolConfigs[key] = val;
			return val;
		}

		public ConfigEntry<string> RegisterString(string section, string key, string description, string defaultValue)
		{
			ConfigEntry<string> val = _configFile.Bind<string>(section, key, defaultValue, description);
			_stringConfigs[key] = val;
			return val;
		}

		public ConfigEntry<KeyCode> RegisterKeyCode(string section, string key, string description, KeyCode defaultValue)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			ConfigEntry<KeyCode> val = _configFile.Bind<KeyCode>(section, key, defaultValue, description);
			_keyCodeConfigs[key] = val;
			return val;
		}

		public ConfigEntry<int> RegisterInt(string section, string key, string description, int defaultValue)
		{
			ConfigEntry<int> val = _configFile.Bind<int>(section, key, defaultValue, description);
			_intConfigs[key] = val;
			return val;
		}

		public ConfigEntry<int> RegisterIntMax(string section, string key, string description, int defaultValue, int minValue, int maxValue)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			ConfigEntry<int> val = _configFile.Bind<int>(section, key, defaultValue, new ConfigDescription(description, (AcceptableValueBase)(object)new AcceptableValueRange<int>(minValue, maxValue), Array.Empty<object>()));
			_intConfigs[key] = val;
			return val;
		}

		public ConfigEntry<float> RegisterFloat(string section, string key, string description, float defaultValue)
		{
			ConfigEntry<float> val = _configFile.Bind<float>(section, key, defaultValue, description);
			_floatConfigs[key] = val;
			return val;
		}

		public ConfigEntry<float> RegisterFloatMax(string section, string key, string description, float defaultValue, float minValue, float maxValue)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			ConfigEntry<float> val = _configFile.Bind<float>(section, key, defaultValue, new ConfigDescription(description, (AcceptableValueBase)(object)new AcceptableValueRange<float>(minValue, maxValue), Array.Empty<object>()));
			_floatConfigs[key] = val;
			return val;
		}
	}
}