Skip to content

Commit

Permalink
Fixing
Browse files Browse the repository at this point in the history
fixed the namings and spaces
  • Loading branch information
gul4sch committed Aug 28, 2024
1 parent 3446eef commit 6f141f6
Show file tree
Hide file tree
Showing 78 changed files with 2,115 additions and 1,145 deletions.
113 changes: 74 additions & 39 deletions Warcraft.NET/Extensions/ExtendedIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,22 @@ public static Vector3 ReadVector3(this BinaryReader binaryReader, AxisConfigurat
}
}

/// <summary>
/// Reads a 48-byte <see cref="Mat3x4"/> structure from the data stream and advances the position of the stream by
/// 48 bytes.
/// </summary>
/// <returns>The Mat3x4.</returns>
/// <param name="binaryReader">The reader.</param>
/// <param name="convertTo">Which axis configuration the read mat3x4 should be converted to.</param>
public static Matrix3x4 ReadMatrix3x4(this BinaryReader binaryReader, AxisConfiguration convertTo = AxisConfiguration.YUp)
{
var a = binaryReader.ReadVector3(convertTo);
var b = binaryReader.ReadVector3(convertTo);
var c = binaryReader.ReadVector3(convertTo);
var pos = binaryReader.ReadVector3(convertTo);
return new Matrix3x4(a, b, c, pos);
}

/// <summary>
/// Reads a 12-byte <see cref="Rotator"/> from the data stream and advances the position of the stream by
/// 12 bytes.
Expand Down Expand Up @@ -273,37 +289,37 @@ public static ShortVector3 ReadShortVector3(this BinaryReader binaryReader, Axis
switch (convertTo)
{
case AxisConfiguration.Native:
{
return new ShortVector3(binaryReader.ReadInt16(), binaryReader.ReadInt16(), binaryReader.ReadInt16());
}
{
return new ShortVector3(binaryReader.ReadInt16(), binaryReader.ReadInt16(), binaryReader.ReadInt16());
}
case AxisConfiguration.YUp:
{
var x1 = binaryReader.ReadInt16();
var y1 = binaryReader.ReadInt16();
var z1 = binaryReader.ReadInt16();
{
var x1 = binaryReader.ReadInt16();
var y1 = binaryReader.ReadInt16();
var z1 = binaryReader.ReadInt16();

var x = x1;
var y = z1;
var z = (short)-y1;
var x = x1;
var y = z1;
var z = (short)-y1;

return new ShortVector3(x, y, z);
}
return new ShortVector3(x, y, z);
}
case AxisConfiguration.ZUp:
{
var x1 = binaryReader.ReadInt16();
var y1 = binaryReader.ReadInt16();
var z1 = binaryReader.ReadInt16();
{
var x1 = binaryReader.ReadInt16();
var y1 = binaryReader.ReadInt16();
var z1 = binaryReader.ReadInt16();

var x = x1;
var y = (short)-z1;
var z = y1;
var x = x1;
var y = (short)-z1;
var z = y1;

return new ShortVector3(x, y, z);
}
return new ShortVector3(x, y, z);
}
default:
{
throw new ArgumentOutOfRangeException(nameof(convertTo), convertTo, null);
}
{
throw new ArgumentOutOfRangeException(nameof(convertTo), convertTo, null);
}
}
}

Expand Down Expand Up @@ -565,6 +581,25 @@ public static void WriteVector3(this BinaryWriter binaryWriter, Vector3 vector,
}
}

/// <summary>
/// Writes a 48-byte <see cref="Matrix3x4"/> value to the data stream. This function
/// </summary>
/// <param name="binaryWriter">The current <see cref="BinaryWriter"/> object.</param>
/// <param name="matrix">The Vector to write.</param>
/// <param name="storeAs">Which axis configuration the read vector should be stored as.</param>
public static void WriteMatrix3x4(this BinaryWriter binaryWriter, Matrix3x4 matrix, AxisConfiguration storeAs = AxisConfiguration.ZUp)
{
var column1 = matrix.RotationX * matrix.Scale.X;
var column2 = matrix.RotationY * matrix.Scale.Y;
var column3 = matrix.RotationZ * matrix.Scale.Z;
var column4 = matrix.Position;

binaryWriter.WriteVector3(column1, storeAs);
binaryWriter.WriteVector3(column2, storeAs);
binaryWriter.WriteVector3(column3, storeAs);
binaryWriter.WriteVector3(column4, storeAs);
}

/// <summary>
/// Writes a 16-byte <see cref="Quaternion"/> to the data stream.
/// </summary>
Expand Down Expand Up @@ -602,23 +637,23 @@ public static void WriteShortVector3(this BinaryWriter binaryWriter, ShortVector
{
case AxisConfiguration.Native:
case AxisConfiguration.YUp:
{
binaryWriter.Write(vector.X);
binaryWriter.Write(vector.Y);
binaryWriter.Write(vector.Z);
break;
}
{
binaryWriter.Write(vector.X);
binaryWriter.Write(vector.Y);
binaryWriter.Write(vector.Z);
break;
}
case AxisConfiguration.ZUp:
{
binaryWriter.Write(vector.X);
binaryWriter.Write((short)(vector.Z * -1));
binaryWriter.Write(vector.Y);
break;
}
{
binaryWriter.Write(vector.X);
binaryWriter.Write((short)(vector.Z * -1));
binaryWriter.Write(vector.Y);
break;
}
default:
{
throw new ArgumentOutOfRangeException(nameof(storeAs), storeAs, null);
}
{
throw new ArgumentOutOfRangeException(nameof(storeAs), storeAs, null);
}
}
}

Expand Down
4 changes: 1 addition & 3 deletions Warcraft.NET/Files/M2/Chunks/BfA/LDV1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class LDV1 : IIFFChunk, IBinarySerializable
public const string Signature = "LDV1";

/// <summary>
/// Gets or sets the Skin FileDataId
/// Gets or sets the Lod Data Version 1 Entries
/// </summary>
public List<LDV1Entry> LDV1Entries = new();

Expand Down Expand Up @@ -62,10 +62,8 @@ public byte[] Serialize(long offset = 0)
{
bw.Write(obj.Serialize());
}

return ms.ToArray();
}
}

}
}
2 changes: 1 addition & 1 deletion Warcraft.NET/Files/M2/Chunks/BfA/TXID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ public byte[] Serialize(long offset = 0)
}
}
}
}
}
23 changes: 6 additions & 17 deletions Warcraft.NET/Files/M2/Chunks/BfA/WFV1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ public class WFV1 : IIFFChunk, IBinarySerializable
/// </summary>
public const string Signature = "WFV1";

public byte[] data;
/// <summary>
/// Gets or sets the full data (deserialization NYI)
/// </summary>
public byte[] Data;

/// <summary>
/// Initializes a new instance of <see cref="WFV1"/>
Expand All @@ -36,27 +39,13 @@ public WFV1() { }
/// <inheritdoc />
public void LoadBinaryData(byte[] inData)
{
{
using (var ms = new MemoryStream(inData))
using (var br = new BinaryReader(ms))
{
data = inData;
}
}
Data = inData;
}

/// <inheritdoc />
public byte[] Serialize(long offset = 0)
{
using (var ms = new MemoryStream())
using (var bw = new BinaryWriter(ms))
{
bw.Write(data);


return ms.ToArray();
}
return Data;
}

}
}
23 changes: 6 additions & 17 deletions Warcraft.NET/Files/M2/Chunks/BfA/WFV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ public class WFV2 : IIFFChunk, IBinarySerializable
/// </summary>
public const string Signature = "WFV2";

public byte[] data;
/// <summary>
/// Gets or sets the full data (deserialization NYI)
/// </summary>
public byte[] Data;

/// <summary>
/// Initializes a new instance of <see cref="WFV2"/>
Expand All @@ -36,27 +39,13 @@ public WFV2() { }
/// <inheritdoc />
public void LoadBinaryData(byte[] inData)
{
{
using (var ms = new MemoryStream(inData))
using (var br = new BinaryReader(ms))
{
data = inData;
}
}
Data = inData;
}

/// <inheritdoc />
public byte[] Serialize(long offset = 0)
{
using (var ms = new MemoryStream())
using (var bw = new BinaryWriter(ms))
{
bw.Write(data);


return ms.ToArray();
}
return Data;
}

}
}
33 changes: 12 additions & 21 deletions Warcraft.NET/Files/M2/Chunks/DF/AFRA.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
using System.Collections.Generic;
using System.IO;
using Warcraft.NET.Attribute;
using Warcraft.NET.Files.Interfaces;
using Warcraft.NET.Files.M2.Entries;
using Warcraft.NET.Files.Interfaces;

namespace Warcraft.NET.Files.M2.Chunks.DF
{
[AutoDocChunk(AutoDocChunkVersionHelper.VersionAfterSL, AutoDocChunkVersionHelper.VersionBeforeDF)]
public class AFRA : IIFFChunk, IBinarySerializable
{
/// <summary>
/// Holds the binary chunk signature.
/// </summary>
public const string Signature = "AFRA";

/// <summary>
/// Gets or sets the full data (deserialization NYI)
/// </summary>
public byte[] Data;

/// <summary>
/// Initializes a new instance of <see cref="AFRA"/>
/// </summary>
Expand All @@ -29,30 +29,21 @@ public AFRA() { }
public string GetSignature() { return Signature; }

/// <inheritdoc />
public uint GetSize() { return (uint)Serialize().Length; }

byte[] data;
public uint GetSize()
{
return (uint)Serialize().Length;
}

/// <inheritdoc/>
public void LoadBinaryData(byte[] inData)
{
using (var ms = new MemoryStream(inData))
using (var br = new BinaryReader(ms))
{
data = inData;
}
Data = inData;
}

/// <inheritdoc/>
public byte[] Serialize(long offset = 0)
{
using (var ms = new MemoryStream())
using (var bw = new BinaryWriter(ms))
{
bw.Write(data);

return ms.ToArray();
}
return Data;
}
}
}
3 changes: 1 addition & 2 deletions Warcraft.NET/Files/M2/Chunks/Legion/AFID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ public byte[] Serialize(long offset = 0)
{
bw.Write(obj.Serialize());
}

return ms.ToArray();
}
}
}
}
}
4 changes: 1 addition & 3 deletions Warcraft.NET/Files/M2/Chunks/Legion/BFID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public void LoadBinaryData(byte[] inData)
using (var br = new BinaryReader(ms))
{
uint nBone = (uint)inData.Length / 4;

for (var i = 0; i < nBone; i++)
BoneFileDataIds.Add(br.ReadUInt32());
}
Expand All @@ -56,9 +55,8 @@ public byte[] Serialize(long offset = 0)
{
foreach(uint boneFileDataId in BoneFileDataIds)
bw.Write(boneFileDataId);

return ms.ToArray();
}
}
}
}
}
Loading

0 comments on commit 6f141f6

Please sign in to comment.