Add ability to automatically detect selected DLL (#17)

This commit is contained in:
Isaac Drew
2018-06-23 11:59:16 +08:00
committed by Will
parent fbf138e13e
commit 5e920f031e
5 changed files with 591 additions and 438 deletions
+181 -38
View File
@@ -31,14 +31,14 @@ StandardPatch.prototype.createUI = function(parent) {
}; };
StandardPatch.prototype.updateUI = function(file) { StandardPatch.prototype.updateUI = function(file) {
this.checkbox.checked = this.checkPatchBytes(file) == "on"; this.checkbox.checked = this.checkPatchBytes(file) === "on";
}; };
StandardPatch.prototype.validatePatch = function(file) { StandardPatch.prototype.validatePatch = function(file) {
var status = this.checkPatchBytes(file); var status = this.checkPatchBytes(file);
if(status == "on") { if(status === "on") {
console.log('"' + this.name + '"', "is enabled!"); console.log('"' + this.name + '"', "is enabled!");
} else if(status == "off") { } else if(status === "off") {
console.log('"' + this.name + '"', "is disabled!"); console.log('"' + this.name + '"', "is disabled!");
} else { } else {
return '"' + this.name + '" is neither on nor off! Have you got the right dll?'; return '"' + this.name + '" is neither on nor off! Have you got the right dll?';
@@ -61,13 +61,13 @@ StandardPatch.prototype.checkPatchBytes = function(file) {
for(var i = 0; i < this.patches.length; i++) { for(var i = 0; i < this.patches.length; i++) {
var patch = this.patches[i]; var patch = this.patches[i];
if(bytesMatch(file, patch.offset, patch.off)) { if(bytesMatch(file, patch.offset, patch.off)) {
if(patchStatus == "") { if(patchStatus === "") {
patchStatus = "off"; patchStatus = "off";
} else if(patchStatus != "off"){ } else if(patchStatus != "off"){
return "on/off mismatch within patch"; return "on/off mismatch within patch";
} }
} else if(bytesMatch(file, patch.offset, patch.on)) { } else if(bytesMatch(file, patch.offset, patch.on)) {
if(patchStatus == "") { if(patchStatus === "") {
patchStatus = "on"; patchStatus = "on";
} else if(patchStatus != "on"){ } else if(patchStatus != "on"){
return "on/off mismatch within patch"; return "on/off mismatch within patch";
@@ -148,46 +148,186 @@ UnionPatch.prototype.getSelected = function() {
return null; return null;
} }
var DllPatcherContainer = function (patchers) {
this.patchers = patchers;
this.createUI();
};
DllPatcherContainer.prototype.getSupportedDLLs = function () {
var dlls = [];
for (var i = 0; i < this.patchers.length; i++) {
var name = this.patchers[i].filename + ".dll";
if (dlls.indexOf(name) === -1) {
dlls.push(name);
}
}
return dlls;
};
DllPatcherContainer.prototype.getSupportedVersions = function () {
var descriptions = [];
for (var i = 0; i < this.patchers.length; i++) {
if ($.type(this.patchers[i].description) === "string") {
descriptions.push(this.patchers[i].description);
}
}
return descriptions;
};
DllPatcherContainer.prototype.createUI = function () {
var self = this;
var container = $("<div>", {"class": "patchContainer"});
var header = this.getSupportedDLLs().join(", ");
container.html("<h3>" + header + "</h3>");
var supportedDlls = $("<ul>");
var versions = this.getSupportedVersions();
for (var i = 0; i < versions.length; i++) {
$("<li>").text(versions[i]).appendTo(supportedDlls);
}
$("html").on("dragover dragenter", function () {
container.addClass("dragover");
return true;
})
.on("dragleave dragend drop", function () {
container.removeClass("dragover");
return true;
})
.on("dragover dragenter dragleave dragend drop", function (e) {
e.preventDefault();
});
container.on("drop", function (e) {
var files = e.originalEvent.dataTransfer.files;
if (files && files.length > 0)
self.loadFile(files[0]);
});
this.fileInput = $("<input>",
{
"class": "fileInput",
"id": "any-file",
"type": "file",
});
var label = $("<label>", {"class": "fileLabel", "for": "any-file"});
label.html("<strong>Choose a file</strong> or drag and drop.");
this.fileInput.on("change", function (e) {
if (this.files && this.files.length > 0)
self.loadFile(this.files[0]);
});
this.successDiv = $("<div>", {"class": "success"});
this.errorDiv = $("<div>", {"class": "error"});
container.append(this.fileInput);
container.append(label);
if (versions.length > 0) {
$("<h4>Supported Versions</h4>").appendTo(container);
}
container.append(supportedDlls);
container.append(this.successDiv);
container.append(this.errorDiv);
$("body").append(container);
};
DllPatcherContainer.prototype.loadFile = function (file) {
var reader = new FileReader();
var self = this;
reader.onload = function (e) {
var found = false;
// clear logs
self.errorDiv.empty();
self.successDiv.empty();
for (var i = 0; i < self.patchers.length; i++) {
var patcher = self.patchers[i];
// remove the previous UI to clear the page
patcher.destroyUI();
// patcher UI elements have to exist to load the file
patcher.createUI();
patcher.container.hide();
patcher.loadBuffer(e.target.result);
if (patcher.validatePatches()) {
found = true;
patcher.loadPatchUI();
patcher.updatePatchUI();
patcher.container.show();
var successStr = patcher.filename + ".dll"
if ($.type(this.description) === "string") {
successStr += "(" + patcher.description + ")";
}
self.successDiv.html(successStr + " loaded successfully!");
}
}
if (!found) {
self.errorDiv.html("No patches found matching the given DLL.");
}
};
reader.readAsArrayBuffer(file);
};
var DllPatcher = function(fname, args, description) { var DllPatcher = function(fname, args, description) {
this.mods = []; this.mods = [];
for(var i = 0; i < args.length; i++) { for(var i = 0; i < args.length; i++) {
var mod = args[i]; var mod = args[i];
if(mod.type) { if(mod.type) {
if(mod.type == "union") { if(mod.type === "union") {
this.mods.push(new UnionPatch(mod)); this.mods.push(new UnionPatch(mod));
} }
} else { // standard patch } else { // standard patch
this.mods.push(new StandardPatch(mod)); this.mods.push(new StandardPatch(mod));
} }
} }
this.filename = fname; this.filename = fname;
this.description = description; this.description = description;
this.multiPatcher = true;
if (!this.description) {
// old style patcher, use the old method to generate the UI
this.multiPatcher = false;
this.createUI(); this.createUI();
this.loadPatchUI(); this.loadPatchUI();
}
}; };
DllPatcher.prototype.createUI = function() { DllPatcher.prototype.createUI = function() {
var self = this; var self = this;
var container = $("<div>", {"class": "patchContainer"}); this.container = $("<div>", {"class": "patchContainer"});
var header = this.filename + '.dll'; var header = this.filename + '.dll';
if(this.description) { if($.type(this.description) === "string") {
header += ' (' + this.description + ')'; header += ' (' + this.description + ')';
} }
container.html('<h3>' + header + '</h3>'); this.container.html('<h3>' + header + '</h3>');
this.successDiv = $("<div>", {"class": "success"});
this.errorDiv = $("<div>", {"class": "error"});
this.patchDiv = $("<div>", {"class": "patches"});
var saveButton = $("<button disabled>");
saveButton.text('Load DLL First');
saveButton.on('click', this.saveDll.bind(this));
this.saveButton = saveButton;
if (!this.multiPatcher) {
$('html').on('dragover dragenter', function() { $('html').on('dragover dragenter', function() {
container.addClass('dragover'); self.container.addClass('dragover');
return true; return true;
}) })
.on('dragleave dragend drop', function() { .on('dragleave dragend drop', function() {
container.removeClass('dragover'); self.container.removeClass('dragover');
return true; return true;
}) })
.on('dragover dragenter dragleave dragend drop', function(e) { .on('dragover dragenter dragleave dragend drop', function(e) {
e.preventDefault(); e.preventDefault();
}); });
container.on('drop', function(e) { this.container.on('drop', function(e) {
var files = e.originalEvent.dataTransfer.files; var files = e.originalEvent.dataTransfer.files;
if(files && files.length > 0) if(files && files.length > 0)
self.loadFile(files[0]); self.loadFile(files[0]);
@@ -205,22 +345,34 @@ DllPatcher.prototype.createUI = function() {
self.loadFile(this.files[0]); self.loadFile(this.files[0]);
}); });
this.successDiv = $("<div>", {"class": "success"}); this.container.append(this.fileInput);
this.errorDiv = $("<div>", {"class": "error"}); this.container.append(label);
this.patchDiv = $("<div>", {"class": "patches"}); }
var saveButton = $("<button disabled>"); this.container.append(this.successDiv);
saveButton.text('Load DLL First'); this.container.append(this.errorDiv);
saveButton.on('click', this.saveDll.bind(this)); this.container.append(this.patchDiv);
this.saveButton = saveButton; this.container.append(saveButton);
$("body").append(this.container);
}
container.append(this.fileInput); DllPatcher.prototype.destroyUI = function () {
container.append(label); if (this.hasOwnProperty("container"))
container.append(this.successDiv); this.container.remove();
container.append(this.errorDiv); };
container.append(this.patchDiv);
container.append(saveButton); DllPatcher.prototype.loadBuffer = function(buffer) {
$('body').append(container); this.dllFile = new Uint8Array(buffer);
if(this.validatePatches()) {
this.successDiv.removeClass("hidden");
this.successDiv.html("DLL loaded successfully!");
} else {
this.successDiv.addClass("hidden");
}
// Update save button regardless
this.saveButton.prop('disabled', false);
this.saveButton.text('Save DLL');
this.errorDiv.html(this.errorLog);
} }
DllPatcher.prototype.loadFile = function(file) { DllPatcher.prototype.loadFile = function(file) {
@@ -228,18 +380,8 @@ DllPatcher.prototype.loadFile = function(file) {
var self = this; var self = this;
reader.onload = function(e) { reader.onload = function(e) {
self.dllFile = new Uint8Array(e.target.result); self.loadBuffer(e.target.result);
if(self.validatePatches()) { this.updatePatchUI();
self.successDiv.removeClass("hidden");
self.successDiv.html("DLL loaded successfully!");
} else {
self.successDiv.addClass("hidden");
}
// Update save button regardless
self.saveButton.prop('disabled', false);
self.saveButton.text('Save DLL');
self.errorDiv.html(self.errorLog);
self.updatePatchUI();
}; };
reader.readAsArrayBuffer(file); reader.readAsArrayBuffer(file);
@@ -307,5 +449,6 @@ var whichBytesMatch = function(buffer, offset, bytesArray) {
} }
window.DllPatcher = DllPatcher; window.DllPatcher = DllPatcher;
window.DllPatcherContainer = DllPatcherContainer;
})(window, document); })(window, document);
+4 -1
View File
@@ -10,6 +10,7 @@
<script type="text/javascript" src="js/dllpatcher.js"></script> <script type="text/javascript" src="js/dllpatcher.js"></script>
<script type="text/javascript"> <script type="text/javascript">
window.addEventListener("load", function() { window.addEventListener("load", function() {
new DllPatcherContainer([
new DllPatcher("jubeat", [ new DllPatcher("jubeat", [
{ {
name : "Disable tutorial", name : "Disable tutorial",
@@ -19,12 +20,14 @@
name : "SELECT MUSIC timer lock", name : "SELECT MUSIC timer lock",
patches : [{offset : 0x16E64D, off : [0x75], on : [0xEB]}] patches : [{offset : 0x16E64D, off : [0x75], on : [0xEB]}]
}, },
]); ], true),
new DllPatcher("music_db", [ new DllPatcher("music_db", [
{ {
name : "Unlock all songs", name : "Unlock all songs",
patches : [{offset : 0x266D, off: [0x02], on : [0x1f]}] patches : [{offset : 0x266D, off: [0x02], on : [0x1f]}]
}, },
], true)
]); ]);
}); });
</script> </script>
+4 -1
View File
@@ -10,6 +10,7 @@
<script type="text/javascript" src="js/dllpatcher.js"></script> <script type="text/javascript" src="js/dllpatcher.js"></script>
<script type="text/javascript"> <script type="text/javascript">
window.addEventListener("load", function() { window.addEventListener("load", function() {
new DllPatcherContainer([
new DllPatcher("jubeat", [ new DllPatcher("jubeat", [
{ {
name : "Disable tutorial", name : "Disable tutorial",
@@ -19,12 +20,14 @@
name : "SELECT MUSIC timer lock", name : "SELECT MUSIC timer lock",
patches : [{offset : 0x80576, off : [0x75], on : [0xEB]}] patches : [{offset : 0x80576, off : [0x75], on : [0xEB]}]
}, },
]); ], true),
new DllPatcher("music_db", [ new DllPatcher("music_db", [
{ {
name : "Unlock all songs", name : "Unlock all songs",
patches : [{offset : 0x17DF, off: [0x74, 0x09], on : [0x90, 0x90]}] patches : [{offset : 0x17DF, off: [0x74, 0x09], on : [0x90, 0x90]}]
}, },
], true)
]); ]);
}); });
</script> </script>
+6 -5
View File
@@ -10,6 +10,7 @@
<script type='text/javascript' src='js/dllpatcher.js'></script> <script type='text/javascript' src='js/dllpatcher.js'></script>
<script type='text/javascript'> <script type='text/javascript'>
window.addEventListener('load', function () { window.addEventListener('load', function () {
new DllPatcherContainer([
new DllPatcher('soundvoltex', [ new DllPatcher('soundvoltex', [
{ {
name: 'All songs/difficulties unlocked', name: 'All songs/difficulties unlocked',
@@ -45,8 +46,7 @@
on: [0xB8, 0x01, 0x00, 0x00, 0x00, 0x89, 0x83, 0x64, 0x10, 0x00, 0x00, 0x90, 0x56, 0x57, 0x90, 0x90] on: [0xB8, 0x01, 0x00, 0x00, 0x00, 0x89, 0x83, 0x64, 0x10, 0x00, 0x00, 0x90, 0x56, 0x57, 0x90, 0x90]
}] }]
}, },
], "2018-01-16"); ], "2018-01-16"),
new DllPatcher('soundvoltex', [ new DllPatcher('soundvoltex', [
{ {
// Credit to kacklappen23 // Credit to kacklappen23
@@ -101,7 +101,7 @@
tooltip: 'Useful to play with Omega Dimension Ex-Track', tooltip: 'Useful to play with Omega Dimension Ex-Track',
patches: [{offset: 0x7749B, off: [0x8B, 0x43, 0x60, 0x85, 0xC0, 0x74, 0x04], on: [0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90]}] patches: [{offset: 0x7749B, off: [0x8B, 0x43, 0x60, 0x85, 0xC0, 0x74, 0x04], on: [0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90]}]
} }
], "2018-01-16 with Enhanced Continue"); ], "2018-01-16 with Enhanced Continue"),
// all patches ported to IV by Zelminar unless specified otherwise // all patches ported to IV by Zelminar unless specified otherwise
// all original patches created by DJH unless specified otherwise // all original patches created by DJH unless specified otherwise
@@ -195,8 +195,9 @@
tooltip: 'Useful to play with Omega Dimension Ex-Track', tooltip: 'Useful to play with Omega Dimension Ex-Track',
patches: [{offset: 0x75C1B, off: [0x8B, 0x43, 0x60, 0x85, 0xC0, 0x74, 0x04], on: [0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90]}] patches: [{offset: 0x75C1B, off: [0x8B, 0x43, 0x60, 0x85, 0xC0, 0x74, 0x04], on: [0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90]}]
}, },
], "2017-11-28"); ], "2017-11-28")
}) ]);
});
</script> </script>
</head> </head>
<body> <body>
+5 -2
View File
@@ -10,6 +10,7 @@
<script type="text/javascript" src="js/dllpatcher.js"></script> <script type="text/javascript" src="js/dllpatcher.js"></script>
<script type="text/javascript"> <script type="text/javascript">
window.addEventListener("load", function() { window.addEventListener("load", function() {
new DllPatcherContainer([
new DllPatcher("bm2dx", [ new DllPatcher("bm2dx", [
{ {
name : "Timer Freeze", name : "Timer Freeze",
@@ -94,7 +95,8 @@
tooltip : "Hold VEFX and Effect during a song to restart", tooltip : "Hold VEFX and Effect during a song to restart",
patches : [{offset : 0x4e284, off: [0x8A, 0xC3], on : [0xB0, 0x01]}] patches : [{offset : 0x4e284, off: [0x8A, 0xC3], on : [0xB0, 0x01]}]
}, },
], "stock"); ], "stock"),
new DllPatcher("bm2dx_omni", [ new DllPatcher("bm2dx_omni", [
{ {
name : "Timer Freeze", name : "Timer Freeze",
@@ -169,7 +171,8 @@
tooltip : "Hold VEFX and Effect during a song to restart", tooltip : "Hold VEFX and Effect during a song to restart",
patches : [{offset : 0x4e154, off: [0x8A, 0xC3], on : [0xB0, 0x01]}] patches : [{offset : 0x4e154, off: [0x8A, 0xC3], on : [0xB0, 0x01]}]
}, },
], "omnimix"); ], "omnimix")
]);
}); });
</script> </script>
</head> </head>