Update the way we get data so we don't have to do ridiculous static pointer casts and indirections.

master
sigonasr2 1 year ago
parent dded211294
commit bb3606adc8
  1. 18
      SHNFileDecryptor/SHNFileDecryptor.h
  2. 6
      SHNFileDecryptor/SHNFile_example.cpp

@ -12,7 +12,6 @@ typedef char sbyte;
class SHNFile{
SHNFile(const SHNFile&)=delete;
SHNFile(const SHNFile&&)=delete;
std::vector<std::byte>ReadBytes(std::ifstream&file);
std::vector<std::byte>ReadBytes(std::ifstream&file,int bytes);
void WriteBytes(std::ofstream&file,char*data,int length);
@ -99,8 +98,11 @@ public:
void Write(int row,int col,uint32_t val);
void Write(int row,int col,float val);
void Write(int row,int col,std::string val);
const SHNFile::Data Get(int row,int col)const;
//const SHNFile::Data Get(int row,int col)const;
template<typename T>
const T Get(int row,int col)const;
SHNFile();
SHNFile(SHNFile&&)noexcept;
~SHNFile();
};
#ifdef OLC_PGEX_SHNFile
@ -523,8 +525,9 @@ void SHNFile::Save(){
WriteBytes(encryptedFile,data,readAmt-0x24);
std::cout<<"File "<<filename<<" Saved!"<<std::endl;
}
const SHNFile::Data SHNFile::Get(int row,int col)const{
return contents[row][col];
template<typename T>
const T SHNFile::Get(int row,int col)const{
return *(std::static_pointer_cast<T>(contents[row][col].data));
};
void SHNFile::Write(int row,int col,std::byte val){
contents[row][col].Set<std::byte>(val);
@ -556,6 +559,13 @@ SHNFile::SHNFile(){
SHNFile::~SHNFile(){
Cleanup();
}
SHNFile::SHNFile(SHNFile&&temp)noexcept{
temp.cryptHeader=cryptHeader;
temp.data=data;
temp.rawData=rawData;
cryptHeader=data=rawData=nullptr;
}
void SHNFile::Cleanup(){
if(cryptHeader!=nullptr){
delete[] cryptHeader;

@ -8,6 +8,8 @@
int main(){
SHNFile shn3;
shn3.Load("ItemViewInfo.shn");
shn3.Write(3,2,14);
shn3.Save();
SHNFile shn4((SHNFile&&)shn3);
uint32_t test=shn3.Get<uint32_t>(3,2);
//shn3.Write(3,2,14);
//shn3.Save();
}
Loading…
Cancel
Save