Add a Warp hack

Seems i also accidentally formatted stuff but i'm leaving it in here
This commit is contained in:
BenCat07 2020-04-16 23:03:32 +02:00
parent 3144f5ad73
commit 073cd6805e
9 changed files with 305 additions and 38 deletions

View File

@ -56,4 +56,16 @@
<AutoVariable width="fill" target="antibackstab.nope" label="Nope!"/> <AutoVariable width="fill" target="antibackstab.nope" label="Nope!"/>
</List> </List>
</Box> </Box>
<Box padding="12 6 6 6" width="content" height="content" name="Warp" x="370" y="65">
<List width="180">
<AutoVariable width="fill" target="warp.enabled" label="Enable Warp" tooltip="Allows you to charge a burst of speed"/>
<AutoVariable width="fill" target="warp.key" label="Warp Key" tooltip="Pressing this key will use all stored ticks to accelerate you"/>
<AutoVariable width="fill" target="warp.draw" label="Draw Warp" tooltip="Draws a bar indicating your warp readyness"/>
<AutoVariable width="fill" target="warp.bar-size" label="Bar Size"/>
<AutoVariable width="fill" target="warp.bar-x" label="X Position"/>
<AutoVariable width="fill" target="warp.bar-y" label="Y Position"/>
<AutoVariable width="fill" target="warp.movement-ratio" label="Movement Ratio" tooltip="Every Xth movement tick is converted to warp"/>
<AutoVariable width="fill" target="warp.peek" label="Peek Mode" tooltip="This will teleport you for a tick and then teleport you back"/>
</List>
</Box>
</Tab> </Tab>

6
include/hacks/Warp.hpp Normal file
View File

@ -0,0 +1,6 @@
#pragma once
class INetMessage;
namespace hacks::tf2::warp
{
void SendNetMessage(INetMessage &msg);
}

View File

@ -10,7 +10,7 @@
#include "SeedPrediction.hpp" #include "SeedPrediction.hpp"
#if ENABLE_VISUALS #if ENABLE_VISUALS
union SDL_Event; union SDL_Event;
struct SDL_Window; class SDL_Window;
#endif #endif
#define DECLARE_HOOKED_METHOD(name, rtype, ...) \ #define DECLARE_HOOKED_METHOD(name, rtype, ...) \
@ -43,6 +43,7 @@ DECLARE_HOOKED_METHOD(FireGameEvent, void, void *, IGameEvent *);
// IBaseClient // IBaseClient
DECLARE_HOOKED_METHOD(DispatchUserMessage, bool, void *, int, bf_read &); DECLARE_HOOKED_METHOD(DispatchUserMessage, bool, void *, int, bf_read &);
DECLARE_HOOKED_METHOD(IN_KeyEvent, int, void *, int, ButtonCode_t, const char *); DECLARE_HOOKED_METHOD(IN_KeyEvent, int, void *, int, ButtonCode_t, const char *);
DECLARE_HOOKED_METHOD(FrameStageNotify, void, void *, ClientFrameStage_t);
// IInput // IInput
DECLARE_HOOKED_METHOD(GetUserCmd, CUserCmd *, IInput *, int); DECLARE_HOOKED_METHOD(GetUserCmd, CUserCmd *, IInput *, int);
// INetChannel // INetChannel
@ -73,8 +74,6 @@ DECLARE_HOOKED_METHOD(ChatPrintf, void, CHudBaseChat *, int, int, const char *,
DECLARE_HOOKED_METHOD(OverrideView, void, void *, CViewSetup *); DECLARE_HOOKED_METHOD(OverrideView, void, void *, CViewSetup *);
// IStudioRender // IStudioRender
DECLARE_HOOKED_METHOD(BeginFrame, void, IStudioRender *); DECLARE_HOOKED_METHOD(BeginFrame, void, IStudioRender *);
// IBaseClient
DECLARE_HOOKED_METHOD(FrameStageNotify, void, void *, ClientFrameStage_t);
// SDL // SDL
DECLARE_HOOKED_METHOD(SDL_GL_SwapWindow, void, SDL_Window *); DECLARE_HOOKED_METHOD(SDL_GL_SwapWindow, void, SDL_Window *);
DECLARE_HOOKED_METHOD(SDL_PollEvent, int, SDL_Event *); DECLARE_HOOKED_METHOD(SDL_PollEvent, int, SDL_Event *);

View File

@ -36,7 +36,8 @@ set(files "${CMAKE_CURRENT_LIST_DIR}/AutoJoin.cpp"
"${CMAKE_CURRENT_LIST_DIR}/PureBypass.cpp" "${CMAKE_CURRENT_LIST_DIR}/PureBypass.cpp"
"${CMAKE_CURRENT_LIST_DIR}/Trigger.cpp" "${CMAKE_CURRENT_LIST_DIR}/Trigger.cpp"
"${CMAKE_CURRENT_LIST_DIR}/UberSpam.cpp" "${CMAKE_CURRENT_LIST_DIR}/UberSpam.cpp"
"${CMAKE_CURRENT_LIST_DIR}/Walkbot.cpp") "${CMAKE_CURRENT_LIST_DIR}/Walkbot.cpp"
"${CMAKE_CURRENT_LIST_DIR}/Warp.cpp")
target_sources(cathook PRIVATE ${files}) target_sources(cathook PRIVATE ${files})
list(REMOVE_ITEM ignore_files ${files}) list(REMOVE_ITEM ignore_files ${files})
set(ignore_files ${ignore_files} CACHE INTERNAL "") set(ignore_files ${ignore_files} CACHE INTERNAL "")

