From b27039dbe6335d4336daaeda22adad6ac178f7cd Mon Sep 17 00:00:00 2001 From: Will Toohey Date: Sun, 17 Nov 2019 20:58:28 +1000 Subject: [PATCH] Refactor: Support exe, sane arg order --- README.md | 4 +- ballerz.html | 14 +- beatstream1.html | 8 +- beatstream2.html | 10 +- copula.html | 6 +- ddr2014.html | 2 +- ddra.html | 18 +- gfdmv5.html | 20 +- gfdmv6.html | 16 +- gfdmv7.html | 20 +- gitadoraexchain.html | 6 +- gitadoramatixx.html | 10 +- gitadoraod.html | 2 +- gitadoratb.html | 2 +- gitadoratbre.html | 6 +- js/dllpatcher.js | 787 +++++++++++++++++----------------- jubeatclan.html | 15 +- jubeatprop.html | 10 +- jubeatqubell.html | 14 +- museca1.html | 16 +- museca2.html | 10 +- pendual.html | 10 +- popn22lapistoria.html | 2 +- popn23eclale.html | 2 +- popn24usaneko.html | 2 +- popn25peace.html | 6 +- reflecbeat-groovin-upper.html | 6 +- rootage.html | 22 +- sdvx3-s2.html | 4 +- sdvx4.html | 56 +-- sinobuz.html | 6 +- spada.html | 10 +- tricoro.html | 22 +- 33 files changed, 567 insertions(+), 577 deletions(-) diff --git a/README.md b/README.md index c53fa40..ec58ec2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # BemaniPatcher -A tool to easily apply known hex edits to any DLL, with examples for Bemani games. +A tool to easily apply known hex edits to any binary, with examples for Bemani games. Should work on most modern browsers. -Live version hosted [on my website](http://mon.im/bemanipatcher/). \ No newline at end of file +Live version hosted [on my website](https://mon.im/bemanipatcher/). \ No newline at end of file diff --git a/ballerz.html b/ballerz.html index 93ded3d..f6680e4 100644 --- a/ballerz.html +++ b/ballerz.html @@ -10,8 +10,8 @@ diff --git a/beatstream1.html b/beatstream1.html index 7175b1e..0913aa2 100644 --- a/beatstream1.html +++ b/beatstream1.html @@ -10,8 +10,8 @@ diff --git a/beatstream2.html b/beatstream2.html index 546ed28..e1cda56 100644 --- a/beatstream2.html +++ b/beatstream2.html @@ -10,8 +10,8 @@ diff --git a/copula.html b/copula.html index 5e3ad6b..164012d 100644 --- a/copula.html +++ b/copula.html @@ -10,8 +10,8 @@ diff --git a/ddr2014.html b/ddr2014.html index 1db4613..19b1b92 100644 --- a/ddr2014.html +++ b/ddr2014.html @@ -10,7 +10,7 @@ diff --git a/gfdmv5.html b/gfdmv5.html index 9db88d9..f9165f6 100644 --- a/gfdmv5.html +++ b/gfdmv5.html @@ -10,16 +10,15 @@ diff --git a/gfdmv6.html b/gfdmv6.html index 1bf648b..8650f72 100644 --- a/gfdmv6.html +++ b/gfdmv6.html @@ -10,16 +10,15 @@ diff --git a/gfdmv7.html b/gfdmv7.html index a688455..9d170d7 100644 --- a/gfdmv7.html +++ b/gfdmv7.html @@ -10,16 +10,15 @@ diff --git a/gitadoraexchain.html b/gitadoraexchain.html index 9621320..12d82f3 100644 --- a/gitadoraexchain.html +++ b/gitadoraexchain.html @@ -10,14 +10,12 @@ diff --git a/gitadoramatixx.html b/gitadoramatixx.html index ae401e9..18c6f2d 100644 --- a/gitadoramatixx.html +++ b/gitadoramatixx.html @@ -10,8 +10,7 @@ diff --git a/gitadoraod.html b/gitadoraod.html index 556be69..bb307f1 100644 --- a/gitadoraod.html +++ b/gitadoraod.html @@ -10,7 +10,7 @@ diff --git a/js/dllpatcher.js b/js/dllpatcher.js index a1d83d1..29caa94 100644 --- a/js/dllpatcher.js +++ b/js/dllpatcher.js @@ -2,493 +2,496 @@ "use strict"; // form labels often need unique IDs - this can be used to generate some -window.DllPatcher_uniqueid = 0; +window.Patcher_uniqueid = 0; var createID = function() { - window.DllPatcher_uniqueid++; - return "dllpatch_" + window.DllPatcher_uniqueid; -} - -// Each unique kind of patch should have createUI, validatePatch, applyPatch, -// updateUI - -var StandardPatch = function(options) { - this.name = options.name; - this.patches = options.patches; - this.tooltip = options.tooltip; -}; - -StandardPatch.prototype.createUI = function(parent) { - var id = createID(); - var label = this.name; - var patch = $('
', {'class' : 'patch'}); - this.checkbox = $('')[0]; - patch.append(this.checkbox); - patch.append(''); - if(this.tooltip) { - patch.append('
' + this.tooltip + '
'); - } - parent.append(patch); -}; - -StandardPatch.prototype.updateUI = function(file) { - this.checkbox.checked = this.checkPatchBytes(file) === "on"; + window.Patcher_uniqueid++; + return "dllpatch_" + window.Patcher_uniqueid; }; -StandardPatch.prototype.validatePatch = function(file) { - var status = this.checkPatchBytes(file); - if(status === "on") { - console.log('"' + this.name + '"', "is enabled!"); - } else if(status === "off") { - console.log('"' + this.name + '"', "is disabled!"); - } else { - return '"' + this.name + '" is neither on nor off! Have you got the right dll?'; +var bytesMatch = function(buffer, offset, bytes) { + for(var i = 0; i < bytes.length; i++) { + if(buffer[offset+i] != bytes[i]) + return false; } + return true; }; -StandardPatch.prototype.applyPatch = function(file) { - this.replaceAll(file, this.checkbox.checked); -}; - -StandardPatch.prototype.replaceAll = function(file, featureOn) { - for(var i = 0; i < this.patches.length; i++) { - replace(file, this.patches[i].offset, - featureOn? this.patches[i].on : this.patches[i].off); +var replace = function(buffer, offset, bytes) { + for(var i = 0; i < bytes.length; i++) { + buffer[offset+i] = bytes[i]; } } -StandardPatch.prototype.checkPatchBytes = function(file) { - var patchStatus = ""; - for(var i = 0; i < this.patches.length; i++) { - var patch = this.patches[i]; - if(bytesMatch(file, patch.offset, patch.off)) { - if(patchStatus === "") { - patchStatus = "off"; - } else if(patchStatus != "off"){ - return "on/off mismatch within patch"; - } - } else if(bytesMatch(file, 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"; - } +var whichBytesMatch = function(buffer, offset, bytesArray) { + for(var i = 0; i < bytesArray.length; i++) { + if(bytesMatch(buffer, offset, bytesArray[i])) + return i; } - return patchStatus; + return -1; } // Each unique kind of patch should have createUI, validatePatch, applyPatch, // updateUI -// The DEFAULT state is always the 1st element in the patches array -var UnionPatch = function(options) { - this.name = options.name; - this.offset = options.offset; - this.patches = options.patches; -}; - -UnionPatch.prototype.createUI = function(parent) { - this.radios = []; - var radio_id = createID(); +class StandardPatch { + constructor(options) { + this.name = options.name; + this.patches = options.patches; + this.tooltip = options.tooltip; + } - var container = $("
", {"class": "patch-union"}); - container.append('' + this.name + ':'); - for(var i = 0; i < this.patches.length; i++) { - var patch = this.patches[i]; + createUI(parent) { var id = createID(); - var label = patch.name; - var patchDiv = $('
', {'class' : 'patch'}); - var radio = $('')[0]; - this.radios.push(radio); - - patchDiv.append(radio); - patchDiv.append(''); - if(patch.tooltip) { - patchDiv.append('
' + patch.tooltip + '
'); + var label = this.name; + var patch = $('
', {'class' : 'patch'}); + this.checkbox = $('')[0]; + patch.append(this.checkbox); + patch.append(''); + if(this.tooltip) { + patch.append('
' + this.tooltip + '
'); } - container.append(patchDiv); + parent.append(patch); } - parent.append(container); -}; -UnionPatch.prototype.updateUI = function(file) { - for(var i = 0; i < this.patches.length; i++) { - if(bytesMatch(file, this.offset, this.patches[i].patch)) { - this.radios[i].checked = true; - return; - } + updateUI(file) { + this.checkbox.checked = this.checkPatchBytes(file) === "on"; } - // Default fallback - this.radios[0].checked = true; -}; -UnionPatch.prototype.validatePatch = function(file) { - for(var i = 0; i < this.patches.length; i++) { - if(bytesMatch(file, this.offset, this.patches[i].patch)) { - console.log(this.name, "has", this.patches[i].name, "enabled"); - return; + validatePatch(file) { + var status = this.checkPatchBytes(file); + if(status === "on") { + console.log('"' + this.name + '"', "is enabled!"); + } else if(status === "off") { + console.log('"' + this.name + '"', "is disabled!"); + } else { + return '"' + this.name + '" is neither on nor off! Have you got the right dll?'; } } - return '"' + this.name + '" doesn\'t have a valid patch! Have you got the right dll?'; -}; -UnionPatch.prototype.applyPatch = function(file) { - var patch = this.getSelected(); - replace(file, this.offset, patch.patch); -}; + applyPatch(file) { + this.replaceAll(file, this.checkbox.checked); + } + + replaceAll(file, featureOn) { + for(var i = 0; i < this.patches.length; i++) { + replace(file, this.patches[i].offset, + featureOn? this.patches[i].on : this.patches[i].off); + } + } -UnionPatch.prototype.getSelected = function() { - for(var i = 0; i < this.patches.length; i++) { - if(this.radios[i].checked) { - return this.patches[i]; + checkPatchBytes(file) { + var patchStatus = ""; + for(var i = 0; i < this.patches.length; i++) { + var patch = this.patches[i]; + if(bytesMatch(file, patch.offset, patch.off)) { + if(patchStatus === "") { + patchStatus = "off"; + } else if(patchStatus != "off"){ + return "on/off mismatch within patch"; + } + } else if(bytesMatch(file, 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; } - return null; } -var DllPatcherContainer = function (patchers) { - this.patchers = patchers; - this.createUI(); -}; +// Each unique kind of patch should have createUI, validatePatch, applyPatch, +// updateUI -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); - } +// The DEFAULT state is always the 1st element in the patches array +class UnionPatch { + constructor(options) { + this.name = options.name; + this.offset = options.offset; + this.patches = options.patches; } - 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); + createUI(parent) { + this.radios = []; + var radio_id = createID(); + + var container = $("
", {"class": "patch-union"}); + container.append('' + this.name + ':'); + for(var i = 0; i < this.patches.length; i++) { + var patch = this.patches[i]; + var id = createID(); + var label = patch.name; + var patchDiv = $('
', {'class' : 'patch'}); + var radio = $('')[0]; + this.radios.push(radio); + + patchDiv.append(radio); + patchDiv.append(''); + if(patch.tooltip) { + patchDiv.append('
' + patch.tooltip + '
'); + } + container.append(patchDiv); } + parent.append(container); } - return descriptions; -}; -DllPatcherContainer.prototype.createUI = function () { - var self = this; - var container = $("
", {"class": "patchContainer"}); - var header = this.getSupportedDLLs().join(", "); - container.html("

" + header + "

"); - - var supportedDlls = $("
    "); - var versions = this.getSupportedVersions(); - this.forceLoadTexts = []; - this.forceLoadButtons = []; - for (var i = 0; i < versions.length; i++) { - var listItem = $("
  • "); - $('').text(versions[i]).appendTo(listItem); - var matchPercent = $('').addClass('matchPercent'); - this.forceLoadTexts.push(matchPercent); - matchPercent.appendTo(listItem); - var forceButton = $('