183 lines
4.9 KiB
C++
183 lines
4.9 KiB
C++
#include <iostream>
|
|
#include <fstream>
|
|
#include <unistd.h>
|
|
#include <pwd.h>
|
|
#include <vector>
|
|
#include <cstring>
|
|
#include <openssl/md5.h> /* md5sum */
|
|
|
|
#include "../include/etw-lmm_config.h"
|
|
#include "../include/rapidjson/document.h"
|
|
|
|
|
|
std::string to_hex(unsigned char*);
|
|
void md5sum(std::string, unsigned char [MD5_DIGEST_LENGTH]);
|
|
void print_md5_sum(unsigned char*);
|
|
int calibrate_preferences();
|
|
int calibrate_text_bug_fix();
|
|
int calibrate_backup(const std::string&);
|
|
int yn_query(const std::string&, bool);
|
|
int dir_not_exists(const std::string&);
|
|
|
|
/**
|
|
* Brings up the command list/help menu
|
|
*/
|
|
void help_menu()
|
|
{
|
|
std::cout << "EMPIRE: TOTAL WAR -- LINUX MOD MANAGER "
|
|
<< std::to_string(etw_lmm_VERSION_MAJOR) << "." << std::to_string(etw_lmm_VERSION_MINOR) << "\n"
|
|
<< "Options:\n"
|
|
<< "\thelp\t\tShow this help message\n"
|
|
<< "\tinstall [MOD]\tInstall a mod\n"
|
|
<< "\tuninstall [MOD]\tUninstall a mod\n"
|
|
<< "\tcalibrate\tCalibrate original game files for modding\n"
|
|
<< "\tlist\t\tList installed mods\n"
|
|
<< "\tquery [MOD]\tQuery available mods"
|
|
<< std::endl;
|
|
}
|
|
|
|
/**
|
|
* Lists installed mods in mods filepath
|
|
*
|
|
* @param Path for file MODS
|
|
*/
|
|
int list(const std::string& hd)
|
|
{
|
|
const std::string mods = hd + "/.config/etw-lmm/MODS";
|
|
|
|
/* If file MODS doesn't exist */
|
|
if (access(mods.c_str(), F_OK) == -1)
|
|
{
|
|
std::cout << "No mods installed!";
|
|
return 0;
|
|
}
|
|
|
|
std::ifstream ioMODS(mods);
|
|
std::string name;
|
|
|
|
while (std::getline (ioMODS, name))
|
|
{
|
|
if (name == "\0")
|
|
{
|
|
std::cout << "No mods installed!";
|
|
}
|
|
std::cout << name << std::endl;
|
|
}
|
|
|
|
ioMODS.close();
|
|
|
|
return 0;
|
|
}
|
|
|
|
int calibrate(const std::string& hd, const std::vector<std::string>& path, const char* path_md5[])
|
|
{
|
|
const std::string mods = hd + "/.config/etw-lmm/MODS";
|
|
|
|
/* If file MODS exists */
|
|
if (access(mods.c_str(), F_OK) != -1)
|
|
{
|
|
std::ifstream ioMODS(mods);
|
|
std::string name;
|
|
|
|
std::getline (ioMODS, name);
|
|
if (name != "\0")
|
|
{
|
|
std::cerr << "Either get a fresh install of Empire: Total War or uninstall the following mods: " << std::endl;
|
|
list(mods);
|
|
ioMODS.close();
|
|
return 1;
|
|
}
|
|
|
|
ioMODS.close();
|
|
}
|
|
|
|
unsigned int x = 0;
|
|
|
|
std::cout << "No mods installed! Calibrating files now..." << std::endl;
|
|
for (unsigned int i = 0; i < path.size(); i++)
|
|
{
|
|
unsigned char md5_local[MD5_DIGEST_LENGTH];
|
|
md5sum(path[i], md5_local);
|
|
if ((strcmp(to_hex(md5_local).c_str(), path_md5[i]) != 0))
|
|
{
|
|
/* write_preferences_at_exit false in preferences.empire_script.txt */
|
|
if (i == 0 && to_hex(md5_local) == "fbf65ef80563e0bd76836c150e49ecd0")
|
|
{
|
|
if (calibrate_preferences())
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
continue;
|
|
}
|
|
|
|
/* preferences has VBOSurfaces set to 1, TEXT BUG FIX */
|
|
if (i == 1 && to_hex(md5_local) == "1d7c5d84f79a3d361bfa7c608b71d8c8")
|
|
{
|
|
if (calibrate_text_bug_fix())
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
continue;
|
|
}
|
|
print_md5_sum(md5_local);
|
|
std::cerr << " != " << path_md5[i] << "\n" << path[i] << " is not calibrated!" << std::endl;
|
|
x++;
|
|
}
|
|
}
|
|
|
|
if (x > 0)
|
|
{
|
|
std::cerr << "Number of files uncalibrated: " << x << std::endl;
|
|
return 1;
|
|
}
|
|
|
|
std::cout << "All files are calibrated!" << std::endl;
|
|
|
|
/* GAME FILE BACKUPS */
|
|
|
|
if (calibrate_backup(hd))
|
|
{
|
|
if (yn_query("Would you like to backup your game files? This is recommended.", true))
|
|
{
|
|
std::cout << "Backing up files now..." << std::endl;
|
|
|
|
const std::string dir_main_backup = hd + "/.local/share/Steam/steamapps/common/Empire\ Total\ War/data/campaigns/main_backup";
|
|
const std::string dir_global_map_backup = hd + "/.local/share/Steam/steamapps/common/Empire\ Total\ War/data/campaign_maps/global_map_backup";
|
|
|
|
if (dir_not_exists(dir_main_backup))
|
|
{
|
|
const std::string dir_main = hd + "/.local/share/Steam/steamapps/common/Empire\ Total\ War/data/campaigns/main/";
|
|
|
|
const std::string backup_main = "cp -R " + dir_main + ". " + dir_main_backup;
|
|
|
|
if (system(backup_main.c_str()))
|
|
{
|
|
std::cerr << "Failed to backup data/campaigns/main/!" << std::endl;
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
if (dir_not_exists(dir_global_map_backup))
|
|
{
|
|
const std::string dir_global_map = hd + "/.local/share/Steam/steamapps/common/Empire\ Total\ War/data/campaign_maps/global_map/";
|
|
|
|
const std::string backup_global_map = "cp -R " + dir_global_map + ". " + dir_global_map_backup;
|
|
|
|
if (system(backup_global_map.c_str()))
|
|
{
|
|
std::cerr << "Failed to backup data/campaign_map/global_map/!" << std::endl;
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
std::cout << "Critical game data is now backed up!" << std::endl;
|
|
}
|
|
}
|
|
|
|
std::cout << "The game is now ready to install mods." << std::endl;
|
|
|
|
return 0;
|
|
}
|