Exemple #1
1
BOOL __stdcall DllEntryPoint (HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
{
    BOOL fRc;
//    char msg[80];

    switch(dwReason)
    {
    case DLL_PROCESS_ATTACH:
//        DebugBreak();
        break;
    }
    if (fRc = _CRT_INIT(hDll, dwReason, lpReserved))
        fRc = LibMain(hDll, dwReason, lpReserved);
    switch(dwReason)
    {
    case DLL_PROCESS_ATTACH:
//        sprintf(msg, "Compob32 returning %d on attach\r\n", fRc);
//        OutputDebugStringA(msg);
        break;
    }
    return fRc;
}
Exemple #2
0
// For the CoreClr, this is the real DLL entrypoint. We make ourselves the first entrypoint as
// we need to capture coreclr's hInstance before the C runtine initializes. This function
// will capture hInstance, let the C runtime initialize and then invoke the "classic"
// DllMain that initializes everything else.
extern "C" BOOL WINAPI CoreDllMain(HANDLE hInstance, DWORD dwReason, LPVOID lpReserved)
{
    STATIC_CONTRACT_NOTHROW;

    BOOL result;
    switch (dwReason)
    {
        case DLL_PROCESS_ATTACH:
#ifndef FEATURE_PAL        
            // Make sure the /GS security cookie is initialized before we call anything else.
            // BinScope detects the call to __security_init_cookie in its "Has Non-GS-friendly
            // Initialization" check and makes it pass.
            __security_init_cookie();
#endif // FEATURE_PAL        

            // It's critical that we invoke InitUtilCode() before the CRT initializes. 
            // We have a lot of global ctors that will break if we let the CRT initialize without
            // this step having been done.

            CoreClrCallbacks cccallbacks;
            cccallbacks.m_hmodCoreCLR               = (HINSTANCE)hInstance;
            cccallbacks.m_pfnIEE                    = IEE;
            cccallbacks.m_pfnGetCORSystemDirectory  = GetCORSystemDirectoryInternal;
            cccallbacks.m_pfnGetCLRFunction         = GetCLRFunction;
            InitUtilcode(cccallbacks);

            if (!(result = _CRT_INIT(hInstance, dwReason, lpReserved)))
            {
                // CRT_INIT may fail to initialize the CRT heap. Make sure we don't continue 
                // down a path that would trigger an AV and tear down the host process
                break;
            }
            result = DllMain(hInstance, dwReason, lpReserved);
            break;
        
        case DLL_THREAD_ATTACH:
            _CRT_INIT(hInstance, dwReason, lpReserved);
            result = DllMain(hInstance, dwReason, lpReserved);
            break;

        case DLL_PROCESS_DETACH: // intentional fallthru
        case DLL_THREAD_DETACH:
            result = DllMain(hInstance, dwReason, lpReserved);
            _CRT_INIT(hInstance, dwReason, lpReserved);
            break;

        default:
            result = FALSE;  // it'd be an OS bug if we got here - not much we can do.
            break;   
    }
    return result;
}
Exemple #3
0
BOOL
APIENTRY
DllMain (HMODULE hModule,
         DWORD   ul_reason_for_call,
         LPVOID  /* lpReserved */)
{
  switch (ul_reason_for_call)
  {
    case DLL_PROCESS_ATTACH:
    {
      _CRT_INIT ((HINSTANCE)hModule, ul_reason_for_call, nullptr);
      hDLLMod = hModule;
    } break;

    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
      _CRT_INIT ((HINSTANCE)hModule, ul_reason_for_call, nullptr);
      break;

    case DLL_PROCESS_DETACH:
    {
      if (dll_log != nullptr) {
        tsf::WindowManager::Shutdown ();
        tsf::RenderFix::Shutdown     ();
        tsf::InputManager::Shutdown  ();
        tsf::TimingFix::Shutdown     ();

        TSFix_UnInit_MinHook ();
        TSFix_SaveConfig     ();

        dll_log->LogEx ( false, L"=========== (Version: v %s) "
                                L"===========\n",
                                TSFIX_VER_STR.c_str () );
        dll_log->LogEx ( true,  L"End TSFix Plug-In\n" );
        dll_log->LogEx ( false, L"------- [Tales of Symphonia \"Fix\"] "
                                L"-------\n" );

        dll_log->close ();
      }
      _CRT_INIT ((HINSTANCE)hModule, ul_reason_for_call, nullptr);
    } break;
  }

  return TRUE;
}
Exemple #4
0
__declspec(noinline) WINBOOL
__DllMainCRTStartup (HANDLE hDllHandle, DWORD dwReason, LPVOID lpreserved)
{
  WINBOOL retcode = TRUE;

  __native_dllmain_reason = dwReason;
  if (dwReason == DLL_PROCESS_DETACH && __proc_attached == 0)
    {
	retcode = FALSE;
	goto i__leave;
    }
  if (dwReason == DLL_PROCESS_ATTACH || dwReason == DLL_THREAD_ATTACH)
    {
        retcode = DllEntryPoint (hDllHandle, dwReason, lpreserved);
	if (retcode)
	  retcode = _CRT_INIT (hDllHandle, dwReason, lpreserved);
	if (! retcode)
	  goto i__leave;
    }
  _pei386_runtime_relocator ();
  if (retcode && dwReason == DLL_PROCESS_ATTACH)
    __main ();
  retcode = DllMain(hDllHandle,dwReason,lpreserved);
  if ((dwReason == DLL_PROCESS_ATTACH) && ! retcode)
    {
	DllMain (hDllHandle, DLL_PROCESS_DETACH, lpreserved);
	_CRT_INIT (hDllHandle, DLL_PROCESS_DETACH, lpreserved);
	DllEntryPoint (hDllHandle, DLL_PROCESS_DETACH, lpreserved);
    }
  if (dwReason == DLL_PROCESS_DETACH || dwReason == DLL_THREAD_DETACH)
    {
	if (_CRT_INIT (hDllHandle, dwReason, lpreserved) == FALSE)
	  {
	    retcode = FALSE;
	  }
	if (retcode)
	  {
	    retcode = DllEntryPoint (hDllHandle, dwReason, lpreserved);
	  }
    }
i__leave:
  __native_dllmain_reason = UINT_MAX;
  return retcode ;
}
void main()
{
	_CRT_INIT(GetModuleHandle(NULL), DLL_PROCESS_ATTACH, NULL);

	if (Bootstrap_RunInit())
	{
		ExitProcess(0);
	}

	wchar_t exeName[512];
	GetModuleFileName(GetModuleHandle(NULL), exeName, sizeof(exeName) / 2);

	wchar_t* exeBaseName = wcsrchr(exeName, L'\\');
	exeBaseName[0] = L'\0';
	exeBaseName++;

	// expand the path to include bin/
	static wchar_t path[32768];
	static wchar_t newPath[32768];
	GetEnvironmentVariable(L"PATH", path, sizeof(path));

	_snwprintf(newPath, sizeof(newPath), L"%s\\bin;%s", exeName, path);

	SetEnvironmentVariable(L"PATH", newPath);

	// set the current directory
	SetCurrentDirectory(exeName);

	bool devMode = false;

	if (GetFileAttributes(va(L"%s.iw4dev", exeBaseName)) != INVALID_FILE_ATTRIBUTES || wcsstr(GetCommandLine(), L"dedicated"))
	{
		devMode = true;
	}

	if (!devMode)
	{
		if (!Bootstrap_DoBootstrap())
		{
			ExitProcess(0);
			return;
		}
	}

	if (!Installer_GetIW4C())
	{
		ExitProcess(0);
	}

	// load the game
	W2_StartGame();
}
Exemple #6
0
    extern "C" BOOL WINAPI  DllEntryPoint (HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved)
    {
        switch (dwReason)
        {
                case DLL_PROCESS_ATTACH:

                //
                // DLL is attaching to the address space of 
                // the current process.
                //
                    if (!_CRT_INIT(hDLL, dwReason, lpReserved)) 
                        return FALSE;
                
                    // register the error message table
                    // Note, that if your function never returns
                    // an error -- you do not need to 
                    // register an error message table
                    if ( CreateUserErrorMessageTable(
                            hDLL, NUMBER_OF_ERRORS, myErrorMessageTable ) )
                        // and if the errors register OK
                        // go ahead and
                        // register user function
                        CreateUserFunction( hDLL, &Props1SI );
						CreateUserFunction( hDLL, &PropsSI );
						CreateUserFunction( hDLL, &HAPropsSI );
						CreateUserFunction( hDLL, &get_global_param_string);
                    break;

                case DLL_THREAD_ATTACH:
                case DLL_THREAD_DETACH:
                case DLL_PROCESS_DETACH:

                    if (!_CRT_INIT(hDLL, dwReason, lpReserved)) 
                        return FALSE;
                    break;                   
        }
        return TRUE;
    }
Exemple #7
0
BOOL WINAPI
ice_DLL_Main(HINSTANCE hDLL, DWORD reason, LPVOID reserved)
{
    //
    // During ATTACH, we must call _CRT_INIT first.
    //
    if(reason == DLL_PROCESS_ATTACH || reason == DLL_THREAD_ATTACH)
    {
        if(!_CRT_INIT(hDLL, reason, reserved))
        {
            return FALSE;
        }
    }

    if(reason == DLL_PROCESS_ATTACH)
    {
        Ice::Service::setModuleHandle(hDLL);
    }
    else if(reason == DLL_THREAD_DETACH)
    {
        Ice::ImplicitContextI::cleanupThread();
    }

    //
    // During DETACH, we must call _CRT_INIT last.
    //
    if(reason == DLL_PROCESS_DETACH || reason == DLL_THREAD_DETACH)
    {
        if(!_CRT_INIT(hDLL, reason, reserved))
        {
            return FALSE;
        }
    }

    return TRUE;
}
Exemple #8
0
ice_DLL_Main(HINSTANCE hDLL, DWORD reason, LPVOID reserved)
{
    if(!_CRT_INIT(hDLL, reason, reserved))
    {
        return FALSE;
    }
#endif
    if(reason == DLL_PROCESS_ATTACH)
    {
        Ice::EventLoggerI::setModuleHandle(hDLL);
        Ice::Service::setModuleHandle(hDLL);
    }
    else if(reason == DLL_THREAD_DETACH)
    {
        Ice::ImplicitContextI::cleanupThread();
    }

    return TRUE;
}
Exemple #9
0
BOOL __cdecl
__DllMainCRTStartup(
    HANDLE  hDllHandle,
    DWORD   dwReason,
    LPVOID  lpreserved
) {
    BOOL retcode = TRUE;

    /*
     * If this is a process detach notification, check that there has
     * has been a prior process attach notification.
     */
    if ((dwReason == DLL_PROCESS_DETACH) && (__proc_attached == 0))
        /*
         * no prior process attach notification. just return
         * without doing anything.
         */
    {
        return FALSE;
    }

    __try {
        if (dwReason == DLL_PROCESS_ATTACH || dwReason == DLL_THREAD_ATTACH) {
            if (_pRawDllMain) {
                retcode = (*_pRawDllMain)(hDllHandle, dwReason, lpreserved);
            }

            if (retcode) {
                retcode = _CRT_INIT(hDllHandle, dwReason, lpreserved);
            }

            if (!retcode) {
                return FALSE;
            }
        }

        retcode = DllMain(hDllHandle, dwReason, lpreserved);

        if ((dwReason == DLL_PROCESS_ATTACH) && !retcode) {
            /*
             * The user's DllMain routine returned failure, the C runtime
             * needs to be cleaned up. Do this by calling _CRT_INIT again,
             * this time imitating DLL_PROCESS_DETACH. Note this will also
             * clear the __proc_attached flag so the cleanup will not be
             * repeated upon receiving the real process detach notification.
             */
            DllMain(hDllHandle, DLL_PROCESS_DETACH, lpreserved);
            _CRT_INIT(hDllHandle, DLL_PROCESS_DETACH, lpreserved);

            if (_pRawDllMain) {
                (*_pRawDllMain)(hDllHandle, DLL_PROCESS_DETACH, lpreserved);
            }
        }

        if ((dwReason == DLL_PROCESS_DETACH) ||
                (dwReason == DLL_THREAD_DETACH)) {
            if (_CRT_INIT(hDllHandle, dwReason, lpreserved) == FALSE) {
                retcode = FALSE ;
            }

            if (retcode && _pRawDllMain) {
                retcode = (*_pRawDllMain)(hDllHandle, dwReason, lpreserved);
            }
        }
    } __except (__CppXcptFilter(GetExceptionCode(), GetExceptionInformation())) {
        return FALSE;
    }

    return retcode ;
}
Exemple #10
0
BOOL __cdecl
__DllMainCRTStartup(
        HANDLE  hDllHandle,
        DWORD   dwReason,
        LPVOID  lpreserved
        )
{
        BOOL retcode = TRUE;

    __try {
         __native_dllmain_reason = dwReason;
        __try{
            /*
             * If this is a process detach notification, check that there has
             * been a prior process attach notification.
             */
            if ( (dwReason == DLL_PROCESS_DETACH) && (__proc_attached == 0) ) {
                retcode = FALSE;
                __leave;
            }

            if ( dwReason == DLL_PROCESS_ATTACH || dwReason == DLL_THREAD_ATTACH ) {
                if ( _pRawDllMain )
                    retcode = (*_pRawDllMain)(hDllHandle, dwReason, lpreserved);

                if ( retcode )
                    retcode = _CRT_INIT(hDllHandle, dwReason, lpreserved);

                if ( !retcode )
                    __leave;
            }

            retcode = DllMain(hDllHandle, dwReason, lpreserved);

            if ( (dwReason == DLL_PROCESS_ATTACH) && !retcode ) {
                /*
                 * The user's DllMain routine returned failure.  Unwind the init.
                 */
                DllMain(hDllHandle, DLL_PROCESS_DETACH, lpreserved);
                _CRT_INIT(hDllHandle, DLL_PROCESS_DETACH, lpreserved);
                if ( _pRawDllMain )
                    (*_pRawDllMain)(hDllHandle, DLL_PROCESS_DETACH, lpreserved);
            }

            if ( (dwReason == DLL_PROCESS_DETACH) ||
                 (dwReason == DLL_THREAD_DETACH) ) {
                if ( _CRT_INIT(hDllHandle, dwReason, lpreserved) == FALSE ) {
                    retcode = FALSE ;
                }

                if ( retcode && _pRawDllMain ) {
                    retcode = (*_pRawDllMain)(hDllHandle, dwReason, lpreserved);
                }
            }
        } __except ( __CppXcptFilter(GetExceptionCode(), GetExceptionInformation()) ) {
            retcode = FALSE;
        }
    } __finally
    {
        __native_dllmain_reason = __NO_REASON;
    }

        return retcode ;
}