Skip to content

Commit

Permalink
fix incompatible patches applying, fix some win breakages, refactor a…
Browse files Browse the repository at this point in the history
… bit
  • Loading branch information
sigsegv-mvm committed Jan 23, 2016
1 parent b91e93e commit a4ecfd9
Show file tree
Hide file tree
Showing 25 changed files with 299 additions and 335 deletions.
23 changes: 6 additions & 17 deletions MSVC14/Performance.psess
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Solution>sigsegv.sln</Solution>
<CollectionMethod>Instrumentation</CollectionMethod>
<AllocationMethod>None</AllocationMethod>
<Reportname>C:\Users\jgottula\AppData\Local\Temp\Report.vsp</Reportname>
<Reportname>C:\Profiling\Report.vsp</Reportname>
<AddReport>true</AddReport>
<ResourceBasedAnalysisSelected>true</ResourceBasedAnalysisSelected>
<UniqueReport>Timestamp</UniqueReport>
Expand Down Expand Up @@ -37,7 +37,7 @@
</PostinstrumentEvent>
<Binaries>
<ProjBinary>
<Path>Debug\sigsegv.ext.2.tf2.dll</Path>
<Path>Release\sigsegv.ext.2.tf2.dll</Path>
<ArgumentTimestamp>01/01/0001 00:00:00</ArgumentTimestamp>
<Instrument>true</Instrument>
<Sample>true</Sample>
Expand Down Expand Up @@ -76,13 +76,13 @@
<IsLocalJavascript>false</IsLocalJavascript>
<IsWindowsStoreApp>false</IsWindowsStoreApp>
<IsWWA>false</IsWWA>
<LaunchProject>true</LaunchProject>
<OverrideProjectSettings>false</OverrideProjectSettings>
<LaunchProject>false</LaunchProject>
<OverrideProjectSettings>true</OverrideProjectSettings>
<LaunchMethod>Executable</LaunchMethod>
<ExecutablePath>C:\Program Files (x86)\Steam\SteamApps\common\Team Fortress 2\hl2.exe</ExecutablePath>
<StartupDirectory>C:\Program Files (x86)\Steam\SteamApps\common\Team Fortress 2\</StartupDirectory>
<Arguments>-steam -game tf -novid -console -condebug -insecure -textmode -nosound +maxplayers 32 +developer 1 +map mvm_example
</Arguments>
<Arguments>-steam -game tf -novid -console -condebug -insecure -windowed -w 1280 -h 720 +maxplayers 32 +developer 1 +map mvm_example
+exec cheat</Arguments>
<NetAppHost>IIS</NetAppHost>
<NetBrowser>InternetExplorer</NetBrowser>
<ExcludeSmallFuncs>true</ExcludeSmallFuncs>
Expand All @@ -95,17 +95,6 @@
</PostinstrumentEvent>
</Binary>
</Binaries>
<Reports>
<Report>
<Path>C:\Users\jgottula\AppData\Local\Temp\Report160118.vsp</Path>
</Report>
<Report>
<Path>C:\Users\jgottula\AppData\Local\Temp\Report160118(1).vsp</Path>
</Report>
<Report>
<Path>C:\Users\jgottula\AppData\Local\Temp\Report160118(2).vsp</Path>
</Report>
</Reports>
<Launches>
<Binary>
<Path>C:\Program Files (x86)\Steam\SteamApps\common\Team Fortress 2\hl2.exe</Path>
Expand Down
4 changes: 2 additions & 2 deletions MSVC14/sigsegv.sln
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ Project("{911E67C6-3D85-4FCE-B560-20A9C3E3FF48}") = "hl2", "C:\Program Files (x8
ProjectSection(DebuggerProjectSystem) = preProject
PortSupplier = 00000000-0000-0000-0000-000000000000
Executable = C:\Program Files (x86)\Steam\SteamApps\common\Team Fortress 2\hl2.exe
RemoteMachine = JGVM-WIN8
RemoteMachine =
StartingDirectory = C:\Program Files (x86)\Steam\SteamApps\common\Team Fortress 2
Arguments = -steam -game tf -novid -condebug -insecure -textmode -nosound -windowed -w 640 -h 480 +maxplayers 32 +developer 1 +map mvm_example
Arguments = -steam -game tf -novid -condebug -insecure -windowed -w 1280 -h 720 +maxplayers 32 +developer 1 +map mvm_example +exec cheat
Environment = Default
LaunchingEngine = 3b476d35-a401-11d2-aad4-00c04f990171
UseLegacyDebugEngines = No
Expand Down
16 changes: 8 additions & 8 deletions PackageScript
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ def CopyFiles(src, dest, files):
builder.AddCopy(source_path, dest_entry)

