private void btnSave_Click(object sender, EventArgs e) { uint flags = (uint)m_Texture.m_Tex.m_TexType; flags |= ((uint)Math.Log(m_Texture.m_Tex.m_Width, 2) - 3) << 4; flags |= ((uint)Math.Log(m_Texture.m_Tex.m_Height, 2) - 3) << 8; flags |= (uint)(m_Texture.m_RepeatX == Particle.Texture.RepeatMode.REPEAT ? 0x1000 : m_Texture.m_RepeatX == Particle.Texture.RepeatMode.FLIP ? 0x5000 : 0); flags |= (uint)(m_Texture.m_RepeatY == Particle.Texture.RepeatMode.REPEAT ? 0x2000 : m_Texture.m_RepeatY == Particle.Texture.RepeatMode.FLIP ? 0xa000 : 0); flags |= (uint)(m_Texture.m_Tex.m_Colour0Mode != 0 ? 1 : 0) << 16; uint texelArrSize = (uint)m_Texture.m_Tex.m_RawTextureData.Length; uint palOffset = 0x20 + texelArrSize; uint palSize = (uint)m_Texture.m_Tex.m_RawPaletteData.Length; uint totalSize = palOffset + palSize; m_ParticleTexFile.Write32(0x0, 0x53505420); // "SPT " in ascii m_ParticleTexFile.Write32(0x04, flags); // flags m_ParticleTexFile.Write32(0x08, texelArrSize); // texelArrSize m_ParticleTexFile.Write32(0x0c, palOffset); // palOffset m_ParticleTexFile.Write32(0x10, palSize); // palSize m_ParticleTexFile.Write32(0x1c, totalSize); // totalSize m_ParticleTexFile.WriteBlock(0x20, m_Texture.m_Tex.m_RawTextureData); m_ParticleTexFile.WriteBlock(palOffset, m_Texture.m_Tex.m_RawPaletteData); // make it so the file is only as big as it needs to be if (m_ParticleTexFile.m_Data.Length - (int)totalSize > 0) { m_ParticleTexFile.RemoveSpace(totalSize, (uint)m_ParticleTexFile.m_Data.Length - totalSize); } m_ParticleTexFile.SaveChanges(); }