Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Copy Kitty 1.8 IGT auto-splitter
- # Utilizes LiveSplit and its Server component to auto-split a Copy Kitty run
- # Built for version 1.8 Turbo.
- # Caveat: This script does not detect the final split at the end of a run. That must be handled manually. Sorry!
- import time
- import struct
- import socket
- from watchdog.observers import Observer
- from watchdog.events import FileSystemEventHandler
- class BokiHandler(FileSystemEventHandler):
- # Data locations in the bytestream in the savefile
- handle = {"stage": 4, "second": 8, "minute": 10, "hour": 12}
- # Stages that come after bosses
- bosses = [27, 37, 47, 57, 72, 82, 92, 103, 112, 127]
- def on_modified(self, event):
- # If the marathon savefile got edited, parse it
- if event.src_path.endswith("boki.kittymarathon"):
- data = self.parse_savefile(event.src_path)
- # If we didn't beat a boss stage, stop processing
- if not data["stage"] in self.bosses:
- return None
- # From here on is where you'd do whatever you want to handle
- # the data. I make LiveSplit begin a new split.
- # Figure out how many seconds in gametime we're in
- sec = ((data["hour"] * 3600) +
- (data["minute"] * 60) +
- data["second"])
- # When the first boss is beaten, start the timer
- # This makes RTA timing useless but IGT is better anyway
- if data["stage"] == self.bosses[0]:
- s.send("starttimer\r\n")
- # Send the split command to livesplit
- print "Sending split at %02i:%02i:%02i" % (data["hour"],
- data["minute"],
- data["second"])
- s.send("setgametime %i\r\n" % sec)
- s.send("split\r\n")
- def parse_savefile(self, filename):
- # Datafile is 39 4-byte ints, parse as such
- with open(filename, 'rb') as f:
- data = struct.unpack(">" + "H" * 39, f.read())
- # Use the information on handle to construct a data dict
- packed_data = {}
- for k, v in self.handle.items():
- packed_data[k] = data[v]
- # Return said dict
- return packed_data
- if __name__ == "__main__":
- s = socket.socket()
- # LiveSplit specific stuff. If you're doing something else with this
- # script, do initial setup here.
- try:
- s.connect(("localhost", 16834))
- print "Connected to LiveSplit"
- except:
- print "Could not connect to LiveSplit. Is it running?"
- # End LiveSplit specific stuff
- # Here we set a hook to fire BokiHandler.on_modified when files
- # in CopyKitty's data dir change.
- i = "C:/Users/Trysdyn/AppData/Local/Apps/2.0/CopyKitty/"
- event_handler = BokiHandler()
- observer = Observer()
- observer.schedule(event_handler, path=i, recursive=False)
- observer.start()
- # Now we check once a second for a ctrl-C to terminate
- try:
- while True:
- time.sleep(1)
- except KeyboardInterrupt:
- observer.stop()
- s.close()
- observer.join()
Advertisement
Add Comment
Please, Sign In to add comment