From 873c5c0eb18a4ef9c65cf0075af30a6650f7b389 Mon Sep 17 00:00:00 2001 From: Terri00 Date: Mon, 25 Mar 2019 03:40:10 +0000 Subject: [PATCH] VTX version limit, misc vpk/vmf format patches, installer rework. --- AutoRadar_installer/main.cpp | 223 ++++++++++++++++++++++------------- MCDV/main.cpp | 11 +- MCDV/util.h | 6 + MCDV/vmf.hpp | 15 ++- MCDV/vpk.hpp | 10 +- MCDV/vtx.hpp | 8 ++ 6 files changed, 185 insertions(+), 88 deletions(-) diff --git a/AutoRadar_installer/main.cpp b/AutoRadar_installer/main.cpp index 470f253..6bd548e 100644 --- a/AutoRadar_installer/main.cpp +++ b/AutoRadar_installer/main.cpp @@ -15,12 +15,127 @@ std::string steam_install_path = "C:\\Program Files (x86)\\Steam\\"; std::string csgo_sdk_bin_path = ""; +/* + +// Find steam installation ___________________________________________________________________________ + +if argc > 0: // overridden input + RETURN SDK_BIN + +if CheckExist ([DRIVE]:/program files (x86)/steam/) 'steam.exe': // normal drive letter installs + steam_path = ^ +else: if CheckExist (/) 'steam.exe': // check from registry if not found + steam_path = ^ +else: RETURN FAIL // can't find steam installation. + +CheckExist (steam_path steamapps/common/Counter-Strike Global Offensive/bin/) 'hammer.exe': // check steam install's regular /common/ folder + RETURN SDK_BIN + +CheckExist '__ steamapps/libraryfolders.vdf' // check if steam library folder vdf exists + FOREACH lib_folder :: libraryfolders.vdf: // iterate the library folders + CheckExist (lib_folder steamapps/common/Counter-Strike Global Offensive/bin/) 'hammer.exe': // check for hammer + RETURN SDK_BIN + +RETURN FAIL +*/ + int exit() { cc::reset(); system("PAUSE"); return -1; } +inline bool checkFileExist(const char* path) { + return (_access_s(path, 0) == 0); +} + +bool get_steam_install_from_winreg(std::string* s) { + HKEY hKey = NULL; + char buffer[1024]; + + bool regReadSuccess = true; + + if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Valve\\Steam", NULL, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) { + DWORD size; + if (RegQueryValueEx(hKey, "SteamPath", NULL, NULL, (LPBYTE)buffer, &size) == ERROR_SUCCESS) { + steam_install_path = buffer; + steam_install_path += "\\"; + } + else regReadSuccess = false; + } + else regReadSuccess = false; + + RegCloseKey(hKey); + + if (regReadSuccess) + *s = buffer; + + return regReadSuccess; +} + +std::vector get_library_folders_from_vdf(std::string vdf) { + std::vector libraryFolders; + + std::ifstream ifs(vdf); + if (!ifs) return libraryFolders; //ifs failed to open. + + else { + std::string str((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); + kv::FileData libFolders(str); + + kv::DataBlock* libFoldersDB = libFolders.headNode.GetFirstByName("\"LibraryFolders\""); + + if (libFoldersDB != NULL) { + int index = 0; + while (libFoldersDB->Values.count(std::to_string(++index))) libraryFolders.push_back(libFoldersDB->Values[std::to_string(index)] + "/steamapps/common/"); + } + } + + return libraryFolders; +} + +/* Work through all possible locations of steam / csgo. */ +std::string detect_csgo_bin(std::string steam_drive_letter = "c") { + std::string steam_path = ""; + + try { + if (checkFileExist((steam_drive_letter + ":/program files (x86)/steam/steam.exe").c_str())) + steam_path = steam_drive_letter + ":/program files (x86)/steam/"; + + else if (get_steam_install_from_winreg(&steam_path)) + if (checkFileExist((steam_path + "/steam.exe").c_str())) + steam_path = steam_path + "/"; + else throw std::exception(( "1) [" + steam_drive_letter + ":/program files (x86)/steam/steam.exe] not found\n2) Steam registry key pointed to wrong location.").c_str()); + else throw std::exception(( "1) [" + steam_drive_letter + ":/program files (x86)/steam/steam.exe] not found\n2) Failed to open registry for steam path.").c_str()); + + // steam_path assumed to be correct from here. + + // check steam apps folder + if (checkFileExist((steam_path + "steamapps/common/Counter-Strike Global Offensive/bin/hammer.exe").c_str())) + return steam_path + "steamapps/common/Counter-Strike Global Offensive/bin/"; + + // check if library folder thingy exists + if (checkFileExist((steam_path + "steamapps/libraryfolders.vdf").c_str())) { + for (auto && folder : get_library_folders_from_vdf(steam_path + "steamapps/libraryfolders.vdf")) + if (checkFileExist((folder + "Counter-Strike Global Offensive/bin/hammer.exe").c_str())) + return sutil::ReplaceAll(folder, "\\\\", "/") + "Counter-Strike Global Offensive/bin/"; + + throw std::exception(("1) [" + steam_path + "steamapps/common/Counter-Strike Global Offensive/bin/hammer.exe] not found\n2) libraryfolders.vdf search failed.").c_str()); + } + + // unable to find hammer using any methods. + throw std::exception(("1) [" + steam_path + "steamapps/common/Counter-Strike Global Offensive/bin/hammer.exe] not found\n2) libraryfolders.vdf not found.").c_str()); + } + catch (std::exception e) { + cc::error(); std::cout << "\nFailed to automatically detect /bin/ folder...\n\n"; + cc::info(); std::cout << "Reasons:\n====================================================================\n"; + cc::reset(); std::cout << e.what(); + cc::info(); std::cout << "\n====================================================================\n\n"; + } + + return ""; +} + int main(int argc, const char** argv) { cc::setup(); @@ -39,89 +154,40 @@ int main(int argc, const char** argv) { kv::DataBlock vinfodata = vinfo.headNode.SubBlocks[0]; cc::fancy(); std::cout << "Installing version: " << vinfodata.Values["version"] << "\n"; + cc::reset(); // Overide install if (argc > 1) { csgo_sdk_bin_path = std::string(argv[1]) + "\\"; - goto IL_COPYFILES; + goto IL_PRE_INSTALL; + } + else { + csgo_sdk_bin_path = detect_csgo_bin(); } -#pragma region sdk_detect - /* Get steam installation path */ - { - cc::info(); std::cout << "Getting steam installation path from windows registry\n"; - - HKEY hKey = NULL; - char buffer[1024]; - - bool regReadSuccess = true; - - if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Valve\\Steam", NULL, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) { - DWORD size; - if (RegQueryValueEx(hKey, "SteamPath", NULL, NULL, (LPBYTE)buffer, &size) == ERROR_SUCCESS) { - steam_install_path = buffer; - steam_install_path += "\\"; - } - else regReadSuccess = false; - } - else regReadSuccess = false; - - RegCloseKey(hKey); - - if (!regReadSuccess) { - cc::warning(); - std::cout << "Failed to read registry key: 'Software\\Valve\\Steam\\SteamPath'\nDefaulting to C:\\Program Files (x86)\\Steam\\ installation...\n"; - } - - cc::info(); - std::cout << "Reading steam library folders\n"; - - /* Read library folders file */ - - std::vector libraryFolders; - libraryFolders.push_back(steam_install_path + "steammapps\\common\\"); - libraryFolders.push_back("C:\\Program Files (x86)\\Steam\\steammapps\\common\\"); - - std::ifstream ifs(steam_install_path + "steamapps\\libraryfolders.vdf"); - if (!ifs) { - std::cout << "Libraryfolders.vdf not found. Skipping search...\n" << std::endl; - } - else { - std::string str((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); - kv::FileData libFolders(str); - - kv::DataBlock* libFoldersDB = libFolders.headNode.GetFirstByName("\"LibraryFolders\""); - - if (libFoldersDB != NULL) { - int index = 0; - while (libFoldersDB->Values.count(std::to_string(++index))) libraryFolders.push_back(libFoldersDB->Values[std::to_string(index)] + "\\steamapps\\common\\"); - } - } - - if (libraryFolders.size() == 0) std::cout << "No library folders found, defaulting to steamapps common folder...\n"; - - /* Scan for csgo sdk installations */ + if (csgo_sdk_bin_path == "") { + cc::reset(); std::cout << "Having issues?\nRun this installer from command prompt with the first argument being the path to your Counter Strike bin folder\n(the same folder as where hammer.exe is located)\n"; + cc::reset(); std::cout << " > "; + cc::info(); std::cout << "AutoRadar_installer.exe "; + cc::reset(); std::cout << "\""; + cc::info(); std::cout << "..."; + cc::reset(); std::cout << "Counter-Strike Global Offensive/bin/\"\n"; + exit(); + }; - std::cout << "Scanning for SDK installation\n"; + std::cout << "Evaluated bin_path to: " << csgo_sdk_bin_path << "\n"; - for (auto && folder : libraryFolders) { - if (_access_s((folder + "Counter-Strike Global Offensive\\bin\\gameinfo.txt").c_str(), 0) == 0) { - csgo_sdk_bin_path = folder + "Counter-Strike Global Offensive\\bin\\"; - } - } +IL_PRE_INSTALL: - if (csgo_sdk_bin_path == "") { - cc::error(); - std::cout << "Failed to find CS:GO SDK bin.\nFollow manual_install.txt"; - return exit(); - } + /* Check files that are required for install exist */ + if (!checkFileExist((csgo_sdk_bin_path + "GameConfig.txt").c_str())){ + cc::error(); std::cout << "Required file missing: \'" << csgo_sdk_bin_path + "GameConfig.txt\'\n"; + exit(); } -#pragma endregion #pragma region copyfiles /* Start doing the heavy work */ -IL_COPYFILES: std::cout << "Copying files\n________________________________________________________\n\n"; // Copy folders @@ -177,6 +243,11 @@ IL_COPYFILES: target_file = csgo_sdk_bin_path + target_file; + if (!checkFileExist(target_file.c_str())) { + cc::warning(); std::cout << "CmdSeq.wc missing, command sequences won't be installed!\nCheck manual_install.txt (# Command Sequences)\n"; cc::info(); + continue; + } + fs::copyFile(target_file, target_file + ".bak"); wc::filedata WcFile(target_file); @@ -196,8 +267,7 @@ IL_COPYFILES: wc::Sequence seq_new = wc::Sequence(); strcpy_s(seq_new.name, name.c_str()); - for (auto && cmd : seqS.GetAllByName("Command")) - { + for (auto && cmd : seqS.GetAllByName("Command")){ wc::Command command_build = wc::Command(); command_build.is_enabled = kv::tryGetValue(cmd.Values, "is_enabled", 0); command_build.special = kv::tryGetValue(cmd.Values, "special", 0); @@ -270,15 +340,6 @@ IL_COPYFILES: #pragma endregion cc::success(); std::cout << "\nCompleted setup!\n"; - - /* Small wait to auto close */ - for (int i = 10; i > 0; i--) { - cc::info(); - std::cout << "Closing in " << i << " seconds...\r"; - Sleep(1000); - } - - cc::reset(); - std::cout << "\n"; + exit(); return 0; } \ No newline at end of file diff --git a/MCDV/main.cpp b/MCDV/main.cpp index 74e0283..46d2126 100644 --- a/MCDV/main.cpp +++ b/MCDV/main.cpp @@ -126,11 +126,11 @@ int app(int argc, const char** argv) { ("d,dumpMasks", "Toggles whether auto radar should output mask images (resources/map_file.resources/)") ("o,onlyMasks", "Specift whether auto radar should only output mask images and do nothing else (resources/map_file.resources)") - ("ao", "Turn on AO in the compisotor") - ("shadows", "Turn on Shadows in the compositor") + ("ao", "[OBSOLETE] Turn on AO in the compisotor") + ("shadows", "[OBSOLETE] Turn on Shadows in the compositor") - ("w,width", "Render width in pixels (experimental)", cxxopts::value()->default_value("1024")) - ("h,height", "Render height in pixels (experimental)", cxxopts::value()->default_value("1024")) + ("w,width", "[OBSOLETE] Render width in pixels (experimental)", cxxopts::value()->default_value("1024")) + ("h,height", "[OBSOLETE] Render height in pixels (experimental)", cxxopts::value()->default_value("1024")) // Experimental ("autoModulate", "Enables automatic height modulation between two levels") @@ -216,6 +216,9 @@ int app(int argc, const char** argv) { std::cout << "Failed to initialize GLAD" << std::endl; return -1; } + const unsigned char* glver = glGetString(GL_VERSION); + std::cout << "(required: min core 3.3.0) opengl version: " << glver << "\n"; + glEnable(GL_DEPTH_TEST); glViewport(0, 0, m_renderWidth, m_renderHeight); diff --git a/MCDV/util.h b/MCDV/util.h index 368ac94..0cb2b6e 100644 --- a/MCDV/util.h +++ b/MCDV/util.h @@ -73,6 +73,12 @@ std::vector split(std::string s, std::string delimiter) namespace sutil { + std::string to_lower(std::string in) { + std::string o = in; + std::transform(o.begin(), o.end(), o.begin(), ::tolower); + return o; + } + std::string get_unquoted_material(std::string in) { std::vector sgts = split(in, '\"'); std::string u = ""; diff --git a/MCDV/vmf.hpp b/MCDV/vmf.hpp index beba806..a254191 100644 --- a/MCDV/vmf.hpp +++ b/MCDV/vmf.hpp @@ -200,6 +200,8 @@ namespace vmf { vmf(std::string path) { + std::cout << "Opening: " << path << "\n"; + std::ifstream ifs(path); if (!ifs) { std::cout << "Could not open file... " << path << std::endl; @@ -626,13 +628,14 @@ namespace vmf { this->modelDict.insert({ modelName, mIndex++ }); // Add to our list // Generate our model data and wham it into the model cache + // TODO: Clean up code duplication here. vpk::vEntry* vEntry = pakIndex.find(modelName); if (vEntry != NULL) { vpk::vEntry* vtx_entry = pakIndex.find(baseName + ".dx90.vtx"); vpk::vEntry* vvd_entry = pakIndex.find(baseName + ".vvd"); if (vtx_entry == NULL || vvd_entry == NULL) { - std::cout << "Couldn't find vtx/vvd model data\n"; + std::cout << "[pak] Couldn't find vtx/vvd model data\n"; this->modelCache.push_back(NULL); continue; } @@ -669,7 +672,8 @@ namespace vmf { // Check that custom model data actually exists if (_access_s(vtxFile.c_str(), 0) != 0 || _access_s(vvdFile.c_str(), 0) != 0) { - std::cout << "Couldn't find vtx/vvd model data\n"; + std::cout << "[custom] Couldn't find vtx/vvd model data\n"; + std::cout << "Skipping: " << baseName << "\n"; this->modelCache.push_back(NULL); continue; } @@ -677,6 +681,13 @@ namespace vmf { // Read vtx vtx_mesh vtx(vtxFile); + // VTX issues only exist for custom content. Everying in pakfiles are v7 + if (!vtx.read_success) { + std::cout << "Skipping: " << baseName << "\n"; + this->modelCache.push_back(NULL); + continue; + } + // Read vvd vvd_data vvd(vvdFile); diff --git a/MCDV/vpk.hpp b/MCDV/vpk.hpp index 4f33b12..b9e364e 100644 --- a/MCDV/vpk.hpp +++ b/MCDV/vpk.hpp @@ -85,6 +85,9 @@ namespace vpk std::cout << "Version: " << this->header.Version << "\n"; std::cout << "TreeSize: " << this->header.TreeSize << "\n"; + std::ofstream f; + f.open("vpk.txt"); + while (true) { std::string extension = get_sz(&reader); std::cout << " *." << extension << "\n"; @@ -111,6 +114,7 @@ namespace vpk } entry.entryString = folder + "/" + filename + "." + extension; + f << folder + "/" + filename + "." + extension << "\n"; this->entries.push_back(entry); } @@ -119,6 +123,8 @@ namespace vpk IL_EXIT: + f.close(); + std::cout << "Done reading\n"; std::cout << this->entries.size() << " entries read\n"; @@ -126,8 +132,10 @@ namespace vpk } vEntry* find(std::string name) { + // All files in vpk are stored in lowercase. + std::string search = sutil::to_lower(name); for (auto && v : this->entries) { - if (v.entryString == name) { + if (v.entryString == search) { return &v; } } diff --git a/MCDV/vtx.hpp b/MCDV/vtx.hpp index 6cb09b0..715ee03 100644 --- a/MCDV/vtx.hpp +++ b/MCDV/vtx.hpp @@ -151,6 +151,7 @@ class vtx_mesh : public util::verboseControl public: std::vector vertexSequence; vtx::FileHeader header; + bool read_success = true; vtx_mesh(std::string filepath, bool verbose = false) { @@ -168,6 +169,13 @@ public: this->debug("VTX version:", this->header.version); this->debug("Num LODS:", this->header.numLODs); + // We only support version 7 + if (this->header.version != 7) { + this->read_success = false; + std::cout << "VTX version " << this->header.version << " unsupported. Expected v7.\n"; + return; + } + /* Read bulk of .VTX file */ /* Body part array */ -- 2.25.1