Fix a closing bug and moved some focus arguments for canClose flags to the internal window update function instead.

master
sigonasr2 2 years ago
parent 623f0137ab
commit 2ec1d538be
  1. 7
      FiestaOnlineEditor/FiestaOnlineEditor.cpp
  2. 2
      FiestaOnlineEditor/ItemEditor.cpp
  3. 96
      FiestaOnlineEditor/SHNFileDecryptor.h
  4. 15
      FiestaOnlineEditor/Window.cpp

@ -167,12 +167,13 @@ bool FiestaOnlineEditor::OnUserUpdate(float fElapsedTime){
} }
if(!menuOpened){ if(!menuOpened){
if(!internalMouseFocus){ for(auto it=windows.begin();it!=windows.end();++it){ //A second iteration through the windows because windows without focus should only have priority after a window with focus.
for(auto it=windows.begin();it!=windows.end();++it){ //A second iteration through the windows because windows without focus should only have priority after a window with focus. Window*w=*it;
Window*w=*it; if(!internalMouseFocus){
if(!w->IsFocusedWindow()){ if(!w->IsFocusedWindow()){
if(w->IsInBounds(GetMousePos())){ if(w->IsInBounds(GetMousePos())){
w->InternalMouseFocus(this); w->InternalMouseFocus(this);
internalMouseFocus=true;
if(w->IsFocusedWindow()){//The focused window has changed! if(w->IsFocusedWindow()){//The focused window has changed!
windows.push_back(w);//HACK ALERT! Whenever we are iterating through the windows list we could potentially add an item to the end of it whenever it becomes focused to keep layering. Because of this we don't want to reallocate during another push_back. This ensures that will never occur. windows.push_back(w);//HACK ALERT! Whenever we are iterating through the windows list we could potentially add an item to the end of it whenever it becomes focused to keep layering. Because of this we don't want to reallocate during another push_back. This ensures that will never occur.
it=windows.erase(it); it=windows.erase(it);

@ -7,6 +7,8 @@ ItemEditor::~ItemEditor(){};
void ItemEditor::Load(std::string basePath){ void ItemEditor::Load(std::string basePath){
ItemInfo.Load(basePath+"/ItemInfo.shn"); ItemInfo.Load(basePath+"/ItemInfo.shn");
ItemInfoServer.Load(basePath+"/ItemInfoServer.shn");
ItemViewInfo.Load(basePath+"/View/ItemViewInfo.shn");
} }
void ItemEditor::Update(FiestaOnlineEditor*pge,float fElapsedTime){ void ItemEditor::Update(FiestaOnlineEditor*pge,float fElapsedTime){

@ -11,8 +11,10 @@
typedef char sbyte; typedef char sbyte;
class SHNFile{ class SHNFile{
SHNFile(const SHNFile&)=delete;
std::vector<std::byte>ReadBytes(std::ifstream&file); std::vector<std::byte>ReadBytes(std::ifstream&file);
std::vector<std::byte>ReadBytes(std::ifstream&file,int bytes); std::vector<std::byte>ReadBytes(std::ifstream&file,int bytes);
void WriteBytes(std::ofstream&file,char*data,int length);
void WriteBytes(std::ofstream&file,std::vector<std::byte>&data); void WriteBytes(std::ofstream&file,std::vector<std::byte>&data);
int ReadInt32(std::ifstream&file); int ReadInt32(std::ifstream&file);
void Encrypt(); void Encrypt();
@ -76,14 +78,15 @@ private:
int length=0; int length=0;
}; };
int marker=0; int marker=0;
std::vector<std::byte>cryptHeader; char*cryptHeader=nullptr;
std::vector<std::byte>data,rawData; char*data=nullptr,*rawData=nullptr;
uint32_t header=0,recordCount=0,defaultRecordLength=0,columnCount=0; uint32_t header=0,recordCount=0,defaultRecordLength=0,columnCount=0;
std::vector<Column>columns; std::vector<Column>columns;
std::vector<std::vector<Data>>contents; std::vector<std::vector<Data>>contents;
std::string filename; std::string filename;
std::vector<std::byte>readArr; std::vector<std::byte>readArr;
std::byte*fileMarker=0; int readAmt=0;
void Cleanup();
public: public:
void Load(std::string file); void Load(std::string file);
void Save(); void Save();
@ -95,8 +98,12 @@ public:
void Write(int row,int col,uint32_t val); void Write(int row,int col,uint32_t val);
void Write(int row,int col,float val); void Write(int row,int col,float val);
void Write(int row,int col,std::string 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(SHNFile&&)noexcept;
~SHNFile();
}; };
#ifdef OLC_PGEX_SHNFile #ifdef OLC_PGEX_SHNFile
std::vector<std::byte>SHNFile::ReadBytes(std::ifstream&file){ std::vector<std::byte>SHNFile::ReadBytes(std::ifstream&file){
@ -117,6 +124,11 @@ std::vector<std::byte>SHNFile::ReadBytes(std::ifstream&file,int bytes){
} }
return byteArr; return byteArr;
} }
void SHNFile::WriteBytes(std::ofstream&file,char*data,int length){
for(int i=0;i<length;i++){
file<<unsigned char(data[i]);
}
}
void SHNFile::WriteBytes(std::ofstream&file,std::vector<std::byte>&data){ void SHNFile::WriteBytes(std::ofstream&file,std::vector<std::byte>&data){
for(int i=0;i<data.size();i++){ for(int i=0;i<data.size();i++){
file<<unsigned char(data[i]); file<<unsigned char(data[i]);
@ -131,9 +143,9 @@ void SHNFile::Encrypt(){
Decrypt(); Decrypt();
} }
void SHNFile::Decrypt(){ void SHNFile::Decrypt(){
std::byte num = std::byte(data.size()); std::byte num = std::byte(readAmt-0x24);
for(int i=data.size()-1;i>=0;i--){ for(int i=readAmt-0x24-1;i>=0;i--){
data[i] = std::byte(data[i]^num); data[i] = char(std::byte(data[i])^num);
std::byte num3 = std::byte(i); std::byte num3 = std::byte(i);
num3 = std::byte(num3&std::byte(15)); num3 = std::byte(num3&std::byte(15));
num3 = std::byte(int(num3)+0x55); num3 = std::byte(int(num3)+0x55);
@ -145,7 +157,9 @@ void SHNFile::Decrypt(){
} }
std::vector<std::byte>&SHNFile::ReadBytes(int bytes){ std::vector<std::byte>&SHNFile::ReadBytes(int bytes){
readArr.clear(); readArr.clear();
std::copy(data.begin()+marker,data.begin()+marker+bytes,std::back_inserter(readArr)); for(int i=0;i<bytes;i++){
readArr.push_back(std::byte(*(data+i+marker)));
}
marker+=bytes; marker+=bytes;
return readArr; return readArr;
} }
@ -339,23 +353,29 @@ void SHNFile::Load(std::string file){
header=recordCount=defaultRecordLength=columnCount=0; header=recordCount=defaultRecordLength=columnCount=0;
columns.clear(); columns.clear();
contents.clear(); contents.clear();
rawData.clear();
marker=0; marker=0;
std::chrono::time_point<std::chrono::high_resolution_clock>timer=std::chrono::high_resolution_clock::now(); std::chrono::time_point<std::chrono::high_resolution_clock>timer=std::chrono::high_resolution_clock::now();
filename=file; filename=file;
Cleanup();
//FILE OPERATIONS! //FILE OPERATIONS!
std::ifstream f(filename,std::ios::binary); std::ifstream f(filename,std::ios::binary);
//Since we don't just read in the entire file raw, we have to do some additional work here as the header provides us with some basic info on how to decrypt this file. //Since we don't just read in the entire file raw, we have to do some additional work here as the header provides us with some basic info on how to decrypt this file.
//The backup itself needs all the data from the original file, so we're appending it to rawData as we continue reading it. //The backup itself needs all the data from the original file, so we're appending it to rawData as we continue reading it.
cryptHeader=ReadBytes(f,0x20);
int readAmt=ReadInt32(f); cryptHeader=new char[0x20];
rawData.push_back(std::byte(readAmt&0xFF)); f.read(cryptHeader,0x20);
rawData.push_back(std::byte((readAmt>>8)&0xFF)); readAmt=ReadInt32(f);
rawData.push_back(std::byte((readAmt>>16)&0xFF)); rawData=new char[readAmt-0x20];
rawData.push_back(std::byte((readAmt>>24)&0xFF)); rawData[0]=char(readAmt&0xFF);
data=ReadBytes(f,readAmt-0x24); rawData[1]=char((readAmt>>8)&0xFF);
std::copy(data.begin(),data.end(),std::back_inserter(rawData)); rawData[2]=char((readAmt>>16)&0xFF);
rawData[3]=char((readAmt>>24)&0xFF);
data=new char[readAmt-0x24];
f.read(data,readAmt-0x24);
for(int i=0;i<readAmt-0x24;i++){
rawData[i+4]=data[i];
}
Decrypt(); Decrypt();
header=ReadUInt32(); header=ReadUInt32();
@ -422,7 +442,10 @@ void SHNFile::Load(std::string file){
void SHNFile::Save(){ void SHNFile::Save(){
std::ofstream fBackup(filename+".bak",std::ios::binary); std::ofstream fBackup(filename+".bak",std::ios::binary);
std::cout<<"Saving a backup to "<<filename+".bak"<<std::endl; std::cout<<"Saving a backup to "<<filename+".bak"<<std::endl;
for(int i=0;i<rawData.size();i++){ for(int i=0;i<0x20;i++){
fBackup<<unsigned char(cryptHeader[i]);
}
for(int i=0;i<readAmt-0x20;i++){
fBackup<<unsigned char(rawData[i]); fBackup<<unsigned char(rawData[i]);
} }
/*//Decoded version only required for debugging. /*//Decoded version only required for debugging.
@ -493,17 +516,18 @@ void SHNFile::Save(){
} }
f.close(); f.close();
std::ifstream finishedFile(filename,std::ios::binary); std::ifstream finishedFile(filename,std::ios::binary);
data=ReadBytes(finishedFile); finishedFile.read(data,readAmt-0x24);
std::ofstream encryptedFile(filename,std::ios::binary); std::ofstream encryptedFile(filename,std::ios::binary);
std::cout<<"Encrypting..."<<std::endl; std::cout<<"Encrypting..."<<std::endl;
Encrypt(); Encrypt();
WriteBytes(encryptedFile,cryptHeader); WriteBytes(encryptedFile,cryptHeader,0x20);
WriteInt32(encryptedFile,int32_t(data.size()+0x24)); WriteInt32(encryptedFile,int32_t(readAmt));
WriteBytes(encryptedFile,data); WriteBytes(encryptedFile,data,readAmt-0x24);
std::cout<<"File "<<filename<<" Saved!"<<std::endl; std::cout<<"File "<<filename<<" Saved!"<<std::endl;
} }
const SHNFile::Data SHNFile::Get(int row,int col)const{ template<typename T>
return contents[row][col]; 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){ void SHNFile::Write(int row,int col,std::byte val){
contents[row][col].Set<std::byte>(val); contents[row][col].Set<std::byte>(val);
@ -532,4 +556,28 @@ void SHNFile::Write(int row,int col,std::string val){
SHNFile::SHNFile(){ SHNFile::SHNFile(){
readArr.reserve(64000); readArr.reserve(64000);
} }
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;
cryptHeader=nullptr;
}
if(data!=nullptr){
delete[] data;
data=nullptr;
}
if(rawData!=nullptr){
delete[] rawData;
rawData=nullptr;
}
}
#endif #endif

@ -19,12 +19,7 @@ void Window::InternalUpdate(FiestaOnlineEditor*pge,float fElapsedTime){
if(dragging){ if(dragging){
pos=pge->GetMousePos()-dragPoint; pos=pge->GetMousePos()-dragPoint;
} }
if(pge->GetMouseX()>=pos.x+size.x-64&&pge->GetMouseY()<pos.y+headerHeight&&pge->GetMouseY()>=pos.y){ if(pge->GetMouseX()>=pos.x+size.x||pge->GetMouseX()<pos.x+size.x-64||pge->GetMouseY()>=pos.y+headerHeight||pge->GetMouseY()<pos.y){
if(!canClose){
canClose=true;
InternalRefresh(pge);
}
} else {
if(canClose){ if(canClose){
canClose=false; canClose=false;
InternalRefresh(pge); InternalRefresh(pge);
@ -108,9 +103,15 @@ void Window::InternalMouseFocus(FiestaOnlineEditor*pge){
if(pge->GetMouse(0).bReleased){ if(pge->GetMouse(0).bReleased){
dragging=false; dragging=false;
} }
if(pge->GetMouse(1).bPressed){ if(pge->GetMouse(1).bPressed&&canClose){
closed=true; closed=true;
} }
if(pge->GetMouseX()>=pos.x+size.x-64&&pge->GetMouseY()<pos.y+headerHeight&&pge->GetMouseY()>=pos.y){
if(!canClose){
canClose=true;
InternalRefresh(pge);
}
}
} }
void Window::MouseFocus(FiestaOnlineEditor*pge){} void Window::MouseFocus(FiestaOnlineEditor*pge){}

Loading…
Cancel
Save