Skip to content

Commit

Permalink
Added new address name mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
krystalgamer committed Jul 13, 2017
1 parent fe05e31 commit b7a9faf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
9 changes: 6 additions & 3 deletions psx_extractor/bmp.c
Expand Up @@ -3,8 +3,11 @@
#include <stdint.h>
#include <string.h>

extern bool nameAsAdd;

typedef struct __attribute__((packed)){
uint16_t type; uint32_t size;
uint16_t type;
uint32_t size;
uint16_t reserved1, reserved2;
uint32_t offBits;
}BmpFileHeader;
Expand All @@ -31,7 +34,7 @@ typedef struct __attribute__((packed)){
BmpImageHeader image;
}Bmp;

bool WriteBmpFile(uint8_t *buffer, uint32_t width, uint32_t height, uint32_t curTexture){
bool WriteBmpFile(uint8_t *buffer, uint32_t width, uint32_t height, uint32_t fileName){

static Bmp extracted;
memset(&extracted, 0, sizeof(Bmp));
Expand All @@ -58,7 +61,7 @@ bool WriteBmpFile(uint8_t *buffer, uint32_t width, uint32_t height, uint32_t cur
extracted.image.greenMask = 0x07E0;

char extractedName[32];
sprintf(extractedName, "%d.bmp", curTexture);
sprintf(extractedName, (nameAsAdd ? "%08X.bmp" : "%d.bmp"), fileName);

FILE *fp = fopen(extractedName, "wb");
if(!fp)
Expand Down
20 changes: 14 additions & 6 deletions psx_extractor/psx.c
Expand Up @@ -15,6 +15,7 @@ typedef struct{
}Mem;

FILE *fp = NULL;
bool nameAsAdd = false;

bool GetAdd1(Mem *mem){

Expand All @@ -35,8 +36,7 @@ bool GetAdd1(Mem *mem){
if(!fread(&newAdd, 4, 1, fp))
return false;

mem->add1[0] += 4;
mem->add1[0] += newAdd + 4;
mem->add1[0] += newAdd + 8;

fseek(fp, mem->add1[0], SEEK_SET);
if(!fread(&newAdd, 4, 1, fp))
Expand Down Expand Up @@ -103,6 +103,7 @@ typedef struct{
uint16_t width;
uint16_t height;
uint32_t palette;
uint32_t size;
}PSXPVR;

typedef struct{
Expand Down Expand Up @@ -187,18 +188,17 @@ bool ExtractTexture(uint32_t curTexture){
fseek(fp, textureOff, SEEK_SET);
if(!fread(&pvr, sizeof(pvr), 1, fp))
return false;
fseek(fp, 4, SEEK_CUR);

if((pvr.palette & 0xFF00) != 0x300){
puts("Not implement yet.");
printf("Not implement yet %08X.\n", pvr.palette);
return false;
}

uint8_t *decompressed = DecompressTexture(&pvr);
if(!decompressed)
return false;

if(!WriteBmpFile(decompressed, pvr.width, pvr.height, curTexture)){
if(!WriteBmpFile(decompressed, pvr.width, pvr.height, (nameAsAdd ? textureOff + 0x1C : curTexture))){
free(decompressed);
return false;
}
Expand All @@ -212,8 +212,10 @@ bool ExtractTexture(uint32_t curTexture){

int main(int argc, char *argv[]){

if(argc != 2)
if(argc < 2){
printf("Format is:\n%s filename (-a)\n-a flag is to output the filenames as addresses", argv[0]);
return 1;
}

fp = fopen(argv[1], "rb");
if(!fp){
Expand Down Expand Up @@ -251,6 +253,12 @@ int main(int argc, char *argv[]){

printf("There are %d textures.\n", numTextures);

if(argc == 3)
if(!strcmp(argv[2], "-a")){
puts("Filenames will be their addresses!");
nameAsAdd = true;
}

for(int i = 0; i<numTextures; i++){
if(!ExtractTexture(i))
return 8;
Expand Down

0 comments on commit b7a9faf

Please sign in to comment.