Example #1
0
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)
                {
                    uint32 id;
                    ADT.read(&id, 4);
                    ModelInstance inst(ADT,ModelInstansName[id].c_str(), map_num, tileX, tileY, dirfile);
                }
                delete[] ModelInstansName;
            }
        }
        else if (!strcmp(fourcc,"MODF"))
        {
            if (size)
            {
                nWMO = (int)size / 64;
                for (int i=0; i<nWMO; ++i)
                {
                    uint32 id;
                    ADT.read(&id, 4);
                    WMOInstance inst(ADT,WmoInstansName[id].c_str(), map_num, tileX, tileY, dirfile);
                }
                delete[] WmoInstansName;
            }
        }
        //======================
        ADT.seek(nextpos);
    }
    ADT.close();
    fclose(dirfile);
    return true;
}
Example #2
0
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;
                WmoInstansName = new string[size];
                while (p<buf+size)
                {
                    string path(p);
                    char* s=GetPlainName(p);
                    fixnamen(s,strlen(s));
                    fixname2(s,strlen(s));
                    p=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)
                {
                    uint32 id;
                    ADT.read(&id, 4);
                    ModelInstance inst(ADT,ModelInstansName[id].c_str(), map_num, tileX, tileY, dirfile);
                }
                delete[] ModelInstansName;
            }
        }
        else if (!strcmp(fourcc,"MODF"))
        {
            if (size)
            {
                nWMO = (int)size / 64;
                for (int i=0; i<nWMO; ++i)
                {
                    uint32 id;
                    ADT.read(&id, 4);
                    WMOInstance inst(ADT,WmoInstansName[id].c_str(), map_num, tileX, tileY, dirfile);
                }
                delete[] WmoInstansName;
            }
        }
        //======================
        ADT.seek(nextpos);
    }
    ADT.close();
    fclose(dirfile);
    return true;
}
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");
}
Example #4
0
void ExtractGameobjectModels()
{
    printf("Extracting GameObject models...");
    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;

    std::string modelListPath = basepath + "temp_gameobject_models";
    FILE* model_list = fopen(modelListPath.c_str(), "wb");
    if (!model_list)
    {
        printf("Fatal error: Could not open file %s\n", modelListPath.c_str());
        return;
    }

    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);
        }

        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");
}
Example #5
0
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;
				int q = 0;
                WmoInstansName = new string[size];
				while (p<buf+size) 
				{
					string path(p);
                    char* s=GetPlainName(p);
					fixnamen(s,strlen(s));
					fixname2(s,strlen(s));
					p=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++)
                {
                    int id;
                    ADT.read(&id, 4);
                    ModelInstance inst(ADT,ModelInstansName[id].c_str(),map_id, dirfile);//!!!!!!!!!!!
                }
            delete[] ModelInstansName;
            }
        }
        else if (!strcmp(fourcc,"MODF"))
        {
            if (size)
            {
                nWMO = (int)size / 64;
                for (int i=0; i<nWMO; i++)
                {
                    int id;
                    ADT.read(&id, 4);
                    WMOInstance inst(ADT,WmoInstansName[id].c_str(),map_id, dirfile);//!!!!!!!!!!!!!
                }
                delete[] WmoInstansName;
            }        
        }
        //======================
#if 0 
		else if (!strcmp(fourcc,"MDDF")) 
		{
			if (size)
            {			
			nMDX = (int)size / 36;
			for (int i=0; i<nMDX; i++) 
			    {
				    int id;
				    ADT.read(&id, 4);
				    ModelInstance inst(ADT,ModelInstansName[id].c_str(),AdtMapNumber.c_str(), dirfile);
			    }
			delete[] ModelInstansName;
			}
		}
		else if (!strcmp(fourcc,"MODF")) 
		{
			if (size)
            {
				nWMO = (int)size / 64;
			    for (int i=0; i<nWMO; i++) 
			    {
				    int id;
				    ADT.read(&id, 4);
				    WMOInstance inst(ADT,WmoInstansName[id].c_str(),AdtMapNumber.c_str(), dirfile);
			    }
                delete[] WmoInstansName;
			}		
		}
#endif
		ADT.seek(nextpos);
	}
	ADT.close();
    fclose(dirfile);
	return true;
}
Example #6
0
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");
                    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;
                WmoInstansName = new string[size];
                while (p<buf+size)
                {
                    string path(p);
                    char* s=GetPlainName(p);
                    fixnamen(s,strlen(s));
                    fixname2(s,strlen(s));
                    p=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)
                {
                    uint32 id;
                    ADT.read(&id, 4);
                    ModelInstance inst(ADT, ModelInstansName[id].c_str(), map_num, tileX, tileY, dirfile);
                }
                delete[] ModelInstansName;
            }
        }
        else if (!strcmp(fourcc,"MODF"))
        {
            if (size)
            {
                nWMO = (int)size / 64;
                for (int i=0; i<nWMO; ++i)
                {
                    uint32 id;
                    ADT.read(&id, 4);
                    WMOInstance inst(ADT, WmoInstansName[id].c_str(), map_num, tileX, tileY, dirfile);
                }
                delete[] WmoInstansName;
            }
        }
        else if (!strcmp(fourcc,"MCNK"))
        {
        }
        else if (!strcmp(fourcc,"MH2O"))
        {
            if (size)
            {
				mh2o_base = ADT.getPos();
				for (int i = 0; i < 256; i++)
					ADT.read(&mh2oheader[i], sizeof(MH20_Header));
            }
        }
        else
        {
            printf("Unknown Chunk type: %s\n", (char*)fourcc);
        }
        //======================
        ADT.seek(nextpos);
    }

    FILE *input = NULL;
	uint32 Offsets[256];
	string output = format("%s/Liquid_%03u_%02u_%02u.L2", szWorkDirWmo, map_num, tileX, tileY);
	fopen_s(&input, output.c_str(), "w");
	for (int j=0; j<16; j++)
		for (int i=0; i<16; i++)
			Offsets[j*16+i] = 0;

	fwrite(&Offsets, sizeof(uint32)*256, 1, input);
	for (int j=0; j<16; j++)
	{
		for (int i=0; i<16; i++)
		{
			if (mh2oheader[j*16+i].layerCount > 0)
			{
				uint32 Offset = ftell(input);
				LiquidModelInstance Liq(ADT, mh2o_base, j*16+i, &mh2oheader[j*16+i], map_num, tileX, tileY, input);
				if(Liq.ShouldWrite())
					Offsets[j*16+i] = Offset;
			}
		}
	}
	fwrite(&Offsets, sizeof(uint32)*256, 1, input);
	fclose(input);

    ADT.close();

    fclose(dirfile);
    return true;
}