Skip to content

Commit

Permalink
Process single ifndef id->offset definition
Browse files Browse the repository at this point in the history
  • Loading branch information
alandtse committed Sep 26, 2021
1 parent 34a3d38 commit 150638b
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion vr_address_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
OFFSET_OFFSET_PATTERN = (
r"(?:inline|constexpr) REL::Offset\s+(\w+)\s*\(\s*([a-fx0-9]+)\s*\)\s*;"
)
IFNDEF_PATTERN = r"([\w():]*)\s*{\s*#ifndef SKYRIMVR\s*([^{]*){\s*rel::id\(([0-9]*)\)\s}.*\s*#else\s*\2{.*(?:rel::offset)*(0x[0-9a-f]*)"
REPLACEMENT = """
#ifndef SKYRIMVR
{} // SSE {}
Expand Down Expand Up @@ -191,6 +192,7 @@ def scan_code(
for filename in filenames:
if filename not in a_exclude and filename.endswith(ALL_TYPES):
count += 1
found_ifndef = False
if not filename.lower().startswith("offset"):
with open(f"{dirpath}/{filename}") as f:
try:
Expand All @@ -213,8 +215,44 @@ def scan_code(
"matches": match,
}
)
}
if line.lower().startswith("#ifndef skyrimvr"):
found_ifndef = True
if found_ifndef:
f.seek(0)
if debug:
print(
f"Searching for ifndef id offset definitions in {dirpath}/{filename}"
)
ifndef_matches = re.findall(
IFNDEF_PATTERN,
f.read(),
flags=re.IGNORECASE | re.MULTILINE,
)
if ifndef_matches:
for match in ifndef_matches:
name = (
match[0]
if not match[0].endswith("()")
else match[0][:-2]
)
id = match[2]
offset = match[3]
func = {
"namespace": f"{filename}::",
"name": name,
}
defined_rel_ids[f"{filename}::{name}"] = {
"id": id,
"func": func,
}
defined_vr_offsets[f"{filename}::{name}"] = {
"id": offset,
"func": func,
}
if debug:
print(
f"Found ifndef {filename}::{name} with id: {id} offset: {offset}"
)
except UnicodeDecodeError as ex:
print(f"Unable to read {dirpath}/{filename}: ", ex)
else:
Expand Down

0 comments on commit 150638b

Please sign in to comment.