Advertisement
Liamm

MW3 Build Weapon

Oct 25th, 2023 (edited)
722
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.77 KB | Source Code | 0 0
  1. map<char, int> makeLettersToNumbers()
  2.     {
  3.         map<char, int> array;
  4.  
  5.         array.insert(pair<char, int>('a', 0));
  6.         array.insert(pair<char, int>('b', 1));
  7.         array.insert(pair<char, int>('c', 2));
  8.         array.insert(pair<char, int>('d', 3));
  9.         array.insert(pair<char, int>('e', 4));
  10.         array.insert(pair<char, int>('f', 5));
  11.         array.insert(pair<char, int>('g', 6));
  12.         array.insert(pair<char, int>('h', 7));
  13.         array.insert(pair<char, int>('i', 8));
  14.         array.insert(pair<char, int>('j', 9));
  15.         array.insert(pair<char, int>('k', 10));
  16.         array.insert(pair<char, int>('l', 11));
  17.         array.insert(pair<char, int>('m', 12));
  18.         array.insert(pair<char, int>('n', 13));
  19.         array.insert(pair<char, int>('o', 14));
  20.         array.insert(pair<char, int>('p', 15));
  21.         array.insert(pair<char, int>('q', 16));
  22.         array.insert(pair<char, int>('r', 17));
  23.         array.insert(pair<char, int>('s', 18));
  24.         array.insert(pair<char, int>('t', 19));
  25.         array.insert(pair<char, int>('u', 20));
  26.         array.insert(pair<char, int>('v', 21));
  27.         array.insert(pair<char, int>('w', 22));
  28.         array.insert(pair<char, int>('x', 23));
  29.         array.insert(pair<char, int>('y', 24));
  30.         array.insert(pair<char, int>('z', 25));
  31.         return array;
  32.     }
  33.  
  34.     char* attachmentMap(char* attachmentName, char* weaponName)
  35.     {
  36.         auto weaponClass = tableLookup("mp/statstable.csv", 4, weaponName, 2);
  37.  
  38.         if (!strcmp(weaponClass, "weapon_smg"))
  39.         {
  40.             if (attachmentName == "reflex")
  41.                 return "reflexsmg";
  42.             else if (attachmentName == "eotech")
  43.                 return "eotechsmg";
  44.             else if (attachmentName == "acog")
  45.                 return "acogsmg";
  46.             else if (attachmentName == "thermal")
  47.                 return "thermalsmg";
  48.         }
  49.        
  50.         if (!strcmp(weaponClass, "weapon_lmg"))
  51.         {
  52.             if (attachmentName == "reflex")
  53.                 return "reflexlmg";
  54.             else if (attachmentName == "eotech")
  55.                 return "eotechlmg";
  56.         }
  57.  
  58.         if (!strcmp(weaponClass, "weapon_machine_pistol"))
  59.         {
  60.             if (attachmentName == "reflex")
  61.                 return "reflexsmg";
  62.             else if (attachmentName == "eotech")
  63.                 return "eotechsmg";
  64.         }
  65.  
  66.         return attachmentName;
  67.     }
  68.  
  69.     char* getAttachmentType(char* attachmentName)
  70.     {
  71.         auto attachmentType = tableLookup("mp/attachmentTable.csv", 4, attachmentName, 2);
  72.  
  73.         return attachmentType;
  74.     }
  75.  
  76.     bool is_later_in_alphabet(char* string1, char* string2)
  77.     {
  78.         return stricmp(string1, string2) > 0;
  79.     }
  80.  
  81.     string buildWeaponNameCamo(string weaponName, int camo)
  82.     {
  83.         if (!camo)
  84.             return weaponName;
  85.         if (camo <= 0)
  86.             return weaponName;
  87.  
  88.         if (camo < 10)
  89.             weaponName += "_camo0";
  90.         else
  91.             weaponName += "_camo";
  92.  
  93.         weaponName += string(Functions::va("%d", camo));
  94.  
  95.         return weaponName;
  96.     }
  97.  
  98.     string buildWeaponNameReticle(string weaponName, int reticle)
  99.     {
  100.         if (!reticle)
  101.             return weaponName;
  102.         if (reticle <= 0)
  103.             return weaponName;
  104.  
  105.         weaponName += "_scope";
  106.         weaponName += string(Functions::va("%d", reticle));
  107.  
  108.         return weaponName;
  109.     }
  110.  
  111.     char* buildWeaponName(char* baseName, char* attachment1, char* attachment2, int camo, int reticle)
  112.     {
  113.         if (Functions::Dvar_GetInt("scr_game_perks") == 0)
  114.         {
  115.             attachment2 = "none";
  116.         }
  117.  
  118.         if (!strcmp(getAttachmentType(attachment1), "rail"))
  119.         {
  120.             attachment1 = attachmentMap(attachment1, baseName);
  121.         }
  122.         else if (!strcmp(getAttachmentType(attachment2), "rail"))
  123.         {
  124.             attachment2 = attachmentMap(attachment2, baseName);
  125.         }
  126.  
  127.         char* bareWeaponName = "";
  128.         string weaponName = "";
  129.  
  130.         if (strstr(baseName, "iw5_"))
  131.         {
  132.             weaponName = Functions::va("%s_mp", baseName);
  133.             string baseNameStr = baseName;
  134.             bareWeaponName = (char*)baseNameStr.substr(4).c_str();
  135.         }
  136.         else
  137.         {
  138.             weaponName = baseName;
  139.         }
  140.  
  141.         vector<char*> attachments;
  142.  
  143.         auto levelToNumber = makeLettersToNumbers();
  144.         auto weaponClass = tableLookup("mp/statstable.csv", 4, baseName, 2);
  145.         if (strcmp(attachment1, "none") && strcmp(attachment2, "none"))
  146.         {
  147.             if (levelToNumber.find(attachment1[0])->second < levelToNumber.find(attachment2[0])->second)
  148.             {
  149.                 attachments.push_back(attachment1);
  150.                 attachments.push_back(attachment2);
  151.             }
  152.  
  153.             else if (levelToNumber.find(attachment1[0])->second == levelToNumber.find(attachment2[0])->second)
  154.             {
  155.                 if (levelToNumber.find(attachment1[1])->second < levelToNumber.find(attachment2[1])->second)
  156.                 {
  157.                     attachments.push_back(attachment1);
  158.                     attachments.push_back(attachment2);
  159.                 }
  160.                 else
  161.                 {
  162.                     attachments.push_back(attachment2);
  163.                     attachments.push_back(attachment1);
  164.                 }
  165.             }
  166.             else
  167.             {
  168.                 attachments.push_back(attachment2);
  169.                 attachments.push_back(attachment1);
  170.             }
  171.  
  172.             if (!strcmp(weaponClass, "weapon_sniper") && strcmp(getAttachmentType(attachment1), "rail") && strcmp(attachment2, "rail"))
  173.             {
  174.                 if (attachment1 != "zoomscope" && attachment2 != "zoomscope")
  175.                     attachments[2] = Functions::va("%sscope", bareWeaponName);
  176.             }
  177.         }
  178.  
  179.         else if (attachment1 != "none")
  180.         {
  181.             attachments[0] = attachment1;
  182.  
  183.             if (!strcmp(weaponClass, "weapon_sniper") && strcmp(getAttachmentType(attachment1), "rail") && strcmp(attachment1, "zoomscope"))
  184.                 attachments[1] = Functions::va("%sscope", bareWeaponName);
  185.  
  186.         }
  187.         else if (attachment2 != "none")
  188.         {
  189.             attachments[0] = attachment2;
  190.  
  191.             if (!strcmp(weaponClass, "weapon_sniper") && strcmp(getAttachmentType(attachment2), "rail") && strcmp(attachment2, "zoomscope"))
  192.                 attachments[1] = Functions::va("%sscope", bareWeaponName);
  193.         }
  194.         else if (!strcmp(weaponClass, "weapon_sniper"))
  195.         {
  196.             attachments[0] = Functions::va("%sscope", bareWeaponName);
  197.         }
  198.  
  199.         if (attachments[0] && !strcmp(attachments[0], "vzscope"))
  200.             attachments[0] = Functions::va("%sscopevz", bareWeaponName);
  201.         else if (attachments[1] && !strcmp(attachments[1], "vzscope"))
  202.             attachments[1] = Functions::va("%sscopevz", bareWeaponName);
  203.         else if (attachments[2] && !strcmp(attachments[2], "vzscope"))
  204.             attachments[2] = Functions::va("%sscopevz", bareWeaponName);
  205.  
  206.         if (attachments.size())
  207.         {
  208.             auto i = 0;
  209.             while (i < attachments.size())
  210.             {
  211.                 if (attachments[i + 1] && is_later_in_alphabet(attachments[i], attachments[i + 1]))
  212.                 {
  213.                     auto tmpAtch = attachments[i];
  214.                     attachments[i] = attachments[i + 1];
  215.                     attachments[i + 1] = tmpAtch;
  216.                     i = 0;
  217.                     continue;
  218.                 }
  219.                 i++;
  220.             }
  221.         }
  222.  
  223.         std::for_each(attachments.begin(), attachments.end(),
  224.             [&](char* attachment)
  225.             {
  226.                 weaponName += Functions::va("_%s", attachment);
  227.             }
  228.         );
  229.  
  230.         attachments.clear();
  231.  
  232.         if (strstr(weaponName.c_str(), "iw5_"))
  233.         {
  234.             weaponName = buildWeaponNameCamo(weaponName, camo);
  235.             weaponName = buildWeaponNameReticle(weaponName, reticle);
  236.             return (char*)weaponName.c_str();
  237.         }
  238.         else
  239.         {
  240.             weaponName = buildWeaponNameCamo(weaponName, camo);
  241.             weaponName = buildWeaponNameReticle(weaponName, reticle);
  242.             auto newWeaponName = weaponName + "_mp";
  243.             return (char*)newWeaponName.c_str();
  244.         }
  245.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement