Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ModVerify.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
<Project Path="src/PetroglyphTools/PG.StarWarsGame.Engine.FileSystem/PG.StarWarsGame.Engine.FileSystem.csproj" />
<Project Path="src/PetroglyphTools/PG.StarWarsGame.Engine/PG.StarWarsGame.Engine.csproj" />
<Project Path="src/PetroglyphTools/PG.StarWarsGame.Files.ALO/PG.StarWarsGame.Files.ALO.csproj" />
<Project Path="src/PetroglyphTools/PG.StarWarsGame.Files.ChunkFiles.Test/PG.StarWarsGame.Files.ChunkFiles.Test.csproj" Id="cf14a3d6-9f76-479a-9ae2-c3f2e8c6464c">
<Build Solution="Debug|*" Project="false" />
</Project>
<Project Path="src/PetroglyphTools/PG.StarWarsGame.Files.ChunkFiles/PG.StarWarsGame.Files.ChunkFiles.csproj" />
<Project Path="src/PetroglyphTools/PG.StarWarsGame.Files.TED.Test/PG.StarWarsGame.Files.TED.Test.csproj" Id="f8ee09db-2472-4825-8cb9-a0bec243a6fb" />
<Project Path="src/PetroglyphTools/PG.StarWarsGame.Files.TED/PG.StarWarsGame.Files.TED.csproj" Id="eeae3b31-7a07-468a-a2f7-4dc11fe7ce45" />
<Project Path="src/PetroglyphTools/PG.StarWarsGame.Files.XML/PG.StarWarsGame.Files.XML.csproj" />
</Folder>
<Project Path="src/ModVerify.CliApp/ModVerify.CliApp.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace PG.StarWarsGame.Files.ChunkFiles.Binary.Metadata;
namespace PG.StarWarsGame.Files.ALO.Binary;

