home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 11256 / CryRyseImport.7z / include / load_CAF_.ms < prev    next >
Encoding:
Text File  |  2016-07-01  |  17.2 KB  |  496 lines

  1.  
  2.  
  3.  
  4. struct GAHCAF_PROCESSOR
  5. (
  6.     -------- CAF --------
  7.     fn fill_CAF_struct \
  8.                             bstream: \
  9.                             &struct2Fill: =
  10.     (
  11.         struct2Fill.m_flags                         = readlong bstream #unsigned
  12.         
  13.         struct2Fill.m_FilePath                     = ReadFixedString \
  14.                                                                                     bstream:    &bstream \
  15.                                                                                     fixedLen:    &struct2Fill.FILEPATH_SIZE
  16.         
  17.         struct2Fill.m_FilePathCRC32             = readlong bstream #unsigned
  18.         struct2Fill.m_FilePathDBACRC32         = readlong bstream #unsigned
  19.  
  20.         struct2Fill.m_LHeelStart                 = readfloat bstream
  21.         struct2Fill.m_LHeelEnd                     = readfloat bstream
  22.  
  23.         struct2Fill.m_LToe0Start                 = readfloat bstream
  24.         struct2Fill.m_LToe0End                 = readfloat bstream
  25.  
  26.         struct2Fill.m_RHeelStart                 = readfloat bstream
  27.         struct2Fill.m_RHeelEnd                     = readfloat bstream
  28.  
  29.         struct2Fill.m_RToe0Start                 = readfloat bstream
  30.         struct2Fill.m_RToe0End                 = readfloat bstream                            
  31.  
  32.         struct2Fill.m_fStartSec                 = readfloat bstream
  33.         struct2Fill.m_fEndSec                     = readfloat bstream
  34.         struct2Fill.m_fTotalDuration             = readfloat bstream
  35.         struct2Fill.m_nControllers                 = readlong bstream #unsigned
  36.  
  37.         
  38.         --Vec3
  39.         struct2Fill.T_StartLocation                = point3 (readfloat bstream) (readfloat bstream) (readfloat bstream)
  40.         --QuatT
  41.         struct2Fill.m_StartLocation.x             = readfloat bstream
  42.         struct2Fill.m_StartLocation.y             = readfloat bstream
  43.         struct2Fill.m_StartLocation.z             = readfloat bstream
  44.         struct2Fill.m_StartLocation.w         = readfloat bstream
  45.         
  46.         --Vec3
  47.         struct2Fill.m_LastLocatorKey            = point3 (readfloat bstream) (readfloat bstream) (readfloat bstream)
  48.         --QuatT
  49.         struct2Fill.m_LastLocatorKey.x         = readfloat bstream
  50.         struct2Fill.m_LastLocatorKey.y         = readfloat bstream
  51.         struct2Fill.m_LastLocatorKey.z         = readfloat bstream
  52.         struct2Fill.m_LastLocatorKey.w         = readfloat bstream
  53.  
  54.         --Vec3
  55.         struct2Fill.m_vVelocity    = point3 (readfloat bstream) (readfloat bstream) (readfloat bstream)
  56.         
  57.         struct2Fill.m_fDistance                     = readfloat bstream
  58.         struct2Fill.m_fSpeed                     = readfloat bstream                            
  59.         struct2Fill.m_fSlope                         = readfloat bstream
  60.         struct2Fill.m_fTurnSpeed                 = readfloat bstream
  61.         struct2Fill.m_fAssetTurn                 = readfloat bstream
  62.     ),
  63.     
  64.     fn get_CAF_infoFrom_CHUNK_GAHCAF_INFO \
  65.                                                                 bstream: \
  66.                                                                 struct2Read: \
  67.                                                                 &struct2Fill: =
  68.     (
  69.         m_flags                             = readlong bstream #unsigned
  70.         
  71.         m_FilePath                         = ReadFixedString \
  72.                                                                         bstream:    &bstream \
  73.                                                                         fixedLen:    &struct2Fill.FILEPATH_SIZE
  74.         
  75.         m_FilePathCRC32             = readlong bstream #unsigned
  76.         m_FilePathDBACRC32         = readlong bstream #unsigned
  77.         
  78.         /*        
  79.         m_LHeelStart                     = readfloat bstream
  80.         m_LHeelEnd                     = readfloat bstream
  81.                             
  82.         m_LToe0Start                 = readfloat bstream
  83.         m_LToe0End                     = readfloat bstream
  84.                             
  85.         m_RHeelStart                     = readfloat bstream
  86.         m_RHeelEnd                     = readfloat bstream
  87.                             
  88.         m_RToe0Start                 = readfloat bstream
  89.         m_RToe0End                     = readfloat bstream
  90.                             
  91.                             
  92.         m_fStartSec                     = readfloat bstream
  93.         m_fEndSec                     = readfloat bstream
  94.         m_fTotalDuration             = readfloat bstream
  95.         m_nControllers                 = readlong bstream #unsigned --This is the number of bones/controllers                            
  96.         
  97.         --Vec3
  98.         T_StartLocation                = point3 (readfloat bstream) (readfloat bstream) (readfloat bstream)
  99.         --QuatT
  100.         m_StartLocation.x             = readfloat bstream
  101.         m_StartLocation.y             = readfloat bstream
  102.         m_StartLocation.z             = readfloat bstream
  103.         m_StartLocation.w             = readfloat bstream
  104.         
  105.         --Vec3
  106.         m_LastLocatorKey            = point3 (readfloat bstream) (readfloat bstream) (readfloat bstream)
  107.         --QuatT
  108.         m_LastLocatorKey.x         = readfloat bstream
  109.         m_LastLocatorKey.y         = readfloat bstream
  110.         m_LastLocatorKey.z         = readfloat bstream
  111.         m_LastLocatorKey.w         = readfloat bstream
  112.                             
  113.         --Vec3
  114.         m_vVelocity                    = point3 (readfloat bstream) (readfloat bstream) (readfloat bstream)
  115.                             
  116.         m_fDistance                     = readfloat bstream
  117.         m_fSpeed                         = readfloat bstream                            
  118.         m_fSlope                         = readfloat bstream
  119.         m_fTurnSpeed                 = readfloat bstream
  120.         m_fAssetTurn                     = readfloat bstream
  121.         --*/
  122.     ),
  123.     
  124.         -------- MotionParams905 --------
  125.     fn fill_CAF_MotionParams905 \
  126.                                             bstream: \
  127.                                             &struct2Fill: =
  128.     (
  129.         struct2Fill.m_nAssetFlags                         = readlong bstream #unsigned
  130.         struct2Fill.m_nCompression                     = readlong bstream #unsigned
  131.         
  132.         struct2Fill.m_nTicksPerFrame                     = readlong bstream        --//!< Unused (always assumed to be 1).
  133.         struct2Fill.m_fSecsPerTick                     = readfloat bstream        --//!< Unused (always assumed to be 1/30).
  134.         
  135.         struct2Fill.m_nStart                                 = readlong bstream
  136.         struct2Fill.m_nEnd                                 = readlong bstream
  137.         
  138.         struct2Fill.m_fMoveSpeed                         = readfloat bstream
  139.         struct2Fill.m_fTurnSpeed                         = readfloat bstream
  140.         struct2Fill.m_fAssetTurn                         = readfloat bstream
  141.         struct2Fill.m_fDistance                             = readfloat bstream
  142.         struct2Fill.m_fSlope                                 = readfloat bstream
  143.         
  144.         --Vec3
  145.         struct2Fill.T_StartLocation                        = point3 (readfloat bstream) (readfloat bstream) (readfloat bstream)
  146.         --QuatT
  147.         struct2Fill.m_StartLocation.x                     = readfloat bstream
  148.         struct2Fill.m_StartLocation.y                     = readfloat bstream
  149.         struct2Fill.m_StartLocation.z                     = readfloat bstream
  150.         struct2Fill.m_StartLocation.w                 = readfloat bstream
  151.         
  152.         --Vec3
  153.         struct2Fill.T_EndLocation                        = point3 (readfloat bstream) (readfloat bstream) (readfloat bstream)
  154.         --QuatT
  155.         struct2Fill.m_EndLocation.x                     = readfloat bstream
  156.         struct2Fill.m_EndLocation.y                     = readfloat bstream
  157.         struct2Fill.m_EndLocation.z                     = readfloat bstream
  158.         struct2Fill.m_EndLocation.w                     = readfloat bstream
  159.         
  160.         
  161.         
  162.         struct2Fill.m_LHeelStart                         = readfloat bstream
  163.         struct2Fill.m_LHeelEnd                             = readfloat bstream
  164.                             
  165.         struct2Fill.m_LToe0Start                         = readfloat bstream
  166.         struct2Fill.m_LToe0End                         = readfloat bstream
  167.                             
  168.         struct2Fill.m_RHeelStart                         = readfloat bstream
  169.         struct2Fill.m_RHeelEnd                             = readfloat bstream
  170.                             
  171.         struct2Fill.m_RToe0Start                         = readfloat bstream
  172.         struct2Fill.m_RToe0End                         = readfloat bstream
  173.     ),
  174.     
  175.     fn fill_CONTROLLER_CHUNK_DESC_0829 \
  176.                                                             bstream: \
  177.                                                             &struct2Fill: =
  178.     (
  179.         --TODO
  180. --         --We must fix the fill_CONTROLLER_CHUNK_DESC_0829 to read the correct specifed number of keys etc, now it doesn't take that into consideration!!!!
  181.         
  182. --         --enum { VERSION = 0x0829 };
  183.  
  184. --         --enum { eKeyTimeRotation = 0, eKeyTimePosition = 1 };
  185.         
  186.         --CONTROLLER ID
  187.         struct2Fill.nControllerId                 = readlong bstream #unsigned     --uint32      --//!< Unique controller ID (crc32 of the bone name).        
  188.         
  189.  
  190.         struct2Fill.numRotationKeys             = readshort bstream #unsigned     --uint16    --//!< Number of rotation keys stored within this chunk.
  191.         struct2Fill.numPositionKeys             = readshort bstream #unsigned     --uint16    --//!< Number of position keys stored within this chunk.
  192.         
  193.         struct2Fill.RotationFormat                 = readbyte bstream #unsigned     --uint8     --//!< Format identifier of the rotation value keys (see: ECompressionInformation enumeration type).
  194.         struct2Fill.RotationTimeFormat         = readbyte bstream #unsigned    --uint8     --//!< Format identifier of the rotation time keys (see: EKeyTimesFormat enumeration type).
  195.         struct2Fill.PositionFormat                 = readbyte bstream #unsigned    --uint8     --//!< Format identifier of the position value keys (see: ECompressionInformation enumeration type).
  196.         
  197.         struct2Fill.PositionKeysInfo             = readbyte bstream #unsigned    --uint8       --//!< Specifies which time key array is used by the position component (eKeyTimeRotation, eKeyTimePosition).
  198.         struct2Fill.PositionTimeFormat         = readbyte bstream #unsigned    --uint8     --//!< Format of identifier the position time keys (see: EKeyTimesFormat enumeration type). May not be used depending on the value of PositionKeysInfo.
  199.         struct2Fill.TracksAligned                 = readbyte bstream #unsigned    --uint8     --//!< If set to nonzero, signals that all key arrays are padded to a 4-byte boundary.
  200.     ),
  201.     
  202.     fn read_CHUNK_GAHCAF \
  203.                                     bstream: \
  204.                                     fileHeader: \
  205.                                     struct2read: =
  206.     (
  207.         for i=1 to ::g_CAF_CHUNKTABLE_FILE_CONSTANTS[1].nChunkTable_entries do
  208.         (
  209.             if struct2read.ChunkType[1][i] == 0x0007 AND \
  210.                 struct2read.ChunkType[2][i] == 0xAAFC then
  211.             (
  212.                 fseek bstream struct2read.FileOffset[1][i] #seek_set --jump to offset
  213.                 
  214.                 if struct2read.ChunkVersion[1][i] == 0x0971 then --if Ox0971
  215.                 (
  216.                     local struct2Fill = CHUNK_GAHCAF_INFO()
  217.                     
  218.                     local A     = readshort bstream #unsigned --should be 0x0007
  219.                     local B     = readshort bstream #unsigned --should be 0xAAFC
  220.                     local C     = readshort bstream --should be 0x0971                
  221.                         local D     = readshort bstream --usually 0x0000 unknown --we do not check for this as we do not know what it is
  222.                     local F     = readlong bstream #unsigned
  223.                     local ID = 0
  224.                     
  225.                     if fileHeader.version == 0x0745 then
  226.                     (
  227.                         ID = readlong bstream --chunk ID --//new in version 0x0745
  228.                         
  229.                         --confirm we are on the right chunk
  230.                         if  A == 0x0007 AND \
  231.                             B == 0xAAFC AND \            
  232.                             C == 0x0971 AND \
  233.                             ID == struct2read.ChunkID[1][i] AND \
  234.                             F == struct2read.FileOffset[1][i] then
  235.                         (
  236.                             --Store the Chunk ID
  237.                             struct2fill.chunkID = ID
  238.                             
  239.                             fill_CAF_struct \
  240.                                                     bstream:bstream \
  241.                                                     struct2Fill:&struct2Fill
  242.                             
  243.                             Append         ::g_CHUNK_GAHCAF_INFO         struct2Fill
  244.                         )
  245.                     )                    
  246.                 )
  247.             )
  248.             else if struct2read.ChunkType[1][i] == 0x0002 AND \
  249.                 struct2read.ChunkType[2][i] == 0xAAFC then
  250.             (
  251.                 fseek bstream struct2read.FileOffset[1][i] #seek_set --jump to offset
  252.                 
  253.                 if struct2read.ChunkVersion[1][i] == 0x0925 then --if 0x0925
  254.                 (
  255.                     local struct2Fill = MotionParams905()
  256.                     
  257.                     local A     = readshort bstream #unsigned --should be 0x0002
  258.                     local B     = readshort bstream #unsigned --should be 0xAAFC
  259.                     local C     = readshort bstream --should be 0x0925                
  260.                         local D     = readshort bstream --usually 0x0000 unknown --we do not check for this as we do not know what it is
  261.                     local F     = readlong bstream #unsigned
  262.                     local ID = 0
  263.                     
  264.                     if fileHeader.version == 0x0745 then
  265.                     (
  266.                         ID = readlong bstream --chunk ID --//new in version 0x0745
  267.                         
  268.                         --confirm we are on the right chunk
  269.                         if  A == 0x0002 AND \
  270.                             B == 0xAAFC AND \            
  271.                             C == 0x0925 AND \
  272.                             ID == struct2read.ChunkID[1][i] AND \
  273.                             F == struct2read.FileOffset[1][i] then
  274.                         (
  275.                             --Store the Chunk ID
  276.                             struct2fill.chunkID = ID
  277.                             
  278.                             fill_CAF_MotionParams905 \
  279.                                                                 bstream:bstream \
  280.                                                                 struct2Fill:&struct2Fill
  281.                             
  282.                             Append         ::g_MotionParams905     struct2Fill
  283.                         )
  284.                     )                    
  285.                 )
  286.                 
  287.             )
  288.             else if struct2read.ChunkType[1][i] == 0x0009 AND \
  289.                 struct2read.ChunkType[2][i] == 0xAAFC then
  290.             (
  291.                 fseek bstream struct2read.FileOffset[1][i] #seek_set --jump to offset
  292.                 
  293.                 if struct2read.ChunkVersion[1][i] == 0x0001 then --if 0x0829
  294.                 (
  295.                     local struct2Fill = ChunkType_BspTreeData()
  296.                     
  297.                     local A     = readshort bstream #unsigned --should be 0x0009
  298.                     local B     = readshort bstream #unsigned --should be 0xAAFC
  299.                     local C     = readshort bstream --should be 0x0001                
  300.                         local D     = readshort bstream --usually 0x0000 unknown --we do not check for this as we do not know what it is
  301.                     local F     = readlong bstream #unsigned
  302.                     local ID = 0
  303.                     
  304.                     if fileHeader.version == 0x0745 then
  305.                     (
  306.                         ID = readlong bstream --chunk ID --//new in version 0x0745
  307.                         
  308.                         --confirm we are on the right chunk
  309.                         if  A == 0x0009 AND \
  310.                             B == 0xAAFC AND \            
  311.                             C == 0x0001 AND \
  312.                             ID == struct2read.ChunkID[1][i] AND \
  313.                             F == struct2read.FileOffset[1][i] then
  314.                         (                            
  315.                             --Store the Chunk ID
  316.                             struct2fill.chunkID = ID
  317.                             
  318.                             struct2Fill.vec3_a = point3 (readfloat bstream) (readfloat bstream) (readfloat bstream)
  319.                             struct2Fill.vec3_b = point3 (readfloat bstream) (readfloat bstream) (readfloat bstream)
  320.                             
  321.                             Append         ::g_ChunkType_BspTreeData     struct2Fill
  322.                         )
  323.                     )
  324.                 )
  325.             )
  326.             else if struct2read.ChunkType[1][i] == 0x000D AND \
  327.                 struct2read.ChunkType[2][i] == 0xCCCC then
  328.             (
  329.                 fseek bstream struct2read.FileOffset[1][i] #seek_set --jump to offset
  330.                 
  331.                 if struct2read.ChunkVersion[1][i] == 0x0829 then --if 0x0829
  332.                 (
  333.                     local struct2Fill = CONTROLLER_CHUNK_DESC_0829()
  334.                     
  335.                     local A     = readshort bstream #unsigned --should be 0x000D
  336.                     local B     = readshort bstream #unsigned --should be 0xCCCC
  337.                     local C     = readshort bstream --should be 0x0829                
  338.                         local D     = readshort bstream --usually 0x0000 unknown --we do not check for this as we do not know what it is
  339.                     local F     = readlong bstream #unsigned
  340.                     local ID = 0
  341.                     
  342.                     if fileHeader.version == 0x0745 then
  343.                     (
  344.                         ID = readlong bstream --chunk ID --//new in version 0x0745
  345.                         
  346.                         --confirm we are on the right chunk
  347.                         if  A == 0x000D AND \
  348.                             B == 0xCCCC AND \            
  349.                             C == 0x0829 AND \
  350.                             ID == struct2read.ChunkID[1][i] AND \
  351.                             F == struct2read.FileOffset[1][i] then
  352.                         (                            
  353.                             --Store the Chunk ID
  354.                             struct2fill.chunkID = ID
  355.                             
  356.                             fill_CONTROLLER_CHUNK_DESC_0829 \
  357.                                                                                 bstream:        bstream \
  358.                                                                                 struct2Fill:        &struct2Fill
  359.                             
  360.                             Append         ::g_CONTROLLER_CHUNK_DESC_0829     struct2Fill
  361.                         )
  362.                     )
  363.                 )
  364.             )
  365.             
  366.         )
  367.     ),
  368.     
  369.     fn read_CHUNK_GAHCAF_INFO \
  370.                                                 caller: \
  371.                                                 bstream: \
  372.                                                 global_Append: =
  373.     (
  374.         if bstream != undefined then
  375.         (
  376.             if bstream != unsupplied then
  377.             (
  378.                 if iskindof bstream BinStream then
  379.                 (        
  380.                     --Put code in here
  381.                     print "We are inside the read_CHUNK_GAHCAF_INFO\n"
  382.                     
  383.                     --------------------Constants-----------------------
  384.                     inst_ChunkTypes = ChunkTypes()
  385.  
  386.                     ---------------------------------------- Check that the file indeed has the "CryTek" header ----------------------------------------
  387.                     local inst_FILE_HEADER = FILE_HEADER()
  388.                     
  389.                     inst_FILE_HEADER.Signature = ReadFixedString \
  390.                                                                                     bstream:    &bstream \
  391.                                                                                     fixedLen:    &(::g__CONST_SIGN_length)    --this will be checked later, must be "CryTek"                
  392.                     
  393.                     --We do NOT use stricmp here because we want the comparison to be case sensitive - to keep it strongly strict
  394.                     if inst_FILE_HEADER.Signature == ::g_CryTek_string then
  395.                     (
  396.                         local STAT = true
  397.                         
  398.                         read_FILE_HEADER \
  399.                                                     bstream:            bstream \
  400.                                                     struct2fill:            &inst_FILE_HEADER \
  401.                                                     global_Append:    ::g_CAF_FILE_HEADER \
  402.                                                     STAT:                &STAT
  403.                         
  404.                         if STAT then
  405.                         (
  406.                             local inst_CHUNKTABLE_FILE_CONSTANTS = CHUNKTABLE_FILE_CONSTANTS()
  407.                             read_CHUNKTABLE_FILE_CONSTANTS \
  408.                                                                                 bstream:            bstream \
  409.                                                                                 struct2read:        inst_FILE_HEADER \
  410.                                                                                 struct2fill:            &inst_CHUNKTABLE_FILE_CONSTANTS \
  411.                                                                                 global_Append:     ::g_CAF_CHUNKTABLE_FILE_CONSTANTS \
  412.                                                                                 STAT:                &STAT
  413.                             
  414.                             if STAT then
  415.                             (
  416.                                 --Can only be 1 (meaning there can only be one table in each CryFile - naturally)
  417.                                 if ::g_CHUNKTABLE_FILE_CONSTANTS.count == 1 then
  418.                                 (                
  419.                                     --Read ChunkTable
  420.                                     inst_CHUNKTABLE_0744_0745 = CHUNK_TABLE_0744_0745() --create instance of struct
  421.                                     read_ChunkTable_0744_0745 \
  422.                                                                             bstream:            bstream \
  423.                                                                             struct2read_A:    inst_FILE_HEADER \
  424.                                                                             struct2read_B:    inst_CHUNKTABLE_FILE_CONSTANTS \
  425.                                                                             struct2fill:            &inst_CHUNKTABLE_0744_0745 \
  426.                                                                             global_Append:    ::g_CAF_CHUNKTABLE_0744_0745 \
  427.                                                                             STAT:                &STAT
  428.                                     if STAT then
  429.                                     (
  430.                                         format "STAT: %\n" STAT
  431.                                         
  432.                                         read_CHUNK_GAHCAF \
  433.                                                                         bstream:        bstream \
  434.                                                                         fileHeader:        inst_FILE_HEADER \
  435.                                                                         struct2read:    inst_CHUNKTABLE_0744_0745
  436.                                     )                                    
  437.                                 )
  438.                             )                            
  439.                         )                        
  440.                     )
  441.                     else
  442.                     (
  443.                         format "***Signature Check Failed - Cannot create BinStream - Aborting CAF reading***\n"
  444.                     )                    
  445.                 )
  446.                 else
  447.                 (
  448.                     format "***This is not a BinStream - Aborting CAF reading***\n"
  449.                 )
  450.             )
  451.             else
  452.             (
  453.                 format "***BinStream is unsupplied - Aborting CAF reading***\n"
  454.             )
  455.         )
  456.         else
  457.         (
  458.             format "***BinStream is undefined - Aborting CAF reading***\n"
  459.         )
  460.     ),
  461.     
  462.     fn load_CAF \
  463.                         caller: \
  464.                         CAF_file: =
  465.     (
  466.         if CAF_file != undefined then
  467.         (
  468.             if CAF_file != unsupplied then
  469.             (
  470.                 -----------------------------------Load--------------------------------------
  471.                 bstream = fopen CAF_file "rb" --open binary stream
  472.  
  473.                 --//////////////////////////
  474.                 if caller == "IMG" OR \
  475.                     caller == ".img" then
  476.                 (
  477.                     read_CHUNK_GAHCAF_INFO \
  478.                                                             caller:        caller \
  479.                                                             bstream:    bstream    
  480.                 )
  481.                 else if caller == "CAF" OR \
  482.                     caller == ".caf" then
  483.                 (
  484.                     read_CHUNK_GAHCAF_INFO \
  485.                                                             caller:        caller \
  486.                                                             bstream:    bstream    
  487.                 )
  488.                 --//////////////////////////                        
  489.                 
  490.                 --------------------------------End of Load---------------------------------
  491.                 fclose bstream    --Close & Flush Binary Stream
  492.             )
  493.         )
  494.     )
  495.     
  496. )