mirror of
https://github.com/mon/BemaniPatcher.git
synced 2026-08-01 14:10:40 -07:00
Add Subtractive score for SDVX, class-ify patch styles
This commit is contained in:
+149
-55
@@ -3,8 +3,148 @@ mods = null;
|
||||
filename = null;
|
||||
errorLog = "";
|
||||
|
||||
// Each unique kind of patch should have createUI, validatePatch, applyPatch,
|
||||
// updateUI
|
||||
|
||||
StandardPatch = function(options) {
|
||||
this.name = options.name;
|
||||
this.shortname = options.shortname;
|
||||
this.patches = options.patches;
|
||||
};
|
||||
|
||||
StandardPatch.prototype.createUI = function(parent) {
|
||||
var id = this.shortname;
|
||||
var label = this.name;
|
||||
parent.append('<div class="patch"><input type="checkbox" id="' + id + '"><label for="' + id + '">' + label + '</label></div>');
|
||||
};
|
||||
|
||||
StandardPatch.prototype.updateUI = function(file) {
|
||||
var id = this.shortname;
|
||||
var elem = document.getElementById(id);
|
||||
elem.checked = this.checkPatchBytes(file) == "on";
|
||||
};
|
||||
|
||||
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 {
|
||||
success = false;
|
||||
return '"' + this.name + '" is neither on nor off! Have you got the right dll?';
|
||||
}
|
||||
};
|
||||
|
||||
StandardPatch.prototype.applyPatch = function(file) {
|
||||
id = this.shortname;
|
||||
var enabled = document.getElementById(id).checked;
|
||||
this.replaceAll(file, enabled);
|
||||
return enabled ? this.shortname : "";
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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";
|
||||
}
|
||||
}
|
||||
return patchStatus;
|
||||
}
|
||||
|
||||
// Each unique kind of patch should have createUI, validatePatch, applyPatch,
|
||||
// updateUI
|
||||
|
||||
// The DEFAULT state is always the 1st element in the patches array
|
||||
UnionPatch = function(options) {
|
||||
this.name = options.name;
|
||||
this.shortname = options.shortname;
|
||||
this.offset = options.offset;
|
||||
this.patches = options.patches;
|
||||
};
|
||||
|
||||
UnionPatch.prototype.createUI = function(parent) {
|
||||
var container = $("<div>", {"class": "patch-union"});
|
||||
container.append('<span class="patch-union-title">' + this.name + ':</span>');
|
||||
for(var i = 0; i < this.patches.length; i++) {
|
||||
var patch = this.patches[i];
|
||||
var id = this.shortname + '-' + patch.shortname;
|
||||
var label = patch.name;
|
||||
container.append('<div class="patch"><input type="radio" id="' + id + '" name="' + this.shortname + '"><label for="' + id + '">' + label + '</label></div>');
|
||||
}
|
||||
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)) {
|
||||
document.getElementById(this.shortname + '-' + this.patches[i].shortname).checked = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Default fallback
|
||||
document.getElementById(this.shortname + '-' + this.patches[0].shortname).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;
|
||||
}
|
||||
}
|
||||
return '"' + this.name + '" doesn\'t have a valid patch! Have you got the right dll?';
|
||||
};
|
||||
|
||||
UnionPatch.prototype.applyPatch = function(file) {
|
||||
var patch = this.getSelected();
|
||||
var name = this.shortname + patch.shortname;
|
||||
replace(file, this.offset, patch.patch);
|
||||
return patch.shortname == "default" ? "" : name;
|
||||
};
|
||||
|
||||
UnionPatch.prototype.getSelected = function() {
|
||||
for(var i = 0; i < this.patches.length; i++) {
|
||||
if(document.getElementById(this.shortname + '-' + this.patches[i].shortname).checked) {
|
||||
return this.patches[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
DllPatcher = function(fname, args) {
|
||||
mods = args;
|
||||
mods = [];
|
||||
for(var i = 0; i < args.length; i++) {
|
||||
mod = args[i];
|
||||
if(mod.type) {
|
||||
if(mod.type == "union") {
|
||||
mods.push(new UnionPatch(mod));
|
||||
}
|
||||
} else { // standard patch
|
||||
mods.push(new StandardPatch(mod));
|
||||
}
|
||||
}
|
||||
filename = fname;
|
||||
loadPatchUI();
|
||||
};
|
||||
@@ -33,11 +173,9 @@ saveDll = function() {
|
||||
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;
|
||||
var enabledStr = mods[i].applyPatch(dllFile);
|
||||
if(enabledStr) {
|
||||
fname += '-' + enabledStr;
|
||||
}
|
||||
}
|
||||
fname += '.dll';
|
||||
@@ -49,67 +187,29 @@ saveDll = function() {
|
||||
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>');
|
||||
mods[i].createUI(patchDiv);
|
||||
}
|
||||
}
|
||||
|
||||
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";
|
||||
mods[i].updateUI(dllFile);
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
var error = mods[i].validatePatch(dllFile);
|
||||
if(error) {
|
||||
errorLog += error + "<br/>";
|
||||
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])
|
||||
@@ -118,12 +218,6 @@ bytesMatch = function(buffer, offset, bytes) {
|
||||
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];
|
||||
|
||||
Reference in New Issue
Block a user