home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 10119 / FEAR_1_Fix.7z / FEAR_1.ms
Encoding:
Text File  |  2015-12-06  |  14.8 KB  |  636 lines

  1. if (heapSize < 200000) then
  2.         heapSize = 2000000 -- allow ~ 40 MB instead of just 7.5 MB. Prevents "Runtime Error: Out of scripter memory"    
  3. gname = getOpenFileName \
  4. caption:"Open .mesh from FEAR MMO Model folder" \
  5. types:"F.E.A.R 1 Model (*.model00p)|*.model00p" \
  6. historyCategory:"F1ObjectPresets"
  7. g = fopen gname "rb"        
  8.  
  9. clearlistener()
  10.  
  11. fn ReadHalfFloat fstream = 
  12.     (
  13.     hf=readshort fstream
  14.     sign = bit.get hf 16
  15.     exponent = (bit.shift (bit.and hf (bit.hexasint "7C00")) -10) as integer - 16
  16.     fraction = bit.and hf (bit.hexasint "03FF")
  17.     if sign==true then sign = 1 else sign = 0
  18.     exponentF = exponent + 127
  19.     outputAsFloat = bit.or (bit.or (bit.shift fraction 13) \
  20.     (bit.shift exponentF 23)) (bit.shift sign 31)
  21.     return bit.intasfloat outputasfloat*2
  22. )
  23.  
  24. fn readFixedString bstream fixedLen = (
  25. local str = ""
  26. for i = 1 to fixedLen do (
  27. str += bit.intAsChar (ReadByte bstream #unsigned))
  28. str
  29. )
  30.  
  31. struct weight_data
  32. (
  33.     boneids,weights
  34. )
  35.  
  36. struct Mesh_Info
  37. (
  38.     VertPos,VertCount,VertSize,FacePos,FaceCount,BoneMapCount,UnkId,Null,Null2
  39. )
  40.  
  41. clearlistener()
  42.  
  43. fseek g 0x14 #seek_set
  44. AnimOrMesh=readlong g
  45. if AnimOrMesh!=0 then (
  46. tarr = #()
  47. rarr = #()
  48. Barr = #()
  49. BPArr = #()
  50.  
  51. fseek g 0x8 #seek_set
  52. DataSizeFirst=readlong g
  53. CAfterBones=readlong g
  54. BoneCount=readlong g
  55. LODCountUnk=readlong g
  56. MatCountUnk=readlong g
  57. MeshCount=readlong g    
  58. fseek g 0x24 #seek_set
  59. LODCount=readlong g    
  60. BoneHashCount=readlong g
  61. StringSize=readlong g
  62. AfterMatCount=readlong g
  63. MatCount=readlong g
  64. fseek g 0x54 #seek_set
  65. LongSecCount=readlong g
  66. SecStride=readlong g
  67. fseek g (0x60) #seek_set
  68.  
  69. Print ("Strings Start @ 0x"+((bit.intAsHex(ftell g))as string))
  70.  
  71. BoneOrderNameArray=#()
  72.     
  73. while ftell g<(0x60+StringSize) do (
  74. BoneOrderName=readstring g
  75. if BoneOrderName!="" then append BoneOrderNameArray BoneOrderName    
  76. )    
  77.  
  78. fseek g (0x5C+StringSize) #seek_set
  79.  
  80. for i=1 to LongSecCount do (
  81. readlong g    
  82. )    
  83.  
  84. Print ("Bone Start @ 0x"+((bit.intAsHex(ftell g))as string))
  85.  
  86. for i=1 to BoneCount do (
  87.  
  88. BoneNameOff=readlong g
  89. PosName=ftell g        
  90. fseek g (0x5C+BoneNameOff) #seek_set    
  91. BoneName=readstring g
  92. fseek g (PosName) #seek_set
  93. BoneId=readshort g    
  94. readbyte g    
  95.     
  96. c11 = ReadFloat g; c12 = ReadFloat g; c13 = ReadFloat g; c14 = ReadFloat g    
  97. c21 = ReadFloat g; c22 = ReadFloat g; c23 = ReadFloat g    
  98.     
  99. BoneParent=readlong g    
  100.             
  101. tfm = (quat c11 c12 c13 c14) as matrix3
  102. bvx=c11
  103. bvy=c12
  104. bvz=c13
  105.     
  106. append tarr [bvx,bvy,bvz]
  107. append rarr tfm
  108. append Barr BoneName
  109. append BPArr BoneParent    
  110. )    
  111.  
  112. BNArr = #()
  113. for i = 1 to BoneCount Do (
  114. if isvalidnode (getNodeByName Barr[i]) != true then (
  115. tfm = rarr[i]
  116. tfm.row4 = tarr[i]
  117. newBone = bonesys.createbone   \
  118.               tfm.row4   \
  119.               (tfm.row4 + 0.01 * (normalize tfm.row1)) \
  120.               (normalize tfm.row3)
  121.          newBone.name = Barr[i]
  122.          newBone.width  = 0.01
  123.          newBone.height = 0.01
  124.          newBone.transform = tfm
  125.          newBone.setBoneEnable false 0
  126.          newBone.wirecolor = yellow
  127.          newbone.showlinks = true
  128.          newBone.pos.controller      = TCB_position ()
  129.          newBone.rotation.controller = TCB_rotation ()        
  130. if BNArr.count > 0 then (
  131. newBone.parent = BNArr[BNArr.count]
  132. deleteitem BNArr BNArr.count
  133. )
  134. )
  135. if isvalidnode (getNodeByName Barr[i]) == true then (
  136. newBone = getNodeByName Barr[i]
  137. )
  138. for j = 1 to BPArr[i] do append BNArr newBone    
  139. )
  140.  
  141. Print ("Bone End @ 0x"+((bit.intAsHex(ftell g))as string))    
  142.  
  143. rootRT = bone name:"Main_Root" boxsize:[5.0,5.0,5.0]    
  144. boneMain= getnodebyname Barr[1]
  145. boneMain.parent = rootRT
  146. rootRT.transform = (matrix3 [-1,0,0] [0,0,1] [0,-1,0] [0,0,0])
  147.     
  148.  
  149. FearBone=#()    
  150. FearBoneOrder=#()        
  151. FearHelper=BoneOrderNameArray
  152. FearHelper2=Barr
  153. for i=1 to BoneOrderNameArray.count do (    
  154. for a=1 to BoneCount do (
  155. if FearHelper[i]==FearHelper2[a] then append FearBoneOrder i    
  156. )    
  157. )
  158.  
  159. for i=1 to BoneCount do (
  160. FearBones=getnodebyname BoneOrderNameArray[(FearBoneOrder[i])]    
  161. append FearBone FearBones    
  162. )    
  163.  
  164. Unk=readlong g
  165. for i=1 to BoneHashCount do (
  166. SecNextBones=readshort g
  167. SecNextBones2=readshort g
  168. for i=1 to BoneCount do (
  169. readlong g    
  170. )    
  171. )
  172.  
  173. Print ("Bones Count Long End @ 0x"+((bit.intAsHex(ftell g))as string))    
  174.  
  175. fseek g ((SecStride)) #seek_cur    
  176.  
  177. Print ("After Bones Section Start @ 0x"+((bit.intAsHex(ftell g))as string))        
  178.     
  179. for i=1 to (CAfterBones) do (
  180. fseek g (0x24) #seek_cur        
  181. Count8=readlong g
  182. for i=1 to Count8 do (
  183. fseek g (0x8) #seek_cur        
  184. )    
  185. )    
  186.  
  187. Print ("After Bones Section End @ 0x"+((bit.intAsHex(ftell g))as string))    
  188.     
  189. Count2=readlong g
  190. for i=1 to Count2 do (
  191. UnkOff=readlong g
  192. BoneCount2=readlong g
  193. for i=1 to BoneCount2 do (    
  194. readlong g    
  195. )
  196. print UnkOff
  197. )    
  198.  
  199. Print ("After Bones Section 2 End @ 0x"+((bit.intAsHex(ftell g))as string))        
  200.     
  201. Count3=readlong g
  202. for i=1 to Count3 do (
  203. fseek g (0x28) #seek_cur    
  204. )    
  205.  
  206. Print ("After Bones Section 3 End @ 0x"+((bit.intAsHex(ftell g))as string))    
  207.  
  208. MeshNameArray=#()    
  209. MeshNameCount=readlong g    
  210. for i=1 to MeshNameCount-1 do (
  211. MeshNameSize=readshort g    
  212. MeshName=readFixedString g MeshNameSize
  213. print MeshName    
  214. append MeshNameArray MeshName    
  215. )        
  216.  
  217. Print ("Mesh Name End @ 0x"+((bit.intAsHex(ftell g))as string))    
  218.  
  219. readbyte g
  220. CountAfter=readlong g
  221. for i=1 to CountAfter do (
  222. readlong g    
  223. )    
  224.  
  225. for i=1 to MatCount do (
  226. fseek g (0x29) #seek_cur        
  227. Check7=readlong g
  228. if Check7==7 then fseek g (0x24) #seek_cur         
  229. if Check7==6 then (        
  230. CountL=readlong g
  231. Check7_1=readlong g
  232. if Check7_1==7 then fseek g (0x24) #seek_cur     
  233. if Check7_1==5 then (        
  234. fseek g (0x1C) #seek_cur
  235. )
  236. if Check7_1==3 then (        
  237. fseek g (0xC) #seek_cur
  238. )    
  239. if Check7_1==2 then (        
  240. fseek g (0x18) #seek_cur
  241. )    
  242. ----------------------
  243. for i=1 to CountL do (
  244. Check7_2=readlong g
  245. if Check7_2==7 then fseek g (0x24) #seek_cur     
  246. if Check7_2==5 then (        
  247. fseek g (0x1C) #seek_cur
  248. )
  249. if Check7_2==3 then (        
  250. fseek g (0xC) #seek_cur
  251. )    
  252. if Check7_2==2 then (        
  253. fseek g (0x18) #seek_cur
  254. )        
  255. )    
  256. ----------------------
  257. )    
  258. if Check7==5 then (        
  259. fseek g (0x1C) #seek_cur
  260. )
  261. if Check7==3 then (        
  262. fseek g (0xC) #seek_cur
  263. )    
  264. if Check7==2 then (        
  265. fseek g (0x18) #seek_cur
  266. )    
  267. )    
  268.  
  269. Print ("!!!!! @ 0x"+((bit.intAsHex(ftell g))as string))    
  270.  
  271. MCount=readlong g
  272. if MCount!=0 then     
  273. for i=1 to MCount do (
  274. IdSize1=readlong g
  275. IdSize2=readlong g
  276. IdSize3=readlong g    
  277. if IdSize1==3 then fseek g (0x54) #seek_cur    
  278. if IdSize1==4 then fseek g (0x64) #seek_cur        
  279. )    
  280. if MCount==0 then fseek g (0x8) #seek_cur    
  281.     
  282.  
  283. Print ("00 @ 0x"+((bit.intAsHex(ftell g))as string))    
  284.  
  285. SecIdCount=readlong  g
  286. for i=1 to SecIdCount do (
  287. Print ("Mat Section Position! @ 0x"+((bit.intAsHex(ftell g))as string))        
  288. fseek g (0x67) #seek_cur        
  289. Short01Pos=ftell g
  290. Short01=readlong g    
  291. if Short01==1 then fseek g (0x56) #seek_cur        
  292. if Short01!=1 then fseek g (Short01Pos) #seek_set        
  293. )
  294.  
  295. Print ("01 @ 0x"+((bit.intAsHex(ftell g))as string))    
  296.  
  297. CountNew=readlong g
  298. for i=1 to CountNew do (
  299. UnkOff_00=readlong g
  300. CountData=readlong g    
  301. readshort g    
  302. for i=1 to CountData do (    
  303. UnkCount=readlong g    
  304. UnkID=readbyte g
  305. DataCount=readlong g
  306. -- print (DataCount as string)    
  307. for i=1 to DataCount do (    
  308. ModelNumber=readlong g
  309. NullPos=ftell g    
  310. Null=readshort g
  311. if Null==0 then fseek g (0x0) #seek_cur        
  312. if Null!=0 then fseek g (NullPos) #seek_set
  313. print (ModelNumber as string)    
  314. )
  315. )
  316. )    
  317.  
  318. Print ("!!!!!!! @ 0x"+((bit.intAsHex(ftell g))as string))    
  319.     
  320. fseek g 0xC #seek_cur
  321.  
  322. LODCount=2    
  323. for a=1 to LODCount do (    
  324.     
  325. vertArray = #()
  326. faceArray = #()
  327. UV_array = #()
  328. Weight_array=#()        
  329.     
  330. UnkMeshType=readlong g    
  331. MeshCount=readlong g
  332. VertId=readlong g    
  333. VertexSecSize=readlong g
  334. FaceSecSize=readlong g
  335.         
  336. VertexStartPos=ftell g
  337.  
  338. fseek g (VertexSecSize) #seek_cur    
  339.  
  340. Print ("Vertex Section End @ 0x"+((bit.intAsHex(ftell g))as string))
  341.  
  342. FaceStartPos=ftell g
  343. fseek g (FaceSecSize) #seek_cur        
  344.  
  345. Print ("Face Section End @ 0x"+((bit.intAsHex(ftell g))as string))    
  346.         
  347. CountDataSec=readlong g
  348.     
  349. for i=1 to CountDataSec do (    
  350. DataSize=readlong g
  351. fseek g (DataSize) #seek_cur    
  352. )
  353.  
  354. Print ("Info Start @ 0x"+((bit.intAsHex(ftell g))as string))
  355.     
  356. SubCount=readlong g
  357.     
  358. Mesh_Info_Array=#()
  359. BoneMapPosArray=#()    
  360. for i=1 to SubCount do (
  361. BoneMapPos=ftell g
  362. append BoneMapPosArray BoneMapPos    
  363. VertPos=readlong g
  364. VertCount=readlong g
  365. VertSize=readlong g
  366. FacePos=readlong g
  367. Null=readlong g    
  368. FaceCount=readlong g
  369. UnkId=readlong g    
  370. BoneMapCount=readlong g
  371. Null2=readlong g
  372. for a=1 to BoneMapCount do (
  373. BoneMapId=readbyte g#usigned     
  374. )    
  375. append Mesh_Info_Array (Mesh_Info VertPos:VertPos VertCount:VertCount VertSize:VertSize FacePos:FacePos FaceCount:FaceCount BoneMapCount:BoneMapCount UnkId:UnkId Null:Null Null2:Null2) 
  376. )    
  377.  
  378. print Mesh_Info_Array
  379. print BoneMapPosArray
  380.  
  381. Print ("Info End @ 0x"+((bit.intAsHex(ftell g))as string))    
  382.  
  383. for i=1 to SubCount do (
  384.     
  385. vertArray = #()
  386. faceArray = #()
  387. UV_array = #()
  388. Normal_Array=#()    
  389. Weight_array=#()    
  390.  
  391. BMapPos=BoneMapPosArray[i]
  392.     
  393. fseek g (BMapPos+28) #seek_set
  394.  
  395. Print ("BMap Start @ 0x"+((bit.intAsHex(ftell g))as string))
  396.     
  397. BoneMapArray=#()
  398. BoneMapCount02=readlong g
  399. Null02=readlong g
  400. for a=1 to BoneMapCount02 do (
  401. BoneMapId02=readbyte g#usigned     
  402. append BoneMapArray (BoneMapID02+1)    
  403. )    
  404.  
  405. fseek g (VertexStartPos) #seek_set
  406.  
  407. Print ("Vertex Start @ 0x"+((bit.intAsHex(ftell g))as string))
  408.  
  409. if a==1 then     
  410. if Mesh_Info_Array[i].VertSize==64 then 
  411. for x =1 to (Mesh_Info_Array[i].VertCount) do (
  412. getPos = ftell g + Mesh_Info_Array[i].VertSize
  413.     
  414. vx = ReadFloat g
  415. vy = ReadFloat g
  416. vz = ReadFloat g
  417.  
  418. fseek g 12 #seek_cur    
  419.     
  420. tu = ReadFloat g
  421. tv = ReadFloat g*-1    
  422.     
  423. fseek g 24 #seek_cur    
  424.     
  425. weight3 = readbyte g #unsigned    
  426. weight2 = readbyte g #unsigned
  427. weight1 = readbyte g #unsigned
  428. weight4 =readbyte g #unsigned    
  429.     
  430. bone1 = readbyte g #unsigned
  431. bone2 = readbyte g #unsigned
  432. bone3 = readbyte g #unsigned
  433. bone4 = readbyte g #unsigned    
  434.  
  435. w = (weight_data boneids:#() weights:#())
  436. maxweight = 0
  437. if(weight1 != 0) then
  438.    maxweight = maxweight + weight1
  439. if(weight2 != 0) then
  440.    maxweight = maxweight + weight2
  441. if(weight3 != 0) then
  442.    maxweight = maxweight + weight3
  443. if(weight4 != 0) then
  444.    maxweight = maxweight + weight4
  445.  
  446. if(maxweight != 0) then (
  447.       if(weight1 != 0) then (
  448.          w1 = weight1 as float
  449.          append w.boneids (bone1 + 1)
  450.          append w.weights (w1 / 255.0)
  451.       )
  452.       if(weight2 != 0) then (
  453.          w2 = weight2 as float
  454.          append w.boneids (bone2 + 1)
  455.          append w.weights (w2 / 255.0)
  456.       )
  457.       if(weight3 != 0) then (
  458.          w3 = weight3 as float
  459.          append w.boneids (bone3 + 1)
  460.          append w.weights (w3 / 255.0)
  461.       )
  462.       if(weight4 != 0) then (
  463.          w4 = weight4 as float
  464.          append w.boneids (bone4 + 1)
  465.          append w.weights (w4 / 255.0)
  466.       )      
  467.    )
  468. append Weight_array w            
  469. fseek g getPos #seek_set
  470. append vertArray ([-vx,-vz,vy])    
  471. append UV_Array [tu,tv,0]            
  472. )    
  473.  
  474. if a!=1 then     
  475. if Mesh_Info_Array[i].VertSize==64 then 
  476. for x =1 to (Mesh_Info_Array[i].VertCount) do (
  477. getPos = ftell g + Mesh_Info_Array[i].VertSize
  478.     
  479. vx = ReadFloat g
  480. vy = ReadFloat g
  481. vz = ReadFloat g
  482.     
  483. nx = ReadFloat g
  484. ny = ReadFloat g
  485. nz = ReadFloat g    
  486.     
  487. fseek g 0x10 #seek_cur    
  488.     
  489. weight3 = readbyte g #unsigned    
  490. weight2 = readbyte g #unsigned
  491. weight1 = readbyte g #unsigned
  492. weight4 =readbyte g #unsigned    
  493.     
  494. fseek g 0x8 #seek_cur        
  495.     
  496. bone1 = readbyte g #unsigned
  497. bone2 = readbyte g #unsigned
  498. bone3 = readbyte g #unsigned
  499. bone4 = readbyte g #unsigned    
  500.     
  501. w = (weight_data boneids:#() weights:#())
  502. maxweight = 0
  503. if(weight1 != 0) then
  504.    maxweight = maxweight + weight1
  505. if(weight2 != 0) then
  506.    maxweight = maxweight + weight2
  507. if(weight3 != 0) then
  508.    maxweight = maxweight + weight3
  509. if(weight4 != 0) then
  510.    maxweight = maxweight + weight4
  511.  
  512. if(maxweight != 0) then (
  513.       if(weight1 != 0) then (
  514.          w1 = weight1 as float
  515.          append w.boneids (bone1 + 1)
  516.          append w.weights (w1 / 255.0)
  517.       )
  518.       if(weight2 != 0) then (
  519.          w2 = weight2 as float
  520.          append w.boneids (bone2 + 1)
  521.          append w.weights (w2 / 255.0)
  522.       )
  523.       if(weight3 != 0) then (
  524.          w3 = weight3 as float
  525.          append w.boneids (bone3 + 1)
  526.          append w.weights (w3 / 255.0)
  527.       )
  528.       if(weight4 != 0) then (
  529.          w4 = weight4 as float
  530.          append w.boneids (bone4 + 1)
  531.          append w.weights (w4 / 255.0)
  532.       )      
  533.    )
  534. append Weight_array w            
  535. fseek g getPos #seek_set
  536. append vertArray ([-vx,-vz,vy])    
  537. append Normal_Array [-nx,-nz,ny]  
  538. append UV_Array ([0,0,0])            
  539. )    
  540.  
  541. if Mesh_Info_Array[i].VertSize==32 then 
  542. for x =1 to (Mesh_Info_Array[i].VertCount) do (
  543. getPos = ftell g + Mesh_Info_Array[i].VertSize
  544.     
  545. vx = ReadFloat g
  546. vy = ReadFloat g
  547. vz = ReadFloat g
  548.     
  549. tu = ReadFloat g
  550. tv = ReadFloat g*-1    
  551.             
  552. fseek g getPos #seek_set
  553. append vertArray ([-vx,-vz,vy])    
  554. append UV_Array [0,0,0]            
  555. )
  556.  
  557. VertexStartPos+=(Mesh_Info_Array[i].VertCount*Mesh_Info_Array[i].VertSize)
  558.  
  559. fseek g (FaceStartPos+(Mesh_Info_Array[i].FacePos*2)) #seek_set
  560.  
  561. Print ("FaceStart @ 0x"+((bit.intAsHex(ftell g))as string))
  562.  
  563. for x = 1 to Mesh_Info_Array[i].FaceCount do (
  564. fa=(readshort g #unsigned+ 1)-Mesh_Info_Array[i].VertPos    
  565. fb=(readshort g #unsigned+ 1)-Mesh_Info_Array[i].VertPos    
  566. fc=(readshort g #unsigned+ 1)-Mesh_Info_Array[i].VertPos    
  567. append faceArray [fc,fb,fa]     
  568. )        
  569.  
  570. if vertArray.count!=0 then 
  571. Try(
  572. msh = mesh vertices:vertArray faces:faceArray
  573. if a==1 then msh.name="F.E.A.R 1 Model "+ i as string     
  574. if a!=1 then (
  575. msh.name="F.E.A.R 1 Shadow-Mesh "+ i as string 
  576. for j = 1 to Normal_Array.count do setNormal msh j Normal_Array[j]
  577. )    
  578. msh.numTVerts = UV_Array.count
  579. buildTVFaces msh
  580. for j = 1 to UV_Array.count do setTVert msh j UV_Array[j]
  581. for j = 1 to faceArray.count do setTVFace msh j faceArray[j]
  582.     
  583. max modify mode
  584. select msh
  585. skinMod = skin ()
  586. addModifier msh skinMod
  587. for i = 1 to BoneMapCount02 do
  588. (
  589.     maxbone = FearBone[(BoneMapArray[i])]
  590.     if i != BoneMapCount02 then 
  591.         skinOps.addBone skinMod maxbone 0
  592.     else
  593.         skinOps.addBone skinMod maxbone 1
  594. )
  595. modPanel.setCurrentObject skinMod
  596. for i = 1 to Weight_array.count do (
  597.    w = Weight_array[i]
  598.    bi = #() --bone index array
  599.    wv = #() --weight value array
  600.    
  601.    for j = 1 to w.boneids.count do
  602.    (
  603.       boneid = w.boneids[j]
  604.       weight = w.weights[j]
  605.       append bi boneid
  606.       append wv weight
  607.    )   
  608.    
  609.    skinOps.ReplaceVertexWeights skinMod i bi wv
  610. )
  611. )catch(format "Wrong Skel or Messed Bones!!\n")
  612. )
  613.  
  614. CountDataSec2=readlong g    
  615.     
  616. for i=1 to CountDataSec2 do (    
  617. DataSize2=readlong g
  618. fseek g (DataSize2) #seek_cur    
  619. )
  620.  
  621. SubCount2=readlong g
  622.         
  623. for i=1 to SubCount2 do (
  624. getPos = ftell g + 28
  625. fseek g getPos #seek_set    
  626. BoneMapCount2=readlong g
  627. Null3=readlong g
  628. for a=1 to BoneMapCount2 do (
  629. BoneMapId2=readbyte g#usigned     
  630. )    
  631. )    
  632. Print ("MeshEnd @ 0x"+((bit.intAsHex(ftell g))as string))
  633. )    
  634. fclose g
  635. )
  636. if AnimOrMesh==0 then fclose g