diff --git a/SeamlessTransfer/ModLoader.cs b/SeamlessTransfer/ModLoader.cs index 07fb895..42e6cdf 100644 --- a/SeamlessTransfer/ModLoader.cs +++ b/SeamlessTransfer/ModLoader.cs @@ -131,7 +131,7 @@ namespace SeamlessClientPlugin.SeamlessTransfer MyGuiTextures.Static.Unload(); MySession.Static.ScriptManager.Init(checkpoint.ScriptManagerData); - MyDefinitionManager.Static.LoadData(TargetServerMods); + //MyDefinitionManager.Static.LoadData(TargetServerMods); PrepareBaseSession.Invoke(null, new object[] { sector }); diff --git a/SeamlessTransfer/SwitchServers.cs b/SeamlessTransfer/SwitchServers.cs index 1b2ef42..2e5f1e8 100644 --- a/SeamlessTransfer/SwitchServers.cs +++ b/SeamlessTransfer/SwitchServers.cs @@ -100,10 +100,6 @@ namespace SeamlessClientPlugin.SeamlessTransfer Sync.Clients.SetLocalSteamId(Sync.MyId, false, MyGameService.UserName); Sync.Players.RegisterEvents(); - - - - } @@ -121,69 +117,19 @@ namespace SeamlessClientPlugin.SeamlessTransfer private void ForceClientConnection() { - - - - + //Set World Settings SetWorldSettings(); + //Load force load any connected players LoadConnectedClients(); - LoadOnlinePlayers(); + - - //ModLoader.ReadyModSwitch(TargetWorld.Checkpoint, TargetWorld.Sector); MySector.InitEnvironmentSettings(TargetWorld.Sector.Environment); - - - //MethodInfo inf = typeof(MySession).GetMethod("LoadGameDefinition", BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[1] { typeof(MyObjectBuilder_Checkpoint) }, null); - //inf.Invoke(MySession.Static, new object[] { TargetWorld.Checkpoint }); - - /* - CachingDictionary dic = (CachingDictionary)typeof(MySession).GetField("m_sessionComponents", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(MySession.Static); - - foreach (var item in dic.ToList()) - { - if (item.Value.ModContext != null) - dic.Remove(item.Key, true); - } - - - foreach (KeyValuePair> item in MyScriptManager.Static.ScriptsPerMod) - { - MyStringId key = item.Value.First(); - MySession.Static.RegisterComponentsFromAssembly(MyScriptManager.Static.Scripts[key], true, item.Key); - } - - - - List dic1 = (List)typeof(MySession).GetField("m_sessionComponentForDrawAsync", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(MySession.Static); - List dic2 = (List)typeof(MySession).GetField("m_sessionComponentForDraw", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(MySession.Static); - - dic1.Clear(); - dic2.Clear(); - - foreach (MySessionComponentBase value in dic.Values) - { - - - if (value.ModContext == null || value.ModContext.IsBaseGame) - { - dic1.Add(value); - } - else - { - dic2.Add(value); - } - } - - */ - - string text = ((!string.IsNullOrEmpty(TargetWorld.Checkpoint.CustomSkybox)) ? TargetWorld.Checkpoint.CustomSkybox : MySector.EnvironmentDefinition.EnvironmentTexture); MyRenderProxy.PreloadTextures(new string[1] { text }, TextureType.CubeMap); @@ -209,20 +155,8 @@ namespace SeamlessClientPlugin.SeamlessTransfer MyHud.Chat.RegisterChat(MyMultiplayer.Static); + Patches.GPSRegisterChat.Invoke(MySession.Static.Gpss, new object[] { MyMultiplayer.Static }); - /* - foreach (MySessionComponentBase value in dic.Values) - { - - if(value.ModContext != null) - { - SeamlessClient.TryShow($"{value.Definition?.ToString()} - {value.ModContext.ModName}"); - value.BeforeStart(); - } - - - } - */ // Allow the game to start proccessing incoming messages in the buffer MyMultiplayer.Static.StartProcessingClientMessages(); @@ -230,6 +164,8 @@ namespace SeamlessClientPlugin.SeamlessTransfer //Recreate all controls... Will fix weird gui/paint/crap MyGuiScreenHudSpace.Static.RecreateControls(true); //MySession.Static.LocalHumanPlayer.BuildArmorSkin = OldArmorSkin; + + } @@ -388,8 +324,7 @@ namespace SeamlessClientPlugin.SeamlessTransfer private void LoadConnectedClients() { - - + Patches.LoadMembersFromWorld.Invoke(MySession.Static, new object[] { TargetWorld, MyMultiplayer.Static }); @@ -397,13 +332,9 @@ namespace SeamlessClientPlugin.SeamlessTransfer object VirtualClientsValue = Patches.VirtualClients.GetValue(MySession.Static); Patches.InitVirtualClients.Invoke(VirtualClientsValue, null); - /* - SeamlessClient.TryShow("Loading exsisting Members From World!"); - foreach (var Client in TargetWorld.Checkpoint.Clients) - { - SeamlessClient.TryShow("Adding New Client: " + Client.Name); - Sync.Clients.AddClient(Client.SteamId, Client.Name); - }*/ + + //load online players + LoadOnlinePlayers(); } @@ -442,6 +373,7 @@ namespace SeamlessClientPlugin.SeamlessTransfer MyMultiplayer.Static.PendingReplicablesDone -= MyMultiplayer_PendingReplicablesDone; } + private void UpdateWorldGenerator() { //This will re-init the MyProceduralWorldGenerator. (Not doing this will result in asteroids not rendering in properly) @@ -461,12 +393,9 @@ namespace SeamlessClientPlugin.SeamlessTransfer Generator.Init(GeneratorSettings); } - - //Force component to reload, re-syncing settings and seeds to the destination server Generator.LoadData(); - //We need to go in and force planets to be empty areas in the generator. This is originially done on planet init. FieldInfo PlanetInitArgs = typeof(MyPlanet).GetField("m_planetInitValues", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); foreach (var Planet in MyEntities.GetEntities().OfType()) diff --git a/Utilities/Patches.cs b/Utilities/Patches.cs index a85532a..c0bbae3 100644 --- a/Utilities/Patches.cs +++ b/Utilities/Patches.cs @@ -69,6 +69,7 @@ namespace SeamlessClientPlugin.SeamlessTransfer public static MethodInfo LoadPlayerInternal { get; private set; } public static MethodInfo LoadMembersFromWorld { get; private set; } public static MethodInfo LoadMultiplayer { get; private set; } + public static MethodInfo GPSRegisterChat { get; private set; } public static MethodInfo SendPlayerData; @@ -118,7 +119,7 @@ namespace SeamlessClientPlugin.SeamlessTransfer LoadMultiplayer = GetMethod(typeof(MySession), "LoadMultiplayer", BindingFlags.Static | BindingFlags.NonPublic); SendPlayerData = GetMethod(ClientType, "SendPlayerData", BindingFlags.Instance | BindingFlags.NonPublic); UnloadProceduralWorldGenerator = GetMethod(typeof(MyProceduralWorldGenerator), "UnloadData", BindingFlags.Instance | BindingFlags.NonPublic); - + GPSRegisterChat = GetMethod(typeof(MyGpsCollection), "RegisterChat", BindingFlags.Instance | BindingFlags.NonPublic); @@ -128,7 +129,7 @@ namespace SeamlessClientPlugin.SeamlessTransfer //Test patches - MethodInfo SetPlayerDed = GetMethod(typeof(MyPlayerCollection), "SetPlayerDeadInternal", BindingFlags.Instance | BindingFlags.NonPublic); + //MethodInfo SetPlayerDed = GetMethod(typeof(MyPlayerCollection), "SetPlayerDeadInternal", BindingFlags.Instance | BindingFlags.NonPublic); @@ -140,7 +141,7 @@ namespace SeamlessClientPlugin.SeamlessTransfer Patcher.Patch(LoadingScreenDraw, prefix: new HarmonyMethod(GetPatchMethod(nameof(DrawInternal)))); Patcher.Patch(OnJoin, postfix: new HarmonyMethod(GetPatchMethod(nameof(OnUserJoined)))); Patcher.Patch(LoadingAction, prefix: new HarmonyMethod(GetPatchMethod(nameof(LoadMultiplayerSession)))); - Patcher.Patch(SetPlayerDed, prefix: new HarmonyMethod(GetPatchMethod(nameof(SetPlayerDeadInternal)))); + //Patcher.Patch(SetPlayerDed, prefix: new HarmonyMethod(GetPatchMethod(nameof(SetPlayerDeadInternal)))); @@ -434,73 +435,6 @@ namespace SeamlessClientPlugin.SeamlessTransfer { throw Ex; } - - } - - - - private static bool SetPlayerDeadInternal(MyPlayerCollection __instance, bool __result, ulong playerSteamId, int playerSerialId, bool deadState, bool resetIdentity) - { - - FieldInfo ControlledEntities = typeof(MyPlayerCollection).GetField("m_controlledEntities", BindingFlags.Instance | BindingFlags.NonPublic); - MethodInfo RemoveControlledEntity = typeof(MyPlayerCollection).GetMethod("RemoveControlledEntityInternal", BindingFlags.Instance | BindingFlags.NonPublic); - - CachingDictionary m_controlledEntities = (CachingDictionary)ControlledEntities.GetValue(__instance); - - - - - MyPlayer.PlayerId id = new MyPlayer.PlayerId(playerSteamId, playerSerialId); - MyPlayer playerById = Sync.Players.GetPlayerById(id); - if (playerById == null) - { - __result = false; - return false; - } - if (playerById.Identity == null) - { - __result = false; - return false; - } - playerById.Identity.SetDead(resetIdentity); - if (deadState) - { - - SeamlessClient.TryShow($"Player: {playerSteamId}, SerialID: {playerSerialId} deadstate: {deadState}, resetIdentity: {resetIdentity}"); - - playerById.Controller.TakeControl(null); - foreach (KeyValuePair controlledEntity in m_controlledEntities) - { - if (controlledEntity.Value == playerById.Id) - { - MyEntity entity = null; - MyEntities.TryGetEntityById(controlledEntity.Key, out entity); - if (entity != null) - { - //RemoveControlledEntityInternal(entity, false); - RemoveControlledEntity.Invoke(__instance, new object[] { entity, false }); - } - } - } - - - - m_controlledEntities.ApplyRemovals(); - if (Sync.Clients.LocalClient != null && playerById == Sync.Clients.LocalClient.FirstPlayer) - { - MyPlayer P = Sync.Clients.LocalClient.FirstPlayer; - SeamlessClient.TryShow($"FirstPlayerName: {P.DisplayName}, ID: {P.Id.SteamId}, Serial: {P.Id.SerialId}"); - SeamlessClient.TryShow(Environment.StackTrace); - MyPlayerCollection.RequestLocalRespawn(); - } - } - - __result = true; - return false; - } - - - } }