Skip to content

Commit 1ee41af

Browse files
Updating ShopEntryHelper class to have optional values that default to the corresponding ShopEntry values
1 parent 971c78d commit 1ee41af

2 files changed

Lines changed: 45 additions & 42 deletions

File tree

OpenKh.Kh2/SystemData/Shop.cs

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -105,51 +105,52 @@ public class ProductEntry
105105

106106
public class ShopEntryHelper
107107
{
108-
public ushort CommandArgument { get; set; }
109-
public ushort UnlockMenuFlag { get; set; }
110-
public ushort NameID { get; set; }
111-
public ushort ShopKeeperEntityID { get; set; }
112-
public short PosX { get; set; }
113-
public short PosY { get; set; }
114-
public short PosZ { get; set; }
115-
public byte ExtraInventoryBitMask { get; set; }
116-
public byte SoundID { get; set; }
117-
public ushort InventoryCount { get; set; }
108+
public ushort? CommandArgument { get; set; }
109+
public ushort? UnlockMenuFlag { get; set; }
110+
public ushort? NameID { get; set; }
111+
public ushort? ShopKeeperEntityID { get; set; }
112+
public short? PosX { get; set; }
113+
public short? PosY { get; set; }
114+
public short? PosZ { get; set; }
115+
public byte? ExtraInventoryBitMask { get; set; }
116+
public byte? SoundID { get; set; }
117+
public ushort? InventoryCount { get; set; }
118118
public byte ShopID { get; set; }
119-
public byte Unk19 { get; set; }
120-
public uint InventoryStartIndex { get; set; }
119+
public byte? Unk19 { get; set; }
120+
public uint? InventoryStartIndex { get; set; }
121121

122122
public ShopEntryHelper() { }
123-
public ShopEntryHelper(ushort commandArgument, ushort unlockMenuFlag, ushort nameID, ushort shopKeeperEntityID, short posX, short posY, short posZ, byte extraInventoryBitMask, byte soundID, ushort inventoryCount, byte shopID, byte unk19, uint inventoryStartIndex)
124-
{
125-
CommandArgument = commandArgument;
126-
UnlockMenuFlag = unlockMenuFlag;
127-
NameID = nameID;
128-
ShopKeeperEntityID = shopKeeperEntityID;
129-
PosX = posX;
130-
PosY = posY;
131-
PosZ = posZ;
132-
ExtraInventoryBitMask = extraInventoryBitMask;
133-
SoundID = soundID;
134-
InventoryCount = inventoryCount;
135-
ShopID = shopID;
136-
Unk19 = unk19;
137-
InventoryStartIndex = inventoryStartIndex;
138-
}
139123
public ShopEntry ToShopEntry(ushort InventoriesBaseOffset) => new ShopEntry() {
140-
CommandArgument = CommandArgument,
141-
UnlockMenuFlag = UnlockMenuFlag,
142-
NameID = NameID,
143-
ShopKeeperEntityID = ShopKeeperEntityID,
144-
PosX = PosX,
145-
PosY = PosY,
146-
PosZ = PosZ,
147-
ExtraInventoryBitMask = ExtraInventoryBitMask,
148-
SoundID = SoundID,
149-
InventoryCount = InventoryCount,
124+
CommandArgument = CommandArgument.Value,
125+
UnlockMenuFlag = UnlockMenuFlag.Value,
126+
NameID = NameID.Value,
127+
ShopKeeperEntityID = ShopKeeperEntityID.Value,
128+
PosX = PosX.Value,
129+
PosY = PosY.Value,
130+
PosZ = PosZ.Value,
131+
ExtraInventoryBitMask = ExtraInventoryBitMask.Value,
132+
SoundID = SoundID.Value,
133+
InventoryCount = InventoryCount.Value,
150134
ShopID = ShopID,
151-
Unk19 = Unk19,
152-
InventoryOffset = (ushort)(InventoriesBaseOffset + InventoryStartIndex * InventoryEntrySize),
135+
Unk19 = Unk19.Value,
136+
InventoryOffset = (ushort)(InventoriesBaseOffset + InventoryStartIndex.Value * InventoryEntrySize),
137+
Reserved = 0
138+
};
139+
public ShopEntry ToShopEntry(ShopEntry template, ushort InventoriesBaseOffset) => new ShopEntry()
140+
{
141+
CommandArgument = CommandArgument ?? template.CommandArgument,
142+
UnlockMenuFlag = UnlockMenuFlag ?? template.UnlockMenuFlag,
143+
NameID = NameID ?? template.UnlockMenuFlag,
144+
ShopKeeperEntityID = ShopKeeperEntityID ?? template.ShopKeeperEntityID,
145+
PosX = PosX ?? template.PosX,
146+
PosY = PosY ?? template.PosY,
147+
PosZ = PosZ ?? template.PosZ,
148+
ExtraInventoryBitMask = ExtraInventoryBitMask ?? template.ExtraInventoryBitMask,
149+
SoundID = SoundID ?? template.SoundID,
150+
InventoryCount = InventoryCount ?? template.InventoryCount,
151+
ShopID = ShopID,
152+
Unk19 = Unk19 ?? template.Unk19,
153+
InventoryOffset = InventoryStartIndex.HasValue ? (ushort)(InventoriesBaseOffset + InventoryStartIndex.Value * InventoryEntrySize) : template.InventoryOffset,
153154
Reserved = 0
154155
};
155156
}

OpenKh.Patcher/PatcherProcessor.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
using System.IO;
1212
using System.Linq;
1313
using YamlDotNet.Serialization;
14-
using static OpenKh.Kh2.SystemData.Shop;
1514

1615
namespace OpenKh.Patcher
1716
{
@@ -1018,7 +1017,10 @@ private static void PatchList(Context context, List<AssetFile> sources, Stream s
10181017
}
10191018
}
10201019
inventoriesBaseOffset = (ushort)(Kh2.SystemData.Shop.HeaderSize + moddedShopEntryHelpers.Count * Kh2.SystemData.Shop.ShopEntrySize);
1021-
shop.ShopEntries = moddedShopEntryHelpers.Select(x => x.ToShopEntry(inventoriesBaseOffset)).ToList();
1020+
shop.ShopEntries = moddedShopEntryHelpers.Select(x =>
1021+
shop.ShopEntries.FindIndex(0, y => x.ShopID == y.ShopID) != -1 ?
1022+
x.ToShopEntry(shop.ShopEntries.Find(y => x.ShopID == y.ShopID), inventoriesBaseOffset) : x.ToShopEntry(inventoriesBaseOffset)
1023+
).ToList();
10221024
List<Kh2.SystemData.Shop.InventoryEntryHelper> moddedInventoryEntryHelpers = shop.InventoryEntries.Select((x, index) =>
10231025
x.ToInventoryEntryHelper(index, productsBaseOffset)
10241026
).ToList();

0 commit comments

Comments
 (0)