Exemple #1
0
    private void HandleListingEvents(IntPtr data)
    {
        var dataPtr = data + 0x10;

        var packet = Marshal.PtrToStructure <PartyFinderPacket>(dataPtr);

        // rewriting is an expensive operation, so only do it if necessary
        var needToRewrite = false;

        for (var i = 0; i < packet.Listings.Length; i++)
        {
            // these are empty slots that are not shown to the player
            if (packet.Listings[i].IsNull())
            {
                continue;
            }

            var listing = new PartyFinderListing(packet.Listings[i]);
            var args    = new PartyFinderListingEventArgs(packet.BatchNumber);
            this.ReceiveListing?.Invoke(listing, args);

            if (args.Visible)
            {
                continue;
            }

            // hide the listing from the player by setting it to a null listing
            packet.Listings[i] = default;
            needToRewrite      = true;
        }

        if (!needToRewrite)
        {
            return;
        }

        // write our struct into the memory (doing this directly crashes the game)
        Marshal.StructureToPtr(packet, this.memory, false);

        // copy our new memory over the game's
        unsafe
        {
            Buffer.MemoryCopy((void *)this.memory, (void *)dataPtr, PartyFinderPacket.PacketSize, PartyFinderPacket.PacketSize);
        }
    }
 private void PartyFinderOnReceiveListing(PartyFinderListing listing, PartyFinderListingEventArgs args)
 {
     this.hasPassed = true;
 }