Facepunch.Steamworks/Generator/CodeWriter/CodeWriter.cs

130 lines
5.2 KiB
C#
Raw Normal View History

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;
public CodeParser Parser;
2016-10-25 12:29:35 +03:00
public CodeWriter( CodeParser parser, SteamApiDefinition def )
2016-10-25 12:29:35 +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();
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-29 15:28:20 +03:00
{
GenerateGlobalFunctions( "SteamAPI", $"{folder}../Generated/SteamAPI.cs" );
GenerateGlobalFunctions( "SteamGameServer", $"{folder}../Generated/SteamGameServer.cs" );
GenerateGlobalFunctions( "SteamInternal", $"{folder}../Generated/SteamInternal.cs" );
}
{
GenerateVTableClass( "ISteamApps", $"{folder}../Generated/Interfaces/ISteamApps.cs" );
2019-04-13 00:53:46 +03:00
GenerateVTableClass( "ISteamUtils", $"{folder}../Generated/Interfaces/ISteamUtils.cs" );
2019-04-14 23:48:11 +03:00
GenerateVTableClass( "ISteamParentalSettings", $"{folder}../Generated/Interfaces/ISteamParentalSettings.cs" );
2019-04-14 23:57:09 +03:00
GenerateVTableClass( "ISteamMusic", $"{folder}../Generated/Interfaces/ISteamMusic.cs" );
2019-04-15 00:04:46 +03:00
GenerateVTableClass( "ISteamVideo", $"{folder}../Generated/Interfaces/ISteamVideo.cs" );
2019-04-15 12:24:44 +03:00
GenerateVTableClass( "ISteamUser", $"{folder}../Generated/Interfaces/ISteamUser.cs" );
2019-04-15 13:41:19 +03:00
GenerateVTableClass( "ISteamMatchmakingServers", $"{folder}../Generated/Interfaces/ISteamMatchmakingServers.cs" );
2019-04-15 16:19:40 +03:00
GenerateVTableClass( "ISteamFriends", $"{folder}../Generated/Interfaces/ISteamFriends.cs" );
2019-04-15 22:54:50 +03:00
GenerateVTableClass( "ISteamGameServer", $"{folder}../Generated/Interfaces/ISteamGameServer.cs" );
2019-04-16 18:37:49 +03:00
GenerateVTableClass( "ISteamScreenshots", $"{folder}../Generated/Interfaces/ISteamScreenshots.cs" );
2019-04-16 18:55:08 +03:00
GenerateVTableClass( "ISteamUserStats", $"{folder}../Generated/Interfaces/ISteamUserStats.cs" );
2019-04-17 16:07:58 +03:00
GenerateVTableClass( "ISteamUGC", $"{folder}../Generated/Interfaces/ISteamUGC.cs" );
2019-04-27 16:10:40 +03:00
GenerateVTableClass( "ISteamRemoteStorage", $"{folder}../Generated/Interfaces/ISteamRemoteStorage.cs" );
2019-04-27 17:49:33 +03:00
GenerateVTableClass( "ISteamInventory", $"{folder}../Generated/Interfaces/ISteamInventory.cs" );
2019-05-01 00:01:02 +03:00
GenerateVTableClass( "ISteamNetworking", $"{folder}../Generated/Interfaces/ISteamNetworking.cs" );
2019-05-01 16:28:42 +03:00
GenerateVTableClass( "ISteamMatchmaking", $"{folder}../Generated/Interfaces/ISteamMatchmaking.cs" );
2019-05-01 23:33:10 +03:00
GenerateVTableClass( "ISteamParties", $"{folder}../Generated/Interfaces/ISteamParties.cs" );
2019-05-02 15:05:38 +03:00
GenerateVTableClass( "ISteamNetworkingUtils", $"{folder}../Generated/Interfaces/ISteamNetworkingUtils.cs" );
2019-05-02 18:55:50 +03:00
GenerateVTableClass( "ISteamNetworkingSockets", $"{folder}../Generated/Interfaces/ISteamNetworkingSockets.cs" );
2019-05-09 13:17:19 +03:00
GenerateVTableClass( "ISteamGameServerStats", $"{folder}../Generated/Interfaces/ISteamGameServerStats.cs" );
2019-06-19 13:33:16 +03:00
GenerateVTableClass( "ISteamInput", $"{folder}../Generated/Interfaces/ISteamInput.cs" );
}
}
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;" );
WriteLine( "using System.Linq;" );
2019-04-16 16:38:10 +03:00
WriteLine( "using Steamworks.Data;" );
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
}