From fc92216b43750c4cb236d906e8d0f4a657b281ed Mon Sep 17 00:00:00 2001 From: Niaz Date: Fri, 13 May 2022 22:38:45 +0200 Subject: [PATCH 01/18] Add Trigger Editor --- BaseHandlers/BaseHandlers.csproj | 6 + BaseHandlers/TriggerData.cs | 285 ++++++++++++--------- BaseHandlers/TriggerDataEditor.Designer.cs | 54 ++++ BaseHandlers/TriggerDataEditor.cs | 48 ++++ 4 files changed, 279 insertions(+), 114 deletions(-) create mode 100644 BaseHandlers/TriggerDataEditor.Designer.cs create mode 100644 BaseHandlers/TriggerDataEditor.cs diff --git a/BaseHandlers/BaseHandlers.csproj b/BaseHandlers/BaseHandlers.csproj index 0df59b0..dfaac9c 100644 --- a/BaseHandlers/BaseHandlers.csproj +++ b/BaseHandlers/BaseHandlers.csproj @@ -55,6 +55,12 @@ + + Form + + + TriggerDataEditor.cs + diff --git a/BaseHandlers/TriggerData.cs b/BaseHandlers/TriggerData.cs index d5254e9..d3b9fa1 100644 --- a/BaseHandlers/TriggerData.cs +++ b/BaseHandlers/TriggerData.cs @@ -1,4 +1,4 @@ -using BundleFormat; +using BundleFormat; using BundleUtilities; using PluginAPI; using System; @@ -10,139 +10,139 @@ namespace BaseHandlers { public struct LandmarkTrigger { - public float PositionX; - public float PositionY; - public float PositionZ; - public float RotationX; - public float RotationY; - public float RotationZ; - public float SizeX; - public float SizeY; - public float SizeZ; - public int GameDBID; - public short GlobalIndex; - public byte Type; // Should be 0 - public byte UnknownByte2B; - public uint UnknownOffset; - public byte UnknownByte30; - public byte LocalIndex; - public byte Subtype; - public byte UnknownByte33; + public float PositionX { get; set; } + public float PositionY { get; set; } + public float PositionZ { get; set; } + public float RotationX { get; set; } + public float RotationY { get; set; } + public float RotationZ { get; set; } + public float SizeX { get; set; } + public float SizeY { get; set; } + public float SizeZ { get; set; } + public int GameDBID { get; set; } + public short GlobalIndex { get; set; } + public byte Type { get; set; } // Should be 0 + public byte UnknownByte2B { get; set; } + public uint UnknownOffset { get; set; } + public byte UnknownByte30 { get; set; } + public byte LocalIndex { get; set; } + public byte Subtype { get; set; } + public byte UnknownByte33 { get; set; } public override string ToString() => $"ID {GameDBID}"; } public struct GenericRegionTrigger { - public float PositionX; - public float PositionY; - public float PositionZ; - public float RotationX; - public float RotationY; - public float RotationZ; - public float SizeX; - public float SizeY; - public float SizeZ; - public int GameDBID; - public short Index; - public byte Type; // Should be 2 - public byte UnknownByte2B; - public int GameDBID2; // Only used for _some_ super jumps - public short UnknownShort30; - public short UnknownShort32; - public byte UnknownByte34; - public byte UnknownByte35; - public byte Subtype; - public byte UnknownByte37; // most, but not all, super jumps have this set (to 1) + public float PositionX { get; set; } + public float PositionY { get; set; } + public float PositionZ { get; set; } + public float RotationX { get; set; } + public float RotationY { get; set; } + public float RotationZ { get; set; } + public float SizeX { get; set; } + public float SizeY { get; set; } + public float SizeZ { get; set; } + public int GameDBID { get; set; } + public short Index { get; set; } + public byte Type { get; set; } // Should be 2 + public byte UnknownByte2B { get; set; } + public int GameDBID2 { get; set; } // Only used for _some_ super jumps + public short UnknownShort30 { get; set; } + public short UnknownShort32 { get; set; } + public byte UnknownByte34 { get; set; } + public byte UnknownByte35 { get; set; } + public byte Subtype { get; set; } + public byte UnknownByte37 { get; set; } // most, but not all, super jumps have this set (to 1) public override string ToString() => $"ID {GameDBID}"; } public struct TriggerSection4Entry { - public uint TriggerOffsetListOffset; - public int TriggerOffsetListCount; - public uint GameDBIDListOffset; - public int GameDBIDListCount; + public uint TriggerOffsetListOffset { get; set; } + public int TriggerOffsetListCount { get; set; } + public uint GameDBIDListOffset { get; set; } + public int GameDBIDListCount { get; set; } - public List Triggers; - public List GameDBIDs; + public List Triggers { get; set; } + public List GameDBIDs { get; set; } } public struct RoamingLocation { - public float PositionX; - public float PositionY; - public float PositionZ; - public uint UnknownHash; - public byte Subdistrict; - public byte UnknownByte11; - public byte UnknownByte12; - public byte UnknownByte13; - public int UnknownInt14; - public int UnknownInt18; - public int UnknownInt1C; + public float PositionX { get; set; } + public float PositionY { get; set; } + public float PositionZ { get; set; } + public uint UnknownHash { get; set; } + public byte Subdistrict { get; set; } + public byte UnknownByte11 { get; set; } + public byte UnknownByte12 { get; set; } + public byte UnknownByte13 { get; set; } + public int UnknownInt14 { get; set; } + public int UnknownInt18 { get; set; } + public int UnknownInt1C { get; set; } } public struct SpawnLocation { - public float PositionX; - public float PositionY; - public float PositionZ; - public uint UnknownHash; - public float RotationX; - public float RotationY; - public float RotationZ; - public float UnknownFloat1C; - public long JunkyardGameDBID; - public GenericRegionTrigger JunkyardTrigger; - public byte UnknownByte28; - public byte UnknownByte29; - public byte UnknownByte30; - public byte UnknownByte31; - public int UnknownInt32; + public float PositionX { get; set; } + public float PositionY { get; set; } + public float PositionZ { get; set; } + public uint UnknownHash { get; set; } + public float RotationX { get; set; } + public float RotationY { get; set; } + public float RotationZ { get; set; } + public float UnknownFloat1C { get; set; } + public long JunkyardGameDBID { get; set; } + public GenericRegionTrigger JunkyardTrigger { get; set; } + public byte UnknownByte28 { get; set; } + public byte UnknownByte29 { get; set; } + public byte UnknownByte30 { get; set; } + public byte UnknownByte31 { get; set; } + public int UnknownInt32 { get; set; } } public class TriggerData : IEntryData { - public int FormatRevision; - public uint FileSize; - public int Unknown0C; - public int Unknown10; - public float DevSpawnPositionX; - public float DevSpawnPositionY; - public float DevSpawnPositionZ; - public uint DevSpawnUnknownHash; - public float DevSpawnRotationX; - public float DevSpawnRotationY; - public float DevSpawnRotationZ; - public float DevSpawnUnknownFloat; - public uint LandmarkTriggersOffset; - public int LandmarkTriggersCount; - public int LandmarkNonFinishLineCount; - public uint BlackspotTriggersOffset; - public int BlackspotTriggersCount; - public uint GenericRegionTriggersOffset; - public int GenericRegionTriggersCount; - public uint Section4Offset; - public int Section4Count; - public uint VFXBoxRegionOffset; - public int VFXBoxRegionCount; - public uint StartPositionsOffset; - public int StartPositionsCount; - public uint RoamingLocationsOffset; - public int RoamingLocationsCount; - public uint SpawnLocationsOffset; - public int SpawnLocationsCount; - public uint TriggerOffsetListOffset; - public int TriggerOffsetListCount; - - public List LandmarkTriggers; - public SortedDictionary GenericRegionTriggers; - public List Section4Entries; - public List RoamingLocationEntries; - public List SpawnLocationEntries; - public List TriggerOffsets; + public int FormatRevision { get; set; } + public uint FileSize { get; set; } + public int Unknown0C { get; set; } + public int Unknown10 { get; set; } + public float DevSpawnPositionX { get; set; } + public float DevSpawnPositionY { get; set; } + public float DevSpawnPositionZ { get; set; } + public uint DevSpawnUnknownHash { get; set; } + public float DevSpawnRotationX { get; set; } + public float DevSpawnRotationY { get; set; } + public float DevSpawnRotationZ { get; set; } + public float DevSpawnUnknownFloat { get; set; } + public uint LandmarkTriggersOffset { get; set; } + public int LandmarkTriggersCount { get; set; } + public int LandmarkNonFinishLineCount { get; set; } + public uint BlackspotTriggersOffset { get; set; } + public int BlackspotTriggersCount { get; set; } + public uint GenericRegionTriggersOffset { get; set; } + public int GenericRegionTriggersCount { get; set; } + public uint Section4Offset { get; set; } + public int Section4Count { get; set; } + public uint VFXBoxRegionOffset { get; set; } + public int VFXBoxRegionCount { get; set; } + public uint StartPositionsOffset { get; set; } + public int StartPositionsCount { get; set; } + public uint RoamingLocationsOffset { get; set; } + public int RoamingLocationsCount { get; set; } + public uint SpawnLocationsOffset { get; set; } + public int SpawnLocationsCount { get; set; } + public uint TriggerOffsetListOffset { get; set; } + public int TriggerOffsetListCount { get; set; } + + public List LandmarkTriggers { get; set; } + public SortedDictionary GenericRegionTriggers { get; set; } + public List Section4Entries { get; set; } + public List RoamingLocationEntries { get; set; } + public List SpawnLocationEntries { get; set; } + public List TriggerOffsets { get; set; } public TriggerData() { @@ -313,8 +313,28 @@ public bool Read(BundleEntry entry, ILoader loader = null) section4Entry.Triggers = new List(); for (int j = 0; j < section4Entry.TriggerOffsetListCount; j++) { - uint offset = br.ReadUInt32(); - section4Entry.Triggers.Add(GenericRegionTriggers[offset]); + GenericRegionTrigger region = new GenericRegionTrigger(); + region.PositionX = br.ReadSingle(); + region.PositionY = br.ReadSingle(); + region.PositionZ = br.ReadSingle(); + region.RotationX = br.ReadSingle(); + region.RotationY = br.ReadSingle(); + region.RotationZ = br.ReadSingle(); + region.SizeX = br.ReadSingle(); + region.SizeY = br.ReadSingle(); + region.SizeZ = br.ReadSingle(); + region.GameDBID = br.ReadInt32(); + region.Index = br.ReadInt16(); + region.Type = br.ReadByte(); + region.UnknownByte2B = br.ReadByte(); + region.GameDBID2 = br.ReadInt32(); + region.UnknownShort30 = br.ReadInt16(); + region.UnknownShort32 = br.ReadInt16(); + region.UnknownByte34 = br.ReadByte(); + region.UnknownByte35 = br.ReadByte(); + region.Subtype = br.ReadByte(); + region.UnknownByte37 = br.ReadByte(); + section4Entry.Triggers.Add(region); } br.BaseStream.Position = section4Entry.GameDBIDListOffset; @@ -399,7 +419,13 @@ public bool Read(BundleEntry entry, ILoader loader = null) public IEntryEditor GetEditor(BundleEntry entry) { - return null; + TriggerDataEditor triggerDataEditor = new TriggerDataEditor(); + triggerDataEditor.trigger = this; + triggerDataEditor.EditEvent += () => + { + Write(entry); + }; + return triggerDataEditor; } public EntryType GetEntryType(BundleEntry entry) @@ -506,7 +532,38 @@ public bool Write(BundleEntry entry) bw.Write(section4Entry.GameDBIDListOffset); bw.Write(section4Entry.GameDBIDListCount); - // TODO: write list + long oldPosition = bw.BaseStream.Position; + + bw.BaseStream.Position = section4Entry.TriggerOffsetListOffset; + foreach (GenericRegionTrigger trigger in section4Entry.Triggers) + { + bw.Write(trigger.PositionX); + bw.Write(trigger.PositionY); + bw.Write(trigger.PositionZ); + bw.Write(trigger.RotationX); + bw.Write(trigger.RotationY); + bw.Write(trigger.RotationZ); + bw.Write(trigger.SizeX); + bw.Write(trigger.SizeY); + bw.Write(trigger.SizeZ); + bw.Write(trigger.GameDBID); + bw.Write(trigger.Index); + bw.Write(trigger.Type); + bw.Write(trigger.UnknownByte2B); + bw.Write(trigger.GameDBID2); + bw.Write(trigger.UnknownShort30); + bw.Write(trigger.UnknownShort32); + bw.Write(trigger.UnknownByte34); + bw.Write(trigger.UnknownByte35); + bw.Write(trigger.Subtype); + bw.Write(trigger.UnknownByte37); + } + bw.BaseStream.Position = section4Entry.GameDBIDListOffset; + foreach(long id in section4Entry.GameDBIDs) + { + bw.Write(id); + } + bw.BaseStream.Position = oldPosition; } bw.BaseStream.Position = RoamingLocationsOffset; @@ -566,7 +623,7 @@ public bool Write(BundleEntry entry) long paddingCount = 16 - (bw.BaseStream.Position % 16); for (int i = 0; i < paddingCount; i++) - bw.Write((byte) 0); + bw.Write((byte)0); bw.Flush(); diff --git a/BaseHandlers/TriggerDataEditor.Designer.cs b/BaseHandlers/TriggerDataEditor.Designer.cs new file mode 100644 index 0000000..54385d2 --- /dev/null +++ b/BaseHandlers/TriggerDataEditor.Designer.cs @@ -0,0 +1,54 @@ + +namespace BaseHandlers +{ + partial class TriggerDataEditor + { + private System.ComponentModel.IContainer components = null; + + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Vom Windows Form-Designer generierter Code + + /// + /// Erforderliche Methode für die Designerunterstützung. + /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. + /// + private void InitializeComponent() + { + this.propertyGrid1 = new System.Windows.Forms.PropertyGrid(); + this.SuspendLayout(); + // + // propertyGrid1 + // + this.propertyGrid1.Location = new System.Drawing.Point(-2, -4); + this.propertyGrid1.Name = "propertyGrid1"; + this.propertyGrid1.Size = new System.Drawing.Size(802, 456); + this.propertyGrid1.TabIndex = 0; + this.propertyGrid1.PropertyValueChanged += new System.Windows.Forms.PropertyValueChangedEventHandler(this.propertyGrid1_PropertyValueChanged); + // + // LuaListEditor + // + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.propertyGrid1); + this.Name = "TriggerDataEditor"; + this.Text = "Trigger Data Editor"; + this.ResumeLayout(false); + + this.Controls.Add(this.propertyGrid1); + + } + + #endregion + + private System.Windows.Forms.PropertyGrid propertyGrid1; + } +} diff --git a/BaseHandlers/TriggerDataEditor.cs b/BaseHandlers/TriggerDataEditor.cs new file mode 100644 index 0000000..db833c8 --- /dev/null +++ b/BaseHandlers/TriggerDataEditor.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using PluginAPI; + +namespace BaseHandlers +{ + + public delegate void Notify(); // delegate + public partial class TriggerDataEditor : Form, IEntryEditor + { + public event Notify EditEvent; + + private TriggerData _trigger; + public TriggerData trigger + { + get => _trigger; + set + { + _trigger = value; + UpdateComponent(); + } + } + + public void UpdateComponent() + { + + propertyGrid1.SelectedObject = trigger; + } + + public TriggerDataEditor() + { + InitializeComponent(); + UpdateComponent(); + } + + private void propertyGrid1_PropertyValueChanged(object s, PropertyValueChangedEventArgs e) + { + EditEvent?.Invoke(); + } + } +} From b21d7de42040ff12f8e5367cf4197313b2a89ba8 Mon Sep 17 00:00:00 2001 From: Niaz Date: Fri, 13 May 2022 23:40:12 +0200 Subject: [PATCH 02/18] Force saving of collections --- BaseHandlers/TriggerDataEditor.Designer.cs | 1 + BaseHandlers/TriggerDataEditor.cs | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/BaseHandlers/TriggerDataEditor.Designer.cs b/BaseHandlers/TriggerDataEditor.Designer.cs index 54385d2..8385069 100644 --- a/BaseHandlers/TriggerDataEditor.Designer.cs +++ b/BaseHandlers/TriggerDataEditor.Designer.cs @@ -32,6 +32,7 @@ private void InitializeComponent() this.propertyGrid1.Size = new System.Drawing.Size(802, 456); this.propertyGrid1.TabIndex = 0; this.propertyGrid1.PropertyValueChanged += new System.Windows.Forms.PropertyValueChangedEventHandler(this.propertyGrid1_PropertyValueChanged); + this.propertyGrid1.LostFocus += (sender, args) => this.propertyChanged(); // // LuaListEditor // diff --git a/BaseHandlers/TriggerDataEditor.cs b/BaseHandlers/TriggerDataEditor.cs index db833c8..7be806e 100644 --- a/BaseHandlers/TriggerDataEditor.cs +++ b/BaseHandlers/TriggerDataEditor.cs @@ -44,5 +44,9 @@ private void propertyGrid1_PropertyValueChanged(object s, PropertyValueChangedEv { EditEvent?.Invoke(); } + + private void propertyChanged() { + EditEvent?.Invoke(); + } } } From bdf58a00f46a42c9b220cc3458a1952a65e82f77 Mon Sep 17 00:00:00 2001 From: Niaz Date: Sat, 14 May 2022 09:10:18 +0200 Subject: [PATCH 03/18] Allow editing of generic region triggers --- BaseHandlers/TriggerData.cs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/BaseHandlers/TriggerData.cs b/BaseHandlers/TriggerData.cs index d3b9fa1..19c9700 100644 --- a/BaseHandlers/TriggerData.cs +++ b/BaseHandlers/TriggerData.cs @@ -54,7 +54,6 @@ public struct GenericRegionTrigger public byte UnknownByte35 { get; set; } public byte Subtype { get; set; } public byte UnknownByte37 { get; set; } // most, but not all, super jumps have this set (to 1) - public override string ToString() => $"ID {GameDBID}"; } @@ -138,7 +137,7 @@ public class TriggerData : IEntryData public int TriggerOffsetListCount { get; set; } public List LandmarkTriggers { get; set; } - public SortedDictionary GenericRegionTriggers { get; set; } + public List GenericRegionTriggers { get; set; } public List Section4Entries { get; set; } public List RoamingLocationEntries { get; set; } public List SpawnLocationEntries { get; set; } @@ -147,7 +146,7 @@ public class TriggerData : IEntryData public TriggerData() { LandmarkTriggers = new List(); - GenericRegionTriggers = new SortedDictionary(); + GenericRegionTriggers = new List(); Section4Entries = new List(); RoamingLocationEntries = new List(); SpawnLocationEntries = new List(); @@ -268,10 +267,7 @@ public bool Read(BundleEntry entry, ILoader loader = null) for (int i = 0; i < GenericRegionTriggersCount; i++) { - long startPosition = br.BaseStream.Position; - GenericRegionTrigger genericRegionTrigger = new GenericRegionTrigger(); - genericRegionTrigger.PositionX = br.ReadSingle(); genericRegionTrigger.PositionY = br.ReadSingle(); genericRegionTrigger.PositionZ = br.ReadSingle(); @@ -293,7 +289,7 @@ public bool Read(BundleEntry entry, ILoader loader = null) genericRegionTrigger.Subtype = br.ReadByte(); genericRegionTrigger.UnknownByte37 = br.ReadByte(); - GenericRegionTriggers.Add((uint)startPosition, genericRegionTrigger); + GenericRegionTriggers.Add(genericRegionTrigger); } br.BaseStream.Position = Section4Offset; @@ -391,7 +387,7 @@ public bool Read(BundleEntry entry, ILoader loader = null) spawnLocation.UnknownByte31 = br.ReadByte(); spawnLocation.UnknownInt32 = br.ReadInt32(); - foreach (GenericRegionTrigger trigger in GenericRegionTriggers.Values) + foreach (GenericRegionTrigger trigger in GenericRegionTriggers) { if (trigger.GameDBID == spawnLocation.JunkyardGameDBID) { @@ -499,7 +495,7 @@ public bool Write(BundleEntry entry) bw.BaseStream.Position = GenericRegionTriggersOffset; - foreach (GenericRegionTrigger genericRegionTrigger in GenericRegionTriggers.Values) + foreach (GenericRegionTrigger genericRegionTrigger in GenericRegionTriggers) { bw.Write(genericRegionTrigger.PositionX); bw.Write(genericRegionTrigger.PositionY); From 9b9733902ecae6b88e76537721474ef1f9a7d0ce Mon Sep 17 00:00:00 2001 From: Niaz Date: Fri, 20 May 2022 11:16:20 +0200 Subject: [PATCH 04/18] Move unknown / undefined bytes into own category --- BaseHandlers/TriggerData.cs | 65 ++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 5 deletions(-) diff --git a/BaseHandlers/TriggerData.cs b/BaseHandlers/TriggerData.cs index 19c9700..b98a7c1 100644 --- a/BaseHandlers/TriggerData.cs +++ b/BaseHandlers/TriggerData.cs @@ -3,11 +3,13 @@ using PluginAPI; using System; using System.Collections.Generic; +using System.ComponentModel; using System.IO; using System.Linq; namespace BaseHandlers { + //To-Do: Calculate Offsets and Counts to allow for adding new Triggers public struct LandmarkTrigger { public float PositionX { get; set; } @@ -22,11 +24,15 @@ public struct LandmarkTrigger public int GameDBID { get; set; } public short GlobalIndex { get; set; } public byte Type { get; set; } // Should be 0 + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public byte UnknownByte2B { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public uint UnknownOffset { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public byte UnknownByte30 { get; set; } public byte LocalIndex { get; set; } public byte Subtype { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public byte UnknownByte33 { get; set; } public override string ToString() => $"ID {GameDBID}"; @@ -46,22 +52,33 @@ public struct GenericRegionTrigger public int GameDBID { get; set; } public short Index { get; set; } public byte Type { get; set; } // Should be 2 + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public byte UnknownByte2B { get; set; } public int GameDBID2 { get; set; } // Only used for _some_ super jumps + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public short UnknownShort30 { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public short UnknownShort32 { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public byte UnknownByte34 { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public byte UnknownByte35 { get; set; } public byte Subtype { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public byte UnknownByte37 { get; set; } // most, but not all, super jumps have this set (to 1) public override string ToString() => $"ID {GameDBID}"; } public struct TriggerSection4Entry { + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public uint TriggerOffsetListOffset { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public int TriggerOffsetListCount { get; set; } + + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public uint GameDBIDListOffset { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public int GameDBIDListCount { get; set; } public List Triggers { get; set; } @@ -73,13 +90,20 @@ public struct RoamingLocation public float PositionX { get; set; } public float PositionY { get; set; } public float PositionZ { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public uint UnknownHash { get; set; } public byte Subdistrict { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public byte UnknownByte11 { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public byte UnknownByte12 { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public byte UnknownByte13 { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public int UnknownInt14 { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public int UnknownInt18 { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public int UnknownInt1C { get; set; } } @@ -88,17 +112,24 @@ public struct SpawnLocation public float PositionX { get; set; } public float PositionY { get; set; } public float PositionZ { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public uint UnknownHash { get; set; } public float RotationX { get; set; } public float RotationY { get; set; } public float RotationZ { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public float UnknownFloat1C { get; set; } public long JunkyardGameDBID { get; set; } public GenericRegionTrigger JunkyardTrigger { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public byte UnknownByte28 { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public byte UnknownByte29 { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public byte UnknownByte30 { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public byte UnknownByte31 { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public int UnknownInt32 { get; set; } } @@ -106,34 +137,57 @@ public class TriggerData : IEntryData { public int FormatRevision { get; set; } public uint FileSize { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public int Unknown0C { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public int Unknown10 { get; set; } public float DevSpawnPositionX { get; set; } public float DevSpawnPositionY { get; set; } public float DevSpawnPositionZ { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public uint DevSpawnUnknownHash { get; set; } public float DevSpawnRotationX { get; set; } public float DevSpawnRotationY { get; set; } public float DevSpawnRotationZ { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public float DevSpawnUnknownFloat { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public uint LandmarkTriggersOffset { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public int LandmarkTriggersCount { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public int LandmarkNonFinishLineCount { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public uint BlackspotTriggersOffset { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public int BlackspotTriggersCount { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public uint GenericRegionTriggersOffset { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public int GenericRegionTriggersCount { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public uint Section4Offset { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public int Section4Count { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public uint VFXBoxRegionOffset { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public int VFXBoxRegionCount { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public uint StartPositionsOffset { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public int StartPositionsCount { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public uint RoamingLocationsOffset { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public int RoamingLocationsCount { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public uint SpawnLocationsOffset { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public int SpawnLocationsCount { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public uint TriggerOffsetListOffset { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public int TriggerOffsetListCount { get; set; } public List LandmarkTriggers { get; set; } @@ -141,6 +195,7 @@ public class TriggerData : IEntryData public List Section4Entries { get; set; } public List RoamingLocationEntries { get; set; } public List SpawnLocationEntries { get; set; } + [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] public List TriggerOffsets { get; set; } public TriggerData() @@ -321,14 +376,14 @@ public bool Read(BundleEntry entry, ILoader loader = null) region.SizeZ = br.ReadSingle(); region.GameDBID = br.ReadInt32(); region.Index = br.ReadInt16(); - region.Type = br.ReadByte(); + region.Type = br.ReadByte(); region.UnknownByte2B = br.ReadByte(); region.GameDBID2 = br.ReadInt32(); region.UnknownShort30 = br.ReadInt16(); region.UnknownShort32 = br.ReadInt16(); region.UnknownByte34 = br.ReadByte(); region.UnknownByte35 = br.ReadByte(); - region.Subtype = br.ReadByte(); + region.Subtype = br.ReadByte(); region.UnknownByte37 = br.ReadByte(); section4Entry.Triggers.Add(region); } @@ -544,9 +599,9 @@ public bool Write(BundleEntry entry) bw.Write(trigger.SizeZ); bw.Write(trigger.GameDBID); bw.Write(trigger.Index); - bw.Write(trigger.Type); + bw.Write(trigger.Type); bw.Write(trigger.UnknownByte2B); - bw.Write(trigger.GameDBID2); + bw.Write(trigger.GameDBID2); bw.Write(trigger.UnknownShort30); bw.Write(trigger.UnknownShort32); bw.Write(trigger.UnknownByte34); @@ -555,7 +610,7 @@ public bool Write(BundleEntry entry) bw.Write(trigger.UnknownByte37); } bw.BaseStream.Position = section4Entry.GameDBIDListOffset; - foreach(long id in section4Entry.GameDBIDs) + foreach (long id in section4Entry.GameDBIDs) { bw.Write(id); } From 854235f6aaafdc07404f7664b6e613d3a8f85d4e Mon Sep 17 00:00:00 2001 From: Niaz Date: Sat, 10 Dec 2022 15:50:51 +0100 Subject: [PATCH 05/18] Add updated datastructures Reading and writing does not work yet. --- BaseHandlers/TriggerData.cs | 727 ++++++------------------------------ 1 file changed, 113 insertions(+), 614 deletions(-) diff --git a/BaseHandlers/TriggerData.cs b/BaseHandlers/TriggerData.cs index b98a7c1..a19ecb3 100644 --- a/BaseHandlers/TriggerData.cs +++ b/BaseHandlers/TriggerData.cs @@ -9,245 +9,148 @@ namespace BaseHandlers { - //To-Do: Calculate Offsets and Counts to allow for adding new Triggers - public struct LandmarkTrigger - { - public float PositionX { get; set; } - public float PositionY { get; set; } - public float PositionZ { get; set; } - public float RotationX { get; set; } - public float RotationY { get; set; } - public float RotationZ { get; set; } - public float SizeX { get; set; } - public float SizeY { get; set; } - public float SizeZ { get; set; } - public int GameDBID { get; set; } - public short GlobalIndex { get; set; } - public byte Type { get; set; } // Should be 0 - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public byte UnknownByte2B { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public uint UnknownOffset { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public byte UnknownByte30 { get; set; } - public byte LocalIndex { get; set; } - public byte Subtype { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public byte UnknownByte33 { get; set; } - public override string ToString() => $"ID {GameDBID}"; + public struct StartingGrid { + public Vector3I[] maStartingPositions; //0x0 0x80 Vector3[8] maStartingPositions + public Vector3I[] maStartingDirections; //0x80 0x80 Vector3[8] maStartingDirections + } + + public struct BoxRegion { + + public float mPositionX { get; set; } //0x0 0x4 float32_t mPositionX + public float mPositionY { get; set; } //0x4 0x4 float32_t mPositionY + public float mPositionZ { get; set; } //0x8 0x4 float32_t mPositionZ + public float mRotationX { get; set; } //0xC 0x4 float32_t mRotationX + public float mRotationY { get; set; } //0x10 0x4 float32_t mRotationY + public float mRotationZ { get; set; } //0x14 0x4 float32_t mRotationZ + public float mDimensionX { get; set; } //0x18 0x4 float32_t mDimensionX + public float mDimensionY { get; set; } //0x1C 0x4 float32_t mDimensionY + public float mDimensionZ { get; set; } //0x20 0x4 float32_t mDimensionZ } - public struct GenericRegionTrigger + public struct TriggerRegion { + public BoxRegion mBoxRegion; //0x0 0x24 BoxRegion mBoxRegion + public int mId; //0x24 0x4 int32_t mId + public Int16 miRegionIndex; //0x28 0x2 int16_t miRegionIndex Region index + public short meType; //0x2A 0x1 uint8_t meType Region type See type + public short muPad; //0x2B 0x1 uint8_t[1] muPad + } + + public struct Landmark { - public float PositionX { get; set; } - public float PositionY { get; set; } - public float PositionZ { get; set; } - public float RotationX { get; set; } - public float RotationY { get; set; } - public float RotationZ { get; set; } - public float SizeX { get; set; } - public float SizeY { get; set; } - public float SizeZ { get; set; } - public int GameDBID { get; set; } - public short Index { get; set; } - public byte Type { get; set; } // Should be 2 - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public byte UnknownByte2B { get; set; } - public int GameDBID2 { get; set; } // Only used for _some_ super jumps - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public short UnknownShort30 { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public short UnknownShort32 { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public byte UnknownByte34 { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public byte UnknownByte35 { get; set; } - public byte Subtype { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public byte UnknownByte37 { get; set; } // most, but not all, super jumps have this set (to 1) - public override string ToString() => $"ID {GameDBID}"; + public TriggerRegion triggerRegion; //0x0 0x2C TriggerRegion super_TriggerRegion + //0x2C 0x4 padding + public int mpaStartingGrids; // 0x30 0x8 StartingGrid* mpaStartingGrids StartingGrid + public short miStartingGridCount { get; set; } //0x38 0x1 int8_t miStartingGridCount Always 0 + public byte muDesignIndex { get; set; } //0x39 0x1 uint8_t muDesignIndex Landmark index + public byte muDistrict { get; set; } //0x3A 0x1 uint8_t muDistrict District ID Always 3. See Districts + public byte mu8Flags { get; set; } //0x3B 0x1 uint8_t mu8Flags Flags See flags + //0x3C 0x4 padding } - public struct TriggerSection4Entry + public struct GenericRegion { - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public uint TriggerOffsetListOffset { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public int TriggerOffsetListCount { get; set; } + public TriggerRegion triggerRegion; //0x0 0x2C TriggerRegion super_TriggerRegion + public int miGroupID { get; set; } //0x2C 0x4 int32_t miGroupID GameDB ID + public short miCameraCut1 { get; set; } //0x30 0x2 int16_t miCameraCut1 + public short miCameraCut2 { get; set; } //0x32 0x2 int16_t miCameraCut2 + public byte miCameraType1 { get; set; } //0x34 0x1 int8_t miCameraType1 Stunt camera type 1 See stunt camera type + public byte miCameraType2 { get; set; } //0x35 0x1 int8_t miCameraType2 Stunt camera type 2 See stunt camera type + public byte meType { get; set; } //0x36 0x1 uint8_t meType Generic region type See type + public byte miIsOneWay { get; set; } //0x37 0x1 int8_t miIsOneWay + } + + public struct Blackspot { + public TriggerRegion triggerRegion; //0x0 0x2C TriggerRegion super_TriggerRegion + public ushort muScoreType; //0x2C 0x1 uint8_t muScoreType See score type + //0x2D 0x3 padding + public int miScoreAmount; //0x30 0x4 int32_t miScoreAmount + } + + public struct Killzone + { + public int mppTriggers;//0x0 0x8 GenericRegion** mppTriggers GenericRegion pointer array + public int miTriggerCount; //0x8 0x4 int32_t miTriggerCount Number of generic regions + //0xC 0x4 padding + public int mpRegionIds; //0x10 0x8 CgsID* mpRegionIds Regions GameDB IDs + public int miRegionIdCount; //0x18 0x4 int32_t miRegionIdCount Number of region IDs + //0x1C 0x4 padding + } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public uint GameDBIDListOffset { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public int GameDBIDListCount { get; set; } + public struct SignatureStunt { + public UInt64 mId; //0x0 0x8 CgsID mId GameDB ID + public long miCamera; //0x8 0x8 int64_t miCamera + public int mppStuntElements; //0x10 0x4 GenericRegion** mppStuntElements + public int miStuntElementCount; //0x14 0x4 int32_t miStuntElementCount + //0x1C 0x4 padding - public List Triggers { get; set; } - public List GameDBIDs { get; set; } } public struct RoamingLocation { - public float PositionX { get; set; } - public float PositionY { get; set; } - public float PositionZ { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public uint UnknownHash { get; set; } - public byte Subdistrict { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public byte UnknownByte11 { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public byte UnknownByte12 { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public byte UnknownByte13 { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public int UnknownInt14 { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public int UnknownInt18 { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public int UnknownInt1C { get; set; } + public Vector3I mPosition { get; set; } //0x0 0x10 Vector3 mPosition + public uint muDistrictIndex { get; set; } //0x10 0x1 uint8_t muDistrictIndex See Districts + //0x11 0xF padding + } + + public struct VFXBoxRegion { + public TriggerRegion region; //0x0 0x2C TriggerRegion super_TriggerRegion } public struct SpawnLocation { - public float PositionX { get; set; } - public float PositionY { get; set; } - public float PositionZ { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public uint UnknownHash { get; set; } - public float RotationX { get; set; } - public float RotationY { get; set; } - public float RotationZ { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public float UnknownFloat1C { get; set; } - public long JunkyardGameDBID { get; set; } - public GenericRegionTrigger JunkyardTrigger { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public byte UnknownByte28 { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public byte UnknownByte29 { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public byte UnknownByte30 { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public byte UnknownByte31 { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public int UnknownInt32 { get; set; } + public Vector3I mPosition { get; set; } //0x0 0x10 Vector3 mPosition + public Vector3I mDirection { get; set; } //0x10 0x10 Vector3 mDirection + public UInt64 mJunkyardId { get; set; } //0x20 0x8 CgsID mJunkyardId GameDB ID + public uint muType { get; set; } //0x28 0x1 uint8_t muType Type See type + // 0x29 0x7 padding + } + + public class TriggerData : IEntryData { - public int FormatRevision { get; set; } - public uint FileSize { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public int Unknown0C { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public int Unknown10 { get; set; } - public float DevSpawnPositionX { get; set; } - public float DevSpawnPositionY { get; set; } - public float DevSpawnPositionZ { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public uint DevSpawnUnknownHash { get; set; } - public float DevSpawnRotationX { get; set; } - public float DevSpawnRotationY { get; set; } - public float DevSpawnRotationZ { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public float DevSpawnUnknownFloat { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public uint LandmarkTriggersOffset { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public int LandmarkTriggersCount { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public int LandmarkNonFinishLineCount { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public uint BlackspotTriggersOffset { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public int BlackspotTriggersCount { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public uint GenericRegionTriggersOffset { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public int GenericRegionTriggersCount { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public uint Section4Offset { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public int Section4Count { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public uint VFXBoxRegionOffset { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public int VFXBoxRegionCount { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public uint StartPositionsOffset { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public int StartPositionsCount { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public uint RoamingLocationsOffset { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public int RoamingLocationsCount { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public uint SpawnLocationsOffset { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public int SpawnLocationsCount { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public uint TriggerOffsetListOffset { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public int TriggerOffsetListCount { get; set; } + public int miVersionNumber { get; set; } //0x0 0x4 int32_t miVersionNumber Resource version 42 + public uint muSize { get; set; } //0x4 0x4 uint32_t muSize Resource size + //0x8 0x8 padding + public Vector3I mPlayerStartPosition { get; set; } //0x10 0x10 Vector3 mPlayerStartPosition Dev start position + public Vector3I mPlayerStartDirection { get; set; } //0x20 0x10 Vector3 mPlayerStartDirection Dev start direction + public uint mpLandmarks { get; set; } //0x30 0x8 Landmark* mpLandmarks Landmarks + public int miLandmarkCount { get; set; } //0x38 0x4 int32_t miLandmarkCount Number of landmarks + public int miOnlineLandmarkCount { get; set; } //0x3C 0x4 int32_t miOnlineLandmarkCount Number of online landmarks + public uint mpSignatureStunts { get; set; } // 0x40 0x8 SignatureStunt* mpSignatureStunts Signature stunts + public int miSignatureStuntCount { get; set; } //0x48 0x4 int32_t miSignatureStuntCount Number of signature stunts + //0x4C 0x4 padding + public uint mpGenericRegions { get; set; } //0x50 0x8 GenericRegion* mpGenericRegions Generic regions + public int miGenericRegionCount { get; set; } //0x58 0x4 int32_t miGenericRegionCount Number of generic regions + //0x5C 0x4 padding + public uint mpKillzones { get; set; } //0x60 0x8 Killzone* mpKillzones Killzones + public int miKillzoneCount { get; set; } // 0x68 0x4 int32_t miKillzoneCount Number of killzones + //0x6C 0x4 padding + public uint mpBlackspots { get; set; } //0x70 0x8 Blackspot* mpBlackspots Blackspots + public int miBlackspotCount { get; set; } //0x78 0x4 int32_t miBlackspotCount Number of blackspots + //0x7C 0x4 padding + public uint mpVFXBoxRegions { get; set; } //0x80 0x8 VFXBoxRegion* mpVFXBoxRegions VFX box regions + public int miVFXBoxRegionCount { get; set; } //0x88 0x4 int32_t miVFXBoxRegionCount Number of VFX box regions + //0x8C 0x4 padding + public uint mpRoamingLocations { get; set; } //0x90 0x8 RoamingLocation* mpRoamingLocations Roaming locations + public int miRoamingLocationCount { get; set; } //0x98 0x4 int32_t miRoamingLocationCount Number of roaming locations + //0x9C 0x4 padding + public uint mpSpawnLocations { get; set; } //0xA0 0x8 SpawnLocation* mpSpawnLocations Spawn locations + public int miSpawnLocationCount { get; set; } //0xA8 0x4 int32_t miSpawnLocationCount Number of spawn locations + //0xAC 0x4 padding + public uint mppRegions { get; set; } //0xB0 0x8 TriggerRegion** mppRegions Trigger regions Generic regions used in Killzones, landmarks for debug only + public int miRegionCount { get; set; } //0xB8 0x4 int32_t miRegionCount Number of regions + //0xBC 0x4 padding - public List LandmarkTriggers { get; set; } - public List GenericRegionTriggers { get; set; } - public List Section4Entries { get; set; } - public List RoamingLocationEntries { get; set; } - public List SpawnLocationEntries { get; set; } - [Category("Undefined Datastructure"), Description("This is currently not implented and can be ignored")] - public List TriggerOffsets { get; set; } public TriggerData() { - LandmarkTriggers = new List(); - GenericRegionTriggers = new List(); - Section4Entries = new List(); - RoamingLocationEntries = new List(); - SpawnLocationEntries = new List(); - TriggerOffsets = new List(); } private void Clear() { - FormatRevision = default; - FileSize = default; - Unknown0C = default; - Unknown10 = default; - DevSpawnPositionX = default; - DevSpawnPositionY = default; - DevSpawnPositionZ = default; - DevSpawnUnknownHash = default; - DevSpawnRotationX = default; - DevSpawnRotationY = default; - DevSpawnRotationZ = default; - DevSpawnUnknownFloat = default; - LandmarkTriggersOffset = default; - LandmarkTriggersCount = default; - LandmarkNonFinishLineCount = default; - BlackspotTriggersOffset = default; - BlackspotTriggersCount = default; - GenericRegionTriggersOffset = default; - GenericRegionTriggersCount = default; - Section4Offset = default; - Section4Count = default; - VFXBoxRegionOffset = default; - VFXBoxRegionCount = default; - StartPositionsOffset = default; - StartPositionsCount = default; - RoamingLocationsOffset = default; - RoamingLocationsCount = default; - SpawnLocationsOffset = default; - SpawnLocationsCount = default; - TriggerOffsetListOffset = default; - TriggerOffsetListCount = default; - - LandmarkTriggers.Clear(); - GenericRegionTriggers.Clear(); - Section4Entries.Clear(); - RoamingLocationEntries.Clear(); - SpawnLocationEntries.Clear(); - TriggerOffsets.Clear(); } public bool Read(BundleEntry entry, ILoader loader = null) @@ -258,213 +161,6 @@ public bool Read(BundleEntry entry, ILoader loader = null) BinaryReader2 br = new BinaryReader2(ms); br.BigEndian = entry.Console; - FormatRevision = br.ReadInt32(); - FileSize = br.ReadUInt32(); - Unknown0C = br.ReadInt32(); - Unknown10 = br.ReadInt32(); - DevSpawnPositionX = br.ReadSingle(); - DevSpawnPositionY = br.ReadSingle(); - DevSpawnPositionZ = br.ReadSingle(); - DevSpawnUnknownHash = br.ReadUInt32(); - DevSpawnRotationX = br.ReadSingle(); - DevSpawnRotationY = br.ReadSingle(); - DevSpawnRotationZ = br.ReadSingle(); - DevSpawnUnknownFloat = br.ReadSingle(); - LandmarkTriggersOffset = br.ReadUInt32(); - LandmarkTriggersCount = br.ReadInt32(); - LandmarkNonFinishLineCount = br.ReadInt32(); - BlackspotTriggersOffset = br.ReadUInt32(); - BlackspotTriggersCount = br.ReadInt32(); - GenericRegionTriggersOffset = br.ReadUInt32(); - GenericRegionTriggersCount = br.ReadInt32(); - Section4Offset = br.ReadUInt32(); - Section4Count = br.ReadInt32(); - VFXBoxRegionOffset = br.ReadUInt32(); - VFXBoxRegionCount = br.ReadInt32(); - StartPositionsOffset = br.ReadUInt32(); - StartPositionsCount = br.ReadInt32(); - RoamingLocationsOffset = br.ReadUInt32(); - RoamingLocationsCount = br.ReadInt32(); - SpawnLocationsOffset = br.ReadUInt32(); - SpawnLocationsCount = br.ReadInt32(); - TriggerOffsetListOffset = br.ReadUInt32(); - TriggerOffsetListCount = br.ReadInt32(); - - br.BaseStream.Position = LandmarkTriggersOffset; - - for (int i = 0; i < LandmarkTriggersCount; i++) - { - LandmarkTrigger landmarkTrigger = new LandmarkTrigger(); - - landmarkTrigger.PositionX = br.ReadSingle(); - landmarkTrigger.PositionY = br.ReadSingle(); - landmarkTrigger.PositionZ = br.ReadSingle(); - landmarkTrigger.RotationX = br.ReadSingle(); - landmarkTrigger.RotationY = br.ReadSingle(); - landmarkTrigger.RotationZ = br.ReadSingle(); - landmarkTrigger.SizeX = br.ReadSingle(); - landmarkTrigger.SizeY = br.ReadSingle(); - landmarkTrigger.SizeZ = br.ReadSingle(); - landmarkTrigger.GameDBID = br.ReadInt32(); - landmarkTrigger.GlobalIndex = br.ReadInt16(); - landmarkTrigger.Type = br.ReadByte(); - landmarkTrigger.UnknownByte2B = br.ReadByte(); - landmarkTrigger.UnknownOffset = br.ReadUInt32(); - landmarkTrigger.UnknownByte30 = br.ReadByte(); - landmarkTrigger.LocalIndex = br.ReadByte(); - landmarkTrigger.Subtype = br.ReadByte(); - landmarkTrigger.UnknownByte33 = br.ReadByte(); - - LandmarkTriggers.Add(landmarkTrigger); - } - - br.BaseStream.Position = GenericRegionTriggersOffset; - - for (int i = 0; i < GenericRegionTriggersCount; i++) - { - GenericRegionTrigger genericRegionTrigger = new GenericRegionTrigger(); - genericRegionTrigger.PositionX = br.ReadSingle(); - genericRegionTrigger.PositionY = br.ReadSingle(); - genericRegionTrigger.PositionZ = br.ReadSingle(); - genericRegionTrigger.RotationX = br.ReadSingle(); - genericRegionTrigger.RotationY = br.ReadSingle(); - genericRegionTrigger.RotationZ = br.ReadSingle(); - genericRegionTrigger.SizeX = br.ReadSingle(); - genericRegionTrigger.SizeY = br.ReadSingle(); - genericRegionTrigger.SizeZ = br.ReadSingle(); - genericRegionTrigger.GameDBID = br.ReadInt32(); - genericRegionTrigger.Index = br.ReadInt16(); - genericRegionTrigger.Type = br.ReadByte(); - genericRegionTrigger.UnknownByte2B = br.ReadByte(); - genericRegionTrigger.GameDBID2 = br.ReadInt32(); - genericRegionTrigger.UnknownShort30 = br.ReadInt16(); - genericRegionTrigger.UnknownShort32 = br.ReadInt16(); - genericRegionTrigger.UnknownByte34 = br.ReadByte(); - genericRegionTrigger.UnknownByte35 = br.ReadByte(); - genericRegionTrigger.Subtype = br.ReadByte(); - genericRegionTrigger.UnknownByte37 = br.ReadByte(); - - GenericRegionTriggers.Add(genericRegionTrigger); - } - - br.BaseStream.Position = Section4Offset; - - for (int i = 0; i < Section4Count; i++) - { - TriggerSection4Entry section4Entry = new TriggerSection4Entry(); - - section4Entry.TriggerOffsetListOffset = br.ReadUInt32(); - section4Entry.TriggerOffsetListCount = br.ReadInt32(); - section4Entry.GameDBIDListOffset = br.ReadUInt32(); - section4Entry.GameDBIDListCount = br.ReadInt32(); - - long oldPosition = br.BaseStream.Position; - - br.BaseStream.Position = section4Entry.TriggerOffsetListOffset; - section4Entry.Triggers = new List(); - for (int j = 0; j < section4Entry.TriggerOffsetListCount; j++) - { - GenericRegionTrigger region = new GenericRegionTrigger(); - region.PositionX = br.ReadSingle(); - region.PositionY = br.ReadSingle(); - region.PositionZ = br.ReadSingle(); - region.RotationX = br.ReadSingle(); - region.RotationY = br.ReadSingle(); - region.RotationZ = br.ReadSingle(); - region.SizeX = br.ReadSingle(); - region.SizeY = br.ReadSingle(); - region.SizeZ = br.ReadSingle(); - region.GameDBID = br.ReadInt32(); - region.Index = br.ReadInt16(); - region.Type = br.ReadByte(); - region.UnknownByte2B = br.ReadByte(); - region.GameDBID2 = br.ReadInt32(); - region.UnknownShort30 = br.ReadInt16(); - region.UnknownShort32 = br.ReadInt16(); - region.UnknownByte34 = br.ReadByte(); - region.UnknownByte35 = br.ReadByte(); - region.Subtype = br.ReadByte(); - region.UnknownByte37 = br.ReadByte(); - section4Entry.Triggers.Add(region); - } - - br.BaseStream.Position = section4Entry.GameDBIDListOffset; - section4Entry.GameDBIDs = new List(); - for (int j = 0; j < section4Entry.GameDBIDListCount; j++) - { - section4Entry.GameDBIDs.Add(br.ReadInt64()); - } - - br.BaseStream.Position = oldPosition; - - Section4Entries.Add(section4Entry); - } - - br.BaseStream.Position = RoamingLocationsOffset; - - for (int i = 0; i < RoamingLocationsCount; i++) - { - RoamingLocation roamingLocation = new RoamingLocation(); - - roamingLocation.PositionX = br.ReadSingle(); - roamingLocation.PositionY = br.ReadSingle(); - roamingLocation.PositionZ = br.ReadSingle(); - roamingLocation.UnknownHash = br.ReadUInt32(); - roamingLocation.Subdistrict = br.ReadByte(); - roamingLocation.UnknownByte11 = br.ReadByte(); - roamingLocation.UnknownByte12 = br.ReadByte(); - roamingLocation.UnknownByte13 = br.ReadByte(); - roamingLocation.UnknownInt14 = br.ReadInt32(); - roamingLocation.UnknownInt18 = br.ReadInt32(); - roamingLocation.UnknownInt1C = br.ReadInt32(); - - RoamingLocationEntries.Add(roamingLocation); - } - - br.BaseStream.Position = SpawnLocationsOffset; - - for (int i = 0; i < SpawnLocationsCount; i++) - { - SpawnLocation spawnLocation = new SpawnLocation(); - - spawnLocation.PositionX = br.ReadSingle(); - spawnLocation.PositionY = br.ReadSingle(); - spawnLocation.PositionZ = br.ReadSingle(); - spawnLocation.UnknownHash = br.ReadUInt32(); - spawnLocation.RotationX = br.ReadSingle(); - spawnLocation.RotationY = br.ReadSingle(); - spawnLocation.RotationZ = br.ReadSingle(); - spawnLocation.UnknownFloat1C = br.ReadSingle(); - spawnLocation.JunkyardGameDBID = br.ReadInt64(); - spawnLocation.UnknownByte28 = br.ReadByte(); - spawnLocation.UnknownByte29 = br.ReadByte(); - spawnLocation.UnknownByte30 = br.ReadByte(); - spawnLocation.UnknownByte31 = br.ReadByte(); - spawnLocation.UnknownInt32 = br.ReadInt32(); - - foreach (GenericRegionTrigger trigger in GenericRegionTriggers) - { - if (trigger.GameDBID == spawnLocation.JunkyardGameDBID) - { - spawnLocation.JunkyardTrigger = trigger; - break; - } - } - - SpawnLocationEntries.Add(spawnLocation); - } - - br.BaseStream.Position = TriggerOffsetListOffset; - - for (int i = 0; i < TriggerOffsetListCount; i++) - { - uint section6Entry = br.ReadUInt32(); - TriggerOffsets.Add(section6Entry); - } - - br.Close(); - ms.Close(); - return true; } @@ -489,203 +185,6 @@ public bool Write(BundleEntry entry) MemoryStream ms = new MemoryStream(); BinaryWriter bw = new BinaryWriter(ms); - bw.Write(FormatRevision); - long fileSizeOffset = bw.BaseStream.Position; - bw.Write((int)0); - bw.Write(Unknown0C); - bw.Write(Unknown10); - bw.Write(DevSpawnPositionX); - bw.Write(DevSpawnPositionY); - bw.Write(DevSpawnPositionZ); - bw.Write(DevSpawnUnknownHash); - bw.Write(DevSpawnRotationX); - bw.Write(DevSpawnRotationY); - bw.Write(DevSpawnRotationZ); - bw.Write(DevSpawnUnknownFloat); - bw.Write(LandmarkTriggersOffset); - bw.Write(LandmarkTriggersCount); - bw.Write(LandmarkNonFinishLineCount); - bw.Write(BlackspotTriggersOffset); - bw.Write(BlackspotTriggersCount); - bw.Write(GenericRegionTriggersOffset); - bw.Write(GenericRegionTriggersCount); - bw.Write(Section4Offset); - bw.Write(Section4Count); - bw.Write(VFXBoxRegionOffset); - bw.Write(VFXBoxRegionCount); - bw.Write(StartPositionsOffset); - bw.Write(StartPositionsCount); - bw.Write(RoamingLocationsOffset); - bw.Write(RoamingLocationsCount); - bw.Write(SpawnLocationsOffset); - bw.Write(SpawnLocationsCount); - bw.Write(TriggerOffsetListOffset); - bw.Write(TriggerOffsetListCount); - - bw.BaseStream.Position = LandmarkTriggersOffset; - - for (int i = 0; i < LandmarkTriggers.Count; i++) - { - LandmarkTrigger landmarkTrigger = LandmarkTriggers[i]; - - bw.Write(landmarkTrigger.PositionX); - bw.Write(landmarkTrigger.PositionY); - bw.Write(landmarkTrigger.PositionZ); - bw.Write(landmarkTrigger.RotationX); - bw.Write(landmarkTrigger.RotationY); - bw.Write(landmarkTrigger.RotationZ); - bw.Write(landmarkTrigger.SizeX); - bw.Write(landmarkTrigger.SizeY); - bw.Write(landmarkTrigger.SizeZ); - bw.Write(landmarkTrigger.GameDBID); - bw.Write(landmarkTrigger.GlobalIndex); - bw.Write(landmarkTrigger.Type); - bw.Write(landmarkTrigger.UnknownByte2B); - bw.Write(landmarkTrigger.UnknownOffset); - bw.Write(landmarkTrigger.UnknownByte30); - bw.Write(landmarkTrigger.LocalIndex); - bw.Write(landmarkTrigger.Subtype); - bw.Write(landmarkTrigger.UnknownByte33); - } - - bw.BaseStream.Position = GenericRegionTriggersOffset; - - foreach (GenericRegionTrigger genericRegionTrigger in GenericRegionTriggers) - { - bw.Write(genericRegionTrigger.PositionX); - bw.Write(genericRegionTrigger.PositionY); - bw.Write(genericRegionTrigger.PositionZ); - bw.Write(genericRegionTrigger.RotationX); - bw.Write(genericRegionTrigger.RotationY); - bw.Write(genericRegionTrigger.RotationZ); - bw.Write(genericRegionTrigger.SizeX); - bw.Write(genericRegionTrigger.SizeY); - bw.Write(genericRegionTrigger.SizeZ); - bw.Write(genericRegionTrigger.GameDBID); - bw.Write(genericRegionTrigger.Index); - bw.Write(genericRegionTrigger.Type); - bw.Write(genericRegionTrigger.UnknownByte2B); - bw.Write(genericRegionTrigger.GameDBID2); - bw.Write(genericRegionTrigger.UnknownShort30); - bw.Write(genericRegionTrigger.UnknownShort32); - bw.Write(genericRegionTrigger.UnknownByte34); - bw.Write(genericRegionTrigger.UnknownByte35); - bw.Write(genericRegionTrigger.Subtype); - bw.Write(genericRegionTrigger.UnknownByte37); - } - - bw.BaseStream.Position = Section4Offset; - - foreach (TriggerSection4Entry section4Entry in Section4Entries) - { - bw.Write(section4Entry.TriggerOffsetListOffset); - bw.Write(section4Entry.TriggerOffsetListCount); - bw.Write(section4Entry.GameDBIDListOffset); - bw.Write(section4Entry.GameDBIDListCount); - - long oldPosition = bw.BaseStream.Position; - - bw.BaseStream.Position = section4Entry.TriggerOffsetListOffset; - foreach (GenericRegionTrigger trigger in section4Entry.Triggers) - { - bw.Write(trigger.PositionX); - bw.Write(trigger.PositionY); - bw.Write(trigger.PositionZ); - bw.Write(trigger.RotationX); - bw.Write(trigger.RotationY); - bw.Write(trigger.RotationZ); - bw.Write(trigger.SizeX); - bw.Write(trigger.SizeY); - bw.Write(trigger.SizeZ); - bw.Write(trigger.GameDBID); - bw.Write(trigger.Index); - bw.Write(trigger.Type); - bw.Write(trigger.UnknownByte2B); - bw.Write(trigger.GameDBID2); - bw.Write(trigger.UnknownShort30); - bw.Write(trigger.UnknownShort32); - bw.Write(trigger.UnknownByte34); - bw.Write(trigger.UnknownByte35); - bw.Write(trigger.Subtype); - bw.Write(trigger.UnknownByte37); - } - bw.BaseStream.Position = section4Entry.GameDBIDListOffset; - foreach (long id in section4Entry.GameDBIDs) - { - bw.Write(id); - } - bw.BaseStream.Position = oldPosition; - } - - bw.BaseStream.Position = RoamingLocationsOffset; - - for (int i = 0; i < RoamingLocationEntries.Count; i++) - { - RoamingLocation roamingLocation = RoamingLocationEntries[i]; - - bw.Write(roamingLocation.PositionX); - bw.Write(roamingLocation.PositionY); - bw.Write(roamingLocation.PositionZ); - bw.Write(roamingLocation.UnknownHash); - bw.Write(roamingLocation.Subdistrict); - bw.Write(roamingLocation.UnknownByte11); - bw.Write(roamingLocation.UnknownByte12); - bw.Write(roamingLocation.UnknownByte13); - bw.Write(roamingLocation.UnknownInt14); - bw.Write(roamingLocation.UnknownInt18); - bw.Write(roamingLocation.UnknownInt1C); - } - - bw.BaseStream.Position = SpawnLocationsOffset; - - for (int i = 0; i < SpawnLocationEntries.Count; i++) - { - SpawnLocation spawnLocation = SpawnLocationEntries[i]; - - bw.Write(spawnLocation.PositionX); - bw.Write(spawnLocation.PositionY); - bw.Write(spawnLocation.PositionZ); - bw.Write(spawnLocation.UnknownHash); - bw.Write(spawnLocation.RotationX); - bw.Write(spawnLocation.RotationY); - bw.Write(spawnLocation.RotationZ); - bw.Write(spawnLocation.UnknownFloat1C); - bw.Write(spawnLocation.JunkyardGameDBID); - bw.Write(spawnLocation.UnknownByte28); - bw.Write(spawnLocation.UnknownByte29); - bw.Write(spawnLocation.UnknownByte30); - bw.Write(spawnLocation.UnknownByte31); - bw.Write(spawnLocation.UnknownInt32); - } - - bw.BaseStream.Position = TriggerOffsetListOffset; - - for (int i = 0; i < TriggerOffsets.Count; i++) - { - uint section6Entry = TriggerOffsets[i]; - bw.Write(section6Entry); - } - - long fileSize = bw.BaseStream.Position; - bw.BaseStream.Position = fileSizeOffset; - bw.Write((int)fileSize); - - bw.BaseStream.Position = fileSize; - - long paddingCount = 16 - (bw.BaseStream.Position % 16); - for (int i = 0; i < paddingCount; i++) - bw.Write((byte)0); - - bw.Flush(); - - byte[] data = ms.ToArray(); - - bw.Close(); - ms.Close(); - - entry.EntryBlocks[0].Data = data; - entry.Dirty = true; - return true; } } From ce0575d80f632c64f534b35efc5e74f77d82785e Mon Sep 17 00:00:00 2001 From: Niaz Date: Sun, 23 Apr 2023 12:47:17 +0200 Subject: [PATCH 06/18] Implement Reading and Writing --- BaseHandlers/BaseHandlers.csproj | 3 + BaseHandlers/TriggerData.cs | 972 ++++++++++++++++++--- BaseHandlers/TriggerDataEditor.Designer.cs | 5 +- BaseHandlers/TriggerDataEditor.cs | 6 +- BaseHandlers/TriggerDataEditor.resx | 120 +++ 5 files changed, 988 insertions(+), 118 deletions(-) create mode 100644 BaseHandlers/TriggerDataEditor.resx diff --git a/BaseHandlers/BaseHandlers.csproj b/BaseHandlers/BaseHandlers.csproj index dfaac9c..4362c78 100644 --- a/BaseHandlers/BaseHandlers.csproj +++ b/BaseHandlers/BaseHandlers.csproj @@ -122,6 +122,9 @@ InstanceListEditor.cs + + TriggerDataEditor.cs + diff --git a/BaseHandlers/TriggerData.cs b/BaseHandlers/TriggerData.cs index a19ecb3..54f3224 100644 --- a/BaseHandlers/TriggerData.cs +++ b/BaseHandlers/TriggerData.cs @@ -9,157 +9,667 @@ namespace BaseHandlers { + public class CgsID + { + private UInt64 m_id; + + public UInt64 ID + { + get { return m_id; } + set { m_id = value; } + } + + public static CgsID FromByteArray(byte[] data, int startIndex) + { + UInt64 id = BitConverter.ToUInt64(data, startIndex); + CgsID result = new CgsID(); + result.ID = id; + return new CgsID(); + } + + public byte[] ToByteArray() + { + return BitConverter.GetBytes(m_id); + } + + public void Read(BinaryReader reader) + { + m_id = reader.ReadUInt64(); + } + + public void Write(BinaryWriter writer) + { + writer.Write(m_id); + } + + public override string ToString() + { + return string.Format("{0:X16}", m_id); + } + } + public enum RegionType + { + E_TYPE_LANDMARK = 0, + E_TYPE_BLACKSPOT = 1, + E_TYPE_GENERIC_REGION = 2, + E_TYPE_VFXBOX_REGION = 3, + E_TYPE_COUNT = 4 + } public struct StartingGrid { - public Vector3I[] maStartingPositions; //0x0 0x80 Vector3[8] maStartingPositions - public Vector3I[] maStartingDirections; //0x80 0x80 Vector3[8] maStartingDirections + public Vector3I[] StartingPositions { get; set; } + public Vector3I[] StartingDirections { get; set; } + + public void Read(BinaryReader reader) + { + StartingPositions = new Vector3I[8]; + for (int i = 0; i < 8; i++) + { + StartingPositions[i] = new Vector3I( + reader.ReadSingle(), + reader.ReadSingle(), + reader.ReadSingle(), reader.ReadSingle()); + } + + StartingDirections = new Vector3I[8]; + for (int i = 0; i < 8; i++) + { + StartingDirections[i] = new Vector3I( + reader.ReadSingle(), + reader.ReadSingle(), + reader.ReadSingle(), reader.ReadSingle()); + } + } + + public void Write(BinaryWriter writer) + { + for (int i = 0; i < 8; i++) + { + writer.Write(StartingPositions[i].X); + writer.Write(StartingPositions[i].Y); + writer.Write(StartingPositions[i].Z); + writer.Write(StartingPositions[i].S); + } + + for (int i = 0; i < 8; i++) + { + writer.Write(StartingDirections[i].X); + writer.Write(StartingDirections[i].Y); + writer.Write(StartingDirections[i].Z); + writer.Write(StartingDirections[i].S); + } + } } - public struct BoxRegion { - - public float mPositionX { get; set; } //0x0 0x4 float32_t mPositionX - public float mPositionY { get; set; } //0x4 0x4 float32_t mPositionY - public float mPositionZ { get; set; } //0x8 0x4 float32_t mPositionZ - public float mRotationX { get; set; } //0xC 0x4 float32_t mRotationX - public float mRotationY { get; set; } //0x10 0x4 float32_t mRotationY - public float mRotationZ { get; set; } //0x14 0x4 float32_t mRotationZ - public float mDimensionX { get; set; } //0x18 0x4 float32_t mDimensionX - public float mDimensionY { get; set; } //0x1C 0x4 float32_t mDimensionY - public float mDimensionZ { get; set; } //0x20 0x4 float32_t mDimensionZ + public class BoxRegion + { + public float PositionX { get; set; } + public float PositionY { get; set; } + public float PositionZ { get; set; } + public float RotationX { get; set; } + public float RotationY { get; set; } + public float RotationZ { get; set; } + public float DimensionX { get; set; } + public float DimensionY { get; set; } + public float DimensionZ { get; set; } + + public void Read(BinaryReader reader) + { + PositionX = reader.ReadSingle(); + PositionY = reader.ReadSingle(); + PositionZ = reader.ReadSingle(); + RotationX = reader.ReadSingle(); + RotationY = reader.ReadSingle(); + RotationZ = reader.ReadSingle(); + DimensionX = reader.ReadSingle(); + DimensionY = reader.ReadSingle(); + DimensionZ = reader.ReadSingle(); + } + + public void Write(BinaryWriter writer) + { + writer.Write(PositionX); + writer.Write(PositionY); + writer.Write(PositionZ); + writer.Write(RotationX); + writer.Write(RotationY); + writer.Write(RotationZ); + writer.Write(DimensionX); + writer.Write(DimensionY); + writer.Write(DimensionZ); + } } - public struct TriggerRegion { - public BoxRegion mBoxRegion; //0x0 0x24 BoxRegion mBoxRegion - public int mId; //0x24 0x4 int32_t mId - public Int16 miRegionIndex; //0x28 0x2 int16_t miRegionIndex Region index - public short meType; //0x2A 0x1 uint8_t meType Region type See type - public short muPad; //0x2B 0x1 uint8_t[1] muPad + public class TriggerRegion + { + public BoxRegion mBoxRegion { get; set; } + public int mId { get; set; } + public short miRegionIndex { get; set; } + public RegionType meType { get; set; } + private byte[] muPad { get; set; } + + public virtual void Read(BinaryReader reader) + { + mBoxRegion = new BoxRegion(); + mBoxRegion.Read(reader); + mId = reader.ReadInt32(); + miRegionIndex = reader.ReadInt16(); + meType = (RegionType)reader.ReadByte(); + muPad = reader.ReadBytes(1); + } + + public virtual void Write(BinaryWriter writer) + { + mBoxRegion.Write(writer); + + writer.Write(mId); + writer.Write(miRegionIndex); + writer.Write((byte)meType); + writer.Write(muPad); + } } - public struct Landmark + public class Landmark : TriggerRegion { - public TriggerRegion triggerRegion; //0x0 0x2C TriggerRegion super_TriggerRegion - //0x2C 0x4 padding - public int mpaStartingGrids; // 0x30 0x8 StartingGrid* mpaStartingGrids StartingGrid - public short miStartingGridCount { get; set; } //0x38 0x1 int8_t miStartingGridCount Always 0 - public byte muDesignIndex { get; set; } //0x39 0x1 uint8_t muDesignIndex Landmark index - public byte muDistrict { get; set; } //0x3A 0x1 uint8_t muDistrict District ID Always 3. See Districts - public byte mu8Flags { get; set; } //0x3B 0x1 uint8_t mu8Flags Flags See flags - //0x3C 0x4 padding + public List mpaStartingGrids { get; set; } + + private long startingGridsOffset; + public byte miStartingGridCount { get; set; } + public byte muDesignIndex { get; set; } + public byte muDistrict { get; set; } + public byte mu8Flags { get; set; } + + public void Read(BinaryReader reader) + { + base.Read(reader); + startingGridsOffset = reader.ReadUInt32(); + miStartingGridCount = reader.ReadByte(); + muDesignIndex = reader.ReadByte(); + muDistrict = reader.ReadByte(); + mu8Flags = reader.ReadByte(); + + // Somehow StartingGrid is never used + long currentPosition = reader.BaseStream.Position; + reader.BaseStream.Position = startingGridsOffset; + mpaStartingGrids = new List(); + for (int i = 0; i < miStartingGridCount; i++) + { + StartingGrid startingGrid = new StartingGrid(); + startingGrid.Read(reader); + mpaStartingGrids.Add(startingGrid); + } + reader.BaseStream.Position = currentPosition; + + } + + public void Write(BinaryWriter writer) + { + base.Write(writer); + writer.Write((uint)startingGridsOffset); + writer.Write(miStartingGridCount); + writer.Write(muDesignIndex); + writer.Write(muDistrict); + writer.Write(mu8Flags); + // To-Do: Does not handle saving startingGridsOffsetAtAll + /* + for (int i = 0; i < miStartingGridCount; i++) + { + mpaStartingGrids[i].Write(writer); + } + */ + } } - public struct GenericRegion + public class GenericRegion : TriggerRegion { - public TriggerRegion triggerRegion; //0x0 0x2C TriggerRegion super_TriggerRegion - public int miGroupID { get; set; } //0x2C 0x4 int32_t miGroupID GameDB ID - public short miCameraCut1 { get; set; } //0x30 0x2 int16_t miCameraCut1 - public short miCameraCut2 { get; set; } //0x32 0x2 int16_t miCameraCut2 - public byte miCameraType1 { get; set; } //0x34 0x1 int8_t miCameraType1 Stunt camera type 1 See stunt camera type - public byte miCameraType2 { get; set; } //0x35 0x1 int8_t miCameraType2 Stunt camera type 2 See stunt camera type - public byte meType { get; set; } //0x36 0x1 uint8_t meType Generic region type See type - public byte miIsOneWay { get; set; } //0x37 0x1 int8_t miIsOneWay + public int GroupID { get; set; } + public short CameraCut1 { get; set; } + public short CameraCut2 { get; set; } + public sbyte CameraType1 { get; set; } + public sbyte CameraType2 { get; set; } + public byte Type { get; set; } + public sbyte IsOneWay { get; set; } + + public void Read(BinaryReader reader) + { + base.Read(reader); + GroupID = reader.ReadInt32(); + CameraCut1 = reader.ReadInt16(); + CameraCut2 = reader.ReadInt16(); + CameraType1 = reader.ReadSByte(); + CameraType2 = reader.ReadSByte(); + Type = reader.ReadByte(); + IsOneWay = reader.ReadSByte(); + } + + public void Write(BinaryWriter writer) + { + base.Write(writer); + writer.Write(GroupID); + writer.Write(CameraCut1); + writer.Write(CameraCut2); + writer.Write(CameraType1); + writer.Write(CameraType2); + writer.Write(Type); + writer.Write(IsOneWay); + } } - public struct Blackspot { - public TriggerRegion triggerRegion; //0x0 0x2C TriggerRegion super_TriggerRegion - public ushort muScoreType; //0x2C 0x1 uint8_t muScoreType See score type - //0x2D 0x3 padding - public int miScoreAmount; //0x30 0x4 int32_t miScoreAmount + public class Blackspot : TriggerRegion + { + public byte muScoreType { get; set; } + public int miScoreAmount { get; set; } + + public override void Read(BinaryReader reader) + { + base.Read(reader); + + muScoreType = reader.ReadByte(); + reader.ReadBytes(3); // Padding + miScoreAmount = reader.ReadInt32(); + } + + public override void Write(BinaryWriter writer) + { + base.Write(writer); + + writer.Write(muScoreType); + writer.Write(new byte[3]); // Padding + writer.Write(miScoreAmount); + } } - public struct Killzone + public class Killzone { - public int mppTriggers;//0x0 0x8 GenericRegion** mppTriggers GenericRegion pointer array - public int miTriggerCount; //0x8 0x4 int32_t miTriggerCount Number of generic regions - //0xC 0x4 padding - public int mpRegionIds; //0x10 0x8 CgsID* mpRegionIds Regions GameDB IDs - public int miRegionIdCount; //0x18 0x4 int32_t miRegionIdCount Number of region IDs - //0x1C 0x4 padding + public List TriggerIds { get; set; } + public CgsID[] RegionIds { get; set; } + + private long TriggerOffsetPosition; + + private long CGSIDOffsetPosition; + public void Read(BinaryReader reader) + { + // Read the trigger pointer array + long genericRegionOffset = reader.ReadUInt32(); + int TriggerCount = reader.ReadInt32(); + + // Read the region ID array + long cgsOffset = reader.ReadUInt32(); + int RegionIdCount = reader.ReadInt32(); + long currentPosition = reader.BaseStream.Position; + + reader.BaseStream.Position = genericRegionOffset; + uint[] Triggers = new uint[TriggerCount]; + for (int i = 0; i < TriggerCount; i++) + { + Triggers[i] = reader.ReadUInt32(); + } + + TriggerIds = new List(); + foreach (uint trigger in Triggers) + { + reader.BaseStream.Position = trigger; + GenericRegion region = new GenericRegion(); + region.Read(reader); + TriggerIds.Add(region.mId); + } + + reader.BaseStream.Position = cgsOffset; + RegionIds = new CgsID[RegionIdCount]; + for (int i = 0; i < RegionIds.Length; i++) + { + RegionIds[i] = new CgsID(); + RegionIds[i].Read(reader); + } + + reader.BaseStream.Position = currentPosition; + } + + public void Write(BinaryWriter writer) + { + TriggerOffsetPosition = writer.BaseStream.Position; + writer.WriteUniquePadding(4); + writer.Write(TriggerIds.Count); + CGSIDOffsetPosition = writer.BaseStream.Position; + writer.WriteUniquePadding(4); + writer.Write(RegionIds.Length); + } + + public void WritePointerStuff(BinaryWriter writer, Dictionary genericRegionOffsets) { + + long currentPosition = writer.BaseStream.Position; + writer.BaseStream.Position = TriggerOffsetPosition; + writer.Write((uint)currentPosition); + writer.BaseStream.Position = currentPosition; + foreach (int trigger in TriggerIds) + { + writer.Write(genericRegionOffsets[trigger]); + } + long paddingCount = 16 - (writer.BaseStream.Position % 16); + if (paddingCount < 16) + { + for (int i = 0; i < paddingCount; i++) + writer.Write((byte)0); + } + currentPosition = writer.BaseStream.Position; + writer.BaseStream.Position = CGSIDOffsetPosition; + writer.Write((uint)currentPosition); + writer.BaseStream.Position = currentPosition; + foreach (CgsID ids in RegionIds) + { + ids.Write(writer); + } + paddingCount = 16 - (writer.BaseStream.Position % 16); + if (paddingCount < 16) + { + for (int i = 0; i < paddingCount; i++) + writer.Write((byte)0); + } + + } + + } - public struct SignatureStunt { - public UInt64 mId; //0x0 0x8 CgsID mId GameDB ID - public long miCamera; //0x8 0x8 int64_t miCamera - public int mppStuntElements; //0x10 0x4 GenericRegion** mppStuntElements - public int miStuntElementCount; //0x14 0x4 int32_t miStuntElementCount - //0x1C 0x4 padding + public class SignatureStunt + { + public CgsID mId { get; set; } + public long miCamera { get; set; } + public List genericRegionIds { get; set; } + + public void Read(BinaryReader reader) + { + mId = new CgsID(); + mId.Read(reader); + miCamera = reader.ReadInt64(); + + uint mppStuntElementsOffset = reader.ReadUInt32(); + int miStuntElementCount = reader.ReadInt32(); + + long currentPosition = reader.BaseStream.Position; + reader.BaseStream.Position = mppStuntElementsOffset; + uint[] Triggers = new uint[miStuntElementCount]; + for (int i = 0; i < miStuntElementCount; i++) + { + Triggers[i] = reader.ReadUInt32(); + } + + genericRegionIds = new List(); + foreach (uint trigger in Triggers) + { + reader.BaseStream.Position = trigger; + GenericRegion region = new GenericRegion(); + region.Read(reader); + genericRegionIds.Add(region.mId); + } + reader.BaseStream.Position = currentPosition; + } + + // Write something in triggerIds, because we dont have the actual positions yet + public void WriteWithEmpty(BinaryWriter writer) + { + mId.Write(writer); + writer.Write(miCamera); + long GenericRegionIdsPosition = writer.BaseStream.Position; + writer.WriteUniquePadding(4); + writer.Write(genericRegionIds.Count); + + long currentPosition = writer.BaseStream.Position; + writer.BaseStream.Position = GenericRegionIdsPosition; + writer.Write(currentPosition); + writer.BaseStream.Position = currentPosition; + foreach (int trigger in genericRegionIds) + { + writer.Write((uint)trigger); + } + } + public void Write(BinaryWriter writer, Dictionary genericRegionOffsets) + { + mId.Write(writer); + writer.Write(miCamera); + long GenericRegionIdsPosition = writer.BaseStream.Position; + writer.WriteUniquePadding(4); + writer.Write(genericRegionIds.Count); + + + long currentPosition = writer.BaseStream.Position; + writer.BaseStream.Position = GenericRegionIdsPosition; + writer.Write(currentPosition); + writer.BaseStream.Position = currentPosition; + foreach (int trigger in genericRegionIds) + { + writer.Write(genericRegionOffsets[trigger]); + } + } } public struct RoamingLocation { - public Vector3I mPosition { get; set; } //0x0 0x10 Vector3 mPosition - public uint muDistrictIndex { get; set; } //0x10 0x1 uint8_t muDistrictIndex See Districts - //0x11 0xF padding - } + public Vector3I Position { get; set; } + public byte DistrictIndex { get; set; } + + public void Read(BinaryReader reader) { + + Position = new Vector3I( + reader.ReadSingle(), + reader.ReadSingle(), + reader.ReadSingle(), reader.ReadSingle()); + DistrictIndex = reader.ReadByte(); + // Read and discard padding + reader.ReadBytes(15); + } + + public void Write(BinaryWriter writer) + { + writer.Write(Position.X); + writer.Write(Position.Y); + writer.Write(Position.Z); + writer.Write(Position.S); + writer.Write(DistrictIndex); - public struct VFXBoxRegion { - public TriggerRegion region; //0x0 0x2C TriggerRegion super_TriggerRegion + // Write padding + writer.Write(new byte[15]); + } } - public struct SpawnLocation + public class VFXBoxRegion : TriggerRegion { - public Vector3I mPosition { get; set; } //0x0 0x10 Vector3 mPosition - public Vector3I mDirection { get; set; } //0x10 0x10 Vector3 mDirection - public UInt64 mJunkyardId { get; set; } //0x20 0x8 CgsID mJunkyardId GameDB ID - public uint muType { get; set; } //0x28 0x1 uint8_t muType Type See type - // 0x29 0x7 padding + public VFXBoxRegion() : base() + { + // Set meType to E_TYPE_VFXBOX_REGION + meType = RegionType.E_TYPE_VFXBOX_REGION; + } + public override void Read(BinaryReader reader) + { + base.Read(reader); + } + + public override void Write(BinaryWriter writer) + { + base.Write(writer); + } } + public class SpawnLocation + { + public Vector3I mPosition { get; set; } + public Vector3I mDirection { get; set; } + public CgsID mJunkyardId { get; set; } + public byte muType { get; set; } + private byte[] padding = new byte[7]; + public void Read(BinaryReader reader) + { + mPosition = new Vector3I(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); + mDirection = new Vector3I(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); + mJunkyardId = new CgsID(); + mJunkyardId.Read(reader); + muType = reader.ReadByte(); + padding = reader.ReadBytes(7); + } - public class TriggerData : IEntryData - { - public int miVersionNumber { get; set; } //0x0 0x4 int32_t miVersionNumber Resource version 42 - public uint muSize { get; set; } //0x4 0x4 uint32_t muSize Resource size - //0x8 0x8 padding - public Vector3I mPlayerStartPosition { get; set; } //0x10 0x10 Vector3 mPlayerStartPosition Dev start position - public Vector3I mPlayerStartDirection { get; set; } //0x20 0x10 Vector3 mPlayerStartDirection Dev start direction - public uint mpLandmarks { get; set; } //0x30 0x8 Landmark* mpLandmarks Landmarks - public int miLandmarkCount { get; set; } //0x38 0x4 int32_t miLandmarkCount Number of landmarks - public int miOnlineLandmarkCount { get; set; } //0x3C 0x4 int32_t miOnlineLandmarkCount Number of online landmarks - public uint mpSignatureStunts { get; set; } // 0x40 0x8 SignatureStunt* mpSignatureStunts Signature stunts - public int miSignatureStuntCount { get; set; } //0x48 0x4 int32_t miSignatureStuntCount Number of signature stunts - //0x4C 0x4 padding - public uint mpGenericRegions { get; set; } //0x50 0x8 GenericRegion* mpGenericRegions Generic regions - public int miGenericRegionCount { get; set; } //0x58 0x4 int32_t miGenericRegionCount Number of generic regions - //0x5C 0x4 padding - public uint mpKillzones { get; set; } //0x60 0x8 Killzone* mpKillzones Killzones - public int miKillzoneCount { get; set; } // 0x68 0x4 int32_t miKillzoneCount Number of killzones - //0x6C 0x4 padding - public uint mpBlackspots { get; set; } //0x70 0x8 Blackspot* mpBlackspots Blackspots - public int miBlackspotCount { get; set; } //0x78 0x4 int32_t miBlackspotCount Number of blackspots - //0x7C 0x4 padding - public uint mpVFXBoxRegions { get; set; } //0x80 0x8 VFXBoxRegion* mpVFXBoxRegions VFX box regions - public int miVFXBoxRegionCount { get; set; } //0x88 0x4 int32_t miVFXBoxRegionCount Number of VFX box regions - //0x8C 0x4 padding - public uint mpRoamingLocations { get; set; } //0x90 0x8 RoamingLocation* mpRoamingLocations Roaming locations - public int miRoamingLocationCount { get; set; } //0x98 0x4 int32_t miRoamingLocationCount Number of roaming locations - //0x9C 0x4 padding - public uint mpSpawnLocations { get; set; } //0xA0 0x8 SpawnLocation* mpSpawnLocations Spawn locations - public int miSpawnLocationCount { get; set; } //0xA8 0x4 int32_t miSpawnLocationCount Number of spawn locations - //0xAC 0x4 padding - public uint mppRegions { get; set; } //0xB0 0x8 TriggerRegion** mppRegions Trigger regions Generic regions used in Killzones, landmarks for debug only - public int miRegionCount { get; set; } //0xB8 0x4 int32_t miRegionCount Number of regions - //0xBC 0x4 padding - - - public TriggerData() - { - } - - private void Clear() + public void Write(BinaryWriter writer) { + writer.Write(mPosition.X); + writer.Write(mPosition.Y); + writer.Write(mPosition.Z); + writer.Write(mPosition.S); + writer.Write(mDirection.X); + writer.Write(mDirection.Y); + writer.Write(mDirection.Z); + writer.Write(mDirection.S); + mJunkyardId.Write(writer); + writer.Write(muType); + writer.Write(padding); } + } + + +public class TriggerData : IEntryData + { + public int miVersionNumber { get; set; } + public uint muSize { get; set; } + public Vector3I mPlayerStartPosition { get; set; } + public Vector3I mPlayerStartDirection { get; set; } + public List mpLandmarks { get; set; } + public int miOnlineLandmarkCount { get; set; } + public SignatureStunt[] mpSignatureStunts { get; set; } + public GenericRegion[] mpGenericRegions { get; set; } + public Killzone[] mpKillzones { get; set; } + public Blackspot[] mpBlackspots { get; set; } + public VFXBoxRegion[] mpVFXBoxRegions { get; set; } + public RoamingLocation[] mpRoamingLocations { get; set; } + public SpawnLocation[] mpSpawnLocations { get; set; } + private List TriggerOffsets { get; set; } + + public bool Read(BundleEntry entry, ILoader loader = null) { - Clear(); - MemoryStream ms = entry.MakeStream(); - BinaryReader2 br = new BinaryReader2(ms); - br.BigEndian = entry.Console; + BinaryReader2 reader = new BinaryReader2(ms); + reader.BigEndian = entry.Console; + + miVersionNumber = reader.ReadInt32(); + muSize = reader.ReadUInt32(); + reader.ReadBytes(8);// skip 8 bytes of padding + mPlayerStartPosition = new Vector3I(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); + mPlayerStartDirection = new Vector3I(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); + // read landmarks + long LandmarkTriggersOffset = reader.ReadUInt32(); + int miLandmarkCount = reader.ReadInt32(); + miOnlineLandmarkCount = reader.ReadInt32(); + + long SignatureStuntsOffset = reader.ReadUInt32(); + int miSignatureStuntCount = reader.ReadInt32(); + + long GenericRegionsOffset = reader.ReadUInt32(); + int miGenericRegionCount = reader.ReadInt32(); + + long KillzoneOffset = reader.ReadUInt32(); + int miKillzoneCount = reader.ReadInt32(); + + long BlackspotOffset = reader.ReadUInt32(); + int miBlackspotCount = reader.ReadInt32(); + + long VFXBoxRegionOffset = reader.ReadUInt32(); + int miVFXBoxRegionCount = reader.ReadInt32(); + + long RoamingLocationOffset = reader.ReadUInt32(); + int miRoamingLocationCount = reader.ReadInt32(); + + long SpawnLocationOffset = reader.ReadUInt32(); + int miSpawnLocationCount = reader.ReadInt32(); + + long TriggerRegionOffset = reader.ReadUInt32(); + int miRegionCount = reader.ReadInt32(); + + reader.BaseStream.Position = LandmarkTriggersOffset; + mpLandmarks = new List(); + for (int i = 0; i < miLandmarkCount; i++) + { + Landmark landmark = new Landmark(); + landmark.Read(reader); + mpLandmarks.Add(landmark); + } + + reader.BaseStream.Position = SignatureStuntsOffset; + // read signature stunts + mpSignatureStunts = new SignatureStunt[miSignatureStuntCount]; + for (int i = 0; i < miSignatureStuntCount; i++) + { + mpSignatureStunts[i] = new SignatureStunt(); + mpSignatureStunts[i].Read(reader); + } + + reader.BaseStream.Position = GenericRegionsOffset; + // read generic regions + mpGenericRegions = new GenericRegion[miGenericRegionCount]; + for (int i = 0; i < miGenericRegionCount; i++) + { + mpGenericRegions[i] = new GenericRegion(); + mpGenericRegions[i].Read(reader); + } + + + reader.BaseStream.Position = KillzoneOffset; + // read killzones + mpKillzones = new Killzone[miKillzoneCount]; + for (int i = 0; i < miKillzoneCount; i++) + { + mpKillzones[i] = new Killzone(); + mpKillzones[i].Read(reader); + } + + // read blackspots + reader.BaseStream.Position = BlackspotOffset; + mpBlackspots = new Blackspot[miBlackspotCount]; + for (int i = 0; i < miBlackspotCount; i++) + { + mpBlackspots[i] = new Blackspot(); + mpBlackspots[i].Read(reader); + } + + reader.BaseStream.Position = VFXBoxRegionOffset; + + // read VFX box regions + mpVFXBoxRegions = new VFXBoxRegion[miVFXBoxRegionCount]; + for (int i = 0; i < miVFXBoxRegionCount; i++) + { + mpVFXBoxRegions[i] = new VFXBoxRegion(); + mpVFXBoxRegions[i].Read(reader); + } + + reader.BaseStream.Position = RoamingLocationOffset; + + // read roaming locations + mpRoamingLocations = new RoamingLocation[miRoamingLocationCount]; + for (int i = 0; i < miRoamingLocationCount; i++) + { + mpRoamingLocations[i] = new RoamingLocation(); + mpRoamingLocations[i].Read(reader); + } + + reader.BaseStream.Position = SpawnLocationOffset; + + mpSpawnLocations = new SpawnLocation[miSpawnLocationCount]; + for (int i = 0; i < miSpawnLocationCount; i++) + { + mpSpawnLocations[i] = new SpawnLocation(); + mpSpawnLocations[i].Read(reader); + } + + reader.BaseStream.Position = TriggerRegionOffset; + + // read TriggerRegion (miGenericCount + miLandmarkCount) + TriggerOffsets = new List(); + for (int i = 0; i < miRegionCount; i++) + { + uint section6Entry = reader.ReadUInt32(); + TriggerOffsets.Add(section6Entry); + } return true; } @@ -168,6 +678,7 @@ public IEntryEditor GetEditor(BundleEntry entry) { TriggerDataEditor triggerDataEditor = new TriggerDataEditor(); triggerDataEditor.trigger = this; + triggerDataEditor.EditEvent += () => { Write(entry); @@ -183,7 +694,242 @@ public EntryType GetEntryType(BundleEntry entry) public bool Write(BundleEntry entry) { MemoryStream ms = new MemoryStream(); - BinaryWriter bw = new BinaryWriter(ms); + BinaryWriter writer = new BinaryWriter(ms); + writer.Write(miVersionNumber); + long SizePosition = writer.BaseStream.Position; + writer.WriteUniquePadding(4); + writer.WriteUniquePadding(8); //padding + writer.Write(mPlayerStartPosition.X); + writer.Write(mPlayerStartPosition.Y); + writer.Write(mPlayerStartPosition.Z); + writer.Write(mPlayerStartPosition.S); + writer.Write(mPlayerStartDirection.X); + writer.Write(mPlayerStartDirection.Y); + writer.Write(mPlayerStartDirection.Z); + writer.Write(mPlayerStartDirection.S); + + long LandmarkOffsetPosition = writer.BaseStream.Position; + writer.WriteUniquePadding(4); + writer.Write(mpLandmarks.Count); + writer.Write(miOnlineLandmarkCount); + long SignatureStuntskOffsetPosition = writer.BaseStream.Position; + writer.WriteUniquePadding(4); + writer.Write(mpSignatureStunts.Length); + long GenericRegionsOffsetPosition = writer.BaseStream.Position; + writer.WriteUniquePadding(4); + writer.Write(mpGenericRegions.Length); + long KillzoneOffsetPosition = writer.BaseStream.Position; + writer.WriteUniquePadding(4); + writer.Write(mpKillzones.Length); + long BlackspotOffsetPosition = writer.BaseStream.Position; + writer.WriteUniquePadding(4); + writer.Write(mpBlackspots.Length); + long VFXBoxRegionsOffsetPosition = writer.BaseStream.Position; + writer.WriteUniquePadding(4); + writer.Write(mpVFXBoxRegions.Length); + long RoamingLocationsOffsetPosition = writer.BaseStream.Position; + writer.WriteUniquePadding(4); + writer.Write(mpRoamingLocations.Length); + long SpawnLocationsOffsetPosition = writer.BaseStream.Position; + writer.WriteUniquePadding(4); + writer.Write(mpSpawnLocations.Length); + long TriggerOffsetPosition = writer.BaseStream.Position; + writer.WriteUniquePadding(4); + writer.Write(mpLandmarks.Count + mpGenericRegions.Length + mpBlackspots.Length + mpVFXBoxRegions.Length); + writer.WriteUniquePadding(4); // padding + + + List TriggerRegionOffsets = new List(); + + + long currentPosition = writer.BaseStream.Position; + writer.BaseStream.Position = LandmarkOffsetPosition; + writer.Write((uint)currentPosition); + writer.BaseStream.Position = currentPosition; + foreach (Landmark landmark in mpLandmarks) + { + TriggerRegionOffsets.Add((uint)writer.BaseStream.Position); + landmark.Write(writer); + } + + // Write padding + long paddingCount = 16 - (writer.BaseStream.Position % 16); + if (paddingCount < 16) + { + for (int i = 0; i < paddingCount; i++) + writer.Write((byte)0); + } + + + currentPosition = writer.BaseStream.Position; + long offsetForSignatureStunts = writer.BaseStream.Position; + writer.BaseStream.Position = SignatureStuntskOffsetPosition; + writer.Write((uint)currentPosition); + writer.BaseStream.Position = currentPosition; + + foreach (SignatureStunt stunt in mpSignatureStunts) + { + stunt.WriteWithEmpty(writer); + } + + // Write padding + paddingCount = 16 - (writer.BaseStream.Position % 16); + if(paddingCount < 16) { + for (int i = 0; i < paddingCount; i++) + writer.Write((byte)0); + } + + currentPosition = writer.BaseStream.Position; + writer.BaseStream.Position = GenericRegionsOffsetPosition; + writer.Write((uint)currentPosition); + writer.BaseStream.Position = currentPosition; + Dictionary genericRegionOffsets = new Dictionary(); + foreach (GenericRegion region in mpGenericRegions) + { + genericRegionOffsets.Add(region.mId, (uint)writer.BaseStream.Position); + TriggerRegionOffsets.Add((uint)writer.BaseStream.Position); + region.Write(writer); + } + + // Write padding + paddingCount = 16 - (writer.BaseStream.Position % 16); + if (paddingCount < 16) + { + for (int i = 0; i < paddingCount; i++) + writer.Write((byte)0); + } + + // Go Back To SignatureStunt and Overwrite it with the actual positions in the file, then go back + currentPosition = writer.BaseStream.Position; + writer.BaseStream.Position = offsetForSignatureStunts; + foreach (SignatureStunt stunt in mpSignatureStunts) + { + stunt.Write(writer, genericRegionOffsets); + } + writer.BaseStream.Position = currentPosition; + + currentPosition = writer.BaseStream.Position; + writer.BaseStream.Position = KillzoneOffsetPosition; + writer.Write((uint)currentPosition); + writer.BaseStream.Position = currentPosition; + foreach (Killzone killzone in mpKillzones) + { + killzone.Write(writer); + }; + + // Write padding + paddingCount = 16 - (writer.BaseStream.Position % 16); + if (paddingCount < 16) + { + for (int i = 0; i < paddingCount; i++) + writer.Write((byte)0); + } + + currentPosition = writer.BaseStream.Position; + writer.BaseStream.Position = BlackspotOffsetPosition; + writer.Write((uint)currentPosition); + writer.BaseStream.Position = currentPosition; + foreach (Blackspot blackspot in mpBlackspots) + { + TriggerRegionOffsets.Add((uint)writer.BaseStream.Position); + blackspot.Write(writer); + } + + // Write padding + paddingCount = 16 - (writer.BaseStream.Position % 16); + if (paddingCount < 16) + { + for (int i = 0; i < paddingCount; i++) + writer.Write((byte)0); + } + + currentPosition = writer.BaseStream.Position; + writer.BaseStream.Position = VFXBoxRegionsOffsetPosition; + writer.Write((uint)currentPosition); + writer.BaseStream.Position = currentPosition; + foreach (VFXBoxRegion region in mpVFXBoxRegions) + { + TriggerRegionOffsets.Add((uint)writer.BaseStream.Position); + region.Write(writer); + } + + // Write padding + paddingCount = 16 - (writer.BaseStream.Position % 16); + if (paddingCount < 16) + { + for (int i = 0; i < paddingCount; i++) + writer.Write((byte)0); + } + + currentPosition = writer.BaseStream.Position; + writer.BaseStream.Position = RoamingLocationsOffsetPosition; + writer.Write((uint)currentPosition); + writer.BaseStream.Position = currentPosition; + foreach (RoamingLocation location in mpRoamingLocations) + { + location.Write(writer); + } + + // Write padding + paddingCount = 16 - (writer.BaseStream.Position % 16); + if (paddingCount < 16) + { + for (int i = 0; i < paddingCount; i++) + writer.Write((byte)0); + } + + currentPosition = writer.BaseStream.Position; + writer.BaseStream.Position = SpawnLocationsOffsetPosition; + writer.Write((uint)currentPosition); + writer.BaseStream.Position = currentPosition; + foreach (SpawnLocation location in mpSpawnLocations) + { + location.Write(writer); + } + // Write padding + paddingCount = 16 - (writer.BaseStream.Position % 16); + if (paddingCount < 16) + { + for (int i = 0; i < paddingCount; i++) + writer.Write((byte)0); + } + + foreach (Killzone killzone in mpKillzones) + { + killzone.WritePointerStuff(writer, genericRegionOffsets); + + }; + + currentPosition = writer.BaseStream.Position; + writer.BaseStream.Position = TriggerOffsetPosition; + writer.Write((uint)currentPosition); + writer.BaseStream.Position = currentPosition; + foreach (uint region in TriggerOffsets) + { + writer.Write(region); + } + + currentPosition = writer.BaseStream.Position; + writer.BaseStream.Position = SizePosition; + writer.Write((uint)currentPosition); + writer.BaseStream.Position = currentPosition; + + paddingCount = 16 - (writer.BaseStream.Position % 16); + if (paddingCount < 16) + { + for (int i = 0; i < paddingCount; i++) + writer.Write((byte)0); + } + + writer.Flush(); + + byte[] data = ms.ToArray(); + + writer.Close(); + ms.Close(); + + entry.EntryBlocks[0].Data = data; + entry.Dirty = true; return true; } diff --git a/BaseHandlers/TriggerDataEditor.Designer.cs b/BaseHandlers/TriggerDataEditor.Designer.cs index 8385069..a9a2275 100644 --- a/BaseHandlers/TriggerDataEditor.Designer.cs +++ b/BaseHandlers/TriggerDataEditor.Designer.cs @@ -32,9 +32,8 @@ private void InitializeComponent() this.propertyGrid1.Size = new System.Drawing.Size(802, 456); this.propertyGrid1.TabIndex = 0; this.propertyGrid1.PropertyValueChanged += new System.Windows.Forms.PropertyValueChangedEventHandler(this.propertyGrid1_PropertyValueChanged); - this.propertyGrid1.LostFocus += (sender, args) => this.propertyChanged(); // - // LuaListEditor + // TriggerDataEditor // this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; @@ -44,8 +43,6 @@ private void InitializeComponent() this.Text = "Trigger Data Editor"; this.ResumeLayout(false); - this.Controls.Add(this.propertyGrid1); - } #endregion diff --git a/BaseHandlers/TriggerDataEditor.cs b/BaseHandlers/TriggerDataEditor.cs index 7be806e..b70299f 100644 --- a/BaseHandlers/TriggerDataEditor.cs +++ b/BaseHandlers/TriggerDataEditor.cs @@ -24,13 +24,16 @@ public TriggerData trigger set { _trigger = value; + Console.WriteLine(value.muSize); + Console.WriteLine(_trigger.muSize); + Console.WriteLine(trigger.muSize); + UpdateComponent(); } } public void UpdateComponent() { - propertyGrid1.SelectedObject = trigger; } @@ -48,5 +51,6 @@ private void propertyGrid1_PropertyValueChanged(object s, PropertyValueChangedEv private void propertyChanged() { EditEvent?.Invoke(); } + } } diff --git a/BaseHandlers/TriggerDataEditor.resx b/BaseHandlers/TriggerDataEditor.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/BaseHandlers/TriggerDataEditor.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file From a66434e23e04c7e0adcb03a4e7b988eb16df4810 Mon Sep 17 00:00:00 2001 From: Niaz Date: Tue, 25 Apr 2023 09:30:22 +0200 Subject: [PATCH 07/18] Initialize all values and make them all classes - also refactor padding calls --- BaseHandlers/TriggerData.cs | 177 ++++++++++++------------------------ 1 file changed, 58 insertions(+), 119 deletions(-) diff --git a/BaseHandlers/TriggerData.cs b/BaseHandlers/TriggerData.cs index 54f3224..60286ff 100644 --- a/BaseHandlers/TriggerData.cs +++ b/BaseHandlers/TriggerData.cs @@ -11,7 +11,7 @@ namespace BaseHandlers { public class CgsID { - private UInt64 m_id; + private UInt64 m_id = 0; public UInt64 ID { @@ -56,9 +56,9 @@ public enum RegionType E_TYPE_COUNT = 4 } - public struct StartingGrid { - public Vector3I[] StartingPositions { get; set; } - public Vector3I[] StartingDirections { get; set; } + public class StartingGrid { + public Vector3I[] StartingPositions { get; set; } = new Vector3I[1]; + public Vector3I[] StartingDirections { get; set; } = new Vector3I[1]; public void Read(BinaryReader reader) { @@ -103,15 +103,15 @@ public void Write(BinaryWriter writer) public class BoxRegion { - public float PositionX { get; set; } - public float PositionY { get; set; } - public float PositionZ { get; set; } - public float RotationX { get; set; } - public float RotationY { get; set; } - public float RotationZ { get; set; } - public float DimensionX { get; set; } - public float DimensionY { get; set; } - public float DimensionZ { get; set; } + public float PositionX { get; set; } = 0; + public float PositionY { get; set; } = 0; + public float PositionZ { get; set; } = 0; + public float RotationX { get; set; } = 0; + public float RotationY { get; set; } = 0; + public float RotationZ { get; set; } = 0; + public float DimensionX { get; set; } = 0; + public float DimensionY { get; set; } = 0; + public float DimensionZ { get; set; } = 0; public void Read(BinaryReader reader) { @@ -142,11 +142,11 @@ public void Write(BinaryWriter writer) public class TriggerRegion { - public BoxRegion mBoxRegion { get; set; } - public int mId { get; set; } - public short miRegionIndex { get; set; } - public RegionType meType { get; set; } - private byte[] muPad { get; set; } + public BoxRegion mBoxRegion { get; set; } = new BoxRegion(); + public int mId { get; set; } = 0; + public short miRegionIndex { get; set; } = 0; + public RegionType meType { get; set; } = RegionType.E_TYPE_LANDMARK; + private byte[] muPad { get; set; } = new byte[1]; public virtual void Read(BinaryReader reader) { @@ -171,13 +171,13 @@ public virtual void Write(BinaryWriter writer) public class Landmark : TriggerRegion { - public List mpaStartingGrids { get; set; } + public List mpaStartingGrids { get; set; } = new List(); - private long startingGridsOffset; - public byte miStartingGridCount { get; set; } - public byte muDesignIndex { get; set; } - public byte muDistrict { get; set; } - public byte mu8Flags { get; set; } + private long startingGridsOffset = 0; + public byte miStartingGridCount { get; set; } = 0; + public byte muDesignIndex { get; set; } = 0; + public byte muDistrict { get; set; } = 0; + public byte mu8Flags { get; set; } = 0; public void Read(BinaryReader reader) { @@ -222,13 +222,13 @@ public void Write(BinaryWriter writer) public class GenericRegion : TriggerRegion { - public int GroupID { get; set; } - public short CameraCut1 { get; set; } - public short CameraCut2 { get; set; } - public sbyte CameraType1 { get; set; } - public sbyte CameraType2 { get; set; } - public byte Type { get; set; } - public sbyte IsOneWay { get; set; } + public int GroupID { get; set; } = 0; + public short CameraCut1 { get; set; } = 0; + public short CameraCut2 { get; set; } = 0; + public sbyte CameraType1 { get; set; } = 0; + public sbyte CameraType2 { get; set; } = 0; + public byte Type { get; set; } = 0; + public sbyte IsOneWay { get; set; } = 0; public void Read(BinaryReader reader) { @@ -257,8 +257,8 @@ public void Write(BinaryWriter writer) public class Blackspot : TriggerRegion { - public byte muScoreType { get; set; } - public int miScoreAmount { get; set; } + public byte muScoreType { get; set; } = 0; + public int miScoreAmount { get; set; } = 0; public override void Read(BinaryReader reader) { @@ -281,12 +281,12 @@ public override void Write(BinaryWriter writer) public class Killzone { - public List TriggerIds { get; set; } - public CgsID[] RegionIds { get; set; } + public List TriggerIds { get; set; } = new List(); + public CgsID[] RegionIds { get; set; } = new CgsID[1]; - private long TriggerOffsetPosition; + private long TriggerOffsetPosition = 0; - private long CGSIDOffsetPosition; + private long CGSIDOffsetPosition = 0; public void Read(BinaryReader reader) { // Read the trigger pointer array @@ -373,9 +373,9 @@ public void WritePointerStuff(BinaryWriter writer, Dictionary generic public class SignatureStunt { - public CgsID mId { get; set; } - public long miCamera { get; set; } - public List genericRegionIds { get; set; } + public CgsID mId { get; set; } = new CgsID(); + public long miCamera { get; set; } = 0; + public List genericRegionIds { get; set; } = new List(); public void Read(BinaryReader reader) { @@ -444,10 +444,10 @@ public void Write(BinaryWriter writer, Dictionary genericRegionOffset } } - public struct RoamingLocation + public class RoamingLocation { - public Vector3I Position { get; set; } - public byte DistrictIndex { get; set; } + public Vector3I Position { get; set; } = new Vector3I(0,0,0,0); + public byte DistrictIndex { get; set; } = 0; public void Read(BinaryReader reader) { @@ -494,10 +494,10 @@ public override void Write(BinaryWriter writer) public class SpawnLocation { - public Vector3I mPosition { get; set; } - public Vector3I mDirection { get; set; } - public CgsID mJunkyardId { get; set; } - public byte muType { get; set; } + public Vector3I mPosition { get; set; } = new Vector3I(0, 0, 0, 0); + public Vector3I mDirection { get; set; } = new Vector3I(0, 0, 0, 0); + public CgsID mJunkyardId { get; set; } = new CgsID(); + public byte muType { get; set; } = 0; private byte[] padding = new byte[7]; public void Read(BinaryReader reader) @@ -532,8 +532,8 @@ public class TriggerData : IEntryData { public int miVersionNumber { get; set; } public uint muSize { get; set; } - public Vector3I mPlayerStartPosition { get; set; } - public Vector3I mPlayerStartDirection { get; set; } + public Vector3I mPlayerStartPosition { get; set; } + public Vector3I mPlayerStartDirection { get; set; } public List mpLandmarks { get; set; } public int miOnlineLandmarkCount { get; set; } public SignatureStunt[] mpSignatureStunts { get; set; } @@ -751,15 +751,7 @@ public bool Write(BundleEntry entry) TriggerRegionOffsets.Add((uint)writer.BaseStream.Position); landmark.Write(writer); } - - // Write padding - long paddingCount = 16 - (writer.BaseStream.Position % 16); - if (paddingCount < 16) - { - for (int i = 0; i < paddingCount; i++) - writer.Write((byte)0); - } - + writer.WritePadding(); currentPosition = writer.BaseStream.Position; long offsetForSignatureStunts = writer.BaseStream.Position; @@ -771,13 +763,7 @@ public bool Write(BundleEntry entry) { stunt.WriteWithEmpty(writer); } - - // Write padding - paddingCount = 16 - (writer.BaseStream.Position % 16); - if(paddingCount < 16) { - for (int i = 0; i < paddingCount; i++) - writer.Write((byte)0); - } + writer.WritePadding(); currentPosition = writer.BaseStream.Position; writer.BaseStream.Position = GenericRegionsOffsetPosition; @@ -790,14 +776,7 @@ public bool Write(BundleEntry entry) TriggerRegionOffsets.Add((uint)writer.BaseStream.Position); region.Write(writer); } - - // Write padding - paddingCount = 16 - (writer.BaseStream.Position % 16); - if (paddingCount < 16) - { - for (int i = 0; i < paddingCount; i++) - writer.Write((byte)0); - } + writer.WritePadding(); // Go Back To SignatureStunt and Overwrite it with the actual positions in the file, then go back currentPosition = writer.BaseStream.Position; @@ -816,14 +795,7 @@ public bool Write(BundleEntry entry) { killzone.Write(writer); }; - - // Write padding - paddingCount = 16 - (writer.BaseStream.Position % 16); - if (paddingCount < 16) - { - for (int i = 0; i < paddingCount; i++) - writer.Write((byte)0); - } + writer.WritePadding(); currentPosition = writer.BaseStream.Position; writer.BaseStream.Position = BlackspotOffsetPosition; @@ -834,14 +806,7 @@ public bool Write(BundleEntry entry) TriggerRegionOffsets.Add((uint)writer.BaseStream.Position); blackspot.Write(writer); } - - // Write padding - paddingCount = 16 - (writer.BaseStream.Position % 16); - if (paddingCount < 16) - { - for (int i = 0; i < paddingCount; i++) - writer.Write((byte)0); - } + writer.WritePadding(); currentPosition = writer.BaseStream.Position; writer.BaseStream.Position = VFXBoxRegionsOffsetPosition; @@ -852,14 +817,7 @@ public bool Write(BundleEntry entry) TriggerRegionOffsets.Add((uint)writer.BaseStream.Position); region.Write(writer); } - - // Write padding - paddingCount = 16 - (writer.BaseStream.Position % 16); - if (paddingCount < 16) - { - for (int i = 0; i < paddingCount; i++) - writer.Write((byte)0); - } + writer.WritePadding(); currentPosition = writer.BaseStream.Position; writer.BaseStream.Position = RoamingLocationsOffsetPosition; @@ -869,14 +827,7 @@ public bool Write(BundleEntry entry) { location.Write(writer); } - - // Write padding - paddingCount = 16 - (writer.BaseStream.Position % 16); - if (paddingCount < 16) - { - for (int i = 0; i < paddingCount; i++) - writer.Write((byte)0); - } + writer.WritePadding(); currentPosition = writer.BaseStream.Position; writer.BaseStream.Position = SpawnLocationsOffsetPosition; @@ -886,13 +837,7 @@ public bool Write(BundleEntry entry) { location.Write(writer); } - // Write padding - paddingCount = 16 - (writer.BaseStream.Position % 16); - if (paddingCount < 16) - { - for (int i = 0; i < paddingCount; i++) - writer.Write((byte)0); - } + writer.WritePadding(); foreach (Killzone killzone in mpKillzones) { @@ -913,13 +858,7 @@ public bool Write(BundleEntry entry) writer.BaseStream.Position = SizePosition; writer.Write((uint)currentPosition); writer.BaseStream.Position = currentPosition; - - paddingCount = 16 - (writer.BaseStream.Position % 16); - if (paddingCount < 16) - { - for (int i = 0; i < paddingCount; i++) - writer.Write((byte)0); - } + writer.WritePadding(); writer.Flush(); From 5134f7414984d3fd02f54ea6df6530d0ff11cf17 Mon Sep 17 00:00:00 2001 From: Niaz Date: Wed, 26 Apr 2023 09:58:37 +0200 Subject: [PATCH 08/18] Add enums and make editable --- BaseHandlers/TriggerData.cs | 70 +++++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 10 deletions(-) diff --git a/BaseHandlers/TriggerData.cs b/BaseHandlers/TriggerData.cs index 60286ff..4b12fe6 100644 --- a/BaseHandlers/TriggerData.cs +++ b/BaseHandlers/TriggerData.cs @@ -142,6 +142,7 @@ public void Write(BinaryWriter writer) public class TriggerRegion { + [TypeConverter(typeof(ExpandableObjectConverter))] public BoxRegion mBoxRegion { get; set; } = new BoxRegion(); public int mId { get; set; } = 0; public short miRegionIndex { get; set; } = 0; @@ -188,10 +189,9 @@ public void Read(BinaryReader reader) muDistrict = reader.ReadByte(); mu8Flags = reader.ReadByte(); - // Somehow StartingGrid is never used long currentPosition = reader.BaseStream.Position; reader.BaseStream.Position = startingGridsOffset; - mpaStartingGrids = new List(); + for (int i = 0; i < miStartingGridCount; i++) { StartingGrid startingGrid = new StartingGrid(); @@ -210,7 +210,7 @@ public void Write(BinaryWriter writer) writer.Write(muDesignIndex); writer.Write(muDistrict); writer.Write(mu8Flags); - // To-Do: Does not handle saving startingGridsOffsetAtAll + // To-Do: Does not handle saving startingGridsOffsetAtAll, not clear where it should be saved in the file /* for (int i = 0; i < miStartingGridCount; i++) { @@ -220,6 +220,46 @@ public void Write(BinaryWriter writer) } } + public enum GenericRegionType + { + E_TYPE_JUNK_YARD = 0, + E_TYPE_BIKE_SHOP = 1, + E_TYPE_GAS_STATION = 2, + E_TYPE_BODY_SHOP = 3, + E_TYPE_PAINT_SHOP = 4, + E_TYPE_CAR_PARK = 5, + E_TYPE_SIGNATURE_TAKEDOWN = 6, + E_TYPE_KILLZONE = 7, + E_TYPE_JUMP = 8, + E_TYPE_SMASH = 9, + E_TYPE_SIGNATURE_CRASH = 10, + E_TYPE_SIGNATURE_CRASH_CAMERA = 11, + E_TYPE_ROAD_LIMIT = 12, + E_TYPE_OVERDRIVE_BOOST = 13, + E_TYPE_OVERDRIVE_STRENGTH = 14, + E_TYPE_OVERDRIVE_SPEED = 15, + E_TYPE_OVERDRIVE_CONTROL = 16, + E_TYPE_TIRE_SHOP = 17, + E_TYPE_TUNING_SHOP = 18, + E_TYPE_PICTURE_PARADISE = 19, + E_TYPE_TUNNEL = 20, + E_TYPE_OVERPASS = 21, + E_TYPE_BRIDGE = 22, + E_TYPE_WAREHOUSE = 23, + E_TYPE_LARGE_OVERHEAD_OBJECT = 24, + E_TYPE_NARROW_ALLEY = 25, + E_TYPE_PASS_TUNNEL = 26, + E_TYPE_PASS_OVERPASS = 27, + E_TYPE_PASS_BRIDGE = 28, + E_TYPE_PASS_WAREHOUSE = 29, + E_TYPE_PASS_LARGEOVERHEADOBJECT = 30, + E_TYPE_PASS_NARROWALLEY = 31, + E_TYPE_RAMP = 32, + E_TYPE_GOLD = 33, + E_TYPE_ISLAND_ENTITLEMENT = 34, + E_TYPE_COUNT = 35, + } + public class GenericRegion : TriggerRegion { public int GroupID { get; set; } = 0; @@ -227,7 +267,7 @@ public class GenericRegion : TriggerRegion public short CameraCut2 { get; set; } = 0; public sbyte CameraType1 { get; set; } = 0; public sbyte CameraType2 { get; set; } = 0; - public byte Type { get; set; } = 0; + public GenericRegionType Type { get; set; } = GenericRegionType.E_TYPE_JUNK_YARD; public sbyte IsOneWay { get; set; } = 0; public void Read(BinaryReader reader) @@ -238,7 +278,7 @@ public void Read(BinaryReader reader) CameraCut2 = reader.ReadInt16(); CameraType1 = reader.ReadSByte(); CameraType2 = reader.ReadSByte(); - Type = reader.ReadByte(); + Type = (GenericRegionType)reader.ReadByte(); IsOneWay = reader.ReadSByte(); } @@ -250,21 +290,27 @@ public void Write(BinaryWriter writer) writer.Write(CameraCut2); writer.Write(CameraType1); writer.Write(CameraType2); - writer.Write(Type); + writer.Write((byte)Type); writer.Write(IsOneWay); } } + public enum BlackspotScoreType { + E_SCORE_TYPE_DISTANCE = 0, + E_SCORE_TYPE_CAR_COUNT = 1, + E_SCORE_TYPE_COUNT = 2, + } + public class Blackspot : TriggerRegion { - public byte muScoreType { get; set; } = 0; + public BlackspotScoreType muScoreType { get; set; } = BlackspotScoreType.E_SCORE_TYPE_DISTANCE; public int miScoreAmount { get; set; } = 0; public override void Read(BinaryReader reader) { base.Read(reader); - muScoreType = reader.ReadByte(); + muScoreType = (BlackspotScoreType) reader.ReadByte(); reader.ReadBytes(3); // Padding miScoreAmount = reader.ReadInt32(); } @@ -273,7 +319,7 @@ public override void Write(BinaryWriter writer) { base.Write(writer); - writer.Write(muScoreType); + writer.Write((byte)muScoreType); writer.Write(new byte[3]); // Padding writer.Write(miScoreAmount); } @@ -446,6 +492,7 @@ public void Write(BinaryWriter writer, Dictionary genericRegionOffset public class RoamingLocation { + [TypeConverter(typeof(ExpandableObjectConverter))] public Vector3I Position { get; set; } = new Vector3I(0,0,0,0); public byte DistrictIndex { get; set; } = 0; @@ -494,8 +541,11 @@ public override void Write(BinaryWriter writer) public class SpawnLocation { + [TypeConverter(typeof(ExpandableObjectConverter))] public Vector3I mPosition { get; set; } = new Vector3I(0, 0, 0, 0); + [TypeConverter(typeof(ExpandableObjectConverter))] public Vector3I mDirection { get; set; } = new Vector3I(0, 0, 0, 0); + [TypeConverter(typeof(ExpandableObjectConverter))] public CgsID mJunkyardId { get; set; } = new CgsID(); public byte muType { get; set; } = 0; private byte[] padding = new byte[7]; @@ -575,7 +625,7 @@ public bool Read(BundleEntry entry, ILoader loader = null) int miBlackspotCount = reader.ReadInt32(); long VFXBoxRegionOffset = reader.ReadUInt32(); - int miVFXBoxRegionCount = reader.ReadInt32(); + int miVFXBoxRegionCount = reader.ReadInt32(); long RoamingLocationOffset = reader.ReadUInt32(); int miRoamingLocationCount = reader.ReadInt32(); From 54fe1d9bff0f1c89ebd127d0325ece991347d5a8 Mon Sep 17 00:00:00 2001 From: Niaz Date: Wed, 26 Apr 2023 10:14:26 +0200 Subject: [PATCH 09/18] Add a description for TriggerIDs --- BaseHandlers/BaseHandlers.csproj | 1 + BaseHandlers/TriggerData.cs | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/BaseHandlers/BaseHandlers.csproj b/BaseHandlers/BaseHandlers.csproj index 4362c78..0754107 100644 --- a/BaseHandlers/BaseHandlers.csproj +++ b/BaseHandlers/BaseHandlers.csproj @@ -42,6 +42,7 @@ + diff --git a/BaseHandlers/TriggerData.cs b/BaseHandlers/TriggerData.cs index 4b12fe6..c313e2b 100644 --- a/BaseHandlers/TriggerData.cs +++ b/BaseHandlers/TriggerData.cs @@ -4,11 +4,36 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.ComponentModel.Design; +using System.Drawing.Design; using System.IO; using System.Linq; +using System.Windows.Forms; namespace BaseHandlers { + class DescriptiveCollectionEditor : CollectionEditor + { + public DescriptiveCollectionEditor(Type type) : base(type) { } + protected override CollectionForm CreateCollectionForm() + { + CollectionForm form = base.CreateCollectionForm(); + form.Shown += delegate + { + ShowDescription(form); + }; + return form; + } + static void ShowDescription(Control control) + { + PropertyGrid grid = control as PropertyGrid; + if (grid != null) grid.HelpVisible = true; + foreach (Control child in control.Controls) + { + ShowDescription(child); + } + } + } public class CgsID { private UInt64 m_id = 0; @@ -327,6 +352,7 @@ public override void Write(BinaryWriter writer) public class Killzone { + [Description("Triggers as GenericRegions. Uses region.mId")] public List TriggerIds { get; set; } = new List(); public CgsID[] RegionIds { get; set; } = new CgsID[1]; @@ -588,6 +614,8 @@ public class TriggerData : IEntryData public int miOnlineLandmarkCount { get; set; } public SignatureStunt[] mpSignatureStunts { get; set; } public GenericRegion[] mpGenericRegions { get; set; } + + [Editor(typeof(DescriptiveCollectionEditor), typeof(UITypeEditor))] public Killzone[] mpKillzones { get; set; } public Blackspot[] mpBlackspots { get; set; } public VFXBoxRegion[] mpVFXBoxRegions { get; set; } From 02accefe5ee6340142afbba3c60c94bb9288ba99 Mon Sep 17 00:00:00 2001 From: Niaz Date: Thu, 27 Apr 2023 08:13:24 +0200 Subject: [PATCH 10/18] Fix "Fixed List" Error --- BaseHandlers/TriggerData.cs | 87 ++++++++++++++++++++----------------- 1 file changed, 47 insertions(+), 40 deletions(-) diff --git a/BaseHandlers/TriggerData.cs b/BaseHandlers/TriggerData.cs index c313e2b..82830fd 100644 --- a/BaseHandlers/TriggerData.cs +++ b/BaseHandlers/TriggerData.cs @@ -82,12 +82,12 @@ public enum RegionType } public class StartingGrid { - public Vector3I[] StartingPositions { get; set; } = new Vector3I[1]; - public Vector3I[] StartingDirections { get; set; } = new Vector3I[1]; + public List StartingPositions { get; set; } = new List(); + public List StartingDirections { get; set; } = new List(); public void Read(BinaryReader reader) { - StartingPositions = new Vector3I[8]; + StartingPositions = new List(8); for (int i = 0; i < 8; i++) { StartingPositions[i] = new Vector3I( @@ -96,7 +96,7 @@ public void Read(BinaryReader reader) reader.ReadSingle(), reader.ReadSingle()); } - StartingDirections = new Vector3I[8]; + StartingDirections = new List(8); for (int i = 0; i < 8; i++) { StartingDirections[i] = new Vector3I( @@ -612,15 +612,15 @@ public class TriggerData : IEntryData public Vector3I mPlayerStartDirection { get; set; } public List mpLandmarks { get; set; } public int miOnlineLandmarkCount { get; set; } - public SignatureStunt[] mpSignatureStunts { get; set; } - public GenericRegion[] mpGenericRegions { get; set; } + public List mpSignatureStunts { get; set; } + public List mpGenericRegions { get; set; } [Editor(typeof(DescriptiveCollectionEditor), typeof(UITypeEditor))] - public Killzone[] mpKillzones { get; set; } - public Blackspot[] mpBlackspots { get; set; } - public VFXBoxRegion[] mpVFXBoxRegions { get; set; } - public RoamingLocation[] mpRoamingLocations { get; set; } - public SpawnLocation[] mpSpawnLocations { get; set; } + public List mpKillzones { get; set; } + public List mpBlackspots { get; set; } + public List mpVFXBoxRegions { get; set; } + public List mpRoamingLocations { get; set; } + public List mpSpawnLocations { get; set; } private List TriggerOffsets { get; set; } @@ -675,68 +675,75 @@ public bool Read(BundleEntry entry, ILoader loader = null) reader.BaseStream.Position = SignatureStuntsOffset; // read signature stunts - mpSignatureStunts = new SignatureStunt[miSignatureStuntCount]; + mpSignatureStunts = new List(); for (int i = 0; i < miSignatureStuntCount; i++) { - mpSignatureStunts[i] = new SignatureStunt(); - mpSignatureStunts[i].Read(reader); + SignatureStunt stunt = new SignatureStunt(); + stunt.Read(reader); + mpSignatureStunts.Add(stunt); } reader.BaseStream.Position = GenericRegionsOffset; // read generic regions - mpGenericRegions = new GenericRegion[miGenericRegionCount]; + mpGenericRegions = new List(); for (int i = 0; i < miGenericRegionCount; i++) { - mpGenericRegions[i] = new GenericRegion(); - mpGenericRegions[i].Read(reader); + GenericRegion region = new GenericRegion(); + region.Read(reader); + mpGenericRegions.Add(region); } reader.BaseStream.Position = KillzoneOffset; // read killzones - mpKillzones = new Killzone[miKillzoneCount]; + mpKillzones = new List(); for (int i = 0; i < miKillzoneCount; i++) { - mpKillzones[i] = new Killzone(); - mpKillzones[i].Read(reader); + Killzone killzone = new Killzone(); + killzone.Read(reader); + mpKillzones.Add(killzone); } // read blackspots reader.BaseStream.Position = BlackspotOffset; - mpBlackspots = new Blackspot[miBlackspotCount]; + mpBlackspots = new List(); for (int i = 0; i < miBlackspotCount; i++) { - mpBlackspots[i] = new Blackspot(); - mpBlackspots[i].Read(reader); + Blackspot spot = new Blackspot(); + spot.Read(reader); + mpBlackspots.Add(spot); } reader.BaseStream.Position = VFXBoxRegionOffset; // read VFX box regions - mpVFXBoxRegions = new VFXBoxRegion[miVFXBoxRegionCount]; + mpVFXBoxRegions = new List(); for (int i = 0; i < miVFXBoxRegionCount; i++) { - mpVFXBoxRegions[i] = new VFXBoxRegion(); - mpVFXBoxRegions[i].Read(reader); + VFXBoxRegion box = new VFXBoxRegion(); + box.Read(reader); + mpVFXBoxRegions.Add(box); } reader.BaseStream.Position = RoamingLocationOffset; // read roaming locations - mpRoamingLocations = new RoamingLocation[miRoamingLocationCount]; + mpRoamingLocations = new List(); for (int i = 0; i < miRoamingLocationCount; i++) { - mpRoamingLocations[i] = new RoamingLocation(); - mpRoamingLocations[i].Read(reader); + RoamingLocation location = new RoamingLocation(); + location.Read(reader); + mpRoamingLocations.Add(location); } reader.BaseStream.Position = SpawnLocationOffset; - mpSpawnLocations = new SpawnLocation[miSpawnLocationCount]; + mpSpawnLocations = new List(); for (int i = 0; i < miSpawnLocationCount; i++) { - mpSpawnLocations[i] = new SpawnLocation(); - mpSpawnLocations[i].Read(reader); + SpawnLocation location = new SpawnLocation(); + location.Read(reader); + mpSpawnLocations.Add(location); } reader.BaseStream.Position = TriggerRegionOffset; @@ -792,28 +799,28 @@ public bool Write(BundleEntry entry) writer.Write(miOnlineLandmarkCount); long SignatureStuntskOffsetPosition = writer.BaseStream.Position; writer.WriteUniquePadding(4); - writer.Write(mpSignatureStunts.Length); + writer.Write(mpSignatureStunts.Count); long GenericRegionsOffsetPosition = writer.BaseStream.Position; writer.WriteUniquePadding(4); - writer.Write(mpGenericRegions.Length); + writer.Write(mpGenericRegions.Count); long KillzoneOffsetPosition = writer.BaseStream.Position; writer.WriteUniquePadding(4); - writer.Write(mpKillzones.Length); + writer.Write(mpKillzones.Count); long BlackspotOffsetPosition = writer.BaseStream.Position; writer.WriteUniquePadding(4); - writer.Write(mpBlackspots.Length); + writer.Write(mpBlackspots.Count); long VFXBoxRegionsOffsetPosition = writer.BaseStream.Position; writer.WriteUniquePadding(4); - writer.Write(mpVFXBoxRegions.Length); + writer.Write(mpVFXBoxRegions.Count); long RoamingLocationsOffsetPosition = writer.BaseStream.Position; writer.WriteUniquePadding(4); - writer.Write(mpRoamingLocations.Length); + writer.Write(mpRoamingLocations.Count); long SpawnLocationsOffsetPosition = writer.BaseStream.Position; writer.WriteUniquePadding(4); - writer.Write(mpSpawnLocations.Length); + writer.Write(mpSpawnLocations.Count); long TriggerOffsetPosition = writer.BaseStream.Position; writer.WriteUniquePadding(4); - writer.Write(mpLandmarks.Count + mpGenericRegions.Length + mpBlackspots.Length + mpVFXBoxRegions.Length); + writer.Write(mpLandmarks.Count + mpGenericRegions.Count + mpBlackspots.Count + mpVFXBoxRegions.Count); writer.WriteUniquePadding(4); // padding From 26a5f073f210001a5c6b705b9540d5dd0227906f Mon Sep 17 00:00:00 2001 From: Niaz Date: Thu, 27 Apr 2023 08:25:50 +0200 Subject: [PATCH 11/18] Write StartingGrid --- BaseHandlers/TriggerData.cs | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/BaseHandlers/TriggerData.cs b/BaseHandlers/TriggerData.cs index 82830fd..1183dc6 100644 --- a/BaseHandlers/TriggerData.cs +++ b/BaseHandlers/TriggerData.cs @@ -200,7 +200,8 @@ public class Landmark : TriggerRegion public List mpaStartingGrids { get; set; } = new List(); private long startingGridsOffset = 0; - public byte miStartingGridCount { get; set; } = 0; + + private long startingGridOffsetPosition = 0; public byte muDesignIndex { get; set; } = 0; public byte muDistrict { get; set; } = 0; public byte mu8Flags { get; set; } = 0; @@ -209,7 +210,7 @@ public void Read(BinaryReader reader) { base.Read(reader); startingGridsOffset = reader.ReadUInt32(); - miStartingGridCount = reader.ReadByte(); + long miStartingGridCount = reader.ReadByte(); muDesignIndex = reader.ReadByte(); muDistrict = reader.ReadByte(); mu8Flags = reader.ReadByte(); @@ -230,18 +231,23 @@ public void Read(BinaryReader reader) public void Write(BinaryWriter writer) { base.Write(writer); + startingGridOffsetPosition = writer.BaseStream.Position; writer.Write((uint)startingGridsOffset); - writer.Write(miStartingGridCount); + writer.Write(mpaStartingGrids.Count); writer.Write(muDesignIndex); writer.Write(muDistrict); writer.Write(mu8Flags); - // To-Do: Does not handle saving startingGridsOffsetAtAll, not clear where it should be saved in the file - /* - for (int i = 0; i < miStartingGridCount; i++) - { - mpaStartingGrids[i].Write(writer); + } + + public void WriteStartingGrid(BinaryWriter writer){ + + long currentPosition = writer.BaseStream.Position; + writer.BaseStream.Position = startingGridOffsetPosition; + writer.Write((uint)currentPosition); + writer.BaseStream.Position = currentPosition; + foreach (StartingGrid grid in mpaStartingGrids) { + grid.Write(writer); } - */ } } @@ -924,10 +930,15 @@ public bool Write(BundleEntry entry) } writer.WritePadding(); + foreach (Landmark land in mpLandmarks) { + land.WriteStartingGrid(writer); + } + + // To-Do: Signature Stunts belong here + foreach (Killzone killzone in mpKillzones) { killzone.WritePointerStuff(writer, genericRegionOffsets); - }; currentPosition = writer.BaseStream.Position; From 1d4baeba7198c8d5a843f1d0ca84b24fb5a804dc Mon Sep 17 00:00:00 2001 From: Niaz Date: Thu, 27 Apr 2023 08:33:31 +0200 Subject: [PATCH 12/18] Write StuntElements --- BaseHandlers/TriggerData.cs | 55 ++++++++++++------------------------- 1 file changed, 18 insertions(+), 37 deletions(-) diff --git a/BaseHandlers/TriggerData.cs b/BaseHandlers/TriggerData.cs index 1183dc6..7f3cc70 100644 --- a/BaseHandlers/TriggerData.cs +++ b/BaseHandlers/TriggerData.cs @@ -453,7 +453,9 @@ public class SignatureStunt { public CgsID mId { get; set; } = new CgsID(); public long miCamera { get; set; } = 0; - public List genericRegionIds { get; set; } = new List(); + public List stuntElementRegions { get; set; } = new List(); + + private long StuntElementOffsetPosition = 0; public void Read(BinaryReader reader) { @@ -472,54 +474,38 @@ public void Read(BinaryReader reader) Triggers[i] = reader.ReadUInt32(); } - genericRegionIds = new List(); + stuntElementRegions = new List(); foreach (uint trigger in Triggers) { reader.BaseStream.Position = trigger; GenericRegion region = new GenericRegion(); region.Read(reader); - genericRegionIds.Add(region.mId); + stuntElementRegions.Add(region.mId); } reader.BaseStream.Position = currentPosition; } // Write something in triggerIds, because we dont have the actual positions yet - public void WriteWithEmpty(BinaryWriter writer) + public void Write(BinaryWriter writer) { mId.Write(writer); writer.Write(miCamera); - long GenericRegionIdsPosition = writer.BaseStream.Position; + StuntElementOffsetPosition = writer.BaseStream.Position; writer.WriteUniquePadding(4); - writer.Write(genericRegionIds.Count); - - long currentPosition = writer.BaseStream.Position; - writer.BaseStream.Position = GenericRegionIdsPosition; - writer.Write(currentPosition); - writer.BaseStream.Position = currentPosition; - foreach (int trigger in genericRegionIds) - { - writer.Write((uint)trigger); - } + writer.Write(stuntElementRegions.Count); } - public void Write(BinaryWriter writer, Dictionary genericRegionOffsets) - { - mId.Write(writer); - writer.Write(miCamera); - long GenericRegionIdsPosition = writer.BaseStream.Position; - writer.WriteUniquePadding(4); - writer.Write(genericRegionIds.Count); - - + public void WriteStuntElements(BinaryWriter writer, Dictionary genericRegionOffsets) { long currentPosition = writer.BaseStream.Position; - writer.BaseStream.Position = GenericRegionIdsPosition; + writer.BaseStream.Position = StuntElementOffsetPosition; writer.Write(currentPosition); writer.BaseStream.Position = currentPosition; - foreach (int trigger in genericRegionIds) + foreach (int trigger in stuntElementRegions) { writer.Write(genericRegionOffsets[trigger]); } } + } public class RoamingLocation @@ -845,14 +831,12 @@ public bool Write(BundleEntry entry) writer.WritePadding(); currentPosition = writer.BaseStream.Position; - long offsetForSignatureStunts = writer.BaseStream.Position; writer.BaseStream.Position = SignatureStuntskOffsetPosition; writer.Write((uint)currentPosition); writer.BaseStream.Position = currentPosition; - foreach (SignatureStunt stunt in mpSignatureStunts) { - stunt.WriteWithEmpty(writer); + stunt.Write(writer); } writer.WritePadding(); @@ -869,13 +853,7 @@ public bool Write(BundleEntry entry) } writer.WritePadding(); - // Go Back To SignatureStunt and Overwrite it with the actual positions in the file, then go back - currentPosition = writer.BaseStream.Position; - writer.BaseStream.Position = offsetForSignatureStunts; - foreach (SignatureStunt stunt in mpSignatureStunts) - { - stunt.Write(writer, genericRegionOffsets); - } + writer.BaseStream.Position = currentPosition; currentPosition = writer.BaseStream.Position; @@ -934,7 +912,10 @@ public bool Write(BundleEntry entry) land.WriteStartingGrid(writer); } - // To-Do: Signature Stunts belong here + foreach (SignatureStunt stunt in mpSignatureStunts) + { + stunt.WriteStuntElements(writer, genericRegionOffsets); + } foreach (Killzone killzone in mpKillzones) { From e5c3efe509f9d8f9974575e330a685e3a5cca148 Mon Sep 17 00:00:00 2001 From: Niaz Date: Thu, 27 Apr 2023 09:02:25 +0200 Subject: [PATCH 13/18] Fix smallish stuff --- BaseHandlers/TriggerData.cs | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/BaseHandlers/TriggerData.cs b/BaseHandlers/TriggerData.cs index 7f3cc70..50030f5 100644 --- a/BaseHandlers/TriggerData.cs +++ b/BaseHandlers/TriggerData.cs @@ -199,8 +199,6 @@ public class Landmark : TriggerRegion { public List mpaStartingGrids { get; set; } = new List(); - private long startingGridsOffset = 0; - private long startingGridOffsetPosition = 0; public byte muDesignIndex { get; set; } = 0; public byte muDistrict { get; set; } = 0; @@ -209,14 +207,14 @@ public class Landmark : TriggerRegion public void Read(BinaryReader reader) { base.Read(reader); - startingGridsOffset = reader.ReadUInt32(); - long miStartingGridCount = reader.ReadByte(); + long startingGridOffset = reader.ReadUInt32(); + int miStartingGridCount = reader.ReadByte(); muDesignIndex = reader.ReadByte(); muDistrict = reader.ReadByte(); mu8Flags = reader.ReadByte(); long currentPosition = reader.BaseStream.Position; - reader.BaseStream.Position = startingGridsOffset; + reader.BaseStream.Position = startingGridOffset; for (int i = 0; i < miStartingGridCount; i++) { @@ -232,7 +230,7 @@ public void Write(BinaryWriter writer) { base.Write(writer); startingGridOffsetPosition = writer.BaseStream.Position; - writer.Write((uint)startingGridsOffset); + writer.WriteUniquePadding(4); writer.Write(mpaStartingGrids.Count); writer.Write(muDesignIndex); writer.Write(muDistrict); @@ -815,9 +813,7 @@ public bool Write(BundleEntry entry) writer.Write(mpLandmarks.Count + mpGenericRegions.Count + mpBlackspots.Count + mpVFXBoxRegions.Count); writer.WriteUniquePadding(4); // padding - List TriggerRegionOffsets = new List(); - long currentPosition = writer.BaseStream.Position; writer.BaseStream.Position = LandmarkOffsetPosition; @@ -853,9 +849,6 @@ public bool Write(BundleEntry entry) } writer.WritePadding(); - - writer.BaseStream.Position = currentPosition; - currentPosition = writer.BaseStream.Position; writer.BaseStream.Position = KillzoneOffsetPosition; writer.Write((uint)currentPosition); From 0ad285eee9625caa5e6da84e305b116fc0128e25 Mon Sep 17 00:00:00 2001 From: Niaz Date: Thu, 27 Apr 2023 12:34:27 +0200 Subject: [PATCH 14/18] Its a byte duh --- BaseHandlers/TriggerData.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BaseHandlers/TriggerData.cs b/BaseHandlers/TriggerData.cs index 50030f5..a7766f0 100644 --- a/BaseHandlers/TriggerData.cs +++ b/BaseHandlers/TriggerData.cs @@ -231,7 +231,7 @@ public void Write(BinaryWriter writer) base.Write(writer); startingGridOffsetPosition = writer.BaseStream.Position; writer.WriteUniquePadding(4); - writer.Write(mpaStartingGrids.Count); + writer.Write((byte)mpaStartingGrids.Count); writer.Write(muDesignIndex); writer.Write(muDistrict); writer.Write(mu8Flags); From ffe76938d73956adf3614b150d0aa59320052b21 Mon Sep 17 00:00:00 2001 From: Niaz Date: Fri, 28 Apr 2023 09:34:25 +0200 Subject: [PATCH 15/18] Fix small bugs - Add allowing edting mId - Switch to List for RegionIDs to hopefully resolve bug for burninrubber - Add default constructor for Vector3I --- BaseHandlers/TriggerData.cs | 14 ++++++++------ BundleUtilities/BinaryReader2.cs | 7 +++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/BaseHandlers/TriggerData.cs b/BaseHandlers/TriggerData.cs index a7766f0..72a7ce3 100644 --- a/BaseHandlers/TriggerData.cs +++ b/BaseHandlers/TriggerData.cs @@ -358,7 +358,7 @@ public class Killzone { [Description("Triggers as GenericRegions. Uses region.mId")] public List TriggerIds { get; set; } = new List(); - public CgsID[] RegionIds { get; set; } = new CgsID[1]; + public List RegionIds { get; set; } = new List(); private long TriggerOffsetPosition = 0; @@ -391,11 +391,12 @@ public void Read(BinaryReader reader) } reader.BaseStream.Position = cgsOffset; - RegionIds = new CgsID[RegionIdCount]; - for (int i = 0; i < RegionIds.Length; i++) + RegionIds = new List(); + for (int i = 0; i < RegionIdCount; i++) { - RegionIds[i] = new CgsID(); - RegionIds[i].Read(reader); + CgsID id = new CgsID(); + id.Read(reader); + RegionIds.Add(id); } reader.BaseStream.Position = currentPosition; @@ -408,7 +409,7 @@ public void Write(BinaryWriter writer) writer.Write(TriggerIds.Count); CGSIDOffsetPosition = writer.BaseStream.Position; writer.WriteUniquePadding(4); - writer.Write(RegionIds.Length); + writer.Write(RegionIds.Count); } public void WritePointerStuff(BinaryWriter writer, Dictionary genericRegionOffsets) { @@ -449,6 +450,7 @@ public void WritePointerStuff(BinaryWriter writer, Dictionary generic public class SignatureStunt { + [TypeConverter(typeof(ExpandableObjectConverter))] public CgsID mId { get; set; } = new CgsID(); public long miCamera { get; set; } = 0; public List stuntElementRegions { get; set; } = new List(); diff --git a/BundleUtilities/BinaryReader2.cs b/BundleUtilities/BinaryReader2.cs index bf05259..8be95de 100644 --- a/BundleUtilities/BinaryReader2.cs +++ b/BundleUtilities/BinaryReader2.cs @@ -15,6 +15,13 @@ public class Vector3I public float Y { get; set; } public float Z { get; set; } public float S { get; set; } + + public Vector3I() { + X = 0; + Y = 0; + Z = 0; + S = 0; + } public Vector3I(float x, float y, float z, float s) { X = x; From fec188aac82b916896c460e246755d7e5e66892b Mon Sep 17 00:00:00 2001 From: burninrubber0 Date: Sat, 29 Apr 2023 01:15:20 -0400 Subject: [PATCH 16/18] Use default TriggerRegion types This was already done with VFX box regions, just applying it to the rest. --- BaseHandlers/TriggerData.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/BaseHandlers/TriggerData.cs b/BaseHandlers/TriggerData.cs index 72a7ce3..8a4a23b 100644 --- a/BaseHandlers/TriggerData.cs +++ b/BaseHandlers/TriggerData.cs @@ -197,6 +197,12 @@ public virtual void Write(BinaryWriter writer) public class Landmark : TriggerRegion { + public Landmark() : base() + { + // Set meType to E_TYPE_LANDMARK + meType = RegionType.E_TYPE_LANDMARK; + } + public List mpaStartingGrids { get; set; } = new List(); private long startingGridOffsetPosition = 0; @@ -291,6 +297,12 @@ public enum GenericRegionType public class GenericRegion : TriggerRegion { + public GenericRegion() : base() + { + // Set meType to E_TYPE_GENERIC_REGION + meType = RegionType.E_TYPE_GENERIC_REGION; + } + public int GroupID { get; set; } = 0; public short CameraCut1 { get; set; } = 0; public short CameraCut2 { get; set; } = 0; @@ -332,6 +344,12 @@ public enum BlackspotScoreType { public class Blackspot : TriggerRegion { + public Blackspot() : base() + { + // Set meType to E_TYPE_BLACKSPOT + meType = RegionType.E_TYPE_BLACKSPOT; + } + public BlackspotScoreType muScoreType { get; set; } = BlackspotScoreType.E_SCORE_TYPE_DISTANCE; public int miScoreAmount { get; set; } = 0; From b24cbb137b794a251f8385d4ef9c3d756666c59c Mon Sep 17 00:00:00 2001 From: burninrubber0 Date: Sat, 29 Apr 2023 01:25:36 -0400 Subject: [PATCH 17/18] Add a couple more enums Spawn location type, generic region stunt camera type --- BaseHandlers/TriggerData.cs | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/BaseHandlers/TriggerData.cs b/BaseHandlers/TriggerData.cs index 8a4a23b..9a3541f 100644 --- a/BaseHandlers/TriggerData.cs +++ b/BaseHandlers/TriggerData.cs @@ -255,6 +255,13 @@ public void WriteStartingGrid(BinaryWriter writer){ } } + public enum GenericRegionStuntCameraType + { + E_STUNT_CAMERA_TYPE_NO_CUTS = 0, + E_STUNT_CAMERA_TYPE_CUSTOM = 1, + E_STUNT_CAMERA_TYPE_NORMAL = 2 + } + public enum GenericRegionType { E_TYPE_JUNK_YARD = 0, @@ -306,8 +313,8 @@ public GenericRegion() : base() public int GroupID { get; set; } = 0; public short CameraCut1 { get; set; } = 0; public short CameraCut2 { get; set; } = 0; - public sbyte CameraType1 { get; set; } = 0; - public sbyte CameraType2 { get; set; } = 0; + public GenericRegionStuntCameraType CameraType1 { get; set; } = 0; + public GenericRegionStuntCameraType CameraType2 { get; set; } = 0; public GenericRegionType Type { get; set; } = GenericRegionType.E_TYPE_JUNK_YARD; public sbyte IsOneWay { get; set; } = 0; @@ -317,8 +324,8 @@ public void Read(BinaryReader reader) GroupID = reader.ReadInt32(); CameraCut1 = reader.ReadInt16(); CameraCut2 = reader.ReadInt16(); - CameraType1 = reader.ReadSByte(); - CameraType2 = reader.ReadSByte(); + CameraType1 = (GenericRegionStuntCameraType)reader.ReadSByte(); + CameraType2 = (GenericRegionStuntCameraType)reader.ReadSByte(); Type = (GenericRegionType)reader.ReadByte(); IsOneWay = reader.ReadSByte(); } @@ -329,8 +336,8 @@ public void Write(BinaryWriter writer) writer.Write(GroupID); writer.Write(CameraCut1); writer.Write(CameraCut2); - writer.Write(CameraType1); - writer.Write(CameraType2); + writer.Write((sbyte)CameraType1); + writer.Write((sbyte)CameraType2); writer.Write((byte)Type); writer.Write(IsOneWay); } @@ -575,6 +582,15 @@ public override void Write(BinaryWriter writer) } } + public enum SpawnLocationType + { + E_TYPE_PLAYER_SPAWN = 0, + E_TYPE_CAR_SELECT_LEFT = 1, + E_TYPE_CAR_SELECT_RIGHT = 2, + E_TYPE_CAR_UNLOCK = 3, + E_TYPE_COUNT = 4 + } + public class SpawnLocation { [TypeConverter(typeof(ExpandableObjectConverter))] @@ -583,7 +599,7 @@ public class SpawnLocation public Vector3I mDirection { get; set; } = new Vector3I(0, 0, 0, 0); [TypeConverter(typeof(ExpandableObjectConverter))] public CgsID mJunkyardId { get; set; } = new CgsID(); - public byte muType { get; set; } = 0; + public SpawnLocationType muType { get; set; } = 0; private byte[] padding = new byte[7]; public void Read(BinaryReader reader) @@ -592,7 +608,7 @@ public void Read(BinaryReader reader) mDirection = new Vector3I(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); mJunkyardId = new CgsID(); mJunkyardId.Read(reader); - muType = reader.ReadByte(); + muType = (SpawnLocationType)reader.ReadByte(); padding = reader.ReadBytes(7); } @@ -607,7 +623,7 @@ public void Write(BinaryWriter writer) writer.Write(mDirection.Z); writer.Write(mDirection.S); mJunkyardId.Write(writer); - writer.Write(muType); + writer.Write((byte)muType); writer.Write(padding); } From 85f17a9c4c70ab72d4ff3b87c8d18fe9b05f8294 Mon Sep 17 00:00:00 2001 From: burninrubber0 Date: Sat, 29 Apr 2023 01:31:03 -0400 Subject: [PATCH 18/18] Remove enum counts Not a valid value, shouldn't be selectable in the editor --- BaseHandlers/TriggerData.cs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/BaseHandlers/TriggerData.cs b/BaseHandlers/TriggerData.cs index 9a3541f..22ec201 100644 --- a/BaseHandlers/TriggerData.cs +++ b/BaseHandlers/TriggerData.cs @@ -77,11 +77,11 @@ public enum RegionType E_TYPE_LANDMARK = 0, E_TYPE_BLACKSPOT = 1, E_TYPE_GENERIC_REGION = 2, - E_TYPE_VFXBOX_REGION = 3, - E_TYPE_COUNT = 4 + E_TYPE_VFXBOX_REGION = 3 } - public class StartingGrid { + public class StartingGrid + { public List StartingPositions { get; set; } = new List(); public List StartingDirections { get; set; } = new List(); @@ -298,8 +298,7 @@ public enum GenericRegionType E_TYPE_PASS_NARROWALLEY = 31, E_TYPE_RAMP = 32, E_TYPE_GOLD = 33, - E_TYPE_ISLAND_ENTITLEMENT = 34, - E_TYPE_COUNT = 35, + E_TYPE_ISLAND_ENTITLEMENT = 34 } public class GenericRegion : TriggerRegion @@ -343,10 +342,10 @@ public void Write(BinaryWriter writer) } } - public enum BlackspotScoreType { + public enum BlackspotScoreType + { E_SCORE_TYPE_DISTANCE = 0, - E_SCORE_TYPE_CAR_COUNT = 1, - E_SCORE_TYPE_COUNT = 2, + E_SCORE_TYPE_CAR_COUNT = 1 } public class Blackspot : TriggerRegion @@ -587,8 +586,7 @@ public enum SpawnLocationType E_TYPE_PLAYER_SPAWN = 0, E_TYPE_CAR_SELECT_LEFT = 1, E_TYPE_CAR_SELECT_RIGHT = 2, - E_TYPE_CAR_UNLOCK = 3, - E_TYPE_COUNT = 4 + E_TYPE_CAR_UNLOCK = 3 } public class SpawnLocation