Skip to content

Instantly share code, notes, and snippets.

@Sanqui
Created May 5, 2019 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sanqui/72c6e1dab07ce32b2b78c1ce84766b4b to your computer and use it in GitHub Desktop.
Save Sanqui/72c6e1dab07ce32b2b78c1ce84766b4b to your computer and use it in GitHub Desktop.
import colorsys
import png
import datamijn
from datamijn import dmtypes
VGATLAS_DIR = "/home/sanqui/romhacking/vgatlas/vgatlas"
name = "pokered"
rom_filename = "pokered.gbc"
dm = open(f"{VGATLAS_DIR}/games/{name}/data/{name}.dm")
rom = open(f"{VGATLAS_DIR}/games/{name}/data/{rom_filename}", "rb")
data = datamijn.parse(dm, rom, f"{VGATLAS_DIR}/games/{name}/static/")
img = []
def hsv_to_rgb(*color):
return [int(x*255) for x in colorsys.hsv_to_rgb(*color)]
#p = [(255,0,0, 0,255,0, 0,0,255),
# (128,0,0, 0,128,0, 0,0,128)]
def render_container(container):
row = []
for name, value in container.items():
row += render_type(name, value)
return row
def render_type(name, value):
row = []
if isinstance(value, dmtypes.Container):
row += render_container(value)
elif isinstance(value, dmtypes.U8) or type(value).__name__ == "B4" or isinstance(value, dmtypes.U16):
if isinstance(value, dmtypes.U16): size = 16
if isinstance(value, dmtypes.U8): size = 8
if type(value).__name__ == "B4": size = 4
# draw a progress bar
for i in range(size):
if size == 16: cur = value / (2**12) - i
if size == 8: cur = value / 32 - i
elif size == 4: cur = value / 4 - i
if cur < 0: cur = 0
if cur > 1: cur = 1
row += hsv_to_rgb((hash(name+"SAAAALT")%256)/255, 1, cur)
elif isinstance(value, dmtypes.ForeignKey):
h1 = hash(str(value._result)+name+'solt')%256/255
h2 = hash(str(value._result)+name+'salt')%256/255
h3 = hash(str(value._result)+name+'selt')%256/255
row += hsv_to_rgb(h1, h2/3 + 0.666, h3/3 + 0.666) * 8
elif isinstance(value, dmtypes.B1):
row += hsv_to_rgb(0, 0, value)
elif isinstance(value, dmtypes.Array):
for v in value:
if v != None:
row += render_type(name, v)
else:
row += [0, 0, 0]*8
else:
print("Unknown type", type(value))
return row
pokemon = data._pokemon_base_stats[0:150]
pokemon = sorted(pokemon, key=lambda p: p.catch_rate)
for base_stats in pokemon:
row = render_container(base_stats)
img.append(row)
f = open('out.png', 'wb')
w = png.Writer(int(len(img[0])/3), len(img))
w.write(f, img)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment