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

master
sigonasr2 1 year 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(!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.
Window*w=*it;
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;
if(!internalMouseFocus){
if(!w->IsFocusedWindow()){
if(w->IsInBounds(GetMousePos())){
w->InternalMouseFocus(this);
internalMouseFocus=true;
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.
it=windows.erase(it);

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

@ -11,8 +11,10 @@
typedef char sbyte;
class SHNFile{
SHNFile(const SHNFile&)=delete;
std::vector<std::byte>ReadBytes(std::ifstream&file);
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);
int ReadInt32(std::ifstream&file);
void Encrypt();
@ -76,14 +78,15 @@ private:
int length=0;
};
int marker=0;
std::vector<std::byte>cryptHeader;
std::vector<std::byte>data,rawData;
char*cryptHeader=nullptr;
char*data=nullptr,*rawData=nullptr;
uint32_t header=0,recordCount=0,defaultRecordLength=0,columnCount=0;
std::vector<Column>columns;
std::vector<std::vector<Data>>contents;
std::string filename;
std::vector<std::byte>readArr;
std::byte*fileMarker=0;
int readAmt=0;
void Cleanup();
public:
void Load(std::string file);
void Save();
@ -95,8 +98,12 @@ public:
void Write(int row,int col,uint32_t val);
void Write(int row,int col,float 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&&)noexcept;
~SHNFile();
};
#ifdef OLC_PGEX_SHNFile
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;
}
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){
for(int i=0;i<data.size();i++){
file<<unsigned char(data[i]);
@ -131,9 +143,9 @@ void SHNFile::Encrypt(){
Decrypt();
}
void SHNFile::Decrypt(){
std::byte num = std::byte(data.size());
for(int i=data.size()-1;i>=0;i--){
data[i] = std::byte(data[i]^num);
std::byte num = std::byte(readAmt-0x24);
for(int i=readAmt-0x24-1;i>=0;i--){
data[i] = char(std::byte(data[i])^num);
std::byte num3 = std::byte(i);
num3 = std::byte(num3&std::byte(15));
num3 = std::byte(int(num3)+0x55);
@ -145,7 +157,9 @@ void SHNFile::Decrypt(){
}
std::vector<std::byte>&SHNFile::ReadBytes(int bytes){
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;
return readArr;
}
@ -339,23 +353,29 @@ void SHNFile::Load(std::string file){
header=recordCount=defaultRecordLength=columnCount=0;
columns.clear();
contents.clear();
rawData.clear();
marker=0;
std::chrono::time_point<std::chrono::high_resolution_clock>timer=std::chrono::high_resolution_clock::now();
filename=file;
Cleanup();
//FILE OPERATIONS!
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.
//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);
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));
cryptHeader=new char[0x20];
f.read(cryptHeader,0x20);
readAmt=ReadInt32(f);
rawData=new char[readAmt-0x20];
rawData[0]=char(readAmt&0xFF);
rawData[1]=char((readAmt>>8)&0xFF);
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();
header=ReadUInt32();
@ -422,7 +442,10 @@ void SHNFile::Load(std::string file){
void SHNFile::Save(){
std::ofstream fBackup(filename+".bak",std::ios::binary);
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]);
}
/*//Decoded version only required for debugging.
@ -493,17 +516,18 @@ void SHNFile::Save(){
}
f.close();
std::ifstream finishedFile(filename,std::ios::binary);
data=ReadBytes(finishedFile);
finishedFile.read(data,readAmt-0x24);
std::ofstream encryptedFile(filename,std::ios::binary);
std::cout<<"Encrypting..."<<std::endl;
Encrypt();
WriteBytes(encryptedFile,cryptHeader);
WriteInt32(encryptedFile,int32_t(data.size()+0x24));
WriteBytes(encryptedFile,data);
WriteBytes(encryptedFile,cryptHeader,0x20);
WriteInt32(encryptedFile,int32_t(readAmt));
WriteBytes(encryptedFile,data,readAmt-0x24);
std::cout<<"File "<<filename<<" Saved!"<<std::endl;
}
const SHNFile::Data SHNFile::Get(int row,int col)const{
return contents[row][col];
template<typename T>
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){
contents[row][col].Set<std::byte>(val);
@ -532,4 +556,28 @@ void SHNFile::Write(int row,int col,std::string val){
SHNFile::SHNFile(){
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

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

Loading…
Cancel
Save