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> /// <summary>
/// Gets the request status. Nonzero statuses are errors. /// Gets the request status. Nonzero statuses are errors.
/// Known values: default=0; rate limited=0x70000003
/// </summary> /// </summary>
public uint Status { get; private set; } public uint Status { get; private set; }
@ -32,44 +28,33 @@ internal class MarketBoardItemRequest
/// <summary> /// <summary>
/// Gets the amount to arrive. /// Gets the amount to arrive.
/// </summary> /// </summary>
public byte AmountToArrive { get; private set; } public uint AmountToArrive { get; private set; }
/// <summary> /// <summary>
/// Gets the offered item listings. /// Gets the offered item listings.
/// </summary> /// </summary>
public List<MarketBoardCurrentOfferings.MarketBoardItemListing> Listings { get; } = new(); public List<MarketBoardCurrentOfferings.MarketBoardItemListing> Listings { get; } = [];
/// <summary> /// <summary>
/// Gets the historical item listings. /// Gets the historical item listings.
/// </summary> /// </summary>
public List<MarketBoardHistory.MarketBoardHistoryListing> History { get; } = new(); public List<MarketBoardHistory.MarketBoardHistoryListing> History { get; } = [];
/// <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;
/// <summary> /// <summary>
/// Read a packet off the wire. /// Read a packet off the wire.
/// </summary> /// </summary>
/// <param name="dataPtr">Packet data.</param> /// <param name="dataPtr">Packet data.</param>
/// <returns>An object representing the data read.</returns> /// <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 stream = new UnmanagedMemoryStream((byte*)dataPtr.ToPointer(), 1544);
using var reader = new BinaryReader(stream); using var reader = new BinaryReader(stream);
var output = new MarketBoardItemRequest(); var output = new MarketBoardItemRequest
{
output.CatalogId = reader.ReadUInt32(); Status = reader.ReadUInt32(),
output.Status = reader.ReadUInt32(); AmountToArrive = reader.ReadUInt32(),
stream.Position += 0x3; };
output.AmountToArrive = reader.ReadByte();
return output; return output;
} }

View file

@ -1,4 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -47,9 +48,9 @@ internal class UniversalisMarketBoardUploader : IMarketBoardUploader
{ {
WorldId = clientState.LocalPlayer?.CurrentWorld.Id ?? 0, WorldId = clientState.LocalPlayer?.CurrentWorld.Id ?? 0,
UploaderId = uploader.ToString(), UploaderId = uploader.ToString(),
ItemId = request.CatalogId, ItemId = request.Listings.FirstOrDefault()?.CatalogId ?? 0,
Listings = new List<UniversalisItemListingsEntry>(), Listings = [],
Sales = new List<UniversalisHistoryEntry>(), Sales = [],
}; };
foreach (var marketBoardItemListing in request.Listings) 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/> /// <inheritdoc/>

View file

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