L L4D2node

CSocketCreator::ConnectSocket

0x0028c770 · 719 bytes · __thiscall

_ZN14CSocketCreator13ConnectSocketERK8netadr_sb

Decompiled

undefined (3 params)

/* CSocketCreator::ConnectSocket(netadr_s const&, bool) */

int __thiscall CSocketCreator::ConnectSocket(CSocketCreator *this,netadr_s *param_1,bool param_2)

{
  uint *puVar1;
  undefined2 uVar2;
  undefined4 *puVar3;
  char cVar4;
  uint __fd;
  int iVar5;
  int *piVar6;
  char *pcVar7;
  __fd_mask *p_Var8;
  int in_GS_OFFSET;
  undefined4 local_c0;
  undefined4 local_bc;
  timeval local_b8;
  uint local_b0 [32];
  sockaddr local_30;
  int local_20;
  
  local_20 = *(int *)(in_GS_OFFSET + 0x14);
  if (param_2) {
    CloseAllAcceptedSockets(this);
  }
  __fd = socket(2,1,6);
  if (__fd == 0xffffffff) {
    piVar6 = __errno_location();
    pcVar7 = strerror(*piVar6);
    Warning("Unable to create socket (%s)\n",pcVar7);
    iVar5 = -1;
    goto LAB_0028c912;
  }
  local_c0 = 1;
  iVar5 = ioctl(__fd,0x5421,&local_c0);
  if (iVar5 == -1) {
    piVar6 = __errno_location();
    pcVar7 = strerror(*piVar6);
    Warning("Socket ioctl(FIONBIO) failed (%s)\n",pcVar7);
    close(__fd);
    iVar5 = -1;
    goto LAB_0028c912;
  }
  local_bc = 1;
  setsockopt(__fd,6,1,&local_bc,4);
  netadr_s::ToSockadr(param_1,&local_30);
  iVar5 = connect(__fd,&local_30,0x10);
  if (iVar5 == -1) {
    piVar6 = __errno_location();
    iVar5 = *piVar6;
    if ((iVar5 == 0x73) || (iVar5 == 0xb)) {
      local_b8.tv_usec = 0;
      local_b8.tv_sec = 1;
      p_Var8 = (__fd_mask *)local_b0;
      for (iVar5 = 0x20; iVar5 != 0; iVar5 = iVar5 + -1) {
        *p_Var8 = 0;
        p_Var8 = p_Var8 + 1;
      }
      local_b0[__fd >> 5] = local_b0[__fd >> 5] | 1 << ((byte)__fd & 0x1f);
      iVar5 = select(__fd + 1,(fd_set *)0x0,(fd_set *)local_b0,(fd_set *)0x0,&local_b8);
      if (0 < iVar5) goto LAB_0028c857;
      goto LAB_0028c876;
    }
    pcVar7 = strerror(iVar5);
    Warning("Socket connection failed (%s)\n",pcVar7);
    close(__fd);
  }
  else {
LAB_0028c857:
    puVar3 = *(undefined4 **)this;
    if ((puVar3 == (undefined4 *)0x0) ||
       (cVar4 = (**(code **)*puVar3)(puVar3,__fd,param_1), cVar4 != '\0')) {
      local_b0[0] = 0;
      iVar5 = CUtlVector<CSocketCreator::AcceptedSocket_t,CUtlMemory<CSocketCreator::AcceptedSocket_t,int>>
              ::InsertBefore((CUtlVector<CSocketCreator::AcceptedSocket_t,CUtlMemory<CSocketCreator::AcceptedSocket_t,int>>
                              *)(this + 4),*(int *)(this + 0x10));
      puVar1 = (uint *)(*(int *)(this + 4) + iVar5 * 0x14);
      *puVar1 = __fd;
      puVar1[1] = *(uint *)param_1;
      puVar1[2] = *(uint *)(param_1 + 4);
      uVar2 = *(undefined2 *)(param_1 + 8);
      puVar1[4] = 0;
      *(undefined2 *)(puVar1 + 3) = uVar2;
      piVar6 = *(int **)this;
      if (piVar6 != (int *)0x0) {
        (**(code **)(*piVar6 + 4))(piVar6,__fd,param_1,local_b0);
      }
      puVar1[4] = local_b0[0];
      goto LAB_0028c912;
    }
LAB_0028c876:
    close(__fd);
  }
  iVar5 = -1;
LAB_0028c912:
  if (local_20 != *(int *)(in_GS_OFFSET + 0x14)) {
                    /* WARNING: Subroutine does not return */
    __stack_chk_fail();
  }
  return iVar5;
}

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)