Created
August 15, 2020 22:49
-
-
Save Fothsid/e9801b067fe496438d04edf3461958da to your computer and use it in GitHub Desktop.
LZSS decoder for textures in Resident Evil Outbreak
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdint> | |
#include <cstdlib> | |
#include <cstdio> | |
#include <cstring> | |
int main(int argc, char* argv[]) | |
{ | |
char* inputFilename = argv[1]; | |
char* outputFilename = argv[2]; | |
FILE* inputFP = fopen(inputFilename, "rb+"); | |
fseek(inputFP, 0, SEEK_END); | |
size_t srcSize = ftell(inputFP); | |
fseek(inputFP, 0, SEEK_SET); | |
FILE* outputFP = fopen(outputFilename, "wb+"); | |
uint16_t* dest = (uint16_t*)malloc(16 * 1024 * 1024); | |
memset(dest, 0x00, 16 * 1024 * 1024); | |
uint32_t dest_pos = 0; | |
uint32_t blockSize = 0; | |
uint16_t flag = 0; | |
while (ftell(inputFP) < srcSize) | |
{ | |
if (blockSize == 0) | |
{ | |
fread(&flag, 2, 1, inputFP); | |
blockSize = 16; | |
} | |
if (flag & 0x8000) | |
{ | |
uint16_t mode; | |
fread(&mode, 2, 1, inputFP); | |
uint16_t count = mode >> 0xb; | |
if (count == 0) | |
{ | |
fread(&count, 2, 1, inputFP); | |
} | |
uint16_t offset = mode & 0x7ff; | |
if (offset == 0) | |
{ | |
for (int i = 0; i < count; i++) | |
{ | |
dest[dest_pos] = 0; | |
dest_pos++; | |
} | |
} | |
else | |
{ | |
uint32_t pos = dest_pos - offset; | |
for (int i = 0; i < count; i++) | |
{ | |
dest[dest_pos] = dest[pos + i]; | |
dest_pos++; | |
} | |
} | |
} | |
else | |
{ | |
uint16_t val; | |
fread(&val, 2, 1, inputFP); | |
dest[dest_pos] = val; | |
dest_pos++; | |
} | |
flag = flag << 1; | |
blockSize--; | |
} | |
fwrite(dest, dest_pos*2, 1, outputFP); | |
fclose(inputFP); | |
fclose(outputFP); | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment