Skip to content

Commit

Permalink
New update
Browse files Browse the repository at this point in the history
  • Loading branch information
jianmingyong committed Aug 13, 2022
1 parent ac0e9e9 commit a9ee7e0
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 167 deletions.
10 changes: 10 additions & 0 deletions .idea/.idea.Fossil Fighters Tool/.idea/riderPublish.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .run/Publish win-x64.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Publish win-x64" type="DotNetFolderPublish" factoryName="Publish to folder">
<riderPublish configuration="Release" delete_existing_files="true" include_native_libs_for_self_extract="true" platform="Any CPU" produce_single_file="true" ready_to_run="true" runtime="win-x64" self_contained="true" target_folder="$PROJECT_DIR$/Fossil Fighters Tool/bin/Release/net6.0/win-x64/publish" target_framework="net6.0" trim_unused_assemblies="true" uuid_high="-4720315309679686371" uuid_low="-7220674542550829973" />
<method v="2" />
</configuration>
</component>
10 changes: 5 additions & 5 deletions Fossil Fighters Tool/Archive/McmFileStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ public McmFileStream(Stream outputStream, McmFileStreamMode mode, bool leaveOpen
_dataChunkOffsets = Array.Empty<int>();
}

public override int Read(byte[] buffer, int offset, int count)
{
throw new NotSupportedException();
}

public override void Write(byte[] buffer, int offset, int count)
{
_inputStream.Seek(_inputStreamWritten, SeekOrigin.Begin);
Expand All @@ -83,6 +78,11 @@ public override void Write(byte[] buffer, int offset, int count)
}
}

public override int Read(byte[] buffer, int offset, int count)
{
throw new NotSupportedException();
}

public override long Seek(long offset, SeekOrigin origin)
{
throw new NotSupportedException();
Expand Down
114 changes: 52 additions & 62 deletions Fossil Fighters Tool/Header/MmsFileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Fossil_Fighters_Tool.Header;

public class MmsFileReader : IDisposable
{
private const int MmsFileHeaderId = 0x00534D4D;
public const int Id = 0x00534D4D;

public int Unknown1 { get; }

Expand All @@ -14,7 +14,7 @@ public class MmsFileReader : IDisposable

public int Unknown4 { get; }

public int EndHeaderOffset { get; }
public int Unknown5 { get; }

public int AnimationFileCount { get; }

Expand All @@ -33,108 +33,98 @@ public class MmsFileReader : IDisposable
public int[] BitmapFileIndexes { get; }

public string BitmapFileName { get; }

private readonly FileStream _stream;

public MmsFileReader(FileStream stream)
private readonly BinaryReader _reader;
public MmsFileReader(BinaryReader reader)
{
_stream = stream;

using var binaryReader = new BinaryReader(stream, Encoding.ASCII, true);
_reader = reader;

if (binaryReader.ReadInt32() != MmsFileHeaderId)
{
throw new Exception("This is not a MMS file.");
}
reader.BaseStream.Seek(0, SeekOrigin.Begin);

if (reader.ReadInt32() != Id) throw new Exception("This is not a MMS file.");

Unknown1 = binaryReader.ReadInt32();
Unknown2 = binaryReader.ReadInt32();
Unknown3 = binaryReader.ReadInt32();
Unknown4 = binaryReader.ReadInt32();
EndHeaderOffset = binaryReader.ReadInt32();
AnimationFileCount = binaryReader.ReadInt32();
var animationFileIndexOffset = binaryReader.ReadInt32();
var animationFileNameOffset = binaryReader.ReadInt32();
ColorPaletteFileCount = binaryReader.ReadInt32();
var colorPaletteFileIndexOffset = binaryReader.ReadInt32();
var colorPaletteFileNameOffset = binaryReader.ReadInt32();
BitmapFileCount = binaryReader.ReadInt32();
var bitmapFileIndexOffset = binaryReader.ReadInt32();
var bitmapFileNameOffset = binaryReader.ReadInt32();

_stream.Seek(animationFileIndexOffset, SeekOrigin.Begin);

var animationFileIndexes = new List<int>();
Unknown1 = reader.ReadInt32();
Unknown2 = reader.ReadInt32();
Unknown3 = reader.ReadInt32();
Unknown4 = reader.ReadInt32();
Unknown5 = reader.ReadInt32();

do
{
animationFileIndexes.Add(binaryReader.ReadInt32());
} while (_stream.Position < animationFileNameOffset);
AnimationFileCount = reader.ReadInt32();
AnimationFileIndexes = new int[AnimationFileCount];
var animationFileIndexOffset = reader.ReadInt32();
var animationFileNameOffset = reader.ReadInt32();

ColorPaletteFileCount = reader.ReadInt32();
ColorPaletteFileIndexes = new int[ColorPaletteFileCount];
var colorPaletteFileIndexOffset = reader.ReadInt32();
var colorPaletteFileNameOffset = reader.ReadInt32();

BitmapFileCount = reader.ReadInt32();
BitmapFileIndexes = new int[BitmapFileCount];
var bitmapFileIndexOffset = reader.ReadInt32();
var bitmapFileNameOffset = reader.ReadInt32();

reader.BaseStream.Seek(animationFileIndexOffset, SeekOrigin.Begin);

AnimationFileIndexes = animationFileIndexes.ToArray();
for (var i = 0; i < AnimationFileCount; i++)
{
AnimationFileIndexes[i] = reader.ReadInt32();
}

_stream.Seek(animationFileNameOffset, SeekOrigin.Begin);
reader.BaseStream.Seek(animationFileNameOffset, SeekOrigin.Begin);

var animationFileName = new StringBuilder();
char animationFileNameChar;

while ((animationFileNameChar = binaryReader.ReadChar()) != '\0')
while ((animationFileNameChar = reader.ReadChar()) != '\0')
{
animationFileName.Append(animationFileNameChar);
}

AnimationFileName = animationFileName.ToString();

_stream.Seek(colorPaletteFileIndexOffset, SeekOrigin.Begin);

var colorPaletteFileIndexes = new List<int>();
reader.BaseStream.Seek(colorPaletteFileIndexOffset, SeekOrigin.Begin);

do
for (var i = 0; i < ColorPaletteFileCount; i++)
{
colorPaletteFileIndexes.Add(binaryReader.ReadInt32());
} while (_stream.Position < colorPaletteFileNameOffset);

ColorPaletteFileIndexes = colorPaletteFileIndexes.ToArray();

_stream.Seek(colorPaletteFileNameOffset, SeekOrigin.Begin);
ColorPaletteFileIndexes[i] = reader.ReadInt32();
}

reader.BaseStream.Seek(colorPaletteFileNameOffset, SeekOrigin.Begin);

var colorPaletteFileName = new StringBuilder();
char colorPaletteFileNameChar;

while ((colorPaletteFileNameChar = binaryReader.ReadChar()) != '\0')
while ((colorPaletteFileNameChar = reader.ReadChar()) != '\0')
{
colorPaletteFileName.Append(colorPaletteFileNameChar);
}

ColorPaletteFileName = colorPaletteFileName.ToString();

_stream.Seek(bitmapFileIndexOffset, SeekOrigin.Begin);

var bitmapFileIndexes = new List<int>();
reader.BaseStream.Seek(bitmapFileIndexOffset, SeekOrigin.Begin);

do
for (var i = 0; i < BitmapFileCount; i++)
{
bitmapFileIndexes.Add(binaryReader.ReadInt32());
} while (_stream.Position < bitmapFileNameOffset);
BitmapFileIndexes[i] = reader.ReadInt32();
}

BitmapFileIndexes = bitmapFileIndexes.ToArray();

_stream.Seek(bitmapFileNameOffset, SeekOrigin.Begin);
reader.BaseStream.Seek(bitmapFileNameOffset, SeekOrigin.Begin);

var bitmapFileName = new StringBuilder();
char bitmapFileNameChar;

while ((bitmapFileNameChar = binaryReader.ReadChar()) != '\0')
while ((bitmapFileNameChar = reader.ReadChar()) != '\0')
{
bitmapFileName.Append(bitmapFileNameChar);
}

BitmapFileName = bitmapFileName.ToString();
}

public void Dispose()
{
_stream.Dispose();
GC.SuppressFinalize(this);
_reader.Dispose();
}
}
23 changes: 10 additions & 13 deletions Fossil Fighters Tool/Motion/BitmapFileReader.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Text;

namespace Fossil_Fighters_Tool.Motion;
namespace Fossil_Fighters_Tool.Motion;

public class BitmapFileReader : IDisposable
{
Expand All @@ -14,15 +12,15 @@ public class BitmapFileReader : IDisposable

public byte[] BitmapColorIndexes { get; }

private readonly Stream _stream;
private readonly BinaryReader _reader;

public BitmapFileReader(Stream stream)
public BitmapFileReader(BinaryReader reader)
{
_stream = stream;
_reader = reader;

using var binaryReader = new BinaryReader(stream, Encoding.ASCII, true);

Unknown1 = binaryReader.ReadInt32();
reader.BaseStream.Seek(0, SeekOrigin.Begin);
Unknown1 = reader.ReadInt32();

switch (Unknown1 & 0xF)
{
Expand Down Expand Up @@ -93,15 +91,14 @@ public BitmapFileReader(Stream stream)

do
{
bitmapColorIndexes.Add(binaryReader.ReadByte());
} while (_stream.Position < _stream.Length);
bitmapColorIndexes.Add(reader.ReadByte());
} while (reader.BaseStream.Position < reader.BaseStream.Length);

BitmapColorIndexes = bitmapColorIndexes.ToArray();
}

public void Dispose()
{
_stream.Dispose();
GC.SuppressFinalize(this);
_reader.Dispose();
}
}
20 changes: 9 additions & 11 deletions Fossil Fighters Tool/Motion/ColorPaletteFileReader.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Text;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.PixelFormats;

namespace Fossil_Fighters_Tool.Motion;

Expand All @@ -15,27 +14,26 @@ public enum ColorPaletteType

public Rgba32[] ColorTable { get; }

private readonly Stream _stream;
private readonly BinaryReader _reader;

public ColorPaletteFileReader(Stream stream)
public ColorPaletteFileReader(BinaryReader reader)
{
_stream = stream;

using var binaryReader = new BinaryReader(stream, Encoding.ASCII, true);
_reader = reader;

ColorTableType = Enum.Parse<ColorPaletteType>(binaryReader.ReadInt32().ToString());
reader.BaseStream.Seek(0, SeekOrigin.Begin);

ColorTableType = (ColorPaletteType) reader.ReadInt32();
ColorTable = new Rgba32[ColorTableType == ColorPaletteType.Color16 ? 16 : 256];

for (var i = 0; i < ColorTable.Length; i++)
{
var rawValue = binaryReader.ReadInt16();
var rawValue = reader.ReadUInt16();
ColorTable[i] = new Rgba32((byte) ((rawValue & 0x1F) << 3), (byte) (((rawValue >> 5) & 0x1F) << 3), (byte) (((rawValue >> 10) & 0x1F) << 3), (byte) (i == 0 ? 0 : 255));
}
}

public void Dispose()
{
_stream.Dispose();
GC.SuppressFinalize(this);
_reader.Dispose();
}
}
Loading

0 comments on commit a9ee7e0

Please sign in to comment.