From 730be27a10061783043c2ce6bcd5ee9ea976d41e Mon Sep 17 00:00:00 2001 From: IMXNOOBX Date: Fri, 11 Aug 2023 15:32:13 +0200 Subject: [PATCH] Fixed everything and added zip file as a resource --- .github/workflows/create_zip.yml | 32 ------- .gitignore | 3 + generate_binaries.py | 88 ------------------ generate_zip_binary.py | 29 +----- steam-rollback/resource.h | 16 ++++ steam-rollback/steam-rollback.cpp | 69 +++----------- steam-rollback/steam-rollback.rc | Bin 0 -> 3846 bytes steam-rollback/steam-rollback.vcxproj | 11 ++- steam-rollback/steam-rollback.vcxproj.filters | 9 +- .../process.hpp => utils/utilities.hpp} | 20 +++- 10 files changed, 74 insertions(+), 203 deletions(-) delete mode 100644 .github/workflows/create_zip.yml delete mode 100644 generate_binaries.py create mode 100644 steam-rollback/resource.h create mode 100644 steam-rollback/steam-rollback.rc rename steam-rollback/{process/process.hpp => utils/utilities.hpp} (86%) diff --git a/.github/workflows/create_zip.yml b/.github/workflows/create_zip.yml deleted file mode 100644 index 1146d23..0000000 --- a/.github/workflows/create_zip.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: Zip Steam Files - -on: - push: - branches: - - main - -jobs: - create-and-commit-zip: - runs-on: ubuntu-latest - - steps: - - name: Checkout Repository - uses: actions/checkout@v2 - - - name: Create Zip - run: | - zip -r old_steam.zip old_steam - - - name: Commit Zip File - run: | - git config --local user.email "actions@github.com" - git config --local user.name "GitHub Actions" - git add old_steam.zip - git commit -m "Add zip file" - git push - - - name: Upload Zip Artifact - uses: actions/upload-artifact@v2 - with: - name: my-zip-artifact - path: old_steam.zip diff --git a/.gitignore b/.gitignore index 8a30d25..1cabfa8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,9 @@ ## ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore +# Steam zip file +steam-rollback/resources/old_steam.zip + # User-specific files *.rsuser *.suo diff --git a/generate_binaries.py b/generate_binaries.py deleted file mode 100644 index 350dacb..0000000 --- a/generate_binaries.py +++ /dev/null @@ -1,88 +0,0 @@ -import os - -# Input directory containing the files -input_dir = "old_steam/" - -# Output directory for generated header files -output_dir = "steam-rollback/resources/" - -# Create the output directory if it doesn't exist -os.makedirs(output_dir, exist_ok=True) -os.remove(output_dir + "*") -# Function to generate C-style array from binary content -def generate_binary_array(binary_content, filename): - binary_array = ", ".join(f"{byte:#04x}" for byte in binary_content) - result = f"const unsigned char {filename}_data[] = {{ {binary_array} }};\n\n" - result += f"const size_t {filename}_size = sizeof({filename}_data);" - return result - -# Recursively walk through the input directory and its subdirectories -header_entries = [] - -for root, _, filenames in os.walk(input_dir): - for filename in filenames: - file_path = os.path.join(root, filename) - raw_relative_path = os.path.relpath(file_path, input_dir) - relative_path_parts = raw_relative_path.split(os.sep) - relative_path_parts[-1] = relative_path_parts[-1].replace(".", "_").replace("-", "_") - relative_path = os.path.join(*relative_path_parts) - output_path = os.path.join(output_dir, raw_relative_path) + ".h" - - with open(file_path, "rb") as f: - binary_content = f.read() - - header_content = f"#pragma once\n\n" - header_content += generate_binary_array(binary_content, filename.replace(".", "_").replace("-", "_")) - - header_subdir = os.path.dirname(output_path) - os.makedirs(header_subdir, exist_ok=True) - - with open(output_path, "w") as header_file: - header_file.write(header_content) - - print(f"Generated header: {output_path}") - - # Append entry to header_entries list - header_entries.append({ - "relative_path": raw_relative_path, - "raw_relative_path": raw_relative_path.replace("\\", "\\\\"), - "filename": filename.replace(".", "_").replace("-", "_"), - "raw_filename": filename, - "variable_name": f"data_{relative_path.replace('/', '_').replace('.', '_')}", - }) - -# Generate the index header file -index_header_content = "#pragma once\n\n" -index_header_content += "#include \n" -index_header_content += "#include \n\n" - -for entry in header_entries: - index_header_content += f"#include \"{entry['relative_path']}.h\"\n" - -index_header_content += "\nnamespace embedded_files {\n" - -index_header_content += """ -\tstruct binary_info { -\t const unsigned char* data; -\t size_t size; -\t std::string name; -\t std::string relative_path; -\t}; - -""" - -index_header_content += "\tconst binary_info file_array[] = {\n" - -for entry in header_entries: - index_header_content += "\t\t{ " + entry['filename'] + "_data, " + entry['filename'] + "_size, \"" + entry['raw_filename'] + "\", \"" + entry['raw_relative_path'] + "\" },\n" - -index_header_content += "\t};\n" - -index_header_content += "}\n" - -index_header_path = os.path.join(output_dir, "embedded_files.h") -with open(index_header_path, "w") as index_header_file: - index_header_file.write(index_header_content) - -print(f"Generated index header: {index_header_path}") -print("All headers and index file generated.") diff --git a/generate_zip_binary.py b/generate_zip_binary.py index f52ae28..7a7f4c5 100644 --- a/generate_zip_binary.py +++ b/generate_zip_binary.py @@ -10,37 +10,14 @@ output_dir = "steam-rollback/resources/" # Create the output directory if it doesn't exist os.makedirs(output_dir, exist_ok=True) -# os.remove(output_dir + "*") -# Function to generate C-style array from binary content -def generate_binary_array(binary_content, filename): - binary_array = ", ".join(f"{byte:#04x}" for byte in binary_content) - result = f"const unsigned char {filename}_data[] = {{ {binary_array} }};\n\n" - result += f"const size_t {filename}_size = sizeof({filename}_data);" - return result - - -with zipfile.ZipFile(zip_file_name + ".zip", 'w') as zipf: +with zipfile.ZipFile(output_dir + zip_file_name + ".zip", 'w') as zipf: for root, _, filenames in os.walk(input_dir): for filename in filenames: file_path = os.path.join(root, filename) # Construct the full path print(f"Adding file into zip: {file_path}") zipf.write(file_path, os.path.relpath(file_path, input_dir)) # Add the file to the zip archive -print(f"All files added to the zip, generating header file") - -# Generate the index header file -header_content = f"#pragma once\n\n" - -with open(zip_file_name + ".zip", "rb") as f: - binary_content = f.read() - -header_content += f"const char* file_name = \"{zip_file_name}.zip\";\n" -header_content += generate_binary_array(binary_content, zip_file_name.replace(".", "_").replace("-", "_")) - -with open(output_dir + zip_file_name + ".h", "w") as header_file: - header_file.write(header_content) - +print(f"All files added to the zip, generating file...") -print(f"Generated index header: {output_dir + zip_file_name}.h") -print("All headers and index file generated.") +print(f"Generated zip file: {output_dir + zip_file_name}.zip") \ No newline at end of file diff --git a/steam-rollback/resource.h b/steam-rollback/resource.h new file mode 100644 index 0000000..cbb8a2f --- /dev/null +++ b/steam-rollback/resource.h @@ -0,0 +1,16 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by steam-rollback.rc +// +#define IDR_OLDSTEAM1 101 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 102 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1001 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/steam-rollback/steam-rollback.cpp b/steam-rollback/steam-rollback.cpp index cd50683..b95565b 100644 --- a/steam-rollback/steam-rollback.cpp +++ b/steam-rollback/steam-rollback.cpp @@ -2,15 +2,16 @@ #include #include // Include the filesystem library #include -#include -#include "resources/old_steam.h" +#include "resource.h" #include "utils/miniz.h" -#include "process/process.hpp" #include "utils/debug.hpp" +#include "utils/utilities.hpp" int main() { + SetConsoleTitle("Steam Rollback"); + HKEY hKey; WCHAR steam_path_w[256]; // Adjust the size according to your needs DWORD steam_path_s = sizeof(steam_path_w); @@ -32,8 +33,8 @@ int main() return 0; } - for (int i = 0; i < size(proc::steamProcesses); i++) - proc::terminate_process(proc::steamProcesses[i]); + for (int i = 0; i < size(util::steamProcesses); i++) + util::terminate_process(util::steamProcesses[i]); debug::log::warn("Steam has been closed."); @@ -43,7 +44,7 @@ int main() std::string steam_path(size_needed - 1, 0); // Subtract 1 to exclude the null character WideCharToMultiByte(CP_UTF8, 0, steam_path_w, -1, &steam_path[0], size_needed, nullptr, nullptr); - std::string steam_version = proc::get_file_version(steam_path + "/steam.exe"); + std::string steam_version = util::get_file_version(steam_path + "/steam.exe"); if (steam_version.find("Error") != std::string::npos) { debug::log::error("Could not get steam version: " + steam_version); } @@ -59,50 +60,16 @@ int main() } } - // Unzip files and restore old steam + // Extract and unzip files to restore old steam if (should_rollback) { - //for (const embedded_files::binary_info& file : embedded_files::file_array) { - - // std::string absolute_path = steam_path + file.relative_path; - // //std::cout << "absolute_path " << absolute_path << std::endl; - - // // Create the directory path if it doesn't exist - // std::filesystem::path directoryPath(absolute_path); - // directoryPath.remove_filename(); // Get the directory path without the filename - // std::filesystem::create_directories(directoryPath); - - // std::ofstream outFile(absolute_path, std::ios::out | std::ios::binary); - - // if (!outFile) { - // debug::log::error("Failed to open output file for: " + file.name); - // continue; - // } - - // // Write binary data to the file - // outFile.write(reinterpret_cast(file.data), file.size); - - // // Close the file - // outFile.close(); - - // debug::log::success("Binary data written to " + file.relative_path); - //} + std::string absolute_path = steam_path + "/" + "old_steam.zip"; - std::string file_name_ = file_name; - std::string absolute_path = steam_path + "/" + file_name_; - std::ofstream outFile(absolute_path, std::ios::out | std::ios::binary); - - if (!outFile) { - debug::log::error("Failed to open output file for: " + absolute_path); - return -1; - } - - outFile.write(reinterpret_cast(old_steam_data), old_steam_size); - outFile.close(); + util::extract_resource(absolute_path); debug::log::success("ZIP File build successfully: " + absolute_path + "\n"); - //std::this_thread::sleep_for(std::chrono::seconds(5)); + std::this_thread::sleep_for(std::chrono::seconds(1)); mz_zip_archive zip_archive; memset(&zip_archive, 0, sizeof(zip_archive)); @@ -118,17 +85,14 @@ int main() std::string output_filename = steam_path + std::string("/") + file_stat.m_filename; // Check if the file already exists - if (proc::file_exists(output_filename)) { - //std::cout << "Replacing existing file: " << output_filename << std::endl; + if (util::file_exists(output_filename)) { debug::log::success("replacing existing file -> " + output_filename); } if (mz_zip_reader_extract_to_file(&zip_archive, i, output_filename.c_str(), 0)) { - //std::cout << "Extracted: " << output_filename << std::endl; debug::log::success("extracted -> " + output_filename); } else { - //std::cerr << "Failed to extract: " << output_filename << std::endl; debug::log::error("failed to extract -> " + output_filename); } } @@ -138,16 +102,14 @@ int main() debug::log::success("Files extraction clompleted!"); } else { - //std::cerr << "Failed to open zip file." << std::endl; debug::log::error("Failed to open zip file."); return -1; } - debug::log::success("Deleting zip file..."); std::remove(absolute_path.c_str()); } - else { + else { // Delete essential files and let steam update them const std::string file_array[] = { "steam.cfg", "tier0_s.dll", "tier0_s64.dll" }; for (std::string file : file_array) @@ -158,9 +120,7 @@ int main() std::this_thread::sleep_for(std::chrono::seconds(1)); - std::cin.get(); - - debug::log::success("Starting steam..."); + debug::log::success("Starting steam...\n"); HINSTANCE hInstance = ShellExecuteW(NULL, L"open", L"steam://open/main", NULL, NULL, SW_SHOWNORMAL); if ((int)hInstance <= 32) { @@ -168,6 +128,7 @@ int main() return 0; } + debug::log::warn("Program finished, click any key to close."); std::cin.get(); return 0; diff --git a/steam-rollback/steam-rollback.rc b/steam-rollback/steam-rollback.rc new file mode 100644 index 0000000000000000000000000000000000000000..2ae20d0f8978ff1894b97f7bd783767346ae767d GIT binary patch literal 3846 zcmd6q+iuf95QgU(iFYu`4HYQi@B}%O5G8F&Xj7Ah+^S5}p+P z8ajuULUrAS*$wl6H`TU~6*4V(Do@y@?PwEj!q+9zb0^yrNTTc^4^ z@I;5{oVv$36^~>1Z+P}S^0*JaIDGSUyZHNum|2uZ#|Er4l48z%SZo;brq?fO z)&+PsA^(HiXFJ(7M`uUg5m$Lug=El- z{OYlHM0|}Is`ncss9iZl$Al=3Sak|La=VV<>e~!DaFJ>plN%Gup}d!u=nj$VvRl4p zUn1h`=>9Bz`KxG+`Oav7XO`fWIiFqQCHtaOpCKquKu#-H9~3mpJJhn*U{W>q^;O9f zdF5)G$rU5l6BR6L$yefOwNr_;F3sU;uH{2d`|l#Nh@D?^^N;za$(c4$^YY5f4kwWz*Ul0L0)4M)op2G8^f`n9!$16xkSD>|`zJlyZMC8<&yD=xM zGVf}45^w8T)or48?K$g4WM%(8cMW~NsKtWOx{krV8wOfw>Us;6>2me~IOnKY9Vpio z?INz^)wX`W7&`5vy|AFD?7Y;>h)WZ5a NNVvcBAMEdD)K7h&$$|g? literal 0 HcmV?d00001 diff --git a/steam-rollback/steam-rollback.vcxproj b/steam-rollback/steam-rollback.vcxproj index 9202bb3..15beb3c 100644 --- a/steam-rollback/steam-rollback.vcxproj +++ b/steam-rollback/steam-rollback.vcxproj @@ -139,12 +139,21 @@ - + + + + + Document + + + + + diff --git a/steam-rollback/steam-rollback.vcxproj.filters b/steam-rollback/steam-rollback.vcxproj.filters index 3be0776..04a61be 100644 --- a/steam-rollback/steam-rollback.vcxproj.filters +++ b/steam-rollback/steam-rollback.vcxproj.filters @@ -11,9 +11,16 @@ - + + + + + + + + \ No newline at end of file diff --git a/steam-rollback/process/process.hpp b/steam-rollback/utils/utilities.hpp similarity index 86% rename from steam-rollback/process/process.hpp rename to steam-rollback/utils/utilities.hpp index 9d1b472..9e721ed 100644 --- a/steam-rollback/process/process.hpp +++ b/steam-rollback/utils/utilities.hpp @@ -6,7 +6,7 @@ #define size(arr) sizeof(arr) / sizeof(arr[0]) -namespace proc { +namespace util { const char* steamProcesses[] = { "csgo.exe", "Steam.exe", "SteamClient.exe", "SteamService.exe", "SteamWebHelper.exe", "steamwebhelper.exe" }; bool terminate_process(const char* pName) { @@ -88,6 +88,24 @@ namespace proc { return file.good(); } + void extract_resource(const std::string& outputFilePath) + { + HRSRC hResource = FindResource(NULL, MAKEINTRESOURCE(IDR_OLDSTEAM1), "oldsteam"); + if (hResource) + { + HGLOBAL hResourceData = LoadResource(NULL, hResource); + if (hResourceData) + { + void* pResourceData = LockResource(hResourceData); + DWORD dataSize = SizeofResource(NULL, hResource); + + std::ofstream outputFile(outputFilePath, std::ios::binary); + outputFile.write(reinterpret_cast(pResourceData), dataSize); + outputFile.close(); + } + } + } + bool check_open_processname(const char* pName) { PROCESSENTRY32 processEntry; processEntry.dwSize = sizeof(PROCESSENTRY32);