Fix MarketBoardItemRequest & Universalis upload (#1888)

This commit is contained in:
Infi 2024-07-03 18:36:18 +02:00 committed by GitHub
parent b546dd0f96
commit a4c234c4fa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 27 additions and 49 deletions

View file

@ -14,13 +14,9 @@ internal class MarketBoardItemRequest
{
}
/// <summary>
/// Gets the catalog ID.
/// </summary>
public uint CatalogId { get; private set; }
/// <summary>
/// Gets the request status. Nonzero statuses are errors.
/// Known values: default=0; rate limited=0x70000003
/// </summary>
public uint Status { get; private set; }
@ -32,44 +28,33 @@ internal class MarketBoardItemRequest
/// <summary>
/// Gets the amount to arrive.
/// </summary>
public byte AmountToArrive { get; private set; }
public uint AmountToArrive { get; private set; }
/// <summary>
/// Gets the offered item listings.
/// </summary>
public List<MarketBoardCurrentOfferings.MarketBoardItemListing> Listings { get; } = new();
public List<MarketBoardCurrentOfferings.MarketBoardItemListing> Listings { get; } = [];
/// <summary>
/// Gets the historical item listings.
/// </summary>
public List<MarketBoardHistory.MarketBoardHistoryListing> History { get; } = new();
/// <summary>
/// Gets or sets the listing request ID.
/// </summary>
public int ListingsRequestId { get; set; } = -1;
/// <summary>
/// Gets a value indicating whether the upload is complete.
/// </summary>
public bool IsDone => this.Listings.Count == this.AmountToArrive && this.History.Count != 0;
public List<MarketBoardHistory.MarketBoardHistoryListing> History { get; } = [];
/// <summary>
/// Read a packet off the wire.
/// </summary>
/// <param name="dataPtr">Packet data.</param>
/// <returns>An object representing the data read.</returns>
public static unsafe MarketBoardItemRequest Read(IntPtr dataPtr)
public static unsafe MarketBoardItemRequest Read(nint dataPtr)
{
using var stream = new UnmanagedMemoryStream((byte*)dataPtr.ToPointer(), 1544);
using var reader = new BinaryReader(stream);
var output = new MarketBoardItemRequest();
output.CatalogId = reader.ReadUInt32();
output.Status = reader.ReadUInt32();
stream.Position += 0x3;
output.AmountToArrive = reader.ReadByte();
var output = new MarketBoardItemRequest
{
Status = reader.ReadUInt32(),
AmountToArrive = reader.ReadUInt32(),
};
return output;
}

View file

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
@ -47,9 +48,9 @@ internal class UniversalisMarketBoardUploader : IMarketBoardUploader
{
WorldId = clientState.LocalPlayer?.CurrentWorld.Id ?? 0,
UploaderId = uploader.ToString(),
ItemId = request.CatalogId,
Listings = new List<UniversalisItemListingsEntry>(),
Sales = new List<UniversalisHistoryEntry>(),
ItemId = request.Listings.FirstOrDefault()?.CatalogId ?? 0,
Listings = [],
Sales = [],
};
foreach (var marketBoardItemListing in request.Listings)
@ -105,7 +106,7 @@ internal class UniversalisMarketBoardUploader : IMarketBoardUploader
// ====================================================================================
Log.Verbose("Universalis data upload for item#{CatalogId} completed", request.CatalogId);
Log.Verbose("Universalis data upload for item#{CatalogId} completed", request.Listings.FirstOrDefault()?.CatalogId ?? 0);
}
/// <inheritdoc/>

View file

@ -315,7 +315,7 @@ internal unsafe class NetworkHandlers : IInternalDisposableService
}
catch (Exception ex)
{
Log.Error(ex, "CfPopDetour threw an exception");
Log.Error(ex, "CfPopDetour threw an exception");
}
return result;
@ -350,7 +350,7 @@ internal unsafe class NetworkHandlers : IInternalDisposableService
}
return offeringsObservable
.Where(offerings => offerings.InternalItemListings.All(l => l.CatalogId == request.CatalogId))
.Where(offerings => offerings.InternalItemListings.All(l => l.CatalogId != 0))
.Skip(totalPackets - 1)
.Do(LogEndObserved);
}
@ -387,7 +387,7 @@ internal unsafe class NetworkHandlers : IInternalDisposableService
IObservable<MarketBoardHistory> UntilBatchEnd(MarketBoardItemRequest request)
{
return historyObservable
.Where(history => history.CatalogId == request.CatalogId)
.Where(history => history.CatalogId != 0)
.Take(1);
}
@ -411,10 +411,7 @@ internal unsafe class NetworkHandlers : IInternalDisposableService
{
void LogStartObserved(MarketBoardItemRequest request)
{
Log.Verbose(
"Observed start of request for item#{CatalogId} with {NumListings} expected listings",
request.CatalogId,
request.AmountToArrive);
Log.Verbose("Observed start of request for item with {NumListings} expected listings", request.AmountToArrive);
}
var startObservable = this.MbItemRequestObservable
@ -442,23 +439,18 @@ internal unsafe class NetworkHandlers : IInternalDisposableService
ICollection<MarketBoardHistory.MarketBoardHistoryListing> sales,
ICollection<MarketBoardCurrentOfferings.MarketBoardItemListing> listings)
{
var catalogId = listings.FirstOrDefault()?.CatalogId ?? 0;
if (listings.Count != request.AmountToArrive)
{
Log.Error(
"Wrong number of Market Board listings received for request: {ListingsCount} != {RequestAmountToArrive} item#{RequestCatalogId}",
listings.Count, request.AmountToArrive, request.CatalogId);
return;
}
if (listings.Any(listing => listing.CatalogId != request.CatalogId))
{
Log.Error("Received listings with mismatched item IDs for item#{RequestCatalogId}", request.CatalogId);
listings.Count, request.AmountToArrive, catalogId);
return;
}
Log.Verbose(
"Market Board request resolved, starting upload: item#{CatalogId} listings#{ListingsObserved} sales#{SalesObserved}",
request.CatalogId,
catalogId,
listings.Count,
sales.Count);
@ -545,7 +537,7 @@ internal unsafe class NetworkHandlers : IInternalDisposableService
{
Log.Error(ex, "MarketPurchasePacketHandler threw an exception");
}
return this.mbPurchaseHook.OriginalDisposeSafe(a1, packetData);
}
@ -559,7 +551,7 @@ internal unsafe class NetworkHandlers : IInternalDisposableService
{
Log.Error(ex, "MarketHistoryPacketDetour threw an exception");
}
return this.mbHistoryHook.OriginalDisposeSafe(a1, packetData, a3, a4);
}
@ -589,7 +581,7 @@ internal unsafe class NetworkHandlers : IInternalDisposableService
{
Log.Error(ex, "MarketItemRequestStartDetour threw an exception");
}
return this.mbItemRequestStartHook.OriginalDisposeSafe(a1, packetRef);
}
@ -603,7 +595,7 @@ internal unsafe class NetworkHandlers : IInternalDisposableService
{
Log.Error(ex, "MarketBoardOfferingsDetour threw an exception");
}
return this.mbOfferingsHook.OriginalDisposeSafe(a1, packetRef);
}
@ -617,7 +609,7 @@ internal unsafe class NetworkHandlers : IInternalDisposableService
{
Log.Error(ex, "MarketBoardSendPurchaseRequestDetour threw an exception");
}
return this.mbSendPurchaseRequestHook.OriginalDisposeSafe(infoProxyItemSearch);
}
}