# Include files
CopyFiles('include', 'addons/sourcemod/scripting/include',
[
#CopyFiles('include', 'addons/sourcemod/scripting/include',
# [
# 'sample.inc',
]
)
# ]
#)

# GameData files
CopyFiles('gamedata/sigsegv', 'addons/sourcemod/gamedata/sigsegv',
Expand All @@ -55,11 +55,11 @@ CopyFiles('gamedata/sigsegv', 'addons/sourcemod/gamedata/sigsegv',
)

# Config Files
CopyFiles('configs', 'addons/sourcemod/configs',
[
#CopyFiles('configs', 'addons/sourcemod/configs',
# [
# 'configfile.cfg',
]
)
# ]
#)

# Copy binaries.
for cxx_task in Extension.extensions:
Expand Down
9 changes: 8 additions & 1 deletion addr/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,20 @@ class CAddr_pszWpnEntTranslationList : public IAddr_Sym
static CAddr_pszWpnEntTranslationList addr_pszWpnEntTranslationList;


// TODO: finder for CBasePlayer::IsBot
// (need to differentiate from CBasePlayer::IsFakeClient)
// 8b 81 xx xx xx xx mov eax,[ecx+m_fFlags]
// c1 e8 xx shr eax,log2(FL_FAKECLIENT)
// 83 e0 01 and eax,1
// c3 ret


#if 0
/* vtable indexes (valid for windows ONLY!) */
constexpr int VT_idx_CBaseCombatWeapon_ItemPostFrame = (0x41c / 4);
constexpr int VT_idx_Action_Update = ( 0xb8 / 4);


#if 0
struct CAddr_CTFSniperRifle_ItemPostFrame : public IAddr_Sym
{
const char *GetName() const override { return "CTFSniperRifle::ItemPostFrame"; }
Expand Down
41 changes: 35 additions & 6 deletions gamedata/sigsegv/sigsegv.misc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@
unistr "CreateEntityByName( %s, %d ) - CreateEdict failed."
}

"TranslateWeaponEntForClass"
{
type "func ebpprologue uniref"
sym "_Z26TranslateWeaponEntForClassPKci"
uniref "pszWpnEntTranslationList"
}
// "TranslateWeaponEntForClass"
// {
// type "func ebpprologue uniref"
// sym "_Z26TranslateWeaponEntForClassPKci"
// uniref "pszWpnEntTranslationList"
// }

"CBaseEntity::GetNetworkable"
{
Expand Down Expand Up @@ -86,6 +86,21 @@
type "sym"
sym "_ZNK9CTFPlayer13IsPlayerClassEi"
}
"CTFPlayer::ShouldGib"
{
type "func ebpprologue unistr"
sym "_ZN9CTFPlayer9ShouldGibERK15CTakeDamageInfo"
unistr "crit_kill_will_gib"
}
"CTFPlayer::SpeakConceptIfAllowed"
{
type "func ebpprologue unistr"
sym "_ZN9CTFPlayer21SpeakConceptIfAllowedEiPKcPcjP16IRecipientFilter"
unistr "disguiseclass:%s"
}
// CTFPlayer::TFPlayerThink
// warning! warning! not a straightforward ebp prologue!
// push ebx; mov ebx, esp

"CTFGameRules::PushAllPlayersAway"
{
Expand Down Expand Up @@ -122,6 +137,13 @@
sym "_ZN21CTFSniperRifleClassic13ItemPostFrameEv"
}

"CTFKnife::PrimaryAttack"
{
type "func ebpprologue unistr"
sym "_ZN8CTFKnife13PrimaryAttackEv"
unistr "DisguiseOnKill"
}

"CCurrencyPack::ComeToRest"
{
type "func datamap vthunk"
Expand All @@ -145,6 +167,13 @@
sym "_ZN10CTFNavMesh19CollectBuiltObjectsEP10CUtlVectorIP11CBaseObject10CUtlMemoryIS2_iEEi"
}

"CTFNavArea::IsBlocked"
{
type "func knownvtidx"
sym "_ZNK10CTFNavArea9IsBlockedEib"
vtable "[VT] CTFNavArea"
idx "0x11"
}
"CTFNavArea::IsValidForWanderingPopulation"
{
type "sym"
Expand Down
7 changes: 7 additions & 0 deletions gamedata/sigsegv/sigsegv.vtable.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@
winrtti ".?AVCCurrencyPack@@"
}

"[VT] CTFNavArea"
{
type "vtable"
sym "_ZTV10CTFNavArea"
winrtti ".?AVCTFNavArea@@"
}

"[VT] INextBotEventResponder"
{
type "vtable"
Expand Down
98 changes: 3 additions & 95 deletions link/vcall.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ inline const T& VFuncThunk<T>::Get(const void *_this) const
}


#if defined __GNUC__

template<typename T>
inline bool VFuncThunk<T>::Link(char *error, size_t maxlen)
{
Expand All @@ -70,96 +68,9 @@ inline bool VFuncThunk<T>::Link(char *error, size_t maxlen)
return false;
}

pVT = (T *)((uintptr_t)pVT - offsetof(vtable, vfptrs));

bool found = false;
for (int i = 0; i < 0x1000; ++i) {
if (pVT[i] == pFunc) {
this->m_iVTIndex = i;
found = true;
break;
}
}

if (!found) {
DevMsg("VFuncThunk::Link FAIL \"%s\"\n", this->m_pszFuncName);
snprintf(error, maxlen, "VFuncThunk linkage error: vtable lookup failed for \"%s\"", this->m_pszFuncName);
return false;
}
}

