profile.cを追加
This commit is contained in:
commit
534e82f706
1 changed files with 54 additions and 0 deletions
54
c/profile.c
Normal file
54
c/profile.c
Normal file
|
@ -0,0 +1,54 @@
|
|||
/* 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;
|
||||
}
|
Loading…
Add table
Reference in a new issue