mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-27 07:05:50 +03:00
SteamNetworkUtil global config basics
This commit is contained in:
parent
16ce5f4d63
commit
3eae3314b6
@ -11,7 +11,7 @@ enum SteamNetworkingGetConfigValueResult
|
||||
Force32Bit = 0x7fffffff
|
||||
};
|
||||
|
||||
enum SteamNetworkingConfigDataType
|
||||
enum NetConfigType
|
||||
{
|
||||
Int32 = 1,
|
||||
Int64 = 2,
|
||||
@ -37,7 +37,7 @@ enum SteamNetworkingSocketsDebugOutputType : int
|
||||
Force32Bit = 0x7fffffff
|
||||
};
|
||||
|
||||
internal enum SteamNetworkingConfigScope : int
|
||||
internal enum NetScope : int
|
||||
{
|
||||
Global = 1,
|
||||
SocketsInterface = 2,
|
||||
@ -47,7 +47,7 @@ internal enum SteamNetworkingConfigScope : int
|
||||
Force32Bit = 0x7fffffff
|
||||
}
|
||||
|
||||
internal enum SteamNetworkingConfigValue : int
|
||||
internal enum NetConfig : int
|
||||
{
|
||||
Invalid = 0,
|
||||
FakePacketLoss_Send = 2,
|
||||
|
@ -181,45 +181,45 @@ internal void SetDebugOutputFunction( SteamNetworkingSocketsDebugOutputType eDet
|
||||
#region FunctionMeta
|
||||
[UnmanagedFunctionPointer( CallingConvention.ThisCall )]
|
||||
[return: MarshalAs( UnmanagedType.I1 )]
|
||||
private delegate bool FSetConfigValue( IntPtr self, SteamNetworkingConfigValue eValue, SteamNetworkingConfigScope eScopeType, IntPtr scopeObj, SteamNetworkingConfigDataType eDataType, IntPtr pArg );
|
||||
private delegate bool FSetConfigValue( IntPtr self, NetConfig eValue, NetScope eScopeType, long scopeObj, NetConfigType eDataType, IntPtr pArg );
|
||||
private FSetConfigValue _SetConfigValue;
|
||||
|
||||
#endregion
|
||||
internal bool SetConfigValue( SteamNetworkingConfigValue eValue, SteamNetworkingConfigScope eScopeType, IntPtr scopeObj, SteamNetworkingConfigDataType eDataType, IntPtr pArg )
|
||||
internal bool SetConfigValue( NetConfig eValue, NetScope eScopeType, long scopeObj, NetConfigType eDataType, IntPtr pArg )
|
||||
{
|
||||
return _SetConfigValue( Self, eValue, eScopeType, scopeObj, eDataType, pArg );
|
||||
}
|
||||
|
||||
#region FunctionMeta
|
||||
[UnmanagedFunctionPointer( CallingConvention.ThisCall )]
|
||||
private delegate SteamNetworkingGetConfigValueResult FGetConfigValue( IntPtr self, SteamNetworkingConfigValue eValue, SteamNetworkingConfigScope eScopeType, IntPtr scopeObj, [In,Out] SteamNetworkingConfigDataType[] pOutDataType, IntPtr pResult, ref ulong cbResult );
|
||||
private delegate SteamNetworkingGetConfigValueResult FGetConfigValue( IntPtr self, NetConfig eValue, NetScope eScopeType, long scopeObj, ref NetConfigType pOutDataType, IntPtr pResult, ref ulong cbResult );
|
||||
private FGetConfigValue _GetConfigValue;
|
||||
|
||||
#endregion
|
||||
internal SteamNetworkingGetConfigValueResult GetConfigValue( SteamNetworkingConfigValue eValue, SteamNetworkingConfigScope eScopeType, IntPtr scopeObj, [In,Out] SteamNetworkingConfigDataType[] pOutDataType, IntPtr pResult, ref ulong cbResult )
|
||||
internal SteamNetworkingGetConfigValueResult GetConfigValue( NetConfig eValue, NetScope eScopeType, long scopeObj, ref NetConfigType pOutDataType, IntPtr pResult, ref ulong cbResult )
|
||||
{
|
||||
return _GetConfigValue( Self, eValue, eScopeType, scopeObj, pOutDataType, pResult, ref cbResult );
|
||||
return _GetConfigValue( Self, eValue, eScopeType, scopeObj, ref pOutDataType, pResult, ref cbResult );
|
||||
}
|
||||
|
||||
#region FunctionMeta
|
||||
[UnmanagedFunctionPointer( CallingConvention.ThisCall )]
|
||||
[return: MarshalAs( UnmanagedType.I1 )]
|
||||
private delegate bool FGetConfigValueInfo( IntPtr self, SteamNetworkingConfigValue eValue, [In,Out] string[] pOutName, [In,Out] SteamNetworkingConfigDataType[] pOutDataType, [In,Out] SteamNetworkingConfigScope[] pOutScope, [In,Out] SteamNetworkingConfigValue[] pOutNextValue );
|
||||
private delegate bool FGetConfigValueInfo( IntPtr self, NetConfig eValue, [In,Out] string[] pOutName, ref NetConfigType pOutDataType, [In,Out] NetScope[] pOutScope, [In,Out] NetConfig[] pOutNextValue );
|
||||
private FGetConfigValueInfo _GetConfigValueInfo;
|
||||
|
||||
#endregion
|
||||
internal bool GetConfigValueInfo( SteamNetworkingConfigValue eValue, [In,Out] string[] pOutName, [In,Out] SteamNetworkingConfigDataType[] pOutDataType, [In,Out] SteamNetworkingConfigScope[] pOutScope, [In,Out] SteamNetworkingConfigValue[] pOutNextValue )
|
||||
internal bool GetConfigValueInfo( NetConfig eValue, [In,Out] string[] pOutName, ref NetConfigType pOutDataType, [In,Out] NetScope[] pOutScope, [In,Out] NetConfig[] pOutNextValue )
|
||||
{
|
||||
return _GetConfigValueInfo( Self, eValue, pOutName, pOutDataType, pOutScope, pOutNextValue );
|
||||
return _GetConfigValueInfo( Self, eValue, pOutName, ref pOutDataType, pOutScope, pOutNextValue );
|
||||
}
|
||||
|
||||
#region FunctionMeta
|
||||
[UnmanagedFunctionPointer( CallingConvention.ThisCall )]
|
||||
private delegate SteamNetworkingConfigValue FGetFirstConfigValue( IntPtr self );
|
||||
private delegate NetConfig FGetFirstConfigValue( IntPtr self );
|
||||
private FGetFirstConfigValue _GetFirstConfigValue;
|
||||
|
||||
#endregion
|
||||
internal SteamNetworkingConfigValue GetFirstConfigValue()
|
||||
internal NetConfig GetFirstConfigValue()
|
||||
{
|
||||
return _GetFirstConfigValue( Self );
|
||||
}
|
||||
|
@ -78,5 +78,139 @@ public static async Task WaitForPingDataAsync( float maxAgeInSeconds = 60 * 5 )
|
||||
await Task.Delay( 10 );
|
||||
}
|
||||
}
|
||||
|
||||
public static SteamNetworkingMicroseconds LocalTimetamp => Internal.GetLocalTimestamp();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// [0 - 100] - Randomly discard N pct of packets
|
||||
/// </summary>
|
||||
public static float FakeSendPacketLoss
|
||||
{
|
||||
get => GetConfigFloat( NetConfig.FakePacketLoss_Send );
|
||||
set => SetConfigFloat( NetConfig.FakePacketLoss_Send, value );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// [0 - 100] - Randomly discard N pct of packets
|
||||
/// </summary>
|
||||
public static float FakeRecvPacketLoss
|
||||
{
|
||||
get => GetConfigFloat( NetConfig.FakePacketLoss_Recv );
|
||||
set => SetConfigFloat( NetConfig.FakePacketLoss_Recv, value );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delay all packets by N ms
|
||||
/// </summary>
|
||||
public static float FakeSendPacketLag
|
||||
{
|
||||
get => GetConfigFloat( NetConfig.FakePacketLag_Send );
|
||||
set => SetConfigFloat( NetConfig.FakePacketLag_Send, value );
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delay all packets by N ms
|
||||
/// </summary>
|
||||
public static float FakeRecvPacketLag
|
||||
{
|
||||
get => GetConfigFloat( NetConfig.FakePacketLag_Recv );
|
||||
set => SetConfigFloat( NetConfig.FakePacketLag_Recv, value );
|
||||
}
|
||||
|
||||
#region Config Internals
|
||||
|
||||
internal unsafe static bool GetConfigInt( NetConfig type, int value )
|
||||
{
|
||||
int* ptr = &value;
|
||||
return Internal.SetConfigValue( type, NetScope.Global, 0, NetConfigType.Int32, (IntPtr)ptr );
|
||||
}
|
||||
|
||||
internal unsafe static int GetConfigInt( NetConfig type )
|
||||
{
|
||||
int value = 0;
|
||||
NetConfigType dtype = NetConfigType.Int32;
|
||||
int* ptr = &value;
|
||||
ulong size = sizeof( int );
|
||||
var result = Internal.GetConfigValue( type, NetScope.Global, 0, ref dtype, (IntPtr) ptr, ref size );
|
||||
if ( result != SteamNetworkingGetConfigValueResult.OK )
|
||||
return 0;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
internal unsafe static bool SetConfigFloat( NetConfig type, float value )
|
||||
{
|
||||
float* ptr = &value;
|
||||
return Internal.SetConfigValue( type, NetScope.Global, 0, NetConfigType.Float, (IntPtr)ptr );
|
||||
}
|
||||
|
||||
internal unsafe static float GetConfigFloat( NetConfig type )
|
||||
{
|
||||
float value = 0;
|
||||
NetConfigType dtype = NetConfigType.Float;
|
||||
float* ptr = &value;
|
||||
ulong size = sizeof( float );
|
||||
var result = Internal.GetConfigValue( type, NetScope.Global, 0, ref dtype, (IntPtr)ptr, ref size );
|
||||
if ( result != SteamNetworkingGetConfigValueResult.OK )
|
||||
return 0;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
internal unsafe static bool SetConfigString( NetConfig type, string value )
|
||||
{
|
||||
var bytes = Encoding.UTF8.GetBytes( value );
|
||||
|
||||
fixed ( byte* ptr = bytes )
|
||||
{
|
||||
return Internal.SetConfigValue( type, NetScope.Global, 0, NetConfigType.String, (IntPtr)ptr );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
internal unsafe static float GetConfigString( NetConfig type )
|
||||
{
|
||||
|
||||
float value = 0;
|
||||
NetConfigType dtype = NetConfigType.Float;
|
||||
float* ptr = &value;
|
||||
ulong size = sizeof( float );
|
||||
var result = Internal.GetConfigValue( type, NetScope.Global, 0, ref dtype, (IntPtr)ptr, ref size );
|
||||
if ( result != SteamNetworkingGetConfigValueResult.OK )
|
||||
return 0;
|
||||
|
||||
return value;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
|
||||
TODO - Connection object
|
||||
|
||||
internal unsafe static bool SetConnectionConfig( uint con, NetConfig type, int value )
|
||||
{
|
||||
int* ptr = &value;
|
||||
return Internal.SetConfigValue( type, NetScope.Connection, con, NetConfigType.Int32, (IntPtr)ptr );
|
||||
}
|
||||
|
||||
internal unsafe static bool SetConnectionConfig( uint con, NetConfig type, float value )
|
||||
{
|
||||
float* ptr = &value;
|
||||
return Internal.SetConfigValue( type, NetScope.Connection, con, NetConfigType.Float, (IntPtr)ptr );
|
||||
}
|
||||
|
||||
internal unsafe static bool SetConnectionConfig( uint con, NetConfig type, string value )
|
||||
{
|
||||
var bytes = Encoding.UTF8.GetBytes( value );
|
||||
|
||||
fixed ( byte* ptr = bytes )
|
||||
{
|
||||
return Internal.SetConfigValue( type, NetScope.Connection, con, NetConfigType.String, (IntPtr)ptr );
|
||||
}
|
||||
}*/
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -27,6 +27,9 @@ public static string ConvertType( string type )
|
||||
type = type.Replace( "SteamItemDef_t", "InventoryDefId" );
|
||||
type = type.Replace( "ChatRoomEnterResponse", "RoomEnter" );
|
||||
type = type.Replace( "SteamNetworkPingLocation_t", "PingLocation" );
|
||||
type = type.Replace( "SteamNetworkingConfigValue", "NetConfig" );
|
||||
type = type.Replace( "SteamNetworkingConfigScope", "NetScope" );
|
||||
type = type.Replace( "SteamNetworkingConfigDataType", "NetConfigType" );
|
||||
|
||||
return type;
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ public static BaseType Parse( string type, string varname = null )
|
||||
type = Cleanup.ConvertType( type );
|
||||
|
||||
if ( type == "SteamAPIWarningMessageHook_t" ) return new PointerType { NativeType = type, VarName = varname };
|
||||
if ( type == "intptr_t" ) return new PointerType { NativeType = type, VarName = varname };
|
||||
|
||||
if ( type == "SteamAPICall_t" ) return new SteamApiCallType { NativeType = type, VarName = varname };
|
||||
|
||||
@ -39,6 +38,8 @@ public static BaseType Parse( string type, string varname = null )
|
||||
|
||||
// DANGER DANGER Danger
|
||||
if ( basicType == "size_t" ) return new ULongType { NativeType = type, VarName = varname };
|
||||
if ( basicType == "intptr_t" ) return new LongType { NativeType = type, VarName = varname };
|
||||
if ( basicType == "ptrdiff_t" ) return new LongType { NativeType = type, VarName = varname };
|
||||
|
||||
if ( basicType == "uint64" ) return new ULongType { NativeType = type, VarName = varname };
|
||||
if ( basicType == "int64" ) return new LongType { NativeType = type, VarName = varname };
|
||||
@ -73,6 +74,7 @@ public virtual bool IsVector
|
||||
if ( VarName == "pOutBuffer" ) return false;
|
||||
if ( VarName == "pubRGB" ) return false;
|
||||
if ( VarName == "pOutResultHandle" ) return false;
|
||||
if ( VarName == "pOutDataType" ) return false;
|
||||
|
||||
if ( VarName == "psteamIDClans" ) return true;
|
||||
if ( VarName == "pScoreDetails" ) return true;
|
||||
|
Loading…
Reference in New Issue
Block a user