Created
October 29, 2025 18:59
-
-
Save sequoiadotdev/e9fb15459636647e42be8b4ca2f4e493 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <cmath> | |
| typedef struct { float x, y, z; } Vec3; | |
| typedef struct { Vec3 v1, v2, v3; } Input; | |
| typedef struct { | |
| bool active; | |
| int ticks; | |
| float speed, drag, grav, pad; | |
| Vec3 start; | |
| } Bullet; | |
| typedef struct { const char* msg; int status; } Result; | |
| bool ValidateBulletTrajectory(Vec3* aim, Bullet* b, Input* in) { | |
| float vy = b->grav * in->v3.y; | |
| float vx = b->grav * in->v2.x; | |
| float vz = b->grav * in->v2.z; | |
| float tol = fabsf(b->drag * 0.02f); | |
| int steps = b->active ? (b->ticks + 1) : 1; | |
| if (steps < 1) return false; | |
| float gpt = b->drag * b->speed * 0.02f; | |
| for (int i = 0; i < steps; i++) { | |
| if (i) { | |
| vy -= gpt; | |
| tol += fabsf(gpt); | |
| } | |
| Vec3 pos = b->start; | |
| for (int j = 0; j < i + 1; j++) { | |
| float cvy = vy; | |
| if (j) { | |
| pos.x += vx * 0.02f; | |
| pos.z += vz * 0.02f; | |
| cvy = vy + gpt; | |
| pos.y += vy * 0.02f; | |
| } | |
| if (j == i) { | |
| float dist = b->active ? (sqrtf(cvy*cvy + vx*vx + vz*vz) * 0.02f) : b->speed; | |
| float vmag = sqrtf(cvy*cvy + vx*vx + vz*vz); | |
| Vec3 nv = {0, 0, 0}; | |
| if (vmag > 1e-05f) { | |
| nv = (Vec3){cvy/vmag, vx/vmag, vz/vmag}; | |
| } | |
| float bt = b->active ? tol : 0.5f; | |
| Vec3 tt = {in->v1.x - pos.x, in->v1.y - pos.y, in->v1.z - pos.z}; | |
| Vec3 pm = {nv.x * dist, nv.y * dist, nv.z * dist}; | |
| float ps = (tt.x*pm.x + tt.y*pm.y + tt.z*pm.z) / | |
| (pm.x*pm.x + pm.y*pm.y + pm.z*pm.z); | |
| Vec3 cp = {pos.x + ps*pm.x, pos.y + ps*pm.y, pos.z + ps*pm.z}; | |
| float amag = sqrtf(aim->x*aim->x + aim->y*aim->y + aim->z*aim->z); | |
| float md = 0.5f; | |
| if (amag > 0.0f) { | |
| bt += fabsf(aim->y) * 4.0f; | |
| md = amag * 4.0f + 0.5f; | |
| } | |
| Vec3 tc = {in->v1.x - cp.x, in->v1.y - cp.y, in->v1.z - cp.z}; | |
| float pd = sqrtf(tc.x*tc.x + tc.z*tc.z); | |
| float hd = fabsf(tt.y - ps*pm.y); | |
| if (pd < md && hd < bt) return true; | |
| } | |
| } | |
| } | |
| return false; | |
| } | |
| float Mag(Vec3 v) { | |
| return sqrtf(v.x * v.x + v.y * v.y + v.z * v.z); | |
| } | |
| float Dist(Vec3 a, Vec3 b) { | |
| return Mag((Vec3){b.x - a.x, b.y - a.y, b.z - a.z}); | |
| } | |
| float Dot(Vec3 a, Vec3 b) { | |
| return a.x * b.x + a.y * b.y + a.z * b.z; | |
| } | |
| bool CheckInputLength(bool hasInput, Input* in) { | |
| float m2 = sqrtf(in->v2.x * in->v2.x + in->v2.y * in->v2.y + in->v2.z * in->v2.z); | |
| if (fabsf(m2 - 1.0f) > 0.005f) return true; | |
| if (hasInput) { | |
| float m3 = sqrtf(in->v3.x * in->v3.x + in->v3.y * in->v3.y + in->v3.z * in->v3.z); | |
| if (fabsf(m3 - 1.0f) > 0.005f) return true; | |
| } | |
| return false; | |
| } | |
| Result CheckRaycastBasic(bool living, bool failDir, bool hasInput, bool suspect, | |
| bool vehicle, float maxRange, Vec3 fwd, Vec3 pos, | |
| Vec3 aimDiff, Input* in) { | |
| Result r; | |
| float dist = Dist(pos, in->v1); | |
| float thresh = Mag(aimDiff) * 0.5f + maxRange + 0.25f; | |
| if (CheckInputLength(hasInput, in)) return (Result){"type: C", 4}; | |
| if (hasInput && Dot(in->v2, in->v3) > 0.0f) return (Result){"type: D", 4}; | |
| if (dist > thresh && !vehicle) { | |
| r.msg = "type: E"; | |
| r.status = (dist <= thresh + 1.0f || living) ? 0 : 1; | |
| return r; | |
| } | |
| if (dist <= thresh || vehicle) { | |
| if (failDir) { | |
| r.msg = "type: F"; | |
| r.status = (living && !suspect) ? 1 : 0; | |
| return r; | |
| } | |
| if (hasInput) { | |
| float tDist = Dist(fwd, in->v3); | |
| if (tDist > 0.03f && !vehicle) { | |
| r.msg = "type: G"; | |
| r.status = suspect ? 3 : ((living && tDist > 1.8f) ? 1 : 0); | |
| return r; | |
| } | |
| } | |
| return (Result){"", 0}; | |
| } | |
| return (Result){"type: E", 0}; | |
| } | |
| Result CheckRaycastBullet(bool living, bool mismatch, bool hasInput, bool suspect, | |
| bool vehicle, Vec3* aim, Bullet* b, Input* in) { | |
| if (hasInput && !vehicle) { | |
| Bullet lb = *b; | |
| Input li = *in; | |
| Vec3 la = *aim; | |
| if (!ValidateBulletTrajectory(&la, &lb, &li)) { | |
| return (Result){"type: E", suspect ? 1 : 0}; | |
| } | |
| } | |
| return (Result){"", 0}; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
+rep Best unturned anticheat