Advertisement
keybode

source engine DynAppSysFactory

Jan 26th, 2015
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.78 KB | None | 0 0
  1. class DynAppSysFactory
  2. {
  3.     struct InterfaceLinkedList_t
  4.     {
  5.         void* (*Function)();
  6.  
  7.         const char*             pName;
  8.         InterfaceLinkedList_t*  pNext;
  9.     };
  10.  
  11.     InterfaceLinkedList_t*  m_pList;
  12. public:
  13.     DynAppSysFactory ( const std::string& module );
  14.  
  15.     void* Get ( const std::string& name );
  16. };
  17.  
  18. DynAppSysFactory::DynAppSysFactory ( const std::string& module )
  19. {
  20.     void* create_interface = GetProcAddress ( GetModuleHandleA ( module.c_str () ), "CreateInterface" );
  21.  
  22.     size_t jmp_instruction = (size_t)create_interface + 4;
  23.  
  24.     size_t jmp_target = jmp_instruction + *(size_t*)( jmp_instruction + 1 ) + 5;
  25.  
  26.     m_pList = **(InterfaceLinkedList_t***)( jmp_target + 6 );
  27. }
  28.  
  29. void* DynAppSysFactory::Get ( const std::string& name )
  30. {
  31.     InterfaceLinkedList_t* pList = m_pList;
  32.  
  33.     size_t nLength = name.length ();
  34.  
  35.     while ( pList )
  36.     {
  37.         if ( !std::strncmp ( pList->pName, name.c_str (), nLength ) )
  38.         {
  39.             int nVersion = atoi ( pList->pName + nLength );
  40.  
  41.             if ( nVersion > 0 )
  42.                 return pList->Function ();
  43.         }
  44.  
  45.         pList = pList->pNext;
  46.     }
  47.  
  48.     return nullptr;
  49. }
  50.  
  51. DynAppSysFactory ClientFactory  ( "client.dll" );
  52. DynAppSysFactory EngineFactory  ( "engine.dll" );
  53. DynAppSysFactory VGuiFactory    ( "vguimatsurface.dll" );
  54. DynAppSysFactory VGui2Factory   ( "vgui2.dll" );
  55.  
  56. m_pClient       = (Source::IBaseClientDLL*) ClientFactory.Get ( "VClient" );
  57. m_pEngine       = (Source::IVEngineClient*) EngineFactory.Get ( "VEngineClient" );
  58. m_pPanel        = (Source::IPanel*) VGui2Factory.Get ( "VGUI_Panel" );
  59. m_pSurface      = (Source::ISurface*) VGuiFactory.Get ( "VGUI_Surface" );
  60. m_pModelInfo    = (Source::IVModelInfo*) EngineFactory.Get ( "VModelInfoClient" );
  61. m_pEntList      = (Source::IClientEntityList*) ClientFactory.Get ( "VClientEntityList" );
  62. m_pEngineTrace  = (Source::IEngineTrace*) EngineFactory.Get ( "EngineTraceClient" );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement