Advertisement
Brick

Midtown Madness 2 Installer Patcher

Sep 22nd, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.03 KB | None | 0 0
  1. #include <algorithm>    // std::copy, std::copy_n
  2. #include <iterator>     // std::istreambuf_iterator, std::ostreambuf_iterator, std::back_inserter
  3. #include <vector>       // std::vector
  4. #include <fstream>      // std::ifstream, std::ofstream
  5.  
  6. template <typename T, typename CharT>
  7. T IStreamRead(std::basic_istream<CharT>& stream)
  8. {
  9.     return T
  10.     (
  11.         std::istreambuf_iterator<CharT>(stream),
  12.         std::istreambuf_iterator<CharT>()
  13.     );
  14. }
  15.  
  16. template <typename CharT>
  17. std::vector<CharT> BufferRead_N(std::basic_istream<CharT>& stream, std::size_t read)
  18. {
  19.     std::vector<CharT> out;
  20.  
  21.     std::copy_n(std::istreambuf_iterator<CharT>(stream), read, std::back_inserter(out));
  22.    
  23.     return out;
  24. }
  25.  
  26. template <typename T, typename CharT>
  27. void IStreamWrite(std::basic_ostream<CharT>& stream, T& write)
  28. {
  29.     std::copy(write.begin(), write.end(), std::ostreambuf_iterator<CharT>(stream));
  30. };
  31.  
  32. #include <iostream>
  33. #include <string>
  34.  
  35. #include <Windows.h>
  36.  
  37. struct MM2FileHeader
  38. {
  39.     WORD entryCount;
  40.     WORD word02;
  41.     DWORD dword4;
  42.     DWORD dword8;
  43.     DWORD dwordC;
  44.     DWORD firstEntryOffset;
  45. };
  46.  
  47. struct MM2FileStruct
  48. {
  49.     DWORD dword00;
  50.     DWORD dword04;
  51.     DWORD dword08;
  52.     DWORD dword0C;
  53.     DWORD dword10;
  54.     FILETIME fileTime;
  55.     DWORD dword1C;
  56.     WORD firstStringLength;
  57. };
  58.  
  59. struct MM2InstallerEntry
  60. {
  61.     WORD entryType; // 10
  62.     WORD field02;
  63.     DWORD field04;
  64.     DWORD dword8; // 11
  65.     DWORD dwordC; // 0
  66.     WORD word10; // 19
  67.     WORD word12;
  68.     DWORD entrySize;
  69.     DWORD dword18; // 1
  70.     DWORD dword1C;
  71.     DWORD dword20; // 4294967295
  72.     BYTE byte24;
  73.     BYTE gap25;
  74.     WORD field26;
  75.     DWORD fileSize;
  76.     DWORD field2C;
  77.     DWORD field30;
  78.     DWORD lpUnkString;
  79.     MM2InstallerEntry* lpNextEntry2;
  80.     MM2InstallerEntry* lpNextEntry;
  81.     WORD gap40;
  82.     WORD field_42;
  83.     WORD field_44;
  84.     WORD field_46;
  85.  
  86.     MM2FileStruct fileStruct;
  87. };
  88.  
  89. const char* months[ ] =
  90. {
  91.     "January",
  92.     "Februray",
  93.     "March",
  94.     "April",
  95.     "May",
  96.     "June",
  97.     "July",
  98.     "August",
  99.     "September",
  100.     "October",
  101.     "November",
  102.     "December"
  103. };
  104.  
  105. void view()
  106. {
  107.     std::vector<BYTE> bytes = IStreamRead<std::vector<BYTE>>
  108.     (
  109.         std::ifstream("SETUPDATA.bin", std::ifstream::binary)
  110.     );
  111.  
  112.     MM2FileHeader* header = (MM2FileHeader*)(bytes.data());
  113.  
  114.     WORD itemCount = header->entryCount;
  115.  
  116.     MM2InstallerEntry* currentEntry = (MM2InstallerEntry*)((char*)(&header->dwordC) + header->firstEntryOffset);
  117.  
  118.     while (itemCount-- > 0)
  119.     {
  120.         DebugBreak();
  121.  
  122.         switch (currentEntry->entryType)
  123.         {
  124.             case 3:
  125.             {
  126.  
  127.             } break;
  128.  
  129.             case 2: case 11:
  130.             {
  131.  
  132.             } break;
  133.  
  134.             case 10:
  135.             {
  136.                 char* from = (char*)(&currentEntry->fileStruct.firstStringLength) + 2;
  137.                 char* to = from + currentEntry->fileStruct.firstStringLength;
  138.                 char* copyType = to + strlen(to) + 1; // 1 = Always, 2 = Only in full version
  139.                 char* unkNumber2 = copyType + strlen(copyType) + 1; // Always -1;
  140.  
  141.                 SYSTEMTIME systemTime;
  142.                 FileTimeToSystemTime(&currentEntry->fileStruct.fileTime, &systemTime);
  143.  
  144.                 printf_s("Copy File %24s to %24s | %s, %s - %hu %s %hu \n",
  145.                          from,
  146.                          to,
  147.                          copyType,
  148.                          unkNumber2,
  149.                          systemTime.wDay,
  150.                          months[systemTime.wMonth],
  151.                          systemTime.wYear);
  152.             } break;
  153.  
  154.             case 13:  
  155.             {
  156.                 // Set some global variable to true
  157.             } break;
  158.         };
  159.  
  160.         currentEntry = (MM2InstallerEntry*)((char*)currentEntry + currentEntry->entrySize + 0x48);
  161.     };
  162.  
  163.     std::cin.get();
  164. }
  165.  
  166. #include <array>
  167.  
  168. int main()
  169. {
  170.     view();
  171.     return 0;
  172.  
  173.     //std::vector<char> fileBytes = IStreamRead<std::vector<char>>
  174.     //(
  175.     //    std::ifstream("SETUPDATA.bin", std::ifstream::binary)
  176.     //);
  177.  
  178.     //WORD* entryCount = (WORD*)(fileBytes.data() + 0);
  179.  
  180.     std::vector<char> fileBytes;
  181.    
  182.     std::vector<std::array<std::string, 2>> mods =
  183.     {
  184.         { "mods\\! !rv5_audio.ar", "! !rv5_audio.ar" },
  185.         { "mods\\! !rv5_buckNeye.ar", "! !rv5_buckNeye.ar" },
  186.         { "mods\\! !rv5_graphics.ar", "! !rv5_graphics.ar" },
  187.         { "mods\\! !rv5_groover.ar", "! !rv5_groover.ar" },
  188.         { "mods\\! !rv5_LOD.ar", "! !rv5_LOD.ar" },
  189.         { "mods\\! !rv5_maincars.ar", "! !rv5_maincars.ar" },
  190.         { "mods\\! !rv5_maincity.ar", "! !rv5_maincity.ar" },
  191.         { "mods\\! !rv5_materials.ar", "! !rv5_materials.ar" },
  192.         { "mods\\! !rv5_mirrordist.ar", "! !rv5_mirrordist.ar" },
  193.         { "mods\\! !rv5_pickupNvan.ar", "! !rv5_pickupNvan.ar" },
  194.         { "mods\\! !rv5_seagulls.ar", "! !rv5_seagulls.ar" },
  195.         { "mods\\! !rv5_trafficweight.ar", "! !rv5_trafficweight.ar" },
  196.         { "mods\\!!mod_riva_refl_3.1.ar", "!!mod_riva_refl_3.1.ar" },
  197.         { "mods\\!!sm2.ar", "!!sm2.ar" },
  198.         { "mods\\Fire and Smoke mod-3.2.ar", "Fire and Smoke mod-3.2.ar" },
  199.         { "patch\\Midtown2.exe", "Midtown2Patched.exe" },
  200.     };
  201.    
  202.     fileBytes.push_back(BYTE(mods.size()));
  203.  
  204.     for (auto mod : mods)
  205.     {
  206.         std::vector<char> bytes = std::vector<char>(106, NULL);
  207.  
  208.         MM2InstallerEntry* entry = (MM2InstallerEntry*)(bytes.data());
  209.  
  210.         std::string from    = "game\\" + mod[0];
  211.         std::string to      = mod[1];
  212.  
  213.         std::string copyType    = "1"; // 2
  214.         std::string unkNum2     = "-1"; // 3
  215.  
  216.         entry->entryType = 10;
  217.         entry->dword8 = 11;
  218.         entry->word10 = 19;
  219.  
  220.         entry->entrySize =
  221.             34 +                            // MM2FileStruct (without end padding)
  222.             WORD(from.size())       + 1 +   // from + 1
  223.             WORD(to.size())         + 1 +   // to + 1
  224.             WORD(copyType.size())   + 1 +   // copy type + 1
  225.             WORD(unkNum2.size())    + 1 +   // unkNnum2 + 1
  226.             4;                              // FF FF FF FF
  227.  
  228.         entry->dword18 = 1;
  229.         entry->dword20 = 4294967295;
  230.         entry->fileSize = 0;
  231.  
  232.         entry->fileStruct.dword1C = 80;
  233.         entry->fileStruct.firstStringLength = WORD(from.size() + 1);
  234.  
  235.         bytes.insert(bytes.end(), from.begin(),     from.end());        bytes.push_back('\0');
  236.         bytes.insert(bytes.end(), to.begin(),       to.end());          bytes.push_back('\0');
  237.         bytes.insert(bytes.end(), copyType.begin(), copyType.end());    bytes.push_back('\0');
  238.         bytes.insert(bytes.end(), unkNum2.begin(),  unkNum2.end());     bytes.push_back('\0');
  239.  
  240.         bytes.push_back('\xFF'); bytes.push_back('\xFF'); bytes.push_back('\xFF'); bytes.push_back('\xFF');
  241.  
  242.         fileBytes.insert(fileBytes.end(), bytes.begin(), bytes.end());
  243.     }
  244.  
  245.     IStreamWrite(std::ofstream("SETUPDATA2.bin", std::ofstream::binary), fileBytes);
  246.  
  247.     std::cin.get();
  248.  
  249.     return 0;
  250. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement