Update for latest version of seamless
Notable feature: ModAPI
This commit is contained in:
@@ -69,17 +69,17 @@ namespace SeamlessClient.Components
|
||||
if (WaitingForClientCheck == false && isSeamlessSwitching)
|
||||
WaitingForClientCheck = true;
|
||||
|
||||
if(WaitingForClientCheck && MySession.Static.LocalHumanPlayer != null)
|
||||
if (WaitingForClientCheck && MySession.Static.LocalHumanPlayer != null)
|
||||
WaitingForClientCheck = false;
|
||||
|
||||
if (isSeamlessSwitching || WaitingForClientCheck)
|
||||
{
|
||||
//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.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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace SeamlessClient.Components
|
||||
public override void Patch(Harmony patcher)
|
||||
{
|
||||
TransportLayerConstructor = PatchUtils.GetConstructor(PatchUtils.MyTransportLayerType, new[] { typeof(int) });
|
||||
SyncLayerConstructor = PatchUtils.GetConstructor(PatchUtils.SyncLayerType, new[] { PatchUtils.MyTransportLayerType });
|
||||
SyncLayerConstructor = PatchUtils.GetConstructor(PatchUtils.SyncLayerType, new[] { PatchUtils.MyTransportLayerType });
|
||||
ClientConstructor = PatchUtils.GetConstructor(PatchUtils.ClientType, new[] { typeof(MyGameServerItem), PatchUtils.SyncLayerType });
|
||||
MySessionLayer = PatchUtils.GetProperty(typeof(MySession), "SyncLayer");
|
||||
|
||||
@@ -100,8 +100,51 @@ namespace SeamlessClient.Components
|
||||
InitVirtualClients = PatchUtils.GetMethod(PatchUtils.VirtualClientsType, "Init");
|
||||
VirtualClients = PatchUtils.GetField(typeof(MySession), "VirtualClients");
|
||||
|
||||
patcher.Patch(onJoin, postfix: new HarmonyMethod(Get(typeof(ServerSwitcherComponentOLD), nameof(OnUserJoined))));
|
||||
base.Patch(patcher);
|
||||
patcher.Patch(onJoin, postfix: new HarmonyMethod(Get(typeof(ServerSwitcherComponentOLD), nameof(OnUserJoined))));
|
||||
|
||||
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -111,14 +154,16 @@ namespace SeamlessClient.Components
|
||||
//SeamlessClient.TryShow("User Joined! Result: " + msg.JoinResult.ToString());
|
||||
|
||||
//Invoke the switch event
|
||||
|
||||
SwitchingText = "Server Responded! Removing Old Entities and forcing client connection!";
|
||||
RemoveOldEntities();
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -126,12 +171,12 @@ namespace SeamlessClient.Components
|
||||
public void StartBackendSwitch(MyGameServerItem _TargetServer, MyObjectBuilder_World _TargetWorld)
|
||||
{
|
||||
|
||||
if(MySession.Static.LocalCharacter != null)
|
||||
if (MySession.Static.LocalCharacter != null)
|
||||
{
|
||||
var viewMatrix = MySession.Static.LocalCharacter.GetViewMatrix();
|
||||
MySpectator.Static.SetViewMatrix(viewMatrix);
|
||||
}
|
||||
|
||||
|
||||
SwitchingText = "Starting Seamless Switch... Please wait!";
|
||||
isSeamlessSwitching = true;
|
||||
OldArmorSkin = MySession.Static.LocalHumanPlayer.BuildArmorSkin;
|
||||
@@ -140,10 +185,15 @@ namespace SeamlessClient.Components
|
||||
|
||||
MySandboxGame.Static.Invoke(delegate
|
||||
{
|
||||
//Pause the game/update thread while we load
|
||||
MySandboxGame.IsPaused = true;
|
||||
|
||||
//Set camera controller to fixed spectator
|
||||
MySession.Static.SetCameraController(MyCameraControllerEnum.SpectatorFixed);
|
||||
UnloadCurrentServer();
|
||||
SetNewMultiplayerClient();
|
||||
ModAPI.StartModSwitching();
|
||||
|
||||
//SeamlessClient.IsSwitching = false;
|
||||
|
||||
SwitchingText = "Waiting for server response...";
|
||||
@@ -172,7 +222,7 @@ namespace SeamlessClient.Components
|
||||
|
||||
SwitchingText = "New Multiplayer Session Set";
|
||||
Seamless.TryShow("Successfully set MyMultiplayer.Static");
|
||||
|
||||
MySandboxGame.IsPaused = true;
|
||||
|
||||
Sync.Clients.SetLocalSteamId(Sync.MyId, false, MyGameService.UserName);
|
||||
Sync.Players.RegisterEvents();
|
||||
@@ -184,6 +234,8 @@ namespace SeamlessClient.Components
|
||||
private static void ForceClientConnection()
|
||||
{
|
||||
|
||||
|
||||
|
||||
//Set World Settings
|
||||
SetWorldSettings();
|
||||
|
||||
@@ -217,6 +269,8 @@ namespace SeamlessClient.Components
|
||||
|
||||
StartEntitySync();
|
||||
|
||||
//Resume the game/update thread
|
||||
MySandboxGame.IsPaused = false;
|
||||
|
||||
MyHud.Chat.RegisterChat(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
|
||||
MyGuiScreenHudSpace.Static.RecreateControls(true);
|
||||
SwitchingText = "Client Registered. Waiting for entities from server...";
|
||||
|
||||
|
||||
Seamless.TryShow($"LocalHumanPlayer = {MySession.Static.LocalHumanPlayer == null}");
|
||||
|
||||
|
||||
|
||||
//MySession.Static.LocalHumanPlayer.BuildArmorSkin = OldArmorSkin;
|
||||
}
|
||||
|
||||
@@ -392,6 +452,8 @@ namespace SeamlessClient.Components
|
||||
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 });
|
||||
|
||||
|
||||
@@ -511,7 +573,8 @@ namespace SeamlessClient.Components
|
||||
//Close any respawn screens that are open
|
||||
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())
|
||||
{
|
||||
if (ent is MyPlanet)
|
||||
{
|
||||
//Re-Add planet updates
|
||||
MyEntities.RegisterForUpdate(ent);
|
||||
continue;
|
||||
}
|
||||
|
||||
ent.Close();
|
||||
}
|
||||
@@ -530,7 +597,7 @@ namespace SeamlessClient.Components
|
||||
{
|
||||
AccessTools.Field(typeof(MyCoordinateSystem), "m_lastCoordSysId").SetValue(MyCoordinateSystem.Static, 1L);
|
||||
AccessTools.Field(typeof(MyCoordinateSystem), "m_localCoordSystems").SetValue(MyCoordinateSystem.Static, new Dictionary<long, MyLocalCoordSys>());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user