hpf.d 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. module system.hpf;
  2. import system.debugwriteln;
  3. import system.uintreader;
  4. import std.string;
  5. import std.conv;
  6. import std.stdio;
  7. import variables;
  8. // not ready for use yet
  9. ParsedChunk[] parseArchive(string filename) {
  10. ParsedChunk[] parsedChunks;
  11. auto archive = File(filename, "rb");
  12. ubyte[] offsetsChunkLengthUbyte = new ubyte[4];
  13. archive.rawRead(offsetsChunkLengthUbyte);
  14. debugWriteln(offsetsChunkLengthUbyte); // debug
  15. int offsetsChunkLength = readUInt32(offsetsChunkLengthUbyte, 0);
  16. debugWriteln("int repres: ", offsetsChunkLength);
  17. ubyte[] chunks = new ubyte[offsetsChunkLength];
  18. archive.rawRead(chunks);
  19. int currentOffset = 0;
  20. while (readUInt32(chunks, currentOffset) != 0xFFFFFFFF) {
  21. parsedChunks ~= ParsedChunk(
  22. cast(int)readUInt32(chunks, currentOffset),
  23. cast(int)readUInt32(chunks, currentOffset+4)
  24. );
  25. currentOffset+=8;
  26. }
  27. return parsedChunks;
  28. }
  29. ubyte[] loadFileFromHPF(string filename, ParsedChunk[] parsedChunks, int fileIndex) {
  30. auto archive = File(filename, "rb");
  31. archive.seek(parsedChunks[fileIndex].offset);
  32. ubyte[] file = new ubyte[parsedChunks[fileIndex].length];
  33. archive.rawRead(file);
  34. return file;
  35. }