');
}
container.append('');
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);
}
updateUI(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;
}
}
// Default fallback
this.radios[0].checked = true;
}
validatePatch(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 file?';
}
applyPatch(file) {
var patch = this.getSelected();
replace(file, this.offset, patch.patch);
}
getSelected() {
for(var i = 0; i < this.patches.length; i++) {
if(this.radios[i].checked) {
return this.patches[i];
}
}
return null;
}
}
// Each unique kind of patch should have createUI, validatePatch, applyPatch,
// updateUI
class NumberPatch {
constructor(options) {
this.name = options.name;
this.tooltip = options.tooltip;
this.offset = options.offset;
this.size = options.size;
this.min = options.min;
this.max = options.max;
}
createUI(parent) {
var id = createID();
var label = this.name;
var patch = $('
');
}
parent.append(patch)
}
updateUI(file) {
// This converts bytes from the file to big endian by shifting each
// byte `i` bytes to the left then doing a bitwise OR to add the less
// significant bytes that were gathered at earlier iterations of loop
var val = 0;
for (var i = 0; i < this.size; i++) {
val = (file[this.offset + i] << (8 * i)) | val;
}
this.number.value = val;
}
validatePatch(file) {
return;
}
applyPatch(file) {
// Convert user inputted number to little endian
const view = new DataView(new ArrayBuffer(this.size * 2));
view.setInt32(1, this.number.value, true);
for (var i = 0; i < this.size; i++) {
var val = view.getInt32(1);
// Shift off less significant bytes
val = val >> ((this.size - 1 - i) * 8);
// Mask off more significant bytes
val = val & 0xFF;
// Write this byte
file[this.offset + i] = val;
}
}
}
var loadPatch = function(_this, self, patcher) {
patcher.loadPatchUI();
patcher.updatePatchUI();
patcher.container.show();
var successStr = patcher.filename;
if ($.type(_this.description) === "string") {
successStr += "(" + patcher.description + ")";
}
self.successDiv.html(successStr + " loaded successfully!");
};
class PatchContainer {
constructor(patchers) {
this.patchers = patchers;
this.createUI();
}
getSupportedDLLs() {
var dlls = [];
for (var i = 0; i < this.patchers.length; i++) {
var name = this.patchers[i].filename;
if (dlls.indexOf(name) === -1) {
dlls.push(name);
}
}
return dlls;
}
createUI() {
var self = this;
var container = $("
", {"class": "patchContainer"});
var header = this.getSupportedDLLs().join(", ");
container.html("
" + header + "
");
var supportedDlls = $("
");
this.forceLoadTexts = [];
this.forceLoadButtons = [];
this.matchSuccessText = [];
for (var i = 0; i < this.patchers.length; i++) {
var checkboxId = createID();
var listItem = $("