Mercurial > mm7
changeset 2174:5ca3251ea543
autosave continue
author | Ritor1 |
---|---|
date | Tue, 21 Jan 2014 16:37:23 +0600 |
parents | daa61976637d |
children | 2f9689a85c31 |
files | LOD.cpp SaveLoad.cpp UI/UISaveLoad.cpp mm7_3.cpp |
diffstat | 4 files changed, 198 insertions(+), 230 deletions(-) [+] |
line wrap: on
line diff
--- a/LOD.cpp Tue Jan 21 00:59:21 2014 +0600 +++ b/LOD.cpp Tue Jan 21 16:37:23 2014 +0600 @@ -1501,163 +1501,165 @@ //----- (00461B48) -------------------------------------------------------- unsigned int LODWriteableFile::Write(const LOD::Directory *pDir, const void *pDirData, int a4) { - char Filename[256]; - char NewFilename[256]; - FILE *tmp_file; - int comp_res; - bool bRewrite_data; - int offset_to_data; - int total_data_size; - int size_correction; - int to_copy_size; - int read_size; - int curr_position; - int insert_index; - - //insert new data in sorted index lod file - bRewrite_data = false; - insert_index=-1; - if (!isFileOpened)//sometimes gives crash - return 1; - if ( !pSubIndices) - return 2; - if (!pIOBuffer||!uIOBufferSize) - return 3; - - for (int i=0;i<uNumSubDirs; i++) - { - comp_res=_stricmp(pSubIndices[i].pFilename,pDir->pFilename); - if(comp_res==0) - { - insert_index=i; - if (a4==0) - { - bRewrite_data=true; + char Filename[256]; + char NewFilename[256]; + FILE *tmp_file; + //int comp_res; + bool bRewrite_data; + int offset_to_data; + int total_data_size; + int size_correction; + int to_copy_size; + int read_size; + int curr_position; + int insert_index; - break; - } - if (a4==1) - { - if(pSubIndices[i].uNumSubIndices<pDir->uNumSubIndices) - { - if (pSubIndices[i].word_00001E<pDir->word_00001E) - return 4; - } - else - bRewrite_data=true; - break; - } - if (a4==2) - return 4; - } - else if (comp_res>0) - { - if (insert_index==-1) - { - insert_index=i; - break; - } - } - } - strcpy(Filename, "lod.tmp"); - tmp_file = fopen(Filename, "wb+"); - if ( !tmp_file ) - return 5; - if (!bRewrite_data) - size_correction=0; - else - size_correction=pSubIndices[insert_index].uDataSize; + //insert new data in sorted index lod file + bRewrite_data = false; + insert_index = -1; + if (!isFileOpened)//sometimes gives crash + return 1; + if ( !pSubIndices ) + return 2; + if ( !pIOBuffer || !uIOBufferSize ) + return 3; - //create chapter index - LOD::Directory Lindx; - strcpy(Lindx.pFilename, "chapter"); - Lindx.dword_000018=0; - Lindx.word_00001E=0; - Lindx.uNumSubIndices= uNumSubDirs; - Lindx.uOfsetFromSubindicesStart=sizeof(LOD::FileHeader)+sizeof(LOD::Directory); - total_data_size=uLODDataSize+pDir->uDataSize-size_correction; - if (!bRewrite_data) + for ( int i = 0; i < uNumSubDirs; i++ ) + { + //comp_res = _stricmp(pSubIndices[i].pFilename, pDir->pFilename ); + if( !_stricmp(pSubIndices[i].pFilename, pDir->pFilename) ) + { + insert_index = i; + if ( a4 == 0 ) + { + bRewrite_data = true; + break; + } + if ( a4 == 1 ) + { + if(pSubIndices[i].uNumSubIndices<pDir->uNumSubIndices) { - total_data_size+=sizeof(LOD::Directory); - Lindx.uNumSubIndices++; - } - - Lindx.uDataSize=total_data_size; - uNumSubDirs= Lindx.uNumSubIndices; - //move indexes +1 after insert point - if (!bRewrite_data&&(insert_index<uNumSubDirs)) - { - for(int i=uNumSubDirs;i>insert_index; --i) - memcpy(&pSubIndices[i],&pSubIndices[i-1],sizeof(LOD::Directory)); - + if (pSubIndices[i].word_00001E<pDir->word_00001E) + return 4; } - //insert - memcpy(&pSubIndices[insert_index],pDir,sizeof(LOD::Directory)); - //correct offsets to data - if (uNumSubDirs>0) - { - offset_to_data=sizeof(LOD::Directory)*uNumSubDirs; - for (int i=0;i<uNumSubDirs; i++) - { - pSubIndices[i].uOfsetFromSubindicesStart=offset_to_data; - offset_to_data+=pSubIndices[i].uDataSize; - } - } + else + bRewrite_data = true; + break; + } + if ( a4 == 2 ) + return 4; + } + else + { + if ( insert_index == -1 ) + { + insert_index = i; + break; + } + } + } + strcpy(Filename, "lod.tmp"); + tmp_file = fopen(Filename, "wb+"); + if ( !tmp_file ) + return 5; + if (!bRewrite_data) + size_correction = 0; + else + size_correction=pSubIndices[insert_index].uDataSize; - //construct lod file with added data - fwrite( &header, sizeof(LOD::FileHeader), 1, tmp_file); - fwrite(&Lindx, sizeof(LOD::Directory), 1, tmp_file); - fseek(pFile,Lindx.uOfsetFromSubindicesStart, SEEK_SET); - fwrite(pSubIndices, sizeof(LOD::Directory), uNumSubDirs, tmp_file); - - offset_to_data = sizeof(LOD::Directory) * uNumSubDirs; - if ( !bRewrite_data ) - offset_to_data -= sizeof(LOD::Directory); + //create chapter index + LOD::Directory Lindx; + strcpy(Lindx.pFilename, "chapter"); + Lindx.dword_000018 = 0; + Lindx.word_00001E = 0; + Lindx.uNumSubIndices = uNumSubDirs; + Lindx.uOfsetFromSubindicesStart=sizeof(LOD::FileHeader)+sizeof(LOD::Directory); + total_data_size=uLODDataSize+pDir->uDataSize-size_correction; + if (!bRewrite_data) + { + total_data_size+=sizeof(LOD::Directory); + Lindx.uNumSubIndices++; + } - fseek(pFile, offset_to_data, SEEK_CUR); - //copy from open lod to temp lod first half - to_copy_size=pSubIndices[insert_index].uOfsetFromSubindicesStart-pSubIndices[0].uOfsetFromSubindicesStart; - while(to_copy_size>0) - { - read_size = uIOBufferSize; - if ( to_copy_size <= uIOBufferSize ) - read_size = to_copy_size; - fread(pIOBuffer, 1, read_size, pFile); - fwrite(pIOBuffer, 1, read_size, tmp_file); - to_copy_size-=read_size; - } - // add container data - fwrite(pDirData, 1, pDir->uDataSize, tmp_file); - if ( bRewrite_data ) - fseek(pFile,size_correction , SEEK_CUR); + Lindx.uDataSize=total_data_size; + uNumSubDirs = Lindx.uNumSubIndices; + //move indexes +1 after insert point + if (!bRewrite_data&&(insert_index<uNumSubDirs)) + { + for(int i=uNumSubDirs;i>insert_index; --i) + memcpy(&pSubIndices[i],&pSubIndices[i - 1],sizeof(LOD::Directory)); + } + //insert + memcpy(&pSubIndices[insert_index],pDir,sizeof(LOD::Directory)); + //correct offsets to data + if (uNumSubDirs > 0) + { + offset_to_data=sizeof(LOD::Directory)*uNumSubDirs; + for (int i=0;i<uNumSubDirs; i++) + { + pSubIndices[i].uOfsetFromSubindicesStart=offset_to_data; + offset_to_data+=pSubIndices[i].uDataSize; + } + } + + //construct lod file with added data + fwrite( &header, sizeof(LOD::FileHeader), 1, tmp_file); + fwrite(&Lindx, sizeof(LOD::Directory), 1, tmp_file); + fseek(pFile,Lindx.uOfsetFromSubindicesStart, SEEK_SET); + fwrite(pSubIndices, sizeof(LOD::Directory), uNumSubDirs, tmp_file); + + offset_to_data = sizeof(LOD::Directory) * uNumSubDirs; + if ( !bRewrite_data ) + offset_to_data -= sizeof(LOD::Directory); - //add remainng data last half - curr_position = ftell(pFile); - fseek(pFile, 0, SEEK_END); - to_copy_size = ftell(pFile) - curr_position; - fseek(pFile, curr_position, SEEK_SET); - while ( to_copy_size > 0 ) - { - read_size = uIOBufferSize; - if ( to_copy_size <= uIOBufferSize ) - read_size = to_copy_size; - fread(pIOBuffer, 1, read_size, pFile); - fwrite(pIOBuffer, 1, read_size, tmp_file); - to_copy_size-=read_size; - } - //replace old file by new with added data - strcpy(NewFilename, pLODName); - fclose(tmp_file); - CloseWriteFile(); //isFileOpened == false, current file - remove(NewFilename); - rename(Filename, NewFilename); - CloseWriteFile(); - //reload new - LoadFile(pLODName, 0);//isFileOpened == true, next file - if (isFileOpened == false) - __debugbreak(); - return 0; - } + fseek(pFile, offset_to_data, SEEK_CUR); + //copy from open lod to temp lod first half + to_copy_size=pSubIndices[insert_index].uOfsetFromSubindicesStart-pSubIndices[0].uOfsetFromSubindicesStart; + while(to_copy_size>0) + { + read_size = uIOBufferSize; + if ( to_copy_size <= uIOBufferSize ) + read_size = to_copy_size; + fread(pIOBuffer, 1, read_size, pFile); + fwrite(pIOBuffer, 1, read_size, tmp_file); + to_copy_size-=read_size; + } + // add container data + fwrite(pDirData, 1, pDir->uDataSize, tmp_file); + if ( bRewrite_data ) + fseek(pFile,size_correction , SEEK_CUR); + + //add remainng data last half + curr_position = ftell(pFile); + fseek(pFile, 0, SEEK_END); + to_copy_size = ftell(pFile) - curr_position; + fseek(pFile, curr_position, SEEK_SET); + while ( to_copy_size > 0 ) + { + read_size = uIOBufferSize; + if ( to_copy_size <= uIOBufferSize ) + read_size = to_copy_size; + fread(pIOBuffer, 1, read_size, pFile); + fwrite(pIOBuffer, 1, read_size, tmp_file); + to_copy_size-=read_size; + } + //replace old file by new with added data + strcpy(NewFilename, pLODName); + bool temp_isFileOpened3 = isFileOpened; + fclose(tmp_file); + bool temp_isFileOpened2 = isFileOpened; + CloseWriteFile(); //isFileOpened == false, current file + remove(NewFilename); + rename(Filename, NewFilename); + bool temp_isFileOpened1 = isFileOpened; + CloseWriteFile(); + bool temp_isFileOpened = isFileOpened; + //reload new + LoadFile(pLODName, 0);//isFileOpened == true, next file + if (isFileOpened == false) + __debugbreak(); + return 0; +} //----- (00461A43) --------------------------------------------------------
--- a/SaveLoad.cpp Tue Jan 21 00:59:21 2014 +0600 +++ b/SaveLoad.cpp Tue Jan 21 16:37:23 2014 +0600 @@ -25,24 +25,12 @@ #include "mm7_data.h" - - - struct SavegameList *pSavegameList = new SavegameList; unsigned int uNumSavegameFiles; std::array<unsigned int, 45> pSavegameUsedSlots; std::array<struct RGBTexture, 45> pSavegameThumbnails; std::array<SavegameHeader, 45> pSavegameHeader; - - - - - - - - - //----- (0045EE8A) -------------------------------------------------------- void __fastcall LoadGame(unsigned int uSlot) { @@ -68,7 +56,6 @@ remove(pTmpBuf.data()); } - if (SoundSetAction[24][0]) for (uint i = 0; i < 4; ++i) { @@ -161,7 +148,6 @@ Log::Warning(L"NPCStats: deserialization warning"); fread(pNPCStats->pGroups_copy, sizeof(pNPCStats->pGroups_copy), 1, file); - uActiveCharacter = 0; for (uint i = 0; i < 4; ++i) if (pParty->pPlayers[i].CanAct()) @@ -224,11 +210,9 @@ viewparams->bRedrawGameUI = true; } - //----- (0045F469) -------------------------------------------------------- void SaveGame( bool IsAutoSAve, bool NotSaveWorld ) { - //unsigned short *pScreenshot; // edi@5 int text_pos; // eax@6 FILE *pLLoidFile; // edi@24 char* compressed_buf; // edi@30 @@ -278,7 +262,7 @@ else pOutdoor->loc_time.uLastVisitDay = pParty->uTimePlayed; - pRenderer->PackScreenshot(150, 112, uncompressed_buff, 1000000, &pLodDirectory.uDataSize); + pRenderer->PackScreenshot(150, 112, uncompressed_buff, 1000000, &pLodDirectory.uDataSize);//создание скриншота strcpy(pLodDirectory.pFilename, "image.pcx"); if (pCurrentScreen == SCREEN_SAVEGAME) @@ -398,19 +382,17 @@ data_write_pos += sizeof(DDM_DLV_Header); memcpy(data_write_pos, pIndoor->_visible_outlines, 0x36B); data_write_pos += 875; - - for (int i = 0; i <(signed int)pIndoor->uNumFaces; ++i) - { - memcpy(data_write_pos, &pIndoor->pFaces[i].uAttributes, 4); - data_write_pos += 4; - } + for (int i = 0; i <(signed int)pIndoor->uNumFaces; ++i) + { + memcpy(data_write_pos, &pIndoor->pFaces[i].uAttributes, 4); + data_write_pos += 4; + } - for (int i = 0; i <(signed int)uNumLevelDecorations; ++i) - { - memcpy(data_write_pos, &pLevelDecorations[i].uFlags, 2); - - data_write_pos+= 2; - } + for (int i = 0; i <(signed int)uNumLevelDecorations; ++i) + { + memcpy(data_write_pos, &pLevelDecorations[i].uFlags, 2); + data_write_pos += 2; + } memcpy(data_write_pos, &uNumActors, 4); data_write_pos += 4; memcpy(data_write_pos, &pActors, uNumActors * sizeof(Actor)); @@ -433,13 +415,11 @@ data_write_pos += 56; } - else + else//for Outdoor { pOutdoor->ddm.uNumFacesInBModels = 0; - for (int i=0; i<pOutdoor->uNumBModels;++i) - { - pOutdoor->ddm.uNumFacesInBModels +=pOutdoor->pBModels[i].uNumFaces; - } + for ( int i = 0; i < pOutdoor->uNumBModels; ++i ) + pOutdoor->ddm.uNumFacesInBModels += pOutdoor->pBModels[i].uNumFaces; pOutdoor->ddm.uNumBModels = pOutdoor->uNumBModels; pOutdoor->ddm.uNumDecorations = uNumLevelDecorations; memcpy(data_write_pos, &pOutdoor->ddm, sizeof(DDM_DLV_Header));//0x28 @@ -448,18 +428,18 @@ data_write_pos += 968; memcpy(data_write_pos, pOutdoor->uDicovered_area, 0x3C8); data_write_pos += 968; - for (int i = 0; i < pOutdoor->uNumBModels ; ++i) - for (int j = 0; j < pOutdoor->pBModels[i].uNumFaces;++j)//*(int *)&pOutdoor->pBModels->pModelName[v24]; ++j) - { - memcpy(data_write_pos, &(pOutdoor->pBModels[i].pFaces[j].uAttributes), 4); - data_write_pos += 4; - } - - for (int i = 0; i < (signed int)uNumLevelDecorations; ++i) + for (int i = 0; i < pOutdoor->uNumBModels ; ++i) + for (int j = 0; j < pOutdoor->pBModels[i].uNumFaces;++j)//*(int *)&pOutdoor->pBModels->pModelName[v24]; ++j) { - memcpy(data_write_pos, &pLevelDecorations[i].uFlags, 2); - data_write_pos += 2; + memcpy(data_write_pos, &(pOutdoor->pBModels[i].pFaces[j].uAttributes), 4); + data_write_pos += 4; } + + for (int i = 0; i < (signed int)uNumLevelDecorations; ++i) + { + memcpy(data_write_pos, &pLevelDecorations[i].uFlags, 2); + data_write_pos += 2; + } memcpy(data_write_pos, &uNumActors, 4); data_write_pos += 4; memcpy(data_write_pos, pActors.data(), 836 * uNumActors); @@ -519,34 +499,21 @@ pParty->sRotationX = sPRotationX; } - //----- (00460078) -------------------------------------------------------- void __fastcall DoSavegame(unsigned int uSlot) { - //unsigned int v1; // esi@1 - //int v2; // esi@2 - //RGBTexture *v3; // ebx@3 - int bNotArena; // [sp+2Ch] [bp-8h]@1 - //unsigned int v6; // [sp+30h] [bp-4h]@1 - - //__debugbreak(); - - //v1 = uSlot; - //v6 = uSlot; - bNotArena = _stricmp(pCurrentMapName, "d05.blv"); - if ( bNotArena ) + if ( _stricmp(pCurrentMapName, "d05.blv") )//Not Arena(не Арена) { LOD::Directory pDir; // [sp+Ch] [bp-28h]@2 SaveGame(0, 0); - //v2 = 100 * v1; - strcpy(pSavegameHeader[uSlot].pLocationName, pCurrentMapName); - pSavegameHeader[uSlot].uWordTime = pParty->uTimePlayed; + strcpy(pSavegameHeader[uSlot].pLocationName, pCurrentMapName);//дать название карты + pSavegameHeader[uSlot].uWordTime = pParty->uTimePlayed;//текущее время strcpy(pDir.pFilename, "header.bin"); pDir.uDataSize = 100; pNew_LOD->Write(&pDir, &pSavegameHeader[uSlot], 0); sprintf(pTmpBuf.data(), "saves\\save%03d.mm7", uSlot); - pNew_LOD->CloseWriteFile(); - CopyFileA("data\\new.lod", pTmpBuf.data(), 0); + pNew_LOD->CloseWriteFile();//закрыть + CopyFileA("data\\new.lod", pTmpBuf.data(), 0);//сохранение файла в директорию saves } GUI_UpdateWindows(); pGUIWindow_CurrentMenu->Release(); @@ -556,7 +523,7 @@ for (uint i = 0; i < 45; i++) pSavegameThumbnails[i].Release(); - if ( bNotArena ) + if ( _stricmp(pCurrentMapName, "d05.blv") ) pNew_LOD->_4621A7(); else ShowStatusBarString(pGlobalTXT_LocalizationStrings[583], 2);// "No saving in the Arena" @@ -608,37 +575,37 @@ //----- (0046086A) -------------------------------------------------------- void SaveNewGame() { - FILE *v3; // eax@7 + FILE *file; // eax@7 void *pSave; // [sp+170h] [bp-8h]@3 if ( pVideoPlayer->AnyMovieLoaded() ) pVideoPlayer->Unload(); pSave = malloc(1000000); pNew_LOD->CloseWriteFile(); - remove("data\\new.lod"); + remove("data\\new.lod");//удалить new.lod - LOD::FileHeader this_; // [sp+Ch] [bp-16Ch]@3 - strcpy(this_.LodVersion, "MMVII"); - strcpy(this_.LodDescription, "newmaps for MMVII"); - this_.LODSize = 100; - this_.dword_0000A8 = 0; + LOD::FileHeader header; // [sp+Ch] [bp-16Ch]@3 заголовок + strcpy(header.LodVersion, "MMVII"); + strcpy(header.LodDescription, "newmaps for MMVII"); + header.LODSize = 100; + header.dword_0000A8 = 0; LOD::Directory a3; // [sp+14Ch] [bp-2Ch]@3 a3.dword_000018 = 0; a3.word_00001E = 0; strcpy(a3.pFilename, "current"); - pNew_LOD->CreateNewLod(&this_, &a3, "data\\new.lod"); - if (pNew_LOD->LoadFile("data\\new.lod", false)) + pNew_LOD->CreateNewLod(&header, &a3, "data\\new.lod");//создаётся new.lod в дирректории + if (pNew_LOD->LoadFile("data\\new.lod", false))//загрузить файл new.lod(isFileOpened = true) { - pNew_LOD->CreateTempFile(); + pNew_LOD->CreateTempFile();//создаётся временный файл OutputFileHandle pNew_LOD->uNumSubDirs = 0; LOD::Directory pDir; // [sp+10Ch] [bp-6Ch]@4 - for (int i = pGames_LOD->uNumSubDirs / 2; i < pGames_LOD->uNumSubDirs; ++i) + for (int i = pGames_LOD->uNumSubDirs / 2; i < pGames_LOD->uNumSubDirs; ++i)//копирование файлов с 76 по 151 { - memcpy(&pDir, &pGames_LOD->pSubIndices[i], sizeof(pDir)); - v3 = pGames_LOD->FindContainer(pGames_LOD->pSubIndices[i].pFilename, 1); - fread(pSave, pGames_LOD->pSubIndices[i].uDataSize, 1, v3); + memcpy(&pDir, &pGames_LOD->pSubIndices[i], sizeof(pDir));//копирование текущего файла в pDir + file = pGames_LOD->FindContainer(pGames_LOD->pSubIndices[i].pFilename, 1); + fread(pSave, pGames_LOD->pSubIndices[i].uDataSize, 1, file); pNew_LOD->AppendDirectory(&pDir, pSave); }
--- a/UI/UISaveLoad.cpp Tue Jan 21 00:59:21 2014 +0600 +++ b/UI/UISaveLoad.cpp Tue Jan 21 16:37:23 2014 +0600 @@ -253,8 +253,8 @@ ++pIcons_LOD->uTexturePacksCount; if ( !pIcons_LOD->uNumPrevLoadedFiles ) pIcons_LOD->uNumPrevLoadedFiles = pIcons_LOD->uNumLoadedFiles; - memset(pSavegameUsedSlots.data(), 0, 0xB4u); - memset(&pSavegameThumbnails, 0, 0x708u); + memset(&pSavegameUsedSlots, 0, sizeof(pSavegameUsedSlots)); + memset(&pSavegameThumbnails, 0, sizeof(pSavegameThumbnails)); uTextureID_loadsave = pIcons_LOD->LoadTexture("loadsave", TEXTURE_16BIT_PALETTE); uTextureID_load_up = pIcons_LOD->LoadTexture("load_up", TEXTURE_16BIT_PALETTE); uTextureID_save_up = pIcons_LOD->LoadTexture("save_up", TEXTURE_16BIT_PALETTE);