From d1e868c18371324e87b7445656ab88012189069d Mon Sep 17 00:00:00 2001 From: Sunpy Date: Wed, 13 Mar 2019 11:13:55 +0100 Subject: [PATCH] beatmap hash fix --- README.md | 2 +- osuRepy/replay.py | 6 +++++- test.py | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3bf5ada..bbdd99f 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ from osuRepy.replay import Replay # Replay instance from osuRepy.helpers import osuButtons, osuMods # Enum helpers -replay = Replay() # Create replay instance +replay = Replay(beatmap_hash = "9e66c0a0eadced7d07f06b3968a74cc0") # Create replay instance replay.write( ReplayFrame(2, 256, 192, osuButtons.M1) ) # Add replay frame (time, x, y, buttons) diff --git a/osuRepy/replay.py b/osuRepy/replay.py index ec87117..c21dc43 100644 --- a/osuRepy/replay.py +++ b/osuRepy/replay.py @@ -74,6 +74,7 @@ class Replay: "mode": self.set_mode, "mods": self.set_mods, "osu_version": self.set_osu_version, + "beatmap_hash": self.set_beatmap_hash, "player_name": self.set_player_name, "replay_data": self.write } @@ -95,9 +96,12 @@ class Replay: self._osu_version.value = osu_version def set_beatmap_hash(self, md5_hash): + if type(md5_hash) is bytes: + md5_hash = md5_hash.decode() + if len(md5_hash) != 32 or len([x for x in md5_hash if x in string.hexdigits]) != 32: raise Exception("Invalid beatmap hash") - self._beatmap_hash.value = md5_hash + self._beatmap_hash.value = md5_hash.encode() def set_beatmap_file(self, filepath): if not isfile(filepath): diff --git a/test.py b/test.py index f748e98..09a922e 100644 --- a/test.py +++ b/test.py @@ -3,7 +3,7 @@ from osuRepy.replay import Replay # Replay instance from osuRepy.helpers import osuButtons, osuMods # Enum helpers -replay = Replay() # Create replay instance +replay = Replay(beatmap_hash = "9e66c0a0eadced7d07f06b3968a74cc0") # Create replay instance replay.write( ReplayFrame(2, 256, 192, osuButtons.M1) ) # Add replay frame (time, x, y, buttons)