DevMsg("VFuncThunk::Link OK +0x%x \"%s\"\n", this->m_iVTIndex * 4, this->m_pszFuncName);
return true;
}

#elif defined _MSC_VER

// for MSVC:
// 1. do a string search for the ".?AV" string
// 2. ensure exactly one match; subtract 8; now we have the _TypeDescriptor
// 3. do a mem search for references to the _TypeDescriptor:
// 0x00000000 (signature)
// 0x00000000 (offset)
// 0x00000000 (cdOffset)
// &_TypeDescriptor
// 4. ensure exactly one match; now we have the __RTTI_CompleteObjectLocator
// 5. do a mem search for references to the __RTTI_CompleteObjectLocator
// 6. ensure exactly one match; add 4; now we have the VFTable

template<typename T>
inline bool VFuncThunk<T>::Link(char *error, size_t maxlen)
{
#if 0
_TypeDescriptor *pTD = nullptr;
__RTTI_CompleteObjectLocator *pCOL = nullptr;
T *pVT = nullptr;
T pFunc = nullptr;

if (this->m_iVTIndex == -1) {
pTD = (_TypeDescriptor *)AddrManager::GetAddr(this->m_pszVTName);
if (pTD == nullptr) {
DevMsg("VFuncThunk::Link FAIL \"%s\"\n", this->m_pszFuncName);
snprintf(error, maxlen, "VFuncThunk linkage error: signature lookup failed for \"%s\"", this->m_pszVTName);
return false;
}

pFunc = (T)AddrManager::GetAddr(this->m_pszFuncName);
if (pFunc == nullptr) {
DevMsg("VFuncThunk::Link FAIL \"%s\"\n", this->m_pszFuncName);
snprintf(error, maxlen, "VFuncThunk linkage error: signature lookup failed for \"%s\"", this->m_pszFuncName);
return false;
}

pTD = (_TypeDescriptor *)((uintptr_t)pTD - offsetof(_TypeDescriptor, name));

__RTTI_CompleteObjectLocator pattern_COL = {
0x00000000,
0x00000000,
0x00000000,
pTD,
};

std::vector<void *> refs_TD;
assert(MemFindPattern(gamedll, (const char *)&pattern_COL, 0x10, refs_TD));

if (refs_TD.size() != 1) {
DevMsg("VFuncThunk::Link FAIL \"%s\"\n", this->m_pszFuncName);
snprintf(error, maxlen, "VFuncThunk linkage error: %d TD refs for \"%s\"", refs_TD.size(), this->m_pszFuncName);
return false;
}

pCOL = (__RTTI_CompleteObjectLocator *)refs_TD[0];

std::vector<void *>refs_COL;
assert(MemFindPattern(gamedll, (const char *)&pCOL, 0x4, refs_COL));

if (refs_COL.size() != 1) {
DevMsg("VFuncThunk::Link FAIL \"%s\"\n", this->m_pszFuncName);
snprintf(error, maxlen, "VFuncThunk linkage error: %d COL refs for \"%s\"", refs_COL.size(), this->m_pszFuncName);
return false;
}

pVT = (T *)((uintptr_t)refs_COL[0] + 0x4);
#if defined __GNUC__
pVT = (T *)((uintptr_t)pVT + offsetof(vtable, vfptrs));
#endif

bool found = false;
for (int i = 0; i < 0x1000; ++i) {
Expand All @@ -177,12 +88,9 @@ inline bool VFuncThunk<T>::Link(char *error, size_t maxlen)
}
}

#endif
DevMsg("VFuncThunk::Link OK +0x%x \"%s\"\n", this->m_iVTIndex * 4, this->m_pszFuncName);
return true;
}

