Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CodeGen/src/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,8 +718,8 @@ def parse_func(f, interface, func):
argnames += ")"
elif func.returntype == "gameserveritem_t *":
wrapperreturntype = "gameserveritem_t"
strReturnable += "(gameserveritem_t)Marshal.PtrToStructure("
argnames += "), typeof(gameserveritem_t)"
strReturnable += "Marshal.PtrToStructure<gameserveritem_t>("
argnames += "))"
elif func.returntype == "CSteamID":
wrapperreturntype = "CSteamID"
strReturnable += "(CSteamID)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static void Release(IntPtr pointer) {
/// Convert an IntPtr received from ISteamNetworkingSockets.ReceiveMessagesOnPollGroup into our structure.
/// This is a Steamworks.NET extension.
public static SteamNetworkingMessage_t FromIntPtr(IntPtr pointer) {
return (SteamNetworkingMessage_t)Marshal.PtrToStructure(pointer, typeof(SteamNetworkingMessage_t));
return Marshal.PtrToStructure<SteamNetworkingMessage_t>(pointer);
}
}
}
Expand Down
30 changes: 17 additions & 13 deletions com.rlabrecque.steamworks.net/Runtime/CallbackDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ internal static void Initialize() {
lock (m_sync) {
if (m_initCount == 0) {
NativeMethods.SteamAPI_ManualDispatch_Init();
m_pCallbackMsg = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(CallbackMsg_t)));
m_pCallbackMsg = Marshal.AllocHGlobal(Marshal.SizeOf<CallbackMsg_t>());
}
++m_initCount;
}
Expand Down Expand Up @@ -160,11 +160,11 @@ internal static void RunFrame(bool isGameServer) {
NativeMethods.SteamAPI_ManualDispatch_RunFrame(hSteamPipe);
var callbacksRegistry = isGameServer ? m_registeredGameServerCallbacks : m_registeredCallbacks;
while (NativeMethods.SteamAPI_ManualDispatch_GetNextCallback(hSteamPipe, m_pCallbackMsg)) {
CallbackMsg_t callbackMsg = (CallbackMsg_t)Marshal.PtrToStructure(m_pCallbackMsg, typeof(CallbackMsg_t));
CallbackMsg_t callbackMsg = Marshal.PtrToStructure<CallbackMsg_t>(m_pCallbackMsg);
try {
// Check for dispatching API call results
if (callbackMsg.m_iCallback == SteamAPICallCompleted_t.k_iCallback) {
SteamAPICallCompleted_t callCompletedCb = (SteamAPICallCompleted_t)Marshal.PtrToStructure(callbackMsg.m_pubParam, typeof(SteamAPICallCompleted_t));
SteamAPICallCompleted_t callCompletedCb = Marshal.PtrToStructure<SteamAPICallCompleted_t>(callbackMsg.m_pubParam);
IntPtr pTmpCallResult = Marshal.AllocHGlobal((int)callCompletedCb.m_cubParam);
bool bFailed;
if (NativeMethods.SteamAPI_ManualDispatch_GetAPICallResult(hSteamPipe, callCompletedCb.m_hAsyncCall, pTmpCallResult, (int)callCompletedCb.m_cubParam, callCompletedCb.m_iCallback, out bFailed)) {
Expand All @@ -181,14 +181,12 @@ internal static void RunFrame(bool isGameServer) {
}
Marshal.FreeHGlobal(pTmpCallResult);
} else {
List<Callback> callbacksCopy = null;
lock (m_sync) {
List<Callback> callbacks = null;
if (callbacksRegistry.TryGetValue(callbackMsg.m_iCallback, out callbacks)) {
List<Callback> callbacks;
if (callbacksRegistry.TryGetValue(callbackMsg.m_iCallback, out callbacks)) {
List<Callback> callbacksCopy;
lock (m_sync) {
callbacksCopy = new List<Callback>(callbacks);
}
}
if (callbacksCopy != null) {
foreach (var callback in callbacksCopy) {
callback.OnRunCallback(callbackMsg.m_pubParam);
}
Expand All @@ -210,7 +208,10 @@ public abstract class Callback {
internal abstract void SetUnregistered();
}

public sealed class Callback<T> : Callback, IDisposable {
public sealed class Callback<
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)]
T
> : Callback, IDisposable {
public delegate void DispatchDelegate(T param);
private event DispatchDelegate m_Func;

Expand Down Expand Up @@ -290,7 +291,7 @@ internal override Type GetCallbackType() {

internal override void OnRunCallback(IntPtr pvParam) {
try {
m_Func((T)Marshal.PtrToStructure(pvParam, typeof(T)));
m_Func(Marshal.PtrToStructure<T>(pvParam));
}
catch (Exception e) {
CallbackDispatcher.ExceptionHandler(e);
Expand All @@ -308,7 +309,10 @@ public abstract class CallResult {
internal abstract void SetUnregistered();
}

public sealed class CallResult<T> : CallResult, IDisposable {
public sealed class CallResult<
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)]
T
> : CallResult, IDisposable {
public delegate void APIDispatchDelegate(T param, bool bIOFailure);
private event APIDispatchDelegate m_Func;

Expand Down Expand Up @@ -385,7 +389,7 @@ internal override void OnRunCallResult(IntPtr pvParam, bool bFailed, ulong hStea
SteamAPICall_t hSteamAPICall = (SteamAPICall_t)hSteamAPICall_;
if (hSteamAPICall == m_hAPICall) {
try {
m_Func((T)Marshal.PtrToStructure(pvParam, typeof(T)), bFailed);
m_Func(Marshal.PtrToStructure<T>(pvParam), bFailed);
}
catch (Exception e) {
CallbackDispatcher.ExceptionHandler(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public ISteamMatchmakingServerListResponse(ServerResponded onServerResponded, Se
m_VTServerFailedToRespond = InternalOnServerFailedToRespond,
m_VTRefreshComplete = InternalOnRefreshComplete
};
m_pVTable = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(VTable)));
m_pVTable = Marshal.AllocHGlobal(Marshal.SizeOf<VTable>());
Marshal.StructureToPtr(m_VTable, m_pVTable, false);

m_pGCHandle = GCHandle.Alloc(m_pVTable, GCHandleType.Pinned);
Expand Down Expand Up @@ -204,7 +204,7 @@ public ISteamMatchmakingPingResponse(ServerResponded onServerResponded, ServerFa
m_VTServerResponded = InternalOnServerResponded,
m_VTServerFailedToRespond = InternalOnServerFailedToRespond,
};
m_pVTable = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(VTable)));
m_pVTable = Marshal.AllocHGlobal(Marshal.SizeOf<VTable>());
Marshal.StructureToPtr(m_VTable, m_pVTable, false);

m_pGCHandle = GCHandle.Alloc(m_pVTable, GCHandleType.Pinned);
Expand Down Expand Up @@ -303,7 +303,7 @@ public ISteamMatchmakingPlayersResponse(AddPlayerToList onAddPlayerToList, Playe
m_VTPlayersFailedToRespond = InternalOnPlayersFailedToRespond,
m_VTPlayersRefreshComplete = InternalOnPlayersRefreshComplete
};
m_pVTable = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(VTable)));
m_pVTable = Marshal.AllocHGlobal(Marshal.SizeOf<VTable>());
Marshal.StructureToPtr(m_VTable, m_pVTable, false);

m_pGCHandle = GCHandle.Alloc(m_pVTable, GCHandleType.Pinned);
Expand Down Expand Up @@ -416,7 +416,7 @@ public ISteamMatchmakingRulesResponse(RulesResponded onRulesResponded, RulesFail
m_VTRulesFailedToRespond = InternalOnRulesFailedToRespond,
m_VTRulesRefreshComplete = InternalOnRulesRefreshComplete
};
m_pVTable = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(VTable)));
m_pVTable = Marshal.AllocHGlobal(Marshal.SizeOf<VTable>());
Marshal.StructureToPtr(m_VTable, m_pVTable, false);

m_pGCHandle = GCHandle.Alloc(m_pVTable, GCHandleType.Pinned);
Expand Down
8 changes: 4 additions & 4 deletions com.rlabrecque.steamworks.net/Runtime/InteropHelp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ public SteamParamStringArray(System.Collections.Generic.IList<string> strings) {
Marshal.Copy(strbuf, 0, m_Strings[i], strbuf.Length);
}

m_ptrStrings = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr)) * m_Strings.Length);
m_ptrStrings = Marshal.AllocHGlobal(Marshal.SizeOf<IntPtr>() * m_Strings.Length);
SteamParamStringArray_t stringArray = new SteamParamStringArray_t() {
m_ppStrings = m_ptrStrings,
m_nNumStrings = m_Strings.Length
};
Marshal.Copy(m_Strings, 0, stringArray.m_ppStrings, m_Strings.Length);

m_pSteamParamStringArray = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SteamParamStringArray_t)));
m_pSteamParamStringArray = Marshal.AllocHGlobal(Marshal.SizeOf<SteamParamStringArray_t>());
Marshal.StructureToPtr(stringArray, m_pSteamParamStringArray, false);
}

