Skip to content

Commit

Permalink
fix dumb thing in main and add a fix for 0 warps in experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
danielah05 committed Feb 27, 2022
1 parent 829f9da commit af05779
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 27 deletions.
60 changes: 35 additions & 25 deletions mwl2bin-experimental.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
obj_datasplit = data_headerless.split(b"\xff\x04", 1)
obj_data = obj_datasplit[0]

print("converted obj: "+filename)

# -------------------------------
# level data - obj (screen exits)
# -------------------------------
Expand All @@ -48,29 +46,41 @@

warpamount = input("enter the amount of screen exits in the level: ")

print("fixing "+warpamount+" screen exit(s)...")

warpdata = obj_data[-4*int(warpamount):]
nowarpdata = obj_data[:-4*int(warpamount)]

# do multiple replace checks to make sure warps are correct
warpdatacheck1 = warpdata.replace(b"\x05\x00", b"\x00\x00") # default pipe, no sub exit
warpdatacheck2 = warpdatacheck1.replace(b"\x07\x00", b"\x02\x00") # default pipe, sub exit
warpdatacheck3 = warpdatacheck2.replace(b"\x0f\x00", b"\x02\x00") # default pipe, sub exit water flag (custom lunar magic value, so it gets converted to 02)
warpdatacheck4 = warpdatacheck3.replace(b"\x0d\x00", b"\x00\x00") # default pipe, midway exit (custom lunar magic value, so it gets converted to 00)

warpdatafinal = warpdatacheck4

reconstructedwarps = nowarpdata+warpdatafinal

print(str(warpdata)+" -> "+str(warpdatafinal))

print("(hopefully) fixed screen exits: "+filename)

# export finished bin
with open("lvl/obj/"+filename+".bin", "wb") as binobj:
binobj.write(reconstructedwarps)
binobj.write(b"\xff")
if warpamount > str(0):
print("fixing "+warpamount+" screen exit(s)...")

warpdata = obj_data[-4*int(warpamount):]
nowarpdata = obj_data[:-4*int(warpamount)]

# do multiple replace checks to make sure warps are correct
warpdatacheck1 = warpdata.replace(b"\x05\x00", b"\x00\x00") # default pipe, no sub exit
warpdatacheck2 = warpdatacheck1.replace(b"\x07\x00", b"\x02\x00") # default pipe, sub exit
warpdatacheck3 = warpdatacheck2.replace(b"\x0f\x00", b"\x02\x00") # default pipe, sub exit water flag (custom lunar magic value, so it gets converted to 02)
warpdatacheck4 = warpdatacheck3.replace(b"\x0d\x00", b"\x00\x00") # default pipe, midway exit (custom lunar magic value, so it gets converted to 00)

warpdatafinal = warpdatacheck4

reconstructedwarps = nowarpdata+warpdatafinal

print(str(warpdata)+" -> "+str(warpdatafinal))

print("(hopefully) fixed screen exits: "+filename)

print("converted obj: "+filename)

# export finished bin
with open("lvl/obj/"+filename+".bin", "wb") as binobj:
binobj.write(reconstructedwarps)
binobj.write(b"\xff")

if warpamount == str(0):
print("0 screen exits, fixing skipped!")
print("converted obj: "+filename)

# export finished bin
with open("lvl/obj/"+filename+".bin", "wb") as binobj:
binobj.write(obj_data)
binobj.write(b"\xff")

# ----------------
# level data - spr
Expand Down
2 changes: 0 additions & 2 deletions mwl2bin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import os, sys

import os, sys

# create directories and stuff
if not os.path.isdir("lvl"):
os.mkdir("lvl")
Expand Down

0 comments on commit af05779

Please sign in to comment.