本文整理汇总了C++中GetPlainName函数的典型用法代码示例。如果您正苦于以下问题:C++ GetPlainName函数的具体用法?C++ GetPlainName怎么用?C++ GetPlainName使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetPlainName函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ExtractSingleModel
bool ExtractSingleModel(std::string& fname, StringSet& failedPaths)
{
char* ext = GetExtension(GetPlainName((char*)fname.c_str()));
// < 3.1.0 ADT MMDX section store filename.mdx filenames for corresponded .m2 file
if (!strcmp(ext, ".mdx"))
{
// replace .mdx -> .m2
fname.erase(fname.length() - 2, 2);
fname.append("2");
}
// >= 3.1.0 ADT MMDX section store filename.m2 filenames for corresponded .m2 file
// nothing do
std::string output(szWorkDirWmo); // Stores output filename (possible changed)
output += "/";
output += GetPlainName(fname.c_str());
if (FileExists(output.c_str()))
return true;
Model mdl(fname); // Possible changed fname
if (!mdl.open(failedPaths))
return false;
return mdl.ConvertToVMAPModel(output.c_str());
}
示例2: ExtractSingleModel
bool ExtractSingleModel(std::string& fname)
{
if (fname.substr(fname.length() - 4, 4) == ".mdx")
{
fname.erase(fname.length() - 2, 2);
fname.append("2");
}
std::string originalName = fname;
char* name = GetPlainName((char*)fname.c_str());
FixNameCase(name, strlen(name));
FixNameSpaces(name, strlen(name));
std::string output(szWorkDirWmo);
output += "/";
output += name;
if (FileExists(output.c_str()))
return true;
Model mdl(originalName);
if (!mdl.open())
return false;
return mdl.ConvertToVMAPModel(output.c_str());
}
示例3: ExtractGameobjectModels
void ExtractGameobjectModels()
{
printf("Extracting GameObject models...");
DBCFile dbc(LocaleMpq, "DBFilesClient\\GameObjectDisplayInfo.dbc");
if(!dbc.open())
{
printf("Fatal error: Invalid GameObjectDisplayInfo.dbc file format!\n");
exit(1);
}
std::string basepath = szWorkDirWmo;
basepath += "/";
std::string path;
FILE * model_list = fopen((basepath + "temp_gameobject_models").c_str(), "wb");
for (DBCFile::Iterator it = dbc.begin(); it != dbc.end(); ++it)
{
path = it->getString(1);
if (path.length() < 4)
continue;
FixNameCase((char*)path.c_str(), path.size());
char * name = GetPlainName((char*)path.c_str());
FixNameSpaces(name, strlen(name));
char * ch_ext = GetExtension(name);
if (!ch_ext)
continue;
strToLower(ch_ext);
bool result = false;
if (!strcmp(ch_ext, ".wmo"))
result = ExtractSingleWmo(path);
else if (!strcmp(ch_ext, ".mdl")) // TODO: extract .mdl files, if needed
continue;
else //if (!strcmp(ch_ext, ".mdx") || !strcmp(ch_ext, ".m2"))
result = ExtractSingleModel(path);
if (result)
{
uint32 displayId = it->getUInt(0);
uint32 path_length = strlen(name);
fwrite(&displayId, sizeof(uint32), 1, model_list);
fwrite(&path_length, sizeof(uint32), 1, model_list);
fwrite(name, sizeof(char), path_length, model_list);
}
}
fclose(model_list);
printf("Done!\n");
}
示例4: ExtractSingleWmo
bool ExtractSingleWmo(std::string& fname)
{
// Copy files from archive
char szLocalFile[1024];
const char * plain_name = GetPlainName(fname.c_str());
sprintf(szLocalFile, "%s/%s", szWorkDirWmo, plain_name);
FixNameCase(szLocalFile,strlen(szLocalFile));
if (FileExists(szLocalFile))
return true;
int p = 0;
// Select root wmo files
char const* rchr = strrchr(plain_name, '_');
if (rchr != NULL)
{
char cpy[4];
memcpy(cpy, rchr, 4);
for (int i = 0; i < 4; ++i)
{
int m = cpy[i];
if (isdigit(m))
p++;
}
}
if (p == 3)
return true;
bool file_ok = true;
std::cout << "Extracting " << fname << std::endl;
WMORoot froot(fname);
if(!froot.open())
{
printf("Couldn't open RootWmo!!!\n");
return true;
}
FILE *output = fopen(szLocalFile,"wb");
if(!output)
{
printf("couldn't open %s for writing!\n", szLocalFile);
return false;
}
froot.ConvertToVMAPRootWmo(output);
int Wmo_nVertices = 0;
//printf("root has %d groups\n", froot->nGroups);
if (froot.nGroups !=0)
{
for (uint32 i = 0; i < froot.nGroups; ++i)
{
char temp[1024];
strcpy(temp, fname.c_str());
temp[fname.length()-4] = 0;
char groupFileName[1024];
sprintf(groupFileName, "%s_%03u.wmo", temp, i);
//printf("Trying to open groupfile %s\n",groupFileName);
std::string s = groupFileName;
WMOGroup fgroup(s);
if(!fgroup.open())
{
printf("Could not open all Group file for: %s\n", plain_name);
file_ok = false;
break;
}
Wmo_nVertices += fgroup.ConvertToVMAPGroupWmo(output, &froot, preciseVectorData);
}
}
fseek(output, 8, SEEK_SET); // store the correct no of vertices
fwrite(&Wmo_nVertices,sizeof(int),1,output);
fclose(output);
// Delete the extracted file in the case of an error
if (!file_ok)
remove(szLocalFile);
return true;
}
示例5: fopen
bool ADTFile::init(uint32 map_num, uint32 tileX, uint32 tileY)
{
if(ADT.isEof ())
return false;
uint32 size;
string xMap;
string yMap;
Adtfilename.erase(Adtfilename.find(".adt"),4);
string TempMapNumber;
TempMapNumber = Adtfilename.substr(Adtfilename.length()-6,6);
xMap = TempMapNumber.substr(TempMapNumber.find("_")+1,(TempMapNumber.find_last_of("_")-1) - (TempMapNumber.find("_")));
yMap = TempMapNumber.substr(TempMapNumber.find_last_of("_")+1,(TempMapNumber.length()) - (TempMapNumber.find_last_of("_")));
Adtfilename.erase((Adtfilename.length()-xMap.length()-yMap.length()-2), (xMap.length()+yMap.length()+2));
//string AdtMapNumber = xMap + ' ' + yMap + ' ' + GetPlainName((char*)Adtfilename.c_str());
//printf("Processing map %s...\n", AdtMapNumber.c_str());
//printf("MapNumber = %s\n", TempMapNumber.c_str());
//printf("xMap = %s\n", xMap.c_str());
//printf("yMap = %s\n", yMap.c_str());
std::string dirname = std::string(szWorkDirWmo) + "/dir_bin";
FILE *dirfile;
dirfile = fopen(dirname.c_str(), "ab");
if(!dirfile)
{
printf("Can't open dirfile!'%s'\n", dirname.c_str());
return false;
}
while (!ADT.isEof())
{
char fourcc[5];
ADT.read(&fourcc,4);
ADT.read(&size, 4);
flipcc(fourcc);
fourcc[4] = 0;
size_t nextpos = ADT.getPos() + size;
if (!strcmp(fourcc,"MCIN"))
{
}
else if (!strcmp(fourcc,"MTEX"))
{
}
else if (!strcmp(fourcc,"MMDX"))
{
if (size)
{
char *buf = new char[size];
ADT.read(buf, size);
char *p=buf;
int t=0;
ModelInstansName = new string[size];
while (p<buf+size)
{
fixnamen(p,strlen(p));
char* s = GetPlainName(p);
fixname2(s,strlen(s));
ModelInstansName[t++] = s;
string path(p);
ExtractSingleModel(path);
p = p+strlen(p)+1;
}
delete[] buf;
}
}
else if (!strcmp(fourcc,"MWMO"))
{
if (size)
{
char* buf = new char[size];
ADT.read(buf, size);
char* p=buf;
int q = 0;
WmoInstansName = new string[size];
while (p<buf+size)
{
char* s = GetPlainName(p);
fixnamen(s, strlen(s));
fixname2(s, strlen(s));
p += strlen(p) + 1;
WmoInstansName[q++] = s;
}
delete[] buf;
}
}
//======================
else if (!strcmp(fourcc,"MDDF"))
{
if (size)
{
nMDX = (int)size / 36;
for (int i=0; i<nMDX; ++i)
{
//.........这里部分代码省略.........
示例6: ExtractWmo
int ExtractWmo()
{
char szLocalFile[1024] = "";
bool success=true;
//const char* ParsArchiveNames[] = {"patch-2.MPQ", "patch.MPQ", "common.MPQ", "expansion.MPQ"};
for (ArchiveSet::const_iterator ar_itr = gOpenArchives.begin(); ar_itr != gOpenArchives.end() && success; ++ar_itr)
{
vector<string> filelist;
(*ar_itr)->GetFileListTo(filelist);
for (vector<string>::iterator fname=filelist.begin(); fname != filelist.end() && success; ++fname)
{
bool file_ok=true;
if (fname->find(".wmo") != string::npos)
{
// Copy files from archive
//std::cout << "found *.wmo file " << *fname << std::endl;
sprintf(szLocalFile, "%s/%s", szWorkDirWmo, GetPlainName(fname->c_str()));
fixnamen(szLocalFile,strlen(szLocalFile));
FILE * n;
if ((n = fopen(szLocalFile, "rb"))== NULL)
{
int p = 0;
//Select root wmo files
const char * rchr = strrchr(GetPlainName(fname->c_str()),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)
{
std::cout << "Extracting " << *fname << std::endl;
WMORoot * froot = new WMORoot(*fname);
if (!froot->open())
{
printf("Couldn't open RootWmo!!!\n");
delete froot;
continue;
}
FILE *output=fopen(szLocalFile,"wb");
if (!output)
{
printf("couldn't open %s for writing!\n", szLocalFile);
success=false;
}
froot->ConvertToVMAPRootWmo(output);
int Wmo_nVertices = 0;
//printf("root has %d groups\n", froot->nGroups);
if (froot->nGroups !=0)
{
for (uint32 i=0; i<froot->nGroups; ++i)
{
char temp[1024];
strcpy(temp, fname->c_str());
temp[fname->length()-4] = 0;
char groupFileName[1024];
sprintf(groupFileName,"%s_%03d.wmo",temp, i);
//printf("Trying to open groupfile %s\n",groupFileName);
string s = groupFileName;
WMOGroup * fgroup = new WMOGroup(s);
if (!fgroup->open())
{
printf("Could not open all Group file for: %s\n",GetPlainName(fname->c_str()));
file_ok=false;
break;
}
Wmo_nVertices += fgroup->ConvertToVMAPGroupWmo(output, froot, preciseVectorData);
delete fgroup;
}
}
fseek(output, 8, SEEK_SET); // store the correct no of vertices
fwrite(&Wmo_nVertices,sizeof(int),1,output);
fclose(output);
delete froot;
}
}
else
{
fclose(n);
}
}
// Delete the extracted file in the case of an error
if (!file_ok)
remove(szLocalFile);
}
}
if (success)
printf("\nExtract wmo complete (No (fatal) errors)\n");
//.........这里部分代码省略.........
示例7: GetPlainName
bool ADTFile::init(uint32 map_num, uint32 tileX, uint32 tileY)
{
if(ADT.isEof ())
return false;
uint32 size;
string xMap;
string yMap;
Adtfilename.erase(Adtfilename.find(".adt"),4);
string TempMapNumber;
TempMapNumber = Adtfilename.substr(Adtfilename.length()-6,6);
xMap = TempMapNumber.substr(TempMapNumber.find("_")+1,(TempMapNumber.find_last_of("_")-1) - (TempMapNumber.find("_")));
yMap = TempMapNumber.substr(TempMapNumber.find_last_of("_")+1,(TempMapNumber.length()) - (TempMapNumber.find_last_of("_")));
Adtfilename.erase((Adtfilename.length()-xMap.length()-yMap.length()-2), (xMap.length()+yMap.length()+2));
string AdtMapNumber = xMap + ' ' + yMap + ' ' + GetPlainName((char*)Adtfilename.c_str());
//printf("Processing map %s...\n", AdtMapNumber.c_str());
//printf("MapNumber = %s\n", TempMapNumber.c_str());
//printf("xMap = %s\n", xMap.c_str());
//printf("yMap = %s\n", yMap.c_str());
std::string dirname = std::string(szWorkDirWmo) + "/dir_bin";
FILE *dirfile;
dirfile = fopen(dirname.c_str(), "ab");
if(!dirfile)
{
printf("Can't open dirfile!'%s'\n", dirname.c_str());
return false;
}
while (!ADT.isEof())
{
char fourcc[5];
ADT.read(&fourcc,4);
ADT.read(&size, 4);
flipcc(fourcc);
fourcc[4] = 0;
size_t nextpos = ADT.getPos() + size;
if (!strcmp(fourcc,"MCIN"))
{
}
else if (!strcmp(fourcc,"MTEX"))
{
}
else if (!strcmp(fourcc,"MMDX"))
{
if (size)
{
char *buf = new char[size];
ADT.read(buf, size);
char *p=buf;
int t=0;
ModelInstansName = new string[size];
while (p<buf+size)
{
fixnamen(p,strlen(p));
string path(p);
char* s=GetPlainName(p);
fixname2(s,strlen(s));
p=p+strlen(p)+1;
ModelInstansName[t++] = s;
// < 3.1.0 ADT MMDX section store filename.mdx filenames for corresponded .m2 file
std::string ext3 = path.size() >= 4 ? path.substr(path.size()-4,4) : "";
std::transform( ext3.begin(), ext3.end(), ext3.begin(), ::tolower );
if(ext3 == ".mdx")
{
// replace .mdx -> .m2
path.erase(path.length()-2,2);
path.append("2");
}
// >= 3.1.0 ADT MMDX section store filename.m2 filenames for corresponded .m2 file
// nothing do
char szLocalFile[1024];
snprintf(szLocalFile, 1024, "%s/%s", szWorkDirWmo, s);
FILE * output = fopen(szLocalFile,"rb");
if(!output)
{
Model m2(path);
if(m2.open())
m2.ConvertToVMAPModel(szLocalFile);
}
else
fclose(output);
}
delete[] buf;
}
}
else if (!strcmp(fourcc,"MWMO"))
{
if (size)
{
char *buf = new char[size];
ADT.read(buf, size);
char *p=buf;
int q = 0;
//.........这里部分代码省略.........
示例8: ExtractWmo
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------
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
//.........这里部分代码省略.........
示例9: ExtractGameobjectModels
void ExtractGameobjectModels()
{
printf("\n");
printf("Extracting GameObject models...\n");
DBCFile dbc("DBFilesClient\\GameObjectDisplayInfo.dbc");
if (!dbc.open())
{
printf("Fatal error: Invalid GameObjectDisplayInfo.dbc file format!\n");
exit(1);
}
std::string basepath = szWorkDirWmo;
basepath += "/";
std::string path;
StringSet failedPaths;
FILE* model_list = fopen((basepath + "temp_gameobject_models").c_str(), "wb");
for (DBCFile::Iterator it = dbc.begin(); it != dbc.end(); ++it)
{
path = it->getString(1);
if (path.length() < 4)
continue;
fixnamen((char*)path.c_str(), path.size());
char* name = GetPlainName((char*)path.c_str());
fixname2(name, strlen(name));
char* ch_ext = GetExtension(name);
if (!ch_ext)
continue;
strToLower(ch_ext);
bool result = false;
if (!strcmp(ch_ext, ".wmo"))
{
result = ExtractSingleWmo(path);
}
else if (!strcmp(ch_ext, ".mdl"))
{
// TODO: extract .mdl files, if needed
continue;
}
else //if (!strcmp(ch_ext, ".mdx") || !strcmp(ch_ext, ".m2"))
{
result = ExtractSingleModel(path, failedPaths);
}
if (result)
{
uint32 displayId = it->getUInt(0);
uint32 path_length = strlen(name);
fwrite(&displayId, sizeof(uint32), 1, model_list);
fwrite(&path_length, sizeof(uint32), 1, model_list);
fwrite(name, sizeof(char), path_length, model_list);
}
}
fclose(model_list);
if (!failedPaths.empty())
{
printf("Warning: Some models could not be extracted, see below\n");
for (StringSet::const_iterator itr = failedPaths.begin(); itr != failedPaths.end(); ++itr)
printf("Could not find file of model %s\n", itr->c_str());
printf("A few of these warnings are expected to happen, so be not alarmed!\n");
}
printf("Done!\n");
}
示例10: fopen
bool ADTFile::init(uint32 map_num, uint32 tileX, uint32 tileY)
{
if (ADT.isEof())
return false;
uint32 size;
std::string dirname = std::string(szWorkDirWmo) + "/dir_bin";
FILE *dirfile;
dirfile = fopen(dirname.c_str(), "ab");
if(!dirfile)
{
printf("Can't open dirfile!'%s'\n", dirname.c_str());
return false;
}
while (!ADT.isEof())
{
char fourcc[5];
ADT.read(&fourcc,4);
ADT.read(&size, 4);
flipcc(fourcc);
fourcc[4] = 0;
size_t nextpos = ADT.getPos() + size;
if (!strcmp(fourcc,"MCIN"))
{
}
else if (!strcmp(fourcc,"MTEX"))
{
}
else if (!strcmp(fourcc,"MMDX"))
{
if (size)
{
char* buf = new char[size];
ADT.read(buf, size);
char* p = buf;
while (p < buf + size)
{
std::string path(p);
char* s = GetPlainName(p);
FixNameCase(s, strlen(s));
FixNameSpaces(s, strlen(s));
ModelInstanceNames.push_back(s);
ExtractSingleModel(path);
p += strlen(p) + 1;
}
delete[] buf;
}
}
else if (!strcmp(fourcc,"MWMO"))
{
if (size)
{
char* buf = new char[size];
ADT.read(buf, size);
char* p = buf;
while (p < buf + size)
{
char* s = GetPlainName(p);
FixNameCase(s, strlen(s));
FixNameSpaces(s, strlen(s));
WmoInstanceNames.push_back(s);
p += strlen(p) + 1;
}
delete[] buf;
}
}
//======================
else if (!strcmp(fourcc,"MDDF"))
{
if (size)
{
nMDX = (int)size / 36;
for (int i=0; i<nMDX; ++i)
{
uint32 id;
ADT.read(&id, 4);
ModelInstance inst(ADT, ModelInstanceNames[id].c_str(), map_num, tileX, tileY, dirfile);
}
ModelInstanceNames.clear();
}
}
else if (!strcmp(fourcc,"MODF"))
{
if (size)
{
nWMO = (int)size / 64;
for (int i=0; i<nWMO; ++i)
{
uint32 id;
ADT.read(&id, 4);
//.........这里部分代码省略.........
示例11: initFromCache
bool ADTFile::init(uint32 map_num, uint32 originalMapId)
{
if (dirfileCache)
return initFromCache(map_num, originalMapId);
if (_file.isEof())
return false;
uint32 size;
std::string dirname = std::string(szWorkDirWmo) + "/dir_bin";
FILE* dirfile = fopen(dirname.c_str(), "ab");
if(!dirfile)
{
printf("Can't open dirfile!'%s'\n", dirname.c_str());
return false;
}
if (cacheable)
dirfileCache = new std::vector<ADTOutputCache>();
while (!_file.isEof())
{
char fourcc[5];
_file.read(&fourcc,4);
_file.read(&size, 4);
flipcc(fourcc);
fourcc[4] = 0;
size_t nextpos = _file.getPos() + size;
if (!strcmp(fourcc,"MCIN"))
{
}
else if (!strcmp(fourcc,"MTEX"))
{
}
else if (!strcmp(fourcc,"MMDX"))
{
if (size)
{
char* buf = new char[size];
_file.read(buf, size);
char* p = buf;
while (p < buf + size)
{
std::string path(p);
char* s = GetPlainName(p);
FixNameCase(s, strlen(s));
FixNameSpaces(s, strlen(s));
ModelInstanceNames.emplace_back(s);
ExtractSingleModel(path);
p += strlen(p) + 1;
}
delete[] buf;
}
}
else if (!strcmp(fourcc,"MWMO"))
{
if (size)
{
char* buf = new char[size];
_file.read(buf, size);
char* p = buf;
while (p < buf + size)
{
std::string path(p);
char* s = GetPlainName(p);
FixNameCase(s, strlen(s));
FixNameSpaces(s, strlen(s));
WmoInstanceNames.emplace_back(s);
ExtractSingleWmo(path);
p += strlen(p) + 1;
}
delete[] buf;
}
}
//======================
else if (!strcmp(fourcc, "MDDF"))
{
if (size)
{
uint32 doodadCount = size / sizeof(ADT::MDDF);
for (uint32 i = 0; i < doodadCount; ++i)
{
ADT::MDDF doodadDef;
_file.read(&doodadDef, sizeof(ADT::MDDF));
if (!(doodadDef.Flags & 0x40))
{
Doodad::Extract(doodadDef, ModelInstanceNames[doodadDef.Id].c_str(), map_num, originalMapId, dirfile, dirfileCache);
}
else
{
//.........这里部分代码省略.........
示例12: GetPlainName
bool ADTFile::init(char *map_id)
{
if(ADT.isEof ())
return false;
size_t size;
string xMap;
string yMap;
Adtfilename.erase(Adtfilename.find(".adt"),4);
string TempMapNumber;
TempMapNumber = Adtfilename.substr(Adtfilename.length()-6,6);
xMap = TempMapNumber.substr(TempMapNumber.find("_")+1,(TempMapNumber.find_last_of("_")-1) - (TempMapNumber.find("_")));
yMap = TempMapNumber.substr(TempMapNumber.find_last_of("_")+1,(TempMapNumber.length()) - (TempMapNumber.find_last_of("_")));
Adtfilename.erase((Adtfilename.length()-xMap.length()-yMap.length()-2), (xMap.length()+yMap.length()+2));
string AdtMapNumber = xMap + ' ' + yMap + ' ' + GetPlainName((char*)Adtfilename.c_str());
printf("Processing map %s...\n", AdtMapNumber.c_str());
//printf("MapNumber = %s\n", TempMapNumber.c_str());
//printf("xMap = %s\n", xMap.c_str());
//printf("yMap = %s\n", yMap.c_str());
const char dirname[] = "buildings\\dir";
FILE *dirfile;
dirfile = fopen(dirname, "ab");
if(!dirfile)
{
printf("Can't open dirfile!'%s'\n");
return false;
}
while (!ADT.isEof ())
{
char fourcc[5];
ADT.read(&fourcc,4);
ADT.read(&size, 4);
flipcc(fourcc);
fourcc[4] = 0;
size_t nextpos = ADT.getPos () + size;
if (!strcmp(fourcc,"MCIN"))//MCIN
{
}
else if (!strcmp(fourcc,"MTEX"))
{
}
else if (!strcmp(fourcc,"MMDX"))
{
if (size)
{
char *buf = new char[size];
ADT.read(buf, size);
char *p=buf;
int t=0;
ModelInstansName = new string[size];
while (p<buf+size)
{
fixnamen(p,strlen(p));
string path(p);
char* s=GetPlainName(p);
fixname2(s,strlen(s));
p=p+strlen(p)+1;
ModelInstansName[t++] = s;
path.erase(path.length()-2,2);
path.append("2");
char* szLocalFile[512];
sprintf((char*)szLocalFile, ".\\buildings\\%s", s);
FILE * output = fopen((char*)szLocalFile,"rb");
if(!output)
{
Model * m2 = new Model(path);
if(m2->open())
{
m2->ConvertToVMAPModel((char*)szLocalFile);
}
delete m2;
}
else
fclose(output);
}
delete[] buf;
}
}
else if (!strcmp(fourcc,"MWMO"))
{
if (size)
{
char *buf = new char[size];
ADT.read(buf, size);
char *p=buf;
//.........这里部分代码省略.........
示例13: memset
bool ADTFile::init(uint32 map_num, uint32 tileX, uint32 tileY)
{
if(ADT.isEof ())
return false;
uint32 size;
string xMap;
string yMap;
MH20_Header mh2oheader[256];
memset(&mh2oheader,0, sizeof(MH20_Header)*256);
uint32 mh2o_base = 0;
Adtfilename.erase(Adtfilename.find(".adt"),4);
string TempMapNumber;
TempMapNumber = Adtfilename.substr(Adtfilename.length()-6,6);
xMap = TempMapNumber.substr(TempMapNumber.find("_")+1,(TempMapNumber.find_last_of("_")-1) - (TempMapNumber.find("_")));
yMap = TempMapNumber.substr(TempMapNumber.find_last_of("_")+1,(TempMapNumber.length()) - (TempMapNumber.find_last_of("_")));
Adtfilename.erase((Adtfilename.length()-xMap.length()-yMap.length()-2), (xMap.length()+yMap.length()+2));
string AdtMapNumber = xMap + ' ' + yMap + ' ' + GetPlainName((char*)Adtfilename.c_str());
std::string dirname = std::string(szWorkDirWmo) + "/dir_bin";
FILE *dirfile = fopen(dirname.c_str(), "ab");
if(!dirfile)
{
printf("Can't open dirfile!'%s'\n", dirname.c_str());
return false;
}
while (!ADT.isEof())
{
char fourcc[5];
ADT.read(&fourcc, 4);
ADT.read(&size, 4);
flipcc(fourcc);
fourcc[4] = 0;
size_t nextpos = ADT.getPos() + size;
if (!strcmp(fourcc,"MCIN"))
{
}
else if (!strcmp(fourcc,"MVER"))
{
}
else if (!strcmp(fourcc,"MHDR"))
{
}
else if (!strcmp(fourcc,"MTEX"))
{
}
else if (!strcmp(fourcc,"MWID")) // offsets for strings in MWMO
{
}
else if (!strcmp(fourcc,"MMID")) // offsets for strings in MMDX
{
}
else if (!strcmp(fourcc,"MTEX"))
{
}
else if (!strcmp(fourcc,"MTXF"))
{
}
else if (!strcmp(fourcc,"MFBO"))
{
}
else if (!strcmp(fourcc,"MMDX"))
{
if (size)
{
char *buf = new char[size];
ADT.read(buf, size);
char *p=buf;
int t=0;
ModelInstansName = new string[size];
while (p<buf+size)
{
fixnamen(p,strlen(p));
string path(p);
char* s=GetPlainName(p);
fixname2(s,strlen(s));
p=p+strlen(p)+1;
ModelInstansName[t++] = s;
// < 3.1.0 ADT MMDX section store filename.mdx filenames for corresponded .m2 file
std::string ext3 = path.size() >= 4 ? path.substr(path.size()-4,4) : "";
std::transform( ext3.begin(), ext3.end(), ext3.begin(), ::tolower );
if(ext3 == ".mdx")
{
// replace .mdx -> .m2
path.erase(path.length()-2,2);
path.append("2");
}
// >= 3.1.0 ADT MMDX section store filename.m2 filenames for corresponded .m2 file
// nothing do
char szLocalFile[1024];
snprintf(szLocalFile, 1024, "%s/%s", szWorkDirWmo, s);
FILE * output = fopen(szLocalFile,"rb");
//.........这里部分代码省略.........
示例14: ExtractSingleWmo
bool ExtractSingleWmo(std::string& fname)
{
// Copy files from archive
char szLocalFile[1024];
const char * plain_name = GetPlainName(fname.c_str());
sprintf(szLocalFile, "%s/%s", szWorkDirWmo, plain_name);
FixNameCase(szLocalFile, strlen(szLocalFile));
FixNameSpaces(szLocalFile, strlen(szLocalFile));
if (FileExists(szLocalFile))
return true;
int p = 0;
// Select root wmo files
char const* rchr = strrchr(plain_name, '_');
if (rchr != NULL)
{
char cpy[4];
memcpy(cpy, rchr, 4);
for (int i = 0; i < 4; ++i)
{
int m = cpy[i];
if (isdigit(m))
p++;
}
}
if (p == 3)
return true;
bool file_ok = true;
printf("Extracting %s\n", fname.c_str());
WMORoot froot(fname);
if(!froot.open())
{
printf("Couldn't open RootWmo!!!\n");
return true;
}
FILE *output = fopen(szLocalFile,"wb");
if(!output)
{
printf("couldn't open %s for writing!\n", szLocalFile);
return false;
}
froot.ConvertToVMAPRootWmo(output);
int Wmo_nVertices = 0;
//printf("root has %d groups\n", froot->nGroups);
for (std::size_t i = 0; i < froot.groupFileDataIDs.size(); ++i)
{
std::string s = Trinity::StringFormat("FILE%08X.xxx", froot.groupFileDataIDs[i]);
WMOGroup fgroup(s);
if(!fgroup.open())
{
printf("Could not open all Group file for: %s\n", plain_name);
file_ok = false;
break;
}
Wmo_nVertices += fgroup.ConvertToVMAPGroupWmo(output, &froot, preciseVectorData);
}
fseek(output, 8, SEEK_SET); // store the correct no of vertices
fwrite(&Wmo_nVertices,sizeof(int),1,output);
fclose(output);
// Delete the extracted file in the case of an error
if (!file_ok)
remove(szLocalFile);
return true;
}
示例15: ExtractSingleWmo
bool ExtractSingleWmo(std::string& fname)
{
// Copy files from archive
std::string originalName = fname;
char szLocalFile[1024];
char* plain_name = GetPlainName(&fname[0]);
FixNameCase(plain_name, strlen(plain_name));
FixNameSpaces(plain_name, strlen(plain_name));
sprintf(szLocalFile, "%s/%s", szWorkDirWmo, plain_name);
if (FileExists(szLocalFile))
return true;
int p = 0;
// Select root wmo files
char const* rchr = strrchr(plain_name, '_');
if (rchr != NULL)
{
char cpy[4];
memcpy(cpy, rchr, 4);
for (int i = 0; i < 4; ++i)
{
int m = cpy[i];
if (isdigit(m))
p++;
}
}
if (p == 3)
return true;
bool file_ok = true;
printf("Extracting %s\n", originalName.c_str());
WMORoot froot(originalName);
if (!froot.open())
{
printf("Couldn't open RootWmo!!!\n");
return true;
}
FILE *output = fopen(szLocalFile,"wb");
if(!output)
{
printf("couldn't open %s for writing!\n", szLocalFile);
return false;
}
froot.ConvertToVMAPRootWmo(output);
WMODoodadData& doodads = WmoDoodads[plain_name];
std::swap(doodads, froot.DoodadData);
int Wmo_nVertices = 0;
//printf("root has %d groups\n", froot->nGroups);
for (std::size_t i = 0; i < froot.groupFileDataIDs.size(); ++i)
{
std::string s = Trinity::StringFormat("FILE%08X.xxx", froot.groupFileDataIDs[i]);
WMOGroup fgroup(s);
if (!fgroup.open(&froot))
{
printf("Could not open all Group file for: %s\n", plain_name);
file_ok = false;
break;
}
Wmo_nVertices += fgroup.ConvertToVMAPGroupWmo(output, preciseVectorData);
for (uint16 groupReference : fgroup.DoodadReferences)
{
if (groupReference >= doodads.Spawns.size())
continue;
uint32 doodadNameIndex = doodads.Spawns[groupReference].NameIndex;
if (froot.ValidDoodadNames.find(doodadNameIndex) == froot.ValidDoodadNames.end())
continue;
doodads.References.insert(groupReference);
}
}
fseek(output, 8, SEEK_SET); // store the correct no of vertices
fwrite(&Wmo_nVertices,sizeof(int),1,output);
fclose(output);
// Delete the extracted file in the case of an error
if (!file_ok)
remove(szLocalFile);
return true;
}