diff --git a/README.md b/README.md index 7e30bcb..9d3cfe4 100644 --- a/README.md +++ b/README.md @@ -31,4 +31,14 @@ void CMovementSpeedMod::InputSpeedMod(inputdata_t &data) [...] ``` -**NOP**'d out the block. \ No newline at end of file +**NOP**'d out the block. + +# Configuration +In cstrike/cfg/server.cfg add this +``` +//============================================================================ +// Late load support - since multiples things need to be init before load it +// The upcoming extensions can not use autoload file + +sm exts load CSSFixes +``` diff --git a/package/addons/sourcemod/extensions/CSSFixes.autoload b/package/addons/sourcemod/extensions/CSSFixes.autoload deleted file mode 100644 index e69de29..0000000 diff --git a/product.version b/product.version index ec6d649..b57fc72 100644 --- a/product.version +++ b/product.version @@ -1 +1 @@ -1.18.1 +1.18.2 diff --git a/src/extension.cpp b/src/extension.cpp index f4ccc58..81323cb 100644 --- a/src/extension.cpp +++ b/src/extension.cpp @@ -1,33 +1,33 @@ /** - * vim: set ts=4 : - * ============================================================================= - * SourceMod Sample Extension - * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. - * ============================================================================= - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License, version 3.0, as published by the - * Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - * - * As a special exception, AlliedModders LLC gives you permission to link the - * code of this program (as well as its derivative works) to "Half-Life 2," the - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software - * by the Valve Corporation. You must obey the GNU General Public License in - * all respects for all other code used. Additionally, AlliedModders LLC grants - * this exception to all derivative works. AlliedModders LLC defines further - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), - * or . - * - * Version: $Id$ - */ +* vim: set ts=4 : +* ============================================================================= +* SourceMod Sample Extension +* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. +* ============================================================================= +* +* This program is free software; you can redistribute it and/or modify it under +* the terms of the GNU General Public License, version 3.0, as published by the +* Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +* details. +* +* You should have received a copy of the GNU General Public License along with +* this program. If not, see . +* +* As a special exception, AlliedModders LLC gives you permission to link the +* code of this program (as well as its derivative works) to "Half-Life 2," the +* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software +* by the Valve Corporation. You must obey the GNU General Public License in +* all respects for all other code used. Additionally, AlliedModders LLC grants +* this exception to all derivative works. AlliedModders LLC defines further +* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), +* or . +* +* Version: $Id$ +*/ #include "extension.h" #include "CDetour/detours.h" @@ -40,6 +40,9 @@ #include #include +#define VPROF_ENABLED +#include + #define SetBit(A,I) ((A)[(I) >> 5] |= (1 << ((I) & 31))) #define ClearBit(A,I) ((A)[(I) >> 5] &= ~(1 << ((I) & 31))) #define CheckBit(A,I) !!((A)[(I) >> 5] & (1 << ((I) & 31))) @@ -149,69 +152,77 @@ static struct SrcdsPatch // 0: game_ui should not apply FL_ONTRAIN flag, else client prediction turns off { "_ZN7CGameUI5ThinkEv", - (unsigned char *)"\xC7\x44\x24\x04\x10\x00\x00\x00\x89\x34\x24\xE8\x00\x00\x00\x00", - "xxxxxxxxxxxx????", - (unsigned char *)"\xC7\x44\x24\x04\x10\x00\x00\x00\x89\x34\x24\x90\x90\x90\x90\x90", + (unsigned char *)"\x0F\x82\xC4\x03\x00\x00\x83\xEC\x08\x6A\x10\x53\xE8\x91\x00\xF5\xFF", + "xx????xx?x?xx????", + (unsigned char *)"\x0F\x82\xC4\x03\x00\x00\x83\xEC\x08\x6A\x10\x53\x90\x90\x90\x90\x90", "cstrike/bin/server_srv.so" }, // 1: player_speedmod should not turn off flashlight { "_ZN17CMovementSpeedMod13InputSpeedModER11inputdata_t", - (unsigned char *)"\xFF\x90\x8C\x05\x00\x00\x85\xC0\x0F\x85\x85\x02\x00\x00", - "xxxxxxxxxxxxxx", - (unsigned char *)"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90", + (unsigned char *)"\x8B\x90\xA4\x05\x00\x00\x81\xFA\x10\x6E\x3E\x00\x0F\x85\xC7\x02\x00\x00\x8B\x80\xA0\x05\x00\x00\x3D\x00\x6E\x3E\x00\x0F\x85\xEE\x02\x00\x00", + "xx????xx????xx????xx????x????xx????", + (unsigned char *)"\x8B\x90\xA4\x05\x00\x00\x81\xFA\x10\x6E\x3E\x00\x0F\x84\xC7\x02\x00\x00\x8B\x80\xA0\x05\x00\x00\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90", "cstrike/bin/server_srv.so" }, // 2: only select CT spawnpoints { "_ZN9CCSPlayer19EntSelectSpawnPointEv", - (unsigned char *)"\x89\x1C\x24\xE8\x00\x00\x00\x00\x83\xF8\x03\x74\x6B", - "xxxx????xxxxx", - (unsigned char *)"\x89\x1C\x24\x90\x90\x90\x90\x90\x90\x90\x90\xEB\x6B", + (unsigned char *)"\x74\x57\x83\xEC\x0C\x53\xE8\x6E\x34\xCA\xFF\x83\xC4\x10\x83\xF8\x02\x0F\x84", + "x?xx?xx????xx?xx?xx", + (unsigned char *)"\xEB\x57\x83\xEC\x0C\x53\xE8\x6E\x34\xCA\xFF\x83\xC4\x10\x83\xF8\x02\x0F\x84", "cstrike/bin/server_srv.so" }, // 3: don't check if we have T spawns { "_ZN12CCSGameRules18NeededPlayersCheckERb", - (unsigned char *)"\x74\x0E\x8B\x83\x80\x02\x00\x00\x85\xC0\x0F\x85\x9E\x00\x00\x00\xC7\x04\x24\xAC\xF7\x87\x00\xE8\xC2\x82\x91\x00", - "xxxxxxxxxxxxxxxx????????????", - (unsigned char *)"\x0F\x85\xA8\x00\x00\x00\x8B\x83\x80\x02\x00\x00\x85\xC0\x0F\x85\x9A\x00\x00\x00\x90\x90\x90\x90\x90\x90\x90\x90", + (unsigned char *)"\x74\x0A\x8B\x83\x94\x02\x00\x00\x85\xC0\x75\x4A\x83\xEC\x0C\x68\xE8\xCF\x93\x00\xE8\xA9\x46\x52\x00\x5A\x59", + "xxxx????xxx?xx?x????x????xx", + (unsigned char *)"\x75\x54\x8B\x83\x94\x02\x00\x00\x85\xC0\x75\x4A\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90", "cstrike/bin/server_srv.so" }, // 5: disable alive check in point_viewcontrol->Disable { "_ZN14CTriggerCamera7DisableEv", - (unsigned char *)"\x8B\x10\x89\x04\x24\xFF\x92\x08\x01\x00\x00\x84\xC0\x0F\x84\x58\xFF\xFF\xFF", - "xxxxxxx??xxxxxx?xxx", - (unsigned char *)"\x8B\x10\x89\x04\x24\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90", + (unsigned char *)"\x0F\x84\x47\x02\x00\x00\xF6\x83\x40\x01\x00\x00\x20\x0F\x85", + "xx????xx?????xx", + (unsigned char *)"\x90\x90\x90\x90\x90\x90\xF6\x83\x40\x01\x00\x00\x20\x0F\x85", "cstrike/bin/server_srv.so" }, // 6: disable player->m_takedamage = DAMAGE_NO in point_viewcontrol->Enable { "_ZN14CTriggerCamera6EnableEv", - (unsigned char *)"\xC6\x86\x00\x00\x00\x00\x00\x8B\x83\x00\x00\x00\x00\xA8\x20", - "xx?????xx????xx", - (unsigned char *)"\x90\x90\x90\x90\x90\x90\x90\x8B\x83\x00\x00\x00\x00\xA8\x20", + (unsigned char *)"\xC6\x80\xFD\x00\x00\x00\x00\x8B\x83", + "xxxxxxxxx", + (unsigned char *)"\x90\x90\x90\x90\x90\x90\x90\x8B\x83", "cstrike/bin/server_srv.so", 0x600 }, // 7: disable player->m_takedamage = m_nOldTakeDamage in point_viewcontrol->Disable { "_ZN14CTriggerCamera7DisableEv", - (unsigned char *)"\x89\xF9\x38\x8E\xFD\x00\x00\x00\x0F\x84\xCA\xFD\xFF\xFF", - "xxxx?xxxxxxxxx", - (unsigned char *)"\x89\xF9\x38\x8E\xFD\x00\x00\x00\x90\xE9\xCA\xFD\xFF\xFF", + (unsigned char *)"\x74\x1A\x8B\x16\x8B\x92\x04\x02\x00\x00\x81\xFA\x30\xF9\x29\x00\x0F\x85", + "x?xxxx????xx????xx", + (unsigned char *)"\xEB\x1A\x8B\x16\x8B\x92\x04\x02\x00\x00\x81\xFA\x30\xF9\x29\x00\x0F\x85", "cstrike/bin/server_srv.so" }, // 8: userinfo stringtable don't write fakeclient field { "_ZN11CBaseClient12FillUserInfoER13player_info_s", - (unsigned char *)"\xFF\x50\x70\x88\x46\x6C", - "xxxxxx", - (unsigned char *)"\x90\x90\x90\x90\x90\x90", + (unsigned char *)"\x88\x46\x6C", + "xxx", + (unsigned char *)"\x90\x90\x90", "bin/engine_srv.so" }, - // 9: fix server lagging resulting from too many ConMsgs due to packet spam + // 9: dont reset cash to 16000 when buying an item + { + "_ZN9CCSPlayer10AddAccountEibbPKc", + (unsigned char *)"\x3D\x80\x3E\x00\x00\x0F\x8F\x00\x00\x00\x00\x8D\x65", + "x????xx????xx", + (unsigned char *)"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x8D\x65", + "cstrike/bin/server_srv.so" + }, + // 10: fix server lagging resulting from too many ConMsgs due to packet spam { "_ZN8CNetChan19ProcessPacketHeaderEP11netpacket_s", (unsigned char *)"_Z6ConMsgPKcz", @@ -221,7 +232,7 @@ static struct SrcdsPatch 0x7d1, 100, true, "bin/libtier0_srv.so" }, - // 10: fix server lagging resulting from too many ConMsgs due to packet spam + // 11: fix server lagging resulting from too many ConMsgs due to packet spam { "_Z11NET_GetLongiP11netpacket_s", (unsigned char *)"Msg", @@ -231,7 +242,8 @@ static struct SrcdsPatch 0x800, 100, true, "bin/libtier0_srv.so" }, - // 11: Always transmit point_viewcontrol (for debugging) + // 12: Always transmit point_viewcontrol (for debugging) + /* { "_ZN14CTriggerCamera19UpdateTransmitStateEv", (unsigned char *)"\x74\x16", @@ -239,22 +251,32 @@ static struct SrcdsPatch (unsigned char *)"\xEB\x16", "cstrike/bin/server_srv.so" }, - // 12: CTriggerCamera::FollowTarget: Don't early return when the player handle is null + */ + // 13: CTriggerCamera::FollowTarget: Don't early return when the player handle is null { "_ZN14CTriggerCamera12FollowTargetEv", - (unsigned char *)"\x74\x1B\x89\xD0\x25\x00\x00\x00\x00\xC1\xE0\x04", - "xxxxx????xxx", - (unsigned char *)"\xEB\x23\x89\xD0\x25\x00\x00\x00\x00\xC1\xE0\x04", + (unsigned char *)"\x0F\x84\xD6\x02\x00\x00\x83\xFA\xFF", + "xxxxxxxxx", + (unsigned char *)"\x90\x90\x90\x90\x90\x90\x83\xFA\xFF", "cstrike/bin/server_srv.so" }, - // 13: CGameMovement::LadderMove NOP out player->SetGravity( 0 ); + // 14: CGameMovement::LadderMove NOP out player->SetGravity( 0 ); + // This is in a cloned function which has a weird symbol (_ZN13CGameMovement10LadderMoveEv_part_0) so I went with the function right before it { - "_ZN13CGameMovement10LadderMoveEv", - (unsigned char *)"\xC7\x80\x78\x02\x00\x00\x00\x00\x00\x00", - "xxxxxxx???", - (unsigned char *)"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90", + "_ZN13CGameMovement12CheckFallingEv", + (unsigned char *)"\xC7\x80\xA4\x02\x00\x00\x00\x00\x00\x00\x8B\x03\x8B\x80", + "xx????????xxxx", + (unsigned char *)"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x8B\x03\x8B\x80", "cstrike/bin/server_srv.so" }, + // 18: Remove weird filename handle check in CZipPackFile::GetFileInfo that broke loading mixed case files in bsp pakfiles + { + "_ZN12CZipPackFile11GetFileInfoEPKcRiRxS2_S2_Rt", + (unsigned char *)"\x75\x00\x8B\x09", + "x?xx", + (unsigned char *)"\x90\x90\x8B\x09", + "bin/dedicated_srv.so" + }, }; class CBaseEntity; @@ -288,9 +310,9 @@ uintptr_t FindPattern(uintptr_t BaseAddr, const unsigned char *pData, const char uintptr_t FindFunctionCall(uintptr_t BaseAddr, uintptr_t Function, size_t MaxSize); /** - * @file extension.cpp - * @brief Implement extension code here. - */ +* @file extension.cpp +* @brief Implement extension code here. +*/ CSSFixes g_Interface; SMEXT_LINK(&g_Interface); @@ -326,7 +348,6 @@ DETOUR_DECL_MEMBER1(DETOUR_InputTestActivator, void, inputdata_t *, inputdata) const char *pszNonEdicts[] = { - "ambient_generic", "game_score", "game_text", "game_ui", @@ -342,6 +363,8 @@ const char *pszNonEdicts[] = DETOUR_DECL_MEMBER1(DETOUR_PostConstructor, void, const char *, szClassname) { + VPROF_ENTER_SCOPE("CSSFixes::DETOUR_PostConstructor"); + CBaseEntity *pEntity = (CBaseEntity *)this; static datamap_t *pMap = gamehelpers->GetDataMap(pEntity); @@ -371,6 +394,8 @@ DETOUR_DECL_MEMBER1(DETOUR_PostConstructor, void, const char *, szClassname) } DETOUR_MEMBER_CALL(DETOUR_PostConstructor)(szClassname); + + VPROF_EXIT_SCOPE(); } // Implementation for custom filter entities @@ -424,15 +449,23 @@ DETOUR_DECL_MEMBER2(DETOUR_PassesFilterImpl, bool, CBaseEntity*, pCaller, CBaseE // Switch new entity classnames to ones that can be instantiated while keeping the classname keyvalue intact so it can be used later DETOUR_DECL_STATIC2(DETOUR_CreateEntityByName, CBaseEntity*, const char*, className, int, iForceEdictIndex) { + VPROF_ENTER_SCOPE("CSSFixes::DETOUR_CreateEntityByName"); + // Nice of valve to expose CBaseFilter as filter_base :) if (strcasecmp(className, "filter_activator_context") == 0) className = "filter_base"; - return DETOUR_STATIC_CALL(DETOUR_CreateEntityByName)(className, iForceEdictIndex); + CBaseEntity *pEntity = DETOUR_STATIC_CALL(DETOUR_CreateEntityByName)(className, iForceEdictIndex); + + VPROF_EXIT_SCOPE(); + + return pEntity; } DETOUR_DECL_MEMBER2(DETOUR_KeyValue, bool, const char *, szKeyName, const char *, szValue) { + VPROF_ENTER_SCOPE("CSSFixes::DETOUR_KeyValue"); + CBaseEntity *pEntity = (CBaseEntity *)this; // Fix crash bug in engine @@ -474,7 +507,11 @@ DETOUR_DECL_MEMBER2(DETOUR_KeyValue, bool, const char *, szKeyName, const char * vecAbsVelocity->Init(tmp[0], tmp[1], tmp[2]); } - return DETOUR_MEMBER_CALL(DETOUR_KeyValue)(szKeyName, szValue); + bool bHandled = DETOUR_MEMBER_CALL(DETOUR_KeyValue)(szKeyName, szValue); + + VPROF_EXIT_SCOPE(); + + return bHandled; } /* Ignore players in +USE trace */ @@ -492,7 +529,7 @@ DETOUR_DECL_MEMBER3(DETOUR_CTraceFilterSimple, void, const IHandleEntity *, pass DETOUR_MEMBER_CALL(DETOUR_CTraceFilterSimple)(passedict, collisionGroup, pExtraShouldHitFunc); // If we're in FindUseEntity right now then switch out the VTable - if(g_InFindUseEntity) + if (g_InFindUseEntity) *(uintptr_t *)this = g_CTraceFilterNoNPCsOrPlayer; } @@ -768,6 +805,8 @@ bool CSSFixes::SDK_OnLoad(char *error, size_t maxlength, bool late) g_SH_SkipTwoEntitiesShouldHitEntity = SH_ADD_DVPHOOK(CTraceFilterSkipTwoEntities, ShouldHitEntity, g_CTraceFilterSkipTwoEntities, SH_STATIC(ShouldHitEntity), true); g_SH_SimpleShouldHitEntity = SH_ADD_DVPHOOK(CTraceFilterSimple, ShouldHitEntity, g_CTraceFilterSimple, SH_STATIC(ShouldHitEntity), true); + bool bSuccess = true; + // Apply all patches for(size_t i = 0; i < sizeof(gs_Patches) / sizeof(*gs_Patches); i++) { @@ -781,9 +820,9 @@ bool CSSFixes::SDK_OnLoad(char *error, size_t maxlength, bool late) #endif if(!pBinary) { - snprintf(error, maxlength, "Could not dlopen %s", pPatch->pLibrary); - SDK_OnUnload(); - return false; + g_pSM->LogError(myself, "Could not dlopen %s", pPatch->pLibrary); + bSuccess = false; + continue; } pPatch->pAddress = (uintptr_t)memutils->ResolveSymbol(pBinary, pPatch->pSignature); @@ -794,10 +833,10 @@ bool CSSFixes::SDK_OnLoad(char *error, size_t maxlength, bool late) #endif if(!pPatch->pAddress) { - snprintf(error, maxlength, "Could not find symbol: %s in %s (%p)", + g_pSM->LogError(myself, "Could not find symbol: %s in %s (%p)", pPatch->pSignature, pPatch->pLibrary, pBinary); - SDK_OnUnload(); - return false; + bSuccess = false; + continue; } SrcdsPatch::Restore **ppRestore = &pPatch->pRestore; @@ -811,9 +850,9 @@ bool CSSFixes::SDK_OnLoad(char *error, size_t maxlength, bool late) #endif if(!pFunctionBinary) { - snprintf(error, maxlength, "Could not dlopen %s", pPatch->pFunctionLibrary); - SDK_OnUnload(); - return false; + g_pSM->LogError(myself, "Could not dlopen %s", pPatch->pFunctionLibrary); + bSuccess = false; + continue; } pPatch->pSignatureAddress = (uintptr_t)memutils->ResolveSymbol(pFunctionBinary, (char *)pPatch->pPatchSignature); @@ -824,10 +863,10 @@ bool CSSFixes::SDK_OnLoad(char *error, size_t maxlength, bool late) #endif if(!pPatch->pSignatureAddress) { - snprintf(error, maxlength, "Could not find patch signature symbol: %s in %s (%p)", + g_pSM->LogError(myself, "Could not find patch signature symbol: %s in %s (%p)", (char *)pPatch->pPatchSignature, pPatch->pFunctionLibrary, pFunctionBinary); - SDK_OnUnload(); - return false; + bSuccess = false; + continue; } } @@ -846,9 +885,9 @@ bool CSSFixes::SDK_OnLoad(char *error, size_t maxlength, bool late) if(found) break; - snprintf(error, maxlength, "Could not find patch signature for symbol: %s", pPatch->pSignature); - SDK_OnUnload(); - return false; + g_pSM->LogError(myself, "Could not find patch signature for symbol: %s", pPatch->pSignature); + bSuccess = false; + continue; } ofs = pPatchAddress - pPatch->pAddress + PatchLen; @@ -870,6 +909,12 @@ bool CSSFixes::SDK_OnLoad(char *error, size_t maxlength, bool late) } } + if (!bSuccess) + { + SDK_OnUnload(); + return false; + } + return true; }