init
This commit is contained in:
52
TempleWare-CS2/source/templeware/config/config.cpp
Normal file
52
TempleWare-CS2/source/templeware/config/config.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "config.h"
|
||||
|
||||
// CBA to make proper atm, it's 03:42 right now.
|
||||
// For now just stores config values don't mind it too much
|
||||
//
|
||||
// (FYI THIS IS A HORRID SOLUTION BUT FUNCTIONS)
|
||||
|
||||
namespace Config {
|
||||
bool esp = false;
|
||||
bool glow = false;
|
||||
bool showHealth = false;
|
||||
bool teamCheck = false;
|
||||
bool espFill = false;
|
||||
bool showNameTags = false;
|
||||
|
||||
bool Night = false;
|
||||
|
||||
bool enemyChamsInvisible = false;
|
||||
bool enemyChams = false;
|
||||
bool teamChams = false;
|
||||
bool teamChamsInvisible = false;
|
||||
int chamsMaterial = 0;
|
||||
|
||||
|
||||
bool armChams = false;
|
||||
bool viewmodelChams = false;
|
||||
ImVec4 colViewmodelChams = ImVec4(1, 0, 0, 1);
|
||||
ImVec4 colArmChams = ImVec4(1, 0, 0, 1);
|
||||
|
||||
ImVec4 colVisualChams = ImVec4(1, 0, 0, 1);
|
||||
ImVec4 colVisualChamsIgnoreZ = ImVec4(1, 0, 0, 1);
|
||||
ImVec4 teamcolVisualChamsIgnoreZ = ImVec4(1, 0, 0, 1);
|
||||
ImVec4 teamcolVisualChams = ImVec4(1, 0, 0, 1);
|
||||
|
||||
float espThickness = 1.0f;
|
||||
float espFillOpacity = 0.5f;
|
||||
ImVec4 espColor = ImVec4(1, 0, 0, 1);
|
||||
|
||||
bool fovEnabled = false;
|
||||
float fov = 90.0f;
|
||||
|
||||
bool antiflash = false;
|
||||
|
||||
ImVec4 NightColor = ImVec4(0.1, 0.1, 0.1, 1);
|
||||
|
||||
bool aimbot = true;
|
||||
float aimbot_fov = 90;
|
||||
bool team_check = false;
|
||||
bool rcs = 0;
|
||||
bool fov_circle = 0;
|
||||
ImVec4 fovCircleColor = ImVec4(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
}
|
||||
51
TempleWare-CS2/source/templeware/config/config.h
Normal file
51
TempleWare-CS2/source/templeware/config/config.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
#include "../../../external/imgui/imgui.h"
|
||||
|
||||
// CBA to make proper atm, it's 03:42 right now.
|
||||
// For now just stores config values don't mind it too much
|
||||
//
|
||||
// (FYI THIS IS A HORRID SOLUTION BUT FUNCTIONS)
|
||||
|
||||
namespace Config {
|
||||
extern bool esp;
|
||||
extern bool showHealth;
|
||||
extern bool teamCheck;
|
||||
extern bool espFill;
|
||||
extern float espThickness;
|
||||
extern float espFillOpacity;
|
||||
extern ImVec4 espColor;
|
||||
extern bool showNameTags;
|
||||
|
||||
extern bool Night;
|
||||
extern ImVec4 NightColor;
|
||||
|
||||
extern bool enemyChamsInvisible;
|
||||
extern bool enemyChams;
|
||||
extern bool teamChams;
|
||||
extern bool teamChamsInvisible;
|
||||
extern int chamsMaterial;
|
||||
|
||||
extern ImVec4 colVisualChams;
|
||||
extern ImVec4 colVisualChamsIgnoreZ;
|
||||
extern ImVec4 teamcolVisualChamsIgnoreZ;
|
||||
extern ImVec4 teamcolVisualChams;
|
||||
|
||||
extern bool armChams;
|
||||
extern bool viewmodelChams;
|
||||
extern ImVec4 colViewmodelChams;
|
||||
extern ImVec4 colArmChams;
|
||||
|
||||
extern bool fovEnabled;
|
||||
extern float fov;
|
||||
|
||||
extern bool antiflash;
|
||||
|
||||
extern bool Night;
|
||||
|
||||
extern bool aimbot;
|
||||
extern float aimbot_fov;
|
||||
extern bool team_check;
|
||||
extern bool rcs;
|
||||
extern bool fov_circle;
|
||||
extern ImVec4 fovCircleColor;
|
||||
}
|
||||
301
TempleWare-CS2/source/templeware/config/configmanager.h
Normal file
301
TempleWare-CS2/source/templeware/config/configmanager.h
Normal file
@@ -0,0 +1,301 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "config.h"
|
||||
#include "../../../external/json/json.hpp"
|
||||
|
||||
namespace internal_config
|
||||
{
|
||||
class ConfigManager
|
||||
{
|
||||
private:
|
||||
|
||||
static std::filesystem::path GetConfigFolder()
|
||||
{
|
||||
char* userProfile = nullptr;
|
||||
size_t len = 0;
|
||||
errno_t err = _dupenv_s(&userProfile, &len, "USERPROFILE");
|
||||
|
||||
std::filesystem::path folder;
|
||||
if (err != 0 || userProfile == nullptr || len == 0)
|
||||
{
|
||||
folder = ".templeware";
|
||||
}
|
||||
else
|
||||
{
|
||||
folder = userProfile;
|
||||
free(userProfile);
|
||||
folder /= ".templeware";
|
||||
}
|
||||
folder /= "internal";
|
||||
|
||||
std::error_code ec;
|
||||
std::filesystem::create_directories(folder, ec);
|
||||
|
||||
return folder;
|
||||
}
|
||||
|
||||
static std::filesystem::path GetConfigPath(const std::string& configName)
|
||||
{
|
||||
auto folder = GetConfigFolder();
|
||||
return folder / (configName + ".json");
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
static std::vector<std::string> ListConfigs()
|
||||
{
|
||||
std::vector<std::string> list;
|
||||
auto folder = GetConfigFolder();
|
||||
if (!std::filesystem::exists(folder))
|
||||
return list;
|
||||
|
||||
for (const auto& entry : std::filesystem::directory_iterator(folder))
|
||||
{
|
||||
if (entry.is_regular_file())
|
||||
{
|
||||
auto path = entry.path();
|
||||
if (path.extension() == ".json")
|
||||
{
|
||||
list.push_back(path.stem().string());
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
static void Save(const std::string& configName)
|
||||
{
|
||||
nlohmann::json j;
|
||||
j["esp"] = Config::esp;
|
||||
j["showHealth"] = Config::showHealth;
|
||||
j["teamCheck"] = Config::teamCheck;
|
||||
j["espFill"] = Config::espFill;
|
||||
j["espThickness"] = Config::espThickness;
|
||||
j["espFillOpacity"] = Config::espFillOpacity;
|
||||
|
||||
j["fovEnabled"] = Config::fovEnabled;
|
||||
j["fov"] = Config::fov;
|
||||
|
||||
j["espColor"] = {
|
||||
Config::espColor.x,
|
||||
Config::espColor.y,
|
||||
Config::espColor.z,
|
||||
Config::espColor.w
|
||||
};
|
||||
|
||||
j["Night"] = Config::Night;
|
||||
j["NightColor"] = {
|
||||
Config::NightColor.x,
|
||||
Config::NightColor.y,
|
||||
Config::NightColor.z,
|
||||
Config::NightColor.w
|
||||
};
|
||||
|
||||
j["armChams"] = Config::armChams;
|
||||
j["viewmodelChams"] = Config::viewmodelChams;
|
||||
|
||||
j["armChams_color"] = {
|
||||
Config::colArmChams.x,
|
||||
Config::colArmChams.y,
|
||||
Config::colArmChams.z,
|
||||
Config::colArmChams.w
|
||||
};
|
||||
|
||||
j["viewmodelChams_color"] = {
|
||||
Config::colViewmodelChams.x,
|
||||
Config::colViewmodelChams.y,
|
||||
Config::colViewmodelChams.z,
|
||||
Config::colViewmodelChams.w
|
||||
};
|
||||
|
||||
j["aimbot"] = Config::aimbot;
|
||||
j["aimbot_fov"] = Config::aimbot_fov;
|
||||
j["antiflash"] = Config::antiflash;
|
||||
j["rcs"] = Config::rcs;
|
||||
j["fov_circle"] = Config::fov_circle;
|
||||
|
||||
j["enemyChamsInvisible"] = Config::enemyChamsInvisible;
|
||||
j["enemyChams"] = Config::enemyChams;
|
||||
j["teamChams"] = Config::teamChams;
|
||||
j["teamChamsInvisible"] = Config::teamChamsInvisible;
|
||||
j["chamsMaterial"] = Config::chamsMaterial;
|
||||
j["colVisualChams"] = {
|
||||
Config::colVisualChams.x,
|
||||
Config::colVisualChams.y,
|
||||
Config::colVisualChams.z,
|
||||
Config::colVisualChams.w
|
||||
};
|
||||
j["colVisualChamsIgnoreZ"] = {
|
||||
Config::colVisualChamsIgnoreZ.x,
|
||||
Config::colVisualChamsIgnoreZ.y,
|
||||
Config::colVisualChamsIgnoreZ.z,
|
||||
Config::colVisualChamsIgnoreZ.w
|
||||
};
|
||||
j["teamcolVisualChamsIgnoreZ"] = {
|
||||
Config::teamcolVisualChamsIgnoreZ.x,
|
||||
Config::teamcolVisualChamsIgnoreZ.y,
|
||||
Config::teamcolVisualChamsIgnoreZ.z,
|
||||
Config::teamcolVisualChamsIgnoreZ.w
|
||||
};
|
||||
j["teamcolVisualChams"] = {
|
||||
Config::teamcolVisualChams.x,
|
||||
Config::teamcolVisualChams.y,
|
||||
Config::teamcolVisualChams.z,
|
||||
Config::teamcolVisualChams.w
|
||||
};
|
||||
j["fovCircleColor"] = {
|
||||
Config::fovCircleColor.x,
|
||||
Config::fovCircleColor.y,
|
||||
Config::fovCircleColor.z,
|
||||
Config::fovCircleColor.w
|
||||
};
|
||||
|
||||
auto filePath = GetConfigPath(configName);
|
||||
std::ofstream ofs(filePath);
|
||||
if (ofs.is_open())
|
||||
{
|
||||
ofs << j.dump(4);
|
||||
ofs.close();
|
||||
}
|
||||
}
|
||||
|
||||
static void Load(const std::string& configName)
|
||||
{
|
||||
auto filePath = GetConfigPath(configName);
|
||||
if (!std::filesystem::exists(filePath))
|
||||
return;
|
||||
|
||||
std::ifstream ifs(filePath);
|
||||
if (!ifs.is_open())
|
||||
return;
|
||||
|
||||
nlohmann::json j;
|
||||
ifs >> j;
|
||||
|
||||
Config::esp = j.value("esp", false);
|
||||
Config::showHealth = j.value("showHealth", false);
|
||||
Config::teamCheck = j.value("teamCheck", false);
|
||||
Config::espFill = j.value("espFill", false);
|
||||
Config::espThickness = j.value("espThickness", 1.0f);
|
||||
Config::espFillOpacity = j.value("espFillOpacity", 0.5f);
|
||||
|
||||
Config::fovEnabled = j.value("fovEnabled", false);
|
||||
Config::fov = j.value("fov", 90.0f);
|
||||
|
||||
if (j.contains("espColor") && j["espColor"].is_array() && j["espColor"].size() == 4)
|
||||
{
|
||||
auto arr = j["espColor"];
|
||||
Config::espColor.x = arr[0].get<float>();
|
||||
Config::espColor.y = arr[1].get<float>();
|
||||
Config::espColor.z = arr[2].get<float>();
|
||||
Config::espColor.w = arr[3].get<float>();
|
||||
}
|
||||
|
||||
Config::Night = j.value("Night", false);
|
||||
if (j.contains("NightColor") && j["NightColor"].is_array() && j["NightColor"].size() == 4)
|
||||
{
|
||||
auto arr = j["NightColor"];
|
||||
Config::NightColor.x = arr[0].get<float>();
|
||||
Config::NightColor.y = arr[1].get<float>();
|
||||
Config::NightColor.z = arr[2].get<float>();
|
||||
Config::NightColor.w = arr[3].get<float>();
|
||||
}
|
||||
|
||||
Config::enemyChamsInvisible = j.value("enemyChamsInvisible", false);
|
||||
Config::enemyChams = j.value("enemyChams", false);
|
||||
Config::teamChams = j.value("teamChams", false);
|
||||
Config::teamChamsInvisible = j.value("teamChamsInvisible", false);
|
||||
Config::chamsMaterial = j.value("chamsMaterial", 0);
|
||||
|
||||
Config::fov_circle = j.value("fov_circle", false);
|
||||
Config::aimbot = j.value("aimbot", false);
|
||||
Config::rcs = j.value("rcs", false);
|
||||
Config::aimbot_fov = j.value("aimbot_fov", 0.f);
|
||||
|
||||
Config::antiflash = j.value("antiflash", false);
|
||||
|
||||
Config::armChams = j.value("armChams", false);
|
||||
Config::viewmodelChams = j.value("viewmodelChams", false);
|
||||
|
||||
if (j.contains("colArmChams") && j["colArmChams"].is_array() && j["colArmChams"].size() == 4)
|
||||
{
|
||||
auto arr = j["colArmChams"];
|
||||
Config::colArmChams.x = arr[0].get<float>();
|
||||
Config::colArmChams.y = arr[1].get<float>();
|
||||
Config::colArmChams.z = arr[2].get<float>();
|
||||
Config::colArmChams.w = arr[3].get<float>();
|
||||
}
|
||||
|
||||
if (j.contains("colViewmodelChams") && j["colViewmodelChams"].is_array() && j["colViewmodelChams"].size() == 4)
|
||||
{
|
||||
auto arr = j["colViewmodelChams"];
|
||||
Config::colViewmodelChams.x = arr[0].get<float>();
|
||||
Config::colViewmodelChams.y = arr[1].get<float>();
|
||||
Config::colViewmodelChams.z = arr[2].get<float>();
|
||||
Config::colViewmodelChams.w = arr[3].get<float>();
|
||||
}
|
||||
|
||||
if (j.contains("colVisualChams") && j["colVisualChams"].is_array() && j["colVisualChams"].size() == 4)
|
||||
{
|
||||
auto arr = j["colVisualChams"];
|
||||
Config::colVisualChams.x = arr[0].get<float>();
|
||||
Config::colVisualChams.y = arr[1].get<float>();
|
||||
Config::colVisualChams.z = arr[2].get<float>();
|
||||
Config::colVisualChams.w = arr[3].get<float>();
|
||||
}
|
||||
|
||||
if (j.contains("colVisualChamsIgnoreZ") && j["colVisualChamsIgnoreZ"].is_array() && j["colVisualChamsIgnoreZ"].size() == 4)
|
||||
{
|
||||
auto arr = j["colVisualChamsIgnoreZ"];
|
||||
Config::colVisualChamsIgnoreZ.x = arr[0].get<float>();
|
||||
Config::colVisualChamsIgnoreZ.y = arr[1].get<float>();
|
||||
Config::colVisualChamsIgnoreZ.z = arr[2].get<float>();
|
||||
Config::colVisualChamsIgnoreZ.w = arr[3].get<float>();
|
||||
}
|
||||
|
||||
if (j.contains("teamcolVisualChamsIgnoreZ") && j["teamcolVisualChamsIgnoreZ"].is_array() && j["teamcolVisualChamsIgnoreZ"].size() == 4)
|
||||
{
|
||||
auto arr = j["teamcolVisualChamsIgnoreZ"];
|
||||
Config::teamcolVisualChamsIgnoreZ.x = arr[0].get<float>();
|
||||
Config::teamcolVisualChamsIgnoreZ.y = arr[1].get<float>();
|
||||
Config::teamcolVisualChamsIgnoreZ.z = arr[2].get<float>();
|
||||
Config::teamcolVisualChamsIgnoreZ.w = arr[3].get<float>();
|
||||
}
|
||||
|
||||
if (j.contains("teamcolVisualChams") && j["teamcolVisualChams"].is_array() && j["teamcolVisualChams"].size() == 4)
|
||||
{
|
||||
auto arr = j["teamcolVisualChams"];
|
||||
Config::teamcolVisualChams.x = arr[0].get<float>();
|
||||
Config::teamcolVisualChams.y = arr[1].get<float>();
|
||||
Config::teamcolVisualChams.z = arr[2].get<float>();
|
||||
Config::teamcolVisualChams.w = arr[3].get<float>();
|
||||
}
|
||||
|
||||
if (j.contains("fovCircleColor") && j["fovCircleColor"].is_array() && j["fovCircleColor"].size() == 4) {
|
||||
auto arr = j["fovCircleColor"];
|
||||
Config::fovCircleColor.x = arr[0].get<float>();
|
||||
Config::fovCircleColor.y = arr[1].get<float>();
|
||||
Config::fovCircleColor.z = arr[2].get<float>();
|
||||
Config::fovCircleColor.w = arr[3].get<float>();
|
||||
}
|
||||
|
||||
ifs.close();
|
||||
}
|
||||
|
||||
static void Remove(const std::string& configName)
|
||||
{
|
||||
auto filePath = GetConfigPath(configName);
|
||||
if (std::filesystem::exists(filePath))
|
||||
{
|
||||
std::error_code ec;
|
||||
std::filesystem::remove(filePath, ec);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
125
TempleWare-CS2/source/templeware/features/aim/aim.cpp
Normal file
125
TempleWare-CS2/source/templeware/features/aim/aim.cpp
Normal file
@@ -0,0 +1,125 @@
|
||||
#include "../../../cs2/entity/C_CSPlayerPawn/C_CSPlayerPawn.h"
|
||||
#include "../../../templeware/interfaces/CGameEntitySystem/CGameEntitySystem.h"
|
||||
#include "../../../templeware/interfaces/interfaces.h"
|
||||
#include "../../../templeware/hooks/hooks.h"
|
||||
#include "../../../templeware/config/config.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <Windows.h>
|
||||
#include "../../menu/hud.h"
|
||||
|
||||
// Literally the most autistic code ive ever written in my life
|
||||
// Please dont ever make me do this again
|
||||
|
||||
Vector_t GetEntityEyePos(const C_CSPlayerPawn* Entity) {
|
||||
if (!Entity)
|
||||
return {};
|
||||
|
||||
uintptr_t game_scene_node = *reinterpret_cast<uintptr_t*>((uintptr_t)Entity + SchemaFinder::Get(hash_32_fnv1a_const("C_BaseEntity->m_pGameSceneNode")));
|
||||
|
||||
auto Origin = *reinterpret_cast<Vector_t*>(game_scene_node + SchemaFinder::Get(hash_32_fnv1a_const("CGameSceneNode->m_vecAbsOrigin")));
|
||||
auto ViewOffset = *reinterpret_cast<Vector_t*>((uintptr_t)Entity + SchemaFinder::Get(hash_32_fnv1a_const("C_BaseModelEntity->m_vecViewOffset")));
|
||||
|
||||
Vector_t Result = Origin + ViewOffset;
|
||||
if (!std::isfinite(Result.x) || !std::isfinite(Result.y) || !std::isfinite(Result.z))
|
||||
return {};
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
inline QAngle_t CalcAngles(Vector_t viewPos, Vector_t aimPos)
|
||||
{
|
||||
QAngle_t angle = { 0, 0, 0 };
|
||||
|
||||
Vector_t delta = aimPos - viewPos;
|
||||
|
||||
angle.x = -asin(delta.z / delta.Length()) * (180.0f / 3.141592654f);
|
||||
angle.y = atan2(delta.y, delta.x) * (180.0f / 3.141592654f);
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
inline float GetFov(const QAngle_t& viewAngle, const QAngle_t& aimAngle)
|
||||
{
|
||||
QAngle_t delta = (aimAngle - viewAngle).Normalize();
|
||||
|
||||
return sqrtf(powf(delta.x, 2.0f) + powf(delta.y, 2.0f));
|
||||
}
|
||||
|
||||
void Aimbot() {
|
||||
static C_CSPlayerPawn* lockedTarget = nullptr;
|
||||
static bool prevAimbotState = false;
|
||||
|
||||
bool aimbotActive = Config::aimbot;
|
||||
|
||||
// Получаем локального игрока и viewangles всегда, чтобы не дублировать код
|
||||
C_CSPlayerPawn* lp = H::oGetLocalPlayer(0);
|
||||
Vector_t lep = GetEntityEyePos(lp);
|
||||
QAngle_t* viewangles = (QAngle_t*)(modules.getModule("client") + 0x1A78650);
|
||||
|
||||
// Если кнопка только что нажата (переход с false на true) — ищем новую цель
|
||||
if (aimbotActive && !prevAimbotState) {
|
||||
int nMaxHighestEntity = I::GameEntity->Instance->GetHighestEntityIndex();
|
||||
float bestFov = Config::aimbot_fov;
|
||||
C_CSPlayerPawn* bestTarget = nullptr;
|
||||
QAngle_t bestAngle = {0, 0, 0};
|
||||
|
||||
for (int i = 1; i <= nMaxHighestEntity; i++) {
|
||||
auto Entity = I::GameEntity->Instance->Get(i);
|
||||
if (!Entity)
|
||||
continue;
|
||||
if (!Entity->handle().valid())
|
||||
continue;
|
||||
SchemaClassInfoData_t* _class = nullptr;
|
||||
Entity->dump_class_info(&_class);
|
||||
if (!_class)
|
||||
continue;
|
||||
const uint32_t hash = HASH(_class->szName);
|
||||
if (hash == HASH("C_CSPlayerPawn")) {
|
||||
C_CSPlayerPawn* pawn = (C_CSPlayerPawn*)Entity;
|
||||
if (pawn->get_entity_by_handle() == lp->get_entity_by_handle())
|
||||
continue;
|
||||
if (pawn->getHealth() <= 0)
|
||||
continue;
|
||||
/* if (!Config::team_check && pawn->getTeam() == lp->getTeam())
|
||||
continue;*/
|
||||
Vector_t eye_pos = GetEntityEyePos(pawn);
|
||||
QAngle_t angle = CalcAngles(eye_pos, lep);
|
||||
angle.x *= -1.f;
|
||||
angle.y += 180.f;
|
||||
const float fov = GetFov(*viewangles, angle);
|
||||
if (!std::isfinite(fov) || fov > bestFov)
|
||||
continue;
|
||||
bestFov = fov;
|
||||
bestTarget = pawn;
|
||||
bestAngle = angle;
|
||||
}
|
||||
}
|
||||
lockedTarget = bestTarget;
|
||||
}
|
||||
|
||||
// Если кнопка отпущена — сбрасываем захват
|
||||
if (!aimbotActive)
|
||||
lockedTarget = nullptr;
|
||||
|
||||
// Если есть захваченная цель и кнопка удерживается
|
||||
if (aimbotActive && lockedTarget) {
|
||||
// Проверяем, что цель всё ещё валидна
|
||||
if (!lockedTarget->handle().valid() || lockedTarget->getHealth() <= 0) {
|
||||
lockedTarget = nullptr;
|
||||
} else {
|
||||
Vector_t eye_pos = GetEntityEyePos(lockedTarget);
|
||||
QAngle_t angle = CalcAngles(eye_pos, lep);
|
||||
angle.x *= -1.f;
|
||||
angle.y += 180.f;
|
||||
QAngle_t ang_punch_angle = *(QAngle_t*)((uintptr_t)lp + SchemaFinder::Get(hash_32_fnv1a_const("C_CSPlayerPawn->m_aimPunchAngle")));
|
||||
if (Config::rcs)
|
||||
angle -= ang_punch_angle * 2.f;
|
||||
angle.z = 0.f;
|
||||
angle = angle.Normalize();
|
||||
*viewangles = angle;
|
||||
}
|
||||
}
|
||||
|
||||
prevAimbotState = aimbotActive;
|
||||
}
|
||||
3
TempleWare-CS2/source/templeware/features/aim/aim.h
Normal file
3
TempleWare-CS2/source/templeware/features/aim/aim.h
Normal file
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
void Aimbot();
|
||||
281
TempleWare-CS2/source/templeware/features/chams/chams.cpp
Normal file
281
TempleWare-CS2/source/templeware/features/chams/chams.cpp
Normal file
@@ -0,0 +1,281 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include "chams.h"
|
||||
#include "../../hooks/hooks.h"
|
||||
#include "../../config/config.h"
|
||||
#include "../../../../external/imgui/imgui.h"
|
||||
#include "../../utils/math/utlstronghandle/utlstronghandle.h"
|
||||
#include "../../../cs2/entity/C_Material/C_Material.h"
|
||||
#include "../../interfaces/interfaces.h"
|
||||
#include "../../interfaces/CGameEntitySystem/CGameEntitySystem.h"
|
||||
#include "../../../cs2/datatypes/keyvalues/keyvalues.h"
|
||||
#include "../../../cs2/datatypes/cutlbuffer/cutlbuffer.h"
|
||||
|
||||
CStrongHandle<CMaterial2> chams::create(const char* name, const char szVmatBuffer[])
|
||||
{
|
||||
CKeyValues3* pKeyValues3 = nullptr;
|
||||
|
||||
pKeyValues3 = pKeyValues3->create_material_from_resource();
|
||||
|
||||
pKeyValues3->LoadFromBuffer(szVmatBuffer);
|
||||
|
||||
CStrongHandle<CMaterial2> pCustomMaterial = {};
|
||||
|
||||
I::CreateMaterial(nullptr, &pCustomMaterial, name, pKeyValues3, 0, 1);
|
||||
|
||||
return pCustomMaterial;
|
||||
}
|
||||
|
||||
struct resource_material_t
|
||||
{
|
||||
CStrongHandle<CMaterial2> mat;
|
||||
CStrongHandle<CMaterial2> mat_invs;
|
||||
};
|
||||
|
||||
static resource_material_t resourceMaterials[ChamsType::MAXCOUNT];
|
||||
bool loaded_materials = false;
|
||||
bool chams::Materials::init()
|
||||
{
|
||||
// flat
|
||||
resourceMaterials[FLAT] = resource_material_t{
|
||||
.mat = create("materials/dev/flat.vmat", R"(<!-- kv3 encoding:text:version{e21c7f3c-8a33-41c5-9977-a76d3a32aa0d} format:generic:version{7412167c-06e9-4698-aff2-e63eb59037e7} -->
|
||||
{
|
||||
Shader = "csgo_unlitgeneric.vfx"
|
||||
|
||||
F_IGNOREZ = 0
|
||||
F_DISABLE_Z_WRITE = 0
|
||||
F_DISABLE_Z_BUFFERING = 0
|
||||
F_BLEND_MODE = 1
|
||||
F_TRANSLUCENT = 1
|
||||
F_RENDER_BACKFACES = 0
|
||||
|
||||
g_vColorTint = [1.000000, 1.000000, 1.000000, 1.000000]
|
||||
g_vGlossinessRange = [0.000000, 1.000000, 0.000000, 0.000000]
|
||||
g_vNormalTexCoordScale = [1.000000, 1.000000, 0.000000, 0.000000]
|
||||
g_vTexCoordOffset = [0.000000, 0.000000, 0.000000, 0.000000]
|
||||
g_vTexCoordScale = [1.000000, 1.000000, 0.000000, 0.000000]
|
||||
g_tColor = resource:"materials/dev/primary_white_color_tga_f7b257f6.vtex"
|
||||
g_tNormal = resource:"materials/default/default_normal_tga_7652cb.vtex"
|
||||
})"),
|
||||
.mat_invs = create("materials/dev/flat_i.vmat", R"(<!-- kv3 encoding:text:version{e21c7f3c-8a33-41c5-9977-a76d3a32aa0d} format:generic:version{7412167c-06e9-4698-aff2-e63eb59037e7} -->
|
||||
{
|
||||
Shader = "csgo_unlitgeneric.vfx"
|
||||
F_IGNOREZ = 1
|
||||
F_DISABLE_Z_WRITE = 1
|
||||
F_DISABLE_Z_BUFFERING = 1
|
||||
F_BLEND_MODE = 1
|
||||
F_TRANSLUCENT = 1
|
||||
g_vColorTint = [1.000000, 1.000000, 1.000000, 0.000000]
|
||||
g_vGlossinessRange = [0.000000, 1.000000, 0.000000, 0.000000]
|
||||
g_vNormalTexCoordScale = [1.000000, 1.000000, 0.000000, 0.000000]
|
||||
g_vTexCoordOffset = [0.000000, 0.000000, 0.000000, 0.000000]
|
||||
g_vTexCoordScale = [1.000000, 1.000000, 0.000000, 0.000000]
|
||||
g_tColor = resource:"materials/dev/primary_white_color_tga_f7b257f6.vtex"
|
||||
g_tNormal = resource:"materials/default/default_normal_tga_7652cb.vtex"
|
||||
})")
|
||||
};
|
||||
resourceMaterials[ILLUMINATE] = resource_material_t{
|
||||
.mat = create("materials/dev/primary_white.vmat", R"(<!-- kv3 encoding:text:version{e21c7f3c-8a33-41c5-9977-a76d3a32aa0d} format:generic:version{7412167c-06e9-4698-aff2-e63eb59037e7} -->
|
||||
{
|
||||
shader = "csgo_complex.vfx"
|
||||
|
||||
F_SELF_ILLUM = 1
|
||||
F_PAINT_VERTEX_COLORS = 1
|
||||
F_TRANSLUCENT = 1
|
||||
|
||||
g_vColorTint = [ 1.000000, 1.000000, 1.000000, 1.000000 ]
|
||||
g_flSelfIllumScale = [ 3.000000, 3.000000, 3.000000, 3.000000 ]
|
||||
g_flSelfIllumBrightness = [ 3.000000, 3.000000, 3.000000, 3.000000 ]
|
||||
g_vSelfIllumTint = [ 10.000000, 10.000000, 10.000000, 10.000000 ]
|
||||
|
||||
g_tColor = resource:"materials/default/default_mask_tga_fde710a5.vtex"
|
||||
g_tNormal = resource:"materials/default/default_mask_tga_fde710a5.vtex"
|
||||
g_tSelfIllumMask = resource:"materials/default/default_mask_tga_fde710a5.vtex"
|
||||
TextureAmbientOcclusion = resource:"materials/debug/particleerror.vtex"
|
||||
g_tAmbientOcclusion = resource:"materials/debug/particleerror.vtex"
|
||||
})"),
|
||||
.mat_invs = create("materials/dev/primary_white.vmat", R"(<!-- kv3 encoding:text:version{e21c7f3c-8a33-41c5-9977-a76d3a32aa0d} format:generic:version{7412167c-06e9-4698-aff2-e63eb59037e7} -->
|
||||
{
|
||||
shader = "csgo_complex.vfx"
|
||||
|
||||
F_SELF_ILLUM = 1
|
||||
F_PAINT_VERTEX_COLORS = 1
|
||||
F_TRANSLUCENT = 1
|
||||
F_DISABLE_Z_BUFFERING = 1
|
||||
|
||||
g_vColorTint = [ 1.000000, 1.000000, 1.000000, 1.000000 ]
|
||||
g_flSelfIllumScale = [ 3.000000, 3.000000, 3.000000, 3.000000 ]
|
||||
g_flSelfIllumBrightness = [ 3.000000, 3.000000, 3.000000, 3.000000 ]
|
||||
g_vSelfIllumTint = [ 10.000000, 10.000000, 10.000000, 10.000000 ]
|
||||
|
||||
g_tColor = resource:"materials/default/default_mask_tga_fde710a5.vtex"
|
||||
g_tNormal = resource:"materials/default/default_mask_tga_fde710a5.vtex"
|
||||
g_tSelfIllumMask = resource:"materials/default/default_mask_tga_fde710a5.vtex"
|
||||
TextureAmbientOcclusion = resource:"materials/debug/particleerror.vtex"
|
||||
g_tAmbientOcclusion = resource:"materials/debug/particleerror.vtex"
|
||||
})")
|
||||
};
|
||||
|
||||
resourceMaterials[GLOW] = resource_material_t{
|
||||
.mat = create("materials/dev/primary_white.vmat", R"(<!-- kv3 encoding:text:version{e21c7f3c-8a33-41c5-9977-a76d3a32aa0d} format:generic:version{7412167c-06e9-4698-aff2-e63eb59037e7} -->
|
||||
{
|
||||
shader = "csgo_effects.vfx"
|
||||
g_flFresnelExponent = 7.0
|
||||
g_flFresnelFalloff = 10.0
|
||||
g_flFresnelMax = 0.1
|
||||
g_flFresnelMin = 1.0
|
||||
g_tColor = resource:"materials/dev/primary_white_color_tga_21186c76.vtex"
|
||||
g_tMask1 = resource:"materials/default/default_mask_tga_fde710a5.vtex"
|
||||
g_tMask2 = resource:"materials/default/default_mask_tga_fde710a5.vtex"
|
||||
g_tMask3 = resource:"materials/default/default_mask_tga_fde710a5.vtex"
|
||||
g_tSceneDepth = resource:"materials/default/default_mask_tga_fde710a5.vtex"
|
||||
g_flToolsVisCubemapReflectionRoughness = 1.0
|
||||
g_flBeginMixingRoughness = 1.0
|
||||
g_vColorTint = [ 1.000000, 1.000000, 1.000000, 0 ]
|
||||
F_IGNOREZ = 0
|
||||
F_TRANSLUCENT = 1
|
||||
|
||||
F_DISABLE_Z_WRITE = 0
|
||||
F_DISABLE_Z_BUFFERING = 1
|
||||
F_RENDER_BACKFACES = 0
|
||||
})"),
|
||||
|
||||
.mat_invs = create("materials/dev/primary_white.vmat", R"(<!-- kv3 encoding:text:version{e21c7f3c-8a33-41c5-9977-a76d3a32aa0d} format:generic:version{7412167c-06e9-4698-aff2-e63eb59037e7} -->
|
||||
{
|
||||
shader = "csgo_effects.vfx"
|
||||
g_flFresnelExponent = 7.0
|
||||
g_flFresnelFalloff = 10.0
|
||||
g_flFresnelMax = 0.1
|
||||
g_flFresnelMin = 1.0
|
||||
g_tColor = resource:"materials/dev/primary_white_color_tga_21186c76.vtex"
|
||||
g_tMask1 = resource:"materials/default/default_mask_tga_fde710a5.vtex"
|
||||
g_tMask2 = resource:"materials/default/default_mask_tga_fde710a5.vtex"
|
||||
g_tMask3 = resource:"materials/default/default_mask_tga_fde710a5.vtex"
|
||||
g_tSceneDepth = resource:"materials/default/default_mask_tga_fde710a5.vtex"
|
||||
g_flToolsVisCubemapReflectionRoughness = 1.0
|
||||
g_flBeginMixingRoughness = 1.0
|
||||
g_vColorTint = [ 1.000000, 1.000000, 1.000000, 0 ]
|
||||
F_IGNOREZ = 1
|
||||
F_TRANSLUCENT = 1
|
||||
|
||||
F_DISABLE_Z_WRITE = 1
|
||||
F_DISABLE_Z_BUFFERING = 1
|
||||
F_RENDER_BACKFACES = 0
|
||||
})")
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
ChamsEntity chams::GetTargetType(C_BaseEntity* render_ent) noexcept {
|
||||
auto local = H::oGetLocalPlayer(0);
|
||||
if (!local)
|
||||
return ChamsEntity::INVALID;
|
||||
|
||||
if (render_ent->IsViewmodelAttachment())
|
||||
return ChamsEntity::HANDS;
|
||||
|
||||
if (render_ent->IsViewmodel())
|
||||
return ChamsEntity::VIEWMODEL;
|
||||
|
||||
if (!render_ent->IsBasePlayer() && !render_ent->IsPlayerController())
|
||||
return ChamsEntity::INVALID;
|
||||
|
||||
auto player = (C_CSPlayerPawn*)render_ent;
|
||||
if (!player)
|
||||
return ChamsEntity::INVALID;
|
||||
|
||||
auto alive = player->m_iHealth() > 0;
|
||||
if (!alive)
|
||||
return ChamsEntity::INVALID;
|
||||
|
||||
if (player->m_iTeamNum() == local->m_iTeamNum())
|
||||
return ChamsEntity::INVALID;
|
||||
|
||||
return ChamsEntity::ENEMY;
|
||||
}
|
||||
|
||||
CMaterial2* GetMaterial(int type, bool invisible) { return invisible ? resourceMaterials[type].mat_invs : resourceMaterials[type].mat; }
|
||||
|
||||
void __fastcall chams::hook(void* a1, void* a2, CMeshData* pMeshScene, int nMeshCount, void* pSceneView, void* pSceneLayer, void* pUnk, void* pUnk2)
|
||||
{
|
||||
static auto original = H::DrawArray.GetOriginal();
|
||||
|
||||
if (!I::EngineClient->valid())
|
||||
return original(a1, a2, pMeshScene, nMeshCount, pSceneView, pSceneLayer, pUnk, pUnk2);
|
||||
auto local_player = H::oGetLocalPlayer(0);
|
||||
if (!local_player)
|
||||
return original(a1, a2, pMeshScene, nMeshCount, pSceneView, pSceneLayer, pUnk, pUnk2);
|
||||
if (!pMeshScene)
|
||||
return original(a1, a2, pMeshScene, nMeshCount, pSceneView, pSceneLayer, pUnk, pUnk2);
|
||||
|
||||
if (!pMeshScene->pSceneAnimatableObject)
|
||||
return original(a1, a2, pMeshScene, nMeshCount, pSceneView, pSceneLayer, pUnk, pUnk2);
|
||||
|
||||
if (nMeshCount < 1)
|
||||
return original(a1, a2, pMeshScene, nMeshCount, pSceneView, pSceneLayer, pUnk, pUnk2);
|
||||
|
||||
CMeshData* render_data = pMeshScene;
|
||||
if (!render_data)
|
||||
return original(a1, a2, pMeshScene, nMeshCount, pSceneView, pSceneLayer, pUnk, pUnk2);
|
||||
|
||||
if (!render_data->pSceneAnimatableObject)
|
||||
return original(a1, a2, pMeshScene, nMeshCount, pSceneView, pSceneLayer, pUnk, pUnk2);
|
||||
|
||||
auto render_ent = render_data->pSceneAnimatableObject->Owner();
|
||||
if (!render_ent.valid())
|
||||
return original(a1, a2, pMeshScene, nMeshCount, pSceneView, pSceneLayer, pUnk, pUnk2);
|
||||
|
||||
auto entity = I::GameEntity->Instance->Get(render_ent);
|
||||
if (!entity)
|
||||
return original(a1, a2, pMeshScene, nMeshCount, pSceneView, pSceneLayer, pUnk, pUnk2);
|
||||
|
||||
const auto target = GetTargetType(entity);
|
||||
|
||||
if (target == ChamsEntity::VIEWMODEL && Config::viewmodelChams) {
|
||||
pMeshScene->pMaterial = GetMaterial(Config::chamsMaterial, false);
|
||||
pMeshScene->color.r = static_cast<uint8_t>(Config::colViewmodelChams.x * 255.0f);
|
||||
pMeshScene->color.g = static_cast<uint8_t>(Config::colViewmodelChams.y * 255.0f);
|
||||
pMeshScene->color.b = static_cast<uint8_t>(Config::colViewmodelChams.z * 255.0f);
|
||||
pMeshScene->color.a = static_cast<uint8_t>(Config::colViewmodelChams.w * 255.0f);
|
||||
return original(a1, a2, pMeshScene, nMeshCount, pSceneView, pSceneLayer, pUnk, pUnk2);
|
||||
}
|
||||
|
||||
if (target == ChamsEntity::HANDS && Config::armChams) {
|
||||
pMeshScene->pMaterial = GetMaterial(Config::chamsMaterial, false);
|
||||
pMeshScene->color.r = static_cast<uint8_t>(Config::colArmChams.x * 255.0f);
|
||||
pMeshScene->color.g = static_cast<uint8_t>(Config::colArmChams.y * 255.0f);
|
||||
pMeshScene->color.b = static_cast<uint8_t>(Config::colArmChams.z * 255.0f);
|
||||
pMeshScene->color.a = static_cast<uint8_t>(Config::colArmChams.w * 255.0f);
|
||||
return original(a1, a2, pMeshScene, nMeshCount, pSceneView, pSceneLayer, pUnk, pUnk2);
|
||||
}
|
||||
|
||||
if (target != ENEMY)
|
||||
return original(a1, a2, pMeshScene, nMeshCount, pSceneView, pSceneLayer, pUnk, pUnk2);
|
||||
|
||||
bool og = !Config::enemyChams && !Config::enemyChamsInvisible;
|
||||
if (og)
|
||||
return original(a1, a2, pMeshScene, nMeshCount, pSceneView, pSceneLayer, pUnk, pUnk2);
|
||||
|
||||
if (Config::enemyChamsInvisible) {
|
||||
pMeshScene->pMaterial = GetMaterial(Config::chamsMaterial, true);
|
||||
pMeshScene->color.r = static_cast<uint8_t>(Config::colVisualChamsIgnoreZ.x * 255.0f);
|
||||
pMeshScene->color.g = static_cast<uint8_t>(Config::colVisualChamsIgnoreZ.y * 255.0f);
|
||||
pMeshScene->color.b = static_cast<uint8_t>(Config::colVisualChamsIgnoreZ.z * 255.0f);
|
||||
pMeshScene->color.a = static_cast<uint8_t>(Config::colVisualChamsIgnoreZ.w * 255.0f);
|
||||
|
||||
original(a1, a2, pMeshScene, nMeshCount, pSceneView, pSceneLayer, pUnk, pUnk2);
|
||||
}
|
||||
|
||||
if (Config::enemyChams) {
|
||||
pMeshScene->pMaterial = GetMaterial(Config::chamsMaterial, false);
|
||||
pMeshScene->color.r = static_cast<uint8_t>(Config::colVisualChams.x * 255.0f);
|
||||
pMeshScene->color.g = static_cast<uint8_t>(Config::colVisualChams.y * 255.0f);
|
||||
pMeshScene->color.b = static_cast<uint8_t>(Config::colVisualChams.z * 255.0f);
|
||||
pMeshScene->color.a = static_cast<uint8_t>(Config::colVisualChams.w * 255.0f);
|
||||
return original(a1, a2, pMeshScene, nMeshCount, pSceneView, pSceneLayer, pUnk, pUnk2);
|
||||
}
|
||||
|
||||
// If we get here, neither chams type is enabled, so just render normally
|
||||
return original(a1, a2, pMeshScene, nMeshCount, pSceneView, pSceneLayer, pUnk, pUnk2);
|
||||
}
|
||||
42
TempleWare-CS2/source/templeware/features/chams/chams.h
Normal file
42
TempleWare-CS2/source/templeware/features/chams/chams.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include "../../../cs2/entity/C_BaseEntity/C_BaseEntity.h"
|
||||
#include "../../../cs2/entity/C_Material/C_Material.h"
|
||||
|
||||
#include "../../utils/math/utlstronghandle/utlstronghandle.h"
|
||||
|
||||
// forward declarations
|
||||
class CMeshData;
|
||||
|
||||
enum ChamsType {
|
||||
FLAT,
|
||||
ILLUMINATE,
|
||||
GLOW,
|
||||
MAXCOUNT
|
||||
};
|
||||
|
||||
enum ChamsEntity : std::int32_t {
|
||||
INVALID = 0,
|
||||
ENEMY,
|
||||
TEAM,
|
||||
VIEWMODEL,
|
||||
HANDS
|
||||
};
|
||||
|
||||
enum MaterialType {
|
||||
e_visible,
|
||||
e_invisible,
|
||||
e_max_material
|
||||
};
|
||||
|
||||
namespace chams
|
||||
{
|
||||
class Materials {
|
||||
public:
|
||||
bool init();
|
||||
};
|
||||
|
||||
static ChamsEntity GetTargetType(C_BaseEntity* entity) noexcept;
|
||||
CStrongHandle<CMaterial2> create(const char* name, const char szVmatBuffer[]);
|
||||
void __fastcall hook(void* pAnimatableSceneObjectDesc, void* pDx11, CMeshData* arrMeshDraw, int nDataCount, void* pSceneView, void* pSceneLayer, void* pUnk, void* pUnk2);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
#include "../../../hooks/hooks.h"
|
||||
#include "../../../config/config.h"
|
||||
|
||||
void __fastcall H::hkRenderFlashbangOverlay(void* a1, void* a2, void* a3, void* a4, void* a5) {
|
||||
if (Config::antiflash) return;
|
||||
return RenderFlashBangOverlay.GetOriginal()(a1, a2, a3, a4, a5);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
#include "../../../hooks/hooks.h"
|
||||
#include "../../../config/config.h"
|
||||
|
||||
float H::hkGetRenderFov(void* rcx) {
|
||||
if (Config::fovEnabled) {
|
||||
float flTargetFov = Config::fov;
|
||||
g_flActiveFov = flTargetFov;
|
||||
}else
|
||||
g_flActiveFov = H::GetRenderFov.GetOriginal()(rcx);
|
||||
|
||||
return g_flActiveFov;
|
||||
}
|
||||
268
TempleWare-CS2/source/templeware/features/visuals/visuals.cpp
Normal file
268
TempleWare-CS2/source/templeware/features/visuals/visuals.cpp
Normal file
@@ -0,0 +1,268 @@
|
||||
#include "visuals.h"
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include "../../hooks/hooks.h"
|
||||
#include "../../players/players.h"
|
||||
#include "../../utils/memory/patternscan/patternscan.h"
|
||||
#include "../../utils/memory/gaa/gaa.h"
|
||||
#include "../../../../external/imgui/imgui.h"
|
||||
#include "../../interfaces/interfaces.h"
|
||||
#include "../../config/config.h"
|
||||
#include "../../menu/menu.h"
|
||||
using namespace Esp;
|
||||
|
||||
LocalPlayerCached cached_local;
|
||||
std::vector<PlayerCache> cached_players;
|
||||
|
||||
void Visuals::init() {
|
||||
viewMatrix.viewMatrix = (viewmatrix_t*)M::getAbsoluteAddress(M::patternScan("client", "48 8D 0D ? ? ? ? 48 C1 E0 06"), 3, 0);
|
||||
}
|
||||
|
||||
void Esp::cache()
|
||||
{
|
||||
if (!I::EngineClient->valid())
|
||||
return;
|
||||
|
||||
/* Old method READ ME
|
||||
* @ // @here: manually cache once all existing entitys
|
||||
// to avoid issues when injecting mid game and hkAddEnt not called by game on existing Entity's
|
||||
|
||||
int highest_index = I::GameEntity->Instance->GetHighestEntityIndex();
|
||||
for (int i = 1; i <= highest_index; i++) {
|
||||
auto entity = I::GameEntity->Instance->Get(i);
|
||||
if (!entity)
|
||||
continue;
|
||||
|
||||
uintptr_t entityPointer = reinterpret_cast<uintptr_t>(entity);
|
||||
|
||||
SchemaClassInfoData_t* entityInfo = nullptr;
|
||||
GetSchemaClassInfo(entityPointer, &entityInfo);
|
||||
if (!entityInfo) continue;
|
||||
|
||||
if (strcmp(entityInfo->szName, "C_CSPlayerPawn") == 0) {
|
||||
bool exists = std::any_of(Players::pawns.begin(), Players::pawns.end(),
|
||||
[&](const C_CSPlayerPawn& pawn) { return pawn.getAddress() == entityPointer; });
|
||||
if (!exists) {
|
||||
Players::pawns.emplace_back(entityPointer);
|
||||
std::cout << "Added pawn " << Players::pawns.size() << "\n";
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strcmp(entityInfo->szName, "CCSPlayerController") == 0) {
|
||||
bool exists = std::any_of(Players::controllers.begin(), Players::controllers.end(),
|
||||
[&](const CCSPlayerController& controller) { return controller.getAddress() == entityPointer; });
|
||||
if (!exists) {
|
||||
Players::controllers.emplace_back(entityPointer);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}*/
|
||||
|
||||
cached_players.clear();
|
||||
|
||||
int nMaxHighestEntity = I::GameEntity->Instance->GetHighestEntityIndex();
|
||||
|
||||
for (int i = 1; i <= nMaxHighestEntity; i++)
|
||||
{
|
||||
auto Entity = I::GameEntity->Instance->Get(i);
|
||||
if (!Entity)
|
||||
continue;
|
||||
|
||||
if (!Entity->handle().valid())
|
||||
continue;
|
||||
|
||||
SchemaClassInfoData_t* _class = nullptr;
|
||||
Entity->dump_class_info(&_class);
|
||||
if (!_class)
|
||||
continue;
|
||||
|
||||
const uint32_t hash = HASH(_class->szName);
|
||||
|
||||
PlayerType_t type = none;
|
||||
|
||||
if (hash == HASH("CCSPlayerController"))
|
||||
{
|
||||
|
||||
type = none; int health = 0;
|
||||
Vector_t position; Vector_t viewOffset;
|
||||
const char* name = "none"; const char* weapon_name = "none";
|
||||
|
||||
CCSPlayerController* Controller = reinterpret_cast<CCSPlayerController*>(Entity);
|
||||
if (!Controller)
|
||||
continue;
|
||||
|
||||
if (!Controller->m_hPawn().valid())
|
||||
continue;
|
||||
|
||||
//@handle caching local player
|
||||
if (Controller->IsLocalPlayer()) {
|
||||
auto LocalPlayer = I::GameEntity->Instance->Get<C_CSPlayerPawn>(Controller->m_hPawn().index());
|
||||
if (!LocalPlayer) {
|
||||
cached_local.reset();
|
||||
continue;
|
||||
}
|
||||
|
||||
cached_local.alive = LocalPlayer->m_iHealth() > 0;
|
||||
if (LocalPlayer->m_iHealth() > 0) {
|
||||
cached_local.poisition = LocalPlayer->m_vOldOrigin();
|
||||
cached_local.health = LocalPlayer->m_iHealth();
|
||||
cached_local.handle = LocalPlayer->handle().index();
|
||||
cached_local.team = LocalPlayer->m_iTeamNum();
|
||||
}
|
||||
else {
|
||||
cached_local.reset();
|
||||
}
|
||||
}
|
||||
else // @handle only players
|
||||
{
|
||||
auto Player = I::GameEntity->Instance->Get<C_CSPlayerPawn>(Controller->m_hPawn().index());
|
||||
if (!Player)
|
||||
continue;
|
||||
|
||||
if (Player->m_iHealth() <= 0)
|
||||
continue;
|
||||
|
||||
health = Player->m_iHealth();
|
||||
name = Controller->m_sSanitizedPlayerName();
|
||||
position = Player->m_vOldOrigin(); viewOffset = Player->m_vecViewOffset();
|
||||
|
||||
cached_players.emplace_back(Entity, Player, Player->handle(),
|
||||
type, health, name,
|
||||
weapon_name, position, viewOffset, Player->m_iTeamNum());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Visuals::esp() {
|
||||
// Only proceed if at least one ESP component is enabled
|
||||
if (!Config::esp && !Config::showHealth && !Config::espFill && !Config::showNameTags) {
|
||||
return; // Exit early if no component is enabled
|
||||
}
|
||||
|
||||
//@better example of getting local pawn
|
||||
C_CSPlayerPawn* localPawn = H::oGetLocalPlayer(0);
|
||||
if (!localPawn) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (cached_players.empty())
|
||||
return;
|
||||
|
||||
for (const auto& Player : cached_players)
|
||||
{
|
||||
|
||||
if (!Player.handle.valid() || Player.health <= 0 || Player.handle.index() == INVALID_EHANDLE_INDEX)
|
||||
continue;
|
||||
|
||||
if (Config::teamCheck && (Player.team_num == cached_local.team))
|
||||
continue;
|
||||
|
||||
ImDrawList* drawList = ImGui::GetBackgroundDrawList();
|
||||
Vector_t feetPos = Player.position;
|
||||
Vector_t headPos = Player.position + Player.viewOffset;
|
||||
|
||||
Vector_t feetScreen, headScreen;
|
||||
if (!viewMatrix.WorldToScreen(feetPos, feetScreen) ||
|
||||
!viewMatrix.WorldToScreen(headPos, headScreen))
|
||||
continue;
|
||||
|
||||
float boxHeight = (feetScreen.y - headScreen.y) * 1.3f;
|
||||
float boxWidth = boxHeight / 2.0f;
|
||||
|
||||
float centerX = (feetScreen.x + headScreen.x) / 2.0f;
|
||||
float boxX = centerX - (boxWidth / 2.0f);
|
||||
|
||||
float boxY = headScreen.y - (boxHeight - (feetScreen.y - headScreen.y)) / 2.0f;
|
||||
|
||||
ImVec4 espColorWithAlpha = Config::espColor;
|
||||
espColorWithAlpha.w = Config::espFillOpacity;
|
||||
ImU32 boxColor = ImGui::ColorConvertFloat4ToU32(Config::espColor);
|
||||
ImU32 fillColor = ImGui::ColorConvertFloat4ToU32(espColorWithAlpha);
|
||||
|
||||
// ESP Fill
|
||||
if (Config::espFill) {
|
||||
drawList->AddRectFilled(
|
||||
ImVec2(boxX, boxY),
|
||||
ImVec2(boxX + boxWidth, boxY + boxHeight),
|
||||
fillColor
|
||||
);
|
||||
}
|
||||
|
||||
// ESP Box - only render if Config::esp is enabled
|
||||
if (Config::esp) {
|
||||
drawList->AddRect(
|
||||
ImVec2(boxX, boxY),
|
||||
ImVec2(boxX + boxWidth, boxY + boxHeight),
|
||||
boxColor,
|
||||
0.0f,
|
||||
0,
|
||||
Config::espThickness
|
||||
);
|
||||
}
|
||||
|
||||
// Health Bar
|
||||
if (Config::showHealth) {
|
||||
int health = Player.health;
|
||||
float healthHeight = boxHeight * (static_cast<float>(health) / 100.0f);
|
||||
float barWidth = 4.0f;
|
||||
float barX = boxX - (barWidth + 2);
|
||||
float barY = boxY + (boxHeight - healthHeight);
|
||||
|
||||
drawList->AddRectFilled(
|
||||
ImVec2(barX, boxY),
|
||||
ImVec2(barX + barWidth, boxY + boxHeight),
|
||||
IM_COL32(70, 70, 70, 255)
|
||||
);
|
||||
|
||||
ImU32 healthColor = IM_COL32(
|
||||
static_cast<int>((100 - health) * 2.55f),
|
||||
static_cast<int>(health * 2.55f),
|
||||
0,
|
||||
255
|
||||
);
|
||||
drawList->AddRectFilled(
|
||||
ImVec2(barX, barY),
|
||||
ImVec2(barX + barWidth, barY + healthHeight),
|
||||
healthColor
|
||||
);
|
||||
|
||||
std::string displayText = "[" + std::to_string(health) + "HP]";
|
||||
ImVec2 textSize = ImGui::CalcTextSize(displayText.c_str());
|
||||
float textX = boxX + (boxWidth - textSize.x) / 2;
|
||||
float textY = boxY + boxHeight + 2;
|
||||
drawList->AddText(
|
||||
ImVec2(textX + 1, textY + 1),
|
||||
IM_COL32(0, 0, 0, 255),
|
||||
displayText.c_str()
|
||||
);
|
||||
drawList->AddText(
|
||||
ImVec2(textX, textY),
|
||||
IM_COL32(255, 255, 255, 255),
|
||||
displayText.c_str()
|
||||
);
|
||||
}
|
||||
|
||||
if (Config::showNameTags) {
|
||||
std::string playerName = Player.name;
|
||||
ImVec2 nameSize = ImGui::CalcTextSize(playerName.c_str());
|
||||
|
||||
float nameX = boxX + (boxWidth - nameSize.x) / 2;
|
||||
float nameY = boxY - nameSize.y - 2;
|
||||
|
||||
//@FIXME: shit method to do outline
|
||||
drawList->AddText(
|
||||
ImVec2(nameX + 1, nameY + 1),
|
||||
IM_COL32(0, 0, 0, 255),
|
||||
playerName.c_str()
|
||||
);
|
||||
|
||||
drawList->AddText(
|
||||
ImVec2(nameX, nameY),
|
||||
IM_COL32(255, 255, 255, 255),
|
||||
playerName.c_str()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
60
TempleWare-CS2/source/templeware/features/visuals/visuals.h
Normal file
60
TempleWare-CS2/source/templeware/features/visuals/visuals.h
Normal file
@@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
#include "../../utils/math/viewmatrix/viewmatrix.h"
|
||||
#include "..\..\..\cs2\entity\C_CSPlayerPawn\C_CSPlayerPawn.h"
|
||||
#include "..\..\..\cs2\entity\C_BaseEntity\C_BaseEntity.h"
|
||||
|
||||
class LocalPlayerCached {
|
||||
public:
|
||||
int handle;
|
||||
int health;
|
||||
int team;
|
||||
bool alive;
|
||||
Vector_t poisition;
|
||||
void reset() {
|
||||
poisition = Vector_t();
|
||||
team = 0;
|
||||
health = 0;
|
||||
handle = 0;
|
||||
alive = false;
|
||||
}
|
||||
};
|
||||
|
||||
enum PlayerType_t : int
|
||||
{
|
||||
none = -1,
|
||||
enemy = 0,
|
||||
team = 1,
|
||||
};
|
||||
|
||||
struct PlayerCache
|
||||
{
|
||||
PlayerCache(C_BaseEntity* a1, C_CSPlayerPawn* plyr, CBaseHandle hdl, PlayerType_t typ, int hp, const char* nm,
|
||||
const char* wep_name, Vector_t pos, Vector_t viewOff, int teamnm) :
|
||||
entity(a1), player(plyr), handle(hdl), type(typ), health(hp), name(nm),
|
||||
weapon_name(wep_name), position(pos), viewOffset(viewOff), team_num(teamnm) { }
|
||||
|
||||
C_BaseEntity* entity;
|
||||
C_CSPlayerPawn* player;
|
||||
CBaseHandle handle;
|
||||
PlayerType_t type;
|
||||
int health;
|
||||
const char* name;
|
||||
const char* weapon_name;
|
||||
Vector_t position;
|
||||
Vector_t viewOffset;
|
||||
int team_num;
|
||||
};
|
||||
|
||||
namespace Esp {
|
||||
class Visuals {
|
||||
public:
|
||||
void init();
|
||||
void esp();
|
||||
private:
|
||||
ViewMatrix viewMatrix;
|
||||
};
|
||||
void cache();
|
||||
}
|
||||
|
||||
extern LocalPlayerCached cached_local;
|
||||
extern std::vector<PlayerCache> cached_players;
|
||||
43
TempleWare-CS2/source/templeware/features/world/world.cpp
Normal file
43
TempleWare-CS2/source/templeware/features/world/world.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include "../../hooks/hooks.h"
|
||||
#include "../../players/players.h"
|
||||
#include "../../config/config.h"
|
||||
#include "../../../../external/imgui/imgui.h"
|
||||
|
||||
|
||||
void reset_walls(C_AggregateSceneObject* object) {
|
||||
for (int i = 0; i < object->m_nCount; i++) {
|
||||
object->m_pData[i].r = 255;
|
||||
object->m_pData[i].g = 255;
|
||||
object->m_pData[i].b = 255;
|
||||
}
|
||||
}
|
||||
|
||||
void apply_walls(C_AggregateSceneObject* object, ImVec4 colors) {
|
||||
for (int i = 0; i < object->m_nCount; i++) {
|
||||
object->m_pData[i].r = static_cast<uint8_t>(colors.x * 255.0f);
|
||||
object->m_pData[i].g = static_cast<uint8_t>(colors.y * 255.0f);
|
||||
object->m_pData[i].b = static_cast<uint8_t>(colors.z * 255.0f);
|
||||
}
|
||||
}
|
||||
|
||||
void* __fastcall H::hkUpdateSceneObject(C_AggregateSceneObject* object, void* unk)
|
||||
{
|
||||
static auto update_walls_object = UpdateWallsObject.GetOriginal();
|
||||
auto result = update_walls_object(object, unk);
|
||||
auto colors = Config::NightColor;
|
||||
|
||||
if (object) {
|
||||
if (Config::Night) {
|
||||
apply_walls(object, colors);
|
||||
}
|
||||
else {
|
||||
reset_walls(object);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
56
TempleWare-CS2/source/templeware/hooks/hooks.cpp
Normal file
56
TempleWare-CS2/source/templeware/hooks/hooks.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#include "hooks.h"
|
||||
#include <iostream>
|
||||
|
||||
#include "../../../external/kiero/minhook/include/MinHook.h"
|
||||
|
||||
#include "../../templeware/utils/memory/Interface/Interface.h"
|
||||
#include "../utils/memory/patternscan/patternscan.h"
|
||||
#include "../utils/memory/gaa/gaa.h"
|
||||
|
||||
#include "../players/hook/playerHook.h"
|
||||
#include "../features/visuals/visuals.h"
|
||||
#include "../features/chams/chams.h"
|
||||
|
||||
#include "../../cs2/datatypes/cutlbuffer/cutlbuffer.h"
|
||||
#include "../../cs2/datatypes/keyvalues/keyvalues.h"
|
||||
#include "../../cs2/entity/C_Material/C_Material.h"
|
||||
|
||||
#include "../config/config.h"
|
||||
#include "../interfaces/interfaces.h"
|
||||
#include "../features/aim/aim.h"
|
||||
|
||||
void __fastcall H::hkFrameStageNotify(void* a1, int stage)
|
||||
{
|
||||
FrameStageNotify.GetOriginal()(a1, stage);
|
||||
|
||||
// frame_render_stage | 9
|
||||
if (stage == 9 && oGetLocalPlayer(0)) {
|
||||
Esp::cache();
|
||||
|
||||
Aimbot();
|
||||
}
|
||||
}
|
||||
|
||||
void* __fastcall H::hkLevelInit(void* pClientModeShared, const char* szNewMap) {
|
||||
static void* g_pPVS = (void*)M::getAbsoluteAddress(M::patternScan("engine2", "48 8D 0D ? ? ? ? 33 D2 FF 50"), 0x3);
|
||||
|
||||
M::vfunc<void*, 6U, void>(g_pPVS, false);
|
||||
|
||||
return LevelInit.GetOriginal()(pClientModeShared, szNewMap);
|
||||
}
|
||||
|
||||
void H::Hooks::init() {
|
||||
|
||||
oGetWeaponData = *reinterpret_cast<int*>(M::patternScan("client", ("48 8B 81 ? ? ? ? 85 D2 78 ? 48 83 FA ? 73 ? F3 0F 10 84 90 ? ? ? ? C3 F3 0F 10 80 ? ? ? ? C3 CC CC CC CC")) + 0x3);
|
||||
ogGetBaseEntity = reinterpret_cast<decltype(ogGetBaseEntity)>(M::patternScan("client", ("81 FA ? ? ? ? 77 ? 8B C2 C1 F8 ? 83 F8 ? 77 ? 48 98 48 8B 4C C1 ? 48 85 C9 74 ? 8B C2 25 ? ? ? ? 48 6B C0 ? 48 03 C8 74 ? 8B 41 ? 25 ? ? ? ? 3B C2 75 ? 48 8B 01")));
|
||||
oGetLocalPlayer = reinterpret_cast<decltype(oGetLocalPlayer)>(M::patternScan("client", ("48 83 EC 28 83 F9 FF 75 17 48 8B 0D ?? ?? ?? ?? 48 8D 54 24 30 48 8B 01 FF 90 ?? ?? ?? ?? 8B 08 48 63 C1 48 8D 0D ?? ?? ?? ?? 48 8B 0C")));
|
||||
|
||||
UpdateWallsObject.Add((void*)M::patternScan("scenesystem", ("48 89 5C 24 10 48 89 6C 24 18 56 57 41 54 41 56 41 57 48 83 EC 40")), &hkUpdateSceneObject);
|
||||
FrameStageNotify.Add((void*)M::patternScan("client", ("48 89 5C 24 ? 56 48 83 EC 30 8B 05 ? ? ? ?")), &hkFrameStageNotify);
|
||||
DrawArray.Add((void*)M::patternScan("scenesystem", ("48 8B C4 48 89 50 10 53 41 55 41 56 48 81 EC ? ? ? ? 4D 63 F1")), &chams::hook);
|
||||
GetRenderFov.Add((void*)M::getAbsoluteAddress(M::patternScan("client", "E8 ? ? ? ? F3 0F 11 45 00 48 8B 5C 24 40"), 1), &hkGetRenderFov);
|
||||
LevelInit.Add((void*)M::getAbsoluteAddress(M::patternScan("client", "E8 ? ? ? ? C6 83 ? ? ? ? ? C6 83"), 1), &hkLevelInit);
|
||||
RenderFlashBangOverlay.Add((void*)M::patternScan("client", ("85 D2 0F 88 ? ? ? ? 55 56 41 55")), &hkRenderFlashbangOverlay);
|
||||
|
||||
MH_EnableHook(MH_ALL_HOOKS);
|
||||
}
|
||||
38
TempleWare-CS2/source/templeware/hooks/hooks.h
Normal file
38
TempleWare-CS2/source/templeware/hooks/hooks.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
#include "includeHooks.h"
|
||||
#include "../../cs2/entity/C_AggregateSceneObject/C_AggregateSceneObject.h"
|
||||
#include "../../cs2/entity/C_CSPlayerPawn/C_CSPlayerPawn.h"
|
||||
#include "../../cs2/datatypes/cutlbuffer/cutlbuffer.h"
|
||||
#include "../../cs2/datatypes/keyvalues/keyvalues.h"
|
||||
#include "../../cs2/entity/C_Material/C_Material.h"
|
||||
|
||||
// Forward declaration
|
||||
class CMeshData;
|
||||
class CEntityIdentity;
|
||||
|
||||
namespace H {
|
||||
void* __fastcall hkUpdateSceneObject(C_AggregateSceneObject* object, void* unk);
|
||||
void __fastcall hkFrameStageNotify(void* a1, int stage);
|
||||
void* __fastcall hkLevelInit(void* pClientModeShared, const char* szNewMap);
|
||||
void __fastcall hkChamsObject(void* pAnimatableSceneObjectDesc, void* pDx11, CMeshData* arrMeshDraw, int nDataCount, void* pSceneView, void* pSceneLayer, void* pUnk, void* pUnk2);
|
||||
void __fastcall hkRenderFlashbangOverlay(void* a1, void* a2, void* a3, void* a4, void* a5);
|
||||
inline float g_flActiveFov;
|
||||
float hkGetRenderFov(void* rcx);
|
||||
|
||||
inline CInlineHookObj<decltype(&hkChamsObject)> DrawArray = { };
|
||||
inline CInlineHookObj<decltype(&hkFrameStageNotify)> FrameStageNotify = { };
|
||||
inline CInlineHookObj<decltype(&hkUpdateSceneObject)> UpdateWallsObject = { };
|
||||
inline CInlineHookObj<decltype(&hkGetRenderFov)> GetRenderFov = { };
|
||||
inline CInlineHookObj<decltype(&hkLevelInit)> LevelInit = { };
|
||||
inline CInlineHookObj<decltype(&hkRenderFlashbangOverlay)> RenderFlashBangOverlay = { };
|
||||
|
||||
// inline hooks
|
||||
inline int oGetWeaponData;
|
||||
inline void* (__fastcall* ogGetBaseEntity)(void*, int);
|
||||
inline C_CSPlayerPawn* (__fastcall* oGetLocalPlayer)(int);
|
||||
|
||||
class Hooks {
|
||||
public:
|
||||
void init();
|
||||
};
|
||||
}
|
||||
108
TempleWare-CS2/source/templeware/hooks/includeHooks.h
Normal file
108
TempleWare-CS2/source/templeware/hooks/includeHooks.h
Normal file
@@ -0,0 +1,108 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../../external/kiero/minhook/include/MinHook.h"
|
||||
#include <cstdint>
|
||||
// @source: popular github minhook instance
|
||||
template <typename T>
|
||||
class CInlineHookObj
|
||||
{
|
||||
public:
|
||||
/// setup hook and replace function
|
||||
/// @returns: true if hook has been successfully created, false otherwise
|
||||
bool Add(void* pFunction, void* pDetour)
|
||||
{
|
||||
if (pFunction == nullptr || pDetour == nullptr)
|
||||
return false;
|
||||
|
||||
pBaseFn = pFunction;
|
||||
pReplaceFn = pDetour;
|
||||
|
||||
if (const MH_STATUS status = MH_CreateHook(pBaseFn, pReplaceFn, &pOriginalFn); status != MH_OK)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Replace())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// patch memory to jump to our function instead of original
|
||||
/// @returns: true if hook has been successfully applied, false otherwise
|
||||
bool Replace()
|
||||
{
|
||||
// check is hook has been created
|
||||
if (pBaseFn == nullptr)
|
||||
return false;
|
||||
|
||||
// check that function isn't already hooked
|
||||
if (bIsHooked)
|
||||
return false;
|
||||
|
||||
if (const MH_STATUS status = MH_EnableHook(pBaseFn); status != MH_OK)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// switch hook state
|
||||
bIsHooked = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// restore original function call and cleanup hook data
|
||||
/// @returns: true if hook has been successfully removed, false otherwise
|
||||
bool Remove()
|
||||
{
|
||||
// restore it at first
|
||||
if (!Restore())
|
||||
return false;
|
||||
|
||||
if (const MH_STATUS status = MH_RemoveHook(pBaseFn); status != MH_OK)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// restore patched memory to original function call
|
||||
/// @returns: true if hook has been successfully restored, false otherwise
|
||||
bool Restore()
|
||||
{
|
||||
// check that function is hooked
|
||||
if (!bIsHooked)
|
||||
return false;
|
||||
|
||||
if (const MH_STATUS status = MH_DisableHook(pBaseFn); status != MH_OK)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// switch hook state
|
||||
bIsHooked = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// @returns: original, unwrapped function that would be called without the hook
|
||||
inline T GetOriginal()
|
||||
{
|
||||
return reinterpret_cast<T>(pOriginalFn);
|
||||
}
|
||||
|
||||
/// @returns: true if hook is applied at the time, false otherwise
|
||||
inline bool IsHooked() const
|
||||
{
|
||||
return bIsHooked;
|
||||
}
|
||||
|
||||
private:
|
||||
// current hook state
|
||||
bool bIsHooked = false;
|
||||
// function base handle
|
||||
void* pBaseFn = nullptr;
|
||||
// function that being replace the original call
|
||||
void* pReplaceFn = nullptr;
|
||||
// original function
|
||||
void* pOriginalFn = nullptr;
|
||||
};
|
||||
@@ -0,0 +1,6 @@
|
||||
#include "CGameEntitySystem.h"
|
||||
#include "..\..\hooks\hooks.h"
|
||||
|
||||
void* CGameEntitySystem::GetEntityByIndex(int nIndex) {
|
||||
return H::ogGetBaseEntity(this, nIndex);
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include "../../../cs2/entity/handle.h"
|
||||
#include "../../../templeware/utils/memory/memorycommon.h"
|
||||
#include "../../../templeware/utils/math/vector/vector.h"
|
||||
#include "..\..\..\..\source\templeware\utils\schema\schema.h"
|
||||
#include "..\..\..\..\source\templeware\utils\memory\vfunc\vfunc.h"
|
||||
|
||||
#include "..\..\..\cs2\entity\C_BaseEntity\C_BaseEntity.h"
|
||||
#include "..\..\..\cs2\entity\C_CSPlayerPawn\C_CSPlayerPawn.h"
|
||||
#include "..\..\..\cs2\entity\CCSPlayerController\CCSPlayerController.h"
|
||||
|
||||
class CGameEntitySystem
|
||||
{
|
||||
public:
|
||||
template <typename T = C_BaseEntity>
|
||||
T* Get(int nIndex)
|
||||
{
|
||||
return reinterpret_cast<T*>(this->GetEntityByIndex(nIndex));
|
||||
}
|
||||
|
||||
/// GetClientEntityFromHandle
|
||||
template <typename T = C_BaseEntity>
|
||||
T* Get(const CBaseHandle hHandle)
|
||||
{
|
||||
if (!hHandle.valid())
|
||||
return nullptr;
|
||||
|
||||
return reinterpret_cast<T*>(this->GetEntityByIndex(hHandle.index()));
|
||||
}
|
||||
|
||||
int GetHighestEntityIndex()
|
||||
{
|
||||
return *reinterpret_cast<int*>(reinterpret_cast<std::uintptr_t>(this) + 0x20F0);
|
||||
}
|
||||
|
||||
|
||||
C_CSPlayerPawn* get_entity(int index)
|
||||
{
|
||||
__int64 v2; // rcx
|
||||
__int64 v3; // r8
|
||||
__int64 result{}; // rax
|
||||
|
||||
if ((unsigned int)index <= 0x7FFE
|
||||
&& (unsigned int)(index >> 9) <= 0x3F
|
||||
&& (v2 = *(std::uintptr_t*)(std::uintptr_t(this) + 8 * (index >> 9) + 16)) != 0
|
||||
&& (v3 = 120 * (index & 0x1FF), v3 + v2)
|
||||
&& (*(std::uintptr_t*)(v3 + v2 + 16) & 0x7FFF) == index)
|
||||
{
|
||||
result = *(std::uintptr_t*)(v3 + v2);
|
||||
}
|
||||
return reinterpret_cast<C_CSPlayerPawn*>(result);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
void* GetEntityByIndex(int nIndex);
|
||||
|
||||
};
|
||||
|
||||
class IGameResourceService
|
||||
{
|
||||
public:
|
||||
MEM_PAD(0x58);
|
||||
CGameEntitySystem* Instance;
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
// used: callvfunc
|
||||
#include "..\..\utils\memory\vfunc\vfunc.h"
|
||||
#include <type_traits>
|
||||
class IEngineClient
|
||||
{
|
||||
public:
|
||||
int maxClients()
|
||||
{
|
||||
return M::vfunc<int, 34U>(this);
|
||||
}
|
||||
|
||||
bool in_game()
|
||||
{
|
||||
return M::vfunc<bool, 35U>(this);
|
||||
}
|
||||
|
||||
bool connected()
|
||||
{
|
||||
return M::vfunc<bool, 36U>(this);
|
||||
}
|
||||
|
||||
int get_local_player() {
|
||||
int nIndex = -1;
|
||||
M::vfunc<void, 49U>(this, std::ref(nIndex), 0);
|
||||
return nIndex + 1;
|
||||
}
|
||||
public:
|
||||
inline bool valid() {
|
||||
return connected() && in_game();
|
||||
}
|
||||
|
||||
};
|
||||
36
TempleWare-CS2/source/templeware/interfaces/interfaces.cpp
Normal file
36
TempleWare-CS2/source/templeware/interfaces/interfaces.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "interfaces.h"
|
||||
#include "CGameEntitySystem/CGameEntitySystem.h"
|
||||
|
||||
// @used: I::Get<template>
|
||||
#include "..\..\templeware\utils\memory\Interface\Interface.h"
|
||||
bool I::Interfaces::init()
|
||||
{
|
||||
const HMODULE tier0_base = GetModuleHandleA("tier0.dll");
|
||||
if (!tier0_base)
|
||||
return false;
|
||||
|
||||
bool success = true;
|
||||
|
||||
// interfaces
|
||||
EngineClient = I::Get<IEngineClient>(("engine2.dll"), "Source2EngineToClient00");
|
||||
success &= (EngineClient != nullptr);
|
||||
|
||||
GameEntity = I::Get<IGameResourceService>(("engine2.dll"), "GameResourceServiceClientV00");
|
||||
success &= (GameEntity != nullptr);
|
||||
|
||||
// exports
|
||||
ConstructUtlBuffer = reinterpret_cast<decltype(ConstructUtlBuffer)>(GetProcAddress(tier0_base, "??0CUtlBuffer@@QEAA@HHH@Z"));
|
||||
EnsureCapacityBuffer = reinterpret_cast<decltype(EnsureCapacityBuffer)>(GetProcAddress(tier0_base, "?EnsureCapacity@CUtlBuffer@@QEAAXH@Z"));
|
||||
PutUtlString = reinterpret_cast<decltype(PutUtlString)>(GetProcAddress(tier0_base, "?PutString@CUtlBuffer@@QEAAXPEBD@Z"));
|
||||
CreateMaterial = reinterpret_cast<decltype(CreateMaterial)>(M::FindPattern("materialsystem2.dll", "48 89 5C 24 ? 48 89 6C 24 ? 56 57 41 56 48 81 EC ? ? ? ? 48 8B 05"));
|
||||
LoadKeyValues = reinterpret_cast<decltype(LoadKeyValues)>(GetProcAddress(tier0_base, "?LoadKV3@@YA_NPEAVKeyValues3@@PEAVCUtlString@@PEBDAEBUKV3ID_t@@2@Z"));
|
||||
ConMsg = reinterpret_cast<decltype(ConMsg)>(GetProcAddress(tier0_base, "?ConMsg@@YAXPEBDZZ"));
|
||||
ConColorMsg = reinterpret_cast<decltype(ConColorMsg)>(GetProcAddress(tier0_base, "?ConColorMsg@@YAXAEBVColor@@PEBDZZ"));
|
||||
|
||||
printf("Source2EngineToClient00: 0x%p\n", reinterpret_cast<void*>(EngineClient));
|
||||
printf("GameResourceServiceClientV00: 0x%p\n", reinterpret_cast<void*>(GameEntity));
|
||||
printf("CreateMaterial: 0x%p\n", reinterpret_cast<void*>(CreateMaterial));
|
||||
|
||||
// return status
|
||||
return success;
|
||||
}
|
||||
27
TempleWare-CS2/source/templeware/interfaces/interfaces.h
Normal file
27
TempleWare-CS2/source/templeware/interfaces/interfaces.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
#include "IEngineClient/IEngineClient.h"
|
||||
#include "CGameEntitySystem/CGameEntitySystem.h"
|
||||
#include "..\..\cs2\entity\C_CSPlayerPawn\C_CSPlayerPawn.h"
|
||||
#include "..\..\cs2\datatypes\cutlbuffer\cutlbuffer.h"
|
||||
#include "..\..\cs2\datatypes\keyvalues\keyvalues.h"
|
||||
#include "..\..\cs2\entity\C_Material\C_Material.h"
|
||||
|
||||
namespace I
|
||||
{
|
||||
inline void(__fastcall* EnsureCapacityBuffer)(CUtlBuffer*, int) = nullptr;
|
||||
inline CUtlBuffer* (__fastcall* ConstructUtlBuffer)(CUtlBuffer*, int, int, int) = nullptr;
|
||||
inline void(__fastcall* PutUtlString)(CUtlBuffer*, const char*);
|
||||
inline std::int64_t(__fastcall* CreateMaterial)(void*, void*, const char*, void*, unsigned int, unsigned int);
|
||||
inline bool(__fastcall* LoadKeyValues)(CKeyValues3*, void*, const char*, const KV3ID_t*, const char*);
|
||||
|
||||
// Logging functions
|
||||
inline void(__fastcall* ConMsg)(const char*, ...);
|
||||
inline void(__fastcall* ConColorMsg)(const Color&, const char*, ...);
|
||||
|
||||
inline IEngineClient* EngineClient = nullptr;
|
||||
inline IGameResourceService* GameEntity = nullptr;
|
||||
class Interfaces {
|
||||
public:
|
||||
bool init();
|
||||
};
|
||||
}
|
||||
99
TempleWare-CS2/source/templeware/keybinds/keybinds.cpp
Normal file
99
TempleWare-CS2/source/templeware/keybinds/keybinds.cpp
Normal file
@@ -0,0 +1,99 @@
|
||||
#include "keybinds.h"
|
||||
#include <Windows.h>
|
||||
#include <cstring> // For strcpy_s and sprintf_s
|
||||
#include <cstdio> // For sprintf_s
|
||||
|
||||
#include "../../../external/imgui/imgui.h"
|
||||
#include "../config/config.h"
|
||||
|
||||
Keybind::Keybind(bool& v, int k)
|
||||
: var(v), key(k), isListening(false), skipFrame(false) {}
|
||||
|
||||
Keybinds::Keybinds() {
|
||||
keybinds.emplace_back(Keybind(Config::aimbot, 0x12));
|
||||
}
|
||||
|
||||
void Keybinds::pollInputs() {
|
||||
for (Keybind& k : keybinds) {
|
||||
if (k.key != 0) {
|
||||
// Если кнопка удерживается
|
||||
if (GetAsyncKeyState(k.key) & 0x8000) {
|
||||
k.var = true;
|
||||
} else {
|
||||
k.var = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Keybinds::menuButton(bool& var) {
|
||||
for (auto& kb : keybinds) {
|
||||
if (&kb.var != &var) continue;
|
||||
|
||||
char keyName[32] = "None";
|
||||
if (kb.key != 0) {
|
||||
switch (kb.key) {
|
||||
case VK_INSERT: strcpy_s(keyName, "INSERT"); break;
|
||||
case VK_DELETE: strcpy_s(keyName, "DELETE"); break;
|
||||
case VK_HOME: strcpy_s(keyName, "HOME"); break;
|
||||
case VK_END: strcpy_s(keyName, "END"); break;
|
||||
case VK_PRIOR: strcpy_s(keyName, "PAGE UP"); break;
|
||||
case VK_NEXT: strcpy_s(keyName, "PAGE DOWN"); break;
|
||||
case VK_LBUTTON: strcpy_s(keyName, "MOUSE1"); break;
|
||||
case VK_RBUTTON: strcpy_s(keyName, "MOUSE2"); break;
|
||||
case VK_MBUTTON: strcpy_s(keyName, "MOUSE3"); break;
|
||||
case VK_XBUTTON1: strcpy_s(keyName, "MOUSE4"); break;
|
||||
case VK_XBUTTON2: strcpy_s(keyName, "MOUSE5"); break;
|
||||
default:
|
||||
if (kb.key >= 'A' && kb.key <= 'Z') {
|
||||
sprintf_s(keyName, "%c", kb.key);
|
||||
}
|
||||
else if (kb.key >= '0' && kb.key <= '9') {
|
||||
sprintf_s(keyName, "%c", kb.key);
|
||||
}
|
||||
else {
|
||||
sprintf_s(keyName, "0x%X", kb.key);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!kb.isListening) {
|
||||
ImGui::PushID(&kb);
|
||||
ImGui::Text("[%s]", keyName);
|
||||
ImGui::SameLine();
|
||||
bool clicked = ImGui::Button("Change##Bind");
|
||||
ImGui::PopID();
|
||||
|
||||
if (clicked) {
|
||||
kb.isListening = true;
|
||||
kb.skipFrame = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ImGui::Text("Press any key...");
|
||||
ImGui::SameLine();
|
||||
|
||||
if (ImGui::Button("Cancel") || (GetAsyncKeyState(VK_ESCAPE) & 0x8000)) {
|
||||
kb.isListening = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!kb.skipFrame) {
|
||||
for (int keyCode = 7; keyCode < 256; ++keyCode) {
|
||||
if (GetAsyncKeyState(keyCode) & 0x8000) {
|
||||
kb.key = keyCode;
|
||||
kb.isListening = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
kb.skipFrame = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Keybinds keybind;
|
||||
24
TempleWare-CS2/source/templeware/keybinds/keybinds.h
Normal file
24
TempleWare-CS2/source/templeware/keybinds/keybinds.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
|
||||
struct Keybind {
|
||||
bool& var;
|
||||
int key;
|
||||
bool isListening;
|
||||
bool skipFrame;
|
||||
|
||||
Keybind(bool& v, int k = 0);
|
||||
};
|
||||
|
||||
|
||||
class Keybinds {
|
||||
public:
|
||||
Keybinds();
|
||||
void pollInputs();
|
||||
|
||||
void menuButton(bool& var);
|
||||
private:
|
||||
std::vector<Keybind> keybinds;
|
||||
};
|
||||
|
||||
extern Keybinds keybind;
|
||||
82
TempleWare-CS2/source/templeware/menu/hud.cpp
Normal file
82
TempleWare-CS2/source/templeware/menu/hud.cpp
Normal file
@@ -0,0 +1,82 @@
|
||||
#include "hud.h"
|
||||
#include "../../../external/imgui/imgui.h"
|
||||
#include "../config/config.h"
|
||||
#include "../hooks/hooks.h"
|
||||
#include <ctime>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <DirectXMath.h>
|
||||
|
||||
std::string g_DebugString;
|
||||
|
||||
Hud::Hud() {
|
||||
|
||||
}
|
||||
|
||||
float CalculateFovRadius(float fovDegrees, float screenWidth, float screenHeight, float gameVerticalFOV) {
|
||||
float aspectRatio = screenWidth / screenHeight;
|
||||
float fovRadians = fovDegrees * (DirectX::XM_PI / 180.0f);
|
||||
|
||||
float screenRadius = std::tan(fovRadians / 2.0f) * (screenHeight / 2.0f) / std::tan(gameVerticalFOV * (DirectX::XM_PI / 180.0f) / 2.0f);
|
||||
|
||||
static float flScalingMultiplier = 2.5f;
|
||||
|
||||
return screenRadius * flScalingMultiplier;
|
||||
}
|
||||
|
||||
void RenderFovCircle(ImDrawList* drawList, float fov, ImVec2 screenCenter, float screenWidth, float screenHeight, float thickness) {
|
||||
float radius = CalculateFovRadius(fov, screenWidth, screenHeight, H::g_flActiveFov);
|
||||
uint32_t color = ImGui::ColorConvertFloat4ToU32(Config::fovCircleColor);
|
||||
drawList->AddCircle(screenCenter, radius, color, 100, thickness);
|
||||
}
|
||||
|
||||
void Hud::render() {
|
||||
|
||||
// Time
|
||||
std::time_t now = std::time(nullptr);
|
||||
std::tm localTime;
|
||||
localtime_s(&localTime, &now);
|
||||
char timeBuffer[9];
|
||||
std::strftime(timeBuffer, sizeof(timeBuffer), "%H:%M:%S", &localTime);
|
||||
|
||||
// FPS
|
||||
float fps = ImGui::GetIO().Framerate;
|
||||
std::ostringstream fpsStream;
|
||||
fpsStream << static_cast<int>(fps) << " FPS";
|
||||
|
||||
// WaterMark
|
||||
std::string watermarkText = "TempleWare | " + fpsStream.str() + " | " + timeBuffer;
|
||||
|
||||
ImVec2 textSize = ImGui::CalcTextSize(watermarkText.c_str());
|
||||
float padding = 5.0f;
|
||||
ImVec2 pos = ImVec2(10, 10);
|
||||
ImVec2 rectSize = ImVec2(textSize.x + padding * 2, textSize.y + padding * 2);
|
||||
|
||||
ImU32 bgColor = IM_COL32(50, 50, 50, 200);
|
||||
ImU32 borderColor = IM_COL32(153, 76, 204, 255);
|
||||
ImU32 textColor = IM_COL32(255, 255, 255, 255);
|
||||
|
||||
ImDrawList* drawList = ImGui::GetBackgroundDrawList();
|
||||
|
||||
drawList->AddRectFilled(pos, ImVec2(pos.x + rectSize.x, pos.y + rectSize.y), bgColor);
|
||||
|
||||
float lineThickness = 2.0f;
|
||||
drawList->AddLine(pos, ImVec2(pos.x, pos.y + rectSize.y), borderColor, lineThickness);
|
||||
drawList->AddLine(ImVec2(pos.x + rectSize.x, pos.y), ImVec2(pos.x + rectSize.x, pos.y + rectSize.y), borderColor, lineThickness);
|
||||
|
||||
ImVec2 textPos = ImVec2(pos.x + padding, pos.y + padding);
|
||||
drawList->AddText(textPos, textColor, watermarkText.c_str());
|
||||
|
||||
if (Config::fov_circle) {
|
||||
ImVec2 Center = ImVec2(ImGui::GetIO().DisplaySize.x / 2.f, ImGui::GetIO().DisplaySize.y / 2.f);
|
||||
|
||||
RenderFovCircle(drawList, Config::aimbot_fov, Center, ImGui::GetIO().DisplaySize.x, ImGui::GetIO().DisplaySize.y, 1.f);
|
||||
}
|
||||
|
||||
// Debug overlay
|
||||
if (!g_DebugString.empty()) {
|
||||
ImVec2 debugPos = ImVec2(10, 40); // чуть ниже watermark
|
||||
ImU32 debugColor = IM_COL32(255, 255, 0, 255); // жёлтый
|
||||
ImGui::GetBackgroundDrawList()->AddText(debugPos, debugColor, g_DebugString.c_str());
|
||||
}
|
||||
}
|
||||
9
TempleWare-CS2/source/templeware/menu/hud.h
Normal file
9
TempleWare-CS2/source/templeware/menu/hud.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
extern std::string g_DebugString;
|
||||
|
||||
class Hud {
|
||||
public:
|
||||
Hud();
|
||||
void render();
|
||||
};
|
||||
315
TempleWare-CS2/source/templeware/menu/menu.cpp
Normal file
315
TempleWare-CS2/source/templeware/menu/menu.cpp
Normal file
@@ -0,0 +1,315 @@
|
||||
#include "menu.h"
|
||||
#include "../config/config.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "../config/configmanager.h"
|
||||
|
||||
#include "../keybinds/keybinds.h"
|
||||
|
||||
#include "../utils/logging/log.h"
|
||||
|
||||
void ApplyImGuiTheme() {
|
||||
ImGui::StyleColorsDark();
|
||||
|
||||
ImGuiStyle& style = ImGui::GetStyle();
|
||||
ImVec4* colors = style.Colors;
|
||||
|
||||
ImVec4 primaryColor = ImVec4(0.44f, 0.23f, 0.78f, 1.0f);
|
||||
ImVec4 outlineColor = ImVec4(0.54f, 0.33f, 0.88f, 0.7f);
|
||||
|
||||
colors[ImGuiCol_WindowBg] = ImVec4(0.11f, 0.11f, 0.13f, 1.0f);
|
||||
colors[ImGuiCol_Border] = ImVec4(0.30f, 0.30f, 0.30f, 1.0f);
|
||||
colors[ImGuiCol_FrameBg] = ImVec4(0.11f, 0.11f, 0.13f, 1.0f);
|
||||
colors[ImGuiCol_FrameBgHovered] = ImVec4(0.15f, 0.15f, 0.18f, 1.0f);
|
||||
colors[ImGuiCol_FrameBgActive] = ImVec4(0.15f, 0.15f, 0.18f, 1.0f);
|
||||
colors[ImGuiCol_TitleBg] = ImVec4(0.11f, 0.11f, 0.13f, 1.0f);
|
||||
colors[ImGuiCol_TitleBgActive] = ImVec4(0.11f, 0.11f, 0.13f, 1.0f);
|
||||
colors[ImGuiCol_PopupBg] = ImVec4(0.11f, 0.11f, 0.13f, 1.0f);
|
||||
|
||||
colors[ImGuiCol_Button] = primaryColor;
|
||||
colors[ImGuiCol_ButtonHovered] = ImVec4(0.54f, 0.33f, 0.88f, 1.0f);
|
||||
colors[ImGuiCol_ButtonActive] = ImVec4(0.34f, 0.13f, 0.68f, 1.0f);
|
||||
|
||||
colors[ImGuiCol_CheckMark] = ImVec4(0.80f, 0.50f, 1.00f, 1.0f);
|
||||
colors[ImGuiCol_SliderGrab] = primaryColor;
|
||||
colors[ImGuiCol_SliderGrabActive] = ImVec4(0.54f, 0.33f, 0.88f, 1.0f);
|
||||
|
||||
colors[ImGuiCol_Header] = primaryColor;
|
||||
colors[ImGuiCol_HeaderHovered] = ImVec4(0.54f, 0.33f, 0.88f, 1.0f);
|
||||
colors[ImGuiCol_HeaderActive] = ImVec4(0.34f, 0.13f, 0.68f, 1.0f);
|
||||
|
||||
colors[ImGuiCol_Separator] = ImVec4(0.34f, 0.13f, 0.68f, 1.0f);
|
||||
colors[ImGuiCol_SeparatorHovered] = primaryColor;
|
||||
colors[ImGuiCol_SeparatorActive] = ImVec4(0.54f, 0.33f, 0.88f, 1.0f);
|
||||
|
||||
colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
|
||||
|
||||
colors[ImGuiCol_Tab] = ImVec4(0.17f, 0.17f, 0.21f, 1.0f);
|
||||
colors[ImGuiCol_TabHovered] = ImVec4(0.44f, 0.23f, 0.78f, 0.8f);
|
||||
colors[ImGuiCol_TabActive] = primaryColor;
|
||||
colors[ImGuiCol_TabUnfocused] = ImVec4(0.17f, 0.17f, 0.21f, 1.0f);
|
||||
colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.34f, 0.13f, 0.68f, 1.0f);
|
||||
|
||||
colors[ImGuiCol_Border] = outlineColor;
|
||||
colors[ImGuiCol_BorderShadow] = ImVec4(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
|
||||
style.WindowRounding = 0.0f;
|
||||
style.FrameRounding = 0.0f;
|
||||
style.ScrollbarRounding = 0.0f;
|
||||
style.GrabRounding = 0.0f;
|
||||
style.TabRounding = 0.0f;
|
||||
style.ChildRounding = 0.0f;
|
||||
style.PopupRounding = 0.0f;
|
||||
|
||||
style.ItemSpacing = ImVec2(8, 4);
|
||||
style.FramePadding = ImVec2(4, 3);
|
||||
style.WindowPadding = ImVec2(8, 8);
|
||||
|
||||
style.FrameBorderSize = 1.0f;
|
||||
style.TabBorderSize = 1.0f;
|
||||
style.WindowBorderSize = 1.0f;
|
||||
style.PopupBorderSize = 1.0f;
|
||||
style.ChildBorderSize = 1.0f;
|
||||
|
||||
style.GrabMinSize = 7.0f;
|
||||
}
|
||||
|
||||
Menu::Menu() {
|
||||
activeTab = 0;
|
||||
showMenu = true;
|
||||
}
|
||||
|
||||
void Menu::init(HWND& window, ID3D11Device* pDevice, ID3D11DeviceContext* pContext, ID3D11RenderTargetView* mainRenderTargetView) {
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.ConfigFlags = ImGuiConfigFlags_NoMouseCursorChange;
|
||||
ImGui_ImplWin32_Init(window);
|
||||
ImGui_ImplDX11_Init(pDevice, pContext);
|
||||
|
||||
ApplyImGuiTheme();
|
||||
|
||||
io.Fonts->AddFontFromFileTTF("C:\\Windows\\Fonts\\arial.ttf", 16.0f);
|
||||
|
||||
std::cout << "initialized menu\n";
|
||||
}
|
||||
|
||||
void Menu::render() {
|
||||
keybind.pollInputs();
|
||||
if (showMenu) {
|
||||
ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse |
|
||||
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoTitleBar;
|
||||
|
||||
ImGui::SetNextWindowSize(ImVec2(600, 400), ImGuiCond_Once);
|
||||
ImGui::SetNextWindowPos(ImVec2(50, 50), ImGuiCond_Once);
|
||||
|
||||
ImGui::Begin("TempleWare | Internal", nullptr, window_flags);
|
||||
|
||||
{
|
||||
float windowWidth = ImGui::GetWindowWidth();
|
||||
float rightTextWidth = ImGui::CalcTextSize("templecheats.xyz").x;
|
||||
|
||||
ImGui::Text("TempleWare - Internal");
|
||||
|
||||
ImGui::SameLine(windowWidth - rightTextWidth - 10);
|
||||
ImGui::Text("templecheats.xyz");
|
||||
}
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
const char* tabNames[] = { "Aim", "Visuals", "Misc", "Config" };
|
||||
|
||||
if (ImGui::BeginTabBar("MainTabBar", ImGuiTabBarFlags_NoTooltip)) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (ImGui::BeginTabItem(tabNames[i])) {
|
||||
activeTab = i;
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
}
|
||||
ImGui::EndTabBar();
|
||||
}
|
||||
|
||||
ImGui::BeginChild("ContentRegion", ImVec2(0, 0), false);
|
||||
|
||||
switch (activeTab) {
|
||||
case 0:
|
||||
{
|
||||
ImGui::BeginChild("AimLeft", ImVec2(ImGui::GetContentRegionAvail().x * 0.5f - 5, 0), true);
|
||||
ImGui::Text("General");
|
||||
ImGui::Separator();
|
||||
|
||||
ImGui::Checkbox("Enable##AimBot", &Config::aimbot);
|
||||
ImGui::SameLine();
|
||||
ImGui::Text("Key:");
|
||||
ImGui::SameLine();
|
||||
keybind.menuButton(Config::aimbot);
|
||||
|
||||
ImGui::Checkbox("Team Check", &Config::team_check);
|
||||
ImGui::SliderFloat("FOV", &Config::aimbot_fov, 0.f, 90.f);
|
||||
ImGui::Checkbox("Draw FOV Circle", &Config::fov_circle);
|
||||
if (Config::fov_circle) {
|
||||
ImGui::ColorEdit4("Circle Color##FovColor", (float*)&Config::fovCircleColor);
|
||||
}
|
||||
ImGui::Checkbox("Recoil Control", &Config::rcs);
|
||||
ImGui::EndChild();
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::BeginChild("AimRight", ImVec2(0, 0), true);
|
||||
ImGui::Text("TriggerBot");
|
||||
ImGui::Separator();
|
||||
ImGui::Text("No additional settings");
|
||||
|
||||
ImGui::EndChild();
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
{
|
||||
ImGui::BeginChild("VisualsLeft", ImVec2(ImGui::GetContentRegionAvail().x * 0.5f - 5, 0), true);
|
||||
ImGui::Text("Player ESP");
|
||||
ImGui::Separator();
|
||||
|
||||
ImGui::Checkbox("Box", &Config::esp);
|
||||
ImGui::SliderFloat("Thickness", &Config::espThickness, 1.0f, 5.0f);
|
||||
ImGui::Checkbox("Box Fill", &Config::espFill);
|
||||
if (Config::espFill) {
|
||||
ImGui::SliderFloat("Fill Opacity", &Config::espFillOpacity, 0.0f, 1.0f);
|
||||
}
|
||||
ImGui::ColorEdit4("ESP Color##BoxColor", (float*)&Config::espColor);
|
||||
ImGui::Checkbox("Team Check", &Config::teamCheck);
|
||||
ImGui::Checkbox("Health Bar", &Config::showHealth);
|
||||
ImGui::Checkbox("Name Tags", &Config::showNameTags);
|
||||
|
||||
ImGui::Spacing();
|
||||
ImGui::Text("World");
|
||||
ImGui::Separator();
|
||||
|
||||
ImGui::Checkbox("Night Mode", &Config::Night);
|
||||
if (Config::Night) {
|
||||
ImGui::ColorEdit4("Night Color", (float*)&Config::NightColor);
|
||||
}
|
||||
|
||||
ImGui::Checkbox("Custom FOV", &Config::fovEnabled);
|
||||
if (Config::fovEnabled) {
|
||||
ImGui::SliderFloat("FOV Value##FovSlider", &Config::fov, 20.0f, 160.0f, "%1.0f");
|
||||
}
|
||||
|
||||
ImGui::EndChild();
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::BeginChild("VisualsRight", ImVec2(0, 0), true);
|
||||
ImGui::Text("Chams");
|
||||
ImGui::Separator();
|
||||
|
||||
ImGui::Checkbox("Chams##ChamsCheckbox", &Config::enemyChams);
|
||||
const char* chamsMaterials[] = { "Flat", "Illuminate", "Glow" };
|
||||
ImGui::Combo("Material", &Config::chamsMaterial, chamsMaterials, IM_ARRAYSIZE(chamsMaterials));
|
||||
if (Config::enemyChams) {
|
||||
ImGui::ColorEdit4("Chams Color##ChamsColor", (float*)&Config::colVisualChams);
|
||||
}
|
||||
ImGui::Checkbox("Chams-XQZ", &Config::enemyChamsInvisible);
|
||||
if (Config::enemyChamsInvisible) {
|
||||
ImGui::ColorEdit4("XQZ Color##ChamsXQZColor", (float*)&Config::colVisualChamsIgnoreZ);
|
||||
}
|
||||
|
||||
ImGui::Spacing();
|
||||
ImGui::Text("Hand Chams");
|
||||
ImGui::Separator();
|
||||
|
||||
ImGui::Checkbox("Hand Chams", &Config::armChams);
|
||||
if (Config::armChams) {
|
||||
ImGui::ColorEdit4("Hand Color##HandChamsColor", (float*)&Config::colArmChams);
|
||||
}
|
||||
ImGui::Checkbox("Viewmodel Chams", &Config::viewmodelChams);
|
||||
if (Config::viewmodelChams) {
|
||||
ImGui::ColorEdit4("Viewmodel Color##ViewModelChamsColor", (float*)&Config::colViewmodelChams);
|
||||
}
|
||||
|
||||
ImGui::Spacing();
|
||||
ImGui::Text("Removals");
|
||||
ImGui::Separator();
|
||||
|
||||
ImGui::Checkbox("Anti Flash", &Config::antiflash);
|
||||
|
||||
ImGui::EndChild();
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
{
|
||||
ImGui::BeginChild("MiscLeft", ImVec2(ImGui::GetContentRegionAvail().x * 0.5f - 5, 0), true);
|
||||
ImGui::Text("Movement");
|
||||
ImGui::Separator();
|
||||
|
||||
ImGui::Text("No additional settings");
|
||||
|
||||
ImGui::EndChild();
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::BeginChild("MiscRight", ImVec2(0, 0), true);
|
||||
ImGui::Text("Other");
|
||||
ImGui::Separator();
|
||||
|
||||
ImGui::Text("No additional settings");
|
||||
|
||||
ImGui::EndChild();
|
||||
}
|
||||
break;
|
||||
|
||||
case 3:
|
||||
{
|
||||
ImGui::BeginChild("ConfigLeft", ImVec2(ImGui::GetContentRegionAvail().x * 0.5f - 5, 0), true);
|
||||
ImGui::Text("General");
|
||||
ImGui::Separator();
|
||||
|
||||
static char configName[128] = "";
|
||||
static std::vector<std::string> configList = internal_config::ConfigManager::ListConfigs();
|
||||
static int selectedConfigIndex = -1;
|
||||
|
||||
ImGui::InputText("Config Name", configName, IM_ARRAYSIZE(configName));
|
||||
|
||||
if (ImGui::Button("Refresh")) {
|
||||
configList = internal_config::ConfigManager::ListConfigs();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Load")) {
|
||||
internal_config::ConfigManager::Load(configName);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Save")) {
|
||||
internal_config::ConfigManager::Save(configName);
|
||||
configList = internal_config::ConfigManager::ListConfigs();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Delete")) {
|
||||
internal_config::ConfigManager::Remove(configName);
|
||||
configList = internal_config::ConfigManager::ListConfigs();
|
||||
}
|
||||
|
||||
ImGui::EndChild();
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::BeginChild("ConfigRight", ImVec2(0, 0), true);
|
||||
ImGui::Text("Saved Configs");
|
||||
ImGui::Separator();
|
||||
|
||||
for (int i = 0; i < static_cast<int>(configList.size()); i++) {
|
||||
if (ImGui::Selectable(configList[i].c_str(), selectedConfigIndex == i)) {
|
||||
selectedConfigIndex = i;
|
||||
strncpy_s(configName, sizeof(configName), configList[i].c_str(), _TRUNCATE);
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::EndChild();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
ImGui::EndChild();
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
||||
|
||||
void Menu::toggleMenu() {
|
||||
showMenu = !showMenu;
|
||||
}
|
||||
20
TempleWare-CS2/source/templeware/menu/menu.h
Normal file
20
TempleWare-CS2/source/templeware/menu/menu.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include <Windows.h>
|
||||
#include <d3d11.h>
|
||||
#include "../../../external/imgui/imgui.h"
|
||||
#include "../../../external/imgui/imgui_impl_dx11.h"
|
||||
#include "../../../external/imgui/imgui_impl_win32.h"
|
||||
|
||||
|
||||
class Menu {
|
||||
public:
|
||||
Menu();
|
||||
|
||||
void init(HWND& window, ID3D11Device* pDevice, ID3D11DeviceContext* pContext, ID3D11RenderTargetView* mainRenderTargetView);
|
||||
void render();
|
||||
|
||||
void toggleMenu();
|
||||
private:
|
||||
bool showMenu;
|
||||
int activeTab;
|
||||
};
|
||||
13
TempleWare-CS2/source/templeware/offsets/offsets.h
Normal file
13
TempleWare-CS2/source/templeware/offsets/offsets.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#include <cstddef>
|
||||
|
||||
namespace Offset {
|
||||
constexpr std::ptrdiff_t dwLocalPlayerPawn = 0x188BF30;
|
||||
|
||||
namespace C_BasePlayerPawn {
|
||||
constexpr std::ptrdiff_t m_vOldOrigin = 0x1324;
|
||||
constexpr std::ptrdiff_t m_iHealth = 0x344;
|
||||
constexpr std::ptrdiff_t m_iTeamNum = 0x3E3;
|
||||
constexpr std::ptrdiff_t m_vecViewOffset = 0xCB0;
|
||||
}
|
||||
}
|
||||
83
TempleWare-CS2/source/templeware/players/hook/playerHook.cpp
Normal file
83
TempleWare-CS2/source/templeware/players/hook/playerHook.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
#include "../../../cs2/datatypes/schema/ISchemaClass/ISchemaClass.h"
|
||||
#include "../players.h"
|
||||
#include "playerHook.h"
|
||||
|
||||
#include <iostream>
|
||||
/*
|
||||
// @READ ME: This should be storing Handles and not address pointers
|
||||
// it s hould store C_BaseEntity Handle
|
||||
// which can later globally be used to grab its right instance
|
||||
|
||||
|
||||
void onAddEntityHook(__int64 CGameEntitySystem, void* entityPointer, int entityHandle) {
|
||||
if (!entityPointer || !CGameEntitySystem || !entityHandle) {
|
||||
oOnAddEntity(CGameEntitySystem, entityPointer, entityHandle);
|
||||
return;
|
||||
}
|
||||
|
||||
uintptr_t uEntityPointer = reinterpret_cast<uintptr_t>(entityPointer);
|
||||
|
||||
SchemaClassInfoData_t* entityInfo = nullptr;
|
||||
GetSchemaClassInfo(uEntityPointer, &entityInfo);
|
||||
|
||||
if (entityInfo == nullptr) {
|
||||
oOnAddEntity(CGameEntitySystem, entityPointer, entityHandle);
|
||||
return;
|
||||
}
|
||||
|
||||
if (strcmp(entityInfo->szName, "C_CSPlayerPawn") == 0) {
|
||||
|
||||
Players::pawns.emplace_back(uEntityPointer);
|
||||
std::cout << "Added pawn " << Players::pawns.size() << "\n";
|
||||
|
||||
oOnAddEntity(CGameEntitySystem, entityPointer, entityHandle);
|
||||
return;
|
||||
}
|
||||
if (strcmp(entityInfo->szName, "CCSPlayerController") == 0) {
|
||||
|
||||
Players::controllers.emplace_back(uEntityPointer);
|
||||
|
||||
oOnAddEntity(CGameEntitySystem, entityPointer, entityHandle);
|
||||
return;
|
||||
}
|
||||
|
||||
oOnAddEntity(CGameEntitySystem, entityPointer, entityHandle);
|
||||
return;
|
||||
}
|
||||
|
||||
void onRemoveEntityHook(__int64 CGameEntitySystem, void* entityPointer, int entityHandle) {
|
||||
if (!entityPointer || !CGameEntitySystem || !entityHandle) {
|
||||
oOnRemoveEntity(CGameEntitySystem, entityPointer, entityHandle);
|
||||
return;
|
||||
}
|
||||
|
||||
uintptr_t uEntityPointer = reinterpret_cast<uintptr_t>(entityPointer);
|
||||
|
||||
SchemaClassInfoData_t* entityInfo = nullptr;
|
||||
GetSchemaClassInfo(uEntityPointer, &entityInfo);
|
||||
|
||||
if (strcmp(entityInfo->szName, "C_CSPlayerPawn") == 0) {
|
||||
for (auto it = Players::pawns.begin(); it != Players::pawns.end(); ++it) {
|
||||
if (it->getAddress() == uEntityPointer) {
|
||||
Players::pawns.erase(it);
|
||||
std::cout << "Removed pawn " << Players::pawns.size();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp(entityInfo->szName, "CCSPlayerController") == 0) {
|
||||
for (auto it = Players::controllers.begin(); it != Players::controllers.end(); ++it) {
|
||||
if (it->getAddress() == uEntityPointer) {
|
||||
Players::controllers.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
oOnRemoveEntity(CGameEntitySystem, entityPointer, entityHandle);
|
||||
return;
|
||||
}
|
||||
|
||||
onAddEntity oOnAddEntity = nullptr;
|
||||
onRemoveEntity oOnRemoveEntity = nullptr;*/
|
||||
21
TempleWare-CS2/source/templeware/players/hook/playerHook.h
Normal file
21
TempleWare-CS2/source/templeware/players/hook/playerHook.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include "../../hooks/includeHooks.h"
|
||||
|
||||
typedef void(__fastcall* onAddEntity)(__int64 CGameEntitySystem, void* entityPointer, int entityHandle);
|
||||
extern onAddEntity oOnAddEntity;
|
||||
|
||||
// @Author: basmannetjeeee
|
||||
// @IDA:
|
||||
// Signature: 48 89 74 24 ? 57 48 83 EC ? 48 8B F9 41 8B C0 B9
|
||||
// __int64 __fastcall sub_651290(__int64 a1, __int64 a2, int a3)
|
||||
void onAddEntityHook(__int64 CGameEntitySystem, void* entityPointer, int entityHandle);
|
||||
|
||||
|
||||
typedef void(__fastcall* onRemoveEntity)(__int64 CGameEntitySystem, void* entityPointer, int entityHandle);
|
||||
extern onRemoveEntity oOnRemoveEntity;
|
||||
|
||||
// @Author: basmannetjeeee
|
||||
// @IDA:
|
||||
// Signature: 48 89 74 24 ? 57 48 83 EC ? 48 8B F9 41 8B C0 25
|
||||
// __int64 __fastcall sub_651890(__int64 a1, _QWORD *a2, int a3)
|
||||
void onRemoveEntityHook(__int64 CGameEntitySystem, void* entityPointer, int entityHandle);
|
||||
5
TempleWare-CS2/source/templeware/players/players.cpp
Normal file
5
TempleWare-CS2/source/templeware/players/players.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
#include "players.h"
|
||||
#include "../offsets/offsets.h"
|
||||
//@not used anymore
|
||||
//std::vector<CCSPlayerController> Players::controllers;
|
||||
//std::vector<C_CSPlayerPawn> Players::pawns;
|
||||
8
TempleWare-CS2/source/templeware/players/players.h
Normal file
8
TempleWare-CS2/source/templeware/players/players.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../cs2/entity/CCSPlayerController/CCSPlayerController.h"
|
||||
#include "../../cs2/entity/C_CSPlayerPawn/C_CSPlayerPawn.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
//@not used anymore
|
||||
5546
TempleWare-CS2/source/templeware/renderer/icons.h
Normal file
5546
TempleWare-CS2/source/templeware/renderer/icons.h
Normal file
File diff suppressed because it is too large
Load Diff
12
TempleWare-CS2/source/templeware/renderer/renderer.h
Normal file
12
TempleWare-CS2/source/templeware/renderer/renderer.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "../menu/menu.h"
|
||||
#include "../features/visuals/visuals.h"
|
||||
#include "../menu/hud.h"
|
||||
|
||||
class Renderer {
|
||||
public:
|
||||
Menu menu;
|
||||
Esp::Visuals visuals;
|
||||
Hud hud;
|
||||
};
|
||||
48
TempleWare-CS2/source/templeware/templeware.cpp
Normal file
48
TempleWare-CS2/source/templeware/templeware.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
#include "templeware.h"
|
||||
|
||||
#include "utils/module/module.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <filesystem>
|
||||
#include "config/configmanager.h"
|
||||
|
||||
void TempleWare::init(HWND& window, ID3D11Device* pDevice, ID3D11DeviceContext* pContext, ID3D11RenderTargetView* mainRenderTargetView) {
|
||||
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
|
||||
auto printWithPrefix = [&](const char* message) {
|
||||
std::cout << "[";
|
||||
SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
|
||||
std::cout << "+";
|
||||
SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
|
||||
std::cout << "] " << message << std::endl;
|
||||
};
|
||||
|
||||
printWithPrefix("Initializing modules...");
|
||||
modules.init();
|
||||
|
||||
printWithPrefix("Initializing menu...");
|
||||
renderer.menu.init(window, pDevice, pContext, mainRenderTargetView);
|
||||
|
||||
printWithPrefix("Initializing schema...");
|
||||
schema.init("client.dll", 0);
|
||||
|
||||
printWithPrefix("Initializing Interfaces...");
|
||||
interfaces.init();
|
||||
|
||||
printWithPrefix("Initializing visuals...");
|
||||
renderer.visuals.init();
|
||||
|
||||
printWithPrefix("Initializing materials...");
|
||||
materials.init();
|
||||
|
||||
printWithPrefix("Initializing hooks...");
|
||||
hooks.init();
|
||||
|
||||
printWithPrefix("Success...");
|
||||
|
||||
// --- Автозагрузка конфига 1.json ---
|
||||
internal_config::ConfigManager::Load("1");
|
||||
printWithPrefix("Loaded config: 1.json");
|
||||
// --- конец автозагрузки ---
|
||||
}
|
||||
21
TempleWare-CS2/source/templeware/templeware.h
Normal file
21
TempleWare-CS2/source/templeware/templeware.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include "config/config.h"
|
||||
|
||||
#include "hooks/hooks.h"
|
||||
#include "renderer/renderer.h"
|
||||
#include "utils/schema/schema.h"
|
||||
#include "interfaces/interfaces.h"
|
||||
#include "features/chams/chams.h"
|
||||
class TempleWare {
|
||||
public:
|
||||
void init(HWND& window, ID3D11Device* pDevice, ID3D11DeviceContext* pContext, ID3D11RenderTargetView* mainRenderTargetView);
|
||||
|
||||
Schema schema;
|
||||
Renderer renderer;
|
||||
|
||||
|
||||
H::Hooks hooks;
|
||||
chams::Materials materials;
|
||||
I::Interfaces interfaces;
|
||||
|
||||
};
|
||||
20
TempleWare-CS2/source/templeware/utils/fnv1a/fnv1a.h
Normal file
20
TempleWare-CS2/source/templeware/utils/fnv1a/fnv1a.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
// FNV1a c++11 constexpr compile time hash functions, 32 and 64 bit
|
||||
// str should be a null terminated string literal, value should be left out
|
||||
// e.g hash_32_fnv1a_const("example")
|
||||
// code license: public domain or equivalent
|
||||
// post: https://notes.underscorediscovery.com/constexpr-fnv1a/
|
||||
|
||||
constexpr uint32_t val_32_const = 0x811c9dc5;
|
||||
constexpr uint32_t prime_32_const = 0x1000193;
|
||||
|
||||
inline constexpr uint32_t hash_32_fnv1a_const(const char* const str, const uint32_t value = val_32_const) noexcept
|
||||
{
|
||||
return (str[0] == '\0') ? value : hash_32_fnv1a_const(&str[1], (value ^ uint32_t(str[0])) * prime_32_const);
|
||||
}
|
||||
|
||||
// life do be like that
|
||||
|
||||
#define HASH hash_32_fnv1a_const
|
||||
33
TempleWare-CS2/source/templeware/utils/logging/log.cpp
Normal file
33
TempleWare-CS2/source/templeware/utils/logging/log.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include "log.h"
|
||||
#include "../../interfaces/interfaces.h"
|
||||
|
||||
// Temporary, will implement much more beautiful logging code wise (also I'm not really sorry for the watermark formatting :3)
|
||||
|
||||
void Logger::Log(const char* text, LogType logType) {
|
||||
std::string message;
|
||||
Color color(255, 255, 255, 255);
|
||||
|
||||
switch (logType) {
|
||||
case LogType::Info:
|
||||
message = "\n[*] ";
|
||||
break;
|
||||
case LogType::Warning:
|
||||
message = "\n[?] ";
|
||||
color = Color(255, 222, 105, 255);
|
||||
break;
|
||||
case LogType::Error:
|
||||
message = "\n[!] ";
|
||||
color = Color(255, 92, 87, 255);
|
||||
break;
|
||||
case LogType::None:
|
||||
message = "\n";
|
||||
}
|
||||
|
||||
message += text;
|
||||
I::ConColorMsg(color, message.c_str());
|
||||
}
|
||||
|
||||
void Logger::Watermark() {
|
||||
const char* watermark = "\n /$$$$$$$$ /$$ /$$ /$$ \n|__ $$__/ | $$ | $$ /$ | $$ \n | $$ /$$$$$$ /$$$$$$/$$$$ /$$$$$$ | $$ /$$$$$$ | $$ /$$$| $$ /$$$$$$ /$$$$$$ /$$$$$$ \n | $$ /$$__ $$| $$_ $$_ $$ /$$__ $$| $$ /$$__ $$| $$/$$ $$ $$ |____ $$ /$$__ $$ /$$__ $$\n | $$| $$$$$$$$| $$ \\ $$ \\ $$| $$ \\ $$| $$| $$$$$$$$| $$$$_ $$$$ /$$$$$$$| $$ \\__/| $$$$$$$$\n | $$| $$_____/| $$ | $$ | $$| $$ | $$| $$| $$_____/| $$$/ \\ $$$ /$$__ $$| $$ | $$_____/\n | $$| $$$$$$$| $$ | $$ | $$| $$$$$$$/| $$| $$$$$$$| $$/ \\ $$| $$$$$$$| $$ | $$$$$$$\n |__/ \\_______/|__/ |__/ |__/| $$____/ |__/ \\_______/|__/ \\__/ \\_______/|__/ \\_______/\n | $$ \n | $$ \n |__/ \n";
|
||||
I::ConColorMsg(Color(152, 52, 224, 255), watermark);
|
||||
}
|
||||
16
TempleWare-CS2/source/templeware/utils/logging/log.h
Normal file
16
TempleWare-CS2/source/templeware/utils/logging/log.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
enum LogType {
|
||||
Info,
|
||||
Warning,
|
||||
Error,
|
||||
None
|
||||
};
|
||||
|
||||
class Logger {
|
||||
public:
|
||||
// Using std::string for ease of use, overhead is practically non-existent
|
||||
static void Log(const char* text, LogType = LogType::Info);
|
||||
static void Watermark();
|
||||
};
|
||||
9
TempleWare-CS2/source/templeware/utils/math/math.h
Normal file
9
TempleWare-CS2/source/templeware/utils/math/math.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
#include <algorithm>
|
||||
|
||||
namespace Math {
|
||||
template <typename T>
|
||||
T clamp(T value, T min, T max) {
|
||||
return std::min(std::max(value, min), max);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,622 @@
|
||||
#pragma once
|
||||
#include <cstddef>
|
||||
#define debug(EXPRESSION) static_cast<void>(0)
|
||||
|
||||
#pragma warning (disable:4100)
|
||||
#pragma warning (disable:4514)
|
||||
|
||||
template <class T>
|
||||
inline void V_swap(T& x, T& y)
|
||||
{
|
||||
T temp = x;
|
||||
x = y;
|
||||
y = temp;
|
||||
}
|
||||
|
||||
template <class T, class N = size_t>
|
||||
class CUtlMemory
|
||||
{
|
||||
enum
|
||||
{
|
||||
EXTERNAL_BUFFER_MARKER = -1,
|
||||
EXTERNAL_CONST_BUFFER_MARKER = -2,
|
||||
};
|
||||
|
||||
public:
|
||||
class Iterator_t
|
||||
{
|
||||
public:
|
||||
Iterator_t(const N nIndex) :
|
||||
nIndex(nIndex) { }
|
||||
|
||||
bool operator==(const Iterator_t it) const
|
||||
{
|
||||
return nIndex == it.nIndex;
|
||||
}
|
||||
|
||||
bool operator!=(const Iterator_t it) const
|
||||
{
|
||||
return nIndex != it.nIndex;
|
||||
}
|
||||
|
||||
N nIndex;
|
||||
};
|
||||
|
||||
|
||||
CUtlMemory() :
|
||||
pMemory(nullptr), nAllocationCount(0), nGrowSize(0) { }
|
||||
|
||||
CUtlMemory& operator=(const CUtlMemory& rhs)
|
||||
{
|
||||
if (this != &rhs)
|
||||
{
|
||||
|
||||
pMemory = rhs.pMemory;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
CUtlMemory(const int nInitialGrowSize, const int nAllocationCount) :
|
||||
pMemory(nullptr), nAllocationCount(nAllocationCount), nGrowSize(nInitialGrowSize)
|
||||
{
|
||||
|
||||
if (nAllocationCount > 0)
|
||||
pMemory = static_cast<T*>(alloca(nAllocationCount * sizeof(T)));
|
||||
}
|
||||
|
||||
CUtlMemory(T* pMemory, const int nElements) :
|
||||
pMemory(pMemory), nAllocationCount(nElements), nGrowSize(EXTERNAL_BUFFER_MARKER) { }
|
||||
|
||||
CUtlMemory(T* pMemory, const void* pElements, size_t size) :
|
||||
pMemory(pMemory), nAllocationCount(static_cast<N>(pElements / sizeof(T))), nGrowSize(size)
|
||||
{
|
||||
if (pElements != nullptr)
|
||||
{
|
||||
memcpy(pMemory, pElements, size);
|
||||
}
|
||||
}
|
||||
|
||||
~CUtlMemory()
|
||||
{
|
||||
Purge();
|
||||
}
|
||||
template<class T, class N>
|
||||
inline CUtlMemory(CUtlMemory&& moveFrom)
|
||||
{
|
||||
moveFrom.pMemory = nullptr;
|
||||
moveFrom.nAllocationCount = 0;
|
||||
moveFrom.nGrowSize = 0;
|
||||
}
|
||||
|
||||
template<class T, class N>
|
||||
inline CUtlMemory& operator=(CUtlMemory&& moveFrom)
|
||||
{
|
||||
T* pMemoryTemp = moveFrom.pMemory;
|
||||
const int nAllocationCountTemp = moveFrom.nAllocationCount;
|
||||
const int nGrowSizeTemp = moveFrom.nGrowSize;
|
||||
|
||||
moveFrom.pMemory = nullptr;
|
||||
moveFrom.nAllocationCount = 0;
|
||||
moveFrom.nGrowSize = 0;
|
||||
|
||||
Purge();
|
||||
|
||||
pMemory = pMemoryTemp;
|
||||
nAllocationCount = nAllocationCountTemp;
|
||||
nGrowSize = nGrowSizeTemp;
|
||||
return *this;
|
||||
}
|
||||
|
||||
[[nodiscard]] T& operator[](const N nIndex)
|
||||
{
|
||||
return pMemory[nIndex];
|
||||
}
|
||||
|
||||
[[nodiscard]] const T& operator[](const N nIndex) const
|
||||
{
|
||||
return pMemory[nIndex];
|
||||
}
|
||||
|
||||
[[nodiscard]] T& Element(const N nIndex)
|
||||
{
|
||||
return pMemory[nIndex];
|
||||
}
|
||||
|
||||
[[nodiscard]] const T& Element(const N nIndex) const
|
||||
{
|
||||
return pMemory[nIndex];
|
||||
}
|
||||
|
||||
[[nodiscard]] T* Base()
|
||||
{
|
||||
return pMemory;
|
||||
}
|
||||
|
||||
[[nodiscard]] const T* Base() const
|
||||
{
|
||||
return pMemory;
|
||||
}
|
||||
|
||||
[[nodiscard]] int AllocationCount() const
|
||||
{
|
||||
return nAllocationCount;
|
||||
}
|
||||
int AllocationNum() const
|
||||
{
|
||||
return nAllocationCount;
|
||||
}
|
||||
|
||||
|
||||
|
||||
[[nodiscard]] bool IsExternallyAllocated() const
|
||||
{
|
||||
return nGrowSize <= EXTERNAL_BUFFER_MARKER;
|
||||
}
|
||||
|
||||
[[nodiscard]] static N InvalidIndex()
|
||||
{
|
||||
return static_cast<N>(-1);
|
||||
}
|
||||
|
||||
[[nodiscard]] bool IsValidIndex(N nIndex) const
|
||||
{
|
||||
return (nIndex >= 0) && (nIndex < nAllocationCount);
|
||||
}
|
||||
|
||||
[[nodiscard]] Iterator_t First() const
|
||||
{
|
||||
return Iterator_t(IsValidIndex(0) ? 0 : InvalidIndex());
|
||||
}
|
||||
|
||||
[[nodiscard]] Iterator_t Next(const Iterator_t& it) const
|
||||
{
|
||||
return Iterator_t(IsValidIndex(it.nIndex + 1) ? it.nIndex + 1 : InvalidIndex());
|
||||
}
|
||||
|
||||
|
||||
[[nodiscard]] N GetIndex(const Iterator_t& it) const
|
||||
{
|
||||
return it.nIndex;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool IsIndexAfter(N nIndex, const Iterator_t& it) const
|
||||
{
|
||||
return nIndex > it.nIndex;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool IsValidIterator(const Iterator_t& it) const
|
||||
{
|
||||
return IsValidIndex(it.index);
|
||||
}
|
||||
|
||||
[[nodiscard]] Iterator_t InvalidIterator() const
|
||||
{
|
||||
return Iterator_t(InvalidIndex());
|
||||
}
|
||||
|
||||
void Grow(const int nCount = 1)
|
||||
{
|
||||
if (IsExternallyAllocated())
|
||||
return;
|
||||
|
||||
int nAllocationRequested = nAllocationCount + nCount;
|
||||
int nNewAllocationCount = 0;
|
||||
|
||||
if (nGrowSize)
|
||||
nAllocationCount = ((1 + ((nAllocationRequested - 1) / nGrowSize)) * nGrowSize);
|
||||
else
|
||||
{
|
||||
if (nAllocationCount == 0)
|
||||
nAllocationCount = (31 + sizeof(T)) / sizeof(T);
|
||||
|
||||
while (nAllocationCount < nAllocationRequested)
|
||||
nAllocationCount <<= 1;
|
||||
}
|
||||
|
||||
if (static_cast<int>(static_cast<N>(nNewAllocationCount)) < nAllocationRequested)
|
||||
{
|
||||
if (static_cast<int>(static_cast<N>(nNewAllocationCount)) == 0 && static_cast<int>(static_cast<N>(nNewAllocationCount - 1)) >= nAllocationRequested)
|
||||
--nNewAllocationCount;
|
||||
else
|
||||
{
|
||||
if (static_cast<int>(static_cast<N>(nAllocationRequested)) != nAllocationRequested)
|
||||
return;
|
||||
|
||||
while (static_cast<int>(static_cast<N>(nNewAllocationCount)) < nAllocationRequested)
|
||||
nNewAllocationCount = (nNewAllocationCount + nAllocationRequested) / 2;
|
||||
}
|
||||
}
|
||||
|
||||
nAllocationCount = nNewAllocationCount;
|
||||
|
||||
// @test: we can always call realloc, since it must allocate instead when passed null ptr
|
||||
if (pMemory != nullptr)
|
||||
pMemory = static_cast<T*>(realloc(pMemory, nAllocationCount * sizeof(T)));
|
||||
else
|
||||
pMemory = static_cast<T*>(alloca(nAllocationCount * sizeof(T)));
|
||||
}
|
||||
|
||||
void EnsureCapacity(const int nCapacity)
|
||||
{
|
||||
if (nAllocationCount >= nCapacity)
|
||||
return;
|
||||
|
||||
if (IsExternallyAllocated())
|
||||
{
|
||||
// can't grow a buffer whose memory was externally allocated
|
||||
debug(false);
|
||||
return;
|
||||
}
|
||||
|
||||
nAllocationCount = nCapacity;
|
||||
|
||||
// @test: we can always call realloc, since it must allocate instead when passed null ptr
|
||||
if (pMemory != nullptr)
|
||||
pMemory = static_cast<T*>(realloc(pMemory, nAllocationCount * sizeof(T)));
|
||||
else
|
||||
pMemory = static_cast<T*>(alloca(nAllocationCount * sizeof(T)));
|
||||
}
|
||||
|
||||
void ConvertToGrowableMemory(int nInitialGrowSize)
|
||||
{
|
||||
if (!IsExternallyAllocated())
|
||||
return;
|
||||
|
||||
nGrowSize = nInitialGrowSize;
|
||||
|
||||
if (nAllocationCount > 0)
|
||||
{
|
||||
const int nByteCount = nAllocationCount * sizeof(T);
|
||||
T* pGrowableMemory = static_cast<T*>(alloca(nByteCount));
|
||||
memcpy(pGrowableMemory, pMemory, nByteCount);
|
||||
pMemory = pGrowableMemory;
|
||||
}
|
||||
else
|
||||
pMemory = nullptr;
|
||||
}
|
||||
|
||||
void Purge()
|
||||
{
|
||||
if (IsExternallyAllocated())
|
||||
return;
|
||||
|
||||
if (pMemory != nullptr)
|
||||
{
|
||||
free(static_cast<void*>(pMemory));
|
||||
pMemory = nullptr;
|
||||
}
|
||||
|
||||
nAllocationCount = 0;
|
||||
}
|
||||
void Init(size_t nGrowSize, size_t nInitSize);
|
||||
|
||||
void SetExternalBuffer(T* pMemory, size_t numElements);
|
||||
|
||||
void AssumeMemory(T* pMemory, size_t numElements);
|
||||
|
||||
void* DetachMemory();
|
||||
|
||||
T* Detach();
|
||||
|
||||
CUtlMemory(const T* pMemory, size_t numElements);
|
||||
|
||||
void Swap(CUtlMemory< T, N >& mem);
|
||||
|
||||
void Purge(const int nElements)
|
||||
{
|
||||
debug(nElements >= 0);
|
||||
|
||||
if (nElements > nAllocationCount)
|
||||
{
|
||||
// ensure this isn't a grow request in disguise
|
||||
debug(nElements <= nAllocationCount);
|
||||
return;
|
||||
}
|
||||
|
||||
if (nElements == 0)
|
||||
{
|
||||
Purge();
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsExternallyAllocated() || nElements == nAllocationCount)
|
||||
return;
|
||||
|
||||
if (pMemory == nullptr)
|
||||
{
|
||||
// allocation count is non zero, but memory is null
|
||||
debug(false);
|
||||
return;
|
||||
}
|
||||
|
||||
nAllocationCount = nElements;
|
||||
pMemory = static_cast<T*>(realloc(pMemory, nAllocationCount * sizeof(T)));
|
||||
}
|
||||
|
||||
public:
|
||||
T* pMemory; // 0x00
|
||||
int nAllocationCount; // 0x04
|
||||
int nGrowSize;
|
||||
// 0x08
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Attaches the buffer to external memory....
|
||||
//-----------------------------------------------------------------------------
|
||||
template< class T, class N >
|
||||
void CUtlMemory<T, N>::SetExternalBuffer(T* pMemory, size_t numElements)
|
||||
{
|
||||
// Blow away any existing allocated memory
|
||||
Purge();
|
||||
|
||||
pMemory = pMemory;
|
||||
nAllocationCount = numElements;
|
||||
|
||||
// Indicate that we don't own the memory
|
||||
nGrowSize = EXTERNAL_BUFFER_MARKER;
|
||||
}
|
||||
|
||||
template< class T, class N >
|
||||
void CUtlMemory<T, N>::AssumeMemory(T* pMemory, size_t numElements)
|
||||
{
|
||||
// Blow away any existing allocated memory
|
||||
Purge();
|
||||
|
||||
// Simply take the pointer but don't mark us as external
|
||||
pMemory = pMemory;
|
||||
nAllocationCount = numElements;
|
||||
}
|
||||
|
||||
template< class T, class N >
|
||||
void* CUtlMemory<T, N>::DetachMemory()
|
||||
{
|
||||
if (IsExternallyAllocated())
|
||||
return NULL;
|
||||
|
||||
void* pMemory = pMemory;
|
||||
pMemory = 0;
|
||||
nAllocationCount = 0;
|
||||
return pMemory;
|
||||
}
|
||||
|
||||
template< class T, class N >
|
||||
inline T* CUtlMemory<T, N>::Detach()
|
||||
{
|
||||
return (T*)DetachMemory();
|
||||
}
|
||||
|
||||
|
||||
template<class T, class N>
|
||||
inline CUtlMemory<T, N>::CUtlMemory(const T* pMemory, size_t numElements) : nAllocationCount(static_cast<N>(numElements))
|
||||
{
|
||||
// Special marker indicating externally supplied modifiable memory
|
||||
this->pMemory = (T*)pMemory;
|
||||
nGrowSize = -2;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template< class T, class I >
|
||||
void CUtlMemory<T, I>::Init(size_t nGrowSize /*= 0*/, size_t nInitSize /*= 0*/)
|
||||
{
|
||||
Purge();
|
||||
nGrowSize = nGrowSize;
|
||||
nAllocationCount = nInitSize;
|
||||
ConvertToGrowableMemory(nGrowSize);
|
||||
if (nAllocationCount)
|
||||
{
|
||||
pMemory = (T*)malloc(nAllocationCount * sizeof(T));
|
||||
}
|
||||
}
|
||||
|
||||
template< class T, class N >
|
||||
void CUtlMemory<T, N>::Swap(CUtlMemory<T, N>& mem)
|
||||
{
|
||||
V_swap(nGrowSize, mem.nGrowSize);
|
||||
V_swap(pMemory, mem.pMemory);
|
||||
V_swap(nAllocationCount, mem.nAllocationCount);
|
||||
}
|
||||
|
||||
template <class T, int nAlignment>
|
||||
class CUtlMemoryAligned : public CUtlMemory<T>
|
||||
{
|
||||
public:
|
||||
// @note: not implemented
|
||||
};
|
||||
|
||||
template <class T, std::size_t SIZE, class I = int>
|
||||
class CUtlMemoryFixedGrowable : public CUtlMemory<T, I>
|
||||
{
|
||||
typedef CUtlMemory<T, I> BaseClass;
|
||||
|
||||
public:
|
||||
CUtlMemoryFixedGrowable(int nInitialGrowSize = 0, int nInitialSize = SIZE) :
|
||||
BaseClass(arrFixedMemory, SIZE)
|
||||
{
|
||||
debug(nInitialSize == 0 || nInitialSize == SIZE);
|
||||
nMallocGrowSize = nInitialGrowSize;
|
||||
}
|
||||
|
||||
void Grow(int nCount = 1)
|
||||
{
|
||||
if (this->IsExternallyAllocated())
|
||||
this->ConvertToGrowableMemory(nMallocGrowSize);
|
||||
|
||||
BaseClass::Grow(nCount);
|
||||
}
|
||||
|
||||
void EnsureCapacity(int nCapacity)
|
||||
{
|
||||
if (CUtlMemory<T>::nAllocationCount >= nCapacity)
|
||||
return;
|
||||
|
||||
if (this->IsExternallyAllocated())
|
||||
// can't grow a buffer whose memory was externally allocated
|
||||
this->ConvertToGrowableMemory(nMallocGrowSize);
|
||||
|
||||
BaseClass::EnsureCapacity(nCapacity);
|
||||
}
|
||||
|
||||
private:
|
||||
int nMallocGrowSize;
|
||||
T arrFixedMemory[SIZE];
|
||||
};
|
||||
|
||||
template <typename T, std::size_t SIZE, int nAlignment = 0>
|
||||
class CUtlMemoryFixed
|
||||
{
|
||||
public:
|
||||
CUtlMemoryFixed(const int nGrowSize = 0, const int nInitialCapacity = 0)
|
||||
{
|
||||
debug(nInitialCapacity == 0 || nInitialCapacity == SIZE);
|
||||
}
|
||||
|
||||
CUtlMemoryFixed(const T* pMemory, const int nElements)
|
||||
{
|
||||
debug(false);
|
||||
}
|
||||
|
||||
[[nodiscard]] static constexpr bool IsValidIndex(const int nIndex)
|
||||
{
|
||||
return (nIndex >= 0) && (nIndex < SIZE);
|
||||
}
|
||||
|
||||
// specify the invalid ('null') index that we'll only return on failure
|
||||
static constexpr int INVALID_INDEX = -1;
|
||||
|
||||
[[nodiscard]] static constexpr int InvalidIndex()
|
||||
{
|
||||
return INVALID_INDEX;
|
||||
}
|
||||
|
||||
[[nodiscard]] T* Base()
|
||||
{
|
||||
if (nAlignment == 0)
|
||||
return reinterpret_cast<T*>(&pMemory[0]);
|
||||
|
||||
return reinterpret_cast<T*>((reinterpret_cast<std::uintptr_t>(&pMemory[0]) + nAlignment - 1) & ~(nAlignment - 1));
|
||||
}
|
||||
|
||||
[[nodiscard]] const T* Base() const
|
||||
{
|
||||
if (nAlignment == 0)
|
||||
return reinterpret_cast<T*>(&pMemory[0]);
|
||||
|
||||
return reinterpret_cast<T*>((reinterpret_cast<std::uintptr_t>(&pMemory[0]) + nAlignment - 1) & ~(nAlignment - 1));
|
||||
}
|
||||
|
||||
[[nodiscard]] T& operator[](int nIndex)
|
||||
{
|
||||
debug(IsValidIndex(nIndex));
|
||||
return Base()[nIndex];
|
||||
}
|
||||
|
||||
[[nodiscard]] const T& operator[](int nIndex) const
|
||||
{
|
||||
debug(IsValidIndex(nIndex));
|
||||
return Base()[nIndex];
|
||||
}
|
||||
|
||||
[[nodiscard]] T& Element(int nIndex)
|
||||
{
|
||||
debug(IsValidIndex(nIndex));
|
||||
return Base()[nIndex];
|
||||
}
|
||||
|
||||
[[nodiscard]] const T& Element(int nIndex) const
|
||||
{
|
||||
debug(IsValidIndex(nIndex));
|
||||
return Base()[nIndex];
|
||||
}
|
||||
|
||||
[[nodiscard]] int AllocationCount() const
|
||||
{
|
||||
return SIZE;
|
||||
}
|
||||
|
||||
[[nodiscard]] int Count() const
|
||||
{
|
||||
return SIZE;
|
||||
}
|
||||
|
||||
void Grow(int nCount = 1)
|
||||
{
|
||||
debug(false);
|
||||
}
|
||||
|
||||
void EnsureCapacity(const int nCapacity)
|
||||
{
|
||||
debug(nCapacity <= SIZE);
|
||||
}
|
||||
|
||||
void Purge() { }
|
||||
|
||||
void Purge(const int nElements)
|
||||
{
|
||||
debug(false);
|
||||
}
|
||||
|
||||
[[nodiscard]] bool IsExternallyAllocated() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
class Iterator_t
|
||||
{
|
||||
public:
|
||||
Iterator_t(const int nIndex) :
|
||||
nIndex(nIndex) { }
|
||||
|
||||
bool operator==(const Iterator_t it) const
|
||||
{
|
||||
return nIndex == it.nIndex;
|
||||
}
|
||||
|
||||
bool operator!=(const Iterator_t it) const
|
||||
{
|
||||
return nIndex != it.nIndex;
|
||||
}
|
||||
|
||||
int nIndex;
|
||||
};
|
||||
|
||||
[[nodiscard]] Iterator_t First() const
|
||||
{
|
||||
return Iterator_t(IsValidIndex(0) ? 0 : InvalidIndex());
|
||||
}
|
||||
|
||||
[[nodiscard]] Iterator_t Next(const Iterator_t& it) const
|
||||
{
|
||||
return Iterator_t(IsValidIndex(it.nIndex + 1) ? it.nIndex + 1 : InvalidIndex());
|
||||
}
|
||||
|
||||
[[nodiscard]] int GetIndex(const Iterator_t& it) const
|
||||
{
|
||||
return it.nIndex;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool IsIndexAfter(int i, const Iterator_t& it) const
|
||||
{
|
||||
return i > it.nIndex;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool IsValidIterator(const Iterator_t& it) const
|
||||
{
|
||||
return IsValidIndex(it.nIndex);
|
||||
}
|
||||
|
||||
[[nodiscard]] Iterator_t InvalidIterator() const
|
||||
{
|
||||
return Iterator_t(InvalidIndex());
|
||||
}
|
||||
|
||||
private:
|
||||
char pMemory[SIZE * sizeof(T) + nAlignment];
|
||||
};
|
||||
@@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
template <size_t SIZE = 256>
|
||||
struct String_t
|
||||
{
|
||||
char szBuffer[SIZE];
|
||||
|
||||
// Constructor for formatting a string
|
||||
String_t(const char* szFormat, const char* arg1, const char* arg2)
|
||||
{
|
||||
CustomFormat(szFormat, arg1, arg2);
|
||||
}
|
||||
|
||||
// Custom format function (simplified for two arguments)
|
||||
void CustomFormat(const char* szFormat, const char* arg1, const char* arg2)
|
||||
{
|
||||
size_t idx = 0;
|
||||
const char* ptr = szFormat;
|
||||
|
||||
// Loop through the format string
|
||||
while (*ptr != '\0' && idx < SIZE - 1)
|
||||
{
|
||||
if (*ptr == '%' && *(ptr + 1) == 's') // Handle first "%s"
|
||||
{
|
||||
ptr += 2; // Skip "%s"
|
||||
const char* strArg = arg1;
|
||||
while (*strArg != '\0' && idx < SIZE - 1)
|
||||
{
|
||||
szBuffer[idx++] = *strArg++;
|
||||
}
|
||||
}
|
||||
else if (*ptr == '%' && *(ptr + 1) == 's') // Handle second "%s"
|
||||
{
|
||||
ptr += 2; // Skip "%s"
|
||||
const char* strArg = arg2;
|
||||
while (*strArg != '\0' && idx < SIZE - 1)
|
||||
{
|
||||
szBuffer[idx++] = *strArg++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
szBuffer[idx++] = *ptr++; // Copy the current character
|
||||
}
|
||||
}
|
||||
|
||||
szBuffer[idx] = '\0'; // Null terminate the string
|
||||
}
|
||||
|
||||
// Getter for the formatted data
|
||||
const char* Data() const
|
||||
{
|
||||
return this->szBuffer;
|
||||
}
|
||||
|
||||
// Clear the buffer
|
||||
void Clear()
|
||||
{
|
||||
szBuffer[0] = '\0';
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
struct ResourceBinding_t
|
||||
{
|
||||
void* pData;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class CStrongHandle
|
||||
{
|
||||
public:
|
||||
operator T* () const
|
||||
{
|
||||
if (pBinding == nullptr)
|
||||
return nullptr;
|
||||
|
||||
return static_cast<T*>(pBinding->pData);
|
||||
}
|
||||
|
||||
T* operator->() const
|
||||
{
|
||||
if (pBinding == nullptr)
|
||||
return nullptr;
|
||||
|
||||
return static_cast<T*>(pBinding->pData);
|
||||
}
|
||||
|
||||
const ResourceBinding_t* pBinding;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,336 @@
|
||||
#pragma once
|
||||
#include <cstddef>
|
||||
#include "..\utlmemory\utlmemory.h"
|
||||
|
||||
|
||||
template <class T, class A = CUtlMemory<T>>
|
||||
class CUtlVector
|
||||
{
|
||||
using CAllocator = A;
|
||||
|
||||
public:
|
||||
explicit CUtlVector(const int nGrowSize = 0, const int nInitialCapacity = 0) :
|
||||
memory(nGrowSize, nInitialCapacity), nSize(0), pElements(memory.Base()) { }
|
||||
|
||||
CUtlVector(T* pMemory, const int nInitialCapacity, const int nInitialCount = 0) :
|
||||
memory(pMemory, nInitialCapacity), nSize(nInitialCount), pElements(memory.Base()) { }
|
||||
|
||||
CUtlVector(const CUtlVector&) = delete;
|
||||
|
||||
~CUtlVector()
|
||||
{
|
||||
Purge();
|
||||
}
|
||||
|
||||
CUtlVector& operator=(const CUtlVector& vecOther)
|
||||
{
|
||||
debug(&vecOther != this);
|
||||
|
||||
const int nSourceCount = vecOther.Count();
|
||||
SetCount(nSourceCount);
|
||||
|
||||
for (int i = 0; i < nSourceCount; i++)
|
||||
(*this)[i] = vecOther[i];
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
[[nodiscard]] T& operator[](const int nIndex)
|
||||
{
|
||||
debug(IsValidIndex(nIndex));
|
||||
return memory[nIndex];
|
||||
}
|
||||
|
||||
[[nodiscard]] const T& operator[](const int nIndex) const
|
||||
{
|
||||
debug(IsValidIndex(nIndex));
|
||||
return memory[nIndex];
|
||||
}
|
||||
|
||||
[[nodiscard]] T& Element2(int nIndex) const
|
||||
{
|
||||
debug(IsValidIndex(nIndex));
|
||||
return memory[nIndex];
|
||||
}
|
||||
[[nodiscard]] T& Element(const int nIndex)
|
||||
{
|
||||
debug(IsValidIndex(nIndex));
|
||||
return memory[nIndex];
|
||||
}
|
||||
|
||||
[[nodiscard]] const T& Element(const int nIndex) const
|
||||
{
|
||||
debug(IsValidIndex(nIndex));
|
||||
return memory[nIndex];
|
||||
}
|
||||
|
||||
[[nodiscard]] T* Base()
|
||||
{
|
||||
return memory.Base();
|
||||
}
|
||||
|
||||
[[nodiscard]] const T* Base() const
|
||||
{
|
||||
return memory.Base();
|
||||
}
|
||||
|
||||
[[nodiscard]] int Count() const
|
||||
{
|
||||
return nSize;
|
||||
}
|
||||
|
||||
[[nodiscard]] int& Size()
|
||||
{
|
||||
return nSize;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool IsValidIndex(const int nIndex) const
|
||||
{
|
||||
return (nIndex >= 0) && (nIndex < nSize);
|
||||
}
|
||||
|
||||
void CopyFromArray(const T* pArraySource, int nArraySize)
|
||||
{
|
||||
|
||||
debug(memory.Base() == nullptr || pArraySource == nullptr || begin() >= (pArraySource + nArraySize) || pArraySource >= end());
|
||||
|
||||
|
||||
SetCount(nArraySize);
|
||||
|
||||
for (int i = 0; i < nArraySize; i++)
|
||||
(*this)[i] = pArraySource[i];
|
||||
}
|
||||
|
||||
void GrowVector(const int nCount = 1)
|
||||
{
|
||||
if (nSize + nCount > memory.AllocationCount())
|
||||
memory.Grow(nSize + nCount - memory.AllocationCount());
|
||||
|
||||
nSize += nCount;
|
||||
pElements = memory.Base();
|
||||
}
|
||||
|
||||
void EnsureCapacity(int nCapacity)
|
||||
{
|
||||
memory.EnsureCapacity(nCapacity);
|
||||
pElements = memory.Base();
|
||||
}
|
||||
|
||||
void Purge()
|
||||
{
|
||||
RemoveAll();
|
||||
memory.Purge();
|
||||
pElements = memory.Base();
|
||||
}
|
||||
|
||||
void ShiftElementsRight(const int nElement, const int nShift = 1)
|
||||
{
|
||||
debug(IsValidIndex(nElement) || nSize == 0 || nShift == 0);
|
||||
|
||||
if (const int nToMove = nSize - nElement - nShift; nToMove > 0 && nShift > 0)
|
||||
memmove(&Element(nElement + nShift), &Element(nElement), nToMove * sizeof(T));
|
||||
}
|
||||
|
||||
void ShiftElementsLeft(const int nElement, const int nShift = 1)
|
||||
{
|
||||
debug(IsValidIndex(nElement) || nSize == 0 || nShift == 0);
|
||||
|
||||
if (const int nToMove = nSize - nElement - nShift; nToMove > 0 && nShift > 0)
|
||||
memmove(&Element(nElement), &Element(nElement + nShift), nToMove * sizeof(T));
|
||||
}
|
||||
|
||||
int AddToHead()
|
||||
{
|
||||
return InsertBefore(0);
|
||||
}
|
||||
|
||||
int AddToHead(const T& source)
|
||||
{
|
||||
// can't insert something that's in the list. reallocation may hose us
|
||||
debug(memory.Base() == nullptr || &source < begin() || &source >= end());
|
||||
return InsertBefore(0, source);
|
||||
}
|
||||
|
||||
int AddMultipleToHead(const int nCount)
|
||||
{
|
||||
return InsertMultipleBefore(0, nCount);
|
||||
}
|
||||
|
||||
int AddToTail()
|
||||
{
|
||||
return InsertBefore(nSize);
|
||||
}
|
||||
|
||||
int AddToTail(const T& source)
|
||||
{
|
||||
// can't insert something that's in the list. reallocation may hose us
|
||||
debug(memory.Base() == nullptr || &source < begin() || &source >= end());
|
||||
return InsertBefore(nSize, source);
|
||||
}
|
||||
|
||||
int AddMultipleToTail(const int nCount)
|
||||
{
|
||||
return InsertMultipleBefore(nSize, nCount);
|
||||
}
|
||||
|
||||
void SetCount(const int nCount)
|
||||
{
|
||||
RemoveAll();
|
||||
AddMultipleToTail(nCount);
|
||||
}
|
||||
|
||||
int InsertBefore(const int nElement)
|
||||
{
|
||||
// can insert at the end
|
||||
debug(nElement == nSize || IsValidIndex(nElement));
|
||||
|
||||
GrowVector();
|
||||
ShiftElementsRight(nElement);
|
||||
new (&Element(nElement)) T;
|
||||
return nElement;
|
||||
}
|
||||
|
||||
int InsertMultipleBefore(const int nElement, const int nCount)
|
||||
{
|
||||
if (nCount == 0)
|
||||
return nElement;
|
||||
|
||||
|
||||
debug(nElement == nSize || IsValidIndex(nElement));
|
||||
|
||||
GrowVector(nCount);
|
||||
ShiftElementsRight(nElement, nCount);
|
||||
|
||||
|
||||
for (int i = 0; i < nElement; ++i)
|
||||
new (&Element(nElement + i)) T;
|
||||
|
||||
return nElement;
|
||||
}
|
||||
|
||||
int InsertBefore(const int nElement, const T& source)
|
||||
{
|
||||
|
||||
debug(memory.Base() == nullptr || &source < begin() || &source >= end());
|
||||
|
||||
debug(nElement == nSize || IsValidIndex(nElement));
|
||||
|
||||
GrowVector();
|
||||
ShiftElementsRight(nElement);
|
||||
new (&Element(nElement)) T(source);
|
||||
return nElement;
|
||||
}
|
||||
|
||||
int InsertMultipleBefore(const int nElement, const int nCount, const T* pSource)
|
||||
{
|
||||
if (nCount == 0)
|
||||
return nElement;
|
||||
|
||||
debug(nElement == nSize || IsValidIndex(nElement));
|
||||
|
||||
GrowVector(nCount);
|
||||
ShiftElementsRight(nElement, nCount);
|
||||
|
||||
if (pSource == nullptr)
|
||||
{
|
||||
for (int i = 0; i < nCount; ++i)
|
||||
new (&Element(nElement + i)) T;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < nCount; i++)
|
||||
new (&Element(nElement)) T(pSource[i]);
|
||||
}
|
||||
|
||||
return nElement;
|
||||
}
|
||||
|
||||
[[nodiscard]] int Find(const T& source) const
|
||||
{
|
||||
for (int i = 0; i < nSize; ++i)
|
||||
{
|
||||
if (Element(i) == source)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool FindAndRemove(const T& source)
|
||||
{
|
||||
if (const int nElement = Find(source); nElement != -1)
|
||||
{
|
||||
Remove(nElement);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Remove(const int nElement)
|
||||
{
|
||||
(&Element(nElement))->~T();
|
||||
ShiftElementsLeft(nElement);
|
||||
--nSize;
|
||||
}
|
||||
|
||||
void RemoveAll()
|
||||
{
|
||||
for (int i = nSize; --i >= 0;)
|
||||
(&Element(i))->~T();
|
||||
|
||||
nSize = 0;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto begin() noexcept
|
||||
{
|
||||
return memory.Base();
|
||||
}
|
||||
|
||||
[[nodiscard]] auto end() noexcept
|
||||
{
|
||||
return memory.Base() + nSize;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto begin() const noexcept
|
||||
{
|
||||
return memory.Base();
|
||||
}
|
||||
|
||||
[[nodiscard]] auto end() const noexcept
|
||||
{
|
||||
return memory.Base() + nSize;
|
||||
}
|
||||
|
||||
protected:
|
||||
int nSize;
|
||||
CAllocator memory;
|
||||
T* pElements;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class CUtlVectorAligned : public CUtlVector<T, CUtlMemoryAligned<T, alignof(T)>>
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
template <class T, std::size_t MAX_SIZE>
|
||||
class CUtlVectorFixed : public CUtlVector<T, CUtlMemoryFixed<T, MAX_SIZE>>
|
||||
{
|
||||
using CBaseClass = CUtlVector<T, CUtlMemoryFixed<T, MAX_SIZE>>;
|
||||
|
||||
public:
|
||||
explicit CUtlVectorFixed(int nGrowSize = 0, int nInitialCapacity = 0) :
|
||||
CBaseClass(nGrowSize, nInitialCapacity) { }
|
||||
|
||||
CUtlVectorFixed(T* pMemory, int nElements) :
|
||||
CBaseClass(pMemory, nElements) { }
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class C_NetworkUtlVectorBase
|
||||
{
|
||||
public:
|
||||
std::uint32_t nSize;
|
||||
T* pElements;
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
#include "vector.h"
|
||||
392
TempleWare-CS2/source/templeware/utils/math/vector/vector.h
Normal file
392
TempleWare-CS2/source/templeware/utils/math/vector/vector.h
Normal file
@@ -0,0 +1,392 @@
|
||||
#pragma once
|
||||
#include "../../module/module.h"
|
||||
|
||||
#include <limits>
|
||||
#include <cmath>
|
||||
|
||||
|
||||
struct QAngle_t;
|
||||
struct Matrix3x4_t;
|
||||
|
||||
struct Vector2D_t {
|
||||
constexpr Vector2D_t(const float x = 0.0f, const float y = 0.0f) :
|
||||
x(x), y(y) {
|
||||
}
|
||||
|
||||
[[nodiscard]] bool IsZero() const {
|
||||
return (this->x == 0.0f && this->y == 0.0f);
|
||||
}
|
||||
|
||||
float x = 0.0f, y = 0.0f;
|
||||
};
|
||||
|
||||
struct Vector_t {
|
||||
public:
|
||||
constexpr Vector_t(const float x = 0.0f, const float y = 0.0f, const float z = 0.0f) :
|
||||
x(x), y(y), z(z) {
|
||||
}
|
||||
|
||||
constexpr Vector_t(const float* arrVector) :
|
||||
x(arrVector[0]), y(arrVector[1]), z(arrVector[2]) {
|
||||
}
|
||||
|
||||
constexpr Vector_t(const Vector2D_t& vecBase2D) :
|
||||
x(vecBase2D.x), y(vecBase2D.y) {
|
||||
}
|
||||
|
||||
|
||||
[[nodiscard]] float& operator[](const int nIndex) {
|
||||
return reinterpret_cast<float*>(this)[nIndex];
|
||||
}
|
||||
|
||||
[[nodiscard]] const float& operator[](const int nIndex) const {
|
||||
return reinterpret_cast<const float*>(this)[nIndex];
|
||||
}
|
||||
|
||||
constexpr Vector_t& operator=(const Vector_t& vecBase) {
|
||||
this->x = vecBase.x;
|
||||
this->y = vecBase.y;
|
||||
this->z = vecBase.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vector_t& operator=(const Vector2D_t& vecBase2D) {
|
||||
this->x = vecBase2D.x;
|
||||
this->y = vecBase2D.y;
|
||||
this->z = 0.0f;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vector_t& operator+=(const Vector_t& vecBase) {
|
||||
this->x += vecBase.x;
|
||||
this->y += vecBase.y;
|
||||
this->z += vecBase.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vector_t& operator-=(const Vector_t& vecBase) {
|
||||
this->x -= vecBase.x;
|
||||
this->y -= vecBase.y;
|
||||
this->z -= vecBase.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vector_t& operator*=(const Vector_t& vecBase) {
|
||||
this->x *= vecBase.x;
|
||||
this->y *= vecBase.y;
|
||||
this->z *= vecBase.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vector_t& operator/=(const Vector_t& vecBase) {
|
||||
this->x /= vecBase.x;
|
||||
this->y /= vecBase.y;
|
||||
this->z /= vecBase.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vector_t& operator+=(const float flAdd) {
|
||||
this->x += flAdd;
|
||||
this->y += flAdd;
|
||||
this->z += flAdd;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vector_t& operator-=(const float flSubtract) {
|
||||
this->x -= flSubtract;
|
||||
this->y -= flSubtract;
|
||||
this->z -= flSubtract;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vector_t& operator*=(const float flMultiply) {
|
||||
this->x *= flMultiply;
|
||||
this->y *= flMultiply;
|
||||
this->z *= flMultiply;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vector_t& operator/=(const float flDivide) {
|
||||
this->x /= flDivide;
|
||||
this->y /= flDivide;
|
||||
this->z /= flDivide;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vector_t& operator-() {
|
||||
this->x = -this->x;
|
||||
this->y = -this->y;
|
||||
this->z = -this->z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Vector_t operator-() const {
|
||||
return { -this->x, -this->y, -this->z };
|
||||
}
|
||||
|
||||
Vector_t operator+(const Vector_t& vecAdd) const {
|
||||
return { this->x + vecAdd.x, this->y + vecAdd.y, this->z + vecAdd.z };
|
||||
}
|
||||
|
||||
Vector_t operator-(const Vector_t& vecSubtract) const {
|
||||
return { this->x - vecSubtract.x, this->y - vecSubtract.y, this->z - vecSubtract.z };
|
||||
}
|
||||
|
||||
Vector_t operator*(const Vector_t& vecMultiply) const {
|
||||
return { this->x * vecMultiply.x, this->y * vecMultiply.y, this->z * vecMultiply.z };
|
||||
}
|
||||
|
||||
Vector_t operator/(const Vector_t& vecDivide) const {
|
||||
return { this->x / vecDivide.x, this->y / vecDivide.y, this->z / vecDivide.z };
|
||||
}
|
||||
|
||||
Vector_t operator+(const float flAdd) const {
|
||||
return { this->x + flAdd, this->y + flAdd, this->z + flAdd };
|
||||
}
|
||||
|
||||
Vector_t operator-(const float flSubtract) const {
|
||||
return { this->x - flSubtract, this->y - flSubtract, this->z - flSubtract };
|
||||
}
|
||||
|
||||
Vector_t operator*(const float flMultiply) const {
|
||||
return { this->x * flMultiply, this->y * flMultiply, this->z * flMultiply };
|
||||
}
|
||||
|
||||
Vector_t operator/(const float flDivide) const {
|
||||
return { this->x / flDivide, this->y / flDivide, this->z / flDivide };
|
||||
}
|
||||
Vector_t Normalize() const {
|
||||
float len = Length();
|
||||
if (len != 0)
|
||||
return { x / len, y / len, z / len };
|
||||
return { 0, 0, 0 };
|
||||
}
|
||||
float Length() const {
|
||||
return std::sqrt(x * x + y * y + z * z);
|
||||
}
|
||||
float Distance(const Vector_t& other) const {
|
||||
return std::sqrt((x - other.x) * (x - other.x) +
|
||||
(y - other.y) * (y - other.y) +
|
||||
(z - other.z) * (z - other.z));
|
||||
}
|
||||
|
||||
float x = 0.0f, y = 0.0f, z = 0.0f;
|
||||
};
|
||||
|
||||
struct Vector4D_t {
|
||||
constexpr Vector4D_t(const float x = 0.0f, const float y = 0.0f, const float z = 0.0f, const float w = 0.0f) :
|
||||
x(x), y(y), z(z), w(w) {
|
||||
}
|
||||
|
||||
float x = 0.0f, y = 0.0f, z = 0.0f, w = 0.0f;
|
||||
};
|
||||
|
||||
struct alignas(16) VectorAligned_t : Vector_t {
|
||||
VectorAligned_t() = default;
|
||||
|
||||
explicit VectorAligned_t(const Vector_t& vecBase) {
|
||||
this->x = vecBase.x;
|
||||
this->y = vecBase.y;
|
||||
this->z = vecBase.z;
|
||||
this->w = 0.0f;
|
||||
}
|
||||
|
||||
constexpr VectorAligned_t& operator=(const Vector_t& vecBase) {
|
||||
this->x = vecBase.x;
|
||||
this->y = vecBase.y;
|
||||
this->z = vecBase.z;
|
||||
this->w = 0.0f;
|
||||
return *this;
|
||||
}
|
||||
|
||||
float w = 0.0f;
|
||||
};
|
||||
|
||||
struct Matrix3x4_t;
|
||||
|
||||
struct QAngle_t {
|
||||
constexpr QAngle_t(float x = 0.f, float y = 0.f, float z = 0.f) :
|
||||
x(x), y(y), z(z) {
|
||||
}
|
||||
|
||||
constexpr QAngle_t(const float* arrAngles) :
|
||||
x(arrAngles[0]), y(arrAngles[1]), z(arrAngles[2]) {
|
||||
}
|
||||
|
||||
#pragma region qangle_array_operators
|
||||
|
||||
[[nodiscard]] float& operator[](const int nIndex) {
|
||||
return reinterpret_cast<float*>(this)[nIndex];
|
||||
}
|
||||
|
||||
[[nodiscard]] const float& operator[](const int nIndex) const {
|
||||
return reinterpret_cast<const float*>(this)[nIndex];
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region qangle_relational_operators
|
||||
|
||||
bool operator==(const QAngle_t& angBase) const {
|
||||
return this->IsEqual(angBase);
|
||||
}
|
||||
|
||||
bool operator!=(const QAngle_t& angBase) const {
|
||||
return !this->IsEqual(angBase);
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region qangle_assignment_operators
|
||||
|
||||
constexpr QAngle_t& operator=(const QAngle_t& angBase) {
|
||||
this->x = angBase.x;
|
||||
this->y = angBase.y;
|
||||
this->z = angBase.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region qangle_arithmetic_assignment_operators
|
||||
|
||||
constexpr QAngle_t& operator+=(const QAngle_t& angBase) {
|
||||
this->x += angBase.x;
|
||||
this->y += angBase.y;
|
||||
this->z += angBase.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr QAngle_t& operator-=(const QAngle_t& angBase) {
|
||||
this->x -= angBase.x;
|
||||
this->y -= angBase.y;
|
||||
this->z -= angBase.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr QAngle_t& operator*=(const QAngle_t& angBase) {
|
||||
this->x *= angBase.x;
|
||||
this->y *= angBase.y;
|
||||
this->z *= angBase.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr QAngle_t& operator/=(const QAngle_t& angBase) {
|
||||
this->x /= angBase.x;
|
||||
this->y /= angBase.y;
|
||||
this->z /= angBase.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr QAngle_t& operator+=(const float flAdd) {
|
||||
this->x += flAdd;
|
||||
this->y += flAdd;
|
||||
this->z += flAdd;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr QAngle_t& operator-=(const float flSubtract) {
|
||||
this->x -= flSubtract;
|
||||
this->y -= flSubtract;
|
||||
this->z -= flSubtract;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr QAngle_t& operator*=(const float flMultiply) {
|
||||
this->x *= flMultiply;
|
||||
this->y *= flMultiply;
|
||||
this->z *= flMultiply;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr QAngle_t& operator/=(const float flDivide) {
|
||||
this->x /= flDivide;
|
||||
this->y /= flDivide;
|
||||
this->z /= flDivide;
|
||||
return *this;
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region qangle_arithmetic_unary_operators
|
||||
|
||||
constexpr QAngle_t& operator-() {
|
||||
this->x = -this->x;
|
||||
this->y = -this->y;
|
||||
this->z = -this->z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr QAngle_t operator-() const {
|
||||
return { -this->x, -this->y, -this->z };
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region qangle_arithmetic_ternary_operators
|
||||
|
||||
constexpr QAngle_t operator+(const QAngle_t& angAdd) const {
|
||||
return { this->x + angAdd.x, this->y + angAdd.y, this->z + angAdd.z };
|
||||
}
|
||||
|
||||
constexpr QAngle_t operator-(const QAngle_t& angSubtract) const {
|
||||
return { this->x - angSubtract.x, this->y - angSubtract.y, this->z - angSubtract.z };
|
||||
}
|
||||
|
||||
constexpr QAngle_t operator*(const QAngle_t& angMultiply) const {
|
||||
return { this->x * angMultiply.x, this->y * angMultiply.y, this->z * angMultiply.z };
|
||||
}
|
||||
|
||||
constexpr QAngle_t operator/(const QAngle_t& angDivide) const {
|
||||
return { this->x / angDivide.x, this->y / angDivide.y, this->z / angDivide.z };
|
||||
}
|
||||
|
||||
constexpr QAngle_t operator+(const float flAdd) const {
|
||||
return { this->x + flAdd, this->y + flAdd, this->z + flAdd };
|
||||
}
|
||||
|
||||
constexpr QAngle_t operator-(const float flSubtract) const {
|
||||
return { this->x - flSubtract, this->y - flSubtract, this->z - flSubtract };
|
||||
}
|
||||
|
||||
constexpr QAngle_t operator*(const float flMultiply) const {
|
||||
return { this->x * flMultiply, this->y * flMultiply, this->z * flMultiply };
|
||||
}
|
||||
|
||||
constexpr QAngle_t operator/(const float flDivide) const {
|
||||
return { this->x / flDivide, this->y / flDivide, this->z / flDivide };
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
[[nodiscard]] bool IsValid() const {
|
||||
return (std::isfinite(this->x) && std::isfinite(this->y) && std::isfinite(this->z));
|
||||
}
|
||||
|
||||
[[nodiscard]] bool IsEqual(const QAngle_t& angEqual, const float flErrorMargin = std::numeric_limits<float>::epsilon()) const {
|
||||
return (std::fabsf(this->x - angEqual.x) < flErrorMargin && std::fabsf(this->y - angEqual.y) < flErrorMargin && std::fabsf(this->z - angEqual.z) < flErrorMargin);
|
||||
}
|
||||
|
||||
[[nodiscard]] bool IsZero() const {
|
||||
return (this->x == 0.0f && this->y == 0.0f && this->z == 0.0f);
|
||||
}
|
||||
|
||||
/// @returns: length of hypotenuse
|
||||
[[nodiscard]] float Length2D() const {
|
||||
return std::sqrtf(x * x + y * y);
|
||||
}
|
||||
|
||||
QAngle_t& Normalize() {
|
||||
this->x = std::remainderf(this->x, 360.f);
|
||||
this->y = std::remainderf(this->y, 360.f);
|
||||
this->z = std::remainderf(this->z, 360.f);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void ToDirections(Vector_t* pvecForward, Vector_t* pvecRight = nullptr, Vector_t* pvecUp = nullptr) const;
|
||||
|
||||
[[nodiscard]] Matrix3x4_t ToMatrix(const Vector_t& vecOrigin = {}) const;
|
||||
|
||||
public:
|
||||
float x = 0.0f, y = 0.0f, z = 0.0f;
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
#include "viewmatrix.h"
|
||||
|
||||
#include "../../../../../external/imgui/imgui.h"
|
||||
#include <iostream>
|
||||
|
||||
bool ViewMatrix::WorldToScreen(const Vector_t& position, Vector_t& out) const {
|
||||
const float w = viewMatrix->matrix[3][0] * position.x + viewMatrix->matrix[3][1] * position.y + viewMatrix->matrix[3][2] * position.z + viewMatrix->matrix[3][3];
|
||||
if (w <= 0.001f)
|
||||
return false;
|
||||
|
||||
const float invW = 1.0f / w;
|
||||
|
||||
ImVec2 wS = ImGui::GetIO().DisplaySize;
|
||||
|
||||
const float centerX = static_cast<float>(wS.x) / 2;
|
||||
const float centerY = static_cast<float>(wS.y) / 2;
|
||||
|
||||
out.x = centerX + ((viewMatrix->matrix[0][0] * position.x + viewMatrix->matrix[0][1] * position.y + viewMatrix->matrix[0][2] * position.z + viewMatrix->matrix[0][3]) * invW * centerX);
|
||||
out.y = centerY - ((viewMatrix->matrix[1][0] * position.x + viewMatrix->matrix[1][1] * position.y + viewMatrix->matrix[1][2] * position.z + viewMatrix->matrix[1][3]) * invW * centerY);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../../../cs2/datatypes/viewmatrix/viewmatrix.h"
|
||||
#include "../vector/vector.h"
|
||||
|
||||
class ViewMatrix {
|
||||
public:
|
||||
//Vector_t WorldToScreen(const Vector_t& position) const;
|
||||
bool WorldToScreen(const Vector_t& position, Vector_t& out) const;
|
||||
|
||||
viewmatrix_t* viewMatrix;
|
||||
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
#include <windows.h>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <string_view>
|
||||
namespace I {
|
||||
using InstantiateInterfaceFn = void* (*)();
|
||||
class CInterfaceReg
|
||||
{
|
||||
public:
|
||||
InstantiateInterfaceFn m_create_fn;
|
||||
const char* m_name;
|
||||
CInterfaceReg* m_next;
|
||||
};
|
||||
|
||||
inline const CInterfaceReg* Find(const char* module_name)
|
||||
{
|
||||
const HMODULE module_base = GetModuleHandleA(module_name);
|
||||
if (module_base == nullptr)
|
||||
return nullptr;
|
||||
|
||||
const auto symbol = reinterpret_cast<std::uintptr_t>(GetProcAddress(module_base, "CreateInterface"));
|
||||
const std::uintptr_t list = symbol + *reinterpret_cast<std::int32_t*>(symbol + 3) + 7;
|
||||
return *reinterpret_cast<CInterfaceReg**>(list);
|
||||
}
|
||||
template <typename T = void*>
|
||||
T* Get(const char* module_name, const char* interface_partial_version)
|
||||
{
|
||||
for (const CInterfaceReg* current = Find(module_name); current; current = current->m_next)
|
||||
{
|
||||
if (std::string_view(current->m_name).find(interface_partial_version) != std::string_view::npos)
|
||||
{
|
||||
return reinterpret_cast<T*>(current->m_create_fn());
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#include "gaa.h"
|
||||
|
||||
uintptr_t M::getAbsoluteAddress(uintptr_t addr, const int nPreOffset, const int nPostOffset) {
|
||||
addr += nPreOffset;
|
||||
int32_t nRva = *reinterpret_cast<int32_t*>(addr);
|
||||
addr += nPostOffset + sizeof(uint32_t) + nRva;
|
||||
return addr;
|
||||
}
|
||||
6
TempleWare-CS2/source/templeware/utils/memory/gaa/gaa.h
Normal file
6
TempleWare-CS2/source/templeware/utils/memory/gaa/gaa.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
namespace M {
|
||||
uintptr_t getAbsoluteAddress(uintptr_t addr, const int nPreOffset, const int nPostOffset = 0);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#define CS_CONCATENATE_DETAIL(x, y) x##y
|
||||
#define CS_CONCATENATE(x, y) CS_CONCATENATE_DETAIL(x, y)
|
||||
|
||||
#define MEM_PAD(SIZE) \
|
||||
private: \
|
||||
char CS_CONCATENATE(pad_, __COUNTER__)[SIZE]; \
|
||||
public:
|
||||
@@ -0,0 +1,132 @@
|
||||
#include "patternscan.h"
|
||||
|
||||
#include "../../module/module.h"
|
||||
|
||||
#include <Windows.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <span>
|
||||
#include <sstream>
|
||||
|
||||
#include <Psapi.h>
|
||||
#include <algorithm>
|
||||
#include <string_view>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
std::vector<std::pair<uint8_t, bool>> PatternToBytes(const std::string& pattern) {
|
||||
std::vector<std::pair<uint8_t, bool>> patternBytes;
|
||||
const char* start = pattern.c_str();
|
||||
const char* end = start + pattern.size();
|
||||
|
||||
for (const char* current = start; current < end; ++current) {
|
||||
if (*current == ' ') continue;
|
||||
if (*current == '?') {
|
||||
patternBytes.emplace_back(0, false);
|
||||
if (*(current + 1) == '?') ++current;
|
||||
}
|
||||
else {
|
||||
patternBytes.emplace_back(strtoul(current, nullptr, 16), true);
|
||||
if (*(current + 1) != ' ') ++current;
|
||||
}
|
||||
}
|
||||
|
||||
return patternBytes;
|
||||
}
|
||||
|
||||
uintptr_t M::patternScan(const std::string& module, const std::string& pattern) {
|
||||
uintptr_t baseAddress = modules.getModule(module);
|
||||
HMODULE hModule = reinterpret_cast<HMODULE>(baseAddress);
|
||||
|
||||
if (!hModule) return 0;
|
||||
|
||||
MODULEINFO moduleInfo;
|
||||
GetModuleInformation(GetCurrentProcess(), hModule, &moduleInfo, sizeof(MODULEINFO));
|
||||
|
||||
size_t moduleSize = moduleInfo.SizeOfImage;
|
||||
|
||||
std::vector<std::pair<uint8_t, bool>> patternBytes = PatternToBytes(pattern);
|
||||
size_t patternLength = patternBytes.size();
|
||||
|
||||
for (size_t i = 0; i < moduleSize - patternLength; ++i) {
|
||||
bool found = true;
|
||||
for (size_t j = 0; j < patternLength; ++j) {
|
||||
if (patternBytes[j].second && patternBytes[j].first != *reinterpret_cast<uint8_t*>(baseAddress + i + j)) {
|
||||
found = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found) {
|
||||
return baseAddress + i;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
std::uint8_t* M::FindPattern(const char* module_name, const std::string& byte_sequence)
|
||||
{
|
||||
// retrieve the handle to the specified module
|
||||
const HMODULE module = GetModuleHandleA(module_name);
|
||||
if (module == nullptr)
|
||||
return nullptr;
|
||||
|
||||
// retrieve the DOS header of the module
|
||||
const auto dos_header = reinterpret_cast<PIMAGE_DOS_HEADER>(module);
|
||||
if (dos_header->e_magic != IMAGE_DOS_SIGNATURE)
|
||||
return nullptr;
|
||||
|
||||
// retrieve the NT headers of the module
|
||||
const auto nt_headers = reinterpret_cast<PIMAGE_NT_HEADERS>(reinterpret_cast<std::uint8_t*>(module) + dos_header->e_lfanew);
|
||||
if (nt_headers->Signature != IMAGE_NT_SIGNATURE)
|
||||
return nullptr;
|
||||
|
||||
// get the size and base address of the code section
|
||||
DWORD m_size = nt_headers->OptionalHeader.SizeOfCode;
|
||||
std::uint8_t* m_base = reinterpret_cast<std::uint8_t*>(module) + nt_headers->OptionalHeader.BaseOfCode;
|
||||
|
||||
using SeqByte_t = std::pair< std::uint8_t, bool >;
|
||||
|
||||
std::string str{ };
|
||||
std::vector< std::pair< std::uint8_t, bool > > byte_sequence_vec{ };
|
||||
std::stringstream stream(byte_sequence);
|
||||
// parse the byte sequence string into a vector of byte sequence elements
|
||||
while (stream >> str)
|
||||
{
|
||||
// wildcard byte
|
||||
if (str[0u] == '?')
|
||||
{
|
||||
byte_sequence_vec.emplace_back(0u, true);
|
||||
continue;
|
||||
}
|
||||
|
||||
// invalid hex digit, skip this byte
|
||||
if (!std::isxdigit(str[0u]) || !std::isxdigit(str[1u]))
|
||||
continue;
|
||||
|
||||
byte_sequence_vec.emplace_back(static_cast<std::uint8_t>(std::strtoul(str.data(), nullptr, 16)), false);
|
||||
}
|
||||
|
||||
// end pointer of the code section
|
||||
const auto end = reinterpret_cast<std::uint8_t*>(m_base + m_size);
|
||||
|
||||
// search for the byte sequence within the code section
|
||||
const auto ret = std::search(reinterpret_cast<std::uint8_t*>(m_base), end, byte_sequence_vec.begin(), byte_sequence_vec.end(),
|
||||
[](const std::uint8_t byte, const std::pair< std::uint8_t, bool >& seq_byte)
|
||||
{
|
||||
return std::get< bool >(seq_byte) || byte == std::get< std::uint8_t >(seq_byte);
|
||||
});
|
||||
|
||||
// byte sequence found, return the pointer
|
||||
if (ret)
|
||||
return ret;
|
||||
#ifdef _DEBUG
|
||||
|
||||
// failed to find byte sequence, log error and return
|
||||
std::cout<< "failed to find pattern:" << byte_sequence.c_str() << " | inside: " << module_name << std::endl;
|
||||
|
||||
#endif
|
||||
return nullptr;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace M {
|
||||
template <typename T = std::uint8_t>
|
||||
T* abs(T* relative_address, int pre_offset = 0x0, int post_offset = 0x0)
|
||||
{
|
||||
relative_address += pre_offset;
|
||||
relative_address += sizeof(std::int32_t) + *reinterpret_cast<std::int32_t*>(relative_address);
|
||||
relative_address += post_offset;
|
||||
return relative_address;
|
||||
}
|
||||
std::uint8_t* FindPattern(const char* module_name, const std::string& byte_sequence);
|
||||
|
||||
uintptr_t patternScan(const std::string& module, const std::string& pattern);
|
||||
}
|
||||
12
TempleWare-CS2/source/templeware/utils/memory/vfunc/vfunc.h
Normal file
12
TempleWare-CS2/source/templeware/utils/memory/vfunc/vfunc.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
namespace M {
|
||||
template <typename T, std::size_t nIndex, class CBaseClass, typename... Args_t>
|
||||
static inline T vfunc(CBaseClass* thisptr, Args_t... argList) {
|
||||
using VirtualFn_t = T(__thiscall*)(const void*, decltype(argList)...);
|
||||
return (*reinterpret_cast<VirtualFn_t* const*>(reinterpret_cast<std::uintptr_t>(thisptr)))[nIndex](thisptr, argList...);
|
||||
}
|
||||
}
|
||||
38
TempleWare-CS2/source/templeware/utils/module/module.cpp
Normal file
38
TempleWare-CS2/source/templeware/utils/module/module.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include "module.h"
|
||||
#include <Windows.h>
|
||||
|
||||
Module::Module(uintptr_t moduleAddress, const std::string &moduleName) : address(moduleAddress), name(moduleName) {}
|
||||
|
||||
void Modules::init() {
|
||||
registerModule("client.dll", "client");
|
||||
registerModule("scenesystem.dll", "scenesystem");
|
||||
registerModule("particles.dll", "particles");
|
||||
registerModule("materialsystem2.dll", "materialsystem2");
|
||||
registerModule("tier0.dll", "tier0");
|
||||
registerModule("engine2.dll", "engine2");
|
||||
}
|
||||
|
||||
// Completely acceptable solution because there simply just aren't that many modules :)
|
||||
uintptr_t Modules::getModule(const std::string &moduleName) {
|
||||
for (const Module &m : modules) {
|
||||
if (m.name == moduleName) {
|
||||
return m.address;
|
||||
}
|
||||
}
|
||||
// No module found
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool Modules::registerModule(const std::string &aModuleName, const std::string &moduleName) {
|
||||
uintptr_t moduleHandle = reinterpret_cast<uintptr_t>(GetModuleHandle(aModuleName.c_str()));
|
||||
|
||||
if (!moduleHandle)
|
||||
return false;
|
||||
|
||||
Module module(moduleHandle, moduleName);
|
||||
modules.emplace_back(module);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Modules modules;
|
||||
28
TempleWare-CS2/source/templeware/utils/module/module.h
Normal file
28
TempleWare-CS2/source/templeware/utils/module/module.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// Class names might be too broad ngl -- just namespace them if someones ever really cares
|
||||
class Module {
|
||||
public:
|
||||
Module(uintptr_t moduleAddress, const std::string &moduleName);
|
||||
|
||||
uintptr_t address;
|
||||
std::string name;
|
||||
};
|
||||
|
||||
class Modules {
|
||||
public:
|
||||
void init();
|
||||
|
||||
uintptr_t getModule(const std::string &moduleName);
|
||||
private:
|
||||
// example usage: registerModule("client.dll", "client")
|
||||
bool registerModule(const std::string &aModuleName, const std::string &moduleName);
|
||||
|
||||
std::vector<Module> modules;
|
||||
};
|
||||
|
||||
// We luv global state
|
||||
extern Modules modules;
|
||||
88
TempleWare-CS2/source/templeware/utils/schema/schema.cpp
Normal file
88
TempleWare-CS2/source/templeware/utils/schema/schema.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
#include "schema.h"
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <Shlobj.h>
|
||||
#include <shlobj_core.h>
|
||||
|
||||
|
||||
#include "../fnv1a/fnv1a.h"
|
||||
|
||||
#include "../math/utlstring/utlstring.h"
|
||||
#include "../memory/Interface/Interface.h"
|
||||
|
||||
struct SchemaDumpedData_t
|
||||
{
|
||||
uint32_t hashedName = 0x0ULL;
|
||||
std::uint32_t uOffset = 0x0U;
|
||||
};
|
||||
|
||||
static std::vector<SchemaDumpedData_t> dumped_data;
|
||||
|
||||
bool Schema::init(const char* ModuleName, int module_type)
|
||||
{
|
||||
|
||||
schema_system = I::Get<ISchemaSystem>("schemasystem.dll", "SchemaSystem_00");
|
||||
if (!schema_system)
|
||||
return false;
|
||||
|
||||
CSchemaSystemTypeScope* pTypeScope = schema_system->FindTypeScopeForModule(ModuleName);
|
||||
if (pTypeScope == nullptr)
|
||||
return false;
|
||||
|
||||
const int nTableSize = pTypeScope->hashClasses.Count();
|
||||
|
||||
UtlTSHashHandle_t* pElements = new UtlTSHashHandle_t[nTableSize + 1U];
|
||||
const auto nElements = pTypeScope->hashClasses.GetElements(0, nTableSize, pElements);
|
||||
|
||||
for (int i = 0; i < nElements; i++)
|
||||
{
|
||||
const UtlTSHashHandle_t hElement = pElements[i];
|
||||
|
||||
if (hElement == 0)
|
||||
continue;
|
||||
|
||||
CSchemaClassBinding* pClassBinding = pTypeScope->hashClasses[hElement];
|
||||
if (pClassBinding == nullptr)
|
||||
continue;
|
||||
|
||||
SchemaClassInfoData_t* pDeclaredClassInfo;
|
||||
pTypeScope->FindDeclaredClass(&pDeclaredClassInfo, pClassBinding->szBinaryName);
|
||||
|
||||
if (pDeclaredClassInfo == nullptr)
|
||||
continue;
|
||||
|
||||
if (pDeclaredClassInfo->nFieldSize == 0)
|
||||
continue;
|
||||
|
||||
for (auto j = 0; j < pDeclaredClassInfo->nFieldSize; j++)
|
||||
{
|
||||
SchemaClassFieldData_t* pFields = pDeclaredClassInfo->pFields;
|
||||
std::string szFieldClassBuffer = std::string(pDeclaredClassInfo->szName) + "->" + std::string(pFields[j].szName);
|
||||
|
||||
dumped_data.emplace_back(hash_32_fnv1a_const(szFieldClassBuffer.c_str()), pFields[j].nSingleInheritanceOffset);
|
||||
}
|
||||
|
||||
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
|
||||
SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
|
||||
printf("[Schema] ");
|
||||
|
||||
SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
|
||||
printf("Dumped Class: %s fields: %i \n", pDeclaredClassInfo->szName, pDeclaredClassInfo->nFieldSize);
|
||||
}
|
||||
|
||||
delete[] pElements;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::uint32_t SchemaFinder::Get(const uint32_t hashedName)
|
||||
{
|
||||
if (const auto it = std::ranges::find_if(dumped_data, [hashedName](const SchemaDumpedData_t& data)
|
||||
{ return data.hashedName == hashedName; });
|
||||
it != dumped_data.end())
|
||||
return it->uOffset;
|
||||
|
||||
return 0U;
|
||||
}
|
||||
|
||||
41
TempleWare-CS2/source/templeware/utils/schema/schema.h
Normal file
41
TempleWare-CS2/source/templeware/utils/schema/schema.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
#include <memory>
|
||||
|
||||
#include "..\fnv1a\fnv1a.h"
|
||||
#include "..\memory\vfunc\vfunc.h"
|
||||
#include "..\math\utlmemory\utlmemory.h"
|
||||
#include "..\math\utlvector\utlvector.h"
|
||||
#include "..\..\..\cs2\datatypes\schema\ISchemaClass\ISchemaClass.h"
|
||||
|
||||
#define SCHEMA_ADD_OFFSET(TYPE, NAME, OFFSET) \
|
||||
[[nodiscard]] inline std::add_lvalue_reference_t<TYPE> NAME() \
|
||||
{ \
|
||||
static const std::uint32_t uOffset = OFFSET; \
|
||||
return *reinterpret_cast<std::add_pointer_t<TYPE>>(reinterpret_cast<std::uint8_t*>(this) + (uOffset)); \
|
||||
}
|
||||
|
||||
#define SCHEMA_ADD_POFFSET(TYPE, NAME, OFFSET) \
|
||||
[[nodiscard]] inline std::add_pointer_t<TYPE> NAME() \
|
||||
{ \
|
||||
const static std::uint32_t uOffset = OFFSET; \
|
||||
return reinterpret_cast<std::add_pointer_t<TYPE>>(reinterpret_cast<std::uint8_t*>(this) + (uOffset)); \
|
||||
}
|
||||
|
||||
|
||||
#define schema(TYPE, NAME, FIELD) SCHEMA_ADD_OFFSET(TYPE, NAME, SchemaFinder::Get(hash_32_fnv1a_const(FIELD)) + 0u)
|
||||
|
||||
#define schema_pfield(TYPE, NAME, FIELD, ADDITIONAL) SCHEMA_ADD_POFFSET(TYPE, NAME, SchemaFinder::Get(hash_32_fnv1a_const(FIELD)) + ADDITIONAL)
|
||||
|
||||
class Schema {
|
||||
public:
|
||||
bool init( const char* module_name, int module_type);
|
||||
|
||||
ISchemaSystem* schema_system = nullptr;
|
||||
|
||||
};
|
||||
|
||||
namespace SchemaFinder {
|
||||
|
||||
[[nodiscard]] std::uint32_t Get(const uint32_t hashed);
|
||||
[[nodiscard]] std::uint32_t GetExternal(const char* moduleName, const uint32_t HashedClass, const uint32_t HashedFieldName);
|
||||
}
|
||||
Reference in New Issue
Block a user