Last active
October 17, 2021 22:22
-
-
Save codemasher/760ff0c34339c51848453393fe5c6b88 to your computer and use it in GitHub Desktop.
Guild Wars 2 Mumble link stuff
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
<?php | |
$prevTick = 0; | |
$prevPos = [0, 0]; | |
while(true){ | |
exec('python mumblelink.py', $data); | |
$json = json_decode($data[0]); | |
if($json->ui_tick !== $prevTick && $json->position !== $prevPos){ | |
var_dump($data[0]); | |
// do stuff... | |
$prevTick = $json->ui_tick; | |
$prevPos = $json->position; | |
} | |
// remove the first (only) element to not blow up memory | |
array_shift($data); | |
usleep(500000); | |
} |
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
import ctypes | |
import mmap | |
import json | |
class Link(ctypes.Structure): | |
_fields_ = [ | |
("uiVersion", ctypes.c_uint32), # 4 | |
("uiTick", ctypes.c_ulong), # 4 | |
("fAvatarPosition", ctypes.c_float * 3), # 3*4 | |
("fAvatarFront", ctypes.c_float * 3), # 3*4 | |
("fAvatarTop", ctypes.c_float * 3), # 3*4 | |
("name", ctypes.c_wchar * 256), # 512 | |
("fCameraPosition", ctypes.c_float * 3), # 3*4 | |
("fCameraFront", ctypes.c_float * 3), # 3*4 | |
("fCameraTop", ctypes.c_float * 3), # 3*4 | |
("identity", ctypes.c_wchar * 256), # 512 | |
("context_len", ctypes.c_uint32), # 4 | |
# ("context", ctypes.c_byte * 256), | |
# ("description", ctypes.c_byte * 2048), # always empty | |
] | |
class Context(ctypes.Structure): | |
_fields_ = [ | |
("serverAddress", ctypes.c_byte * 28), | |
("mapId", ctypes.c_uint32), | |
("mapType", ctypes.c_uint32), | |
("shardId", ctypes.c_uint32), | |
("instance", ctypes.c_uint32), | |
("buildId", ctypes.c_uint32), | |
("uiState", ctypes.c_uint32), | |
("compassWidth", ctypes.c_uint16), | |
("compassHeight", ctypes.c_uint16), | |
("compassRotation", ctypes.c_float), | |
("playerX", ctypes.c_float), | |
("playerY", ctypes.c_float), | |
("mapCenterX", ctypes.c_float), | |
("mapCenterY", ctypes.c_float), | |
("mapScale", ctypes.c_float), | |
] | |
class MumbleLink: | |
data: Link | |
context: Context | |
def __init__(self): | |
size1 = ctypes.sizeof(Link) | |
size2 = ctypes.sizeof(Context) | |
memfile = mmap.mmap(0, size1 + size2, "MumbleLink", mmap.ACCESS_READ) | |
memfile.seek(0) | |
self.data = self.unpack(Link, memfile.read(size1)) | |
self.context = self.unpack(Context, memfile.read(size2)) | |
memfile.close() | |
def to_json(self): | |
identity = json.loads(self.data.identity) | |
js = { | |
"name": identity['name'], | |
"profession": identity['profession'], | |
"race": identity['race'], | |
"spec": identity['spec'], | |
"commander": identity['commander'], | |
"team_color_id": identity['team_color_id'], | |
"map_id": self.context.mapId, | |
"build_id": self.context.buildId, | |
"ui_tick": self.data.uiTick, | |
"avatar_position": [round(self.data.fAvatarPosition[0], 5), round(self.data.fAvatarPosition[2], 5)], | |
"player_position": [round(self.context.playerX), round(self.context.playerY)], | |
} | |
return json.dumps(js) | |
@staticmethod | |
def unpack(ctype, buf): | |
cstring = ctypes.create_string_buffer(buf) | |
ctype_instance = ctypes.cast(ctypes.pointer(cstring), ctypes.POINTER(ctype)).contents | |
return ctype_instance | |
def main(): | |
ml = MumbleLink() | |
print(ml.to_json()) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment