HLD save converter

by zelnoth

HTML

<body>
  <p>To use you need a HLD savefile of your own and a savefile you want converted.</p>
  <p>To find your savefile go to C:\Users\YOURUSERNAME\AppData\Local\HyperLightDrifter  (on windows)</p>
  <p>(swap C with relevant disk and YOURUSERNAME with your username on the pc)</p>
  <textarea id="your" placeholder="Your save here" rows="4" cols="50"></textarea>
  <textarea id="other" placeholder="Other save here" rows="4" cols="50"></textarea>
  <br />
  <textarea id="fileNo" placeholder="Save file number (0-3)" rows="1" cols="50"></textarea>
  <br />
  <button id="btn">convert</button>
  <br />
  <textarea id="new" placeholder="Your new save end up here after converting, copy text into a savefile or click    download" rows="10" cols="103"></textarea>
  <br />
  <button id="download">download file</button>
</body>

JavaScript

$("#btn").click(function() {
  var your = atob($("#your").val());
  var other = atob($("#other").val());
  var yourPcInfo = your.substr(0, getInfoIndex(your));
  var newSave = btoa(yourPcInfo + other.substr(getInfoIndex(other), other.length));
  $("#new").val(newSave);
});

//note instead of doing this, I could probably just index "{ "mapMod", but I'm not 100% sure that is consistent 
function getInfoIndex(savefile){
	var i = savefile.length;
  while(i--){
  	if(savefile[i] == "{"){
    	break;
    }
	}
  return i;
}

$("#download").click(function(){
  var saveFile = $("#new").val();
  var textFileAsBlob = new Blob([saveFile], {type:'text/plain'});
  var fileNameToSaveAs = "HyperLight_RecordOfTheDrifter_" + $("#fileNo").val() + ".sav";

  var downloadLink = document.createElement("a");
  downloadLink.download = fileNameToSaveAs;
  downloadLink.innerHTML = "Download File";
  if (window.webkitURL != null)
  {
    // Chrome allows the link to be clicked
    // without actually adding it to the DOM.
    downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
  }
  else
  {
    // Firefox requires the link to be added to the DOM
    // before it can be clicked.
    downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
    downloadLink.onclick = destroyClickedElement;
    downloadLink.style.display = "none";
    document.body.appendChild(downloadLink);
  }

  downloadLink.click();
});