sewer56lol

Sonic Riders PVRT to DXT Conversion

May 4th, 2021 (edited)
609
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.23 KB | None | 0 0
  1. void __cdecl MakeDdsFile(DDS_HEADER_WITH_MAGIC *ddsHeader, const void *pSrcData, signed int width, signed int height, __int16 a5)
  2. {
  3.   unsigned int widthCopy; // edx
  4.   unsigned int v6; // ebp
  5.   DWORD v7; // ecx
  6.   DWORD v8; // ecx
  7.   DWORD v9; // ecx
  8.   DWORD v10; // ecx
  9.   DWORD v11; // ecx
  10.   DWORD v12; // ecx
  11.   unsigned int rgbBitCount; // eax
  12.   DWORD pitchOrLinearSize; // eax
  13.   DWORD v15; // eax
  14.   DWORD v16; // eax
  15.   int v17; // [esp+10h] [ebp-4h]
  16.  
  17.   widthCopy = height;
  18.   v6 = a5 & 0xFF00;
  19.   v17 = 0;
  20.   ddsHeader->dwSize = 124;
  21.   ddsHeader->dwFlags = 0x1007;
  22.   ddsHeader->dwHeight = height;
  23.   ddsHeader->dwWidth = width;
  24.   if ( v6 <= 0x7600 )
  25.   {
  26.     if ( v6 == 0x7600 )
  27.     {
  28.       ddsHeader->dwFlags = 0xA1007;
  29.       ddsHeader->ddspf.dwFlags = 4;
  30.       ddsHeader->ddspf.dwFourCC = '2TXD';
  31.       ddsHeader->dwCaps = 0x401008;
  32.       v17 = 1;
  33.       goto LABEL_31;
  34.     }
  35.     if ( v6 > 0x7300 )
  36.     {
  37.       if ( v6 == 0x7400 )
  38.       {
  39.         ddsHeader->dwFlags = 0xA1007;
  40.         ddsHeader->ddspf.dwFlags = 4;
  41.         ddsHeader->ddspf.dwFourCC = '1TXD';
  42.         ddsHeader->dwCaps = 0x401008;
  43.         v17 = 1;
  44.         goto LABEL_31;
  45.       }
  46.       if ( v6 != 0x7500 )
  47.         goto LABEL_31;
  48.       ddsHeader->ddspf.dwFourCC = '2TXD';
  49.     }
  50.     else
  51.     {
  52.       if ( v6 != 0x7300 )
  53.       {
  54.         if ( v6 != 0x7000 )
  55.         {
  56.           if ( v6 == 0x7100 )
  57.           {
  58.             ddsHeader->ddspf.dwFlags = 0x40;
  59.             ddsHeader->ddspf.dwFourCC = 0;
  60.             ddsHeader->dwFlags = 0x2100F;
  61.             ddsHeader->dwCaps = 0x401008;
  62.             goto LABEL_31;
  63.           }
  64.           if ( v6 != 29184 )
  65.             goto LABEL_31;
  66.         }
  67.         ddsHeader->dwFlags = 0x100F;
  68.         ddsHeader->ddspf.dwFlags = 0x40;
  69.         ddsHeader->ddspf.dwFourCC = 0;
  70.         goto LABEL_30;
  71.       }
  72.       ddsHeader->ddspf.dwFourCC = 827611204;
  73.     }
  74. LABEL_29:
  75.     ddsHeader->dwFlags = 0x81007;
  76.     ddsHeader->ddspf.dwFlags = 4;
  77.     v17 = 1;
  78. LABEL_30:
  79.     ddsHeader->dwCaps = 0x1000;
  80.     goto LABEL_31;
  81.   }
  82.   if ( v6 <= 0x7A00 )
  83.   {
  84.     switch ( v6 )
  85.     {
  86.       case 0x7A00u:
  87.         ddsHeader->dwFlags = 0xA1007;
  88.         ddsHeader->ddspf.dwFlags = 4;
  89.         ddsHeader->ddspf.dwFourCC = '4TXD';
  90.         ddsHeader->dwCaps = (DWORD)sub_401008;
  91.         v17 = 1;
  92.         goto LABEL_31;
  93.       case 0x7700u:
  94.         ddsHeader->ddspf.dwFourCC = '3TXD';
  95.         break;
  96.       case 0x7800u:
  97.         ddsHeader->dwFlags = 0xA1007;
  98.         ddsHeader->ddspf.dwFlags = 4;
  99.         ddsHeader->ddspf.dwFourCC = '3TXD';
  100.         ddsHeader->dwCaps = (DWORD)sub_401008;
  101.         v17 = 1;
  102.         goto LABEL_31;
  103.       case 0x7900u:
  104.         ddsHeader->ddspf.dwFourCC = '4TXD';
  105.         break;
  106.       default:
  107.         goto LABEL_31;
  108.     }
  109.     goto LABEL_29;
  110.   }
  111.   if ( v6 == 0x7B00 )
  112.   {
  113.     ddsHeader->ddspf.dwFourCC = '5TXD';
  114.     goto LABEL_29;
  115.   }
  116.   if ( v6 == 0x7C00 )
  117.   {
  118.     ddsHeader->dwFlags = 0xA1007;
  119.     ddsHeader->ddspf.dwFlags = 4;
  120.     ddsHeader->ddspf.dwFourCC = '5TXD';
  121.     ddsHeader->dwCaps = (DWORD)sub_401008;
  122.     v17 = 1;
  123.   }
  124. LABEL_31:
  125.   ddsHeader->dwDepth = 0;
  126.   ddsHeader->dwMipMapCount = 0;
  127.   if ( v6 > 0x7800 )
  128.   {
  129.     if ( v6 != 0x7A00 && v6 != 0x7C00 )
  130.       goto LABEL_52;
  131.     goto LABEL_60;
  132.   }
  133.   if ( v6 == 0x7800 )
  134.   {
  135. LABEL_60:
  136.     if ( width < height )
  137.       widthCopy = width;
  138.     if ( widthCopy <= 0x40 )
  139.     {
  140.       if ( widthCopy == 64 )
  141.       {
  142. LABEL_45:
  143.         ddsHeader->dwMipMapCount = 5;
  144.       }
  145.       else
  146.       {
  147.         switch ( widthCopy )
  148.         {
  149.           case 4u:
  150.             ddsHeader->dwMipMapCount = 1;
  151.             break;
  152.           case 8u:
  153.             goto LABEL_42;
  154.           case 0x10u:
  155.             goto LABEL_43;
  156.           case 0x20u:
  157.             goto LABEL_44;
  158.           default:
  159.             goto LABEL_72;
  160.         }
  161.       }
  162.       goto LABEL_52;
  163.     }
  164.     if ( widthCopy <= 0x200 )
  165.     {
  166.       if ( widthCopy != 512 )
  167.       {
  168.         if ( widthCopy == 128 )
  169.         {
  170. LABEL_46:
  171.           ddsHeader->dwMipMapCount = 6;
  172.           goto LABEL_52;
  173.         }
  174.         if ( widthCopy == 256 )
  175.           goto LABEL_70;
  176. LABEL_72:
  177.         ddsHeader->dwMipMapCount = 0;
  178.         goto LABEL_52;
  179.       }
  180. LABEL_53:
  181.       ddsHeader->dwMipMapCount = 8;
  182.       goto LABEL_52;
  183.     }
  184.     if ( widthCopy != 1024 )
  185.       goto LABEL_72;
  186. LABEL_51:
  187.     ddsHeader->dwMipMapCount = 9;
  188.     goto LABEL_52;
  189.   }
  190.   if ( v6 != 0x7100 )
  191.   {
  192.     if ( v6 != 0x7400 && v6 != 0x7600 )
  193.       goto LABEL_52;
  194.     goto LABEL_60;
  195.   }
  196.   if ( width < height )
  197.     widthCopy = width;
  198.   if ( widthCopy > 0x40 )
  199.   {
  200.     if ( widthCopy > 0x200 )
  201.     {
  202.       if ( widthCopy == 1024 )
  203.       {
  204.         ddsHeader->dwMipMapCount = 11;
  205.         goto LABEL_52;
  206.       }
  207.     }
  208.     else
  209.     {
  210.       switch ( widthCopy )
  211.       {
  212.         case 0x200u:
  213.           ddsHeader->dwMipMapCount = 10;
  214.           goto LABEL_52;
  215.         case 0x80u:
  216.           goto LABEL_53;
  217.         case 0x100u:
  218.           goto LABEL_51;
  219.       }
  220.     }
  221. LABEL_56:
  222.     ddsHeader->dwMipMapCount = 0;
  223.     goto LABEL_52;
  224.   }
  225.   if ( widthCopy == 64 )
  226.   {
  227. LABEL_70:
  228.     ddsHeader->dwMipMapCount = 7;
  229.     goto LABEL_52;
  230.   }
  231.   switch ( widthCopy )
  232.   {
  233.     case 2u:
  234. LABEL_42:
  235.       ddsHeader->dwMipMapCount = 2;
  236.       break;
  237.     case 4u:
  238. LABEL_43:
  239.       ddsHeader->dwMipMapCount = 3;
  240.       break;
  241.     case 8u:
  242. LABEL_44:
  243.       ddsHeader->dwMipMapCount = 4;
  244.       break;
  245.     case 0x10u:
  246.       goto LABEL_45;
  247.     case 0x20u:
  248.       goto LABEL_46;
  249.     default:
  250.       goto LABEL_56;
  251.   }
  252. LABEL_52:
  253.   ddsHeader->ddspf.dwSize = 32;
  254.   ddsHeader->dwReserved1[0] = 0;
  255.   ddsHeader->dwReserved1[1] = 0;
  256.   ddsHeader->dwReserved1[2] = 0;
  257.   ddsHeader->dwReserved1[3] = 0;
  258.   ddsHeader->dwReserved1[4] = 0;
  259.   ddsHeader->dwReserved1[5] = 0;
  260.   ddsHeader->dwReserved1[6] = 0;
  261.   ddsHeader->dwReserved1[7] = 0;
  262.   ddsHeader->dwReserved1[8] = 0;
  263.   ddsHeader->dwReserved1[9] = 0;
  264.   ddsHeader->dwReserved1[10] = 0;
  265.   switch ( (char)a5 )
  266.   {
  267.     case 0:
  268.     case 1:
  269.     case 9:
  270.     case 10:
  271.       ddsHeader->ddspf.dwRGBBitCount = 8;
  272.       goto LABEL_91;
  273.     case 2:
  274.       v7 = ddsHeader->ddspf.dwFlags | 1;
  275.       ddsHeader->ddspf.dwRBitMask = 0x7C00;
  276.       ddsHeader->ddspf.dwGBitMask = 0x3E0;
  277.       ddsHeader->ddspf.dwBBitMask = 0x1F;
  278.       ddsHeader->ddspf.dwABitMask = 0x8000;
  279.       ddsHeader->ddspf.dwRGBBitCount = 16;
  280.       ddsHeader->ddspf.dwFlags = v7;
  281.       break;
  282.     case 3:
  283.       ddsHeader->ddspf.dwRBitMask = 0x7C00;
  284.       goto LABEL_79;
  285.     case 4:
  286.       v8 = ddsHeader->ddspf.dwFlags | 1;
  287.       ddsHeader->ddspf.dwRBitMask = 0xF00;
  288.       ddsHeader->ddspf.dwGBitMask = 0xF0;
  289.       ddsHeader->ddspf.dwBBitMask = 0xF;
  290.       ddsHeader->ddspf.dwABitMask = 61440;
  291.       ddsHeader->ddspf.dwRGBBitCount = 16;
  292.       ddsHeader->ddspf.dwFlags = v8;
  293.       break;
  294.     case 5:
  295.     case 19:
  296.       ddsHeader->ddspf.dwRBitMask = 0xF800;
  297.       ddsHeader->ddspf.dwGBitMask = 0x7E0;
  298.       ddsHeader->ddspf.dwBBitMask = 0x1F;
  299.       ddsHeader->ddspf.dwRGBBitCount = 16;
  300.       goto LABEL_93;
  301.     case 6:
  302.       ddsHeader->ddspf.dwRBitMask = 0xFF0000;
  303.       ddsHeader->ddspf.dwBBitMask = 0xFF;
  304.       goto LABEL_88;
  305.     case 7:
  306.       ddsHeader->ddspf.dwRBitMask = 0xFF0000;
  307.       ddsHeader->ddspf.dwGBitMask = 0xFF00;
  308.       ddsHeader->ddspf.dwBBitMask = 0xFF;
  309.       ddsHeader->ddspf.dwRGBBitCount = 32;
  310.       goto LABEL_93;
  311.     case 8:
  312.     case 18:
  313.     case 22:
  314.     case 26:
  315.       ddsHeader->ddspf.dwRGBBitCount = 32;
  316.       goto LABEL_91;
  317.     case 11:
  318.       v9 = ddsHeader->ddspf.dwFlags | 1;
  319.       ddsHeader->ddspf.dwRBitMask = 0;
  320.       ddsHeader->ddspf.dwGBitMask = 0;
  321.       ddsHeader->ddspf.dwBBitMask = 0;
  322.       ddsHeader->ddspf.dwABitMask = 0xFF00;
  323.       ddsHeader->ddspf.dwRGBBitCount = 16;
  324.       ddsHeader->ddspf.dwFlags = v9;
  325.       break;
  326.     case 12:
  327.       ddsHeader->ddspf.dwRBitMask = 0xFC00;
  328. LABEL_79:
  329.       ddsHeader->ddspf.dwGBitMask = 0x3E0;
  330.       ddsHeader->ddspf.dwBBitMask = 0x1F;
  331.       ddsHeader->ddspf.dwRGBBitCount = 16;
  332.       goto LABEL_93;
  333.     case 13:
  334.     case 14:
  335.     case 17:
  336.     case 25:
  337.       ddsHeader->ddspf.dwRGBBitCount = 16;
  338. LABEL_91:
  339.       ddsHeader->ddspf.dwGBitMask = 0;
  340.       ddsHeader->ddspf.dwBBitMask = 0;
  341.       goto LABEL_92;
  342.     case 15:
  343.       ddsHeader->ddspf.dwGBitMask = 0xFF00;
  344.       ddsHeader->ddspf.dwBBitMask = 0xFF;
  345.       ddsHeader->ddspf.dwRGBBitCount = 16;
  346. LABEL_92:
  347.       ddsHeader->ddspf.dwRBitMask = 0;
  348.       goto LABEL_93;
  349.     case 16:
  350.       ddsHeader->ddspf.dwRBitMask = 0xFF00;
  351.       ddsHeader->ddspf.dwGBitMask = 0;
  352.       ddsHeader->ddspf.dwBBitMask = 0xFF;
  353.       ddsHeader->ddspf.dwRGBBitCount = 16;
  354. LABEL_93:
  355.       ddsHeader->ddspf.dwABitMask = 0;
  356.       break;
  357.     case 20:
  358.       v10 = ddsHeader->ddspf.dwFlags | 1;
  359.       ddsHeader->ddspf.dwRBitMask = 0xF000;
  360.       ddsHeader->ddspf.dwGBitMask = 0xF00;
  361.       ddsHeader->ddspf.dwBBitMask = 0xF0;
  362.       ddsHeader->ddspf.dwABitMask = 0xF;
  363.       ddsHeader->ddspf.dwRGBBitCount = 16;
  364.       ddsHeader->ddspf.dwFlags = v10;
  365.       break;
  366.     case 21:
  367.     case 24:
  368.       v12 = ddsHeader->ddspf.dwFlags | 1;
  369.       ddsHeader->ddspf.dwRBitMask = 0xFF;
  370.       ddsHeader->ddspf.dwGBitMask = 0xFF00;
  371.       ddsHeader->ddspf.dwBBitMask = 0xFF0000;
  372.       ddsHeader->ddspf.dwABitMask = 0xFF000000;
  373.       ddsHeader->ddspf.dwRGBBitCount = 32;
  374.       ddsHeader->ddspf.dwFlags = v12;
  375.       break;
  376.     case 23:
  377.       ddsHeader->ddspf.dwRBitMask = 0xFF;
  378.       ddsHeader->ddspf.dwBBitMask = 0xFF0000;
  379. LABEL_88:
  380.       v11 = ddsHeader->ddspf.dwFlags | 1;
  381.       ddsHeader->ddspf.dwGBitMask = 0xFF00;
  382.       ddsHeader->ddspf.dwABitMask = 0xFF000000;
  383.       ddsHeader->ddspf.dwRGBBitCount = 32;
  384.       ddsHeader->ddspf.dwFlags = v11;
  385.       break;
  386.     default:
  387.       break;
  388.   }
  389.   ddsHeader->dwCaps2 = 0;
  390.   ddsHeader->dwCaps3 = 0;
  391.   ddsHeader->dwCaps4 = 0;
  392.   ddsHeader->dwReserved2 = 0;
  393.   rgbBitCount = ddsHeader->ddspf.dwRGBBitCount;
  394.   if ( (ddsHeader->dwFlags & 8) != 0 )
  395.     pitchOrLinearSize = width * (rgbBitCount >> 2);
  396.   else
  397.     pitchOrLinearSize = MakeDdsCalculatePitchOrLinearSize(width, height, rgbBitCount, ddsHeader->dwMipMapCount, v17);
  398.   ddsHeader->dwPitchOrLinearSize = pitchOrLinearSize;
  399.   // 'DDS '
  400.   LOBYTE(ddsHeader->Magic) = 68;
  401.   BYTE1(ddsHeader->Magic) = 68;
  402.   BYTE2(ddsHeader->Magic) = 83;
  403.   HIBYTE(ddsHeader->Magic) = 32;
  404.   if ( v6 == 0x7000 )
  405.   {
  406.     v16 = ddsHeader->ddspf.dwRGBBitCount;
  407.     switch ( v16 )
  408.     {
  409.       case 8u:
  410.         sub_543530((int)&ddsHeader[1], (char *)pSrcData, width, height);
  411.         break;
  412.       case 16u:
  413.         sub_543980(&ddsHeader[1], pSrcData, width, height);
  414.         break;
  415.       case 32u:
  416.         sub_543DE0(&ddsHeader[1], pSrcData, width, height);
  417.         break;
  418.     }
  419.   }
  420.   else if ( v6 == 0x7100 )
  421.   {
  422.     v15 = ddsHeader->ddspf.dwRGBBitCount;
  423.     switch ( v15 )
  424.     {
  425.       case 8u:
  426.         sub_543920((int)&ddsHeader[1], (int)pSrcData, width, height);
  427.         break;
  428.       case 16u:
  429.         sub_543D80(&ddsHeader[1], pSrcData, width, height);
  430.         break;
  431.       case 32u:
  432.         sub_5441D0(&ddsHeader[1], pSrcData, width, height);
  433.         break;
  434.     }
  435.   }
  436.   else
  437.   {
  438.     qmemcpy(
  439.       &ddsHeader[1],
  440.       pSrcData,
  441.       MakeDdsCalculatePitchOrLinearSize(width, height, ddsHeader->ddspf.dwRGBBitCount, ddsHeader->dwMipMapCount, v17));
  442.   }
  443. }
Add Comment
Please, Sign In to add comment