diff --git a/Facepunch.Steamworks/Generated/Interfaces/ISteamClient.cs b/Facepunch.Steamworks/Generated/Interfaces/ISteamClient.cs index 82b21a4..11d3529 100644 --- a/Facepunch.Steamworks/Generated/Interfaces/ISteamClient.cs +++ b/Facepunch.Steamworks/Generated/Interfaces/ISteamClient.cs @@ -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 ); } diff --git a/Facepunch.Steamworks/Generated/Interfaces/ISteamGameServer.cs b/Facepunch.Steamworks/Generated/Interfaces/ISteamGameServer.cs index a7ecdc4..48d5b8f 100644 --- a/Facepunch.Steamworks/Generated/Interfaces/ISteamGameServer.cs +++ b/Facepunch.Steamworks/Generated/Interfaces/ISteamGameServer.cs @@ -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; diff --git a/Facepunch.Steamworks/Generated/Interfaces/ISteamNetworking.cs b/Facepunch.Steamworks/Generated/Interfaces/ISteamNetworking.cs index f3a67a3..15eb2e9 100644 --- a/Facepunch.Steamworks/Generated/Interfaces/ISteamNetworking.cs +++ b/Facepunch.Steamworks/Generated/Interfaces/ISteamNetworking.cs @@ -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; diff --git a/Facepunch.Steamworks/Generated/SteamStructs.cs b/Facepunch.Steamworks/Generated/SteamStructs.cs index 2db0bc1..882c765 100644 --- a/Facepunch.Steamworks/Generated/SteamStructs.cs +++ b/Facepunch.Steamworks/Generated/SteamStructs.cs @@ -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 { diff --git a/Facepunch.Steamworks/SteamServer.cs b/Facepunch.Steamworks/SteamServer.cs index 0f572cb..50c6c0b 100644 --- a/Facepunch.Steamworks/SteamServer.cs +++ b/Facepunch.Steamworks/SteamServer.cs @@ -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. /// - 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(); /// /// Enable or disable heartbeats, which are sent regularly to the master server. diff --git a/Facepunch.Steamworks/Structs/SteamIpAddress.cs b/Facepunch.Steamworks/Structs/SteamIpAddress.cs new file mode 100644 index 0000000..b36af9c --- /dev/null +++ b/Facepunch.Steamworks/Structs/SteamIpAddress.cs @@ -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" ); + } + } +} \ No newline at end of file diff --git a/Generator/Cleanup.cs b/Generator/Cleanup.cs index c098b3f..aad47b2 100644 --- a/Generator/Cleanup.cs +++ b/Generator/Cleanup.cs @@ -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; } diff --git a/Generator/CodeWriter/Types/BaseType.cs b/Generator/CodeWriter/Types/BaseType.cs index ef66259..1c6cd38 100644 --- a/Generator/CodeWriter/Types/BaseType.cs +++ b/Generator/CodeWriter/Types/BaseType.cs @@ -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 };