117 lines
4.2 KiB
C#
Raw Normal View History

2016-10-25 10:29:35 +01: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 16:11:29 +01:00
public partial class CodeWriter
2016-10-25 10:29:35 +01:00
{
private SteamApiDefinition def;
public CodeParser Parser;
2016-10-25 10:29:35 +01:00
public CodeWriter( CodeParser parser, SteamApiDefinition def )
2016-10-25 10:29:35 +01:00
{
Parser = parser;
this.def = def;
2016-10-25 10:29:35 +01:00
WorkoutTypes();
}
public void ToFolder( string folder )
{
{
sb = new StringBuilder();
Header();
Enums();
Footer();
2019-04-16 11:45:44 +01:00
System.IO.File.WriteAllText( $"{folder}SteamEnums.cs", sb.ToString() );
2016-10-25 10:29:35 +01:00
}
{
sb = new StringBuilder();
2019-04-16 15:05:19 +01:00
Header( "Steamworks.Data" );
2016-10-25 10:29:35 +01:00
Types();
Footer();
2019-04-16 11:45:44 +01:00
System.IO.File.WriteAllText( $"{folder}SteamTypes.cs", sb.ToString() );
2016-10-25 10:29:35 +01:00
}
{
sb = new StringBuilder();
2019-04-16 15:00:22 +01:00
Header( "Steamworks.Data" );
2016-10-25 10:29:35 +01:00
Structs();
Footer();
2019-04-16 11:45:44 +01:00
System.IO.File.WriteAllText( $"{folder}SteamStructs.cs", sb.ToString() );
2016-10-25 10:29:35 +01:00
}
2016-10-29 20:28:16 +01:00
{
sb = new StringBuilder();
2019-04-16 15:05:19 +01:00
Header( "Steamworks.Data" );
2016-10-29 20:28:16 +01:00
Constants();
Footer();
2019-04-16 11:45:44 +01:00
System.IO.File.WriteAllText( $"{folder}SteamConstants.cs", sb.ToString() );
2016-10-25 10:29:35 +01:00
}
{
GenerateVTableClass( "ISteamApps", $"{folder}../Generated/Interfaces/ISteamApps.cs" );
2019-04-12 22:53:46 +01:00
GenerateVTableClass( "ISteamUtils", $"{folder}../Generated/Interfaces/ISteamUtils.cs" );
2019-04-14 21:48:11 +01:00
GenerateVTableClass( "ISteamParentalSettings", $"{folder}../Generated/Interfaces/ISteamParentalSettings.cs" );
2019-04-14 21:57:09 +01:00
GenerateVTableClass( "ISteamMusic", $"{folder}../Generated/Interfaces/ISteamMusic.cs" );
2019-04-14 22:04:46 +01:00
GenerateVTableClass( "ISteamVideo", $"{folder}../Generated/Interfaces/ISteamVideo.cs" );
2019-04-15 10:24:44 +01:00
GenerateVTableClass( "ISteamUser", $"{folder}../Generated/Interfaces/ISteamUser.cs" );
2019-04-15 11:41:19 +01:00
GenerateVTableClass( "ISteamMatchmakingServers", $"{folder}../Generated/Interfaces/ISteamMatchmakingServers.cs" );
2019-04-15 14:19:40 +01:00
GenerateVTableClass( "ISteamFriends", $"{folder}../Generated/Interfaces/ISteamFriends.cs" );
2019-04-15 20:54:50 +01:00
GenerateVTableClass( "ISteamGameServer", $"{folder}../Generated/Interfaces/ISteamGameServer.cs" );
2019-04-16 16:37:49 +01:00
GenerateVTableClass( "ISteamGameServer", $"{folder}../Generated/Interfaces/ISteamGameServer.cs" );
GenerateVTableClass( "ISteamScreenshots", $"{folder}../Generated/Interfaces/ISteamScreenshots.cs" );
2019-04-16 16:55:08 +01:00
GenerateVTableClass( "ISteamUserStats", $"{folder}../Generated/Interfaces/ISteamUserStats.cs" );
2019-04-17 14:07:58 +01:00
GenerateVTableClass( "ISteamUGC", $"{folder}../Generated/Interfaces/ISteamUGC.cs" );
2019-04-27 14:10:40 +01:00
GenerateVTableClass( "ISteamRemoteStorage", $"{folder}../Generated/Interfaces/ISteamRemoteStorage.cs" );
2019-04-27 15:49:33 +01:00
GenerateVTableClass( "ISteamInventory", $"{folder}../Generated/Interfaces/ISteamInventory.cs" );
}
}
2016-10-25 10:29:35 +01: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 12:17:24 +01:00
TypeDefs.Add( c.Name, new TypeDef()
2016-10-25 10:29:35 +01:00
{
Name = c.Name,
NativeType = c.Type,
ManagedType = type,
} );
}
}
2019-04-16 11:45:44 +01:00
private void Header( string NamespaceName = "Steamworks" )
2016-10-25 10:29:35 +01:00
{
WriteLine( "using System;" );
WriteLine( "using System.Runtime.InteropServices;" );
WriteLine( "using System.Linq;" );
2019-04-16 14:38:10 +01:00
WriteLine( "using Steamworks.Data;" );
2016-10-25 10:29:35 +01:00
WriteLine();
2016-11-11 14:51:04 +00:00
StartBlock( "namespace " + NamespaceName );
2016-10-25 10:29:35 +01:00
}
2016-10-29 13:02:36 +01:00
private void Footer()
{
EndBlock();
}
}
2016-10-25 10:29:35 +01:00
}