Skip to content

Commit

Permalink
2.1.0 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
hendrikp committed May 23, 2015
1 parent c76877b commit be150f6
Show file tree
Hide file tree
Showing 8 changed files with 304 additions and 118 deletions.
13 changes: 13 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
Plugin SDK 2.1.0 (24.05.2015)
-----------------------------
Stable Release for CryEngine 3.6.16+ (32/64 bit)

New:
* Verfied 3.6.16 compatibility

Fixes:
* Plugins can now detect better if CryENGINE is shutting down

Changes:
* Hooking tools improved

Plugin SDK 2.1.0 (02.10.2014)
-----------------------------
Stable Release for CryEngine 3.6.8+ (32/64 bit)
Expand Down
5 changes: 3 additions & 2 deletions inc/CPluginBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <Nodes/G2FlowBaseNode.h>
#include <CPluginBaseMinimal.hpp>
#include <PMUtils.hpp>
#include <HookTool.hpp>

namespace PluginManager
{
Expand Down Expand Up @@ -73,7 +74,7 @@ namespace PluginManager
{
IFlowSystem* pFlow = NULL;

if ( gEnv && gEnv->pSystem && !gEnv->pSystem->IsQuitting() && gEnv->pGame && gEnv->pGame->GetIGameFramework() && ( pFlow = gEnv->pGame->GetIGameFramework()->GetIFlowSystem() ) )
if ( !IsBadReadPtr( gEnv, sizeof( void* ) ) && !IsBadReadPtr( gEnv->pSystem, sizeof( void* ) ) && !gEnv->pSystem->IsQuitting() && gEnv->pGame && gEnv->pGame->GetIGameFramework() && ( pFlow = gEnv->pGame->GetIGameFramework()->GetIFlowSystem() ) )
{
if ( !bUnregister )
{
Expand Down Expand Up @@ -178,7 +179,7 @@ namespace PluginManager
strFormat += "] ";
strFormat += sFormat;

if ( gEnv && gEnv->pSystem && gEnv->pLog )
if ( gEnv && !IsBadReadPtr( gEnv, sizeof( void* ) ) && gEnv->pSystem && !IsBadReadPtr( gEnv->pSystem, sizeof( void* ) ) && gEnv->pLog )
{
gEnv->pLog->LogV( nType, strFormat.c_str(), ArgList );
}
Expand Down
2 changes: 1 addition & 1 deletion inc/CPluginBaseMinimal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ namespace PluginManager
#pragma warning( disable : 4800 )
virtual bool RegisterTypes( int nFactoryType, bool bUnregister )
{
return gEnv;
return gEnv && !IsBadReadPtr( gEnv, sizeof( void* ) ) && gEnv->pSystem && !IsBadReadPtr( gEnv->pSystem, sizeof( void* ) );
};

virtual bool CheckDependencies() const
Expand Down
263 changes: 263 additions & 0 deletions inc/HookTool.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,263 @@
/* CE3 Plugin Manager - for licensing and copyright see license.txt */
#pragma once

// Check memory address access
const DWORD dwForbiddenArea = PAGE_GUARD | PAGE_NOACCESS;
const DWORD dwReadRights = PAGE_READONLY | PAGE_READWRITE | PAGE_WRITECOPY | PAGE_EXECUTE_READ | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY;
const DWORD dwWriteRights = PAGE_READWRITE | PAGE_WRITECOPY | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY;

template<DWORD dwAccessRights>
bool CheckAccess( void* pAddress, size_t nSize )
{
if ( !pAddress || !nSize )
{
return false;
}

MEMORY_BASIC_INFORMATION sMBI;
bool bRet = false;

UINT_PTR pCurrentAddress = UINT_PTR( pAddress );
UINT_PTR pEndAdress = pCurrentAddress + ( nSize - 1 );

do
{
ZeroMemory( &sMBI, sizeof( sMBI ) );
VirtualQuery( LPCVOID( pCurrentAddress ), &sMBI, sizeof( sMBI ) );

bRet = ( sMBI.State & MEM_COMMIT ) // memory allocated and
&& !( sMBI.Protect & dwForbiddenArea ) // access to page allowed and
&& ( sMBI.Protect & dwAccessRights ); // the required rights

pCurrentAddress = ( UINT_PTR( sMBI.BaseAddress ) + sMBI.RegionSize );
}
while ( bRet && pCurrentAddress <= pEndAdress );

return bRet;
}

#define IsBadWritePtr(p,n) (!CheckAccess<dwWriteRights>(p,n))
#define IsBadReadPtr(p,n) (!CheckAccess<dwReadRights>(p,n))

// preprocessor tools
#define PPCAT_NX(A, B) A ## B //!< concatenate identifier
#define PPCAT(A, B) PPCAT_NX(A, B) //!< concatenate identifier

#define GVT(x) virtual int PPCAT(Get,x)() { return x; }

#define getVT(ptr) (IsBadWritePtr(ptr, sizeof(INT_PTR)) ? NULL : *(void***)ptr)

template <class T, typename F>
int VTableIndex( F f )
{
struct VTableCounter
{
GVT( 0 );
GVT( 1 );
GVT( 2 );
GVT( 3 );
GVT( 4 );
GVT( 5 );
GVT( 6 );
GVT( 7 );
GVT( 8 );
GVT( 9 );
GVT( 10 );
GVT( 11 );
GVT( 12 );
GVT( 13 );
GVT( 14 );
GVT( 15 );
GVT( 16 );
GVT( 17 );
GVT( 18 );
GVT( 19 );
GVT( 20 );
GVT( 21 );
GVT( 22 );
GVT( 23 );
GVT( 24 );
GVT( 25 );
GVT( 26 );
GVT( 27 );
GVT( 28 );
GVT( 29 );
GVT( 30 );
GVT( 31 );
GVT( 32 );
GVT( 33 );
GVT( 34 );
GVT( 35 );
GVT( 36 );
GVT( 37 );
GVT( 38 );
GVT( 39 );
GVT( 40 );
GVT( 41 );
GVT( 42 );
GVT( 43 );
GVT( 44 );
GVT( 45 );
GVT( 46 );
GVT( 47 );
GVT( 48 );
GVT( 49 );
GVT( 50 );
GVT( 51 );
GVT( 52 );
GVT( 53 );
GVT( 54 );
GVT( 55 );
GVT( 56 );
GVT( 57 );
GVT( 58 );
GVT( 59 );
GVT( 60 );
GVT( 61 );
GVT( 62 );
GVT( 63 );
GVT( 64 );
GVT( 65 );
GVT( 66 );
GVT( 67 );
GVT( 68 );
GVT( 69 );
GVT( 70 );
GVT( 71 );
GVT( 72 );
GVT( 73 );
GVT( 74 );
GVT( 75 );
GVT( 76 );
GVT( 77 );
GVT( 78 );
GVT( 79 );
GVT( 80 );
GVT( 81 );
GVT( 82 );
GVT( 83 );
GVT( 84 );
GVT( 85 );
GVT( 86 );
GVT( 87 );
GVT( 88 );
GVT( 89 );
GVT( 90 );
GVT( 91 );
GVT( 92 );
GVT( 93 );
GVT( 94 );
GVT( 95 );
GVT( 96 );
GVT( 97 );
GVT( 98 );
GVT( 99 );
GVT( 100 );
GVT( 101 );
GVT( 102 );
GVT( 103 );
GVT( 104 );
GVT( 105 );
GVT( 106 );
GVT( 107 );
GVT( 108 );
GVT( 109 );
GVT( 110 );
GVT( 111 );
GVT( 112 );
GVT( 113 );
GVT( 114 );
GVT( 115 );
GVT( 116 );
GVT( 117 );
GVT( 118 );
GVT( 119 );
GVT( 120 );
GVT( 121 );
GVT( 122 );
GVT( 123 );
GVT( 124 );
GVT( 125 );
GVT( 126 );
GVT( 127 );
GVT( 128 );
GVT( 129 );
GVT( 130 );
GVT( 131 );
GVT( 132 );
GVT( 133 );
GVT( 134 );
GVT( 135 );
GVT( 136 );
GVT( 137 );
GVT( 138 );
GVT( 139 );
GVT( 140 );
GVT( 141 );
GVT( 142 );
GVT( 143 );
GVT( 144 );
GVT( 145 );
GVT( 146 );
GVT( 147 );
GVT( 148 );
GVT( 149 );
GVT( 150 );
GVT( 151 );
GVT( 152 );
GVT( 153 );
GVT( 154 );
GVT( 155 );
GVT( 156 );
GVT( 157 );
GVT( 158 );
GVT( 159 );
GVT( 160 );
GVT( 161 );
GVT( 162 );
GVT( 163 );
GVT( 164 );
GVT( 165 );
GVT( 166 );
GVT( 167 );
GVT( 168 );
GVT( 169 );
GVT( 170 );
GVT( 171 );
GVT( 172 );
GVT( 173 );
GVT( 174 );
GVT( 175 );
GVT( 176 );
GVT( 177 );
GVT( 178 );
GVT( 179 );
GVT( 180 );
GVT( 181 );
GVT( 182 );
GVT( 183 );
GVT( 184 );
GVT( 185 );
GVT( 186 );
GVT( 187 );
GVT( 188 );
GVT( 189 );
GVT( 190 );
GVT( 191 );
GVT( 192 );
GVT( 193 );
GVT( 194 );
GVT( 195 );
GVT( 196 );
GVT( 197 );
GVT( 198 );
GVT( 199 );
GVT( 200 );
} vt;

T* t = reinterpret_cast<T*>( &vt );

typedef int ( T::*GetIndex )();
GetIndex getIndex = ( GetIndex )f;
return ( t->*getIndex )();
};
2 changes: 1 addition & 1 deletion project/PluginManager.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,14 @@ call "$(ProjectDir)\..\tools\stylecode.bat" "$(ProjectDir)\.." </Command>
<ClInclude Include="..\inc\CDKVersion.h" />
<ClInclude Include="..\inc\CPluginBase.hpp" />
<ClInclude Include="..\inc\CPluginBaseMinimal.hpp" />
<ClInclude Include="..\inc\HookTool.hpp" />
<ClInclude Include="..\inc\IPluginBase.h" />
<ClInclude Include="..\inc\IPluginManager.h" />
<ClInclude Include="..\inc\IPluginManager_impl.h" />
<ClInclude Include="..\inc\Nodes\G2FlowBaseNode.h" />
<ClInclude Include="..\inc\PMUtils.hpp" />
<ClInclude Include="..\mhook-lib\mhook.h" />
<ClInclude Include="..\src\CPluginManager.h" />
<ClInclude Include="..\src\HookTool.hpp" />
<ClInclude Include="resource.h" />
<ClInclude Include="..\src\StdAfx.h" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions project/PluginManager.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@
<ClInclude Include="..\disasm-lib\misc.h">
<Filter>mhook</Filter>
</ClInclude>
<ClInclude Include="..\src\HookTool.hpp">
<Filter>Source</Filter>
<ClInclude Include="..\inc\HookTool.hpp">
<Filter>Headers</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
Expand Down
28 changes: 21 additions & 7 deletions src/CPluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <CPluginManager.h>
#include <PMUtils.hpp>

#include <mhook.h>
#include <HookTool.hpp>

#define COMMAND_LIST "pm_list"
Expand Down Expand Up @@ -270,14 +271,17 @@ namespace PluginManager
hookUpdate( false );

// Unregister listeners
if ( gEnv && gEnv->pSystem && gEnv->pGame && gEnv->pGame->GetIGameFramework() )
if ( gEnv && !IsBadReadPtr( gEnv, sizeof( void* ) ) && gEnv->pSystem && !IsBadReadPtr( gEnv->pSystem, sizeof( void* ) ) )
{
gEnv->pGame->GetIGameFramework()->UnregisterListener( this );
}
if ( gEnv->pGame && gEnv->pGame->GetIGameFramework() )
{
gEnv->pGame->GetIGameFramework()->UnregisterListener( this );
}

if ( gEnv && gEnv->pSystem && gEnv->pSystem->GetISystemEventDispatcher() )
{
gEnv->pSystem->GetISystemEventDispatcher()->RemoveListener( this );
if ( gEnv->pSystem->GetISystemEventDispatcher() )
{
gEnv->pSystem->GetISystemEventDispatcher()->RemoveListener( this );
}
}

// Cleanup all plugins (special case only in manager...)
Expand Down Expand Up @@ -607,7 +611,17 @@ namespace PluginManager

void CPluginManager::PluginGarbageCollector()
{
bool bQuit = !( gEnv && gEnv->pSystem && !gEnv->pSystem->IsQuitting() );
bool bQuit = false;

if ( gEnv && !IsBadReadPtr( gEnv, sizeof( void* ) ) && gEnv->pSystem && !IsBadReadPtr( gEnv->pSystem, sizeof( void* ) ) )
{
bQuit = gEnv->pSystem->IsQuitting();
}

else
{
bQuit = true;
}

// Something to do?
if ( bQuit )
Expand Down
Loading

3 comments on commit be150f6

@SalahAdDin
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, but, now is 3.7 eeas

@hendrikp
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3.7 is not a stable release yet, lets wait for some service packs.

@SalahAdDin
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, Now i understand, thank you.

Please sign in to comment.