Skip to content

Commit 9086e88

Browse files
committed
support dk64 patching
1 parent 93ebe1c commit 9086e88

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

worlds/dk64/__init__.py

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
import typing
44
import math
55
import threading
6+
import time
7+
import json
8+
import zipfile
9+
import codecs
10+
from io import BytesIO
611
# Print the original running script
712
original_file = os.path.basename(sys.argv[0])
813
if not "DK64Client" in original_file:
@@ -16,10 +21,12 @@
1621
from .Regions import all_locations, create_regions, connect_regions
1722
from .Rules import set_rules
1823
from worlds.AutoWorld import WebWorld, World
19-
import Patch
24+
# import Patch
2025
from .Logic import LogicVarHolder
2126
from worlds.dk64.DK64R.randomizer.Spoiler import Spoiler
2227
from worlds.dk64.DK64R.randomizer.Settings import Settings
28+
from worlds.dk64.DK64R.randomizer.Patching.ApplyRandomizer import patching_response
29+
from worlds.dk64.DK64R import version
2330

2431
class DK64Web(WebWorld):
2532
theme = "jungle"
@@ -122,15 +129,43 @@ def generate_output(self, output_directory: str):
122129
self.logic_holder.spoiler.LocationList[dk64_location_id].PlaceItem(self.logic_holder.spoiler, DK64RItems.NoItem)
123130
else:
124131
print(f"Location {ap_location.name} not found in DK64 location table.")
125-
126-
rompath = os.path.join(output_directory, f"{self.multiworld.get_out_file_name_base(self.player)}.sfc")
132+
patch_data, _ = patching_response(self.logic_holder.spoiler)
133+
self.logic_holder.spoiler.FlushAllExcessSpoilerData()
134+
patch_file = self.update_seed_results(patch_data, self.logic_holder.spoiler, self.player)
135+
rompath = os.path.join(output_directory, f"{self.multiworld.get_out_file_name_base(self.player)}.lanky")
136+
with open(rompath, "wb") as f:
137+
f.write(patch_file)
127138
except:
128139
raise
129140
finally:
130141
if os.path.exists(rompath):
131142
os.unlink(rompath)
132143
self.rom_name_available_event.set() # make sure threading continues and errors are collected
133144

145+
def update_seed_results(self, patch, spoiler, player_id):
146+
"""Update the seed results."""
147+
148+
timestamp = time.time()
149+
hash = spoiler.settings.seed_hash
150+
spoiler_log = json.loads(spoiler.json)
151+
spoiler_log["Generated Time"] = timestamp
152+
# Zip all the data into a single file.
153+
zip_data = BytesIO()
154+
with zipfile.ZipFile(zip_data, "w") as zip_file:
155+
# Write each variable to the zip file
156+
zip_file.writestr("patch", patch)
157+
zip_file.writestr("hash", str(hash))
158+
zip_file.writestr("spoiler_log", str(json.dumps(spoiler_log)))
159+
zip_file.writestr("seed_id", str(spoiler.settings.seed_id))
160+
zip_file.writestr("generated_time", str(timestamp))
161+
zip_file.writestr("version", version)
162+
zip_file.writestr("seed_number", "archipelago-seed-" + str(player_id))
163+
zip_data.seek(0)
164+
# Convert the zip to a string of base64 data
165+
zip_conv = codecs.encode(zip_data.getvalue(), "base64").decode()
166+
167+
return zip_conv
168+
134169
def modify_multidata(self, multidata: dict):
135170
pass
136171

0 commit comments

Comments
 (0)