Worms4Editor/LibXom/Data/XomContainer.cs

71 lines
1.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LibXom.Data
{
public class XomContainer : XomFileComponent
{
private string typeBelongs;
internal byte[] data;
public XomType Type
{
get
{
return this.fileBelongs.GetTypeByName(typeBelongs);
}
}
public override int Id
{
get
{
return this.fileBelongs.calculateIdForXomFileComponent(this.uuid, fileBelongs.XomContainers);
}
}
public byte[] GetData()
{
return data;
}
public void SetData(byte[] data)
{
this.Type.ReplaceContainerData(this, data);
}
private byte[] intArrayToByteArray(int[] intArray)
{
using (MemoryStream ms = new MemoryStream())
{
foreach (int i in intArray)
{
byte[] buf = BitConverter.GetBytes(i);
ms.Write(buf, 0, buf.Length);
}
ms.Seek(0, SeekOrigin.Begin);
return ms.ToArray();
}
}
public int[] Decompress()
{
byte[] compressedData = new byte[data.Length - 3];
Array.ConstrainedCopy(data, 3, compressedData, 0, compressedData.Length);
return XomCompressor.decompressBuffer(compressedData);
}
public byte[] DecompressToBytes()
{
return intArrayToByteArray(this.Decompress());
}
internal XomContainer(XomFile fromFile, string fromType, byte[] data)
{
fileBelongs = fromFile;
typeBelongs = fromType;
this.data = data;
}
}
}