Updated seamless

This commit is contained in:
Garrett
2023-08-25 14:19:50 -05:00
parent 91f0e57d97
commit b470ca8a36
6 changed files with 60 additions and 26 deletions

View File

@@ -16,6 +16,9 @@ namespace SeamlessClient.OnlinePlayersWindow
public class PlayersWindowComponent : ComponentBase public class PlayersWindowComponent : ComponentBase
{ {
public override void Patch(Harmony patcher) public override void Patch(Harmony patcher)
{ {
patcher.CreateClassProcessor(typeof(OnlineNexusPlayersWindow)).Patch(); patcher.CreateClassProcessor(typeof(OnlineNexusPlayersWindow)).Patch();
@@ -30,6 +33,8 @@ namespace SeamlessClient.OnlinePlayersWindow
public static void ApplyRecievedPlayers(List<OnlineServer> servers, int CurrentServer) public static void ApplyRecievedPlayers(List<OnlineServer> servers, int CurrentServer)
{ {
Seamless.TryShow($"Recieved {CurrentServer} - {servers.Count}"); Seamless.TryShow($"Recieved {CurrentServer} - {servers.Count}");
} }

View File

@@ -33,6 +33,12 @@ namespace SeamlessClient.ServerSwitching
{ {
public class ServerSwitcherComponent : ComponentBase public class ServerSwitcherComponent : ComponentBase
{ {
public static ConstructorInfo ClientConstructor;
public static ConstructorInfo SyncLayerConstructor;
public static ConstructorInfo TransportLayerConstructor;
public static PropertyInfo MySessionLayer;
private static FieldInfo RemoteAdminSettings; private static FieldInfo RemoteAdminSettings;
private static FieldInfo AdminSettings; private static FieldInfo AdminSettings;
private static MethodInfo UnloadProceduralWorldGenerator; private static MethodInfo UnloadProceduralWorldGenerator;
@@ -63,6 +69,13 @@ namespace SeamlessClient.ServerSwitching
public override void Patch(Harmony patcher) public override void Patch(Harmony patcher)
{ {
MySessionLayer = PatchUtils.GetProperty(typeof(MySession), "SyncLayer");
ClientConstructor = PatchUtils.GetConstructor(PatchUtils.ClientType, new[] { typeof(MyGameServerItem), PatchUtils.SyncLayerType });
SyncLayerConstructor = PatchUtils.GetConstructor(PatchUtils.SyncLayerType, new[] { PatchUtils.MyTransportLayerType });
TransportLayerConstructor = PatchUtils.GetConstructor(PatchUtils.MyTransportLayerType, new[] { typeof(int) });
RemoteAdminSettings = PatchUtils.GetField(typeof(MySession), "m_remoteAdminSettings"); RemoteAdminSettings = PatchUtils.GetField(typeof(MySession), "m_remoteAdminSettings");
AdminSettings = PatchUtils.GetField(typeof(MySession), "m_adminSettings"); AdminSettings = PatchUtils.GetField(typeof(MySession), "m_adminSettings");
VirtualClients = PatchUtils.GetField(typeof(MySession), "VirtualClients"); VirtualClients = PatchUtils.GetField(typeof(MySession), "VirtualClients");
@@ -124,7 +137,7 @@ namespace SeamlessClient.ServerSwitching
UnloadServer(); UnloadServer();
SetNewMultiplayerClient(); SetNewMultiplayerClient();
}); });
} }
@@ -174,17 +187,41 @@ namespace SeamlessClient.ServerSwitching
private void SetNewMultiplayerClient() private void SetNewMultiplayerClient()
{ {
OnJoinEvent += ServerSwitcherComponent_OnJoinEvent; OnJoinEvent += ServerSwitcherComponent_OnJoinEvent;
MySandboxGame.Static.SessionCompatHelper.FixSessionComponentObjectBuilders(TargetWorld.Checkpoint, TargetWorld.Sector);
// Create constructors
var LayerInstance = TransportLayerConstructor.Invoke(new object[] { 2 });
var SyncInstance = SyncLayerConstructor.Invoke(new object[] { LayerInstance });
var instance = ClientConstructor.Invoke(new object[] { TargetServer, SyncInstance });
MyMultiplayer.Static = UtilExtensions.CastToReflected(instance, PatchUtils.ClientType);
MyMultiplayer.Static.ExperimentalMode = true;
// Set the new SyncLayer to the MySession.Static.SyncLayer
MySessionLayer.SetValue(MySession.Static, MyMultiplayer.Static.SyncLayer);
Seamless.TryShow("Successfully set MyMultiplayer.Static");
Sync.Clients.SetLocalSteamId(Sync.MyId, false, MyGameService.UserName);
Sync.Players.RegisterEvents();
} }
private void ServerSwitcherComponent_OnJoinEvent(object sender, JoinResultMsg e) private void ServerSwitcherComponent_OnJoinEvent(object sender, JoinResultMsg e)
{ {
OnJoinEvent -= ServerSwitcherComponent_OnJoinEvent; OnJoinEvent -= ServerSwitcherComponent_OnJoinEvent;
if (e.JoinResult != JoinResult.OK) if (e.JoinResult != JoinResult.OK)
{ {
Seamless.TryShow("Failed to join the target server!"); Seamless.TryShow("Failed to join the target server!");
return; return;
} }
Seamless.TryShow("Starting new MP Client!");
/* On Server Successfull Join /* On Server Successfull Join
* *

View File

@@ -113,7 +113,6 @@ namespace SeamlessClient
{ {
//Ignore anything except dedicated server //Ignore anything except dedicated server
Seamless.TryShow($"From Server {fromServer} - {sender}");
if (!fromServer || sender == 0) if (!fromServer || sender == 0)
return; return;
@@ -122,15 +121,12 @@ namespace SeamlessClient
return; return;
//Get Nexus Version //Get Nexus Version
Seamless.TryShow($"NexusVersion {msg.NexusVersion}");
if (!string.IsNullOrEmpty(msg.NexusVersion)) if (!string.IsNullOrEmpty(msg.NexusVersion))
NexusVersion = Version.Parse(msg.NexusVersion); NexusVersion = Version.Parse(msg.NexusVersion);
switch (msg.MessageType) switch (msg.MessageType)
{ {
case ClientMessageType.FirstJoin: case ClientMessageType.FirstJoin:
Seamless.TryShow("Sending First Join!"); Seamless.TryShow("Sending First Join!");
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));

View File

@@ -98,6 +98,7 @@
<Compile Include="Components\EntityPerformanceImprovements.cs" /> <Compile Include="Components\EntityPerformanceImprovements.cs" />
<Compile Include="Components\LoadingScreenComponent.cs" /> <Compile Include="Components\LoadingScreenComponent.cs" />
<Compile Include="Messages\OnlinePlayerData.cs" /> <Compile Include="Messages\OnlinePlayerData.cs" />
<Compile Include="Utilities\UtilExtensions.cs" />
<Compile Include="Utilities\PatchUtils.cs" /> <Compile Include="Utilities\PatchUtils.cs" />
<Compile Include="Messages\ClientMessage.cs" /> <Compile Include="Messages\ClientMessage.cs" />
<Compile Include="Messages\TransferData.cs" /> <Compile Include="Messages\TransferData.cs" />

View File

@@ -50,19 +50,10 @@ namespace SeamlessClient.Components
/* Static Contructors */ /* Static Contructors */
public static ConstructorInfo ClientConstructor { get; private set; }
public static ConstructorInfo SyncLayerConstructor { get; private set; }
public static ConstructorInfo TransportLayerConstructor { get; private set; }
public static ConstructorInfo MySessionConstructor { get; private set; } public static ConstructorInfo MySessionConstructor { get; private set; }
public static ConstructorInfo MyMultiplayerClientBaseConstructor { get; private set; } public static ConstructorInfo MyMultiplayerClientBaseConstructor { get; private set; }
/* Static FieldInfos and PropertyInfos */
public static PropertyInfo MySessionLayer { get; private set; }
public static FieldInfo AdminSettings { get; private set; }
public static FieldInfo MPlayerGpsCollection { get; private set; }
/* Static MethodInfos */ /* Static MethodInfos */
public static MethodInfo LoadPlayerInternal { get; private set; } public static MethodInfo LoadPlayerInternal { get; private set; }
@@ -78,24 +69,13 @@ namespace SeamlessClient.Components
public static MethodInfo UnloadProceduralWorldGenerator; public static MethodInfo UnloadProceduralWorldGenerator;
public override void Patch(Harmony patcher) public override void Patch(Harmony patcher)
{ {
ClientConstructor = GetConstructor(ClientType, new[] { typeof(MyGameServerItem), SyncLayerType });
SyncLayerConstructor = GetConstructor(SyncLayerType, new[] { MyTransportLayerType });
TransportLayerConstructor = GetConstructor(MyTransportLayerType, new[] { typeof(int) });
MySessionConstructor = GetConstructor(MySessionType, new[] { typeof(MySyncLayer), typeof(bool) }); MySessionConstructor = GetConstructor(MySessionType, new[] { typeof(MySyncLayer), typeof(bool) });
MyMultiplayerClientBaseConstructor = GetConstructor(MyMultiplayerClientBase, new[] { typeof(MySyncLayer) }); MyMultiplayerClientBaseConstructor = GetConstructor(MyMultiplayerClientBase, new[] { typeof(MySyncLayer) });
/* Get Fields and Properties */
MySessionLayer = GetProperty(typeof(MySession), "SyncLayer");
AdminSettings = GetField(typeof(MySession), "m_adminSettings");
MPlayerGpsCollection = GetField(typeof(MyPlayerCollection), "m_players");
/* Get Methods */ /* Get Methods */

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SeamlessClient.Utilities
{
public static class UtilExtensions
{
public static dynamic CastToReflected(this object o, Type type) => Convert.ChangeType(o, type);
}
}