Skip to content

Commit

Permalink
add hook manifest v2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
shevernitskiy committed May 4, 2024
1 parent a2cc89d commit cca1d67
Show file tree
Hide file tree
Showing 4 changed files with 244 additions and 33 deletions.
62 changes: 41 additions & 21 deletions automation/hook_manifest_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,56 +10,76 @@

base_dir = Path(__file__).parent.parent # base directory of the repository
hook_json_path = base_dir / "metadata/hook.json"
hook_v2_json_path = base_dir / "metadata/hook_v2.json"


def update_or_append(df_checksum: int, checksum: int, lib: str, config: str, offsets: str):
hook_manifest = json.loads(hook_json_path.read_text())
def update_or_append(
manifest_path: str, df_checksum: int, checksum: int, lib: str, config: str, offsets: str, dfhooks: str | None
):
hook_manifest = json.loads(manifest_path.read_text())
for i, item in enumerate(hook_manifest):
if item["df"] == df_checksum:
item["checksum"] = checksum
item["lib"] = lib
item["config"] = config
item["offsets"] = offsets
hook_json_path.write_text(json.dumps(hook_manifest, indent=2))
if dfhooks:
item["dfhooks"] = dfhooks
manifest_path.write_text(json.dumps(hook_manifest, indent=2))
return

hook_manifest.append(
{
"df": df_checksum,
"checksum": checksum,
"lib": lib,
"config": config,
"offsets": offsets,
}
)
hook_json_path.write_text(json.dumps(hook_manifest, indent=2))


def main(lib: str, config: str, offsets: str):
if dfhooks:
hook_manifest.append(
{
"df": df_checksum,
"checksum": checksum,
"lib": lib,
"config": config,
"offsets": offsets,
"dfhooks": dfhooks,
}
)
else:
hook_manifest.append(
{
"df": df_checksum,
"checksum": checksum,
"lib": lib,
"config": config,
"offsets": offsets,
}
)
manifest_path.write_text(json.dumps(hook_manifest, indent=2))


def main(lib: str, config: str, offsets: str, dfhooks: str):
res_hook = get_from_url(lib)
res_config = get_from_url(config)
res_offsets = get_from_url(offsets)

res_dfhooks = get_from_url(dfhooks)

offsets_data = toml.loads(res_offsets.decode(encoding="utf-8"))
df_checksum = offsets_data["metadata"]["checksum"]
checksum = crc32(res_hook + res_config + res_offsets)
update_or_append(df_checksum, checksum, lib, config, offsets)
checksum_v2 = crc32(res_hook + res_config + res_offsets + res_dfhooks)
update_or_append(hook_json_path, df_checksum, checksum, lib, config, offsets, None)
update_or_append(hook_v2_json_path, df_checksum, checksum_v2, lib, config, offsets, dfhooks)


def run_with_config():
config = toml.load(base_dir / "automation/hook_manifest_add.toml")
for lib_variant in config.values():
for offset_url in lib_variant["offset_urls"]:
main(lib_variant["lib_url"], lib_variant["config_url"], offset_url)
main(lib_variant["lib_url"], lib_variant["config_url"], offset_url, lib_variant["dfhooks_url"])


def run():
args = sys.argv[1:]

if not args:
run_with_config()
return

if len(args) < 3:
raise Exception("Not enought args")

Expand Down
2 changes: 2 additions & 0 deletions automation/hook_manifest_add.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ offset_urls = [
"https://raw.githubusercontent.com/dfint/update-data/main/store/offsets/50.13_itchio_win64.toml",
"https://raw.githubusercontent.com/dfint/update-data/main/store/offsets/50.13_classic_win64.toml",
]
dfhooks_url = "https://github.com/DFHack/dfhooks/releases/download/v1/dfhooks.dll"

[so]
lib_url = "https://github.com/dfint/df-steam-hook-rs/releases/download/0.1.3/hook_0.1.3.so"
Expand All @@ -15,3 +16,4 @@ offset_urls = [
"https://raw.githubusercontent.com/dfint/update-data/main/store/offsets/50.13_itchio_linux64.toml",
"https://raw.githubusercontent.com/dfint/update-data/main/store/offsets/50.13_classic_linux64.toml",
]
dfhooks_url = "https://github.com/DFHack/dfhooks/releases/download/v1/libdfhooks.so"
27 changes: 15 additions & 12 deletions automation/hook_manifest_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@
from utils import get_from_url

