Guest User

Untitled

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