Re: (Request) King Of Fighters Maximum Impact model rip
Posted: Thu Sep 22, 2011 10:00 pm
Game Research Forum
https://forum.xentax.com/
Code: Select all
fn int2bin val = (
local ary = #()
if val <-1 then val += 256 --convert signed byte to unsigned byte
if val >= 128 then (append ary 1 ;val-=128) else append ary 0
if val >= 64 then (append ary 1 ;val-=64) else append ary 0
if val >= 32 then (append ary 1 ;val-=32) else append ary 0
if val >= 16 then (append ary 1 ;val-=16) else append ary 0
if val >= 8 then (append ary 1 ;val-=8) else append ary 0
if val >= 4 then (append ary 1 ;val-=4) else append ary 0
if val >= 2 then (append ary 1 ;val-=2) else append ary 0
if val == 1 then (append ary 1) else append ary 0
return ary
)--end fn int2bin
fn KOFdecompress fstream Usize = (
debugmode=false
clearlistener()
local ctrlBits = #()
local Ubuffer = #()
do (
join ctrlBits ( int2bin ( readbyte fstream #unsigned ) )
if debugmode==true then (
format "In: "
for j in ctrlBits do format "%" j
format "\n"
)--end debugmode
do (
if ctrlBits[1] == 1 then (
append Ubuffer (readbyte fstream #unsigned)
deleteitem ctrlBits 1
) else (
local len = 0
local ofs = 0
if ctrlBits[2] == 0 then (
len = ctrlBits[3]*2 + ctrlBits[4] + 2
ofs = (readbyte fstream #unsigned) - 256
if debugmode==true then format "ofs: %\tlen: %\n" ofs len
deleteitem ctrlBits 1; deleteitem ctrlBits 1
deleteitem ctrlBits 1; deleteitem ctrlBits 1
) else (
ctrlH = readbyte fstream #unsigned
ctrlL = readbyte fstream #unsigned
if debugmode==true then format "H: %\tL: % @ [%]\n" (dec2hex ctrlH) (dec2hex ctrlL) (dec2hex (ftell fstream))
len = (mod ctrlL 32)
if len == 0 then len = 1 + (readbyte fstream #unsigned)
else len += 2
--ofs = ((mod ctrlH 32)*8+(ctrlL/32))*256 + 0xF8 + (ctrlH/32)
--if ofs > 0x7FFF then ofs = ofs - 65536
--** KOF method--
ofs = ((mod ctrlH 32)*8+(ctrlL/32)) + (0xF8 + (ctrlH/32))*256 - 65536
if debugmode==true then format "Bofs: %\tBlen: %\n" ofs len
deleteitem ctrlBits 1; deleteitem ctrlBits 1
)
--copy stuff here
loc = ofs + Ubuffer.count
if abs(ofs) >= len then (
for j = 1 to len do append Ubuffer (Ubuffer[(loc+j)])
) else (
for j = 1 to len/(abs(ofs)) do
for jj = 1 to abs(ofs) do append Ubuffer (Ubuffer[(loc+jj)])
for j = 1 to (mod len (abs(ofs))) do append Ubuffer (Ubuffer[(loc+j)])
)--end if/else
--for j in Ubuffer do format "% " (dec2hex j)
--format "\n"
)--end if/else
if Ubuffer.count >= Usize then exit
if (ctrlBits.count == 0) then exit
if (ctrlBits.count==1)AND(ctrlBits[1]==0) then exit
if (ctrlBits.count <= 3)AND(ctrlBits[1]==0)AND(ctrlBits[2]==0) then exit
) while 1==1
if debugmode==true then (
format "Out: "
for j in ctrlBits do format "%" j
format "\n"
--for j in Ubuffer do format "% " (dec2hex j)
--format "\n"
format "\t[%]\nUbuffer: %\n\n" (dec2hex (ftell fstream)) (dec2hex Ubuffer.count)
)--end debugmode
) while Ubuffer.count < Usize
format "->%\n" Ubuffer.count
return Ubuffer
)--end fn KOFdecompress
Code: Select all
fn int2bin val = (
local ary = #()
if val <-1 then val += 256 --convert signed byte to unsigned byte
if val >= 128 then (append ary 1 ;val-=128) else append ary 0
if val >= 64 then (append ary 1 ;val-=64) else append ary 0
if val >= 32 then (append ary 1 ;val-=32) else append ary 0
if val >= 16 then (append ary 1 ;val-=16) else append ary 0
if val >= 8 then (append ary 1 ;val-=8) else append ary 0
if val >= 4 then (append ary 1 ;val-=4) else append ary 0
if val >= 2 then (append ary 1 ;val-=2) else append ary 0
if val == 1 then (append ary 1) else append ary 0
return ary
)--end fn int2bin
fn KOFdecompress fstream Usize = (
debugmode=false
clearlistener()
local ctrlBits = #()
local Ubuffer = #()
do (
join ctrlBits ( int2bin ( readbyte fstream #unsigned ) )
if debugmode==true then (
format "In: "
for j in ctrlBits do format "%" j
format "\n"
)--end debugmode
do (
if ctrlBits[1] == 1 then (
append Ubuffer (readbyte fstream #unsigned)
deleteitem ctrlBits 1
) else (
local len = 0
local ofs = 0
if ctrlBits[2] == 0 then (
len = ctrlBits[3]*2 + ctrlBits[4] + 2
ofs = (readbyte fstream #unsigned) - 256
if debugmode==true then format "ofs: %\tlen: %\n" ofs len
deleteitem ctrlBits 1; deleteitem ctrlBits 1
deleteitem ctrlBits 1; deleteitem ctrlBits 1
) else (
ctrlH = readbyte fstream #unsigned
ctrlL = readbyte fstream #unsigned
if debugmode==true then format "H: %\tL: % @ [%]\n" (dec2hex ctrlH) (dec2hex ctrlL) (dec2hex (ftell fstream))
len = (mod ctrlL 32)
if len == 0 then len = 1 + (readbyte fstream #unsigned)
else len += 2
--ofs = ((mod ctrlH 32)*8+(ctrlL/32))*256 + 0xF8 + (ctrlH/32)
--if ofs > 0x7FFF then ofs = ofs - 65536
--** KOF method--
ofs = ((mod ctrlH 32)*8+(ctrlL/32)) + (0xF8 + (ctrlH/32))*256 - 65536
if debugmode==true then format "Bofs: %\tBlen: %\n" ofs len
deleteitem ctrlBits 1; deleteitem ctrlBits 1
)
--copy stuff here
loc = ofs + Ubuffer.count
if abs(ofs) >= len then (
for j = 1 to len do append Ubuffer (Ubuffer[(loc+j)])
) else (
for j = 1 to len/(abs(ofs)) do
for jj = 1 to abs(ofs) do append Ubuffer (Ubuffer[(loc+jj)])
for j = 1 to (mod len (abs(ofs))) do append Ubuffer (Ubuffer[(loc+j)])
)--end if/else
--for j in Ubuffer do format "% " (dec2hex j)
--format "\n"
)--end if/else
if Ubuffer.count >= Usize then exit
if (ctrlBits.count == 0) then exit
if (ctrlBits.count==1)AND(ctrlBits[1]==0) then exit
if (ctrlBits.count <= 3)AND(ctrlBits[1]==0)AND(ctrlBits[2]==0) then exit
) while 1==1
if debugmode==true then (
format "Out: "
for j in ctrlBits do format "%" j
format "\n"
--for j in Ubuffer do format "% " (dec2hex j)
--format "\n"
format "\t[%]\nUbuffer: %\n\n" (dec2hex (ftell fstream)) (dec2hex Ubuffer.count)
)--end debugmode
) while Ubuffer.count < Usize
format "->%\n" Ubuffer.count
return Ubuffer
)--end fn KOFdecompress