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
3 changes: 3 additions & 0 deletions ModVerify.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
<Folder Name="/PetroglyphTools/">
<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" />
<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
Expand Up @@ -19,7 +19,7 @@ public AloContentInfo GetContentInfo(Stream stream)
case ChunkType.Skeleton:
case ChunkType.Mesh:
case ChunkType.Light:
return FromModel(chunk.Size, chunkReader);
return FromModel(chunk.BodySize, chunkReader);
case ChunkType.Connections:
return FromConnection(chunkReader);
case ChunkType.Particle:
Expand All @@ -41,14 +41,14 @@ private static AloContentInfo FromAnimation(ChunkReader chunkReader)
switch ((ChunkType)chunk.Value.Type)
{
case ChunkType.AnimationInformation:
return chunk.Value.Size switch
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 @@ -66,7 +66,7 @@ private static AloContentInfo FromConnection(ChunkReader chunkReader)
case ChunkType.ProxyConnection:
case ChunkType.ObjectConnection:
case ChunkType.ConnectionCounts:
chunkReader.Skip(chunk.Value.Size);
chunkReader.Skip(chunk.Value.BodySize);
break;
case ChunkType.Dazzle:
return new AloContentInfo(AloType.Model, AloVersion.V2);
Expand All @@ -92,7 +92,7 @@ private static AloContentInfo FromModel(int size, ChunkReader chunkReader)
case ChunkType.Skeleton:
case ChunkType.Mesh:
case ChunkType.Light:
return FromModel(chunk.Value.Size, chunkReader);
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 @@ -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,15 @@ protected virtual void ReadAnimation(
switch (chunk.Type)
{
case (int)AnimationChunkTypes.AnimationInfo:
animationInformation = ReadAnimationInfo(chunk.Size);
if (chunk.RawSize < 0)
ThrowChunkSizeTooLargeException();
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 +72,12 @@ protected virtual void ReadBoneDataCore(ChunkMetadata chunk, List<AnimationBoneD
switch (chunk.Type)
{
case (int)AnimationChunkTypes.BoneDataInfo:
ReadBoneInfo(chunk.Size, bones);
if (chunk.RawSize < 0)
ThrowChunkSizeTooLargeException();
ReadBoneInfo(chunk.BodySize, bones);
break;
default:
ChunkReader.Skip(chunk.Size);
ChunkReader.Skip(chunk.BodySize);
break;
}
}
Expand All @@ -86,7 +90,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 +112,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 +160,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,16 @@ private void ReadConnections(int size, HashSet<string> proxies)
do
{
var chunk = ChunkReader.ReadChunk(ref actualSize);
if (chunk.RawSize < 0)
ThrowChunkSizeTooLargeException();

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 +86,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 +112,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 +134,17 @@ 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);
if (chunk.RawSize < 0)
ThrowChunkSizeTooLargeException();
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 +166,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 +195,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 +205,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
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@ public override AlamoParticle Read()
switch (chunk.Type)
{
case (int)ParticleChunkType.Name:
ReadName(chunk.Size, out name);
ReadName(chunk.BodySize, out name);
break;
case (int)ParticleChunkType.Emitters:
ReadEmitters(chunk.Size, textures);
ReadEmitters(chunk.BodySize, textures);
break;
default:
ChunkReader.Skip(chunk.Size);
ChunkReader.Skip(chunk.BodySize);
break;
}

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 (string.IsNullOrEmpty(name))
Expand All @@ -70,9 +70,9 @@ private void ReadEmitters(int size, HashSet<string> textures)
if (chunk.Type != (int)ParticleChunkType.Emitter)
throw new BinaryCorruptedException("Unable to read particle");

ReadEmitter(chunk.Size, textures);
ReadEmitter(chunk.BodySize, textures);

actualSize += chunk.Size;
actualSize += chunk.BodySize;


} while (actualSize < size);
Expand All @@ -92,24 +92,24 @@ private void ReadEmitter(int chunkSize, HashSet<string> textures)
if (chunk.Type == (int)ParticleChunkType.Properties)
{
var shader = ChunkReader.ReadDword();
ChunkReader.Skip(chunk.Size - sizeof(uint));
ChunkReader.Skip(chunk.BodySize - sizeof(uint));
}
else if (chunk.Type == (int)ParticleChunkType.ColorTextureName)
{
var texture = ChunkReader.ReadString(chunk.Size, Encoding.ASCII, true);
var texture = ChunkReader.ReadString(chunk.BodySize, Encoding.ASCII, true);
textures.Add(texture);
}
else if (chunk.Type == (int)ParticleChunkType.BumpTextureName)
{
var bump = ChunkReader.ReadString(chunk.Size, Encoding.ASCII, true);
var bump = ChunkReader.ReadString(chunk.BodySize, Encoding.ASCII, true);
textures.Add(bump);
}
else
{
ChunkReader.Skip(chunk.Size);
ChunkReader.Skip(chunk.BodySize);
}

actualSize += chunk.Size;
actualSize += chunk.BodySize;

} while (actualSize < chunkSize);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
<TargetFrameworks Condition="!$([MSBuild]::IsOsUnixLike())">$(TargetFrameworks);net481</TargetFrameworks>
</PropertyGroup>
<PropertyGroup>
<IsPackable>false</IsPackable>
<IsTestable>true</IsTestable>
<OutputType>Exe</OutputType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AnakinRaW.CommonUtilities.Testing" Version="13.0.18" />
<PackageReference Include="GitHubActionsTestLogger" Version="3.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.3.0" />
<PackageReference Include="xunit.v3.mtp-v2" Version="3.2.2" />
<PackageReference Include="Microsoft.Testing.Platform" Version="2.1.0" />
<PackageReference Include="coverlet.msbuild" Version="8.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="8.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\PG.StarWarsGame.Files.ChunkFiles\PG.StarWarsGame.Files.ChunkFiles.csproj" />
</ItemGroup>

</Project>
Loading
Loading