2014-git-work/cpp/profile.c

55 lines
1.3 KiB
C
Raw Normal View History

2012-08-28 21:40:32 +09:00
/* profile.c
Windows版Mac版の洞窟物語のセーブデータ(Profile.dat)
(C)2012 kou029w - MIT License
*/
#include <stdio.h>
#include <stdint.h>
uint16_t swab2(uint16_t x) {
return ((x << 8) | (x >> 8));
}
uint32_t swab4(uint32_t x){
return ((swab2(x) << 16) | swab2(x >> 16));
}
int profile(char *filename){
FILE *fp;
unsigned char bufc[8];
unsigned short bufs[8];
unsigned int bufi[123];
int i;
size_t size;
fp = fopen(filename, "rb");
if(fp == NULL) return 1;
size = fread(bufc, sizeof(unsigned char), 8, fp);
fwrite(bufc, sizeof(unsigned char), size, stdout);
size = fread(bufi, sizeof(unsigned int), 5, fp);
for(i=0; i<size; i++){
bufi[i] = swab4(bufi[i]);
}
fwrite(bufi, sizeof(unsigned int), size, stdout);
size = fread(bufs, sizeof(unsigned short), 8, fp);
for(i=0; i<size; i++){
bufs[i] = swab2(bufs[i]);
}
fwrite(bufs, sizeof(unsigned short), size, stdout);
size = fread(bufi, sizeof(unsigned int), 123, fp);
for(i=0; i<size; i++){
bufi[i] = swab4(bufi[i]);
}
fwrite(bufi, sizeof(unsigned int), size, stdout);
while(size = fread(bufc, sizeof(unsigned char), 8, fp)){
fwrite(bufc, sizeof(unsigned char), size, stdout);
}
return 0;
}
int main(int argc, char *argv[]){
if(argc > 1){
return profile(argv[1]);
}
return 0;
}