public enum ChunkType
public enum AloChunkType
{
Unknown,
Name = 0x0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.IO;
using PG.StarWarsGame.Files.ALO.Files;
using PG.StarWarsGame.Files.Binary;
using PG.StarWarsGame.Files.ChunkFiles.Binary.Metadata;
using PG.StarWarsGame.Files.ChunkFiles.Binary;
using PG.StarWarsGame.Files.ChunkFiles.Binary.Reader;

namespace PG.StarWarsGame.Files.ALO.Binary.Identifier;
Expand All @@ -14,19 +14,19 @@ public AloContentInfo GetContentInfo(Stream stream)

var chunk = chunkReader.ReadChunk();

switch ((ChunkType)chunk.Type)
switch ((AloChunkType)chunk.Type)
{
case ChunkType.Skeleton:
case ChunkType.Mesh:
case ChunkType.Light:
return FromModel(chunk.Size, chunkReader);
case ChunkType.Connections:
case AloChunkType.Skeleton:
case AloChunkType.Mesh:
case AloChunkType.Light:
return FromModel(chunk.BodySize, chunkReader);
case AloChunkType.Connections:
return FromConnection(chunkReader);
case ChunkType.Particle:
case AloChunkType.Particle:
return new AloContentInfo(AloType.Particle, AloVersion.V1);
case ChunkType.ParticleUaW:
case AloChunkType.ParticleUaW:
return new AloContentInfo(AloType.Particle, AloVersion.V2);
case ChunkType.Animation:
case AloChunkType.Animation:
return FromAnimation(chunkReader);
default:
throw new BinaryCorruptedException("Unable to get ALO content information.");
Expand All @@ -38,17 +38,17 @@ private static AloContentInfo FromAnimation(ChunkReader chunkReader)
var chunk = chunkReader.TryReadChunk();
while (chunk.HasValue)
{
switch ((ChunkType)chunk.Value.Type)
switch ((AloChunkType)chunk.Value.Type)
{
case ChunkType.AnimationInformation:
return chunk.Value.Size switch
case AloChunkType.AnimationInformation:
return chunk.Value.BodySize switch
{
36 => new AloContentInfo(AloType.Animation, AloVersion.V2),
18 => new AloContentInfo(AloType.Animation, AloVersion.V1),
_ => throw new BinaryCorruptedException("Invalid ALA animation.")
};
default:
chunkReader.Skip(chunk.Value.Size);
chunkReader.Skip(chunk.Value.BodySize);
break;
}
chunk = chunkReader.TryReadChunk();
Expand All @@ -61,14 +61,14 @@ private static AloContentInfo FromConnection(ChunkReader chunkReader)
var chunk = chunkReader.TryReadChunk();
while (chunk.HasValue)
{
switch ((ChunkType)chunk.Value.Type)
switch ((AloChunkType)chunk.Value.Type)
{
case ChunkType.ProxyConnection:
case ChunkType.ObjectConnection:
case ChunkType.ConnectionCounts:
chunkReader.Skip(chunk.Value.Size);
case AloChunkType.ProxyConnection:
case AloChunkType.ObjectConnection:
case AloChunkType.ConnectionCounts:
chunkReader.Skip(chunk.Value.BodySize);
break;
case ChunkType.Dazzle:
case AloChunkType.Dazzle:
return new AloContentInfo(AloType.Model, AloVersion.V2);
default:
throw new BinaryCorruptedException("Invalid ALO model.");
Expand All @@ -85,14 +85,14 @@ private static AloContentInfo FromModel(int size, ChunkReader chunkReader)
var chunk = chunkReader.TryReadChunk();
if (chunk is null)
throw new BinaryCorruptedException("Unable to get ALO content information.");
switch ((ChunkType)chunk.Value.Type)
switch ((AloChunkType)chunk.Value.Type)
{
case ChunkType.Connections:
case AloChunkType.Connections:
return FromConnection(chunkReader);
case ChunkType.Skeleton:
case ChunkType.Mesh:
case ChunkType.Light:
return FromModel(chunk.Value.Size, chunkReader);
case AloChunkType.Skeleton:
case AloChunkType.Mesh:
case AloChunkType.Light:
return FromModel(chunk.Value.BodySize, chunkReader);
default:
throw new BinaryCorruptedException("Invalid ALO model.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using PG.StarWarsGame.Files.ALO.Data;
using PG.StarWarsGame.Files.ALO.Services;
using PG.StarWarsGame.Files.Binary;
using PG.StarWarsGame.Files.ChunkFiles.Binary.Metadata;
using PG.StarWarsGame.Files.ChunkFiles.Binary.Model.Metadata;

namespace PG.StarWarsGame.Files.ALO.Binary.Reader.Animations;

Expand All @@ -27,11 +27,11 @@ public sealed override AlamoAnimation Read()
{
var chunk = ChunkReader.ReadChunk(ref actualSize);
ReadAnimation(chunk, ref info, bones);
actualSize += chunk.Size;
actualSize += chunk.BodySize;

} while (actualSize < rootChunk.Size);
} while (actualSize < rootChunk.BodySize);

if (actualSize != rootChunk.Size)
if (actualSize != rootChunk.BodySize)
throw new BinaryCorruptedException();

if (info.NumberBones != bones.Count)
Expand All @@ -54,13 +54,14 @@ protected virtual void ReadAnimation(
switch (chunk.Type)
{
case (int)AnimationChunkTypes.AnimationInfo:
animationInformation = ReadAnimationInfo(chunk.Size);
ThrowIfChunkSizeTooLargeException(chunk);
animationInformation = ReadAnimationInfo(chunk.BodySize);
break;
case (int)AnimationChunkTypes.BoneData:
ReadBonesData(chunk.Size, bones);
ReadBonesData(chunk.BodySize, bones);
break;
default:
ChunkReader.Skip(chunk.Size);
ChunkReader.Skip(chunk.BodySize);
break;
}
}
Expand All @@ -70,10 +71,11 @@ protected virtual void ReadBoneDataCore(ChunkMetadata chunk, List<AnimationBoneD
switch (chunk.Type)
{
case (int)AnimationChunkTypes.BoneDataInfo:
ReadBoneInfo(chunk.Size, bones);
ThrowIfChunkSizeTooLargeException(chunk);
ReadBoneInfo(chunk.BodySize, bones);
break;
default:
ChunkReader.Skip(chunk.Size);
ChunkReader.Skip(chunk.BodySize);
break;
}
}
Expand All @@ -86,7 +88,7 @@ private void ReadBonesData(int chunkSize, List<AnimationBoneData> bones)
{
var chunk = ChunkReader.ReadChunk(ref actualSize);
ReadBoneDataCore(chunk, bones);
actualSize += chunk.Size;
actualSize += chunk.BodySize;

} while (actualSize < chunkSize);

Expand All @@ -108,13 +110,13 @@ private void ReadBoneInfo(int chunkSize, List<AnimationBoneData> bones)
switch (chunk.Type)
{
case (int)AnimationChunkTypes.BoneName:
name = ChunkReader.ReadString(chunk.Size, Encoding.ASCII, true, ref actualSize);
name = ChunkReader.ReadString(chunk.BodySize, Encoding.ASCII, true, ref actualSize);
break;
case (int)AnimationChunkTypes.BoneIndex:
index = ChunkReader.ReadDword(ref actualSize);
break;
default:
ChunkReader.Skip(chunk.Size, ref actualSize);
ChunkReader.Skip(chunk.BodySize, ref actualSize);
break;
}

Expand Down Expand Up @@ -156,7 +158,7 @@ private AnimationInformationData ReadAnimationInfo(int chunkSize)
info.ScaleBlockSize = ChunkReader.ReadDword(ref actualSize);
break;
default:
ChunkReader.Skip(chunk.Size, ref actualSize);
ChunkReader.Skip(chunk.BodySize, ref actualSize);
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ public override AlamoModel Read()
switch (chunk.Value.Type)
{
case (int)ModelChunkTypes.Skeleton:
ReadSkeleton(chunk.Value.Size, bones);
ReadSkeleton(chunk.Value.BodySize, bones);
break;
case (int)ModelChunkTypes.Mesh:
ReadMesh(chunk.Value.Size, textures, shaders);
ReadMesh(chunk.Value.BodySize, textures, shaders);
break;
case (int)ModelChunkTypes.Connections:
ReadConnections(chunk.Value.Size, proxies);
ReadConnections(chunk.Value.BodySize, proxies);
break;
default:
ChunkReader.Skip(chunk.Value.Size);
ChunkReader.Skip(chunk.Value.BodySize);
break;
}

Expand All @@ -59,14 +59,14 @@ private void ReadConnections(int size, HashSet<string> proxies)
do
{
var chunk = ChunkReader.ReadChunk(ref actualSize);

ThrowIfChunkSizeTooLargeException(chunk);
if (chunk.Type == (int)ModelChunkTypes.ProxyConnection)
{
ReadProxy(chunk.Size, out var proxy, ref actualSize);
ReadProxy(chunk.BodySize, out var proxy, ref actualSize);
proxies.Add(proxy);
}
else
ChunkReader.Skip(chunk.Size, ref actualSize);
ChunkReader.Skip(chunk.BodySize, ref actualSize);


} while (actualSize < size);
Expand All @@ -84,9 +84,9 @@ private void ReadProxy(int size, out string proxy, ref int readSize)
var chunk = ChunkReader.ReadMiniChunk(ref actualSize);

if (chunk.Type == 5)
proxy = ChunkReader.ReadString(chunk.Size, Encoding.ASCII, true, ref actualSize);
proxy = ChunkReader.ReadString(chunk.BodySize, Encoding.ASCII, true, ref actualSize);
else
ChunkReader.Skip(chunk.Size, ref actualSize);
ChunkReader.Skip(chunk.BodySize, ref actualSize);

} while (actualSize < size);

Expand All @@ -110,9 +110,9 @@ private void ReadMesh(int size, ISet<string> textures, ISet<string> shaders)
var chunk = ChunkReader.ReadChunk(ref actualSize);

if (chunk.Type == (int)ModelChunkTypes.SubMeshMaterialInformation)
ReadSubMeshMaterialInformation(chunk.Size, textures, shaders, ref actualSize);
ReadSubMeshMaterialInformation(chunk.BodySize, textures, shaders, ref actualSize);
else
ChunkReader.Skip(chunk.Size, ref actualSize);
ChunkReader.Skip(chunk.BodySize, ref actualSize);


} while (actualSize < size);
Expand All @@ -132,15 +132,16 @@ private void ReadSubMeshMaterialInformation(int size, ISet<string> textures, ISe
{
case (int)ModelChunkTypes.ShaderFileName:
{
var shader = ChunkReader.ReadString(chunk.Size, Encoding.ASCII, true, ref actualSize);
var shader = ChunkReader.ReadString(chunk.BodySize, Encoding.ASCII, true, ref actualSize);
shaders.Add(shader);
break;
}
case (int)ModelChunkTypes.ShaderTexture:
ReadShaderTexture(chunk.Size, textures, ref actualSize);
ThrowIfChunkSizeTooLargeException(chunk);
ReadShaderTexture(chunk.BodySize, textures, ref actualSize);
break;
default:
ChunkReader.Skip(chunk.Size, ref actualSize);
ChunkReader.Skip(chunk.BodySize, ref actualSize);
break;
}

Expand All @@ -162,11 +163,11 @@ private void ReadShaderTexture(int size, ISet<string> textures, ref int readSize

if (mini.Type == 2)
{
var texture = ChunkReader.ReadString(mini.Size, Encoding.ASCII, true, ref actualTextureChunkSize);
var texture = ChunkReader.ReadString(mini.BodySize, Encoding.ASCII, true, ref actualTextureChunkSize);
textures.Add(texture);
}
else
ChunkReader.Skip(mini.Size, ref actualTextureChunkSize);
ChunkReader.Skip(mini.BodySize, ref actualTextureChunkSize);

} while (actualTextureChunkSize != size);

Expand All @@ -191,7 +192,7 @@ private void ReadSkeleton(int size, IList<string> bones)

var boneCountChunk = ChunkReader.ReadChunk(ref actualSize);

Debug.Assert(boneCountChunk is { Size: 128, Type: (int)ModelChunkTypes.BoneCount });
Debug.Assert(boneCountChunk is { BodySize: 128, Type: (int)ModelChunkTypes.BoneCount });

var boneCount = ChunkReader.ReadDword(ref actualSize);

Expand All @@ -201,24 +202,24 @@ private void ReadSkeleton(int size, IList<string> bones)
{
var bone = ChunkReader.ReadChunk(ref actualSize);

Debug.Assert(bone is { Type: (int)ModelChunkTypes.Bone, IsContainer: true });
Debug.Assert(bone is { Type: (int)ModelChunkTypes.Bone, HasChildrenHint: true });

var boneReadSize = 0;

while (boneReadSize < bone.Size)
while (boneReadSize < bone.BodySize)
{
var innerBoneChunk = ChunkReader.ReadChunk(ref boneReadSize);

if (innerBoneChunk.Type == (int)ModelChunkTypes.BoneName)
{
var nameSize = innerBoneChunk.Size;
var nameSize = innerBoneChunk.BodySize;

var name = ChunkReader.ReadString(nameSize, Encoding.ASCII, true, ref boneReadSize);
bones.Add(name);
}
else
{
ChunkReader.Skip(innerBoneChunk.Size, ref boneReadSize);
ChunkReader.Skip(innerBoneChunk.BodySize, ref boneReadSize);
}
}

Expand Down
Loading
Loading