Some missing from merge.

Signed-off-by: Salja <salja2012@hotmail.de>
This commit is contained in:
Salja 2012-08-05 14:54:07 +02:00 committed by Antz
parent ec939a5bce
commit f4be15a7af
1895 changed files with 160408 additions and 53601 deletions

View file

@ -48,6 +48,27 @@ bool ADT_file::prepareLoadedData()
if (!a_grid->prepareLoadedData())
return false;
// funny offsets calculations because there is no mapping for them and they have variable lengths
uint8* ptr = (uint8*)a_grid + a_grid->size + 8;
uint32 mcnk_count = 0;
memset(cells, 0, ADT_CELLS_PER_GRID * ADT_CELLS_PER_GRID * sizeof(adt_MCNK*));
while (ptr < GetData() + GetDataSize())
{
uint32 header = *(uint32*)ptr;
uint32 size = *(uint32*)(ptr + 4);
if (header == 'MCNK')
{
cells[mcnk_count / ADT_CELLS_PER_GRID][mcnk_count % ADT_CELLS_PER_GRID] = (adt_MCNK*)ptr;
++mcnk_count;
}
// move to next chunk
ptr += size + 8;
}
if (mcnk_count != ADT_CELLS_PER_GRID * ADT_CELLS_PER_GRID)
return false;
return true;
}

View file

@ -25,6 +25,7 @@ enum LiquidType
//
// Adt file height map chunk
//
class ADT_file;
class adt_MCVT
{
union{
@ -252,9 +253,11 @@ class adt_MHDR
uint32 fcc;
char fcc_txt[4];
};
public:
uint32 size;
uint32 pad;
uint32 flags;
uint32 offsMCIN; // MCIN
uint32 offsTex; // MTEX
uint32 offsModels; // MMDX
@ -272,8 +275,8 @@ class adt_MHDR
uint32 data5;
public:
bool prepareLoadedData();
adt_MCIN *getMCIN(){ return (adt_MCIN *)((uint8 *)&pad+offsMCIN);}
adt_MH2O *getMH2O(){ return offsMH2O ? (adt_MH2O *)((uint8 *)&pad+offsMH2O) : 0;}
adt_MCIN* getMCIN() { return offsMCIN ? (adt_MCIN *)((uint8 *)&flags+offsMCIN) : 0; }
adt_MH2O* getMH2O() { return offsMH2O ? (adt_MH2O *)((uint8 *)&flags+offsMH2O) : 0; }
};
@ -284,7 +287,8 @@ public:
~ADT_file();
void free();
adt_MHDR *a_grid;
adt_MHDR* a_grid;
adt_MCNK* cells[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID];
};
bool isHole(int holes, int i, int j);

View file

@ -1,11 +1,78 @@
#define _CRT_SECURE_NO_DEPRECATE
#include "loadlib.h"
#include "../mpq_libmpq.h"
#include <stdio.h>
// list of mpq files for lookup most recent file version
ArchiveSet gOpenArchives;
class MPQFile;
ArchiveSetBounds GetArchivesBounds()
{
return ArchiveSetBounds(gOpenArchives.begin(), gOpenArchives.end());
}
bool OpenArchive(char const* mpqFileName, HANDLE* mpqHandlePtr /*= NULL*/)
{
HANDLE mpqHandle;
if (!SFileOpenArchive(mpqFileName, 0, MPQ_OPEN_READ_ONLY, &mpqHandle))
return false;
gOpenArchives.push_back(mpqHandle);
if (mpqHandlePtr)
*mpqHandlePtr = mpqHandle;
return true;
}
bool OpenNewestFile(char const* filename, HANDLE* fileHandlerPtr)
{
for(ArchiveSet::const_reverse_iterator i=gOpenArchives.rbegin(); i!=gOpenArchives.rend();++i)
{
// always prefer get updated file version
if (SFileOpenFileEx(*i, filename, SFILE_OPEN_PATCHED_FILE, fileHandlerPtr))
return true;
}
return false;
}
bool ExtractFile( char const* mpq_name, std::string const& filename )
{
for(ArchiveSet::const_reverse_iterator i=gOpenArchives.rbegin(); i!=gOpenArchives.rend();++i)
{
HANDLE fileHandle;
if (!SFileOpenFileEx(*i, mpq_name, SFILE_OPEN_PATCHED_FILE, &fileHandle))
continue;
if (SFileGetFileSize(fileHandle, NULL) == 0) // some files removed in next updates and its reported size 0
{
SFileCloseFile(fileHandle);
return true;
}
SFileCloseFile(fileHandle);
if (!SFileExtractFile(*i, mpq_name, filename.c_str(), SFILE_OPEN_PATCHED_FILE))
{
printf("Can't extract file: %s\n", mpq_name);
return false;
}
return true;
}
printf("Extracting file not found: %s\n", filename.c_str());
return false;
}
void CloseArchives()
{
for(ArchiveSet::const_iterator i = gOpenArchives.begin(); i != gOpenArchives.end();++i)
SFileCloseArchive(*i);
gOpenArchives.clear();
}
FileLoader::FileLoader()
{
@ -22,36 +89,54 @@ FileLoader::~FileLoader()
bool FileLoader::loadFile(char *filename, bool log)
{
free();
MPQFile mf(filename);
if(mf.isEof())
HANDLE fileHandle = 0;
if (!OpenNewestFile(filename, &fileHandle))
{
if (log)
printf("No such file %s\n", filename);
return false;
}
data_size = mf.getSize();
data_size = SFileGetFileSize(fileHandle, NULL);
data = new uint8 [data_size];
if (data)
if (!data)
{
mf.read(data, data_size);
mf.close();
if (prepareLoadedData())
return true;
SFileCloseFile(fileHandle);
return false;
}
printf("Error loading %s", filename);
mf.close();
free();
return false;
if (!SFileReadFile(fileHandle, data, data_size, NULL, NULL))
{
if (log)
printf("Can't read file %s\n", filename);
SFileCloseFile(fileHandle);
return false;
}
SFileCloseFile(fileHandle);
// ToDo: Fix WDT errors...
if (!prepareLoadedData())
{
//printf("Error loading %s\n\n", filename);
//free();
return true;
}
return true;
}
bool FileLoader::prepareLoadedData()
{
// Check version
version = (file_MVER *) data;
if (version->fcc != 'MVER')
return false;
if (version->ver != FILE_FORMAT_VERSION)
return false;
return true;

View file

@ -1,6 +1,13 @@
#ifndef LOAD_LIB_H
#define LOAD_LIB_H
#ifdef _DLL
#undef _DLL
#endif
#include "StormLib.h"
#include <deque>
#ifdef WIN32
typedef __int64 int64;
typedef __int32 int32;
@ -27,6 +34,15 @@ typedef uint16_t uint16;
typedef uint8_t uint8;
#endif
typedef std::deque<HANDLE> ArchiveSet;
typedef std::pair<ArchiveSet::const_iterator,ArchiveSet::const_iterator> ArchiveSetBounds;
bool OpenArchive(char const* mpqFileName, HANDLE* mpqHandlePtr = NULL);
bool OpenNewestFile(char const* filename, HANDLE* fileHandlerPtr);
ArchiveSetBounds GetArchivesBounds();
bool ExtractFile( char const* mpq_name, std::string const& filename );
void CloseArchives();
#define FILE_FORMAT_VERSION 18
//