summaryrefslogtreecommitdiff
path: root/Assembly_Firstpass/Steamworks/CSteamGameServerAPIContext.cs
blob: 7d08aad9cebe48379880b3e72fd16f01045a3335 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
using System;

namespace Steamworks;

internal static class CSteamGameServerAPIContext
{
	private static IntPtr m_pSteamClient;

	private static IntPtr m_pSteamGameServer;

	private static IntPtr m_pSteamUtils;

	private static IntPtr m_pSteamNetworking;

	private static IntPtr m_pSteamGameServerStats;

	private static IntPtr m_pSteamHTTP;

	private static IntPtr m_pSteamInventory;

	private static IntPtr m_pSteamUGC;

	private static IntPtr m_pSteamApps;

	private static IntPtr m_pSteamNetworkingUtils;

	private static IntPtr m_pSteamNetworkingSockets;

	private static IntPtr m_pSteamNetworkingMessages;

	internal static void Clear()
	{
		m_pSteamClient = IntPtr.Zero;
		m_pSteamGameServer = IntPtr.Zero;
		m_pSteamUtils = IntPtr.Zero;
		m_pSteamNetworking = IntPtr.Zero;
		m_pSteamGameServerStats = IntPtr.Zero;
		m_pSteamHTTP = IntPtr.Zero;
		m_pSteamInventory = IntPtr.Zero;
		m_pSteamUGC = IntPtr.Zero;
		m_pSteamApps = IntPtr.Zero;
		m_pSteamNetworkingUtils = IntPtr.Zero;
		m_pSteamNetworkingSockets = IntPtr.Zero;
		m_pSteamNetworkingMessages = IntPtr.Zero;
	}

	internal static bool Init()
	{
		HSteamUser hSteamUser = GameServer.GetHSteamUser();
		HSteamPipe hSteamPipe = GameServer.GetHSteamPipe();
		if (hSteamPipe == (HSteamPipe)0)
		{
			return false;
		}
		using (InteropHelp.UTF8StringHandle ver = new InteropHelp.UTF8StringHandle("SteamClient020"))
		{
			m_pSteamClient = NativeMethods.SteamInternal_CreateInterface(ver);
		}
		if (m_pSteamClient == IntPtr.Zero)
		{
			return false;
		}
		m_pSteamGameServer = SteamGameServerClient.GetISteamGameServer(hSteamUser, hSteamPipe, "SteamGameServer013");
		if (m_pSteamGameServer == IntPtr.Zero)
		{
			return false;
		}
		m_pSteamUtils = SteamGameServerClient.GetISteamUtils(hSteamPipe, "SteamUtils010");
		if (m_pSteamUtils == IntPtr.Zero)
		{
			return false;
		}
		m_pSteamNetworking = SteamGameServerClient.GetISteamNetworking(hSteamUser, hSteamPipe, "SteamNetworking006");
		if (m_pSteamNetworking == IntPtr.Zero)
		{
			return false;
		}
		m_pSteamGameServerStats = SteamGameServerClient.GetISteamGameServerStats(hSteamUser, hSteamPipe, "SteamGameServerStats001");
		if (m_pSteamGameServerStats == IntPtr.Zero)
		{
			return false;
		}
		m_pSteamHTTP = SteamGameServerClient.GetISteamHTTP(hSteamUser, hSteamPipe, "STEAMHTTP_INTERFACE_VERSION003");
		if (m_pSteamHTTP == IntPtr.Zero)
		{
			return false;
		}
		m_pSteamInventory = SteamGameServerClient.GetISteamInventory(hSteamUser, hSteamPipe, "STEAMINVENTORY_INTERFACE_V003");
		if (m_pSteamInventory == IntPtr.Zero)
		{
			return false;
		}
		m_pSteamUGC = SteamGameServerClient.GetISteamUGC(hSteamUser, hSteamPipe, "STEAMUGC_INTERFACE_VERSION015");
		if (m_pSteamUGC == IntPtr.Zero)
		{
			return false;
		}
		m_pSteamApps = SteamGameServerClient.GetISteamApps(hSteamUser, hSteamPipe, "STEAMAPPS_INTERFACE_VERSION008");
		if (m_pSteamApps == IntPtr.Zero)
		{
			return false;
		}
		using (InteropHelp.UTF8StringHandle pszVersion = new InteropHelp.UTF8StringHandle("SteamNetworkingUtils003"))
		{
			m_pSteamNetworkingUtils = ((NativeMethods.SteamInternal_FindOrCreateUserInterface(hSteamUser, pszVersion) != IntPtr.Zero) ? NativeMethods.SteamInternal_FindOrCreateUserInterface(hSteamUser, pszVersion) : NativeMethods.SteamInternal_FindOrCreateGameServerInterface(hSteamUser, pszVersion));
		}
		if (m_pSteamNetworkingUtils == IntPtr.Zero)
		{
			return false;
		}
		using (InteropHelp.UTF8StringHandle pszVersion2 = new InteropHelp.UTF8StringHandle("SteamNetworkingSockets009"))
		{
			m_pSteamNetworkingSockets = NativeMethods.SteamInternal_FindOrCreateGameServerInterface(hSteamUser, pszVersion2);
		}
		if (m_pSteamNetworkingSockets == IntPtr.Zero)
		{
			return false;
		}
		using (InteropHelp.UTF8StringHandle pszVersion3 = new InteropHelp.UTF8StringHandle("SteamNetworkingMessages002"))
		{
			m_pSteamNetworkingMessages = NativeMethods.SteamInternal_FindOrCreateGameServerInterface(hSteamUser, pszVersion3);
		}
		if (m_pSteamNetworkingMessages == IntPtr.Zero)
		{
			return false;
		}
		return true;
	}

	internal static IntPtr GetSteamClient()
	{
		return m_pSteamClient;
	}

	internal static IntPtr GetSteamGameServer()
	{
		return m_pSteamGameServer;
	}

	internal static IntPtr GetSteamUtils()
	{
		return m_pSteamUtils;
	}

	internal static IntPtr GetSteamNetworking()
	{
		return m_pSteamNetworking;
	}

	internal static IntPtr GetSteamGameServerStats()
	{
		return m_pSteamGameServerStats;
	}

	internal static IntPtr GetSteamHTTP()
	{
		return m_pSteamHTTP;
	}

	internal static IntPtr GetSteamInventory()
	{
		return m_pSteamInventory;
	}

	internal static IntPtr GetSteamUGC()
	{
		return m_pSteamUGC;
	}

	internal static IntPtr GetSteamApps()
	{
		return m_pSteamApps;
	}

	internal static IntPtr GetSteamNetworkingUtils()
	{
		return m_pSteamNetworkingUtils;
	}

	internal static IntPtr GetSteamNetworkingSockets()
	{
		return m_pSteamNetworkingSockets;
	}

	internal static IntPtr GetSteamNetworkingMessages()
	{
		return m_pSteamNetworkingMessages;
	}
}