Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Text;
- using Lzo64;
- namespace Marvel_heroes_tfc
- {
- class Marvel_heroes_tfc
- {
- static void Main(string[] args)
- {
- LZOCompressor compressor = new LZOCompressor();
- int i, j, k;
- FileStream fsp = new FileStream(args[0], FileMode.Open);
- BinaryReader brp = new BinaryReader(fsp);
- if (Path.GetExtension(args[0]) == ".tfc")
- {
- int nf = 0;
- int sn, blen;
- int[] ssize_u = new int[200]; // hope there will be no more than 200 segments
- int[] ssize_p = new int[200];
- while (fsp.Position < fsp.Length)
- {
- Console.WriteLine(nf + " " + fsp.Position.ToString("X8"));
- FileStream fs = new FileStream(Path.GetFileNameWithoutExtension(args[0]) + "_" + nf.ToString("d3") + ".tex", FileMode.Create);
- BinaryWriter bw = new BinaryWriter(fs);
- int id = brp.ReadInt32();
- int b_siz = brp.ReadInt32();
- blen = brp.ReadInt32();
- sn = 0;
- brp.ReadInt32(); // full unpacked size
- while (blen > 0)
- {
- ssize_p[sn] = brp.ReadInt32();
- ssize_u[sn] = brp.ReadInt32();
- blen -= ssize_p[sn];
- sn++;
- }
- for (j = 0; j < sn; j++)
- {
- byte[] buf = new byte[ssize_p[j]];
- fsp.Read(buf, 0, ssize_p[j]);
- byte[] unp;
- unp = compressor.Decompress(buf, ssize_u[j]);
- fs.Write(unp, 0, unp.Length);
- }
- bw.Close();
- fs.Close();
- nf++;
- }
- }
- else if (Path.GetExtension(args[0]) == ".bin") // manifest
- {
- int sn, blen, pos;
- int[] ssize_u = new int[200]; // hope there will be no more than 200 segments
- int[] ssize_p = new int[200];
- int nf = brp.ReadInt32();
- int len, nlen, child;
- string name, tname, currtfc="";
- int sx, sy, ttype, size;
- FileStream fsr = null;
- BinaryReader brr = null;
- //FileStream fsr = new FileStream("CharTextures.tfc", FileMode.Open);
- //BinaryReader brr = new BinaryReader(fsr);
- for (i = 0; i < nf; i++)
- {
- Console.Write(i + "\t");
- len = brp.ReadInt32()-1;
- name = ""; tname = "";
- for (j = 0; j < len; j++) tname += brp.ReadChar();
- brp.ReadChar();
- fsp.Seek(16, SeekOrigin.Current);
- nlen = brp.ReadInt32() - 1;
- for (j = 0; j < nlen; j++) name += brp.ReadChar();
- brp.ReadChar();
- k = tname.LastIndexOf(".");
- tname = tname.Substring(k + 1);
- Console.Write(name + "\t");
- //Console.Write(brp.ReadInt32().ToString("X4") + "\t");
- //brp.ReadInt32(); brp.ReadInt32(); brp.ReadInt32();
- //Console.Write(brp.ReadInt32().ToString("X4") + "\t");
- //Console.Write(brp.ReadInt32().ToString("X4") + "\t");
- //Console.Write(brp.ReadInt32().ToString("X4") + "\t");
- child = brp.ReadInt32();
- //Console.Write(child + "\t");
- //for (k = 0; k < child; k++)
- {
- Console.Write(brp.ReadInt32() + "\t");
- pos = brp.ReadInt32();
- Console.Write(pos.ToString("X4") + "\t");
- Console.Write(brp.ReadInt32().ToString("X4") + "\t");
- }
- Console.WriteLine();
- // skip lesser childs
- fsp.Seek(12 * (child - 1), SeekOrigin.Current);
- // now unpack
- if (name != currtfc)
- {
- currtfc = name;
- if (fsr != null)
- {
- fsr.Close();
- fsr = null;
- }
- if (File.Exists(name + ".tfc"))
- {
- fsr = new FileStream(name + ".tfc", FileMode.Open);
- brr = new BinaryReader(fsr);
- }
- }
- if (fsr!=null)
- {
- fsr.Seek(pos, SeekOrigin.Begin);
- int id = brr.ReadInt32();
- int b_siz = brr.ReadInt32();
- blen = brr.ReadInt32();
- sn = 0;
- brr.ReadInt32(); // full unpacked size
- while (blen > 0)
- {
- ssize_p[sn] = brr.ReadInt32();
- ssize_u[sn] = brr.ReadInt32();
- blen -= ssize_p[sn];
- sn++;
- }
- sx = 512; sy = 512;
- size = ssize_u[0];
- if (size < 0x4000) continue;
- ttype = 0x31545844;
- if (sn == 8)
- {
- sx = 1024; sy = 1024;
- size = sx*sy;
- ttype = 0x35545844;
- }
- else if (sn == 4)
- {
- sx = 1024; sy = 1024;
- size = sx * sy / 2;
- ttype = 0x31545844;
- }
- else if (sn == 2)
- {
- sx = 512; sy = 512;
- size = sx * sy;
- ttype = 0x35545844;
- }
- else if (size == 0x20000)
- {
- sx = 512; sy = 512;
- size = sx * sy / 2;
- ttype = 0x31545844;
- }
- else if (size == 0x10000)
- {
- sx = 256; sy = 256;
- size = sx * sy;
- ttype = 0x35545844;
- }
- else if (size == 0x8000)
- {
- sx = 256; sy = 256;
- size = sx * sy / 2;
- ttype = 0x31545844;
- }
- else if (size == 0x4000)
- {
- sx = 128; sy = 128;
- size = sx * sy / 2;
- ttype = 0x31545844;
- }
- //FileStream fs = new FileStream(name + "_" + i.ToString("d3") + ".dds", FileMode.Create);
- FileStream fs = new FileStream(tname + ".dds", FileMode.Create);
- BinaryWriter bw = new BinaryWriter(fs);
- bw.Write(0x7c20534444L);
- bw.Write(0x1007);
- bw.Write(sy);
- bw.Write(sx);
- bw.Write(size);
- bw.Write(0);
- bw.Write(1); // mips
- fs.Seek(0x2C, SeekOrigin.Current);
- bw.Write(0x20);
- bw.Write(4);
- bw.Write(ttype);
- fs.Seek(0x28, SeekOrigin.Current);
- for (j = 0; j < sn; j++)
- {
- byte[] buf = new byte[ssize_p[j]];
- fsr.Read(buf, 0, ssize_p[j]);
- byte[] unp;
- unp = compressor.Decompress(buf, ssize_u[j]);
- fs.Write(unp, 0, unp.Length);
- }
- bw.Close();
- fs.Close();
- }
- }
- }
- brp.Close();
- fsp.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement