2016-10-25 12:29:35 +03:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Generator;
|
|
|
|
|
|
|
|
|
|
namespace Generator
|
|
|
|
|
{
|
2016-10-25 18:11:29 +03:00
|
|
|
|
public partial class CodeWriter
|
2016-10-25 12:29:35 +03:00
|
|
|
|
{
|
|
|
|
|
private SteamApiDefinition def;
|
2019-04-12 17:43:11 +03:00
|
|
|
|
public CodeParser Parser;
|
2016-10-25 12:29:35 +03:00
|
|
|
|
|
2019-04-12 17:43:11 +03:00
|
|
|
|
public CodeWriter( CodeParser parser, SteamApiDefinition def )
|
2016-10-25 12:29:35 +03:00
|
|
|
|
{
|
2019-04-12 17:43:11 +03:00
|
|
|
|
Parser = parser;
|
|
|
|
|
|
|
|
|
|
this.def = def;
|
2016-10-25 12:29:35 +03:00
|
|
|
|
WorkoutTypes();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ToFolder( string folder )
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
sb = new StringBuilder();
|
|
|
|
|
Header();
|
|
|
|
|
Enums();
|
|
|
|
|
Footer();
|
|
|
|
|
System.IO.File.WriteAllText( $"{folder}SteamNative.Enums.cs", sb.ToString() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
sb = new StringBuilder();
|
|
|
|
|
Header();
|
|
|
|
|
Types();
|
|
|
|
|
Footer();
|
|
|
|
|
System.IO.File.WriteAllText( $"{folder}SteamNative.Types.cs", sb.ToString() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
sb = new StringBuilder();
|
|
|
|
|
Header();
|
|
|
|
|
Structs();
|
|
|
|
|
Footer();
|
|
|
|
|
System.IO.File.WriteAllText( $"{folder}SteamNative.Structs.cs", sb.ToString() );
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-29 22:28:16 +03:00
|
|
|
|
{
|
|
|
|
|
sb = new StringBuilder();
|
|
|
|
|
Header();
|
|
|
|
|
Constants();
|
|
|
|
|
Footer();
|
|
|
|
|
System.IO.File.WriteAllText( $"{folder}SteamNative.Constants.cs", sb.ToString() );
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-25 15:22:59 +03:00
|
|
|
|
{
|
|
|
|
|
sb = new StringBuilder();
|
|
|
|
|
Header();
|
|
|
|
|
PlatformInterface();
|
|
|
|
|
Footer();
|
|
|
|
|
System.IO.File.WriteAllText( $"{folder}SteamNative.Platform.Interface.cs", sb.ToString() );
|
|
|
|
|
}
|
2016-10-25 12:29:35 +03:00
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
sb = new StringBuilder();
|
|
|
|
|
Header();
|
2019-04-11 18:18:08 +03:00
|
|
|
|
PlatformClass( "Windows", "steam_api64.dll", true );
|
2016-10-25 12:29:35 +03:00
|
|
|
|
Footer();
|
|
|
|
|
System.IO.File.WriteAllText( $"{folder}SteamNative.Platform.Win64.cs", sb.ToString() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
sb = new StringBuilder();
|
|
|
|
|
Header();
|
2019-04-11 23:34:52 +03:00
|
|
|
|
PlatformClass( "Linux", "libsteam_api.so", false );
|
2016-10-25 12:29:35 +03:00
|
|
|
|
Footer();
|
2016-10-25 15:22:59 +03:00
|
|
|
|
System.IO.File.WriteAllText( $"{folder}SteamNative.Platform.Linux64.cs", sb.ToString() );
|
2016-10-25 12:29:35 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
sb = new StringBuilder();
|
|
|
|
|
Header();
|
2016-10-25 17:35:48 +03:00
|
|
|
|
PlatformClass( "Mac", "libsteam_api.dylib", false );
|
2016-10-25 12:29:35 +03:00
|
|
|
|
Footer();
|
|
|
|
|
System.IO.File.WriteAllText( $"{folder}SteamNative.Platform.Mac.cs", sb.ToString() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2016-10-29 15:02:36 +03:00
|
|
|
|
GenerateClasses( $"{folder}SteamNative." );
|
2016-10-25 12:29:35 +03:00
|
|
|
|
}
|
2019-04-12 17:43:11 +03:00
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
GenerateVTableClass( "ISteamApps", $"{folder}../Generated/Interfaces/ISteamApps.cs" );
|
2019-04-13 00:53:46 +03:00
|
|
|
|
GenerateVTableClass( "ISteamUtils", $"{folder}../Generated/Interfaces/ISteamUtils.cs" );
|
2019-04-12 17:43:11 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-25 12:29:35 +03:00
|
|
|
|
|
|
|
|
|
void WorkoutTypes()
|
|
|
|
|
{
|
|
|
|
|
def.typedefs.Add( new SteamApiDefinition.TypeDef() { Name = "CGameID", Type = "ulong" } );
|
|
|
|
|
def.typedefs.Add( new SteamApiDefinition.TypeDef() { Name = "CSteamID", Type = "ulong" } );
|
|
|
|
|
|
|
|
|
|
foreach ( var c in def.typedefs )
|
|
|
|
|
{
|
|
|
|
|
if ( c.Name.StartsWith( "uint" ) || c.Name.StartsWith( "int" ) || c.Name.StartsWith( "lint" ) || c.Name.StartsWith( "luint" ) || c.Name.StartsWith( "ulint" ) )
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// Unused, messers
|
|
|
|
|
if ( c.Name == "Salt_t" || c.Name == "compile_time_assert_type" || c.Name == "ValvePackingSentinel_t" || c.Name.Contains( "::" ) || c.Type.Contains( "(*)" ) )
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
var type = c.Type;
|
|
|
|
|
|
|
|
|
|
type = ToManagedType( type );
|
|
|
|
|
|
|
|
|
|
TypeDefs.Add( c.Name, new TypeDef()
|
|
|
|
|
{
|
|
|
|
|
Name = c.Name,
|
|
|
|
|
NativeType = c.Type,
|
|
|
|
|
ManagedType = type,
|
|
|
|
|
} );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<Argument> BuildArguments( SteamApiDefinition.MethodDef.ParamType[] ps )
|
|
|
|
|
{
|
|
|
|
|
var args = new List<Argument>();
|
|
|
|
|
if ( ps == null ) return args;
|
|
|
|
|
|
|
|
|
|
foreach ( var p in ps )
|
|
|
|
|
{
|
2016-10-25 18:16:02 +03:00
|
|
|
|
var a = new Argument( p.Name, p.Type, TypeDefs );
|
2016-10-25 12:29:35 +03:00
|
|
|
|
args.Add( a );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return args;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-11 17:51:04 +03:00
|
|
|
|
private void Header( string NamespaceName = "SteamNative" )
|
2016-10-25 12:29:35 +03:00
|
|
|
|
{
|
|
|
|
|
WriteLine( "using System;" );
|
|
|
|
|
WriteLine( "using System.Runtime.InteropServices;" );
|
2017-04-05 18:17:30 +03:00
|
|
|
|
WriteLine( "using System.Linq;" );
|
2016-10-25 12:29:35 +03:00
|
|
|
|
WriteLine();
|
2016-11-11 17:51:04 +03:00
|
|
|
|
StartBlock( "namespace " + NamespaceName );
|
2016-10-25 12:29:35 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-29 15:02:36 +03:00
|
|
|
|
private void Footer()
|
|
|
|
|
{
|
|
|
|
|
EndBlock();
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-25 12:29:35 +03:00
|
|
|
|
}
|