From 988f901dc8ca7168383b1de83f2afbf7044f6df5 Mon Sep 17 00:00:00 2001 From: AURUMVORXX Date: Tue, 15 Apr 2025 12:20:31 +0300 Subject: [PATCH] feat: version 2.0.0 --- include/events.nut | 626 ++++++++++++ include/main.nut | 128 +++ include/pyg2o.xml | 4 + main.py | 0 pyproject.toml | 2 +- python/g2o/__init__.py | 155 --- python/g2o/classes/packets.py | 196 ---- python/g2o/classes/sky.py | 106 -- python/g2o/classes/way.py | 48 - python/g2o/constants/__init__.py | 13 - python/g2o/constants/anticheat.py | 3 - python/g2o/constants/context.py | 4 - python/g2o/constants/damage.py | 11 - python/g2o/constants/general.py | 5 - python/g2o/constants/hand.py | 4 - python/g2o/constants/item.py | 38 - python/g2o/constants/network.py | 5 - python/g2o/constants/npc.py | 28 - python/g2o/constants/reliability.py | 7 - python/g2o/constants/skillweapon.py | 6 - python/g2o/constants/talent.py | 24 - python/g2o/constants/weaponmode.py | 11 - python/g2o/constants/weather.py | 4 - python/g2o/functions/event.py | 248 ----- src/pyg2o/__init__.py | 160 ++- src/pyg2o/call_repr.py | 14 + {python/g2o => src/pyg2o}/classes/__init__.py | 0 {python/g2o => src/pyg2o}/classes/daedalus.py | 26 +- {python/g2o => src/pyg2o}/classes/damage.py | 58 +- {python/g2o => src/pyg2o}/classes/items.py | 70 +- {python/g2o => src/pyg2o}/classes/mds.py | 18 +- src/pyg2o/classes/sky.py | 161 ++++ src/pyg2o/constants/__init__.py | 129 +++ .../g2o => src/pyg2o}/functions/__init__.py | 0 {python/g2o => src/pyg2o}/functions/chat.py | 43 +- src/pyg2o/functions/event.py | 737 ++++++++++++++ {python/g2o => src/pyg2o}/functions/game.py | 137 ++- {python/g2o => src/pyg2o}/functions/math.py | 33 +- {python/g2o => src/pyg2o}/functions/npc.py | 153 ++- {python/g2o => src/pyg2o}/functions/player.py | 910 ++++++++++++------ .../g2o => src/pyg2o}/functions/streamer.py | 33 +- .../g2o => src/pyg2o}/functions/waypoint.py | 23 +- src/pyg2o/serialize.py | 14 + src/pyg2o/server.py | 126 +++ 44 files changed, 3143 insertions(+), 1378 deletions(-) create mode 100644 include/events.nut create mode 100644 include/main.nut create mode 100644 include/pyg2o.xml delete mode 100644 main.py delete mode 100644 python/g2o/__init__.py delete mode 100644 python/g2o/classes/packets.py delete mode 100644 python/g2o/classes/sky.py delete mode 100644 python/g2o/classes/way.py delete mode 100644 python/g2o/constants/__init__.py delete mode 100644 python/g2o/constants/anticheat.py delete mode 100644 python/g2o/constants/context.py delete mode 100644 python/g2o/constants/damage.py delete mode 100644 python/g2o/constants/general.py delete mode 100644 python/g2o/constants/hand.py delete mode 100644 python/g2o/constants/item.py delete mode 100644 python/g2o/constants/network.py delete mode 100644 python/g2o/constants/npc.py delete mode 100644 python/g2o/constants/reliability.py delete mode 100644 python/g2o/constants/skillweapon.py delete mode 100644 python/g2o/constants/talent.py delete mode 100644 python/g2o/constants/weaponmode.py delete mode 100644 python/g2o/constants/weather.py delete mode 100644 python/g2o/functions/event.py create mode 100644 src/pyg2o/call_repr.py rename {python/g2o => src/pyg2o}/classes/__init__.py (100%) rename {python/g2o => src/pyg2o}/classes/daedalus.py (60%) rename {python/g2o => src/pyg2o}/classes/damage.py (59%) rename {python/g2o => src/pyg2o}/classes/items.py (64%) rename {python/g2o => src/pyg2o}/classes/mds.py (62%) create mode 100644 src/pyg2o/classes/sky.py create mode 100644 src/pyg2o/constants/__init__.py rename {python/g2o => src/pyg2o}/functions/__init__.py (100%) rename {python/g2o => src/pyg2o}/functions/chat.py (67%) create mode 100644 src/pyg2o/functions/event.py rename {python/g2o => src/pyg2o}/functions/game.py (62%) rename {python/g2o => src/pyg2o}/functions/math.py (65%) rename {python/g2o => src/pyg2o}/functions/npc.py (61%) rename {python/g2o => src/pyg2o}/functions/player.py (62%) rename {python/g2o => src/pyg2o}/functions/streamer.py (64%) rename {python/g2o => src/pyg2o}/functions/waypoint.py (62%) create mode 100644 src/pyg2o/serialize.py create mode 100644 src/pyg2o/server.py diff --git a/include/events.nut b/include/events.nut new file mode 100644 index 0000000..24e8c6d --- /dev/null +++ b/include/events.nut @@ -0,0 +1,626 @@ + +addEventHandler("onPlayerUseCheat", function(playerid, type) +{ + local data = { + event = "onPlayerUseCheat", + args = { + playerid = playerid, + type = type + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onBan", function(banInfo) +{ + local data = { + event = "onBan", + args = { + ban = { + mac = "mac" in banInfo ? banInfo["mac"] : "-1", + ip = "ip" in banInfo ? banInfo["ip"] : "-1", + serial = "serial" in banInfo ? banInfo["serial"] : "-1", + name = "name" in banInfo ? banInfo["name"] : "-1", + timestamp = "timestamp" in banInfo ? banInfo["timestamp"] : -1 + } + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onInit", function() +{ + local data = { + event = "onInit", + args = {} + } + + _PyG2O_Send(data); +}); + +addEventHandler("onExit", function() +{ + local data = { + event = "onExit", + args = {} + } + + _PyG2O_Send(data); +}); + +addEventHandler("onTick", function() +{ + local data = { + event = "onTick", + args = {} + } + + _PyG2O_Send(data); +}); + +addEventHandler("onTime", function(day, hour, min) +{ + local data = { + event = "onTime", + args = { + day = day, + hour = hour, + min = min, + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onUnban", function(banInfo) +{ + local data = { + event = "onUnban", + args = { + ban = { + mac = "mac" in banInfo ? banInfo["mac"] : "-1", + ip = "ip" in banInfo ? banInfo["ip"] : "-1", + serial = "serial" in banInfo ? banInfo["serial"] : "-1", + name = "name" in banInfo ? banInfo["name"] : "-1", + timestamp = "timestamp" in banInfo ? banInfo["timestamp"] : -1 + } + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onNpcActionFinished", function(npc_id, action_type, action_id, result) +{ + local data = { + event = "onNpcActionFinished", + args = { + npc_id = npc_id, + action_type = action_type, + action_id = action_id, + result = result + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onNpcActionSent", function(npc_id, action_type, action_id) +{ + local data = { + event = "onNpcActionSent", + args = { + npc_id = npc_id, + action_type = action_type, + action_id = action_id, + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onNpcChangeHostPlayer", function(npc_id, current_id, previous_id) +{ + local data = { + event = "onNpcChangeHostPlayer", + args = { + npc_id = npc_id, + current_id = current_id, + previous_id = previous_id + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onNpcCreated", function(npc_id) +{ + local data = { + event = "onNpcCreated", + args = { + npc_id = npc_id + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onNpcDestroyed", function(npc_id) +{ + local data = { + event = "onNpcDestroyed", + args = { + npc_id = npc_id + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onPlayerChangeColor", function(playerid, r, g, b) +{ + local data = { + event = "onPlayerChangeColor", + args = { + playerid = playerid, + r = r, + g = g, + b = b + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onPlayerChangeFocus", function(playerid, oldFocusId, newFocusId) +{ + local data = { + event = "onPlayerChangeFocus", + args = { + playerid = playerid, + oldFocusId = oldFocusId, + newFocusId = newFocusId + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onPlayerChangeHealth", function(playerid, previous, current) +{ + local data = { + event = "onPlayerChangeHealth", + args = { + playerid = playerid, + previous = previous, + current = current + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onPlayerChangeMana", function(playerid, previous, current) +{ + local data = { + event = "onPlayerChangeMana", + args = { + playerid = playerid, + previous = previous, + current = current + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onPlayerChangeMaxHealth", function(playerid, previous, current) +{ + local data = { + event = "onPlayerChangeMaxHealth", + args = { + playerid = playerid, + previous = previous, + current = current + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onPlayerChangeMaxMana", function(playerid, previous, current) +{ + local data = { + event = "onPlayerChangeMaxMana", + args = { + playerid = playerid, + previous = previous, + current = current + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onPlayerChangeWeaponMode", function(playerid, previous, current) +{ + local data = { + event = "onPlayerChangeWeaponMode", + args = { + playerid = playerid, + previous = previous, + current = current + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onPlayerChangeWorld", function(playerid, previous, current) +{ + local data = { + event = "onPlayerChangeWorld", + args = { + playerid = playerid, + previous = previous, + current = current + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onPlayerCommand", function(playerid, command, params) +{ + local data = { + event = "onPlayerCommand", + args = { + playerid = playerid, + command = command, + params = params + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onPlayerDamage", function(playerid, killerid, description) +{ + local data = { + event = "onPlayerDamage", + args = { + playerid = playerid, + killerid = killerid, + obj_DamageDescription = { + name = "desc", + data = _PyG2O_Serialize(description) + } + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onPlayerDead", function(playerid, killerid) +{ + local data = { + event = "onPlayerDead", + args = { + playerid = playerid, + killerid = killerid + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onPlayerDisconnect", function(playerid, reason) +{ + local data = { + event = "onPlayerDisconnect", + args = { + playerid = playerid, + reason = reason + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onPlayerDropItem", function(playerid, itemGround) +{ + local data = { + event = "onPlayerDropItem", + args = { + playerid = playerid, + obj_ItemGround = { + name = "itemGround", + data = _PyG2O_Serialize(itemGround) + } + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onPlayerEnterWorld", function(playerid, world) +{ + local data = { + event = "onPlayerEnterWorld", + args = { + playerid = playerid, + world = world + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onPlayerEquipAmulet", function(playerid, instance) +{ + local data = { + event = "onPlayerEquipAmulet", + args = { + playerid = playerid, + instance = instance + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onPlayerEquipArmor", function(playerid, instance) +{ + local data = { + event = "onPlayerEquipArmor", + args = { + playerid = playerid, + instance = instance + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onPlayerEquipBelt", function(playerid, instance) +{ + local data = { + event = "onPlayerEquipBelt", + args = { + playerid = playerid, + instance = instance + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onPlayerEquipHandItem", function(playerid, hand, instance) +{ + local data = { + event = "onPlayerEquipHandItem", + args = { + playerid = playerid, + hand = hand, + instance = instance + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onPlayerEquipHelmet", function(playerid, instance) +{ + local data = { + event = "onPlayerEquipHelmet", + args = { + playerid = playerid, + instance = instance + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onPlayerEquipMeleeWeapon", function(playerid, instance) +{ + local data = { + event = "onPlayerEquipMeleeWeapon", + args = { + playerid = playerid, + instance = instance + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onPlayerEquipRangedWeapon", function(playerid, instance) +{ + local data = { + event = "onPlayerEquipRangedWeapon", + args = { + playerid = playerid, + instance = instance + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onPlayerEquipRing", function(playerid, handId, instance) +{ + local data = { + event = "onPlayerEquipRing", + args = { + playerid = playerid, + handId = handId, + instance = instance + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onPlayerEquipShield", function(playerid, instance) +{ + local data = { + event = "onPlayerEquipShield", + args = { + playerid = playerid, + instance = instance + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onPlayerEquipSpell", function(playerid, slotId, instance) +{ + local data = { + event = "onPlayerEquipSpell", + args = { + playerid = playerid, + slotId = slotId, + instance = instance + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onPlayerJoin", function(playerid) +{ + local data = { + event = "onPlayerJoin", + args = { + playerid = playerid + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onPlayerMessage", function(playerid, message) +{ + local data = { + event = "onPlayerMessage", + args = { + playerid = playerid, + message = message + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onPlayerMobInteract", function(playerid, from, to) +{ + local data = { + event = "onPlayerMobInteract", + args = { + playerid = playerid, + from = from, + to = to + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onPlayerRespawn", function(playerid) +{ + local data = { + event = "onPlayerRespawn", + args = { + playerid = playerid + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onPlayerShoot", function(playerid, munition) +{ + local data = { + event = "onPlayerShoot", + args = { + playerid = playerid, + munition = munition + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onPlayerSpellCast", function(playerid, instance, spellLevel) +{ + local data = { + event = "onPlayerSpellCast", + args = { + playerid = playerid, + instance = instance, + spellLevel = spellLevel + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onPlayerSpellSetup", function(playerid, instance) +{ + local data = { + event = "onPlayerSpellSetup", + args = { + playerid = playerid, + instance = instance + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onPlayerTakeItem", function(playerid, itemGround) +{ + local data = { + event = "onPlayerTakeItem", + args = { + playerid = playerid, + obj_ItemGround = { + name = "itemGround", + data = _PyG2O_Serialize(itemGround) + } + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onPlayerTeleport", function(playerid, vobName) +{ + local data = { + event = "onPlayerTeleport", + args = { + playerid = playerid, + vobName = vobName + } + } + + _PyG2O_Send(data); +}); + +addEventHandler("onPlayerToggleFaceAni", function(playerid, aniName, toggle) +{ + local data = { + event = "onPlayerToggleFaceAni", + args = { + playerid = playerid, + aniName = aniName, + toggle = toggle + } + } + + _PyG2O_Send(data); +}); \ No newline at end of file diff --git a/include/main.nut b/include/main.nut new file mode 100644 index 0000000..d6178d9 --- /dev/null +++ b/include/main.nut @@ -0,0 +1,128 @@ + +local _pyg2o_server_connection = -1; +local _silent = false; +local _url = -1 +local _reconnect = false; + +function PyG2O_Start(url, reconnect = false, silent = false) +{ + _silent = silent; + _url = url; + _reconnect = reconnect; + + _pyg2o_server_connection = WebsocketClient(); + _pyg2o_server_connection.silent = true; + _pyg2o_server_connection.setUrl("ws://localhost:8080"); + _pyg2o_server_connection.start(); + + if (!_silent) + print("[PyG2O] Initializing connection on " + url) +} + +function _PyG2O_Send(data) +{ + if (_pyg2o_server_connection == -1) + return; + + _pyg2o_server_connection.send(JSON.dump_ansi(data)); +} + +function _PyG2O_InitializeConstants() +{ + local const_data = { + "type": "const_init", + "args": getconsttable() + }; + + _PyG2O_Send(const_data); +} + +function _PyG2O_GetClassName(object) +{ + if (object instanceof DamageDescription) + return "DamageDescription"; + else if (object instanceof ItemGround) + return "ItemGround"; + + return null; +} + +function _PyG2O_Serialize(object) +{ + local cls = object.getclass(); + local tab = {}; + + if (object instanceof DamageDescription) + { + tab["_flags"] <- object.flags; + tab["_damage"] <- object.damage; + tab["_item_instance"] <- object.item_instance; + tab["_distance"] <- object.distance; + tab["_spell_id"] <- object.spell_id; + tab["_spell_level"] <- object.spell_level; + tab["_node"] <- object.node; + } + else if (object instanceof ItemGround) + { + tab["_id"] <- object.id; + tab["_instance"] <- object.instance; + tab["_amount"] <- object.amount; + tab["_world"] <- object.world; + tab["_virtualWorld"] <- object.virtualWorld; + tab["_position"] <- object.getPosition(); + tab["_rotation"] <- object.getRotation(); + } + + return tab; +} + +addEventHandler("onWebsocketConnect", function(socket, url) +{ + if (socket != _pyg2o_server_connection) + return; + + if (!_silent) + { + print("[PyG2O] Successfully connected to " + url); + _PyG2O_InitializeConstants(); + } +}); + +addEventHandler("onWebsocketDisconnect", function(socket, url) +{ + if (socket != _pyg2o_server_connection || _reconnect) + return; + + _pyg2o_server_connection = -1; +}); + +addEventHandler("onWebsocketMessage", function(socket, url, message) +{ + if (socket != _pyg2o_server_connection) + return; + + local request = JSON.parse_ansi(message); + if ("uuid" in request) + { + local result = compilestring(request["args"])(); + local className = _PyG2O_GetClassName(result); + if (className != null) + { + className = format("obj_%s", className) + + request["args"] = {}; + request["args"].rawset(className, {}); + local objTab = request["args"].rawget(className); + objTab["name"] <- "result"; + objTab["data"] <- _PyG2O_Serialize(result); + } + else + { + request["args"] = + { + "result": result + }; + } + _pyg2o_server_connection.send(JSON.dump_ansi(request, 2)); + } +}); diff --git a/include/pyg2o.xml b/include/pyg2o.xml new file mode 100644 index 0000000..37df48a --- /dev/null +++ b/include/pyg2o.xml @@ -0,0 +1,4 @@ + +