View File

@ -172,5 +172,5 @@ mov [esp], ecx
} }
}); });
}); });
} } // namespace hacks::tf2::killfeed
#endif #endif

245
src/hacks/Warp.cpp Normal file
View File

@ -0,0 +1,245 @@
/*
* Created on 16.4.2020
* Author: BenCat07
*
* Copyright Nullworks 2020
*/
#include "init.hpp"
#include "sdk.hpp"
#include "interfaces.hpp"
#include "settings/Bool.hpp"
#include "offsets.hpp"
#include "globals.h"
#include "Warp.hpp"
#include "HookTools.hpp"
#include "usercmd.hpp"
#include "localplayer.hpp"
#include "netvars.hpp"
#include "entitycache.hpp"
#include "conditions.hpp"
#include "velocity.hpp"
#if ENABLE_VISUALS
#include "drawing.hpp"
#endif
namespace hacks::tf2::warp
{
static settings::Boolean enabled{ "warp.enabled", "false" };
static settings::Boolean draw{ "warp.draw", "false" };
static settings::Button warp_key{ "warp.key", "<null>" };
static settings::Int warp_movement_ratio{ "warp.movement-ratio", "6" };
static settings::Boolean warp_peek{ "warp.peek", "false" };
// Draw control
static settings::Int size{ "warp.bar-size", "100" };
static settings::Int bar_x{ "warp.bar-x", "50" };
static settings::Int bar_y{ "warp.bar-y", "200" };
static bool should_charge = false;
static int warp_amount = 0;
static int warp_override = 0;
static bool charged = false;
// Taken from MrSteyk
class clc_move_proto
{
public:
int VTable;
char reliable;
int netchan;
int field_C;
int field_10;
int m_nBackupCommands;
int m_nNewCommands;
int m_nLength;
bf_write m_DataIn;
bf_write m_DataOut;
};
int GetWarpAmount()
{
static auto sv_max_dropped_packets_to_process = g_ICvar->FindVar("sv_max_dropped_packets_to_process");
if (!warp_override)
return sv_max_dropped_packets_to_process->GetInt();
else
return warp_override;
}
bool should_warp = true;
// Warping part
void Warp()
{
auto ch = g_IEngine->GetNetChannelInfo();
if (!ch)
return;
if (!should_warp)
{
should_warp = true;
return;
}
int &m_nOutSequenceNr = *(int *) ((uintptr_t) ch + offsets::m_nOutSequenceNr());
// Has to be from the cvar
m_nOutSequenceNr += GetWarpAmount();
warp_amount -= GetWarpAmount();
if (warp_amount < 0)
warp_amount = 0;
}
int GetMaxWarpTicks()
{
static auto usercmd_cvar = g_ICvar->FindVar("sv_maxusrcmdprocessticks");
int ticks = usercmd_cvar->GetInt();
// No limit set
if (!ticks)
ticks = INT_MAX;
return ticks;
}
void SendNetMessage(INetMessage &msg)
{
if (!enabled)
return;
// Credits to MrSteyk for this btw
if (msg.GetGroup() == 0xA)
{
// Charge
if (should_charge && !charged)
{
int ticks = GetMaxWarpTicks();
auto movemsg = (clc_move_proto *) &msg;
// Just null it :shrug:
movemsg->m_nBackupCommands = 0;
movemsg->m_nNewCommands = 0;
movemsg->m_DataOut.Reset();
movemsg->m_DataOut.m_nDataBits = 0;
movemsg->m_DataOut.m_nDataBytes = 0;
movemsg->m_DataOut.m_iCurBit = 0;
warp_amount++;
if (warp_amount >= ticks)
{
warp_amount = ticks;
charged = true;
}
}
// Warp
if (warp_key.isKeyDown() && warp_amount)
{
Warp();
if (warp_amount < GetWarpAmount())
charged = false;
}
}
should_charge = false;
}
static bool move_last_tick = true;
static bool warp_last_tick = false;
static bool should_warp_last_tick = false;
void CreateMove()
{
if (!enabled)
return;
warp_override = 0;
if (!warp_key.isKeyDown())
{
warp_last_tick = false;
// Bunch of checks, if they all pass we are standing still
if (!HasCondition<TFCond_Charging>(LOCAL_E) && !current_user_cmd->forwardmove && !current_user_cmd->sidemove && !current_user_cmd->upmove && (CE_INT(LOCAL_E, netvar.iFlags) & FL_ONGROUND) && !(current_user_cmd->buttons & (IN_ATTACK | IN_ATTACK2)))
{
Vector velocity{};
velocity::EstimateAbsVelocity(RAW_ENT(LOCAL_E), velocity);
if (velocity.IsZero())
{
if (!move_last_tick)
should_charge = true;
move_last_tick = false;
}
return;
}
else
{
should_charge = false;
// Use everxy xth tick for charging
if (!(tickcount % *warp_movement_ratio))
should_charge = true;
move_last_tick = true;
}
}
// Warp peaking
else if (warp_peek)
{
// We Have warp
if (warp_amount)
{
// Warped last tick, time to reverse
if (warp_last_tick)
{
// Wait 1 tick before tping back
if (should_warp && !should_warp_last_tick)
{
should_warp_last_tick = true;
should_warp = false;
}
else
should_warp_last_tick = false;
// Inverse direction
current_user_cmd->forwardmove = -current_user_cmd->forwardmove;
current_user_cmd->sidemove = -current_user_cmd->sidemove;
}
else
warp_override = warp_amount / 2;
warp_last_tick = true;
}
// Prevent movement so you don't overshoot when you don't want to
else
{
current_user_cmd->forwardmove = 0.0f;
current_user_cmd->sidemove = 0.0f;
}
}
}
#if ENABLE_VISUALS
void Draw()
{
if (!enabled || !draw)
return;
if (!g_IEngine->IsInGame())
return;
if (CE_BAD(LOCAL_E))
return;
float charge_percent = (float) warp_amount / (float) GetMaxWarpTicks();
// Draw background
static rgba_t background_color = colors::FromRGBA8(96, 96, 96, 150);
float bar_bg_x_size = *size * 2.0f;
float bar_bg_y_size = *size / 5.0f;
draw::Rectangle(*bar_x - 5.0f, *bar_y - 5.0f, bar_bg_x_size + 10.0f, bar_bg_y_size + 10.0f, background_color);
// Draw bar
rgba_t color_bar = colors::orange;
if (GetMaxWarpTicks() == warp_amount)
color_bar = colors::green;
color_bar.a = 100 / 255.0f;
draw::Rectangle(*bar_x, *bar_y, *size * 2.0f * charge_percent, *size / 5.0f, color_bar);
}
#endif
void LevelShutdown()
{
charged = false;
warp_amount = 0;
}
static InitRoutine init([]() {
EC::Register(EC::LevelShutdown, LevelShutdown, "warp_levelshutdown");
EC::Register(EC::CreateMove, CreateMove, "warp_createmove", EC::late);
#if ENABLE_VISUALS
EC::Register(EC::Draw, Draw, "warp_draw");
#endif
});
} // namespace hacks::tf2::warp

View File

@ -9,6 +9,7 @@
#include <MiscTemporary.hpp> #include <MiscTemporary.hpp>
#include "nullnexus.hpp" #include "nullnexus.hpp"
#include "e8call.hpp" #include "e8call.hpp"
#include "Warp.hpp"
static settings::Int newlines_msg{ "chat.prefix-newlines", "0" }; static settings::Int newlines_msg{ "chat.prefix-newlines", "0" };
static settings::Boolean log_sent{ "debug.log-sent-chat", "false" }; static settings::Boolean log_sent{ "debug.log-sent-chat", "false" };
@ -195,6 +196,9 @@ DEFINE_HOOKED_METHOD(SendNetMsg, bool, INetChannel *this_, INetMessage &msg, boo
int offset; int offset;
std::string newlines{}; std::string newlines{};
NET_StringCmd stringcmd; NET_StringCmd stringcmd;
hacks::tf2::warp::SendNetMessage(msg);
// net_StringCmd // net_StringCmd
if (msg.GetType() == 4 && (newlines_msg || crypt_chat)) if (msg.GetType() == 4 && (newlines_msg || crypt_chat))
{ {