IRC WIP
This commit is contained in:
parent
b224125a18
commit
4b4e610d3c
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -22,3 +22,6 @@
|
||||
[submodule "external/TF2_NavFile_Reader"]
|
||||
path = external/TF2_NavFile_Reader
|
||||
url = https://github.com/nullworks/TF2_NavFile_Reader
|
||||
[submodule "external/IRCClient"]
|
||||
path = external/IRCClient
|
||||
url = https://github.com/TotallyNotElite/IRCClient
|
||||
|
1
external/CMakeLists.txt
vendored
1
external/CMakeLists.txt
vendored
@ -5,3 +5,4 @@ target_include_directories(cathook PRIVATE "${CMAKE_CURRENT_LIST_DIR}/MicroPathe
|
||||
target_include_directories(cathook PRIVATE "${CMAKE_CURRENT_LIST_DIR}/ucccccp")
|
||||
target_include_directories(cathook PRIVATE "${CMAKE_CURRENT_LIST_DIR}/TF2_NavFile_Reader")
|
||||
|
||||
add_subdirectory(IRCClient)
|
||||
|
1
external/IRCClient
vendored
Submodule
1
external/IRCClient
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 61d5866823fdae5e76044c947dcdaeae3686c616
|
@ -13,12 +13,13 @@ namespace HookTools
|
||||
{
|
||||
std::vector<HookedFunction *> &GetHookedFunctions();
|
||||
void CM();
|
||||
void PT();
|
||||
} // namespace HookTools
|
||||
|
||||
enum HookedFunctions_types
|
||||
{
|
||||
HF_CreateMove = 0,
|
||||
HF_Painttraverse
|
||||
HF_Draw
|
||||
|
||||
};
|
||||
|
||||
@ -35,8 +36,8 @@ class HookedFunction
|
||||
case HF_CreateMove:
|
||||
m_name = "CM_";
|
||||
break;
|
||||
case HF_Painttraverse:
|
||||
m_name = "PT_";
|
||||
case HF_Draw:
|
||||
m_name = "DRAW_";
|
||||
break;
|
||||
}
|
||||
m_name.append(name);
|
||||
|
@ -32,6 +32,7 @@ target_sources(cathook PRIVATE
|
||||
"${CMAKE_CURRENT_LIST_DIR}/MiscTemporary.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/navparser.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/Options.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/IRC.cpp"
|
||||
"${CMAKE_CURRENT_LIST_DIR}/PlayerTools.cpp")
|
||||
|
||||
add_subdirectory(core)
|
||||
|
140
src/IRC.cpp
Normal file
140
src/IRC.cpp
Normal file
@ -0,0 +1,140 @@
|
||||
#include "common.hpp"
|
||||
#include "core/logging.hpp"
|
||||
#include <thread>
|
||||
//#include "Thread.h"
|
||||
#include "IRCClient.h"
|
||||
#include <atomic>
|
||||
#include "boost/random.hpp"
|
||||
#include "boost/generator_iterator.hpp"
|
||||
|
||||
|
||||
namespace IRC
|
||||
{
|
||||
std::atomic<bool> thread_shouldrun;
|
||||
std::atomic<bool> thread_running;
|
||||
std::unique_ptr<IRCClient> IRCConnection;
|
||||
Timer heartbeat{};
|
||||
settings::Bool enabled("irc.enabled", "true");
|
||||
|
||||
void handleMessage(IRCMessage message, IRCClient *client)
|
||||
{
|
||||
std::string &cmd = message.command;
|
||||
std::string &channel = message.parameters.at(0);
|
||||
std::string &msg = message.parameters.at(1);
|
||||
std::string &usr = message.prefix.nick;
|
||||
if (msg.empty() || usr.empty())
|
||||
return;
|
||||
logging::Info("passed");
|
||||
if (g_Settings.bInvalid)
|
||||
logging::Info("[IRC] %s: %s", usr.c_str(), msg.c_str());
|
||||
else
|
||||
PrintChat("\x07%06X[IRC] %s\x01: %s", 0xe05938, usr.c_str(),
|
||||
msg.c_str());
|
||||
}
|
||||
|
||||
int randomint() {
|
||||
boost::mt19937 rng;
|
||||
boost::uniform_int<> one_to_six( 1, 10000 );
|
||||
boost::variate_generator< boost::mt19937, boost::uniform_int<> >
|
||||
dice(rng, one_to_six);
|
||||
return dice();
|
||||
}
|
||||
|
||||
void IRCThread()
|
||||
{
|
||||
char address[] = "flash.rizon.net";
|
||||
int port = 7000;
|
||||
std::atomic<bool> thread_shouldrun;
|
||||
std::string user = g_ISteamFriends->GetPersonaName();
|
||||
// user.append(format("-", getpid()));
|
||||
std::string nick = g_ISteamFriends->GetPersonaName();
|
||||
nick.append(format("-", randomint()));
|
||||
std::string channel("#pixelz");
|
||||
|
||||
IRCConnection = std::make_unique<IRCClient>();
|
||||
IRCClient &client = *IRCConnection;
|
||||
client.HookIRCCommand("PRIVMSG", handleMessage);
|
||||
|
||||
logging::Info("IRC: Initializing IRC");
|
||||
if (client.InitSocket())
|
||||
{
|
||||
logging::Info("IRC: Socket Initialized. Connecting to cathook IRC...");
|
||||
if (client.Connect(address, port))
|
||||
{
|
||||
logging::Info("IRC: Connected. Logging in...");
|
||||
if (client.Login(nick, user))
|
||||
{
|
||||
logging::Info("IRC: Logged in. Joining channel.");
|
||||
std::thread joinChannel([=]() {
|
||||
std::this_thread::sleep_for(
|
||||
std::chrono_literals::operator""s(3));
|
||||
if (IRCConnection && IRCConnection->Connected())
|
||||
IRCConnection->SendIRC(format("JOIN ", channel));
|
||||
logging::Info("IRC: Init complete.");
|
||||
});
|
||||
joinChannel.detach();
|
||||
while (client.Connected() && thread_shouldrun.load())
|
||||
{
|
||||
if (heartbeat.check(5000))
|
||||
{
|
||||
thread_shouldrun.store(false);
|
||||
break;
|
||||
}
|
||||
client.ReceiveData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
logging::Info("Exiting IRC thread...");
|
||||
IRCConnection->Disconnect();
|
||||
IRCConnection.reset();
|
||||
thread_running.store(false);
|
||||
}
|
||||
|
||||
static HookedFunction pt(HF_Draw, "IRC", 16, []() {
|
||||
if (!*enabled)
|
||||
{
|
||||
thread_shouldrun.store(false);
|
||||
return;
|
||||
}
|
||||
thread_shouldrun.store(true);
|
||||
if (!thread_running.load())
|
||||
{
|
||||
thread_running.store(true);
|
||||
heartbeat.update();
|
||||
std::thread ircthread(IRCThread);
|
||||
ircthread.detach();
|
||||
logging::Info("IRC: Running.");
|
||||
}
|
||||
heartbeat.update();
|
||||
});
|
||||
|
||||
namespace irc
|
||||
{
|
||||
bool sendmsg(std::string msg, std::string = "pixelz")
|
||||
{
|
||||
if (!IRCConnection || IRCConnection->Connected())
|
||||
{
|
||||
if (IRCConnection->SendIRC(format("PRIVMSG #pixelz :", msg)))
|
||||
{
|
||||
;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} // namespace irc
|
||||
|
||||
CatCommand irc_send("irc_send", "Send message to IRC",
|
||||
[](const CCommand &args) {
|
||||
IRCConnection->SendIRC(args.ArgS());
|
||||
});
|
||||
|
||||
CatCommand irc_send_msg("irc_send_msg", "Send message to IRC",
|
||||
[](const CCommand &args) {
|
||||
if (irc::sendmsg(args.ArgS()))
|
||||
logging::Info("IRC: Sent!");
|
||||
else
|
||||
logging::Info("IRC: Error!");
|
||||
});
|
||||
}
|
@ -72,8 +72,8 @@ DEFINE_HOOKED_METHOD(DispatchUserMessage, bool, void *this_, int type,
|
||||
for (i = 0; i < s; i++)
|
||||
data[i] = buf.ReadByte();
|
||||
j = 0;
|
||||
std::string name;
|
||||
std::string message;
|
||||
std::string name{};
|
||||
std::string message{};
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
while ((c = data[j++]) && (loop_index < 150))
|
||||
|
@ -16,6 +16,14 @@ void HookTools::CM()
|
||||
}
|
||||
}
|
||||
|
||||
void HookTools::PT()
|
||||
{
|
||||
for (auto i : GetHookedFunctions())
|
||||
{
|
||||
i->run(HF_Draw);
|
||||
}
|
||||
}
|
||||
|
||||
static InitRoutine init([]() {
|
||||
auto &HookedFunctions = HookTools::GetHookedFunctions();
|
||||
std::sort(HookedFunctions.begin(), HookedFunctions.end(),
|
||||
|
@ -104,6 +104,10 @@ void DrawCheatVisuals()
|
||||
{
|
||||
AddCenterString("Press SPACE to stop spectating");
|
||||
}
|
||||
{
|
||||
PROF_SECTION(DRAW_WRAPPER);
|
||||
HookTools::PT();
|
||||
}
|
||||
if (CE_GOOD(g_pLocalPlayer->entity) && !g_Settings.bInvalid)
|
||||
{
|
||||
PROF_SECTION(PT_total_hacks);
|
||||
|
Reference in New Issue
Block a user