Switch to using templates.

master
sigonasr2 1 year ago
parent d5f7cf205d
commit a8eb9356c4
  1. BIN
      SHNFileDecryptor/AbState.shn
  2. 78
      SHNFileDecryptor/SHNFileDecryptor.cpp

Binary file not shown.

@ -181,93 +181,77 @@ class SHNFile{
int type=0;
Data(byte b){
std::shared_ptr<byte>ptr=std::make_shared<byte>(byte(b));
data=std::static_pointer_cast<byte>(ptr);
data=ptr;
type=1;
}
Data(sbyte b){
std::shared_ptr<sbyte>ptr=std::make_shared<sbyte>(sbyte(b));
data=std::static_pointer_cast<sbyte>(ptr);
data=ptr;
type=7;
}
Data(uint16_t n){
std::shared_ptr<uint16_t>ptr=std::make_shared<uint16_t>(uint16_t(n));
data=std::static_pointer_cast<uint16_t>(ptr);
data=ptr;
type=2;
}
Data(int16_t n){
std::shared_ptr<int16_t>ptr=std::make_shared<int16_t>(int16_t(n));
data=std::static_pointer_cast<int16_t>(ptr);
data=ptr;
type=6;
}
Data(uint32_t n){
std::shared_ptr<uint32_t>ptr=std::make_shared<uint32_t>(uint32_t(n));
data=std::static_pointer_cast<uint32_t>(ptr);
data=ptr;
type=3;
}
Data(int32_t n){
std::shared_ptr<int32_t>ptr=std::make_shared<int32_t>(int32_t(n));
data=std::static_pointer_cast<int32_t>(ptr);
data=ptr;
type=8;
}
Data(float n){
std::shared_ptr<float>ptr=std::make_shared<float>(float(n));
data=std::static_pointer_cast<float>(ptr);
data=ptr;
type=4;
}
Data(std::string str){
std::shared_ptr<std::string>ptr=std::make_shared<std::string>(str);
data=std::static_pointer_cast<std::string>(ptr);
data=ptr;
type=5;
}
byte GetByte(){
return *std::static_pointer_cast<byte>(data);
template <typename T>
T Get(){
return *std::static_pointer_cast<T>(data);
}
uint16_t GetUInt16(){
return *std::static_pointer_cast<uint16_t>(data);
}
int16_t GetInt16(){
return *std::static_pointer_cast<int16_t>(data);
}
sbyte GetSByte(){
return *std::static_pointer_cast<sbyte>(data);
}
uint32_t GetUInt32(){
return *std::static_pointer_cast<uint32_t>(data);
}
int32_t GetInt32(){
return *std::static_pointer_cast<int32_t>(data);
}
float GetFloat(){
return *std::static_pointer_cast<float>(data);
}
std::string GetString(){
return *std::static_pointer_cast<std::string>(data);
template<typename T>
void Set(T b){
data=std::make_shared<T>(T(b));
}
std::string GetDisplayText(){
switch(type){
case 1:{
return std::to_string(int(GetByte()));
return std::to_string(int(Get<byte>()));
}break;
case 7:{
return std::to_string(int(GetSByte()));
return std::to_string(int(Get<sbyte>()));
}break;
case 2:{
return std::to_string(GetUInt16());
return std::to_string(Get<uint16_t>());
}break;
case 6:{
return std::to_string(GetInt16());
return std::to_string(Get<int16_t>());
}break;
case 3:{
return std::to_string(GetUInt32());
return std::to_string(Get<uint32_t>());
}break;
case 8:{
return std::to_string(GetInt32());
return std::to_string(Get<int32_t>());
}break;
case 4:{
return std::to_string(GetFloat());
return std::to_string(Get<float>());
}break;
case 5:{
return GetString();
return Get<std::string>();
}break;
}
}
@ -404,36 +388,36 @@ public:
case 1:
case 12:
case 0x10:{
WriteByte(f,col.GetByte());
WriteByte(f,col.Get<byte>());
}break;
case 2:{
WriteUInt16(f,col.GetUInt16());
WriteUInt16(f,col.Get<uint16_t>());
}break;
case 3:
case 11:
case 0x12:
case 0x1b:{
WriteUInt32(f,col.GetUInt32());
WriteUInt32(f,col.Get<uint32_t>());
}break;
case 5:{
WriteSingle(f,col.GetFloat());
WriteSingle(f,col.Get<float>());
}break;
case 9:
case 0x18:{
WriteString(f,col.GetString(),columns[colNum].length);
WriteString(f,col.Get<std::string>(),columns[colNum].length);
}break;
case 13:
case 0x15:{
WriteInt16(f,col.GetInt16());
WriteInt16(f,col.Get<uint16_t>());
}break;
case 20:{
WriteSByte(f,col.GetSByte());
WriteSByte(f,col.Get<sbyte>());
}break;
case 0x16:{
WriteInt32(f,col.GetInt32());
WriteInt32(f,col.Get<int32_t>());
}break;
case 0x1a:{
WriteString(f,col.GetString(),-1);
WriteString(f,col.Get<std::string>(),-1);
}break;
}
colNum++;

Loading…
Cancel
Save