Bonjour tout le monde! Premier post sur le forum (c'est important ;) ) pour ma part!
Je poste aujourd'hui pour vous faire part d'un problème que je rencontre lors de la lecture des fichier map de Dofus (.swl).
En gros, j'ai (pour le moment) 2 classes qui font l'intégralité de mon programme:
- Map.hpp: Classe qui va s'occuper d'initialiser tous les attributs d'une map, c'est à dire en gros, une "copie" de Map.as- SwlFile.hpp: Classe qui d'occupe d'ouvrir les fichiers .dlm des maps, de les décompresser, de les décrypter et enfin qui me sert à lire les données contenues dans ces fichiers
Tous les codes sont à la fin du post.
Maintenant, la partie intéressante! Le problème!
Le "départ" de ma classe Map marche à merveille (j'obtiens exactement les mêmes résultats que Caramba dans son 6e message, juste ici -> https://cadernis.com/d/1068-[d2p]-décryption-des-maps), jusqu'au moment où je me met à lire les informations liées au backGround (ce qui donne la partie ci-dessous dans le .as de Dofus)
Cliquez pour révéler
Cliquez pour masquer
if(this.mapVersion >= 3)
{
this.backgroundRed = raw.readByte();
this.backgroundGreen = raw.readByte();
this.backgroundBlue = raw.readByte();
this.backgroundColor = (this.backgroundRed & 255) << 16 | (this.backgroundGreen & 255) << 8 | this.backgroundBlue & 255;
if(AtouinConstants.DEBUG_FILES_PARSING)
{
_log.debug("BackgroundColor : " + this.backgroundRed + "," + this.backgroundGreen + "," + this.backgroundBlue);
}
}
Et ici, j'ai un problème: Toutes les valeurs lues sont 0 (quelque soit le type lu) alors que les bits lus ne sont pas tous nuls! :lol:
Les données que le programme lis sont en pièces-jointes (avec une petite description)..
Enfin, voici mon code:
Map.hpp
Cliquez pour révéler
Cliquez pour masquer
#ifndef MAP_HPP
#define MAP_HPP
#include "SwlFile.hpp"
#include "Fixture.hpp"
#include <QString>
#include <exception>
#include <ostream>
#include <vector>
class Map
{
public:
Map(){
}
Map(QString const &path){
QFile file(path);
try{
if(!file.open(QIODevice::ReadOnly)){
throw QString("Mauvais path de fichier! Pointeur *_swlFile vide!");
}
_swlFile = new Swlfile(file);
}
catch(QString const& error){
std::cerr << error.toStdString() << std::endl;
}
_swlFile->unCompress();
try{
_header = _swlFile->readByte();
if(_header != 77)
throw QString("Header different de 77!");
_mapVersion = _swlFile->readByte();
_mapID = _swlFile->readUInt32();
if(_mapVersion >= 7){
_encrypted = _swlFile->readBool();
_encryptionVersion = _swlFile->readByte();
_dataLen = _swlFile->readInt32();
if(_encrypted)
_swlFile->decrypt();
_relativeID = _swlFile->readUInt32();
_mapType = _swlFile->readByte();
_subAreaID = _swlFile->readInt32();
_topNeighbourId = _swlFile->readInt32();
_bottomNeighbourId = _swlFile->readInt32();
_leftNeighbourId = _swlFile->readInt32();
_rightNeighbourId = _swlFile->readInt32();
_shadowBonusOnEntities = _swlFile->readInt32();
}
//Juste pour voir les bits! Sinon ce bout de code est passé en commentaire
for(int i(1); i < 801; ++i){
std::cout << (int)_swlFile->readBool();
if(i%8 == 0 && i%(8*9)!=0)
std::cout << " ";
//Fin partie "débug"
}
if(_mapVersion >= 3){
_backGroundRed = _swlFile->readByte();
_backGroundGreen = _swlFile->readByte();
_backGroundBlue = _swlFile->readByte();
_backGroundColor = (_backGroundRed & 255) << 16 | (_backGroundGreen & 255) << 8 | (_backGroundBlue & 255);
}
if(_mapVersion >= 4){
_zoomScale = ((double)_swlFile->readUShort())/((double)100);
_zoomOffsetX = _swlFile->readShort();
_zoomOffsetY = _swlFile->readShort();
if(_zoomScale < 1){
_zoomScale = 1;
_zoomOffsetX = _zoomOffsetY = 0;
}
}
_useLowPassFilter = (_swlFile->readByte() == 1);
_useReverb = (_swlFile->readByte() == 1);
if(_useReverb)
_presetID = _swlFile->readInt32();
else
_presetID = -1;
_backgroundsCount = _swlFile->readByte();
for(int i(0); i < _backgroundsCount; ++i){
Fixture buffer(_swlFile);
buffer.initialiser();
_backgroundFixtures.push_back(buffer);
}
std::cout << "Header = " << (int)_header << std::endl << "mapVersion = " << (int)_mapVersion << std::endl
<< "mapID = " << _mapID << std::endl << "Encrypted? " << _encrypted << std::endl
<< "encryptionVersion = " << (int)_encryptionVersion << std::endl << "dataLen = " << _dataLen
<< std::endl << "relativeID = " << _relativeID << std::endl << "mapType = " << (int)_mapType
<< std::endl << "subAreaID = " << _subAreaID << std::endl << "topNeigbourID = " << _topNeighbourId
<< std::endl << "bottomNeighbourID = " << _bottomNeighbourId << std::endl << "leftNeighbourId = "
<< _leftNeighbourId << std::endl << "rightNeighbourId = " << _rightNeighbourId << std::endl
<< "shadowBonusOnEntities = " << _shadowBonusOnEntities << std::endl << "backgroundRed = "
<< (int)_backGroundRed << std::endl << "backgroundGreen = " << (int)_backGroundGreen << std::endl
<< "backgroundBlue = " << (int)_backGroundBlue << std::endl << "backgroundColor = "
<< (int)_backGroundColor << std::endl << "zoomScale = " << _zoomScale << std::endl
<< "zoomOffsetX = " << _zoomOffsetX << std::endl << "zoomOffsetY = " << _zoomOffsetY << std::endl
<< "useLowPassFilter = " << _useLowPassFilter << std::endl << "useReverb = " << _useReverb
<< std::endl << "presetID = " << _presetID << std::endl << "backgroundsCount = "
<< (int)_backgroundsCount << std::endl;
}
catch (QString const& error){
std::cerr << error.toStdString() << std::endl;
}
file.close();
}
private:
Swlfile *_swlFile;
//Caracteristiques!
qint8 _header;
qint8 _mapVersion;
quint32 _mapID;
bool _encrypted;
qint8 _encryptionVersion;
qint32 _dataLen;
quint32 _relativeID;
qint8 _mapType;
qint32 _subAreaID;
qint32 _topNeighbourId;
qint32 _bottomNeighbourId;
qint32 _leftNeighbourId;
qint32 _rightNeighbourId;
qint32 _shadowBonusOnEntities;
qint8 _backGroundRed;
qint8 _backGroundGreen;
qint8 _backGroundBlue;
qint8 _backGroundColor;
qreal _zoomScale;
qint16 _zoomOffsetX;
qint16 _zoomOffsetY;
bool _useLowPassFilter;
bool _useReverb;
qint32 _presetID;
qint8 _backgroundsCount;
std::vector<Fixture> _backgroundFixtures;
};
#endif // MAP_HPP
SwlFile.hpp
Cliquez pour révéler
Cliquez pour masquer
#ifndef SWLFILE_HPP
#define SWLFILE_HPP
#include <iostream>
#include <QFile>
#include <QDataStream>
#include <QByteArray>
class Swlfile
{
public:
Swlfile();
Swlfile(QFile &file): _swlFile(file.readAll()),
_fileDataStream(new QDataStream(_swlFile)),
_decrypted(false),
_uncompressed(false)
{
}
~Swlfile(){
delete _fileDataStream;
}
bool end(){
return _fileDataStream->atEnd();
}
template <typename T>
T read(T &value){
*_fileDataStream >> value;
return value;
}
bool readBool(){
bool retour;
return read(retour);
}
qint8 readByte(){
qint8 retour;
return read(retour);
}
quint8 readUByte(){
quint8 retour;
return read(retour);
}
qint16 readShort(){
qint16 retour;
return read(retour);
}
quint16 readUShort(){
quint16 retour;
return read(retour);
}
quint32 readUInt32(){
quint32 retour;
return read(retour);
}
qint32 readInt32(){
qint32 retour;
return read(retour);
}
void unCompress(){
if(_uncompressed)
return;
qint32 swlFileSize(_swlFile.size());
char sizeBytes[sizeof (int)];
memcpy(sizeBytes, &swlFileSize, sizeof(int));
for(int i(0); i < 4; ++i){
_swlFile.insert(0, sizeBytes);
}
_swlFile = qUncompress(_swlFile);
_uncompressed = true;
delete _fileDataStream;
_fileDataStream = new QDataStream(_swlFile);
}
void decrypt(){
if(_decrypted)
return;
const QByteArray decryptionKey("649ae451ca33ec53bbcbcc33becf15f4");
qint8 buffer;
for(int i(0); i < _swlFile.size(); ++i){
*_fileDataStream >> buffer;
_swlFile = buffer^decryptionKey[i%decryptionKey.size()];
}
_decrypted = true;
delete _fileDataStream;
_fileDataStream = new QDataStream(_swlFile);
}
private:
bool _uncompressed;
bool _decrypted;
QByteArray _swlFile;
QDataStream *_fileDataStream;
};
#endif // SWLFILE_HPP
Voila voila.. Merci d'avance pour vos réponses, et bonne journée :)