Skip to content

Commit

Permalink
add script helpful to run after patches. (#67)
Browse files Browse the repository at this point in the history
* add script helpful to run after patches.

* add quick readme

* fix signature

* Update readme; dry out scan to one function.
  • Loading branch information
jmctune authored Jul 31, 2023
1 parent be6542b commit 85b375b
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/common/signatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# takes you to the section of the function where you can read where dialog is stored before
# it's rendered to screen. captures npc text.
# FF 77 08 C7 45 FC ?? ?? ?? ?? BB
# FF 77 08 C7 45
# 8D 64 24 FC 89 04 24 8D 64 24 FC E9 ?? ?? ?? ?? 3B -- better, but picked up by integrity scans in combat.
#
# Code around where we detour
Expand Down
1 change: 1 addition & 0 deletions scripts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.log
16 changes: 16 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# scripts

Helpful scripts to run after patches to quickly find common patterns that dqxclarity uses.

### find_names.py

Searches for patterns configured for the `npc_monster_pattern` pattern. Writes the previous 49 bytes of the found string to a file to be used when figuring out the pattern.

Usage:

```
python -m venv venv
.\venv\Scripts\activate
pip install -r requirements.txt
python find_names.py --help
```
83 changes: 83 additions & 0 deletions scripts/find_names.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import argparse
import sys
import pymem


# zone into megistris and stand at the entrance
npc_names = [
"ハパリーパ",
"魚交換員ノポナ",
"紹介人プリュノ",
"チャヌジャ",
"神官ペオ",
]

# zone outside of megistris and don't move
monster_names = [
"おむつっこり",
"リザードマン",
]

# add your party members here
party_names = [
"ももちゃん",
"べっぴん",
"ミルラ",
]


DQX = pymem.Pymem("DQXGame.exe")


def get_scan_results(names: list):
npcs_found = []
for npc in names:
pattern = npc.encode(encoding="utf-8")
results = DQX.pattern_scan_all(pattern=pattern, return_multiple=True)
for result in results:
data = DQX.read_bytes(result - 48, 49)

# correct pattern never starts with this
if data.startswith(b"\x00\x00\x00\x00"):
continue
# correct pattern always has nulls in these positions
if data[4:9] != b"\x00\x00\x00\x00\x00":
continue

npcs_found.append(data.hex(" ", 1).upper())
return npcs_found


def write_to_file(data: str):
with open("npc_monster_pattern.log", "a+") as f:
f.write(data)


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Returns bytes following an NPC's name for pattern scanning. Used specifically to target the 'npc_monster_pattern' pattern.")
parser.add_argument("-n", "--npcs", default=False, action="store_true", help="Scans for configured NPCs and writes results to file.")
parser.add_argument("-m", "--monsters", default=False, action="store_true", help="Scans for configured monsters and writes results to file.")
parser.add_argument("-p", "--party", default=False, action="store_true", help="Scans for configured party members and writes results to file.")
args = parser.parse_args(args=None if sys.argv[1:] else ["--help"])

if args.npcs:
results = get_scan_results(npc_names)
if results:
write_to_file("NPCs:\n---------------------\n")
for result in results:
write_to_file(f"{result}\n")
write_to_file("\n")
if args.monsters:
results = get_scan_results(monster_names)
if results:
write_to_file("Monsters:\n---------------------\n")
for result in results:
write_to_file(f"{result}\n")
write_to_file("\n")
if args.party:
results = get_scan_results(party_names)
if results:
write_to_file("Party members:\n---------------------\n")
for result in results:
write_to_file(f"{result}\n")
write_to_file("\n")
1 change: 1 addition & 0 deletions scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pymem

0 comments on commit 85b375b

Please sign in to comment.