mirror of
https://github.com/libAthena/athena.git
synced 2025-12-16 00:17:05 +00:00
lots of new 'atdna' types; travis update
This commit is contained in:
@@ -1,18 +1,3 @@
|
||||
// This file is part of libAthena.
|
||||
//
|
||||
// libAthena is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// libAthena is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with libAthena. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
#include "Athena/Checksums.hpp"
|
||||
#include "Athena/FileReader.hpp"
|
||||
#include <iostream>
|
||||
|
||||
@@ -1,18 +1,3 @@
|
||||
// This file is part of libAthena.
|
||||
//
|
||||
// libAthena is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// libAthena is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with libAthena. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
#include "Athena/Compression.hpp"
|
||||
#include "Athena/Exception.hpp"
|
||||
#include <lzo/lzo1x.h>
|
||||
|
||||
@@ -1,18 +1,3 @@
|
||||
// This file is part of libAthena.
|
||||
//
|
||||
// libAthena is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// libAthena is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with libAthena. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
#include "Athena/FileReader.hpp"
|
||||
#include "Athena/FileNotFoundException.hpp"
|
||||
#include "Athena/InvalidDataException.hpp"
|
||||
@@ -316,9 +301,48 @@ bool FileReader::readBool()
|
||||
return (readByte() != 0);
|
||||
}
|
||||
|
||||
atVec3f FileReader::readVec3f()
|
||||
{
|
||||
if (!isOpen())
|
||||
THROW_INVALID_OPERATION_EXCEPTION_RETURN({}, "File not open for reading");
|
||||
|
||||
m_bitValid = false;
|
||||
atVec3f val = {};
|
||||
fread(&val, 1, 12, m_fileHandle);
|
||||
|
||||
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
||||
{
|
||||
val.vec[0] = utility::swapFloat(val.vec[0]);
|
||||
val.vec[1] = utility::swapFloat(val.vec[1]);
|
||||
val.vec[2] = utility::swapFloat(val.vec[2]);
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
atVec4f FileReader::readVec4f()
|
||||
{
|
||||
if (!isOpen())
|
||||
THROW_INVALID_OPERATION_EXCEPTION_RETURN({}, "File not open for reading");
|
||||
|
||||
m_bitValid = false;
|
||||
atVec4f val = {};
|
||||
fread(&val, 1, 16, m_fileHandle);
|
||||
|
||||
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
||||
{
|
||||
val.vec[0] = utility::swapFloat(val.vec[0]);
|
||||
val.vec[1] = utility::swapFloat(val.vec[1]);
|
||||
val.vec[2] = utility::swapFloat(val.vec[2]);
|
||||
val.vec[3] = utility::swapFloat(val.vec[3]);
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
std::string FileReader::readString(atInt32 maxlen)
|
||||
{
|
||||
std::string ret = "";
|
||||
std::string ret;
|
||||
atUint8 chr = readByte();
|
||||
|
||||
atInt32 i = 0;
|
||||
@@ -336,6 +360,26 @@ std::string FileReader::readString(atInt32 maxlen)
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::wstring FileReader::readWString(atInt32 maxlen)
|
||||
{
|
||||
std::wstring ret;
|
||||
atUint16 chr = readUint16();
|
||||
|
||||
atInt32 i = 0;
|
||||
|
||||
while (chr != 0)
|
||||
{
|
||||
if (maxlen >= 0 && i >= maxlen - 1)
|
||||
break;
|
||||
|
||||
ret += chr;
|
||||
chr = readUint16();
|
||||
i++;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string FileReader::readUnicode(atInt32 maxlen)
|
||||
{
|
||||
if (!isOpen())
|
||||
|
||||
@@ -1,18 +1,3 @@
|
||||
// This file is part of libAthena.
|
||||
//
|
||||
// libAthena is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// libAthena is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with libAthena. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
#include "Athena/FileWriter.hpp"
|
||||
#include "Athena/FileNotFoundException.hpp"
|
||||
#include "Athena/InvalidDataException.hpp"
|
||||
@@ -276,6 +261,43 @@ void FileWriter::writeBool(bool val)
|
||||
writeByte(val);
|
||||
}
|
||||
|
||||
void FileWriter::writeVec3f(atVec3f vec)
|
||||
{
|
||||
if (!isOpen())
|
||||
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
|
||||
|
||||
m_bitValid = false;
|
||||
|
||||
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
||||
{
|
||||
vec.vec[0] = utility::swapFloat(vec.vec[0]);
|
||||
vec.vec[1] = utility::swapFloat(vec.vec[1]);
|
||||
vec.vec[2] = utility::swapFloat(vec.vec[2]);
|
||||
}
|
||||
|
||||
if (fwrite(&vec, 1, 12, m_fileHandle) != 12)
|
||||
THROW_IO_EXCEPTION("Unable to write to stream");
|
||||
}
|
||||
|
||||
void FileWriter::writeVec4f(atVec4f vec)
|
||||
{
|
||||
if (!isOpen())
|
||||
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
|
||||
|
||||
m_bitValid = false;
|
||||
|
||||
if ((!utility::isSystemBigEndian() && isBigEndian()) || (utility::isSystemBigEndian() && isLittleEndian()))
|
||||
{
|
||||
vec.vec[0] = utility::swapFloat(vec.vec[0]);
|
||||
vec.vec[1] = utility::swapFloat(vec.vec[1]);
|
||||
vec.vec[2] = utility::swapFloat(vec.vec[2]);
|
||||
vec.vec[3] = utility::swapFloat(vec.vec[3]);
|
||||
}
|
||||
|
||||
if (fwrite(&vec, 1, 16, m_fileHandle) != 16)
|
||||
THROW_IO_EXCEPTION("Unable to write to stream");
|
||||
}
|
||||
|
||||
void FileWriter::writeString(const std::string& val)
|
||||
{
|
||||
if (!isOpen())
|
||||
@@ -292,6 +314,22 @@ void FileWriter::writeString(const std::string& val)
|
||||
THROW_IO_EXCEPTION("Unable to write to stream");
|
||||
}
|
||||
|
||||
void FileWriter::writeWString(const std::wstring& val)
|
||||
{
|
||||
if (!isOpen())
|
||||
THROW_INVALID_OPERATION_EXCEPTION("File not open for writing");
|
||||
|
||||
m_bitValid = false;
|
||||
|
||||
wchar_t term = L'\0';
|
||||
|
||||
if (fwrite(val.c_str(), 2, val.length(), m_fileHandle) != val.length())
|
||||
THROW_IO_EXCEPTION("Unable to write to stream");
|
||||
|
||||
if (fwrite(&term, 2, 1, m_fileHandle) != 1)
|
||||
THROW_IO_EXCEPTION("Unable to write to stream");
|
||||
}
|
||||
|
||||
void FileWriter::writeUnicode(const std::string& str)
|
||||
{
|
||||
if (!isOpen())
|
||||
|
||||
@@ -1,18 +1,3 @@
|
||||
// This file is part of libAthena.
|
||||
//
|
||||
// libAthena is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// libAthena is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with libAthena. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
#include "Athena/Global.hpp"
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const Athena::SeekOrigin& origin)
|
||||
|
||||
@@ -1,18 +1,3 @@
|
||||
// This file is part of libAthena.
|
||||
//
|
||||
// libAthena is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// libAthena is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with libAthena. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
#include "Athena/MemoryReader.hpp"
|
||||
#include "Athena/IOException.hpp"
|
||||
#include "Athena/FileNotFoundException.hpp"
|
||||
@@ -434,6 +419,74 @@ bool MemoryReader::readBool()
|
||||
return ret;
|
||||
}
|
||||
|
||||
atVec3f MemoryReader::readVec3f()
|
||||
{
|
||||
if (!m_data)
|
||||
loadData();
|
||||
|
||||
if (m_bitPosition > 0)
|
||||
{
|
||||
m_bitPosition = 0;
|
||||
m_position += sizeof(atUint8);
|
||||
}
|
||||
|
||||
if (m_position + 12 > m_length)
|
||||
THROW_IO_EXCEPTION_RETURN({}, "Position %0.8X outside stream bounds ", m_position);
|
||||
|
||||
float* source = (float*)(m_data + m_position);
|
||||
atVec3f result = {source[0], source[1], source[2]};
|
||||
if (isBigEndian())
|
||||
{
|
||||
utility::BigFloat(result.vec[0]);
|
||||
utility::BigFloat(result.vec[1]);
|
||||
utility::BigFloat(result.vec[2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
utility::LittleFloat(result.vec[0]);
|
||||
utility::LittleFloat(result.vec[1]);
|
||||
utility::LittleFloat(result.vec[2]);
|
||||
}
|
||||
|
||||
m_position += 12;
|
||||
return result;
|
||||
}
|
||||
|
||||
atVec4f MemoryReader::readVec4f()
|
||||
{
|
||||
if (!m_data)
|
||||
loadData();
|
||||
|
||||
if (m_bitPosition > 0)
|
||||
{
|
||||
m_bitPosition = 0;
|
||||
m_position += sizeof(atUint8);
|
||||
}
|
||||
|
||||
if (m_position + 16 > m_length)
|
||||
THROW_IO_EXCEPTION_RETURN({}, "Position %0.8X outside stream bounds ", m_position);
|
||||
|
||||
float* source = (float*)(m_data + m_position);
|
||||
atVec4f result = {source[0], source[1], source[2], source[3]};
|
||||
if (isBigEndian())
|
||||
{
|
||||
utility::BigFloat(result.vec[0]);
|
||||
utility::BigFloat(result.vec[1]);
|
||||
utility::BigFloat(result.vec[2]);
|
||||
utility::BigFloat(result.vec[3]);
|
||||
}
|
||||
else
|
||||
{
|
||||
utility::LittleFloat(result.vec[0]);
|
||||
utility::LittleFloat(result.vec[1]);
|
||||
utility::LittleFloat(result.vec[2]);
|
||||
utility::LittleFloat(result.vec[3]);
|
||||
}
|
||||
|
||||
m_position += 16;
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string MemoryReader::readUnicode(atInt32 maxlen)
|
||||
{
|
||||
if (!m_data)
|
||||
@@ -464,7 +517,7 @@ std::string MemoryReader::readUnicode(atInt32 maxlen)
|
||||
|
||||
std::string MemoryReader::readString(atInt32 maxlen)
|
||||
{
|
||||
std::string ret = "";
|
||||
std::string ret;
|
||||
atUint8 chr = readByte();
|
||||
|
||||
atInt32 i = 0;
|
||||
@@ -482,6 +535,26 @@ std::string MemoryReader::readString(atInt32 maxlen)
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::wstring MemoryReader::readWString(atInt32 maxlen)
|
||||
{
|
||||
std::wstring ret;
|
||||
atUint16 chr = readUint16();
|
||||
|
||||
atInt32 i = 0;
|
||||
|
||||
while (chr != 0)
|
||||
{
|
||||
if (maxlen >= 0 && i >= maxlen - 1)
|
||||
break;
|
||||
|
||||
ret += chr;
|
||||
chr = readUint16();
|
||||
i++;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void MemoryReader::setProgressCallback(std::function<void (int)> cb)
|
||||
{
|
||||
m_progressCallback = cb;
|
||||
|
||||
@@ -1,18 +1,3 @@
|
||||
// This file is part of libAthena.
|
||||
//
|
||||
// libAthena is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// libAthena is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with libAthena. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
#include "Athena/MemoryWriter.hpp"
|
||||
#include "Athena/IOException.hpp"
|
||||
#include "Athena/InvalidOperationException.hpp"
|
||||
@@ -443,6 +428,75 @@ void MemoryWriter::writeBool(bool val)
|
||||
m_position += sizeof(bool);
|
||||
}
|
||||
|
||||
void MemoryWriter::writeVec3f(atVec3f vec)
|
||||
{
|
||||
if (!isOpen())
|
||||
resize(12);
|
||||
|
||||
if (m_bitPosition > 0)
|
||||
{
|
||||
m_bitPosition = 0;
|
||||
m_position += sizeof(atUint8);
|
||||
}
|
||||
|
||||
if (m_position + 12 > m_length)
|
||||
resize(m_position + 12);
|
||||
|
||||
if (isBigEndian())
|
||||
{
|
||||
utility::BigFloat(vec.vec[0]);
|
||||
utility::BigFloat(vec.vec[1]);
|
||||
utility::BigFloat(vec.vec[2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
utility::LittleFloat(vec.vec[0]);
|
||||
utility::LittleFloat(vec.vec[1]);
|
||||
utility::LittleFloat(vec.vec[2]);
|
||||
}
|
||||
|
||||
((float*)(m_data + m_position))[0] = vec.vec[0];
|
||||
((float*)(m_data + m_position))[1] = vec.vec[1];
|
||||
((float*)(m_data + m_position))[2] = vec.vec[2];
|
||||
m_position += 12;
|
||||
}
|
||||
|
||||
void MemoryWriter::writeVec4f(atVec4f vec)
|
||||
{
|
||||
if (!isOpen())
|
||||
resize(16);
|
||||
|
||||
if (m_bitPosition > 0)
|
||||
{
|
||||
m_bitPosition = 0;
|
||||
m_position += sizeof(atUint8);
|
||||
}
|
||||
|
||||
if (m_position + 16 > m_length)
|
||||
resize(m_position + 16);
|
||||
|
||||
if (isBigEndian())
|
||||
{
|
||||
utility::BigFloat(vec.vec[0]);
|
||||
utility::BigFloat(vec.vec[1]);
|
||||
utility::BigFloat(vec.vec[2]);
|
||||
utility::BigFloat(vec.vec[3]);
|
||||
}
|
||||
else
|
||||
{
|
||||
utility::LittleFloat(vec.vec[0]);
|
||||
utility::LittleFloat(vec.vec[1]);
|
||||
utility::LittleFloat(vec.vec[2]);
|
||||
utility::LittleFloat(vec.vec[3]);
|
||||
}
|
||||
|
||||
((float*)(m_data + m_position))[0] = vec.vec[0];
|
||||
((float*)(m_data + m_position))[1] = vec.vec[1];
|
||||
((float*)(m_data + m_position))[2] = vec.vec[2];
|
||||
((float*)(m_data + m_position))[3] = vec.vec[3];
|
||||
m_position += 16;
|
||||
}
|
||||
|
||||
void MemoryWriter::writeUnicode(const std::string& str)
|
||||
{
|
||||
std::string tmpStr = "\xEF\xBB\xBF" + str;
|
||||
@@ -473,6 +527,19 @@ void MemoryWriter::writeString(const std::string& str)
|
||||
writeUByte(0);
|
||||
}
|
||||
|
||||
void MemoryWriter::writeWString(const std::wstring& str)
|
||||
{
|
||||
for (atUint16 c : str)
|
||||
{
|
||||
writeUint16(c);
|
||||
|
||||
if (c == L'\0')
|
||||
break;
|
||||
}
|
||||
|
||||
writeUint16(0);
|
||||
}
|
||||
|
||||
void MemoryWriter::fill(atUint8 val, atUint64 length)
|
||||
{
|
||||
while ((length--) > 0)
|
||||
|
||||
@@ -1,19 +1,4 @@
|
||||
// This file is part of libAthena.
|
||||
//
|
||||
// libAthena is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// libAthena is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with libAthena. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
#include "Athena/Utility.hpp"
|
||||
#include "Athena/Utility.hpp"
|
||||
#include <iostream>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
Reference in New Issue
Block a user