Created
July 2, 2021 12:06
-
-
Save at15four2020/9e2986f76d6dd67ef8149d5e4edd73f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function _intercepted(message) { | |
var side = message.getDestination() | |
var packet = message.getPacket() | |
var sideListeners = side == TOCLIENT ? _toClientListeners : _toServerListeners | |
var handlers = sideListeners[packet.headerId()] | |
if (!handlers) return | |
handlers.forEach(function (handler) { | |
try { | |
handler.call(null, message) | |
} catch(e) { | |
print("Script fail -->\n\n") | |
print(e) | |
if (getBytes) { | |
print("\nHere is the packet in bytes:\n") | |
print(getBytes(message.getPacket())) | |
} | |
print("\n\n<-- Script fail\n") | |
} | |
}) | |
} | |
clear() | |
load("https://gist.github.com/Alynva/7f5dd840fc54fa49e0c538f51b69ac93/raw/RoomChatManager.gprog.js") | |
// parse_in_Objects.gprog.js | |
function parse_in_Objects(packet) { | |
var ownersCount = packet.readInteger() | |
var owners = [] | |
for (var i = 0; i < ownersCount; i++) { | |
var owner = {} | |
owner.id = packet.readInteger() | |
owner.nick = packet.readString() | |
owners.push(owner) | |
} | |
var mobisCount = packet.readInteger() | |
var mobis = [] | |
for (var i = 0; i < mobisCount; i++) { | |
var mobi = {} | |
mobi.raw = [ | |
packet.readInteger(), | |
packet.readInteger(), | |
packet.readInteger(), | |
packet.readInteger(), | |
packet.readInteger(), | |
packet.readString(), | |
packet.readString(), | |
packet.readInteger(), | |
packet.readInteger() | |
] | |
mobi.type = mobi.raw[8] | |
if (mobi.type == 0) { // normal | |
mobi.raw.push( | |
packet.readString() | |
) | |
} else if (mobi.type == 1) { // custom props, like gifts | |
// for gifts from users it appears like this: | |
// "EXTRA_PARAM", "", "MESSAGE", message, "PURCHASER_NAME", purchaser name, "PURCHASER_FIGURE", purchaser figure, "PRODUCT_CODE", gift type | |
// for figts from hotel it appeas like this: | |
// "MESSAGE", message, "PRODUCT_CODE", gift type | |
mobi.raw.push( | |
packet.readInteger() | |
) | |
var customPropsCount = mobi.raw[9] | |
for (var j = 0; j < customPropsCount; j++) { | |
mobi.raw.push( | |
packet.readString(), | |
packet.readString() | |
) | |
} | |
} else if (mobi.type == 2) { // group | |
mobi.raw.push( | |
packet.readInteger(), | |
packet.readString(), | |
packet.readString(), // id | |
packet.readString(), // badge | |
packet.readString(), // color | |
packet.readString() // color | |
) | |
} | |
mobi.raw.push( | |
packet.readInteger(), | |
packet.readInteger(), | |
packet.readInteger() | |
) | |
mobi.uid = mobi.raw[0] | |
mobi.spriteId = mobi.raw[1] | |
mobi.x = mobi.raw[2] | |
mobi.y = mobi.raw[3] | |
mobi.z = mobi.raw[4] | |
mobi.ownerId = mobi.raw[mobi.raw.length - 1] | |
mobis.push(mobi) | |
} | |
return { | |
owners: owners, | |
mobis: mobis | |
} | |
} | |
function find(array, handler) { | |
var result = undefined | |
for (var i = 0; i < array.length; i++) { | |
if (handler(array[i], i, array)) { | |
result = array[i] | |
break | |
} | |
} | |
return result | |
} | |
var defaultObjects | |
function removeMobi(uid) { | |
var mobi = find(defaultObjects.mobis, function(x) { | |
return x.uid == uid | |
}) | |
sendToClient(HPacket(3095, [""+uid, false, mobi.ownerId, 0])) | |
} | |
function addMobi(uid) { | |
var mobi = find(defaultObjects.mobis, function(x) { | |
return x.uid == uid | |
}) | |
var owner = find(defaultObjects.owners, function(x) { | |
return x.id == mobi.ownerId | |
}) | |
var packetData = mobi.raw | |
packetData.push(owner.nick) | |
sendToClient(HPacket(426, packetData)) | |
} | |
interceptToClient(953, function(message) { // Objects | |
clear() | |
var objects = parse_in_Objects(message.getPacket()) | |
defaultObjects = objects | |
print(JSON.stringify(objects, null, 2)) | |
// print(getBytes(message.getPacket())) | |
}) | |
var manager = RoomChatManager({ | |
inChatHeaderId: 1918, | |
outChatHeaderId: 3351 | |
}) | |
var itemsRemoved = {} | |
function update(maxAxis, maxValue) { | |
var itemsToRemove = [] | |
var itemsToAdd = [] | |
for (var i = 0; i < defaultObjects.mobis.length; i++) { | |
var realValue = defaultObjects.mobis[i][maxAxis] | |
var itemUid = defaultObjects.mobis[i].uid | |
if (realValue > maxValue) { | |
if (!itemsRemoved[itemUid]) { | |
itemsToRemove.push(itemUid) | |
itemsRemoved[itemUid] = true | |
} | |
} else if (itemsRemoved[itemUid]) { | |
itemsToAdd.push(itemUid) | |
delete itemsRemoved[itemUid] | |
} | |
} | |
if (itemsToRemove.length) { | |
for (var i = 0; i < itemsToRemove.length; i++) { | |
removeMobi(itemsToRemove[i]) | |
} | |
manager.sendChat("Just removed "+itemsToRemove.length+" items.") | |
} | |
if (itemsToAdd.length) { | |
for (var i = 0; i < itemsToAdd.length; i++) { | |
addMobi(itemsToAdd[i]) | |
} | |
manager.sendChat("Just added "+itemsToAdd.length+" items.") | |
} | |
if (!itemsToRemove.length && !itemsToAdd.length) { | |
manager.sendChat("Nothing to change.") | |
} | |
} | |
var max = {} | |
manager.handleCommand("setMax", function (message, command) { | |
var text = command.extra.split(" ") | |
if (text.length != 2) { | |
manager.sendChat("You must define the axis and the value. Provied: "+command.extra) | |
return | |
} | |
var maxAxis = text[0] | |
var maxValue = Number(text[1]) | |
manager.sendChat("Set "+maxAxis+" to "+maxValue) | |
max[maxAxis] = maxValue | |
update(maxAxis, maxValue) | |
}, "/") | |
manager.handleCommand("pushMax", function (message, command) { | |
var text = command.extra.split(" ") | |
if (text.length != 2) { | |
manager.sendChat("You must define the axis and the offset. Provied: "+command.extra) | |
return | |
} | |
var maxAxis = text[0] | |
var maxOffset = Number(text[1]) | |
var maxValue = (max[maxAxis] || 0) + maxOffset | |
manager.sendChat("Set "+maxAxis+" to "+maxValue) | |
max[maxAxis] = maxValue | |
update(maxAxis, maxValue) | |
}, "/") | |
manager.handleCommand("reset", function () { | |
sendToServer(HPacket(3720)) | |
}, "/") | |
sendToServer(HPacket(3720)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment