Updated seamless
This commit is contained in:
@@ -16,6 +16,9 @@ namespace SeamlessClient.OnlinePlayersWindow
|
||||
public class PlayersWindowComponent : ComponentBase
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
public override void Patch(Harmony patcher)
|
||||
{
|
||||
patcher.CreateClassProcessor(typeof(OnlineNexusPlayersWindow)).Patch();
|
||||
@@ -30,6 +33,8 @@ namespace SeamlessClient.OnlinePlayersWindow
|
||||
public static void ApplyRecievedPlayers(List<OnlineServer> servers, int CurrentServer)
|
||||
{
|
||||
Seamless.TryShow($"Recieved {CurrentServer} - {servers.Count}");
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@@ -33,6 +33,12 @@ namespace SeamlessClient.ServerSwitching
|
||||
{
|
||||
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 AdminSettings;
|
||||
private static MethodInfo UnloadProceduralWorldGenerator;
|
||||
@@ -63,6 +69,13 @@ namespace SeamlessClient.ServerSwitching
|
||||
|
||||
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");
|
||||
AdminSettings = PatchUtils.GetField(typeof(MySession), "m_adminSettings");
|
||||
VirtualClients = PatchUtils.GetField(typeof(MySession), "VirtualClients");
|
||||
@@ -124,7 +137,7 @@ namespace SeamlessClient.ServerSwitching
|
||||
|
||||
UnloadServer();
|
||||
SetNewMultiplayerClient();
|
||||
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
@@ -174,17 +187,41 @@ namespace SeamlessClient.ServerSwitching
|
||||
private void SetNewMultiplayerClient()
|
||||
{
|
||||
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)
|
||||
{
|
||||
OnJoinEvent -= ServerSwitcherComponent_OnJoinEvent;
|
||||
|
||||
|
||||
if (e.JoinResult != JoinResult.OK)
|
||||
{
|
||||
Seamless.TryShow("Failed to join the target server!");
|
||||
return;
|
||||
}
|
||||
|
||||
Seamless.TryShow("Starting new MP Client!");
|
||||
|
||||
/* On Server Successfull Join
|
||||
*
|
||||
|
@@ -113,7 +113,6 @@ namespace SeamlessClient
|
||||
{
|
||||
//Ignore anything except dedicated server
|
||||
|
||||
Seamless.TryShow($"From Server {fromServer} - {sender}");
|
||||
if (!fromServer || sender == 0)
|
||||
return;
|
||||
|
||||
@@ -122,15 +121,12 @@ namespace SeamlessClient
|
||||
return;
|
||||
|
||||
//Get Nexus Version
|
||||
Seamless.TryShow($"NexusVersion {msg.NexusVersion}");
|
||||
if (!string.IsNullOrEmpty(msg.NexusVersion))
|
||||
NexusVersion = Version.Parse(msg.NexusVersion);
|
||||
|
||||
switch (msg.MessageType)
|
||||
{
|
||||
case ClientMessageType.FirstJoin:
|
||||
|
||||
|
||||
Seamless.TryShow("Sending First Join!");
|
||||
ClientMessage response = new ClientMessage(SeamlessVersion.ToString());
|
||||
MyAPIGateway.Multiplayer?.SendMessageToServer(SeamlessClientNetId, MessageUtils.Serialize(response));
|
||||
|
@@ -98,6 +98,7 @@
|
||||
<Compile Include="Components\EntityPerformanceImprovements.cs" />
|
||||
<Compile Include="Components\LoadingScreenComponent.cs" />
|
||||
<Compile Include="Messages\OnlinePlayerData.cs" />
|
||||
<Compile Include="Utilities\UtilExtensions.cs" />
|
||||
<Compile Include="Utilities\PatchUtils.cs" />
|
||||
<Compile Include="Messages\ClientMessage.cs" />
|
||||
<Compile Include="Messages\TransferData.cs" />
|
||||
|
@@ -50,19 +50,10 @@ namespace SeamlessClient.Components
|
||||
|
||||
|
||||
/* 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 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 */
|
||||
public static MethodInfo LoadPlayerInternal { get; private set; }
|
||||
@@ -78,24 +69,13 @@ namespace SeamlessClient.Components
|
||||
public static MethodInfo UnloadProceduralWorldGenerator;
|
||||
|
||||
|
||||
|
||||
|
||||
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) });
|
||||
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 */
|
||||
|
||||
|
15
Utilities/UtilExtensions.cs
Normal file
15
Utilities/UtilExtensions.cs
Normal 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);
|
||||
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user