diff --git a/src/acts/main.cpp b/src/acts/main.cpp index ab50a6d..f169a65 100644 --- a/src/acts/main.cpp +++ b/src/acts/main.cpp @@ -300,10 +300,10 @@ int MainActs(int argc, const char* _argv[], HINSTANCE hInstance, int nShowCmd) { const char* query[]{ argv[1] }; tool::search(query, 1, [&find](const tool::toolfunctiondata* tool) { if (!find) { - LOG_ERROR("Similar tool name(s):"); + LOG_INFO("Similar tool name(s):"); find = true; } - LOG_ERROR("- {}", tool->m_name); + LOG_INFO("- {}", tool->m_name); }); return -1; diff --git a/src/acts/tools/tools.cpp b/src/acts/tools/tools.cpp index c74f281..224acf6 100644 --- a/src/acts/tools/tools.cpp +++ b/src/acts/tools/tools.cpp @@ -1,4 +1,7 @@ #include +#include +#include +#include std::map& tool::tools() { static std::map map{}; @@ -194,7 +197,79 @@ namespace { } return tool::OK; } +#ifndef CI_BUILD + int color(Process& proc, int argc, const char* argv[]) { + for (int b = 0; b < 6; b++) { + for (int i = 0; i < 6; i++) { + for (int j = 0; j < 6; j++) { + std::cout << " " << clicolor::ColorBackground(i, j, b) << i << j << b << clicolor::Reset(); + } + std::cout << " "; + for (int j = 0; j < 6; j++) { + std::cout << " " << clicolor::Color(i, j, b) << i << j << b << clicolor::Reset(); + } + std::cout << "\n"; + } + } + + std::cout << "\n"; + + LOG_TRACE("Trace log"); + LOG_DEBUG("Debug log"); + LOG_INFO("Info log"); + LOG_WARNING("Warning log"); + LOG_ERROR("Error log"); + + return tool::OK; + } + ADD_TOOL("color", "dev", "", "color tool", nullptr, color); +#endif + int info(Process& proc, int argc, const char* argv[]) { + LOG_INFO("Loading acts data..."); + hashutils::ReadDefaultFile(); + tool::gsc::opcode::RegisterOpCodes(); + LOG_INFO("----- acts"); + LOG_INFO("version .. {} (0x{:x})", actsinfo::VERSION, actsinfo::VERSION_ID); + LOG_INFO("tools .... {} ({} categories)", tool::tools().size(), tool::toolsCategories().size()); + LOG_INFO("tools ui . {}", tool::ui::tools().size()); + LOG_INFO("hash(es) . {}", hashutils::GetMap().size()); + LOG_INFO("path ..... {}", utils::GetProgDir().string()); + LOG_INFO("----- games"); + + auto& gameMap = tool::gsc::opcode::GetVMMaps(); + + if (gameMap.empty()) { + LOG_WARNING("No game available"); + } + + for (auto& [vm, info] : gameMap) { + const char* out = utils::va("- %s (%s/%x) ->", info.name, info.codeName, (int)info.vm); + for (size_t i = 0; i < tool::gsc::opcode::PLATFORM_COUNT; i++) { + tool::gsc::opcode::Platform plt = (tool::gsc::opcode::Platform)i; + + if (!info.HasPlatform(plt)) continue; + + size_t count{}; + + auto it = info.opcodemappltlookup.find(plt); + + if (it != info.opcodemappltlookup.end()) { + for (auto& [op, reg] : it->second) { + count += reg.size(); + } + } + out = utils::va("%s %s:0x%llx", out, + utils::MapString(utils::va("%s", tool::gsc::opcode::PlatformName(plt)), [](char c) { return c == ' ' ? '_' : c; }), + count); + } + + LOG_INFO("{}", out); + } + + return tool::OK; + } } ADD_TOOL("list", "acts", "", "list all the tools", nullptr, list); +ADD_TOOL("info", "acts", "", "acts info", nullptr, info); ADD_TOOL("search", "acts", " (args)*", "search a tool", nullptr, search); diff --git a/src/shared/clicolor.cpp b/src/shared/clicolor.cpp new file mode 100644 index 0000000..e8f150f --- /dev/null +++ b/src/shared/clicolor.cpp @@ -0,0 +1,25 @@ +#include "includes_shared.hpp" +#include "clicolor.hpp" +#include "utils.hpp" + +namespace clicolor { + bool ConsoleAllowColor() { + static bool color = [] { + HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); + DWORD mode{}; + return handle && GetConsoleMode(handle, &mode) && (mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING) != 0; + }(); + return color; + } + +} +std::ostream& operator<<(std::ostream& out, clicolor::ColorData data) { + if (data) { + if (data & clicolor::CD_BACKGROUND) { + return out << "\033[48;5;" << std::dec << (int)(data & clicolor::CD_COLOR_MASK) << "m"; + } + return out << "\033[38;5;" << std::dec << (int)(data & clicolor::CD_COLOR_MASK) << "m"; + } + + return out << "\033[0m"; +} \ No newline at end of file diff --git a/src/shared/clicolor.hpp b/src/shared/clicolor.hpp new file mode 100644 index 0000000..99daa4b --- /dev/null +++ b/src/shared/clicolor.hpp @@ -0,0 +1,30 @@ +#pragma once + +namespace clicolor { + + enum ColorData : uint32_t { + CD_RESET = 0, + CD_BACKGROUND = 0x10000000, + CD_COLOR_MASK = ~(CD_BACKGROUND), + }; + + bool ConsoleAllowColor(); + + constexpr ColorData Reset() { + return CD_RESET; + } + + constexpr ColorData Color(int r, int g, int b) { + return (ColorData)(16 + 36 * r + 6 * g + b); + } + + constexpr ColorData ResetBackground() { + return CD_RESET; + } + + constexpr ColorData ColorBackground(int r, int g, int b) { + return (ColorData)(16 + 36 * r + 6 * g + b | CD_BACKGROUND); + } + +} +std::ostream& operator<<(std::ostream& out, clicolor::ColorData data); \ No newline at end of file diff --git a/src/shared/logs.cpp b/src/shared/logs.cpp index 53e4f15..e209c04 100644 --- a/src/shared/logs.cpp +++ b/src/shared/logs.cpp @@ -1,5 +1,6 @@ #include #include "logs.hpp" +#include "clicolor.hpp" const char* alogs::name(loglevel lvl) { switch (lvl) @@ -61,28 +62,51 @@ void alogs::log(loglevel level, const std::string& str) { return; } - auto f = [&](std::ostream& out) { + auto f = [&](std::ostream& out, bool color) { if (!g_basiclog) { + if (color) { + out << clicolor::Color(5, 5, 5); + } std::tm tm = localtime_xp(std::time(nullptr)); out << "[" << std::put_time(&tm, "%H:%M:%S") << "]" + ; + } + if (color) { + switch (level) { + case alogs::LVL_ERROR: out << clicolor::Color(5, 1, 1); break; + case alogs::LVL_WARNING: out << clicolor::Color(5, 4, 1); break; + case alogs::LVL_INFO: out << clicolor::Color(5, 5, 5); break; + case alogs::LVL_DEBUG: out << clicolor::Color(4, 5, 1); break; + case alogs::LVL_TRACE: out << clicolor::Color(1, 5, 5); break; + default: out << clicolor::Reset(); break; + } + } + + if (!g_basiclog) { + out << '[' << name(level) << "] " ; } - out - << str - << "\n"; - }; + out << str; + + if (color) { + out << clicolor::Reset(); + } + out << "\n"; + }; auto* lf = logfile(); if (lf) { std::ofstream out{ lf, std::ios::app }; - f(out); + f(out, false); out.close(); } else { - f(level < LVL_WARNING ? std::cout : std::cerr); + static bool allowColor = clicolor::ConsoleAllowColor(); + + f(level < LVL_WARNING ? std::cout : std::cerr, allowColor); } }