-
Notifications
You must be signed in to change notification settings - Fork 95
/
xash.html
532 lines (466 loc) · 16.4 KB
/
xash.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
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
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="MobileOptimized" content="640"/>
<meta name="HandheldFriendly" content="true"/>
<title>Xash3D Emscripten Port</title>
<style>
body {
font-family: arial;
margin: 0;
padding: none;
background-color: #555555;
color: #f0b418;
}
.emscripten { padding-right: 0; margin-left: auto; margin-right: auto; display: block; }
div.emscripten { text-align: center; }
div.emscripten_border { border: 2px solid #F0b418; }
/* the canvas *must not* have any border or padding, or mouse coords will be wrong */
canvas.emscripten { border: 0px none; background-color: black; }
@-webkit-keyframes rotation {
from {-webkit-transform: rotate(0deg);}
to {-webkit-transform: rotate(360deg);}
}
@-moz-keyframes rotation {
from {-moz-transform: rotate(0deg);}
to {-moz-transform: rotate(360deg);}
}
@-o-keyframes rotation {
from {-o-transform: rotate(0deg);}
to {-o-transform: rotate(360deg);}
}
@keyframes rotation {
from {transform: rotate(0deg);}
to {transform: rotate(360deg);}
}
#controls {
display: inline-block;
float: right;
vertical-align: top;
margin-top: 5px;
margin-right: 20px;
}
#output {
width: 100%;
height: 200px;
margin: 0 auto;
margin-top: 10px;
border-left: 0px;
border-right: 0px;
border-style: solid;
padding-left: 0px;
padding-right: 0px;
display: block;
background-color: black;
color: white;
font-family: 'Lucida Console', Monaco, monospace;
outline: none;
border-color:#f0B418;
}
.loader {
border: 4px solid #f3f3f3;
border-radius: 50%;
border-top: 4px solid #ffa600;
width: 16px;
height: 16px;
-webkit-animation: spin 2s linear infinite; /* Safari */
animation: spin 2s linear infinite;
}
/* Safari */
@-webkit-keyframes spin {
0% { -webkit-transform: rotate(0deg); }
100% { -webkit-transform: rotate(360deg); }
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
a.glow, a.glow:hover, a.glow:focus
{
text-decoration: none;
color: #F0B418;
text-shadow: none;
-webkit-transition: 500ms linear 0s;
-moz-transition: 500ms linear 0s;
-o-transition: 500ms linear 0s;
transition: 500ms linear 0s;
outline: 0 none;
}
a.glow:hover, a.glow:focus
{
color: #ffa600;
text-shadow: -1px 1px 8px #ffa600, 1px -1px 8px #ffa600;
}
if (document.createElement("detect").style.textShadow === "") {
document.getElementsByTagName("html")[0].className += " textshadow";
}
</style>
</head>
<body onerror=alert(event); bgcolor=#555555 text=#F0B418 link=#ffa600 vlink=#ffa600>
<div class="emscripten_border">
<canvas style="display:none" class="emscripten" id="canvas" oncontextmenu="event.preventDefault()"></canvas>
</div>
<p><div style=width:100%;height:0px>
<div style="float:left;" id="status">Downloading...</div>
<div id="progress1" style=position:relative;z-index:10;display:none;float:right;width:70%;border-color:#F0B418;border-style:solid;border-width:2px;height:20px><div id=progress style=text-align:center;background-color:#F0B418;border-color:#555555;border-style:solid:border-width:3px;width:50%;height:20px></div></div><br>
</div><br></p>
<div class="loader" id=loader1></div>
<div style=width:100%><span id='controls'>
<a class="glow"><span><input type="checkbox" id="resize">Resize canvas</span></a>
<a class="glow"><span><input type="checkbox" id="pointerLock" checked>Lock/hide mouse pointer </span></a>
<span><input type="button" value="Fullscreen" onclick="Module.requestFullscreen(document.getElementById('pointerLock').checked, document.getElementById('resize').checked)"></span>
</span></div>
<textarea id="output" rows="8"></textarea><div id="asyncDialog" style="float:left"></div>
<a class="glow"><u><div id=optionsTitle><h1>Game Options</h1></u></div></a>
<form style=display:none id=fSettings>Select filesystem for settings and saverestore:<br><br>
<div id=idbHider style=display:none><input name=a type=radio id=rIndexedDB />IndexedDB (Need exit correctly to save changes)<br></div>
<input name=a type=radio id=rLocalStorage />LocalStorage (Sometimes not enough space)<br>
<input name=a type=radio id=rNone checked=true />None(in RAM)<br><br>
<hr>
Select game data source:<br><br>
<div id=pkgHider style=display:none><input name=b type=radio id=rPackage checked=true />Emscripten package from server (cached in IndexedDB if availiable)<select id=selectPkg style=display:none></select><br></div>
<div id=zipHider style=display:none><input name=b type=radio id=rZip />ZIP archive from server (slower, but smaller, no IndexedDB cache)<select id=selectZip style=display:none></select><br></div>
<input name=b type=radio id=rLocalZip />Local ZIP file:<input type=file name=c id=iZipFile /><br><br>
<hr>
Command-line arguments: <input name=d type=text id=iArgs /><br><br>
<input type=button onclick="startXash();return false;" value="Launch Xash3D!" />
<br><hr>
<div id='linksPlaceholder' style=display:none>Download archives to load locally next time:</div><br>
</form>
<script type='text/javascript' src='browserfs.min.js'></script>
<script type='text/javascript'>
var zipMods = [];
var pkgMods = [];
</script>
<script type='text/javascript' src='mods.js'></script>
<script type='text/javascript'>
var statusElement = document.getElementById('status');
var progressElement = document.getElementById('progress');
var asyncDialog = document.getElementById('asyncDialog');
var myerrorbuf = ''
var myerrordate = new Date();
var mounted = false;
var gamedir = 'valve';
var moduleCount = 0;
//var mem = 150;
var mfs;
var zipSize;
// make BrowserFS to work on ES5 browsers
if (!ArrayBuffer['isView']) {
ArrayBuffer.isView = function(a) {
return a !== null && typeof(a) === "object" && a['buffer'] instanceof ArrayBuffer;
};
}
showElement('optionsTitle', false);
function prepareSelects()
{
var len = zipMods.length;
var select = document.getElementById('selectZip');
if( len )
{
showElement('zipHider', true);
if(len > 1)
{
var links = '';
for(var i = 0; i < len; i++)
{
select.options[i] = new Option(zipMods[i][1], zipMods[i][0]);
links += '<br><a href="'+zipMods[i][0]+'">'+zipMods[i][1]+'</a>';
}
select.style.display = 'block';
document.getElementById('linksPlaceholder').innerHTML += links;
showElement('linksPlaceholder', true);
}
}
else
document.getElementById('rZip').checked = false;
len = pkgMods.length;
select = document.getElementById('selectPkg');
if( len )
{
showElement('pkgHider', true);
if(len > 1)
{
for(var i = 0; i < len; i++)
select.options[i] = new Option(pkgMods[i][1], pkgMods[i][0]);
select.style.display = 'block';
}
}
else
document.getElementById('rPackage').checked = false;
if( !zipMods.length && !len )
{
document.getElementById('rLocalZip').checked = true;
showElement('rLocalZip', false);
}
}
try{mem = Math.round(window.location.hash.substring(1));}catch(e){};
var Module = {
TOTAL_MEMORY: mem * 1024 * 1024,
preRun: [],
postRun: [],
print: (function() {
var element = document.getElementById('output');
if (element) element.value = ''; // clear browser cache
return function(text) {
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
// These replacements are necessary if you render to raw HTML
//text = text.replace(/&/g, "&");
//text = text.replace(/</g, "<");
//text = text.replace(/>/g, ">");
//text = text.replace('\n', '<br>', 'g');
//console.log(text);
if(text)
myerrorbuf += text + '\n';
if (element) {
if(element.value.length > 65536)
element.value = element.value.substring(512) + myerrorbuf;
else
element.value += myerrorbuf;
element.scrollTop = element.scrollHeight; // focus on bottom
}
myerrorbuf = ''
};
})(),
printErr: function(text) {
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
if (0) { // XXX disabled for safety typeof dump == 'function') {
dump(text + '\n'); // fast, straight to the real console
} else {
if( myerrorbuf.length > 2048 )
myerrorbuf = 'some lines skipped\n'+ myerrorbuf.substring(512);
myerrorbuf += text + '\n';
if( new Date() - myerrordate > 3000 )
{
myerrordate = new Date();
Module.print();
}
}
},
canvas: (function() {
var canvas = document.getElementById('canvas');
// As a default initial behavior, pop up an alert when webgl context is lost. To make your
// application robust, you may want to override this behavior before shipping!
// See http://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15.2
canvas.addEventListener("webglcontextlost", function(e) { alert('WebGL context lost. You will need to reload the page.'); e.preventDefault(); }, false);
return canvas;
})(),
setStatus: function(text) {
if (!Module.setStatus.last) Module.setStatus.last = { time: Date.now(), text: '' };
if (text === Module.setStatus.text) return;
if( new Date() - myerrordate > 3000 )
{
myerrordate = new Date();
Module.print();
}
statusElement.innerHTML = text;
if( progressElement )
{
var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/);
if(m)
{
var progress = Math.round(parseInt(m[2])*100/parseInt(m[4]));
progressElement.style.color = progress > 5?'#303030':'#aaa000';
progressElement.style.width = progressElement.innerHTML = ''+progress+'%';
}
showElement('progress1', !!m);
}
},
totalDependencies: 0,
monitorRunDependencies: function(left) {
this.totalDependencies = Math.max(this.totalDependencies, left);
if(left)
Module.setStatus('Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')');
}
};
window.onerror = function(event) {
if(mounted)
FS.syncfs(false, function(err){Module.print('Saving IDBFS: '+err);});
if( (''+event).indexOf('SimulateInfiniteLoop') > 0 )
return;
var text = 'Exception thrown: ' + event;
text = text.replace(/&/g, "&");
text = text.replace(/</g, "<");
text = text.replace(/>/g, ">");
text = text.replace('\n', '<br>', 'g');
Module.setStatus(text);
Module.print('Exception thrown: ' + event);
};
function haltRun()
{
}
var savedRun;
function radioChecked(id)
{
var r = document.getElementById('r'+id);
if(r) return r.checked;
return false;
}
function showElement(id, show)
{
var e = document.getElementById(id);
if(!e) return;
e.style.display=show?'block':'none';
}
Module.setStatus('Downloading...');
function startXash()
{
showElement('loader1', false);
showElement('optionsTitle', false);
showElement('fSettings', false);
setupFS();
Module.arguments = document.getElementById('iArgs').value.split(' ');
Module.run = run = savedRun;
if( radioChecked('Zip') )
fetchZIP(zipMods.length>1?document.getElementById('selectZip').value:zipMods[0][0], savedRun);
else if( (!zipMods.length && !pkgMods.length) || radioChecked('LocalZip') )
{
var reader = new FileReader();
reader.onload = function(){
mountZIP(reader.result);
Module.print("Loaded zip data");
savedRun();
};
reader.readAsArrayBuffer(document.getElementById('iZipFile').files[0]);
}
else if( radioChecked('Package') )
{
var script = document.createElement('script');
script.onload = savedRun;
document.body.appendChild(script);
script.src = pkgMods.length>1?document.getElementById('selectPkg').value:pkgMods[0][0];
}
showElement('canvas', true);
window.addEventListener("beforeunload", function (e) {
var confirmationMessage = 'Leave the game?';
(e || window.event).returnValue = confirmationMessage; //Gecko + IE
return confirmationMessage; //Gecko + Webkit, Safari, Chrome etc.
});
}
function mountZIP(data)
{
var Buffer = BrowserFS.BFSRequire('buffer').Buffer;
mfs.mount('/zip', new BrowserFS.FileSystem.ZipFS(Buffer.from(data)));
FS.mount(new BrowserFS.EmscriptenFS(), {root:'/zip'}, '/rodir');
}
function fetchZIP(packageName, cb)
{
var xhr = new XMLHttpRequest();
xhr.open('GET', packageName, true);
xhr.responseType = 'arraybuffer';
xhr.onprogress = function(event) {
var url = packageName;
var size;
if (event.total) size = event.total;
else size = zipMods[document.getElementById('selectZip').selectedIndex][2];
if (event.loaded) {
var total = size;
var loaded = event.loaded;
var num = 0;
if (Module['setStatus']) Module['setStatus']('Downloading data... (' + loaded + '/' + total + ')');
} else if (!Module.dataFileDownloads) {
if (Module['setStatus']) Module['setStatus']('Downloading data...');
}
};
xhr.onerror = function(event) {
throw new Error("NetworkError");
}
xhr.onload = function(event) {
if (xhr.status == 200 || xhr.status == 304 || xhr.status == 206 || (xhr.status == 0 && xhr.response)) { // file URLs can return 0
mountZIP(xhr.response);
cb();
} else {
throw new Error(xhr.statusText + " : " + xhr.responseURL);
}
};
xhr.send(null);
}
function setupFS()
{
FS.mkdir('/rodir');
FS.mkdir('/xash');
try
{
mfs = new BrowserFS.FileSystem.MountableFileSystem();
BrowserFS.initialize(mfs);
}
catch(e)
{
mfs = undefined;
Module.print('Failed to initialize BrowserFS: '+e);
}
if( radioChecked('IndexedDB'))
{
FS.mount(IDBFS,{},'/xash');
FS.syncfs(true,function(err){if(err)Module.print('Loading IDBFS: ' + err);});
mounted = true;
}
if( radioChecked('LocalStorage') && mfs)
{
mfs.mount('/ls', new BrowserFS.FileSystem.LocalStorage());
FS.mount(new BrowserFS.EmscriptenFS(), {root:'/ls'}, '/xash');
Module.print('LocalStorage mounted');
}
FS.chdir('/xash/');
}
function skipRun()
{
savedRun = run;
Module.run = haltRun;
run = haltRun;
Module.setStatus("Engine downloaded!");
showElement('loader1', false);
showElement('optionsTitle', true);
if(window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB)
showElement('idbHider', true);
prepareSelects();
showElement('fSettings',true);
ENV.XASH3D_GAMEDIR = gamedir;
ENV.XASH3D_RODIR = '/rodir'
function loadModule(name)
{
var script = document.createElement('script');
script.onload = function(){moduleCount++;if(moduleCount==3){Module.setStatus("Scripts downloaded!");}};
document.body.appendChild(script);
script.src = name + ".js";
}
loadModule("server");
loadModule("client");
loadModule("menu");
};
Module.preInit = [skipRun];
Module.websocket = [];
Module.websocket.url = 'wsproxy://the-swank.pp.ua:3000/'
ENV = [];
</script>
<script>
(function() {
var memoryInitializer = 'xash.html.mem';
if (typeof Module['locateFile'] === 'function') {
memoryInitializer = Module['locateFile'](memoryInitializer);
} else if (Module['memoryInitializerPrefixURL']) {
memoryInitializer = Module['memoryInitializerPrefixURL'] + memoryInitializer;
}
var xhr = Module['memoryInitializerRequest'] = new XMLHttpRequest();
xhr.open('GET', memoryInitializer, true);
xhr.responseType = 'arraybuffer';
xhr.send(null);
})();
var script = document.createElement('script');
script.src = "xash.js";
document.body.appendChild(script);
</script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-68666752-4', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>