Pymem无法写入内存CSGO

2024-09-29 03:37:39 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我想尝试为机器人游戏制作一个CSGO欺骗(不是公开的,我实际上喜欢那个游戏,而且我是一个高水平的玩家)。我正在测试一些代码,第一次发生了一些事情。请记住,这个欺骗在此之前就已经奏效了,我确保更新偏移量。所以这个错误发生在我的ESP/wallhack/glow函数中。下面是它的代码:

def glow():
    print("Diamond has launched.")
    #pm = pymem.Pymem("csgo.exe")
    #client = pymem.process.module_from_name(pm.process_handle, "client.dll").lpBaseOfDll
    while True:
        glow_manager = pm.read_int(client + dwGlowObjectManager)
        for i in range(1, 32):  # Entities 1-32 are reserved for players.
            entity = pm.read_int(client + dwEntityList + i * 0x10)

            if entity:
                entity_team_id = pm.read_int(entity + m_iTeamNum)
                entity_glow = pm.read_int(entity + m_iGlowIndex)

                if entity_team_id == 2:  # Terrorist
                    pm.write_float(glow_manager + entity_glow * 0x38 + 0x4, float(1))   # R
                    pm.write_float(glow_manager + entity_glow * 0x38 + 0x8, float(1))   # G
                    pm.write_float(glow_manager + entity_glow * 0x38 + 0xC, float(0))   # B
                    pm.write_float(glow_manager + entity_glow * 0x38 + 0x10, float(1))  # Alpha
                    pm.write_int(glow_manager + entity_glow * 0x38 + 0x24, 1)           # Enable glow

                elif entity_team_id == 3:  # Counter-terrorist
                    pm.write_float(glow_manager + entity_glow * 0x38 + 0x4, float(0))   # R
                    pm.write_float(glow_manager + entity_glow * 0x38 + 0x8, float(0))   # G
                    pm.write_float(glow_manager + entity_glow * 0x38 + 0xC, float(1))   # B
                    pm.write_float(glow_manager + entity_glow * 0x38 + 0x10, float(1))  # Alpha
                    pm.write_int(glow_manager + entity_glow * 0x38 + 0x24, 1)           # Enable glow

但是在第21行,这是elif实体_team _id==3:#Counter terroist下的第一行,它给了我这个错误:

Traceback (most recent call last):
  File "C:\Users\gjohn\anaconda3\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\Users\gjohn\anaconda3\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "c:/Users/gjohn/Desktop/csgoHop/main.py", line 87, in glow
    pm.write_float(glow_manager + entity_glow * 0x38 + 0x4, float(0))   # R
  File "C:\Users\gjohn\anaconda3\lib\site-packages\pymem\__init__.py", line 961, in write_float
    raise pymem.exception.MemoryWriteError(address, value, e.error_code)
pymem.exception.MemoryWriteError: Could not write memory at: 2244, length: 0.0 - GetLastError: 998

特别是pymem.exception.MemoryWriteError:无法在以下位置写入内存:2244,长度:0.0-GetLastError:998。我对这个很陌生,过去很少使用pymem,所以我不知道这里发生了什么。我再次确保偏移量是最新的。它也只发生在我加载游戏时,而不是在菜单上。它将运行良好,直到机器人加载和东西

这也发生在我的防闪光功能中:

def flash():
    print("Emerald has launched.")
    #pm = pymem.Pymem("csgo.exe")
    #client = pymem.process.module_from_name(pm.process_handle, "client.dll").lpBaseOfDll

    while True:
        player = pm.read_int(client + dwLocalPlayer)
        if player:
            flash_value = player + m_flFlashMaxAlpha
            if flash_value:
                pm.write_float(flash_value, float(0))
        time.sleep(1)

在第11行,在“if flash_值:”的正下方

编辑:我知道pm和客户端分配被注释掉了,这是因为我决定在代码的前面将其上移,所以我不会为每个函数重新创建变量,但我想保留它以防万一。我是这样做的:

try:
    pm = pymem.Pymem("csgo.exe")
    client = pymem.process.module_from_name(pm.process_handle, "client.dll").lpBaseOfDll
    engine = pymem.process.module_from_name(pm.process_handle, "engine.dll").lpBaseOfDll
    enginepointer = pm.read_int(engine + dwClientState)
except pymem.exception.ProcessNotFound:
    print('Launch Game')
    quit()

编辑#2: 因此,错误998表示它对内存的访问无效。我的猜测是,无论它试图访问什么,都不存在。为了让其他函数运行,我在glow和flash周围放了一个try语句。尽管它仍然不起作用


Tags: inclientreadifmanagerfloatprocesswrite