From 534e82f706cc261579d1a2c065202c5b8db596e5 Mon Sep 17 00:00:00 2001 From: kou029w Date: Tue, 28 Aug 2012 21:40:32 +0900 Subject: [PATCH] =?UTF-8?q?profile.c=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- c/profile.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 c/profile.c diff --git a/c/profile.c b/c/profile.c new file mode 100644 index 0000000..bba749e --- /dev/null +++ b/c/profile.c @@ -0,0 +1,54 @@ +/* profile.c +Windows版、Mac版の洞窟物語のセーブデータ(Profile.dat)を相互に変換する +(C)2012 kou029w - MIT License +*/ + +#include +#include + +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 1){ + return profile(argv[1]); + } + return 0; +}