Skip to content

Commit

Permalink
v17.7-dev9-fix4 - Fixes (Ghost) NPC detection in mods like Returning …
Browse files Browse the repository at this point in the history
…2.0 AB
  • Loading branch information
kirides committed Jul 14, 2021
1 parent 144d9bd commit 9ef8a16
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
4 changes: 4 additions & 0 deletions D3D11Engine/GothicMemoryLocations2_6_fix.h
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,10 @@ struct GothicMemoryLocations {
static const unsigned int RemoveVob = 0x00624B70;
};

struct zCClassDef {
static const unsigned int oCNpc = 0x00ab1e20;
};

class VobTypes // vftables
{
public:
Expand Down
2 changes: 1 addition & 1 deletion D3D11Engine/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#define stdext std
#endif

#define VERSION_NUMBER "17.7-dev19-fix3"
#define VERSION_NUMBER "17.7-dev19-fix4"
__declspec(selectany) const char* VERSION_NUMBER_STR = VERSION_NUMBER;

extern bool GMPModeActive;
Expand Down
42 changes: 41 additions & 1 deletion D3D11Engine/zCVob.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class zCVob {

return (flags & GothicMemoryLocations::zCVob::MASK_SkeepingMode);
}
void SetSleeping(int on) {
void SetSleeping( int on ) {
XCALL( GothicMemoryLocations::zCVob::SetSleeping );
}
/** Returns whether the visual of this vob is visible */
Expand Down Expand Up @@ -246,13 +246,53 @@ class zCVob {

/** returns the NPC pointer from the Vob, or nullptr if not an NPC */
oCNPC* AsNpc() {
#if BUILD_GOTHIC_2_6_fix
zCClassDef* classDef = ((zCObject*)this)->_GetClassDef();
/* // Quickly check for classdef
if( CheckInheritanceByString( classDef , "OCNPC") ) { // all uppercase!
bool ok = 1;
}*/
if ( CheckInheritance( classDef, _ClassDef_oCNpc() ) ) {
return reinterpret_cast<oCNPC*>(this);
}
#else
int vtbl = ((int*)this)[0];
if ( vtbl == GothicMemoryLocations::VobTypes::Npc ) {
return reinterpret_cast<oCNPC*>(this);
}
#endif
return nullptr;
}
protected:
bool CheckInheritanceByString( zCClassDef* def, const char* target ) {
while ( def ) {
if ( strcmp( def->className.ToChar(), target ) ) {
return true;
}
def = def->baseClassDef;
}
return false;
}

bool CheckInheritance( const zCClassDef* def, const zCClassDef* target ) {
while ( def ) {
if ( def == target ) {
return true;
}
def = def->baseClassDef;
}
return false;
}

const zCClassDef* _ClassDef_oCNpc() {
#if BUILD_GOTHIC_2_6_fix
return reinterpret_cast<const zCClassDef*>(GothicMemoryLocations::zCClassDef::oCNpc);
#else
// Find addres in G1
return nullptr;
#endif
}

zSTRING& __GetObjectName() {
XCALL( GothicMemoryLocations::zCObject::GetObjectName );
}
Expand Down

0 comments on commit 9ef8a16

Please sign in to comment.