Skip to content

Commit

Permalink
gamedata check v1
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyano1337 committed Dec 12, 2024
1 parent 18bfbef commit f271a78
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ jobs:

- name: Download depots and gamedata
run: python3 ./download.py

- name: Check gamedata
run: python3 ./gamedata.py
1 change: 0 additions & 1 deletion script/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def find_depot_files(directory):

if __name__ == "__main__":
config_gamedata = read_jsonc("../config/download.jsonc")

for url in config_gamedata["urls"]:
download_file(url, "../gamedata/")

Expand Down
98 changes: 98 additions & 0 deletions script/gamedata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import os
import re
import json5


def convert_to_regex(hex_signature):
pattern = ""
hex_signature = hex_signature.replace(" ", "")
i = 0
while i < len(hex_signature):
if hex_signature[i] == "?":
pattern += "."
i += 1
else:
if i + 1 < len(hex_signature):
byte = hex_signature[i : i + 2]
pattern += f"\\x{byte}"
i += 2
else:
pattern += "."
i += 1
return re.compile(pattern.encode("latin1"), re.DOTALL)


def count_binary_signature_with_regex(file, signature: str, key: str):
file.seek(0)
data = file.read()

regex_pattern = convert_to_regex(signature)

matches = regex_pattern.findall(data)

return len(matches)


def library_load(library):
if library in files and files[library] is not None:
return files[library]

try:
if library == "server":
file_path = game_path + "csgo/bin/win64/server.dll"
else:
file_path = game_path + "bin/win64/" + library + ".dll"

files[library] = open(file_path, "rb")
except FileNotFoundError:
print(f"Error: File {file_path} not found.")
return None
except Exception as e:
print(
f"Error: An unexpected error occurred while opening the file {file_path}. Exception: {e}"
)
return None

return files[library]


def read_files_in_directory(directory):
result = {}
for filename in os.listdir(directory):
path = os.path.join(directory, filename)
if os.path.isfile(path):
with open(path, "r", encoding="utf-8") as file:
if os.path.basename(path).endswith("placeholder"):
continue

signatures = json5.load(file)["Signature"]
for key, val in signatures.items():
library_name = str(val["library"]).lower()
library = library_load(library_name)
count = count_binary_signature_with_regex(
library, str(val["windows"]), key
)

if count == 1:
continue

if library_name not in result:
result[library_name] = {}

result[library_name][key] = count
elif os.path.isdir(path):
result.update(read_files_in_directory(path))

return result


if __name__ == "__main__":
game_path = "../cs2/game/"

files = {}

result = read_files_in_directory("../gamedata")

for lib, sig in result.items():
sigs = [f"[{sig[s]}] {s}" for s in sig]
print(f"Library: {lib}\n" + "\n".join(sigs))

0 comments on commit f271a78

Please sign in to comment.