Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加 steam 版本支持 #4

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pvz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@

## 功能修改
from .extra import set_zombies as SetZombies
from .extra import get_zombies as GetZombies

## 选卡/更新炮列表
from .extra import select_seeds_and_lets_rock as SelectCards
Expand Down Expand Up @@ -99,6 +100,7 @@
"PressKeys",
# 功能修改
"SetZombies",
"GetZombies",
# 选卡/更新炮列表
"SelectCards",
"UpdatePaoList",
Expand Down Expand Up @@ -143,6 +145,10 @@ def _on_start():
# set_dpi_scale(1.25) # 出错则手动设置

if find_pvz():
if pvz_ver() != "1.2.0.1096":
set_addr(0x6A9EC0, 0x768, 0x00)
else:
set_addr(0x731C50, 0x868, 0x18)
ui = game_ui()
if ui in (2, 3):
set_pvz_foreground()
Expand All @@ -153,7 +159,7 @@ def _on_start():
else:
critical("游戏未开启或者游戏版本不受支持!")

enable_logging(False) # 是否输出调试日志
enable_logging(True) # 是否输出调试日志
set_logging_level("INFO")


Expand Down
24 changes: 22 additions & 2 deletions pvz/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,12 @@ def find_pvz():
pvz_version = "1.2.0.1065"
info("已找到游戏 1.2.0.1065 !!!")
return True
elif True:
# TODO 缺少 steam 版检测机制
# 暂时默认非 1051、1065 的版本一定是 steam 版
pvz_version = "1.2.0.1096"
info("已找到游戏 1.2.0.1096 !!!")
return True
else:
pvz_version = None
warning("不支持的游戏版本 !!!")
Expand Down Expand Up @@ -567,6 +573,7 @@ def read_memory(data_type, *address, array=1):
size = ctypes.sizeof(buffer)
success = ReadProcessMemory(pvz_handle, offset, ctypes.byref(buffer), size, ctypes.byref(bytes_read))
if success == 0 or bytes_read.value != size:
memory_lock.release()
critical("读取内存失败, 错误代码 %d." % GetLastError())

else:
Expand All @@ -575,6 +582,7 @@ def read_memory(data_type, *address, array=1):
buff = ctypes.create_string_buffer(size) # 目标数据缓冲
success = ReadProcessMemory(pvz_handle, offset, ctypes.byref(buff), size, ctypes.byref(bytes_read))
if success == 0 or bytes_read.value != size:
memory_lock.release()
critical("读取内存失败, 错误代码 %d." % GetLastError())

result = struct.unpack(fmt_str, buff.raw)
Expand Down Expand Up @@ -627,6 +635,7 @@ def write_memory(data_type, values, *address):
size = ctypes.sizeof(buffer)
success = ReadProcessMemory(pvz_handle, offset, ctypes.byref(buffer), size, ctypes.byref(bytes_read))
if success == 0 or bytes_read.value != size:
memory_lock.release()
critical("读取内存失败, 错误代码 %d." % GetLastError())

else:
Expand All @@ -637,6 +646,7 @@ def write_memory(data_type, values, *address):
buff.value = struct.pack(fmt_str, *values) # 将目标数据载入缓冲区
success = WriteProcessMemory(pvz_handle, offset, ctypes.byref(buff), size, ctypes.byref(bytes_written))
if success == 0 or bytes_written.value != size:
memory_lock.release()
critical("写入内存失败, 错误代码 %d." % GetLastError())

memory_lock.release()
Expand Down Expand Up @@ -733,6 +743,12 @@ def asm_push(code):
asm_add_dword(code)


# push 0x12
def asm_push_byte(code):
asm_add_byte(0x6A)
asm_add_byte(code)


# mov exx, 0x12345678
asm_mov_exx_code = {
"eax": [0xB8],
Expand Down Expand Up @@ -902,15 +918,19 @@ def asm_code_inject():
def asm_code_inject_safely():
if pvz_ver() == "1.0.0.1051":
write_memory("unsigned char", 0xFE, 0x00552014)
else:
elif pvz_ver() == "1.2.0.1065":
write_memory("unsigned char", 0xFE, 0x00552244)
else:
write_memory("unsigned char", 0xFE, 0x005DD25E)
time.sleep(0.01)
if is_valid():
asm_code_inject()
if pvz_ver() == "1.0.0.1051":
write_memory("unsigned char", 0xDB, 0x00552014)
else:
elif pvz_ver() == "1.2.0.1065":
write_memory("unsigned char", 0xDB, 0x00552244)
else:
write_memory("unsigned char", 0xC8, 0x005DD25E)


### 键盘操作
Expand Down
Loading