Last active
November 15, 2019 17:18
-
-
Save leo60228/ff36b2bfb94e9408a119151b0dd68d7e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import struct | |
import os | |
import shutil | |
from PIL import Image | |
prefix = "atmosphere/titles/0100B1E0022F8000/romfs/resources/" | |
if os.path.exists("vvvvvvmusic.vvv"): | |
with open('vvvvvvmusic.vvv', 'rb') as f: | |
data = f.read() | |
# find filenames | |
# (name, len) | |
headers = [] | |
iptr = 0 | |
while data[iptr] == 0x64: | |
headers.append(list(struct.unpack("<48s4xI4x", data[iptr:iptr+0x3C]))) | |
headers[-1][0] = headers[-1][0][:headers[-1][0].index(b'\x00')] | |
iptr += 0x3C | |
moffset = 0x1e00 | |
if not os.path.exists(prefix + "data/music"): | |
os.makedirs(prefix + "data/music") | |
for n, length in headers: | |
print(f"writing {n.decode('ascii')} to {prefix + n.decode('ascii')}") | |
with open(prefix + n.decode('ascii'), 'wb') as f: | |
f.write(data[moffset:moffset+length]) | |
moffset += length | |
ignore = shutil.ignore_patterns("atmosphere", "*.vvv", "*.py", "levels", "*/sprites.png") | |
print("copying files") | |
shutil.copytree(".", prefix + "data/", dirs_exist_ok=True, ignore=ignore) | |
if os.path.exists("graphics/sprites.png"): | |
print(f"fixing sprites.png") | |
if not os.path.exists(prefix + "data/graphics"): | |
os.makedirs(prefix + "data/graphics") | |
im = Image.open("graphics/sprites.png") | |
pixels = im.load() | |
width, height = im.size | |
for x in range(width): | |
for y in range(height): | |
_, _, _, a = pixels[x, y] | |
pixels[x, y] = (255, 255, 255, a) | |
im.save(prefix + "data/graphics/sprites.png") | |
if os.path.isdir("levels"): | |
if not os.path.exists(prefix + "data/levels"): | |
os.makedirs(prefix + "data/levels") | |
levels = ["333333_easy.vvvvvv", "4kvvvv.vvvvvv", "a_new_dimension.vvvvvv", "linewrap.vvvvvv", "pyramid.vvvvvv", "quantumtunnel12.vvvvvv", "roadtrip.vvvvvv", "seasons.vvvvvv", "soulsearching.vvvvvv", "the_dual_challenge.vvvvvv", "towerofpower.vvvvvv", "variationventure.vvvvvv", "varietyshow.vvvvvv", "vertexvortex.vvvvvv", "vertiginousviridian.vvvvvv", "victuals.vvvvvv", "vvvvvvgoldenspiral.vvvvvv", "gordian.vvvvvv"] | |
for level in os.listdir("levels"): | |
level = "levels/" + level | |
dst = prefix + "data/levels/" + levels.pop() | |
print(f"copying level {level} to {dst}") | |
shutil.copy2(level, dst) | |
for remaining in levels: | |
print(f"stubbing level {remaining}") | |
open(prefix + "data/levels/" + remaining, 'w').close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment