Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
0.7.0: revert to old pymem write_bytes until it's updated and add yaw…
Browse files Browse the repository at this point in the history
… reading and setting
  • Loading branch information
StarrFox committed Aug 20, 2020
1 parent 3b6c0ba commit ff4c07d
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "wizwalker"
version = "0.6.0"
version = "0.7.0"
description = "Automation bot for wizard101"
authors = ["StarrFox <[email protected]>"]
license = "GPL-3.0-or-later"
Expand Down
5 changes: 4 additions & 1 deletion wizwalker/cli/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def get_commands(self):
teleport_parser.add_argument("x", type=float)
teleport_parser.add_argument("y", type=float)
teleport_parser.add_argument("--z", type=float)
teleport_parser.add_argument("--yaw", type=float)
commands["teleport"] = (self.teleport_command, teleport_parser)

return commands
Expand All @@ -77,6 +78,7 @@ async def player_command(self, _, writer):
f"mana={await client.mana()} "
f"potions={await client.potions()} "
f"gold={await client.gold()} "
f"yaw={await client.yaw()} "
f"player_base={hex(await client.memory.read_player_base())} "
f"player_stat_base={hex(await client.memory.read_player_stat_base())}\n"
)
Expand Down Expand Up @@ -116,12 +118,13 @@ async def send_command(self, _, writer, key, seconds):

writer.write("Started\n")

async def teleport_command(self, _, writer, x, y, z=None):
async def teleport_command(self, _, writer, x, y, z=None, yaw=None):
for client in self.walker.clients:
await client.teleport(
x=x,
y=y,
z=z,
yaw=yaw
)

writer.write("Teleported\n")
22 changes: 20 additions & 2 deletions wizwalker/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,41 @@ def process_id(self):
user32.GetWindowThreadProcessId(self.window_handle, pid_ref)
return pid.value

async def teleport(self, *, x: float = None, y: float = None, z: float = None):
async def teleport(self, *, x: float = None, y: float = None, z: float = None, yaw: float = None):
"""
Teleport the player to a set x, y, z
returns False if not injected, True otherwise
"""
await self.memory.set_xyz(
res = await self.memory.set_xyz(
x=x,
y=y,
z=z,
)

if yaw:
await self.memory.set_player_yaw(yaw)

return res

async def xyz(self) -> Optional[utils.XYZ]:
"""
Player xyz if memory hooks are injected, otherwise None
"""
return await self.memory.read_xyz()

async def yaw(self) -> Optional[float]:
"""
Player yaw if memory hooks are injected, otherwise None
"""
return await self.memory.read_player_yaw()

async def set_yaw(self, yaw: float) -> bool:
"""
Set the player yaw to this value,
returns True if injected and value was set, False otherwise
"""
return await self.memory.set_player_yaw(yaw)

async def quest_xyz(self) -> Optional[utils.XYZ]:
"""
Quest xyz if memory hooks are injected, otherwise None
Expand Down
48 changes: 43 additions & 5 deletions wizwalker/windows/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,39 @@ def hook(self) -> Any:
self.jump_address, len(self.jump_bytecode)
)

self.memory_handler.process.write_bytes(
self.hook_address, self.hook_bytecode, len(self.hook_bytecode),
# Todo: Fix this whenever pymem is updated
# self.memory_handler.process.write_bytes(
# self.hook_address, self.hook_bytecode, len(self.hook_bytecode),
# )
# self.memory_handler.process.write_bytes(
# self.jump_address, self.jump_bytecode, len(self.jump_bytecode),
# )
pymem.memory.write_bytes(
self.memory_handler.process.process_handle,
self.hook_address,
self.hook_bytecode,
len(self.hook_bytecode),
)
self.memory_handler.process.write_bytes(
self.jump_address, self.jump_bytecode, len(self.jump_bytecode),
pymem.memory.write_bytes(
self.memory_handler.process.process_handle,
self.jump_address,
self.jump_bytecode,
len(self.jump_bytecode),
)

def unhook(self):
"""
Deallocates hook memory and rewrites jump addr to it's origional code,
also called when a client is closed
"""
self.memory_handler.process.write_bytes(
# Todo: fix when pymem updates
# self.memory_handler.process.write_bytes(
# self.jump_address,
# self.jump_original_bytecode,
# len(self.jump_original_bytecode),
# )
pymem.memory.write_bytes(
self.memory_handler.process.process_handle,
self.jump_address,
self.jump_original_bytecode,
len(self.jump_original_bytecode),
Expand Down Expand Up @@ -347,6 +367,24 @@ def set_xyz(self, *, x=None, y=None, z=None):

return True

@utils.executor_function
def read_player_yaw(self):
if not self.is_injected:
return None

player_struct = self.process.read_int(self.player_struct_addr)
return self.process.read_double(player_struct + 0x3C)

@utils.executor_function
def set_player_yaw(self, yaw):
if not self.is_injected:
return False

player_struct = self.process.read_int(self.player_struct_addr)
self.process.write_double(player_struct + 0x3C, yaw)

return True

@utils.executor_function
def read_quest_xyz(self):
if not self.is_injected:
Expand Down

0 comments on commit ff4c07d

Please sign in to comment.