forked from gn-math/html
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path118.html
More file actions
474 lines (441 loc) · 17.5 KB
/
118.html
File metadata and controls
474 lines (441 loc) · 17.5 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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
<!-- Ultimate Game Stash file-->
<!-- For the regularly updating doc go to https://docs.google.com/document/d/1_FmH3BlSBQI7FGgAQL59-ZPe8eCxs35wel6JUyVaG8Q/ -->
<!DOCTYPE html>
<html lang="en-us">
<head>
<base href="https://cdn.jsdelivr.net/gh/bubbls/youtube-playables@c5eefc5c13316b94c58e63cb5270b99a13c88fea/solar-smash/">
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>YT Game Wrapper WebGL Template</title>
<link rel="stylesheet" href="TemplateData/style.css" nonce="we8ZPMAc10sjbMeA8f_pRw">
<script src="https://cdn.jsdelivr.net/gh/bubbls/youtube-playables@main/ytgame.js" nonce="we8ZPMAc10sjbMeA8f_pRw">// Load YT Game API code</script>
</head>
<body>
<div id="unity-container" class="unity-desktop">
<canvas id="unity-canvas" width=100% height=100% tabindex="-1"></canvas>
<div id="unity-loading-bar">
<div id="unity-logo"></div>
<div id="unity-progress-bar-empty">
<div id="unity-progress-bar-full"></div>
</div>
</div>
<div id="unity-warning"> </div>
</div>
<script nonce="VdK5nAGpFKd9vu2JazSNaA">
"use strict";
const DIST = 1,
EXT = DIST ? ".min.js" : ".js";
function loadScript(e, r) {
return loadScriptFromPath("lib/" + r + EXT)
}
function loadScriptFromPath(a) {
return new Promise((r, e) => {
if ("object" == typeof window) {
let e = document.createElement("script");
e.type = "text/javascript", e.src = a, e.onload = r, document.head.appendChild(e)
} else "function" == typeof importScripts ? (importScripts(a), r()) : e()
})
}
function currentScriptPath() {
try {
throw new Error("")
} catch (e) {
let r = e.stack,
a = (-1 !== r.indexOf("@") ? r.split("@")[1].split("\n") : r.split("(")[1].split(")"))[0];
return a.substring(0, a.lastIndexOf("/")) + "/"
}
}
let unrarMemoryFileLocation = null,
g_on_loaded_cb = null,
unrarReady = new Promise((e, r) => {
g_on_loaded_cb = e
});
class Unarchiver {
static async load(e = null) {
return e = e || ["zip", "rar", "tar", "gz", "xz", "bz2"], Promise.all(e.map(this._loadFormat))
}
static async _loadFormat(t) {
if (!(t in Unarchiver.loadedFormats)) {
let a = currentScriptPath();
return Unarchiver.loadedFormats[t] = new Promise(async (e, r) => {
switch (t) {
case "zip":
await loadScript(a, "jszip");
break;
case "rar":
unrarMemoryFileLocation = a + "lib/libunrar.js.mem", await loadScript(a, "libunrar"), await unrarReady;
break;
case "tar":
await loadScript(a, "libuntar");
break;
case "gz":
await loadScript(a, "pako_inflate");
break;
case "xz":
await loadScript(a, "xz");
break;
case "bz2":
await loadScript(a, "bz2");
break;
default:
throw new Error("Unknown archive format '" + t + "'.")
}
e()
})
}
await Unarchiver.loadedFormats[t]
}
static open(r, l = null) {
let o = this;
return new Promise((i, e) => {
let n = r.name;
l = l || null;
let s = new FileReader;
s.onload = async () => {
let e = s.result;
o._isGzip(e) ? (await o._loadFormat("gz"), e = pako.inflate(e).buffer) : o._isXZ(e) ? (await o._loadFormat("xz"), e = toXZ(new Uint8Array(e), 0, 0, 0, 2 ** 28).buffer) : o._isBZ2(e) && (await o._loadFormat("bz2"), e = bz2.decompress(new Uint8Array(e)).buffer);
let r = null,
a = [],
t = null;
if (o._isRarFile(e)) t = "rar", await o._loadFormat(t), r = o._rarOpen(n, l, e), a = o._rarGetEntries(r);
else if (o._isZipFile(e)) t = "zip", await o._loadFormat(t), r = await o._zipOpen(n, l, e), a = o._zipGetEntries(r);
else {
if (!o._isTarFile(e)) throw new Error("The archive type is unknown");
t = "tar", await o._loadFormat(t), r = o._tarOpen(n, l, e), a = o._tarGetEntries(r)
}
a.sort((e, r) => e.name.localeCompare(r.name)), i({
file_name: n,
archive_type: t,
array_buffer: e,
entries: a,
handle: r
})
}, s.readAsArrayBuffer(r)
})
}
static close(e) {
e.file_name = null, e.archive_type = null, e.array_buffer = null, e.entries = null, e.handle = null
}
static _rarOpen(e, r, a) {
return {
file_name: e,
array_buffer: a,
password: r,
rar_files: [{
name: e,
size: a.byteLength,
type: "",
content: new Uint8Array(a)
}]
}
}
static async _zipOpen(e, r, a) {
return {
file_name: e,
array_buffer: a,
password: r,
zip: await JSZip.loadAsync(a)
}
}
static _tarOpen(e, r, a) {
return {
file_name: e,
array_buffer: a,
password: r
}
}
static _rarGetEntries(n) {
return Object.entries(readRARFile(n.rar_files, n.password)).map(([, e]) => {
let t = e.name,
i = e.is_file;
return {
name: t,
is_file: e.is_file,
size_compressed: e.size_compressed,
size_uncompressed: e.size_uncompressed,
read: () => new Promise((r, a) => {
if (i) try {
readRARContent(n.rar_files, n.password, t, e => {
r(new File([e], t))
})
} catch (e) {
a(e)
} else r(null)
})
}
})
}
static _zipGetEntries(e) {
return Object.entries(e.zip.files).map(([, a]) => {
let t = a.name,
i = !a.dir;
var e = a._data ? a._data.compressedSize : 0,
r = a._data ? a._data.uncompressedSize : 0;
return {
name: t,
is_file: i,
size_compressed: e,
size_uncompressed: r,
read: () => new Promise(async (e, r) => {
e(i ? new File([await a.async("blob")], t) : null)
})
}
})
}
static _tarGetEntries(s) {
return tarGetEntries(s.file_name, s.array_buffer).map(t => {
let i = t.name,
n = t.is_file;
var e = t.size;
return {
name: i,
is_file: n,
size_compressed: e,
size_uncompressed: e,
read: () => new Promise((e, r) => {
var a;
n ? (a = tarGetEntryData(t, s.array_buffer), e(new File([a.buffer], i))) : e(null)
})
}
})
}
static _isRarFile(e) {
if (e.byteLength < 8) return !1;
e = new Uint8Array(e, 0, 8);
return 82 == e[0] && (69 == e[1] && 126 == e[2] && 94 == e[3] || 97 == e[1] && 114 == e[2] && 33 == e[3] && 26 == e[4] && 7 == e[5] && (0 == e[6] || 1 == e[6] && 0 == e[7]))
}
static _isZipFile(e) {
return this._checkHeader([80, 75, 3, 4], e)
}
static _isTarFile(e) {
return this._checkHeader([117, 115, 116, 97, 114], e, 257, 512)
}
static _isGzip(e) {
return this._checkHeader([31, 139, 8], e)
}
static _isBZ2(e) {
return this._checkHeader([66, 90, 104], e)
}
static _isXZ(e) {
return this._checkHeader([253, 55, 122, 88, 90, 0], e)
}
static _checkHeader(r, e, a = 0, t = null) {
var i = a + r.length;
if (e.byteLength < (t || i)) return !1;
var n = new Uint8Array(e, a, i);
for (let e = 0; e < r.length; ++e)
if (n[e] != r[e]) return !1;
return !0
}
}
Unarchiver.loadedFormats = {};
</script>
<script nonce="VdK5nAGpFKd9vu2JazSNaA"> // Logic for Unity contianer
var container = document.querySelector("#unity-container");
var canvas = document.querySelector("#unity-canvas");
var loadingBar = document.querySelector("#unity-loading-bar");
var progressBarFull = document.querySelector("#unity-progress-bar-full");
var fullscreenButton = document.querySelector("#unity-fullscreen-button");
var fullscreenOverlayButton = document.querySelector("#unity-overlay-fullscreen-button");
var quitcanvas = document.querySelector("#quit-canvas");
var warningBanner = document.querySelector("#unity-warning");
// For YT it is strongly encouraged that all warnings / errors show in
// console and banners should be in game as needed to not confuse users.
//
// If needed please uncomment section below to show a temporary message
// banner/ribbon for a few seconds, or a permanent error message on top
// of the canvas if type=='error'.
function unityShowBanner(msg, type) {
// function updateBannerVisibility() {
// warningBanner.style.display = warningBanner.children.length ? 'block' : 'none';
// }
// var div = document.createElement('div');
// div.innerHTML = msg;
// warningBanner.appendChild(div);
// if (type == 'error') div.style = 'background: red; padding: 10px;';
// else {
// if (type == 'warning') div.style = 'background: yellow; padding: 10px;';
// setTimeout(function() {
// warningBanner.removeChild(div);
// updateBannerVisibility();
// }, 5000);
// }
// updateBannerVisibility();
}
var buildUrl = "Build";
var loaderUrl = buildUrl + "/Build.loader.js";
var config = {
dataUrl: buildUrl + "/Build.data",
frameworkUrl: buildUrl + "/Build.framework.js",
codeUrl: buildUrl + "/Build.wasm",
streamingAssetsUrl: "StreamingAssets",
companyName: "Paradyme Games",
productName: "Live - Solar Smash YouTube",
productVersion: "0.1.0",
showBanner: unityShowBanner,
};
// By default, Unity keeps WebGL canvas render target size matched with
// the DOM size of the canvas element (scaled by window.devicePixelRatio)
// Set this to false if you want to decouple this synchronization from
// happening inside the engine, and you would instead like to size up
// the canvas DOM size and WebGL render target sizes yourself.
// config.matchWebGLToCanvasSize = false;
if (/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)) {
// Mobile device style: fill the whole browser client area with the game canvas:
var meta = document.createElement('meta');
meta.name = 'viewport';
meta.content = 'width=device-width, height=device-height, initial-scale=1.0, user-scalable=no, shrink-to-fit=yes';
document.getElementsByTagName('head')[0].appendChild(meta);
container.className = "unity-mobile";
canvas.className = "unity-mobile";
// To lower canvas resolution on mobile devices to gain some
// performance, uncomment the following line:
//config.devicePixelRatio = 0.8;
} else {
// Desktop style: Render the game canvas in a window that can be maximized to fullscreen:
canvas.style.width = "100%";
canvas.style.height = "100%";
}
loadingBar.style.display = "block";
const subZipStr = '.zip';
const subWASMStr = '.wasm';
const subJSStr = '.js';
const subDataStr = '.data';
// loadResources is only used if you need load Zipped files for .wasm, or .data and need
// them to be decompressed. If the file is not zipped we bypass decompression step automatically,
// however its best to not trigger this if you dont used compression.
// NOTE: GZip does not work ATM. If this is needed Unarchiver will need to be updated.
loadResources = (callback) => {
// Check the Data Url first, followed by the WASM file
var dataUrl = config.dataUrl;
var shouldDecompress = true;
// check if .zip already exists in the URL, if it doesnt check if a .zip file exists
if (!dataUrl.includes(subZipStr)) {
if (UrlExists(dataUrl + subZipStr)) {
dataUrl = dataUrl + subZipStr;
} else {
shouldDecompress = false;
}
}
if (shouldDecompress)
{
var blobTypeData = GetBlobType(dataUrl);
DecompressFile(dataUrl, blobTypeData, (file) => {
config.dataUrl = file;
LoadWASM(callback);
});
}
else
{
LoadWASM(callback);
}
}
// Fetch/Load a file then call our callback
loadZipData = (url, callback) => {
fetch(url)
.then(response => response.blob())
.then(blob => {
callback(blob);
});
}
function LoadWASM(callback)
{
// After Data file is checked decompress and check WASM file, followed by our callback
var codeUrl = config.codeUrl;
var shouldDecompress = true;
// check if .zip already exists in the URL, if it doesnt check if a .zip file exists
if (!codeUrl.includes(subZipStr)) {
if (UrlExists(codeUrl + subZipStr)) {
codeUrl = codeUrl + subZipStr;
} else {
shouldDecompress = false;
}
}
// decompress if using a zip file, otherwise just load regular wasm file
if (shouldDecompress) {
// Decompress the file based on the type, WASM, JS, etc.
// if you need more types please add a const above and modify the type logic below.
var blobTypeWASM = GetBlobType(codeUrl);
DecompressFile(codeUrl, blobTypeWASM, (file) => {
config.codeUrl = file;
callback();
});
} else {
callback();
}
}
function GetBlobType(urlToCheck) {
// if you need more types please add a const above and modify the type logic below.
// Note that octet-stream default is for .data files, JS and WASM have their own MIME types.
var blobType = 'application/octet-stream';
if (urlToCheck.includes(subWASMStr)){
blobType = 'application/wasm';
} else if (urlToCheck.includes(subJSStr)){
blobType = 'text/javascript';
}
return blobType;
}
// Check if URL / File exists
function UrlExists(urlToCheck)
{
var httpReq = new XMLHttpRequest();
httpReq.open('HEAD', urlToCheck, false);
httpReq.send();
return httpReq.status!=404;
}
// decompress files and call callback
// TODO: test and potentially switch to Compression Streams API
function DecompressFile(file, blobMimeType, callback) {
let decompressedFile;
loadZipData(file, (f) => {
Unarchiver.open(f).then(async function (archive) {
for (let entry of archive.entries) {
if (entry.is_file) {
let entryRead = await entry.read();
let entryData = await entryRead.arrayBuffer();
let dataBlob = new Blob([new Uint8Array(entryData)], { type: blobMimeType });
decompressedFile = window.URL.createObjectURL(dataBlob);
}
}
callback(decompressedFile);
});
});
}
var unityGameInstance = null;
// Setup the Unity section once zip file is downloaded and decompressed
function InitUnitySection() {
var script = document.createElement("script");
script.src = loaderUrl;
script.onload = () => {
createUnityInstance(canvas, config, (progress) => {
progressBarFull.style.width = 100 * progress + "%";
}).then((unityInstance) => {
unityGameInstance = unityInstance;
loadingBar.style.display = "none";
}).catch((message) => {
console.error(message);
});
};
document.body.appendChild(script);
}
const originalFetch = window.fetch;
window.fetch = function(input, options) {
if (typeof input === 'string' && input.endsWith("AssetBundles/WebGL/planets")) {
input = 'https://rawcdn.githack.com/bubbls/youtube-playables/c5eefc5c13316b94c58e63cb5270b99a13c88fea/solar-smash/StreamingAssets/AssetBundles/WebGL/planets';
return originalFetch(input, options);
} else if (typeof input === 'string' && input.endsWith("AssetBundles/WebGL/planets2")) {
input = 'https://rawcdn.githack.com/bubbls/youtube-playables/c5eefc5c13316b94c58e63cb5270b99a13c88fea/solar-smash/StreamingAssets/AssetBundles/WebGL/planets2';
return originalFetch(input, options);
}
return originalFetch(input, options);
};
// Path 1: Use this path if no decompression of your .wasm, .data, .js files are needed
//InitUnitySection();
// Path 2: Use this path to Load resources (.wasm, .data) that are Zipped and need to be decompressed
// if you dont use compresseion its best to comment out Path 1 and uncomment Path 2.
loadResources(InitUnitySection); // Uncomment this line to start Unity by loading zipped files
</script>
</body>
</html>