diff --git a/SHNFileDecryptor/AbState.shn b/SHNFileDecryptor/AbState.shn index 0841484..49c9c46 100644 Binary files a/SHNFileDecryptor/AbState.shn and b/SHNFileDecryptor/AbState.shn differ diff --git a/SHNFileDecryptor/SHNFileDecryptor.cpp b/SHNFileDecryptor/SHNFileDecryptor.cpp index 76bf140..f669827 100644 --- a/SHNFileDecryptor/SHNFileDecryptor.cpp +++ b/SHNFileDecryptor/SHNFileDecryptor.cpp @@ -181,93 +181,77 @@ class SHNFile{ int type=0; Data(byte b){ std::shared_ptrptr=std::make_shared(byte(b)); - data=std::static_pointer_cast(ptr); + data=ptr; type=1; } Data(sbyte b){ std::shared_ptrptr=std::make_shared(sbyte(b)); - data=std::static_pointer_cast(ptr); + data=ptr; type=7; } Data(uint16_t n){ std::shared_ptrptr=std::make_shared(uint16_t(n)); - data=std::static_pointer_cast(ptr); + data=ptr; type=2; } Data(int16_t n){ std::shared_ptrptr=std::make_shared(int16_t(n)); - data=std::static_pointer_cast(ptr); + data=ptr; type=6; } Data(uint32_t n){ std::shared_ptrptr=std::make_shared(uint32_t(n)); - data=std::static_pointer_cast(ptr); + data=ptr; type=3; } Data(int32_t n){ std::shared_ptrptr=std::make_shared(int32_t(n)); - data=std::static_pointer_cast(ptr); + data=ptr; type=8; } Data(float n){ std::shared_ptrptr=std::make_shared(float(n)); - data=std::static_pointer_cast(ptr); + data=ptr; type=4; } Data(std::string str){ std::shared_ptrptr=std::make_shared(str); - data=std::static_pointer_cast(ptr); + data=ptr; type=5; } - byte GetByte(){ - return *std::static_pointer_cast(data); + template + T Get(){ + return *std::static_pointer_cast(data); } - uint16_t GetUInt16(){ - return *std::static_pointer_cast(data); - } - int16_t GetInt16(){ - return *std::static_pointer_cast(data); - } - sbyte GetSByte(){ - return *std::static_pointer_cast(data); - } - uint32_t GetUInt32(){ - return *std::static_pointer_cast(data); - } - int32_t GetInt32(){ - return *std::static_pointer_cast(data); - } - float GetFloat(){ - return *std::static_pointer_cast(data); - } - std::string GetString(){ - return *std::static_pointer_cast(data); + template + void Set(T b){ + data=std::make_shared(T(b)); } std::string GetDisplayText(){ switch(type){ case 1:{ - return std::to_string(int(GetByte())); + return std::to_string(int(Get())); }break; case 7:{ - return std::to_string(int(GetSByte())); + return std::to_string(int(Get())); }break; case 2:{ - return std::to_string(GetUInt16()); + return std::to_string(Get()); }break; case 6:{ - return std::to_string(GetInt16()); + return std::to_string(Get()); }break; case 3:{ - return std::to_string(GetUInt32()); + return std::to_string(Get()); }break; case 8:{ - return std::to_string(GetInt32()); + return std::to_string(Get()); }break; case 4:{ - return std::to_string(GetFloat()); + return std::to_string(Get()); }break; case 5:{ - return GetString(); + return Get(); }break; } } @@ -404,36 +388,36 @@ public: case 1: case 12: case 0x10:{ - WriteByte(f,col.GetByte()); + WriteByte(f,col.Get()); }break; case 2:{ - WriteUInt16(f,col.GetUInt16()); + WriteUInt16(f,col.Get()); }break; case 3: case 11: case 0x12: case 0x1b:{ - WriteUInt32(f,col.GetUInt32()); + WriteUInt32(f,col.Get()); }break; case 5:{ - WriteSingle(f,col.GetFloat()); + WriteSingle(f,col.Get()); }break; case 9: case 0x18:{ - WriteString(f,col.GetString(),columns[colNum].length); + WriteString(f,col.Get(),columns[colNum].length); }break; case 13: case 0x15:{ - WriteInt16(f,col.GetInt16()); + WriteInt16(f,col.Get()); }break; case 20:{ - WriteSByte(f,col.GetSByte()); + WriteSByte(f,col.Get()); }break; case 0x16:{ - WriteInt32(f,col.GetInt32()); + WriteInt32(f,col.Get()); }break; case 0x1a:{ - WriteString(f,col.GetString(),-1); + WriteString(f,col.Get(),-1); }break; } colNum++;