public static RawTaskRoot Read(Stream input, Endian endian) { var instance = new RawTaskRoot(); instance.TaskOffset = input.ReadValueS64(endian); instance.TaskCount = input.ReadValueS64(endian); return(instance); }
public static void Write(Stream output, RawTaskRoot instance, Endian endian) { output.WriteValueS64(instance.TaskOffset, endian); output.WriteValueS64(instance.TaskCount, endian); }
public void Deserialize(Stream input, Endian endian) { var basePosition = input.Position; var rawTaskRoot = RawTaskRoot.Read(input, endian); var tasks = new Task[rawTaskRoot.TaskCount]; if (rawTaskRoot.TaskCount != 0) { if (rawTaskRoot.TaskCount < 0 || rawTaskRoot.TaskCount > int.MaxValue) { throw new FormatException(); } var rawTasks = new RawTask[rawTaskRoot.TaskCount]; input.Position = basePosition + rawTaskRoot.TaskOffset; for (long i = 0; i < rawTaskRoot.TaskCount; i++) { rawTasks[i] = RawTask.Read(input, endian); } for (long i = 0; i < rawTaskRoot.TaskCount; i++) { var rawTask = rawTasks[i]; var task = new Task() { Name = rawTask.Name, TaskGroup = rawTask.TaskGroup, Type = rawTask.Type, ProvinceWeight = rawTask.ProvinceWeight, LiberationPercent = rawTask.LiberationPercent, RepeatableRewardSemantics = rawTask.RepeatableRewardSemantics, RepeatableReward = new Reward() { Skillpoints = rawTask.RepeatableReward.Skillpoints, Chaos = rawTask.RepeatableReward.Chaos, ItemRewardSemantics = rawTask.RepeatableReward.ItemRewardSemantics, Items = new ItemReward[rawTask.RepeatableReward.ItemCount], }, RewardThresholds = new RewardThreshold[rawTask.RewardThresholdCount], Prerequisites = new Prerequisite[rawTask.PrerequisiteCount], HasChurch = rawTask.HasChurch, ShownOnMap = rawTask.ShownOnMap, UIName = rawTask.UIName, UIDescription = rawTask.UIDescription, UITip = rawTask.UITip, UIOrderHint = rawTask.UIOrderHint, }; if (rawTask.RepeatableReward.ItemCount != 0) { if (rawTask.RepeatableReward.ItemCount < 0 || rawTask.RepeatableReward.ItemCount > int.MaxValue) { throw new FormatException(); } input.Position = basePosition + rawTask.RepeatableReward.ItemOffset; for (long j = 0; j < rawTask.RepeatableReward.ItemCount; j++) { task.RepeatableReward.Items[j] = ItemReward.Read(input, endian); } } if (rawTask.RewardThresholdCount != 0) { if (rawTask.RewardThresholdCount < 0 || rawTask.RewardThresholdCount > int.MaxValue) { throw new FormatException(); } var rawRewardThresholds = new RawRewardThreshold[rawTask.RewardThresholdCount]; input.Position = basePosition + rawTask.RewardThresholdOffset; for (long j = 0; j < rawTask.RewardThresholdCount; j++) { rawRewardThresholds[j] = RawRewardThreshold.Read(input, endian); } for (long j = 0; j < rawTask.RewardThresholdCount; j++) { var rawRewardThreshold = rawRewardThresholds[j]; var rewardThreshold = new RewardThreshold() { Threshold = rawRewardThreshold.Threshold, Reward = new Reward() { Skillpoints = rawRewardThreshold.Reward.Skillpoints, Chaos = rawRewardThreshold.Reward.Chaos, ItemRewardSemantics = rawRewardThreshold.Reward.ItemRewardSemantics, Items = new ItemReward[rawRewardThreshold.Reward.ItemCount], }, }; if (rawRewardThreshold.Reward.ItemCount != 0) { if (rawRewardThreshold.Reward.ItemCount < 0 || rawRewardThreshold.Reward.ItemCount > int.MaxValue) { throw new FormatException(); } input.Position = basePosition + rawRewardThreshold.Reward.ItemOffset; for (long k = 0; k < rawRewardThreshold.Reward.ItemCount; k++) { rewardThreshold.Reward.Items[k] = ItemReward.Read(input, endian); } } task.RewardThresholds[j] = rewardThreshold; } } if (rawTask.PrerequisiteCount != 0) { if (rawTask.PrerequisiteCount < 0 || rawTask.PrerequisiteCount > int.MaxValue) { throw new FormatException(); } input.Position = basePosition + rawTask.PrerequisiteOffset; for (long j = 0; j < rawTask.PrerequisiteCount; j++) { task.Prerequisites[j] = Prerequisite.Read(input, endian); } } tasks[i] = task; } } this._Tasks.Clear(); this._Tasks.AddRange(tasks); }