#endif


#endif
8 changes: 4 additions & 4 deletions mem/patch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
#include "extension.h"


bool IPatch::Init(char *error, size_t maxlen)
bool IPatch::Init()
{
this->m_pszFuncName = this->GetFuncName();
this->m_iFuncOffset = this->GetFuncOffset();

this->m_pFuncAddr = AddrManager::GetAddr(this->m_pszFuncName);
if (this->m_pFuncAddr == nullptr) {
snprintf(error, maxlen, "Patch error: signature lookup failed for %s", this->m_pszFuncName);
DevMsg("IPatch::Init: FAIL: no addr for \"%s\"\n", this->m_pszFuncName);
return false;
}

Expand All @@ -23,7 +23,7 @@ bool IPatch::Init(char *error, size_t maxlen)
return true;
}

bool IPatch::Check(char *error, size_t maxlen)
bool IPatch::Check()
{
uint8_t *ptr = (uint8_t *)((uintptr_t)this->m_pFuncAddr + this->m_iFuncOffset);
for (int i = 0; i < this->m_iLength; ++i) {
Expand All @@ -33,7 +33,7 @@ bool IPatch::Check(char *error, size_t maxlen)
uint8_t v_mask = this->m_MaskVerify[i];

if ((*mem & v_mask) != (v_byte & v_mask)) {
snprintf(error, maxlen, "Patch/verify failure: func %s, offset 0x%x, byte 0x%x: < byte:%02x mask:%02x | mem:%02x >",
DevMsg("IPatch::Check: FAIL: func \"%s\", off 0x%x, byte 0x%x: < byte:%02x mask:%02x | mem:%02x >\n",
this->m_pszFuncName, this->m_iFuncOffset, i, v_byte, v_mask, *mem);
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions mem/patch.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class IPatch

virtual bool VerifyOnly() const { return false; }

bool Init(char *error, size_t maxlen);
bool Check(char *error, size_t maxlen);
bool Init();
bool Check();

virtual void Apply();
virtual void UnApply();
Expand Down
Loading

0 comments on commit a4ecfd9

Please sign in to comment.