Пользователь
-
Автор темы
- #1
Onetap v2 trace to exit.
C++:
bool AutoWall::TraceToExit(Vector start, Vector dir, Vector& end, CGameTrace* enterTrace, CGameTrace* exitTrace)
{
int first_contents = 0;
float distance = 0.0;
Vector newOut;
CTraceFilter filter;
while (true)
{
distance += 4.0;
end = (dir * distance) + start;
int contents = g_pEngineTrace->GetPointContents(end, MASK_SHOT_HULL | CONTENTS_HITBOX);
if (!first_contents)
first_contents = contents;
if (contents & MASK_SHOT_HULL && (!(contents & CONTENTS_HITBOX) || first_contents == contents))
continue;
newOut = (end - (dir * 4.0));
g_pEngineTrace->TraceRay(Ray_t(end, newOut), MASK_SHOT, nullptr, exitTrace);
if (exitTrace->startsolid && (exitTrace->surface.flags & SURF_HITBOX))
{
filter.SetPassEntity(exitTrace->entity);
g_pEngineTrace->TraceRay(Ray_t(end, start), MASK_SHOT_HULL, &filter, exitTrace);
if (exitTrace->DidHit() && !exitTrace->startsolid)
{
end = exitTrace->endpos;
return true;
}
continue;
}
bool is_window = false;
bool flag = false;
int* name = (int*)enterTrace->surface.name;
if (enterTrace->surface.name)
{
if (*name != 0x7370616D
|| name[1] != 0x5F73632F
|| name[2] != 0x6966666F
|| name[3] != 0x672F6563
|| name[4] != 0x7373616C
|| name[5] != 0x6272752F
|| name[6] != 0x675F6E61
|| name[7] != 0x7373616C)
is_window = false;
else
is_window = true;
if (name[1] == 0x5F65642F
&& name[2] == 0x656B616C
&& name[3] == 0x616C672F
&& name[4] == 0x672F7373
&& name[5] == 0x7373616C)
{
flag = true;
if (is_window || flag)
{
exitTrace = enterTrace;
exitTrace->endpos = end + dir;
return true;
}
}
}
if (exitTrace->DidHit())
{
if (IsBreakable((C_BaseEntity*)enterTrace->entity) && IsBreakable((C_BaseEntity*)exitTrace->entity))
return true;
if (exitTrace->plane.normal.Dot(dir) <= 1.0)
{
end = end - (dir * (exitTrace->fraction * 4.0));
return true;
}
return true;
}
if (distance > 90.0)
continue;
}
exitTrace = enterTrace;
exitTrace->endpos = dir + end;
return true;
}