forked from alterware/iw6-mod
Compare commits
7 Commits
struct_suf
...
fallback_l
Author | SHA1 | Date | |
---|---|---|---|
2516a48fc1 | |||
1db89c64c6 | |||
51e831cbfe | |||
50aa4097bb | |||
e5a547650c | |||
adc33983a8 | |||
27d1f61789 |
@ -86,18 +86,28 @@ namespace colors
|
||||
return string;
|
||||
}
|
||||
|
||||
size_t get_client_name_stub(const int local_client_num, const int index, char* buf, const int size,
|
||||
const size_t unk, const size_t unk2)
|
||||
size_t get_client_name_stub(const int local_client_num, const int index, char* name_buf,
|
||||
const int max_name_size, char* clan_buf, const int max_clan_size)
|
||||
{
|
||||
// CL_GetClientName (CL_GetClientNameAndClantag?)
|
||||
const auto result = reinterpret_cast<size_t(*)(int, int, char*, int, size_t, size_t)>(0x1402CF790)(
|
||||
local_client_num, index, buf, size, unk, unk2);
|
||||
// CL_GetClientNameAndClanTag (wrapper for CL_GetClientNameAndClanTagColorize)
|
||||
const auto result = reinterpret_cast<size_t(*)(int, int, char*, int, char*, int)>(0x1402CF790)(
|
||||
local_client_num, index, name_buf, max_name_size, clan_buf, max_clan_size);
|
||||
|
||||
utils::string::strip(buf, buf, size);
|
||||
utils::string::strip(name_buf, name_buf, static_cast<size_t>(max_name_size));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int clean_agent_name_stub(char* out, int max_size, const char* fmt, const char* in)
|
||||
{
|
||||
// format agent overhead name like [%s]
|
||||
const auto length = sprintf_s(out, max_size, fmt, in);
|
||||
|
||||
utils::string::strip(in, out, std::min(static_cast<size_t>(length), static_cast<size_t>(max_size)));
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
void rb_lookup_color_stub(const char index, DWORD* color)
|
||||
{
|
||||
*color = RGB(255, 255, 255);
|
||||
@ -143,6 +153,9 @@ namespace colors
|
||||
// don't apply colors to overhead names
|
||||
utils::hook::call(0x14025CE79, get_client_name_stub);
|
||||
|
||||
// don't apply colors to overhead names of agents (like dogs or juggernauts)
|
||||
utils::hook::call(0x1402CF760, clean_agent_name_stub);
|
||||
|
||||
// patch I_CleanStr
|
||||
utils::hook::jump(0x1404F63C0, i_clean_str_stub);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "loader/component_loader.hpp"
|
||||
#include "game/game.hpp"
|
||||
|
||||
#include "utils/command_line.hpp"
|
||||
#include <utils/flags.hpp>
|
||||
#include <utils/io.hpp>
|
||||
#include <utils/string.hpp>
|
||||
@ -167,8 +168,23 @@ FARPROC load_binary(const launcher::mode mode)
|
||||
std::string data;
|
||||
if (!utils::io::read_file(binary, &data))
|
||||
{
|
||||
throw std::runtime_error(
|
||||
"Failed to read game binary! Please select the correct path in the launcher settings.");
|
||||
// Check the first argument to see if the current directory needs to changed
|
||||
// Required when the game is used to open a file (like a demo file)
|
||||
const auto& args = utils::command_line::get_args();
|
||||
if (!args.empty())
|
||||
{
|
||||
const auto& binary_dir = args.front();
|
||||
if (binary_dir.filename().string().ends_with("iw6-mod.exe"))
|
||||
{
|
||||
std::filesystem::current_path(binary_dir.parent_path());
|
||||
}
|
||||
}
|
||||
|
||||
if (!utils::io::read_file(binary, &data))
|
||||
{
|
||||
throw std::runtime_error(
|
||||
"Failed to read game binary! Please select the correct path in the launcher settings.");
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef INJECT_HOST_AS_LIB
|
||||
|
35
src/common/utils/command_line.cpp
Normal file
35
src/common/utils/command_line.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#include "command_line.hpp"
|
||||
#include "nt.hpp"
|
||||
|
||||
#include <shellapi.h>
|
||||
#include <winrt/Windows.Foundation.h>
|
||||
|
||||
namespace utils::command_line
|
||||
{
|
||||
template <typename type, typename deleter>
|
||||
constexpr std::unique_ptr<type, deleter> make_unique_ptr(type* ptr, deleter&& del)
|
||||
{
|
||||
return std::unique_ptr<type, deleter&&>(ptr, std::forward<deleter>(del));
|
||||
}
|
||||
|
||||
const std::vector<std::filesystem::path>& get_args()
|
||||
{
|
||||
static const auto args = []()
|
||||
{
|
||||
auto argc = 0;
|
||||
const auto cmd_line = winrt::check_pointer(::GetCommandLineW());
|
||||
const auto up = make_unique_ptr(winrt::check_pointer(::CommandLineToArgvW(cmd_line, &argc)), ::LocalFree);
|
||||
const auto argv = up.get();
|
||||
|
||||
std::vector<std::filesystem::path> vec(argc);
|
||||
std::transform(argv, argv + argc, vec.begin(), [](const auto* path)
|
||||
{
|
||||
return std::filesystem::path(path);
|
||||
});
|
||||
|
||||
return vec;
|
||||
}();
|
||||
|
||||
return args;
|
||||
}
|
||||
}
|
9
src/common/utils/command_line.hpp
Normal file
9
src/common/utils/command_line.hpp
Normal file
@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <vector>
|
||||
|
||||
namespace utils::command_line
|
||||
{
|
||||
[[nodiscard]] const std::vector<std::filesystem::path>& get_args();
|
||||
}
|
@ -109,6 +109,86 @@ namespace utils::compression
|
||||
result.resize(length);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::uint8_t> decompress(std::span<const std::uint8_t> input, std::size_t exp_output_size, double growth_rate)
|
||||
{
|
||||
auto decompress_internal = [](std::uint8_t* output, uLong* output_size, const std::uint8_t* input, uLong* input_size)
|
||||
{
|
||||
return uncompress2(
|
||||
reinterpret_cast<Bytef*>(output), output_size,
|
||||
reinterpret_cast<const Bytef*>(input), input_size
|
||||
);
|
||||
};
|
||||
|
||||
auto output_size = static_cast<uLong>(std::max(exp_output_size, std::size_t(256)));
|
||||
std::vector<std::uint8_t> output(output_size);
|
||||
|
||||
auto input_size = static_cast<uLong>(input.size());
|
||||
auto status = decompress_internal(output.data(), &output_size, input.data(), &input_size);
|
||||
|
||||
if (status == Z_BUF_ERROR)
|
||||
{
|
||||
const auto decompression_ratio = (input_size / static_cast<double>(output.size())) - 0.04;
|
||||
output_size = static_cast<uLong>(std::max(input.size() / decompression_ratio, static_cast<double>(output_size)));
|
||||
output.resize(output_size);
|
||||
|
||||
input_size = static_cast<uLong>(input.size());
|
||||
status = decompress_internal(output.data(), &output_size, input.data(), &input_size);
|
||||
}
|
||||
|
||||
for (growth_rate = std::max(growth_rate, 1.0); status == Z_BUF_ERROR;)
|
||||
{
|
||||
output_size = 4 + static_cast<uLong>(growth_rate * output.size());
|
||||
output.resize(output_size);
|
||||
|
||||
input_size = static_cast<uLong>(input.size());
|
||||
status = decompress_internal(output.data(), &output_size, input.data(), &input_size);
|
||||
}
|
||||
|
||||
if (status != Z_OK)
|
||||
{
|
||||
output.clear();
|
||||
return output;
|
||||
}
|
||||
|
||||
output.resize(output_size);
|
||||
return output;
|
||||
}
|
||||
|
||||
std::vector<std::uint8_t> compress(std::span<const std::uint8_t> input, std::size_t exp_output_size, double growth_rate)
|
||||
{
|
||||
auto compress_internal = [](std::uint8_t* output, uLong* output_size, const std::uint8_t* input, uLong input_size)
|
||||
{
|
||||
return compress2(
|
||||
reinterpret_cast<Bytef*>(output), output_size,
|
||||
reinterpret_cast<const Bytef*>(input), input_size,
|
||||
Z_BEST_COMPRESSION
|
||||
);
|
||||
};
|
||||
|
||||
auto output_size = static_cast<uLong>(std::max(exp_output_size, std::size_t(256)));
|
||||
std::vector<std::uint8_t> output(output_size);
|
||||
|
||||
const auto input_size = static_cast<uLong>(input.size());
|
||||
auto status = compress_internal(output.data(), &output_size, input.data(), input_size);
|
||||
|
||||
for (growth_rate = std::max(growth_rate, 1.0); status == Z_BUF_ERROR;)
|
||||
{
|
||||
output_size = 4 + static_cast<uLong>(growth_rate * output.size());
|
||||
output.resize(output_size);
|
||||
|
||||
status = compress_internal(output.data(), &output_size, input.data(), input_size);
|
||||
}
|
||||
|
||||
if (status != Z_OK)
|
||||
{
|
||||
output.clear();
|
||||
return output;
|
||||
}
|
||||
|
||||
output.resize(output_size);
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
namespace zip
|
||||
|
@ -1,7 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#define CHUNK 16384u
|
||||
|
||||
@ -11,6 +13,9 @@ namespace utils::compression
|
||||
{
|
||||
std::string compress(const std::string& data);
|
||||
std::string decompress(const std::string& data);
|
||||
|
||||
std::vector<std::uint8_t> compress(std::span<const std::uint8_t> input, std::size_t exp_output_size, double growth_rate = 2.0);
|
||||
std::vector<std::uint8_t> decompress(std::span<const std::uint8_t> input, std::size_t exp_output_size, double growth_rate = 2.0);
|
||||
}
|
||||
|
||||
namespace zip
|
||||
|
@ -115,13 +115,13 @@ namespace utils::string
|
||||
|
||||
void strip(const char* in, char* out, size_t max)
|
||||
{
|
||||
if (!in || !out) return;
|
||||
if (!in || !out || !max) return;
|
||||
|
||||
max--;
|
||||
auto current = 0u;
|
||||
while (*in != 0 && current < max)
|
||||
{
|
||||
const auto color_index = (*(in + 1) - 48) >= 0xC ? 7 : (*(in + 1) - 48);
|
||||
const auto color_index = (static_cast<size_t>(*(in + 1) - 48)) >= 0xC ? 7 : (*(in + 1) - 48);
|
||||
|
||||
if (*in == '^' && (color_index != 7 || *(in + 1) == '7'))
|
||||
{
|
||||
@ -140,6 +140,32 @@ namespace utils::string
|
||||
*out = '\0';
|
||||
}
|
||||
|
||||
std::string strip(std::string_view sv, bool strip_default_color)
|
||||
{
|
||||
std::string in(sv);
|
||||
|
||||
for (std::size_t i = 0; i + 1 < in.size();)
|
||||
{
|
||||
if (in[i] == '^' && static_cast<std::size_t>(in[i + 1] - '0') < 0xC)
|
||||
{
|
||||
if (in[i + 1] != '7' || strip_default_color)
|
||||
{
|
||||
in.erase(in.begin() + i, in.begin() + i + 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
std::string convert(const std::wstring& wstr)
|
||||
{
|
||||
std::string result;
|
||||
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include "memory.hpp"
|
||||
#include <cstdint>
|
||||
#include <span>
|
||||
|
||||
template <class Type, size_t n>
|
||||
constexpr auto ARRAY_COUNT(Type(&)[n]) { return n; }
|
||||
@ -91,6 +92,7 @@ namespace utils::string
|
||||
std::string get_clipboard_data();
|
||||
|
||||
void strip(const char* in, char* out, size_t max);
|
||||
std::string strip(std::string_view sv, bool strip_default_color = false);
|
||||
|
||||
std::string convert(const std::wstring& wstr);
|
||||
std::wstring convert(const std::string& str);
|
||||
|
Reference in New Issue
Block a user