panraven Grandmaster Cheater
Reputation: 62
Joined: 01 Oct 2008 Posts: 958
|
Posted: Thu May 14, 2020 6:58 am Post subject: |
|
|
You may try this helper function
Code: |
Struct2Aob = setmetatable({},{
__index = function(me,Pat)
local endian,pat
pat = Pat:gsub('_',function()
endian = endian~='>' and '>'or '<'
return endian
end)
local ok,n,conv = pcall(string.packsize,pat)
if ok and n>0 then -- n is fixed, pack pattern usable
function conv(...)
local r,s = {},string.pack(pat,...)
for i=1,#s do r[i]=string.format('%02X',s:byte(i))end
return table.concat(r,' ')
end
rawset(me,Pat,conv)-- memoized
end
return conv
end
})
-- ref: string.pack https://www.lua.org/manual/5.3/manual.html#6.4.2
-- use '_' to toggle endian, with starting little endian
-- test
--1075970048 4:16842752 4:0 4:0 4:0 4:0 4:0
print(Struct2Aob.fi4i4i4i4i4i4(2.53125,16842752,0,0,0,0,0))
--10759700480 4:168427520 4:0 4:0 4:0 4:0 4:-1
print(Struct2Aob.fi4i4i4i4i4I4(25.3125,168427520,0,0,0,0,-1 & 0xffffffff))
|
Note that you first value should be float, otherwise x10 as integer will be
overflowed even you can convert, the number will not be your expected x10
after truncated to 4byte integer.
The string.pack function has a strict requirement to its input value domain,
for instance, 'i4' signed 4 bytes accept integer from -0x7fffffff to 0x7fffffff,
while 'I4' unsigned 4 bytes accept integer from 0 to 0xffffffff. Outside the
domain (range) will cause error.
In case overflow is acceptable, use the unsigned version and use ( ... & 0xffffffff ) to mask into a proper bytes count integer (like above -1).
More example, for 1st replace:
Code: |
...
searchV = '22 FD 8A 3F 08 AC AC 3F D7 A3 30 3F 52 B8 1E 3F 9A 99 99 3E 9A 99 99 3E' -- use as it, exact pattern in game
replaceV = Struct2Aob.f(1.299999952)..' 08 AC AC 3F D7 A3 30 3F 52 B8 1E 3F 9A 99 99 3E 9A 99 99 3E' -- just modify 1st 4 bytes
AOBRep(searchV,replaceV)
...
|
_________________
- Retarded. |
|