L L4D2node

CWeaponMeleeSpawn::MakeWeaponSelection

0x008d8e20 · 1280 bytes · __thiscall

_ZN17CWeaponMeleeSpawn19MakeWeaponSelectionEv

Decompiled

undefined (1 param)

/* CWeaponMeleeSpawn::MakeWeaponSelection() */

void __thiscall CWeaponMeleeSpawn::MakeWeaponSelection(CWeaponMeleeSpawn *this)

{
  void *pvVar1;
  undefined4 uVar2;
  char *pcVar3;
  int iVar4;
  int iVar5;
  char *pcVar6;
  uint uVar7;
  uint uVar8;
  char *__dest;
  uint *puVar9;
  uint *puVar10;
  int iVar11;
  int in_GS_OFFSET;
  undefined1 *this_00;
  void *local_134;
  int local_130;
  int local_12c;
  int local_128;
  void *local_124;
  uint local_120 [64];
  int local_20;
  
  local_20 = *(int *)(in_GS_OFFSET + 0x14);
  uVar2 = CMeleeWeaponInfoStore::GetInvalidHandle();
  *(undefined4 *)(this + 0x1468) = uVar2;
  pcVar3 = (char *)(**(code **)(*(int *)this + 0x3f0))(this);
  iVar4 = _V_stricmp(pcVar3,"any");
  if (iVar4 == 0) {
    iVar4 = CMeleeWeaponInfoStore::GetRandomMeleeWeapon
                      ((CMeleeWeaponInfoStore *)g_MeleeWeaponInfoStore);
    *(int *)(this + 0x1468) = iVar4;
    this_00 = g_MeleeWeaponInfoStore;
    iVar5 = CMeleeWeaponInfoStore::GetInvalidHandle();
    if (iVar5 != iVar4) goto LAB_008d8ea7;
  }
  else {
    local_134 = (void *)0x0;
    local_130 = 0;
    local_12c = 0;
    local_128 = 0;
    local_124 = (void *)0x0;
                    /* try { // try from 008d8f1d to 008d9131 has its CatchHandler @ 008d934f */
    pcVar6 = (char *)nexttoken((char *)local_120,0x100,pcVar3,',');
    while ((char)local_120[0] != '\0') {
      iVar4 = CMeleeWeaponInfoStore::GetInfoHandle
                        ((CMeleeWeaponInfoStore *)g_MeleeWeaponInfoStore,(char *)local_120);
      iVar5 = CMeleeWeaponInfoStore::GetInvalidHandle();
      puVar10 = local_120;
      if (iVar4 == iVar5) {
        Warning("weapon_melee_spawn specifying an invalid melee weapon ( for this campaign? ) : %s\n"
                ,local_120);
      }
      else {
        do {
          puVar9 = puVar10;
          uVar7 = *puVar9 + 0xfefefeff & ~*puVar9;
          uVar8 = uVar7 & 0x80808080;
          puVar10 = puVar9 + 1;
        } while (uVar8 == 0);
        if ((uVar7 & 0x8080) == 0) {
          puVar10 = (uint *)((int)puVar9 + 6);
          uVar8 = uVar8 >> 0x10;
        }
        __dest = operator_new__((uint)((int)puVar10 +
                                      (-(int)local_120 - (uint)CARRY1((byte)uVar8,(byte)uVar8)) + -2
                                      ));
        strcpy(__dest,(char *)local_120);
        iVar5 = local_128;
        iVar4 = local_128 + 1;
        if ((local_130 < iVar4) && (-1 < local_12c)) {
          if (local_12c == 0) {
            if (local_130 == 0) {
              if (iVar4 < 9) {
                local_130 = 8;
                goto LAB_008d906f;
              }
              local_130 = 8;
            }
            do {
              local_130 = local_130 * 2;
            } while (local_130 < iVar4);
          }
          else {
            for (local_130 = (local_128 / local_12c + 1) * local_12c; local_130 < iVar4;
                local_130 = (local_130 + iVar4) / 2) {
            }
          }
LAB_008d906f:
          if (local_134 == (void *)0x0) {
            local_134 = malloc(local_130 << 2);
          }
          else {
            local_134 = realloc(local_134,local_130 << 2);
            iVar4 = local_128 + 1;
          }
        }
        iVar11 = iVar5 * 4;
        iVar5 = (iVar4 - iVar5) + -1;
        local_128 = iVar4;
        local_124 = local_134;
        if (0 < iVar5) {
          _V_memmove((void *)((int)local_134 + iVar11 + 4),(void *)((int)local_134 + iVar11),
                     iVar5 * 4);
        }
        if ((undefined4 *)(iVar11 + (int)local_134) != (undefined4 *)0x0) {
          *(undefined4 *)(iVar11 + (int)local_134) = __dest;
        }
      }
      pcVar6 = (char *)nexttoken((char *)local_120,0x100,pcVar6,',');
    }
    if (local_128 < 1) {
                    /* try { // try from 008d9262 to 008d9274 has its CatchHandler @ 008d934f */
      Warning("weapon_melee_spawn failed to spawn a melee weapon - using string \'%s\'\n",pcVar3);
      UTIL_Remove((CBaseEntity *)this);
      iVar4 = 0;
      if (0 < local_128) {
        do {
          pvVar1 = *(void **)((int)local_134 + iVar4 * 4);
          if (pvVar1 != (void *)0x0) {
            operator_delete__(pvVar1);
          }
          iVar4 = iVar4 + 1;
        } while (iVar4 < local_128);
      }
      this_00 = (undefined1 *)&local_134;
      iVar4 = 0;
      local_128 = 0;
      CUtlMemory<char*,int>::Purge((CUtlMemory<char*,int> *)this_00);
      local_124 = local_134;
      if (0 < local_128) {
        do {
          iVar5 = iVar4 * 4;
          iVar4 = iVar4 + 1;
          operator_delete(*(void **)((int)local_134 + iVar5));
        } while (iVar4 < local_128);
      }
      local_128 = 0;
      CUtlMemory<char*,int>::Purge((CUtlMemory<char*,int> *)this_00);
      local_128 = 0;
      local_124 = local_134;
      CUtlMemory<char*,int>::Purge((CUtlMemory<char*,int> *)this_00);
      local_124 = local_134;
      CUtlMemory<char*,int>::Purge((CUtlMemory<char*,int> *)this_00);
      goto LAB_008d8ea7;
    }
    iVar4 = RandomInt(0,local_128 + -1);
    uVar2 = CMeleeWeaponInfoStore::GetInfoHandle
                      ((CMeleeWeaponInfoStore *)g_MeleeWeaponInfoStore,
                       *(char **)((int)local_134 + iVar4 * 4));
    iVar4 = 0;
    *(undefined4 *)(this + 0x1468) = uVar2;
    if (0 < local_128) {
      do {
        pvVar1 = *(void **)((int)local_134 + iVar4 * 4);
        if (pvVar1 != (void *)0x0) {
          operator_delete__(pvVar1);
        }
        iVar4 = iVar4 + 1;
      } while (iVar4 < local_128);
    }
    iVar4 = 0;
    local_128 = 0;
    CUtlMemory<char*,int>::Purge((CUtlMemory<char*,int> *)&local_134);
    local_124 = local_134;
    if (0 < local_128) {
      do {
        iVar5 = iVar4 * 4;
        iVar4 = iVar4 + 1;
        operator_delete(*(void **)((int)local_134 + iVar5));
      } while (iVar4 < local_128);
    }
    local_128 = 0;
    CUtlMemory<char*,int>::Purge((CUtlMemory<char*,int> *)&local_134);
    local_128 = 0;
    local_124 = local_134;
    CUtlMemory<char*,int>::Purge((CUtlMemory<char*,int> *)&local_134);
    local_124 = local_134;
    CUtlMemory<char*,int>::Purge((CUtlMemory<char*,int> *)&local_134);
    iVar4 = *(int *)(this + 0x1468);
    this_00 = g_MeleeWeaponInfoStore;
    iVar5 = CMeleeWeaponInfoStore::GetInvalidHandle();
    if (iVar5 != iVar4) goto LAB_008d8ea7;
  }
  Warning("weapon_melee_spawn trying to spawn an invalid melee weapon type - using string \'%s\'\n",
          pcVar3);
  UTIL_Remove((CBaseEntity *)this);
  this_00 = this;
LAB_008d8ea7:
  if (local_20 != *(int *)(in_GS_OFFSET + 0x14)) {
                    /* WARNING: Subroutine does not return */
    __stack_chk_fail(this_00);
  }
  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)