Beispiel #1
0
Ptr<CodegenConfig> CodegenConfig::LoadConfig(Ptr<GuiResource> resource)
{
	Ptr<CodegenConfig> config = new CodegenConfig;
	config->resource = resource;

	if (auto folder = resource->GetFolderByPath(L"GacGenConfig/Cpp/"))
	{
		auto out = MakePtr<CodegenConfig::CppOutput>();
		if (!LoadConfigString(folder, L"Output", out->output)) return nullptr;
		if (!LoadConfigString(folder, L"Include", out->include)) return nullptr;
		if (!LoadConfigString(folder, L"Name", out->name)) return nullptr;
		if (!LoadConfigString(folder, L"Prefix", out->prefix)) return nullptr;

		out->Initialize();
		config->cppOutput = out;
	}

	if (auto folder = resource->GetFolderByPath(L"GacGenConfig/Res/"))
	{
		auto out = MakePtr<CodegenConfig::ResOutput>();
		if (!LoadConfigString(folder, L"Output", out->output)) return nullptr;
		LoadConfigString(folder, L"PrecompiledOutput", out->precompiledOutput, true);
		LoadConfigString(folder, L"PrecompiledBinary", out->precompiledBinary, true);
		LoadConfigString(folder, L"PrecompiledCompressed", out->precompiledCompressed, true);

		out->Initialize();
		config->resOutput = out;
	}

	return config;
}
Beispiel #2
0
void __stdcall DrawDialogHook(BW::bitmap *pSurface, BW::bounds *pBounds)
{
  if ( BW::pOldDrawDialogProc && !hideHUD )
    BW::pOldDrawDialogProc(pSurface, pBounds);

  if ( *BW::BWDATA_gwGameMode == BW::GAME_GLUES )
    BWAPI::BroodwarImpl.onMenuFrame();

  BW::dialog *timeout = BW::FindDialogGlobal("TimeOut");
  if ( timeout )
  {
    BW::dialog *dropbtn = timeout->findIndex(2);
    if ( !dropbtn->isDisabled() )
      BWAPI::BroodwarImpl.dropPlayers();
  }

  // NOSOUND config option
  if ( !nosound )
  {
    nosound = true;
    if ( LoadConfigString("starcraft", "sound", "ON") == "OFF" )
      BW::BWDATA_DSoundDestroy();
  }

  // WMODE config option
  if ( switchToWMode && ghMainWnd )
  {
    switchToWMode = false;
    SetWMode(windowRect.right, windowRect.bottom, true);
  }

  //click the menu dialog that pops up when you win/lose a game
  BW::dialog *endDialog = BW::FindDialogGlobal("LMission");
  if ( !endDialog )
    endDialog = BW::FindDialogGlobal("WMission");
  if ( endDialog )
    endDialog->findIndex(-2)->activate();
}
Beispiel #3
0
void InitPrimaryConfig()
{
  static bool isPrimaryConfigInitialized = false;
  // Return if already initialized
  if ( isPrimaryConfigInitialized )
    return;
  isPrimaryConfigInitialized = true;

  // ------------------------- GENERAL/GLOBAL CONFIG OPTIONS ----------------------------------
  // Get screenshot format
  screenshotFmt = LoadConfigString("starcraft", "screenshots", "gif");
  if ( !screenshotFmt.empty() )
    screenshotFmt.insert(0, ".");

  // Check if warning dialogs should be shown
  showWarn = LoadConfigStringUCase("config", "show_warnings", "YES") == "YES";

  // Check if shared memory should be enabled
  serverEnabled = LoadConfigStringUCase("config", "shared_memory", "ON") == "ON";

  // Get process count
  gdwProcNum = getProcessCount("StarCraft.exe");

  // ------------------------- WMODE CONFIG OPTIONS ----------------------------------
  // Load windowed mode position and fullscreen setting
  windowRect.left   = LoadConfigInt("window", "left");
  windowRect.top    = LoadConfigInt("window", "top");
  windowRect.right  = LoadConfigInt("window", "width");
  windowRect.bottom = LoadConfigInt("window", "height");
  switchToWMode     = LoadConfigStringUCase("window", "windowed", "OFF") == "ON";

  // Limit minimum w-mode size
  if ( windowRect.right < WMODE_MIN_WIDTH )
    windowRect.right = WMODE_MIN_WIDTH;
  if ( windowRect.bottom < WMODE_MIN_HEIGHT )
    windowRect.bottom = WMODE_MIN_HEIGHT;

}
Beispiel #4
0
// this version uppercase result string after loading, should be used for the most of enum-like strings
std::string LoadConfigStringUCase (const char *pszKey, const char *pszItem, const char *pszDefault)
{
  return Util::to_upper_copy(LoadConfigString(pszKey, pszItem, pszDefault));
}
Beispiel #5
0
//------------------------------------------------- DLL MAIN -------------------------------------------------
BOOL APIENTRY DllMain(HMODULE, DWORD ul_reason_for_call, LPVOID)
{
  switch (ul_reason_for_call)
  {
    case DLL_PROCESS_ATTACH:
      {
#ifdef _DEBUG
        _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif
        // Retrieve the initial configuration stuff if not already
        InitPrimaryConfig();

        // Get revision/build automatically
        char szDllPath[MAX_PATH];

        DWORD dwDesiredRevision = 0;
        std::string aicfg = LoadConfigString("ai", BUILD_DEBUG ? "ai_dbg" : "ai", "_NULL");
        strncpy(szDllPath, aicfg.c_str(), MAX_PATH);

        if ( aicfg == "_NULL" )
        {
            BWAPIError("Could not find %s under ai in \"%s\" for revision identification.", BUILD_DEBUG ? "ai_dbg" : "ai", szConfigPath);
        }
        else
        {
          DWORD dwDesiredBuild    = 0; // 0 = undefined, 1 = release, 2 = debug

          // Tokenize and retrieve correct path for the instance number
          char *pszDll = strtok(szDllPath, ",");
          for ( unsigned int i = 0; i < gdwProcNum-1; ++i )
          {
            char *pszNext = strtok(NULL, ",");
            if ( !pszNext )
              break;
            pszDll = pszNext;
          }
          // Retrieve revision info if it exists
          char *pszLoadRevCheck = strchr(pszDll, ':');
          if ( pszLoadRevCheck )
          {
            pszLoadRevCheck[0] = 0;
            ++pszLoadRevCheck;
            sscanf(pszLoadRevCheck, "%u", &dwDesiredRevision);
          }

          // Remove spaces
          while ( isspace(pszDll[0]) )
            ++pszDll;

          // Open File
          HANDLE hFile = NULL;
          if ( !SFileOpenFileEx(NULL, pszDll, SFILE_FROM_ABSOLUTE, &hFile) || !hFile)
          {
              BWAPIError("Could not load module \"%s\" for revision identification.", pszDll);
          }
          else
          {
            // Obtain file size
            DWORD dwFileSize = SFileGetFileSize(hFile, 0);

            // Allocate memory
            char *pbBuffer = (char*)SMAlloc(dwFileSize);
            if ( !pbBuffer )
            {
                BWAPIError("Unable to allocate enough memory for module \"%s\" for revision identification.", pszDll);
            }
            else
            {
              // Read file
              DWORD dwBytesRead = 0;
              SFileReadFile(hFile, pbBuffer, dwFileSize, &dwBytesRead, 0);
              for ( u32 i = 0; i < dwBytesRead && (dwDesiredRevision == 0 || dwDesiredBuild == 0); ++i )
              {
                if ( dwDesiredRevision == 0 && memcmp(&pbBuffer[i], "XBWAPIXREVISIONXSTAMPX", 22) == 0 )
                {
                  i += 22;
                  sscanf(&pbBuffer[i], "%u", &dwDesiredRevision);
                  i += 5;
                }  // if REVISION
                if ( memcmp(&pbBuffer[i], "XBWAPIXBUILDXSTAMPX", 19) == 0 )
                {
                  i += 19;
                  if ( strcmp(&pbBuffer[i], "DEBUG") == 0 )
                  {
                    dwDesiredBuild = 2;
                    i += 6;
                  }
                  else if ( strcmp(&pbBuffer[i], "RELEASE") == 0 )
                  {
                    dwDesiredBuild = 1;
                    i += 8;
                  }
                } // if BUILD
              } // for (iterate file)
              // Free memory and close file
              SMFree(pbBuffer);
              SFileCloseFile(hFile);
            } // buffer was allocated
          } // file was opened

          /* Do revision checking */
          if ( dwDesiredRevision > 0 && dwDesiredRevision != SVN_REV )
          {
            // revision that ai_dll_# for multiple instances was introduced
            if ( gdwProcNum && dwDesiredRevision < 2753 && showWarn )
            {
              char err[512];
              sprintf(err, "Revision %u is not compatible with multiple instances.\nExpecting revision 2753 (BWAPI Beta 3.1) or greater. If you proceed, the older revision of BWAPI will attempt to load its module from ai_dll instead of the multi-instance specification. Do you want to continue anyway?", dwDesiredRevision);
              BWAPIError("%s", err);
              if ( MessageBox(NULL, err, "Error", MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON1 | MB_TASKMODAL) == IDNO )
                return TRUE;
            } // revision is old

            if ( dwDesiredBuild == 0 )
              dwDesiredBuild = BUILD_DEBUG + 1;
            char szRevModule[MAX_PATH];
            sprintf_s(szRevModule, MAX_PATH, "%sbwapi-data\\revisions\\%u%s.dll", szInstallPath, dwDesiredRevision, dwDesiredBuild == 2 ? "d" : "");
            HMODULE hLib = LoadLibrary(szRevModule);
            if ( hLib )
            {
              if ( showWarn )
              {
                char msg[MAX_PATH+32];
                char szLoadedName[MAX_PATH];
                GetModuleFileName(hLib, szLoadedName, MAX_PATH);
                sprintf_s(msg, MAX_PATH+32, "Loaded \"%s\" instead.", szLoadedName);
                MessageBox(NULL, msg, "Success", MB_OK | MB_ICONINFO);
              }
              return TRUE;
            }

            if ( showWarn )
            {
              char err[512];
              sprintf(err, "Couldn't find revision module \"%s\" of which the AI DLL was compiled for. Do you want to try using the current revision instead?", szRevModule);
              BWAPIError("%s", err);
              if ( MessageBox(NULL, err, "Error", MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON1 | MB_TASKMODAL) == IDNO )
                return TRUE;
            }
          } // specified rev is not this one
          else if ( dwDesiredBuild && BUILD_DEBUG + 1 != dwDesiredBuild )
          {
            char envBuffer[MAX_PATH];
            if ( !GetEnvironmentVariable("ChaosDir", envBuffer, MAX_PATH) )
              if ( !GetCurrentDirectory(MAX_PATH, envBuffer) && showWarn )
                BWAPIError("Could not find ChaosDir or current directory for build identification.");

            SStrNCat(envBuffer, "\\BWAPI", MAX_PATH);
            if ( dwDesiredBuild == 2 )
              SStrNCat(envBuffer, "d", MAX_PATH);
            SStrNCat(envBuffer, ".dll", MAX_PATH);

            HMODULE hLib = LoadLibrary(envBuffer);
            if ( hLib )
            {
              if ( showWarn )
              {
                char msg[MAX_PATH+32];
                sprintf_s(msg, MAX_PATH+32, "Loaded \"%s\" instead.", envBuffer);
                MessageBox(NULL, msg, "Success", MB_OK | MB_ICONINFO);
              }
              return TRUE;
            }

            if ( showWarn )
            {
              char err[512];
              sprintf(err, "Couldn't find build module \"%s\" of which the AI DLL was compiled for. Do you want to try using the current build instead?", envBuffer);
              BWAPIError("%s", err);
              if ( MessageBox(NULL, err, "Error", MB_YESNO | MB_ICONWARNING | MB_DEFBUTTON1 | MB_TASKMODAL) == IDNO )
                return TRUE;
            }
            return TRUE;
          }
        } // module str was found

        // Do version checking
        CheckVersion();

        // Load the auto-menu config
        BWAPI::BroodwarImpl.loadAutoMenuData();

        // Apply all hacks and patches to the game
        ApplyCodePatches();

        // Initialize BWAPI
        BWAPI::BWAPI_init();

        // Create our thread that persistently applies hacks
        CreateThread(NULL, 0, &PersistentPatch, NULL, 0, NULL);

        return TRUE;
      }
  }
  return TRUE;
}