Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ typedef unsigned int uint;
const unsigned int GZIP_BUFFER_SIZE = 128;
const unsigned int WRITE_BUFFER_SIZE = 256;
const unsigned int MIN_TAG = 1;
const unsigned int MAX_TAG = 11;
const unsigned int MAX_TAG = 12;

typedef signed char jbyte;
typedef int16_t jshort;
Expand Down
8 changes: 7 additions & 1 deletion src/NBT/NBTHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace NBT {
tags[NbtList] = new NBTTagList();
tags[NbtCompound] = new NBTTagCompound();
tags[NbtIntArray] = new NBTTagIntArray();
tags[NbtLongArray] = new NBTTagLongArray();
return tags;
}();

Expand All @@ -38,6 +39,7 @@ namespace NBT {

template const NBTTagByteArray* NBTHelper::GetTag<NBTTagByteArray>(NBTType type);
template const NBTTagIntArray* NBTHelper::GetTag<NBTTagIntArray>(NBTType type);
template const NBTTagLongArray* NBTHelper::GetTag<NBTTagLongArray>(NBTType type);

const NBTTag** NBTHelper::GetAllTags() {
return tagsByType;
Expand Down Expand Up @@ -77,6 +79,10 @@ namespace NBT {
return GetTag<NBTTagIntArray>(NbtIntArray)->GetData(entry);
}

NBTArray<jlong>& NBTHelper::GetLongArray(NBTEntry& entry) {
return GetTag<NBTTagLongArray>(NbtLongArray)->GetData(entry);
}

void NBTHelper::SetDouble(NBTEntry& entry, jdouble value) {
GetTag<NBTTagDouble>(NbtDouble)->SetData(entry, value);
}
Expand All @@ -85,4 +91,4 @@ namespace NBT {
GetTag<NBTTagString>(NbtString)->SetData(entry, value);
}

}
}
3 changes: 2 additions & 1 deletion src/NBT/NBTHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace NBT {
static jdouble GetDouble(NBTEntry& entry);
static NBTArray<jbyte>& GetByteArray(NBTEntry& entry);
static NBTArray<jint>& GetIntArray(NBTEntry& entry);
static NBTArray<jlong>& GetLongArray(NBTEntry& entry);
static QString& GetString(NBTEntry& entry);
static NBTList& GetList(NBTEntry& entry);
static NBTCompound* GetCompound(NBTEntry& entry);
Expand All @@ -30,4 +31,4 @@ namespace NBT {
private:
static const NBTTag** tagsByType;
};
}
}
45 changes: 45 additions & 0 deletions src/NBT/NBTTag.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,51 @@ namespace NBT {
}
};

class NBTTagLongArray : public NBTTagBasic<NBTArray<jlong>> {
public:
NBTTagLongArray() : NBTTagBasic("nbt-array.png", "Long Array") {}

void* Read(ByteBuffer* buffer) const override {
jint length = buffer->ReadInt();
// TODO: Overflow check

long* array = new long[length];
for (jint i = 0; i < length; i++) {
array[i] = buffer->ReadLong();
}

return new NBTArray<jlong>(length, array);
}

void Write(WriteBuffer* buffer, NBTEntry& entry) const override {
NBTArray<jlong>& data = GetData(entry);
buffer->WriteInt(data.length);

for (uint i = 0; i < data.length; i++) {
buffer->WriteLong(data.array[i]);
}
}

void* CreateDefaultData() const override {
return new NBTArray<jlong>(0, new jlong[0]);
}

void SetData(NBTEntry& entry, NBTArray<jlong>& data) const override {
if (entry.value != NULL)
delete static_cast<NBTArray<jlong>*>(entry.value);
entry.value = &data;
}

QVariant GetQtData(NBTEntry& entry) const override {
return QString::number(GetData(entry).length) + QString(" longs");
}

bool SetQtData(NBTEntry&, const QVariant&) const override {
// Not possible
return false;
}
};

