Skip to content

Commit

Permalink
Add detailed portal info to spt_print_portals
Browse files Browse the repository at this point in the history
  • Loading branch information
UncraftedName committed Oct 7, 2024
1 parent 109a3c7 commit b0e30b8
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 17 deletions.
4 changes: 4 additions & 0 deletions spt/features/game_fixes/vag_crash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ __declspec(naked) void VAG::HOOKED_EndOfTeleportTouchingEntity()
*/
void __fastcall VAG::HOOKED_MiddleOfTeleportTouchingEntity_Func(void* portalPtr, void* tpStackPointer)
{
/*unsigned int cur;
errno_t err = _controlfp_s(&cur, 0, 0);
Msg("fp control word: 0x%x, err: %d\n", cur, err);*/

if (!spt_vag.ORIG_EndOfTeleportTouchingEntity || !y_spt_prevent_vag_crash.GetBool())
return;
if (spt_vag.recursiveTeleportCount++ > 2)
Expand Down
91 changes: 74 additions & 17 deletions spt/utils/ent_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,87 @@ namespace utils

#ifdef SPT_PORTAL_UTILS

void PrintAllPortals()
{
int maxIndex = interfaces::entList->GetHighestEntityIndex();
#define FLOAT_SPEC "%g"

for (int i = 0; i <= maxIndex; ++i)
template<size_t R, size_t C>
static void PrintMatrix(const float (&arr)[R][C])
{
int fmtLens[R][C]{};
int maxLens[C]{};
for (int i = 0; i < C; i++)
{
auto ent = GetClientEntity(i);
if (!invalidPortal(ent))
for (int j = 0; j < R; j++)
{
fmtLens[j][i] = snprintf(nullptr, 0, FLOAT_SPEC, arr[j][i]);
if (fmtLens[j][i] > maxLens[i])
maxLens[i] = fmtLens[j][i];
}
}
for (int j = 0; j < R; j++)
{
for (int i = 0; i < C; i++)
{
auto& pos = ent->GetAbsOrigin();
auto& angles = ent->GetAbsAngles();
Msg("%d : %s, position (%.3f, %.3f, %.3f), angles (%.3f, %.3f, %.3f)\n",
i,
ent->GetClientClass()->m_pNetworkName,
pos.x,
pos.y,
pos.z,
angles.x,
angles.y,
angles.z);
Msg("%*s" FLOAT_SPEC "%s",
maxLens[i] - fmtLens[j][i],
"",
arr[j][i],
i == C - 1 ? (j == R - 1 ? "" : "\n") : ", ");
}
}
}

void PrintAllPortals()
{
auto PrintVec = [](Vector* v)
{ Msg("<" FLOAT_SPEC ", " FLOAT_SPEC ", " FLOAT_SPEC ">", v->x, v->y, v->z); };

for (int i = 0; i < MAX_EDICTS; i++)
{
edict_t* ed = interfaces::engine_server->PEntityOfEntIndex(i);
if (!ed || strcmp(ed->GetClassName(), "prop_portal"))
continue;
uintptr_t ent = reinterpret_cast<uintptr_t>(ed->GetIServerEntity()->GetBaseEntity());
// abs pos/ang
Vector* pos = (Vector*)(ent + 0x244);
QAngle* ang = (QAngle*)(ent + 0x2c0);
// rel pos/ang
/*Vector* pos = (Vector*)(ent + 0x2cc);
QAngle* ang = (QAngle*)(ent + 0x2d8);*/
Vector* f = (Vector*)(ent + 1360);
Vector* u = (Vector*)(ent + 1372);
Vector* r = (Vector*)(ent + 1364);
VPlane* plane = (VPlane*)(ent + 1396);
matrix3x4_t* mat = (matrix3x4_t*)(ent + 0x1f4);
VMatrix* thisToLinked = (VMatrix*)(ent + 0x430);

EHANDLE* linked = (EHANDLE*)(ent + 0x42c);
bool* activated = (bool*)(ent + 0x470);
bool* portal2 = (bool*)(ent + 0x471);

Msg("\n\n----------------------------------------\n\n[%d] %s %s portal:",
i,
linked->IsValid() ? "open" : (*activated ? "closed" : "invisible"),
*portal2 ? "orange" : "blue");
Msg("\npos: ");
PrintVec(pos);
Msg(", ang: ");
PrintVec((Vector*)ang);
Msg("\nf: ");
PrintVec(f);
Msg("\nr: ");
PrintVec(r);
Msg("\nu: ");
PrintVec(u);
Msg("\nplane: (n=");
PrintVec(&plane->m_Normal);
Msg(") d=" FLOAT_SPEC, plane->m_Dist);
Msg("\nmat:\n");
PrintMatrix(mat->m_flMatVal);
Msg("\n\nmat to linked:\n");
PrintMatrix(thisToLinked->m);
}
}

#endif

IClientEntity* GetPlayer()
Expand Down

0 comments on commit b0e30b8

Please sign in to comment.