//----------------------------------------------------------------------------------------------------------------------------------------------------------//
        //	Steam API setup & shutdown
        //
        //	These functions manage loading, initializing and shutdown of the steamclient.dll
        //
        //----------------------------------------------------------------------------------------------------------------------------------------------------------//


        // SteamAPI_Init must be called before using any other API functions. If it fails, an
        // error message will be output to the debugger (or stderr) with further information.
        public static bool Init()
        {
            InteropHelp.TestIfPlatformSupported();

            bool ret = NativeMethods.SteamAPI_Init();

            // Steamworks.NET specific: We initialize the SteamAPI Context like this for now, but we need to do it
            // every time that Unity reloads binaries, so we also check if the pointers are available and initialized
            // before each call to any interface functions. That is in InteropHelp.cs
            if (ret)
            {
                ret = CSteamAPIContext.Init();
            }

            if (ret)
            {
                CallbackDispatcher.Initialize();
            }

            return(ret);
        }
        private void OnRunCallResult(
#if !STDCALL
            IntPtr thisptr,
#endif
            IntPtr pvParam, bool bFailed, ulong hSteamAPICall_)
        {
            SteamAPICall_t hSteamAPICall = (SteamAPICall_t)hSteamAPICall_;

            if (hSteamAPICall == m_hAPICall)
            {
                m_hAPICall = SteamAPICall_t.Invalid; // Caller unregisters for us

                try
                {
                    m_Func((T)Marshal.PtrToStructure(pvParam, typeof(T)), bFailed);
                }
                catch (Exception e)
                {
                    CallbackDispatcher.ExceptionHandler(e);
                }
            }
        }
        private void OnRunCallResult(
#if !NOTHISPTR
            IntPtr thisptr,
#endif
            IntPtr pvParam, bool bFailed, ulong hSteamAPICall)
        {
            SteamAPICall_t hAPICall = (SteamAPICall_t)hSteamAPICall;

            if (hAPICall == m_hAPICall)
            {
                try {
                    m_Func((T)Marshal.PtrToStructure(pvParam, typeof(T)), bFailed);
                }
                catch (Exception e) {
                    CallbackDispatcher.ExceptionHandler(e);
                }

                if (hAPICall == m_hAPICall)                   // Ensure that m_hAPICall has not been changed in m_Func
                {
                    m_hAPICall = SteamAPICall_t.Invalid;      // Caller unregisters for us
                }
            }
        }
Exemple #4
0
        public void Set(SteamAPICall_t hAPICall, APIDispatchDelegate newFunc = null)
        {
            if (newFunc != null)
            {
                m_Func = newFunc;
            }

            if (m_Func == null)
            {
                throw new Exception("CallResult function was null, you must either set it in the CallResult Constructor or in Set()");
            }

            if (m_hAPICall != SteamAPICall_t.Invalid)
            {
                Cancel();
            }

            m_hAPICall = hAPICall;

            if (hAPICall != SteamAPICall_t.Invalid)
            {
                CallbackDispatcher.RegisterCallResult(this, hAPICall);
            }
        }
 public static void RunCallbacks()
 {
     CallbackDispatcher.RunFrame(true);
 }
Exemple #6
0
 public void UnRegister()
 {
     CallbackDispatcher.UnRegisterCallback(this, CallbackIdentities.GetCallbackIdentity(typeof(T)));
 }
Exemple #7
0
 //----------------------------------------------------------------------------------------------------------------------------------------------------------//
 //	steam callback helper functions
 //
 //	The following classes/macros are used to be able to easily multiplex callbacks
 //	from the Steam API into various objects in the app in a thread-safe manner
 //
 //	These functors are triggered via the SteamAPI_RunCallbacks() function, mapping the callback
 //  to as many functions/objects as are registered to it
 //----------------------------------------------------------------------------------------------------------------------------------------------------------//
 public static void RunCallbacks()
 {
     InteropHelp.TestIfPlatformSupported();
     CallbackDispatcher.RunCallbacks();
 }
		// SteamAPI_Shutdown should be called during process shutdown if possible.
		public static void Shutdown() {
			InteropHelp.TestIfPlatformSupported();
			NativeMethods.SteamAPI_Shutdown();
			CSteamAPIContext.Clear();
			CallbackDispatcher.Shutdown();
		}