使用Python访问内存映射文件 [英] Accessing a memory-mapped file using Python

查看:214
本文介绍了使用Python访问内存映射文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望使用《激战2》中的内存映射文件,该文件旨在链接到Mumble中以获取位置音频.该文件包含有关字符坐标的信息以及其他有用的信息.

I am looking to take use of a memory mapped file from Guild Wars 2, which is designed to link into Mumble for positional audio. The file contains information on the characters coordinates and other useful information.

我已经可以使用此脚本访问坐标信息,

I have been able to access the coordinate information using this script,

import mmap
import struct

last=[]
while True:
    shmem = mmap.mmap(0, 20, "MumbleLink", mmap.ACCESS_READ)
    coord=struct.unpack("IL3f", shmem)[2:5]

    shmem.close()
    if last!=coord:
        print(coord)
        last = coord
        X = coord[2]
        Y = coord[0]
        Z = coord[1])

我的问题是我很难确定如何从文件中获取更多信息.我将如何访问存储的其他信息,例如角色名称和摄像机位置.

My problem is I am having difficulty working out how to get more information out of the file. How would I go about accessing other information that is stored, such as character name and camera position.

此处提供有关文件的信息:
https://forum-en.guildwars2.com/forum /community/api/Map-API-Mumble-Mashup http://mumble.sourceforge.net/Link

There is information on the file here:
https://forum-en.guildwars2.com/forum/community/api/Map-API-Mumble-Mashup http://mumble.sourceforge.net/Link

任何帮助将不胜感激.

干杯, 埃德.

推荐答案

您可以尝试在mmap调用中从文件映射20多个字节,例如使用1024,然后根据

You can try to map more than 20 bytes from the file in mmap call, say use 1024, unpack the whole thing according to the http://mumble.sourceforge.net/Link and then extract the name and camera position:

s = struct.unpack('IL3f3f3f512s3f')
name = s[11].decode('utf-16')
camera_pos_x,camera_pos_y,camera_pos_z = s[12:15]

这篇关于使用Python访问内存映射文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