Facepunch.Steamworks/Generator/CodeWriter/Constants.cs

42 lines
1.3 KiB
C#
Raw Normal View History

2016-10-29 22:28:16 +03:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Generator
{
public partial class CodeWriter
{
2016-10-29 23:05:48 +03:00
private void Constants()
2016-10-29 22:28:16 +03:00
{
2016-11-02 23:22:11 +03:00
StartBlock( "internal static class Defines" );
2020-02-13 14:26:55 +03:00
foreach ( var o in def.Consts )
2016-10-29 23:05:48 +03:00
{
2020-02-19 12:00:35 +03:00
var type = o.Type;
2020-02-13 14:26:55 +03:00
type = Cleanup.ConvertType( type );
var val = o.Val;
// Don't need to ull in c#
if ( val.EndsWith( "ull" ) )
val = val.Replace( "ull", "" );
val = val.Replace( "uint32", "uint" );
val = val.Replace( "16U", "16" );
val = val.Replace( "8U", "8" );
// we're not an actual typedef so can't cast like this
val = val.Replace( "( SteamItemInstanceID_t ) ~ 0", "~default(ulong)" );
// This is defined as 0xffffffff - which is too big for an int
// It seems like the loop around is required, so we just hard code it
if ( o.Name == "HSERVERQUERY_INVALID" && val == "0xffffffff" )
val = "-1";
WriteLine( $"internal static readonly {type} {o.Name} = {val};" );
2016-10-29 22:28:16 +03:00
}
2016-10-29 23:05:48 +03:00
EndBlock();
2016-10-29 22:28:16 +03:00
}
}
2016-10-29 23:05:48 +03:00
}