Last active
August 31, 2019 03:54
-
-
Save Californ1a/9dc692dcb59e33e7b3ac4b8770fe206f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Distance Autosplitter script - Provides autostart/split/reset and load removal | |
Created by Brionac, Californ1a, Seekr, and TntMatthew | |
Thanks to ClownFiesta for the base script to read from an output log: | |
https://raw.githubusercontent.com/ClownFiesta/AutoSplitters/master/LiveSplit.SlayTheSpire.asl | |
*/ | |
state("Distance") | |
{ | |
} | |
startup | |
{ | |
settings.Add("combine_cut", true, "Combine cutscenes and their adjacent levels into one split"); | |
settings.CurrentDefaultParent = "combine_cut"; | |
settings.Add("combine_inst", true, "Instantiation + Cataclysm"); | |
settings.Add("combine_long", true, "Long Ago + Forgotten Utopia"); | |
settings.Add("combine_mob", true, "Mobilization + Resonance"); | |
settings.Add("combine_col", true, "Terminus + Collapse"); | |
} | |
init | |
{ | |
//Get the path for the logs | |
vars.stsLogPath = System.IO.Directory.GetParent(modules.First().FileName).FullName + "\\speedrun_data.txt"; | |
//Open the logs and set the position to the end of the file | |
vars.reader = new StreamReader(new FileStream(vars.stsLogPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)); | |
vars.reader.BaseStream.Seek(0, SeekOrigin.End); | |
vars.lastPointerPosition = vars.reader.BaseStream.Position; | |
//Set the command to "UPDATE" | |
vars.command = "UPDATE"; | |
} | |
update | |
{ | |
if (vars.reader.BaseStream.Length == vars.lastPointerPosition){ //If the logs haven't changed, skip the rest of the code (update, reset, split, start, etc.). We place it first to lessen the load on the computer | |
return false; | |
} else if (vars.reader.BaseStream.Length < vars.lastPointerPosition){ //If the logs have been reset, then place the pointer at the end and update vars.lastPointerPosition and skip the rest of the code. | |
vars.reader.BaseStream.Seek(0, SeekOrigin.End); | |
vars.lastPointerPosition = vars.reader.BaseStream.Position; | |
return false; | |
} | |
string line = ""; | |
//string prevLine = ""; | |
while((line = vars.reader.ReadLine()) != null){ //Read the log until its end | |
//Updates vars.lastPointerPosition to its new position. | |
vars.lastPointerPosition = vars.reader.BaseStream.Position; | |
//print(line); | |
//Changes the value of vars.command depending on the content of line and returns true if a command needs to be issued. | |
if (line.Contains("SpeedrunStart")){ | |
vars.command = "START"; | |
return true; | |
} else if (line.Contains("ModeFinished")) { | |
if ((line.Contains("Instantiation") && settings["combine_inst"] == true) || (line.Contains("Long Ago") && settings["combine_long"] == true) || (line.Contains("Mobilization") && settings["combine_mob"] == true) || (line.Contains("Terminus") && settings["combine_col"] == true)) { | |
return true; | |
} else { | |
vars.command = "SPLIT"; | |
return true; | |
} | |
} else if (line.Contains("LoadStart")) { | |
if (line.Contains("MainMenu")) { | |
vars.command = "RESET"; | |
return true; | |
} else { | |
vars.command = "ISLOADING"; | |
return true; | |
} | |
} else if (line.Contains("SpeedrunEnd") && line.Contains("DNF")){ | |
vars.command = "RESET"; | |
return true; | |
} | |
//prevLine = line; | |
} | |
} | |
reset | |
{ | |
if (vars.command == "RESET"){ | |
vars.command = "UPDATE"; | |
return true; | |
} | |
} | |
split | |
{ | |
if (vars.command == "SPLIT"){ | |
vars.command = "UPDATE"; | |
return true; | |
} | |
} | |
start | |
{ | |
if (vars.command == "START"){ | |
vars.command = "UPDATE"; | |
return true; | |
} | |
} | |
exit | |
{ | |
// Resets the timer if the game closes (either from a bug or manually) | |
new TimerModel() { CurrentState = timer }.Reset(); | |
vars.reader.Close(); | |
vars.lastPointerPosition = 0; | |
} | |
shutdown | |
{ | |
// Closing the reader (Only useful when you close LiveSplit before closing SlayTheSpire) | |
vars.reader.Close(); | |
} | |
isLoading | |
{ | |
if (vars.command == "ISLOADING"){ | |
vars.command = "UPDATE"; | |
return true; | |
} else { | |
return false; | |
} | |
} | |
gameTime | |
{ | |
// blank | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment