diff options
author | chai <215380520@qq.com> | 2023-11-25 18:39:02 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2023-11-25 18:39:02 +0800 |
commit | 0e63c4a2c6dec8dfa260501fb7d73750261ea7b7 (patch) | |
tree | f6f2291be65d195d6082b523a56183c332715240 /Assembly_Firstpass/Steamworks/MMKVPMarshaller.cs |
+ init
Diffstat (limited to 'Assembly_Firstpass/Steamworks/MMKVPMarshaller.cs')
-rw-r--r-- | Assembly_Firstpass/Steamworks/MMKVPMarshaller.cs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/Assembly_Firstpass/Steamworks/MMKVPMarshaller.cs b/Assembly_Firstpass/Steamworks/MMKVPMarshaller.cs new file mode 100644 index 0000000..7e73196 --- /dev/null +++ b/Assembly_Firstpass/Steamworks/MMKVPMarshaller.cs @@ -0,0 +1,43 @@ +using System; +using System.Runtime.InteropServices; + +namespace Steamworks; + +public class MMKVPMarshaller +{ + private IntPtr m_pNativeArray; + + private IntPtr m_pArrayEntries; + + public MMKVPMarshaller(MatchMakingKeyValuePair_t[] filters) + { + if (filters != null) + { + int num = Marshal.SizeOf(typeof(MatchMakingKeyValuePair_t)); + m_pNativeArray = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr)) * filters.Length); + m_pArrayEntries = Marshal.AllocHGlobal(num * filters.Length); + for (int i = 0; i < filters.Length; i++) + { + Marshal.StructureToPtr(filters[i], new IntPtr(m_pArrayEntries.ToInt64() + i * num), fDeleteOld: false); + } + Marshal.WriteIntPtr(m_pNativeArray, m_pArrayEntries); + } + } + + ~MMKVPMarshaller() + { + if (m_pArrayEntries != IntPtr.Zero) + { + Marshal.FreeHGlobal(m_pArrayEntries); + } + if (m_pNativeArray != IntPtr.Zero) + { + Marshal.FreeHGlobal(m_pNativeArray); + } + } + + public static implicit operator IntPtr(MMKVPMarshaller that) + { + return that.m_pNativeArray; + } +} |