-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoeadwrappers.py
More file actions
89 lines (65 loc) · 2.76 KB
/
oeadwrappers.py
File metadata and controls
89 lines (65 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import oead
import os
from pathlib import Path
# A set of wrapper functions around oead for handling SARC and BYAML files for Splatoon 1
def extractSARC(inputSARC):
with open(inputSARC, "rb") as f:
sarcData = f.read()
if oead.yaz0.get_header(sarcData):
sarcData = oead.yaz0.decompress(sarcData)
sarc = oead.Sarc(sarcData)
outputDir = Path(f"{inputSARC}_extracted")
outputDir.mkdir(exist_ok=True)
for file in sarc.get_files():
outputPath = outputDir / file.name
parentDir = outputPath.parent
if parentDir.exists() and not parentDir.is_dir():
print(f"Removing conflicting file: {parentDir}")
parentDir.unlink()
parentDir.mkdir(parents=True, exist_ok=True)
with open(outputPath, "wb") as out_file:
out_file.write(file.data)
def packSARC(inputDir: str, outputPath: str, compress: bool = True):
inputPath = Path(inputDir)
builder = oead.SarcWriter(endian=oead.Endianness.Big, mode=oead.SarcWriter.Mode.Legacy)
for filePath in inputPath.rglob("*"):
if filePath.is_file():
relativePath = filePath.relative_to(inputPath).as_posix()
with open(filePath, "rb") as f:
builder.files[relativePath] = f.read()
sarcData = builder.write()
if isinstance(sarcData, tuple):
sarcData = sarcData[1]
if compress:
sarcData = oead.yaz0.compress(sarcData, 0, 7)
with open(outputPath, "wb") as f:
f.write(sarcData)
print(f"Packed SARC: {outputPath}")
def convertFromBYAML(inputBYAML):
# print(inputBYAML)
with open(inputBYAML, "rb") as f:
info = oead.byml.from_binary(f.read())
ouputYAML = oead.byml.to_text(info)
# print(ouputYAML)
outputYamlName = os.path.splitext(inputBYAML)
print(outputYamlName[0])
with open(f"{outputYamlName[0]}.yaml", "w") as file:
file.write(ouputYAML)
def convertBYAMLToYAMLText(inputBYAML):
# print(inputBYAML)
with open(inputBYAML, "rb") as f:
info = oead.byml.from_binary(f.read())
outputYAML = oead.byml.to_text(info)
return outputYAML
def convertToBYAML(inputYaml):
with open(inputYaml, "r", encoding="utf-8") as file:
content = file.read()
convdBYAML = oead.byml.from_text(content)
outputBYAMLName = os.path.splitext(inputYaml)
print(outputBYAMLName[0])
with open(f"{outputBYAMLName[0]}.byaml", "wb") as f:
f.write(oead.byml.to_binary(data=convdBYAML, big_endian=True, version=1))
def convertYAMLTextToBYAML(inputYamlText, outputBYAMLName):
convdBYAML = oead.byml.from_text(inputYamlText)
with open(f"tmp/{outputBYAMLName}.byaml", "wb") as f:
f.write(oead.byml.to_binary(data=convdBYAML, big_endian=True, version=1))