Created
December 12, 2012 16:09
-
-
Save misodengaku/4269055 to your computer and use it in GitHub Desktop.
例のアレ
This file contains hidden or 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
--- merge_chr_from_cst2.cpp Thu Dec 13 01:04:24 2012 | |
+++ cst.cpp Thu Dec 13 01:04:26 2012 | |
@@ -8,11 +8,16 @@ | |
// Damnit | |
-#include "as-util.h" | |
+#define ZLIB_WINAPI | |
#include "zlib.h" | |
- | |
+#include <io.h> | |
+#include <string> | |
+#include <iostream> | |
+#include <fstream> | |
#include <set> | |
+using namespace std; | |
+ | |
struct CSTHDR1 { | |
unsigned char signature[8]; // "CatScene" | |
unsigned long length; | |
@@ -35,6 +40,8 @@ | |
unsigned long offset; | |
}; | |
+void writeToFile(char * out_buff, int out_len); //あんまり関数化した意味がない | |
+ | |
int main(int argc, char** argv) { | |
if (argc < 2) { | |
fprintf(stderr, "merge_chr_from_cst2 v1.01 by asmodean\n\n"); | |
@@ -42,31 +49,37 @@ | |
return -1; | |
} | |
- string suffix = argv[1]; | |
+// string suffix = argv[1]; | |
- if (as::stringtol(suffix) == "none") { | |
- suffix = ""; | |
- } | |
+// if (as::stringtol(suffix) == "none") { | |
+// suffix = ""; | |
+// } | |
typedef std::set<string> done_files_t; | |
done_files_t done_files; | |
- for (int i = 2; i < argc; i++) { | |
+ for (int i = 1; i < argc; i++) { | |
string in_filename = argv[i]; | |
- int fd = as::open_or_die(in_filename, O_RDONLY | O_BINARY); | |
+ ifstream ifp = ifstream(argv[i], ios::in|ios::binary); | |
+ if(ifp.bad()) | |
+ { | |
+ cout << "File Open Error" << endl; | |
+ exit(1); | |
+ } | |
CSTHDR1 hdr1; | |
- read(fd, &hdr1, sizeof(hdr1)); | |
+ ifp.read((char *)(&hdr1), sizeof(hdr1)); | |
unsigned long len = hdr1.length; | |
unsigned char* buff = new unsigned char[len]; | |
- read(fd, buff, len); | |
+ ifp.read((char *)buff, len); | |
unsigned long out_len = hdr1.original_length; | |
unsigned char* out_buff = new unsigned char[out_len]; | |
uncompress(out_buff, &out_len, buff, len); | |
- | |
+ writeToFile((char *)out_buff, out_len); | |
+/* | |
CSTHDR2* hdr2 = (CSTHDR2*) out_buff; | |
CSTENTRY1* sections = (CSTENTRY1*) (hdr2 + 1); | |
CSTENTRY2* entries = (CSTENTRY2*) (out_buff + sizeof(*hdr2) + hdr2->table2_offset); | |
@@ -177,13 +190,20 @@ | |
} | |
} | |
} | |
- | |
+*/ | |
delete [] out_buff; | |
delete [] buff; | |
- close(fd); | |
+ ifp.close(); | |
} | |
return 0; | |
} | |
+ | |
+void writeToFile(char * out_buff, int out_len) | |
+{ | |
+ ofstream ofp = ofstream("out.bin", ios::binary|ios::out|ios::trunc); | |
+ ofp.write(out_buff, out_len); | |
+ ofp.close(); | |
+} | |
\ No newline at end of file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment