747929791 / majsoul_wrapper

自动化雀魂AI的SDK,实时解析雀魂对局信息,并模拟鼠标动作出牌
MIT License
394 stars 61 forks source link

liqi.py出现致命错误 #18

Closed Eric-Joker closed 1 year ago

Eric-Joker commented 1 year ago

liqi.py 65-68:

B = base64.b64decode(dict_obj['data']) action_proto_obj = getattr(pb, dict_obj['name']).FromString(B) action_dict_obj = MessageToDict(action_proto_obj) dict_obj['data'] = action_dict_obj

日志: Wrong wire type in tag. File "C:\Users\12772\AppData\Local\Programs\Python\Python38\Lib\site-packages\google\protobuf\internal\decoder.py", line 972, in _DecodeUnknownField raise _DecodeError('Wrong wire type in tag.') File "C:\Users\12772\AppData\Local\Programs\Python\Python38\Lib\site-packages\google\protobuf\internal\python_message.py", line 1178, in InternalParse (data, new_pos) = decoder._DecodeUnknownField( File "C:\Users\12772\AppData\Local\Programs\Python\Python38\Lib\site-packages\google\protobuf\internal\python_message.py", line 1127, in MergeFromString if self._InternalParse(serialized, 0, length) != length: File "C:\Users\12772\AppData\Local\Programs\Python\Python38\Lib\site-packages\google\protobuf\internal\python_message.py", line 794, in FromString message.MergeFromString(s) File "C:\Users\12772\Desktop\MajsoulAI-master\majsoul_wrapper\liqi.py", line 67, in parse action_dict_obj = MessageToDict(action_proto_obj) File "C:\Users\12772\Desktop\MajsoulAI-master\main.py", line 124, in recvFromMajsoul result = self.liqiProto.parse(flow_msg) File "C:\Users\12772\Desktop\MajsoulAI-master\main.py", line 724, in MainLoop aiWrapper.recvFromMajsoul() File "C:\Users\12772\Desktop\MajsoulAI-master\main.py", line 744, in MainLoop(level=level) File "C:\Users\12772\AppData\Local\Programs\Python\Python38\Lib\runpy.py", line 87, in _run_code exec(code, run_globals) File "C:\Users\12772\AppData\Local\Programs\Python\Python38\Lib\runpy.py", line 194, in _run_module_as_main (Current frame) return _run_code(code, main_globals, None, google.protobuf.message.DecodeError: Wrong wire type in tag.

将上述代码第二行getattr()添加默认值""可以略过第一次报错(ActionMJStart) {'step': 0, 'name': 'ActionMJStart', 'data': ''} 但是进入新的回合后data的值不为空时无法解码 {'step': 1, 'name': 'ActionNewRound', 'data': 'H/b75PhO8hTmKQEaJGBZ/3ppU1JxThiqHgATnE8BSWXnJL9c/dm9mqNxpsi8i/XO/bINs8/LBwbIiNxQdufk+vInt9iIo5ITP14LTCqWW0wPmL/jGxfTVc9U7tudwMQk8L2oMdTv5atY3WbxUiBvRY5o3kKJYjc0VyufGCUihW4bWF7H'}

修改后删除上述代码后两行会报另一个错:Unexpected end-group tag.

已经更换为最新版(v0.10.194.w)的最新liqi.json并进行proto→py转义

因为使用的是edge,protobuf需要3.14.0 使用protoc版本为3.14.0 使用protobufjs版本为v7.2.1(当前最新版) py3.8

proto模块解码分析wire_type为7

yangruihan commented 1 year ago

这个问题有解决吗?

Eric-Joker commented 1 year ago

这个问题有解决吗?

没有

yangruihan commented 1 year ago

Notify 的消息体经过了 encode,需要 decode

使用如下代码

keys = [0x84, 0x5e, 0x4e, 0x42, 0x39, 0xa2, 0x1f, 0x60, 0x1c]
def decode(data: bytes):
    data = bytearray(data)
    for i in range(len(data)):
        u = (23 ^ len(data)) + 5 * i + keys[i % len(keys)] & 255
        data[i] ^= u
    return bytes(data)

修改 65-68 行中的:

- getattr(pb, dict_obj['name']).FromString(B)
+ getattr(pb, dict_obj['name']).FromString(decode(B))