forked from svalencius/silkroad-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.js
72 lines (63 loc) · 1.43 KB
/
helper.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
module.exports = {
toUInt32: toUInt32,
toUInt32_: toUInt32_,
MAKELONGLONG_: MAKELONGLONG_,
MAKELONG_: MAKELONG_,
MAKEWORD_: MAKEWORD_,
LOWORD_: LOWORD_,
HIWORD_: HIWORD_,
LOBYTE_: LOBYTE_,
HIBYTE_: HIBYTE_
};
function toUInt32(sval) {
var buffer = new Buffer(4);
buffer.writeInt32LE(sval, 0);
var usigned = buffer.readUInt32LE(0);
return usigned;
}
function toUInt32_(sval) {
var buffer = new Buffer(5);
buffer.writeUInt32LE(sval, 0);
var usigned = buffer.readUInt32LE(0);
return usigned;
}
function MAKELONGLONG_(a, b) {
var longlong = ((b << 32) | a);
var buffer = new Buffer(8);
buffer.writeInt64LE(longlong, 0);
longlong = buffer.readUInt64LE(0);
return longlong;
}
function MAKELONG_(a, b) {
var long = ((b << 16) | a);
var buffer = new Buffer(4);
buffer.writeInt32LE(long, 0);
long = buffer.readUInt32LE(0);
return long;
}
function MAKEWORD_(a, b) {
var word = ((b << 8) | a);
var buffer = new Buffer(2);
buffer.writeInt16LE(word, 0);
word = buffer.readUInt16LE(0);
return word;
}
function LOWORD_(a) {
a = a & 0xffff;
var buffer = new Buffer(2);
buffer.writeUInt16LE(a, 0);
a = buffer.readUInt16LE(0);
return a;
}
function HIWORD_(a) {
a = (a >>> 16) & 0xffff;
return a;
}
function LOBYTE_(a) {
a = a & 0xff;
return a;
}
function HIBYTE_(a) {
a = ((a >>> 8) & 0xff);
return a;
}