-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMemoryPatchInLine.lua
1 lines (1 loc) · 1.34 KB
/
MemoryPatchInLine.lua
1
local function MemoryPatch(a,b,c)local d,e,f,g,h,j='',false,false,{},{},0;local function k(a)return#a>0 and a:lower():find("[^%dabcdef]")==nil;end;local function l(a,b)local r=''local function f(v)v=string.format("%X",v)if#v==1 then return"0"..v;end;return v;end;for i=0,b-1 do r=r..f(gg.getValues({{address=a+i,flags=gg.TYPE_BYTE}})[1].value)end;return r;end;local function m(a)local r = ''if#a==0 then return false;end;for i=1,#a,2 do r=r..a:sub(i,i+1)end;return r:upper()end;local function n(a,b)local r,i={},0;for v in a:gmatch("%S%S")do table.insert(r,{address=b+i,flags=gg.TYPE_BYTE,value=v.."r"})i=i+1;end;return r;end;local o={Modify=function()if e and not f then gg.setValues(g)f=true;return true;end;return false;end,Restore=function()if e and f then gg.setValues(h)f=false;return true;end;return false;end,GetInfo=function()return{ok=e,lib=a,offset=string.format("0x%X",j).." + "..string.format("0x%X",b),hex=c,originalHex=d}end,IsModified=function()return f;end}c=c:gsub(" ", ""):gsub("0x", ""):upper()if not k(c)then print("[MemoryPatch] Hex is wrong for "..o.GetInfo())return o;end;for _,v in ipairs(gg.getRangesList(a)) do if v.type=="r-xp"or v.state=="Xa"then j=v.start;e=true;break;end;end;if not e then print("[MemoryPatch] Lib not found for "..o.GetInfo())return o;end;d=m(l(j+b,(#c+#c%2)/2))if #c<#d then c=c..d:sub(#d)end;g=n(c,j+b)h=n(d,j+b)return o;end