Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstring>
- int main()
- {
- FILE* f = fopen("mars.mad", "rb");
- if (!f) return 1;
- char MadHeader[0x1C];
- if (fread(MadHeader, 0x1C, 1, f) < 1)
- return 2;
- if (strncmp(MadHeader, "WORLD&ART&DIRECTORY", 0x13))
- {
- printf("Not a valid MAD file\n");
- return 3;
- }
- int MadCount = *(int*)(MadHeader+0x14);
- int MadOffset = *(int*)(MadHeader+0x18);
- fseek(f, MadOffset, SEEK_SET);
- char* MadTable = new char[MadCount*16];
- fread(MadTable, 16, MadCount, f);
- char* v10 = MadTable;
- for (int i = 0; i < MadCount*16; i++)
- *v10++ -= 0x30;
- // lets convert this bullshit into a WAD file
- FILE* f2 = fopen("mars.wad", "wb");
- if (!f2) return 4;
- int MadCountReal = MadCount;
- int MadOffsetC = MadOffset;
- for (int i = 0; i < MadCount; i++)
- {
- int LumpOffset = *(int*)(MadTable+i*16);
- int LumpSize = *(int*)(MadTable+i*16+4);
- char LumpName[9];
- LumpName[8] = 0;
- memcpy(LumpName, MadTable+i*16+8, 8);
- if (LumpSize < 0)
- continue;
- if (LumpSize)
- {
- char* lump = new char[LumpSize];
- fseek(f, LumpOffset, SEEK_SET);
- fseek(f2, LumpOffset, SEEK_SET);
- fread(lump, LumpSize, 1, f);
- fwrite(lump, LumpSize, 1, f2);
- delete[] lump;
- }
- }
- for (int i = 0; i < MadCount; i++)
- {
- int LumpOffset = *(int*)(MadTable+i*16);
- int LumpSize = *(int*)(MadTable+i*16+4);
- char LumpName[9];
- LumpName[8] = 0;
- memcpy(LumpName, MadTable+i*16+8, 8);
- if (LumpSize < 0)
- {
- MadCountReal--;
- continue;
- }
- fseek(f2, MadOffsetC, SEEK_SET);
- MadOffsetC += 16;
- fwrite(&LumpOffset, 4, 1, f2);
- fwrite(&LumpSize, 4, 1, f2);
- fwrite(LumpName, 8, 1, f2);
- }
- fseek(f2, 0, SEEK_SET);
- fwrite("PWAD", 4, 1, f2);
- fwrite(&MadCount, 4, 1, f2);
- fwrite(&MadOffset, 4, 1, f2);
- fclose(f2);
- fclose(f);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement