From 77f3e09e98b896bc1682a298b6783f366f668a4a Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Wed, 19 Jun 2019 13:04:18 +0100 Subject: [PATCH] Convert steam struct bools to bytes (to make them marshallable) --- Facepunch.Steamworks/Generated/SteamStructs.cs | 18 ++++++------------ Generator/CodeParser/CodeParser.cs | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/Facepunch.Steamworks/Generated/SteamStructs.cs b/Facepunch.Steamworks/Generated/SteamStructs.cs index 8c5ed9f..bafdfbc 100644 --- a/Facepunch.Steamworks/Generated/SteamStructs.cs +++ b/Facepunch.Steamworks/Generated/SteamStructs.cs @@ -12514,8 +12514,7 @@ namespace Steamworks.Data internal InputSourceMode EMode; // eMode EInputSourceMode internal float X; // x float internal float Y; // y float - [MarshalAs(UnmanagedType.I1)] - internal bool BActive; // bActive bool + internal byte BActive; // bActive byte #region Marshalling internal static InputAnalogActionData_t Fill( IntPtr p ) => Config.PackSmall ? ((InputAnalogActionData_t)(InputAnalogActionData_t) Marshal.PtrToStructure( p, typeof(InputAnalogActionData_t) )) : ((InputAnalogActionData_t)(Pack8) Marshal.PtrToStructure( p, typeof(Pack8) )); @@ -12528,8 +12527,7 @@ namespace Steamworks.Data internal InputSourceMode EMode; // eMode EInputSourceMode internal float X; // x float internal float Y; // y float - [MarshalAs(UnmanagedType.I1)] - internal bool BActive; // bActive bool + internal byte BActive; // bActive byte public static implicit operator InputAnalogActionData_t ( InputAnalogActionData_t.Pack8 d ) => new InputAnalogActionData_t{ EMode = d.EMode,X = d.X,Y = d.Y,BActive = d.BActive, }; public static implicit operator InputAnalogActionData_t.Pack8 ( InputAnalogActionData_t d ) => new InputAnalogActionData_t.Pack8{ EMode = d.EMode,X = d.X,Y = d.Y,BActive = d.BActive, }; @@ -12579,10 +12577,8 @@ namespace Steamworks.Data [StructLayout( LayoutKind.Sequential, Pack = 4 )] internal struct InputDigitalActionData_t { - [MarshalAs(UnmanagedType.I1)] - internal bool BState; // bState bool - [MarshalAs(UnmanagedType.I1)] - internal bool BActive; // bActive bool + internal byte BState; // bState byte + internal byte BActive; // bActive byte #region Marshalling internal static InputDigitalActionData_t Fill( IntPtr p ) => Config.PackSmall ? ((InputDigitalActionData_t)(InputDigitalActionData_t) Marshal.PtrToStructure( p, typeof(InputDigitalActionData_t) )) : ((InputDigitalActionData_t)(Pack8) Marshal.PtrToStructure( p, typeof(Pack8) )); @@ -12592,10 +12588,8 @@ namespace Steamworks.Data [StructLayout( LayoutKind.Sequential, Pack = 8 )] public struct Pack8 { - [MarshalAs(UnmanagedType.I1)] - internal bool BState; // bState bool - [MarshalAs(UnmanagedType.I1)] - internal bool BActive; // bActive bool + internal byte BState; // bState byte + internal byte BActive; // bActive byte public static implicit operator InputDigitalActionData_t ( InputDigitalActionData_t.Pack8 d ) => new InputDigitalActionData_t{ BState = d.BState,BActive = d.BActive, }; public static implicit operator InputDigitalActionData_t.Pack8 ( InputDigitalActionData_t d ) => new InputDigitalActionData_t.Pack8{ BState = d.BState,BActive = d.BActive, }; diff --git a/Generator/CodeParser/CodeParser.cs b/Generator/CodeParser/CodeParser.cs index 1622fe5..7c03b15 100644 --- a/Generator/CodeParser/CodeParser.cs +++ b/Generator/CodeParser/CodeParser.cs @@ -155,6 +155,20 @@ namespace Generator //Console.ReadKey(); } - } + // + // Change all struct bool fields to bytes (they're technically bytes anyway, and it helps with marshalling) + // + { + foreach ( var s in def.structs ) + { + foreach ( var f in s.Fields ) + { + if ( f.Type == "bool" ) + f.Type = "byte"; + } + } + } + + } } }