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 DirectPlay v1.0.6
IronLabs.DirectPlay.dll
Decompiled 2 months agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Logging; using HarmonyLib; using IronLabs.SharedLib; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("IronLabs.DirectPlay")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("IronLabs.DirectPlay")] [assembly: AssemblyCopyright("Copyright © 2026")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("046ED613-45E5-48D3-9B7B-72703870DA05")] [assembly: AssemblyFileVersion("1.0.6")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("1.0.6.40292")] namespace IronLabs.DirectPlay { [BepInPlugin("Ironlabs.Directplay", "IronLabs.DirectPlay", "1.0.6")] public sealed class DirectPlayPlugin : IronLabsPlugin { [HarmonyPatch(typeof(FejdStartup), "Start")] private static class StartPatch { private static void Postfix(FejdStartup __instance) { ModLogger.LogDebug("DirectPlay FejdStartup.Start postfix invoked."); StartPostfix(__instance); } } [HarmonyPatch(typeof(FejdStartup), "OnWorldStart")] private static class LocalSessionPatch { private static void Prefix() { ModLogger.LogDebug("DirectPlay FejdStartup.OnWorldStart prefix invoked."); PlatformPrefs.SetString("IronLabs.DirectPlay.LastSession", "local"); } } [HarmonyPatch(typeof(FejdStartup), "JoinServer")] private static class MultiplayerSessionPatch { private static void Prefix(FejdStartup __instance) { ModLogger.LogDebug("DirectPlay FejdStartup.JoinServer prefix invoked."); if (__instance.HasServerToJoin()) { PlatformPrefs.SetString("IronLabs.DirectPlay.LastSession", "multiplayer"); } } } private const string PluginGuid = "Ironlabs.Directplay"; private const string PluginName = "IronLabs.DirectPlay"; private const string PluginVersion = "1.0.6"; private const string LastSessionPreference = "IronLabs.DirectPlay.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.Directplay"); ModLogger.LogInfo("IronLabs.DirectPlay 1.0.6 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.DirectPlay.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: --directplay false."); return true; } } return false; } private static bool MatchesDisabledArgument(string[] arguments, int index) { return string.Equals(arguments[index], "--directplay", StringComparison.OrdinalIgnoreCase) && string.Equals(arguments[index + 1], "false", StringComparison.OrdinalIgnoreCase); } private static bool RememberedProfileExists(string profileFilename) { if (string.IsNullOrEmpty(profileFilename)) { return false; } List<PlayerProfile> allPlayerProfiles = SaveSystem.GetAllPlayerProfiles(); if (!allPlayerProfiles.Exists((PlayerProfile profile) => profile.GetFilename() == profileFilename)) { return false; } return true; } private static bool RememberedWorldExists(string worldName) { if (string.IsNullOrEmpty(worldName)) { return false; } List<World> worldList = SaveSystem.GetWorldList(); if (worldList.Exists((World world) => world.m_name == worldName)) { return true; } return false; } private static void JoinLastMultiplayerSession(FejdStartup startup, string profileFilename) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown //IL_001d: 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) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004e: 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_006f: 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_0034; } ServerJoinData val2 = val[0]; if (!((ServerJoinData)(ref val2)).IsValid) { goto IL_0034; } val3 = val[0]; startup.SetServerToJoin(val3); goto end_IL_0012; IL_0034: ModLogger.LogError("DirectPlay could not find a valid recent multiplayer server."); return; end_IL_0012:; } finally { ((IDisposable)val)?.Dispose(); } ModLogger.LogDebug($"DirectPlay 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<World>(); if (value != null && value.m_name == worldName) { return true; } return false; } private static void StartWorld(FejdStartup startup, string profileFilename, string worldName) { ModLogger.LogDebug("DirectPlay 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_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0041: 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_001a: 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}"); } } }