Skip to content

Commit

Permalink
Fix tests, saving adjustments, texture importing works
Browse files Browse the repository at this point in the history
  • Loading branch information
ihatecompvir committed Jan 1, 2025
1 parent f150e0e commit 01a08fd
Show file tree
Hide file tree
Showing 46 changed files with 195 additions and 154 deletions.
40 changes: 23 additions & 17 deletions MiloEditor/Panels/BitmapEditor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using MiloLib.Assets.Rnd;
using MiloLib;
using MiloLib.Assets;
using MiloLib.Assets.Rnd;
using MiloLib.Classes;
using MiloLib.Utils;
using Pfim;
Expand Down Expand Up @@ -153,24 +155,28 @@ private void importButton_Click(object sender, EventArgs e)
tex.bitmap.bpp = (byte)dds.pf.dwRGBBitCount;
tex.bitmap.mipMaps = (byte)(dds.dwMipMapCount - 1);

// scramble every 4 dds pixels
// like this:
// swizzled.Add(mipMap[j + 1]);
// swizzled.Add(mipMap[j]);
// swizzled.Add(mipMap[j + 3]);
// swizzled.Add(mipMap[j + 2]);
List<List<byte>> swappedBytes = new List<List<byte>>();
for (int i = 0; i < dds.pixels.Count; i += 4)
if (tex.bitmap.platform == DirectoryMeta.Platform.Xbox)
{
List<byte> swapped = new List<byte>();
swapped.Add(dds.pixels[i + 1]);
swapped.Add(dds.pixels[i]);
swapped.Add(dds.pixels[i + 3]);
swapped.Add(dds.pixels[i + 2]);
swappedBytes.Add(swapped);
}

tex.bitmap.textures = swappedBytes;
// scramble every 4 dds pixels for 360
List<List<byte>> swappedBytes = new List<List<byte>>();
for (int i = 0; i < dds.pixels.Count; i += 4)
{
List<byte> swapped = new List<byte>();
swapped.Add(dds.pixels[i + 1]);
swapped.Add(dds.pixels[i]);
swapped.Add(dds.pixels[i + 3]);
swapped.Add(dds.pixels[i + 2]);
swappedBytes.Add(swapped);
}

tex.bitmap.textures = swappedBytes;
}
else
{
// don't do anything special for other platforms
tex.bitmap.textures = new List<List<byte>>() { dds.pixels };
}

tex.height = dds.dwHeight;
tex.width = dds.dwWidth;
Expand Down
4 changes: 2 additions & 2 deletions MiloLib.Tests/IOTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void TestRB3ObjectDirCreation()
objectDir.objFields.type = "Test_Directory";
objectDir.proxyPath = "test_path.milo";

objectDir.Write(writer, false);
objectDir.Write(writer, false, new DirectoryMeta(), null);

MemoryStream stream2 = new MemoryStream();

Expand All @@ -34,7 +34,7 @@ public void TestRB3ObjectDirCreation()
EndianReader reader = new EndianReader(stream2, Endian.BigEndian);

ObjectDir objectDir2 = new ObjectDir(27);
objectDir2.Read(reader, false);
objectDir2.Read(reader, false, new DirectoryMeta(), new DirectoryMeta.Entry("ObjectDir", "test", objectDir2));

// compare the two fields we set in the ObjectDirs
Assert.Equal(objectDir.objFields.type.value, objectDir2.objFields.type.value);
Expand Down
4 changes: 2 additions & 2 deletions MiloLib/Assets/Band/BandCharDesc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,10 @@ public BandCharDesc Read(EndianReader reader, bool standalone, DirectoryMeta par
return this;
}

public override void Write(EndianWriter writer, bool standalone)
public override void Write(EndianWriter writer, bool standalone, DirectoryMeta parent, DirectoryMeta.Entry? entry)
{
writer.WriteUInt32(BitConverter.IsLittleEndian ? (uint)((altRevision << 16) | revision) : (uint)((revision << 16) | altRevision));
base.Write(writer, false);
base.Write(writer, false, parent, entry);
Symbol.Write(writer, prefab);
Symbol.Write(writer, gender);
writer.WriteInt32(skinColor);
Expand Down
6 changes: 3 additions & 3 deletions MiloLib/Assets/Band/BandCharacter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ public BandCharacter Read(EndianReader reader, bool standalone, DirectoryMeta pa
return this;
}

public override void Write(EndianWriter writer, bool standalone)
public override void Write(EndianWriter writer, bool standalone, DirectoryMeta parent, DirectoryMeta.Entry? entry)
{
writer.WriteUInt32(BitConverter.IsLittleEndian ? (uint)((altRevision << 16) | revision) : (uint)((revision << 16) | altRevision));

base.Write(writer, false);
base.Write(writer, false, parent, entry);

writer.WriteInt32(playFlags);
Symbol.Write(writer, tempo);
Expand All @@ -113,7 +113,7 @@ public override void Write(EndianWriter writer, bool standalone)

if (revision != 0)
{
testPrefab.Write(writer, false);
testPrefab.Write(writer, false, parent, entry);
}

if (revision == 2 || revision == 3 || revision == 4)
Expand Down
4 changes: 2 additions & 2 deletions MiloLib/Assets/Band/BandCrowdMeterDir.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public BandCrowdMeterDir Read(EndianReader reader, bool standalone, DirectoryMet
return this;
}

public override void Write(EndianWriter writer, bool standalone)
public override void Write(EndianWriter writer, bool standalone, DirectoryMeta parent, DirectoryMeta.Entry? entry)
{
writer.WriteUInt32(BitConverter.IsLittleEndian ? (uint)((altRevision << 16) | revision) : (uint)((revision << 16) | altRevision));

Expand All @@ -128,7 +128,7 @@ public override void Write(EndianWriter writer, bool standalone)
if (revision >= 1)
writer.WriteFloat(peakValue);

base.Write(writer, false);
base.Write(writer, false, parent, entry);

if (standalone)
{
Expand Down
2 changes: 1 addition & 1 deletion MiloLib/Assets/Band/BandPlacer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public BandPlacer Read(EndianReader reader, bool standalone, DirectoryMeta paren
return this;
}

public override void Write(EndianWriter writer, bool standalone)
public override void Write(EndianWriter writer, bool standalone, DirectoryMeta parent, DirectoryMeta.Entry? entry)
{
writer.WriteUInt32(BitConverter.IsLittleEndian ? (uint)((altRevision << 16) | revision) : (uint)((revision << 16) | altRevision));

Expand Down
4 changes: 2 additions & 2 deletions MiloLib/Assets/Band/BandScoreboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public BandScoreboard Read(EndianReader reader, bool standalone, DirectoryMeta p
return this;
}

public override void Write(EndianWriter writer, bool standalone)
public override void Write(EndianWriter writer, bool standalone, DirectoryMeta parent, DirectoryMeta.Entry? entry)
{
writer.WriteUInt32(BitConverter.IsLittleEndian ? (uint)(altRevision << 16 | revision) : (uint)(revision << 16 | altRevision));

base.Write(writer, false);
base.Write(writer, false, parent, entry);

if (standalone)
writer.WriteBlock(new byte[4] { 0xAD, 0xDE, 0xAD, 0xDE });
Expand Down
2 changes: 1 addition & 1 deletion MiloLib/Assets/Band/BandSongPref.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class BandSongPref : Object
return this;
}

public override void Write(EndianWriter writer, bool standalone)
public override void Write(EndianWriter writer, bool standalone, DirectoryMeta parent, DirectoryMeta.Entry? entry)
{
writer.WriteUInt32(BitConverter.IsLittleEndian ? (uint)((altRevision << 16) | revision) : (uint)((revision << 16) | altRevision));
objFields.Write(writer);
Expand Down
4 changes: 2 additions & 2 deletions MiloLib/Assets/Band/BandStarDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ public BandStarDisplay Read(EndianReader reader, bool standalone, DirectoryMeta
return this;
}

public override void Write(EndianWriter writer, bool standalone)
public override void Write(EndianWriter writer, bool standalone, DirectoryMeta parent, DirectoryMeta.Entry? entry)
{
writer.WriteUInt32(BitConverter.IsLittleEndian ? (uint)(altRevision << 16 | revision) : (uint)(revision << 16 | altRevision));

base.Write(writer, false);
base.Write(writer, false, parent, entry);

if (standalone)
writer.WriteBlock(new byte[4] { 0xAD, 0xDE, 0xAD, 0xDE });
Expand Down
4 changes: 2 additions & 2 deletions MiloLib/Assets/Char/CharBoneDir.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ public CharBoneDir Read(EndianReader reader, bool standalone, DirectoryMeta pare
return this;
}

public override void Write(EndianWriter writer, bool standalone)
public override void Write(EndianWriter writer, bool standalone, DirectoryMeta parent, DirectoryMeta.Entry? entry)
{
writer.WriteUInt32(BitConverter.IsLittleEndian ? (uint)((altRevision << 16) | revision) : (uint)((revision << 16) | altRevision));

base.Write(writer, false);
base.Write(writer, false, parent, entry);

if (revision < 2)
{
Expand Down
4 changes: 2 additions & 2 deletions MiloLib/Assets/Char/CharClipSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,11 @@ public CharClipSet Read(EndianReader reader, bool standalone, DirectoryMeta pare
return this;
}

public override void Write(EndianWriter writer, bool standalone)
public override void Write(EndianWriter writer, bool standalone, DirectoryMeta parent, DirectoryMeta.Entry? entry)
{
writer.WriteUInt32(BitConverter.IsLittleEndian ? (uint)((altRevision << 16) | revision) : (uint)((revision << 16) | altRevision));

base.Write(writer, false);
base.Write(writer, false, parent, entry);

if (revision < 0x11)
{
Expand Down
11 changes: 8 additions & 3 deletions MiloLib/Assets/Char/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static MiloLib.Assets.DirectoryMeta;

namespace MiloLib.Assets.Char
{
Expand Down Expand Up @@ -69,6 +70,10 @@ public void Write(EndianWriter writer, uint revision)
}

writer.WriteUInt32((uint)translucent.Count);
foreach (var trans in translucent)
{
Symbol.Write(writer, trans);
}
}
}
}
Expand Down Expand Up @@ -175,7 +180,6 @@ public void Write(EndianWriter writer)

if (revision == 15)
{
writer.WriteBoolean(unk4);
writer.WriteUInt32(unk5);
}

Expand Down Expand Up @@ -298,11 +302,11 @@ public Character Read(EndianReader reader, bool standalone, DirectoryMeta parent
return this;
}

public override void Write(EndianWriter writer, bool standalone)
public override void Write(EndianWriter writer, bool standalone, DirectoryMeta parent, DirectoryMeta.Entry? entry)
{
writer.WriteUInt32(BitConverter.IsLittleEndian ? (uint)((altRevision << 16) | revision) : (uint)((revision << 16) | altRevision));
base.Write(writer, false, parent, entry);

base.Write(writer, false);

writer.WriteUInt32((uint)lods.Count);
foreach (var lod in lods)
Expand Down Expand Up @@ -343,6 +347,7 @@ public override void Write(EndianWriter writer, bool standalone)
if (revision > 0x10)
Symbol.Write(writer, translucentGroup);


charTest.Write(writer);

if (standalone)
Expand Down
4 changes: 2 additions & 2 deletions MiloLib/Assets/ColorPalette.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ public ColorPalette Read(EndianReader reader, bool standalone, DirectoryMeta par
return this;
}

public override void Write(EndianWriter writer, bool standalone)
public override void Write(EndianWriter writer, bool standalone, DirectoryMeta parent, DirectoryMeta.Entry? entry)
{
writer.WriteUInt32(BitConverter.IsLittleEndian ? (uint)((altRevision << 16) | revision) : (uint)((revision << 16) | altRevision));

base.Write(writer, false);
base.Write(writer, false, parent, entry);

writer.WriteUInt32((uint)colors.Count);
foreach (var color in colors)
Expand Down
4 changes: 2 additions & 2 deletions MiloLib/Assets/CrowdMeterIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ public CrowdMeterIcon Read(EndianReader reader, bool standalone, DirectoryMeta p
return this;
}

public override void Write(EndianWriter writer, bool standalone)
public override void Write(EndianWriter writer, bool standalone, DirectoryMeta parent, DirectoryMeta.Entry? entry)
{
writer.WriteUInt32(BitConverter.IsLittleEndian ? (uint)((altRevision << 16) | revision) : (uint)((revision << 16) | altRevision));

base.Write(writer, false);
base.Write(writer, false, parent, entry);

if (standalone)
{
Expand Down
Loading

0 comments on commit 01a08fd

Please sign in to comment.