forked from gn-math/html
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path120.html
More file actions
133 lines (118 loc) · 4.43 KB
/
120.html
File metadata and controls
133 lines (118 loc) · 4.43 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
<!DOCTYPE html>
<html lang="en-us">
<head>
<base href="https://cdn.jsdelivr.net/gh/genizy/cg-rip@main/fortzone-battle-royale/">
<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, user-scalable=no">
</head>
<body style="margin:0;padding:0" class="noselect">
<div id="loading-text" style="color: black; font-size: 48px; font-family: cursive; text-align: center; margin-top: 20px;">LOADING...</div>
<canvas id="unity-canvas"
style="position:fixed;top:0;left:0;width:100%;height:100%;outline:none"></canvas>
<script>
const SPLIT_MAP = {"CrazyGames.wasm": null, "CrazyGames.data": null};
</script>
<script>
async function mergeParts(baseUrl) {
const parts = [];
for (let i = 1; i <= 99; i++) {
const testUrl = baseUrl + ".part" + i;
try {
const head = await fetch(testUrl, { method: "HEAD" });
if (!head.ok) break;
parts.push(testUrl);
} catch { break; }
}
if (parts.length === 0) return baseUrl;
const buffers = await Promise.all(parts.map(async (u) => {
const r = await fetch(u);
if (!r.ok) throw new Error("Failed part " + u);
return new Uint8Array(await r.arrayBuffer());
}));
const total = buffers.reduce((a, b) => a + b.length, 0);
const merged = new Uint8Array(total);
let offset = 0;
for (const b of buffers) { merged.set(b, offset); offset += b.length; }
return URL.createObjectURL(new Blob([merged]));
}
async function preMergeAll() {
const map = {};
const files = Object.entries(SPLIT_MAP);
const total = files.length;
let done = 0;
const loadingText = document.getElementById("loading-text");
for (const [file, _] of files) {
const merged = await mergeParts("Build/" + file);
map[file] = merged;
done++;
const percent = Math.floor((done / total) * 100);
loadingText.innerText = `LOADING... ${percent}%`;
console.log("Premerged:", file, "→", merged);
}
loadingText.style.display = "none";
return map;
}
(async () => {
const mergedMap = await preMergeAll();
window.SPLIT_MAP = mergedMap;
const origFetch = window.fetch;
window.fetch = async function(resource, options) {
if (typeof resource === "string") {
const key = resource.split("/").pop();
if (mergedMap[key]) {
console.log("Redirect fetch:", key);
return origFetch(mergedMap[key], options);
}
}
return origFetch(resource, options);
};
const OrigXHR = window.XMLHttpRequest;
window.XMLHttpRequest = function() {
const xhr = new OrigXHR();
const origOpen = xhr.open;
xhr.open = function(method, url, ...rest) {
const key = url.split("/").pop();
if (mergedMap[key]) {
console.log("Redirect XHR:", key);
origOpen.call(xhr, method, mergedMap[key], ...rest);
} else {
origOpen.call(xhr, method, url, ...rest);
}
};
return xhr;
};
const canvas = document.querySelector("#unity-canvas");
const loaderUrl = "Build/CrazyGames.loader.js";
const config = {
dataUrl: "Build/CrazyGames.data",
frameworkUrl: "Build/CrazyGames.framework.js",
codeUrl: "Build/CrazyGames.wasm",
streamingAssetsUrl: "StreamingAssets",
companyName: "Fortzone Battle Royale",
productName: "Fortzone Battle Royale",
productVersion: "1.0.0"
};
const script = document.createElement("script");
script.src = loaderUrl;
script.onload = () => {
createUnityInstance(canvas, config, (progress) => {}).then((unityInstance) => {
window.gameInstance = unityInstance;
}).catch((message) => alert(message));
};
document.body.appendChild(script);
})();
</script>
<script>
function resizeCanvas() {
const canvas = document.getElementById("unity-canvas");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
canvas.style.width = window.innerWidth + "px";
canvas.style.height = window.innerHeight + "px";
}
window.addEventListener("load", resizeCanvas);
window.addEventListener("resize", resizeCanvas);
</script>
</body>
</html>