home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 11321 / CryRyseImport.7z / include / load_cryFile_.ms < prev    next >
Encoding:
Text File  |  2016-07-19  |  5.5 KB  |  150 lines

  1.  
  2.  
  3. fn load_cryFile \
  4.                         &bstream: =
  5. (    
  6.     if bstream != unsupplied then
  7.     (
  8.         if bstream != undefined then
  9.         (
  10.             if iskindof bstream BinStream then
  11.             (
  12.                 --------------------Constants-----------------------
  13.                 inst_ChunkTypes = ChunkTypes()
  14.  
  15.                 ---------------------------------------- Check that the file indeed has the "CryTek" header ----------------------------------------
  16.                 local inst_FILE_HEADER = FILE_HEADER()
  17. --                 inst_FILE_HEADER.Signature = ReadFixedString bstream ::g__CONST_SIGN_length    --this will be checked later, must be "CryTek"    --case sensitive    
  18.  
  19.                 inst_FILE_HEADER.Signature = ReadFixedString \
  20.                                                                                 bstream:bstream \
  21.                                                                                 fixedLen:(::g__CONST_SIGN_length)        --this will be checked later, must be "CryTek"    --case sensitive
  22.                                         
  23.                 
  24.                 --We do NOT use stricmp here because we want the comparison to be case sensitive - to keep it strongly strict
  25.                 if inst_FILE_HEADER.Signature == ::g_CryTek_string then
  26.                 (
  27.                     local STAT = false
  28.                     
  29.                     read_FILE_HEADER \
  30.                                                 bstream:            &bstream \
  31.                                                 struct2fill:            &inst_FILE_HEADER \
  32.                                                 global_Append:    ::g_FILE_HEADER \
  33.                                                 STAT:                &STAT
  34.  
  35.                     if STAT then
  36.                     (
  37.                         inst_CHUNKTABLE_FILE_CONSTANTS = CHUNKTABLE_FILE_CONSTANTS()
  38.                         read_CHUNKTABLE_FILE_CONSTANTS \
  39.                                                                             bstream:            &bstream \
  40.                                                                             struct2read:        &inst_FILE_HEADER \
  41.                                                                             struct2fill:            &inst_CHUNKTABLE_FILE_CONSTANTS \
  42.                                                                             global_Append:     ::g_CHUNKTABLE_FILE_CONSTANTS \
  43.                                                                             STAT:                &STAT                        
  44.                         
  45.                         if STAT then
  46.                         (
  47.                             --Can only be 1 (meaning there can only be one table in each CryFile - naturally)
  48.                             if ::g_CHUNKTABLE_FILE_CONSTANTS.count == 1 then
  49.                             (                
  50.                                 --Read ChunkTable
  51.                                 inst_CHUNKTABLE_0744_0745 = CHUNK_TABLE_0744_0745() --create instance of struct
  52.                                 read_ChunkTable_0744_0745 \
  53.                                                                         bstream:            &bstream \
  54.                                                                         struct2read_A:    &inst_FILE_HEADER \
  55.                                                                         struct2read_B:    &inst_CHUNKTABLE_FILE_CONSTANTS \
  56.                                                                         struct2fill:            &inst_CHUNKTABLE_0744_0745 \
  57.                                                                         global_Append:    ::g_CHUNKTABLE_0744_0745 \
  58.                                                                         STAT:                &STAT
  59.                                 
  60.                                 print inst_CHUNKTABLE_0744_0745
  61.                                 print STAT                                
  62.                                 
  63.                                 if STAT then
  64.                                 (                                    
  65.                                     --Read Source Info
  66.                                     --SOURCE_INFO() structs created runtime
  67.                                     read_SOURCE_INFO \
  68.                                                                 bstream:            &bstream \
  69.                                                                 fileHeader:            &inst_FILE_HEADER \
  70.                                                                 struct2read:         &inst_CHUNKTABLE_0744_0745    \
  71.                                                                 global_Append:    ::g_SOURCE_INFO                                    
  72.                                     
  73.                                     --Read Export Flags
  74.                                     --EXPORT_FLAGS_CHUNK_DESC() structs created runtime
  75.                                     read_EXPORT_FLAGS_CHUNK_DESC \
  76.                                                                                     bstream:            &bstream \
  77.                                                                                     fileHeader:            &inst_FILE_HEADER \
  78.                                                                                     struct2read:        &inst_CHUNKTABLE_0744_0745 \
  79.                                                                                     global_Append:    ::g_EXPORT_FLAGS_CHUNK_DESC
  80.  
  81.                                     
  82.                                     --Read Timing Info
  83.                                     --TIMING_CHUNK_DESC_0918(), TIMING_CHUNK_DESC_0919() and RANGE_ENTITY() created runtime
  84.                                     read_TIMING_CHUNK_DESC_0918 \
  85.                                                                                     bstream:            &bstream \
  86.                                                                                     fileHeader:            &inst_FILE_HEADER \
  87.                                                                                     struct2read:        &inst_CHUNKTABLE_0744_0745 \
  88.                                                                                     global_Append:    ::g_TIMING_CHUNK_DESC
  89.                                     
  90.                                     
  91.  
  92.                                     --Read material name
  93.                                     --MTL_NAME_CHUNK_DESC_0802() created runtime
  94.                                     read_CHUNK_0x0014 \
  95.                                                                 bstream:            &bstream \
  96.                                                                 fileHeader:            &inst_FILE_HEADER \
  97.                                                                 struct2read:        &inst_CHUNKTABLE_0744_0745 \
  98.                                                                 global_Append:    ::g_MTL_NAME_CHUNK_DESC_0802
  99.                                     
  100.                                     
  101.                                     --Physics description - CryHeaders.h 711
  102.                                     read_MESH_PHYSICS_DATA_CHUNK_DESC_0800 \
  103.                                                                                                         bstream:            &bstream \
  104.                                                                                                         fileHeader:            &inst_FILE_HEADER \
  105.                                                                                                         struct2read:        &inst_CHUNKTABLE_0744_0745 \
  106.                                                                                                         global_Append:    ::g_MESH_PHYSICS_DATA_CHUNK_DESC_0800                                                                                                    
  107.  
  108.                                     
  109.                                     ----------------------------------------------------------- Read Streams and Build Meshes ----------------------------------------------------------------
  110.                                     --We read all the DataStreams (including Array of mesh subsets) in here, structs are created runtime
  111.                                     inst_MESH_SUBSETS_CHUNK_DESC_0800 = MESH_SUBSETS_CHUNK_DESC_0800()
  112.                                     read_CHUNK_0017 \
  113.                                                                 bstream:        &bstream \
  114.                                                                 fileHeader:        &inst_FILE_HEADER \
  115.                                                                 struct2read:    &inst_CHUNKTABLE_0744_0745
  116.                                     ----------------------------------------------------------------------------------------------------------------------------------------------------------------
  117.  
  118.                                 )
  119.                             )    
  120.                         )
  121.                         else
  122.                         (
  123.                             format "\n*****Failed to read Chunk Table - ABORTING!*****\n"
  124.                         )    
  125.                     )
  126.                     else
  127.                     (
  128.                         format "\n*****Failed to read File Header - ABORTING!*****\n"
  129.                     )
  130.                 )
  131.                 else
  132.                 (
  133.                     format "\n*****CryTek Signature check failed - ABORTING!*****\n"
  134.                 )
  135.             )
  136.             else
  137.             (
  138.                 format "\n*****Binary Stream is invalid - ABORTING!*****\n"
  139.             )
  140.         )
  141.         else
  142.         (
  143.             format "\n*****Binary Stream is undefined - ABORTING!*****\n"
  144.         )
  145.     )
  146.     else
  147.     (
  148.         format "\n*****Binary Stream is unsupplied - ABORTING!*****\n"
  149.     )
  150. )