Fixed null values

This commit is contained in:
Bob Da Ross
2021-05-10 16:58:22 -05:00
parent 5ae7bd5294
commit e3563ae144
4 changed files with 28 additions and 12 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

@@ -23,6 +23,7 @@ namespace SeamlessClientPlugin.SeamlessTransfer
Transfer = ClientTransfer; Transfer = ClientTransfer;
Request = Transfer.WorldRequest; Request = Transfer.WorldRequest;
if (Transfer.TargetServerID == 0) if (Transfer.TargetServerID == 0)
{ {
SeamlessClient.TryShow("This is not a valid server!"); SeamlessClient.TryShow("This is not a valid server!");
@@ -30,15 +31,11 @@ namespace SeamlessClientPlugin.SeamlessTransfer
} }
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 +53,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)
{ {