📄 vmapexport.cpp
字号:
/*****************************************************************************/
/* StormLibTest.cpp Copyright (c) Ladislav Zezula 2003 */
/*---------------------------------------------------------------------------*/
/* This module uses very brutal test methods for StormLib. It extracts all */
/* files from the archive with Storm.dll and with stormlib and compares them,*/
/* then tries to build a copy of the entire archive, then removes a few files*/
/* from the archive and adds them back, then compares the two archives, ... */
/*---------------------------------------------------------------------------*/
/* Date Ver Who Comment */
/* -------- ---- --- ------- */
/* 25.03.03 1.00 Lad The first version of StormLibTest.cpp */
/*****************************************************************************/
#define _CRT_SECURE_NO_DEPRECATE
#include <io.h>
#include <conio.h>
#include <stdio.h>
#include <windows.h>
#include <mmsystem.h>
#include <vector>
#include <list>
#define __STORMLIB_SELF__ // Don't use StormLib.lib
#include "StormLib.h"
#pragma warning(disable : 4505)
#pragma comment(lib, "Winmm.lib")
//From Extractor
#include "adtfile.h"
#include "wdtfile.h"
#include "dbcfile.h"
#include "mpq.h"
#include "wmo.h"
//------------------------------------------------------------------------------
// Defines
#define MPQ_BLOCK_SIZE 0x1000
//-----------------------------------------------------------------------------
// from extractor
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef struct{
char name[64];
unsigned int id;
}map_id;
map_id * map_ids;
uint16 * areas;
uint16 *areamax;
uint32 map_count;
char output_path[128]=".";
char input_path[1024]=".";
bool hasInputPathParam = false;
char tmp[512];
bool preciseVectorData = false;
//char gamepath[1024];
//Convert function
//bool ConvertADT(char*,char*);
// Constants
//static const char * szWorkDirMaps = ".\\Maps";
static const char * szWorkDirWmo = ".\\buildings";
//static LPBYTE pbBuffer1 = NULL;
//static LPBYTE pbBuffer2 = NULL;
// Local testing functions
static void clreol()
{
printf("\r \r");
}
static const char * GetPlainName(const char * szFileName)
{
const char * szTemp;
if((szTemp = strrchr(szFileName, '\\')) != NULL)
szFileName = szTemp + 1;
return szFileName;
}
//------------------------------------------------------------------------------
static void ShowProcessedFile(const char * szFileName)
{
char szLine[80];
size_t nLength = strlen(szFileName);
memset(szLine, 0x20, sizeof(szLine));
szLine[sizeof(szLine)-1] = 0;
if(nLength > sizeof(szLine)-1)
nLength = sizeof(szLine)-1;
memcpy(szLine, szFileName, nLength);
printf("\r%s\n", szLine);
}
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------
int ExtractWmo(const std::vector<std::string>& pArchiveNames)
{
char* szListFile = "";
char szLocalFile[MAX_PATH] = "";
HANDLE hMpq = "";
BOOL bResult = FALSE;
//const char* ParsArchiveNames[] = {"patch-2.MPQ", "patch.MPQ", "common.MPQ", "expansion.MPQ"};
int nError = ERROR_SUCCESS;
if(szListFile == NULL || *szListFile == 0)
szListFile = NULL;
//char tmp[1024];
//for (size_t i=0; i<4; i++)
for (size_t i=0; i<pArchiveNames.size(); i++)
{
//sprintf(tmp,"%s\\%s", input_path, ParsArchiveNames[i]);
//if(!SFileOpenArchive(tmp, 0, 0, &hMpq))
if(!SFileOpenArchive(pArchiveNames[i].c_str(), 0, 0, &hMpq))
printf("NOT open!!! %s\n",pArchiveNames[i].c_str());
// Copy files from archive
if(nError == ERROR_SUCCESS)
{
SFILE_FIND_DATA wf;
HANDLE hFind = SFileFindFirstFile(hMpq,"*.wmo*", &wf, szListFile);
bResult = TRUE;
while(hFind != NULL && bResult == TRUE)
{
ShowProcessedFile(wf.cFileName);
SFileSetLocale(wf.lcLocale);
sprintf(szLocalFile, "%s\\%s", szWorkDirWmo, GetPlainName(wf.cFileName));
fixnamen(szLocalFile,strlen(szLocalFile));
FILE * n;
if ((n = fopen(szLocalFile, "rb"))== NULL)
{
int p = 0;
//Select root wmo files
const char * rchr = strrchr(GetPlainName(wf.cFileName),0x5f);
if(rchr != NULL)
{
char cpy[4];
strncpy((char*)cpy,rchr,4);
for (int i=0;i<4;i++)
{
int m = cpy[i];
if(isdigit(m))
p++;
}
}
if(p != 3)
{
//printf("RootWmo!\n");
string s = wf.cFileName;
WMORoot * froot = new WMORoot(s);
if(!froot->open())
{
printf("Not open RootWmo!!!\n");
bResult = SFileFindNextFile(hFind, &wf);
continue;
}
FILE *output=fopen(szLocalFile,"wb");
froot->ConvertToVMAPRootWmo(output);
int Wmo_nVertices = 0;
if(froot->nGroups !=0)
{
for (int i=0; i<froot->nGroups; i++)
{
char temp[512];
strcpy(temp, wf.cFileName);
temp[strlen(wf.cFileName)-4] = 0;
char groupFileName[512];
sprintf(groupFileName,"%s_%03d.wmo",temp, i);
printf("%s\n",groupFileName);
//printf("GroupWmo!\n");
string s = groupFileName;
WMOGroup * fgroup = new WMOGroup(s);
if(!fgroup->open())
{
printf("Not all open Group file for: %s\n",GetPlainName(wf.cFileName));
bResult = SFileFindNextFile(hFind, &wf);
break;
}
Wmo_nVertices += fgroup->ConvertToVMAPGroupWmo(output, preciseVectorData);
}
}
fseek(output, 8, SEEK_SET); // store the correct no of vertices
fwrite(&Wmo_nVertices,sizeof(int),1,output);
fclose(output);
}
} else {
fclose(n);
}
wf.dwFileFlags &= ~MPQ_FILE_HAS_EXTRA;
wf.dwFileFlags &= ~MPQ_FILE_EXISTS;
// Find the next file
bResult = SFileFindNextFile(hFind, &wf);
}
// Delete the extracted file in the case of an error
if(nError != ERROR_SUCCESS)
DeleteFile(szLocalFile);
// Close the search handle
if(hFind != NULL)
SFileFindClose(hFind);
}
}
// Close both archives
if(hMpq != NULL)
//SFileCloseArchive(hMpq);
if(nError == ERROR_SUCCESS)
printf("\nExtract wmo complete (No errors)\n");
return nError;
}
void ExtractMapsFromMpq()
{
}
//-----------------------------------------------------------------------------
void ParsMapFiles()
{
char fn[512];
char id_filename[64];
char id[10];
for (unsigned int i=0; i<map_count; i++)
{
sprintf(id,"%03u",map_ids[i].id);
sprintf(fn,"World\\Maps\\%s\\%s.wdt", map_ids[i].name, map_ids[i].name);
WDTFile WDT(fn,map_ids[i].name);
if(WDT.init(id))
{
for (int x=0; x<64; x++)
{
for (int y=0; y<64; y++)
{
if (ADTFile*ADT = WDT.GetMap(x,y))
{
sprintf(id_filename,"%02u %02u %03u",x,y,map_ids[i].id);//!!!!!!!!!
ADT->init(id_filename);
delete ADT;
}
}
}
}
}
}
#if 0
void ParsMapFiles()
{
char fn[512];
for (unsigned int i=0; i<map_count; i++)
{
sprintf(fn,"World\\Maps\\%s\\%s.wdt", map_ids[i].name, map_ids[i].name);
WDTFile WDT(fn,map_ids[i].name);
if(WDT.init())
{
for (int x=0; x<64; x++)
{
for (int y=0; y<64; y++)
{
if (ADTFile*ADT = WDT.GetMap(x,y))
{
ADT->init();
delete ADT;
}
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -