Initial commit

This commit is contained in:
William Toohey
2017-01-28 14:41:42 +10:00
commit 67f19039fb
10 changed files with 495 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */
var saveAs=saveAs||function(e){"use strict";if(typeof e==="undefined"||typeof navigator!=="undefined"&&/MSIE [1-9]\./.test(navigator.userAgent)){return}var t=e.document,n=function(){return e.URL||e.webkitURL||e},r=t.createElementNS("http://www.w3.org/1999/xhtml","a"),o="download"in r,a=function(e){var t=new MouseEvent("click");e.dispatchEvent(t)},i=/constructor/i.test(e.HTMLElement)||e.safari,f=/CriOS\/[\d]+/.test(navigator.userAgent),u=function(t){(e.setImmediate||e.setTimeout)(function(){throw t},0)},s="application/octet-stream",d=1e3*40,c=function(e){var t=function(){if(typeof e==="string"){n().revokeObjectURL(e)}else{e.remove()}};setTimeout(t,d)},l=function(e,t,n){t=[].concat(t);var r=t.length;while(r--){var o=e["on"+t[r]];if(typeof o==="function"){try{o.call(e,n||e)}catch(a){u(a)}}}},p=function(e){if(/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(e.type)){return new Blob([String.fromCharCode(65279),e],{type:e.type})}return e},v=function(t,u,d){if(!d){t=p(t)}var v=this,w=t.type,m=w===s,y,h=function(){l(v,"writestart progress write writeend".split(" "))},S=function(){if((f||m&&i)&&e.FileReader){var r=new FileReader;r.onloadend=function(){var t=f?r.result:r.result.replace(/^data:[^;]*;/,"data:attachment/file;");var n=e.open(t,"_blank");if(!n)e.location.href=t;t=undefined;v.readyState=v.DONE;h()};r.readAsDataURL(t);v.readyState=v.INIT;return}if(!y){y=n().createObjectURL(t)}if(m){e.location.href=y}else{var o=e.open(y,"_blank");if(!o){e.location.href=y}}v.readyState=v.DONE;h();c(y)};v.readyState=v.INIT;if(o){y=n().createObjectURL(t);setTimeout(function(){r.href=y;r.download=u;a(r);h();c(y);v.readyState=v.DONE});return}S()},w=v.prototype,m=function(e,t,n){return new v(e,t||e.name||"download",n)};if(typeof navigator!=="undefined"&&navigator.msSaveOrOpenBlob){return function(e,t,n){t=t||e.name||"download";if(!n){e=p(e)}return navigator.msSaveOrOpenBlob(e,t)}}w.abort=function(){};w.readyState=w.INIT=0;w.WRITING=1;w.DONE=2;w.error=w.onwritestart=w.onprogress=w.onwrite=w.onabort=w.onerror=w.onwriteend=null;return m}(typeof self!=="undefined"&&self||typeof window!=="undefined"&&window||this.content);if(typeof module!=="undefined"&&module.exports){module.exports.saveAs=saveAs}else if(typeof define!=="undefined"&&define!==null&&define.amd!==null){define("FileSaver.js",function(){return saveAs})}
+156
View File
@@ -0,0 +1,156 @@
dllFile = null;
mods = null;
filename = null;
errorLog = "";
DllPatcher = function(fname, args) {
mods = args;
filename = fname;
loadPatchUI();
};
loadFile = function(file) {
var reader = new FileReader();
reader.onload = function(e) {
dllFile = new Uint8Array(e.target.result);
if(validatePatches()) {
$("#success").removeClass("hidden");
$("#success").html("DLL loaded successfully!");
} else {
$("#success").addClass("hidden");
}
$('#error').html(errorLog);
updatePatchUI();
};
reader.readAsArrayBuffer(file);
};
saveDll = function() {
if(!dllFile || !mods || !filename)
return;
var fname = filename;
for(var i = 0; i < mods.length; i++) {
id = mods[i].shortname;
var enabled = document.getElementById(id).checked;
replaceAll(dllFile, mods[i].patches, enabled);
if(enabled) {
fname += '-' + id;
}
}
fname += '.dll';
var blob = new Blob([dllFile], {type: "application/octet-stream"});
saveAs(blob, fname);
}
loadPatchUI = function() {
var patchDiv = $('#patches');
for(var i = 0; i < mods.length; i++) {
var id = mods[i].shortname;
var name = mods[i].name;
patchDiv.append('<div class="patch"><input type="checkbox" id="' + id + '"><label for="' + id + '">' + name + '</label></div>');
}
}
updatePatchUI = function() {
for(var i = 0; i < mods.length; i++) {
var id = mods[i].shortname;
var elem = document.getElementById(id);
elem.checked = checkPatchBytes(mods[i].patches) == "on";
}
}
buildError = function(patchName, message) {
var msg = '"' + patchName + '" ' + message;
console.log(msg);
errorLog += msg + '<br/>';
}
validatePatches = function() {
errorLog = "";
success = true;
for(var i = 0; i < mods.length; i++) {
var patch = mods[i];
var status = checkPatchBytes(patch.patches);
if(status == "on") {
console.log('"' + patch.name + '"', "is enabled!");
} else if(status == "off") {
console.log('"' + patch.name + '"', "is disabled!");
} else {
success = false;
buildError(patch.name, "is neither on nor off! Have you got the right dll?");
}
}
return success;
}
checkPatchBytes = function(patches) {
var patchStatus = "";
for(var i = 0; i < patches.length; i++) {
patch = patches[i];
if(bytesMatch(dllFile, patch.offset, patch.off)) {
if(patchStatus == "") {
patchStatus = "off";
} else if(patchStatus != "off"){
return "on/off mismatch within patch";
}
} else if(bytesMatch(dllFile, patch.offset, patch.on)) {
if(patchStatus == "") {
patchStatus = "on";
} else if(patchStatus != "on"){
return "on/off mismatch within patch";
}
} else {
return "patch neither on nor off";
}
}
return patchStatus;
}
bytesMatch = function(buffer, offset, bytes) {
for(var i = 0; i < bytes.length; i++) {
if(buffer[offset+i] != bytes[i])
return false;
}
return true;
};
replaceAll = function(buffer, patches, featureOn) {
for(var i = 0; i < patches.length; i++) {
replace(buffer, patches[i].offset, featureOn? patches[i].on : patches[i].off);
}
}
replace = function(buffer, offset, bytes) {
for(var i = 0; i < bytes.length; i++) {
buffer[offset+i] = bytes[i];
}
}
whichBytesMatch = function(buffer, offset, bytesArray) {
for(var i = 0; i < bytesArray.length; i++) {
if(bytesMatch(buffer, offset, bytesArray[i]))
return i;
}
return -1;
}
$( document ).ready(function() {
$('html').on('drag dragstart dragend dragover dragenter dragleave drop', function(e) {
e.preventDefault();
e.stopPropagation();
})
.on('drop', function(e) {
var files = e.originalEvent.dataTransfer.files;
if(files && files.length > 0)
loadFile(files[0]);
});
$('#file').on('change', function(e) {
if(this.files && this.files.length > 0)
loadFile(this.files[0]);
});
});