-
Notifications
You must be signed in to change notification settings - Fork 5
/
bundle.js
1990 lines (1671 loc) · 60.4 KB
/
bundle.js
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
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
var Buffer=require("__browserify_Buffer");var save={
name: null,
data: null,
blocks: [],
offsets: {}
}
function processFile(file){
var reader=new FileReader();
reader.onload=function(e){
var raw=e.target.result;
save.data=new Buffer(new Uint8Array(raw));
parseBlockLocations();
parseCheatLocations();
loadStats();
}
reader.readAsArrayBuffer(file);
}
function parseBlockLocations(){
for (ii = 0; ii < (save.data.length - 4); ii++){
if (save.data.toString('utf8',ii,ii+1) == 'B'){
if (save.data.toString('utf8',ii,ii+5) == 'BLOCK'){
save.blocks.push(ii+5);
}
}
}
}
function parseCheatLocations(){
save.offsets.money = [save.blocks[15]+8, save.blocks[15]+20];
save.offsets.infRun = save.blocks[15]+36;
save.offsets.fastReload = save.blocks[15]+37;
save.offsets.fireProof = save.blocks[15]+38;
save.offsets.maxHealth = save.blocks[15]+39;
save.offsets.maxArmor = save.blocks[15]+40;
save.offsets.currentHealth = save.blocks[2]+48;
save.offsets.currentArmor = save.blocks[2]+52;
}
function loadStats(){
document.getElementById('curMoney').value=save.data.readUInt32LE(save.offsets.money[0]);
document.getElementById('maxHealth').value=save.data.readUInt8(save.offsets.maxHealth);
document.getElementById('maxArmor').value=save.data.readUInt8(save.offsets.maxArmor);
document.getElementById('curHealth').value=save.data.readFloatLE(save.offsets.currentHealth);
document.getElementById('curArmor').value=save.data.readFloatLE(save.offsets.currentArmor);
if (save.data.readInt8(save.offsets.infRun)==1){
document.getElementById('infRunCheat').checked=true;
}else{
document.getElementById('infRunCheat').checked=false;
}
if (save.data.readInt8(save.offsets.fireProof)==1){
document.getElementById('fireProofCheat').checked=true;
}else{
document.getElementById('infRunCheat').checked=false;
}
}
function writeStats(){
save.data.writeUInt32LE(parseInt(document.getElementById('curMoney').value), save.offsets.money[0]);
save.data.writeUInt32LE(parseInt(document.getElementById('curMoney').value), save.offsets.money[1]);
save.data.writeUInt8(parseInt(document.getElementById('maxHealth').value), save.offsets.maxHealth);
save.data.writeUInt8(parseInt(document.getElementById('maxArmor').value), save.offsets.maxArmor);
save.data.writeFloatLE(parseFloat(document.getElementById('curHealth').value), save.offsets.currentHealth);
save.data.writeFloatLE(parseFloat(document.getElementById('curArmor').value), save.offsets.currentArmor);
save.data.writeInt8(document.getElementById('infRunCheat').checked?1:0, save.offsets.infRun);
save.data.writeInt8(document.getElementById('fireProofCheat').checked?1:0, save.offsets.fireProof);
writeChecksum();
}
function calculateSum(){
var final=0;
for (ii = 0; ii < (save.data.length - 4); ii++){
final+=save.data.readUInt8(ii);
}
return final;
}
function writeChecksum(){
save.data.writeUInt32LE(calculateSum(), save.data.length - 4);
var blob = new Blob([save.data.buffer]);
saveAs(blob, save.name)
}
function handleFileSelect(evt) {
evt.stopPropagation();
evt.preventDefault();
var files = evt.dataTransfer.files;
var output;
var f=files[0];
save.name=f.name;
output='<strong>'+ escape(f.name) +'</strong> - '+f.size+ ' bytes, last modified: '+(f.lastModifiedDate ? f.lastModifiedDate.toLocaleDateString() : 'n/a')+'<br><br>';
document.getElementById('list').innerHTML = output;
processFile(evt.dataTransfer.files[0]);
}
function handleDragOver(evt) {
evt.stopPropagation();
evt.preventDefault();
evt.dataTransfer.clearData();
evt.dataTransfer.dropEffect = 'copy'; // Explicitly show this is a copy.
}
// Setup the dnd listeners.
var dropZone = document.getElementById('drop_zone');
dropZone.addEventListener('dragover', handleDragOver, false);
dropZone.addEventListener('drop', handleFileSelect, false);
document.getElementById("modSaveBut").addEventListener("click", writeStats, false);
document.getElementById("maxMoney").addEventListener("click", function(){
document.getElementById("curMoney").value="999999999";
}, false);
document.getElementById("maxCurHealth").addEventListener("click", function(){
document.getElementById("curHealth").value="255";
}, false);
document.getElementById("maxMaxHealth").addEventListener("click", function(){
document.getElementById("maxHealth").value="255";
}, false);
document.getElementById("maxCurArmor").addEventListener("click", function(){
document.getElementById("curArmor").value="255";
}, false);
document.getElementById("maxMaxArmor").addEventListener("click", function(){
document.getElementById("maxArmor").value="255";
}, false);
},{"__browserify_Buffer":2}],2:[function(require,module,exports){
require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({"PcZj9L":[function(require,module,exports){
var TA = require('typedarray')
var xDataView = typeof DataView === 'undefined'
? TA.DataView : DataView
var xArrayBuffer = typeof ArrayBuffer === 'undefined'
? TA.ArrayBuffer : ArrayBuffer
var xUint8Array = typeof Uint8Array === 'undefined'
? TA.Uint8Array : Uint8Array
exports.Buffer = Buffer
exports.SlowBuffer = Buffer
exports.INSPECT_MAX_BYTES = 50
Buffer.poolSize = 8192
var browserSupport
/**
* Class: Buffer
* =============
*
* The Buffer constructor returns instances of `Uint8Array` that are augmented
* with function properties for all the node `Buffer` API functions. We use
* `Uint8Array` so that square bracket notation works as expected -- it returns
* a single octet.
*
* By augmenting the instances, we can avoid modifying the `Uint8Array`
* prototype.
*
* Firefox is a special case because it doesn't allow augmenting "native" object
* instances. See `ProxyBuffer` below for more details.
*/
function Buffer (subject, encoding) {
var type = typeof subject
// Work-around: node's base64 implementation
// allows for non-padded strings while base64-js
// does not..
if (encoding === 'base64' && type === 'string') {
subject = stringtrim(subject)
while (subject.length % 4 !== 0) {
subject = subject + '='
}
}
// Find the length
var length
if (type === 'number')
length = coerce(subject)
else if (type === 'string')
length = Buffer.byteLength(subject, encoding)
else if (type === 'object')
length = coerce(subject.length) // Assume object is an array
else
throw new Error('First argument needs to be a number, array or string.')
var buf = augment(new xUint8Array(length))
if (Buffer.isBuffer(subject)) {
// Speed optimization -- use set if we're copying from a Uint8Array
buf.set(subject)
} else if (isArrayIsh(subject)) {
// Treat array-ish objects as a byte array.
for (var i = 0; i < length; i++) {
if (Buffer.isBuffer(subject))
buf[i] = subject.readUInt8(i)
else
buf[i] = subject[i]
}
} else if (type === 'string') {
buf.write(subject, 0, encoding)
}
return buf
}
// STATIC METHODS
// ==============
Buffer.isEncoding = function(encoding) {
switch ((encoding + '').toLowerCase()) {
case 'hex':
case 'utf8':
case 'utf-8':
case 'ascii':
case 'binary':
case 'base64':
case 'ucs2':
case 'ucs-2':
case 'utf16le':
case 'utf-16le':
case 'raw':
return true
default:
return false
}
}
Buffer.isBuffer = function isBuffer (b) {
return b && b._isBuffer
}
Buffer.byteLength = function (str, encoding) {
switch (encoding || 'utf8') {
case 'hex':
return str.length / 2
case 'utf8':
case 'utf-8':
return utf8ToBytes(str).length
case 'ascii':
case 'binary':
return str.length
case 'base64':
return base64ToBytes(str).length
default:
throw new Error('Unknown encoding')
}
}
Buffer.concat = function (list, totalLength) {
if (!Array.isArray(list)) {
throw new Error('Usage: Buffer.concat(list, [totalLength])\n' +
'list should be an Array.')
}
var i
var buf
if (list.length === 0) {
return new Buffer(0)
} else if (list.length === 1) {
return list[0]
}
if (typeof totalLength !== 'number') {
totalLength = 0
for (i = 0; i < list.length; i++) {
buf = list[i]
totalLength += buf.length
}
}
var buffer = new Buffer(totalLength)
var pos = 0
for (i = 0; i < list.length; i++) {
buf = list[i]
buf.copy(buffer, pos)
pos += buf.length
}
return buffer
}
// INSTANCE METHODS
// ================
function _hexWrite (buf, string, offset, length) {
offset = Number(offset) || 0
var remaining = buf.length - offset
if (!length) {
length = remaining
} else {
length = Number(length)
if (length > remaining) {
length = remaining
}
}
// must be an even number of digits
var strLen = string.length
if (strLen % 2 !== 0) {
throw new Error('Invalid hex string')
}
if (length > strLen / 2) {
length = strLen / 2
}
for (var i = 0; i < length; i++) {
var byte = parseInt(string.substr(i * 2, 2), 16)
if (isNaN(byte)) throw new Error('Invalid hex string')
buf[offset + i] = byte
}
Buffer._charsWritten = i * 2
return i
}
function _utf8Write (buf, string, offset, length) {
var bytes, pos
return Buffer._charsWritten = blitBuffer(utf8ToBytes(string), buf, offset, length)
}
function _asciiWrite (buf, string, offset, length) {
var bytes, pos
return Buffer._charsWritten = blitBuffer(asciiToBytes(string), buf, offset, length)
}
function _binaryWrite (buf, string, offset, length) {
return _asciiWrite(buf, string, offset, length)
}
function _base64Write (buf, string, offset, length) {
var bytes, pos
return Buffer._charsWritten = blitBuffer(base64ToBytes(string), buf, offset, length)
}
function BufferWrite (string, offset, length, encoding) {
// Support both (string, offset, length, encoding)
// and the legacy (string, encoding, offset, length)
if (isFinite(offset)) {
if (!isFinite(length)) {
encoding = length
length = undefined
}
} else { // legacy
var swap = encoding
encoding = offset
offset = length
length = swap
}
offset = Number(offset) || 0
var remaining = this.length - offset
if (!length) {
length = remaining
} else {
length = Number(length)
if (length > remaining) {
length = remaining
}
}
encoding = String(encoding || 'utf8').toLowerCase()
switch (encoding) {
case 'hex':
return _hexWrite(this, string, offset, length)
case 'utf8':
case 'utf-8':
return _utf8Write(this, string, offset, length)
case 'ascii':
return _asciiWrite(this, string, offset, length)
case 'binary':
return _binaryWrite(this, string, offset, length)
case 'base64':
return _base64Write(this, string, offset, length)
default:
throw new Error('Unknown encoding')
}
}
function BufferToString (encoding, start, end) {
var self = (this instanceof ProxyBuffer)
? this._proxy
: this
encoding = String(encoding || 'utf8').toLowerCase()
start = Number(start) || 0
end = (end !== undefined)
? Number(end)
: end = self.length
// Fastpath empty strings
if (end === start)
return ''
switch (encoding) {
case 'hex':
return _hexSlice(self, start, end)
case 'utf8':
case 'utf-8':
return _utf8Slice(self, start, end)
case 'ascii':
return _asciiSlice(self, start, end)
case 'binary':
return _binarySlice(self, start, end)
case 'base64':
return _base64Slice(self, start, end)
default:
throw new Error('Unknown encoding')
}
}
function BufferToJSON () {
return {
type: 'Buffer',
data: Array.prototype.slice.call(this, 0)
}
}
// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
function BufferCopy (target, target_start, start, end) {
var source = this
if (!start) start = 0
if (!end && end !== 0) end = this.length
if (!target_start) target_start = 0
// Copy 0 bytes; we're done
if (end === start) return
if (target.length === 0 || source.length === 0) return
// Fatal error conditions
if (end < start)
throw new Error('sourceEnd < sourceStart')
if (target_start < 0 || target_start >= target.length)
throw new Error('targetStart out of bounds')
if (start < 0 || start >= source.length)
throw new Error('sourceStart out of bounds')
if (end < 0 || end > source.length)
throw new Error('sourceEnd out of bounds')
// Are we oob?
if (end > this.length)
end = this.length
if (target.length - target_start < end - start)
end = target.length - target_start + start
// copy!
for (var i = 0; i < end - start; i++)
target[i + target_start] = this[i + start]
}
function _base64Slice (buf, start, end) {
var bytes = buf.slice(start, end)
return require('base64-js').fromByteArray(bytes)
}
function _utf8Slice (buf, start, end) {
var bytes = buf.slice(start, end)
var res = ''
var tmp = ''
var i = 0
while (i < bytes.length) {
if (bytes[i] <= 0x7F) {
res += decodeUtf8Char(tmp) + String.fromCharCode(bytes[i])
tmp = ''
} else {
tmp += '%' + bytes[i].toString(16)
}
i++
}
return res + decodeUtf8Char(tmp)
}
function _asciiSlice (buf, start, end) {
var bytes = buf.slice(start, end)
var ret = ''
for (var i = 0; i < bytes.length; i++)
ret += String.fromCharCode(bytes[i])
return ret
}
function _binarySlice (buf, start, end) {
return _asciiSlice(buf, start, end)
}
function _hexSlice (buf, start, end) {
var len = buf.length
if (!start || start < 0) start = 0
if (!end || end < 0 || end > len) end = len
var out = ''
for (var i = start; i < end; i++) {
out += toHex(buf[i])
}
return out
}
// TODO: add test that modifying the new buffer slice will modify memory in the
// original buffer! Use code from:
// http://nodejs.org/api/buffer.html#buffer_buf_slice_start_end
function BufferSlice (start, end) {
var len = this.length
start = clamp(start, len, 0)
end = clamp(end, len, len)
return augment(this.subarray(start, end)) // Uint8Array built-in method
}
function BufferReadUInt8 (offset, noAssert) {
var buf = this
if (!noAssert) {
assert(offset !== undefined && offset !== null, 'missing offset')
assert(offset < buf.length, 'Trying to read beyond buffer length')
}
if (offset >= buf.length)
return
return buf[offset]
}
function _readUInt16 (buf, offset, littleEndian, noAssert) {
if (!noAssert) {
assert(typeof (littleEndian) === 'boolean',
'missing or invalid endian')
assert(offset !== undefined && offset !== null, 'missing offset')
assert(offset + 1 < buf.length, 'Trying to read beyond buffer length')
}
var len = buf.length
if (offset >= len) {
return
} else if (offset + 1 === len) {
var dv = new xDataView(new xArrayBuffer(2))
dv.setUint8(0, buf[len - 1])
return dv.getUint16(0, littleEndian)
} else {
return buf._dataview.getUint16(offset, littleEndian)
}
}
function BufferReadUInt16LE (offset, noAssert) {
return _readUInt16(this, offset, true, noAssert)
}
function BufferReadUInt16BE (offset, noAssert) {
return _readUInt16(this, offset, false, noAssert)
}
function _readUInt32 (buf, offset, littleEndian, noAssert) {
if (!noAssert) {
assert(typeof (littleEndian) === 'boolean',
'missing or invalid endian')
assert(offset !== undefined && offset !== null, 'missing offset')
assert(offset + 3 < buf.length, 'Trying to read beyond buffer length')
}
var len = buf.length
if (offset >= len) {
return
} else if (offset + 3 >= len) {
var dv = new xDataView(new xArrayBuffer(4))
for (var i = 0; i + offset < len; i++) {
dv.setUint8(i, buf[i + offset])
}
return dv.getUint32(0, littleEndian)
} else {
return buf._dataview.getUint32(offset, littleEndian)
}
}
function BufferReadUInt32LE (offset, noAssert) {
return _readUInt32(this, offset, true, noAssert)
}
function BufferReadUInt32BE (offset, noAssert) {
return _readUInt32(this, offset, false, noAssert)
}
function BufferReadInt8 (offset, noAssert) {
var buf = this
if (!noAssert) {
assert(offset !== undefined && offset !== null,
'missing offset')
assert(offset < buf.length, 'Trying to read beyond buffer length')
}
if (offset >= buf.length)
return
return buf._dataview.getInt8(offset)
}
function _readInt16 (buf, offset, littleEndian, noAssert) {
if (!noAssert) {
assert(typeof (littleEndian) === 'boolean',
'missing or invalid endian')
assert(offset !== undefined && offset !== null,
'missing offset')
assert(offset + 1 < buf.length, 'Trying to read beyond buffer length')
}
var len = buf.length
if (offset >= len) {
return
} else if (offset + 1 === len) {
var dv = new xDataView(new xArrayBuffer(2))
dv.setUint8(0, buf[len - 1])
return dv.getInt16(0, littleEndian)
} else {
return buf._dataview.getInt16(offset, littleEndian)
}
}
function BufferReadInt16LE (offset, noAssert) {
return _readInt16(this, offset, true, noAssert)
}
function BufferReadInt16BE (offset, noAssert) {
return _readInt16(this, offset, false, noAssert)
}
function _readInt32 (buf, offset, littleEndian, noAssert) {
if (!noAssert) {
assert(typeof (littleEndian) === 'boolean',
'missing or invalid endian')
assert(offset !== undefined && offset !== null, 'missing offset')
assert(offset + 3 < buf.length, 'Trying to read beyond buffer length')
}
var len = buf.length
if (offset >= len) {
return
} else if (offset + 3 >= len) {
var dv = new xDataView(new xArrayBuffer(4))
for (var i = 0; i + offset < len; i++) {
dv.setUint8(i, buf[i + offset])
}
return dv.getInt32(0, littleEndian)
} else {
return buf._dataview.getInt32(offset, littleEndian)
}
}
function BufferReadInt32LE (offset, noAssert) {
return _readInt32(this, offset, true, noAssert)
}
function BufferReadInt32BE (offset, noAssert) {
return _readInt32(this, offset, false, noAssert)
}
function _readFloat (buf, offset, littleEndian, noAssert) {
if (!noAssert) {
assert(typeof (littleEndian) === 'boolean',
'missing or invalid endian')
assert(offset + 3 < buf.length, 'Trying to read beyond buffer length')
}
return buf._dataview.getFloat32(offset, littleEndian)
}
function BufferReadFloatLE (offset, noAssert) {
return _readFloat(this, offset, true, noAssert)
}
function BufferReadFloatBE (offset, noAssert) {
return _readFloat(this, offset, false, noAssert)
}
function _readDouble (buf, offset, littleEndian, noAssert) {
if (!noAssert) {
assert(typeof (littleEndian) === 'boolean',
'missing or invalid endian')
assert(offset + 7 < buf.length, 'Trying to read beyond buffer length')
}
return buf._dataview.getFloat64(offset, littleEndian)
}
function BufferReadDoubleLE (offset, noAssert) {
return _readDouble(this, offset, true, noAssert)
}
function BufferReadDoubleBE (offset, noAssert) {
return _readDouble(this, offset, false, noAssert)
}
function BufferWriteUInt8 (value, offset, noAssert) {
var buf = this
if (!noAssert) {
assert(value !== undefined && value !== null, 'missing value')
assert(offset !== undefined && offset !== null, 'missing offset')
assert(offset < buf.length, 'trying to write beyond buffer length')
verifuint(value, 0xff)
}
if (offset >= buf.length) return
buf[offset] = value
}
function _writeUInt16 (buf, value, offset, littleEndian, noAssert) {
if (!noAssert) {
assert(value !== undefined && value !== null, 'missing value')
assert(typeof (littleEndian) === 'boolean',
'missing or invalid endian')
assert(offset !== undefined && offset !== null, 'missing offset')
assert(offset + 1 < buf.length, 'trying to write beyond buffer length')
verifuint(value, 0xffff)
}
var len = buf.length
if (offset >= len) {
return
} else if (offset + 1 === len) {
var dv = new xDataView(new xArrayBuffer(2))
dv.setUint16(0, value, littleEndian)
buf[offset] = dv.getUint8(0)
} else {
buf._dataview.setUint16(offset, value, littleEndian)
}
}
function BufferWriteUInt16LE (value, offset, noAssert) {
_writeUInt16(this, value, offset, true, noAssert)
}
function BufferWriteUInt16BE (value, offset, noAssert) {
_writeUInt16(this, value, offset, false, noAssert)
}
function _writeUInt32 (buf, value, offset, littleEndian, noAssert) {
if (!noAssert) {
assert(value !== undefined && value !== null, 'missing value')
assert(typeof (littleEndian) === 'boolean',
'missing or invalid endian')
assert(offset !== undefined && offset !== null, 'missing offset')
assert(offset + 3 < buf.length, 'trying to write beyond buffer length')
verifuint(value, 0xffffffff)
}
var len = buf.length
if (offset >= len) {
return
} else if (offset + 3 >= len) {
var dv = new xDataView(new xArrayBuffer(4))
dv.setUint32(0, value, littleEndian)
for (var i = 0; i + offset < len; i++) {
buf[i + offset] = dv.getUint8(i)
}
} else {
buf._dataview.setUint32(offset, value, littleEndian)
}
}
function BufferWriteUInt32LE (value, offset, noAssert) {
_writeUInt32(this, value, offset, true, noAssert)
}
function BufferWriteUInt32BE (value, offset, noAssert) {
_writeUInt32(this, value, offset, false, noAssert)
}
function BufferWriteInt8 (value, offset, noAssert) {
var buf = this
if (!noAssert) {
assert(value !== undefined && value !== null, 'missing value')
assert(offset !== undefined && offset !== null, 'missing offset')
assert(offset < buf.length, 'Trying to write beyond buffer length')
verifsint(value, 0x7f, -0x80)
}
if (offset >= buf.length) return
buf._dataview.setInt8(offset, value)
}
function _writeInt16 (buf, value, offset, littleEndian, noAssert) {
if (!noAssert) {
assert(value !== undefined && value !== null, 'missing value')
assert(typeof (littleEndian) === 'boolean',
'missing or invalid endian')
assert(offset !== undefined && offset !== null, 'missing offset')
assert(offset + 1 < buf.length, 'Trying to write beyond buffer length')
verifsint(value, 0x7fff, -0x8000)
}
var len = buf.length
if (offset >= len) {
return
} else if (offset + 1 === len) {
var dv = new xDataView(new xArrayBuffer(2))
dv.setInt16(0, value, littleEndian)
buf[offset] = dv.getUint8(0)
} else {
buf._dataview.setInt16(offset, value, littleEndian)
}
}
function BufferWriteInt16LE (value, offset, noAssert) {
_writeInt16(this, value, offset, true, noAssert)
}
function BufferWriteInt16BE (value, offset, noAssert) {
_writeInt16(this, value, offset, false, noAssert)
}
function _writeInt32 (buf, value, offset, littleEndian, noAssert) {
if (!noAssert) {
assert(value !== undefined && value !== null, 'missing value')
assert(typeof (littleEndian) === 'boolean',
'missing or invalid endian')
assert(offset !== undefined && offset !== null, 'missing offset')
assert(offset + 3 < buf.length, 'Trying to write beyond buffer length')
verifsint(value, 0x7fffffff, -0x80000000)
}
var len = buf.length
if (offset >= len) {
return
} else if (offset + 3 >= len) {
var dv = new xDataView(new xArrayBuffer(4))
dv.setInt32(0, value, littleEndian)
for (var i = 0; i + offset < len; i++) {
buf[i + offset] = dv.getUint8(i)
}
} else {
buf._dataview.setInt32(offset, value, littleEndian)
}
}
function BufferWriteInt32LE (value, offset, noAssert) {
_writeInt32(this, value, offset, true, noAssert)
}
function BufferWriteInt32BE (value, offset, noAssert) {
_writeInt32(this, value, offset, false, noAssert)
}
function _writeFloat (buf, value, offset, littleEndian, noAssert) {
if (!noAssert) {
assert(value !== undefined && value !== null, 'missing value')
assert(typeof (littleEndian) === 'boolean',
'missing or invalid endian')
assert(offset !== undefined && offset !== null, 'missing offset')
assert(offset + 3 < buf.length, 'Trying to write beyond buffer length')
verifIEEE754(value, 3.4028234663852886e+38, -3.4028234663852886e+38)
}
var len = buf.length
if (offset >= len) {
return
} else if (offset + 3 >= len) {
var dv = new xDataView(new xArrayBuffer(4))
dv.setFloat32(0, value, littleEndian)
for (var i = 0; i + offset < len; i++) {
buf[i + offset] = dv.getUint8(i)
}
} else {
buf._dataview.setFloat32(offset, value, littleEndian)
}
}
function BufferWriteFloatLE (value, offset, noAssert) {
_writeFloat(this, value, offset, true, noAssert)
}
function BufferWriteFloatBE (value, offset, noAssert) {
_writeFloat(this, value, offset, false, noAssert)
}
function _writeDouble (buf, value, offset, littleEndian, noAssert) {
if (!noAssert) {
assert(value !== undefined && value !== null, 'missing value')
assert(typeof (littleEndian) === 'boolean',
'missing or invalid endian')
assert(offset !== undefined && offset !== null, 'missing offset')
assert(offset + 7 < buf.length,
'Trying to write beyond buffer length')
verifIEEE754(value, 1.7976931348623157E+308, -1.7976931348623157E+308)
}
var len = buf.length
if (offset >= len) {
return
} else if (offset + 7 >= len) {
var dv = new xDataView(new xArrayBuffer(8))
dv.setFloat64(0, value, littleEndian)
for (var i = 0; i + offset < len; i++) {
buf[i + offset] = dv.getUint8(i)
}
} else {
buf._dataview.setFloat64(offset, value, littleEndian)
}
}
function BufferWriteDoubleLE (value, offset, noAssert) {
_writeDouble(this, value, offset, true, noAssert)
}
function BufferWriteDoubleBE (value, offset, noAssert) {
_writeDouble(this, value, offset, false, noAssert)
}
// fill(value, start=0, end=buffer.length)
function BufferFill (value, start, end) {
if (!value) value = 0
if (!start) start = 0
if (!end) end = this.length
if (typeof value === 'string') {
value = value.charCodeAt(0)
}
if (typeof value !== 'number' || isNaN(value)) {
throw new Error('value is not a number')
}
if (end < start) throw new Error('end < start')
// Fill 0 bytes; we're done
if (end === start) return
if (this.length === 0) return
if (start < 0 || start >= this.length) {
throw new Error('start out of bounds')
}
if (end < 0 || end > this.length) {
throw new Error('end out of bounds')
}
for (var i = start; i < end; i++) {
this[i] = value
}
}
function BufferInspect () {
var out = []
var len = this.length
for (var i = 0; i < len; i++) {
out[i] = toHex(this[i])
if (i === exports.INSPECT_MAX_BYTES) {
out[i + 1] = '...'
break
}
}
return '<Buffer ' + out.join(' ') + '>'
}
// Creates a new `ArrayBuffer` with the *copied* memory of the buffer instance.
// Added in Node 0.12.
function BufferToArrayBuffer () {
return (new Buffer(this)).buffer
}
// HELPER FUNCTIONS
// ================
function stringtrim (str) {
if (str.trim) return str.trim()
return str.replace(/^\s+|\s+$/g, '')
}
/**
* Check to see if the browser supports augmenting a `Uint8Array` instance.
* @return {boolean}
*/
function _browserSupport () {
var arr = new xUint8Array(0)
arr.foo = function () { return 42 }