Merge pull request #57 from diamante0018/master

Bounces from all angles. Re-organize includes based on cpp core guideliness
This commit is contained in:
Maurice Heumann 2022-03-26 09:40:56 +01:00 committed by GitHub
commit 50a0e137b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
39 changed files with 162 additions and 129 deletions

View File

@ -1,4 +1,4 @@
#include "std_include.hpp"
#include <std_include.hpp>
#include "context_initializer.hpp"
namespace game::scripting

View File

@ -1,4 +1,4 @@
#include "std_include.hpp"
#include <std_include.hpp>
#include "context_initializer.hpp"
#include "utils/string.hpp"

View File

@ -1,4 +1,4 @@
#include "std_include.hpp"
#include <std_include.hpp>
#include "context.hpp"
namespace game::scripting

View File

@ -1,6 +1,7 @@
#include "std_include.hpp"
#include <std_include.hpp>
#include <utils/string.hpp>
#include "game/game.hpp"
#include "utils/string.hpp"
#include "functions.hpp"
#include "stack_isolation.hpp"
#include "safe_executer.hpp"

View File

@ -1,4 +1,4 @@
#include "std_include.hpp"
#include <std_include.hpp>
#include "functions.hpp"
namespace game::scripting

View File

@ -1,4 +1,4 @@
#include "std_include.hpp"
#include <std_include.hpp>
#include "context.hpp"
namespace game::scripting

View File

@ -1,4 +1,4 @@
#include "std_include.hpp"
#include <std_include.hpp>
#include "safe_executer.hpp"
#pragma warning(push)

View File

@ -1,4 +1,4 @@
#include "std_include.hpp"
#include <std_include.hpp>
#include "context.hpp"
namespace game::scripting

View File

@ -1,4 +1,4 @@
#include "std_include.hpp"
#include <std_include.hpp>
#include "stack_isolation.hpp"
namespace game::scripting

View File