class NBTTagList : public NBTTagBasic<NBTList> {
public:
NBTTagList() : NBTTagBasic("nbt-list.png", "List") {}
Expand Down
3 changes: 2 additions & 1 deletion src/NBT/NBTType.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ namespace NBT {
NbtString = 8,
NbtList = 9,
NbtCompound = 10,
NbtIntArray = 11
NbtIntArray = 11,
NbtLongArray = 12
};

enum NBTFileType {
Expand Down
25 changes: 24 additions & 1 deletion src/UI/EditArrayDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace UI {

template void EditArrayDialog::setArray<jbyte>(NBT::NBTArray<jbyte>&);
template void EditArrayDialog::setArray<jint>(NBT::NBTArray<jint>&);
template void EditArrayDialog::setArray<jlong>(NBT::NBTArray<jlong>&);

NBT::NBTArray<jbyte>* EditArrayDialog::getResultByteArray() {
QString str = widget.plainTextEdit->toPlainText();
Expand Down Expand Up @@ -75,8 +76,30 @@ namespace UI {
return nbtArray;
}

NBT::NBTArray<jlong>* EditArrayDialog::getResultLongArray() {
QString str = widget.plainTextEdit->toPlainText();
QStringList list = str.split(" ", QString::SkipEmptyParts);

NBT::NBTArray<jlong>* nbtArray = new NBT::NBTArray<jlong>();
nbtArray->length = list.length();
nbtArray->array = new jlong[list.length()];

for (uint i = 0; i < nbtArray->length; i++) {
bool success = false;
jlong number = (sizeof(long) == 8) ? list[i].toLong(&success, 10) : list[i].toLongLong(&success, 10);
if (!success) {
delete nbtArray;
return NULL;
}

nbtArray->array[i] = number;
}

return nbtArray;
}

void EditArrayDialog::clickOk() {
accept();
}

}
}
3 changes: 2 additions & 1 deletion src/UI/EditArrayDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ namespace UI {

NBT::NBTArray<jbyte>* getResultByteArray();
NBT::NBTArray<jint>* getResultIntArray();
NBT::NBTArray<jlong>* getResultLongArray();

public slots:
void clickOk();

private:
Ui::EditArrayDialog widget;
};
}
}
20 changes: 16 additions & 4 deletions src/UI/TreeContextMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace UI {
if (item->nbtEntry->type == NbtCompound || item->nbtEntry->type == NbtList)
addToCompoundAction->setVisible(true);

if (item->nbtEntry->type == NbtByteArray || item->nbtEntry->type == NbtIntArray)
if (item->nbtEntry->type == NbtByteArray || item->nbtEntry->type == NbtIntArray || item->nbtEntry->type == NbtLongArray)
editAction->setVisible(true);
}

Expand All @@ -57,7 +57,7 @@ namespace UI {
if (item->nbtEntry == NULL)
return;

if (item->nbtEntry->type == NbtByteArray || item->nbtEntry->type == NbtIntArray)
if (item->nbtEntry->type == NbtByteArray || item->nbtEntry->type == NbtIntArray || item->nbtEntry->type == NbtLongArray)
editArray(index, item);
}

Expand Down Expand Up @@ -129,7 +129,7 @@ namespace UI {
if (item->nbtEntry == NULL)
return;

if (item->nbtEntry->type == NbtByteArray || item->nbtEntry->type == NbtIntArray)
if (item->nbtEntry->type == NbtByteArray || item->nbtEntry->type == NbtIntArray || item->nbtEntry->type == NbtLongArray)
editArray(index, item);
}

Expand Down Expand Up @@ -217,7 +217,19 @@ namespace UI {
NBTHelper::GetTag<NBTTagIntArray>(NbtIntArray)->SetData(*item->nbtEntry, *newArray);
GetModel()->UpdateItem(index);
}
} else if (item->nbtEntry->type == NbtLongArray) {
dialog.setArray(NBTHelper::GetLongArray(*item->nbtEntry));
if (dialog.exec() == QDialog::Accepted) {
NBT::NBTArray<jlong>* newArray = dialog.getResultLongArray();
if (newArray == NULL) {
QMessageBox::critical(form, tr("Invalid data"), tr("The input data is invalid.", ""), QMessageBox::Ok, QMessageBox::Ok);
return;
}

NBTHelper::GetTag<NBTTagLongArray>(NbtLongArray)->SetData(*item->nbtEntry, *newArray);
GetModel()->UpdateItem(index);
}
}
}

}
}