Skip to content

Commit

Permalink
Added preframe hook refresh to fix disconnect crash
Browse files Browse the repository at this point in the history
  • Loading branch information
womblee committed Jun 23, 2024
1 parent 62a66ce commit 5ba60da
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 3 deletions.
Binary file modified .vs/spankerfield/v17/.suo
Binary file not shown.
Binary file modified .vs/spankerfield/v17/Browse.VC.db
Binary file not shown.
40 changes: 40 additions & 0 deletions spankerfield/Features/Refresh Hook/refresh_hook.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "refresh_hook.h"
#include "../../Hooks/hooks.h"
#include "../../Utilities/vtablehook.h"

using namespace big;
namespace plugins
{
static bool refresh = false;
void refresh_preframe_hook()
{
const auto border_input_node = BorderInputNode::GetInstance();
if (!border_input_node) return;

const auto game_context = ClientGameContext::GetInstance();
if (!game_context) return;

const auto player_manager = game_context->m_pPlayerManager;
if (!player_manager) return;

// Rehooking PreFrameUpdate vtable to prevent crashes when leaving the server (credits Menool)
if (!IsValidPtr(player_manager->m_pLocalPlayer))
{
if (!refresh)
{
refresh = true;

hook_vtable_func(reinterpret_cast<PDWORD64*>(border_input_node->m_Vtable), reinterpret_cast<PBYTE>(PreFrame::oPreFrameUpdate), 3);
}

return;
}
else if (refresh)
{
refresh = false;

PreFrame::oPreFrameUpdate = reinterpret_cast<PreFrame::PreFrameUpdate_t>(hook_vtable_func(reinterpret_cast<PDWORD64*>(border_input_node->m_Vtable), reinterpret_cast<PBYTE>(&PreFrame::hkPreFrame), 3));
LOG(INFO) << xorstr_("Refreshed PreFrame.");
}
}
}
7 changes: 7 additions & 0 deletions spankerfield/Features/Refresh Hook/refresh_hook.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once
#include "../../SDK/sdk.h"

namespace plugins
{
void refresh_preframe_hook();
}
3 changes: 3 additions & 0 deletions spankerfield/Features/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ namespace big
{
void features::draw()
{
// This has to be done before the visuals run
plugins::refresh_preframe_hook();

plugins::draw_screenshots();
plugins::draw_crosshair();
plugins::draw_spectators();
Expand Down
1 change: 1 addition & 0 deletions spankerfield/Features/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "Anti AFK/anti_afk.h"
#include "Name Spoofer/name_spoofer.h"
#include "Kill Sound/kill_sound.h"
#include "Refresh Hook/refresh_hook.h"

namespace big
{
Expand Down
4 changes: 1 addition & 3 deletions spankerfield/Hooks/hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
#include "../MinHook.h"
#include "../Utilities/vtablehook.h"
#include "../Utilities/other.h"
#include "../Utilities/thread_pool.h"
#include "../Rendering/renderer.h"
#include "../Rendering/gui.h"
#include "../Features/main.h"
#include "../settings.h"
#include "../global.h"


#ifdef _WIN64
#define GWL_WNDPROC GWLP_WNDPROC
#endif

namespace big
{
Expand Down
11 changes: 11 additions & 0 deletions spankerfield/Hooks/hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,24 @@

namespace big
{
// For the refresh hook plugin
namespace PreFrame
{
using PreFrameUpdate_t = void(*)(float dt);
extern PreFrameUpdate_t oPreFrameUpdate;
void hkPreFrame(float delta_time);
}

// Hooking
class hooking
{
public:
void initialize();
void uninitialize();
void enable();
void disable();

bool refresh_preframe;
};

inline hooking* g_hooking{};
Expand Down
5 changes: 5 additions & 0 deletions spankerfield/Utilities/xorstr.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@
#include <utility>
#include <type_traits>

#ifdef BUILD_FOR_UC
#define xorstr(str) (str)
#define xorstr_(str) (str)
#else
#define xorstr(str) ::jm::xor_string([]() { return str; }, std::integral_constant<std::size_t, sizeof(str) / sizeof(*str)>{}, std::make_index_sequence<::jm::detail::_buffer_size<sizeof(str)>()>{})
#define xorstr_(str) xorstr(str).crypt_get()
#endif

#ifdef _MSC_VER
#define XORSTR_FORCEINLINE __forceinline
Expand Down
3 changes: 3 additions & 0 deletions spankerfield/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

#pragma comment(lib, "Winmm.lib")

// Made this for myself, disables string encryption so I can upload the .dll on UnknownCheats
// #define BUILD_FOR_UC

#include <SDKDDKVer.h>
#include <Windows.h>
#include <TlHelp32.h>
Expand Down
2 changes: 2 additions & 0 deletions spankerfield/spankerfield.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
<ClCompile Include="Features\Name Spoofer\name_spoofer.cpp" />
<ClCompile Include="Features\Overheat\overheat.cpp" />
<ClCompile Include="Features\Radar\radar.cpp" />
<ClCompile Include="Features\Refresh Hook\refresh_hook.cpp" />
<ClCompile Include="Features\Risky\risky.cpp" />
<ClCompile Include="Features\Screenshots\screenshots.cpp" />
<ClCompile Include="Features\Spectator List\spectators.cpp" />
Expand Down Expand Up @@ -213,6 +214,7 @@
<ClInclude Include="Features\Name Spoofer\name_spoofer.h" />
<ClInclude Include="Features\Overheat\overheat.h" />
<ClInclude Include="Features\Radar\radar.h" />
<ClInclude Include="Features\Refresh Hook\refresh_hook.h" />
<ClInclude Include="Features\Risky\risky.h" />
<ClInclude Include="Features\Screenshots\screenshots.h" />
<ClInclude Include="logger.h" />
Expand Down
6 changes: 6 additions & 0 deletions spankerfield/spankerfield.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@
<ClCompile Include="Features\Kill Sound\kill_sound.cpp">
<Filter>Исходные файлы</Filter>
</ClCompile>
<ClCompile Include="Features\Refresh Hook\refresh_hook.cpp">
<Filter>Исходные файлы</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Features\ESP\esp.h">
Expand Down Expand Up @@ -422,6 +425,9 @@
<ClInclude Include="Features\Kill Sound\kill_sound.h">
<Filter>Файлы заголовков</Filter>
</ClInclude>
<ClInclude Include="Features\Refresh Hook\refresh_hook.h">
<Filter>Файлы заголовков</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down

0 comments on commit 5ba60da

Please sign in to comment.