@ -1,6 +1,7 @@
#include <std_include.hpp>
#include <utils/nt.hpp>
#include "launcher.hpp"
#include "utils/nt.hpp"
launcher::launcher()
{

View File

@ -1,10 +1,11 @@
#include <std_include.hpp>
#include <utils/nt.hpp>
#include <utils/io.hpp>
#include <utils/cryptography.hpp>
#include <utils/string.hpp>
#include <utils/compression.hpp>
#include "binary_loader.hpp"
#include "utils/nt.hpp"
#include "utils/io.hpp"
#include "utils/cryptography.hpp"
#include "utils/string.hpp"
#include "utils/compression.hpp"
#define DEDI_HASH "F271C305117B79242E254E9F64BD5AA2993CAC8E57975243EBD44CD576418D20"

View File

@ -1,7 +1,8 @@
#include <std_include.hpp>
#include <utils/string.hpp>
#include "loader.hpp"
#include "binary_loader.hpp"
#include "utils/string.hpp"
loader::loader(const launcher::mode mode) : mode_(mode)
{

View File

@ -1,6 +1,6 @@
#pragma once
#include "utils/nt.hpp"
#include "launcher/launcher.hpp"
#include <utils/nt.hpp>
#include <launcher/launcher.hpp>
class loader final
{

View File

@ -1,4 +1,4 @@
#include <std_include.hpp>
#include "std_include.hpp"
#include "launcher/launcher.hpp"
#include "loader/loader.hpp"
#include "loader/module_loader.hpp"

View File

@ -1,6 +1,7 @@
#include <std_include.hpp>
#include "loader/module_loader.hpp"
#include "utils/hook.hpp"
#include <loader/module_loader.hpp>
#include <utils/hook.hpp>
#include "game/game.hpp"
class ceg final : public module

View File

@ -1,9 +1,9 @@
#include <std_include.hpp>
#include "loader/module_loader.hpp"
#include "command.hpp"
#include "game/game.hpp"
#include <loader/module_loader.hpp>
#include <utils/string.hpp>
#include "utils/string.hpp"
#include "game/game.hpp"
#include "command.hpp"
class client_command final : public module
{

View File

@ -1,8 +1,11 @@
#include <std_include.hpp>
#include "command.hpp"
#include <loader/module_loader.hpp>
#include <utils/string.hpp>
#include <utils/hook.hpp>
#include "utils/string.hpp"
#include "utils/hook.hpp"
#include "game/game.hpp"
#include "command.hpp"
utils::memory::allocator command::allocator_;
std::unordered_map<std::string, std::function<void(const command::params&)>> command::handlers;

View File

@ -1,10 +1,5 @@
#pragma once
#include "loader/module_loader.hpp"
#include "game/structs.hpp"
#include "game/game.hpp"
#include "utils/memory.hpp"
#include <utils/memory.hpp>
class command final : public module
{

View File

@ -1,5 +1,6 @@
#include <std_include.hpp>
#include "loader/module_loader.hpp"
#include <loader/module_loader.hpp>
#include "game/game.hpp"
#include "scheduler.hpp"

View File

@ -1,8 +1,10 @@
#include <std_include.hpp>
#include <loader/module_loader.hpp>
#include <discord_rpc.h>
#include "loader/module_loader.hpp"
#include "scheduler.hpp"
#include "game/game.hpp"
#include "scheduler.hpp"
class discord final : public module
{

View File

@ -1,9 +1,7 @@
#include <std_include.hpp>
#include "dw.hpp"
#include "utils/hook.hpp"
#include "game/game.hpp"
#include "utils/nt.hpp"
#include "utils/cryptography.hpp"
#include <utils/hook.hpp>
#include <utils/nt.hpp>
#include <utils/cryptography.hpp>
#include "game/demonware/services/bdLSGHello.hpp" // 7
#include "game/demonware/services/bdStorage.hpp" // 10
@ -13,6 +11,9 @@
#include "game/demonware/services/bdDediRSAAuth.hpp" // 26
#include "game/demonware/services/bdSteamAuth.hpp" // 28
#include "game/game.hpp"
#include "dw.hpp"
namespace demonware
{
namespace io

View File

@ -1,5 +1,6 @@
#pragma once
#include "loader/module_loader.hpp"
#include <loader/module_loader.hpp>
#include "game/demonware/stun_server.hpp"
#include "game/demonware/service_server.hpp"

View File

@ -1,7 +1,8 @@
#include <std_include.hpp>
#include "loader/module_loader.hpp"
#include <loader/module_loader.hpp>
#include <utils/hook.hpp>
#include "game/game.hpp"
#include "utils/hook.hpp"
static __declspec(naked) void db_load_stub_client(game::native::XZoneInfo*, unsigned int, int)
{

View File

@ -1,6 +1,7 @@
#include <std_include.hpp>
#include "loader/module_loader.hpp"
#include "utils/hook.hpp"
#include <loader/module_loader.hpp>
#include <utils/hook.hpp>
#include "game/game.hpp"
class fov final : public module

View File

@ -1,7 +1,7 @@
#include <std_include.hpp>
#include "loader/module_loader.hpp"
#include "utils/nt.hpp"
#include "utils/string.hpp"
#include <loader/module_loader.hpp>
#include <utils/nt.hpp>
#include <utils/string.hpp>
class game_launcher final : public module
{

View File

@ -1,6 +1,7 @@
#include <std_include.hpp>
#include "loader/module_loader.hpp"
#include "utils/hook.hpp"
#include <loader/module_loader.hpp>
#include <utils/hook.hpp>
#include "game/game.hpp"
class patches final : public module
@ -40,7 +41,7 @@ private:
void patch_mp() const
{
// Note: on SP it's already unlocked to 1000
// Note: on SP the max value is already 1000
utils::hook(0x55411F, &dvar_register_com_max_fps, HOOK_CALL).install()->quick();
}
@ -62,9 +63,10 @@ private:
}
static const game::native::dvar_t* dvar_register_com_max_fps(const char* dvarName, int value,
int min, int /*max*/, unsigned __int16 flags, const char* description)
int min, int /*max*/, unsigned __int16 /*flags*/, const char* description)
{
return game::native::Dvar_RegisterInt(dvarName, value, min, 1000, flags, description);
return game::native::Dvar_RegisterInt(dvarName, value, min, 1000,
game::native::dvar_flags::DVAR_ARCHIVE, description);
}
};

View File

@ -1,8 +1,8 @@
#include <std_include.hpp>
#include <loader/module_loader.hpp>
#include <utils/hook.hpp>
#include "game/game.hpp"
#include "utils/hook.hpp"
#include "player_movement.hpp"
const game::native::dvar_t* player_movement::player_sustainAmmo;
@ -13,6 +13,7 @@ const game::native::dvar_t* player_movement::jump_height;
const game::native::dvar_t* player_movement::jump_stepSize;
const game::native::dvar_t* player_movement::jump_spreadAdd;
const game::native::dvar_t* player_movement::pm_bounces;
const game::native::dvar_t* player_movement::pm_bouncesAllAngles;
const game::native::dvar_t* player_movement::pm_playerEjection;
const game::native::dvar_t* player_movement::pm_playerCollision;
const game::native::dvar_t* player_movement::pm_rocketJump;
@ -22,6 +23,7 @@ DWORD player_movement::bounce_addr;
DWORD player_movement::dont_bounce_addr;
DWORD player_movement::push_off_ladder_addr;
DWORD player_movement::jump_start_addr;
DWORD player_movement::jump_get_step_height_addr;
void player_movement::pm_weapon_use_ammo(game::native::playerState_s* ps, const game::native::Weapon weapon,
bool is_alternate, int amount, game::native::PlayerHandIndex hand)
@ -260,39 +262,16 @@ __declspec(naked) void player_movement::pm_crash_land_stub_sp()
}
}
bool player_movement::jump_get_step_height_stub_mp(game::native::playerState_s* ps, const float* origin, float* step_size)
{
assert(ps->pm_flags & game::native::PMF_JUMPING);
assert(origin != nullptr);
assert(step_size != nullptr);
if (origin[2] >= (jump_height->current.value + ps->jumpOriginZ))
{
return false;
}
*step_size = jump_stepSize->current.value;
if (ps->jumpOriginZ + jump_height->current.value < origin[2] + *step_size)
{
*step_size = (ps->jumpOriginZ + jump_height->current.value) - origin[2];
}
return true;
}
// On SP, only a simple patch is required because jump_height is still implemented by the game
__declspec(naked) void player_movement::jump_get_step_height_stub_sp()
__declspec(naked) void player_movement::jump_get_step_height_stub()
{
__asm
{
push eax
mov eax, player_movement::jump_stepSize
fadd dword ptr [eax + 0xC]
fld dword ptr [eax + 0xC]
pop eax
push 0x48C1FB
retn
jmp jump_get_step_height_addr
}
}
@ -309,6 +288,33 @@ __declspec(naked) void player_movement::jump_start_stub()
}
}
void player_movement::pm_project_velocity_stub(const float* vel_in, const float* normal, float* vel_out)
{
const auto length_squared_2d = vel_in[0] * vel_in[0] + vel_in[1] * vel_in[1];
if (std::fabsf(normal[2]) < 0.001f || length_squared_2d == 0.0f)
{
vel_out[0] = vel_in[0];
vel_out[1] = vel_in[1];
vel_out[2] = vel_in[2];
return;
}
auto new_z = vel_in[0] * normal[0] + vel_in[1] * normal[1];
new_z = -new_z / normal[2];
const auto length_scale = std::sqrtf((vel_in[2] * vel_in[2] + length_squared_2d) /
(new_z * new_z + length_squared_2d));
if (player_movement::pm_bouncesAllAngles->current.enabled == true
|| (length_scale < 1.f || new_z < 0.f || vel_in[2] > 0.f))
{
vel_out[0] = vel_in[0] * length_scale;
vel_out[1] = vel_in[1] * length_scale;
vel_out[2] = new_z * length_scale;
}
}
const game::native::dvar_t* player_movement::dvar_register_player_sustain_ammo(const char* dvar_name,
bool value, unsigned __int16 /*flags*/, const char* description)
{
@ -409,11 +415,14 @@ void player_movement::patch_mp()
utils::hook(0x422BE0, &player_movement::pm_crash_land_stub_mp, HOOK_CALL).install()->quick(); // PM_GroundTrace
utils::hook(0x424B2B, &player_movement::jump_get_step_height_stub_mp, HOOK_CALL).install()->quick(); // PM_StepSlideMove
utils::hook(0x41613F, &player_movement::jump_get_step_height_stub, HOOK_JUMP).install()->quick(); // PM_StepSlideMove
utils::hook::nop(0x416144, 1); // Nop skipped opcode
// Modify the hardcoded value of the spread with the value of jump_spreadAdd
utils::hook(0x4166F0, &player_movement::jump_start_stub, HOOK_JUMP).install()->quick();
utils::hook::nop(0x4166F5, 1); // Nop skipped opcode
utils::hook(0x424E0A, &player_movement::pm_project_velocity_stub, HOOK_CALL).install()->quick(); // PM_StepSlideMove
}
void player_movement::patch_sp()
@ -448,12 +457,14 @@ void player_movement::patch_sp()
utils::hook(0x6442DF, &player_movement::pm_crash_land_stub_sp, HOOK_CALL).install()->quick(); // PM_GroundTrace
utils::hook(0x48C1F5, &player_movement::jump_get_step_height_stub_sp, HOOK_JUMP).install()->quick(); // PM_StepSlideMove
utils::hook::nop(0x48C1FA, 1); // Nop skipped opcode
utils::hook(0x48C1DC, &player_movement::jump_get_step_height_stub, HOOK_JUMP).install()->quick(); // PM_StepSlideMove
utils::hook::nop(0x48C1E1, 1); // Nop skipped opcode
// Modify the hardcoded value of the spread with the value of jump_spreadAdd
utils::hook(0x63E90A, &player_movement::jump_start_stub, HOOK_JUMP).install()->quick();
utils::hook::nop(0x63E90F, 1); // Nop skipped opcode
utils::hook(0x43D9D1, &player_movement::pm_project_velocity_stub, HOOK_CALL).install()->quick(); // PM_StepSlideMove
}
void player_movement::post_load()
@ -470,9 +481,12 @@ void player_movement::post_load()
player_movement::dont_bounce_addr = SELECT_VALUE(0x43D933, 0x424D6C, 0x0);
player_movement::push_off_ladder_addr = SELECT_VALUE(0x63EA4C, 0x41686C, 0x0);
player_movement::jump_start_addr = SELECT_VALUE(0x63E910, 0x4166F6, 0x0);
player_movement::jump_get_step_height_addr = SELECT_VALUE(0x48C1E2, 0x416145, 0x0);
player_movement::pm_bounces = game::native::Dvar_RegisterBool("pm_bounces", false,
game::native::dvar_flags::DVAR_CODINFO, "CoD4 Bounces");
player_movement::pm_bouncesAllAngles = game::native::Dvar_RegisterBool("pm_bouncesAllAngles", false,
game::native::dvar_flags::DVAR_CODINFO, "Force bounces from all angles");
player_movement::pm_playerCollision = game::native::Dvar_RegisterBool("pm_playerCollision",
true, game::native::DVAR_CODINFO, "Push intersecting players away from each other");
player_movement::pm_elevators = game::native::Dvar_RegisterBool("pm_elevators",

View File

@ -1,5 +1,4 @@
#pragma once
#include "loader/module_loader.hpp"
class player_movement final : public module
{
@ -15,6 +14,7 @@ private:
static const game::native::dvar_t* jump_stepSize;
static const game::native::dvar_t* jump_spreadAdd;
static const game::native::dvar_t* pm_bounces;
static const game::native::dvar_t* pm_bouncesAllAngles;
static const game::native::dvar_t* pm_playerEjection;
static const game::native::dvar_t* pm_playerCollision;
static const game::native::dvar_t* pm_rocketJump;
@ -24,6 +24,7 @@ private:
static DWORD dont_bounce_addr;
static DWORD push_off_ladder_addr;
static DWORD jump_start_addr;
static DWORD jump_get_step_height_addr;
static void pm_weapon_use_ammo(game::native::playerState_s* ps, const game::native::Weapon weapon,
bool is_alternate, int amount, game::native::PlayerHandIndex hand);
@ -70,11 +71,12 @@ private:
static void pm_crash_land_stub_mp();
static void pm_crash_land_stub_sp();
static bool jump_get_step_height_stub_mp(game::native::playerState_s* ps, const float* origin, float* stepSize);
static void jump_get_step_height_stub_sp();
static void jump_get_step_height_stub();
static void jump_start_stub();
static void pm_project_velocity_stub(const float* vel_in, const float* normal, float* vel_out);
static void patch_mp();
static void patch_sp();
};

View File

@ -1,8 +1,10 @@
#include <std_include.hpp>
#include "scheduler.hpp"
#include "utils/string.hpp"
#include <loader/module_loader.hpp>
#include <utils/string.hpp>
#include <utils/hook.hpp>
#include "game/game.hpp"
#include "utils/hook.hpp"
#include "scheduler.hpp"
std::mutex scheduler::mutex_;
std::queue<std::pair<std::string, int>> scheduler::errors_;

View File

@ -1,5 +1,4 @@
#pragma once
#include "loader/module_loader.hpp"
#include "utils/concurrent_list.hpp"
class scheduler final : public module

View File

@ -1,7 +1,8 @@
#include <std_include.hpp>
#include "loader/module_loader.hpp"
#include "utils/hook.hpp"
#include "utils/io.hpp"
#include <loader/module_loader.hpp>
#include <utils/hook.hpp>
#include <utils/io.hpp>
#include "game/scripting/context.hpp"
#include "scheduler.hpp"

View File

@ -1,7 +1,8 @@
#include <std_include.hpp>
#include "loader/module_loader.hpp"
#include <loader/module_loader.hpp>
#include <utils/hook.hpp>
#include "game/game.hpp"
#include "utils/hook.hpp"
class security final : public module
{

View File

@ -1,10 +1,12 @@
#include <std_include.hpp>
#include "loader/module_loader.hpp"
#include "game/game.hpp"
#include "utils/nt.hpp"
#include <loader/module_loader.hpp>
#include <utils/nt.hpp>
#include <utils/string.hpp>
#include "steam/steam.hpp"
#include "steam/interface.hpp"
#include "utils/string.hpp"
#include "game/game.hpp"
#include "scheduler.hpp"
class steam_proxy final : public module

View File

@ -1,10 +1,11 @@
#include <std_include.hpp>
#include <loader/module_loader.hpp>
#include <utils/hook.hpp>
#include "game/game.hpp"
#include "test_clients.hpp"
#include "command.hpp"
#include "utils/hook.hpp"
bool test_clients::can_add()
{
auto i = 0;

View File

@ -1,6 +1,4 @@
#pragma once
#include "loader/module_loader.hpp"
#include "game/game.hpp"
class test_clients final : public module
{

View File

@ -1,4 +1,4 @@
#include <std_include.hpp>
#include "std_include.hpp"
#pragma comment(linker, "/merge:.data=.cld")
#pragma comment(linker, "/merge:.rdata=.clr")
@ -11,24 +11,25 @@
#pragma bss_seg(".payload")
char payload_data[BINARY_PAYLOAD_SIZE];
extern "C" {
int s_read_arc4random(void*, size_t)
extern "C"
{
return -1;
}
int s_read_arc4random(void*, size_t)
{
return -1;
}
int s_read_getrandom(void*, size_t)
{
return -1;
}
int s_read_getrandom(void*, size_t)
{
return -1;
}
int s_read_urandom(void*, size_t)
{
return -1;
}
int s_read_urandom(void*, size_t)
{
return -1;
}
int s_read_ltm_rng(void*, size_t)
{
return -1;
}
int s_read_ltm_rng(void*, size_t)
{
return -1;
}
}

View File

@ -53,7 +53,7 @@ namespace utils::io
if (size > -1)
{
data->resize(static_cast<uint32_t>(size));
stream.read(const_cast<char*>(data->data()), size);
stream.read(data->data(), size);
stream.close();
return true;
}

View File

@ -42,13 +42,13 @@ namespace utils
static void* allocate(size_t length);
template <typename T>
static inline T* allocate()
static T* allocate()
{
return allocate_array<T>(1);
}
template <typename T>
static inline T* allocate_array(const size_t count = 1)
static T* allocate_array(const size_t count = 1)
{
return static_cast<T*>(allocate(count * sizeof(T)));
}

View File

@ -228,7 +228,7 @@ namespace utils::nt
void relaunch_self()
{
const utils::nt::library self;
const library self;
STARTUPINFOA startup_info;
PROCESS_INFORMATION process_info;