Advertisement
Guest User

Untitled

a guest
May 8th, 2017
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.82 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Text;
  5. using Lzo64;
  6.  
  7. namespace Marvel_heroes_tfc
  8. {
  9. class Marvel_heroes_tfc
  10. {
  11. static void Main(string[] args)
  12. {
  13. LZOCompressor compressor = new LZOCompressor();
  14. int i, j, k;
  15.  
  16. FileStream fsp = new FileStream(args[0], FileMode.Open);
  17. BinaryReader brp = new BinaryReader(fsp);
  18.  
  19. if (Path.GetExtension(args[0]) == ".tfc")
  20. {
  21.  
  22. int nf = 0;
  23. int sn, blen;
  24. int[] ssize_u = new int[200]; // hope there will be no more than 200 segments
  25. int[] ssize_p = new int[200];
  26.  
  27. while (fsp.Position < fsp.Length)
  28. {
  29. Console.WriteLine(nf + " " + fsp.Position.ToString("X8"));
  30.  
  31. FileStream fs = new FileStream(Path.GetFileNameWithoutExtension(args[0]) + "_" + nf.ToString("d3") + ".tex", FileMode.Create);
  32. BinaryWriter bw = new BinaryWriter(fs);
  33.  
  34. int id = brp.ReadInt32();
  35. int b_siz = brp.ReadInt32();
  36.  
  37. blen = brp.ReadInt32();
  38. sn = 0;
  39. brp.ReadInt32(); // full unpacked size
  40. while (blen > 0)
  41. {
  42. ssize_p[sn] = brp.ReadInt32();
  43. ssize_u[sn] = brp.ReadInt32();
  44. blen -= ssize_p[sn];
  45. sn++;
  46. }
  47. for (j = 0; j < sn; j++)
  48. {
  49. byte[] buf = new byte[ssize_p[j]];
  50. fsp.Read(buf, 0, ssize_p[j]);
  51. byte[] unp;
  52. unp = compressor.Decompress(buf, ssize_u[j]);
  53. fs.Write(unp, 0, unp.Length);
  54. }
  55.  
  56. bw.Close();
  57. fs.Close();
  58.  
  59. nf++;
  60. }
  61. }
  62. else if (Path.GetExtension(args[0]) == ".bin") // manifest
  63. {
  64. int sn, blen, pos;
  65. int[] ssize_u = new int[200]; // hope there will be no more than 200 segments
  66. int[] ssize_p = new int[200];
  67.  
  68. int nf = brp.ReadInt32();
  69. int len, nlen, child;
  70. string name, tname, currtfc="";
  71.  
  72. int sx, sy, ttype, size;
  73.  
  74. FileStream fsr = null;
  75. BinaryReader brr = null;
  76. //FileStream fsr = new FileStream("CharTextures.tfc", FileMode.Open);
  77. //BinaryReader brr = new BinaryReader(fsr);
  78.  
  79. for (i = 0; i < nf; i++)
  80. {
  81. Console.Write(i + "\t");
  82. len = brp.ReadInt32()-1;
  83. name = ""; tname = "";
  84. for (j = 0; j < len; j++) tname += brp.ReadChar();
  85. brp.ReadChar();
  86. fsp.Seek(16, SeekOrigin.Current);
  87. nlen = brp.ReadInt32() - 1;
  88. for (j = 0; j < nlen; j++) name += brp.ReadChar();
  89. brp.ReadChar();
  90. k = tname.LastIndexOf(".");
  91. tname = tname.Substring(k + 1);
  92. Console.Write(name + "\t");
  93. //Console.Write(brp.ReadInt32().ToString("X4") + "\t");
  94. //brp.ReadInt32(); brp.ReadInt32(); brp.ReadInt32();
  95. //Console.Write(brp.ReadInt32().ToString("X4") + "\t");
  96. //Console.Write(brp.ReadInt32().ToString("X4") + "\t");
  97. //Console.Write(brp.ReadInt32().ToString("X4") + "\t");
  98. child = brp.ReadInt32();
  99. //Console.Write(child + "\t");
  100. //for (k = 0; k < child; k++)
  101. {
  102. Console.Write(brp.ReadInt32() + "\t");
  103. pos = brp.ReadInt32();
  104. Console.Write(pos.ToString("X4") + "\t");
  105. Console.Write(brp.ReadInt32().ToString("X4") + "\t");
  106. }
  107. Console.WriteLine();
  108. // skip lesser childs
  109. fsp.Seek(12 * (child - 1), SeekOrigin.Current);
  110.  
  111. // now unpack
  112. if (name != currtfc)
  113. {
  114. currtfc = name;
  115. if (fsr != null)
  116. {
  117. fsr.Close();
  118. fsr = null;
  119. }
  120. if (File.Exists(name + ".tfc"))
  121. {
  122. fsr = new FileStream(name + ".tfc", FileMode.Open);
  123. brr = new BinaryReader(fsr);
  124. }
  125. }
  126. if (fsr!=null)
  127. {
  128. fsr.Seek(pos, SeekOrigin.Begin);
  129. int id = brr.ReadInt32();
  130. int b_siz = brr.ReadInt32();
  131.  
  132. blen = brr.ReadInt32();
  133. sn = 0;
  134. brr.ReadInt32(); // full unpacked size
  135. while (blen > 0)
  136. {
  137. ssize_p[sn] = brr.ReadInt32();
  138. ssize_u[sn] = brr.ReadInt32();
  139. blen -= ssize_p[sn];
  140. sn++;
  141. }
  142.  
  143. sx = 512; sy = 512;
  144. size = ssize_u[0];
  145. if (size < 0x4000) continue;
  146. ttype = 0x31545844;
  147. if (sn == 8)
  148. {
  149. sx = 1024; sy = 1024;
  150. size = sx*sy;
  151. ttype = 0x35545844;
  152. }
  153. else if (sn == 4)
  154. {
  155. sx = 1024; sy = 1024;
  156. size = sx * sy / 2;
  157. ttype = 0x31545844;
  158. }
  159. else if (sn == 2)
  160. {
  161. sx = 512; sy = 512;
  162. size = sx * sy;
  163. ttype = 0x35545844;
  164. }
  165. else if (size == 0x20000)
  166. {
  167. sx = 512; sy = 512;
  168. size = sx * sy / 2;
  169. ttype = 0x31545844;
  170. }
  171. else if (size == 0x10000)
  172. {
  173. sx = 256; sy = 256;
  174. size = sx * sy;
  175. ttype = 0x35545844;
  176. }
  177. else if (size == 0x8000)
  178. {
  179. sx = 256; sy = 256;
  180. size = sx * sy / 2;
  181. ttype = 0x31545844;
  182. }
  183. else if (size == 0x4000)
  184. {
  185. sx = 128; sy = 128;
  186. size = sx * sy / 2;
  187. ttype = 0x31545844;
  188. }
  189. //FileStream fs = new FileStream(name + "_" + i.ToString("d3") + ".dds", FileMode.Create);
  190. FileStream fs = new FileStream(tname + ".dds", FileMode.Create);
  191. BinaryWriter bw = new BinaryWriter(fs);
  192.  
  193. bw.Write(0x7c20534444L);
  194. bw.Write(0x1007);
  195. bw.Write(sy);
  196. bw.Write(sx);
  197. bw.Write(size);
  198. bw.Write(0);
  199. bw.Write(1); // mips
  200. fs.Seek(0x2C, SeekOrigin.Current);
  201. bw.Write(0x20);
  202. bw.Write(4);
  203. bw.Write(ttype);
  204. fs.Seek(0x28, SeekOrigin.Current);
  205.  
  206. for (j = 0; j < sn; j++)
  207. {
  208. byte[] buf = new byte[ssize_p[j]];
  209. fsr.Read(buf, 0, ssize_p[j]);
  210. byte[] unp;
  211. unp = compressor.Decompress(buf, ssize_u[j]);
  212. fs.Write(unp, 0, unp.Length);
  213. }
  214.  
  215. bw.Close();
  216. fs.Close();
  217. }
  218. }
  219. }
  220.  
  221. brp.Close();
  222. fsp.Close();
  223. }
  224. }
  225. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement