Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // WAD reference: http://doom.wikia.com/wiki/WAD
- // DOOM WAD code: code.metager.de/source/xref/idsoftware/doom/w_wad.c
- import std.c.windows.windows;
- import std.stdio;
- struct wadinfo_t
- {
- char[4] identification;
- int numlumps;
- int infotableofs;
- }
- struct filelump_t
- {
- int filepos;
- int size;
- char[8] name;
- }
- // Integers little-endianize themselves?
- void main()
- {
- // Get file.
- // rawRead insists on using arrays, thus the "[1])[0]" hack.
- auto wad = File("doom.wad", "r");
- auto info = wad.rawRead(new wadinfo_t[1])[0];
- // Get lumps.
- // Keeping the name member in filelump_t keeps the code elegant.
- // Associative arrays may not be a good solution if lump order is a concern.
- wad.seek(info.infotableofs);
- filelump_t[char[8]] lumps;
- {
- auto temp = wad.rawRead(new filelump_t[info.numlumps]);
- foreach (lump; temp) lumps[lump.name] = lump;
- }
- // Get ENDOOM lump.
- wad.seek(lumps["ENDOOM"].filepos);
- auto endoom = wad.rawRead(new char[lumps["ENDOOM"].size]);
- // Output ENDOOM.
- // printf() is used because it works with Windows functions.
- auto console = GetStdHandle(STD_OUTPUT_HANDLE);
- for (int i = 0; i < endoom.length; i += 2)
- {
- SetConsoleTextAttribute(console, endoom[i + 1]);
- printf("%.*s", endoom[i] ~ "");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement