Merge pull request #75 from Rackover/feature/xinput

XInput native support
This commit is contained in:
Jan 2021-09-11 21:20:20 +02:00 committed by GitHub
commit 2ed973c1dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 3729 additions and 100 deletions

View File

@ -102,6 +102,7 @@ namespace Components
Loader::Register(new ConnectProtocol());
Loader::Register(new StartupMessages());
Loader::Register(new SoundMutexFix());
Loader::Register(new Gamepad());
Loader::Register(new Client());

View File

@ -132,4 +132,5 @@ namespace Components
#include "Modules/Stats.hpp"
#include "Modules/SoundMutexFix.hpp"
#include "Modules/Gamepad.hpp"
#include "Modules/Client.hpp"

View File

@ -2,6 +2,7 @@
namespace Components
{
char Colors::LastColorIndex;
Dvar::Var Colors::NewColors;
Dvar::Var Colors::ColorBlind;
Game::dvar_t* Colors::ColorAllyColorBlind;
@ -147,6 +148,8 @@ namespace Components
Utils::Hook::Set<char>(0x5A2E2E, limit); // No idea :P
Utils::Hook::Set<char>(0x5A2733, limit - '0'); // No idea :P
LastColorIndex = limit;
}
char Colors::Add(uint8_t r, uint8_t g, uint8_t b)

View File

