mirror of
https://git.triforceproject.com/triforce/source
synced 2026-11-19 16:20:01 -04:00
Triforce v0.5.0
In-game mods (GameBanana browser, search and installs, with the Mask Salesman), code-patch and cheat mods, the devs' test18 to test45 work (full performance overlay, frame pacing on, steady frame rate, save export and import, bug capture, new options rows, Setup's Mods page and Add to Steam), occlusion queries and new defaults, Auto resolution that scales, replay helper threads and robust buffers off by default, the options in sections.
This commit is contained in:
@@ -13,8 +13,37 @@
|
||||
#undef min
|
||||
#undef max
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
namespace mkwvk {
|
||||
/// (Triforce) Long paths: the probe for image.bin is the one Win32 path game_module_path makes. Under MAX_PATH it is the A
|
||||
/// function as before; from MAX_PATH on, the path (UTF-8: the exe's manifest makes that the process's code page) goes to
|
||||
/// GetFileAttributesW with "\\?\" in front ("\\?\UNC\" for \\server\share), which takes it whatever Windows' own
|
||||
/// LongPathsEnabled says (the A function does not, unless the manifest's longPathAware meets it). The probe was a MAX_PATH
|
||||
/// buffer: a folder of 250 characters and more was taken for its bin folder. The path given back has no "\\?\" (as
|
||||
/// host/hos_paths.h): its callers add names with '/' and show it
|
||||
inline bool game_path_there(const std::string& path) {
|
||||
#ifdef _WIN32
|
||||
if (path.size() < MAX_PATH - 1)
|
||||
#endif
|
||||
return GetFileAttributesA(path.c_str()) != INVALID_FILE_ATTRIBUTES; // (Linux: host/posix's, any length)
|
||||
#ifdef _WIN32
|
||||
const int n = MultiByteToWideChar(CP_UTF8, 0, path.data(), (int)path.size(), nullptr, 0);
|
||||
if (n <= 0) return false;
|
||||
std::wstring w((size_t)n, L'\0');
|
||||
MultiByteToWideChar(CP_UTF8, 0, path.data(), (int)path.size(), w.data(), n);
|
||||
const bool already = w.size() > 2 && w[0] == L'\\' && w[1] == L'\\' && (w[2] == L'?' || w[2] == L'.');
|
||||
const bool unc = !already && w.size() > 2 && w[0] == L'\\' && w[1] == L'\\';
|
||||
const bool drive = w.size() > 2 && w[1] == L':' && (w[2] == L'\\' || w[2] == L'/');
|
||||
if (!already && (unc || drive)) {
|
||||
for (wchar_t& c : w)
|
||||
if (c == L'/') c = L'\\';
|
||||
w = unc ? L"\\\\?\\UNC" + w.substr(1) : L"\\\\?\\" + w;
|
||||
}
|
||||
return GetFileAttributesW(w.c_str()) != INVALID_FILE_ATTRIBUTES;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline DWORD game_module_path(char* buf, DWORD size) {
|
||||
DWORD n = GetModuleFileNameA(nullptr, buf, size);
|
||||
if (!n || n >= size) return n;
|
||||
@@ -25,12 +54,8 @@ inline DWORD game_module_path(char* buf, DWORD size) {
|
||||
char* bin = dir;
|
||||
while (bin > buf && bin[-1] != '\\' && bin[-1] != '/') bin--;
|
||||
if (dir - bin != 3 || _strnicmp(bin, "bin", 3) != 0) return n;
|
||||
char probe[MAX_PATH + 16];
|
||||
const size_t root = (size_t)(bin - buf);
|
||||
if (root + 10 >= sizeof probe) return n;
|
||||
std::memcpy(probe, buf, root);
|
||||
std::strcpy(probe + root, "image.bin");
|
||||
if (GetFileAttributesA(probe) == INVALID_FILE_ATTRIBUTES) return n;
|
||||
if (!game_path_there(std::string(buf, root) + "image.bin")) return n; // ((Triforce) any length: game_path_there)
|
||||
std::memmove(buf + root, name, std::strlen(name) + 1);
|
||||
return (DWORD)std::strlen(buf);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user