diff --git a/.gitignore b/.gitignore index 9a44da1..4ae7ca4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ .vs/ build/ +.vscode/.BROWSE.VC.DB +.gitignore +.vscode/BROWSE.VC.DB diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 1e0d7dd..6d49c85 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -3,8 +3,7 @@ { "name": "Win32", "includePath": [ - "${workspaceFolder}/**", - "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.10240.0\\ucrt", + "${workspaceFolder}/src/", "${DIRECTX9_SDK_DIR}/include", "${PLUGIN_SDK_DIR}/plugin_sa", "${PLUGIN_SDK_DIR}/plugin_sa/game_sa", @@ -20,7 +19,7 @@ "windowsSdkVersion": "10.0.10240.0", "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe", "cStandard": "c99", - "cppStandard": "c++17", + "cppStandard": "c++14", "intelliSenseMode": "msvc-x86", "configurationProvider": "ms-vscode.cmake-tools" } diff --git a/.vscode/settings.json b/.vscode/settings.json index 4039b77..7049d38 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -63,5 +63,7 @@ "xstddef": "cpp", "xtr1common": "cpp", "xtree": "cpp" - } + }, + "C_Cpp.errorSquiggles": "Enabled", + "C_Cpp.intelliSenseEngineFallback": "Enabled" } \ No newline at end of file diff --git a/src/Animation.cpp b/src/Animation.cpp index ffaafdf..2cbfd1c 100644 --- a/src/Animation.cpp +++ b/src/Animation.cpp @@ -23,7 +23,7 @@ std::string walking_selected = "default"; Animation::Animation() { - json.LoadJsonData(search_categories, selected_item); + json.LoadData(search_categories, selected_item); } void Animation::Main() @@ -102,6 +102,7 @@ void Animation::Main() if (ImGui::Button("Add animation", Ui::GetSize())) { json.data["Custom"][anim_buffer] = ("0, " + std::string(ifp_buffer)); + json.WriteToDisk(); } ImGui::EndTabItem(); } diff --git a/src/CheatMenu.cpp b/src/CheatMenu.cpp index a148b31..03cb8ec 100644 --- a/src/CheatMenu.cpp +++ b/src/CheatMenu.cpp @@ -85,6 +85,7 @@ CheatMenu::CheatMenu() config.SetValue("window.sizeX", Globals::menu_size.x); config.SetValue("window.sizeY", Globals::menu_size.y); + config.WriteToDisk(); flog << "Log Finished." << std::endl; }; } diff --git a/src/Game.cpp b/src/Game.cpp index fd9229e..9f33a8c 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -47,8 +47,8 @@ Game::Game() { Events::initGameEvent += [] { - json.LoadJsonData(search_categories, selected_item); - stat::json.LoadJsonData(stat::search_categories, stat::selected_item); + json.LoadData(search_categories, selected_item); + stat::json.LoadData(stat::search_categories, stat::selected_item); // Generate enabled cheats vector for (auto element : random_cheats::name_json.data.items()) diff --git a/src/Json.cpp b/src/Json.cpp index b810c2c..00bd4cb 100644 --- a/src/Json.cpp +++ b/src/Json.cpp @@ -4,7 +4,7 @@ CJson::CJson(const char* name,bool create_new) { file_path = "./CheatMenu/json/"+ std::string(name) +".json"; - + if (std::experimental::filesystem::exists(file_path)) { std::ifstream file(file_path); @@ -23,7 +23,14 @@ CJson::CJson(const char* name,bool create_new) } } -void CJson::LoadJsonData(std::vector& vec, std::string& selected) // Test +void CJson::WriteToDisk() +{ + std::ofstream file(file_path); + file << data.dump(4,' ',false, nlohmann::json::error_handler_t::replace) << std::endl; + file.close(); +} + +void CJson::LoadData(std::vector& vec, std::string& selected) // Test { for (auto element : data.items()) vec.push_back(element.key()); @@ -31,7 +38,5 @@ void CJson::LoadJsonData(std::vector& vec, std::string& selected) / CJson::~CJson() { - std::ofstream file(file_path); - file << data.dump(4,' ',false, nlohmann::json::error_handler_t::replace) << std::endl; - file.close(); + // Saving here won't work on crash } diff --git a/src/Json.h b/src/Json.h index 99700e8..5eafc70 100644 --- a/src/Json.h +++ b/src/Json.h @@ -64,9 +64,14 @@ public: Loads the section names into a category vector. Used to create drop down category menus */ - void LoadJsonData(std::vector& vec, std::string& selected); + void LoadData(std::vector& vec, std::string& selected); + + /* + Saves json data to disk + */ + void WriteToDisk(); CJson(const char* text, bool create_new = false); - virtual ~CJson(); + ~CJson(); }; diff --git a/src/Ped.cpp b/src/Ped.cpp index 3f77819..872965c 100644 --- a/src/Ped.cpp +++ b/src/Ped.cpp @@ -31,7 +31,7 @@ Ped::Ped() { Events::initGameEvent += [] { - std::string dir_path = (std::string(".\\CheatMenu\\peds\\")).c_str(); + std::string dir_path = Globals::menu_path +"\\CheatMenu\\peds\\"; Util::LoadTexturesInDirRecursive(dir_path.c_str(), ".jpg", search_categories, peds_vec); if (LoadLibraryW(L"ExGangWars.asi")) diff --git a/src/Teleport.cpp b/src/Teleport.cpp index e6f26ac..0b8a7f2 100644 --- a/src/Teleport.cpp +++ b/src/Teleport.cpp @@ -50,7 +50,7 @@ void Teleport::FetchRadarSpriteData() Teleport::Teleport() { - json.LoadJsonData(search_categories, selected_item); + json.LoadData(search_categories, selected_item); Events::initGameEvent += [] { @@ -255,6 +255,7 @@ void Teleport::Main() if (ImGui::Button("Add location", Ui::GetSize())) { json.data["Custom"][location_buffer] = ("0, " + std::string(input_buffer)); + json.WriteToDisk(); } ImGui::EndTabItem(); } diff --git a/src/Util.cpp b/src/Util.cpp index 73865da..d37313a 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -23,7 +23,7 @@ void Util::ClearCharTasksVehCheck(CPed* ped) } } -void Util::LoadTexturesInDirRecursive(const char * path, const char * file_ext,std::vector& category_vec, std::vector> &store_vec) +void Util::LoadTexturesInDirRecursive(const char *path, const char *file_ext,std::vector& category_vec, std::vector> &store_vec) { std::string folder = ""; for (auto &p : std::experimental::filesystem::recursive_directory_iterator(path)) @@ -33,7 +33,7 @@ void Util::LoadTexturesInDirRecursive(const char * path, const char * file_ext,s { store_vec.push_back(std::make_unique()); HRESULT hr = -1; - + flog << p.path().string() << std::endl; if (Globals::renderer == Render_DirectX9) hr = D3DXCreateTextureFromFileA(GetD3DDevice(), p.path().string().c_str(), &store_vec.back().get()->texture9); diff --git a/src/Vehicle.cpp b/src/Vehicle.cpp index d34e5f5..c79b7f0 100644 --- a/src/Vehicle.cpp +++ b/src/Vehicle.cpp @@ -68,13 +68,13 @@ Vehicle::Vehicle() { Events::initGameEvent += [] { - std::string dir_path = (std::string(".\\CheatMenu\\vehicles\\images\\")).c_str(); + std::string dir_path = std::string(Globals::menu_path + "\\CheatMenu\\vehicles\\images\\"); Util::LoadTexturesInDirRecursive(dir_path.c_str(), ".jpg", spawner::search_categories, spawner::image_vec); - dir_path = (std::string(".\\CheatMenu\\vehicles\\components\\")).c_str(); + dir_path = std::string(Globals::menu_path + "\\CheatMenu\\vehicles\\components\\"); Util::LoadTexturesInDirRecursive(dir_path.c_str(), ".jpg", tune::search_categories, tune::image_vec); - dir_path = (std::string(".\\CheatMenu\\vehicles\\paintjobs\\")).c_str(); + dir_path = std::string(Globals::menu_path + "\\CheatMenu\\vehicles\\paintjobs\\"); Util::LoadTexturesInDirRecursive(dir_path.c_str(), ".png", texture9::search_categories, texture9::image_vec); ParseVehiclesIDE(); @@ -211,7 +211,7 @@ void Vehicle::RemoveComponent(const std::string& component, const bool display_m } } -// Why did I do this shit? +// Why did I do this shit? Guess it was the weather int Vehicle::GetRandomTrainIdForModel(int model) { static int train_ids[] = { @@ -239,8 +239,8 @@ int Vehicle::GetRandomTrainIdForModel(int model) CHud::SetHelpMessage("Invalid train model", false, false, false); return -1; } - - return train_ids[rand() % _end + _start]; + int id = rand() % (_end + 1 - _start) + _start; + return train_ids[id]; } // Get vehicle HandlingId @@ -727,7 +727,7 @@ void Vehicle::Main() ImGui::Spacing(); ImGui::Separator(); } - if (Command(hplayer)) + if (player && player->m_pVehicle) { CVehicle *veh = player->m_pVehicle; int hveh = CPools::GetVehicleRef(veh); @@ -735,6 +735,50 @@ void Vehicle::Main() Ui::EditFloat("Density multiplier", 0x8A5B20, 0, 1, 10); Ui::EditFloat("Dirt level", (int)veh + 0x4B0, 0, 7.5, 15); + if (ImGui::CollapsingHeader("Damage flags")) + { + ImGui::Spacing(); + ImGui::TextWrapped("Flags apply to this vehicle only"); + ImGui::Spacing(); + + bool no_dmg_flag = veh->m_nVehicleFlags.bCanBeDamaged; + + bool state = is_driver && (!no_dmg_flag); + ImGui::Spacing(); + ImGui::SameLine(); + if (Ui::CheckboxWithHint("No damage", &state, nullptr, !is_driver)) + veh->m_nVehicleFlags.bCanBeDamaged = !state; + + ImGui::Spacing(); + + ImGui::Columns(2, 0, false); + + state = is_driver && (veh->m_nPhysicalFlags.bBulletProof); + if (Ui::CheckboxWithHint("Bullet proof", &state, nullptr, !no_dmg_flag)) + veh->m_nPhysicalFlags.bBulletProof = state; + + state = is_driver && (veh->m_nPhysicalFlags.bCollisionProof); + if (Ui::CheckboxWithHint("Collision proof", &state, nullptr, !no_dmg_flag)) + veh->m_nPhysicalFlags.bCollisionProof = state; + + state = is_driver && (veh->m_nPhysicalFlags.bExplosionProof); + if (Ui::CheckboxWithHint("Explosion proof", &state, nullptr, !no_dmg_flag)) + veh->m_nPhysicalFlags.bExplosionProof = state; + + ImGui::NextColumn(); + + state = is_driver && (veh->m_nPhysicalFlags.bFireProof); + if (Ui::CheckboxWithHint("Fire proof", &state, nullptr, !no_dmg_flag)) + veh->m_nPhysicalFlags.bFireProof = state; + + state = is_driver && (veh->m_nPhysicalFlags.bMeeleProof); + if (Ui::CheckboxWithHint("Melee proof", &state, nullptr, !no_dmg_flag)) + veh->m_nPhysicalFlags.bMeeleProof = state; + + ImGui::Columns(1); + ImGui::Spacing(); + ImGui::Separator(); + } if (veh->m_nVehicleClass == VEHICLE_AUTOMOBILE && ImGui::CollapsingHeader("Doors")) { ImGui::Columns(2, 0, false); diff --git a/src/Weapon.cpp b/src/Weapon.cpp index 8142c4c..d130952 100644 --- a/src/Weapon.cpp +++ b/src/Weapon.cpp @@ -35,7 +35,7 @@ Weapon::Weapon() { Events::initGameEvent += [] { - std::string dir_path = (std::string(".\\CheatMenu\\weapons\\")).c_str(); + std::string dir_path = Globals::menu_path + "\\CheatMenu\\weapons\\"; Util::LoadTexturesInDirRecursive(dir_path.c_str(), ".jpg", Weapon::search_categories, Weapon::weapon_vec); }; diff --git a/src/pch.cpp b/src/pch.cpp index b86bd2e..a35329d 100644 --- a/src/pch.cpp +++ b/src/pch.cpp @@ -9,6 +9,7 @@ bool Globals::show_menu = false; bool Globals::init_done = false; Renderer Globals::renderer = Render_Unknown; ID3D11Device *Globals::device11 = nullptr; +std::string Globals::menu_path = paths::GetPluginDirPathA(); CJson config = CJson("config", true); std::ofstream flog = std::ofstream("CheatMenu.log"); diff --git a/src/pch.h b/src/pch.h index 35064bb..48621b7 100644 --- a/src/pch.h +++ b/src/pch.h @@ -4,7 +4,7 @@ #define INPUT_BUFFER_SIZE 64 #define SPAWN_PED_LIMIT 20 #define MENU_VERSION "2.5-beta" -#define BUILD_NUMBER "20201209" +#define BUILD_NUMBER "20201220" #define STB_IMAGE_IMPLEMENTATION #include @@ -46,6 +46,7 @@ #include "extensions/ScriptCommands.h" #include "extensions/Screen.h" #include "eVehicleClass.h" +#include "extensions\Paths.h" #include "external/imgui/imgui.h" #include "external/imgui/imgui_impl_dx9.h" @@ -83,6 +84,7 @@ struct Globals static bool init_done; static Renderer renderer; static ID3D11Device* device11; + static std::string menu_path; }; struct TextureStructure