mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-25 06:05:46 +03:00
Better vector marshalling
This commit is contained in:
parent
ebea536334
commit
199ad77406
@ -1,64 +1,46 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace Facepunch.Steamworks.Test
|
||||
namespace Steamworks
|
||||
{
|
||||
[TestClass]
|
||||
[DeploymentItem( "steam_api64.dll" )]
|
||||
public class App
|
||||
public class AppTest
|
||||
{
|
||||
[TestMethod]
|
||||
public void IsSubscribed()
|
||||
[AssemblyInitialize]
|
||||
public static void AssemblyInit( TestContext context )
|
||||
{
|
||||
Steamworks.Steam.Init( 4000 );
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GameLangauge()
|
||||
{
|
||||
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
|
||||
{
|
||||
Console.WriteLine("This test assumes you own Garry's Mod and not Charles III of Spain and the antiquity");
|
||||
var gl = Apps.GameLanguage;
|
||||
Assert.IsNotNull( gl );
|
||||
Assert.IsTrue( gl.Length > 3 );
|
||||
|
||||
Assert.IsTrue( client.App.IsSubscribed( 4000 ) );
|
||||
Assert.IsFalse( client.App.IsSubscribed( 590440 ));
|
||||
}
|
||||
}
|
||||
Console.WriteLine( $"{gl}" );
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IsInstalled()
|
||||
{
|
||||
using (var client = new Facepunch.Steamworks.Client(252490))
|
||||
{
|
||||
Console.WriteLine("This test assumes you have Garry's Mod installed but not Charles III of Spain and the antiquity");
|
||||
[TestMethod]
|
||||
public void InstalledDepots()
|
||||
{
|
||||
var depots = Apps.InstalledDepots( 4000 ).ToArray();
|
||||
|
||||
Assert.IsTrue(client.App.IsInstalled(4000));
|
||||
Assert.IsFalse(client.App.IsInstalled(590440));
|
||||
}
|
||||
}
|
||||
Assert.IsNotNull( depots );
|
||||
Assert.IsTrue( depots.Length > 0 );
|
||||
|
||||
[TestMethod]
|
||||
public void PurchaseTime()
|
||||
{
|
||||
using (var client = new Facepunch.Steamworks.Client(252490))
|
||||
{
|
||||
Console.WriteLine("This test assumes you own Garry's Mod but not Charles III of Spain and the antiquity");
|
||||
foreach ( var depot in depots )
|
||||
{
|
||||
Console.WriteLine( $"{depot.Value}" );
|
||||
}
|
||||
|
||||
var gmodBuyTime = client.App.PurchaseTime( 4000 );
|
||||
Assert.AreNotEqual( gmodBuyTime, DateTime.MinValue );
|
||||
|
||||
Console.WriteLine($"You bought Garry's Mod {gmodBuyTime}");
|
||||
}
|
||||
}
|
||||
|
||||
var otherBuyTime = client.App.PurchaseTime(590440);
|
||||
Assert.AreEqual(otherBuyTime, DateTime.MinValue);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AppName()
|
||||
{
|
||||
using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
|
||||
{
|
||||
var name = client.App.GetName( 4000 );
|
||||
Console.WriteLine( name );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -239,13 +239,13 @@ public bool MarkContentCorrupt( [MarshalAs( UnmanagedType.U1 )] bool bMissingFil
|
||||
|
||||
#region FunctionMeta
|
||||
[UnmanagedFunctionPointer( CallingConvention.ThisCall )]
|
||||
public delegate uint GetInstalledDepotsDelegate( IntPtr self, AppId_t appID, ref DepotId_t pvecDepots, uint cMaxDepots );
|
||||
public delegate uint GetInstalledDepotsDelegate( IntPtr self, AppId_t appID, [In,Out] DepotId_t[] pvecDepots, uint cMaxDepots );
|
||||
private GetInstalledDepotsDelegate GetInstalledDepotsDelegatePointer;
|
||||
|
||||
#endregion
|
||||
public uint GetInstalledDepots( AppId_t appID, ref DepotId_t pvecDepots, uint cMaxDepots )
|
||||
public uint GetInstalledDepots( AppId_t appID, [In,Out] DepotId_t[] pvecDepots, uint cMaxDepots )
|
||||
{
|
||||
return GetInstalledDepotsDelegatePointer( Self, appID, ref pvecDepots, cMaxDepots );
|
||||
return GetInstalledDepotsDelegatePointer( Self, appID, pvecDepots, cMaxDepots );
|
||||
}
|
||||
|
||||
#region FunctionMeta
|
||||
|
@ -48,7 +48,7 @@ internal static Internal.ISteamApps steamapps
|
||||
/// Gets the current language that the user has set.
|
||||
/// This falls back to the Steam UI language if the user hasn't explicitly picked a language for the title.
|
||||
/// </summary>
|
||||
public static string GameLangauge => steamapps.GetCurrentGameLanguage();
|
||||
public static string GameLanguage => steamapps.GetCurrentGameLanguage();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of the languages the current app supports.
|
||||
@ -84,11 +84,12 @@ internal static Internal.ISteamApps steamapps
|
||||
public static IEnumerable<DlcInformation> DlcInformation()
|
||||
{
|
||||
var appid = default( SteamNative.AppId_t );
|
||||
var sb = new StringBuilder( 512 );
|
||||
var available = false;
|
||||
|
||||
for ( int i = 0; i < steamapps.GetDLCCount(); i++ )
|
||||
{
|
||||
var sb = SteamNative.Helpers.TakeStringBuilder();
|
||||
|
||||
if ( !steamapps.BGetDLCDataByIndex( i, ref appid, ref available, sb, sb.Capacity ) )
|
||||
continue;
|
||||
|
||||
@ -111,5 +112,45 @@ public static IEnumerable<DlcInformation> DlcInformation()
|
||||
/// </summary>
|
||||
public static void UninstallDlc( AppId appid ) => steamapps.UninstallDLC( appid.Value );
|
||||
|
||||
/// <summary>
|
||||
/// Returns null if we're not on a beta branch, else the name of the branch
|
||||
/// </summary>
|
||||
public static string CurrentBetaName
|
||||
{
|
||||
get
|
||||
{
|
||||
var sb = SteamNative.Helpers.TakeStringBuilder();
|
||||
|
||||
if ( !steamapps.GetCurrentBetaName( sb, sb.Capacity ) )
|
||||
return null;
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allows you to force verify game content on next launch.
|
||||
///
|
||||
/// If you detect the game is out-of-date(for example, by having the client detect a version mismatch with a server),
|
||||
/// you can call use MarkContentCorrupt to force a verify, show a message to the user, and then quit.
|
||||
/// </summary>
|
||||
public static void MarkContentCorrupt( bool missingFilesOnly ) => steamapps.MarkContentCorrupt( missingFilesOnly );
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of all installed depots for a given App ID in mount order
|
||||
/// </summary>
|
||||
public static IEnumerable<DepotId> InstalledDepots( AppId appid )
|
||||
{
|
||||
var depots = new SteamNative.DepotId_t[32];
|
||||
uint count = 0;
|
||||
|
||||
count = steamapps.GetInstalledDepots( appid.Value, depots, (uint) depots.Length );
|
||||
|
||||
for ( int i = 0; i < count; i++ )
|
||||
{
|
||||
yield return new DepotId { Value = depots[i].Value };
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
28
Facepunch.Steamworks/Redux/Structs/DepotId.cs
Normal file
28
Facepunch.Steamworks/Redux/Structs/DepotId.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
|
||||
namespace Steamworks
|
||||
{
|
||||
public struct DepotId
|
||||
{
|
||||
public uint Value;
|
||||
|
||||
public static implicit operator DepotId( uint value )
|
||||
{
|
||||
return new DepotId { Value = value };
|
||||
}
|
||||
|
||||
public static implicit operator DepotId( int value )
|
||||
{
|
||||
return new DepotId { Value = (uint) value };
|
||||
}
|
||||
|
||||
public static implicit operator uint( DepotId value )
|
||||
{
|
||||
return value.Value;
|
||||
}
|
||||
}
|
||||
}
|
@ -20,7 +20,7 @@ public static BaseType Parse( string type, string varname = null )
|
||||
var basicType = type.Trim( ' ', '*' );
|
||||
|
||||
|
||||
if ( basicType == "int32" ) return new IntType { NativeType = type, VarName = varname };
|
||||
if ( basicType == "int32" || basicType == "int" ) return new IntType { NativeType = type, VarName = varname };
|
||||
if ( basicType == "uint32" ) return new UIntType { NativeType = type, VarName = varname };
|
||||
if ( basicType == "CSteamID" ) return new CSteamIdType { NativeType = type, VarName = varname };
|
||||
if ( basicType == "uint64" ) return new ULongType { NativeType = type, VarName = varname };
|
||||
@ -31,13 +31,14 @@ public static BaseType Parse( string type, string varname = null )
|
||||
return new BaseType { NativeType = type, VarName = varname };
|
||||
}
|
||||
|
||||
public virtual string AsArgument() => $"{Ref}{TypeName} {VarName}";
|
||||
public virtual string AsArgument() => IsVector? $"[In,Out] {TypeName}[] {VarName}" : $"{Ref}{TypeName} {VarName}";
|
||||
public virtual string AsCallArgument() => $"{Ref}{VarName}";
|
||||
|
||||
public virtual string Return( string varname ) => $"return {varname};";
|
||||
public virtual string ReturnAttribute => null;
|
||||
|
||||
public virtual string Ref => NativeType.EndsWith( "*" ) ? "ref " : "";
|
||||
public virtual string Ref => !IsVector && NativeType.EndsWith( "*" ) ? "ref " : "";
|
||||
public virtual bool IsVector => NativeType.EndsWith( "*" ) && VarName.Contains( "pvec" );
|
||||
|
||||
public virtual bool IsVoid => false;
|
||||
public virtual bool IsReturnedWeird => false;
|
||||
|
Loading…
Reference in New Issue
Block a user