Advertisement
SciresM

TPLToBCLIM

May 10th, 2015
762
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.87 KB | None | 0 0
  1. public string TPLToBCLIM(string path)
  2.         {
  3.             string newname = Path.GetDirectoryName(path) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(path) + ".bclim";
  4.             byte[] data = File.ReadAllBytes(path);
  5.             byte[] tpldata = new byte[data.Length - 0x100];
  6.             Array.Copy(data, 0x100, tpldata, 0, tpldata.Length);
  7.             byte[] climfooter = { (byte)0x43, (byte)0x4C, (byte)0x49, (byte)0x4D, (byte)0xFF, (byte)0xFE, (byte)0x14, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x02, (byte)0x02, (byte)0x28, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x69, (byte)0x6D, (byte)0x61, (byte)0x67, (byte)0x10, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x40, (byte)0x00, (byte)0x00 };
  8.             byte format = data[data[BitConverter.ToUInt16(data, 0x8)] + 4];
  9.             byte[] formats = new byte[] { 0x2, 0x3, 0x2, 0x3, 0x5, 0x8, 0x9 }; // Formats 0-6, 8, 9, E documented.
  10.             if (format < formats.Length)
  11.             {
  12.                 climfooter[0x20] = formats[format];
  13.             }
  14.             else if (format == 0x8 || format == 0x9)
  15.                 climfooter[0x20] = 0x8;
  16.             else if (format == 0xE)
  17.                 climfooter[0x20] = 0xA;
  18.             else
  19.             {
  20.                 throw new ArgumentException("Unknown TPL Format: " + format.ToString("X"));
  21.             }
  22.             Array.Copy(data, BitConverter.ToUInt32(data, 0x1C) + 4, climfooter, 0x1C, 4);
  23.             Array.Copy(BitConverter.GetBytes(tpldata.Length), 0, climfooter, 0x24, 4);
  24.             Array.Copy(BitConverter.GetBytes(tpldata.Length + 0x28), 0, climfooter, 0x0C, 4);
  25.             File.WriteAllBytes(newname, tpldata.Concat(climfooter).ToArray());
  26.             return newname;
  27.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement