Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public struct Tex
- {
- public UInt32 Width;
- public UInt32 Height;
- public byte Format;
- public byte MagCount;
- public UInt16 SanityCheck;
- public string filename;
- public string OldFN;
- public string FilePath;
- public string Extension;
- public string OldFullPath;
- public UInt64 size;
- public string basedir;
- }
- public bool AddTex(string path, ArrayList ReceivingList)
- {
- Tex NewTex = new Tex();
- NewTex.OldFN = Path.GetFileNameWithoutExtension(path);
- NewTex.FilePath = Path.GetDirectoryName(path);
- NewTex.Extension = Path.GetExtension(path);
- byte[] byteArray = File.ReadAllBytes(path);
- using (BinaryReader br = new BinaryReader(new MemoryStream(byteArray)))
- {
- if (br.BaseStream.Length < 0x80) return false;
- br.BaseStream.Seek(0, SeekOrigin.Begin);
- NewTex.Width = br.ReadUInt32();
- NewTex.Height = br.ReadUInt32();
- NewTex.Format = br.ReadByte();
- if (NewTex.Format > 0xD || NewTex.Format < 0) return false;
- NewTex.MagCount = br.ReadByte();
- NewTex.SanityCheck = br.ReadUInt16();
- NewTex.filename = "";
- bool readname = false;
- while (br.BaseStream.Position < 0x80)
- {
- byte b = br.ReadByte();
- if (b == 0) readname = true;
- if (readname)
- {
- while (br.BaseStream.Position < 0x80)
- {
- if (br.ReadByte() != 0) return false;
- }
- }
- else
- {
- char c = (char)b;
- NewTex.filename += c;
- }
- }
- if (!NewTex.filename.EndsWith(".tex",true,System.Globalization.CultureInfo.CurrentCulture)){
- return false;
- }
- NewTex.size = Convert.ToUInt64(br.BaseStream.Length);
- int basedirofs = Math.Max(NewTex.FilePath.LastIndexOf('\\'),NewTex.FilePath.LastIndexOf('/'));
- NewTex.basedir = NewTex.FilePath.Substring(basedirofs+1);
- NewTex.OldFullPath = "" + path;
- }
- ReceivingList.Add(NewTex);
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement