Exemplo n.º 1
0
        internal static void RunFrame(bool isGameServer)
        {
            if (!IsInitialized)
            {
                throw new InvalidOperationException("Callback dispatcher is not initialized.");
            }

            HSteamPipe hSteamPipe = (HSteamPipe)(isGameServer ? NativeMethods.SteamGameServer_GetHSteamPipe() : NativeMethods.SteamAPI_GetHSteamPipe());

            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));
                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));
                        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))
                        {
                            lock (m_sync) {
                                if (m_registeredCallResults.TryGetValue((ulong)callCompletedCb.m_hAsyncCall, out var callResults))
                                {
                                    m_registeredCallResults.Remove((ulong)callCompletedCb.m_hAsyncCall);
                                    foreach (var cr in callResults)
                                    {
                                        cr.OnRunCallResult(pTmpCallResult, bFailed, (ulong)callCompletedCb.m_hAsyncCall);
                                        cr.SetUnregistered();
                                    }
                                }
                            }
                        }
                        Marshal.FreeHGlobal(pTmpCallResult);
                    }
                    else
                    {
                        if (callbacksRegistry.TryGetValue(callbackMsg.m_iCallback, out var callbacks))
                        {
                            List <Callback> callbacksCopy;
                            lock (m_sync) {
                                callbacksCopy = new List <Callback>(callbacks);
                            }
                            foreach (var callback in callbacksCopy)
                            {
                                callback.OnRunCallback(callbackMsg.m_pubParam);
                            }
                        }
                    }
                } catch (Exception e) {
                    ExceptionHandler(e);
                } finally {
                    NativeMethods.SteamAPI_ManualDispatch_FreeLastCallback(hSteamPipe);
                }
            }
        }
Exemplo n.º 2
0
        public static void RunCallResult(SteamAPICallCompleted_t apicall)
        {
            List <ICallResultBase> callResultList;

            if (!m_RegisteredCallResults.TryGetValue(apicall.m_hAsyncCall, out callResultList))
            {
                return;
            }

            if (callResultList.Count == 0)
            {
                // This should never ever happen? Jankyness.
                m_RegisteredCallResults.Remove(apicall.m_hAsyncCall);
                return;
            }

            IntPtr pData = IntPtr.Zero;
            bool   bFailed;

            try {
                ICallResultBase apiCallback = callResultList[0];
                pData = Marshal.AllocHGlobal(apiCallback.GetCallbackSizeBytes());

                if (!NativeMethods.Steam_GetAPICallResult(m_LastActivePipe, apicall.m_hAsyncCall, pData, apiCallback.GetCallbackSizeBytes(), apiCallback.GetICallback(), out bFailed))
                {
                    return;
                }

                foreach (ICallResultBase c in callResultList)
                {
                    c.Run(pData, bFailed);
                }
            }
            finally {
                // Unregister all
                m_RegisteredCallResults.Remove(apicall.m_hAsyncCall);

                Marshal.FreeHGlobal(pData);
            }
        }
Exemplo n.º 3
0
        internal static void RunFrame(bool isGameServer)
        {
            if (!IsInitialized)
            {
                throw new InvalidOperationException("Callback dispatcher is not initialized.");
            }
            HSteamPipe hSteamPipe = (HSteamPipe)(isGameServer ? NativeMethods.SteamGameServer_GetHSteamPipe() : NativeMethods.SteamAPI_GetHSteamPipe());

            NativeMethods.SteamAPI_ManualDispatch_RunFrame(hSteamPipe);
            Dictionary <int, List <Callback> > dictionary = (isGameServer ? m_registeredGameServerCallbacks : m_registeredCallbacks);

            while (NativeMethods.SteamAPI_ManualDispatch_GetNextCallback(hSteamPipe, m_pCallbackMsg))
            {
                CallbackMsg_t callbackMsg_t = (CallbackMsg_t)Marshal.PtrToStructure(m_pCallbackMsg, typeof(CallbackMsg_t));
                try
                {
                    if (callbackMsg_t.m_iCallback == 703)
                    {
                        SteamAPICallCompleted_t steamAPICallCompleted_t = (SteamAPICallCompleted_t)Marshal.PtrToStructure(callbackMsg_t.m_pubParam, typeof(SteamAPICallCompleted_t));
                        IntPtr intPtr = Marshal.AllocHGlobal((int)steamAPICallCompleted_t.m_cubParam);
                        if (NativeMethods.SteamAPI_ManualDispatch_GetAPICallResult(hSteamPipe, steamAPICallCompleted_t.m_hAsyncCall, intPtr, (int)steamAPICallCompleted_t.m_cubParam, steamAPICallCompleted_t.m_iCallback, out var pbFailed))
                        {
                            lock (m_sync)
                            {
                                if (m_registeredCallResults.TryGetValue((ulong)steamAPICallCompleted_t.m_hAsyncCall, out var value))
                                {
                                    m_registeredCallResults.Remove((ulong)steamAPICallCompleted_t.m_hAsyncCall);
                                    foreach (CallResult item in value)
                                    {
                                        item.OnRunCallResult(intPtr, pbFailed, (ulong)steamAPICallCompleted_t.m_hAsyncCall);
                                        item.SetUnregistered();
                                    }
                                }
                            }
                        }
                        Marshal.FreeHGlobal(intPtr);
                    }
                    else
                    {
                        if (!dictionary.TryGetValue(callbackMsg_t.m_iCallback, out var value2))
                        {
                            continue;
                        }
                        List <Callback> list;
                        lock (m_sync)
                        {
                            list = new List <Callback>(value2);
                        }
                        foreach (Callback item2 in list)
                        {
                            item2.OnRunCallback(callbackMsg_t.m_pubParam);
                        }
                        continue;
                    }
                }
                catch (Exception e)
                {
                    ExceptionHandler(e);
                }
                finally
                {
                    NativeMethods.SteamAPI_ManualDispatch_FreeLastCallback(hSteamPipe);
                }
            }
        }