mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-24 13:45:37 +03:00
Cleaning
This commit is contained in:
parent
ba06bce930
commit
9e14aff459
@ -11,9 +11,9 @@ class Argument
|
|||||||
public string Name;
|
public string Name;
|
||||||
public string NativeType;
|
public string NativeType;
|
||||||
public string ManagedType;
|
public string ManagedType;
|
||||||
public TypeDef TypeDef;
|
public CodeWriter.TypeDef TypeDef;
|
||||||
|
|
||||||
public Argument( string Name, string ManagedType, Dictionary<string, TypeDef> typeDefs )
|
public Argument( string Name, string ManagedType, Dictionary<string, CodeWriter.TypeDef> typeDefs )
|
||||||
{
|
{
|
||||||
this.Name = Name;
|
this.Name = Name;
|
||||||
this.NativeType = ManagedType;
|
this.NativeType = ManagedType;
|
||||||
@ -21,7 +21,7 @@ public Argument( string Name, string ManagedType, Dictionary<string, TypeDef> ty
|
|||||||
Build( typeDefs );
|
Build( typeDefs );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Build( Dictionary<string, TypeDef> typeDefs )
|
private void Build( Dictionary<string, CodeWriter.TypeDef> typeDefs )
|
||||||
{
|
{
|
||||||
var cleanNative = NativeType.Trim( '*', ' ' ).Replace( "class ", "" ).Replace( "const ", "" );
|
var cleanNative = NativeType.Trim( '*', ' ' ).Replace( "class ", "" ).Replace( "const ", "" );
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ public partial class CodeWriter
|
|||||||
//
|
//
|
||||||
// Output a class into a file
|
// Output a class into a file
|
||||||
//
|
//
|
||||||
void Class( string FileName )
|
void GenerateClasses( string FileName )
|
||||||
{
|
{
|
||||||
foreach ( var g in def.methods.GroupBy( x => x.ClassName ) )
|
foreach ( var g in def.methods.GroupBy( x => x.ClassName ) )
|
||||||
{
|
{
|
||||||
|
@ -10,11 +10,8 @@ namespace Generator
|
|||||||
{
|
{
|
||||||
public partial class CodeWriter
|
public partial class CodeWriter
|
||||||
{
|
{
|
||||||
private StringBuilder sb = new StringBuilder();
|
|
||||||
private SteamApiDefinition def;
|
private SteamApiDefinition def;
|
||||||
|
|
||||||
private Dictionary<string, TypeDef> TypeDefs = new Dictionary<string, TypeDef>();
|
|
||||||
|
|
||||||
public CodeWriter( SteamApiDefinition def )
|
public CodeWriter( SteamApiDefinition def )
|
||||||
{
|
{
|
||||||
this.def = def;
|
this.def = def;
|
||||||
@ -265,7 +262,7 @@ public void ToFolder( string folder )
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
Class( $"{folder}SteamNative." );
|
GenerateClasses( $"{folder}SteamNative." );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -296,50 +293,6 @@ void WorkoutTypes()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private string ToManagedType( string type )
|
|
||||||
{
|
|
||||||
type = type.Replace( "ISteamHTMLSurface::", "" );
|
|
||||||
type = type.Replace( "class ", "" );
|
|
||||||
type = type.Replace( "struct ", "" );
|
|
||||||
type = type.Replace( "const void", "void" );
|
|
||||||
type = type.Replace( "union ", "" );
|
|
||||||
type = type.Replace( "enum ", "" );
|
|
||||||
|
|
||||||
switch ( type )
|
|
||||||
{
|
|
||||||
case "uint64": return "ulong";
|
|
||||||
case "uint32": return "uint";
|
|
||||||
case "int32": return "int";
|
|
||||||
case "int64": return "long";
|
|
||||||
case "void *": return "IntPtr";
|
|
||||||
case "uint8 *": return "IntPtr";
|
|
||||||
case "int16": return "short";
|
|
||||||
case "uint8": return "byte";
|
|
||||||
case "int8": return "char";
|
|
||||||
case "unsigned short": return "ushort";
|
|
||||||
case "unsigned int": return "uint";
|
|
||||||
case "uint16": return "ushort";
|
|
||||||
case "const char *": return "string";
|
|
||||||
case "_Bool": return "bool";
|
|
||||||
case "CSteamID": return "ulong";
|
|
||||||
|
|
||||||
case "SteamAPIWarningMessageHook_t": return "IntPtr";
|
|
||||||
}
|
|
||||||
|
|
||||||
//type = type.Trim( '*', ' ' );
|
|
||||||
|
|
||||||
// Enums - skip the 'E'
|
|
||||||
if ( type[0] == 'E' )
|
|
||||||
{
|
|
||||||
return type.Substring( 1 );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( type.StartsWith( "ISteamMatchmak" ) && type.Contains( "Response" ) )
|
|
||||||
return "IntPtr";
|
|
||||||
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Argument> BuildArguments( SteamApiDefinition.MethodDef.ParamType[] ps )
|
private List<Argument> BuildArguments( SteamApiDefinition.MethodDef.ParamType[] ps )
|
||||||
{
|
{
|
||||||
var args = new List<Argument>();
|
var args = new List<Argument>();
|
||||||
@ -354,51 +307,6 @@ private List<Argument> BuildArguments( SteamApiDefinition.MethodDef.ParamType[]
|
|||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private int indent = 0;
|
|
||||||
public string Indent { get { return new string( '\t', indent ); } }
|
|
||||||
|
|
||||||
private void EndBlock( string end = "" )
|
|
||||||
{
|
|
||||||
indent--;
|
|
||||||
sb.AppendLine( $"{Indent}}}{end}" );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void WriteLine( string v = "" )
|
|
||||||
{
|
|
||||||
sb.AppendLine( $"{Indent}{v}" );
|
|
||||||
}
|
|
||||||
|
|
||||||
private void StartBlock( string v )
|
|
||||||
{
|
|
||||||
sb.AppendLine( $"{Indent}{v}" );
|
|
||||||
sb.AppendLine( $"{Indent}{{" );
|
|
||||||
|
|
||||||
indent++;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void WriteLines( List<string> beforeLines )
|
|
||||||
{
|
|
||||||
foreach ( var line in beforeLines )
|
|
||||||
{
|
|
||||||
if ( line == "}" )
|
|
||||||
indent--;
|
|
||||||
|
|
||||||
WriteLine( line );
|
|
||||||
|
|
||||||
if ( line == "{" )
|
|
||||||
indent++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void Footer()
|
|
||||||
{
|
|
||||||
EndBlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Header()
|
private void Header()
|
||||||
{
|
{
|
||||||
WriteLine( "using System;" );
|
WriteLine( "using System;" );
|
||||||
@ -406,13 +314,10 @@ private void Header()
|
|||||||
WriteLine();
|
WriteLine();
|
||||||
StartBlock( "namespace SteamNative" );
|
StartBlock( "namespace SteamNative" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Footer()
|
||||||
|
{
|
||||||
|
EndBlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TypeDef
|
|
||||||
{
|
|
||||||
public string Name;
|
|
||||||
public string NativeType;
|
|
||||||
public string ManagedType;
|
|
||||||
}
|
|
||||||
|
|
@ -8,6 +8,15 @@ namespace Generator
|
|||||||
{
|
{
|
||||||
public partial class CodeWriter
|
public partial class CodeWriter
|
||||||
{
|
{
|
||||||
|
public class TypeDef
|
||||||
|
{
|
||||||
|
public string Name;
|
||||||
|
public string NativeType;
|
||||||
|
public string ManagedType;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Dictionary<string, TypeDef> TypeDefs = new Dictionary<string, TypeDef>();
|
||||||
|
|
||||||
//
|
//
|
||||||
// Don't give a fuck about these classes, they just cause us trouble
|
// Don't give a fuck about these classes, they just cause us trouble
|
||||||
//
|
//
|
||||||
|
@ -57,5 +57,50 @@ string CleanMemberName( string m )
|
|||||||
|
|
||||||
return cleanName.Substring( 0, 1 ).ToUpper() + cleanName.Substring( 1 );
|
return cleanName.Substring( 0, 1 ).ToUpper() + cleanName.Substring( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private string ToManagedType( string type )
|
||||||
|
{
|
||||||
|
type = type.Replace( "ISteamHTMLSurface::", "" );
|
||||||
|
type = type.Replace( "class ", "" );
|
||||||
|
type = type.Replace( "struct ", "" );
|
||||||
|
type = type.Replace( "const void", "void" );
|
||||||
|
type = type.Replace( "union ", "" );
|
||||||
|
type = type.Replace( "enum ", "" );
|
||||||
|
|
||||||
|
switch ( type )
|
||||||
|
{
|
||||||
|
case "uint64": return "ulong";
|
||||||
|
case "uint32": return "uint";
|
||||||
|
case "int32": return "int";
|
||||||
|
case "int64": return "long";
|
||||||
|
case "void *": return "IntPtr";
|
||||||
|
case "uint8 *": return "IntPtr";
|
||||||
|
case "int16": return "short";
|
||||||
|
case "uint8": return "byte";
|
||||||
|
case "int8": return "char";
|
||||||
|
case "unsigned short": return "ushort";
|
||||||
|
case "unsigned int": return "uint";
|
||||||
|
case "uint16": return "ushort";
|
||||||
|
case "const char *": return "string";
|
||||||
|
case "_Bool": return "bool";
|
||||||
|
case "CSteamID": return "ulong";
|
||||||
|
|
||||||
|
case "SteamAPIWarningMessageHook_t": return "IntPtr";
|
||||||
|
}
|
||||||
|
|
||||||
|
//type = type.Trim( '*', ' ' );
|
||||||
|
|
||||||
|
// Enums - skip the 'E'
|
||||||
|
if ( type[0] == 'E' )
|
||||||
|
{
|
||||||
|
return type.Substring( 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( type.StartsWith( "ISteamMatchmak" ) && type.Contains( "Response" ) )
|
||||||
|
return "IntPtr";
|
||||||
|
|
||||||
|
return type;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
55
Generator/CodeWriter/Writing.cs
Normal file
55
Generator/CodeWriter/Writing.cs
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Generator;
|
||||||
|
|
||||||
|
namespace Generator
|
||||||
|
{
|
||||||
|
public partial class CodeWriter
|
||||||
|
{
|
||||||
|
private StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
private int indent = 0;
|
||||||
|
public string Indent { get { return new string( '\t', indent ); } }
|
||||||
|
|
||||||
|
private void EndBlock( string end = "" )
|
||||||
|
{
|
||||||
|
indent--;
|
||||||
|
sb.AppendLine( $"{Indent}}}{end}" );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void WriteLine( string v = "" )
|
||||||
|
{
|
||||||
|
sb.AppendLine( $"{Indent}{v}" );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StartBlock( string v )
|
||||||
|
{
|
||||||
|
sb.AppendLine( $"{Indent}{v}" );
|
||||||
|
sb.AppendLine( $"{Indent}{{" );
|
||||||
|
|
||||||
|
indent++;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WriteLines( List<string> beforeLines )
|
||||||
|
{
|
||||||
|
foreach ( var line in beforeLines )
|
||||||
|
{
|
||||||
|
if ( line == "}" )
|
||||||
|
indent--;
|
||||||
|
|
||||||
|
WriteLine( line );
|
||||||
|
|
||||||
|
if ( line == "{" )
|
||||||
|
indent++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -49,7 +49,8 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Argument.cs" />
|
<Compile Include="Argument.cs" />
|
||||||
<Compile Include="CodeWriter\Class.cs" />
|
<Compile Include="CodeWriter\Class.cs" />
|
||||||
<Compile Include="CodeWriter.cs" />
|
<Compile Include="CodeWriter\Writing.cs" />
|
||||||
|
<Compile Include="CodeWriter\CodeWriter.cs" />
|
||||||
<Compile Include="CodeWriter\Enums.cs" />
|
<Compile Include="CodeWriter\Enums.cs" />
|
||||||
<Compile Include="CodeWriter\Struct.cs" />
|
<Compile Include="CodeWriter\Struct.cs" />
|
||||||
<Compile Include="CodeWriter\Types.cs" />
|
<Compile Include="CodeWriter\Types.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user