Fixed null values

This commit is contained in:
Bob Da Ross
2021-05-10 16:58:22 -05:00
parent 6faad11c9d
commit 7ed6ad122e
4 changed files with 29 additions and 14 deletions

View File

@@ -122,6 +122,7 @@ namespace SeamlessClientPlugin
public void Init(object gameInstance) public void Init(object gameInstance)
{ {
Patches.GetPatches();
TryShow("Running Seamless Client Plugin v[" + Version + "]"); TryShow("Running Seamless Client Plugin v[" + Version + "]");
PingTimer.Elapsed += PingTimer_Elapsed; PingTimer.Elapsed += PingTimer_Elapsed;
PingTimer.Start(); PingTimer.Start();

View File

@@ -164,7 +164,7 @@
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SeamlessTransfer\PingServer.cs" /> <Compile Include="SeamlessTransfer\PingServer.cs" />
<Compile Include="Messages\Transfer.cs" /> <Compile Include="Messages\Transfer.cs" />
<Compile Include="SeamlessTransfer\Patches.cs" /> <Compile Include="Utilities\Patches.cs" />
<Compile Include="SeamlessTransfer\SwitchServers.cs" /> <Compile Include="SeamlessTransfer\SwitchServers.cs" />
<Compile Include="Utilities\Utility.cs" /> <Compile Include="Utilities\Utility.cs" />
</ItemGroup> </ItemGroup>

View File

@@ -20,6 +20,9 @@ namespace SeamlessClientPlugin.SeamlessTransfer
public static void StartServerPing(Transfer ClientTransfer) public static void StartServerPing(Transfer ClientTransfer)
{ {
// We need to first ping the server to make sure its running and so we can get a connection // We need to first ping the server to make sure its running and so we can get a connection
Transfer = ClientTransfer;
Request = Transfer.WorldRequest;
if (Transfer.TargetServerID == 0) if (Transfer.TargetServerID == 0)
{ {
@@ -27,18 +30,11 @@ namespace SeamlessClientPlugin.SeamlessTransfer
return; return;
} }
Transfer = ClientTransfer;
Request = Transfer.WorldRequest;
SeamlessClient.TryShow("Beginning Redirect to server: " + Transfer.TargetServerID); SeamlessClient.TryShow("Beginning Redirect to server: " + Transfer.TargetServerID);
MyGameService.OnPingServerResponded += PingResponded; MyGameService.OnPingServerResponded += PingResponded;
MyGameService.OnPingServerFailedToRespond += FailedToRespond; MyGameService.OnPingServerFailedToRespond += FailedToRespond;
MyGameService.PingServer(Transfer.IPAdress); MyGameService.PingServer(Transfer.IPAdress);
} }
private static void PingResponded(object sender, MyGameServerItem e) private static void PingResponded(object sender, MyGameServerItem e)
@@ -56,9 +52,7 @@ namespace SeamlessClientPlugin.SeamlessTransfer
private static void FailedToRespond(object sender, EventArgs e) private static void FailedToRespond(object sender, EventArgs e)
{ {
// If the target server failed to respond, we need to exit/return to menu // If the target server failed to respond, we need to exit/return to menu
UnRegisterEvents(); UnRegisterEvents();
} }

View File

@@ -44,8 +44,8 @@ namespace SeamlessClientPlugin.SeamlessTransfer
/* Static FieldInfos */ /* Static FieldInfos and PropertyInfos */
public static FieldInfo MySessionLayer { get; private set; } public static PropertyInfo MySessionLayer { get; private set; }
public static FieldInfo VirtualClients { get; private set; } public static FieldInfo VirtualClients { get; private set; }
public static FieldInfo AdminSettings { get; private set; } public static FieldInfo AdminSettings { get; private set; }
public static FieldInfo RemoteAdminSettings { get; private set; } public static FieldInfo RemoteAdminSettings { get; private set; }
@@ -80,8 +80,8 @@ namespace SeamlessClientPlugin.SeamlessTransfer
MyMultiplayerClientBaseConstructor = GetConstructor(MyMultiplayerClientBase, BindingFlags.Instance | BindingFlags.NonPublic, new Type[] { typeof(MySyncLayer) }); MyMultiplayerClientBaseConstructor = GetConstructor(MyMultiplayerClientBase, BindingFlags.Instance | BindingFlags.NonPublic, new Type[] { typeof(MySyncLayer) });
/* Get Fields */ /* Get Fields and Properties */
MySessionLayer = GetField(typeof(MySession), "SyncLayer", BindingFlags.Instance | BindingFlags.Public); MySessionLayer = GetProperty(typeof(MySession), "SyncLayer", BindingFlags.Instance | BindingFlags.Public);
VirtualClients = GetField(typeof(MySession), "VirtualClients", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); VirtualClients = GetField(typeof(MySession), "VirtualClients", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
AdminSettings = GetField(typeof(MySession), "m_adminSettings", BindingFlags.Instance | BindingFlags.NonPublic); AdminSettings = GetField(typeof(MySession), "m_adminSettings", BindingFlags.Instance | BindingFlags.NonPublic);
RemoteAdminSettings = GetField(typeof(MySession), "m_remoteAdminSettings", BindingFlags.Instance | BindingFlags.NonPublic); RemoteAdminSettings = GetField(typeof(MySession), "m_remoteAdminSettings", BindingFlags.Instance | BindingFlags.NonPublic);
@@ -266,6 +266,26 @@ namespace SeamlessClientPlugin.SeamlessTransfer
} }
private static PropertyInfo GetProperty(Type type, string PropertyName, BindingFlags Flags)
{
try
{
PropertyInfo FoundProperty = type.GetProperty(PropertyName, Flags);
if (FoundProperty == null)
throw new NullReferenceException($"Property for {PropertyName} is null!");
return FoundProperty;
}
catch (Exception Ex)
{
throw Ex;
}
}
private static ConstructorInfo GetConstructor(Type type, BindingFlags Flags, Type[] Types) private static ConstructorInfo GetConstructor(Type type, BindingFlags Flags, Type[] Types)
{ {