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;
|
|
|
|
|
|
2020-02-12 17:55:36 +03:00
|
|
|
|
public CodeWriter( SteamApiDefinition def )
|
2016-10-25 12:29:35 +03:00
|
|
|
|
{
|
2019-04-12 17:43:11 +03:00
|
|
|
|
this.def = def;
|
2016-10-25 12:29:35 +03:00
|
|
|
|
WorkoutTypes();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ToFolder( string folder )
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
sb = new StringBuilder();
|
|
|
|
|
Header();
|
|
|
|
|
Enums();
|
|
|
|
|
Footer();
|
2019-04-16 13:45:44 +03:00
|
|
|
|
System.IO.File.WriteAllText( $"{folder}SteamEnums.cs", sb.ToString() );
|
2016-10-25 12:29:35 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
sb = new StringBuilder();
|
2019-04-16 17:05:19 +03:00
|
|
|
|
Header( "Steamworks.Data" );
|
2016-10-25 12:29:35 +03:00
|
|
|
|
Types();
|
|
|
|
|
Footer();
|
2019-04-16 13:45:44 +03:00
|
|
|
|
System.IO.File.WriteAllText( $"{folder}SteamTypes.cs", sb.ToString() );
|
2016-10-25 12:29:35 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
sb = new StringBuilder();
|
2019-04-16 17:00:22 +03:00
|
|
|
|
Header( "Steamworks.Data" );
|
2016-10-25 12:29:35 +03:00
|
|
|
|
Structs();
|
|
|
|
|
Footer();
|
2019-04-16 13:45:44 +03:00
|
|
|
|
System.IO.File.WriteAllText( $"{folder}SteamStructs.cs", sb.ToString() );
|
2016-10-25 12:29:35 +03:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-29 22:28:16 +03:00
|
|
|
|
{
|
|
|
|
|
sb = new StringBuilder();
|
2019-04-16 17:05:19 +03:00
|
|
|
|
Header( "Steamworks.Data" );
|
2016-10-29 22:28:16 +03:00
|
|
|
|
Constants();
|
|
|
|
|
Footer();
|
2019-04-16 13:45:44 +03:00
|
|
|
|
System.IO.File.WriteAllText( $"{folder}SteamConstants.cs", sb.ToString() );
|
2016-10-25 12:29:35 +03:00
|
|
|
|
}
|
2019-04-12 17:43:11 +03:00
|
|
|
|
|
2019-04-29 15:28:20 +03:00
|
|
|
|
{
|
2020-02-12 17:55:36 +03:00
|
|
|
|
// GenerateGlobalFunctions( "SteamAPI", $"{folder}../Generated/SteamAPI.cs" );
|
|
|
|
|
// GenerateGlobalFunctions( "SteamGameServer", $"{folder}../Generated/SteamGameServer.cs" );
|
|
|
|
|
// GenerateGlobalFunctions( "SteamInternal", $"{folder}../Generated/SteamInternal.cs" );
|
2019-04-29 15:28:20 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-12 17:55:36 +03:00
|
|
|
|
foreach ( var iface in def.Interfaces )
|
|
|
|
|
{
|
|
|
|
|
GenerateVTableClass( iface, $"{folder}../Generated/Interfaces/" );
|
|
|
|
|
}
|
2019-04-12 17:43:11 +03:00
|
|
|
|
}
|
2016-10-25 12:29:35 +03:00
|
|
|
|
|
|
|
|
|
void WorkoutTypes()
|
|
|
|
|
{
|
|
|
|
|
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 );
|
|
|
|
|
|
2019-04-16 14:17:24 +03:00
|
|
|
|
TypeDefs.Add( c.Name, new TypeDef()
|
2016-10-25 12:29:35 +03:00
|
|
|
|
{
|
|
|
|
|
Name = c.Name,
|
|
|
|
|
NativeType = c.Type,
|
|
|
|
|
ManagedType = type,
|
|
|
|
|
} );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-16 13:45:44 +03:00
|
|
|
|
private void Header( string NamespaceName = "Steamworks" )
|
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;" );
|
2019-04-16 16:38:10 +03:00
|
|
|
|
WriteLine( "using Steamworks.Data;" );
|
2019-04-30 18:43:27 +03:00
|
|
|
|
WriteLine( "using System.Threading.Tasks;" );
|
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
|
|
|
|
}
|