fidget spinner

This commit is contained in:
nullifiedcat 2017-07-04 23:56:46 +03:00
parent 06b561f2be
commit 52bddedb83
12 changed files with 143 additions and 13 deletions

View File

@ -35,7 +35,7 @@
<folderInfo id="cdt.managedbuild.config.gnu.exe.debug.1168214098." name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.exe.debug.965909756" name="Linux GCC" nonInternalBuilderId="cdt.managedbuild.target.gnu.builder.exe.debug" superClass="cdt.managedbuild.toolchain.gnu.exe.debug">
<targetPlatform id="cdt.managedbuild.target.gnu.platform.exe.debug.1799148153" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.exe.debug"/>
<builder arguments="-e GAME=tf2 NOIPC=1" buildPath="${workspace_loc:/cathook}" command="make" id="cdt.managedbuild.target.gnu.builder.exe.debug.1548213350" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="cdt.managedbuild.target.gnu.builder.exe.debug"/>
<builder arguments="-e GAME=tf2 NOIPC=1 BUILD_DEBUG=1" buildPath="${workspace_loc:/cathook}" command="make" id="cdt.managedbuild.target.gnu.builder.exe.debug.1548213350" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="cdt.managedbuild.target.gnu.builder.exe.debug"/>
<tool id="cdt.managedbuild.tool.gnu.archiver.base.782611349" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
<tool command="g++" id="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug.883030293" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug">
<option id="gnu.cpp.compiler.exe.debug.option.optimization.level.908662295" name="Optimization Level" superClass="gnu.cpp.compiler.exe.debug.option.optimization.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.optimization.level.none" valueType="enumerated"/>

BIN
res/atlas

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 272 KiB

After

Width:  |  Height:  |  Size: 300 KiB

Binary file not shown.

Binary file not shown.

View File

@ -47,6 +47,7 @@ extern "C" {
#include "offsets.hpp"
#include "drawing.h"
#include "entitycache.h"
#include "fidgetspinner.hpp"
#include "hoovy.hpp"
#include "enums.h"
#include "projlogging.hpp"

View File

@ -28,17 +28,6 @@ vertex_buffer_t* buffer_triangles_textured;
GLuint shader_v2fc4f;
GLuint shader_v2ft2fc4f;
struct vertex_v2c4_t {
vec2 xy;
vec4 rgba;
};
struct vertex_v2t2c4_t {
vec2 xy;
vec2 st;
vec4 rgba;
};
mat4 model, view, projection;
bool ready_state = false;

View File

@ -10,8 +10,29 @@
#include "drawing.h"
extern "C" {
#include "freetype-gl/vec234.h"
#include "freetype-gl/vertex-buffer.h"
}
namespace drawgl {
struct vertex_v2c4_t {
ftgl::vec2 xy;
ftgl::vec4 rgba;
};
struct vertex_v2t2c4_t {
ftgl::vec2 xy;
ftgl::vec2 st;
ftgl::vec4 rgba;
};
extern ftgl::vertex_buffer_t* buffer_lines;
extern ftgl::vertex_buffer_t* buffer_triangles_plain;
extern ftgl::vertex_buffer_t* buffer_triangles_textured;
extern const float white[4];
void Initialize();

View File

@ -24,7 +24,6 @@ CatVar info_text(CV_SWITCH, "info", "1", "Show info", "Show cathook version in t
void DrawCheatVisuals() {
std::lock_guard<std::mutex> draw_lock(drawing_mutex);
if (drawgl::ready_state) {
{
PROF_SECTION(DRAW_misc);
SAFE_CALL(hacks::shared::misc::DrawText());
@ -80,6 +79,7 @@ void DrawCheatVisuals() {
PROF_SECTION(PT_spyalert);
SAFE_CALL(hacks::tf::spyalert::Draw());
}
DrawSpinner();
{
PROF_SECTION(DRAW_esp);
hacks::shared::esp::Draw();

98
src/fidgetspinner.cpp Normal file
View File

@ -0,0 +1,98 @@
/*
* fidgetspinner.cpp
*
* Created on: Jul 4, 2017
* Author: nullifiedcat
*/
#include "fidgetspinner.hpp"
CatVar enable_spinner(CV_SWITCH, "fidgetspinner", "0", "Fidget Spinner", "Part of Cathook Autism Awareness program");
std::vector<textures::AtlasTexture> spinner_states {};
float spinning_speed = 0.0f;
float angle = 0;
// DEBUG
/*CatCommand add_spinner_speed("fidgetspinner_debug_speedup", "Add speed", []() {
spinning_speed += 100.0f;
});*/
class SpinnerListener : public IGameEventListener {
public:
virtual void FireGameEvent(KeyValues* event) {
std::string name(event->GetName());
if (name == "player_death") {
int attacker = event->GetInt("attacker");
int eid = g_IEngine->GetPlayerForUserID(attacker);
if (eid == g_IEngine->GetLocalPlayer()) {
spinning_speed += 300.0f;
//logging::Info("Spinning %.2f", spinning_speed);
}
}
}
};
SpinnerListener listener;
void InitSpinner() {
for (int i = 0; i < 4; i++)
spinner_states.emplace_back(i * 64, textures::atlas_height - 64 * 4, 64, 64);
g_IGameEventManager->AddListener(&listener, false);
}
CatVar spinner_speed_cap(CV_FLOAT, "fidgetspinner_speed_cap", "30", "Speed cap");
CatVar spinner_speed_scale(CV_FLOAT, "fidgetspinner_speed_scale", "0.03", "Speed scale");
CatVar spinner_decay_speed(CV_FLOAT, "fidgetspinner_decay_speed", "0.1", "Decay speed");
CatVar spinner_scale(CV_FLOAT, "fidgetspinner_scale", "32", "Spinner Size");
CatVar spinner_min_speed(CV_FLOAT, "fidgetspinner_min_speed", "2", "Spinner Min Speed");
void DrawSpinner() {
if (not enable_spinner) return;
spinning_speed -= (spinning_speed > 150.0f) ? float(spinner_decay_speed) : float(spinner_decay_speed) / 2.0f;
if (spinning_speed < float(spinner_min_speed)) spinning_speed = float(spinner_min_speed);
if (spinning_speed > 1000) spinning_speed = 1000;
float real_speed = 0;
const float speed_cap(spinner_speed_cap);
if (spinning_speed < 250) real_speed = speed_cap * (spinning_speed / 250.0f);
else if (spinning_speed < 500) real_speed = speed_cap - (speed_cap - 10) * ((spinning_speed - 250.0f) / 250.0f);
else if (spinning_speed < 750) real_speed = 10 + (speed_cap - 20) * ((spinning_speed - 500.0f) / 250.0f);
else real_speed = (speed_cap - 10) + 10 * ((spinning_speed - 750.0f) / 250.0f);
const float speed_scale(spinner_speed_scale);
const float size(spinner_scale);
ftgl::vec2 positions[4] = {
{ -size, -size },
{ size, -size },
{ size, size },
{ -size, size}
};
angle += speed_scale * real_speed;
for (int i = 0; i < 4; i++) {
float x = positions[i].x;
float y = positions[i].y;
positions[i].x = x * cos(angle) - y * sin(angle);
positions[i].y = x * sin(angle) + y * cos(angle);
positions[i].x += draw::width / 2;
positions[i].y += draw::height / 2;
}
int state = min(3, spinning_speed / 250.0f);
// Paste from drawgl::
using namespace drawgl;
using namespace ftgl;
const auto& u1v1 = spinner_states[state].tex_coords[0];
const auto& u2v2 = spinner_states[state].tex_coords[1];
GLuint idx = buffer_triangles_textured->vertices->size;
GLuint indices[] = { idx, idx + 1, idx + 2, idx, idx + 2, idx + 3 };
vertex_v2t2c4_t vertices[] = {
{ vec2{ positions[0].x, positions[0].y }, vec2{ u1v1.x, u2v2.y }, *reinterpret_cast<const vec4*>(&colors::white) },
{ vec2{ positions[1].x, positions[1].y }, vec2{ u2v2.x, u2v2.y }, *reinterpret_cast<const vec4*>(&colors::white) },
{ vec2{ positions[2].x, positions[2].y }, vec2{ u2v2.x, u1v1.y }, *reinterpret_cast<const vec4*>(&colors::white) },
{ vec2{ positions[3].x, positions[3].y }, vec2{ u1v1.x, u1v1.y }, *reinterpret_cast<const vec4*>(&colors::white) }
};
vertex_buffer_push_back_indices(buffer_triangles_textured, indices, 6);
vertex_buffer_push_back_vertices(buffer_triangles_textured, vertices, 4);
if (angle > PI * 4) angle -= PI * 4;
}

19
src/fidgetspinner.hpp Normal file
View File

@ -0,0 +1,19 @@
/*
* fidgetspinner.hpp
*
* Created on: Jul 4, 2017
* Author: nullifiedcat
*/
#pragma once
#include "common.h"
#include "atlas.hpp"
class CatVar;
extern CatVar enable_spinner;
extern std::vector<textures::AtlasTexture> spinner_states;
void InitSpinner();
void DrawSpinner();

View File

@ -270,6 +270,8 @@ void hack::Initialize() {
logging::Info("SDL hooking done");
g_IGameEventManager->AddListener(&adv_event_listener, false);
hacks::shared::anticheat::Init();
InitSpinner();
logging::Info("Initialized Fidget Spinner");
}