Ejemplo n.º 1
0
int GetMapName(const char* MapPath, char* dest, size_t len)
{
  char* n = SStrChrR(MapPath, '/');
  char* m = SStrChrR(MapPath, '\\');

  if (n < m)
    n = m;

  if (n != NULL)
    return SStrCopy(dest, n+1, len);
  else
    return SStrCopy(dest, MapPath, len);
}
Ejemplo n.º 2
0
//------------------------------------------------- SEND TEXT ------------------------------------------------
int __stdcall _SStrCopy(char *dest, const char *source, size_t size)
{
  if ( source[0] && isCorrectVersion )
  {
    if ( size == 0x7FFFFFFF && *BW::BWDATA_gwGameMode == 3 )
    {
      if ( dest == BW::BWDATA_SaveGameFile )
      {
        /* onSaveGame */
        BWAPI::BroodwarImpl.onSaveGame((char*)source);
      }
      else
      {
        /* onSend Game */
        BWAPI::BroodwarImpl.sentMessages.push_back(std::string(source));
        dest[0] = 0;
        return 0;
      }
    }
    else if ( size == 120 && *BW::BWDATA_gwGameMode != 3 )
    {
      /* onSend Lobby */
    }
  }
  if ( _SStrCopyOld )
    return _SStrCopyOld(dest, source, size);
  return SStrCopy(dest, source, size);
}
Ejemplo n.º 3
0
int GetMapSha1(const char* MapName, const char* Map, int offset, char* buff, int unknow)
{
  SHA1Context context;
  char Name[0x400];
  
  SHA1Reset(&context);
  
  if (unknow != 0)
  {
    SHA1Input(&context, Map+unknow, offset - unknow);
    offset = unknow;
  }
  SHA1Input(&context, Map, offset);

  SStrCopy(Name, MapName, 0x400);
  SStrUpper(Name);
  SHA1Input(&context, Name, SStrLen(Name));

  return SHA1Result(&context, buff);
}
Ejemplo n.º 4
0
  //------------------------------------------ GET MAP HASH --------------------------------------------------
  std::string Map::getMapHash()
  {
    unsigned char hash[20];
    char hexstring[42];
    std::string filename = Map::getPathName();

    // Open File
    HANDLE hFile = NULL;
    if ( !SFileOpenFileEx(NULL, filename.c_str(), SFILE_FROM_ABSOLUTE, &hFile) || !hFile)
    {
      char szPath[MAX_PATH];
      SStrCopy(szPath, filename.c_str(), MAX_PATH);
      SStrNCat(szPath, "\\staredit\\scenario.chk", MAX_PATH);
      if ( !SFileOpenFileEx(NULL, szPath, SFILE_FROM_MPQ, &hFile) || !hFile)
        return std::string("Error_map_cannot_be_opened");
    }

    // Obtain file size
    DWORD dwFileSize = SFileGetFileSize(hFile, 0);

    // Allocate memory
    void *pBuffer = SMAlloc(dwFileSize);
    if ( !pBuffer )
    {
      SFileCloseFile(hFile);
      return std::string("Error_could_not_allocate_memory");
    }

    // Read file
    DWORD dwBytesRead = 0;
    SFileReadFile(hFile, pBuffer, dwFileSize, &dwBytesRead, 0);

    // Calculate hash
    sha1::calc(pBuffer, dwBytesRead, hash);
    sha1::toHexString(hash, hexstring);

    // Free memory and return
    SMFree(pBuffer);
    SFileCloseFile(hFile);
    return string(hexstring);
  }