L L4D2node

CBaseServer::CalculateCPUUsage

0x001078b0 · 388 bytes · __thiscall

_ZN11CBaseServer17CalculateCPUUsageEv

Decompiled

undefined (1 param)

/* CBaseServer::CalculateCPUUsage() */

void __thiscall CBaseServer::CalculateCPUUsage(CBaseServer *this)

{
  float fVar1;
  int iVar2;
  rusage *prVar3;
  __time_t *p_Var4;
  byte bVar5;
  longdouble lVar6;
  float fVar7;
  float fVar8;
  rusage local_64;
  
  bVar5 = 0;
  if (*(int *)(sv_stats._28_4_ + 0x30) != 0) {
    if (*(float *)(this + 0x144) == 0.0) {
      lVar6 = (longdouble)Plat_FloatTime();
      *(float *)(this + 0x144) = (float)lVar6;
    }
    lVar6 = (longdouble)Plat_FloatTime();
    if (*(float *)(this + 0x148) + 1.0 < (float)lVar6) {
      iVar2 = getrusage(RUSAGE_SELF,&local_64);
      if (iVar2 == 0) {
        fVar1 = *(float *)(this + 0x148);
        fVar8 = CalculateCPUUsage()::lastAvg + 5.0;
        fVar7 = ((float)((local_64.ru_utime.tv_usec - DAT_00354d84) / 1000000) +
                (float)(local_64.ru_utime.tv_sec - CalculateCPUUsage()::s_lastUsage)) /
                (fVar1 - CalculateCPUUsage()::lastAvg);
        *(float *)(this + 0x140) = fVar7;
        if (fVar8 < fVar1) {
          prVar3 = &local_64;
          p_Var4 = &CalculateCPUUsage()::s_lastUsage;
          CalculateCPUUsage()::lastAvg = fVar1;
          for (iVar2 = 0x12; iVar2 != 0; iVar2 = iVar2 + -1) {
            *p_Var4 = (prVar3->ru_utime).tv_sec;
            prVar3 = (rusage *)((int)prVar3 + (uint)bVar5 * -8 + 4);
            p_Var4 = p_Var4 + (uint)bVar5 * -2 + 1;
          }
        }
      }
      else {
        fVar7 = *(float *)(this + 0x140);
      }
      if (fVar7 <= 0.999) {
        if (fVar7 < 0.0) {
          *(undefined4 *)(this + 0x140) = 0;
        }
      }
      else {
        *(undefined4 *)(this + 0x140) = 0x3f7fbe77;
      }
      lVar6 = (longdouble)Plat_FloatTime();
      *(float *)(this + 0x148) = (float)lVar6;
      return;
    }
  }
  return;
}

SourceMod gamedata

paste into addons/sourcemod/gamedata/<your_plugin>.txt
used as the SourceMod key — change to fit your plugin's convention
SourceMod library name (server / engine / matchmaking)

Just a Signatures{} block, ready to drop into a gamedata file. Wire it up in your plugin however you like - SDKCall, DHooks, raw memory ops, or anything else.



        

        

          

Type inference is best-effort from the C signature - sanity-check the DHooks types before shipping.

Return-type handling cheatsheet (DHookReturn)