24 lines
1.7 KiB
Lua
24 lines
1.7 KiB
Lua
-- Read-only TSparseArray traversal for the verified game's TMap layout.
|
|
-- It requires a read callback; it has no write or process-opening capability.
|
|
function ReadAccessorySparseMap(read,address,stride,limit)
|
|
assert(stride>=16 and stride<=128 and limit>=1 and limit<=4096,'饰品表读取范围无效')
|
|
local h=assert(read(address,0x38),'饰品表头不可读');assert(#h==0x38)
|
|
local data=string.unpack('<i8',h,1);local n,capacity=string.unpack('<I4I4',h,9)
|
|
local heap=string.unpack('<i8',h,0x21);local bits,bitCapacity=string.unpack('<I4I4',h,0x29);local free=string.unpack('<I4',h,0x35)
|
|
assert(n<=limit and capacity>=n and capacity<=limit*2+64 and free<=n,'饰品表容量异常')
|
|
assert(bits>=n and bits<=limit*2+64 and bitCapacity>=bits and bitCapacity<=limit*4+128,'饰品表分配标记异常')
|
|
if n==0 then assert(read(address,0x38)==h,'饰品表在读取中变化');return {}end
|
|
assert(data>=0x10000,'饰品表数据指针无效')
|
|
local flagsAt=heap~=0 and heap or address+0x10
|
|
assert(flagsAt>=0x10000 and(heap~=0 or bits<=128),'饰品表内联标记容量异常')
|
|
local flagBytes=math.floor((bits+7)/8);local flags=assert(read(flagsAt,flagBytes),'饰品表分配标记不可读')
|
|
local bytes=assert(read(data,n*stride),'饰品表条目不可读');assert(#bytes==n*stride and #flags==flagBytes)
|
|
local rows={}
|
|
for i=0,n-1 do
|
|
if flags:byte(math.floor(i/8)+1)&(1<<(i%8))~=0 then rows[#rows+1]={index=i,address=data+i*stride,raw=bytes:sub(i*stride+1,(i+1)*stride)}end
|
|
end
|
|
assert(#rows==n-free,'饰品表稀疏计数不匹配')
|
|
assert(read(address,0x38)==h and read(flagsAt,flagBytes)==flags and read(data,n*stride)==bytes,'饰品表在读取中变化,请稍后重试')
|
|
return rows
|
|
end
|