summaryrefslogtreecommitdiff
path: root/Assembly_Firstpass/Steamworks/MMKVPMarshaller.cs
blob: 7e731966e8e09636239f6ab38d61624709847f37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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;
	}
}