Guest User

Untitled

a guest
Jan 23rd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 5.73 KB | None | 0 0
  1. @@ -1117,23 +1117,19 @@
  2.     return 1;
  3.  }
  4.  
  5. -static cell_t SetClientInfo(IPluginContext *pContext, const cell_t *params)
  6. +static bool SetClientInfoInternal(int client, const char* szKey, const char *szValue)
  7.  {
  8.     if (iserver == NULL)
  9.     {
  10. -       return pContext->ThrowNativeError("IServer interface not supported, file a bug report.");
  11. +       g_pSM->LogError(myself, "IServer interface not supported, file a bug report.");
  12. +       return false;
  13.     }
  14.  
  15. -   IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]);
  16. -   IClient *pClient = iserver->GetClient(params[1] - 1);
  17. -
  18. -   if (player == NULL || pClient == NULL)
  19. +   IClient *pClient = iserver->GetClient(client - 1);
  20. +   if (pClient == NULL)
  21.     {
  22. -       return pContext->ThrowNativeError("Invalid client index %d", params[1]);
  23. -   }
  24. -   if (!player->IsConnected())
  25. -   {
  26. -       return pContext->ThrowNativeError("Client %d is not connected", params[1]);
  27. +       g_pSM->LogError(myself, "Failed IClient lookup for client %d", client);
  28. +       return false;
  29.     }
  30.  
  31.     static ValveCall *pCall = NULL;
  32. @@ -1145,11 +1141,13 @@
  33.  
  34.         if (!CreateBaseCall("SetUserCvar", ValveCall_Entity, NULL, params, 2, &pCall))
  35.         {
  36. -           return pContext->ThrowNativeError("\"SetUserCvar\" not supported by this mod");
  37. +           g_pSM->LogError(myself, "\"SetUserCvar\" not supported by this mod");
  38. +           return false;
  39.         }
  40.         else if (!pCall)
  41.         {
  42. -           return pContext->ThrowNativeError("\"SetUserCvar\" wrapper failed to initialize");
  43. +           g_pSM->LogError(myself, "\"SetUserCvar\" wrapper failed to initialize");
  44. +           return false;
  45.         }
  46.     }
  47.  
  48. @@ -1160,11 +1158,13 @@
  49.     {
  50.         if (!CreateBaseCall("UpdateUserSettings", ValveCall_Entity, NULL, NULL, 0, &pUpdateSettings))
  51.         {
  52. -           return pContext->ThrowNativeError("\"SetUserCvar\" not supported by this mod");
  53. +           g_pSM->LogError(myself, "\"SetUserCvar\" not supported by this mod");
  54. +           return false;
  55.         }
  56.         else if (!pUpdateSettings)
  57.         {
  58. -           return pContext->ThrowNativeError("\"SetUserCvar\" wrapper failed to initialize");
  59. +           g_pSM->LogError(myself, "\"SetUserCvar\" wrapper failed to initialize");
  60. +           return false;
  61.         }
  62.     }
  63.  #else
  64. @@ -1174,7 +1174,8 @@
  65.     {  
  66.         if (!g_pGameConf->GetOffset("InfoChanged", &changedOffset))
  67.         {
  68. -           return pContext->ThrowNativeError("\"SetUserCvar\" not supported by this mod");
  69. +           g_pSM->LogError(myself, "\"SetUserCvar\" not supported by this mod");
  70. +           return false;
  71.         }
  72.     }
  73.  #endif
  74. @@ -1185,8 +1186,10 @@
  75.     /* Not really a CBaseEntity* but this works */
  76.     CBaseEntity **ebuf = (CBaseEntity **)vptr;
  77.     *ebuf = (CBaseEntity *)CGameClient;
  78. -   DECODE_VALVE_PARAM(2, vparams, 0);
  79. -   DECODE_VALVE_PARAM(3, vparams, 1);
  80. +   ebuf += sizeof(CBaseEntity *);
  81. +   *(const char **)ebuf = szKey;
  82. +   ebuf += sizeof(char *);
  83. +   *(const char **)ebuf = szValue;
  84.     FINISH_CALL_SIMPLE(NULL);
  85.  
  86.  #if SOURCE_ENGINE == SE_DARKMESSIAH
  87. @@ -1199,6 +1202,93 @@
  88.     *changed = 1;
  89.  #endif
  90.  
  91. +   return true;
  92. +}
  93. +
  94. +static cell_t SetClientInfo(IPluginContext *pContext, const cell_t *params)
  95. +{
  96. +   IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]);
  97. +   if (player == NULL)
  98. +   {
  99. +       return pContext->ThrowNativeError("Invalid client index %d", params[1]);
  100. +   }
  101. +   if (!player->IsConnected())
  102. +   {
  103. +       return pContext->ThrowNativeError("Client %d is not connected", params[1]);
  104. +   }
  105. +
  106. +   char *szKey;
  107. +   if (SP_ERROR_NONE != pContext->LocalToString(params[2], &szKey))
  108. +   {
  109. +       return pContext->ThrowNativeError("Error reading name");
  110. +   }
  111. +   char *szValue;
  112. +   if (SP_ERROR_NONE != pContext->LocalToString(params[3], &szValue))
  113. +   {
  114. +       return pContext->ThrowNativeError("Error reading name");
  115. +   }
  116. +   return SetClientInfoInternal(params[1], szKey, szValue);
  117. +}
  118. +
  119. +// We only need this for cstrike
  120. +#if SOURCE_ENGINE == SE_ORANGEBOXVALVE
  121. +#define MAX_NAME_LENGTH 32
  122. +static char newnames[65][MAX_NAME_LENGTH];
  123. +static char oldnames[65][MAX_NAME_LENGTH];
  124. +#define CHECKFIXNAME(name) \
  125. +   if (name[client][0] != '\0') \
  126. +   { \
  127. +       CBaseEntity *pEntity = gamehelpers->ReferenceToEntity(client); \
  128. +       datamap_t *datamap = gamehelpers->GetDataMap(pEntity); \
  129. +       typedescription_t *td = gamehelpers->FindInDataMap(datamap, "m_szNetname"); \
  130. +       int offset = GetTypeDescOffs(td); \
  131. +       char *dest = (char *)((intptr_t)pEntity + offset); \
  132. +       strncpy(dest, name[client], td->fieldSize); \
  133. +       name[client][0] = '\0'; \
  134. +       return; \
  135. +   }
  136. +void SDKTools::OnClientSettingsChanged(int client)
  137. +{
  138. +   CHECKFIXNAME(oldnames);
  139. +   CHECKFIXNAME(newnames);
  140. +}
  141. +#endif
  142. +
  143. +static cell_t RenameClient(IPluginContext *pContext, const cell_t *params)
  144. +{
  145. +   IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]);
  146. +   if (player == NULL)
  147. +   {
  148. +       return pContext->ThrowNativeError("Invalid client index %d", params[1]);
  149. +   }
  150. +   if (!player->IsConnected())
  151. +   {
  152. +       return pContext->ThrowNativeError("Client %d is not connected", params[1]);
  153. +   }
  154. +
  155. +   char *szNewName;
  156. +   if (SP_ERROR_NONE != pContext->LocalToString(params[2], &szNewName))
  157. +   {
  158. +       return pContext->ThrowNativeError("Error reading name");
  159. +   }
  160. +
  161. +#if SOURCE_ENGINE > SE_EPISODE1
  162. +   SetClientInfoInternal(params[1], "name", szNewName);
  163. +
  164. +#if SOURCE_ENGINE == SE_ORANGEBOXVALVE
  165. +   char gamedir[64];
  166. +   engine->GetGameDir(gamedir, sizeof(gamedir));
  167. +   if (strcmp(gamedir, "cstrike") == 0)
  168. +   {
  169. +       const char *szOldName = player->GetName();
  170. +       strncpy(oldnames[params[1]], szOldName, strlen(szOldName));
  171. +       strncpy(newnames[params[1]], szNewName, strlen(szNewName));
  172. +   }
  173. +#endif //SOURCE_ENGINE == SE_ORANGEBOXVALVE
  174. +#else
  175. +   engine->ClientCommand(player->GetEdict(), "name %s", szNewName);
  176. +#endif //SOURCE_ENGINE > SE_EPISODE1
  177. +
  178.     return 1;
  179.  }
  180.  
  181. @@ -1229,5 +1319,6 @@
  182.     {"EquipPlayerWeapon",       WeaponEquip},
  183.     {"ActivateEntity",          ActivateEntity},
  184.     {"SetClientInfo",           SetClientInfo},
  185. +   {"RenameClient",            RenameClient},
  186.     {NULL,                      NULL},
  187.  };
Add Comment
Please, Sign In to add comment