forked from dank074/habbo-asset-extractor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
figures.php
307 lines (250 loc) · 8.76 KB
/
figures.php
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
<?php
ini_set("display_errors", 1);
set_time_limit(0);
define('OUTPUT_DIRECTORY', dirname(__FILE__) . '/download2/');
define('OFFICIAL_RES_URL', "https://www.habbo.com/");
define('FLASH_CLIENT_URL', "http://habboo-a.akamaihd.net/gordon/PRODUCTION-201506301513-456128588/");
?>
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: #000;
color: #fff;
font-family: monospace;
font-size: 12px;
}
ul {
padding: 0;
margin: 0;
display: block;
}
ul li {
display: block;
height: 1em;
line-height: 1em;
margin: 0;
position: relative;
}
ul li.remove-previous-line {
margin-top: -1em;
}
ul li.ta {
height: auto;
}
ul li.ta textarea {
width: 100em;
height: 10em;
}
ul li p {
padding: 0;
margin: 0;
width: 100%;
height: 1em;
}
ul li p span {
color: #f88;
}
ul li p:last-child {
background-color: #000;
}
</style>
<script>
var complete = false;
var flushingData = function () {
if (document.body) {
window.scrollTo(0, document.body.scrollHeight);
removePreviousLine();
}
if (complete) return;
if (requestAnimationFrame)
requestAnimationFrame(flushingData);
};
flushingData();
var removePreviousLine = function () {
var lines = document.getElementById('console-lines').children;
for (var i = 0; i < lines.length; i++) {
if (lines[i].nextSibling != null && lines[i].className == 'remove-previous-line' && lines[i].nextSibling.className == 'remove-previous-line') {
lines[i].remove();
}
}
};
window.onload = removePreviousLine;
</script>
</head>
<body>
<ul id="console-lines">
<?php
ob_end_flush();
ob_start('mb_output_handler');
$avatar_types = [];
$figure_types = [];
function consoleLog($message, $prevRemove = false)
{
$sp = '';
if ($prevRemove) $sp = ' class="remove-previous-line"';
$message = str_replace("\r", '</p><p>', $message);
$message = str_replace(" ", ' ', $message);
echo '<li' . $sp . '><p>' . $message . '</p></li>';
ob_flush();
flush();
}
function consoleLogBlank()
{
echo '<li class="blank"></li>';
ob_flush();
flush();
}
function consoleLogProgressBar($current, $size, $unit = "kb")
{
$length = (int)(($current / $size) * 100);
$str = sprintf("\r[%-100s] %3d%% (%2d/%2d%s)", str_repeat("=", $length) . ($length == 100 ? "" : ">"), $length, ($current / ($unit == "kb" ? 1024 : 1)), $size / ($unit == "kb" ? 1024 : 1), " " . $unit);
consoleLog($str, true);
}
function checkDIR($path)
{
if (!is_dir($path)) mkdir($path, 0777);
}
function file_get_contents_with_console($filename)
{
consoleLog("Download: " . $filename);
$ctx = stream_context_create();
stream_context_set_params($ctx, array("notification" => "stream_notification_callback"));
$data = @file_get_contents($filename, false, $ctx);
if ($data !== false) {
$size = strlen($data);
consoleLogProgressBar($size, $size);
consoleLogBlank();
consoleLogBlank();
return $data;
}
$err = error_get_last();
consoleLog("<span>Error:</span> " . $err["message"]);
consoleLogBlank();
return false;
}
function stream_notification_callback($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max)
{
static $filesize = null;
switch ($notification_code) {
case STREAM_NOTIFY_RESOLVE:
case STREAM_NOTIFY_COMPLETED:
case STREAM_NOTIFY_AUTH_REQUIRED:
case STREAM_NOTIFY_FAILURE:
case STREAM_NOTIFY_AUTH_RESULT:
break;
case STREAM_NOTIFY_REDIRECTED:
consoleLog("Being redirected to: " . $message);
break;
case STREAM_NOTIFY_CONNECT:
consoleLog("Connected...");
break;
case STREAM_NOTIFY_FILE_SIZE_IS:
$filesize = $bytes_max;
consoleLog("Filesize: " . $filesize);
break;
case STREAM_NOTIFY_MIME_TYPE_IS:
consoleLog("Mime-type: " . $message);
break;
case STREAM_NOTIFY_PROGRESS:
if ($bytes_transferred > 0) {
if ($filesize == 0) {
$str = sprintf("\rUnknown filesize.. %2d kb done..", $bytes_transferred / 1024);
consoleLog($str, true);
} else {
consoleLogProgressBar($bytes_transferred, $filesize);
}
}
break;
}
}
function ExtractFigureMap($filename)
{
consoleLog("<b>Extract FigureMap</b>");
consoleLogBlank();
$xml = file_get_contents_with_console($filename);
$xml = simplexml_load_string($xml);
global $avatar_types;
global $figure_types;
$count = 0;
foreach ($xml[0] as $index => $value):
$name = $value->attributes()->id;
$avatar_types[$count++] = ['id' => $name, 'path' => FLASH_CLIENT_URL . $name . '.swf'];
endforeach;
$count = 0;
foreach ($xml[0] as $index => $value)
foreach ($value->part as $index2 => $value2)
$figure_types[$count++] = $value2->attributes()->type;
$figure_types = array_unique($figure_types);
}
function DownloadAll()
{
global $avatar_types;
consoleLog("Starting Avatars");
foreach ($avatar_types as $index => $value):
consoleLogBlank();
$data = file_get_contents_with_console($value['path']);
$name = $value['id'];
$file_name = OUTPUT_DIRECTORY . $name . '.swf';
file_put_contents($file_name, $data);
ExtractFlash($file_name);
unlink($file_name);
endforeach;
}
function ExtractFlash($flash_file)
{
consoleLog("Analyzing SWF: $flash_file");
$matches = [];
$swf_output = shell_exec("swfextract $flash_file");
preg_match("/PNGs: ID\(s\) (.+)/", $swf_output, $matches);
$ranges = explode(",", $matches[1]);
global $figure_types;
$new_ranges = [];
$count = 0;
foreach ($ranges as $index => $value):
if (strpos($value, '-') !== false):
$explode = explode('-', $value);
for ($i = $explode[0]; $i <= $explode[1];)
$new_ranges[$count++] = $i++;
else:
$new_ranges[$count++] = $value;
endif;
endforeach;
$kaka = [];
$hehe = shell_exec("swfdump -s $flash_file");
consoleLog("Extracting SWF: $flash_file");
foreach ($new_ranges as $index => $value):
$name = sprintf("%04d", $value);
preg_match("/exports $name as \"(.+)\"/", $hehe, $kaka);
$real_value = $kaka[1];
$real_values = $real_value;
foreach ($figure_types as $index2 => $value2):
if (strpos($real_values, "_{$value2}_") !== false):
$exploded = explode("_", $real_values);
$key_net = array_search($value2, $exploded);
$real_exploded = array_slice($exploded, ($key_net - 2));
$real_values = implode("_", $real_exploded);
break;
endif;
endforeach;
consoleLog("File Name: $real_value : $real_values");
$file_name = OUTPUT_DIRECTORY . 'sprites/' . $real_values . '.png';
shell_exec("swfextract $flash_file -p $value -o \"$file_name\"");
endforeach;
}
consoleLog("<b>Habbo SWF FigureMap resource dump Tool</b>");
consoleLogBlank();
consoleLog("OFFICIAL RESOURCE URL : " . OFFICIAL_RES_URL);
consoleLog("FLASH CLIENT URL : " . FLASH_CLIENT_URL);
consoleLog("OUTPUT PATH : " . OUTPUT_DIRECTORY);
consoleLogBlank();
ExtractFigureMap(FLASH_CLIENT_URL . '/figuremap.xml');
DownloadAll();
consoleLog("update complete.");
?>
</ul>
<script> complete = true;
removePreviousLine(); </script>
</body>
</html>