7#include "Core/Private/Ark/ArkBaseApi.h"
8#include "Core/Private/Atlas/AtlasBaseApi.h"
9#include "Core/Public/Logger/Logger.h"
10#include "Core/Public/Tools.h"
12#pragma comment(lib, "Crypt32.lib")
13#pragma comment(lib, "Iphlpapi.lib")
19 "GetFileVersionInfoA",
"GetFileVersionInfoByHandle",
"GetFileVersionInfoExA",
"GetFileVersionInfoExW",
20 "GetFileVersionInfoSizeA",
"GetFileVersionInfoSizeExA",
"GetFileVersionInfoSizeExW",
"GetFileVersionInfoSizeW",
21 "GetFileVersionInfoW",
"VerFindFileA",
"VerFindFileW",
"VerInstallFileA",
"VerInstallFileW",
"VerLanguageNameA",
22 "VerLanguageNameW",
"VerQueryValueA",
"VerQueryValueW"
27 const DWORD InvalidParentProcessId = 0;
30 PROCESSENTRY32 ProcessEntry;
31 DWORD PID = GetCurrentProcessId();
33 Snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
34 if (Snapshot == INVALID_HANDLE_VALUE)
35 return InvalidParentProcessId;
37 ZeroMemory(&ProcessEntry,
sizeof(ProcessEntry));
38 ProcessEntry.dwSize =
sizeof(ProcessEntry);
40 if (!Process32First(Snapshot, &ProcessEntry))
41 return InvalidParentProcessId;
45 if (ProcessEntry.th32ProcessID == PID)
46 return ProcessEntry.th32ParentProcessID;
47 }
while (Process32Next(Snapshot, &ProcessEntry));
49 return InvalidParentProcessId;
54 const std::string config_path = ArkApi::Tools::GetCurrentDir() +
"/config.json";
55 std::ifstream file{ config_path };
59 nlohmann::json config;
63 return config[
"settings"].value(
"AttachToParent",
false);
70 if (GetConsoleWindow())
72 if (attachToParent && parentProcessId && AttachConsole(parentProcessId))
76 freopen_s(&p_cout,
"conout$",
"w", stdout);
77 SetConsoleOutputCP(CP_UTF8);
82 struct _stat64 fileInfo {};
83 if (_wstati64(filename.wstring().c_str(), &fileInfo) != 0)
85 throw std::runtime_error(
"Failed to get last write time.");
87 return fileInfo.st_mtime;
92 namespace fs = std::filesystem;
94 const auto now = std::chrono::system_clock::now();
96 const std::string current_dir = API::Tools::GetCurrentDir();
98 for (
const auto& file : fs::directory_iterator(current_dir +
"/logs"))
100 const std::time_t ftime = GetFileWriteTime(file);
102 if (file.path().filename() ==
"ArkApi.log")
105 localtime_s(&tm, &ftime);
108 strftime(time_str, 64,
"%Y-%m-%d-%H-%M", &tm);
110 const std::string new_name =
"ArkApi_" + std::string(time_str) +
".log";
111 std::rename(file.path().generic_string().data(), (current_dir +
"/logs/" + new_name).data());
114 const auto time_point = std::chrono::system_clock::from_time_t(ftime);
116 auto diff = std::chrono::duration_cast<std::chrono::hours>(now - time_point);
117 if (diff.count() >= 24 * 14)
126 namespace fs = std::filesystem;
128 const std::string current_dir = API::Tools::GetCurrentDir();
130 for (
const auto& directory_entry : fs::directory_iterator(current_dir))
132 const auto& path = directory_entry.path();
133 if (is_directory(path))
135 const auto name = path.filename().stem().generic_string();
136 if (name ==
"ArkApi")
140 if (name ==
"AtlasApi")
152 namespace fs = std::filesystem;
156 const std::string current_dir = API::Tools::GetCurrentDir();
158 if (!fs::exists(current_dir +
"/logs"))
160 fs::create_directory(current_dir +
"/logs");
167 const std::string game_name = DetectGame();
168 if (game_name ==
"Ark")
169 API::game_api = std::make_unique<API::ArkBaseApi>();
170 else if (game_name ==
"Atlas")
171 API::game_api = std::make_unique<API::AtlasBaseApi>();
175 API::game_api->Init();
178BOOL WINAPI
DllMain(HINSTANCE hinst_dll, DWORD fdw_reason, LPVOID )
180 if (fdw_reason == DLL_PROCESS_ATTACH)
182 DisableThreadLibraryCalls(hinst_dll);
184 CHAR sys_dir[MAX_PATH];
185 GetSystemDirectoryA(sys_dir, MAX_PATH);
187 char buffer[MAX_PATH];
188 sprintf_s(buffer,
"%s\\version.dll", sys_dir);
196 for (
int i = 0; i < 17; i++)
203 else if (fdw_reason == DLL_PROCESS_DETACH)
static std::shared_ptr< spdlog::logger > & GetLog()
void GetFileVersionInfoSizeW_wrapper()
void VerQueryValueA_wrapper()
void GetFileVersionInfoExW_wrapper()
void VerLanguageNameA_wrapper()
BOOL WINAPI DllMain(HINSTANCE hinst_dll, DWORD fdw_reason, LPVOID)
void GetFileVersionInfoSizeExW_wrapper()
void GetFileVersionInfoA_wrapper()
void VerInstallFileW_wrapper()
void VerLanguageNameW_wrapper()
void VerFindFileW_wrapper()
void GetFileVersionInfoByHandle_wrapper()
void GetFileVersionInfoW_wrapper()
std::time_t GetFileWriteTime(const std::filesystem::path &filename)
void VerInstallFileA_wrapper()
DWORD GetParentProcessId()
void GetFileVersionInfoExA_wrapper()
void VerQueryValueW_wrapper()
void GetFileVersionInfoSizeExA_wrapper()
void VerFindFileA_wrapper()
void GetFileVersionInfoSizeA_wrapper()