using System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Logging; using HarmonyLib; using IronLabs.SharedLib; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("IronLabs.QuickLaunch")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("IronLabs.QuickLaunch")] [assembly: AssemblyCopyright("Copyright © 2026")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("046ED613-45E5-48D3-9B7B-72703870DA05")] [assembly: AssemblyFileVersion("1.0.1")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("1.0.1.39127")] namespace IronLabs.QuickLaunch { [BepInPlugin("IronLabs.QuickLaunch", "IronLabs.QuickLaunch", "1.0.1")] public sealed class QuickLaunchPlugin : IronLabsPlugin { [HarmonyPatch(typeof(FejdStartup), "Start")] private static class StartPatch { private static void Postfix(FejdStartup __instance) { ModLogger.LogDebug("QuickLaunch FejdStartup.Start postfix invoked."); StartPostfix(__instance); } } [HarmonyPatch(typeof(FejdStartup), "OnWorldStart")] private static class LocalSessionPatch { private static void Prefix() { ModLogger.LogDebug("QuickLaunch FejdStartup.OnWorldStart prefix invoked."); PlatformPrefs.SetString("IronLabs.QuickLaunch.LastSession", "local"); } } [HarmonyPatch(typeof(FejdStartup), "JoinServer")] private static class MultiplayerSessionPatch { private static void Prefix(FejdStartup __instance) { ModLogger.LogDebug("QuickLaunch FejdStartup.JoinServer prefix invoked."); if (__instance.HasServerToJoin()) { PlatformPrefs.SetString("IronLabs.QuickLaunch.LastSession", "multiplayer"); } } } private const string PluginGuid = "IronLabs.QuickLaunch"; private const string PluginName = "IronLabs.QuickLaunch"; private const string PluginVersion = "1.0.1"; private const string LastSessionPreference = "IronLabs.QuickLaunch.LastSession"; private const string LocalSession = "local"; private const string MultiplayerSession = "multiplayer"; private static bool _attemptedAutoStart; private static ModLog ModLogger { get; set; } private void Awake() { ModLogger = InitializePlugin("IronLabs.QuickLaunch"); ModLogger.LogInfo("IronLabs.QuickLaunch 1.0.1 is loaded."); } private void OnDestroy() { ShutdownPlugin(); ModLogger = null; } private static void StartPostfix(FejdStartup startup) { if (_attemptedAutoStart || HasDisabledArgument()) { return; } _attemptedAutoStart = true; string profileFilename = PlatformPrefs.GetString("profile", ""); if (!RememberedProfileExists(profileFilename)) { return; } if (PlatformPrefs.GetString("IronLabs.QuickLaunch.LastSession", "") == "multiplayer") { JoinLastMultiplayerSession(startup, profileFilename); return; } string worldName = PlatformPrefs.GetString("world", ""); if (RememberedWorldExists(worldName)) { startup.OnCharacterStart(); if (IsRememberedWorldSelected(startup, worldName)) { StartWorld(startup, profileFilename, worldName); } } } private static bool HasDisabledArgument() { string[] commandLineArgs = Environment.GetCommandLineArgs(); for (int i = 0; i < commandLineArgs.Length - 1; i++) { if (MatchesDisabledArgument(commandLineArgs, i)) { ModLogger.LogDebug("Received command-line switch: --quicklaunch false."); return true; } } return false; } private static bool MatchesDisabledArgument(string[] arguments, int index) { if (string.Equals(arguments[index], "--quicklaunch", StringComparison.OrdinalIgnoreCase)) { return string.Equals(arguments[index + 1], "false", StringComparison.OrdinalIgnoreCase); } return false; } private static bool RememberedProfileExists(string profileFilename) { if (string.IsNullOrEmpty(profileFilename)) { return false; } if (!SaveSystem.GetAllPlayerProfiles().Exists((PlayerProfile profile) => profile.GetFilename() == profileFilename)) { return false; } return true; } private static bool RememberedWorldExists(string worldName) { if (string.IsNullOrEmpty(worldName)) { return false; } if (SaveSystem.GetWorldList().Exists((World world) => world.m_name == worldName)) { return true; } return false; } private static void JoinLastMultiplayerSession(FejdStartup startup, string profileFilename) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown //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_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0044: 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) LocalServerList val = new LocalServerList((string)null, ServerListGui.GetServerListLocations("recent")); ServerJoinData val3; try { if (val.Count == 0) { goto IL_002a; } ServerJoinData val2 = val[0]; if (!((ServerJoinData)(ref val2)).IsValid) { goto IL_002a; } val3 = val[0]; startup.SetServerToJoin(val3); goto end_IL_0011; IL_002a: ModLogger.LogError("QuickLaunch could not find a valid recent multiplayer server."); return; end_IL_0011:; } finally { ((IDisposable)val)?.Dispose(); } ModLogger.LogDebug($"QuickLaunch is joining multiplayer server '{val3}' with character '{profileFilename}'."); startup.OnCharacterStart(); startup.JoinServer(); } private static bool IsRememberedWorldSelected(FejdStartup startup, string worldName) { World value = Traverse.Create((object)startup).Field("m_world").GetValue(); if (value != null && value.m_name == worldName) { return true; } return false; } private static void StartWorld(FejdStartup startup, string profileFilename, string worldName) { ModLogger.LogDebug("QuickLaunch is joining local world '" + worldName + "' with character '" + profileFilename + "'."); startup.OnWorldStart(); } } } namespace IronLabs.SharedLib { public abstract class IronLabsPlugin : BaseUnityPlugin { private Harmony _harmony; private bool _patchesApplied; protected ModLog InitializePlugin(string pluginGuid) { //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Expected O, but got Unknown ModLog modLog = new ModLog(((BaseUnityPlugin)this).Logger); Version version = ((object)this).GetType().Assembly.GetName().Version; modLog.LogInfo($"AssemblyVersion: {version}."); _harmony = new Harmony(pluginGuid); PatchOwnNamespace(modLog); return modLog; } protected void PatchOwnNamespace(ModLog log) { if (_patchesApplied) { log.LogDebug("Harmony patches are already active; skipping registration."); return; } string text = ((object)this).GetType().Namespace; Type[] types = Assembly.GetExecutingAssembly().GetTypes(); foreach (Type type in types) { if (type.Namespace == text) { _harmony.CreateClassProcessor(type).Patch(); } } _patchesApplied = true; log.LogDebug("Harmony patches were applied for the plugin namespace."); } protected void ShutdownPlugin() { if (_patchesApplied) { Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } _patchesApplied = false; } } } public sealed class ModLog { private readonly ManualLogSource _logger; public ModLog(ManualLogSource logger) { _logger = logger; } public void LogFatal(object message) { Write((LogLevel)1, message); } public void LogError(object message) { Write((LogLevel)2, message); } public void LogWarning(object message) { Write((LogLevel)4, message); } public void LogMessage(object message) { Write((LogLevel)8, message); } public void LogInfo(object message) { Write((LogLevel)16, message); } public void LogDebug(object message) { Write((LogLevel)32, message); } public void Log(LogLevel level, object message) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) Write(level, message); } private void Write(LogLevel level, object message) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) string arg = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); _logger.Log(level, (object)$"[{arg}] {message}"); } } }