Expand Down Expand Up @@ -181,9 +181,9 @@ public MMKVPMarshaller(MatchMakingKeyValuePair_t[] filters) {
return;
}

int sizeOfMMKVP = Marshal.SizeOf(typeof(MatchMakingKeyValuePair_t));
int sizeOfMMKVP = Marshal.SizeOf<MatchMakingKeyValuePair_t>();

m_pNativeArray = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr)) * filters.Length);
m_pNativeArray = Marshal.AllocHGlobal(Marshal.SizeOf<IntPtr>() * filters.Length);
m_pArrayEntries = Marshal.AllocHGlobal(sizeOfMMKVP * filters.Length);
for (int i = 0; i < filters.Length; ++i) {
Marshal.StructureToPtr(filters[i], new IntPtr(m_pArrayEntries.ToInt64() + (i * sizeOfMMKVP)), false);
Expand Down
4 changes: 2 additions & 2 deletions com.rlabrecque.steamworks.net/Runtime/Packsize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public static class Packsize {
#endif

public static bool Test() {
int sentinelSize = Marshal.SizeOf(typeof(ValvePackingSentinel_t));
int subscribedFilesSize = Marshal.SizeOf(typeof(RemoteStorageEnumerateUserSubscribedFilesResult_t));
int sentinelSize = Marshal.SizeOf<ValvePackingSentinel_t>();
int subscribedFilesSize = Marshal.SizeOf<RemoteStorageEnumerateUserSubscribedFilesResult_t>();
#if VALVE_CALLBACK_PACK_LARGE
if (sentinelSize != 32 || subscribedFilesSize != (1 + 1 + 1 + 50 + 100) * 4 + 4)
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ public static void ReleaseRequest(HServerListRequest hServerListRequest) {
/// </summary>
public static gameserveritem_t GetServerDetails(HServerListRequest hRequest, int iServer) {
InteropHelp.TestIfAvailableClient();
return (gameserveritem_t)Marshal.PtrToStructure(NativeMethods.ISteamMatchmakingServers_GetServerDetails(CSteamAPIContext.GetSteamMatchmakingServers(), hRequest, iServer), typeof(gameserveritem_t));
return Marshal.PtrToStructure<gameserveritem_t>(NativeMethods.ISteamMatchmakingServers_GetServerDetails(CSteamAPIContext.GetSteamMatchmakingServers(), hRequest, iServer));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static void Release(IntPtr pointer) {
/// Convert an IntPtr received from ISteamNetworkingSockets.ReceiveMessagesOnPollGroup into our structure.
/// This is a Steamworks.NET extension.
public static SteamNetworkingMessage_t FromIntPtr(IntPtr pointer) {
return (SteamNetworkingMessage_t)Marshal.PtrToStructure(pointer, typeof(SteamNetworkingMessage_t));
return Marshal.PtrToStructure<SteamNetworkingMessage_t>(pointer);
}
}
}
Expand Down