Pages

08 November 2012

Doa5 injector


try(destroydialog stickitin)catch()
clearlistener()
ssource=""
model_scale = 100
rollout stickitin "Untitled" width:333 height:116
(
	editText edt1 "" pos:[14,22] width:300 height:16
	button btn1 "Browse" pos:[256,41] width:57 height:17
	button btn2 "Inject A Texture" pos:[15,70] width:126 height:29
	button btn3 "Inject Vertices" pos:[190,70] width:126 height:29
	label lbl1 "Open a TMCL File:" pos:[18,3] width:89 height:15

	fn writeBEfloat fstream flt = (writelong fstream \
(bit.swapBytes (bit.swapBytes (bit.floatAsInt flt) 1 4) 2 3) #unsigned)

fn ReadBEfloat fstream = (
bit.intAsFloat (bit.swapBytes (bit.swapBytes (readlong fstream #unsigned) 1 4) 2 3)
)	
fn readBEshort fstream = (bit.swapBytes (readshort fstream #unsigned) 1 2)

fn readBElong fstream = (bit.swapBytes (bit.swapBytes (readlong fstream #unsigned) 1 4) 2 3)
fn ReadFixedString bstream fixedLen = (
local str = ""
for i = 1 to fixedLen do (
str += bit.intAsChar (ReadByte bstream #unsigned))
str
)
on edt1 entered txt do (
if txt!=undefined do (
	edt1.text = txt
	if (doesFileExist txt) do (
	ssource = txt
	)
	)
	
)

	on btn1 pressed do (
	txt = getSaveFileName \
caption:"Select TMC File" \
types: "Tecmo Memory Catelog(*.tmcl)|*.TMCL|All files (*.*)|*.*|"
if txt!=undefined do (
	if (doesFileExist txt) do (
	edt1.text = txt
	ssource = txt
	)
	)
	
	)
	on btn2 pressed do ( -- texture injection
			if ssource!=undefined then (
	if (doesFileExist ssource) then (
		fsource = GetOpenFileName \
caption:"Select DDS File" \
types: "DirectDrawSurface(*.dds)|*.DDS|All files (*.*)|*.*|"
		
		if (fsource!=undefined) AND ((doesFileExist fsource)==true) then(
		fname=getFilenameFile fsource
		fsize = getFileSize fsource
		dataArray = filterString fname "_"

		f = fopen fsource "rb"
		fseek f 0x54 #seek_set
		texC=ReadFixedString f 4
if texC==dataArray[2] then (
s = fopen ssource "r+"
fseek s (execute dataArray[1]) #seek_set
fseek f 0x80 #seek_set
fsize -= 0x80

if dataArray[3]=="TX2D" then(
case of (
(texC=="DXT1"): (for r = 1 to (fsize/2) do(writeshort s (ReadBEshort f) #unsigned;fflush s))
(texC=="DXT3"): (for r = 1 to (fsize/2) do(writeshort s (ReadBEshort f) #unsigned;fflush s))
(texC=="DXT5"): (for r = 1 to (fsize/2) do(writeshort s (ReadBEshort f) #unsigned;fflush s))
(texC=="ATI1"): (for r = 1 to (fsize/2) do(writeshort s (ReadBEshort f) #unsigned;fflush s))
(texC=="ATI2"): (for r = 1 to (fsize/2) do(writeshort s (ReadBEshort f) #unsigned;fflush s))
-- (texC=="ARGB16"): (for r = 1 to fsize do(writebyte s (readbyte f #unsigned) #unsigned))
-- (texC=="ARGB32"): (for r = 1 to fsize do(writebyte s (readbyte f #unsigned) #unsigned))
)
)else(
case of (
(texC=="DXT1"): (
for c = 1 to (fsize/8192) do(
for r = 1 to (8192/2) do (writeshort s (ReadBEshort f) #unsigned;fflush s)
for p = 1 to 8192 do (writebyte s 0;fflush s)))
(texC=="DXT3"): (
for c = 1 to (fsize/16384) do(
for r = 1 to (16384/2) do (writeshort s (ReadBEshort f) #unsigned;fflush s)
for p = 1 to 16384 do (writebyte s 0;fflush s)))
(texC=="DXT5"): (
for c = 1 to (fsize/16384) do(
for r = 1 to (16384/2) do (writeshort s (ReadBEshort f) #unsigned;fflush s)
for p = 1 to 16384 do (writebyte s 0;fflush s)))
(texC=="ATI1"): (
for c = 1 to (fsize/8192) do(
for r = 1 to (8192/2) do (writeshort s (ReadBEshort f) #unsigned;fflush s)
for p = 1 to 8192 do (writebyte s 0;fflush s)))
(texC=="ATI2"): (
for c = 1 to (fsize/16384) do(
for r = 1 to (16384/2) do (writeshort s (ReadBEshort f) #unsigned;fflush s)
for p = 1 to 16384 do (writebyte s 0;fflush s)))
-- (texC=="ARGB16"): (for r = 1 to fsize do(writebyte s (readbyte f #unsigned) #unsigned))
-- (texC=="ARGB32"): (for r = 1 to fsize do(writebyte s (readbyte f #unsigned) #unsigned))
)
)

fclose s
messagebox "Done!"
)else(messagebox "Error!\nWrong DDS Compression")
		fclose f
	)else(print "aborted")
	
	)else(messagebox "Error!\nFailed to read TMCL")
)else(messagebox "Error!\nOpen a TMCL First!")
)
	on btn3 pressed do ( -- vertex injection
	if ssource!=undefined then (
	if (doesFileExist ssource) then (

s = fopen ssource "r+"
	
obj = selection
if obj.count!=0 then (
for i = 1 to obj.count do (
dataArray = execute (getUserProp obj[i] "mesh_data")
if dataArray!=undefined then (
if dataArray[1].count == obj[i].material.count then ( -- this even needed?
tmesh = snapshotAsMesh obj[1]
obj_sel = getVertSelection obj[1]
cnt=0
-- 	stride,num_verts,pos
for x = 1 to dataArray[1].count do (
pos=dataArray[3][x]
format "Last Read @ 0x%\n" ((bit.intAsHex(dataArray[3][x]))as string)
for v = 1 to dataArray[2][x] do (
fseek s pos #seek_set;cnt+=1
-- if obj_sel[cnt]==true do (

vert = ((getVert tmesh cnt)/model_scale)
writeBEfloat s vert[1]
writeBEfloat s vert[3]
writeBEfloat s -vert[2]


fflush s
-- )
pos+=dataArray[1][x]
)
)
print cnt
delete tmesh
messagebox "Done!"
fclose s
)else(messagebox "Error!\nMaterials Don't Match Injection details")
)else(messagebox "Error!\ninjection details missing from mesh properties"))
)else(messagebox "Error!\nnothing selected")

)else(messagebox "Error!\nFailed to open file")
)else(messagebox "Error!\nNo File Selected?")
	)
	
	
	
	
	
	
	
	
	
	
	) createdialog stickitin


0 comments: