Advertisement
Guest User

studiomodel big endian

a guest
Aug 31st, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.03 KB | None | 0 0
  1. #ifdef XASH_BIG_ENDIAN
  2.  
  3. // swap all fields in ibuffer starting given field (4byte type)
  4. #define SWAP_INTS(type, startfield) \
  5. for( i = offsetof(type, startfield)/4; i < sizeof(type)/4; i++ ) \
  6.     LittleLongSW(ibuffer[i])
  7.  
  8. // swap all fields in sbuffer starting given field (2byte type)
  9. #define SWAP_SHORTS(type, startfield) \
  10. for( i = offsetof(type, startfield)/2; i < sizeof(type)/2; i++ ) \
  11.     LittleShortSW(sbuffer[i])
  12.  
  13. /*
  14. =========================
  15. Mod_StudioBigEndian
  16. Swap all model fields for big endian system
  17. =========================
  18. */
  19. void Mod_StudioBigEndian( model_t *model, byte *buffer )
  20. {
  21.     studiohdr_t *phdr = buffer;
  22.     int *ibuffer = buffer;
  23.     short *sbuffer;
  24.     int i,j,k, bodyCount = 0;
  25.     mstudiomodel_t *pSubModel;
  26.  
  27.     if( LittleLong(phdr->ident) != IDSTUDIOHEADER )
  28.         return;
  29.  
  30.     LittleLongSW(phdr->ident);
  31.     LittleLongSW(phdr->length);
  32.  
  33.     SWAP_INTS(studiohdr_t,eyeposition);
  34.  
  35.     for( j = 0; j < phdr->numbones; j++ )
  36.     {
  37.         ibuffer = (byte*)phdr + phdr->boneindex + sizeof(mstudiobone_t) * j;
  38.         SWAP_INTS(mstudiobone_t,parent);
  39.     }
  40.  
  41.     for( j = 0; j < phdr->numbonecontrollers; j++ )
  42.     {
  43.         ibuffer = (byte*)phdr + phdr->bonecontrollerindex + sizeof(mstudiobonecontroller_t) * j;
  44.         SWAP_INTS(mstudiobonecontroller_t,bone);
  45.     }
  46.  
  47.     for( j = 0; j < phdr->numhitboxes; j++ )
  48.     {
  49.         ibuffer = (byte*)phdr + phdr->hitboxindex + sizeof(mstudiobbox_t) * j;
  50.         SWAP_INTS(mstudiobbox_t,bone);
  51.     }
  52.  
  53.     for( j = 0; j < phdr->numtextures; j++ )
  54.     {
  55.         ibuffer = (byte*)phdr + phdr->textureindex + sizeof(mstudiotexture_t) * j;
  56.         SWAP_INTS(mstudiotexture_t,flags);
  57.     }
  58.  
  59.  
  60.     for( j = 0; j < phdr->numseq; j++ )
  61.     {
  62.         mstudioseqdesc_t *pseqdesc = (byte*)phdr + phdr->seqindex + sizeof(mstudioseqdesc_t) * j;
  63.         mstudioanim_t *panim;//, *panimend;
  64.         int m;
  65.  
  66.         ibuffer = (byte*)phdr + phdr->seqindex + sizeof(mstudioseqdesc_t) * j;
  67.         SWAP_INTS(mstudioseqdesc_t,fps);
  68.  
  69.         for( k = 0; k < pseqdesc->numpivots; k++ )
  70.         {
  71.             ibuffer = (byte*)phdr + pseqdesc->pivotindex +  sizeof(mstudiopivot_t) * j;
  72.             SWAP_INTS(mstudiopivot_t,org);
  73.         }
  74.  
  75.         // preload and swap external seqgroups
  76.         if( pseqdesc->seqgroup )
  77.         {
  78.             mstudioseqgroup_t   *pseqgroup;
  79.             fs_offset_t     filesize;
  80.             byte        *buf;
  81.             cache_user_t    *paSequences;
  82.  
  83.             if( !model )
  84.                 continue; // not loading model
  85.  
  86.             pseqgroup = (mstudioseqgroup_t *)((byte *)phdr + phdr->seqgroupindex) + pseqdesc->seqgroup;
  87.  
  88.             paSequences = (cache_user_t *)model->submodels;
  89.             if( paSequences == NULL )
  90.             {
  91.                 paSequences = (cache_user_t *)Mem_Alloc( com_studiocache, MAXSTUDIOGROUPS * sizeof( cache_user_t ));
  92.                 model->submodels = (void *)paSequences;
  93.             }
  94.  
  95.             // check for already loaded
  96.             if( !paSequences[pseqdesc->seqgroup].data )
  97.             {
  98.                 string  filepath, modelname, modelpath;
  99.  
  100.                 FS_FileBase( model->name, modelname );
  101.                 FS_ExtractFilePath( model->name, modelpath );
  102.  
  103.                 // NOTE: here we build real sub-animation filename because stupid user may rename model without recompile
  104.                 Q_snprintf( filepath, sizeof( filepath ), "%s/%s%i%i.mdl", modelpath, modelname, pseqdesc->seqgroup / 10, pseqdesc->seqgroup % 10 );
  105.  
  106.                 buf = FS_LoadFile( filepath, &filesize, false );
  107.                 if( !buf || !filesize )
  108.                     Host_Error( "StudioGetAnim: can't load %s\n", filepath );
  109.                 else if( IDSEQGRPHEADER != LittleLong(*(uint *)buf ))
  110.                     Host_Error( "StudioGetAnim: %s is corrupted\n", filepath );
  111.  
  112.                 MsgDev( D_INFO, "loading: %s\n", filepath );
  113.  
  114.                 paSequences[pseqdesc->seqgroup].data = Mem_Alloc( com_studiocache, filesize );
  115.                 Q_memcpy( paSequences[pseqdesc->seqgroup].data, buf, (size_t)filesize );
  116.                 Mem_Free( buf );
  117.             }
  118.  
  119.             panim = (mstudioanim_t *)((byte *)paSequences[pseqdesc->seqgroup].data + pseqdesc->animindex);
  120.             //panimend = (mstudioanim_t *)((byte *)paSequences[pseqdesc->seqgroup].data + filesize);
  121.         }
  122.         else
  123.         {
  124.             panim = (byte*)phdr + pseqdesc->animindex;
  125.             //panimend = pseqdesc;
  126.         }
  127.  
  128.         // swap animations
  129.         for( m = 0; m < phdr->numbones * pseqdesc->numblends; m++ )
  130.         {
  131.             /*mstudioanimvalue_t *panim1 = panimend;
  132.             if( m < phdr->numbones * pseqdesc->numblends -
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement