Thanks for the upload/update! I made an improvement to the function, you can now read the return value too.
Code: Select all
--- Run rom scripts, usage: RoMScript("AcceptResurrect();");
function RoMScript(script)
--- Get the real offset of the address
local macro_address = memoryReadUInt(getProc(), staticmacrobase_address) + macro_offset;
--- Macro length is max 255, and after we add the return code,
--- we are left with 120 character limit.
local text = "/script r='' a={} a[0],a[1],a[2],a[3],a[4] = " .. script
.. " for i=0, 4, 1 do if a[i] then r = r..a[i]..'@' end end"
.. " EditMacro(2,'',16,r);";
--- Write the macro
for i = 0, 254, 1 do
local byte = string.byte(text, i+1);
if byte == null then
byte = 0;
end
memoryWriteByte(getProc(), macro_address+i, byte);
end
--- Execute it
if( settings.profile.hotkeys.MACRO ) then
keyboardPress(settings.profile.hotkeys.MACRO.key);
end
--- Wait for RoM to process it, so that we can read the outcome.
yrest(200);
--- Read the outcome from macro 2
read = ""
ret = {false, false, false, false, false, false, false, false, false, false}
cnt = 0;
for i = 0, 254, 1 do
local byte = memoryReadByte(getProc(), macro_address+0x508+i);
if byte > 0 then
if byte == 64 then -- Use @ to seperate
ret[cnt] = read;
cnt = cnt+1;
read = "";
else
read = read .. string.char(byte);
end
end
end
return ret[0],ret[1],ret[2],ret[3],ret[4],ret[5],ret[6],ret[7],ret[8],ret[9];
end
Usage:
Code: Select all
local bagid, icon, name, itemCount = RoMScript("GetBagItemInfo(1);");
Edit: From 5 to 10 possible return values