Release ranch assistant 1.1.0

This commit is contained in:
AttilaNet
2026-11-08 09:07:35 +08:00
parent 75571d36e1
commit 25ce032bd6
13 changed files with 752 additions and 48 deletions
+21 -3
View File
@@ -10,11 +10,25 @@ root = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(root))
from ranch_assistant.amf import Reader
def repair_names(value):
"""Recover legacy GBK text decoded with the wrong single-byte codec."""
if isinstance(value, dict):
return {key: repair_names(item) for key, item in value.items()}
if isinstance(value, list):
return [repair_names(item) for item in value]
if isinstance(value, str):
try:
return value.encode("latin1").decode("gbk")
except (UnicodeEncodeError, UnicodeDecodeError):
return value
return value
apk = next(p for p in root.glob("*.apk") if p.name.endswith("_1.9.68.apk"))
tables = {}
with zipfile.ZipFile(apk) as archive:
tables["tjchannel"] = json.loads(archive.read("assets/tjchannel.json")) if "assets/tjchannel.json" in archive.namelist() else {"tjchannel": "unknow"}
for name in ("monster_info", "monster_level", "room_info", "game_setting", "stage_info", "stage_sp", "activity_info", "server_info", "task_info", "gacha_machine", "potential_info", "stack_price", "room_price", "item_info"):
for name in ("monster_info", "monster_level", "farm_level", "entangle_info", "room_info", "game_setting", "stage_info", "stage_sp", "activity_info", "server_info", "task_info", "gacha_machine", "potential_info", "stack_price", "room_price", "item_info"):
path = "data/table/" + name + ".json"
raw = zlib.decompress(archive.read("assets/codes/" + hashlib.md5(path.encode()).hexdigest()))
reader = Reader(raw)
@@ -28,7 +42,11 @@ with zipfile.ZipFile(apk) as archive:
fields = {"type", "name", "star", "time_1", "time_2", "sell_money", "sell_exp", "hideLib", "npc", "atk", "def", "hp", "dex", "like"}
fields |= {p + "_grow_" + bound for p in ("atk", "def", "hp", "dex") for bound in ("min", "max")}
tables["monster_info"] = {str(k): {f: v for f, v in row.items() if f in fields} for k, row in tables["monster_info"].items()}
tables["item_names"] = {str(key): row.get("name", str(key)) for key, row in tables.pop("item_info").items()}
tables = repair_names(tables)
tables["item_names"] = {str(key): row.get("name", str(key)) for key, row in tables["item_info"].items()}
tables["item_info"] = {str(key): {k: row.get(k) for k in ("name", "itemType", "quality", "sellMoney", "sellable", "useable")}
for key, row in tables["item_info"].items()}
tables["entangle_info"] = {"haoganMax": tables["entangle_info"]["haoganMax"]}
# The market button uses sc_city + the selected city ID, even where the table's
# legacy city field still says 4. Exclude tavern/premium/event egg machines.
@@ -43,7 +61,7 @@ tables["activity_info"] = {k: v for k, v in tables["activity_info"].items() if k
# Only positions are needed to avoid starting a sweep through an active story task.
tables["stage_task_positions"] = {str(k): [s.get("position", "") for s in r.get("steps", [])] for k, r in tables["task_info"].items()
if any(str(s.get("position", "")).startswith("city") for s in r.get("steps", []))}
tables["game_setting"] = {k: v for k, v in tables["game_setting"].items() if k in ("monExpScale", "xyz", "xyz1", "cityInfo", "upStarAdd", "maxLike", "vipReward") or k.startswith("loopTask") or k.endswith("_xyz")}
tables["game_setting"] = {k: v for k, v in tables["game_setting"].items() if k in ("monExpScale", "xyz", "xyz1", "cityInfo", "upStarAdd", "maxLike", "vipReward", "monGiftTime", "monGiftMax", "masterMaxLevel") or k.startswith("loopTask") or k.endswith("_xyz")}
task_fields = {"type", "typeId", "name", "des", "city", "closed", "condition", "startStep", "reward"}
step_fields = {"statusType", "statusValue", "condition", "des", "position", "npc", "afterStory", "auto"}
tables["task_info"] = {str(k): {f: v for f, v in row.items() if f in task_fields} |
+32
View File
@@ -0,0 +1,32 @@
"""Add v1.1 item and progression tables using the supplied local APK."""
import hashlib
import json
from pathlib import Path
import sys
import zipfile
import zlib
root = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(root))
sys.path.insert(0, str(root / "tools"))
from ranch_assistant.amf import Reader
from extract_ranch_catalog import repair_names
path = root / "ranch_assistant" / "data" / "catalog.json"
data = json.loads(path.read_text(encoding="utf-8"))
apk = next(root.glob("*_1.9.68.apk"))
with zipfile.ZipFile(apk) as archive:
for name in ("item_info", "farm_level", "entangle_info", "game_setting"):
table = "data/table/" + name + ".json"
raw = zlib.decompress(archive.read("assets/codes/" + hashlib.md5(table.encode()).hexdigest()))
value = Reader(raw).read()
data[name] = value.get("datas", value)
data["item_names"] = {str(key): row.get("name", str(key)) for key, row in data["item_info"].items()}
data["item_info"] = {str(key): {k: row.get(k) for k in ("name", "itemType", "quality", "sellMoney", "sellable", "useable")}
for key, row in data["item_info"].items()}
data["entangle_info"] = {"haoganMax": data["entangle_info"]["haoganMax"]}
data["game_setting"] = {k: v for k, v in data["game_setting"].items() if k in ("monExpScale", "xyz", "xyz1", "cityInfo", "upStarAdd", "maxLike", "vipReward", "monGiftTime", "monGiftMax", "masterMaxLevel") or k.startswith("loopTask") or k.endswith("_xyz")}
data = repair_names(data)
path.write_text(json.dumps(data, ensure_ascii=False, separators=(",", ":")), encoding="utf-8")
print("Updated item, level and gift-cap tables from the local 1.9.68 APK.")