Advertisement
SciresM

tex code

Sep 16th, 2014
524
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. public struct Tex
  2. {
  3. public UInt32 Width;
  4. public UInt32 Height;
  5. public byte Format;
  6. public byte MagCount;
  7. public UInt16 SanityCheck;
  8. public string filename;
  9. public string OldFN;
  10. public string FilePath;
  11. public string Extension;
  12. public string OldFullPath;
  13.  
  14. public UInt64 size;
  15. public string basedir;
  16. }
  17.  
  18. public bool AddTex(string path, ArrayList ReceivingList)
  19. {
  20. Tex NewTex = new Tex();
  21. NewTex.OldFN = Path.GetFileNameWithoutExtension(path);
  22. NewTex.FilePath = Path.GetDirectoryName(path);
  23. NewTex.Extension = Path.GetExtension(path);
  24. byte[] byteArray = File.ReadAllBytes(path);
  25. using (BinaryReader br = new BinaryReader(new MemoryStream(byteArray)))
  26. {
  27. if (br.BaseStream.Length < 0x80) return false;
  28. br.BaseStream.Seek(0, SeekOrigin.Begin);
  29. NewTex.Width = br.ReadUInt32();
  30. NewTex.Height = br.ReadUInt32();
  31. NewTex.Format = br.ReadByte();
  32. if (NewTex.Format > 0xD || NewTex.Format < 0) return false;
  33. NewTex.MagCount = br.ReadByte();
  34. NewTex.SanityCheck = br.ReadUInt16();
  35. NewTex.filename = "";
  36. bool readname = false;
  37. while (br.BaseStream.Position < 0x80)
  38. {
  39. byte b = br.ReadByte();
  40. if (b == 0) readname = true;
  41. if (readname)
  42. {
  43. while (br.BaseStream.Position < 0x80)
  44. {
  45. if (br.ReadByte() != 0) return false;
  46. }
  47. }
  48. else
  49. {
  50. char c = (char)b;
  51. NewTex.filename += c;
  52. }
  53. }
  54. if (!NewTex.filename.EndsWith(".tex",true,System.Globalization.CultureInfo.CurrentCulture)){
  55. return false;
  56. }
  57. NewTex.size = Convert.ToUInt64(br.BaseStream.Length);
  58. int basedirofs = Math.Max(NewTex.FilePath.LastIndexOf('\\'),NewTex.FilePath.LastIndexOf('/'));
  59. NewTex.basedir = NewTex.FilePath.Substring(basedirofs+1);
  60. NewTex.OldFullPath = "" + path;
  61. }
  62. ReceivingList.Add(NewTex);
  63. return true;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement