Skip to content

Commit

Permalink
Add Subtractive score for SDVX, class-ify patch styles
Browse files Browse the repository at this point in the history
  • Loading branch information
mon committed Jan 29, 2017
1 parent 67f1903 commit 468ddc6
Show file tree
Hide file tree
Showing 2 changed files with 191 additions and 75 deletions.
204 changes: 149 additions & 55 deletions js/dllpatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand Down Expand Up @@ -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';
Expand All @@ -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])
Expand All @@ -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];
Expand Down
62 changes: 42 additions & 20 deletions sdvx3-s2.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,48 @@
on : [0xB8, 0x01, 0x00, 0x00, 0x00, 0x89, 0x83, 0x78, 0x0A, 0x00, 0x00, 0x90, 0x56, 0x57, 0x90, 0x90]}]
},
{
name : "Score as overall percentage (Osu style % display)",
shortname : "percent",
patches : [{offset : 0x1FBD9,
off : [0x8B, 0x85, 0x50, 0x01, 0x00, 0x00, 0x8B, 0x9D, 0x48, 0x01, 0x00, 0x00, 0x8B, 0x8D, 0x54, 0x01,
0x00, 0x00, 0x8B, 0x95, 0x4C, 0x01, 0x00, 0x00, 0x56, 0x57, 0x3B, 0xC3, 0x75, 0x08, 0x3B, 0xCA,
0x0F, 0x84, 0x86, 0x00, 0x00, 0x00, 0x8B, 0xF8, 0x81, 0xC7, 0x7C, 0x9F, 0x02, 0x00, 0x8B, 0xF1,
0x83, 0xD6, 0x00, 0x3B, 0xD6, 0x7C, 0x1C, 0x7F, 0x04, 0x3B, 0xDF, 0x76, 0x16, 0x05, 0x26, 0x43,
0x00, 0x00, 0x83, 0xD1, 0x00, 0x89, 0x85, 0x50, 0x01, 0x00, 0x00, 0x89, 0x8D, 0x54, 0x01, 0x00,
0x00, 0xEB, 0x59, 0x8B, 0xF8, 0x81, 0xC7, 0x26, 0x43, 0x00, 0x00, 0x8B, 0xF1, 0x83, 0xD6, 0x00,
0x3B, 0xD6, 0x7C, 0x1C, 0x7F, 0x04, 0x3B, 0xDF, 0x76, 0x16, 0x05, 0x62, 0x16, 0x00, 0x00, 0x83,
0xD1, 0x00, 0x89, 0x85, 0x50],
on : [0x56, 0x57, 0x52, 0x51, 0xBE, 0x90, 0x71, 0x7C, 0x18, 0x8B, 0x46, 0x54, 0x99, 0x6A, 0x00, 0x6A,
0x02, 0x52, 0x50, 0xE8, 0x3F, 0xC4, 0x21, 0x00, 0x8B, 0xC8, 0x8B, 0xFA, 0x8B, 0x46, 0x58, 0x99,
0x01, 0xC1, 0x11, 0xD7, 0x6A, 0x00, 0x68, 0x80, 0x96, 0x98, 0x00, 0x57, 0x51, 0xE8, 0x25, 0xC4,
0x21, 0x00, 0x8B, 0xFA, 0x8B, 0xC8, 0x8B, 0x46, 0x54, 0x8B, 0x56, 0x58, 0x01, 0xD0, 0x8B, 0x56,
0x5C, 0x01, 0xD0, 0x01, 0xC0, 0x99, 0x83, 0xF8, 0x00, 0x0F, 0x85, 0x0F, 0x00, 0x00, 0x00, 0xBF,
0x00, 0x00, 0x00, 0x00, 0xBB, 0x00, 0x00, 0x00, 0x00, 0xE9, 0x0D, 0x00, 0x00, 0x00, 0x52, 0x50,
0x57, 0x51, 0xE8, 0x90, 0x36, 0x21, 0x00, 0x8B, 0xF8, 0x8B, 0xDA, 0x59, 0x5A, 0x8B, 0x45, 0x08,
0x8B, 0x40, 0x04, 0xEB, 0x49]}]
},
type : "union",
name : "Score",
shortname : "score",
offset : 0x1FBD9,
patches : [
{
name : "Default (NEAR+CRITICAL add to score from 0)",
shortname : "default",
patch : [0x8B, 0x85, 0x50, 0x01, 0x00, 0x00, 0x8B, 0x9D, 0x48, 0x01, 0x00, 0x00, 0x8B, 0x8D, 0x54, 0x01,
0x00, 0x00, 0x8B, 0x95, 0x4C, 0x01, 0x00, 0x00, 0x56, 0x57, 0x3B, 0xC3, 0x75, 0x08, 0x3B, 0xCA,
0x0F, 0x84, 0x86, 0x00, 0x00, 0x00, 0x8B, 0xF8, 0x81, 0xC7, 0x7C, 0x9F, 0x02, 0x00, 0x8B, 0xF1,
0x83, 0xD6, 0x00, 0x3B, 0xD6, 0x7C, 0x1C, 0x7F, 0x04, 0x3B, 0xDF, 0x76, 0x16, 0x05, 0x26, 0x43,
0x00, 0x00, 0x83, 0xD1, 0x00, 0x89, 0x85, 0x50, 0x01, 0x00, 0x00, 0x89, 0x8D, 0x54, 0x01, 0x00,
0x00, 0xEB, 0x59, 0x8B, 0xF8, 0x81, 0xC7, 0x26, 0x43, 0x00, 0x00, 0x8B, 0xF1, 0x83, 0xD6, 0x00,
0x3B, 0xD6, 0x7C, 0x1C, 0x7F, 0x04, 0x3B, 0xDF, 0x76, 0x16, 0x05, 0x62, 0x16, 0x00, 0x00, 0x83,
0xD1, 0x00, 0x89, 0x85, 0x50],
},
{
name : "Subtractive (NEAR+ERROR subtract score from 10,000,000)",
shortname : "subtract",
patch : [0x56, 0x57, 0x52, 0x51, 0xBE, 0x90, 0x71, 0x7C, 0x18, 0x8B, 0x46, 0x5C, 0x6A, 0x00, 0x99, 0x6A,
0x02, 0x52, 0x50, 0xE8, 0x3F, 0xC4, 0x21, 0x00, 0x8B, 0xC8, 0x8B, 0x46, 0x58, 0x8B, 0xFA, 0x99,
0x6A, 0x00, 0x01, 0xC1, 0x11, 0xD7, 0x68, 0x80, 0x96, 0x98, 0x00, 0x57, 0x51, 0xE8, 0x25, 0xC4,
0x21, 0x00, 0x8B, 0xFA, 0x8B, 0x56, 0x18, 0x8B, 0xC8, 0x8B, 0x82, 0x80, 0x2C, 0x00, 0x00, 0x01,
0xC0, 0x99, 0x52, 0x50, 0x57, 0x51, 0xE8, 0xAC, 0x36, 0x21, 0x00, 0xB9, 0x80, 0x96, 0x98, 0x00,
0xBF, 0x00, 0x00, 0x00, 0x00, 0x29, 0xC1, 0x19, 0xD7, 0x8B, 0xDF, 0x8B, 0xF9, 0x59, 0x5A, 0x8B,
0x45, 0x08, 0x8B, 0x40, 0x04]
},
{
name : "Average (Osu style % display)",
shortname : "avg",
patch : [0x56, 0x57, 0x52, 0x51, 0xBE, 0x90, 0x71, 0x7C, 0x18, 0x8B, 0x46, 0x54, 0x99, 0x6A, 0x00, 0x6A,
0x02, 0x52, 0x50, 0xE8, 0x3F, 0xC4, 0x21, 0x00, 0x8B, 0xC8, 0x8B, 0xFA, 0x8B, 0x46, 0x58, 0x99,
0x01, 0xC1, 0x11, 0xD7, 0x6A, 0x00, 0x68, 0x80, 0x96, 0x98, 0x00, 0x57, 0x51, 0xE8, 0x25, 0xC4,
0x21, 0x00, 0x8B, 0xFA, 0x8B, 0xC8, 0x8B, 0x46, 0x54, 0x8B, 0x56, 0x58, 0x01, 0xD0, 0x8B, 0x56,
0x5C, 0x01, 0xD0, 0x01, 0xC0, 0x99, 0x83, 0xF8, 0x00, 0x0F, 0x85, 0x0F, 0x00, 0x00, 0x00, 0xBF,
0x00, 0x00, 0x00, 0x00, 0xBB, 0x00, 0x00, 0x00, 0x00, 0xE9, 0x0D, 0x00, 0x00, 0x00, 0x52, 0x50,
0x57, 0x51, 0xE8, 0x90, 0x36, 0x21, 0x00, 0x8B, 0xF8, 0x8B, 0xDA, 0x59, 0x5A, 0x8B, 0x45, 0x08,
0x8B, 0x40, 0x04, 0xEB, 0x49]
},
]
}
]);
});
</script>
Expand Down

0 comments on commit 468ddc6

Please sign in to comment.