From 084b1c8c2403a341d6be16ac828ada383ad1df57 Mon Sep 17 00:00:00 2001 From: Ziggy Date: Fri, 28 Jul 2023 21:37:03 +0200 Subject: [PATCH] Fixed packet struct issues in draft schematic packets, causing client crashes --- .../common/data/schematic/DraftSchematic.java | 7 ++++--- .../data/schematic/DraftSlotDataOption.java | 21 ++++++++++--------- .../common/data/schematic/IngridientSlot.java | 17 ++++++++------- .../DraftSlotsQueryResponse.java | 5 +++-- .../swg/zone/resource/ResourceWeight.java | 6 +++--- 5 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/projectswg/common/data/schematic/DraftSchematic.java b/src/main/java/com/projectswg/common/data/schematic/DraftSchematic.java index 9105916..c6ab55c 100644 --- a/src/main/java/com/projectswg/common/data/schematic/DraftSchematic.java +++ b/src/main/java/com/projectswg/common/data/schematic/DraftSchematic.java @@ -1,5 +1,5 @@ /*********************************************************************************** - * Copyright (c) 2018 /// Project SWG /// www.projectswg.com * + * Copyright (c) 2023 /// Project SWG /// www.projectswg.com * * * * ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on * * July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. * @@ -30,6 +30,7 @@ import java.util.ArrayList; import java.util.List; import com.projectswg.common.data.CRC; +import com.projectswg.common.data.encodables.oob.StringId; import com.projectswg.common.data.schematic.IngridientSlot.IngridientType; public class DraftSchematic { @@ -120,8 +121,8 @@ public class DraftSchematic { complexity = 5; canManufacture = true; craftedSharedTemplate = clientTemplate; - IngridientSlot slot = new IngridientSlot("craft_food_ingredients_n.crystal", false); - slot.addSlotDataOption(new DraftSlotDataOption("craft_food_ingredients_n", "crystal", IngridientType.IT_RESOURCE_CLASS, 10)); + IngridientSlot slot = new IngridientSlot(new StringId("craft_food_ingredients_n", "crystal"), false); + slot.addSlotDataOption(new DraftSlotDataOption(new StringId("craft_food_ingredients_n", "crystal"), "crystal", IngridientType.IT_RESOURCE_CLASS, 10)); ingridientSlot.add(slot); } } diff --git a/src/main/java/com/projectswg/common/data/schematic/DraftSlotDataOption.java b/src/main/java/com/projectswg/common/data/schematic/DraftSlotDataOption.java index ab59b69..ebc05c5 100644 --- a/src/main/java/com/projectswg/common/data/schematic/DraftSlotDataOption.java +++ b/src/main/java/com/projectswg/common/data/schematic/DraftSlotDataOption.java @@ -1,5 +1,5 @@ /*********************************************************************************** - * Copyright (c) 2018 /// Project SWG /// www.projectswg.com * + * Copyright (c) 2023 /// Project SWG /// www.projectswg.com * * * * ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on * * July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. * @@ -26,18 +26,19 @@ ***********************************************************************************/ package com.projectswg.common.data.schematic; +import com.projectswg.common.data.encodables.oob.StringId; import com.projectswg.common.data.schematic.IngridientSlot.IngridientType; import com.projectswg.common.encoding.Encodable; import com.projectswg.common.network.NetBuffer; public class DraftSlotDataOption implements Encodable { - private String stfName; + private StringId stfName; private String ingredientName; private IngridientType ingredientType; private int amount; - public DraftSlotDataOption(String stfName, String ingredientName, IngridientType ingredientType, int amount) { + public DraftSlotDataOption(StringId stfName, String ingredientName, IngridientType ingredientType, int amount) { this.stfName = stfName; this.ingredientName = ingredientName; this.ingredientType = ingredientType; @@ -45,13 +46,13 @@ public class DraftSlotDataOption implements Encodable { } public DraftSlotDataOption(){ - this.stfName = ""; + this.stfName = new StringId("", ""); this.ingredientName = ""; this.ingredientType = IngridientType.IT_NONE; this.amount = 0; } - public String getStfName() { + public StringId getStfName() { return stfName; } @@ -69,24 +70,24 @@ public class DraftSlotDataOption implements Encodable { @Override public void decode(NetBuffer data) { - stfName = data.getAscii(); + stfName = data.getEncodable(StringId.class); ingredientName = data.getUnicode(); - ingredientType = IngridientType.getTypeForInt(data.getInt()); + ingredientType = IngridientType.getTypeForInt(data.getByte()); amount = data.getInt(); } @Override public byte[] encode() { NetBuffer data = NetBuffer.allocate(getLength()); - data.addAscii(stfName); + data.addEncodable(stfName); data.addUnicode(ingredientName); - data.addInt(ingredientType.getId()); + data.addByte(ingredientType.getId()); data.addInt(amount); return data.array(); } @Override public int getLength() { - return 14 + stfName.length() + ingredientName.length() * 2; + return 9 + stfName.getLength() + ingredientName.length() * 2; } } diff --git a/src/main/java/com/projectswg/common/data/schematic/IngridientSlot.java b/src/main/java/com/projectswg/common/data/schematic/IngridientSlot.java index b0537df..acbc012 100644 --- a/src/main/java/com/projectswg/common/data/schematic/IngridientSlot.java +++ b/src/main/java/com/projectswg/common/data/schematic/IngridientSlot.java @@ -1,5 +1,5 @@ /*********************************************************************************** - * Copyright (c) 2018 /// Project SWG /// www.projectswg.com * + * Copyright (c) 2023 /// Project SWG /// www.projectswg.com * * * * ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on * * July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. * @@ -31,6 +31,7 @@ import java.util.Collections; import java.util.List; import com.projectswg.common.data.EnumLookup; +import com.projectswg.common.data.encodables.oob.StringId; import com.projectswg.common.encoding.Encodable; import com.projectswg.common.network.NetBuffer; @@ -38,11 +39,11 @@ public class IngridientSlot implements Encodable{ private final List slotOptions; - private String name; + private StringId name; private boolean optional; private String hardPoint; - public IngridientSlot(String name, boolean optional) { + public IngridientSlot(StringId name, boolean optional) { this.name = name; this.optional = optional; this.slotOptions = new ArrayList<>(); @@ -50,13 +51,13 @@ public class IngridientSlot implements Encodable{ } public IngridientSlot(){ - this.name = ""; + this.name = new StringId("", ""); this.optional = false; this.slotOptions = new ArrayList<>(); this.hardPoint = ""; } - public String getName() { + public StringId getName() { return name; } @@ -80,7 +81,7 @@ public class IngridientSlot implements Encodable{ @Override public void decode(NetBuffer data) { - name = data.getAscii(); + name = data.getEncodable(StringId.class); optional = data.getBoolean(); slotOptions.clear(); slotOptions.addAll(data.getList(DraftSlotDataOption.class)); @@ -90,7 +91,7 @@ public class IngridientSlot implements Encodable{ @Override public byte[] encode() { NetBuffer data = NetBuffer.allocate(getLength()); - data.addAscii(name); + data.addEncodable(name); data.addBoolean(optional); data.addList(slotOptions); data.addAscii(hardPoint); @@ -103,7 +104,7 @@ public class IngridientSlot implements Encodable{ for (DraftSlotDataOption draftSlotDataOption : slotOptions) { length += draftSlotDataOption.getLength(); } - return 9 + name.length() + hardPoint.length() + length; + return 7 + name.getLength() + hardPoint.length() + length; } public enum IngridientType { diff --git a/src/main/java/com/projectswg/common/network/packets/swg/zone/object_controller/DraftSlotsQueryResponse.java b/src/main/java/com/projectswg/common/network/packets/swg/zone/object_controller/DraftSlotsQueryResponse.java index 50079e4..8244377 100644 --- a/src/main/java/com/projectswg/common/network/packets/swg/zone/object_controller/DraftSlotsQueryResponse.java +++ b/src/main/java/com/projectswg/common/network/packets/swg/zone/object_controller/DraftSlotsQueryResponse.java @@ -1,5 +1,5 @@ /*********************************************************************************** - * Copyright (c) 2018 /// Project SWG /// www.projectswg.com * + * Copyright (c) 2023 /// Project SWG /// www.projectswg.com * * * * ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on * * July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. * @@ -36,7 +36,8 @@ public class DraftSlotsQueryResponse extends ObjectController { private DraftSchematic schematic; - public DraftSlotsQueryResponse(DraftSchematic schematic) { + public DraftSlotsQueryResponse(DraftSchematic schematic, long objectId) { + super(objectId, CRC); this.schematic = schematic; } diff --git a/src/main/java/com/projectswg/common/network/packets/swg/zone/resource/ResourceWeight.java b/src/main/java/com/projectswg/common/network/packets/swg/zone/resource/ResourceWeight.java index 7297bc4..5ab74df 100644 --- a/src/main/java/com/projectswg/common/network/packets/swg/zone/resource/ResourceWeight.java +++ b/src/main/java/com/projectswg/common/network/packets/swg/zone/resource/ResourceWeight.java @@ -1,5 +1,5 @@ /*********************************************************************************** - * Copyright (c) 2018 /// Project SWG /// www.projectswg.com * + * Copyright (c) 2023 /// Project SWG /// www.projectswg.com * * * * ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on * * July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. * @@ -44,8 +44,8 @@ public class ResourceWeight extends ObjectController { private int schematicId; private int schematicCrc; - public ResourceWeight() { - super(CRC); + public ResourceWeight(long objectId) { + super(objectId, CRC); attributes = new HashMap<>(); resourceMaxWeights = new HashMap<>(); }