Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- map<char, int> makeLettersToNumbers()
- {
- map<char, int> array;
- array.insert(pair<char, int>('a', 0));
- array.insert(pair<char, int>('b', 1));
- array.insert(pair<char, int>('c', 2));
- array.insert(pair<char, int>('d', 3));
- array.insert(pair<char, int>('e', 4));
- array.insert(pair<char, int>('f', 5));
- array.insert(pair<char, int>('g', 6));
- array.insert(pair<char, int>('h', 7));
- array.insert(pair<char, int>('i', 8));
- array.insert(pair<char, int>('j', 9));
- array.insert(pair<char, int>('k', 10));
- array.insert(pair<char, int>('l', 11));
- array.insert(pair<char, int>('m', 12));
- array.insert(pair<char, int>('n', 13));
- array.insert(pair<char, int>('o', 14));
- array.insert(pair<char, int>('p', 15));
- array.insert(pair<char, int>('q', 16));
- array.insert(pair<char, int>('r', 17));
- array.insert(pair<char, int>('s', 18));
- array.insert(pair<char, int>('t', 19));
- array.insert(pair<char, int>('u', 20));
- array.insert(pair<char, int>('v', 21));
- array.insert(pair<char, int>('w', 22));
- array.insert(pair<char, int>('x', 23));
- array.insert(pair<char, int>('y', 24));
- array.insert(pair<char, int>('z', 25));
- return array;
- }
- char* attachmentMap(char* attachmentName, char* weaponName)
- {
- auto weaponClass = tableLookup("mp/statstable.csv", 4, weaponName, 2);
- if (!strcmp(weaponClass, "weapon_smg"))
- {
- if (attachmentName == "reflex")
- return "reflexsmg";
- else if (attachmentName == "eotech")
- return "eotechsmg";
- else if (attachmentName == "acog")
- return "acogsmg";
- else if (attachmentName == "thermal")
- return "thermalsmg";
- }
- if (!strcmp(weaponClass, "weapon_lmg"))
- {
- if (attachmentName == "reflex")
- return "reflexlmg";
- else if (attachmentName == "eotech")
- return "eotechlmg";
- }
- if (!strcmp(weaponClass, "weapon_machine_pistol"))
- {
- if (attachmentName == "reflex")
- return "reflexsmg";
- else if (attachmentName == "eotech")
- return "eotechsmg";
- }
- return attachmentName;
- }
- char* getAttachmentType(char* attachmentName)
- {
- auto attachmentType = tableLookup("mp/attachmentTable.csv", 4, attachmentName, 2);
- return attachmentType;
- }
- bool is_later_in_alphabet(char* string1, char* string2)
- {
- return stricmp(string1, string2) > 0;
- }
- string buildWeaponNameCamo(string weaponName, int camo)
- {
- if (!camo)
- return weaponName;
- if (camo <= 0)
- return weaponName;
- if (camo < 10)
- weaponName += "_camo0";
- else
- weaponName += "_camo";
- weaponName += string(Functions::va("%d", camo));
- return weaponName;
- }
- string buildWeaponNameReticle(string weaponName, int reticle)
- {
- if (!reticle)
- return weaponName;
- if (reticle <= 0)
- return weaponName;
- weaponName += "_scope";
- weaponName += string(Functions::va("%d", reticle));
- return weaponName;
- }
- char* buildWeaponName(char* baseName, char* attachment1, char* attachment2, int camo, int reticle)
- {
- if (Functions::Dvar_GetInt("scr_game_perks") == 0)
- {
- attachment2 = "none";
- }
- if (!strcmp(getAttachmentType(attachment1), "rail"))
- {
- attachment1 = attachmentMap(attachment1, baseName);
- }
- else if (!strcmp(getAttachmentType(attachment2), "rail"))
- {
- attachment2 = attachmentMap(attachment2, baseName);
- }
- char* bareWeaponName = "";
- string weaponName = "";
- if (strstr(baseName, "iw5_"))
- {
- weaponName = Functions::va("%s_mp", baseName);
- string baseNameStr = baseName;
- bareWeaponName = (char*)baseNameStr.substr(4).c_str();
- }
- else
- {
- weaponName = baseName;
- }
- vector<char*> attachments;
- auto levelToNumber = makeLettersToNumbers();
- auto weaponClass = tableLookup("mp/statstable.csv", 4, baseName, 2);
- if (strcmp(attachment1, "none") && strcmp(attachment2, "none"))
- {
- if (levelToNumber.find(attachment1[0])->second < levelToNumber.find(attachment2[0])->second)
- {
- attachments.push_back(attachment1);
- attachments.push_back(attachment2);
- }
- else if (levelToNumber.find(attachment1[0])->second == levelToNumber.find(attachment2[0])->second)
- {
- if (levelToNumber.find(attachment1[1])->second < levelToNumber.find(attachment2[1])->second)
- {
- attachments.push_back(attachment1);
- attachments.push_back(attachment2);
- }
- else
- {
- attachments.push_back(attachment2);
- attachments.push_back(attachment1);
- }
- }
- else
- {
- attachments.push_back(attachment2);
- attachments.push_back(attachment1);
- }
- if (!strcmp(weaponClass, "weapon_sniper") && strcmp(getAttachmentType(attachment1), "rail") && strcmp(attachment2, "rail"))
- {
- if (attachment1 != "zoomscope" && attachment2 != "zoomscope")
- attachments[2] = Functions::va("%sscope", bareWeaponName);
- }
- }
- else if (attachment1 != "none")
- {
- attachments[0] = attachment1;
- if (!strcmp(weaponClass, "weapon_sniper") && strcmp(getAttachmentType(attachment1), "rail") && strcmp(attachment1, "zoomscope"))
- attachments[1] = Functions::va("%sscope", bareWeaponName);
- }
- else if (attachment2 != "none")
- {
- attachments[0] = attachment2;
- if (!strcmp(weaponClass, "weapon_sniper") && strcmp(getAttachmentType(attachment2), "rail") && strcmp(attachment2, "zoomscope"))
- attachments[1] = Functions::va("%sscope", bareWeaponName);
- }
- else if (!strcmp(weaponClass, "weapon_sniper"))
- {
- attachments[0] = Functions::va("%sscope", bareWeaponName);
- }
- if (attachments[0] && !strcmp(attachments[0], "vzscope"))
- attachments[0] = Functions::va("%sscopevz", bareWeaponName);
- else if (attachments[1] && !strcmp(attachments[1], "vzscope"))
- attachments[1] = Functions::va("%sscopevz", bareWeaponName);
- else if (attachments[2] && !strcmp(attachments[2], "vzscope"))
- attachments[2] = Functions::va("%sscopevz", bareWeaponName);
- if (attachments.size())
- {
- auto i = 0;
- while (i < attachments.size())
- {
- if (attachments[i + 1] && is_later_in_alphabet(attachments[i], attachments[i + 1]))
- {
- auto tmpAtch = attachments[i];
- attachments[i] = attachments[i + 1];
- attachments[i + 1] = tmpAtch;
- i = 0;
- continue;
- }
- i++;
- }
- }
- std::for_each(attachments.begin(), attachments.end(),
- [&](char* attachment)
- {
- weaponName += Functions::va("_%s", attachment);
- }
- );
- attachments.clear();
- if (strstr(weaponName.c_str(), "iw5_"))
- {
- weaponName = buildWeaponNameCamo(weaponName, camo);
- weaponName = buildWeaponNameReticle(weaponName, reticle);
- return (char*)weaponName.c_str();
- }
- else
- {
- weaponName = buildWeaponNameCamo(weaponName, camo);
- weaponName = buildWeaponNameReticle(weaponName, reticle);
- auto newWeaponName = weaponName + "_mp";
- return (char*)newWeaponName.c_str();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement