diff --git a/FiestaOnlineEditor/FiestaOnlineEditor.cpp b/FiestaOnlineEditor/FiestaOnlineEditor.cpp index a98f3f9..3c3ecd7 100644 --- a/FiestaOnlineEditor/FiestaOnlineEditor.cpp +++ b/FiestaOnlineEditor/FiestaOnlineEditor.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); diff --git a/FiestaOnlineEditor/ItemEditor.cpp b/FiestaOnlineEditor/ItemEditor.cpp index 6ccfdf0..b38f5b8 100644 --- a/FiestaOnlineEditor/ItemEditor.cpp +++ b/FiestaOnlineEditor/ItemEditor.cpp @@ -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){ diff --git a/FiestaOnlineEditor/SHNFileDecryptor.h b/FiestaOnlineEditor/SHNFileDecryptor.h index 7280103..1696743 100644 --- a/FiestaOnlineEditor/SHNFileDecryptor.h +++ b/FiestaOnlineEditor/SHNFileDecryptor.h @@ -11,8 +11,10 @@ typedef char sbyte; class SHNFile{ + SHNFile(const SHNFile&)=delete; std::vectorReadBytes(std::ifstream&file); std::vectorReadBytes(std::ifstream&file,int bytes); + void WriteBytes(std::ofstream&file,char*data,int length); void WriteBytes(std::ofstream&file,std::vector&data); int ReadInt32(std::ifstream&file); void Encrypt(); @@ -76,14 +78,15 @@ private: int length=0; }; int marker=0; - std::vectorcryptHeader; - std::vectordata,rawData; + char*cryptHeader=nullptr; + char*data=nullptr,*rawData=nullptr; uint32_t header=0,recordCount=0,defaultRecordLength=0,columnCount=0; std::vectorcolumns; std::vector>contents; std::string filename; std::vectorreadArr; - 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 + const T Get(int row,int col)const; SHNFile(); + SHNFile(SHNFile&&)noexcept; + ~SHNFile(); }; #ifdef OLC_PGEX_SHNFile std::vectorSHNFile::ReadBytes(std::ifstream&file){ @@ -117,6 +124,11 @@ std::vectorSHNFile::ReadBytes(std::ifstream&file,int bytes){ } return byteArr; } +void SHNFile::WriteBytes(std::ofstream&file,char*data,int length){ + for(int i=0;i&data){ for(int i=0;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&SHNFile::ReadBytes(int bytes){ readArr.clear(); - std::copy(data.begin()+marker,data.begin()+marker+bytes,std::back_inserter(readArr)); + for(int i=0;itimer=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 +const T SHNFile::Get(int row,int col)const{ + return *(std::static_pointer_cast(contents[row][col].data)); }; void SHNFile::Write(int row,int col,std::byte val){ contents[row][col].Set(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 \ No newline at end of file diff --git a/FiestaOnlineEditor/Window.cpp b/FiestaOnlineEditor/Window.cpp index a430f05..dc4b76f 100644 --- a/FiestaOnlineEditor/Window.cpp +++ b/FiestaOnlineEditor/Window.cpp @@ -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()GetMouseY()>=pos.y){ - if(!canClose){ - canClose=true; - InternalRefresh(pge); - } - } else { + if(pge->GetMouseX()>=pos.x+size.x||pge->GetMouseX()GetMouseY()>=pos.y+headerHeight||pge->GetMouseY()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()GetMouseY()>=pos.y){ + if(!canClose){ + canClose=true; + InternalRefresh(pge); + } + } } void Window::MouseFocus(FiestaOnlineEditor*pge){}