Skip to content

Commit 701cc10

Browse files
authored
game_executable_patcher: initial commit
1 parent 02a6034 commit 701cc10

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed

game_executable_patcher.html

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<h1>Landwirtschafts Simulator / Farming Simulator game executable patcher</h1>
2+
<hr>
3+
<h2>Farming Simulator 2008/2009/2011/2013 FontRenderer Scaling Patch:</h1>
4+
<table><thead>
5+
<tr>
6+
<td align='right'><b>Executable:</b></td>
7+
<td><input type="file" id="fileInput" /><br></td>
8+
</tr>
9+
<tr>
10+
<td align='right'><b>Screen width (e.g 1920):</b></td>
11+
<td><input type="text" id="width" value="640"></td>
12+
</tr>
13+
<tr>
14+
<td align='right'><b>Screen height (e.g 1080):</b></td>
15+
<td><input type="text" id="height" value="480"></td>
16+
</tr>
17+
<tr>
18+
<td></td>
19+
<td><button id="patch" disabled>Patch (FarmingSimulator)(2008|2009|2011|2013)game(.exe)</button></td>
20+
</tr>
21+
</thead></table>
22+
<br>
23+
<div id="container"></div>
24+
25+
<hr>
26+
27+
<a href="http://biskupova.televiziastb.sk/">Morc</a> @ <a href="http://370.network">370network</a> & <a href="https://komeo.xyz/ls2009mods">LS 2009 Mods Archive</a>
28+
29+
30+
31+
<script>
32+
// GIANTS Engine Patcher
33+
// first revision of a javascript based patcher
34+
// Richard Gráčik @ 370network (morc@370.network)
35+
// LS Mods Community (https://komeo.xyz/ls2009mods)
36+
// 29.1.2025
37+
38+
function hex(inputArray)
39+
{
40+
var hexString = '';
41+
for (var i = 0; i < inputArray.length; i++) {
42+
hexString += inputArray[i].toString(16).toUpperCase();
43+
}
44+
return hexString;
45+
}
46+
47+
function findBytes(buffer, sequence) {
48+
for (var i = 0; i < buffer.length - sequence.length + 1; i++) {
49+
var match = true;
50+
for (let j = 0; j < sequence.length; j++) {
51+
if (buffer[i + j] !== sequence[j]) {
52+
match = false;
53+
break;
54+
}
55+
}
56+
if (match)
57+
return i;
58+
}
59+
return -1;
60+
}
61+
62+
document.getElementById("fileInput").addEventListener("change", (event) => {
63+
var file = event.target.files[0];
64+
var reader = new FileReader();
65+
66+
reader.onload = (e) => {
67+
var arrayBuffer = e.target.result;
68+
var gameExecutable = new Uint8Array(arrayBuffer);
69+
70+
var patchButton = document.getElementById("patch");
71+
var widthInput = document.getElementById("width");
72+
var heightInput = document.getElementById("height");
73+
74+
patchButton.disabled = false;
75+
patchButton.onclick = () => {
76+
var widthOffset = findBytes(gameExecutable, [0xC7, 0x06, 0x80, 0x02, 0x00, 0x00]);
77+
var heightOffset = findBytes(gameExecutable, [0xC7, 0x46, 0x04, 0xE0, 0x01, 0x00, 0x00]);
78+
if (widthOffset == -1 && heightOffset == -1) {
79+
alert(`Failed to find offsets, is your executable already patched?`);
80+
}else {
81+
var widthPatchBase = [0xC7, 0x06];
82+
var heightPatchBase = [0xC7, 0x46, 0x04];
83+
84+
var widthPatchRes = [(widthInput.value >> 24) & 0xFF,(widthInput.value >> 16) & 0xFF, (widthInput.value >> 8) & 0xFF, widthInput.value & 0xFF];
85+
var heightPatchRes = [(widthInput.value >> 24) & 0xFF,(widthInput.value >> 16) & 0xFF, (widthInput.value >> 8) & 0xFF, widthInput.value & 0xFF];
86+
87+
var widthPatch = widthPatchBase.concat(widthPatchRes);
88+
var heightPatch = heightPatchBase.concat(heightPatchRes);
89+
90+
for (var i = 0; i < widthPatch.length; i++) {
91+
gameExecutable[widthOffset + i] = widthPatch[i];
92+
}
93+
for (var i = 0; i < heightPatch.length; i++) {
94+
gameExecutable[heightOffset + i] = heightPatch[i];
95+
}
96+
97+
var patchedExecutable = new Blob([gameExecutable], { type: file.type });
98+
99+
alert(`New computed width: ${hex(widthPatchRes)}\nNew computed height: ${hex(heightPatchRes)}\nFontRenderer_00: ${widthOffset}\nFontRenderer_04: ${heightOffset}\nSuccess!`);
100+
}
101+
102+
var link = document.createElement("a");
103+
link.textContent = "Click here if the patched executable didn't start downloading";
104+
link.href = URL.createObjectURL(patchedExecutable);
105+
link.download = `patched_${file.name}`;
106+
document.getElementById("container").appendChild(link);
107+
link.click();
108+
109+
};
110+
};
111+
112+
reader.readAsArrayBuffer(file);
113+
});
114+
</script>

0 commit comments

Comments
 (0)