Hello @Sultan and @patrick13!
Maybe the source code of my program will help you:
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <stdexcept>
#include <cstdio>
#include <Windows.h>
#include "Shlwapi.h"
// Напечатать приветственное сообщение
void Welcome();
// Получить директорию, в которой находится программа
std::string GetBaseDir();
// Прочитать .bin файл
void ReadBinaryFile(const std::string& path,
std::vector<std::string>& list);
// Получить список файлов в директории
void GetFilesInDir(const std::string& path,
std::vector<std::string>& list);
// Получить название файла без расширения
std::string ExtractFileName(const std::string& name);
// Проверить, что программа находится в корневой папке с игрой
bool CheckClient(const std::string& base_path);
// Точка входа
int main(int argc, char *argv[])
{
// Список файлов моделей в sceneeffectinfo.bin
std::vector<std::string> models;
// Список файлов в директории Client\model\effect
std::vector<std::string> client_models;
// Базовый путь
std::string base_path = GetBaseDir();
// Печатаем привественное сообщение
Welcome();
// Проверим, что программа находится в папке с игрой
if (!CheckClient(base_path))
{
std::cout << "[error] Please place the program in the root directory of the game client!" << std::endl << std::endl;
system("PAUSE");
return 0;
}
// Читаем .bin файлы
try
{
ReadBinaryFile(base_path + "\\scripts\\table\\sceneffectinfo.bin", models);
}
catch (const std::runtime_error& e) {
std::cout << "[error] " << e.what() << std::endl;
}
catch (...) {
std::cout << "[error] Unknown error!" << std::endl;
}
// Получаем список файлов в клиенте
GetFilesInDir(base_path + "\\model\\effect\\", client_models);
// Ищем файлы, которые можно удалить
unsigned int n = 0;
for (unsigned int i = 0; i < client_models.size(); i++)
{
auto it = std::find(models.begin(), models.end(), client_models[i]);
if (it == models.end()) {
std::string file_path = base_path + "\\model\\effect\\" + client_models[i] + ".lgo";
if (remove(file_path.c_str())) {
std::cout << "[error] Can't remove model: " << client_models[i] << std::endl;
}
else {
std::cout << "[ok] Model removed: " << client_models[i] << std::endl;
n++;
}
}
}
std::cout << n << " files removed!" << std::endl;
system("PAUSE");
return 0;
}
// Напечатать приветственное сообщение
void Welcome()
{
std::cout << "Swings Fixer by V3ct0r from PkoDEV.NET" << std::endl;
std::cout << "Version 1.0 (05.05.2018)" << std::endl << std::endl;
}
// Получить директорию, в которой находится программа
std::string GetBaseDir()
{
TCHAR path[MAX_PATH];
GetModuleFileName(NULL, path, MAX_PATH);
PathRemoveFileSpec(path);
return std::string(path);
}
// Прочитать .bin файл
void ReadBinaryFile(const std::string& path,
std::vector<std::string>& list)
{
std::cout << "Reading file: " << path << " . . . " << std::endl;
// Открываем файл
std::ifstream file(path, std::ios::binary);
if (file.is_open() == false) {
throw std::runtime_error("Can't open file " + path + "!");
}
// Получим размер файла
size_t file_size = 0;
file.seekg(0, file.end);
file_size = static_cast<size_t>(file.tellg());
file.seekg(0, file.beg);
// Выделяем память под файл
char *file_mem = nullptr;
try {
file_mem = new char[file_size];
}
catch (const std::bad_alloc&) {
throw std::runtime_error("Can't allocate memory for file " + path + "!");
}
// Читаем файл в память
file.read(file_mem, file_size);
if (file.gcount() != file_size) {
delete[] file_mem;
throw std::runtime_error("Error while reading file " + path + "!");
}
// Закрываем файл
file.close();
// Получаем размер блока
unsigned int block_size = 0;
std::memcpy(reinterpret_cast<char *>(&block_size), file_mem, sizeof(block_size));
// Определяем количество файлов
unsigned int n = (file_size - sizeof(block_size)) / block_size;
// Читаем файлы
char name[72];
std::memset(name, 0x00, sizeof(name));
for (unsigned int i = 0; i < n; i++)
{
unsigned int offset = sizeof(block_size) + 8 + i * block_size;
std::memcpy(name, file_mem + offset, sizeof(name));
list.push_back(ExtractFileName(name));
}
// Освобождаем память
delete[] file_mem;
std::cout << n << " objects read!" << std::endl;
}
// Получить список файлов в директории
void GetFilesInDir(const std::string& path,
std::vector<std::string>& list)
{
std::cout << "Reading directory: " << path << " . . . " << std::endl;
WIN32_FIND_DATA fd;
HANDLE hFind = ::FindFirstFile((path + "*.*").c_str(), &fd);
unsigned int n = 0;
if (hFind != INVALID_HANDLE_VALUE)
{
do
{
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
}
else
{
list.push_back(ExtractFileName(fd.cFileName));
n++;
}
}
while(::FindNextFile(hFind, &fd));
::FindClose(hFind);
}
std::cout << n << " files found! " << std::endl;
}
// Получить название файла без расширения
std::string ExtractFileName(const std::string& name)
{
size_t pos = name.find_last_of('.');
return name.substr(0, pos);
}
// Проверить, что программа находится в корневой папке с игрой
bool CheckClient(const std::string& base_path)
{
bool ok = false;
std::ifstream file(base_path + "\\system\\MindPower3D_D8R.dll");
if (file.is_open()) {
ok = true;
file.close();
}
return ok;
}