Skip to content

Commit

Permalink
addresses #36, fixes some issues with map mos (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
krogenth authored Jul 29, 2023
1 parent 121e916 commit d1614d9
Show file tree
Hide file tree
Showing 12 changed files with 776 additions and 189 deletions.
316 changes: 158 additions & 158 deletions documentation/Data File Details.txt

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions src/G2DataGUI.Common/Data/Maps/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class Map
public List<MapEntry> Entries { get; set; } = new();
public List<MapInstance> Instances { get; set; } = new();
public List<MapHTA> HTAs { get; set; } = new();
public List<MapScript> Scripts { get; set; } = new();
public List<MapEnemyPosition> EnemyPositions { get; set; } = new();
public List<MapEnemyGroup> EnemyGroups { get; set; } = new();
public List<MapMOS> MOSs { get; set; } = new();
Expand Down Expand Up @@ -48,6 +49,12 @@ public static Map ReadMap(FileStream reader, string filepath)
map.HTAs.Add(MapHTA.ReadMapHTA(reader));
}

reader.Seek(map.Header.OffsetScripts, SeekOrigin.Begin);
for (var index = 0; index < map.Header.NumScripts; index++)
{
map.Scripts.Add(MapScript.ReadMapScript(reader, index));
}

reader.Seek(map.Header.OffsetEnemyPos, SeekOrigin.Begin);
for (var index = 0; index < map.Header.NumEnemyPos; index++)
{
Expand Down Expand Up @@ -116,11 +123,41 @@ public void WriteMap()
hta.WriteMapHTA(writer);
}

writer.Seek(Header.OffsetScripts, SeekOrigin.Begin);
foreach (var script in Scripts)
{
script.WriteMapScript(writer);
}

writer.Seek(Header.OffsetEnemyPos, SeekOrigin.Begin);
foreach (var position in EnemyPositions)
{
position.WriteMapEnemyPosition(writer);
}

writer.Seek(Header.OffsetEnemyGroups, SeekOrigin.Begin);
foreach (var group in EnemyGroups)
{
group.WriteMapEnemyGroup(writer);
}

writer.Seek(Header.OffsetMOS, SeekOrigin.Begin);
foreach (var mos in MOSs)
{
mos.WriteMapMOS(writer);
}

writer.Seek(Header.OffsetIcons, SeekOrigin.Begin);
foreach (var icon in Icons)
{
icon.WriteMapIcon(writer);
}

writer.Seek(Header.OffsetShop, SeekOrigin.Begin);
if (Shop != null)
{
Shop.WriteMapShop(writer);
}
}

/// <summary>
Expand Down
42 changes: 27 additions & 15 deletions src/G2DataGUI.Common/Data/Maps/MapMOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,35 @@ public class MapMOS
{
public ushort Id { get; set; }
public ushort Index { get; set; }
public int Unknown1 { get; set; }
public byte Unknown1 { get; set; }
public byte Unknown2 { get; set; }
public byte Unknown3 { get; set; }
public byte Unknown4 { get; set; }
public Vector3 Position { get; set; }
public int Unknown2 { get; set; }
public int Unknown3 { get; set; }
public int Unknown4 { get; set; }
public int Unknown5 { get; set; }
public short Unknown5 { get; set; }
public short Unknown6 { get; set; }
public short Unknown7 { get; set; }
public short Unknown8 { get; set; }
public short Unknown9 { get; set; }
public short Unknown10 { get; set; }

public static MapMOS ReadMapMOS(Stream reader)
{
MapMOS mos = new()
{
Id = reader.ReadRawUShort(),
Index = reader.ReadRawUShort(),
Unknown1 = reader.ReadRawInt(),
Unknown1 = reader.ReadRawByte(),
Unknown2 = reader.ReadRawByte(),
Unknown3 = reader.ReadRawByte(),
Unknown4 = reader.ReadRawByte(),
Position = Vector3.ReadVector3(reader),
Unknown2 = reader.ReadRawInt(),
Unknown3 = reader.ReadRawInt(),
Unknown4 = reader.ReadRawInt(),
Unknown5 = reader.ReadRawInt(),
Unknown5 = reader.ReadRawShort(),
Unknown6 = reader.ReadRawShort(),
Unknown7 = reader.ReadRawShort(),
Unknown8 = reader.ReadRawShort(),
Unknown9 = reader.ReadRawShort(),
Unknown10 = reader.ReadRawShort(),
};

return mos;
Expand All @@ -38,12 +46,16 @@ public void WriteMapMOS(Stream writer)
{
writer.WriteRawUShort(Id);
writer.WriteRawUShort(Index);
writer.WriteRawInt(Unknown1);
writer.WriteRawByte(Unknown1);
writer.WriteRawByte(Unknown2);
writer.WriteRawByte(Unknown3);
writer.WriteRawByte(Unknown4);
Position.WriteVector3(writer);
writer.WriteRawInt(Unknown2);
writer.WriteRawInt(Unknown3);
writer.WriteRawInt(Unknown4);
writer.WriteRawInt(Unknown5);
writer.WriteRawShort(Unknown5);
writer.WriteRawShort(Unknown6);
writer.WriteRawShort(Unknown7);
writer.WriteRawShort(Unknown8);
writer.WriteRawShort(Unknown9);
writer.WriteRawShort(Unknown10);
}
}
93 changes: 93 additions & 0 deletions src/G2DataGUI.Common/Data/Maps/MapScript.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using System.IO;
using G2DataGUI.Common.Data.Common;
using G2DataGUI.IO.Streams;

namespace G2DataGUI.Common.Data.Maps;
public class MapScript
{
// used for UI list
public int Index { get; set; }

public byte[] Unknown1 { get; set; }
public Vector3 Offset { get; set; } = new();
public float Direction { get; set; }
public byte TransitionEffect { get; set; }
public byte Unknown2 { get; set; }
public byte Unknown3 { get; set; }
public byte Unknown4 { get; set; }
public short MapID { get; set; }
public short Unknown5 { get; set; }
public byte Unknown6 { get; set; }
public byte Unknown7 { get; set; }
public short Unknown8 { get; set; }
public byte Unknown9 { get; set; }
public byte Unknown10 { get; set; }
public byte Unknown11 { get; set; }
public byte Unknown12 { get; set; }
public byte Unknown13 { get; set; }
public byte Unknown14 { get; set; }
public byte Unknown15 { get; set; }
public byte Unknown16 { get; set; }
public byte Unknown17 { get; set; }
public byte[] Unknown18 { get; set; }

public static uint Unknown1Length => 40;
public static uint Unknown18Length => 15;

public static MapScript ReadMapScript(Stream reader, int index)
{
MapScript mapScript = new()
{
Index = index,
Unknown1 = reader.ReadRawByteArray(Unknown1Length),
Offset = Vector3.ReadVector3(reader),
Direction = reader.ReadRawFloat(),
TransitionEffect = reader.ReadRawByte(),
Unknown2 = reader.ReadRawByte(),
Unknown3 = reader.ReadRawByte(),
Unknown4 = reader.ReadRawByte(),
MapID = reader.ReadRawShort(),
Unknown5 = reader.ReadRawShort(),
Unknown6 = reader.ReadRawByte(),
Unknown7 = reader.ReadRawByte(),
Unknown8 = reader.ReadRawShort(),
Unknown9 = reader.ReadRawByte(),
Unknown10 = reader.ReadRawByte(),
Unknown11 = reader.ReadRawByte(),
Unknown12 = reader.ReadRawByte(),
Unknown13 = reader.ReadRawByte(),
Unknown14 = reader.ReadRawByte(),
Unknown15 = reader.ReadRawByte(),
Unknown16 = reader.ReadRawByte(),
Unknown17 = reader.ReadRawByte(),
Unknown18 = reader.ReadRawByteArray(Unknown18Length),
};
return mapScript;
}

public void WriteMapScript(Stream writer)
{
writer.WriteRawByteArray(Unknown1);
Offset.WriteVector3(writer);
writer.WriteRawFloat(Direction);
writer.WriteRawByte(TransitionEffect);
writer.WriteRawByte(Unknown2);
writer.WriteRawByte(Unknown3);
writer.WriteRawByte(Unknown4);
writer.WriteRawShort(MapID);
writer.WriteRawShort(Unknown5);
writer.WriteRawByte(Unknown6);
writer.WriteRawByte(Unknown7);
writer.WriteRawShort(Unknown8);
writer.WriteRawByte(Unknown9);
writer.WriteRawByte(Unknown10);
writer.WriteRawByte(Unknown11);
writer.WriteRawByte(Unknown12);
writer.WriteRawByte(Unknown13);
writer.WriteRawByte(Unknown14);
writer.WriteRawByte(Unknown15);
writer.WriteRawByte(Unknown16);
writer.WriteRawByte(Unknown17);
writer.WriteRawByteArray(Unknown18);
}
}
9 changes: 3 additions & 6 deletions src/G2DataGUI/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ namespace G2DataGUI;
public class App : Application
{

public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}
public override void Initialize() => AvaloniaXamlLoader.Load(this);

public override void OnFrameworkInitializationCompleted()
public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
Expand All @@ -23,4 +20,4 @@ public override void OnFrameworkInitializationCompleted()

base.OnFrameworkInitializationCompleted();
}
}
}
64 changes: 64 additions & 0 deletions src/G2DataGUI/UI/ViewModels/MapScriptsViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System.Collections.Generic;
using G2DataGUI.Common.Data.Maps;
using G2DataGUI.UI.Common.ViewModels;

namespace G2DataGUI.UI.ViewModels;

public class MapScriptsViewModel : BaseViewModel
{
private List<MapScript> _selectedMapScripts = new();
private int _selectedMapScriptIndex;
private MapScript _selectedMapScriptItem;

public static MapScriptsViewModel Instance { get; private set; } = new();

private MapScriptsViewModel()
{

}

public List<MapScript> SelectedMapScripts
{
get => _selectedMapScripts;
set
{
_selectedMapScripts = value == null ? new List<MapScript>() : value;
SelectedMapScriptIndex = 0;
OnPropertyChanged(nameof(SelectedMapScripts));
OnPropertyChanged(nameof(HasMapScripts));
OnPropertyChanged(nameof(SelectedMapScriptIndex));
}
}

public bool HasMapScripts => SelectedMapScripts.Count > 0;

public int SelectedMapScriptIndex
{
get => _selectedMapScriptIndex;
set
{
if (value < 0)
{
value = 0;
}

if (value >= SelectedMapScripts.Count)
{
return;
}

_selectedMapScriptIndex = value;
SelectedMapScriptItem = SelectedMapScripts[value];
}
}

public MapScript SelectedMapScriptItem
{
get => _selectedMapScriptItem;
set
{
_selectedMapScriptItem = value;
OnPropertyChanged(nameof(SelectedMapScriptItem));
}
}
}
2 changes: 2 additions & 0 deletions src/G2DataGUI/UI/ViewModels/MapsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public sealed class MapsViewModel : BaseViewModel
private readonly MapEntriesViewModel _entriesViewModel = MapEntriesViewModel.Instance;
private readonly MapInstancesViewModel _instancesViewModel = MapInstancesViewModel.Instance;
private readonly MapHTAsViewModel _htaViewModel = MapHTAsViewModel.Instance;
private readonly MapScriptsViewModel _scriptsViewModel = MapScriptsViewModel.Instance;
private readonly MapEnemyPositionsViewModel _enemyPositionsViewModel = MapEnemyPositionsViewModel.Instance;
private readonly MapEnemyGroupsViewModel _enemyGroupsViewModel = MapEnemyGroupsViewModel.Instance;
private readonly MapMOSsViewModel _mosViewModel = MapMOSsViewModel.Instance;
Expand Down Expand Up @@ -60,6 +61,7 @@ public Map SelectedMapItem
_entriesViewModel.SelectedMapEntries = value.Entries;
_instancesViewModel.SelectedMapInstances = value.Instances;
_htaViewModel.SelectedMapHTAs = value.HTAs;
_scriptsViewModel.SelectedMapScripts = value.Scripts;
_enemyPositionsViewModel.SelectedMapEnemyPositions = value.EnemyPositions;
_enemyGroupsViewModel.SelectedMapEnemyGroups = value.EnemyGroups;
_mosViewModel.SelectedMapMOSs = value.MOSs;
Expand Down
Loading

0 comments on commit d1614d9

Please sign in to comment.