You got that patch function from the 'Unlimited Nudges' script I think. A few days after I wrote the '
Idle on Demand' script (already 3 years ago, wow
) I wrote the '
Unlimited Nudges' script. And in that script there is a function:
js code:
// Do the actual patching.
function Patch(nAddress, sByteString) {
// Make a decent byte array out of the string.
// This is again where Plus! comes short with its WriteString() function IMHO.
// Also notice that older Plus! versions expect signed bytes with SetAt(), so we use WriteWORD() instead.
var sBuffer = Interop.Allocate(++sByteString.length);
for (var j = 0; j < sByteString.length; j++) sBuffer.WriteWORD(j, sByteString.charCodeAt(j));
var hProc = Interop.Call("Kernel32", "GetCurrentProcess");
Interop.Call("Kernel32", "WriteProcessMemory", hProc, nAddress, sBuffer.DataPtr, sByteString.length, 0);
}
looking familiar?
the 'uniqueness' of this code (hence why I reconize it as written by me) is the trick I did by using WriteWord to overcome a bug in Plus! and allocating the buffer one byte longer than needed because of it. I was also the first to report/notice that the SetAt()/GetAt() functions needed signed bytes. Nobody before had noticed it (that I know of) because several scripts at that time which used SetAt() or GetAt(), for different stuff that is, had this bug of not returning what the script creator expected it to return. After I reported this in public, several scripts started to use 'GetAt() & 0xFF' (as shown in 'Unlimited Nudges' script), instead of just GetAt().
Anyways, enough off topic history jabber talk, I'll shut up now