public static ThpsWad FromList(string filename) { if (!File.Exists(filename)) { throw new Exception($"Not found: {filename}"); } string[] lines = File.ReadAllLines(filename); string path = Path.ChangeExtension(filename, ""); ThpsWad wad = new ThpsWad(); foreach (string s in lines) { if (s != "") { ThpsWadEntry en = new ThpsWadEntry(Path.Combine(path, s.Trim())); wad.Entries.Add(en); } } wad.RecalcOffsets(); return(wad); }
public void Read(BinaryReader hed, BinaryReader wad) { if (hed.BaseStream.Length % 12 != 0) { if ((hed.BaseStream.Length - 4) % 12 != 0) { throw new Exception("not a THPS2 WAD"); } } do { ThpsWadEntry en = new ThpsWadEntry(hed); wad.BaseStream.Position = en.offset; en.Data = wad.ReadBytes(en.size); Entries.Add(en); }while (hed.BaseStream.Length - hed.BaseStream.Position >= 12); }
public void LoadFromLayout(string f) { string[] lol = File.ReadAllLines(f); string rootpath = Path.GetDirectoryName(f); string wadfold = Path.GetFileNameWithoutExtension(f).Replace("__layout", ""); WADname = wadfold; for (int i = 0; i < lol.Count(); i++) { string path = rootpath + "\\" + wadfold + "\\" + lol[i]; if (File.Exists(path)) { byte[] data = File.ReadAllBytes(path); ThpsWadEntry ff = new ThpsWadEntry(lol[i], 0, data.Length); ff.Data = data; if (lol[i][0] == '_' && lol[i][lol[i].Length - 1] == '_') { string nname = lol[i].Trim('_'); uint hex = 0; Checksum.TryParseHex(nname, out hex); ff.checksum = hex; } else { ff.checksum = Checksum.CalcLegacy(lol[i], false); } files.Add(ff); } } }
public static ThpsWad FromFolder(string path) { if (!Directory.Exists(path)) { throw new Exception($"Not found: {path}"); } string[] lines = Directory.GetFiles(path); ThpsWad wad = new ThpsWad(); foreach (string s in lines) { if (s != "") { ThpsWadEntry en = new ThpsWadEntry(s); wad.Entries.Add(en); } } wad.RecalcOffsets(); return(wad); }