KillSay & Spam update, textfile rewrite, add format for std::string

This commit is contained in:
nullifiedcat 2017-03-17 23:16:16 +03:00
parent 9d2a19fdae
commit 6831d38f48
14 changed files with 131 additions and 129 deletions

View File

@ -13,7 +13,7 @@ namespace chat_stack {
void OnCreateMove() {
if (last_say > g_GlobalVars->curtime) last_say = 0;
if (g_GlobalVars->curtime - CHATSTACK_INTERVAL <= last_say) return;
if (g_GlobalVars->curtime - last_say <= CHATSTACK_INTERVAL) return;
std::string message;
if (!stack.empty()) {
message = stack.top();

View File

@ -185,17 +185,17 @@ void CMenuWindow::AddElements() {
AddTab("spam", "Spam/Killsay");
tab = GetTab("spam");
ADDLABEL("Spam");
ADDCVAR(g_phSpam->v_bSpam);
ADDCVAR(g_phSpam->v_bSpamNewlines);
ADDCVAR(g_phSpam->v_sSpamFile);
ADDCVAR(&hacks::shared::spam::enabled);
ADDCVAR(&hacks::shared::spam::newlines);
ADDCVAR(&hacks::shared::spam::filename);
tab->AddChild(new CBaseButton("spam_reload", tab, "Reload spam", [this](CBaseButton*) {
g_phSpam->Reload();
hacks::shared::spam::Reload();
}));
ADDLABEL("Killsay");
ADDCVAR(g_phKillSay->v_bEnabled);
ADDCVAR(g_phKillSay->v_sFileName);
ADDCVAR(&hacks::shared::killsay::enabled);
ADDCVAR(&hacks::shared::killsay::filename);
tab->AddChild(new CBaseButton("killsay_reload", tab, "Reload killsays", [this](CBaseButton*) {
g_phKillSay->Reload();
hacks::shared::killsay::Reload();
}));
}

View File

@ -61,8 +61,6 @@ void hack::InitHacks() {
ADD_HACK(Aimbot);
ADD_HACK(Bunnyhop);
ADD_HACK(ESP);
ADD_HACK(KillSay);
ADD_HACK(Spam);
}
ConCommand* hack::c_Cat = 0;
@ -165,8 +163,8 @@ void hack::Initialize() {
hooks::hkClient->Apply();
if (TF2) g_GlowObjectManager = *reinterpret_cast<CGlowObjectManager**>(gSignatures.GetClientSignature("C1 E0 05 03 05") + 5);
InitStrings();
hacks::shared::killsay::Init();
logging::Info("Init done.");
g_pChatStack = new ChatStack();
}
void hack::Think() {
@ -189,6 +187,5 @@ void hack::Shutdown() {
DELETE_HACK(Aimbot);
DELETE_HACK(Bunnyhop);
DELETE_HACK(ESP);
DELETE_HACK(KillSay);
DELETE_HACK(Spam);
hacks::shared::killsay::Shutdown();
}

View File

@ -10,9 +10,17 @@
#include "../sdk.h"
#include <pwd.h>
DEFINE_HACK_SINGLETON(KillSay);
void KillSayEventListener::FireGameEvent(IGameEvent* event) {
if (!hacks::shared::killsay::enabled) return;
std::string message = hacks::shared::killsay::ComposeKillSay(event);
if (message.size()) {
chat_stack::stack.push(message);
}
}
const char* tf_classes_killsay[] = {
namespace hacks { namespace shared { namespace killsay {
const std::string tf_classes_killsay[] = {
"class",
"scout",
"sniper",
@ -25,62 +33,56 @@ const char* tf_classes_killsay[] = {
"engineer"
};
const char* tf_teams_killsay[] = {
const std::string tf_teams_killsay[] = {
"RED",
"BLU"
};
void KillSayEventListener::FireGameEvent(IGameEvent* event) {
if (!g_phKillSay->v_bEnabled->GetBool()) return;
SEGV_BEGIN;
const char* msg = g_phKillSay->ComposeKillSay(event);
if (msg) {
g_pChatStack->Push(msg);
delete msg;
}
SEGV_END;
}
TextFile file {};
const char* KillSay::ComposeKillSay(IGameEvent* event) {
if (m_TextFile->GetLineCount() == 0) return 0;
std::string ComposeKillSay(IGameEvent* event) {
if (file.LineCount() == 0) return 0;
if (!event) return 0;
int vid = event->GetInt("userid");
int kid = event->GetInt("attacker");
if (kid == vid) return 0;
if (g_IEngine->GetPlayerForUserID(kid) != g_IEngine->GetLocalPlayer()) return 0;
char* msg = strfmt("%s", m_TextFile->GetLine(rand() % m_TextFile->GetLineCount()));
std::string msg = file.Line(rand() % file.LineCount());
player_info_s info;
g_IEngine->GetPlayerInfo(g_IEngine->GetPlayerForUserID(vid), &info);
ReplaceString(msg, "%name%", info.name);
ReplaceString(msg, "%name%", std::string(info.name));
CachedEntity* ent = ENTITY(g_IEngine->GetPlayerForUserID(vid));
int clz = g_pPlayerResource->GetClass(ent);
ReplaceString(msg, "%class%", (char*)tf_classes_killsay[clz]);
ReplaceString(msg, "%class%", tf_classes_killsay[clz]);
player_info_s infok;
g_IEngine->GetPlayerInfo(g_IEngine->GetPlayerForUserID(kid), &infok);
ReplaceString(msg, "%killer%", (char*)infok.name);
ReplaceString(msg, "%team%", (char*)tf_teams_killsay[ent->m_iTeam - 2]);
ReplaceString(msg, "%myteam%", (char*)tf_teams_killsay[LOCAL_E->m_iTeam - 2]);
ReplaceString(msg, "%myclass%", (char*)tf_classes_killsay[g_pPlayerResource->GetClass(LOCAL_E)]);
ReplaceString(msg, "%killer%", std::string(infok.name));
ReplaceString(msg, "%team%", tf_teams_killsay[ent->m_iTeam - 2]);
ReplaceString(msg, "%myteam%", tf_teams_killsay[LOCAL_E->m_iTeam - 2]);
ReplaceString(msg, "%myclass%", tf_classes_killsay[g_pPlayerResource->GetClass(LOCAL_E)]);
ReplaceString(msg, "\\n", "\n");
return msg;
}
KillSay::KillSay() {
v_bEnabled = new CatVar(CV_SWITCH, "killsay", "0", "KillSay", NULL, "Enable KillSay");
v_sFileName = new CatVar(CV_STRING, "killsay_file", "killsays.txt", "Killsay file (~/.cathook/)", NULL, "Killsay file name. Should be located in ~/.cathook folder.");
CreateConCommand("cat_killsay_reload", CC_KillSay_ReloadFile, "Reload KillSay");
m_TextFile = new TextFile(256, 1024);
g_IEventManager2->AddListener(&m_Listener, "player_death", false);
CatVar enabled(CV_SWITCH, "killsay", "0", "KillSay", "Enable KillSay");
CatVar filename(CV_STRING, "killsay_file", "killsays.txt", "Killsay file (~/.cathook/)", "Killsay file name. Should be located in ~/.cathook folder.");
CatCommand reload("killsay_reload", "Reload killsays", Reload);
KillSayEventListener& getListener() {
static KillSayEventListener listener;
return listener;
}
KillSay::~KillSay() {
g_IEventManager2->RemoveListener(&m_Listener);
void Reload() {
file.Load(std::string(filename.GetString()));
}
void KillSay::Reload() {
m_TextFile->LoadFile(v_sFileName->GetString());
void Init() {
g_IEventManager2->AddListener(&getListener(), (const char*)"player_death", false);
}
void CC_KillSay_ReloadFile(const CCommand& args) {
SAFE_CALL(g_phKillSay->Reload());
void Shutdown() {
g_IEventManager2->RemoveListener(&getListener());
}
}}}

View File

@ -13,29 +13,24 @@
#include "../fixsdk.h"
#include <igameevents.h>
class TextFile;
class CatCommand;
class KillSayEventListener : public IGameEventListener2 {
virtual void FireGameEvent(IGameEvent* event);
};
class KillSay : public IHack {
public:
KillSay();
~KillSay();
const char* ComposeKillSay(IGameEvent* evt);
void Reload();
namespace hacks { namespace shared { namespace killsay {
CatVar* v_bEnabled;
CatVar* v_sFileName;
extern CatVar enabled;
extern CatVar filename;
extern CatCommand reload;
TextFile* m_TextFile;
KillSayEventListener m_Listener;
};
void Init();
void Shutdown();
void Reload();
std::string ComposeKillSay(IGameEvent* event);
//void CC_PushKillsayDBG(const CCommand& args);
void CC_KillSay_ReloadFile(const CCommand& args);
DECLARE_HACK_SINGLETON(KillSay);
}}}
#endif /* HACKS_KILLSAY_H_ */

View File

@ -10,50 +10,38 @@
#include "../sdk.h"
#include <pwd.h>
DEFINE_HACK_SINGLETON(Spam);
namespace hacks { namespace shared { namespace spam {
Spam::Spam() {
v_bSpam = new CatVar(CV_SWITCH, "spam", "0", "Chat spam", NULL, "Enable Spam");
v_bSpamNewlines = new CatVar(CV_SWITCH, "spam_newlines", "1", "Prepend newlines to messages", NULL, "If enabled, several newlines will be added before each message");
v_sSpamFile = new CatVar(CV_STRING, "spam_file", "spam.txt", "Spam file (~/.cathook/...)", NULL, "Spam file name. Each line should be no longer than 100 characters, file must be located in ~/.cathook folder");
c_Reload = CreateConCommand(CON_PREFIX "spam_reload", &CC_Spam_ReloadFile, "Reloads spam file");
m_iCurrentIndex = 0;
m_fLastSpam = 0;
m_TextFile = new TextFile(256, 256);
}
CatVar enabled(CV_SWITCH, "spam", "0", "Chat spam", "Enable Spam");
CatVar filename(CV_STRING, "spam_file", "spam.txt", "Spam file (~/.cathook/...)", "Spam file name. Each line should be no longer than 100 characters, file must be located in ~/.cathook folder");
CatVar newlines(CV_SWITCH, "spam_newlines", "1", "Spam newlines", "If enabled, several newlines will be added before each message");
CatCommand reload("spam_reload", "Reload spam file", Reload);
void Spam::ProcessUserCmd(CUserCmd*) {
if (!v_bSpam->GetBool()) return;
if (g_GlobalVars->curtime - m_fLastSpam < 0.8f) return;
if (g_GlobalVars->curtime < m_fLastSpam) m_fLastSpam = 0.0f;
if (m_TextFile->GetLineCount() == 0) return;
if (m_iCurrentIndex >= m_TextFile->GetLineCount() || m_iCurrentIndex < 0) m_iCurrentIndex = 0;
char* spam = 0;
if (v_bSpamNewlines->GetBool()) {
spam = strfmt("\n\n\n\n\n\n\n\n\n\n\n\n\n%s", m_TextFile->GetLine(m_iCurrentIndex));
} else {
spam = strfmt("%s", m_TextFile->GetLine(m_iCurrentIndex));
int current_index { 0 };
float last_spam { 0.0f };
TextFile file {};
void CreateMove() {
if (!enabled) return;
if (last_spam > g_GlobalVars->curtime) last_spam = 0.0f;
if (!file.LineCount()) return;
if (g_GlobalVars->curtime - last_spam > 0.8f) {
if (chat_stack::stack.empty()) {
if (current_index >= file.LineCount()) current_index = 0;
std::string spamString = (newlines ? format("\n\n\n\n\n\n\n\n\n\n\n\n", file.Line(current_index)) : file.Line(current_index));
ReplaceString(spamString, "\\n", "\n");
chat_stack::stack.push(spamString);
current_index++;
}
}
ReplaceString(spam, "\\n", "\n");
g_pChatStack->Push(spam);
delete [] spam;
m_iCurrentIndex++;
m_fLastSpam = g_GlobalVars->curtime;
return;
}
void Spam::OnLevelShutdown() {
m_fLastSpam = 0;
void Reset() {
last_spam = 0.0f;
}
void Spam::OnLevelInit() {
m_fLastSpam = 0;
void Reload() {
file.Load(std::string(filename.GetString()));
}
void Spam::Reload() {
m_TextFile->LoadFile(v_sSpamFile->GetString());
}
void CC_Spam_ReloadFile(const CCommand& args) {
g_phSpam->Reload();
}
}}}

View File

@ -10,31 +10,21 @@
#include "IHack.h"
#define SPAM_MAX_AMOUNT 64
#define SPAM_MAX_LENGTH 256
#include "../textfile.h"
class TextFile;
class CatCommand;
class Spam : public IHack {
public:
Spam();
namespace hacks { namespace shared { namespace spam {
virtual void ProcessUserCmd(CUserCmd*) override;
virtual void OnLevelShutdown() override;
virtual void OnLevelInit() override;
extern CatVar enabled;
extern CatVar filename;
extern CatVar newlines;
extern CatCommand reload;
void Reload();
CatVar* v_bSpam;
CatVar* v_sSpamFile;
CatVar* v_bSpamNewlines;
ConCommand* c_Reload;
int m_iCurrentIndex;
TextFile* m_TextFile;
float m_fLastSpam;
};
void CreateMove();
void Reset();
void Reload();
DECLARE_HACK_SINGLETON(Spam);
void CC_Spam_ReloadFile(const CCommand& args);
}}}
#endif /* HACKS_SPAM_H_ */

View File

@ -110,6 +110,8 @@ const char* GetBuildingName(CachedEntity* ent) {
return "[NULL]";
}
void format_internal(std::stringstream& stream) {}
std::string WordWrap(std::string& in, int max) {
std::stringstream result;
std::stringstream line;
@ -145,6 +147,14 @@ std::string WordWrap(std::string& in, int max) {
return result.str();
}
void ReplaceString(std::string& input, const std::string& what, const std::string& with_what) {
size_t index = input.find(what);
while (index != std::string::npos) {
input.replace(index, what.size(), with_what);
index = input.find(what, index + with_what.size());
}
}
powerup_type GetPowerupOnPlayer(CachedEntity* player) {
if (!CE_BAD(player)) return powerup_type::not_powerup;
if (HasCondition(player, TFCond_RuneStrength)) return powerup_type::strength;

View File

@ -25,6 +25,7 @@ void SetCVarInterface(ICvar* iface);
//#define DEG2RAD(x) (float)(x) * (float)(PI / 180.0f)
#include "enums.h"
#include "logging.h"
#include "beforecheaders.h"
#include <string>
@ -115,6 +116,21 @@ Vector CalcAngle(Vector src, Vector dst);
void MakeVector(Vector ang, Vector& out);
float GetFov(Vector ang, Vector src, Vector dst);
void ReplaceString(std::string& input, const std::string& what, const std::string& with_what);
void format_internal(std::stringstream& stream);
template<typename T, typename... Targs>
void format_internal(std::stringstream& stream, T value, Targs... args) {
stream << value;
format_internal(stream, args...);
}
template<typename... Args>
std::string format(const Args&... args) {
std::stringstream stream;
format_internal(stream, args...);
return stream.str();
}
extern const char* tfclasses[10];
extern const char* powerups[POWERUP_COUNT];
extern uint32 friends[256];

View File

@ -109,8 +109,7 @@ bool CreateMove_hook(void* thisptr, float inputSample, CUserCmd* cmd) {
}
//SAFE_CALL(CREATE_MOVE(FollowBot));
SAFE_CALL(HACK_PROCESS_USERCMD(Misc, cmd));
SAFE_CALL(HACK_PROCESS_USERCMD(KillSay, cmd));
SAFE_CALL(HACK_PROCESS_USERCMD(Spam, cmd));
SAFE_CALL(hacks::shared::spam::CreateMove());
// PROF_END("Hacks processing");
if (time_replaced) g_GlobalVars->curtime = curtime_old;
}
@ -120,8 +119,7 @@ bool CreateMove_hook(void* thisptr, float inputSample, CUserCmd* cmd) {
}
}*/
g_Settings.bInvalid = false;
if (g_pChatStack)
g_pChatStack->OnCreateMove();
chat_stack::OnCreateMove();
if (CE_GOOD(g_pLocalPlayer->entity)) {
bool speedapplied = false;
if (g_Settings.kRollSpeedhack->GetBool() && g_pGUI->m_bPressedState[g_Settings.kRollSpeedhack->GetInt()] && !(cmd->buttons & IN_ATTACK)) {

View File

@ -137,7 +137,8 @@ void LevelInit_hook(void* thisptr, const char* newmap) {
// LEVEL_SHUTDOWN(FollowBot);
LEVEL_INIT(Misc);
//if (TF) LEVEL_INIT(SpyAlert);
g_pChatStack->Reset();
chat_stack::Reset();
hacks::shared::spam::Reset();
}
bool CanInspect_hook(IClientEntity*) { return true; }
@ -151,6 +152,7 @@ void LevelShutdown_hook(void* thisptr) {
LEVEL_SHUTDOWN(ESP);
// LEVEL_SHUTDOWN(FollowBot);
LEVEL_SHUTDOWN(Misc);
g_pChatStack->Reset();
chat_stack::Reset();
hacks::shared::spam::Reset();
}

View File

@ -74,7 +74,7 @@ void CreateInterfaces() {
g_IPanel = BruteforceInterface<vgui::IPanel>("VGUI_Panel", sharedobj::vgui2);
g_ISteamClient = BruteforceInterface<ISteamClient>("SteamClient", sharedobj::steamclient, 17);
g_ISurface = BruteforceInterface<vgui::ISurface>("VGUI_Surface", sharedobj::vguimatsurface);
g_IEventManager2 = BruteforceInterface<IGameEventManager2>("GAMEEVENTSMANAGER", sharedobj::engine);
g_IEventManager2 = BruteforceInterface<IGameEventManager2>("GAMEEVENTSMANAGER", sharedobj::engine, 2);
g_IBaseClient = BruteforceInterface<IBaseClientDLL>("VClient", sharedobj::client);
g_ITrace = BruteforceInterface<IEngineTrace>("EngineTraceClient", sharedobj::engine);
g_IModelInfo = BruteforceInterface<IVModelInfoClient>("VModelInfoClient", sharedobj::engine);

View File

@ -16,6 +16,8 @@
#include <pwd.h>
#include <stdio.h>
TextFile::TextFile() : lines {} {};
void TextFile::Load(std::string name) {
uid_t uid = geteuid();
passwd* pw = getpwuid(uid);
@ -23,6 +25,7 @@ void TextFile::Load(std::string name) {
logging::Info("can't get the username!");
return;
}
std::string test_format = format(123);
std::string filename = format("/home/", pw->pw_name, "/.cathook/", name);
std::ifstream file(filename, std::ios::in);
if (file.bad()) {

View File

@ -15,6 +15,7 @@
class TextFile {
public:
TextFile();
void Load(std::string filename);
size_t LineCount() const;
const std::string& Line(size_t id) const;