From 723db2bb00e9d5713f89dc4c7e922fb31eacf22d Mon Sep 17 00:00:00 2001 From: MoYoez Date: Thu, 19 Oct 2023 18:11:30 +0800 Subject: [PATCH] feat: use action to update --- .github/workflow/updater.yml | 27 ++++++ gameInformation.py | 154 +++++++++++++++++++++++++++++++++++ 2 files changed, 181 insertions(+) create mode 100644 .github/workflow/updater.yml create mode 100644 gameInformation.py diff --git a/.github/workflow/updater.yml b/.github/workflow/updater.yml new file mode 100644 index 0000000..691176d --- /dev/null +++ b/.github/workflow/updater.yml @@ -0,0 +1,27 @@ +name: Update Phigros Recources +on: + workflow_dispatch: + inputs: + url: + description: "download url" + required: true + type: string +permissions: write-all + + +jobs: + starter: + name: Fetch And Update + runs-on: ubuntu-latest + steps: + - run: pip3 install tqdm + - uses: actions/checkout@v3 + - run: | + python3 handler.py ${{ inputs.url }} + - run: | + content=$(date +'%Y-%m-%d') + git config user.name github-actions + git config user.email github-actions@github.com + git add . + git commit -m "Update GameResource At $content" + git push \ No newline at end of file diff --git a/gameInformation.py b/gameInformation.py new file mode 100644 index 0000000..cb0a37b --- /dev/null +++ b/gameInformation.py @@ -0,0 +1,154 @@ +from UnityPy import Environment +from tqdm import tqdm + +import os +import zipfile +import requests + +import struct +import sys + +# download gameinformation from + +env = Environment() + +filename = sys.argv[1].split("/")[-1] + + +class ByteReader: + def __init__(self, data: bytes): + self.data = data + self.position = 0 + self.d = {int: self.readInt, float: self.readFloat, str: self.readString} + + def readInt(self): + self.position += 4 + return self.data[self.position - 4] ^ self.data[self.position - 3] << 8 + + def readFloat(self): + self.position += 4 + return struct.unpack("f", self.data[self.position - 4 : self.position])[0] + + def readString(self): + length = self.readInt() + result = self.data[self.position : self.position + length].decode() + self.position += length // 4 * 4 + if length % 4 != 0: + self.position += 4 + return result + + def skipString(self): + length = self.readInt() + self.position += length // 4 * 4 + if length % 4 != 0: + self.position += 4 + + def readSchema(self, schema: dict): + result = [] + for x in range(self.readInt()): + item = {} + for key, value in schema.items(): + if value in (int, str, float): + item[key] = self.d[value]() + elif type(value) == list: + l = [] + for i in range(self.readInt()): + l.append(self.d[value[0]]()) + item[key] = l + elif type(value) == tuple: + for t in value: + self.d[t]() + elif type(value) == dict: + item[key] = self.readSchema(value) + else: + raise Exception("无") + result.append(item) + return result + + +def run(path): + with zipfile.ZipFile(path) as apk: + with apk.open("assets/bin/Data/globalgamemanagers.assets") as f: + env.load_file(f.read(), name="assets/bin/Data/globalgamemanagers.assets") + with apk.open("assets/bin/Data/level0") as f: + env.load_file(f.read()) + for obj in env.objects: + if obj.type.name != "MonoBehaviour": + continue + data = obj.read() + if data.m_Script.get_obj().read().name == "GameInformation": + information = data.raw_data.tobytes() + + position = information.index(b"\x16\x00\x00\x00Glaciaxion.SunsetRay.0\x00\x00\n") + + reader = ByteReader(information[position - 4 :]) + information_schema = { + "songId": str, + "songKey": str, + "songName": str, + "songTitle": str, + "difficulty": [float], + "illustrator": str, + "charter": [str], + "composer": str, + "levels": [str], + "previewTime": float, + "unlockList": {"unlockType": int, "unlockInfo": [str]}, + "n": [int], + } + difficulty = [] + table = [] + for i in range(3): + for item in reader.readSchema(information_schema): + item["songId"] = item["songId"][:-2] + if len(item["levels"]) == 5: + item["difficulty"].pop() + item["charter"].pop() + if item["difficulty"][-1] == 0: + item["difficulty"].pop() + item["charter"].pop() + for i in range(len(item["difficulty"])): + item["difficulty"][i] = round(item["difficulty"][i], 1) + difficulty.append([item["songId"]] + item["difficulty"]) + table.append( + ( + item["songId"], + item["songName"], + item["composer"], + item["illustrator"], + *item["charter"], + ) + ) + + print(difficulty) + print(table) + + with open("difficulty.csv", "w", encoding="utf8") as f: + for item in difficulty: + f.write(",".join(map(str, item))) + f.write("\n") + + with open("info.csv", "w", encoding="utf8") as f: + for item in table: + f.write("\\".join(item)) + f.write("\n") + + +if __name__ == "__main__": + response = requests.get(sys.argv[1], stream=True) +# get length. +total = int(response.headers.get("content-length", 0)) + + +with open(filename, "wb") as file, tqdm( + desc=filename, + total=total, + unit="iB", + unit_scale=True, + unit_divisor=1024, +) as bar: + for data in response.iter_content(chunk_size=1024): + size = file.write(data) + bar.update(size) + run(filename) + os.delete(filename)