⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vmapexport.cpp

📁 絲路server源碼 Silk Road server source
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#endif
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

void getGamePath()
{
#ifdef _WIN32
    HKEY key;
    DWORD t,s;
    LONG l;
    s = sizeof(input_path);
    memset(input_path,0,s);
    l = RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Blizzard Entertainment\\World of Warcraft",0,KEY_QUERY_VALUE,&key);
    //l = RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Blizzard Entertainment\\Burning Crusade Closed Beta",0,KEY_QUERY_VALUE,&key);
    l = RegQueryValueEx(key,"InstallPath",0,&t,(LPBYTE)input_path,&s);
    RegCloseKey(key);
	if (strlen(input_path) > 0)
	{
		if (input_path[strlen(input_path) - 1] != '\\') strcat(input_path, "\\");
	}
    strcat(input_path,"Data\\");
#else
    strcpy(input_path,"data/");
#endif
}

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

bool scan_patches(char* scanmatch, std::vector<std::string>& pArchiveNames)
{
    int i;
    char path[512];
    std::list<std::string> matches;

    WIN32_FIND_DATA ffData;
    HANDLE hFind;

    for (i = 1; i <= 99; i++)
    {
        if (i != 1)
        {
            sprintf(path, "%s-%d.mpq", scanmatch, i);
        }
        else
        {
            sprintf(path, "%s.mpq", scanmatch);
        }

        hFind = INVALID_HANDLE_VALUE;
        hFind = FindFirstFile(path, &ffData);
        if (hFind == INVALID_HANDLE_VALUE) break;
        FindClose(hFind);

        matches.push_back(path);
    }

    matches.reverse();
    for (std::list<std::string>::iterator i = matches.begin(); i != matches.end(); i++)
    {
        pArchiveNames.push_back(i->c_str());
    }

    printf("\n");

    return(true);
}

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

bool fillArchiveNameVector(std::vector<std::string>& pArchiveNames) {
    //srand((unsigned int)time(0));

    if(!hasInputPathParam)
        getGamePath();

    printf("\nGame path: %s\n", input_path);

    char path[512];
    std::vector<std::string> locales;

    // scan game directories
    WIN32_FIND_DATA ffData;
    HANDLE hFind;
    DWORD dwError;

    // first, scan for locales (4-letter directories)
    printf("Scanning for locales.\n");
    sprintf(path, "%s*.*", input_path);
    hFind = INVALID_HANDLE_VALUE;
    hFind = FindFirstFile(path, &ffData);
    if (hFind == INVALID_HANDLE_VALUE)
    {
        printf("\nCould not open data directory for reading. Aborting.\n");
        return(false);
    }
    do
    {
        if (ffData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
        {
            if (ffData.cFileName[0] != '.')
            {
                if (strlen(ffData.cFileName) == 4)
                {
                    printf("Found locale: %s\n", ffData.cFileName);
                    locales.push_back(ffData.cFileName);
                }
            }
        }
    } while (FindNextFile(hFind, &ffData) != 0);
    dwError = GetLastError();
    FindClose(hFind);
    if (dwError != ERROR_NO_MORE_FILES)
    {
        printf("\nError reading data directory while scanning locales. Aborting.\n");
        return(false);
    }
    printf("\n");

    if (locales.size() == 0)
    {
        printf("Sorry, no locales found. Aborting.\n");
        return(false);
    }

    // now, scan for the patch levels in the core dir
    printf("Loading patch levels from data directory.\n");
    sprintf(path, "%spatch", input_path);
    if (!scan_patches(path, pArchiveNames)) return(false);

    // now, scan for the patch levels in locale dirs
    printf("Loading patch levels from locale directories.\n");
    for (std::vector<std::string>::iterator i = locales.begin(); i != locales.end(); i++)
    {
        printf("Locale: %s\n", i->c_str());
        sprintf(path, "%s%s\\patch-%s", input_path, i->c_str(), i->c_str());
        if (!scan_patches(path, pArchiveNames)) return(false);
    }

    // open expansion and common files
    printf("Opening data files from data directory.\n");
    sprintf(path, "%sexpansion.mpq", input_path);
    pArchiveNames.push_back(path);
    sprintf(path, "%scommon.mpq", input_path);
    pArchiveNames.push_back(path);
    printf("\n");

    // open locale expansion and common files
    printf("Opening data files from locale directories.\n");
    for (std::vector<std::string>::iterator i = locales.begin(); i != locales.end(); i++)
    {
        printf("Locale: %s\n", i->c_str());
        sprintf(path, "%s%s\\expansion-locale-%s.mpq", input_path, i->c_str(), i->c_str());
        pArchiveNames.push_back(path);
        sprintf(path, "%s%s\\locale-%s.mpq", input_path, i->c_str(), i->c_str());
        pArchiveNames.push_back(path);
        printf("\n");
    }
    return true;
}
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// return false it normal processing can not proceed

bool processArgv(int argc, char ** argv, char*versionString)
{
    bool result = true;
    hasInputPathParam = false;
    bool preciseVectorData = false;

    for(int i=1; i< argc; ++i) {
		if(strcmp("-s",argv[i]) == 0) {
			preciseVectorData = false;
		} else if(strcmp("-d",argv[i]) == 0) {
            if((i+1)<argc) {
                hasInputPathParam = true;
                strcpy(input_path, argv[i+1]);
                if (input_path[strlen(input_path) - 1] != '\\' || input_path[strlen(input_path) - 1] != '/')
                    strcat(input_path, "\\");
                ++i;
            } else {
                result = false;
            }
		} else if(strcmp("-?",argv[1]) == 0) {
            result = false;
		} else if(strcmp("-l",argv[i]) == 0) {
			preciseVectorData = true;
        } else {
            result = false;
            break;
        }
    }
    if(!result)     {
        printf("Extract %s.\n",versionString);
        printf("%s [-?][-s][-l][-d <path>]\n", argv[0]);
        printf("   -s : (default) small size (data size optimization), ~500MB less vmap data.\n");
        printf("   -l : large size, ~500MB more vmap data. (might contain more details)\n");
        printf("   -d <path>: Path to the vector data source folder.\n");
        printf("   -? : This message.\n");
    }
    return result;
}

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// Main
// 
// The program must be run with two command line arguments
//
// Arg1 - The source MPQ name (for testing reading and file find)
// Arg2 - Listfile name
//

int main(int argc, char ** argv)
{
    //char tmp[512];
//    FILE* pDatei;
//    char tmp[512];
//    char tmp1[512];
    //char tmp2[512];
//    char tmp3[512];
//    char tmp4[512];
//    char szMpqName[MAX_PATH] = "";
//    char szListFile[MAX_PATH] = "";
    int nError = ERROR_SUCCESS;
    char *versionString = "V2.4 2007_07_12";

    // Use command line arguments, when some
    if(!processArgv(argc, argv, versionString)) 
        return 1;
 
    printf("Extract %s. Beginning work ....\n",versionString);
    // Set the lowest priority to allow running in the background
    SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_BELOW_NORMAL);
    //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    // Create the working directory
    if(nError == ERROR_SUCCESS)
    {
        //if(!CreateDirectory(szWorkDirMaps, NULL))
        // nError = GetLastError();
        if(!CreateDirectory(szWorkDirWmo, NULL))
            nError = GetLastError();
        if(nError == ERROR_ALREADY_EXISTS)
            nError = ERROR_SUCCESS;
    } 
    //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    // patch goes first -> fake priority handling
    std::vector<MPQArchive*> archives;

    //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    std::vector<std::string> archiveNames;

    fillArchiveNameVector(archiveNames);
    for (size_t i=0; i<archiveNames.size(); i++) {
        archives.push_back(new MPQArchive(archiveNames[i].c_str()));
    }
    ExtractWmo(archiveNames);

     //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    //map.dbc
    if(nError == ERROR_SUCCESS)
    {
        DBCFile * dbc = new DBCFile("DBFilesClient\\Map.dbc");
        dbc->open();
        map_count=dbc->getRecordCount ();
        map_ids=new map_id[map_count];
        for(unsigned int x=0;x<map_count;x++)
        {
            map_ids[x].id=dbc->getRecord (x).getUInt(0);
            strcpy(map_ids[x].name,dbc->getRecord(x).getString(1));
            printf("Map - %s\n",map_ids[x].name);		 
        }

        delete dbc;
        ParsMapFiles();
        delete [] map_ids;
        nError = ERROR_SUCCESS;
    }

    clreol();
    if(nError != ERROR_SUCCESS) {
        printf("ERROR: Extract %s. Work NOT complete.\n   Precise vector data=%d.\nPress any key.\n",versionString, preciseVectorData);
        _getch();
    }
    printf("Extract %s. Work complete. No errors.",versionString);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -