mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-25 06:05:46 +03:00
Cleanup
This commit is contained in:
parent
a333bc3860
commit
14ee1314de
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -73,10 +73,6 @@ private void PlatformClass( string className, SteamApiDefinition.MethodDef[] met
|
|||||||
WriteLine();
|
WriteLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void PlatformClassMethod( string classname, SteamApiDefinition.MethodDef methodDef )
|
private void PlatformClassMethod( string classname, SteamApiDefinition.MethodDef methodDef )
|
||||||
{
|
{
|
||||||
var arguments = BuildArguments( methodDef.Params );
|
var arguments = BuildArguments( methodDef.Params );
|
||||||
@ -97,59 +93,76 @@ private void PlatformClassMethod( string classname, SteamApiDefinition.MethodDef
|
|||||||
if ( argstring != "" ) argstring = $" {argstring} ";
|
if ( argstring != "" ) argstring = $" {argstring} ";
|
||||||
|
|
||||||
StartBlock( $"public virtual {ret.Return()} {classname}_{methodName}({argstring})" );
|
StartBlock( $"public virtual {ret.Return()} {classname}_{methodName}({argstring})" );
|
||||||
|
|
||||||
// var vars = string.Join( " + \",\" + ", arguments.Where( x => !x.InteropParameter( true, true ).StartsWith( "out " ) ).Select( x => x.Name ) );
|
|
||||||
// if ( vars != "" ) vars = "\" + " + vars + " + \"";
|
|
||||||
// WriteLine( $"Console.WriteLine( \"{classname}_{methodName}( {vars} )\" );" );
|
|
||||||
|
|
||||||
if ( methodDef.NeedsSelfPointer )
|
|
||||||
{
|
{
|
||||||
WriteLine( $"if ( _ptr == IntPtr.Zero ) throw new System.Exception( \"{classname} _ptr is null!\" );" );
|
|
||||||
WriteLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
var retcode = "";
|
// var vars = string.Join( " + \",\" + ", arguments.Where( x => !x.InteropParameter( true, true ).StartsWith( "out " ) ).Select( x => x.Name ) );
|
||||||
if ( ret.NativeType != "void" )
|
// if ( vars != "" ) vars = "\" + " + vars + " + \"";
|
||||||
retcode = "return ";
|
// WriteLine( $"Console.WriteLine( \"{classname}_{methodName}( {vars} )\" );" );
|
||||||
|
|
||||||
AfterLines = new List<string>();
|
if ( methodDef.NeedsSelfPointer )
|
||||||
|
|
||||||
foreach ( var a in arguments )
|
|
||||||
{
|
|
||||||
if ( a.InteropParameter( LargePack ).Contains( ".PackSmall" ) )
|
|
||||||
{
|
{
|
||||||
WriteLine( $"var {a.Name}_ps = new {a.ManagedType.Trim( '*' )}.PackSmall();" );
|
WriteLine( $"if ( _ptr == IntPtr.Zero ) throw new System.Exception( \"{classname} _ptr is null!\" );" );
|
||||||
AfterLines.Add( $"{a.Name} = {a.Name}_ps;" );
|
WriteLine();
|
||||||
a.Name = "ref " + a.Name + "_ps";
|
|
||||||
|
|
||||||
if ( retcode != "" )
|
|
||||||
retcode = "var ret = ";
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var retcode = "";
|
||||||
|
if ( ret.NativeType != "void" )
|
||||||
|
retcode = "return ";
|
||||||
|
|
||||||
|
AfterLines = new List<string>();
|
||||||
|
|
||||||
|
foreach ( var a in arguments )
|
||||||
|
{
|
||||||
|
if ( a.InteropParameter( LargePack ).Contains( ".PackSmall" ) )
|
||||||
|
{
|
||||||
|
WriteLine( $"var {a.Name}_ps = new {a.ManagedType.Trim( '*' )}.PackSmall();" );
|
||||||
|
AfterLines.Add( $"{a.Name} = {a.Name}_ps;" );
|
||||||
|
a.Name = "ref " + a.Name + "_ps";
|
||||||
|
|
||||||
|
if ( retcode != "" )
|
||||||
|
retcode = "var ret = ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
argstring = string.Join( ", ", arguments.Select( x => x.InteropVariable( false ) ) );
|
||||||
|
|
||||||
|
if ( methodDef.NeedsSelfPointer )
|
||||||
|
argstring = "_ptr" + ( argstring.Length > 0 ? ", " : "" ) + argstring;
|
||||||
|
|
||||||
|
WriteLine( $"{retcode}Native.{flatName}({argstring});" );
|
||||||
|
|
||||||
|
WriteLines( AfterLines );
|
||||||
|
|
||||||
|
if ( retcode.StartsWith( "var" ) )
|
||||||
|
{
|
||||||
|
WriteLine( "return ret;" );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
argstring = string.Join( ", ", arguments.Select( x => x.InteropVariable( false ) ) );
|
|
||||||
|
|
||||||
if ( methodDef.NeedsSelfPointer )
|
|
||||||
argstring = "_ptr" + ( argstring.Length > 0 ? ", " : "" ) + argstring;
|
|
||||||
|
|
||||||
WriteLine( $"{retcode}Native.{classname}.{methodName}({argstring});" );
|
|
||||||
|
|
||||||
WriteLines( AfterLines );
|
|
||||||
|
|
||||||
if ( retcode.StartsWith( "var" ) )
|
|
||||||
{
|
|
||||||
WriteLine( "return ret;" );
|
|
||||||
}
|
|
||||||
|
|
||||||
EndBlock();
|
EndBlock();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
LastMethodName = methodDef.Name;
|
LastMethodName = methodDef.Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void InteropClass( string libraryName, string className, SteamApiDefinition.MethodDef[] methodDef )
|
||||||
|
{
|
||||||
|
if ( ShouldIgnoreClass( className ) ) return;
|
||||||
|
|
||||||
|
WriteLine( $"//" );
|
||||||
|
WriteLine( $"// {className} " );
|
||||||
|
WriteLine( $"//" );
|
||||||
|
|
||||||
|
LastMethodName = "";
|
||||||
|
foreach ( var m in methodDef )
|
||||||
|
{
|
||||||
|
InteropClassMethod( libraryName, className, m );
|
||||||
|
}
|
||||||
|
|
||||||
|
WriteLine();
|
||||||
|
}
|
||||||
|
|
||||||
private void InteropClassMethod( string library, string classname, SteamApiDefinition.MethodDef methodDef )
|
private void InteropClassMethod( string library, string classname, SteamApiDefinition.MethodDef methodDef )
|
||||||
{
|
{
|
||||||
var arguments = BuildArguments( methodDef.Params );
|
var arguments = BuildArguments( methodDef.Params );
|
||||||
@ -165,7 +178,6 @@ private void InteropClassMethod( string library, string classname, SteamApiDefin
|
|||||||
if ( classname == "SteamApi" )
|
if ( classname == "SteamApi" )
|
||||||
flatName = methodName;
|
flatName = methodName;
|
||||||
|
|
||||||
|
|
||||||
var argstring = string.Join( ", ", arguments.Select( x => x.InteropParameter( LargePack, true ) ) );
|
var argstring = string.Join( ", ", arguments.Select( x => x.InteropParameter( LargePack, true ) ) );
|
||||||
|
|
||||||
if ( methodDef.NeedsSelfPointer )
|
if ( methodDef.NeedsSelfPointer )
|
||||||
@ -175,31 +187,14 @@ private void InteropClassMethod( string library, string classname, SteamApiDefin
|
|||||||
|
|
||||||
if ( argstring != "" ) argstring = $" {argstring} ";
|
if ( argstring != "" ) argstring = $" {argstring} ";
|
||||||
|
|
||||||
WriteLine( $"[DllImportAttribute( \"{library}\", EntryPoint = \"{flatName}\" )]" );
|
Write( $"[DllImportAttribute( \"{library}\" )] " );
|
||||||
|
|
||||||
if ( ret.Return() == "bool" ) WriteLine( "[return: MarshalAs(UnmanagedType.U1)]" );
|
if ( ret.Return() == "bool" ) WriteLine( "[return: MarshalAs(UnmanagedType.U1)]" );
|
||||||
|
|
||||||
WriteLine( $"internal static extern {ret.Return()} {methodName}({argstring});" );
|
WriteLine( $"internal static extern {ret.Return()} {flatName}({argstring});" );
|
||||||
LastMethodName = methodDef.Name;
|
LastMethodName = methodDef.Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InteropClass( string libraryName, string className, SteamApiDefinition.MethodDef[] methodDef )
|
|
||||||
{
|
|
||||||
if ( ShouldIgnoreClass( className ) ) return;
|
|
||||||
|
|
||||||
StartBlock( $"internal static unsafe class {className}" );
|
|
||||||
|
|
||||||
LastMethodName = "";
|
|
||||||
foreach ( var m in methodDef )
|
|
||||||
{
|
|
||||||
InteropClassMethod( libraryName, className, m );
|
|
||||||
}
|
|
||||||
|
|
||||||
EndBlock();
|
|
||||||
|
|
||||||
WriteLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,24 +13,32 @@ public partial class CodeWriter
|
|||||||
private StringBuilder sb = new StringBuilder();
|
private StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
private int indent = 0;
|
private int indent = 0;
|
||||||
public string Indent { get { return new string( '\t', indent ); } }
|
private bool skipIndent = false;
|
||||||
|
public string Indent { get { if ( skipIndent ) { return ""; } return new string( '\t', indent ); } }
|
||||||
|
|
||||||
private void EndBlock( string end = "" )
|
private void EndBlock( string end = "" )
|
||||||
{
|
{
|
||||||
indent--;
|
indent--;
|
||||||
sb.AppendLine( $"{Indent}}}{end}" );
|
WriteLine( "}" + end );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void WriteLine( string v = "" )
|
private void WriteLine( string v = "" )
|
||||||
{
|
{
|
||||||
sb.AppendLine( $"{Indent}{v}" );
|
sb.AppendLine( $"{Indent}{v}" );
|
||||||
|
skipIndent = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Write( string v = "" )
|
||||||
|
{
|
||||||
|
sb.Append( $"{Indent}{v}" );
|
||||||
|
skipIndent = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StartBlock( string v )
|
private void StartBlock( string v )
|
||||||
{
|
{
|
||||||
sb.AppendLine( $"{Indent}{v}" );
|
WriteLine( v );
|
||||||
sb.AppendLine( $"{Indent}{{" );
|
WriteLine( "{" );
|
||||||
|
|
||||||
indent++;
|
indent++;
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="App.config" />
|
<None Include="App.config" />
|
||||||
<Compile Include="CodeWriter.PlatformClass.cs" />
|
<Compile Include="CodeWriter\PlatformClass.cs" />
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
<None Include="steam_api.json" />
|
<None Include="steam_api.json" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
Loading…
Reference in New Issue
Block a user