home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 11220 / CryRyseImport_fix35.7z / include / general_functions_.ms < prev    next >
Encoding:
Text File  |  2016-07-01  |  5.8 KB  |  292 lines

  1.  
  2. fn ReadFixedString \
  3.                             &bstream: \
  4.                             &fixedLen: =
  5. (
  6.     if classof bstream == BinStream then
  7.     (
  8.         local str = ""
  9.         for i = 1 to fixedLen do
  10.         (
  11.             str += bit.intAsChar (ReadByte bstream #unsigned)
  12.         )
  13.         return str
  14.     )
  15. )
  16.  
  17. fn readHalfFloat \
  18.                         bstream =
  19. (
  20.     hf                = readshort bstream #unsigned
  21.     sign             = bit.get hf 16
  22.     exponent     = (bit.shift (bit.and hf (bit.hexasint "7C00")) -10) as integer - 16
  23.     fraction         = bit.and hf (bit.hexasint "03FF")
  24.         
  25.     if sign==true then
  26.     (
  27.         sign = 1
  28.     )
  29.     else
  30.     (
  31.         sign = 0
  32.     )
  33.         
  34.     exponentF = exponent + 127
  35.         
  36.     outputAsFloat = bit.or (bit.or (bit.shift fraction 13) \
  37.     (bit.shift exponentF 23)) (bit.shift sign 31)
  38.         
  39.     return bit.intasfloat outputasfloat*2
  40. )    
  41.  
  42. fn build_complete_filePath \                                    
  43.                                     attribVal: \
  44.                                     dirPath:    \
  45.                                     &filePath: =
  46. (
  47.     if attribVal != undefined AND dirPath != undefined then
  48.     (
  49.         if iskindof attribVal string AND iskindof dirPath string then
  50.         (
  51.             if pathConfig.isLegalPath dirPath then
  52.             (
  53.                 newfilePath = pathConfig.resolvePathSymbols (pathConfig.appendPath dirPath filePath)                
  54.                 
  55.                 filePath = newfilePath
  56.                 
  57.                 if doesfileexist filePath then
  58.                 (
  59.                     return true;
  60.                 )
  61.             )                
  62.         )
  63.     )
  64.     return false;
  65. )
  66.  
  67. fn check_4_mtl_suffix \
  68.                                 &filePath: =
  69. (
  70.     suffix = getFilenameType filePath
  71.     
  72.     if stricmp suffix ".mtl" != 0 then
  73.     (
  74.         filePath = (trimRight filePath ".") + ".mtl"
  75.     )
  76. )
  77.  
  78. --Checks if the header is CryXmlB in the .mtl, if so, then it is in Crytek Binary XML format
  79. fn Binary_XML_check file =
  80. (
  81.     if file != undefined then
  82.     (
  83.         if doesfileexist File then
  84.         (
  85.             szSignature     = "CryXmlB"
  86.                 
  87.             --////////////// Open binary stream //////////////
  88.             xbs                 = fopen file "rb"
  89.             -------------------------------------------
  90.             
  91.             if classof xbs == BinStream then
  92.             (                
  93.                 local fixedLen = 8
  94.                 thisHeader = ReadFixedString \
  95.                                                         bstream:    &xbs \
  96.                                                         fixedLen:    &fixedLen
  97.                     
  98.                 --////////////// Close binarystream //////////////
  99.                 fclose xbs
  100.                     
  101.                 if thisHeader == szSignature then
  102.                 (
  103.                     return true;
  104.                 )
  105.             )
  106.         )
  107.     )    
  108.     return false;
  109. )
  110.  
  111. fn Binary_XML_custom_check \
  112.                                             File: \
  113.                                             type: =
  114. (
  115.     if File != undefined then
  116.     (
  117.         if doesfileexist File then
  118.         (    
  119.             szSignature     = type
  120.                 
  121.             --////////////// Open binary stream //////////////
  122.             xbs                 = fopen File "rb"
  123.             -------------------------------------------
  124.                 
  125.             local fixedLen = 8
  126.             thisHeader = ReadFixedString \
  127.                                                     bstream:    &xbs \
  128.                                                     fixedLen:    &fixedLen
  129.                 
  130.             --////////////// Close binarystream //////////////
  131.             fclose xbs
  132.                 
  133.             if thisHeader == szSignature then
  134.             (
  135.                 return true;
  136.             )
  137.         )
  138.     )    
  139.     return false;
  140. )
  141.  
  142. fn Binary_CryTek_check File: =
  143. (
  144.     if File != undefined then
  145.     (
  146.         if doesfileexist File then
  147.         (
  148.             szSignature     = "CryTek"
  149.                 
  150.             --////////////// Open binary stream //////////////
  151.             xbs                 = fopen File "rb"
  152.             -------------------------------------------
  153.                 
  154.             local fixedLen = 7
  155.             thisHeader = ReadFixedString \
  156.                                                     bstream:    &xbs \
  157.                                                     fixedLen:    &fixedLen
  158.                 
  159.             --////////////// Close binarystream //////////////
  160.             fclose xbs
  161.                 
  162.             if thisHeader == szSignature then
  163.             (
  164.                 return true;
  165.             )
  166.         )
  167.     )
  168.     return false;
  169. )
  170.  
  171.  
  172. fn getFilesRecursive \
  173.                             root: \
  174.                             specDir: \
  175.                             targetFile: =
  176. (
  177.     local rootLevels = ""
  178.     local files_Found = #()    
  179.  
  180.     if doesfileexist  (pathConfig.ResolvePathSymbols (pathConfig.AppendPath sysInfo.windowsdir "\\Microsoft.NET\\Framework*")) then
  181.     (
  182.         if root != unsupplied then
  183.         (
  184.             if iskindof root string then
  185.             (
  186.                 if pathConfig.islegalpath root then
  187.                 (
  188.                     if doesfileexist root then
  189.                     (
  190.                         if specDir != unsupplied then
  191.                         (
  192.                             if iskindof specDir  string then
  193.                             (
  194.                                 rootLevels = pathConfig.resolvePathSymbols (root + "/" + specDir)
  195.                             )                    
  196.                         )
  197.                         else
  198.                         (
  199.                             rootLevels = pathConfig.resolvePathSymbols (root + "/*")
  200.                         )
  201.                         
  202.                         try
  203.                         (
  204.                             SystemIO_SearchOption         = dotNetClass "System.IO.SearchOption"
  205.                             Directory                             = dotNetClass "System.IO.Directory"
  206.                             files_array                             = Directory.getFiles rootLevels "*.*" SystemIO_SearchOption.AllDirectories
  207.                                 
  208.                             for f in files_array do
  209.                             (                            
  210.                                 if (stricmp (filenameFromPath  f) targetFile) == 0 then
  211.                                 (
  212.                                     Append files_Found f
  213.                                 )
  214.                             )
  215.                         )
  216.                         catch print (getCurrentException())
  217.                     )
  218.                 )
  219.             )
  220.         )
  221.     )
  222.     else
  223.     (
  224.         if root != unsupplied then
  225.         (
  226.             if iskindof root string then
  227.             (
  228.                 if pathConfig.islegalpath root then
  229.                 (
  230.                     if doesfileexist root then
  231.                     (
  232.                         if specDir != unsupplied then
  233.                         (
  234.                             if iskindof specDir  string then
  235.                             (
  236.                                 rootLevels = pathConfig.resolvePathSymbols (root + "/" + specDir)
  237.                             )
  238.                         )
  239.                         else
  240.                         (
  241.                             rootLevels = pathConfig.resolvePathSymbols (root + "/*")
  242.                         )
  243.                         
  244.                         if pathConfig.isLegalPath rootLevels AND \
  245.                             doesfileexist rootLevels then
  246.                         (
  247.                             local dir_array = GetDirectories (pathConfig.resolvePathSymbols (rootLevels+"/*"))
  248.                         
  249.                             for d in dir_array do
  250.                             (
  251.                                 join dir_array (GetDirectories (d+"/*"))
  252.                             )                        
  253.                             
  254.                             for f in dir_array do
  255.                             (
  256.                                 if targetFile != unsupplied then
  257.                                 (
  258.                                     if iskindof targetFile string then
  259.                                     (
  260.                                         fName = f + targetFile                                    
  261.                                         
  262.                                         if doesfileexist fName then
  263.                                         (
  264.                                             Append files_Found fName
  265.                                         )
  266.                                     )                
  267.                                 )
  268.                                 else
  269.                                 (
  270.                                     Append files_Found f
  271.                                 )
  272.                             )
  273.                         )
  274.                     )
  275.                 )
  276.             )
  277.         )
  278.     )
  279.     
  280.     return files_Found;
  281. )
  282.  
  283.     
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.