mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-25 06:05:46 +03:00
Struct member name clean
This commit is contained in:
parent
42ccf1b050
commit
0b02bf2331
@ -6,7 +6,7 @@
|
||||
|
||||
namespace Facepunch.Steamworks.Callbacks.User
|
||||
{
|
||||
[StructLayout( LayoutKind.Sequential, Pack = 1 )]
|
||||
[StructLayout( LayoutKind.Sequential, Pack = 4 )]
|
||||
internal struct ValidateAuthTicketResponse
|
||||
{
|
||||
public ulong SteamID;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -25,8 +25,13 @@ void PlatformInterface()
|
||||
EndBlock();
|
||||
}
|
||||
|
||||
private void PlatformClass( string type, string libraryName )
|
||||
|
||||
bool LargePack;
|
||||
|
||||
private void PlatformClass( string type, string libraryName, bool LargePack )
|
||||
{
|
||||
this.LargePack = LargePack;
|
||||
|
||||
StartBlock( $"internal static partial class Platform" );
|
||||
StartBlock( $"public class {type} : Interface" );
|
||||
|
||||
@ -114,7 +119,7 @@ private void PlatformInterfaceMethod( string classname, SteamApiDefinition.Metho
|
||||
if ( classname == "SteamApi" )
|
||||
flatName = methodName;
|
||||
|
||||
var argstring = string.Join( ", ", arguments.Select( x => x.InteropParameter() ) );
|
||||
var argstring = string.Join( ", ", arguments.Select( x => x.InteropParameter( true ) ) );
|
||||
if ( argstring != "" ) argstring = $" {argstring} ";
|
||||
|
||||
WriteLine( $"{ret.Return()} {classname}_{methodName}({argstring});" );
|
||||
@ -143,8 +148,7 @@ private void PlatformClassMethod( string classname, SteamApiDefinition.MethodDef
|
||||
if ( classname == "SteamApi" )
|
||||
flatName = methodName;
|
||||
|
||||
|
||||
var argstring = string.Join( ", ", arguments.Select( x => x.InteropParameter() ) );
|
||||
var argstring = string.Join( ", ", arguments.Select( x => x.InteropParameter( true ) ) );
|
||||
if ( argstring != "" ) argstring = $" {argstring} ";
|
||||
|
||||
StartBlock( $"public virtual {ret.Return()} {classname}_{methodName}({argstring})" );
|
||||
@ -155,10 +159,27 @@ private void PlatformClassMethod( string classname, SteamApiDefinition.MethodDef
|
||||
WriteLine();
|
||||
}
|
||||
|
||||
var retcode = "";
|
||||
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() ) );
|
||||
|
||||
if ( methodDef.NeedsSelfPointer )
|
||||
@ -166,8 +187,17 @@ private void PlatformClassMethod( string classname, SteamApiDefinition.MethodDef
|
||||
|
||||
WriteLine( $"{retcode}Native.{classname}.{methodName}({argstring});" );
|
||||
|
||||
WriteLines( AfterLines );
|
||||
|
||||
if ( retcode.StartsWith( "var" ) )
|
||||
{
|
||||
WriteLine( "return ret;" );
|
||||
}
|
||||
|
||||
EndBlock();
|
||||
|
||||
|
||||
|
||||
LastMethodName = methodDef.Name;
|
||||
}
|
||||
|
||||
@ -194,7 +224,7 @@ private void InteropClassMethod( string library, string classname, SteamApiDefin
|
||||
flatName = methodName;
|
||||
|
||||
|
||||
var argstring = string.Join( ", ", arguments.Select( x => x.InteropParameter() ) );
|
||||
var argstring = string.Join( ", ", arguments.Select( x => x.InteropParameter( LargePack ) ) );
|
||||
|
||||
if ( methodDef.NeedsSelfPointer )
|
||||
{
|
||||
|
@ -15,7 +15,8 @@ void Structs()
|
||||
if ( c.Name == "CSteamID" ||
|
||||
c.Name == "CSteamAPIContext" ||
|
||||
c.Name == "CCallResult" ||
|
||||
c.Name == "CCallback" )
|
||||
c.Name == "CCallback" ||
|
||||
c.Name == "ValvePackingSentinel_t" )
|
||||
continue;
|
||||
|
||||
if ( c.Name.Contains( "::" ) )
|
||||
@ -43,11 +44,15 @@ void Structs()
|
||||
StructFields( c.Fields );
|
||||
|
||||
WriteLine();
|
||||
StartBlock( $"public static implicit operator {c.Name} ( {c.Name}.PackSmall d )" );
|
||||
|
||||
//
|
||||
// Implicit convert from PackSmall to regular
|
||||
//
|
||||
StartBlock( $"public static implicit operator {c.Name} ( {c.Name}.PackSmall d )" );
|
||||
StartBlock( $"return new {c.Name}()" );
|
||||
foreach ( var f in c.Fields )
|
||||
{
|
||||
WriteLine( $"{f.Name} = d.{f.Name}," );
|
||||
WriteLine( $"{CleanMemberName( f.Name )} = d.{CleanMemberName( f.Name )}," );
|
||||
}
|
||||
EndBlock( ";" );
|
||||
EndBlock();
|
||||
@ -111,13 +116,37 @@ private void StructFields( SteamApiDefinition.StructDef.StructFields[] fields )
|
||||
WriteLine( $"[MarshalAs(UnmanagedType.ByValArray, SizeConst = {num}, ArraySubType = UnmanagedType.R4)]" );
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ( t == "const char **" )
|
||||
{
|
||||
t = "IntPtr";
|
||||
}
|
||||
|
||||
WriteLine( $"public {t} {m.Name}; // {m.Type}" );
|
||||
WriteLine( $"public {t} {CleanMemberName( m.Name )}; // {m.Name} {m.Type}" );
|
||||
}
|
||||
}
|
||||
|
||||
string CleanMemberName( string m )
|
||||
{
|
||||
if ( m == "m_pubParam" ) return "ParamPtr";
|
||||
if ( m == "m_cubParam" ) return "ParamCount";
|
||||
|
||||
var cleanName = m.Replace( "m_un", "" )
|
||||
.Replace( "m_us", "" )
|
||||
.Replace( "m_sz", "" )
|
||||
.Replace( "m_h", "" )
|
||||
.Replace( "m_e", "" )
|
||||
.Replace( "m_un", "" )
|
||||
.Replace( "m_ul", "" )
|
||||
.Replace( "m_u", "" )
|
||||
.Replace( "m_b", "" )
|
||||
.Replace( "m_i", "" )
|
||||
.Replace( "m_pub", "" )
|
||||
.Replace( "m_cub", "" )
|
||||
.Replace( "m_", "" );
|
||||
|
||||
return cleanName.Substring( 0, 1 ).ToUpper() + cleanName.Substring( 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user