-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItemMarkers.user.js
222 lines (198 loc) · 6.01 KB
/
ItemMarkers.user.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
// ==UserScript==
// @name Moomoo.io Item markers
// @author Murka
// @description Draws markers on items
// @icon https://moomoo.io/img/favicon.png?v=1
// @version 0.2
// @match *://moomoo.io/*
// @match *://*.moomoo.io/*
// @run-at document-start
// @grant none
// @license MIT
// @namespace https://greasyfork.org/users/919633
// ==/UserScript==
/* jshint esversion:6 */
/*
Author: Murka
Github: https://github.com/Murka007
Discord: https://discord.gg/sG9cyfGPj5
Greasyfork: https://greasyfork.org/en/users/919633
MooMooForge: https://github.com/MooMooForge
*/
(function() {
"use strict";
// render - false/true, used to toggle rendering of marker
// color - hex/rgb color, used to change marker color
const MARKER_COLOR = {
MY_PLAYER: {
render: true,
color: "#a7f060"
},
TEAMMATE: {
render: true,
color: "#fceb65"
},
ENEMY: {
render: true,
color: "#f76363"
}
};
const MARKER_SIZE = 10;
const log = console.log;
const createRecursiveHook = (target, prop, condition, callback) => {
(function recursiveHook() {
Object.defineProperty(target, prop, {
set(value) {
delete target[prop];
this[prop] = value;
if (
condition(this, value) &&
callback(this, value)
) return;
recursiveHook();
},
configurable: true
})
})();
}
function createHook(target, prop, setter, getter) {
const symbol = Symbol(prop);
Object.defineProperty(target, prop, {
get() {
getter(this, this[symbol]);
return this[symbol];
},
set(value) {
setter(this, symbol, value);
},
configurable: true
})
}
let item = null;
createHook(Object.prototype, "isItem", function(that, symbol, value) {
that[symbol] = value;
}, function(that, value) {
if (value === true) {
item = that;
}
});
const myPlayer = { id: null };
const teammates = [];
// myPlayer spawned
function setupPlayer(temp) {
myPlayer.id = temp[1];
}
function createDeleteClan(temp) {
if (!temp[1]) {
teammates.splice(0, teammates.length);
}
}
function updateClanList(temp) {
teammates.splice(0, teammates.length);
for (let i=0;i<temp[1].length;i+=2) {
const [ id, name ] = temp[1].slice(i, i+2);
teammates.push(id);
}
}
function getItemColor(id) {
if (id === myPlayer.id) return MARKER_COLOR.MY_PLAYER;
if (teammates.includes(id)) return MARKER_COLOR.TEAMMATE;
return MARKER_COLOR.ENEMY;
}
function drawMarker(ctx) {
if (!item || !item.owner || myPlayer.id === null) return;
const type = getItemColor(item.owner.sid);
if (!type.render) return;
ctx.fillStyle = type.color;
ctx.beginPath();
ctx.arc(0, 0, MARKER_SIZE, 0, 2 * Math.PI);
ctx.fill();
item = null;
}
// This method is called when item was drawn
CanvasRenderingContext2D.prototype.restore = new Proxy(CanvasRenderingContext2D.prototype.restore, {
apply(target, _this, args) {
drawMarker(_this);
return target.apply(_this, args);
}
});
document.msgpack = {
Encoder: null,
Decoder: null
};
// Intercept msgpack encoder
createRecursiveHook(
Object.prototype, "initialBufferSize",
(_this) => (
typeof _this === "object" &&
typeof _this.encode === "function" &&
_this.encode.length === 1
),
(_this) => {
document.msgpack.Encoder = _this;
return true;
}
);
// Intercept msgpack decoder
createRecursiveHook(
Object.prototype, "maxExtLength",
(_this) => (
typeof _this === "object" &&
typeof _this.decode === "function" &&
_this.decode.length === 1
),
(_this) => {
document.msgpack.Decoder = _this;
return true;
}
);
// previous way to get msgpack encoder and decoder.
// Get msgpack's encode and decode methods
/*Function.prototype.call = new Proxy(Function.prototype.call, {
apply(target, _this, args) {
const data = target.apply(_this, args);
if (args[1] && args[1].i) {
const i = args[1].i;
if (i === 9) msgpack.encode = args[0].encode;
if (i === 15) {
msgpack.decode = args[0].decode;
Function.prototype.call = target;
}
}
return data;
}
})*/
const PACKETS = {
1: setupPlayer,
st: createDeleteClan,
sa: updateClanList,
};
// Handle WebSocket data
function message(event) {
try {
const data = document.msgpack.Decoder.decode(new Uint8Array(event.data));
const temp = [data[0], ...data[1]];
PACKETS[temp[0]](temp);
} catch(err){}
}
// Intercept WebSocket
window.WebSocket = new Proxy(WebSocket, {
construct(target, args) {
const socket = new target(...args);
socket.addEventListener("message", message);
return socket;
}
});
// old intercept ws method
/*const set = Object.getOwnPropertyDescriptor(WebSocket.prototype, "onmessage").set;
Object.defineProperty(WebSocket.prototype, "onmessage", {
set(callback) {
return set.call(this, new Proxy(callback, {
apply(target, _this, args) {
message(args[0]);
return target.apply(_this, args);
}
}))
}
})*/
})();