Skip to content

dynamic_cast patch

Gratt-5r2 edited this page Apr 11, 2022 · 4 revisions

← Home

Patching

dynamic_cast patch is a special patch which allow to use default dynamic_cast with engine and plugin classes. This patch ignores a namespace part of the class name. That mean oCNpc is equal to Gothic_I_Classic::oCNpc. Patch is activated differently for MD and MT runtime libraries.

  • MT uses a static runtime library and dynamic_cast integrated in project. You should export the address of this operator:
extern void* __cdecl __RTDynamicCast( void*, long, void*, void*, int );
cexport void* RTDynamicCast_MT = (void*)__RTDynamicCast;
  • MD uses a dynamic runtime library and dynamic_cast imported from msvcr dll. You should call the Union::DefineCRTVersion function from DllMain:
#include <crtversion.h>

Union.DefineCRTVersion(
  _VC_CRT_MAJOR_VERSION,
  _VC_CRT_MINOR_VERSION,
  _VC_CRT_BUILD_VERSION,
  _VC_CRT_RBUILD_VERSION );

Example

cexport void Game_Loop() {
  oCNpc* focusNpc = dynamic_cast<oCNpc*>( player->GetFocusVob() );
  if( focusNpc )
    screen->PrintCXY( focusNpc->name[0] );
}
Clone this wiki locally