Fixed everything and added zip file as a resource

main
IMXNOOBX 9 months ago
parent edab5bcc8e
commit 730be27a10

@ -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

3
.gitignore vendored

@ -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

@ -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 <cstddef>\n"
index_header_content += "#include <string>\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.")

@ -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")

@ -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

@ -2,15 +2,16 @@
#include <fstream>
#include <filesystem> // Include the filesystem library
#include <locale>
#include <codecvt>
#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<const char*>(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<const char*>(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;

Binary file not shown.

@ -139,12 +139,21 @@
<ClCompile Include="utils\miniz.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="process\process.hpp" />
<ClInclude Include="utils\utilities.hpp" />
<ClInclude Include="resource.h" />
<ClInclude Include="resources\embedded_files.h" />
<ClInclude Include="resources\old_steam.h" />
<ClInclude Include="utils\debug.hpp" />
<ClInclude Include="utils\miniz.h" />
</ItemGroup>
<ItemGroup>
<None Include="resources\old_steam.zip">
<FileType>Document</FileType>
</None>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="steam-rollback.rc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>

@ -11,9 +11,16 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="resources\embedded_files.h" />
<ClInclude Include="process\process.hpp" />
<ClInclude Include="utils\utilities.hpp" />
<ClInclude Include="utils\debug.hpp" />
<ClInclude Include="utils\miniz.h" />
<ClInclude Include="resources\old_steam.h" />
<ClInclude Include="resource.h" />
</ItemGroup>
<ItemGroup>
<None Include="resources\old_steam.zip" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="steam-rollback.rc" />
</ItemGroup>
</Project>

@ -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<char*>(pResourceData), dataSize);
outputFile.close();
}
}
}
bool check_open_processname(const char* pName) {
PROCESSENTRY32 processEntry;
processEntry.dwSize = sizeof(PROCESSENTRY32);
Loading…
Cancel
Save