diff --git a/NebulaModel/Packets/Factory/CreatePrebuildsRequest.cs b/NebulaModel/Packets/Factory/CreatePrebuildsRequest.cs index 5a396a41b..325590fb4 100644 --- a/NebulaModel/Packets/Factory/CreatePrebuildsRequest.cs +++ b/NebulaModel/Packets/Factory/CreatePrebuildsRequest.cs @@ -37,21 +37,29 @@ public CreatePrebuildsRequest(int planetId, List buildPreviews, in public string BuildToolType { get; set; } public int PrebuildId { get; set; } - public List GetBuildPreviews() + public bool TryGetBuildPreviews(out List buildPreviews) { - var result = new List(); + buildPreviews = new(); - using var reader = new BinaryUtils.Reader(BuildPreviewData); - var previewCount = reader.BinaryReader.ReadInt32(); - for (var i = 0; i < previewCount; i++) + try { - result.Add(new BuildPreview()); + using var reader = new BinaryUtils.Reader(BuildPreviewData); + var previewCount = reader.BinaryReader.ReadInt32(); + for (var i = 0; i < previewCount; i++) + { + buildPreviews.Add(new BuildPreview()); + } + for (var i = 0; i < previewCount; i++) + { + DeserializeBuildPreview(buildPreviews[i], buildPreviews, reader.BinaryReader); + } + return true; } - for (var i = 0; i < previewCount; i++) + catch (System.Exception e) { - DeserializeBuildPreview(result[i], result, reader.BinaryReader); + Logger.Log.WarnInform("DeserializeBuildPreview parse error\n" + e); + return false; } - return result; } public static void DeserializeBuildPreview(BuildPreview buildPreview, IReadOnlyList list, BinaryReader br) @@ -88,70 +96,27 @@ public static void DeserializeBuildPreview(BuildPreview buildPreview, IReadOnlyL buildPreview.recipeId = br.ReadInt32(); buildPreview.filterId = br.ReadInt32(); buildPreview.isConnNode = br.ReadBoolean(); - buildPreview.desc = new PrefabDesc - { - //Import more data about the Prefab to properly validate the build condition on server-side - assemblerRecipeType = (ERecipeType)br.ReadInt32(), - cullingHeight = br.ReadSingle(), - gammaRayReceiver = br.ReadBoolean(), - inserterSTT = br.ReadInt32(), - isAccumulator = br.ReadBoolean(), - isAssembler = br.ReadBoolean(), - isBelt = br.ReadBoolean(), - isCollectStation = br.ReadBoolean(), - isDispenser = br.ReadBoolean(), - isEjector = br.ReadBoolean(), - isFractionator = br.ReadBoolean(), - isInserter = br.ReadBoolean(), - isLab = br.ReadBoolean(), - isPowerExchanger = br.ReadBoolean(), - isSplitter = br.ReadBoolean(), - isStation = br.ReadBoolean(), - isStellarStation = br.ReadBoolean(), - isStorage = br.ReadBoolean(), - isTank = br.ReadBoolean(), - isVeinCollector = br.ReadBoolean(), - minerType = (EMinerType)br.ReadInt32(), - modelIndex = br.ReadInt32(), - multiLevel = br.ReadBoolean(), - oilMiner = br.ReadBoolean(), - stationCollectSpeed = br.ReadInt32(), - veinMiner = br.ReadBoolean(), - windForcedPower = br.ReadBoolean(), - workEnergyPerTick = br.ReadInt64() - }; - //Import information about the position of build (land / sea) - num = br.ReadInt32(); - buildPreview.desc.landPoints = new Vector3[num]; - for (var i = 0; i < num; i++) + var modelIndex = br.ReadInt32(); + if (modelIndex >= 0 && modelIndex < LDB.models.modelArray.Length) { - buildPreview.desc.landPoints[i] = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); + var modelProto = LDB.models.modelArray[modelIndex]; + if (modelProto != null) + { + buildPreview.desc = modelProto.prefabDesc; + } } - num = br.ReadInt32(); - buildPreview.desc.waterPoints = new Vector3[num]; - for (var i = 0; i < num; i++) + if (buildPreview.desc == null) { - buildPreview.desc.waterPoints[i] = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); + throw new System.Exception("DeserializeBuildPreview: can't find modelIndx " + modelIndex); } - - //Import information about the collider to check the collisions - buildPreview.desc.hasBuildCollider = br.ReadBoolean(); - num = br.ReadInt32(); - buildPreview.desc.buildColliders = new ColliderData[num]; - for (var i = 0; i < num; i++) + var itemId = br.ReadInt32(); + buildPreview.item = LDB.items.Select(itemId); + if (buildPreview.item == null) { - buildPreview.desc.buildColliders[i].pos = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); - buildPreview.desc.buildColliders[i].ext = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); - buildPreview.desc.buildColliders[i].q = - new Quaternion(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); - buildPreview.desc.buildColliders[i].radius = br.ReadSingle(); - buildPreview.desc.buildColliders[i].idType = br.ReadInt32(); - buildPreview.desc.buildColliders[i].link = br.ReadInt32(); + throw new System.Exception("DeserializeBuildPreview: can't find itemId " + itemId); } - buildPreview.item = new ItemProto { ID = br.ReadInt32(), BuildMode = br.ReadInt32(), Grade = br.ReadInt32() }; - buildPreview.paramCount = br.ReadInt32(); buildPreview.parameters = new int[buildPreview.paramCount]; for (var i = 0; i < buildPreview.paramCount; i++) @@ -195,77 +160,11 @@ public static void SerializeBuildPreview(BuildPreview buildPreview, IList