-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathitems_decoder.cpp
More file actions
329 lines (321 loc) · 7.02 KB
/
Copy pathitems_decoder.cpp
File metadata and controls
329 lines (321 loc) · 7.02 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
/*
Decoder of file items.dat which can be found in Growtopia
Copyright (c) 2019 Growtopia Noobs
*/
#include <fstream>
#include <string>
#include <iostream>
#ifndef __linux__
#include <conio.h>
#endif
#include "json.hpp"
#include <iomanip>
using namespace std;
string secret = "PBG892FXX982ABC*";
using json = nlohmann::json;
int main()
{
json jdata;
std::ifstream file("items.dat", std::ios::binary | std::ios::ate);
int size = file.tellg();
if(size == -1) {
cout << "Failed to open file, are you sure that you have items.dat in current directory?" << std::endl;
return 0;
}
char* data = new char[size];
file.seekg(0, std::ios::beg);
if (file.read((char*)(data), size))
{
cout << "Decoding items data..." << endl;
}
else {
cout << "Decoding of items data has failed..." << endl;
#ifndef __linux__
_getch();
#endif
exit(0);
}
int itemCount;
int memPos = 0;
int16_t itemsdatVersion = 0;
memcpy(&itemsdatVersion, data + memPos, 2);
memPos += 2;
memcpy(&itemCount, data + memPos, 4);
memPos += 4;
jdata["itemsdatVersion"] = itemsdatVersion;
jdata["itemCount"] = itemCount;
for (int i=0;i<itemCount;i++) {
json j;
int itemID = 0;
char editableType = 0;
char itemCategory = 0;
char actionType = 0;
char hitSoundType = 0;
string name = "";
string texture = "";
int textureHash = 0;
char itemKind = 0;
int val1;
char textureX = 0;
char textureY = 0;
char spreadType = 0;
char isStripeyWallpaper = 0;
char collisionType = 0;
char breakHits = 0;
int dropChance = 0;
char clothingType = 0;
int16_t rarity = 0;
unsigned char maxAmount = 0;
string extraFile = "";
int extraFileHash = 0;
int audioVolume = 0;
string petName = "";
string petPrefix = "";
string petSuffix = "";
string petAbility = "";
char seedBase = 0;
char seedOverlay = 0;
char treeBase = 0;
char treeLeaves = 0;
int seedColor = 0;
int seedOverlayColor = 0;
int growTime = 0;
short val2;
short isRayman = 0;
string extraOptions = "";
string texture2 = "";
string extraOptions2 = "";
string punchOptions = "";
{
memcpy(&itemID, data + memPos, 4);
memPos += 4;
}
{
editableType = data[memPos];
memPos += 1;
}
{
itemCategory = data[memPos];
memPos += 1;
}
{
actionType = data[memPos];
memPos += 1;
}
{
hitSoundType = data[memPos];
memPos += 1;
}
{
int16_t strLen = *(int16_t*)&data[memPos];
memPos += 2;
for (int j = 0; j < strLen; j++) {
name += data[memPos] ^ (secret[(j + itemID) % secret.length()]);
memPos++;
}
}
{
int16_t strLen = *(int16_t*)&data[memPos];
memPos += 2;
for (int j = 0; j < strLen; j++) {
texture += data[memPos];
memPos++;
}
}
memcpy(&textureHash, data + memPos, 4);
memPos += 4;
itemKind = memPos[data];
memPos += 1;
memcpy(&val1, data + memPos, 4);
memPos += 4;
textureX = data[memPos];
memPos += 1;
textureY = data[memPos];
memPos += 1;
spreadType = data[memPos];
memPos += 1;
isStripeyWallpaper = data[memPos];
memPos += 1;
collisionType = data[memPos];
memPos += 1;
breakHits = data[memPos];
memPos += 1;
memcpy(&dropChance, data + memPos, 4);
memPos += 4;
clothingType = data[memPos];
memPos += 1;
memcpy(&rarity, data + memPos, 2);
memPos += 2;
maxAmount = data[memPos];
memPos += 1;
{
int16_t strLen = *(int16_t*)&data[memPos];
memPos += 2;
for (int j = 0; j < strLen; j++) {
extraFile += data[memPos];
memPos++;
}
}
memcpy(&extraFileHash, data + memPos, 4);
memPos += 4;
memcpy(&audioVolume, data + memPos, 4);
memPos += 4;
{
int16_t strLen = *(int16_t*)&data[memPos];
memPos += 2;
for (int j = 0; j < strLen; j++) {
petName += data[memPos];
memPos++;
}
}
{
int16_t strLen = *(int16_t*)&data[memPos];
memPos += 2;
for (int j = 0; j < strLen; j++) {
petPrefix += data[memPos];
memPos++;
}
}
{
int16_t strLen = *(int16_t*)&data[memPos];
memPos += 2;
for (int j = 0; j < strLen; j++) {
petSuffix += data[memPos];
memPos++;
}
}
{
int16_t strLen = *(int16_t*)&data[memPos];
memPos += 2;
for (int j = 0; j < strLen; j++) {
petAbility += data[memPos];
memPos++;
}
}
{
seedBase = data[memPos];
memPos += 1;
}
{
seedOverlay = data[memPos];
memPos += 1;
}
{
treeBase = data[memPos];
memPos += 1;
}
{
treeLeaves = data[memPos];
memPos += 1;
}
{
memcpy(&seedColor, data + memPos, 4);
memPos += 4;
}
{
memcpy(&seedOverlayColor, data + memPos, 4);
memPos += 4;
}
memPos += 4; // deleted ingredients
{
memcpy(&growTime, data + memPos, 4);
memPos += 4;
}
memcpy(&val2, data + memPos, 2);
memPos += 2;
memcpy(&isRayman, data + memPos, 2);
memPos += 2;
{
int16_t strLen = *(int16_t*)&data[memPos];
memPos += 2;
for (int j = 0; j < strLen; j++) {
extraOptions += data[memPos];
memPos++;
}
}
{
int16_t strLen = *(int16_t*)&data[memPos];
memPos += 2;
for (int j = 0; j < strLen; j++) {
texture2 += data[memPos];
memPos++;
}
}
{
int16_t strLen = *(int16_t*)&data[memPos];
memPos += 2;
for (int j = 0; j < strLen; j++) {
extraOptions2 += data[memPos];
memPos++;
}
}
memPos += 80;
if(itemsdatVersion >= 11) {
{
int16_t strLen = *(int16_t*)&data[memPos];
memPos += 2;
for (int j = 0; j < strLen; j++) {
punchOptions += data[memPos];
memPos++;
}
}
}
if(itemsdatVersion >= 12) {
// TODO: find what those data mean
memPos += 13;
}
If (itemsdatVersion >= 13) {
memPos += 4;
}
if (i != itemID)
cout << "Item are unordered!" << endl;
j["itemID"] = itemID;
j["hitSoundType"] = hitSoundType;
j["name"] = name;
j["texture"] = texture;
j["textureHash"] = textureHash;
j["val1"] = val1;
j["itemKind"] = itemKind;
j["editableType"] = editableType;
j["itemCategory"] = itemCategory;
j["actionType"] = actionType;
j["textureX"] = textureX;
j["textureY"] = textureY;
j["spreadType"] = spreadType;
j["isStripeyWallpaper"] = isStripeyWallpaper;
j["collisionType"] = collisionType;
j["breakHits"] = breakHits;
j["dropChance"] = dropChance;
j["clothingType"] = clothingType;
j["rarity"] = rarity;
j["maxAmount"] = maxAmount;
j["extraFile"] = extraFile;
j["extraFileHash"] = extraFileHash;
j["audioVolume"] = audioVolume;
j["petName"] = petName;
j["petPrefix"] = petPrefix;
j["petSuffix"] = petSuffix;
j["petAbility"] = petAbility;
j["seedColor"] = seedColor;
j["seedBase"] = seedBase;
j["seedOverlay"] = seedOverlay;
j["treeBase"] = treeBase;
j["treeLeaves"] = treeLeaves;
j["seedOverlayColor"] = seedOverlayColor;
j["growTime"] = growTime;
j["val2"] = val2;
j["isRayman"] = isRayman;
j["extraOptions"] = extraOptions;
j["texture2"] = texture2;
j["extraOptions2"] = extraOptions2;
j["punchOptions"] = punchOptions;
jdata["items"].push_back(j);
}
std::ofstream o("data.json");
o << std::setw(4) << jdata << std::endl;
cout << "Succesfully decoded" << endl;
#ifndef __linux__
_getch();
#endif
return 0;
}