SteamIPAddress takeover

This commit is contained in:
Garry Newman 2020-02-19 10:44:15 +00:00
parent 26e634a7f0
commit ea60c03b95
8 changed files with 42 additions and 31 deletions

View File

@ -96,10 +96,10 @@ namespace Steamworks
#region FunctionMeta
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamClient_SetLocalIPBinding")]
private static extern void _SetLocalIPBinding( IntPtr self, ref SteamIPAddress_t unIP, ushort usPort );
private static extern void _SetLocalIPBinding( IntPtr self, ref SteamIPAddress unIP, ushort usPort );
#endregion
internal void SetLocalIPBinding( ref SteamIPAddress_t unIP, ushort usPort )
internal void SetLocalIPBinding( ref SteamIPAddress unIP, ushort usPort )
{
_SetLocalIPBinding( Self, ref unIP, usPort );
}

View File

@ -387,10 +387,10 @@ namespace Steamworks
#region FunctionMeta
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamGameServer_GetPublicIP")]
private static extern SteamIPAddress_t _GetPublicIP( IntPtr self );
private static extern SteamIPAddress _GetPublicIP( IntPtr self );
#endregion
internal SteamIPAddress_t GetPublicIP()
internal SteamIPAddress GetPublicIP()
{
var returnValue = _GetPublicIP( Self );
return returnValue;

View File

@ -115,10 +115,10 @@ namespace Steamworks
#region FunctionMeta
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamNetworking_CreateListenSocket")]
private static extern SNetListenSocket_t _CreateListenSocket( IntPtr self, int nVirtualP2PPort, SteamIPAddress_t nIP, ushort nPort, [MarshalAs( UnmanagedType.U1 )] bool bAllowUseOfPacketRelay );
private static extern SNetListenSocket_t _CreateListenSocket( IntPtr self, int nVirtualP2PPort, SteamIPAddress nIP, ushort nPort, [MarshalAs( UnmanagedType.U1 )] bool bAllowUseOfPacketRelay );
#endregion
internal SNetListenSocket_t CreateListenSocket( int nVirtualP2PPort, SteamIPAddress_t nIP, ushort nPort, [MarshalAs( UnmanagedType.U1 )] bool bAllowUseOfPacketRelay )
internal SNetListenSocket_t CreateListenSocket( int nVirtualP2PPort, SteamIPAddress nIP, ushort nPort, [MarshalAs( UnmanagedType.U1 )] bool bAllowUseOfPacketRelay )
{
var returnValue = _CreateListenSocket( Self, nVirtualP2PPort, nIP, nPort, bAllowUseOfPacketRelay );
return returnValue;
@ -137,10 +137,10 @@ namespace Steamworks
#region FunctionMeta
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamNetworking_CreateConnectionSocket")]
private static extern SNetSocket_t _CreateConnectionSocket( IntPtr self, SteamIPAddress_t nIP, ushort nPort, int nTimeoutSec );
private static extern SNetSocket_t _CreateConnectionSocket( IntPtr self, SteamIPAddress nIP, ushort nPort, int nTimeoutSec );
#endregion
internal SNetSocket_t CreateConnectionSocket( SteamIPAddress_t nIP, ushort nPort, int nTimeoutSec )
internal SNetSocket_t CreateConnectionSocket( SteamIPAddress nIP, ushort nPort, int nTimeoutSec )
{
var returnValue = _CreateConnectionSocket( Self, nIP, nPort, nTimeoutSec );
return returnValue;
@ -233,10 +233,10 @@ namespace Steamworks
#region FunctionMeta
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamNetworking_GetSocketInfo")]
[return: MarshalAs( UnmanagedType.I1 )]
private static extern bool _GetSocketInfo( IntPtr self, SNetSocket_t hSocket, ref SteamId pSteamIDRemote, ref int peSocketStatus, ref SteamIPAddress_t punIPRemote, ref ushort punPortRemote );
private static extern bool _GetSocketInfo( IntPtr self, SNetSocket_t hSocket, ref SteamId pSteamIDRemote, ref int peSocketStatus, ref SteamIPAddress punIPRemote, ref ushort punPortRemote );
#endregion
internal bool GetSocketInfo( SNetSocket_t hSocket, ref SteamId pSteamIDRemote, ref int peSocketStatus, ref SteamIPAddress_t punIPRemote, ref ushort punPortRemote )
internal bool GetSocketInfo( SNetSocket_t hSocket, ref SteamId pSteamIDRemote, ref int peSocketStatus, ref SteamIPAddress punIPRemote, ref ushort punPortRemote )
{
var returnValue = _GetSocketInfo( Self, hSocket, ref pSteamIDRemote, ref peSocketStatus, ref punIPRemote, ref punPortRemote );
return returnValue;
@ -245,10 +245,10 @@ namespace Steamworks
#region FunctionMeta
[DllImport( Platform.LibraryName, EntryPoint = "SteamAPI_ISteamNetworking_GetListenSocketInfo")]
[return: MarshalAs( UnmanagedType.I1 )]
private static extern bool _GetListenSocketInfo( IntPtr self, SNetListenSocket_t hListenSocket, ref SteamIPAddress_t pnIP, ref ushort pnPort );
private static extern bool _GetListenSocketInfo( IntPtr self, SNetListenSocket_t hListenSocket, ref SteamIPAddress pnIP, ref ushort pnPort );
#endregion
internal bool GetListenSocketInfo( SNetListenSocket_t hListenSocket, ref SteamIPAddress_t pnIP, ref ushort pnPort )
internal bool GetListenSocketInfo( SNetListenSocket_t hListenSocket, ref SteamIPAddress pnIP, ref ushort pnPort )
{
var returnValue = _GetListenSocketInfo( Self, hListenSocket, ref pnIP, ref pnPort );
return returnValue;

View File

@ -6,15 +6,6 @@ using System.Threading.Tasks;
namespace Steamworks.Data
{
[StructLayout( LayoutKind.Sequential, Pack = Platform.StructPlatformPackSize )]
internal struct SteamIPAddress_t
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)] // m_rgubIPv6
internal byte[] GubIPv6; // m_rgubIPv6 uint8 [16]
internal SteamIPType Type; // m_eType ESteamIPType
}
[StructLayout( LayoutKind.Sequential, Pack = Platform.StructPackSize )]
internal struct FriendGameInfo_t
{

View File

@ -298,16 +298,7 @@ namespace Steamworks
/// current public ip address. Be aware that this is likely to return
/// null for the first few seconds after initialization.
/// </summary>
public static System.Net.IPAddress PublicIp
{
get
{
var ip = Internal.GetPublicIP();
if ( ip == 0 ) return null;
return Utility.Int32ToIp( ip );
}
}
public static System.Net.IPAddress PublicIp => Internal.GetPublicIP();
/// <summary>
/// Enable or disable heartbeats, which are sent regularly to the master server.

View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace Steamworks.Data
{
[StructLayout( LayoutKind.Explicit, Pack = Platform.StructPlatformPackSize )]
internal struct SteamIPAddress
{
[FieldOffset( 0 )]
public uint Ip4Address; // Host Order
[FieldOffset( 16 )]
internal SteamIPType Type; // m_eType ESteamIPType
public static implicit operator System.Net.IPAddress( SteamIPAddress value )
{
if ( value.Type == SteamIPType.Type4 )
return Utility.Int32ToIp( value.Ip4Address );
throw new System.Exception( $"Oops - can't convert SteamIPAddress to System.Net.IPAddress because no-one coded support for {value.Type} yet" );
}
}
}

View File

@ -54,6 +54,7 @@ public static class Cleanup
type = type.Replace( "MatchMakingKeyValuePair_t", "MatchMakingKeyValuePair" );
type = type.Replace( "ISteamNetworkingMessage", "NetMsg" );
type = type.Replace( "SteamNetworkingMessage_t", "NetMsg" );
type = type.Replace( "SteamIPAddress_t", "SteamIPAddress" );
type = type.Replace( "::", "." );
@ -83,6 +84,7 @@ public static class Cleanup
if ( type == "SteamNetworkingQuickConnectionStatus" ) return false;
if ( type == "SteamNetworkingErrMsg" ) return false;
if ( type == "NetKeyValue" ) return false;
if ( type == "SteamIPAddress" ) return false;
return true;
}

View File

@ -63,6 +63,7 @@ internal class BaseType
if ( basicType == "MotionState" ) return new StructType { NativeType = type, VarName = varname, StructName = basicType };
if ( basicType == "NetMsg" ) return new StructType { NativeType = type, VarName = varname, StructName = basicType };
if ( basicType == "NetKeyValue" ) return new StructType { NativeType = type, VarName = varname, StructName = basicType };
if ( basicType == "SteamIPAddress" ) return new StructType { NativeType = type, VarName = varname, StructName = basicType };
if ( basicType.StartsWith( "E" ) && char.IsUpper( basicType[1] ) ) return new EnumType { NativeType = type.Substring( 1 ), VarName = varname };
if ( basicType.EndsWith( "_t" ) ) return new StructType { NativeType = type, VarName = varname, StructName = basicType };