@ -5,6 +5,8 @@ namespace Components
class Colors : public Component
{
public:
static char LastColorIndex;
Colors();
~Colors();

View File

@ -218,7 +218,7 @@ namespace Components
{
if (!Dedicated::IsEnabled() && Dvar::Var("sv_dontrotate").get<bool>())
{
Dvar::Var("sv_dontrotate").set(0);
Dvar::Var("sv_dontrotate").set(false);
return;
}

View File

@ -134,6 +134,36 @@ namespace Components
}
}
void Dvar::Var::setRaw(int integer)
{
assert(this->dvar->type == Game::DVAR_TYPE_INT);
if (this->dvar)
{
this->dvar->current.integer = integer;
this->dvar->latched.integer = integer;
}
}
void Dvar::Var::setRaw(float value)
{
assert(this->dvar->type == Game::DVAR_TYPE_FLOAT);
if (this->dvar)
{
this->dvar->current.value = value;
this->dvar->latched.value = value;
}
}
void Dvar::Var::setRaw(bool enabled)
{
assert(this->dvar->type == Game::DVAR_TYPE_BOOL);
if (this->dvar)
{
this->dvar->current.enabled = enabled;
this->dvar->latched.enabled = enabled;
}
}
template<> static Dvar::Var Dvar::Register(const char* name, bool value, Dvar::Flag flag, const char* description)
{
return Game::Dvar_RegisterBool(name, value, flag.val, description);

View File

@ -33,6 +33,10 @@ namespace Components
void set(float value);
void set(bool enabled);
void setRaw(int integer);
void setRaw(float value);
void setRaw(bool enabled);
private:
Game::dvar_t* dvar;
};

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,197 @@
#pragma once
namespace Components
{
class Gamepad : public Component
{
struct ControllerMenuKeyMapping
{
Game::keyNum_t controllerKey;
Game::keyNum_t pcKey;
};
struct GamePad
{
bool enabled;
bool inUse;
int portIndex;
unsigned short digitals;
unsigned short lastDigitals;
float analogs[2];
float lastAnalogs[2];
float sticks[4];
float lastSticks[4];
bool stickDown[4][Game::GPAD_STICK_DIR_COUNT];
bool stickDownLast[4][Game::GPAD_STICK_DIR_COUNT];
float lowRumble;
float highRumble;
XINPUT_VIBRATION rumble;
XINPUT_CAPABILITIES caps;
};
struct GamePadGlobals
{
Game::GpadAxesGlob axes;
unsigned nextScrollTime;
GamePadGlobals();
};
public:
Gamepad();
private:
static Game::ButtonToCodeMap_t buttonList[];
static Game::StickToCodeMap_t analogStickList[4];
static Game::GamePadStick stickForAxis[];
static Game::GamepadPhysicalAxis axisSameStick[];
static const char* physicalAxisNames[];
static const char* virtualAxisNames[];
static const char* gamePadMappingTypeNames[];
static Game::keyNum_t menuScrollButtonList[];
static Game::keyname_t extendedKeyNames[];
static Game::keyname_t extendedLocalizedKeyNames[];
static Game::keyname_t combinedKeyNames[];
static Game::keyname_t combinedLocalizedKeyNames[];
static ControllerMenuKeyMapping controllerMenuKeyMappings[];
static GamePad gamePads[Game::MAX_GAMEPADS];
static GamePadGlobals gamePadGlobals[Game::MAX_GAMEPADS];
static int gamePadBindingsModifiedFlags;
static Dvar::Var gpad_enabled;
static Dvar::Var gpad_debug;
static Dvar::Var gpad_present;
static Dvar::Var gpad_in_use;
static Dvar::Var gpad_sticksConfig;
static Dvar::Var gpad_buttonConfig;
static Dvar::Var gpad_menu_scroll_delay_first;
static Dvar::Var gpad_menu_scroll_delay_rest;
static Dvar::Var gpad_rumble;
static Dvar::Var gpad_stick_pressed_hysteresis;
static Dvar::Var gpad_stick_pressed;
static Dvar::Var gpad_stick_deadzone_max;
static Dvar::Var gpad_stick_deadzone_min;
static Dvar::Var gpad_button_deadzone;
static Dvar::Var gpad_button_rstick_deflect_max;
static Dvar::Var gpad_button_lstick_deflect_max;
static Dvar::Var gpad_use_hold_time;
static Dvar::Var gpad_lockon_enabled;
static Dvar::Var gpad_slowdown_enabled;
static Dvar::Var input_viewSensitivity;
static Dvar::Var input_invertPitch;
static Dvar::Var sv_allowAimAssist;
static Dvar::Var aim_turnrate_pitch;
static Dvar::Var aim_turnrate_pitch_ads;
static Dvar::Var aim_turnrate_yaw;
static Dvar::Var aim_turnrate_yaw_ads;
static Dvar::Var aim_accel_turnrate_enabled;
static Dvar::Var aim_accel_turnrate_lerp;
static Dvar::Var aim_input_graph_enabled;
static Dvar::Var aim_input_graph_index;
static Dvar::Var aim_scale_view_axis;
static Dvar::Var cl_bypassMouseInput;
static Dvar::Var cg_mapLocationSelectionCursorSpeed;
static Dvar::Var aim_aimAssistRangeScale;
static Dvar::Var aim_slowdown_enabled;
static Dvar::Var aim_slowdown_debug;
static Dvar::Var aim_slowdown_pitch_scale;
static Dvar::Var aim_slowdown_pitch_scale_ads;
static Dvar::Var aim_slowdown_yaw_scale;
static Dvar::Var aim_slowdown_yaw_scale_ads;
static Dvar::Var aim_lockon_enabled;
static Dvar::Var aim_lockon_deflection;
static Dvar::Var aim_lockon_pitch_strength;
static Dvar::Var aim_lockon_strength;
static void MSG_WriteDeltaUsercmdKeyStub();
static void ApplyMovement(Game::msg_t* msg, int key, Game::usercmd_s* from, Game::usercmd_s* to);
static void MSG_ReadDeltaUsercmdKeyStub();
static void MSG_ReadDeltaUsercmdKeyStub2();
static float LinearTrack(float target, float current, float rate, float deltaTime);
static bool AimAssist_DoBoundsIntersectCenterBox(const float* clipMins, const float* clipMaxs, float clipHalfWidth, float clipHalfHeight);
static bool AimAssist_IsPlayerUsingOffhand(Game::AimAssistPlayerState* ps);
static const Game::AimScreenTarget* AimAssist_GetBestTarget(const Game::AimAssistGlobals* aaGlob, float range, float regionWidth, float regionHeight);
static const Game::AimScreenTarget* AimAssist_GetTargetFromEntity(const Game::AimAssistGlobals* aaGlob, int entIndex);
static const Game::AimScreenTarget* AimAssist_GetPrevOrBestTarget(const Game::AimAssistGlobals* aaGlob, float range, float regionWidth, float regionHeight, int prevTargetEnt);
static bool AimAssist_IsLockonActive(int gamePadIndex);
static void AimAssist_ApplyLockOn(const Game::AimInput* input, Game::AimOutput* output);
static void AimAssist_CalcAdjustedAxis(const Game::AimInput* input, float* pitchAxis, float* yawAxis);
static bool AimAssist_IsSlowdownActive(const Game::AimAssistPlayerState* ps);
static void AimAssist_CalcSlowdown(const Game::AimInput* input, float* pitchScale, float* yawScale);
static float AimAssist_Lerp(float from, float to, float fraction);
static void AimAssist_ApplyTurnRates(const Game::AimInput* input, Game::AimOutput* output);
static void AimAssist_UpdateGamePadInput(const Game::AimInput* input, Game::AimOutput* output);
static void CL_RemoteControlMove_GamePad(int localClientNum, Game::usercmd_s* cmd);
static void CL_RemoteControlMove_Stub();
static bool CG_HandleLocationSelectionInput_GamePad(int localClientNum, Game::usercmd_s* cmd);
static void CG_HandleLocationSelectionInput_Stub();
static bool CG_ShouldUpdateViewAngles(int localClientNum);
static float CL_GamepadAxisValue(int gamePadIndex, Game::GamepadVirtualAxis virtualAxis);
static char ClampChar(int value);
static void CL_GamepadMove(int gamePadIndex, Game::usercmd_s* cmd, float frameTimeBase);
static void CL_MouseMove_Stub();
static bool Gamepad_ShouldUse(const Game::gentity_s* playerEnt, unsigned useTime);
static void Player_UseEntity_Stub();
static bool Key_IsValidGamePadChar(int key);
static void CL_GamepadResetMenuScrollTime(int gamePadIndex, int key, bool down, unsigned int time);
static bool Scoreboard_HandleInput(int gamePadIndex, int key);
static bool CL_CheckForIgnoreDueToRepeat(int gamePadIndex, int key, int repeatCount, unsigned int time);
static void UI_GamepadKeyEvent(int gamePadIndex, int key, bool down);
static void CL_GamepadGenerateAPad(int gamePadIndex, Game::GamepadPhysicalAxis physicalAxis, unsigned time);
static void CL_GamepadEvent(int gamePadIndex, Game::GamepadPhysicalAxis physicalAxis, float value, unsigned time);
static void CL_GamepadButtonEvent(int gamePadIndex, int key, Game::GamePadButtonEvent buttonEvent, unsigned time);
static void CL_GamepadButtonEventForPort(int gamePadIndex, int key, Game::GamePadButtonEvent buttonEvent, unsigned int time);
static void GPad_ConvertStickToFloat(short x, short y, float& outX, float& outY);
static float GPad_GetStick(int gamePadIndex, Game::GamePadStick stick);
static float GPad_GetButton(int gamePadIndex, Game::GamePadButton button);
static bool GPad_IsButtonPressed(int gamePadIndex, Game::GamePadButton button);
static bool GPad_ButtonRequiresUpdates(int gamePadIndex, Game::GamePadButton button);
static bool GPad_IsButtonReleased(int gamePadIndex, Game::GamePadButton button);
static void GPad_UpdateSticksDown(int gamePadIndex);
static void GPad_UpdateSticks(int gamePadIndex, const XINPUT_GAMEPAD& state);
static void GPad_UpdateDigitals(int gamePadIndex, const XINPUT_GAMEPAD& state);
static void GPad_UpdateAnalogs(int gamePadIndex, const XINPUT_GAMEPAD& state);
static bool GPad_Check(int gamePadIndex, int portIndex);
static void GPad_RefreshAll();
static void GPad_UpdateAll();
static void IN_GamePadsMove();
static void IN_Frame_Hk();
static void Gamepad_WriteBindings(int gamePadIndex, int handle);
static void Key_WriteBindings_Hk(int localClientNum, int handle);
static void Com_WriteConfiguration_Modified_Stub();
static void Gamepad_BindAxis(int gamePadIndex, Game::GamepadPhysicalAxis realIndex, Game::GamepadVirtualAxis axisIndex, Game::GamepadMapping mapType);
static Game::GamepadPhysicalAxis StringToPhysicalAxis(const char* str);
static Game::GamepadVirtualAxis StringToVirtualAxis(const char* str);
static Game::GamepadMapping StringToGamePadMapping(const char* str);
static void Axis_Bind_f(Command::Params* params);
static void Axis_Unbindall_f(Command::Params* params);
static void Bind_GP_SticksConfigs_f(Command::Params* params);
static void Bind_GP_ButtonsConfigs_f(Command::Params* params);
static void Scores_Toggle_f(Command::Params* params);
static void InitDvars();
static void IN_Init_Hk();
static const char* GetGamePadCommand(const char* command);
static int Key_GetCommandAssignmentInternal_Hk(const char* cmd, int(*keys)[2]);
static bool IsGamePadInUse();
static void CL_KeyEvent_Hk(int localClientNum, int key, int down, unsigned int time);
static int CL_MouseEvent_Hk(int x, int y, int dx, int dy);
static bool UI_RefreshViewport_Hk();
static void CreateKeyNameMap();
};
}

View File

@ -560,7 +560,7 @@ namespace Components
}
hasDlc.push_back(hasAllMaps);
Dvar::Var(Utils::String::VA("isDlcInstalled_%d", pack.index)).set(hasAllMaps ? 1 : 0);
Dvar::Var(Utils::String::VA("isDlcInstalled_%d", pack.index)).set(hasAllMaps ? true : false);
}
// Must have all of dlc 3 to 5 or it causes issues
@ -571,7 +571,7 @@ namespace Components
sentMessage = true;
}
Dvar::Var("isDlcInstalled_All").set(hasAllDlcs ? 1 : 0);
Dvar::Var("isDlcInstalled_All").set(hasAllDlcs ? true : false);
}
bool Maps::IsCustomMap()

View File

@ -197,6 +197,12 @@ namespace Components
add esp, 4h
mov [esp + 20h], eax
// Make all material text icons have white tint
mov eax,[esp + 0x50]
or eax,0x00FFFFFF
mov [esp + 0x50],eax
popad
pop eax
@ -285,6 +291,63 @@ namespace Components
#endif
int Materials::R_TextWidth_Hk(const char* text, int maxChars, Game::Font_s* font)
{
auto lineWidth = 0;
auto maxWidth = 0;
if (maxChars <= 0)
maxChars = 0x7FFFFFFF;
if (text == nullptr)
return 0;
auto count = 0;
while (text && *text && count < maxChars)
{
const auto letter = Game::SEH_ReadCharFromString(&text, nullptr);
if (letter == '\r' || letter == '\n')
{
lineWidth = 0;
}
else
{
if (letter == '^' && text)
{
if (*text >= '0' && *text <= Colors::LastColorIndex)
{
text++;
continue;
}
if (*text >= '\x01' && *text <= '\x02' && text[1] != '\0' && text[2] != '\0' && text[3] != '\0')
{
const auto width = text[1];
const auto materialNameLength = text[3];
// This is how the game calculates width and height. Probably some 1 byte floating point number.
auto v9 = font->pixelHeight * (width - 16) + 16;
auto w = ((((v9 >> 24) & 0x1F) + v9) >> 5);
lineWidth += w;
text += 4;
for (auto currentLength = 0; currentLength < materialNameLength && *text; currentLength++)
text++;
continue;
}
}
lineWidth += R_GetCharacterGlyph(font, letter)->dx;
if (lineWidth > maxWidth)
maxWidth = lineWidth;
count++;
}
}
return maxWidth;
}
Materials::Materials()
{
Materials::ImageNameLength = 7;
@ -293,6 +356,7 @@ namespace Components
Materials::ImageVersionCheckHook.initialize(0x53A456, Materials::ImageVersionCheck, HOOK_CALL)->install();
// Fix material pointer exploit
// Also make all material text icons have white tint
Utils::Hook(0x534E0C, Materials::DrawMaterialStub, HOOK_CALL).install()->quick();
// Increment string pointer accordingly
@ -307,6 +371,9 @@ namespace Components
// Debug material comparison
Utils::Hook::Set<void*>(0x523894, Materials::MaterialComparePrint);
// Consider material text icons when calculating text width
Utils::Hook(0x5056C0, Materials::R_TextWidth_Hk, HOOK_JUMP).install()->quick();
#ifdef DEBUG
if (Flags::HasFlag("dump"))
{

View File

@ -33,6 +33,8 @@ namespace Components
static int WriteDeathMessageIcon(char* string, int offset, Game::Material* material);
static void DeathMessageStub();
static int R_TextWidth_Hk(const char* text, int maxChars, Game::Font_s* font);
#ifdef DEBUG
static void DumpImageCfg(int, const char*, const char* material);
static void DumpImageCfgPath(int, const char*, const char* material);

View File

@ -897,6 +897,7 @@ namespace Components
Menus::Add("ui_mp/theater_menu.menu");
Menus::Add("ui_mp/pc_options_multi.menu");
Menus::Add("ui_mp/pc_options_game.menu");
Menus::Add("ui_mp/pc_options_gamepad.menu");
Menus::Add("ui_mp/stats_reset.menu");
Menus::Add("ui_mp/stats_unlock.menu");
Menus::Add("ui_mp/security_increase_popmenu.menu");

View File

@ -352,11 +352,9 @@ namespace Components
{
// execute our hook
pushad
pusha
call Script::StoreScriptBaseProgramNum
popa
popad
// execute overwritten code caused by the jump hook

View File

@ -30,13 +30,19 @@ namespace Game
BG_GetNumWeapons_t BG_GetNumWeapons = BG_GetNumWeapons_t(0x4F5CC0);
BG_GetWeaponName_t BG_GetWeaponName = BG_GetWeaponName_t(0x4E6EC0);
BG_LoadWeaponDef_LoadObj_t BG_LoadWeaponDef_LoadObj = BG_LoadWeaponDef_LoadObj_t(0x57B5F0);
BG_GetWeaponDef_t BG_GetWeaponDef = BG_GetWeaponDef_t(0x440EB0);
Cbuf_AddServerText_t Cbuf_AddServerText = Cbuf_AddServerText_t(0x4BB9B0);
Cbuf_AddText_t Cbuf_AddText = Cbuf_AddText_t(0x404B20);
CG_NextWeapon_f_t CG_NextWeapon_f = CG_NextWeapon_f_t(0x449DE0);
CG_GetClientNum_t CG_GetClientNum = CG_GetClientNum_t(0x433700);
CG_PlayBoltedEffect_t CG_PlayBoltedEffect = CG_PlayBoltedEffect_t(0x00430E10);
CG_GetBoneIndex_t CG_GetBoneIndex = CG_GetBoneIndex_t(0x00504F20);
CG_ScoresDown_f_t CG_ScoresDown_f = CG_ScoresDown_f_t(0x580370);
CG_ScoresUp_f_t CG_ScoresUp_f = CG_ScoresUp_f_t(0x5802C0);
CG_ScrollScoreboardUp_t CG_ScrollScoreboardUp = CG_ScrollScoreboardUp_t(0x47A5C0);
CG_ScrollScoreboardDown_t CG_ScrollScoreboardDown = CG_ScrollScoreboardDown_t(0x493B50);
CL_GetClientName_t CL_GetClientName = CL_GetClientName_t(0x4563D0);
CL_IsCgameInitialized_t CL_IsCgameInitialized = CL_IsCgameInitialized_t(0x43EB20);
@ -129,6 +135,7 @@ namespace Game
FS_FCloseFile_t FS_FCloseFile = FS_FCloseFile_t(0x462000);
FS_WriteFile_t FS_WriteFile = FS_WriteFile_t(0x426450);
FS_Write_t FS_Write = FS_Write_t(0x4C06E0);
FS_Printf_t FS_Printf = FS_Printf_t(0x459320);
FS_Read_t FS_Read = FS_Read_t(0x4A04C0);
FS_Seek_t FS_Seek = FS_Seek_t(0x4A63D0);
FS_FTell_t FS_FTell = FS_FTell_t(0x4E6760);
@ -148,6 +155,7 @@ namespace Game
Info_ValueForKey_t Info_ValueForKey = Info_ValueForKey_t(0x47C820);
Key_SetCatcher_t Key_SetCatcher = Key_SetCatcher_t(0x43BD00);
Key_IsKeyCatcherActive_t Key_IsKeyCatcherActive = Key_IsKeyCatcherActive_t(0x4DA010);
LargeLocalInit_t LargeLocalInit = LargeLocalInit_t(0x4A62A0);
@ -175,8 +183,12 @@ namespace Game
Menus_FindByName_t Menus_FindByName = Menus_FindByName_t(0x487240);
Menu_IsVisible_t Menu_IsVisible = Menu_IsVisible_t(0x4D77D0);
Menus_MenuIsInStack_t Menus_MenuIsInStack = Menus_MenuIsInStack_t(0x47ACB0);
Menu_HandleKey_t Menu_HandleKey = Menu_HandleKey_t(0x4C4A00);
Menu_GetFocused_t Menu_GetFocused = Menu_GetFocused_t(0x4AFF10);
MSG_Init_t MSG_Init = MSG_Init_t(0x45FCA0);
MSG_ReadBit_t MSG_ReadBit = MSG_ReadBit_t(0x476D20);
MSG_ReadBits_t MSG_ReadBits = MSG_ReadBits_t(0x4C3900);
MSG_ReadData_t MSG_ReadData = MSG_ReadData_t(0x4527C0);
MSG_ReadLong_t MSG_ReadLong = MSG_ReadLong_t(0x4C9550);
MSG_ReadShort_t MSG_ReadShort = MSG_ReadShort_t(0x40BDD0);
@ -272,6 +284,7 @@ namespace Game
SE_Load_t SE_Load = SE_Load_t(0x502A30);
SEH_StringEd_GetString_t SEH_StringEd_GetString = SEH_StringEd_GetString_t(0x44BB30);
SEH_ReadCharFromString_t SEH_ReadCharFromString = SEH_ReadCharFromString_t(0x486560);
Dvar_SetFromStringByName_t Dvar_SetFromStringByName = Dvar_SetFromStringByName_t(0x4F52E0);
Dvar_SetFromStringByNameFromSource_t Dvar_SetFromStringByNameFromSource = Dvar_SetFromStringByNameFromSource_t(0x4FC770);
@ -321,6 +334,7 @@ namespace Game
TeleportPlayer_t TeleportPlayer = TeleportPlayer_t(0x496850);
UI_AddMenuList_t UI_AddMenuList = UI_AddMenuList_t(0x4533C0);
UI_GetActiveMenu_t UI_GetActiveMenu = UI_GetActiveMenu_t(0x4BE790);
UI_CheckStringTranslation_t UI_CheckStringTranslation = UI_CheckStringTranslation_t(0x4FB010);
UI_LoadMenus_t UI_LoadMenus = UI_LoadMenus_t(0x641460);
UI_UpdateArenas_t UI_UpdateArenas = UI_UpdateArenas_t(0x4A95B0);
@ -329,13 +343,18 @@ namespace Game
UI_GetContext_t UI_GetContext = UI_GetContext_t(0x4F8940);
UI_TextWidth_t UI_TextWidth = UI_TextWidth_t(0x6315C0);
UI_DrawText_t UI_DrawText = UI_DrawText_t(0x49C0D0);
UI_KeyEvent_t UI_KeyEvent = UI_KeyEvent_t(0x4970F0);
Win_GetLanguage_t Win_GetLanguage = Win_GetLanguage_t(0x45CBA0);
Vec3UnpackUnitVec_t Vec3UnpackUnitVec = Vec3UnpackUnitVec_t(0x45CA90);
vectoyaw_t vectoyaw = vectoyaw_t(0x45AD10);
AngleNormalize360_t AngleNormalize360 = AngleNormalize360_t(0x438DC0);
unzClose_t unzClose = unzClose_t(0x41BF20);
AimAssist_ApplyAutoMelee_t AimAssist_ApplyAutoMelee = AimAssist_ApplyAutoMelee_t(0x56A360);
XAssetHeader* DB_XAssetPool = reinterpret_cast<XAssetHeader*>(0x7998A8);
unsigned int* g_poolSize = reinterpret_cast<unsigned int*>(0x7995E8);
@ -352,6 +371,9 @@ namespace Game
source_t **sourceFiles = reinterpret_cast<source_t **>(0x7C4A98);
keywordHash_t **menuParseKeywordHash = reinterpret_cast<keywordHash_t **>(0x63AE928);
float* cl_angles = reinterpret_cast<float*>(0xB2F8D0);
float* cgameFOVSensitivityScale = reinterpret_cast<float*>(0xB2F884);
int* svs_time = reinterpret_cast<int*>(0x31D9384);
int* svs_numclients = reinterpret_cast<int*>(0x31D938C);
client_t* svs_clients = reinterpret_cast<client_t*>(0x31D9390);
@ -426,6 +448,21 @@ namespace Game
GfxScene* scene = reinterpret_cast<GfxScene*>(0x6944914);
clientActive_t* clients = reinterpret_cast<clientActive_t*>(0xB2C698);
clientStatic_t* cls = reinterpret_cast<clientStatic_t*>(0xA7FE90);
cg_s* cgArray = reinterpret_cast<cg_s*>(0x7F0F78);
PlayerKeyState* playerKeys = reinterpret_cast<PlayerKeyState*>(0xA1B7D0);
kbutton_t* playersKb = reinterpret_cast<kbutton_t*>(0xA1A9A8);
AimAssistGlobals* aaGlobArray = reinterpret_cast<AimAssistGlobals*>(0x7A2110);
keyname_t* keyNames = reinterpret_cast<keyname_t*>(0x798580);
keyname_t* localizedKeyNames = reinterpret_cast<keyname_t*>(0x798880);
GraphFloat* aaInputGraph = reinterpret_cast<GraphFloat*>(0x7A2FC0);
XAssetHeader ReallocateAssetPool(XAssetType type, unsigned int newSize)
{
int elSize = DB_GetXAssetSizeHandlers[type]();
@ -698,14 +735,33 @@ namespace Game
return atoi(StringTable_Lookup(rankTable, 0, maxrank, 7));
}
void Vec3Normalize(vec3_t& vec)
float Vec2Normalize(vec2_t& vec)
{
const float length = std::sqrt((vec[0] * vec[0]) + (vec[1] * vec[1]));
if(length > 0.0f)
{
vec[0] /= length;
vec[1] /= length;
}
return length;
}
float Vec3Normalize(vec3_t& vec)
{
const float length = std::sqrt(std::pow(vec[0], 2.0f) + std::pow(vec[1], 2.0f) + std::pow(vec[2], 2.0f));
if(length > 0.0f)
{
const float length = static_cast<float>(std::sqrt(std::pow(vec[0], 2) + std::pow(vec[1], 2) + std::pow(vec[2], 2)));
vec[0] /= length;
vec[1] /= length;
vec[2] /= length;
}
return length;
}
void Vec2UnpackTexCoords(const PackedTexCoords in, vec2_t* out)
{
unsigned int v3; // xmm1_4
@ -901,7 +957,25 @@ namespace Game
Game::R_AddDebugLine(color, v[3], v[7]);
}
float GraphGetValueFromFraction(const int knotCount, const float(*knots)[2], const float fraction)
{
for (auto knotIndex = 1; knotIndex < knotCount; ++knotIndex)
{
if (knots[knotIndex][0] >= fraction)
{
const auto adjustedFraction = (fraction - knots[knotIndex - 1][0]) / (knots[knotIndex][0] - knots[knotIndex - 1][0]);
return (knots[knotIndex][1] - knots[knotIndex - 1][1]) * adjustedFraction + knots[knotIndex - 1][1];
}
}
return -1.0f;
}
float GraphFloat_GetValue(const GraphFloat* graph, const float fraction)
{
return GraphGetValueFromFraction(graph->knotCount, graph->knots, fraction) * graph->scale;
}
#pragma optimize("", off)
__declspec(naked) float UI_GetScoreboardLeft(void* /*a1*/)
@ -966,6 +1040,21 @@ namespace Game
}
}
bool PM_IsAdsAllowed(Game::playerState_s* playerState)
{
bool result;
__asm
{
mov esi, playerState
mov ebx, 0x5755A0
call ebx
mov result, al // AL
}
return result;
}
__declspec(naked) void FS_AddLocalizedGameDirectory(const char* /*path*/, const char* /*dir*/)
{
__asm
@ -1140,6 +1229,32 @@ namespace Game
}
}
void Menu_SetNextCursorItem(Game::UiContext* a1, Game::menuDef_t* a2, int unk)
{
__asm
{
push unk
push a2
mov eax, a1
mov ebx, 0x639FE0
call ebx
add esp, 0x8 // 2 args = 2x4
}
}
void Menu_SetPrevCursorItem(Game::UiContext* a1, Game::menuDef_t* a2, int unk)
{
__asm
{
push unk
push a2
mov eax, a1
mov ebx, 0x639F20
call ebx
add esp, 0x8 // 2 args = 2x4
}
}
__declspec(naked) void R_AddDebugLine(float* /*color*/, float* /*v1*/, float* /*v2*/)
{
__asm
@ -1199,5 +1314,48 @@ namespace Game
retn
}
}
__declspec(naked) Glyph* R_GetCharacterGlyph(Font_s* /*font */, unsigned int /*letter*/)
{
__asm
{
push eax
pushad
mov edi, [esp + 0x28 + 4]
push [esp + 0x24 + 4]
mov eax, 0x5055C0
call eax
add esp,0x4
mov [esp + 0x20],eax
popad
pop eax
retn
}
}
__declspec(naked) void AimAssist_UpdateTweakables(int /*localClientNum*/)
{
__asm
{
mov eax,[esp+0x4]
mov ebx,0x569950
call ebx
retn
}
}
__declspec(naked) void AimAssist_UpdateAdsLerp(const AimInput* /*aimInput*/)
{
__asm
{
mov eax, [esp + 0x4]
mov ebx, 0x569AA0
call ebx
retn
}
}
#pragma optimize("", on)
}

