Advertisement
Guest User

Untitled

a guest
Mar 7th, 2012
67
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 62.50 KB | None
  1. clearlistener()
  2. rollout dr2otr_ex "Dead Rising 2: OTR - Exporter" width:232 height:220
  3. (
  4. button btn1 ">> Import" pos:[9,7] width:80 height:32
  5. button btn2 ">> Inject" pos:[9,71] width:80 height:32
  6. checkbox chk1 "Make Backup" pos:[105,134] width:110 height:16 enabled:true checked:false
  7. checkbox chk2 "Import Skin" pos:[104,62] width:110 height:16 checked:true
  8. button btn3 "<< Export" pos:[9,39] width:80 height:32
  9. button btn4 ">> Pack" pos:[9,135] width:80 height:32
  10. button btn5 "<< Unpack" pos:[9,103] width:80 height:32
  11. label lbl2 "" pos:[292,286] width:29 height:15
  12. checkbox chk3 "" pos:[104,28] width:14 height:16
  13. editText edt1 "MatID:" pos:[120,29] width:77 height:16
  14. checkbox chk5 "Import Normals" pos:[104,80] width:110 height:16
  15. progressBar pb1 "ProgressBar" pos:[10,172] width:213 height:21 color:red
  16. button btn9 "Info" pos:[173,198] width:50 height:17
  17. label lbl1 "v0.4c" pos:[139,199] width:33 height:16
  18. label lbl6 "By: Mario_Kart64n" pos:[9,199] width:108 height:16
  19. checkbox chk54 "MultumInParvo" pos:[104,116] width:110 height:16 enabled:false
  20. checkbox chk55 "Bone Names" pos:[104,98] width:110 height:16 enabled:false checked:false
  21. groupBox grp1 "Options" pos:[93,8] width:130 height:159
  22. button btn20 "+" pos:[157,45] width:16 height:17
  23. label lbl12 "NormMap" pos:[104,46] width:52 height:13
  24. spinner spn2 "" pos:[174,45] width:34 height:16 range:[-5,5,1]
  25.  
  26.  
  27. local mscale=39.3700787
  28. local nmV=1
  29. local nmR=false
  30. local nmG=false
  31. local nmS=false
  32.  
  33. fn ReadFixedString bstream fixedLen = (
  34. local str = "";
  35. for i = 1 to fixedLen do(str += bit.intAsChar (
  36. ReadByte bstream #unsigned));return str)
  37.  
  38. fn readbig fstream =(
  39. startpos=ftell fstream
  40. unk01=readlong fstream #unsigned
  41. unk02=readlong fstream #unsigned
  42. fsize=readlong fstream #unsigned
  43. files=readlong fstream #unsigned
  44. unk04=readlong fstream #unsigned
  45. names_offset=readlong fstream #unsigned
  46. local infoArray=#();infoArray[files]=[0,0,0,0]
  47. for i = 1 to files do(
  48. NameOff=(readlong fstream #unsigned)+startpos
  49. unk05=readlong fstream #unsigned
  50. zsize=readlong fstream #unsigned
  51. size=readlong fstream #unsigned
  52. offset=(readlong fstream #unsigned)+startpos
  53. type=readlong fstream #unsigned
  54. -- 0x0004 = Info (Header Information)
  55. -- 0x0020 = Data (Geometry)
  56. -- 0x0100 = BIG (BIG Package File)
  57. -- if type!=0x0004 OR type!=0x0020 OR type!=0x0100 DO Print ("ERROR: Type: 0x"+((bit.intAsHex(ftell fstream))as string))
  58. zip=readlong fstream #unsigned
  59. infoArray[i]=[type,NameOff,offset,size]);return infoArray)
  60.  
  61. fn readBIGXML mstream =(struct xmlTag (name,info,count)
  62. xmlInfo=(xmlTag name:#() info:#() count:#());while mstream.eos()==false do(
  63. str=mstream.readLine() as stringstream;if str!=undefined do(peek=""
  64. while peek!="<" AND eof str!=true do (peek=readChar str);xmlEnt="";xmlTag="";xmlDat=""
  65. while peek!=">" AND eof str!=true do (peek=readChar str;if peek!=">" do xmlTag+=peek)
  66. xmlEnt=(readDelimitedString (xmlTag as stringstream) " ");if xmlEnt=="entry" OR xmlEnt=="files" do(
  67. while peek!="<" AND eof str!=true do (peek=readChar str;if peek!="<" do xmlDat+=peek)
  68. subTag=xmlTag as stringstream;counter=0;while eof subTag!=true do(counter+=1;skipToString subTag " "
  69. subDat=readDelimitedString subTag "=";skipToString subTag "\"";subEnt=readDelimitedString subTag "\""
  70. append xmlInfo.name subDat;append xmlInfo.info subEnt);append xmlInfo.count counter)));return xmlInfo)
  71.  
  72.  
  73. fn writeDDSheader streamin texW texH texM texC = (
  74. texP=0
  75. writelong streamin 0x20534444 #unsigned -- File ID
  76. writelong streamin 0x7C #unsigned -- Header Size
  77. case of( -- dwFlags
  78. (texC=="DXT1"): (writelong streamin 0x00081007 #unsigned;texP=((texW*texH)/0x02))
  79. (texC=="DXT3"): (writelong streamin 0x00081007 #unsigned;texP=(texW*texH))
  80. (texC=="DXT5"): (writelong streamin 0x00081007 #unsigned;texP=(texW*texH))
  81. (texC=="ATI1"): (writelong streamin 0x000A1007 #unsigned;texP=((texW*texH)/0x20))
  82. (texC=="ATI2"): (writelong streamin 0x000A1007 #unsigned;texP=(texW*texH))
  83. (texC=="P8"): (writelong streamin 0x000A1007 #unsigned;texP=((texW*texH)/0x02))
  84. (texC=="ARGB16"): (writelong streamin 0x00081007 #unsigned;texP=(((texW*texH)/0x8)*0x10))
  85. (texC=="ARGB32"): (writelong streamin 0x00081007 #unsigned;texP=(((texW*texH)/0x4)*0x10)))
  86. writelong streamin texW #unsigned -- Texture Width
  87. writelong streamin texH #unsigned -- Texture Height
  88. writelong streamin texP #unsigned -- Pitch (#of bytes in a single row across the texture)
  89. writelong streamin 0x00 #unsigned -- Image Depth? Not Used, for Image Volume
  90. writelong streamin texM #unsigned -- Texture MIP Count
  91. for i = 1 to 11 do writelong streamin 0x00 #unsigned -- Reserved Space
  92. writelong streamin 0x20 #unsigned -- Size of PIXEL_FORMAT info, always 32bytes;
  93. case of(
  94. (texC=="DXT1"): (writelong streamin 0x04;writelong streamin 0x31545844 #unsigned
  95. writelong streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00
  96. writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00
  97. writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00
  98. writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00
  99. writebyte streamin 0x00;writelong streamin 0x00001000 #unsigned)
  100. (texC=="DXT3"): (writelong streamin 0x04;writelong streamin 0x33545844 #unsigned
  101. writelong streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00
  102. writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00
  103. writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00
  104. writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00
  105. writebyte streamin 0x00;writelong streamin 0x00001000 #unsigned)
  106. (texC=="DXT5"): (writelong streamin 0x04;writelong streamin 0x35545844 #unsigned
  107. writelong streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00
  108. writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00
  109. writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00
  110. writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00
  111. writebyte streamin 0x00;writelong streamin 0x00001000 #unsigned)
  112. (texC=="ATI1"): (writelong streamin 0x04;writelong streamin 0x31495441 #unsigned
  113. writelong streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00
  114. writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00
  115. writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00
  116. writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00
  117. writebyte streamin 0x00;writelong streamin 0x00401008 #unsigned)
  118. (texC=="ATI2"): (writelong streamin 0x04;writelong streamin 0x32495441 #unsigned
  119. writelong streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00
  120. writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00
  121. writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00
  122. writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00
  123. writebyte streamin 0x00;writelong streamin 0x00401008 #unsigned)
  124. (texC=="P8"): (writelong streamin 0x20;writelong streamin 0x20203850 #unsigned
  125. writelong streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00
  126. writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00
  127. writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00
  128. writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00
  129. writebyte streamin 0x00;writelong streamin 0x00401008 #unsigned)
  130. (texC=="ARGB16"): (writelong streamin 0x41;writelong streamin 0x00000000 #unsigned
  131. writelong streamin 0x10;writebyte streamin 0x00;writebyte streamin 0x0F;writebyte streamin 0x00
  132. writebyte streamin 0x00;writebyte streamin 0xF0;writebyte streamin 0x00;writebyte streamin 0x00
  133. writebyte streamin 0x00;writebyte streamin 0x0F;writebyte streamin 0x00;writebyte streamin 0x00
  134. writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0xF0;writebyte streamin 0x00
  135. writebyte streamin 0x00;writelong streamin 0x00001000 #unsigned)
  136. (texC=="ARGB32"): (writelong streamin 0x41;writelong streamin 0x00000000 #unsigned
  137. writelong streamin 0x20;writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0xFF
  138. writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0xFF;writebyte streamin 0x00
  139. writebyte streamin 0x00;writebyte streamin 0xFF;writebyte streamin 0x00;writebyte streamin 0x00
  140. writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00;writebyte streamin 0x00
  141. writebyte streamin 0xFF;writelong streamin 0x00001000 #unsigned))
  142. for i = 1 to 4 do writelong streamin 0x00 #unsigned) -- Reserved Space for CAPS
  143. fn addshort ptr c =(((ptr[(c+0)]*0x0001)+(ptr[(c+1)]*0x0100)))
  144. fn addlong ptr c =(((ptr[(c+0)]*0x00000001)+(ptr[(c+1)]*0x00000100)+ \
  145. (ptr[(c+2)]*0x00010000)+(ptr[(c+3)]*0x01000000)))
  146.  
  147. on spn2 changed theValue do nmV=theValue
  148. on btn20 pressed do(
  149. rollout normopt "Tangent Options" width:160 height:110
  150. (
  151. groupBox grp4 "Normal Map Direction" pos:[6,2] width:148 height:80
  152. checkbox chk19 "Flip Red (X)" pos:[27,21] width:100 height:16 checked:nmR
  153. button btn21 "OK" pos:[46,85] width:65 height:21
  154. checkbox chk20 "Flip Green (Y)" pos:[27,39] width:100 height:16 checked:nmG
  155. checkbox chk21 "Swap Red n Green" pos:[27,57] width:110 height:16 checked:nmS
  156.  
  157. on chk19 changed theState do nmR=theState
  158. on chk20 changed theState do nmG=theState
  159. on chk21 changed theState do nmS=theState
  160. on btn21 pressed do DestroyDialog normopt
  161.  
  162. ) CreateDialog normopt style:#(#style_border)
  163. )
  164.  
  165.  
  166. on btn1 pressed do( -- Import
  167. fsource = GetOpenFileName \
  168. caption:"[PC] Dead Rising 2: OTR - Model Imporer" \
  169. types: "Big files (*.big)|*.BIG|"
  170. if (fsource!=undefined) AND ((doesFileExist fsource)==true) then(
  171. f = fopen fsource "rb"
  172. -- from chrrox's bms and max script
  173.  
  174. skinON=chk2.checked
  175. normON=chk5.checked
  176.  
  177. -- OBJ=$*;DELETE OBJ
  178.  
  179.  
  180. undo off(;with redraw off (
  181.  
  182.  
  183.  
  184. BNArr=#()
  185.  
  186. bigInfo=readbig f
  187. -- print bigInfo
  188.  
  189. fseek f bigInfo[1][2] #seek_set
  190. -- names_offsets=#();names_offsets[files]=""
  191. names=#();names[bigInfo.count]=""
  192. for i = 1 to bigInfo.count do(
  193. -- names_offsets[i]=ftell f
  194. names[i]=readstring f)
  195.  
  196.  
  197. find=findItem names "SceneHeader"
  198. if find!=0 then(
  199. fseek f bigInfo[find][3] #seek_set
  200. sh_ukn01=readlong f #unsigned
  201. sh_ukn02=readlong f #unsigned
  202. sh_ukn03=readlong f #unsigned
  203. msh_count=readlong f #unsigned
  204. mat_count=readlong f #unsigned
  205.  
  206.  
  207. fseek f bigInfo[(findItem names "SceneDescription")][3] #seek_set
  208. mshNames=#();mshNames[msh_count]=""
  209. for i = 1 to msh_count do(mshNames[i]=ReadFixedString f 36)
  210.  
  211. fseek f bigInfo[(findItem names "MatArray")][3] #seek_set
  212. texInfo=#();texInfo[mat_count]=[0,0]
  213. texIndex=#();texIndex[mat_count]=0
  214. for i = 1 to mat_count do(
  215. mt_ukn01=readlong f #unsigned -- index
  216. mt_ukn02=readlong f #unsigned
  217. mt_ukn03=readlong f #unsigned -- count
  218. mt_ukn04=readlong f #unsigned -- offset
  219. mt_ukn05=readlong f #unsigned
  220. mt_ukn06=readlong f #unsigned
  221. mt_ukn07=readlong f #unsigned
  222. mt_ukn08=readlong f #unsigned
  223. mt_ukn09=readlong f #unsigned
  224. texInfo[i]=[mt_ukn03,mt_ukn04]
  225. texIndex[i]=mt_ukn01
  226. )
  227.  
  228. fseek f bigInfo[(findItem names "MatTextureInfoArray")][3] #seek_set
  229. texNames=#()
  230. mm = MultiMaterial()
  231. mm.numsubs=mat_count
  232. meditMaterials[1]=mm
  233. for i = 1 to mat_count do(
  234. texStr=#()
  235. -- fseek f (bigInfo[(findItem names "MatTextureInfoArray")][3]+texInfo[i][2]) #seek_set
  236. for x = 1 to texInfo[i][1] do(
  237. mt_ukn01=readlong f #unsigned
  238. texName=(ReadFixedString f 52)
  239. mt_ukn02=readlong f #unsigned
  240. mt_ukn03=readlong f #unsigned
  241. mt_ukn04=readlong f #unsigned
  242. mt_ukn05=readlong f #unsigned
  243. mt_ukn06=readlong f #unsigned -- flag
  244. mt_ukn07=readlong f #unsigned
  245. mt_ukn08=readlong f #unsigned
  246. mt_ukn09=readlong f #unsigned
  247. mt_ukn10=readlong f #unsigned
  248. mt_ukn11=readlong f #unsigned
  249. mt_ukn12=readlong f #unsigned
  250. if mt_ukn06==1 do append texStr texName
  251. )
  252. if texStr.count==0 do append texStr ""
  253. append texNames texStr
  254. )
  255. print texNames
  256. -- print (texNames[x][1]+".dds")
  257.  
  258. for x = 1 to mat_count do(
  259.  
  260. texPath=((getFilenamePath fsource)+"\\"+texNames[x][1]+".dds")
  261. mm.materialList[x].diffuseMap = Bitmaptexture fileName:texPath --(texNames[x][1]+".dds"))
  262. mm.materialList[x].opacityMap = Bitmaptexture fileName:texPath
  263. mm.materialList[x].diffuseMap.alphaSource = 2
  264. mm.materialList[x].opacityMap.monoOutput = 1
  265. mm.materialList[x].opacityMap.preMultAlpha = off
  266. mm.materialList[x].opacityMap.alphaSource = 0
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273. )
  274. fseek f bigInfo[(findItem names "persistent.big")][3] #seek_set
  275. mshInfo=readbig f
  276. fseek f mshInfo[1][2] #seek_set
  277. -- names_offsets2=#();names_offsets2[mshInfo.count]=""
  278. names2=#();names2[mshInfo.count]=""
  279. for i = 1 to mshInfo.count do(
  280. -- names_offsets2[i]=ftell f
  281. names2[i]=readstring f)
  282.  
  283.  
  284. mshHeader=#();mshHeader[msh_count]=[0,0,0,0];(for i = 1 to msh_count do (mshHeader[i]=[0,0,0,0]))
  285. drawInfo=#();drawInfo[msh_count]=0;(for i = 1 to msh_count do (drawInfo[i]=0))
  286. matIndex=#();matIndex[msh_count]=0;(for i = 1 to msh_count do (matIndex[i]=0))
  287.  
  288. struct renderStrip (matID,uknA,uknB,uknC,uknD,uknE,type)
  289. geoInfo = (renderStrip matID:#() uknA:#() uknB:#() uknC:#() uknD:#() uknE:#() type:#());a=msh_count
  290. geoInfo.matID[a]=0;geoInfo.uknA[a]=0;geoInfo.uknB[a]=0;geoInfo.uknC[a]=0;geoInfo.uknD[a]=0;geoInfo.uknD[a]=0;geoInfo.type[a]=0
  291.  
  292. for i = 1 to names2.count do(
  293. fullName=names2[i]
  294. mshName=fullName as stringstream
  295.  
  296. baseName=readDelimitedString mshName " "
  297. compName=readDelimitedString mshName " "
  298. -- numName=readDelimitedString mshName " "
  299. find=findItem mshNames baseName
  300.  
  301. fseek f mshInfo[i][3] #seek_set
  302.  
  303. case of (
  304.  
  305. (fullName=="_BOUNDINGBOX_"): (
  306. bMax=[(readfloat f*mscale),(readfloat f*mscale),(readfloat f*mscale)]
  307. bMin=[(readfloat f*mscale),(readfloat f*mscale),(readfloat f*mscale)]
  308. -- Dummy pos:[0,0,((bMin.y-bMax.y)/2)] boxsize:[(bMin.x-bMax.x),(bMin.z-bMax.z),(bMin.y-bMax.y)] isSelected:on
  309. )
  310.  
  311.  
  312. (fullName=="_ANIMLIB_SKELETON_"): (
  313. if skinON==true do(
  314. struct Bone_data
  315. (
  316. BoneID,BoneParent,tfm
  317. )
  318. BoneDataArray = #()
  319. file_version=readlong f #unsigned
  320. bone_count=readshort f #unsigned
  321. bone_flag=readshort f #unsigned
  322.  
  323. boneNames=#();boneNames[bone_count]=""
  324. bonePos=#();bonePos[bone_count]=[0,0,0]
  325. boneRot=#();boneRot[bone_count]=[0,0,0]
  326. boneIdx=#();boneIdx[bone_count]=0
  327. boneArray=#()
  328. for i = 1 to bone_count do(
  329. p1=readfloat f
  330. p2=readfloat f
  331. p3=readfloat f
  332. p4=readfloat f
  333.  
  334. p5=readfloat f*mscale
  335. p6=readfloat f*mscale
  336. p7=readfloat f*mscale
  337. p8=readfloat f
  338.  
  339. pA=readshort f #unsigned
  340. pB=readshort f #unsigned -- String Offset
  341.  
  342.  
  343.  
  344. -- boneRot[i]=[p1,p3,p2,p4]
  345. boneRot[i]=[-p1,p3,-p2,p4]
  346. bonePos[i]=[p5,-p7,p6]
  347. -- $.transform.RotationPart
  348.  
  349.  
  350. )
  351.  
  352. for i = 1 to bone_count do(
  353. boneIdx[i]=readbyte f-- #unsigned
  354. )
  355.  
  356.  
  357. if bone_flag==1 do (
  358. for i = 1 to bone_count do(
  359. boneNames[i]=readstring f
  360. )
  361. )
  362.  
  363.  
  364.  
  365.  
  366.  
  367. -- for i = 1 to bone_count do(
  368. -- pos=bonePos[i]
  369. -- idx=boneIdx[i]+1
  370. -- -- if boneIdx[i]!=0xFF do pos=bonePos[idx]*bonePos[i]
  371.  
  372. -- obj=Dummy pos:pos name:boneNames[i] boxsize:[.01,.01,.01] isSelected:on
  373. -- append boneArray obj
  374. -- obj.parent=boneArray[idx]
  375.  
  376. -- )
  377.  
  378.  
  379.  
  380.  
  381. for i = 1 to bone_count do(
  382. BoneParent=boneIdx[i]+1
  383. tfm = (quat (boneRot[i][1]) (boneRot[i][2]) (boneRot[i][3]) (boneRot[i][4])) as matrix3
  384. tfm.row4 = [(bonePos[i][1]),(bonePos[i][2]),(bonePos[i][3])]
  385. arr = #(i,BoneParent,tfm)
  386. append BoneDataArray arr
  387.  
  388. )
  389.  
  390.  
  391.  
  392. for a = 1 to BoneDataArray.count Do (
  393. -- print BoneDataArray[a][1]
  394. -- print BoneDataArray[a][2]
  395. -- print BoneDataArray[a][3]
  396.  
  397. tfm = BoneDataArray[a][3]
  398.  
  399. newBone = bonesys.createbone \
  400. tfm.row4 \
  401. (tfm.row4 + 0.01 * (normalize tfm.row1)) \
  402. (normalize tfm.row3)
  403. -- newBone.name = (BoneDataArray[a][4])
  404. newBone.width = 0.01
  405. newBone.height = 0.01
  406. newBone.transform = tfm
  407. newBone.setBoneEnable false 0
  408. newBone.wirecolor = yellow
  409. newbone.showlinks = true
  410. newBone.pos.controller = TCB_position ()
  411. newBone.rotation.controller = TCB_rotation ()
  412. append BNArr newBone
  413. )
  414. for a = 1 to BoneDataArray.count Do (
  415. select BNArr[a]
  416. tfm = BoneDataArray[a][3]
  417. if ((BoneDataArray[a][2]) != 0) then (
  418. tfm = tfm * BNArr[(BoneDataArray[a][2])].transform
  419. )
  420. $.transform = tfm
  421. if ((BoneDataArray[a][2]) != 0) then (
  422. $.parent = BNArr[(BoneDataArray[a][2])]
  423. )
  424. )
  425.  
  426.  
  427. ))
  428.  
  429. (compName=="CommandBuffer"): (
  430. while (ftell f)!=(mshInfo[i][3]+mshInfo[i][4]) do(
  431.  
  432. if (readbyte f)==11 do(
  433. if (readbyte f)==0 do(
  434.  
  435. if (readbyte f)==0 do(
  436. if (readbyte f)==0 do(
  437. if (readbyte f)==8 do(
  438.  
  439. drawInfo[find]=readbyte f
  440. )
  441.  
  442. )
  443.  
  444. )
  445. )
  446.  
  447. )
  448. )
  449. )
  450.  
  451. (compName=="D3DVertexDesc"): (
  452.  
  453. )
  454.  
  455. (compName=="desc"): (
  456.  
  457. )
  458.  
  459. (compName=="RenderStrip"): (
  460. geoInfo.matID[find]=readlong f #unsigned+1
  461. geoInfo.uknA[find]=readlong f #unsigned
  462. geoInfo.uknB[find]=readlong f #unsigned
  463. geoInfo.uknC[find]=readlong f #unsigned --+1 -- Bone ID
  464. geoInfo.uknD[find]=readlong f #unsigned -- Bone Count
  465. geoInfo.uknE[find]=readlong f #unsigned
  466. geoInfo.type[find]=readlong f #unsigned;print geoInfo.type[find]
  467. matIndex[find]=(findItem texIndex geoInfo.matID[find])
  468. )
  469.  
  470. (compName=="IBHeader"): (
  471. seekName=ReadFixedString f 36 as stringstream
  472. strName=(readDelimitedString seekName " ")
  473. strIndex=(readDelimitedString seekName " ")
  474. if strIndex=="" do strIndex="0"
  475. seekName=(strName+" Indices "+strIndex)
  476. ukn00=readlong f -- always -1 ?
  477. face_count=readlong f #unsigned
  478. ukn01=readlong f #unsigned
  479. ukn02=readlong f #unsigned
  480. mshHeader[find][2]=(findItem names seekName)
  481. mshHeader[find][4]=face_count
  482. )
  483.  
  484. (compName=="VBHeader"): (
  485. seekName=ReadFixedString f 36 as stringstream
  486. strName=(readDelimitedString seekName " ")
  487. strIndex=(readDelimitedString seekName " ")
  488. if strIndex=="" do strIndex="0"
  489. seekName=(strName+" Vertices "+strIndex)
  490. ukn00=readlong f -- always -1 ?
  491. vert_count=readlong f #unsigned
  492. ukn01=readlong f #unsigned
  493. ukn02=readlong f #unsigned
  494. mshHeader[find][1]=(findItem names seekName)
  495. mshHeader[find][3]=vert_count
  496. )
  497.  
  498. (compName=="VDHeader"): (
  499.  
  500. )
  501.  
  502. )
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513. )
  514. -- print mshHeader
  515. -- print drawInfo
  516. -- print names
  517. -- msh_count=0
  518. for i = 1 to msh_count do(
  519. pb1.value = 100.*i/msh_count
  520. vertArray=#();vertArray[(mshHeader[i][3])]=[0,0,0]
  521. uvwArray=#();uvwArray[(mshHeader[i][3])]=[0,0,0]
  522. normArray=#();normArray[(mshHeader[i][3])]=[0,0,0]
  523. faceArray=#()
  524. boneIDArray=#();boneIDArray[(mshHeader[i][3])]=[0,0,0,0]
  525. weightArray=#();weightArray[(mshHeader[i][3])]=[0,0,0,0]
  526.  
  527. fseek f bigInfo[(mshHeader[i][1])][3] #seek_set
  528. case of (
  529. (geoInfo.type[i]==27): ( -- hair, or other objects using opacity
  530. for x = 1 to mshHeader[i][3] do(
  531.  
  532. vx = readfloat f * mscale
  533. vy = readfloat f * mscale
  534. vz = readfloat f * mscale
  535. tu = readfloat f
  536. tv = (readfloat f * -1) + 1
  537. w1 = (readbyte f #unsigned as float)/255.0
  538. w2 = (readbyte f #unsigned as float)/255.0
  539. w3 = (readbyte f #unsigned as float)/255.0
  540. w4 = (readbyte f #unsigned as float)/255.0
  541. -- if mshNames[i]=="geo_headShape" do (
  542. --
  543. -- print [w1,w2,w3,w4]
  544. -- Print ("Last Read @ 0x"+((bit.intAsHex(ftell f))as string))
  545. --
  546. -- )
  547. b1 = (((readbyte f #unsigned/3)+1)+geoInfo.uknC[i])
  548. b2 = (((readbyte f #unsigned/3)+1)+geoInfo.uknC[i])
  549. b3 = (((readbyte f #unsigned/3)+1)+geoInfo.uknC[i])
  550. b4 = (((readbyte f #unsigned/3)+1)+geoInfo.uknC[i])
  551. -- if (b1+b2+b3+b4)==0 do b1=1
  552. -- if b1!=0 do b1+=geoInfo.uknC[i]
  553. -- if b2!=0 do b2+=geoInfo.uknC[i]
  554. -- if b3!=0 do b3+=geoInfo.uknC[i]
  555. -- if b4!=0 do b4+=geoInfo.uknC[i]
  556.  
  557.  
  558.  
  559.  
  560.  
  561. unk1 = readfloat f
  562. unk1 = readfloat f
  563. unk1 = readfloat f
  564. unk1 = readfloat f
  565. nx = readfloat f
  566. ny = readfloat f
  567. nz = readfloat f
  568.  
  569.  
  570. w1+=(1-(w1+w2+w3+w4))
  571.  
  572.  
  573. boneIDArray[x]=[b1,b2,b3,b4]
  574. weightArray[x]=[w1,w2,w3,w4]
  575.  
  576. vertArray[x]=[vx,-vz,vy]
  577. uvwArray[x]=[tu,tv,0]
  578. normArray[x]=[nx,-nz,ny]
  579. ))
  580. (geoInfo.type[i]==29): ( -- common skinned mesh
  581. for x = 1 to mshHeader[i][3] do(
  582.  
  583. vx = readfloat f * mscale
  584. vy = readfloat f * mscale
  585. vz = readfloat f * mscale
  586. tu = readfloat f
  587. tv = (readfloat f * -1) + 1
  588. w1 = (readbyte f #unsigned as float)/255.0
  589. w2 = (readbyte f #unsigned as float)/255.0
  590. w3 = (readbyte f #unsigned as float)/255.0
  591. w4 = (readbyte f #unsigned as float)/255.0
  592. -- if mshNames[i]=="geo_headShape" do (
  593. --
  594. -- print [w1,w2,w3,w4]
  595. -- Print ("Last Read @ 0x"+((bit.intAsHex(ftell f))as string))
  596. --
  597. -- )
  598. b1 = (((readbyte f #unsigned/3)+1)+geoInfo.uknC[i])
  599. b2 = (((readbyte f #unsigned/3)+1)+geoInfo.uknC[i])
  600. b3 = (((readbyte f #unsigned/3)+1)+geoInfo.uknC[i])
  601. b4 = (((readbyte f #unsigned/3)+1)+geoInfo.uknC[i])
  602. -- if (b1+b2+b3+b4)==0 do b1=1
  603. -- if b1!=0 do b1+=geoInfo.uknC[i]
  604. -- if b2!=0 do b2+=geoInfo.uknC[i]
  605. -- if b3!=0 do b3+=geoInfo.uknC[i]
  606. -- if b4!=0 do b4+=geoInfo.uknC[i]
  607.  
  608.  
  609.  
  610. unk1 = readfloat f
  611. unk1 = readfloat f
  612. unk1 = readfloat f
  613. unk1 = readfloat f
  614. nx = readfloat f
  615. ny = readfloat f
  616. nz = readfloat f
  617.  
  618.  
  619. w1+=(1-(w1+w2+w3+w4))
  620.  
  621.  
  622. boneIDArray[x]=[b1,b2,b3,b4]
  623. weightArray[x]=[w1,w2,w3,w4]
  624.  
  625. vertArray[x]=[vx,-vz,vy]
  626. uvwArray[x]=[tu,tv,0]
  627. normArray[x]=[nx,-nz,ny]
  628. ))
  629. (geoInfo.type[i]==32): ( -- eyes, mouth, accessories, shoes, clothes?
  630. for x = 1 to mshHeader[i][3] do(
  631.  
  632. vx = readfloat f * mscale
  633. vy = readfloat f * mscale
  634. vz = readfloat f * mscale
  635. tu = readfloat f
  636. tv = (readfloat f * -1) + 1
  637. w1 = (readbyte f #unsigned as float)/255.0
  638. w2 = (readbyte f #unsigned as float)/255.0
  639. w3 = (readbyte f #unsigned as float)/255.0
  640. w4 = (readbyte f #unsigned as float)/255.0
  641. -- if mshNames[i]=="geo_headShape" do (
  642. --
  643. -- print [w1,w2,w3,w4]
  644. -- Print ("Last Read @ 0x"+((bit.intAsHex(ftell f))as string))
  645. --
  646. -- )
  647. b1 = (((readbyte f #unsigned/3)+1)+geoInfo.uknC[i])
  648. b2 = (((readbyte f #unsigned/3)+1)+geoInfo.uknC[i])
  649. b3 = (((readbyte f #unsigned/3)+1)+geoInfo.uknC[i])
  650. b4 = (((readbyte f #unsigned/3)+1)+geoInfo.uknC[i])
  651. -- if (b1+b2+b3+b4)==0 do b1=1
  652. -- if b1!=0 do b1+=geoInfo.uknC[i]
  653. -- if b2!=0 do b2+=geoInfo.uknC[i]
  654. -- if b3!=0 do b3+=geoInfo.uknC[i]
  655. -- if b4!=0 do b4+=geoInfo.uknC[i]
  656.  
  657.  
  658.  
  659. unk1 = readfloat f
  660. unk1 = readfloat f
  661. unk1 = readfloat f
  662. unk1 = readfloat f
  663. nx = readfloat f
  664. ny = readfloat f
  665. nz = readfloat f
  666.  
  667.  
  668. w1+=(1-(w1+w2+w3+w4))
  669.  
  670.  
  671. boneIDArray[x]=[b1,b2,b3,b4]
  672. weightArray[x]=[w1,w2,w3,w4]
  673.  
  674. vertArray[x]=[vx,-vz,vy]
  675. uvwArray[x]=[tu,tv,0]
  676. normArray[x]=[nx,-nz,ny]
  677. ))
  678. (geoInfo.type[i]==30): (
  679. for x = 1 to mshHeader[i][3] do(
  680. vx = readfloat f * mscale
  681. vy = readfloat f * mscale
  682. vz = readfloat f * mscale
  683. ukn = readfloat f -- always -1?
  684. ukn = readfloat f -- always -1?
  685. boneIDArray[x]=[1,0,0,0]
  686. weightArray[x]=[1,0,0,0]
  687. vertArray[x]=[vx,-vz,vy]
  688. uvwArray[x]=[0,0,0]
  689. normArray[x]=[0,0,0]
  690. )
  691.  
  692.  
  693. )
  694.  
  695. (geoInfo.type[i]==14): (
  696. for x = 1 to mshHeader[i][3] do(
  697. vx = readfloat f * mscale
  698. vy = readfloat f * mscale
  699. vz = readfloat f * mscale
  700. ukn = readfloat f -- always -1?
  701. boneIDArray[x]=1
  702. weightArray[x]=1
  703. vertArray[x]=[vx,-vz,vy]
  704. uvwArray[x]=[0,0,0]
  705. normArray[x]=[0,0,0]
  706. )
  707.  
  708.  
  709. )
  710.  
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719.  
  720. )
  721.  
  722. fseek f bigInfo[(mshHeader[i][2])][3] #seek_set
  723. if drawInfo[i]==4 then(
  724. StartDirection = -1
  725. fa =readshort f #unsigned + 1
  726. fb =readshort f #unsigned + 1
  727. FaceDirection = StartDirection
  728. IndexCounter = 2
  729. Do (
  730. fc =readshort f #unsigned
  731. IndexCounter += 1
  732. if (fc==0xFFFF) then (
  733. fa =readshort f #unsigned + 1
  734. fb =readshort f #unsigned + 1
  735. FaceDirection = StartDirection
  736. IndexCounter += 2
  737. ) else (
  738. fc += 1
  739. FaceDirection *= -1
  740. if (fa!=fb)AND(fb!=fc)AND(fc!=fa) then (
  741. if FaceDirection > 0 then append faceArray [fa,fb,fc]
  742. else append faceArray [fa,fc,fb]
  743. )
  744. fa = fb
  745. fb = fc
  746. )
  747. )
  748. while IndexCounter !=mshHeader[i][4]
  749. )else(
  750. for x = 1 to (mshHeader[i][4]/3) do(
  751. fa=readshort f #unsigned+1
  752. fb=readshort f #unsigned+1
  753. fc=readshort f #unsigned+1
  754.  
  755. append faceArray[fa,fb,fc]
  756. )
  757. )
  758.  
  759.  
  760.  
  761. -- if geoInfo.type[i]==27 do(
  762.  
  763.  
  764. msh = mesh vertices:vertArray faces:faceArray
  765. msh.numTVerts = vertArray.count
  766. buildTVFaces msh
  767. -- msh.name = ((i as string)+" "+mshNames[i])
  768. msh.name = mshNames[i]
  769. msh.material=mm.materialList[(matIndex[i])]
  770.  
  771. setUserProp msh "MatID" (geoInfo.matID[i]-1)
  772.  
  773. for j = 1 to vertArray.count do setTVert msh j uvwArray[j]
  774. if geoInfo.type[i]==29 do for j = 1 to vertArray.count do setNormal msh j normArray[j] -- Normals Don't Stick, lost when modifers are added
  775. for j = 1 to faceArray.count do setTVFace msh j faceArray[j]
  776.  
  777.  
  778.  
  779. if skinON==true do(
  780.  
  781.  
  782. select msh
  783. max modify mode
  784. skinMod = skin ()
  785. addModifier msh skinMod
  786. for x = 1 to BNArr.count do (
  787. if x!=BNArr.count
  788. then skinOps.addbone skinMod (BNArr[x]) 0
  789. else skinOps.addbone skinMod (BNArr[x]) 1
  790. )
  791. modPanel.setCurrentObject skinMod
  792. for x = 1 to weightArray.count do(
  793. bi = #() --bone index array
  794. wv = #() --weight value array
  795. for j = 1 to 4 do (
  796. boneid = boneIDArray[x][j]
  797. weight = weightArray[x][j]
  798. -- if boneid>=98 do (
  799. -- print "bad"
  800. -- boneid=1
  801. --
  802. -- )
  803. if weight!=0 do(
  804. append bi boneid
  805. append wv weight
  806. )
  807. )
  808.  
  809. skinOps.ReplaceVertexWeights skinMod x bi wv
  810. )
  811. ) --enable skin loop
  812.  
  813. if normON==true do(
  814. select msh
  815. max modify mode
  816. normMod = Edit_Normals()
  817. addModifier msh normMod
  818. normMod.displayLength = 0
  819. my_verts = #{1..(normMod.GetNumNormals node:msh)}
  820. normMod.SetSelection my_verts node:msh
  821. normMod.Break ()
  822. for n = 1 to (normMod.GetNumFaces node:msh) do(
  823. vertID=getFace msh n
  824. for c = 1 to 3 do(
  825. normID=normMod.GetNormalID n c node:msh
  826. normMod.EditNormalsMod.SetNormal normID normArray[(vertID[c])] node:msh
  827. normMod.SetNormal normID normArray[(vertID[c])] node:msh
  828. normMod.EditNormalsMod.MakeExplicit ()
  829. ))
  830. subobjectLevel = 0
  831. )
  832.  
  833.  
  834. -- addModifier msh2 normMod
  835.  
  836.  
  837.  
  838.  
  839.  
  840.  
  841.  
  842.  
  843.  
  844.  
  845.  
  846.  
  847.  
  848.  
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855. )
  856. pb1.value = 0
  857.  
  858.  
  859. PRINT "DONE!!!!"
  860. Print ("Last Read @ 0x"+((bit.intAsHex(ftell f))as string))
  861. fclose g
  862. fclose f
  863. )else(Print "No Scene Data")))) else (Print "Aborted.")
  864. ) --end import
  865.  
  866. on btn2 pressed do(
  867.  
  868.  
  869.  
  870.  
  871.  
  872.  
  873. obj=selection
  874. if obj.count!=0 then(
  875.  
  876. -- fsource="M:\\Dead.Rising.2.Off.The.Record-KaOs\\data\\models\\Errors\\srv_madison\\srv_madison (MOD).big"
  877.  
  878. fsource = GetOpenFileName \
  879. caption:"Select a BIG File to Inject to" \
  880. types: "Big files (*.big)|*.BIG|"
  881.  
  882. if (fsource!=undefined) AND ((doesFileExist fsource)==true) then(
  883.  
  884. if chk1.checked==true do(
  885. num=1
  886. newfile=(fsource+".bak"+(num as string))
  887. while ((doesFileExist newfile)!=false) do(
  888. num+=1
  889. newfile=(fsource+".bak"+(num as string))
  890. )
  891. copyFile fsource newfile
  892. )
  893.  
  894. f = fopen fsource "r+"
  895.  
  896.  
  897. undo off(;with redraw off (
  898.  
  899.  
  900. bigInfo=readbig f
  901.  
  902. fseek f bigInfo[1][2] #seek_set
  903. names=#();names[bigInfo.count]=""
  904. namesD=#();namesD[bigInfo.count]=""
  905. namesA=#();namesA[bigInfo.count]=""
  906. for i = 1 to bigInfo.count do(
  907. names[i]=readstring f
  908. baseName=names[i] as stringstream
  909. namesD[i]=readDelimitedString baseName " "
  910. namesA[i]=readDelimitedString baseName " "
  911. )
  912.  
  913.  
  914. find=findItem names "SceneHeader"
  915. if find!=0 then(
  916. fseek f (bigInfo[find][3]+12) #seek_set
  917. msh_count=readlong f #unsigned
  918.  
  919. fseek f bigInfo[(findItem names "SceneDescription")][3] #seek_set
  920. mshNames=#();mshNames[msh_count]=""
  921. for i = 1 to msh_count do(mshNames[i]=ReadFixedString f 36)
  922.  
  923.  
  924. for i = 1 to obj.count do(
  925. vidx=0
  926. fidx=0
  927. for x = 1 to 2 do(
  928. find=findItem namesD obj[i].name
  929. case of(
  930. (namesA[find]=="Vertices"): (vidx=find)
  931. (namesA[find]=="Indices"): (fidx=find)
  932. )
  933. namesD[find]=""
  934. )
  935. if vidx!=0 AND fidx!=0 then(
  936. tmesh = snapshotAsMesh obj[i]
  937. num_verts = tmesh.numverts
  938. num_faces = tmesh.numfaces
  939. if (bigInfo[vidx][4]/56)==num_verts then(
  940. fseek f bigInfo[vidx][3] #seek_set
  941. for x = 1 to num_verts do(
  942. vert = getVert tmesh x
  943. tvert = getTVert tmesh x
  944. -- norm = getNormal tmesh x
  945. writefloat f (vert.x/mscale)
  946. writefloat f (vert.z/mscale)
  947. writefloat f (vert.y/-mscale)
  948. writefloat f tvert.x
  949. writefloat f ((tvert.y * -1) +1)
  950. -- fseek f 1 #seek_cur -- w1
  951. -- fseek f 1 #seek_cur -- w2
  952. -- fseek f 1 #seek_cur -- w3
  953. -- fseek f 1 #seek_cur -- w4
  954. -- fseek f 1 #seek_cur -- b1
  955. -- fseek f 1 #seek_cur -- b2
  956. -- fseek f 1 #seek_cur -- b3
  957. -- fseek f 1 #seek_cur -- b4
  958. -- fseek f 4 #seek_cur -- unknown?
  959. -- fseek f 4 #seek_cur -- unknown?
  960. -- fseek f 4 #seek_cur -- unknown?
  961. -- fseek f 4 #seek_cur -- unknown?
  962. -- writefloat f norm.x
  963. -- writefloat f norm.z
  964. -- writefloat f norm.y
  965. fseek f 36 #seek_cur -- skips the rest
  966. ))else(
  967. faceArray=#()
  968. fseek f bigInfo[fidx][3] #seek_set
  969. if ((bigInfo[fidx][4]/2)/3)==num_faces then(
  970. for x = 1 to num_faces do(
  971. fa=readshort f #unsigned+1
  972. fb=readshort f #unsigned+1
  973. fc=readshort f #unsigned+1
  974. append faceArray[fa,fb,fc])
  975. )else(StartDirection = -1
  976. fa =readshort f #unsigned + 1
  977. fb =readshort f #unsigned + 1
  978. FaceDirection = StartDirection
  979. IndexCounter = 2;Do (
  980. fc =readshort f #unsigned
  981. IndexCounter += 1
  982. if (fc==0xFFFF) then (
  983. fa =readshort f #unsigned + 1
  984. fb =readshort f #unsigned + 1
  985. FaceDirection = StartDirection;IndexCounter += 2
  986. ) else (fc += 1;FaceDirection *= -1
  987. if (fa!=fb)AND(fb!=fc)AND(fc!=fa) then (
  988. if FaceDirection > 0 then append faceArray [fa,fb,fc]
  989. else (append faceArray [fa,fc,fb]));fa = fb;fb = fc
  990. ))while IndexCounter !=(bigInfo[fidx][4]/2)
  991. if num_faces!=faceArray.count do (faceArray=#()))
  992.  
  993. if faceArray.count!=0 then(
  994. vertArray=#();vertArray[(bigInfo[vidx][4]/56)]=[0,0,0];for x = 1 to (bigInfo[vidx][4]/56) do (vertArray=[0,0,0])
  995. uvwArray=#();uvwArray[(bigInfo[vidx][4]/56)]=[0,0,0];for x = 1 to (bigInfo[vidx][4]/56) do (uvwArray=[0,0,0])
  996. -- normArray=#();normArray[(bigInfo[vidx][4]/56)]=[0,0,0];for x = 1 to (bigInfo[vidx][4]/56) do (normArray=[0,0,0])
  997.  
  998. for y = 1 to faceArray.count do(
  999. face=faceArray[y]
  1000. for x = 1 to 3 do(
  1001. vertArray[(face[x])]=getVert tmesh face[x]
  1002. uvwArray[(face[x])]=getTVert tmesh face[x])
  1003. -- normArray[(face[x])]=getTVert tmesh face[x])
  1004. )
  1005.  
  1006. for x = 1 to (bigInfo[vidx][4]/56) do(
  1007. vert = vertArray[x]
  1008. tvert = uvwArray[x]
  1009. -- norm = normArray[x]
  1010. writefloat f (vert.x/mscale)
  1011. writefloat f (vert.z/mscale)
  1012. writefloat f (vert.y/-mscale)
  1013. writefloat f tvert.x
  1014. writefloat f ((tvert.y * -1) +1)
  1015. -- fseek f 1 #seek_cur -- w1
  1016. -- fseek f 1 #seek_cur -- w2
  1017. -- fseek f 1 #seek_cur -- w3
  1018. -- fseek f 1 #seek_cur -- w4
  1019. -- fseek f 1 #seek_cur -- b1
  1020. -- fseek f 1 #seek_cur -- b2
  1021. -- fseek f 1 #seek_cur -- b3
  1022. -- fseek f 1 #seek_cur -- b4
  1023. -- fseek f 4 #seek_cur -- unknown?
  1024. -- fseek f 4 #seek_cur -- unknown?
  1025. -- fseek f 4 #seek_cur -- unknown?
  1026. -- fseek f 4 #seek_cur -- unknown?
  1027. -- writefloat f norm.x
  1028. -- writefloat f norm.z
  1029. -- writefloat f norm.y
  1030. fseek f 36 #seek_cur -- skips the rest
  1031. ))else(errors+=(obj[i].name+"tttt\n")));delete tmesh)else(errors+=(obj[i].name+"\n")))
  1032. fflush f
  1033.  
  1034. )else(Print "No Scene Data")))
  1035.  
  1036. fclose f
  1037. ) else (Print "Aborted."))else(MessageBox "Nothing Selected?")
  1038.  
  1039.  
  1040.  
  1041.  
  1042.  
  1043. ) --end inject
  1044.  
  1045. on btn3 pressed do( -- export
  1046.  
  1047. -- skinON=chk2.checked
  1048. matON=chk3.checked
  1049. matID=edt1.text as integer
  1050. -- OBJ=$*;DELETE OBJ
  1051.  
  1052. if selection.count==1 then(
  1053. fsource = GetOpenFileName \
  1054. caption:"[PC] Dead Rising 2:OTR - \"persistent.big\" Patcher \\ Model Exporter" \
  1055. types: "Big files (*.big)|*.BIG|"
  1056. -- if chk1.checked==true do(
  1057. -- num=1
  1058. -- newfile=(fsource+".bak"+(num as string))
  1059. -- while ((doesFileExist newfile)!=false) do(
  1060. -- num+=1
  1061. -- newfile=(fsource+".bak"+(num as string))
  1062. -- )
  1063. -- copyFile fsource newfile
  1064. -- )
  1065. if (fsource!=undefined) AND ((doesFileExist fsource)==true) then(
  1066. f = fopen fsource "r+"
  1067. -- fext= getFilenameType fsource
  1068. fpath= getFilenamePath fsource
  1069. -- fname= getFilenameFile fsource
  1070. -- fsize= getFileSize fsource
  1071. perBIG=readbig f
  1072. fseek f perBIG[1][2] #seek_set
  1073. names=#();names[perBIG.count]=""
  1074. seekArray=#()
  1075. for i = 1 to perBIG.count do(names[i]=readstring f)
  1076. for i = 1 to names.count do(
  1077. fullName=names[i] as stringstream
  1078. baseName=(readDelimitedString fullName " ")
  1079. compName=(readDelimitedString fullName" ")
  1080.  
  1081. if baseName==selection[1].name do(
  1082. classesArr = #("RenderStrip","VBHeader","IBHeader","CommandBuffer")
  1083. find=findItem classesArr compName;if find!=0 do append seekArray i))
  1084.  
  1085.  
  1086.  
  1087. if seekArray.count==4 then(
  1088.  
  1089. tmesh = selection[1]
  1090. num_verts = tmesh.numverts
  1091. num_tverts = tmesh.numtverts
  1092. num_faces = tmesh.numfaces
  1093. skinMod=undefined
  1094. bone_count=0
  1095. for i = 1 to tmesh.modifiers.count do ( -- Get Skin Data
  1096. if classOf tmesh.modifiers[i]==Skin do (
  1097. skinMod=tmesh.modifiers[i]))
  1098.  
  1099. struct bone_data(name,position,parent,child)
  1100. struct mesh_data(faces,vertices)
  1101. struct mesh_data(name,matname,faces,vertices,matinfo)
  1102. struct vertex_data(position,normal,tangent,colour,texture1,texture2,texture3,boneids,weights)
  1103. struct material_data(diffmap,dirtmap,specmap,normmap,bumpmap1,bumpmap2,maskmap,envmap)
  1104. meshBuffer = (mesh_data faces:#() vertices:#())
  1105. matBuffer = (material_data diffmap:#() dirtmap:#() specmap:#() normmap:#() bumpmap1:#() bumpmap2:#() maskmap:#() envmap:#())
  1106. meshBuffer = (mesh_data name:#() matname:#() faces:#() vertices:#() matinfo:#())
  1107. vertBuffer = (vertex_data position:#() normal:#() tangent:#() colour:#() texture1:#() texture2:#() texture3:#() boneids:#() weights:#())
  1108. boneBuffer = (bone_data name:#() position:#() parent:#() child:#())
  1109. vertBuffer.position [(num_faces*3)] = [0,0,0]
  1110. vertBuffer.normal [(num_faces*3)] = [0,0,0]
  1111. vertBuffer.tangent [(num_faces*3)] = [0,0,0]
  1112. vertBuffer.colour [(num_faces*3)] = [0,0,0]
  1113. vertBuffer.texture1 [(num_faces*3)] = [0,0,0]
  1114. vertBuffer.texture2 [(num_faces*3)] = [0,0,0]
  1115. vertBuffer.texture3 [(num_faces*3)] = [0,0,0]
  1116. vertBuffer.boneids [(num_faces*3)] = [0,0,0,0]
  1117. vertBuffer.weights [(num_faces*3)] = [0,0,0,0]
  1118. weightBuffer=#();weightBuffer[num_verts]=0.0
  1119. boneIDBuffer=#();boneIDBuffer[num_verts]=0
  1120. vertCollection=#() -- arrays reset on each mesh / material ID
  1121. normCollection=#()
  1122. tvertCollection=#()
  1123. faceCollection=#()
  1124. boneCheck=#()
  1125. vertCollection[(num_faces*3)] = [0,0,0,0]
  1126. normCollection[(num_faces*3)] = [0,0,0]
  1127. tvertCollection[(num_faces*3)] = [0,0,0,0]
  1128. faceCollection[num_faces] = [0,0]
  1129. faceBuffer=#()
  1130. faceBuffer[(num_faces*3)]=0
  1131.  
  1132. boneMin=1024
  1133. boneMax=0
  1134. undo off(;with redraw off (
  1135. if skinMod!=undefined then (
  1136. max modify mode
  1137. modPanel.setCurrentObject skinMod
  1138. bone_count=skinOps.GetNumberBones skinMod
  1139. skinOps.RemoveZeroWeights skinMod
  1140. for i = 1 to tmesh.numverts do(
  1141. vertex_bone_count = skinOps.GetVertexWeightCount skinMod i -- #of weights per vert
  1142. if vertex_bone_count!=0 then(
  1143. weightCollection=#();weightCollection[vertex_bone_count]=0.0
  1144. boneidCollection=#();boneidCollection[vertex_bone_count]=0
  1145. for x = 1 to vertex_bone_count do(
  1146. bone_weight = skinops.getvertexweight skinMod i x
  1147. bone_index = skinOps.GetVertexWeightBoneID skinMod i x
  1148. if bone_index==0 do bone_index=1
  1149. if bone_index<=boneMin do boneMin=bone_index
  1150. if bone_index>=boneMax do boneMax=bone_index
  1151. if x<=4 do ( -- limits to four bones weights per vertex
  1152. weightCollection[x]=bone_weight
  1153. boneidCollection[x]=bone_index))
  1154. )else( --dead weight found, nothing fancy just append weight to bone1
  1155. weightCollection=#();weightCollection[1]=0.0
  1156. boneidCollection=#();boneidCollection[1]=0
  1157. bone_index = 1
  1158. weightCollection[1]=1.0
  1159. boneidCollection[1]=1)
  1160. if vertex_bone_count<=4 then (
  1161. for x = (vertex_bone_count+1) to 4 do(
  1162. weightCollection[x]=0
  1163. boneidCollection[x]=0))
  1164. else(
  1165. w=weightCollection[1]+weightCollection[2]+weightCollection[3]+weightCollection[4]
  1166. d=1-w;weightCollection[1]=(weightCollection[1]+d))
  1167. b1=boneidCollection[1]--1 -- convert to base 0
  1168. b2=boneidCollection[2]--1
  1169. b3=boneidCollection[3]--1
  1170. b4=boneidCollection[4]--1
  1171. -- if b1<=0 do b1=0
  1172. -- if b2<=0 do b2=0
  1173. -- if b3<=0 do b3=0
  1174. -- if b4<=0 do b4=0
  1175. boneIDBuffer[i]=[b1,b2,b3,b4]
  1176. weightBuffer[i]=[(weightCollection[1]),(weightCollection[2]),(weightCollection[3]),(weightCollection[4])]
  1177. ))else(
  1178. for x = 1 to tmesh.numverts do( -- static mesh, fix skin info
  1179. weightBuffer[x]=[1,0,0,0]
  1180. if tmesh.parent!=undefined
  1181. then boneid=findItem boneBuffer.name tmesh.parent.name -- weight to a possible parent
  1182. else boneid=findItem boneBuffer.name tmesh.name -- if no parent weight to scene root
  1183. boneid-=1 -- convert to base 0
  1184. if boneid<=0 do boneid=0 -- convert to base 0
  1185. boneIDBuffer[x]=[boneid,0,0,0]))
  1186. boneMin-=1
  1187.  
  1188. vertCount=0 -- Counts used to index through my arrays
  1189. faceCount=0
  1190.  
  1191. modNorm = Edit_Normals ()
  1192. addModifier selection[1] modNorm
  1193. tan1 =#();tan1[(num_verts * 2)] = [0,0,0]
  1194. tan2 =#();tan2[((num_verts * 2) + num_verts)] = [0,0,0]
  1195. -- nom =#();nom[(num_verts)]=[0,0,0]
  1196. for i = 1 to tan1.count do tan1[i]=[0,0,0]
  1197. for i = 1 to tan2.count do tan2[i]=[0,0,0]
  1198. -- for i = 1 to nom.count do nom[i]=[0,0,0]
  1199.  
  1200. tangent=#()
  1201. for y = 1 to num_faces do
  1202. (
  1203. vertexIndices = getFace tmesh y
  1204. textureIndices = getTVFace tmesh y
  1205.  
  1206.  
  1207.  
  1208. i1 = vertexIndices[1]
  1209. i2 = vertexIndices[2]
  1210. i3 = vertexIndices[3]
  1211. i4 = textureIndices[1]
  1212. i5 = textureIndices[2]
  1213. i6 = textureIndices[3]
  1214. v1 = getVert tmesh i1
  1215. v2 = getVert tmesh i2
  1216. v3 = getVert tmesh i3
  1217.  
  1218. W1 = getTVert tmesh i4
  1219. W2 = getTVert tmesh i5
  1220. W3 = getTVert tmesh i6
  1221.  
  1222. x1 = v2[1] - v1[1]
  1223. x2 = v3[1] - v1[1]
  1224. y1 = v2[2] - v1[2]
  1225. y2 = v3[2] - v1[2]
  1226. z1 = v2[3] - v1[3]
  1227. z2 = v3[3] - v1[3]
  1228.  
  1229. s1 = w2[1] - w1[1]
  1230. s2 = w3[1] - w1[1]
  1231. t1 = w2[2] - w1[2]
  1232. t2 = w3[2] - w1[2]
  1233.  
  1234. r = 1.0 / (s1 * t2 - s2 * t1)
  1235.  
  1236. sdir = [((t2 * x1 - t1 * x2) * r),((t2 * y1 - t1 * y2) * r),((t2 * z1 - t1 * z2) * r)]
  1237. tdir = [((s1 * x2 - s2 * x1) * r),((s1 * y2 - s2 * y1) * r),((s1 * z2 - s2 * z1) * r)]
  1238.  
  1239. tan1[i1] += sdir
  1240. tan1[i2] += sdir
  1241. tan1[i3] += sdir
  1242.  
  1243. tan2[i1] += tdir
  1244. tan2[i2] += tdir
  1245. tan2[i3] += tdir
  1246.  
  1247. -- nom[i1]=modNorm.GetNormal (modNorm.GetNormalID i 1) node:selection[1]
  1248. -- nom[i2]=modNorm.GetNormal (modNorm.GetNormalID i 2) node:selection[1]
  1249. -- nom[i3]=modNorm.GetNormal (modNorm.GetNormalID i 3) node:selection[1]
  1250. )
  1251. -- deletemodifier selection[1] modNorm
  1252. tangent=#()
  1253. faceCounter=0
  1254. count=0 -- count for resetable arrays
  1255. for x = 1 to num_faces do (
  1256. findex=getFace tmesh x
  1257. tindex=getTVFace tmesh x
  1258.  
  1259.  
  1260. for y = 1 to 3 do(
  1261. vert=getVert tmesh findex[y]
  1262. tvert=getTVert tmesh tindex[y]
  1263. norm=modNorm.GetNormal (modNorm.GetNormalID x y)
  1264.  
  1265. n = norm
  1266. t = tan1[(findex[y])]
  1267.  
  1268. -- Gram-Schmidt orthogonalize
  1269. tangent=[0,0,0,-nmV]
  1270. tang = (t - n * (Dot n t))
  1271. if nmR=true do tang[1]=-tang[1]
  1272. if nmG=true do tang[2]=-tang[2]
  1273. tangent[1]=tang[1]
  1274. tangent[2]=tang[2]
  1275. tangent[3]=tang[3]
  1276. if nmS=true do (tangent[1]=tang[2];tangent[2]=tang[1])
  1277.  
  1278. -- Calculate handedness
  1279. if (Dot (Cross n t) tan2[(findex[y])]) >=0 do tangent[4] = nmV
  1280.  
  1281. vertCull=findItem vertCollection [vert.x,vert.y,vert.z,(findex[y])]
  1282. tvertCull=findItem tvertCollection [tvert.x,tvert.y,0,(tindex[y])]
  1283. normCull=findItem normCollection norm
  1284. if vertCull!=0 do (if normCollection[vertCull]!=norm do normCull=0)
  1285. if vertCull!=tvertCull OR vertCull==0 OR normCull==0 then( --not found
  1286. count+=1;faceCount+=1;vertCount+=1
  1287. vertCollection[count]=[vert.x,vert.y,vert.z,(findex[y])]
  1288. tvertCollection[count]=[tvert.x,tvert.y,0,(tindex[y])]
  1289. normCollection[count]=norm
  1290. vertBuffer.position[vertCount]=[vert.x,vert.y,vert.z,(findex[y])] -- Face ID is left, relates to the Skin Weight
  1291. vertBuffer.texture1[vertCount]=[tvert.x,tvert.y,0]
  1292. vertBuffer.colour[vertCount]=cvert
  1293. vertBuffer.normal[vertCount]=norm
  1294. vertBuffer.tangent[vertCount]=[(tangent[1]),(tangent[2]),(tangent[3]),(tangent[4])]
  1295. vertBuffer.boneids[vertCount]=boneIDBuffer[(findex[y])]
  1296. vertBuffer.weights[vertCount]=weightBuffer[(findex[y])]
  1297. faceBuffer[faceCount]=count
  1298. )else(faceCount+=1;faceBuffer[faceCount]=vertCull)
  1299.  
  1300.  
  1301.  
  1302.  
  1303.  
  1304.  
  1305.  
  1306.  
  1307.  
  1308.  
  1309.  
  1310. )
  1311.  
  1312.  
  1313.  
  1314.  
  1315. faceCounter+=1
  1316.  
  1317.  
  1318.  
  1319. )
  1320.  
  1321. deleteModifier tmesh modNorm
  1322.  
  1323. print ("Vert Count: "+(count as string))
  1324. print ("Face Count: "+(faceCounter as string))
  1325. ))
  1326.  
  1327.  
  1328.  
  1329.  
  1330.  
  1331.  
  1332.  
  1333.  
  1334.  
  1335.  
  1336.  
  1337.  
  1338.  
  1339.  
  1340.  
  1341.  
  1342.  
  1343.  
  1344.  
  1345. --oldVcount=0 -- may use to check commandbuffer
  1346. --oldFcount=0 -- may use to check commandbuffer
  1347. vbName=""
  1348. ibName=""
  1349. cbOffset=0
  1350. for x = 1 to 4 do(
  1351. fullName=names[(seekArray[x])] as stringstream
  1352. baseName=(readDelimitedString fullName " ")
  1353. compName=(readDelimitedString fullName" ")
  1354. fseek f (perBIG[(seekArray[x])][3]) #seek_set
  1355. case of(
  1356. (compName=="RenderStrip"): (
  1357. if matON==true then(writelong f matID)else(fseek f 4 #seek_cur)
  1358. -- fseek f 0 #seek_cur
  1359. -- writelong s 63
  1360. -- writelong s 0
  1361. fseek f 4 #seek_cur --63
  1362. fseek f 4 #seek_cur -- 0
  1363. writelong f boneMin #unsigned -- start bone
  1364. writelong f (boneMax-boneMin) #unsigned-- end bone
  1365. fseek f 4 #seek_cur -- 0
  1366. -- writelong f 0x1D -- vertex type, just force type 29
  1367. )
  1368. (compName=="VBHeader"): (
  1369. vbName=ReadFixedString f 36
  1370. fseek f 4 #seek_cur -- (-1), endline
  1371. --oldVcount=readlong f #unsigned;fseek f -4 #seek_cur
  1372. writelong f count
  1373. writelong f 56) -- relates to vertexType, force 56bytes per vertex definition
  1374. (compName=="IBHeader"): (
  1375. ibName=ReadFixedString f 36
  1376. fseek f 4 #seek_cur -- (-1), endline
  1377. --oldFcount=readlong f #unsigned;fseek f -4 #seek_cur
  1378. writelong f faceBuffer.count)
  1379. (compName=="CommandBuffer"): (
  1380. cbOffset=seekArray[x]
  1381. )
  1382. )
  1383. )
  1384.  
  1385. fseek f perBIG[cbOffset][3] #seek_set
  1386. print perBIG[cbOffset][3]
  1387. thingfound=false
  1388. while (ftell f)!=(perBIG[cbOffset][3]+perBIG[cbOffset][4]) do(
  1389.  
  1390. if (readbyte f)==11 do(
  1391. if thingfound==false do(
  1392. if (readbyte f)==0 do(
  1393.  
  1394. if (readbyte f)==0 do(
  1395. if (readbyte f)==0 do(
  1396. if (readbyte f)==8 do(
  1397. thingfound=true
  1398. getPos=ftell f
  1399. fseek f getPos #seek_set
  1400. writebyte f 3
  1401. fseek f (getPos+11) #seek_set
  1402. writelong f count #unsigned --vertex count
  1403.  
  1404. fseek f (getPos+19) #seek_set
  1405. writelong f faceBuffer.count #unsigned --face count
  1406. fseek f 0 #seek_set
  1407. fflush f
  1408. )
  1409.  
  1410. )
  1411.  
  1412. )
  1413. )
  1414. )
  1415. )
  1416. )
  1417. fflush f
  1418. fclose f
  1419.  
  1420. fullName=ibName as stringstream
  1421. baseName=(readDelimitedString fullName " ")
  1422. compName=(readDelimitedString fullName" ")
  1423. -- createFile (fpath+(baseName+" Indices "+compName))
  1424. spath=(fpath+(baseName+" Indices "+compName))
  1425. if doesFileExist spath==true then(
  1426. s = fopen spath "wb"
  1427. ftr=1
  1428. for x = 1 to faceCounter do(
  1429. fa=faceBuffer[(ftr)]-1;ftr+=1
  1430. fb=faceBuffer[(ftr)]-1;ftr+=1
  1431. fc=faceBuffer[(ftr)]-1;ftr+=1
  1432. writeshort s fa #unsigned
  1433. writeshort s fb #unsigned
  1434. writeshort s fc #unsigned
  1435. )
  1436. fflush s
  1437. fclose s
  1438. )else(MessageBox "Error Opening:\n"+(baseName+" Indices "+compName))
  1439.  
  1440. fullName=vbName as stringstream
  1441. baseName=(readDelimitedString fullName " ")
  1442. compName=(readDelimitedString fullName" ")
  1443. -- createFile (fpath+(baseName+" Vertices "+compName))
  1444. spath=(fpath+(baseName+" Vertices "+compName))
  1445. if doesFileExist spath==true then(
  1446. s = fopen (fpath+(baseName+" Vertices "+compName)) "wb"
  1447. for x = 1 to count do(
  1448. writefloat s (vertBuffer.position[x][1]/mscale)
  1449. writefloat s (vertBuffer.position[x][3]/mscale)
  1450. writefloat s (vertBuffer.position[x][2]/-mscale)
  1451. writefloat s vertBuffer.texture1[x][1]
  1452. writefloat s ((vertBuffer.texture1[x][2] * -1) +1)
  1453. w1=floor (vertBuffer.weights[x][1]*0xFF)
  1454. w2=floor (vertBuffer.weights[x][2]*0xFF)
  1455. w3=floor (vertBuffer.weights[x][3]*0xFF)
  1456. w4=floor (vertBuffer.weights[x][4]*0xFF)
  1457. w1+=(0xFF-(w1+w2+w3+w4))
  1458.  
  1459. writebyte s w1 #unsigned
  1460. writebyte s w2 #unsigned
  1461. writebyte s w3 #unsigned
  1462. writebyte s w4 #unsigned
  1463. b1=((vertBuffer.boneids[x][1]-(boneMin+1))*3);if b1<=0 do b1=0
  1464. b2=((vertBuffer.boneids[x][2]-(boneMin+1))*3);if b2<=0 do b2=0
  1465. b3=((vertBuffer.boneids[x][3]-(boneMin+1))*3);if b3<=0 do b3=0
  1466. b4=((vertBuffer.boneids[x][4]-(boneMin+1))*3);if b4<=0 do b4=0
  1467. writebyte s b1 #unsigned
  1468. writebyte s b2 #unsigned
  1469. writebyte s b3 #unsigned
  1470. writebyte s b4 #unsigned
  1471. writefloat s vertBuffer.tangent[x][1]
  1472. writefloat s vertBuffer.tangent[x][3]
  1473. writefloat s -vertBuffer.tangent[x][2]
  1474. writefloat s vertBuffer.tangent[x][4]
  1475. writefloat s vertBuffer.normal[x][1]
  1476. writefloat s vertBuffer.normal[x][3]
  1477. writefloat s -vertBuffer.normal[x][2]
  1478. pb1.value = 100.*x/count
  1479. )
  1480. fflush s
  1481. fclose s
  1482. )else(MessageBox "Error Opening:\n"+(baseName+" Vertices "+compName))
  1483.  
  1484. )else(MessageBox "ERROR\nFailed to Find Components In \"persistent.big\"")
  1485.  
  1486.  
  1487. pb1.value = 0
  1488. MessageBox "DONE!!!!"
  1489. ) else (Print "Aborted.")
  1490. )else(MessageBox "Please Only Select \"ONE\" object at a time")
  1491.  
  1492.  
  1493. -- gc light:true
  1494. ) -- end export
  1495.  
  1496.  
  1497. on btn4 pressed do( -- repack textures
  1498.  
  1499. fsource = GetOpenFileName \
  1500. caption:"Open a \"bigfile.xml\" to rebuild" \
  1501. types: "BIGFILE XML (*.xml)|*.xml|"
  1502. if (fsource!=undefined) AND ((doesFileExist fsource)==true) then(
  1503. f=MemStreamMgr.openFile fsource
  1504. fsize= f.size()
  1505. fext= getFilenameType fsource
  1506. fpath= getFilenamePath fsource
  1507. fname= getFilenameFile fsource
  1508. clearlistener()
  1509.  
  1510. rdxml=readBIGXML f;MemStreamMgr.close f
  1511. createFile (fpath+"bigfile.big")
  1512. f = fopen (fpath+"bigfile.big") "r+"
  1513. counter=1;fversion=0;filePaths=#()
  1514. struct bigstuff (name,type,t1,t2)
  1515. biginput=(bigstuff name:#() type:#() t2:#() t1:#())
  1516. for i = 1 to rdxml.count.count do(
  1517. itmN="";itmD=32;itmT1=0xE0;itmT2=0
  1518. for x = 1 to rdxml.count[i] do(
  1519. datName=rdxml.name[counter]
  1520. case of(;(datName=="version"): (fversion=rdxml.info[counter])
  1521. (datName=="name"): (itmN=rdxml.info[counter])
  1522. (datName=="alignment"): (itmD=rdxml.info[counter])
  1523. (datName=="tex01"): (itmT1=rdxml.info[counter])
  1524. (datName=="tex02"): (itmT2=rdxml.info[counter]);)
  1525. counter+= 1);if itmN!="" do(append biginput.name itmN
  1526. append biginput.type itmD;append biginput.t1 itmT1;append biginput.t2 itmT2))
  1527. filepaths=#();filepaths[biginput.name.count]="";nameSize=0
  1528. ddsInfo=#();ddsInfo[biginput.name.count]=[0,0,0,0]
  1529. fileSizes=#();fileSizes[biginput.name.count]=0
  1530. for i = 1 to biginput.name.count do (
  1531. texW=0
  1532. texH=0
  1533. texC=0
  1534. texM=0
  1535. fsize=1
  1536. spath=""
  1537. nameSize+=(biginput.name[i].count+1)
  1538. if doesFileExist (fpath+biginput.name[i])==true then(
  1539.  
  1540. spath=(fpath+biginput.name[i])
  1541. fsize=getFileSize spath
  1542. )else(
  1543. if doesFileExist (fpath+biginput.name[i]+".dds")==true do (
  1544. spath=(fpath+biginput.name[i]+".dds")
  1545. t = fopen spath "rb"
  1546. fseek t 12 #seek_set
  1547. texW=readlong t #unsigned
  1548. texH=readlong t #unsigned
  1549. fseek t 4 #seek_cur
  1550. texM=readlong t #unsigned
  1551. fseek t 0x54 #seek_set
  1552. texC=readFixedString t 4
  1553. case of(
  1554. (texC=="DXT1"): (texC=2)
  1555. (texC=="DXT5"): (texC=1))
  1556. fsize=(((texW*texH)/texC)+((16*1)+32)) -- 1 represents the mip count, but for now its disabled to 1
  1557. fflush t
  1558. fclose t
  1559. ))
  1560. filepaths[i]=spath
  1561. ddsInfo[i]=[texW,texH,texC,texM]
  1562. fileSizes[i]=fsize
  1563. )
  1564.  
  1565.  
  1566.  
  1567.  
  1568. case of(
  1569. (fversion=="0"): (writelong f 0x01020304)
  1570. (fversion=="1"): (writelong f 0x02030405)
  1571. (fversion=="2"): (writelong f 0x03040506))
  1572. offsetCount=((6*4)+(7*4*biginput.name.count)+nameSize)
  1573. padSize=((ceil ((offsetCount as float)/16)*16)-(offsetCount)) as integer
  1574. -- print padSize
  1575. offsetCount+=padSize
  1576. stringCount=((6*4)+(7*4*biginput.name.count))
  1577. writelong f offsetCount #unsigned -- data offset
  1578. writelong f 0
  1579. writelong f biginput.name.count
  1580. writelong f 24
  1581. writelong f stringCount #unsigned -- string offset
  1582. padArray=#();padArray[biginput.name.count]=0
  1583. for i = 1 to biginput.name.count do(
  1584. fsize=fileSizes[i]--;if fsize==0 do fsize=1
  1585. writelong f stringCount #unsigned -- string offset
  1586. writelong f 0x48534148 #unsigned -- checksum
  1587. writelong f fsize #unsigned -- file size (compresses), compression not supported
  1588. writelong f fsize #unsigned -- file size, uncompressed
  1589. writelong f offsetCount #unsigned -- data offset
  1590. writelong f (biginput.type[i]as integer) -- type
  1591. writelong f 0
  1592. offsetCount+=fsize
  1593. padding=((ceil ((offsetCount as float)/16)*16)-(offsetCount)) as integer
  1594.  
  1595. padArray[i]=padding
  1596. offsetCount+=padding
  1597. stringCount+=(biginput.name[i].count+1)
  1598. )
  1599. for i = 1 to biginput.name.count do(writestring f biginput.name[i])
  1600. for i = 1 to padSize do(writebyte f 0)
  1601. for i = 1 to biginput.name.count do(
  1602.  
  1603. if filepaths[i]!="" then(
  1604.  
  1605. if (getFilenameType filepaths[i])!=".dds"then(
  1606. g = fopen filepaths[i] "rb"
  1607. for x = 1 to (getFileSize filepaths[i]) do(writebyte f (readbyte g #unsigned) #unsigned)
  1608. fflush g;fclose g
  1609. )else(
  1610. --insert import code for DDS
  1611.  
  1612.  
  1613. g = fopen filepaths[i] "rb"
  1614. fseek g 0x80 #seek_set
  1615. writebyte f 0
  1616. writebyte f 1
  1617. writebyte f 1
  1618. case of (
  1619. (ddsInfo[i][3]==2):(
  1620. writebyte f (biginput.t1[i]as integer)
  1621. writeshort f ddsInfo[i][1]
  1622. writeshort f ddsInfo[i][2]
  1623. writebyte f 8
  1624. writebyte f 24
  1625. writebyte f 1 --mip count, 8 mips seems to be common
  1626. writebyte f 4 -- 4 or 8
  1627. )
  1628.  
  1629. (ddsInfo[i][3]==1):(
  1630. writebyte f (biginput.t1[i]as integer)
  1631. writeshort f ddsInfo[i][1]
  1632. writeshort f ddsInfo[i][2]
  1633. writebyte f 10
  1634. writebyte f 24
  1635. writebyte f 1 --mip count, 8 mips seems to be common
  1636. writebyte f 8 -- 4 or 8
  1637. )
  1638.  
  1639.  
  1640.  
  1641.  
  1642. )
  1643. -- fsize=(getFileSize filepaths[i])-0x80
  1644. fsize=((ddsInfo[i][1]*ddsInfo[i][2])/ddsInfo[i][3])
  1645. writelong f (biginput.t2[i]as integer) --#unsigned
  1646. writelong f 24 --table offset
  1647. writelong f 0
  1648.  
  1649. writelong f 0x30 -- offset fo texture, fixed because mips are disabled
  1650. writelong f fsize #unsigned
  1651. -- print ("Last Read @ 0x"+((bit.intAsHex(fsize))as string))
  1652. writebyte f 0
  1653. writebyte f 0
  1654. writebyte f 0
  1655. writebyte f 0x80
  1656. writelong f 0
  1657.  
  1658. writelong f 0
  1659. writelong f 0
  1660.  
  1661. for x = 1 to fsize do(writebyte f (readbyte g #unsigned) #unsigned)
  1662. fflush g;fclose g
  1663.  
  1664.  
  1665.  
  1666. print fsize
  1667.  
  1668.  
  1669. ))else(writebyte f 0)
  1670. pb1.value = 100.*i/biginput.name.count
  1671. )
  1672. -- for i = 1 to 16 do (writebyte f 0 #unsigned)
  1673. fsize=ftell f
  1674. fseek f 8 #seek_set
  1675. writelong f fsize #unsigned
  1676. -- print filepaths
  1677.  
  1678.  
  1679.  
  1680.  
  1681.  
  1682.  
  1683.  
  1684. pb1.value = 0
  1685. messagebox "Done!"
  1686. fflush f
  1687. fclose f
  1688.  
  1689.  
  1690. ) else (Print "Aborted.")
  1691.  
  1692.  
  1693.  
  1694. ) -- end repack textures
  1695.  
  1696.  
  1697. on btn5 pressed do( -- unpack textures
  1698. --===========================================================================
  1699. -- fsource="M:\\Dead.Rising.2.Off.The.Record-KaOs\\data\\models\\npcs_big\\export\\cast_sullivan.big"
  1700.  
  1701. fsource = GetOpenFileName \
  1702. caption:"texture pooper" \
  1703. types: "All Files (*.*)|*.*|Tex (*.tex)|*.tex|Big (*.big)|*.big|"
  1704. if (fsource!=undefined) AND ((doesFileExist fsource)==true) then(
  1705. f = fopen fsource "rb"
  1706. -- fext= getFilenameType fsource
  1707. fext="";for i = 2 to (getFilenameType fsource).count do fext+=(getFilenameType fsource)[i]
  1708. fpath= getFilenamePath fsource
  1709. fbatch= getFiles (fpath+"*"+fext)
  1710. fname= getFilenameFile fsource
  1711. fsize= getFileSize fsource
  1712.  
  1713. fileID=readlong f #unsigned
  1714. if fileID==0x01020304 OR fileID==0x02030405 OR fileID==0x03040506 then(
  1715. dataOffset=readlong f #unsigned -- offset to data
  1716. fileSize=readlong f #unsigned -- total file size
  1717. files=readlong f #unsigned -- file count
  1718. unk04=readlong f #unsigned -- header size? always 0x18?
  1719. names_offset=readlong f #unsigned --offset to string table
  1720. -- local infoArray=#();infoArray[files]=[0,0,0,0]
  1721. -- struct bigInfo (name,zsize,offset,type,flag)
  1722. bigArray=#();bigArray[files]=[0,0,0,0]
  1723. bigFlag=#();bigFlag[files]=0
  1724. bigStr=#();bigStr[files]=""
  1725. makeDir (fpath+fname+"_"+fext)
  1726. bs= createFile (fpath+fname+"_"+fext+"\\"+"bigfile.xml")
  1727. -- s = fopen (fpath+"\\"+fname+"_"+fext+"\\"+"bigfile.xml") "wt"
  1728. format "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" to:bs
  1729. case of(
  1730. (fileID==0x01020304): (format "<files version=\"%\">\n" 0 to:bs)
  1731. (fileID==0x02030405): (format "<files version=\"%\">\n" 1 to:bs)
  1732. (fileID==0x03040506): (format "<files version=\"%\">\n" 2 to:bs))
  1733. for i = 1 to files do(
  1734. NameOff=(readlong f #unsigned) --offset to string
  1735. unk05=readlong f #unsigned -- hash
  1736. zsize=readlong f #unsigned
  1737. size=readlong f #unsigned
  1738. offset=(readlong f #unsigned)
  1739. type=readlong f #unsigned
  1740. -- 0x0004 = Info (Header Information)
  1741. -- 0x0010 = Data (Texture)
  1742. -- 0x0020 = Data (Geometry)
  1743. -- 0x0100 = BIG (BIG Package File)
  1744. -- if type!=0x0004 OR type!=0x0020 OR type!=0x0100 DO Print ("ERROR: Type: 0x"+((bit.intAsHex(ftell f))as string))
  1745. zip=readlong f #unsigned -- flag, to switch on compression schemes
  1746. -- infoArray[i]=[type,NameOff,offset,size]
  1747. bigArray[i]=[NameOff,zsize,offset,type]
  1748. bigFlag[i]=zip
  1749. )
  1750.  
  1751.  
  1752. fseek f names_offset #seek_set
  1753. for i = 1 to files do(
  1754. bigStr[i]=readstring f
  1755.  
  1756.  
  1757.  
  1758.  
  1759. )
  1760.  
  1761.  
  1762. for i = 1 to files do(
  1763. -- memBuffer=#()
  1764. -- memBuffer[(bigArray[i][2])]=0
  1765. fseek f bigArray[i][3] #seek_set
  1766.  
  1767. if bigArray[i][4]!=16 then (
  1768. -- createFile (fpath+fname+"_"+fext+"\\"+bigStr[i])
  1769. sfileA = fopen (fpath+fname+"_"+fext+"\\"+bigStr[i]) "wb"
  1770. -- for x = 1 to bigArray[i][2] do (memBuffer[x]=readbyte f #unsigned)
  1771. -- for x = 1 to bigArray[i][2] do (writebyte s memBuffer[x] #unsigned)
  1772.  
  1773. for x = 1 to bigArray[i][2] do (writebyte sFileA (readbyte f #unsigned) #unsigned)
  1774. format " <entry name=\"%\" alignment=\"%\">%</entry>\n" bigStr[i] (bigArray[i][4]as integer) bigStr[i] to:bs
  1775. fclose sfileA
  1776. )
  1777. else( -- texture file
  1778. -- createFile (fpath+fname+"_"+fext+"\\"+bigStr[i]+".dds")
  1779. sFileB = fopen (fpath+fname+"_"+fext+"\\"+bigStr[i]+".dds") "wb"
  1780. ukn01=readbyte f #unsigned -- Unknown always 0?
  1781. ukn02=readbyte f #unsigned -- Unknown always 1?
  1782. ukn03=readbyte f #unsigned -- Unknown always 1?
  1783. ukn04=readbyte f #unsigned -- Unknown STORE
  1784. texW=readshort f #unsigned
  1785. texH=readshort f #unsigned
  1786. texC=readbyte f #unsigned -- compression flag? STORE
  1787. ukn05=readbyte f #unsigned -- Unknown always 0x24? STORE
  1788. texM=readbyte f #unsigned --;texM=0 -- MIP count
  1789. ukn06=readbyte f #unsigned -- Unknown always 0x04/0x08? STORE
  1790. ukn07=readlong f #unsigned -- Unknown, checksum? STORE
  1791. mtable=readlong f #unsigned
  1792. fseek f (bigArray[i][3]+mtable) #seek_set
  1793. tOffset=readlong f #unsigned
  1794. tSize=readlong f #unsigned
  1795. fseek f (bigArray[i][3]+tOffset) #seek_set
  1796. case of(
  1797. (texC==0x00): (texC="ARGB32")
  1798. (texC==0x08): (texC="DXT1")
  1799. (texC==0x0A): (texC="DXT5"))
  1800. writeDDSheader sFileB texW texH 0 texC
  1801. for x = 1 to tSize do (writebyte sFileB (readbyte f #unsigned) #unsigned)
  1802. format "%.) \t[%x%] [%,%,%] \t%: \t%.dds\n" i texW texH texM ukn05 ukn06 texC bigStr[i]
  1803.  
  1804. format " <entry name=\"%\" alignment=\"%\"tex01=\"%\" tex02=\"%\">%</entry>\n" bigStr[i] (bigArray[i][4]as integer) ukn04 ukn07 bigStr[i] to:bs
  1805. fclose sfileA
  1806. fclose sfileB
  1807. fclose s
  1808. )
  1809.  
  1810.  
  1811.  
  1812.  
  1813. pb1.value = 100.*i/files
  1814. )
  1815. format "</files>" to:bs
  1816. fflush bs
  1817. close bs
  1818. fclose s
  1819. fclose f
  1820. pb1.value = 0
  1821. Print "Done!"
  1822. )else(MessageBox "ERROR\n??Not A Compatible Big File")) else (Print "Aborted.")
  1823. -- gc()
  1824.  
  1825. )-- end unpack textures
  1826.  
  1827. on btn9 pressed do(MessageBox "Script created to mod Models in NPC.BIG File. \nUse Gibb's BIG Unpacker/Packer to get char models in and out. \nSame with textures")
  1828.  
  1829.  
  1830. ) createDialog dr2otr_ex
Advertisement
RAW Paste Data Copied
Advertisement