mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-05-30 10:54:52 +00:00
Add CSMB File Parsing/Writing
This commit is contained in:
104
PCK-Studio/Classes/FileTypes/CSMBFile.cs
Normal file
104
PCK-Studio/Classes/FileTypes/CSMBFile.cs
Normal file
@@ -0,0 +1,104 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using PckStudio.Models;
|
||||
|
||||
namespace PckStudio.Classes.FileTypes
|
||||
{
|
||||
#region File Template
|
||||
/*
|
||||
Version - 4 bytes[int32]
|
||||
NumberOfParts - 4 bytes[int32]
|
||||
{
|
||||
Part name length - 2 bytes[int16]
|
||||
part name - x bytes
|
||||
part parent - 4 bytes[int32] (HEAD=1, BODY=2, LEG0=3, LEG1=4, ARM0=5, ARM1=6)
|
||||
Position-X - 4 bytes[float]
|
||||
Position-Y - 4 bytes[float]
|
||||
Position-Z - 4 bytes[float]
|
||||
Size-X - 4 bytes[float]
|
||||
Size-Y - 4 bytes[float]
|
||||
Size-Z - 4 bytes[float]
|
||||
UV-Y - 4 bytes[int32]
|
||||
UV-X - 4 bytes[int32]
|
||||
mirror texture - 1 byte[bool]
|
||||
Hide with armour - 1 byte[bool]
|
||||
inflation/scale value - 4 bytes[float]
|
||||
}
|
||||
NumberOfOffsets - 4 bytes[int32]
|
||||
{
|
||||
offset part - 4 bytes[int32]
|
||||
vertical offset - 4 bytes[float]
|
||||
}
|
||||
*/
|
||||
#endregion
|
||||
class CSMBFile
|
||||
{
|
||||
public List<CSMBPart> Parts = new List<CSMBPart>();
|
||||
public List<CSMBOffset> Offsets = new List<CSMBOffset>();
|
||||
|
||||
}
|
||||
|
||||
public class CSMBPart
|
||||
{
|
||||
public string Name = "Partname";
|
||||
public ParentPart Parent = 0;
|
||||
public float posX, posY, posZ = 0.0f;
|
||||
public float sizeX, sizeY, sizeZ = 0.0f;
|
||||
public int uvX, uvY = 0;
|
||||
public bool HideWArmour, MirrorTexture = false;
|
||||
public float Inflation = 0.0f;
|
||||
}
|
||||
public class CSMBOffset
|
||||
{
|
||||
public OffsetPart offsetPart = 0;
|
||||
public float VerticalOffset = 0.0f;
|
||||
}
|
||||
|
||||
public enum OffsetPart
|
||||
{
|
||||
HEAD = 0,
|
||||
BODY = 1,
|
||||
ARM0 = 2,
|
||||
ARM1 = 3,
|
||||
LEG0 = 4,
|
||||
LEG1 = 5,
|
||||
HEADWEAR = 6,
|
||||
JACKET = 7,
|
||||
SLEEVE0 = 8,
|
||||
SLEEVE1 = 9,
|
||||
PANTS0 = 10,
|
||||
PANTS1 = 11,
|
||||
WAIST = 12,
|
||||
LEGGING0 = 13,
|
||||
LEGGING1 = 14,
|
||||
SOCK0 = 15,
|
||||
SOCK1 = 16,
|
||||
BOOT0 = 17,
|
||||
BOOT1 = 18,
|
||||
ARMARMOR1 = 19,
|
||||
ARMARMOR0 = 20,
|
||||
BODYARMOR = 21,
|
||||
BELT = 22,
|
||||
TOOL0 = 23,
|
||||
TOOL1 = 24,
|
||||
HELMET = 25,
|
||||
SHOULDER0 = 26,
|
||||
SHOULDER1 = 27,
|
||||
CHEST = 28
|
||||
}
|
||||
|
||||
public enum ParentPart
|
||||
{
|
||||
HEAD = 0,
|
||||
BODY = 1,
|
||||
ARM0 = 2,
|
||||
ARM1 = 3,
|
||||
LEG0 = 4,
|
||||
LEG1 = 5,
|
||||
}
|
||||
}
|
||||
56
PCK-Studio/Classes/IO/CSMB/CSMBFileReader.cs
Normal file
56
PCK-Studio/Classes/IO/CSMB/CSMBFileReader.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using PckStudio.Classes.FileTypes;
|
||||
|
||||
namespace PckStudio.Classes.IO.CSMB
|
||||
{
|
||||
internal class CSMBFileReader : StreamDataReader
|
||||
{
|
||||
public CSMBFile Read(Stream stream)
|
||||
{
|
||||
return new CSMBFileReader().ReadFromStream(stream);
|
||||
}
|
||||
private CSMBFileReader() : base(false)
|
||||
{ }
|
||||
|
||||
private CSMBFile ReadFromStream(Stream stream)
|
||||
{
|
||||
CSMBFile BinFile = new CSMBFile();
|
||||
ReadInt(stream);
|
||||
int NumOfParts = ReadInt(stream);
|
||||
for(int i = 0; i < NumOfParts; i++)
|
||||
{
|
||||
CSMBPart part = new CSMBPart();
|
||||
part.Name = ReadString(stream);
|
||||
part.Parent = (ParentPart)ReadInt(stream);
|
||||
part.posX = ReadFloat(stream);
|
||||
part.posY = ReadFloat(stream);
|
||||
part.posZ = ReadFloat(stream);
|
||||
part.sizeX = ReadFloat(stream);
|
||||
part.sizeY = ReadFloat(stream);
|
||||
part.sizeZ = ReadFloat(stream);
|
||||
part.uvX = ReadInt(stream);
|
||||
part.uvY = ReadInt(stream);
|
||||
part.MirrorTexture = ReadBool(stream);
|
||||
part.HideWArmour = ReadBool(stream);
|
||||
part.Inflation = ReadFloat(stream);
|
||||
BinFile.Parts.Add(part);
|
||||
}
|
||||
int NumOfOffsets = ReadInt(stream);
|
||||
for (int i = 0; i < NumOfOffsets; i++)
|
||||
{
|
||||
CSMBOffset offset = new CSMBOffset();
|
||||
offset.offsetPart = (OffsetPart)ReadInt(stream);
|
||||
offset.VerticalOffset = ReadFloat(stream);
|
||||
BinFile.Offsets.Add(offset);
|
||||
}
|
||||
return BinFile;
|
||||
}
|
||||
|
||||
private string ReadString(Stream stream)
|
||||
{
|
||||
short strlen = ReadShort(stream);
|
||||
return ReadString(stream, strlen, Encoding.ASCII);
|
||||
}
|
||||
}
|
||||
}
|
||||
50
PCK-Studio/Classes/IO/CSMB/CSMBFileWriter.cs
Normal file
50
PCK-Studio/Classes/IO/CSMB/CSMBFileWriter.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using PckStudio.Classes.FileTypes;
|
||||
|
||||
namespace PckStudio.Classes.IO.CSMB
|
||||
{
|
||||
internal class CSMBFileWriter : StreamDataWriter
|
||||
{
|
||||
public static void Write(Stream stream, CSMBFile file)
|
||||
{
|
||||
new CSMBFileWriter().WriteToStream(stream, file);
|
||||
}
|
||||
private CSMBFileWriter() : base(false)
|
||||
{ }
|
||||
|
||||
private void WriteToStream(Stream stream, CSMBFile CSMB)
|
||||
{
|
||||
WriteInt(stream, 0);
|
||||
WriteInt(stream, CSMB.Parts.Count);
|
||||
foreach(CSMBPart part in CSMB.Parts)
|
||||
{
|
||||
WriteString(stream, part.Name);
|
||||
WriteInt(stream, (int)part.Parent);
|
||||
WriteFloat(stream, part.posX);
|
||||
WriteFloat(stream, part.posY);
|
||||
WriteFloat(stream, part.posZ);
|
||||
WriteFloat(stream, part.sizeX);
|
||||
WriteFloat(stream, part.sizeY);
|
||||
WriteFloat(stream, part.sizeZ);
|
||||
WriteInt(stream, part.uvX);
|
||||
WriteInt(stream, part.uvY);
|
||||
WriteBool(stream, part.MirrorTexture);
|
||||
WriteBool(stream, part.HideWArmour);
|
||||
WriteFloat(stream, part.Inflation);
|
||||
}
|
||||
WriteInt(stream, CSMB.Offsets.Count);
|
||||
foreach (CSMBOffset offset in CSMB.Offsets)
|
||||
{
|
||||
WriteInt(stream, (int)offset.offsetPart);
|
||||
WriteFloat(stream, offset.VerticalOffset);
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteString(Stream stream, string s)
|
||||
{
|
||||
WriteShort(stream, (short)s.Length);
|
||||
WriteString(stream, s, Encoding.ASCII);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -138,6 +138,7 @@
|
||||
<Compile Include="Classes\API\PCKCenter\model\PCKCenterJSON.cs" />
|
||||
<Compile Include="Classes\API\PCKCenter\SaveLocalJSON.cs" />
|
||||
<Compile Include="Classes\FileTypes\ARCFile.cs" />
|
||||
<Compile Include="Classes\FileTypes\CSMBFile.cs" />
|
||||
<Compile Include="Classes\FileTypes\PCKAudioFile.cs" />
|
||||
<Compile Include="Classes\FileTypes\Bink.cs" />
|
||||
<Compile Include="Classes\FileTypes\COLFile.cs" />
|
||||
@@ -145,6 +146,8 @@
|
||||
<Compile Include="Classes\FileTypes\GRFFile.cs" />
|
||||
<Compile Include="Classes\IO\ARC\ARCFileWriter.cs" />
|
||||
<Compile Include="Classes\IO\ARC\ARCFileReader.cs" />
|
||||
<Compile Include="Classes\IO\CSMB\CSMBFileReader.cs" />
|
||||
<Compile Include="Classes\IO\CSMB\CSMBFileWriter.cs" />
|
||||
<Compile Include="Classes\IO\PCK\PCKAudioFileReader.cs" />
|
||||
<Compile Include="Classes\IO\PCK\PCKAudioFileWriter.cs" />
|
||||
<Compile Include="Classes\IO\COL\COLFileReader.cs" />
|
||||
|
||||
Reference in New Issue
Block a user