Skip to content

Commit

Permalink
Merge pull request #1092 from Zurphing/modmanager-updates
Browse files Browse the repository at this point in the history
[ModsManager] Various listpatch additions & fixes
  • Loading branch information
shananas authored Aug 1, 2024
2 parents 30adf98 + 01a18f7 commit 3c13a1d
Show file tree
Hide file tree
Showing 25 changed files with 5,919 additions and 2,552 deletions.
10 changes: 5 additions & 5 deletions OpenKh.Game/Field/Kh2Field.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ public void LoadArea(int world, int area)
if (area >= 0 && area < worldInfos.Count)
{
var areaInfo = worldInfos[area];
var isKnown = (areaInfo.Flags & 1) != 0;
var isInDoor = (areaInfo.Flags & 2) != 0;
var isMonochrome = (areaInfo.Flags & 4) != 0;
var hasNoShadow = (areaInfo.Flags & 8) != 0;
var hasGlow = (areaInfo.Flags & 16) != 0;
var isKnown = areaInfo.Flags.HasFlag(Kh2.SystemData.Arif.ArifFlags.IsKnownArea);
var isInDoor = areaInfo.Flags.HasFlag(Kh2.SystemData.Arif.ArifFlags.IndoorArea);
var isMonochrome = areaInfo.Flags.HasFlag(Kh2.SystemData.Arif.ArifFlags.Monochrome);
var hasNoShadow = areaInfo.Flags.HasFlag(Kh2.SystemData.Arif.ArifFlags.NoShadow);
var hasGlow = areaInfo.Flags.HasFlag(Kh2.SystemData.Arif.ArifFlags.HasGlow);

_targetCamera.Type = isInDoor ? 1 : 0;
}
Expand Down
32 changes: 31 additions & 1 deletion OpenKh.Kh2/BaseTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ public static void Write(Stream stream, int version, IEnumerable<T> items)
foreach (var item in itemList)
BinaryMapping.WriteObject(stream, item);
}
}
}



public class BaseShortTable<T>
where T : class
Expand All @@ -56,6 +58,34 @@ public static void Write(Stream stream, int id, IEnumerable<T> items)
Count = (short)itemList.Count,
});

foreach (var item in itemList)
BinaryMapping.WriteObject(stream, item);
}
}


//Tables that only have a Count of entries; like soundinfo, etc.
public class BaseTableCountOnly<T>
where T : class
{
[Data] public int Count { get; set; }

public static List<T> Read(Stream stream)
{
var header = BinaryMapping.ReadObject<BaseTableCountOnly<T>>(stream);
return Enumerable.Range(0, header.Count)
.Select(_ => BinaryMapping.ReadObject<T>(stream))
.ToList();
}

public static void Write(Stream stream, IEnumerable<T> items)
{
var itemList = items as IList<T> ?? items.ToList();
BinaryMapping.WriteObject(stream, new BaseTableCountOnly<T>
{
Count = (short)itemList.Count,
});

foreach (var item in itemList)
BinaryMapping.WriteObject(stream, item);
}
Expand Down
46 changes: 37 additions & 9 deletions OpenKh.Kh2/Battle/Atkp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,42 @@ public enum AttackKind : byte
0x66, 0x5F, 0x6D, 0x6F, 0x76, 0x65, 0x00, 0x63, 0x72, 0x61, 0x73, 0x68, 0x00
};

public static List<Atkp> Read(Stream stream) => BaseTable<Atkp>.Read(stream);

public static void Write(Stream stream, IEnumerable<Atkp> items)
{
BaseTable<Atkp>.Write(stream, 6, items);
stream.Position = 130232;
stream.Write(endBytes,0,277);
}

public static List<Atkp> Read(Stream stream) => BaseTable<Atkp>.Read(stream);

//New ATKP: Extra byte addition is no longer hardcoded to add to a specific position.
//Rather, they're now added at the end.
//The bytes seem to not be important, the strings resemble ones found in AI.
//However, to prevent messing with the ATKP offset unless explicity adding attack hitboxes, they'll be appended to the end of the file.
public static void Write(Stream stream, IEnumerable<Atkp> items)
{
// Get the initial length of the stream
long initialLength = stream.Length;

// Write the items to the stream
BaseTable<Atkp>.Write(stream, 6, items);

// Check if the stream length has increased
if (stream.Length > initialLength)
{

// Seek to the end of the stream
stream.Seek(0, SeekOrigin.End);

// Append the bytes to the end of the stream
stream.Write(endBytes, 0, endBytes.Length);
}
if (stream.Length == initialLength)
{
// Seek to the end of the stream
stream.Seek(0, SeekOrigin.End);
}
//Currently if you're just editing hitboxes, nothing changes. No offset differences occur.
//If you add one hitbox, it overwrites endbytes until it reaches the end of the file, and starts appending new bytes AND endbytes after.

else
{
// If no new data was written, do nothing
}
}
}
}
46 changes: 40 additions & 6 deletions OpenKh.Kh2/Battle/Limt.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,56 @@
using System;
using System.Collections.Generic;
using System.IO;
using Xe.BinaryMapper;

namespace OpenKh.Kh2.Battle
{
public class Limt
{
{


[Flags]
public enum Characters : byte
{
None = 0,
Sora = 1,
Donald = 2,
Goofy = 3,
Mickey = 4,
Auron = 5,
Mulan = 6,
Aladdin = 7,
JackSparrow = 8,
Beast = 9,
JackSkellington = 10,
Simba = 11,
Tron = 12,
Riku = 13,
Roxas = 14,
Ping = 15,
Stitch = 200,
Genie = 201,
PeterPan = 202,
ChickenLittle = 204,
}



[Data] public byte Id { get; set; }
[Data] public byte Character { get; set; }
[Data] public byte Summon { get; set; }
[Data] public Characters Character { get; set; }
[Data] public Characters Summon { get; set; }
[Data] public byte Group { get; set; }
[Data(Count = 32)] public string FileName { get; set; }
[Data] public uint SpawnId { get; set; }
[Data] public ushort Command { get; set; }
[Data] public ushort Limit { get; set; }
[Data] public byte World { get; set; }
[Data(Count = 19)] public byte[] Padding { get; set; }

[Data] public ushort World { get; set; }
[Data(Count = 18)] public byte[] Padding { get; set; }

public override string ToString()
{
return FileName;
}
public static List<Limt> Read(Stream stream) => BaseTable<Limt>.Read(stream);

public static void Write(Stream stream, IEnumerable<Limt> items) =>
Expand Down
26 changes: 26 additions & 0 deletions OpenKh.Kh2/Battle/Stop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.IO;
using Xe.BinaryMapper;

namespace OpenKh.Kh2.Battle
{
public class Stop
{
[Flags]
public enum Flag : uint
{
Exist = 0x01,
DisableDamageReaction = 0x02,
Star = 0x04,
DisableDraw = 0x08,
}
[Data] public ushort Id { get; set; }
[Data] public Flag Flags { get; set; }

public static List<Stop> Read(Stream stream) => BaseTable<Stop>.Read(stream);

public static void Write(Stream stream, IEnumerable<Stop> items) =>
BaseTable<Stop>.Write(stream, 2, items);
}
}
41 changes: 37 additions & 4 deletions OpenKh.Kh2/Jigsaw.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,48 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.IO;
using Xe.BinaryMapper;

namespace OpenKh.Kh2
{
public class Jigsaw
{
[Data] public byte Picture { get; set; }
{
public enum PictureName : byte
{
Awakening = 0,
Heart = 1,
Duality = 2,
Frontier = 3,
Daylight = 4,
Sunset = 5
}

public enum WorldList : byte
{
ZZ = 0,
EndofSea = 1,
TwilightTown = 2,
DestinyIsland = 3,
HollowBastion = 4,
BeastsCastle = 5,
OlympusColiseum = 6,
Agrabah = 7,
TheLandOfDragons = 8,
HundredAcreWood = 9,
PrideLand = 10,
Atlantica = 11,
DisneyCastle = 12,
TimelessRiver = 13,
HalloweenTown = 14,
WorldMap = 15,
PortRoyal = 16,
SpaceParanoids = 17,
TheWorldThatNeverWas = 18,
}

[Data] public PictureName Picture { get; set; }
[Data] public byte Part { get; set; }
[Data] public ushort Text { get; set; } //z_un_002a2de8, binary addition 0x8000
[Data] public byte World { get; set; }
[Data] public WorldList World { get; set; }
[Data] public byte Room { get; set; }
[Data] public byte JigsawIdWorld { get; set; }
[Data] public byte Unk07 { get; set; } //has also something to do with pos and orientation
Expand Down
Loading

0 comments on commit 3c13a1d

Please sign in to comment.