-
Notifications
You must be signed in to change notification settings - Fork 3
/
th12.cpp
130 lines (123 loc) · 3.8 KB
/
th12.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
* th12.cpp
*
* Created on: 2010-5-9
* Author: Argon
*/
#include "common.h"
void th12decode(char *file, unsigned char * buffer, unsigned int flength) {
char frec[50];
char fraw[50];
unsigned int score[6], maxp[6], graze[6];
unsigned int frame, rlength, llength, i, l;
unsigned char character, ctype, rank, clear;
unsigned char framekey, stage;
unsigned char *rawdata = &buffer[0x24], *stagedata, *replaydata, *fpsdata, *decodedata;
unsigned int length = *((unsigned int*) (&buffer[0x1c]));
unsigned int dlength = *((unsigned int*) (&buffer[0x20]));
short keys[] = { 0xf0a1, 0xfca1, 0xfda1, 0xfda1, 0xfba1, 0x49a8, 0x4ca8, 0x49a8, 0xfaa1, 0x4aa8, 0x4ba8, 0x4aa8, 0xfba1,
0x49a8, 0x4ca8, 0x49a8 };
short skey[61];
sprintf(frec, "%s.txt", file);
sprintf(fraw, "%s.raw", file);
decodedata = new unsigned char[dlength];
decode(rawdata, length, 0x800, 0x5e, 0xe1);
decode(rawdata, length, 0x40, 0x7d, 0x3a);
rlength = decompress(rawdata, decodedata, length);
FILE *fpraw = fopen(fraw, "wb");
fwrite(decodedata, dlength, 1, fpraw);
fclose(fpraw);
printf("Decompression done.");
stagedata = &decodedata[0x70];
stage = decodedata[0x58];
if (stage > 6)
stage = 6;
graze[0] = 0;
for (i = 1; i < stage; ++i) {
stagedata = stagedata + 0xa0 + *((unsigned int*) &stagedata[0x8]);
score[i - 1] = *((unsigned int*) &stagedata[0xc]);
maxp[i] = *((unsigned int*) &stagedata[0x14]);
graze[i] = *((unsigned int*) &stagedata[0x44]);
}
score[stage - 1] = *((unsigned int*) &decodedata[0x14]);
character = decodedata[0x5c];
ctype = decodedata[0x60];
rank = decodedata[0x64];
clear = decodedata[0x68];
if (rank == 0)
maxp[0] = 500000;
else if (rank == 1)
maxp[0] = 1000000;
else if (rank == 2)
maxp[0] = 1500000;
else
maxp[0] = 2000000;
FILE * fprec = fopen(frec, "wb");
fprintf(fprec, "file : %s\r\n", file);
fprintf(fprec, "rawdata size = 0x%x\r\n", length);
fprintf(fprec, "alloced size = 0x%x\r\n", dlength);
fprintf(fprec, "decodedatad size = 0x%x\r\n", rlength);
decodedata[8] = 0;
fprintf(fprec, "----------\r\n");
fprintf(fprec, "player : %s\r\n", decodedata);
fprintf(fprec, "character : ");
if (character == 0)
fprintf(fprec, "Reimu");
else if (character == 1)
fprintf(fprec, "Marisa");
else
fprintf(fprec, "Sanae");
if (ctype == 0)
fprintf(fprec, "A\r\n");
else
fprintf(fprec, "B\r\n");
fprintf(fprec, "rank : ");
if (rank == 0)
fprintf(fprec, "easy\r\n");
else if (rank == 1)
fprintf(fprec, "normal\r\n");
else if (rank == 2)
fprintf(fprec, "hard\r\n");
else if (rank == 3)
fprintf(fprec, "lunatic\r\n");
else
fprintf(fprec, "extra\r\n");
fprintf(fprec, "clear : ");
if (clear == 8)
fprintf(fprec, "all\r\n");
else if (clear == 7)
fprintf(fprec, "extra\r\n");
else
fprintf(fprec, "%d\r\n", clear);
fprintf(fprec, "----------\r\n");
stagedata = &decodedata[0x70];
for (l = 0; l < stage; ++l) {
replaydata = stagedata + 0xa0;
frame = *((unsigned int*) &stagedata[0x4]);
llength = *((unsigned int*) &stagedata[0x8]);
fpsdata = replaydata + frame * 6;
if (rank != 0x4)
fprintf(fprec, "stage : %d ", stagedata[0]);
else
fprintf(fprec, "stage : extra ");
fprintf(fprec, "score = %d0 | frame size = 0x%x | stage length = 0x%x\r\n", score[l], frame, llength);
fprintf(fprec, "= Time = ====================================================== ");
fprintf(fprec, "Operations ======================================================\r\n");
skey[60] = 0;
for (i = 0; i < frame; ++i) {
if (!(i % 60))
fprintf(fprec, "[%06d] ", i / 60);
framekey = (replaydata[i * 6] >> 4) & 0xf;
skey[i % 60] = keys[framekey];
if (!((i + 1) % 60))
fprintf(fprec, "%s\r\n", (char *) skey);
}
if (i % 60) {
skey[i % 60] = 0;
fprintf(fprec, "%s\r\n", (char *) skey);
}
stagedata += llength + 0xa0;
}
fclose(fprec);
delete[] decodedata;
}