View File

@ -40,6 +40,9 @@ namespace Game
typedef void*(__cdecl * BG_LoadWeaponDef_LoadObj_t)(const char* filename);
extern BG_LoadWeaponDef_LoadObj_t BG_LoadWeaponDef_LoadObj;
typedef WeaponDef* (__cdecl * BG_GetWeaponDef_t)(int weaponIndex);
extern BG_GetWeaponDef_t BG_GetWeaponDef;
typedef void(__cdecl * Cbuf_AddServerText_t)();
extern Cbuf_AddServerText_t Cbuf_AddServerText;
@ -49,12 +52,27 @@ namespace Game
typedef int(__cdecl * CG_GetClientNum_t)();
extern CG_GetClientNum_t CG_GetClientNum;
typedef std::int32_t(__cdecl* CG_PlayBoltedEffect_t) (std::int32_t, FxEffectDef*, std::int32_t, std::uint32_t);
typedef void(__cdecl * CG_NextWeapon_f_t)();
extern CG_NextWeapon_f_t CG_NextWeapon_f;
typedef std::int32_t(__cdecl * CG_PlayBoltedEffect_t) (std::int32_t, FxEffectDef*, std::int32_t, std::uint32_t);
extern CG_PlayBoltedEffect_t CG_PlayBoltedEffect;
typedef std::int32_t(__cdecl* CG_GetBoneIndex_t)(std::int32_t, std::uint32_t name, char* index);
typedef std::int32_t(__cdecl * CG_GetBoneIndex_t)(std::int32_t, std::uint32_t name, char* index);
extern CG_GetBoneIndex_t CG_GetBoneIndex;
typedef void(__cdecl * CG_ScoresDown_f_t)();
extern CG_ScoresDown_f_t CG_ScoresDown_f;
typedef void(__cdecl * CG_ScoresUp_f_t)();
extern CG_ScoresUp_f_t CG_ScoresUp_f;
typedef void(__cdecl * CG_ScrollScoreboardUp_t)(cg_s* cgameGlob);
extern CG_ScrollScoreboardUp_t CG_ScrollScoreboardUp;
typedef void(__cdecl * CG_ScrollScoreboardDown_t)(cg_s* cgameGlob);
extern CG_ScrollScoreboardDown_t CG_ScrollScoreboardDown;
typedef char*(__cdecl * CL_GetClientName_t)(int localClientNum, int index, char *buf, size_t size);
extern CL_GetClientName_t CL_GetClientName;
@ -311,6 +329,9 @@ namespace Game
typedef int(__cdecl * FS_Write_t)(const void* buffer, size_t size, int file);
extern FS_Write_t FS_Write;
typedef int(__cdecl * FS_Printf_t)(int file, const char* fmt, ...);
extern FS_Printf_t FS_Printf;
typedef int(__cdecl * FS_Read_t)(void* buffer, size_t size, int file);
extern FS_Read_t FS_Read;
@ -354,6 +375,9 @@ namespace Game
typedef void(__cdecl * Key_SetCatcher_t)(int localClientNum, int catcher);
extern Key_SetCatcher_t Key_SetCatcher;
typedef bool(__cdecl * Key_IsKeyCatcherActive_t)(int localClientNum, int catcher);
extern Key_IsKeyCatcherActive_t Key_IsKeyCatcherActive;
typedef void(__cdecl * LargeLocalInit_t)();
extern LargeLocalInit_t LargeLocalInit;
@ -426,6 +450,15 @@ namespace Game
typedef bool(__cdecl * Menus_MenuIsInStack_t)(UiContext *dc, menuDef_t *menu);
extern Menus_MenuIsInStack_t Menus_MenuIsInStack;
typedef menuDef_t*(__cdecl * Menu_GetFocused_t)(UiContext* ctx);
extern Menu_GetFocused_t Menu_GetFocused;
typedef void(__cdecl * Menu_HandleKey_t)(UiContext* ctx, menuDef_t* menu, Game::keyNum_t key, int down);
extern Menu_HandleKey_t Menu_HandleKey;
typedef bool(__cdecl * UI_KeyEvent_t)(int clientNum, int key, int down);
extern UI_KeyEvent_t UI_KeyEvent;
typedef void(__cdecl * MSG_Init_t)(msg_t *buf, char *data, int length);
extern MSG_Init_t MSG_Init;
@ -435,6 +468,12 @@ namespace Game
typedef int(__cdecl * MSG_ReadLong_t)(msg_t* msg);
extern MSG_ReadLong_t MSG_ReadLong;
typedef int(__cdecl * MSG_ReadBit_t)(msg_t* msg);
extern MSG_ReadBit_t MSG_ReadBit;
typedef int(__cdecl * MSG_ReadBits_t)(msg_t* msg, int bits);
extern MSG_ReadBits_t MSG_ReadBits;
typedef short(__cdecl * MSG_ReadShort_t)(msg_t* msg);
extern MSG_ReadShort_t MSG_ReadShort;
@ -462,10 +501,10 @@ namespace Game
typedef void(__cdecl * MSG_WriteLong_t)(msg_t *msg, int c);
extern MSG_WriteLong_t MSG_WriteLong;
typedef void(*MSG_WriteShort_t)(msg_t* msg, short s);
typedef void(__cdecl * MSG_WriteShort_t)(msg_t* msg, short s);
extern MSG_WriteShort_t MSG_WriteShort;
typedef void(*MSG_WriteString_t)(msg_t* msg, const char *str);
typedef void(__cdecl * MSG_WriteString_t)(msg_t* msg, const char *str);
extern MSG_WriteString_t MSG_WriteString;
typedef int(__cdecl * MSG_WriteBitsCompress_t)(bool trainHuffman, const char *from, char *to, int size);
@ -657,6 +696,9 @@ namespace Game
typedef char* (__cdecl * SEH_StringEd_GetString_t)(const char* string);
extern SEH_StringEd_GetString_t SEH_StringEd_GetString;
typedef int (__cdecl * SEH_ReadCharFromString_t)(const char** text, int* isTrailingPunctuation);
extern SEH_ReadCharFromString_t SEH_ReadCharFromString;
typedef char* (__cdecl * SL_ConvertToString_t)(unsigned short stringValue);
extern SL_ConvertToString_t SL_ConvertToString;
@ -753,6 +795,9 @@ namespace Game
typedef void(__cdecl * UI_AddMenuList_t)(UiContext *dc, MenuList *menuList, int close);
extern UI_AddMenuList_t UI_AddMenuList;
typedef uiMenuCommand_t(__cdecl * UI_GetActiveMenu_t)(int localClientNum);
extern UI_GetActiveMenu_t UI_GetActiveMenu;
typedef char* (__cdecl * UI_CheckStringTranslation_t)(char*, char*);
extern UI_CheckStringTranslation_t UI_CheckStringTranslation;
@ -783,9 +828,18 @@ namespace Game
typedef void (__cdecl * Vec3UnpackUnitVec_t)(PackedUnitVec, vec3_t *);
extern Vec3UnpackUnitVec_t Vec3UnpackUnitVec;
typedef float(__cdecl * vectoyaw_t)(vec2_t* vec);
extern vectoyaw_t vectoyaw;
typedef float(__cdecl * AngleNormalize360_t)(float val);
extern AngleNormalize360_t AngleNormalize360;
typedef void(__cdecl * unzClose_t)(void* handle);
extern unzClose_t unzClose;
typedef void(__cdecl * AimAssist_ApplyAutoMelee_t)(const AimInput* input, AimOutput* output);
extern AimAssist_ApplyAutoMelee_t AimAssist_ApplyAutoMelee;
extern XAssetHeader* DB_XAssetPool;
extern unsigned int* g_poolSize;
@ -799,6 +853,9 @@ namespace Game
extern cmd_function_t** cmd_functions;
extern float* cl_angles;
extern float* cgameFOVSensitivityScale;
extern int* svs_time;
extern int* svs_numclients;
extern client_t* svs_clients;
@ -875,8 +932,28 @@ namespace Game
extern GfxScene* scene;
extern clientActive_t* clients;
extern clientStatic_t* cls;
extern cg_s* cgArray;
extern PlayerKeyState* playerKeys;
extern kbutton_t* playersKb;
extern AimAssistGlobals* aaGlobArray;
constexpr auto KEY_NAME_COUNT = 95;
constexpr auto LOCALIZED_KEY_NAME_COUNT = 95;
extern keyname_t* keyNames;
extern keyname_t* localizedKeyNames;
constexpr auto AIM_ASSIST_GRAPH_COUNT = 4u;
extern GraphFloat* aaInputGraph;
XAssetHeader ReallocateAssetPool(XAssetType type, unsigned int newSize);
void Menu_FreeItemMemory(Game::itemDef_s* item);
void Menu_SetNextCursorItem(Game::UiContext* ctx, Game::menuDef_t* currentMenu, int unk = 1);
void Menu_SetPrevCursorItem(Game::UiContext* ctx, Game::menuDef_t* currentMenu, int unk = 1);
const char* TableLookup(StringTable* stringtable, int row, int column);
const char* UI_LocalizeMapName(const char* mapName);
const char* UI_LocalizeGameType(const char* gameType);
@ -892,6 +969,8 @@ namespace Game
void FS_AddLocalizedGameDirectory(const char *path, const char *dir);
bool PM_IsAdsAllowed(Game::playerState_s* playerState);
void ShowMessageBox(const std::string& message, const std::string& title);
unsigned int R_HashString(const char* string);
@ -920,7 +999,8 @@ namespace Game
void Image_Setup(GfxImage* image, unsigned int width, unsigned int height, unsigned int depth, unsigned int flags, _D3DFORMAT format);
void Vec3Normalize(vec3_t& vec);
float Vec2Normalize(vec2_t& vec);
float Vec3Normalize(vec3_t& vec);
void Vec2UnpackTexCoords(const PackedTexCoords in, vec2_t* out);
void MatrixVecMultiply(const float(&mulMat)[3][3], const vec3_t& mulVec, vec3_t& solution);
void QuatRot(vec3_t* vec, const vec4_t* quat);
@ -931,4 +1011,12 @@ namespace Game
void R_AddDebugString(float *color, float *pos, float scale, const char *str);
void R_AddDebugBounds(float* color, Bounds* b);
void R_AddDebugBounds(float* color, Bounds* b, const float(*quat)[4]);
float GraphGetValueFromFraction(int knotCount, const float(*knots)[2], float fraction);
float GraphFloat_GetValue(const GraphFloat* graph, const float fraction);
Glyph* R_GetCharacterGlyph(Font_s* font, unsigned int letter);
void AimAssist_UpdateTweakables(int localClientNum);
void AimAssist_UpdateAdsLerp(const AimInput* input);
}

File diff suppressed because it is too large Load Diff

View File

@ -10,6 +10,7 @@
#define VC_EXTRALEAN
#define WIN32_LEAN_AND_MEAN
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
// Requires Visual Leak Detector plugin: http://vld.codeplex.com/
#define VLD_FORCE_ENABLE
@ -39,6 +40,8 @@
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <limits>
#include <cmath>
// Experimental C++17 features
#include <filesystem>
@ -49,6 +52,9 @@
#include <d3dx9tex.h>
#pragma comment(lib, "D3dx9.lib")
#include <Xinput.h>
#pragma comment (lib, "xinput.lib")
// Usefull for debugging
template <size_t S> class Sizer { };
#define BindNum(x, y) Sizer<x> y;