Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
3.1 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. // vrad_launcher.cpp : Defines the entry point for the console application.
  9. //
  10. #include <windows.h>
  11. #include "interface.h"
  12. #include <direct.h>
  13. #include "tier1/strtools.h"
  14. #include "tier0/icommandline.h"
  15. #include "ishadercompiledll.h"
  16. #include <stdio.h>
  17. #include <conio.h>
  18. char* GetLastErrorString()
  19. {
  20. static char err[2048];
  21. LPVOID lpMsgBuf;
  22. FormatMessage(
  23. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  24. FORMAT_MESSAGE_FROM_SYSTEM |
  25. FORMAT_MESSAGE_IGNORE_INSERTS,
  26. NULL,
  27. GetLastError(),
  28. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  29. (LPTSTR) &lpMsgBuf,
  30. 0,
  31. NULL
  32. );
  33. strncpy( err, (char*)lpMsgBuf, sizeof( err ) );
  34. LocalFree( lpMsgBuf );
  35. err[ sizeof( err ) - 1 ] = 0;
  36. return err;
  37. }
  38. void MakeFullPath( const char *pIn, char *pOut, int outLen )
  39. {
  40. if ( pIn[0] == '/' || pIn[0] == '\\' || pIn[1] == ':' )
  41. {
  42. // It's already a full path.
  43. Q_strncpy( pOut, pIn, outLen );
  44. }
  45. else
  46. {
  47. _getcwd( pOut, outLen );
  48. Q_strncat( pOut, "\\", outLen, COPY_ALL_CHARACTERS );
  49. Q_strncat( pOut, pIn, outLen, COPY_ALL_CHARACTERS );
  50. }
  51. }
  52. void Pause( void )
  53. {
  54. // printf( "Pause\n" );
  55. // fflush( stdout );
  56. // getch();
  57. }
  58. int main(int argc, char* argv[])
  59. {
  60. char dllName[512];
  61. Pause();
  62. CommandLine()->CreateCmdLine( argc, argv );
  63. char fullPath[512], redirectFilename[512];
  64. MakeFullPath( argv[0], fullPath, sizeof( fullPath ) );
  65. Q_StripFilename( fullPath );
  66. Q_snprintf( redirectFilename, sizeof( redirectFilename ), "%s\\%s", fullPath, "vrad.redirect" );
  67. Pause();
  68. // First, look for vrad.redirect and load the dll specified in there if possible.
  69. CSysModule *pModule = NULL;
  70. FILE *fp = fopen( redirectFilename, "rt" );
  71. if ( fp )
  72. {
  73. if ( fgets( dllName, sizeof( dllName ), fp ) )
  74. {
  75. char *pEnd = strstr( dllName, "\n" );
  76. if ( pEnd )
  77. *pEnd = 0;
  78. pModule = Sys_LoadModule( dllName );
  79. if ( pModule )
  80. printf( "Loaded alternate VRAD DLL (%s) specified in vrad.redirect.\n", dllName );
  81. else
  82. printf( "Can't find '%s' specified in vrad.redirect.\n", dllName );
  83. }
  84. fclose( fp );
  85. }
  86. Pause();
  87. // If it didn't load the module above, then use the
  88. if ( !pModule )
  89. {
  90. strcpy( dllName, "shadercompile_dll.dll" );
  91. pModule = Sys_LoadModule( dllName );
  92. }
  93. Pause();
  94. if( !pModule )
  95. {
  96. printf( "vrad_launcher error: can't load %s\n%s", dllName, GetLastErrorString() );
  97. Pause();
  98. return 1;
  99. }
  100. Pause();
  101. CreateInterfaceFn fn = Sys_GetFactory( pModule );
  102. if( !fn )
  103. {
  104. printf( "vrad_launcher error: can't get factory from vrad_dll.dll\n" );
  105. Sys_UnloadModule( pModule );
  106. return 2;
  107. }
  108. int retCode = 0;
  109. IShaderCompileDLL *pDLL = (IShaderCompileDLL*)fn( SHADER_COMPILE_INTERFACE_VERSION, &retCode );
  110. if( !pDLL )
  111. {
  112. printf( "vrad_launcher error: can't get IVRadDLL interface from vrad_dll.dll\n" );
  113. Sys_UnloadModule( pModule );
  114. return 3;
  115. }
  116. int returnValue = pDLL->main( argc, argv );
  117. Sys_UnloadModule( pModule );
  118. return returnValue;
  119. }