Update for latest version of seamless
Notable feature: ModAPI
This commit is contained in:
119
Components/ModAPI.cs
Normal file
119
Components/ModAPI.cs
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
using HarmonyLib;
|
||||||
|
using Sandbox.Game.World;
|
||||||
|
using SeamlessClient.Utilities;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using VRage.Collections;
|
||||||
|
using VRage.Game;
|
||||||
|
using VRage.Game.Components;
|
||||||
|
using VRage.Utils;
|
||||||
|
|
||||||
|
namespace SeamlessClient.Components
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// ModAPI so that mods can register seamless events
|
||||||
|
/// </summary>
|
||||||
|
public class ModAPI : ComponentBase
|
||||||
|
{
|
||||||
|
private static FieldInfo SessionComponents;
|
||||||
|
private static List<LoadedMod> LoadedMods = new List<LoadedMod>();
|
||||||
|
|
||||||
|
public class LoadedMod
|
||||||
|
{
|
||||||
|
public MethodInfo SeamlessServerUnload;
|
||||||
|
public MethodInfo SeamlessServerLoad;
|
||||||
|
public MySessionComponentBase ModSession;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override void Patch(Harmony patcher)
|
||||||
|
{
|
||||||
|
|
||||||
|
var AddModAssembly = PatchUtils.GetMethod(typeof(MySession), "TryRegisterSessionComponent");
|
||||||
|
patcher.Patch(AddModAssembly, postfix: new HarmonyMethod(Get(typeof(ModAPI), nameof(AddModAssembly))));
|
||||||
|
|
||||||
|
SessionComponents = PatchUtils.GetField(typeof(MySession), "m_sessionComponents");
|
||||||
|
|
||||||
|
|
||||||
|
base.Patch(patcher);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ClearCache()
|
||||||
|
{
|
||||||
|
LoadedMods.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void StartModSwitching()
|
||||||
|
{
|
||||||
|
|
||||||
|
Seamless.TryShow($"Invoking SeamlessUnload API on {LoadedMods.Count} mods!");
|
||||||
|
foreach (var mod in LoadedMods)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
mod.SeamlessServerUnload?.Invoke(mod.ModSession, null);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Seamless.TryShow(ex, $"Error during modAPI unloading! {mod.SeamlessServerUnload.Name}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ServerSwitched()
|
||||||
|
{
|
||||||
|
Seamless.TryShow($"Invoking SeamlessServerLoad API on {LoadedMods.Count} mods!");
|
||||||
|
foreach (var mod in LoadedMods)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
mod.SeamlessServerLoad?.Invoke(mod.ModSession, null);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Seamless.TryShow(ex, $"Error during modAPI loading! {mod.SeamlessServerLoad.Name}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void AddModAssembly(Type type, bool modAssembly, MyModContext context)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (!modAssembly || context == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
CachingDictionary<Type, MySessionComponentBase> dict = (CachingDictionary<Type, MySessionComponentBase>)SessionComponents.GetValue(MySession.Static);
|
||||||
|
dict.TryGetValue(type, out MySessionComponentBase component);
|
||||||
|
Seamless.TryShow($"Loading Mod Assembly: {component.ComponentType.FullName}");
|
||||||
|
|
||||||
|
MethodInfo Load = AccessTools.Method(component.ComponentType, "SeamlessServerLoaded");
|
||||||
|
MethodInfo Unload = AccessTools.Method(component.ComponentType, "SeamlessServerUnloaded");
|
||||||
|
|
||||||
|
if(Load != null || Unload != null)
|
||||||
|
{
|
||||||
|
|
||||||
|
LoadedMod newMod = new LoadedMod();
|
||||||
|
newMod.SeamlessServerLoad = Load;
|
||||||
|
newMod.SeamlessServerUnload = Unload;
|
||||||
|
newMod.ModSession = component;
|
||||||
|
|
||||||
|
Seamless.TryShow($"Mod Assembly: {component.ComponentType.FullName} has SeamlessServerLoaded/SeamlessServerUnloaded methods!");
|
||||||
|
|
||||||
|
LoadedMods.Add(newMod);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@@ -55,7 +55,7 @@ namespace SeamlessClient.Components
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(t <= 0)
|
if (t <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
stringBuilder.AppendLine($" [T-{FormatDuration(t)}]");
|
stringBuilder.AppendLine($" [T-{FormatDuration(t)}]");
|
||||||
|
@@ -47,7 +47,7 @@ namespace SeamlessClient.OnlinePlayersWindow
|
|||||||
|
|
||||||
foreach (OnlineClientServer server in servers)
|
foreach (OnlineClientServer server in servers)
|
||||||
{
|
{
|
||||||
if(server.ServerID == CurrentServer)
|
if (server.ServerID == CurrentServer)
|
||||||
{
|
{
|
||||||
onlineServer = server;
|
onlineServer = server;
|
||||||
continue;
|
continue;
|
||||||
|
@@ -91,7 +91,7 @@ namespace SeamlessClient.ServerSwitching
|
|||||||
|
|
||||||
private void PauseResetTimer_Elapsed(object sender, ElapsedEventArgs e)
|
private void PauseResetTimer_Elapsed(object sender, ElapsedEventArgs e)
|
||||||
{
|
{
|
||||||
if(MySandboxGame.IsPaused)
|
if (MySandboxGame.IsPaused)
|
||||||
{
|
{
|
||||||
Seamless.TryShow("Game is still paused... Attempting to unpause!");
|
Seamless.TryShow("Game is still paused... Attempting to unpause!");
|
||||||
MySandboxGame.PausePop();
|
MySandboxGame.PausePop();
|
||||||
@@ -179,6 +179,7 @@ namespace SeamlessClient.ServerSwitching
|
|||||||
MySandboxGame.PausePop();
|
MySandboxGame.PausePop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ModAPI.ServerSwitched();
|
||||||
SendPlayerData.Invoke(MyMultiplayer.Static, new object[] { MyGameService.OnlineName });
|
SendPlayerData.Invoke(MyMultiplayer.Static, new object[] { MyGameService.OnlineName });
|
||||||
isSwitch = false;
|
isSwitch = false;
|
||||||
}
|
}
|
||||||
@@ -186,7 +187,7 @@ namespace SeamlessClient.ServerSwitching
|
|||||||
|
|
||||||
public static bool LoadClientsFromWorld(ref List<MyObjectBuilder_Client> clients)
|
public static bool LoadClientsFromWorld(ref List<MyObjectBuilder_Client> clients)
|
||||||
{
|
{
|
||||||
if(!isSwitch || clients == null || clients.Count == 0)
|
if (!isSwitch || clients == null || clients.Count == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
||||||
@@ -198,7 +199,7 @@ namespace SeamlessClient.ServerSwitching
|
|||||||
|
|
||||||
var keys = m_memberData.Keys.Cast<ulong>();
|
var keys = m_memberData.Keys.Cast<ulong>();
|
||||||
|
|
||||||
for(int i = clients.Count - 1; i >= 0; i-- )
|
for (int i = clients.Count - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
Seamless.TryShow($"Client {clients[i].SteamId}");
|
Seamless.TryShow($"Client {clients[i].SteamId}");
|
||||||
if (keys.Contains(clients[i].SteamId))
|
if (keys.Contains(clients[i].SteamId))
|
||||||
@@ -217,7 +218,7 @@ namespace SeamlessClient.ServerSwitching
|
|||||||
|
|
||||||
private static bool ProcessAllMembersData(ref AllMembersDataMsg msg)
|
private static bool ProcessAllMembersData(ref AllMembersDataMsg msg)
|
||||||
{
|
{
|
||||||
if(!isSwitch)
|
if (!isSwitch)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
||||||
@@ -326,7 +327,8 @@ namespace SeamlessClient.ServerSwitching
|
|||||||
UnloadServer();
|
UnloadServer();
|
||||||
SetNewMultiplayerClient();
|
SetNewMultiplayerClient();
|
||||||
|
|
||||||
}catch(Exception ex)
|
}
|
||||||
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Seamless.TryShow(ex.ToString());
|
Seamless.TryShow(ex.ToString());
|
||||||
}
|
}
|
||||||
@@ -422,7 +424,7 @@ namespace SeamlessClient.ServerSwitching
|
|||||||
Seamless.TryShow($"2 NexusMajor: {Seamless.NexusVersion.Major} - ConrolledEntity {MySession.Static.ControlledEntity == null} - HumanPlayer {MySession.Static.LocalHumanPlayer == null} - Character {MySession.Static.LocalCharacter == null}");
|
Seamless.TryShow($"2 NexusMajor: {Seamless.NexusVersion.Major} - ConrolledEntity {MySession.Static.ControlledEntity == null} - HumanPlayer {MySession.Static.LocalHumanPlayer == null} - Character {MySession.Static.LocalCharacter == null}");
|
||||||
|
|
||||||
|
|
||||||
|
ModAPI.StartModSwitching();
|
||||||
|
|
||||||
//MyMultiplayer.Static.ReplicationLayer.Disconnect();
|
//MyMultiplayer.Static.ReplicationLayer.Disconnect();
|
||||||
//MyMultiplayer.Static.ReplicationLayer.Dispose();
|
//MyMultiplayer.Static.ReplicationLayer.Dispose();
|
||||||
@@ -535,13 +537,13 @@ namespace SeamlessClient.ServerSwitching
|
|||||||
|
|
||||||
|
|
||||||
List<ulong> clients = new List<ulong>();
|
List<ulong> clients = new List<ulong>();
|
||||||
foreach(var client in Sync.Clients.GetClients())
|
foreach (var client in Sync.Clients.GetClients())
|
||||||
{
|
{
|
||||||
clients.Add(client.SteamUserId);
|
clients.Add(client.SteamUserId);
|
||||||
Seamless.TryShow($"ADDING {client.SteamUserId} - {Sync.MyId}");
|
Seamless.TryShow($"ADDING {client.SteamUserId} - {Sync.MyId}");
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach(var client in clients)
|
foreach (var client in clients)
|
||||||
{
|
{
|
||||||
if (client == TargetServer.SteamID || client == Sync.MyId)
|
if (client == TargetServer.SteamID || client == Sync.MyId)
|
||||||
continue;
|
continue;
|
||||||
|
@@ -69,17 +69,17 @@ namespace SeamlessClient.Components
|
|||||||
if (WaitingForClientCheck == false && isSeamlessSwitching)
|
if (WaitingForClientCheck == false && isSeamlessSwitching)
|
||||||
WaitingForClientCheck = true;
|
WaitingForClientCheck = true;
|
||||||
|
|
||||||
if(WaitingForClientCheck && MySession.Static.LocalHumanPlayer != null)
|
if (WaitingForClientCheck && MySession.Static.LocalHumanPlayer != null)
|
||||||
WaitingForClientCheck = false;
|
WaitingForClientCheck = false;
|
||||||
|
|
||||||
if (isSeamlessSwitching || WaitingForClientCheck)
|
if (isSeamlessSwitching || WaitingForClientCheck)
|
||||||
{
|
{
|
||||||
//SeamlessClient.TryShow("Switching Servers!");
|
//SeamlessClient.TryShow("Switching Servers!");
|
||||||
MyRenderProxy.DebugDrawText2D(new VRageMath.Vector2(MySandboxGame.ScreenViewport.Width/2, MySandboxGame.ScreenViewport.Height - 150), SwitchingText, VRageMath.Color.AliceBlue, 1f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER);
|
MyRenderProxy.DebugDrawText2D(new VRageMath.Vector2(MySandboxGame.ScreenViewport.Width / 2, MySandboxGame.ScreenViewport.Height - 150), SwitchingText, VRageMath.Color.AliceBlue, 1f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER);
|
||||||
MyRenderProxy.DebugDrawText2D(new VRageMath.Vector2(MySandboxGame.ScreenViewport.Width / 2, MySandboxGame.ScreenViewport.Height - 200), $"Transferring to {TargetServer.Name}", VRageMath.Color.Yellow, 1.5f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER);
|
MyRenderProxy.DebugDrawText2D(new VRageMath.Vector2(MySandboxGame.ScreenViewport.Width / 2, MySandboxGame.ScreenViewport.Height - 200), $"Transferring to {TargetServer.Name}", VRageMath.Color.Yellow, 1.5f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER);
|
||||||
|
|
||||||
|
|
||||||
MyRenderProxy.DebugDrawLine2D(new VRageMath.Vector2((MySandboxGame.ScreenViewport.Width / 2) - 250, MySandboxGame.ScreenViewport.Height - 170), new VRageMath.Vector2((MySandboxGame.ScreenViewport.Width / 2)+250, MySandboxGame.ScreenViewport.Height - 170), VRageMath.Color.Blue, VRageMath.Color.Green);
|
MyRenderProxy.DebugDrawLine2D(new VRageMath.Vector2((MySandboxGame.ScreenViewport.Width / 2) - 250, MySandboxGame.ScreenViewport.Height - 170), new VRageMath.Vector2((MySandboxGame.ScreenViewport.Width / 2) + 250, MySandboxGame.ScreenViewport.Height - 170), VRageMath.Color.Blue, VRageMath.Color.Green);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +101,50 @@ namespace SeamlessClient.Components
|
|||||||
VirtualClients = PatchUtils.GetField(typeof(MySession), "VirtualClients");
|
VirtualClients = PatchUtils.GetField(typeof(MySession), "VirtualClients");
|
||||||
|
|
||||||
patcher.Patch(onJoin, postfix: new HarmonyMethod(Get(typeof(ServerSwitcherComponentOLD), nameof(OnUserJoined))));
|
patcher.Patch(onJoin, postfix: new HarmonyMethod(Get(typeof(ServerSwitcherComponentOLD), nameof(OnUserJoined))));
|
||||||
base.Patch(patcher);
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Initilized()
|
||||||
|
{
|
||||||
|
MyAPIGateway.Utilities.MessageEntered += Utilities_MessageEntered;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Utilities_MessageEntered(string messageText, ref bool sendToOthers)
|
||||||
|
{
|
||||||
|
if (!messageText.StartsWith("/nexus"))
|
||||||
|
return;
|
||||||
|
|
||||||
|
string[] cmd = messageText.ToLowerInvariant().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
|
||||||
|
if (cmd[1] == "refreshcharacter")
|
||||||
|
{
|
||||||
|
if (MySession.Static.LocalHumanPlayer == null)
|
||||||
|
{
|
||||||
|
MyAPIGateway.Utilities?.ShowMessage("Seamless", "LocalHumanPlayer Null!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MySession.Static.LocalHumanPlayer.Character == null)
|
||||||
|
{
|
||||||
|
MyAPIGateway.Utilities?.ShowMessage("Seamless", "LocalHumanPlayerCharacter Null!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//None of this shit works.... 5/3/2025
|
||||||
|
MySession.Static.LocalHumanPlayer.SpawnIntoCharacter(MySession.Static.LocalHumanPlayer.Character);
|
||||||
|
MySession.Static.LocalHumanPlayer.Controller.TakeControl(MySession.Static.LocalHumanPlayer.Character);
|
||||||
|
|
||||||
|
MySession.Static.LocalHumanPlayer.Character.GetOffLadder();
|
||||||
|
MySession.Static.LocalHumanPlayer.Character.Stand();
|
||||||
|
|
||||||
|
MySession.Static.LocalHumanPlayer.Character.ResetControls();
|
||||||
|
MySession.Static.LocalHumanPlayer.Character.UpdateCharacterPhysics(true);
|
||||||
|
|
||||||
|
MyAPIGateway.Utilities?.ShowMessage("Seamless", "Character Controls Reset!");
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void OnUserJoined(ref JoinResultMsg msg)
|
private static void OnUserJoined(ref JoinResultMsg msg)
|
||||||
@@ -111,14 +154,16 @@ namespace SeamlessClient.Components
|
|||||||
//SeamlessClient.TryShow("User Joined! Result: " + msg.JoinResult.ToString());
|
//SeamlessClient.TryShow("User Joined! Result: " + msg.JoinResult.ToString());
|
||||||
|
|
||||||
//Invoke the switch event
|
//Invoke the switch event
|
||||||
|
|
||||||
SwitchingText = "Server Responded! Removing Old Entities and forcing client connection!";
|
SwitchingText = "Server Responded! Removing Old Entities and forcing client connection!";
|
||||||
RemoveOldEntities();
|
RemoveOldEntities();
|
||||||
ForceClientConnection();
|
ForceClientConnection();
|
||||||
|
ModAPI.ServerSwitched();
|
||||||
|
|
||||||
//Fix any character issues
|
|
||||||
if (MySession.Static.LocalCharacter != null)
|
|
||||||
MySession.Static.LocalHumanPlayer.SpawnIntoCharacter(MySession.Static.LocalCharacter);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
MySession.Static.LocalHumanPlayer?.Character?.Stand();
|
||||||
isSeamlessSwitching = false;
|
isSeamlessSwitching = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -126,7 +171,7 @@ namespace SeamlessClient.Components
|
|||||||
public void StartBackendSwitch(MyGameServerItem _TargetServer, MyObjectBuilder_World _TargetWorld)
|
public void StartBackendSwitch(MyGameServerItem _TargetServer, MyObjectBuilder_World _TargetWorld)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(MySession.Static.LocalCharacter != null)
|
if (MySession.Static.LocalCharacter != null)
|
||||||
{
|
{
|
||||||
var viewMatrix = MySession.Static.LocalCharacter.GetViewMatrix();
|
var viewMatrix = MySession.Static.LocalCharacter.GetViewMatrix();
|
||||||
MySpectator.Static.SetViewMatrix(viewMatrix);
|
MySpectator.Static.SetViewMatrix(viewMatrix);
|
||||||
@@ -140,10 +185,15 @@ namespace SeamlessClient.Components
|
|||||||
|
|
||||||
MySandboxGame.Static.Invoke(delegate
|
MySandboxGame.Static.Invoke(delegate
|
||||||
{
|
{
|
||||||
|
//Pause the game/update thread while we load
|
||||||
|
MySandboxGame.IsPaused = true;
|
||||||
|
|
||||||
//Set camera controller to fixed spectator
|
//Set camera controller to fixed spectator
|
||||||
MySession.Static.SetCameraController(MyCameraControllerEnum.SpectatorFixed);
|
MySession.Static.SetCameraController(MyCameraControllerEnum.SpectatorFixed);
|
||||||
UnloadCurrentServer();
|
UnloadCurrentServer();
|
||||||
SetNewMultiplayerClient();
|
SetNewMultiplayerClient();
|
||||||
|
ModAPI.StartModSwitching();
|
||||||
|
|
||||||
//SeamlessClient.IsSwitching = false;
|
//SeamlessClient.IsSwitching = false;
|
||||||
|
|
||||||
SwitchingText = "Waiting for server response...";
|
SwitchingText = "Waiting for server response...";
|
||||||
@@ -172,7 +222,7 @@ namespace SeamlessClient.Components
|
|||||||
|
|
||||||
SwitchingText = "New Multiplayer Session Set";
|
SwitchingText = "New Multiplayer Session Set";
|
||||||
Seamless.TryShow("Successfully set MyMultiplayer.Static");
|
Seamless.TryShow("Successfully set MyMultiplayer.Static");
|
||||||
|
MySandboxGame.IsPaused = true;
|
||||||
|
|
||||||
Sync.Clients.SetLocalSteamId(Sync.MyId, false, MyGameService.UserName);
|
Sync.Clients.SetLocalSteamId(Sync.MyId, false, MyGameService.UserName);
|
||||||
Sync.Players.RegisterEvents();
|
Sync.Players.RegisterEvents();
|
||||||
@@ -184,6 +234,8 @@ namespace SeamlessClient.Components
|
|||||||
private static void ForceClientConnection()
|
private static void ForceClientConnection()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Set World Settings
|
//Set World Settings
|
||||||
SetWorldSettings();
|
SetWorldSettings();
|
||||||
|
|
||||||
@@ -217,6 +269,8 @@ namespace SeamlessClient.Components
|
|||||||
|
|
||||||
StartEntitySync();
|
StartEntitySync();
|
||||||
|
|
||||||
|
//Resume the game/update thread
|
||||||
|
MySandboxGame.IsPaused = false;
|
||||||
|
|
||||||
MyHud.Chat.RegisterChat(MyMultiplayer.Static);
|
MyHud.Chat.RegisterChat(MyMultiplayer.Static);
|
||||||
GpsRegisterChat.Invoke(MySession.Static.Gpss, new object[] { MyMultiplayer.Static });
|
GpsRegisterChat.Invoke(MySession.Static.Gpss, new object[] { MyMultiplayer.Static });
|
||||||
@@ -228,6 +282,12 @@ namespace SeamlessClient.Components
|
|||||||
//Recreate all controls... Will fix weird gui/paint/crap
|
//Recreate all controls... Will fix weird gui/paint/crap
|
||||||
MyGuiScreenHudSpace.Static.RecreateControls(true);
|
MyGuiScreenHudSpace.Static.RecreateControls(true);
|
||||||
SwitchingText = "Client Registered. Waiting for entities from server...";
|
SwitchingText = "Client Registered. Waiting for entities from server...";
|
||||||
|
|
||||||
|
|
||||||
|
Seamless.TryShow($"LocalHumanPlayer = {MySession.Static.LocalHumanPlayer == null}");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//MySession.Static.LocalHumanPlayer.BuildArmorSkin = OldArmorSkin;
|
//MySession.Static.LocalHumanPlayer.BuildArmorSkin = OldArmorSkin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -392,6 +452,8 @@ namespace SeamlessClient.Components
|
|||||||
private static void LoadConnectedClients()
|
private static void LoadConnectedClients()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
//TargetWorld.Checkpoint.AllPlayers.Count
|
||||||
|
Seamless.TryShow($"Loading members from world... {TargetWorld.Checkpoint.AllPlayers.Count}");
|
||||||
LoadMembersFromWorld.Invoke(MySession.Static, new object[] { TargetWorld, MyMultiplayer.Static });
|
LoadMembersFromWorld.Invoke(MySession.Static, new object[] { TargetWorld, MyMultiplayer.Static });
|
||||||
|
|
||||||
|
|
||||||
@@ -511,7 +573,8 @@ namespace SeamlessClient.Components
|
|||||||
//Close any respawn screens that are open
|
//Close any respawn screens that are open
|
||||||
MyGuiScreenMedicals.Close();
|
MyGuiScreenMedicals.Close();
|
||||||
|
|
||||||
//MySession.Static.UnloadDataComponents();
|
//Unload any lingering updates queued
|
||||||
|
MyEntities.Orchestrator.Unload();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -520,7 +583,11 @@ namespace SeamlessClient.Components
|
|||||||
foreach (var ent in MyEntities.GetEntities())
|
foreach (var ent in MyEntities.GetEntities())
|
||||||
{
|
{
|
||||||
if (ent is MyPlanet)
|
if (ent is MyPlanet)
|
||||||
|
{
|
||||||
|
//Re-Add planet updates
|
||||||
|
MyEntities.RegisterForUpdate(ent);
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
ent.Close();
|
ent.Close();
|
||||||
}
|
}
|
||||||
|
@@ -113,7 +113,7 @@ namespace SeamlessClient.GUI.Screens
|
|||||||
m_isTopMostScreen = true;
|
m_isTopMostScreen = true;
|
||||||
|
|
||||||
object instance = PatchUtils.GetProperty(PatchUtils.MyLoadingPerformance, "Instance").GetValue(null);
|
object instance = PatchUtils.GetProperty(PatchUtils.MyLoadingPerformance, "Instance").GetValue(null);
|
||||||
if(instance != null)
|
if (instance != null)
|
||||||
PatchUtils.GetMethod(PatchUtils.MyLoadingPerformance, "StartTiming").Invoke(instance, null);
|
PatchUtils.GetMethod(PatchUtils.MyLoadingPerformance, "StartTiming").Invoke(instance, null);
|
||||||
|
|
||||||
//MyLoadingPerformance.Instance.StartTiming();
|
//MyLoadingPerformance.Instance.StartTiming();
|
||||||
@@ -531,9 +531,9 @@ namespace SeamlessClient.GUI.Screens
|
|||||||
MyGuiManager.GetSafeHeightFullScreenPictureSize(MyGuiConstants.LOADING_BACKGROUND_TEXTURE_REAL_SIZE, out outRect);
|
MyGuiManager.GetSafeHeightFullScreenPictureSize(MyGuiConstants.LOADING_BACKGROUND_TEXTURE_REAL_SIZE, out outRect);
|
||||||
|
|
||||||
bool isCustom = false;
|
bool isCustom = false;
|
||||||
if(LoadingScreenComponent.CustomLoadingTextures.Count != 0)
|
if (LoadingScreenComponent.CustomLoadingTextures.Count != 0)
|
||||||
{
|
{
|
||||||
if(LoadingScreenComponent.CustomLoadingTextures.Count > 1)
|
if (LoadingScreenComponent.CustomLoadingTextures.Count > 1)
|
||||||
{
|
{
|
||||||
if (!backgroundTimer.Enabled)
|
if (!backgroundTimer.Enabled)
|
||||||
{
|
{
|
||||||
|
@@ -385,8 +385,6 @@ namespace SeamlessClient.OnlinePlayersWindow
|
|||||||
Controls.Add(m_playersTable);
|
Controls.Add(m_playersTable);
|
||||||
|
|
||||||
|
|
||||||
string servername = PlayersWindowComponent.onlineServer?.ServerName ?? "thisServer";
|
|
||||||
|
|
||||||
foreach (MyPlayer onlinePlayer in Sync.Players.GetOnlinePlayers())
|
foreach (MyPlayer onlinePlayer in Sync.Players.GetOnlinePlayers())
|
||||||
{
|
{
|
||||||
if (onlinePlayer.Id.SerialId != 0)
|
if (onlinePlayer.Id.SerialId != 0)
|
||||||
@@ -403,16 +401,14 @@ namespace SeamlessClient.OnlinePlayersWindow
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AddPlayer(onlinePlayer.Id.SteamId, $"{MyMultiplayer.Static.HostName ?? "thisServer"}*");
|
||||||
|
|
||||||
AddPlayer(onlinePlayer.Id.SteamId, servername);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
foreach(var server in PlayersWindowComponent.allServers)
|
foreach (var server in PlayersWindowComponent.allServers)
|
||||||
{
|
{
|
||||||
|
|
||||||
foreach(var player in server.Players)
|
foreach (var player in server.Players)
|
||||||
AddPlayerFromOtherServer(player, server.ServerName);
|
AddPlayerFromOtherServer(player, server.ServerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -796,7 +792,7 @@ namespace SeamlessClient.OnlinePlayersWindow
|
|||||||
|
|
||||||
protected void Multiplayer_PlayerJoined(ulong userId, string userName)
|
protected void Multiplayer_PlayerJoined(ulong userId, string userName)
|
||||||
{
|
{
|
||||||
AddPlayer(userId, PlayersWindowComponent.onlineServer.ServerName);
|
AddPlayer(userId, PlayersWindowComponent.onlineServer?.ServerName ?? "Unknown");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void Multiplayer_PlayerLeft(ulong userId, MyChatMemberStateChangeEnum arg2)
|
protected void Multiplayer_PlayerLeft(ulong userId, MyChatMemberStateChangeEnum arg2)
|
||||||
|
@@ -33,5 +33,5 @@ using System.Runtime.InteropServices;
|
|||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
|
|
||||||
[assembly: AssemblyVersion("3.0.0.6")] //Set these both to the same
|
[assembly: AssemblyVersion("3.0.0.10")] //Set these both to the same
|
||||||
[assembly: AssemblyFileVersion("3.0.0.6")]
|
[assembly: AssemblyFileVersion("3.0.0.10")]
|
||||||
|
18
README.md
18
README.md
@@ -13,13 +13,21 @@ With Nexus servers, all data is shared between servers. (Factions, Identities, P
|
|||||||
|
|
||||||
|
|
||||||
## How to install
|
## How to install
|
||||||
Simply install the plguin loader, and check this plugins box to be added to the plugin loaders' active plugin list. (SE will need to be restarted afterwards)
|
Simply install the plugin loader, and check this plugin's box to be added to the plugin loaders' active plugin list. (SE will need to be restarted afterwards)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Known issues
|
## Known issues
|
||||||
Obviously this is not an issue free-system. Currently since im doing no mod unloading or loading there could be issues if your servers dont have the exact same mods, or the mods dont properly work right. Please do not swarm mod authors with faults if seamless doesnt play nice with it. ***Its not their fault*** its ***mine***. I will be trying to implement mod unloading and loading switching between servers, just no ETA.
|
Obviously this is not an issue-free system. Currently, since im doing no mod unloading or loading, there could be issues if your servers don't have the same mods, or the mods don't work right. Please do not swarm mod authors with faults if seamless doesn't play nice with it. ***Its not their fault*** its ***mine***. I will be trying to implement mod unloading and loading switching between servers, just no ETA.
|
||||||
|
|
||||||
|
## ModAPI
|
||||||
|
I attempted to avoid implementing any modAPI in seamless, but unfortunately, Space Engineers doesn't handle unloading and reloading the same mod without compiling easily. Either I compile the mod every time you switch servers, eventually running into memory issues, or I attempt to unload the mod manually and restart it.
|
||||||
|
In both scenarios, unloading static variables are often up to the mod author and sometimes are set to null. On mod load, these variables are not re-instantiated with the default values resulting in many issues. It is way easier for mod authors when needed implement seamless unload and load logic appropriately.
|
||||||
|
|
||||||
|
There are two methods you can add to your mods (In the main mod session component class)
|
||||||
|
|
||||||
|
private void SeamlessServerLoaded(){}
|
||||||
|
private void SeamlessServerUnloaded(){}
|
||||||
|
|
||||||
|
Unloaded happens when seamless starts switching, Loaded when seamless is done switching. Seamless patches these methods on mod compilation.
|
||||||
|
|
||||||
|
|
||||||
## Fork Changes
|
|
||||||
This fork changes how components are loaded to be compatible with [CringeLauncher](https://git.zznty.ru/PvE/se-launcher).
|
|
23
Seamless.cs
23
Seamless.cs
@@ -2,6 +2,7 @@
|
|||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using NLog.Fluent;
|
using NLog.Fluent;
|
||||||
using Sandbox;
|
using Sandbox;
|
||||||
|
using Sandbox.Engine.Multiplayer;
|
||||||
using Sandbox.Game.Localization;
|
using Sandbox.Game.Localization;
|
||||||
using Sandbox.Game.World;
|
using Sandbox.Game.World;
|
||||||
using Sandbox.ModAPI;
|
using Sandbox.ModAPI;
|
||||||
@@ -49,10 +50,15 @@ namespace SeamlessClient
|
|||||||
GetComponents();
|
GetComponents();
|
||||||
|
|
||||||
PatchComponents(SeamlessPatcher);
|
PatchComponents(SeamlessPatcher);
|
||||||
|
MySession.LoadingStep += SessionLoaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void SessionLoaded(LoadingProgress progress)
|
||||||
|
{
|
||||||
|
if (progress >= LoadingProgress.PROGRESS_STEP8)
|
||||||
|
SendSeamlessVersion();
|
||||||
|
}
|
||||||
|
|
||||||
private void GetComponents()
|
private void GetComponents()
|
||||||
{
|
{
|
||||||
@@ -93,16 +99,19 @@ namespace SeamlessClient
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void InitilizeComponents()
|
private void InitilizeComponents()
|
||||||
{
|
{
|
||||||
foreach(ComponentBase component in allComps)
|
foreach (ComponentBase component in allComps)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
component.Initilized();
|
component.Initilized();
|
||||||
TryShow($"Initilized {component.GetType()}");
|
TryShow($"Initilized {component.GetType()}");
|
||||||
|
|
||||||
}catch(Exception ex)
|
}
|
||||||
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
TryShow(ex, $"Failed to initialize {component.GetType()}");
|
TryShow(ex, $"Failed to initialize {component.GetType()}");
|
||||||
}
|
}
|
||||||
@@ -126,17 +135,11 @@ namespace SeamlessClient
|
|||||||
isSeamlessServer = true;
|
isSeamlessServer = true;
|
||||||
switch (msg.MessageType)
|
switch (msg.MessageType)
|
||||||
{
|
{
|
||||||
case ClientMessageType.FirstJoin:
|
|
||||||
Seamless.TryShow("Sending First Join!");
|
|
||||||
SendSeamlessVersion();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ClientMessageType.TransferServer:
|
case ClientMessageType.TransferServer:
|
||||||
StartSwitch(msg.GetTransferData());
|
StartSwitch(msg.GetTransferData());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ClientMessageType.OnlinePlayers:
|
case ClientMessageType.OnlinePlayers:
|
||||||
//Not implemented yet
|
|
||||||
var playerData = msg.GetOnlinePlayers();
|
var playerData = msg.GetOnlinePlayers();
|
||||||
PlayersWindowComponent.ApplyRecievedPlayers(playerData.OnlineServers, playerData.currentServerID);
|
PlayersWindowComponent.ApplyRecievedPlayers(playerData.OnlineServers, playerData.currentServerID);
|
||||||
break;
|
break;
|
||||||
@@ -151,6 +154,8 @@ namespace SeamlessClient
|
|||||||
ClientMessage response = new ClientMessage(SeamlessVersion.ToString());
|
ClientMessage response = new ClientMessage(SeamlessVersion.ToString());
|
||||||
MyAPIGateway.Multiplayer?.SendMessageToServer(SeamlessClientNetId, MessageUtils.Serialize(response));
|
MyAPIGateway.Multiplayer?.SendMessageToServer(SeamlessClientNetId, MessageUtils.Serialize(response));
|
||||||
Seamless.TryShow("Sending Seamless request...");
|
Seamless.TryShow("Sending Seamless request...");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -97,7 +97,7 @@ Type.GetType("Sandbox.Game.Screens.Helpers.MyLoadingScreenText, Sandbox.Game");
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
//MethodInfo ConnectToServer = GetMethod(typeof(MyGameService), "ConnectToServer", BindingFlags.Static | BindingFlags.Public);
|
|
||||||
base.Patch(patcher);
|
base.Patch(patcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user