Ejemplo n.º 1
0
        internal static void Register(Callback.Run func, int size, int callbackId, bool gameserver)
        {
            Event @event = new Event()
            {
                vTablePtr = Event.BuildVTable(func, @event.Allocations)
            };
            Callback callback = new Callback()
            {
                vTablePtr     = @event.vTablePtr,
                CallbackFlags = (byte)((gameserver ? 2 : 0)),
                CallbackId    = callbackId
            };

            @event.PinnedCallback = GCHandle.Alloc(callback, GCHandleType.Pinned);
            SteamClient.RegisterCallback(@event.PinnedCallback.AddrOfPinnedObject(), callback.CallbackId);
            @event.IsAllocated = true;
            if (!gameserver)
            {
                Event.AllClient.Add(@event);
            }
            else
            {
                Event.AllServer.Add(@event);
            }
        }
Ejemplo n.º 2
0
        internal static void Register(Callback.Run func, int size, int callbackId, bool gameserver)
        {
            var r = new Event();

            r.vTablePtr = BuildVTable(func, r.Allocations);

            //
            // Create the callback object
            //
            var cb = new Callback();

            cb.vTablePtr     = r.vTablePtr;
            cb.CallbackFlags = gameserver ? (byte)0x02 : (byte)0;
            cb.CallbackId    = callbackId;

            //
            // Pin the callback, so it doesn't get garbage collected and we can pass the pointer to native
            //
            r.PinnedCallback = GCHandle.Alloc(cb, GCHandleType.Pinned);

            //
            // Register the callback with Steam
            //
            SteamClient.RegisterCallback(r.PinnedCallback.AddrOfPinnedObject(), cb.CallbackId);

            r.IsAllocated = true;

            if (gameserver)
            {
                Event.AllServer.Add(r);
            }
            else
            {
                Event.AllClient.Add(r);
            }
        }