Fix compatibility with gdiplus, which also defines byte. Use std::byte instead.
This commit is contained in:
parent
05f8c90ec0
commit
e516dbf65a
@ -6,19 +6,19 @@
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
|
||||
typedef std::byte byte;
|
||||
//typedef std::std::byte std::byte;
|
||||
typedef char sbyte;
|
||||
|
||||
class SHNFile{
|
||||
std::vector<byte>ReadBytes(std::ifstream&file);
|
||||
std::vector<byte>ReadBytes(std::ifstream&file,int bytes);
|
||||
void WriteBytes(std::ofstream&file,std::vector<byte>&data);
|
||||
std::vector<std::byte>ReadBytes(std::ifstream&file);
|
||||
std::vector<std::byte>ReadBytes(std::ifstream&file,int bytes);
|
||||
void WriteBytes(std::ofstream&file,std::vector<std::byte>&data);
|
||||
int ReadInt32(std::ifstream&file);
|
||||
void Encrypt();
|
||||
void Decrypt();
|
||||
std::vector<byte>ReadBytes(int bytes);
|
||||
byte ReadByte();
|
||||
void WriteByte(std::ofstream&f,byte b);
|
||||
std::vector<std::byte>ReadBytes(int bytes);
|
||||
std::byte ReadByte();
|
||||
void WriteByte(std::ofstream&f,std::byte b);
|
||||
void WriteSByte(std::ofstream&f,sbyte b);
|
||||
uint16_t ReadUInt16();
|
||||
void WriteUInt16(std::ofstream&f,uint16_t val);
|
||||
@ -50,7 +50,7 @@ public:
|
||||
struct Data{
|
||||
std::shared_ptr<void>data;
|
||||
DataType type=DataType::BYTE;
|
||||
Data(byte b);
|
||||
Data(std::byte b);
|
||||
Data(sbyte b);
|
||||
Data(uint16_t n);
|
||||
Data(int16_t n);
|
||||
@ -75,8 +75,8 @@ private:
|
||||
int length=0;
|
||||
};
|
||||
int marker=0;
|
||||
std::vector<byte>cryptHeader;
|
||||
std::vector<byte>data,rawData;
|
||||
std::vector<std::byte>cryptHeader;
|
||||
std::vector<std::byte>data,rawData;
|
||||
uint32_t header=0,recordCount=0,defaultRecordLength=0,columnCount=0;
|
||||
std::vector<Column>columns;
|
||||
std::vector<std::vector<Data>>contents;
|
||||
@ -84,7 +84,7 @@ private:
|
||||
public:
|
||||
void Load(std::string file);
|
||||
void Save();
|
||||
void Write(int row,int col,byte val);
|
||||
void Write(int row,int col,std::byte val);
|
||||
void Write(int row,int col,sbyte val);
|
||||
void Write(int row,int col,int16_t val);
|
||||
void Write(int row,int col,uint16_t val);
|
||||
@ -96,31 +96,31 @@ public:
|
||||
SHNFile();
|
||||
};
|
||||
#ifdef OLC_PGEX_SHNFile
|
||||
std::vector<byte>SHNFile::ReadBytes(std::ifstream&file){
|
||||
std::vector<byte>byteArr;
|
||||
std::vector<std::byte>SHNFile::ReadBytes(std::ifstream&file){
|
||||
std::vector<std::byte>byteArr;
|
||||
while(!file.eof()){
|
||||
byteArr.push_back(byte(file.get()));
|
||||
byteArr.push_back(std::byte(file.get()));
|
||||
}
|
||||
return byteArr;
|
||||
}
|
||||
std::vector<byte>SHNFile::ReadBytes(std::ifstream&file,int bytes){
|
||||
std::vector<byte>byteArr;
|
||||
std::vector<std::byte>SHNFile::ReadBytes(std::ifstream&file,int bytes){
|
||||
std::vector<std::byte>byteArr;
|
||||
for(int i=0;i<bytes;i++){
|
||||
if(!file.eof()){
|
||||
byteArr.push_back(byte(file.get()));
|
||||
byteArr.push_back(std::byte(file.get()));
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return byteArr;
|
||||
}
|
||||
void SHNFile::WriteBytes(std::ofstream&file,std::vector<byte>&data){
|
||||
void SHNFile::WriteBytes(std::ofstream&file,std::vector<std::byte>&data){
|
||||
for(int i=0;i<data.size();i++){
|
||||
file<<unsigned char(data[i]);
|
||||
}
|
||||
}
|
||||
int SHNFile::ReadInt32(std::ifstream&file){
|
||||
std::vector<byte>intBytes=ReadBytes(file,4);
|
||||
std::vector<std::byte>intBytes=ReadBytes(file,4);
|
||||
int numb = int(intBytes[3])<<24|int(intBytes[2])<<16|int(intBytes[1])<<8|int(intBytes[0]);
|
||||
return numb;
|
||||
}
|
||||
@ -128,20 +128,20 @@ void SHNFile::Encrypt(){
|
||||
Decrypt();
|
||||
}
|
||||
void SHNFile::Decrypt(){
|
||||
byte num = byte(data.size());
|
||||
std::byte num = std::byte(data.size());
|
||||
for(int i=data.size()-1;i>=0;i--){
|
||||
data[i] = byte(data[i]^num);
|
||||
byte num3 = byte(i);
|
||||
num3 = byte(num3&byte(15));
|
||||
num3 = byte(int(num3)+0x55);
|
||||
num3 = byte(num3 ^ (byte((int(byte(i))*11))));
|
||||
num3 = byte(num3^num);
|
||||
num3 = byte(int(num3)^170);
|
||||
data[i] = std::byte(data[i]^num);
|
||||
std::byte num3 = std::byte(i);
|
||||
num3 = std::byte(num3&std::byte(15));
|
||||
num3 = std::byte(int(num3)+0x55);
|
||||
num3 = std::byte(num3 ^ (std::byte((int(std::byte(i))*11))));
|
||||
num3 = std::byte(num3^num);
|
||||
num3 = std::byte(int(num3)^170);
|
||||
num = num3;
|
||||
}
|
||||
}
|
||||
std::vector<byte>SHNFile::ReadBytes(int bytes){
|
||||
std::vector<byte>byteArr={};
|
||||
std::vector<std::byte>SHNFile::ReadBytes(int bytes){
|
||||
std::vector<std::byte>byteArr={};
|
||||
for(int i=0;i<bytes;i++){
|
||||
if(marker<data.size()){
|
||||
byteArr.push_back(data[marker]);
|
||||
@ -152,22 +152,22 @@ std::vector<byte>SHNFile::ReadBytes(int bytes){
|
||||
}
|
||||
return byteArr;
|
||||
}
|
||||
byte SHNFile::ReadByte(){
|
||||
std::vector<byte>b=ReadBytes(1);
|
||||
std::byte SHNFile::ReadByte(){
|
||||
std::vector<std::byte>b=ReadBytes(1);
|
||||
if(b.size()>0){
|
||||
return b[0];
|
||||
} else {
|
||||
return byte(0);
|
||||
return std::byte(0);
|
||||
}
|
||||
}
|
||||
void SHNFile::WriteByte(std::ofstream&f,byte b){
|
||||
void SHNFile::WriteByte(std::ofstream&f,std::byte b){
|
||||
f<<unsigned char(b);
|
||||
}
|
||||
void SHNFile::WriteSByte(std::ofstream&f,sbyte b){
|
||||
f<<char(b);
|
||||
}
|
||||
uint16_t SHNFile::ReadUInt16(){
|
||||
std::vector<byte>intBytes=ReadBytes(2);
|
||||
std::vector<std::byte>intBytes=ReadBytes(2);
|
||||
uint16_t numb = uint16_t(intBytes[1])<<8|uint16_t(intBytes[0]);
|
||||
return numb;
|
||||
}
|
||||
@ -175,7 +175,7 @@ void SHNFile::WriteUInt16(std::ofstream&f,uint16_t val){
|
||||
f<<unsigned char(val&0xFF)<<unsigned char((val>>8)&0xFF);
|
||||
}
|
||||
int16_t SHNFile::ReadInt16(){
|
||||
std::vector<byte>intBytes=ReadBytes(2);
|
||||
std::vector<std::byte>intBytes=ReadBytes(2);
|
||||
int16_t numb = int16_t(intBytes[1])<<8|int16_t(intBytes[0]);
|
||||
return numb;
|
||||
}
|
||||
@ -183,7 +183,7 @@ void SHNFile::WriteInt16(std::ofstream&f,int16_t val){
|
||||
f<<unsigned char(val&0xFF)<<unsigned char((val>>8)&0xFF);
|
||||
}
|
||||
uint32_t SHNFile::ReadUInt32(){
|
||||
std::vector<byte>intBytes=ReadBytes(4);
|
||||
std::vector<std::byte>intBytes=ReadBytes(4);
|
||||
uint32_t numb = uint32_t(intBytes[3])<<24|uint32_t(intBytes[2])<<16|uint32_t(intBytes[1])<<8|uint32_t(intBytes[0]);
|
||||
return numb;
|
||||
}
|
||||
@ -191,12 +191,12 @@ void SHNFile::WriteUInt32(std::ofstream&f,uint32_t val){
|
||||
f<<unsigned char(val&0xFF)<<unsigned char((val>>8)&0xFF)<<unsigned char((val>>16)&0xFF)<<unsigned char((val>>24)&0xFF);
|
||||
}
|
||||
int SHNFile::Read(){
|
||||
std::vector<byte>intBytes=ReadBytes(4);
|
||||
std::vector<std::byte>intBytes=ReadBytes(4);
|
||||
int numb = int(intBytes[3])<<24|int(intBytes[2])<<16|int(intBytes[1])<<8|int(intBytes[0]);
|
||||
return numb;
|
||||
}
|
||||
int32_t SHNFile::ReadInt32(){
|
||||
std::vector<byte>intBytes=ReadBytes(4);
|
||||
std::vector<std::byte>intBytes=ReadBytes(4);
|
||||
int32_t numb = int32_t(intBytes[3])<<24|int32_t(intBytes[2])<<16|int32_t(intBytes[1])<<8|uint32_t(intBytes[0]);
|
||||
return numb;
|
||||
}
|
||||
@ -204,10 +204,10 @@ void SHNFile::WriteInt32(std::ofstream&f,int32_t val){
|
||||
f<<unsigned char(val&0xFF)<<unsigned char((val>>8)&0xFF)<<unsigned char((val>>16)&0xFF)<<unsigned char((val>>24)&0xFF);
|
||||
}
|
||||
std::string SHNFile::ReadString(int bytes){
|
||||
std::vector<byte>strBytes=ReadBytes(bytes);
|
||||
std::vector<std::byte>strBytes=ReadBytes(bytes);
|
||||
std::string str="";
|
||||
for(int i=0;i<strBytes.size();i++){
|
||||
if(strBytes[i]!=byte(0)){
|
||||
if(strBytes[i]!=std::byte(0)){
|
||||
str+=unsigned char(strBytes[i]);
|
||||
}
|
||||
}
|
||||
@ -227,14 +227,14 @@ void SHNFile::WriteString(std::ofstream&f,std::string str,int bytes){
|
||||
}
|
||||
}
|
||||
float SHNFile::ReadSingle(){
|
||||
std::vector<byte>strBytes=ReadBytes(4);
|
||||
byte bytes[]={strBytes[0],strBytes[1],strBytes[2],strBytes[3]};
|
||||
std::vector<std::byte>strBytes=ReadBytes(4);
|
||||
std::byte bytes[]={strBytes[0],strBytes[1],strBytes[2],strBytes[3]};
|
||||
float f;
|
||||
memcpy(&f,&bytes,4);
|
||||
return f;
|
||||
}
|
||||
void SHNFile::WriteSingle(std::ofstream&f,float n){
|
||||
byte bytes[4]={};
|
||||
std::byte bytes[4]={};
|
||||
memcpy(&n,&bytes,4);
|
||||
for(int i=0;i<4;i++){
|
||||
f<<unsigned char(bytes[i]);
|
||||
@ -246,8 +246,8 @@ sbyte SHNFile::ReadSByte(){
|
||||
std::string SHNFile::ReadString(){
|
||||
std::string str="";
|
||||
while(true){
|
||||
std::vector<byte>byteArr=ReadBytes(1);
|
||||
if(byteArr.size()>0&&byteArr[0]!=byte(0)){
|
||||
std::vector<std::byte>byteArr=ReadBytes(1);
|
||||
if(byteArr.size()>0&&byteArr[0]!=std::byte(0)){
|
||||
str+=unsigned char(byteArr[0]);
|
||||
}else{
|
||||
break;
|
||||
@ -262,8 +262,8 @@ uint32_t SHNFile::GetRecordLength(){
|
||||
}
|
||||
return start;
|
||||
}
|
||||
SHNFile::Data::Data(byte b){
|
||||
std::shared_ptr<byte>ptr=std::make_shared<byte>(byte(b));
|
||||
SHNFile::Data::Data(std::byte b){
|
||||
std::shared_ptr<std::byte>ptr=std::make_shared<std::byte>(std::byte(b));
|
||||
data=ptr;
|
||||
type=DataType::BYTE;
|
||||
}
|
||||
@ -313,7 +313,7 @@ void SHNFile::Data::Set(T b){
|
||||
std::string SHNFile::Data::GetDisplayText(){
|
||||
switch(type){
|
||||
case DataType::BYTE:{
|
||||
return std::to_string(int(Get<byte>()));
|
||||
return std::to_string(int(Get<std::byte>()));
|
||||
}break;
|
||||
case DataType::SBYTE:{
|
||||
return std::to_string(int(Get<sbyte>()));
|
||||
@ -356,10 +356,10 @@ void SHNFile::Load(std::string file){
|
||||
cryptHeader=ReadBytes(f,0x20);
|
||||
std::copy(cryptHeader.begin(),cryptHeader.end(),std::back_inserter(rawData));
|
||||
int readAmt=ReadInt32(f);
|
||||
rawData.push_back(byte(readAmt&0xFF));
|
||||
rawData.push_back(byte((readAmt>>8)&0xFF));
|
||||
rawData.push_back(byte((readAmt>>16)&0xFF));
|
||||
rawData.push_back(byte((readAmt>>24)&0xFF));
|
||||
rawData.push_back(std::byte(readAmt&0xFF));
|
||||
rawData.push_back(std::byte((readAmt>>8)&0xFF));
|
||||
rawData.push_back(std::byte((readAmt>>16)&0xFF));
|
||||
rawData.push_back(std::byte((readAmt>>24)&0xFF));
|
||||
data=ReadBytes(f,readAmt-0x24);
|
||||
std::copy(data.begin(),data.end(),std::back_inserter(rawData));
|
||||
|
||||
@ -457,7 +457,7 @@ void SHNFile::Save(){
|
||||
case 1:
|
||||
case 12:
|
||||
case 0x10:{
|
||||
WriteByte(f,col.Get<byte>());
|
||||
WriteByte(f,col.Get<std::byte>());
|
||||
}break;
|
||||
case 2:{
|
||||
WriteUInt16(f,col.Get<uint16_t>());
|
||||
@ -511,8 +511,8 @@ void SHNFile::Save(){
|
||||
const SHNFile::Data SHNFile::Get(int row,int col)const{
|
||||
return contents[row][col];
|
||||
};
|
||||
void SHNFile::Write(int row,int col,byte val){
|
||||
contents[row][col].Set<byte>(val);
|
||||
void SHNFile::Write(int row,int col,std::byte val){
|
||||
contents[row][col].Set<std::byte>(val);
|
||||
}
|
||||
void SHNFile::Write(int row,int col,sbyte val){
|
||||
contents[row][col].Set<sbyte>(val);
|
||||
|
@ -134,6 +134,7 @@
|
||||
<ClCompile Include="SHNFile_example.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="olcPixelGameEngine.h" />
|
||||
<ClInclude Include="SHNFileDecryptor.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
|
@ -23,5 +23,8 @@
|
||||
<ClInclude Include="SHNFileDecryptor.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="olcPixelGameEngine.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -1,6 +1,10 @@
|
||||
|
||||
#define OLC_PGEX_SHNFile
|
||||
#include "SHNFileDecryptor.h"
|
||||
|
||||
#define OLC_PGE_APPLICATION
|
||||
#include "olcPixelGameEngine.h"
|
||||
|
||||
int main(){
|
||||
SHNFile shn;
|
||||
shn.Load("AbState.shn");
|
||||
|
6695
SHNFileDecryptor/olcPixelGameEngine.h
Normal file
6695
SHNFileDecryptor/olcPixelGameEngine.h
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user