Advertisement
Thunder-Menu

my new auto blacklist

Nov 13th, 2021
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.44 KB | None | 0 0
  1. std::string BlackLists::BlackListName = "";
  2. std::string BlackLists::BlackListActions = "Crash";
  3.  
  4. int persist_BlackList::BlackListpersist()
  5. {
  6.     persist_BlackList::save_location2(BlackLists::BlackListName);
  7.     return 0;
  8. }
  9.  
  10. int arraysize = 0;
  11. int lastarray = 0;
  12. int arrayfind = 0;
  13. bool arraychange = 0;
  14. int changedarray()
  15. {
  16.     if (arraychange)
  17.     {
  18.         if (lastarray < arraysize)
  19.         {
  20.             arrayfind = lastarray + 1;
  21.             lastarray = arrayfind;
  22.             arraychange = 0;
  23.         }
  24.         else if (lastarray = arraysize)
  25.         {
  26.             arrayfind = 0;
  27.             lastarray = arrayfind;
  28.             arraychange = 0;
  29.         }
  30.     }
  31.     return 0;
  32. }
  33. std::string menuarray = "";
  34. int intarrayi = 0;
  35. bool persist_BlackList::boolautolistaction = 0;
  36. int persist_BlackList::autolistaction()
  37. {
  38.     if (persist_BlackList::boolautolistaction)
  39.     {
  40.         DWORD ticks = GetTickCount64();
  41.         DWORD milliseconds = ticks % 1000;
  42.         ticks /= 1000;
  43.         DWORD seconds = ticks % 60;
  44.         int getTimer = seconds;
  45.         if (getTimer % 10 == 0)
  46.         {
  47.             auto BlackList_locations = persist_BlackList::list_locations2();
  48.             static std::string selected_BlackList2;
  49.             std::vector<char*> charVeclist(BlackList_locations.size(), nullptr);
  50.             for (int xi = 0; xi < BlackList_locations.size(); xi++) {
  51.                 charVeclist[xi] = &BlackList_locations[xi][0];
  52.                 arraysize = xi;
  53.             }
  54.             if (arraysize != 0)
  55.             {
  56.                 changedarray();
  57.                 std::string stringchar = charVeclist[lastarray];
  58.                 for (int i = 0; i < 32; i++) {
  59.                     intarrayi = i;
  60.                     if (stringchar == PLAYER::GET_PLAYER_NAME(i))
  61.                     {
  62.                         std::string playerlocations = charVeclist[lastarray];
  63.                         persist_BlackList::load_location2(playerlocations);
  64.                     }
  65.                     if (i == intarrayi)
  66.                     {  
  67.                         arraychange = 1;                       
  68.                     }
  69.                 }
  70.             }
  71.         }
  72.     }
  73.     return 0;
  74. }
  75. int Crash(std::string name)
  76. {
  77.     for (int i = 0; i < 33; i++) {
  78.         if (name == PLAYER::GET_PLAYER_NAME(i))
  79.         {
  80.                 int Handle = PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(i);
  81.                 Vector3 coords = ENTITY::GET_ENTITY_COORDS(Handle, 0, 0);
  82.                 Hash cage = HASH::GET_HASH_KEY("s_chuckwagonawning01b");
  83.  
  84.                 Features::attachobj[Features::nuattach] = OBJECT::CREATE_OBJECT_NO_OFFSET1(cage, coords.x - Features::objectx, coords.y - Features::objecty, coords.z - Features::objectz, 1, 1, 0);
  85.                 if (ENTITY::DOES_ENTITY_EXIST(Features::attachobj[Features::nuattach]))
  86.                 {
  87.                     ENTITY::ATTACH_ENTITY_TO_ENTITY(Features::attachobj[Features::nuattach], PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(Features::Online::selectedPlayer), SKEL_Head, 0, 5.8f, -1.5, 0, 0, 0, 1, 1, 0, 0, 2, 1, 1, 1);
  88.                 }
  89.  
  90.                 ENTITY::SET_ENTITY_VISIBLE(Features::attachobj[Features::nuattach], 1);
  91.                 ENTITY::SET_ENTITY_ALPHA(Features::attachobj[Features::nuattach], 255, 0);
  92.                 NETWORK::NETWORK_REGISTER_ENTITY_AS_NETWORKED(Features::attachobj[Features::nuattach]);
  93.                 NETWORK::_NETWORK_SET_ENTITY_INVISIBLE_TO_NETWORK(Features::attachobj[Features::nuattach], false);
  94.                 DWORD id2 = NETWORK::OBJ_TO_NET(Features::attachobj[Features::nuattach]);
  95.                 if (NETWORK::NETWORK_DOES_NETWORK_ID_EXIST(id2)) {
  96.                     ENTITY::_SET_ENTITY_SOMETHING(Features::attachobj[Features::nuattach], true);
  97.                     if (NETWORK::NETWORK_GET_ENTITY_IS_NETWORKED(Features::attachobj[Features::nuattach])) {
  98.                         NETWORK::SET_NETWORK_ID_EXISTS_ON_ALL_MACHINES(id2, true);
  99.                         NETWORK::_NETWORK_CAN_NETWORK_ID_BE_SEEN(id2);
  100.                     }
  101.                 }
  102.                 STREAMING::SET_MODEL_AS_NO_LONGER_NEEDED(cage);
  103.         }
  104.     }
  105.     return 0;
  106. }
  107. int Freeze(std::string name)
  108. {
  109.     for (int i = 0; i < 33; i++) {
  110.         if (name == PLAYER::GET_PLAYER_NAME(i))
  111.         {
  112.             Ped vic = PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(i);
  113.             TASK::CLEAR_PED_TASKS_IMMEDIATELY(vic, 0, 0);
  114.             TASK::CLEAR_PED_TASKS(vic, 0, 0);
  115.             TASK::CLEAR_PED_SECONDARY_TASK(vic);
  116.         }
  117.     }
  118.     return 0;
  119. }
  120. int persist_BlackList::listaction(std::string name, std::string actions)
  121. {
  122.     if (actions == "Crash")
  123.     {
  124.         Crash(name);
  125.     }
  126.     if (actions == "Freeze")
  127.     {
  128.         Freeze(name);
  129.     }
  130.     return 0;
  131. }
  132. void persist_BlackList::save_location2(std::string name)
  133. {
  134.     attachmentBlackList::BlackListattachment attachment;
  135.     attachment.BlackListname = BlackLists::BlackListName;
  136.     attachment.BlackListactions = BlackLists::BlackListActions;
  137.     save2(name, attachment);
  138. }
  139.  
  140. void persist_BlackList::load_location2(std::string name)
  141. {
  142.     auto locations = get_locations_json2();
  143.     if (locations[name].is_null())
  144.         return;
  145.     auto model_attachment = locations[name].get<attachmentBlackList::BlackListattachment>();
  146.  
  147.     BlackLists::BlackListName = model_attachment.BlackListname;
  148.     BlackLists::BlackListActions = model_attachment.BlackListactions;
  149.     listaction(BlackLists::BlackListName, BlackLists::BlackListActions);
  150. }
  151.  
  152. void persist_BlackList::delete_location2(std::string name)
  153. {
  154.     auto locations = get_locations_json2();
  155.     if (locations[name].is_null())
  156.         return;
  157.     locations.erase(name);
  158.     save_json2(locations);
  159. }
  160.  
  161. std::vector<std::string> persist_BlackList::list_locations2()
  162. {
  163.     std::vector<std::string> return_value;
  164.     auto json = get_locations_json2();
  165.     for (auto& item : json.items())
  166.         return_value.push_back(item.key());
  167.     return return_value;
  168. }
  169.  
  170. int Menu2::resultpos32 = 0;
  171. int  Menu2::resultpos42 = 0;
  172.  
  173.  
  174. char* listactions[] = {
  175. (char*)"Crash",
  176. (char*)"Freeze",
  177. };
  178.  
  179. std::string BlackLists::BlackListnamesaved;
  180. void BlackLists::savedBlackList()
  181. {
  182.     persist_BlackList::BlackListpersist();
  183. }
  184.  
  185. void persist_BlackList::do_presentation_layer2()
  186. {  
  187.     Menu::Toggle("BlackList", persist_BlackList::boolautolistaction);
  188.     BlackLists::BlackListName = PLAYER::GET_PLAYER_NAME(Features::Online::selectedPlayer);
  189.     std::string player = "Player " + BlackLists::BlackListName;
  190.     if (Menu::Option((char*)player.c_str()))
  191.     {
  192.     }
  193.     std::string actions = "Actions " + BlackLists::BlackListActions;
  194.     if (Menu::Option((char*)actions.c_str()))
  195.     {
  196.     }
  197.     for (int i = 0; i < ARRAYSIZE(listactions); i++)
  198.     {
  199.         if (Menu::Option(listactions[i]))
  200.         {
  201.             BlackLists::BlackListActions = listactions[i];
  202.         }
  203.     }
  204.     auto BlackList_locations = list_locations2();
  205.     static std::string selected_BlackList2;
  206.     int xi = 0;
  207.     std::vector<char*> charVec2(BlackList_locations.size(), nullptr);
  208.     for (int i = 0; i < BlackList_locations.size(); i++) {
  209.         charVec2[i] = &BlackList_locations[i][0];
  210.         xi = i;
  211.     }
  212.     if (xi != 0)
  213.     {
  214.         if (Menu2::ListVector("List", charVec2, Menu2::resultpos42)) {
  215.             char* result2 = charVec2[Menu2::resultpos42];
  216.             selected_BlackList2 = result2;
  217.             load_location2(selected_BlackList2);
  218.         }
  219.     }
  220.     if (Menu::Option("Save"))
  221.     {
  222.         BlackLists::savedBlackList();
  223.     }
  224.     if (xi != 0)
  225.     {
  226.         if (Menu::Option("Load"))
  227.         {
  228.             if (!selected_BlackList2.empty())
  229.             {
  230.                 load_location2(selected_BlackList2);
  231.                 selected_BlackList2.clear();
  232.             }
  233.         }
  234.         if (Menu::Option("Delete"))
  235.         {
  236.             if (!selected_BlackList2.empty())
  237.             {
  238.                 delete_location2(selected_BlackList2);
  239.                 selected_BlackList2.clear();
  240.             }
  241.         }
  242.     }
  243. }
  244.  
  245. void persist_BlackList::save2(std::string name, attachmentBlackList::BlackListattachment attachment)
  246. {
  247.     auto json = get_locations_json2();
  248.     json[name] = attachment;
  249.     save_json2(json);
  250. }
  251.  
  252. void persist_BlackList::save_json2(nlohmann::json json)
  253. {
  254.     auto file_path = get_locations_config2();
  255.     std::ofstream file(file_path, std::ios::out | std::ios::trunc);
  256.     file << json.dump(4);
  257.     file.close();
  258. }
  259.  
  260. nlohmann::json persist_BlackList::get_locations_json2()
  261. {
  262.     auto file_path = get_locations_config2();
  263.     nlohmann::json locations;
  264.     std::ifstream file(file_path);
  265.  
  266.     if (!file.fail())
  267.         file >> locations;
  268.  
  269.     return locations;
  270. }
  271. void makeBlackListfolder() {
  272.     string BlackListstring = Directory::get_current_dir() + "\\ThunderMenu\\BlackList\\";
  273. #include <windows.h>
  274.     std::wstring BlackListwstring = functions::s2ws(BlackListstring);
  275.     LPCWSTR BlackListlpcwstr = BlackListwstring.c_str();
  276.     if (CreateDirectoryW(BlackListlpcwstr, NULL))
  277.     {
  278.         // Directory created
  279.     }
  280.     else if (ERROR_ALREADY_EXISTS == GetLastError())
  281.     {
  282.         // Directory already exists
  283.     }
  284.     else
  285.     {
  286.         // Failed for some other reason
  287.     }
  288. }
  289. char BlackListchar[255];
  290. void BlackLists::BlackListfolder()
  291. {
  292.     ifstream BlackListstream;
  293.     BlackListstream.open(Directory::get_current_dir() + "\\ThunderMenu\\BlackList\\");
  294.     if (BlackListstream) {
  295.         BlackListstream >> BlackListchar;
  296.     }
  297.     if (!BlackListstream) {
  298.         makeBlackListfolder();
  299.     }
  300.     BlackListstream.close();
  301. }
  302. std::string persist_BlackList::get_locations_config2()
  303. {
  304.     BlackLists::BlackListfolder();
  305.     auto file_path = Directory::get_current_dir();
  306.     file_path += "\\ThunderMenu\\BlackList\\";
  307.     file_path += "TheBlackList.json";
  308.     return file_path;
  309. }
  310.  
  311. namespace BlackLists
  312. {
  313.     extern std::string BlackListName;
  314.     extern void BlackListfolder();
  315.     extern std::string BlackListnamesaved;
  316.     extern void savedBlackList();
  317.     extern std::string BlackListActions;
  318. }
  319.  
  320. class persist_BlackList
  321. {
  322. public:
  323.     static bool boolautolistaction;
  324.     static int autolistaction();
  325.     static int listaction(std::string name, std::string actions);
  326.     static void do_presentation_layer2();
  327.     static int BlackListpersist();
  328. private:
  329.     static void save_location2(std::string name, std::string action);
  330.     static void save_location2(std::string name);
  331.     static void load_location2(std::string name);
  332.     static void delete_location2(std::string name);
  333.     static std::vector<std::string> list_locations2();
  334.     static void save2(std::string name, attachmentBlackList::BlackListattachment attachment);
  335.     static void save_json2(nlohmann::json json);
  336.     static nlohmann::json get_locations_json2();
  337.     static std::string get_locations_config2();
  338.     /*static std::filesystem::path get_locations_config();*/
  339. };
  340. extern void makeBlackListfolder();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement