#include #include "Xentax.h" #include "GWUnpacker.h" #include #include using namespace std; void GWDat::seek(__int64 offset, int origin) { LARGE_INTEGER i; i.QuadPart=offset; SetFilePointerEx(fileHandle,i,NULL,FILE_BEGIN); } void GWDat::read(void *buffer, int size, int count) { DWORD bread; int errcde = ReadFile(fileHandle,buffer,size*count,&bread,NULL); if (!errcde) { TCHAR text[2048]; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0,GetLastError(),0,text,1024,NULL); printf("%s\n",text); } } unsigned char* GWDat::readFile(unsigned int n, bool translate /* = true*/) { MFTEntry& m = MFT[n]; if (!m.b) { m.uncompressedSize = 0; mftBaseFiles += 1; return NULL; } unsigned char *Input = new unsigned char[m.Size]; unsigned char *Output = NULL; int OutSize = 0; seek(m.Offset, 0); read(Input, m.Size, 1); if (m.a) UnpackGWDat(Input, m.Size, Output, OutSize); else { Output = new unsigned char[m.Size]; memcpy(Output, Input, m.Size); OutSize = m.Size; } delete[] Input; if (Output) { } return Output; } bool compareH(MFTExpansion& a, MFTExpansion b) { return a.FileOffset < b.FileOffset; } unsigned int GWDat::readDat(char* file) { fileHandle = CreateFile(file,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); if (fileHandle == INVALID_HANDLE_VALUE) { char text[2048]; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0,GetLastError(),0,text,2048,NULL); printf("Error while opening \"%s\": %s", file, text); return 0; } read(&GWHead,sizeof(GWHead),1); if (!(GWHead.ID[0]==0x33 && GWHead.ID[1]==0x41 && GWHead.ID[2]==0x4e && GWHead.ID[3]==0x1a)) { printf("The input file \"%s\"is not a Guild Wars datafile!", file); CloseHandle(fileHandle); return 0; } //read reserved MFT entries seek(GWHead.MFTOffset,SEEK_SET); read(&MFTH,sizeof(MFTH),1); for (int x = 0; x < 15; ++x) { MFTEntry ME; read(&ME,0x18,1); //ME.type = NOTREAD; ME.uncompressedSize = -1; ME.Hash = 0; MFT.push_back(ME); } //read Hashlist seek(MFT[1].Offset,SEEK_SET); int mftxsize=MFT[1].Size/sizeof(MFTExpansion); for (unsigned int x=0; x