From daa43a9ccc576381f4fed304c5ced51aa3a9e3b0 Mon Sep 17 00:00:00 2001 From: Andrew Zhu Date: Tue, 19 Apr 2022 18:26:51 -0700 Subject: [PATCH] fix: crash when viewing housing info from non-placard --- AutoSweep.csproj | 2 +- Paissa/LotteryObserver.cs | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/AutoSweep.csproj b/AutoSweep.csproj index fafd8da..af551a1 100644 --- a/AutoSweep.csproj +++ b/AutoSweep.csproj @@ -14,7 +14,7 @@ $(appdata)\XIVLauncher\addon\Hooks\dev\ true autoSweep - 1.3.0.0 + 1.3.1.0 diff --git a/Paissa/LotteryObserver.cs b/Paissa/LotteryObserver.cs index b84de47..0627b33 100644 --- a/Paissa/LotteryObserver.cs +++ b/Paissa/LotteryObserver.cs @@ -12,11 +12,11 @@ public unsafe class LotteryObserver { private delegate void HandlePlacardSaleInfoDelegate( void* agentBase, - byte isUnowned, + HousingType housingType, ushort territoryTypeId, byte wardId, byte plotId, - short a6, + short apartmentNumber, IntPtr placardSaleInfoPtr, long a8 ); @@ -36,25 +36,27 @@ public void Dispose() { public void OnPlacardSaleInfo( void* agentBase, - byte isUnowned, + HousingType housingType, ushort territoryTypeId, byte wardId, byte plotId, - short a6, + short apartmentNumber, IntPtr placardSaleInfoPtr, long a8 ) { - PlacardSaleInfoHook!.Original(agentBase, isUnowned, territoryTypeId, wardId, plotId, a6, placardSaleInfoPtr, a8); - + PlacardSaleInfoHook!.Original(agentBase, housingType, territoryTypeId, wardId, plotId, apartmentNumber, placardSaleInfoPtr, a8); + // if the plot is owned, ignore it - if (isUnowned == 0) return; + if (housingType != HousingType.UnownedHouse) return; + if (placardSaleInfoPtr == IntPtr.Zero) return; PlacardSaleInfo saleInfo = PlacardSaleInfo.Read(placardSaleInfoPtr); PluginLog.LogDebug( $"Got PlacardSaleInfo: PurchaseType={saleInfo.PurchaseType}, TenantType={saleInfo.TenantType}, available={saleInfo.AvailabilityType}, until={saleInfo.PhaseEndsAt}, numEntries={saleInfo.EntryCount}"); PluginLog.LogDebug($"unknown1={saleInfo.Unknown1}, unknown2={saleInfo.Unknown2}, unknown3={BitConverter.ToString(saleInfo.Unknown3)}"); - PluginLog.LogDebug($"isUnowned={isUnowned}, territoryTypeId={territoryTypeId}, wardId={wardId}, plotId={plotId}; a6={a6}, a8={a8}"); + PluginLog.LogDebug( + $"housingType={housingType}, territoryTypeId={territoryTypeId}, wardId={wardId}, plotId={plotId}, apartmentNumber={apartmentNumber}, placardSaleInfoPtr={placardSaleInfoPtr}, a8={a8}"); // get information about the world from the clientstate World world = plugin.ClientState.LocalPlayer?.CurrentWorld.GameData; @@ -67,4 +69,11 @@ long a8 plugin.PaissaClient.PostLotteryInfo(world.RowId, territoryTypeId, wardId, plotId, saleInfo); } } + + public enum HousingType : byte { + OwnedHouse = 0, + UnownedHouse = 1, + FreeCompanyApartment = 2, + Apartment = 3 + } }