base_dir = Path(__file__).parent.parent # base directory of the repository
hook_json_path = base_dir / "metadata/hook.json"
hook_json_path = [base_dir / "metadata/hook.json", base_dir / "metadata/hook_v2.json"]

manifest = json.loads(hook_json_path.read_text(encoding="utf-8"))
for path in hook_json_path:
manifest = json.loads(path.read_text(encoding="utf-8"))

for i, item in enumerate(manifest):
try:
data = get_from_url(item["lib"]) + get_from_url(item["config"]) + get_from_url(item["offsets"])
checksum = binascii.crc32(data)
except Exception as ex:
print(f"Failed on recalculation {item['language']}:\n", ex)
else:
if item.get("checksum") != checksum:
manifest[i]["checksum"] = checksum
for i, item in enumerate(manifest):
try:
data = get_from_url(item["lib"]) + get_from_url(item["config"]) + get_from_url(item["offsets"])
if item.get("dfhooks"):
data += get_from_url(item["dfhooks"])
checksum = binascii.crc32(data)
except Exception as ex:
print(f"Failed on recalculation {item['language']}:\n", ex)
else:
if item.get("checksum") != checksum:
manifest[i]["checksum"] = checksum

hook_json_path.write_text(json.dumps(manifest, indent=2, ensure_ascii=False), encoding="utf-8")
path.write_text(json.dumps(manifest, indent=2, ensure_ascii=False), encoding="utf-8")
186 changes: 186 additions & 0 deletions metadata/hook_v2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
[
{
"df": 1695011268,
"checksum": 1341628815,
"lib": "https://github.com/dfint/df-steam-hook-rs/releases/download/0.1.0/hook_0.1.0.dll",
"config": "https://raw.githubusercontent.com/dfint/update-data/main/store/config.toml",
"offsets": "https://raw.githubusercontent.com/dfint/update-data/main/store/offsets/50.10_classic_win64.toml",
"dfhooks": "https://github.com/DFHack/dfhooks/releases/download/v1/dfhooks.dll"
},
{
"df": 1695008478,
"checksum": 2167978200,
"lib": "https://github.com/dfint/df-steam-hook-rs/releases/download/0.1.0/hook_0.1.0.dll",
"config": "https://raw.githubusercontent.com/dfint/update-data/main/store/config.toml",
"offsets": "https://raw.githubusercontent.com/dfint/update-data/main/store/offsets/50.10_itchio_win64.toml",
"dfhooks": "https://github.com/DFHack/dfhooks/releases/download/v1/dfhooks.dll"
},
{
"df": 1695006380,
"checksum": 3986383368,
"lib": "https://github.com/dfint/df-steam-hook-rs/releases/download/0.1.0/hook_0.1.0.dll",
"config": "https://raw.githubusercontent.com/dfint/update-data/main/store/config.toml",
"offsets": "https://raw.githubusercontent.com/dfint/update-data/main/store/offsets/50.10_steam_win64.toml",
"dfhooks": "https://github.com/DFHack/dfhooks/releases/download/v1/dfhooks.dll"
},
{
"df": 1408469667,
"checksum": 2235292304,
"lib": "https://github.com/dfint/df-steam-hook-rs/releases/download/0.1.0/hook_0.1.0.so",
"config": "https://raw.githubusercontent.com/dfint/update-data/main/store/config.toml",
"offsets": "https://raw.githubusercontent.com/dfint/update-data/main/store/offsets/50.10_classic_linux64.toml",
"dfhooks": "https://github.com/DFHack/dfhooks/releases/download/v1/libdfhooks.so"
},
{
"df": 2153814425,
"checksum": 3749404198,
"lib": "https://github.com/dfint/df-steam-hook-rs/releases/download/0.1.0/hook_0.1.0.so",
"config": "https://raw.githubusercontent.com/dfint/update-data/main/store/config.toml",
"offsets": "https://raw.githubusercontent.com/dfint/update-data/main/store/offsets/50.10_itchio_linux64.toml",
"dfhooks": "https://github.com/DFHack/dfhooks/releases/download/v1/libdfhooks.so"
},
{
"df": 1696135234,
"checksum": 3788791124,
"lib": "https://github.com/dfint/df-steam-hook-rs/releases/download/0.1.1/hook_0.1.1.dll",
"config": "https://raw.githubusercontent.com/dfint/update-data/main/store/config.toml",
"offsets": "https://raw.githubusercontent.com/dfint/update-data/main/store/offsets/50.11_steam_win64.toml",
"dfhooks": "https://github.com/DFHack/dfhooks/releases/download/v1/dfhooks.dll"
},
{
"df": 1696136250,
"checksum": 2438894445,
"lib": "https://github.com/dfint/df-steam-hook-rs/releases/download/0.1.1/hook_0.1.1.dll",
"config": "https://raw.githubusercontent.com/dfint/update-data/main/store/config.toml",
"offsets": "https://raw.githubusercontent.com/dfint/update-data/main/store/offsets/50.11_itchio_win64.toml",
"dfhooks": "https://github.com/DFHack/dfhooks/releases/download/v1/dfhooks.dll"
},
{
"df": 1696138628,
"checksum": 206332128,
"lib": "https://github.com/dfint/df-steam-hook-rs/releases/download/0.1.1/hook_0.1.1.dll",
"config": "https://raw.githubusercontent.com/dfint/update-data/main/store/config.toml",
"offsets": "https://raw.githubusercontent.com/dfint/update-data/main/store/offsets/50.11_classic_win64.toml",
"dfhooks": "https://github.com/DFHack/dfhooks/releases/download/v1/dfhooks.dll"
},
{
"df": 26452769,
"checksum": 471048772,
"lib": "https://github.com/dfint/df-steam-hook-rs/releases/download/0.1.1/hook_0.1.1.so",
"config": "https://raw.githubusercontent.com/dfint/update-data/main/store/config.toml",
"offsets": "https://raw.githubusercontent.com/dfint/update-data/main/store/offsets/50.11_classic_linux64.toml",
"dfhooks": "https://github.com/DFHack/dfhooks/releases/download/v1/libdfhooks.so"
},
{
"df": 3379072297,
"checksum": 3587085189,
"lib": "https://github.com/dfint/df-steam-hook-rs/releases/download/0.1.1/hook_0.1.1.so",
"config": "https://raw.githubusercontent.com/dfint/update-data/main/store/config.toml",
"offsets": "https://raw.githubusercontent.com/dfint/update-data/main/store/offsets/50.11_itchio_linux64.toml",
"dfhooks": "https://github.com/DFHack/dfhooks/releases/download/v1/libdfhooks.so"
},
{
"df": 1828862929,
"checksum": 342235316,
"lib": "https://github.com/dfint/df-steam-hook-rs/releases/download/0.1.1/hook_0.1.1.so",
"config": "https://raw.githubusercontent.com/dfint/update-data/main/store/config.toml",
"offsets": "https://raw.githubusercontent.com/dfint/update-data/main/store/offsets/50.11_steam_linux64.toml",
"dfhooks": "https://github.com/DFHack/dfhooks/releases/download/v1/libdfhooks.so"
},
{
"df": 1709713517,
"checksum": 2154464670,
"lib": "https://github.com/dfint/df-steam-hook-rs/releases/download/0.1.3/hook_0.1.3.dll",
"config": "https://raw.githubusercontent.com/dfint/update-data/main/store/config.toml",
"offsets": "https://raw.githubusercontent.com/dfint/update-data/main/store/offsets/50.12_steam_win64.toml",
"dfhooks": "https://github.com/DFHack/dfhooks/releases/download/v1/dfhooks.dll"
},
{
"df": 1709717368,
"checksum": 2639829164,
"lib": "https://github.com/dfint/df-steam-hook-rs/releases/download/0.1.3/hook_0.1.3.dll",
"config": "https://raw.githubusercontent.com/dfint/update-data/main/store/config.toml",
"offsets": "https://raw.githubusercontent.com/dfint/update-data/main/store/offsets/50.12_itchio_win64.toml",
"dfhooks": "https://github.com/DFHack/dfhooks/releases/download/v1/dfhooks.dll"
},
{
"df": 1709719983,
"checksum": 3307932668,
"lib": "https://github.com/dfint/df-steam-hook-rs/releases/download/0.1.3/hook_0.1.3.dll",
"config": "https://raw.githubusercontent.com/dfint/update-data/main/store/config.toml",
"offsets": "https://raw.githubusercontent.com/dfint/update-data/main/store/offsets/50.12_classic_win64.toml",
"dfhooks": "https://github.com/DFHack/dfhooks/releases/download/v1/dfhooks.dll"
},
{
"df": 768338988,
"checksum": 3824627430,
"lib": "https://github.com/dfint/df-steam-hook-rs/releases/download/0.1.3/hook_0.1.3.so",
"config": "https://raw.githubusercontent.com/dfint/update-data/main/store/config.toml",
"offsets": "https://raw.githubusercontent.com/dfint/update-data/main/store/offsets/50.12_steam_linux64.toml",
"dfhooks": "https://github.com/DFHack/dfhooks/releases/download/v1/libdfhooks.so"
},
{
"df": 1394744997,
"checksum": 652311286,
"lib": "https://github.com/dfint/df-steam-hook-rs/releases/download/0.1.3/hook_0.1.3.so",
"config": "https://raw.githubusercontent.com/dfint/update-data/main/store/config.toml",
"offsets": "https://raw.githubusercontent.com/dfint/update-data/main/store/offsets/50.12_itchio_linux64.toml",
"dfhooks": "https://github.com/DFHack/dfhooks/releases/download/v1/libdfhooks.so"
},
{
"df": 445643784,
"checksum": 1643163062,
"lib": "https://github.com/dfint/df-steam-hook-rs/releases/download/0.1.3/hook_0.1.3.so",
"config": "https://raw.githubusercontent.com/dfint/update-data/main/store/config.toml",
"offsets": "https://raw.githubusercontent.com/dfint/update-data/main/store/offsets/50.12_classic_linux64.toml",
"dfhooks": "https://github.com/DFHack/dfhooks/releases/download/v1/libdfhooks.so"
},
{
"df": 1713726302,
"checksum": 757258397,
"lib": "https://github.com/dfint/df-steam-hook-rs/releases/download/0.1.3/hook_0.1.3.dll",
"config": "https://raw.githubusercontent.com/dfint/update-data/main/store/config.toml",
"offsets": "https://raw.githubusercontent.com/dfint/update-data/main/store/offsets/50.13_steam_win64.toml",
"dfhooks": "https://github.com/DFHack/dfhooks/releases/download/v1/dfhooks.dll"
},
{
"df": 1713730104,
"checksum": 2636431967,
"lib": "https://github.com/dfint/df-steam-hook-rs/releases/download/0.1.3/hook_0.1.3.dll",
"config": "https://raw.githubusercontent.com/dfint/update-data/main/store/config.toml",
"offsets": "https://raw.githubusercontent.com/dfint/update-data/main/store/offsets/50.13_classic_win64.toml",
"dfhooks": "https://github.com/DFHack/dfhooks/releases/download/v1/dfhooks.dll"
},
{
"df": 1571398539,
"checksum": 2177505249,
"lib": "https://github.com/dfint/df-steam-hook-rs/releases/download/0.1.3/hook_0.1.3.so",
"config": "https://raw.githubusercontent.com/dfint/update-data/main/store/config.toml",
"offsets": "https://raw.githubusercontent.com/dfint/update-data/main/store/offsets/50.13_steam_linux64.toml",
"dfhooks": "https://github.com/DFHack/dfhooks/releases/download/v1/libdfhooks.so"
},
{
"df": 1154905022,
"checksum": 1703738665,
"lib": "https://github.com/dfint/df-steam-hook-rs/releases/download/0.1.3/hook_0.1.3.so",
"config": "https://raw.githubusercontent.com/dfint/update-data/main/store/config.toml",
"offsets": "https://raw.githubusercontent.com/dfint/update-data/main/store/offsets/50.13_classic_linux64.toml",
"dfhooks": "https://github.com/DFHack/dfhooks/releases/download/v1/libdfhooks.so"
},
{
"df": 1713728445,
"checksum": 581797592,
"lib": "https://github.com/dfint/df-steam-hook-rs/releases/download/0.1.3/hook_0.1.3.dll",
"config": "https://raw.githubusercontent.com/dfint/update-data/main/store/config.toml",
"offsets": "https://raw.githubusercontent.com/dfint/update-data/main/store/offsets/50.13_itchio_win64.toml",
"dfhooks": "https://github.com/DFHack/dfhooks/releases/download/v1/dfhooks.dll"
},
{
"df": 323613002,
"checksum": 1392304140,
"lib": "https://github.com/dfint/df-steam-hook-rs/releases/download/0.1.3/hook_0.1.3.so",
"config": "https://raw.githubusercontent.com/dfint/update-data/main/store/config.toml",
"offsets": "https://raw.githubusercontent.com/dfint/update-data/main/store/offsets/50.13_itchio_linux64.toml",
"dfhooks": "https://github.com/DFHack/dfhooks/releases/download/v1/libdfhooks.so"
}
]

0 comments on commit cca1d67

Please sign in to comment.