summaryrefslogtreecommitdiff
path: root/lib/binarytools
diff options
context:
space:
mode:
authorLywx <kiritodev01@gmail.com>2023-09-16 04:01:24 -0600
committerGitHub <noreply@github.com>2023-09-16 04:01:24 -0600
commitae8487a4adc5d6d33c47d41e3a40d3c67ddb1e45 (patch)
treee03627371fc7423c684631ed7eee68d697709e0f /lib/binarytools
parentf5cbd0056d601e4adaf5ed9006192dd510226ee3 (diff)
parent98b6d598324fdcb499a2cc4d37a7a6fcd19e8ead (diff)
Merge pull request #1 from KiritoDv/feature/audio
Implemented full audio extraction
Diffstat (limited to 'lib/binarytools')
-rw-r--r--lib/binarytools/BinaryReader.cpp31
-rw-r--r--lib/binarytools/BinaryReader.h3
-rw-r--r--lib/binarytools/BinaryWriter.cpp13
-rw-r--r--lib/binarytools/BinaryWriter.h3
4 files changed, 43 insertions, 7 deletions
diff --git a/lib/binarytools/BinaryReader.cpp b/lib/binarytools/BinaryReader.cpp
index 3aff001..f802885 100644
--- a/lib/binarytools/BinaryReader.cpp
+++ b/lib/binarytools/BinaryReader.cpp
@@ -2,6 +2,7 @@
#include "MemoryStream.h"
#include <cmath>
#include <stdexcept>
+#include <locale>
LUS::BinaryReader::BinaryReader(char* nBuffer, size_t nBufferSize) {
mStream = std::make_shared<MemoryStream>(nBuffer, nBufferSize);
@@ -57,7 +58,6 @@ int16_t LUS::BinaryReader::ReadInt16() {
if (mEndianness != Endianness::Native) {
result = BSWAP16(result);
}
-
return result;
}
@@ -113,6 +113,28 @@ uint64_t LUS::BinaryReader::ReadUInt64() {
return result;
}
+unsigned short LUS::BinaryReader::ReadUShort() {
+ unsigned short result = 0;
+ mStream->Read((char*)&result, sizeof(unsigned short));
+
+ if (mEndianness != Endianness::Native) {
+ result = BSWAP16(result);
+ }
+
+ return result;
+}
+
+short LUS::BinaryReader::ReadShort() {
+ short result = 0;
+ mStream->Read((char*)&result, sizeof(short));
+
+ if (mEndianness != Endianness::Native) {
+ result = BSWAP16(result);
+ }
+
+ return result;
+}
+
float LUS::BinaryReader::ReadFloat() {
float result = NAN;
@@ -169,6 +191,7 @@ std::string LUS::BinaryReader::ReadString() {
for (int i = 0; i < numChars; i++) {
res += ReadChar();
}
+
return res;
}
@@ -188,6 +211,10 @@ std::string LUS::BinaryReader::ReadCString() {
return res;
}
+size_t LUS::BinaryReader::GetLength() {
+ return mStream->GetLength();
+}
+
std::vector<char> LUS::BinaryReader::ToVector() {
return mStream->ToVector();
-}
+} \ No newline at end of file
diff --git a/lib/binarytools/BinaryReader.h b/lib/binarytools/BinaryReader.h
index 59eeb52..02e65cc 100644
--- a/lib/binarytools/BinaryReader.h
+++ b/lib/binarytools/BinaryReader.h
@@ -23,6 +23,7 @@ class BinaryReader {
void Seek(int32_t offset, SeekOffsetType seekType);
uint32_t GetBaseAddress();
+ size_t GetLength();
void Read(int32_t length);
void Read(char* buffer, int32_t length);
@@ -34,6 +35,8 @@ class BinaryReader {
uint16_t ReadUInt16();
uint32_t ReadUInt32();
uint64_t ReadUInt64();
+ unsigned short ReadUShort();
+ short ReadShort();
float ReadFloat();
double ReadDouble();
std::string ReadString();
diff --git a/lib/binarytools/BinaryWriter.cpp b/lib/binarytools/BinaryWriter.cpp
index 362824f..6e0140f 100644
--- a/lib/binarytools/BinaryWriter.cpp
+++ b/lib/binarytools/BinaryWriter.cpp
@@ -132,10 +132,11 @@ void LUS::BinaryWriter::Write(double value) {
mStream->Write((char*)&value, sizeof(double));
}
-void LUS::BinaryWriter::Write(const std::string& str) {
- int strLen = str.size();
- Write(strLen);
-
+void LUS::BinaryWriter::Write(const std::string& str, bool writeLength) {
+ if(writeLength){
+ int strLen = str.size();
+ Write(strLen);
+ }
for (char c : str) {
mStream->WriteByte(c);
}
@@ -145,6 +146,10 @@ void LUS::BinaryWriter::Write(char* srcBuffer, size_t length) {
mStream->Write(srcBuffer, length);
}
+void LUS::BinaryWriter::WriteByte(char value) {
+ mStream->WriteByte(value);
+}
+
std::vector<char> LUS::BinaryWriter::ToVector() {
return mStream->ToVector();
}
diff --git a/lib/binarytools/BinaryWriter.h b/lib/binarytools/BinaryWriter.h
index fbd4f65..dca683f 100644
--- a/lib/binarytools/BinaryWriter.h
+++ b/lib/binarytools/BinaryWriter.h
@@ -33,8 +33,9 @@ class BinaryWriter {
void Write(uint64_t value);
void Write(float value);
void Write(double value);
- void Write(const std::string& str);
+ void Write(const std::string& str, bool writeLength = true);
void Write(char* srcBuffer, size_t length);
+ void WriteByte(char value);
std::vector<char> ToVector();