aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDLL/exploitfixes.cpp
diff options
context:
space:
mode:
authorBobTheBob9 <for.oliver.kirkham@gmail.com>2022-08-22 21:59:18 +0100
committerBobTheBob9 <for.oliver.kirkham@gmail.com>2022-08-22 21:59:18 +0100
commitee8ae568bc42cb5311edd7294eb0f8f2ae078bd1 (patch)
tree9cb1cdb308d81772812cd4456f94634ee10b6670 /NorthstarDLL/exploitfixes.cpp
parent921668fd9578d514258edec7432b656cc5d7041d (diff)
downloadNorthstarLauncher-ee8ae568bc42cb5311edd7294eb0f8f2ae078bd1.tar.gz
NorthstarLauncher-ee8ae568bc42cb5311edd7294eb0f8f2ae078bd1.zip
add more prs
Diffstat (limited to 'NorthstarDLL/exploitfixes.cpp')
-rw-r--r--NorthstarDLL/exploitfixes.cpp90
1 files changed, 24 insertions, 66 deletions
diff --git a/NorthstarDLL/exploitfixes.cpp b/NorthstarDLL/exploitfixes.cpp
index a5d377b4..4ce9f351 100644
--- a/NorthstarDLL/exploitfixes.cpp
+++ b/NorthstarDLL/exploitfixes.cpp
@@ -33,35 +33,17 @@ bool ValidateFloats(float a, float b = 0, float c = 0)
return !isnan(a) && !isnan(b) && !isnan(c);
}
-struct Vector
+struct Float3
{
- float x, y, z;
+ float vals[3];
- Vector(float x = 0, float y = 0, float z = 0) : x(x), y(y), z(z) {}
-
- bool IsValid()
- {
- return ValidateFloats(x, y, z);
- }
-};
-
-struct Angle
-{
- float pitch, yaw, roll;
-
- Angle(float pitch = 0, float yaw = 0, float roll = 0) : pitch(pitch), yaw(yaw), roll(roll) {}
-
- bool IsInvalid()
+ void MakeValid()
{
- return !ValidateFloats(pitch, yaw, roll);
-
- if (!ValidateFloats(pitch, yaw, roll))
- return false;
-
- return (pitch > 90 || pitch < -90) || (yaw > 180 || yaw < -180) || (roll > 180 || roll < -180);
+ for (auto& val : vals)
+ if (isnan(val))
+ val = 0;
}
};
-
// block bad netmessages
// Servers can literally request a screenshot from any client, yeah no
AUTOHOOK(CLC_Screenshot_WriteToBuffer, engine.dll + 0x22AF20,
@@ -232,16 +214,16 @@ void, __fastcall, (void* buf, void* pCmd_move, void* pCmd_from)) // 4C 89 44 24
ReadUsercmd(buf, pCmd_move, pCmd_from);
// Now let's make sure the CMD we read isnt messed up to prevent numerous exploits (including server crashing)
- struct __declspec(align(4)) SV_CUserCmd
+ struct alignas(4) SV_CUserCmd
{
DWORD command_number;
DWORD tick_count;
float command_time;
- Angle worldViewAngles;
+ Float3 worldViewAngles;
BYTE gap18[4];
- Angle localViewAngles;
- Angle attackangles;
- Vector move;
+ Float3 localViewAngles;
+ Float3 attackangles;
+ Float3 move;
DWORD buttons;
BYTE impulse;
short weaponselect;
@@ -249,8 +231,8 @@ void, __fastcall, (void* buf, void* pCmd_move, void* pCmd_from)) // 4C 89 44 24
BYTE gap4C[24];
char headoffset;
BYTE gap65[11];
- Vector cameraPos;
- Angle cameraAngles;
+ Float3 cameraPos;
+ Float3 cameraAngles;
BYTE gap88[4];
int tickSomething;
DWORD dword90;
@@ -265,29 +247,17 @@ void, __fastcall, (void* buf, void* pCmd_move, void* pCmd_from)) // 4C 89 44 24
std::string BLOCK_PREFIX =
"ReadUsercmd (command_number delta: " + std::to_string(cmd->command_number - fromCmd->command_number) + "): ";
- if (cmd->worldViewAngles.IsInvalid())
- {
- BLOCKED_INFO("CMD has invalid worldViewAngles");
- goto INVALID_CMD;
- }
+ // fix invalid player angles
+ cmd->worldViewAngles.MakeValid();
+ cmd->attackangles.MakeValid();
+ cmd->localViewAngles.MakeValid();
- if (cmd->attackangles.IsInvalid())
- {
- BLOCKED_INFO("CMD has invalid attackangles");
- goto INVALID_CMD;
- }
+ // Fix invalid camera angles
+ cmd->cameraPos.MakeValid();
+ cmd->cameraAngles.MakeValid();
- if (cmd->localViewAngles.IsInvalid())
- {
- BLOCKED_INFO("CMD has invalid localViewAngles");
- goto INVALID_CMD;
- }
-
- if (cmd->cameraAngles.IsInvalid())
- {
- BLOCKED_INFO("CMD has invalid cameraAngles");
- goto INVALID_CMD;
- }
+ // Fix invaid movement vector
+ cmd->move.MakeValid();
if (cmd->frameTime <= 0 || cmd->tick_count == 0 || cmd->command_time <= 0)
{
@@ -297,27 +267,15 @@ void, __fastcall, (void* buf, void* pCmd_move, void* pCmd_from)) // 4C 89 44 24
goto INVALID_CMD; // No simulation of bogus-timed cmds
}
- if (!cmd->move.IsValid())
- {
- BLOCKED_INFO("Invalid move vector");
- goto INVALID_CMD;
- }
-
- if (!cmd->cameraPos.IsValid())
- {
- BLOCKED_INFO("Invalid cameraPos"); // IIRC this can crash spectating clients or anyone watching replays
- goto INVALID_CMD;
- }
-
return;
INVALID_CMD:
// Fix any gameplay-affecting cmd properties
// NOTE: Currently tickcount/frametime is set to 0, this ~shouldn't~ cause any problems
- cmd->worldViewAngles = cmd->localViewAngles = cmd->attackangles = cmd->cameraAngles = Angle(0, 0, 0);
+ cmd->worldViewAngles = cmd->localViewAngles = cmd->attackangles = cmd->cameraAngles = {0, 0, 0};
cmd->tick_count = cmd->frameTime = 0;
- cmd->move = cmd->cameraPos = Vector(0, 0, 0);
+ cmd->move = cmd->cameraPos = {0, 0, 0};
cmd->buttons = 0;
cmd->meleetarget = 0;
}