dat ver 8.6

This commit is contained in:
Henrique 2011-08-01 23:07:19 -03:00
parent f07648219c
commit cf6ca15c6f
5 changed files with 284 additions and 2 deletions

View File

@ -48,6 +48,9 @@ SET(SOURCES
# game sources # game sources
src/main.cpp src/main.cpp
# game files
src/tibiadat.cpp
# game net # game net
src/protocollogin.cpp src/protocollogin.cpp
src/protocolgame.cpp src/protocolgame.cpp

View File

@ -8,6 +8,7 @@
#include <core/packages.h> #include <core/packages.h>
#include <ui/uicontainer.h> #include <ui/uicontainer.h>
#include <script/luainterface.h> #include <script/luainterface.h>
#include "tibiadat.h"
#include <csignal> #include <csignal>
@ -78,6 +79,10 @@ int main(int argc, const char *argv[])
// load resources paths // load resources paths
g_resources.init(args[0].c_str()); g_resources.init(args[0].c_str());
// load Tibia.dat TODO this is temporary
if(!g_tibiaDat.load("Tibia.dat"))
return -1;
// load configurations // load configurations
loadDefaultConfigs(); loadDefaultConfigs();
if(!g_configs.load("config.otml")) if(!g_configs.load("config.otml"))

View File

@ -1,5 +1,6 @@
#include "protocolgame.h" #include "protocolgame.h"
#include "player.h" #include "player.h"
#include "tibiadat.h"
#include <iomanip> #include <iomanip>
void ProtocolGame::parseMessage(InputMessage& msg) void ProtocolGame::parseMessage(InputMessage& msg)
@ -881,8 +882,10 @@ void ProtocolGame::internalGetItem(InputMessage& msg, uint16 id)
{ {
if(id == 0xFFFF) if(id == 0xFFFF)
id = msg.getU16(); id = msg.getU16();
//if(Data::instance()->hasCountOrSubType(id))
//msg.getU8(); Item *item = g_tibiaDat.getItem(id);
if(item->stackable || item->group == ITEM_GROUP_FLUID || item->group == ITEM_GROUP_SPLASH)
msg.getU8();
} }
Position ProtocolGame::parsePosition(InputMessage& msg) Position ProtocolGame::parsePosition(InputMessage& msg)

184
src/tibiadat.cpp Normal file
View File

@ -0,0 +1,184 @@
#include "tibiadat.h"
#include <core/resources.h>
TibiaDat g_tibiaDat;
bool TibiaDat::load(const std::string& filename)
{
std::stringstream fin;
if(!g_resources.loadFile(filename, fin))
return false;
fin.read((char*)&m_signature, 4);
fin.read((char*)&m_groupCount[0], 2);
fin.read((char*)&m_groupCount[1], 2);
fin.read((char*)&m_groupCount[2], 2);
fin.read((char*)&m_groupCount[3], 2);
m_groupCount[0] -= 99;
m_totalCount = m_groupCount[0] + m_groupCount[1] + m_groupCount[2] + m_groupCount[3];
m_items = new Item*[m_totalCount+1];
for(uint16 i = 0; i <= m_totalCount; i++)
m_items[i] = NULL;
uint8 read_byte;
uint16 read_short;
uint32 read_long;
for(uint16 id = 0; (id <= m_totalCount) && !fin.eof(); id++) {
m_items[id] = new Item();
m_items[id]->id = id;
uint8 opt;
bool done = false;
while(!done) {
fin.read((char*)&opt, 1);
if(opt == 0x00) { // Ground tile
fin.read((char*)&m_items[id]->speed, 2);
m_items[id]->group = ITEM_GROUP_GROUND;
}
else if(opt == 0x01) { // All OnTop
m_items[id]->alwaysOnTop = true;
m_items[id]->alwaysOnTopOrder = 1;
}
else if(opt == 0x02) { // Can walk trough (open doors, arces, bug pen fence)
m_items[id]->alwaysOnTop = true;
m_items[id]->alwaysOnTopOrder = 2;
}
else if(opt == 0x03) { // Can walk trough (arces)
m_items[id]->alwaysOnTop = true;
m_items[id]->alwaysOnTopOrder = 3;
}
else if(opt == 0x04) { // Container
m_items[id]->group = ITEM_GROUP_CONTAINER;
}
else if(opt == 0x05) { // Stackable
m_items[id]->stackable = true;
}
else if(opt == 0x06) { // Unknown
}
else if(opt == 0x07) { // Useable
m_items[id]->useable = true;
}
else if(opt == 0x08) { // Writtable
m_items[id]->group = ITEM_GROUP_WRITEABLE;
m_items[id]->readable = true;
fin.read((char*)&m_items[id]->subParam07, 2);
}
else if(opt == 0x09) { // Writtable once
// Writtable objects that can't be edited by players
m_items[id]->readable = true;
fin.read((char*)&m_items[id]->subParam08, 2);
}
else if(opt == 0x0A) { // Fluid containers
fin.read((char*)&read_byte, 1);
m_items[id]->group = ITEM_GROUP_FLUID;
}
else if(opt == 0x0B) { // Splashes
m_items[id]->group = ITEM_GROUP_SPLASH;
}
else if(opt == 0x0C) { // Blocks solid objects (creatures, walls etc)
m_items[id]->blockSolid = true;
}
else if(opt == 0x0D) { // Not moveable
m_items[id]->moveable = false;
}
else if(opt == 0x0E) { // Blocks missiles (walls, magic wall etc)
m_items[id]->blockProjectile = true;
}
else if(opt == 0x0F) { // Blocks pathfind algorithms (monsters)
m_items[id]->blockPathFind = true;
}
else if(opt == 0x10) { // Blocks monster movement (flowers, parcels etc)
m_items[id]->pickupable = true;
}
else if(opt == 0x11) { // Hangable objects (wallpaper etc)
m_items[id]->isHangable = true;
}
else if(opt == 0x12) { // Horizontal wall
m_items[id]->isHorizontal = true;
}
else if(opt == 0x13) { // Vertical wall
m_items[id]->isVertical = true;
}
else if(opt == 0x14) { // Rotable
m_items[id]->rotable = true;
}
else if(opt == 0x15) { // Light info
fin.read((char*)&m_items[id]->lightLevel, 2);
fin.read((char*)&m_items[id]->lightColor, 2);
}
else if(opt == 0x16) {
}
else if(opt == 0x17) { // Changes floor
}
else if(opt == 0x18) { // Unknown
fin.read((char*)&read_long, 4);
}
else if(opt == 0x19) { // Has height
m_items[id]->hasHeight = true;
fin.read((char*)&m_items[id]->uheight, 2);
}
else if(opt == 0x1A) {
}
else if(opt == 0x1B) {
}
else if(opt == 0x1C) { // Minimap color
fin.read((char*)&m_items[id]->miniMapColor, 2);
m_items[id]->hasMiniMapColor = true;
}
else if(opt == 0x1D) { // Unknown
fin.read((char*)&read_short, 2);
if(read_short == 1112)
m_items[id]->readable = true;
}
else if(opt == 0x1E) {
}
else if(opt == 0x1F) {
m_items[id]->lookThrough = true;
}
else if(opt == 0x20) {
}
else if(opt == 0xFF) {
done = true;
}
else {
logDebug("Unknown byte code: ", opt);
return false;
}
}
fin.read((char*)&m_items[id]->width, 1);
fin.read((char*)&m_items[id]->height, 1);
if((m_items[id]->width > 1) || (m_items[id]->height > 1))
fin.read((char*)&read_byte, 1);
fin.read((char*)&m_items[id]->blendframes, 1);
fin.read((char*)&m_items[id]->xdiv, 1);
fin.read((char*)&m_items[id]->ydiv, 1);
fin.read((char*)&m_items[id]->zdiv, 1);
fin.read((char*)&m_items[id]->animcount, 1);
// Read sprites id.
uint16 totalSprites = m_items[id]->width * m_items[id]->height * m_items[id]->blendframes * m_items[id]->xdiv * m_items[id]->ydiv * m_items[id]->zdiv * m_items[id]->animcount;
m_items[id]->sprites = new uint16[totalSprites];
for(uint16 i = 0; i < totalSprites; i++) {
fin.read((char*)&read_short, 2);
m_items[id]->sprites[i] = read_short-1;
}
}
return true;
}
Item *TibiaDat::getItem(uint16 id)
{
// items id start at 100.
return m_items[id - 100];
}

87
src/tibiadat.h Normal file
View File

@ -0,0 +1,87 @@
#ifndef TIBIADAT_H
#define TIBIADAT_H
#include <global.h>
enum ItemGroup {
ITEM_GROUP_NONE = 0,
ITEM_GROUP_GROUND,
ITEM_GROUP_CONTAINER,
ITEM_GROUP_WEAPON,
ITEM_GROUP_AMMUNITION,
ITEM_GROUP_ARMOR,
ITEM_GROUP_RUNE,
ITEM_GROUP_TELEPORT,
ITEM_GROUP_MAGICFIELD,
ITEM_GROUP_WRITEABLE,
ITEM_GROUP_KEY,
ITEM_GROUP_SPLASH,
ITEM_GROUP_FLUID,
ITEM_GROUP_DOOR,
ITEM_GROUP_LAST
};
struct Item
{
Item() {
group = ITEM_GROUP_NONE;
blockSolid = false;
hasHeight = false;
blockPathFind = false;
blockProjectile = false;
alwaysOnTop = false;
alwaysOnTopOrder = 0;
stackable = false;
useable = false;
moveable = true;
pickupable = false;
rotable = false;
readable = false;
lookThrough = false;
speed = 0;
lightLevel = 0;
lightColor = 0;
isVertical = false;
isHorizontal = false;
isHangable = false;
miniMapColor = 0;
hasMiniMapColor = false;
subParam07 = 0;
subParam08 = 0;
sprites = NULL;
}
~Item() {
if(sprites)
delete []sprites;
}
bool stackable, alwaysOnTop, useable, readable, moveable, blockSolid, blockProjectile, blockPathFind, pickupable,
isHangable, isHorizontal, isVertical, rotable, hasHeight, lookThrough, hasMiniMapColor;
uint8 alwaysOnTopOrder, width, height, blendframes, xdiv, ydiv, zdiv, animcount;
uint16 id, speed, subParam07, subParam08, lightLevel, lightColor, uheight, miniMapColor;
uint16 *sprites;
ItemGroup group;
};
class TibiaDat
{
public:
bool load(const std::string& filename);
Item *getItem(uint16 id);
uint16 getGroupCount(int i) { return m_groupCount[i]; }
uint32 getSignature() { return m_signature; }
uint16 getTotalCount() { return m_totalCount; }
private:
uint32 m_signature, m_totalCount;
uint16 m_groupCount[4];
Item **m_items;
};
extern TibiaDat g_tibiaDat;
#endif // TIBIADAT_H