-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
177 lines (161 loc) · 6.23 KB
/
index.html
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
<head>
<script src="https://cdn.glitch.global/266c51d7-8fa0-473e-aabc-8bbc01617388/mainemu.js"></script>
<style>
body {
font-family: Arial, sans-serif;
background-color: #1a1a1a;
margin: 0;
padding: 0;
color: white;
overflow: hidden;
}
#screen_container {
display: flex;
justify-content: center;
align-items: center;
background-color: #333;
width: 100vw !important;
height: 100vh !important;
}
canvas {
width: 100vw !important;
height: 100vh !important;
}
</style>
</head>
<body>
<p id="loadingtxt">-</p>
<progress id="progressBar"></progress>
<div id="screen_container">
<div style="white-space: pre; font: 14px monospace; line-height: 14px"></div>
<canvas style="display: none"></canvas>
<img style="display: none; user-select: none;" id="fixsound" src="https://cdn.glitch.global/e4eb72c7-d339-4628-9a7a-a99205dfe71a/New%20Project%20(4).png">
</div>
<script>
function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function fetchWithProgress(url, progressCallback) {
const response = await fetch(url, { cache: "force-cache" });
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
const contentLength = response.headers.get('Content-Length');
if (!contentLength) throw new Error('Content-Length response header unavailable');
const total = parseInt(contentLength, 10);
let loaded = 0;
const reader = response.body.getReader();
const stream = new ReadableStream({
start(controller) {
function read() {
reader.read().then(({ done, value }) => {
if (done) {
controller.close();
return;
}
loaded += value.byteLength;
progressCallback(loaded, total);
controller.enqueue(value);
read();
}).catch(error => {
console.error(error);
controller.error(error);
});
}
read();
}
});
return new Response(stream);
}
async function loadgame() {
const drive = [
"https://cdn.glitch.me/7ef48d40-458f-4cec-8e53-da16e95c3f5c/win98.img_1.bin",
"https://cdn.glitch.me/7ef48d40-458f-4cec-8e53-da16e95c3f5c/win98.img_2.bin",
"https://cdn.glitch.me/7ef48d40-458f-4cec-8e53-da16e95c3f5c/win98.img_3.bin",
"https://cdn.glitch.me/7ef48d40-458f-4cec-8e53-da16e95c3f5c/win98.img_4.bin",
"https://cdn.glitch.me/7ef48d40-458f-4cec-8e53-da16e95c3f5c/win98.img_5.bin",
"https://cdn.glitch.me/7ef48d40-458f-4cec-8e53-da16e95c3f5c/win98.img_6.bin",
"https://cdn.glitch.me/7ef48d40-458f-4cec-8e53-da16e95c3f5c/win98.img_7.bin",
"https://cdn.glitch.me/7ef48d40-458f-4cec-8e53-da16e95c3f5c/win98.img_8.bin"
];
const screenContainer = document.getElementById('screen_container');
screenContainer.addEventListener('click', function() {
lockPointer();
});
function lockPointer() {
screenContainer.requestPointerLock().then(() => {
document.documentElement.style.pointerEvents = 'none';
document.addEventListener('pointerlockchange', pointerLockChange);
}).catch((err) => {
document.documentElement.style.pointerEvents = 'auto';
});
}
function pointerLockChange() {
if (document.pointerLockElement === screenContainer) {
// Pointer locked
} else {
document.documentElement.style.pointerEvents = 'auto';
document.removeEventListener('pointerlockchange', pointerLockChange);
}
}
const loadingtext = document.getElementById("loadingtxt");
const progressBar = document.getElementById("progressBar");
const progressCallback = (loaded, total) => {
loadingtext.textContent = `Loading Age of Empires 2 [${((loaded / total) * 100).toFixed(2)}%]`;
progressBar.value = (loaded / total);
};
const stater = await fetchWithProgress("https://cdn.glitch.me/7ef48d40-458f-4cec-8e53-da16e95c3f5c/aoe2sound.bin.zst", progressCallback);
let statres = await stater.blob();
loadingtext.remove();
progressBar.remove();
window.chunksize = 256;
document.getElementById("fixsound").style.display = "";
document.addEventListener("click", async function() {
if (document.getElementById("fixsound")) {
document.getElementById("fixsound").remove();
const emulator = new V86({
wasm_path: "https://cdn.glitch.global/266c51d7-8fa0-473e-aabc-8bbc01617388/v86.wasm",
bios: {
url: "https://cdn.glitch.global/266c51d7-8fa0-473e-aabc-8bbc01617388/seabios.bin"
},
vga_bios: {
url: "https://cdn.glitch.global/266c51d7-8fa0-473e-aabc-8bbc01617388/vgabios.bin"
},
hda: {
url: drive,
size: 2 * 1024 * 1024 * 1024,
async: true
},
memory_size: 512 * 1024 * 1024,
screen_container: screenContainer,
autostart: false
});
var filereader = new FileReader();
filereader.onload = async function(e) {
while (true) {
try {
await emulator.restore_state(e.target.result);
emulator.run();
statres = null;
break;
} catch(err) {
console.log(err);
await delay(1000);
}
}
};
await filereader.readAsArrayBuffer(statres);
}
});
window.drives = [];
for (const imgurl of drive) {
const thisimg = await fetch(imgurl);
const toblob = await thisimg.blob();
const blobUrl = URL.createObjectURL(toblob);
window.drives.push(blobUrl);
console.log("Preloaded chunk " + imgurl);
}
console.log("Entire drive has been preloaded");
}
loadgame();
</script>
</body>
</html>