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)
{
Patches.GetPatches();
TryShow("Running Seamless Client Plugin v[" + Version + "]");
PingTimer.Elapsed += PingTimer_Elapsed;
PingTimer.Start();

View File

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

View File

@@ -23,22 +23,19 @@ namespace SeamlessClientPlugin.SeamlessTransfer
Transfer = ClientTransfer;
Request = Transfer.WorldRequest;
if (Transfer.TargetServerID == 0)
{
SeamlessClient.TryShow("This is not a valid server!");
return;
}
SeamlessClient.TryShow("Beginning Redirect to server: " + Transfer.TargetServerID);
MyGameService.OnPingServerResponded += PingResponded;
MyGameService.OnPingServerFailedToRespond += FailedToRespond;
MyGameService.PingServer(Transfer.IPAdress);
}
private static void PingResponded(object sender, MyGameServerItem e)
@@ -56,9 +53,7 @@ namespace SeamlessClientPlugin.SeamlessTransfer
private static void FailedToRespond(object sender, EventArgs e)
{
// If the target server failed to respond, we need to exit/return to menu
UnRegisterEvents();
}

View File

@@ -44,8 +44,8 @@ namespace SeamlessClientPlugin.SeamlessTransfer
/* Static FieldInfos */
public static FieldInfo MySessionLayer { get; private set; }
/* Static FieldInfos and PropertyInfos */
public static PropertyInfo MySessionLayer { get; private set; }
public static FieldInfo VirtualClients { get; private set; }
public static FieldInfo AdminSettings { 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) });
/* Get Fields */
MySessionLayer = GetField(typeof(MySession), "SyncLayer", BindingFlags.Instance | BindingFlags.Public);
/* Get Fields and Properties */
MySessionLayer = GetProperty(typeof(MySession), "SyncLayer", BindingFlags.Instance | BindingFlags.Public);
VirtualClients = GetField(typeof(MySession), "VirtualClients", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
AdminSettings = GetField(typeof(MySession), "m_adminSettings", 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)
{