From a8eb9356c4e1059357a49eb9ac3c8c3d0f154e5d Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Fri, 4 Aug 2023 04:44:40 -0500 Subject: [PATCH] Switch to using templates. --- SHNFileDecryptor/AbState.shn | Bin 227224 -> 227224 bytes SHNFileDecryptor/SHNFileDecryptor.cpp | 78 ++++++++++---------------- 2 files changed, 31 insertions(+), 47 deletions(-) diff --git a/SHNFileDecryptor/AbState.shn b/SHNFileDecryptor/AbState.shn index 0841484c05ff4ee7263d3e9c3e804e64f627a20f..49c9c463c26aac034c18ce1c04459e08a8512cf1 100644 GIT binary patch delta 42 xcmbR7o_EH3-VF&X-1C3-eAwNye9P)J@sqQ6&2Q#nZRcWT1Y)M`T&&D}MF6}45tRS{ delta 43 zcmbR7o_EH3-VF&XJTqR*yMFK2p<^!(8y=jTvuj>67i&8gDptr=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++;