Mercurial > mm7
comparison LOD.cpp @ 982:08fd1436ef35
enums & lod
author | Nomad |
---|---|
date | Sat, 11 May 2013 13:19:55 +0200 |
parents | bebc19f3d2af |
children | e865f349aa41 c45d51b3f4f4 |
comparison
equal
deleted
inserted
replaced
981:a6ef7125f6e4 | 982:08fd1436ef35 |
---|---|
999 if ( !pDir->pFilename[0] ) | 999 if ( !pDir->pFilename[0] ) |
1000 return 2; | 1000 return 2; |
1001 strcpy(pHeader->pSignature, "LOD"); | 1001 strcpy(pHeader->pSignature, "LOD"); |
1002 pHeader->LODSize = 100; | 1002 pHeader->LODSize = 100; |
1003 pHeader->uNumIndices = 1; | 1003 pHeader->uNumIndices = 1; |
1004 pDir->pFilename[15] = 0; | 1004 pDir->field_F = 0; |
1005 pDir->uDataSize = 0; | 1005 pDir->uDataSize = 0; |
1006 pDir->uOfsetFromSubindicesStart = 288; | 1006 pDir->uOfsetFromSubindicesStart = 288; |
1007 strcpy(pLODName, lod_name); | 1007 strcpy(pLODName, lod_name); |
1008 | 1008 |
1009 pFile = fopen(pLODName, "wb+"); | 1009 pFile = fopen(pLODName, "wb+"); |
1428 return LoadFile(pLODName, 0); | 1428 return LoadFile(pLODName, 0); |
1429 } | 1429 } |
1430 | 1430 |
1431 //----- (00461FD4) ---LODFile_sub_461FD4---text:004632EA -------------------------------------------------- | 1431 //----- (00461FD4) ---LODFile_sub_461FD4---text:004632EA -------------------------------------------------- |
1432 int LODWriteableFile::FixDirectoryOffsets() | 1432 int LODWriteableFile::FixDirectoryOffsets() |
1433 { | 1433 { |
1434 LOD::Directory Lindx; | |
1435 int total_size; // edi@1 | 1434 int total_size; // edi@1 |
1436 int temp_offset; // ecx@5 | 1435 int temp_offset; // ecx@5 |
1437 FILE *tmp_file; // eax@9 | 1436 FILE *tmp_file; // eax@9 |
1438 size_t write_size; // edi@12 | 1437 size_t write_size; // edi@12 |
1439 int result; | 1438 int result; |
1453 } | 1452 } |
1454 strcpy(Filename, "lod.tmp"); | 1453 strcpy(Filename, "lod.tmp"); |
1455 tmp_file = fopen(Filename, "wb+"); | 1454 tmp_file = fopen(Filename, "wb+"); |
1456 | 1455 |
1457 if ( tmp_file ) | 1456 if ( tmp_file ) |
1458 { | 1457 { |
1459 fwrite((const void *)&header, sizeof(LOD::FileHeader), 1, tmp_file); | 1458 fwrite((const void *)&header, sizeof(LOD::FileHeader), 1, tmp_file); |
1460 Lindx.Reset(); | 1459 |
1460 LOD::Directory Lindx; | |
1461 strcpy(Lindx.pFilename, "chapter"); | 1461 strcpy(Lindx.pFilename, "chapter"); |
1462 Lindx.uOfsetFromSubindicesStart=uOffsetToSubIndex; //10h 16 | 1462 Lindx.uOfsetFromSubindicesStart=uOffsetToSubIndex; //10h 16 |
1463 Lindx.uDataSize=sizeof(LOD::Directory) * uNumSubDirs + total_size; //14h 20 | 1463 Lindx.uDataSize=sizeof(LOD::Directory) * uNumSubDirs + total_size; //14h 20 |
1464 Lindx.dword_000018=0; //18h 24 | 1464 Lindx.dword_000018=0; //18h 24 |
1465 Lindx.uNumSubIndices=uNumSubDirs; //1ch 28 | 1465 Lindx.uNumSubIndices=uNumSubDirs; //1ch 28 |
1499 } | 1499 } |
1500 | 1500 |
1501 //----- (00461F71) -------------------------------------------------------- | 1501 //----- (00461F71) -------------------------------------------------------- |
1502 bool LOD::File::AppendDirectory(LOD::Directory *pDir, const void *pData) | 1502 bool LOD::File::AppendDirectory(LOD::Directory *pDir, const void *pData) |
1503 { | 1503 { |
1504 if ( uNumSubDirs < 299 ) | 1504 assert(uNumSubDirs < 299); |
1505 { | 1505 |
1506 memcpy(&pSubIndices[uNumSubDirs], pDir, sizeof(LOD::Directory)); | 1506 memcpy(&pSubIndices[uNumSubDirs++], pDir, sizeof(LOD::Directory)); |
1507 ++uNumSubDirs; | 1507 fwrite(pData, 1, pDir->uDataSize, pOutputFileHandle); |
1508 fwrite(pData, 1u, pDir->uDataSize, pOutputFileHandle); | 1508 return true; |
1509 return true; | |
1510 } | |
1511 else | |
1512 { | |
1513 MessageBoxA(0, "Unable to append item!", "LOD::File", 0x30u); | |
1514 return false; | |
1515 } | |
1516 } | 1509 } |
1517 | 1510 |
1518 | 1511 |
1519 //----- (00461F1E) -------------------------------------------------------- | 1512 //----- (00461F1E) -------------------------------------------------------- |
1520 int LODWriteableFile::CreateTempFile() | 1513 int LODWriteableFile::CreateTempFile() |
1521 { | 1514 { |
1522 int result; // eax@2 | 1515 if (!isFileOpened) |
1523 FILE *pFile; // eax@5; | 1516 return 1; |
1524 if ( isFileOpened ) | 1517 |
1525 { | 1518 if (pIOBuffer && uIOBufferSize ) |
1526 if (pIOBuffer && uIOBufferSize ) | 1519 { |
1527 { | 1520 uCurrentIndexDir = 0; |
1528 uCurrentIndexDir = 0; | 1521 uNumSubDirs = 0; |
1529 uNumSubDirs = 0; | 1522 pOutputFileHandle = fopen("lodapp.tmp", "wb+"); |
1530 pFile = fopen("lodapp.tmp", "wb+"); | 1523 return pOutputFileHandle ? 1 : 7; |
1531 pOutputFileHandle = pFile; | |
1532 result =pFile? 1:7; | |
1533 | |
1534 } | |
1535 else | |
1536 { | |
1537 result = 5; | |
1538 } | |
1539 } | 1524 } |
1540 else | 1525 else |
1541 { | 1526 return 5; |
1542 result = 1; | |
1543 } | |
1544 return result; | |
1545 } | 1527 } |
1546 | 1528 |
1547 | 1529 |
1548 | 1530 |
1549 //----- (00461EE9) -------------------------------------------------------- | 1531 //----- (00461EE9) -------------------------------------------------------- |
1564 // 6A0CA8: using guessed type int 6A0CA8_lod_unused; | 1546 // 6A0CA8: using guessed type int 6A0CA8_lod_unused; |
1565 | 1547 |
1566 | 1548 |
1567 //----- (00461B48) -------------------------------------------------------- | 1549 //----- (00461B48) -------------------------------------------------------- |
1568 unsigned int LODWriteableFile::Write(const LOD::Directory *pDir, const void *pDirData, int a4) | 1550 unsigned int LODWriteableFile::Write(const LOD::Directory *pDir, const void *pDirData, int a4) |
1569 { | 1551 { |
1570 LOD::Directory Lindx; | |
1571 char Filename[256]; | 1552 char Filename[256]; |
1572 char NewFilename[256]; | 1553 char NewFilename[256]; |
1573 FILE *tmp_file; | 1554 FILE *tmp_file; |
1574 int comp_res; | 1555 int comp_res; |
1575 bool bRewrite_data; | 1556 bool bRewrite_data; |
1629 return 5; | 1610 return 5; |
1630 if (!bRewrite_data) | 1611 if (!bRewrite_data) |
1631 size_correction=0; | 1612 size_correction=0; |
1632 else | 1613 else |
1633 size_correction=pSubIndices[insert_index].uDataSize; | 1614 size_correction=pSubIndices[insert_index].uDataSize; |
1615 | |
1634 //create chapter index | 1616 //create chapter index |
1635 Lindx.Reset(); | 1617 LOD::Directory Lindx; |
1636 strcpy(Lindx.pFilename, "chapter"); | 1618 strcpy(Lindx.pFilename, "chapter"); |
1637 Lindx.dword_000018=0; | 1619 Lindx.dword_000018=0; |
1638 Lindx.word_00001E=0; | 1620 Lindx.word_00001E=0; |
1639 Lindx.uNumSubIndices= uNumSubDirs; | 1621 Lindx.uNumSubIndices= uNumSubDirs; |
1640 Lindx.uOfsetFromSubindicesStart=sizeof(LOD::FileHeader)+sizeof(LOD::Directory); | 1622 Lindx.uOfsetFromSubindicesStart=sizeof(LOD::FileHeader)+sizeof(LOD::Directory); |
1721 } | 1703 } |
1722 | 1704 |
1723 | 1705 |
1724 //----- (00461A43) -------------------------------------------------------- | 1706 //----- (00461A43) -------------------------------------------------------- |
1725 bool LODWriteableFile::LoadFile(const char *pFilename, bool bWriting) | 1707 bool LODWriteableFile::LoadFile(const char *pFilename, bool bWriting) |
1726 { | 1708 { |
1727 LOD::Directory lod_indx ; | 1709 if (bWriting & 1) |
1728 | 1710 pFile = fopen(pFilename, "rb"); |
1729 if (bWriting & 1) | 1711 else |
1730 pFile = fopen(pFilename, "rb"); | 1712 pFile = fopen(pFilename, "rb+"); |
1731 else | 1713 if (!pFile) |
1732 pFile = fopen(pFilename, "rb+"); | 1714 return false; |
1733 if (!pFile) | 1715 |
1734 return false; | 1716 strcpy(pLODName, pFilename); |
1735 | 1717 fread(&header, sizeof(LOD::FileHeader), 1, pFile); |
1736 strcpy(pLODName, pFilename); | 1718 |
1737 fread(&header, sizeof(LOD::FileHeader), 1, pFile); | 1719 LOD::Directory lod_indx; |
1738 lod_indx.Reset(); | 1720 fread( &lod_indx,sizeof(LOD::Directory), 1, pFile); |
1739 fread( &lod_indx,sizeof(LOD::Directory), 1, pFile); | 1721 |
1740 fseek(pFile, 0, SEEK_SET); | 1722 fseek(pFile, 0, SEEK_SET); |
1741 isFileOpened = true; | 1723 isFileOpened = true; |
1742 strcpy(pContainerName, "chapter"); | 1724 strcpy(pContainerName, "chapter"); |
1743 uCurrentIndexDir = 0; | 1725 uCurrentIndexDir = 0; |
1744 uLODDataSize = lod_indx.uDataSize; | 1726 uLODDataSize = lod_indx.uDataSize; |
1745 uNumSubDirs = lod_indx.uNumSubIndices; | 1727 uNumSubDirs = lod_indx.uNumSubIndices; |
1746 uOffsetToSubIndex = lod_indx.uOfsetFromSubindicesStart; | 1728 assert(uNumSubDirs <= 300); |
1747 fseek(pFile, uOffsetToSubIndex, SEEK_SET); | 1729 |
1748 | 1730 uOffsetToSubIndex = lod_indx.uOfsetFromSubindicesStart; |
1749 if (uNumSubDirs > 300) | 1731 fseek(pFile, uOffsetToSubIndex, SEEK_SET); |
1750 { | 1732 |
1751 MessageBoxW(0, L"LODchapterPages exceed 300", L"LODFile", MB_ICONEXCLAMATION); | 1733 fread(pSubIndices, sizeof(LOD::Directory), uNumSubDirs, pFile); |
1752 fclose(pFile); | 1734 return true; |
1753 return false; | 1735 } |
1754 } | |
1755 | |
1756 fread(pSubIndices, sizeof(LOD::Directory), uNumSubDirs, pFile); | |
1757 return true; | |
1758 } | |
1759 | 1736 |
1760 | 1737 |
1761 //----- (00461A11) -------------------------------------------------------- | 1738 //----- (00461A11) -------------------------------------------------------- |
1762 void LOD::File::FreeSubIndexAndIO() | 1739 void LOD::File::FreeSubIndexAndIO() |
1763 { | 1740 { |
1857 } | 1834 } |
1858 return true; | 1835 return true; |
1859 } | 1836 } |
1860 | 1837 |
1861 | 1838 |
1862 //----- (004617B6) -------------------------------------------------------- | |
1863 void LOD::FileHeader::Reset() | |
1864 { | |
1865 this->pSignature[0] = 0; | |
1866 this->LodVersion[0] = 0; | |
1867 this->LodDescription[0] = 0; | |
1868 this->LODSize = 0; | |
1869 this->dword_0000A8 = 0; | |
1870 this->uNumIndices = 0; | |
1871 } | |
1872 | |
1873 //----- (00461790) -------------------------------------------------------- | 1839 //----- (00461790) -------------------------------------------------------- |
1874 LOD::File::~File() | 1840 LOD::File::~File() |
1875 { | 1841 { |
1876 LOD::File *v1; // esi@1 | 1842 LOD::File *v1; // esi@1 |
1877 | 1843 |
1898 v1->pSubIndices = 0; | 1864 v1->pSubIndices = 0; |
1899 v1->pIOBuffer = 0; | 1865 v1->pIOBuffer = 0; |
1900 v1->isFileOpened = 0; | 1866 v1->isFileOpened = 0; |
1901 v1->uIOBufferSize = 0; | 1867 v1->uIOBufferSize = 0; |
1902 Close(); | 1868 Close(); |
1903 } | |
1904 | |
1905 | |
1906 //----- (00461743) -------------------------------------------------------- | |
1907 LOD::Directory *LOD::Directory::Reset() | |
1908 { | |
1909 LOD::Directory *result; // eax@1 | |
1910 | |
1911 result = this; | |
1912 this->pFilename[0] = 0; | |
1913 this->uOfsetFromSubindicesStart = 0; | |
1914 this->uDataSize = 0; | |
1915 this->dword_000018 = 0; | |
1916 this->uNumSubIndices = 0; | |
1917 this->word_00001E = 0; | |
1918 return result; | |
1919 } | 1869 } |
1920 | 1870 |
1921 | 1871 |
1922 //----- (0046172B) -------------------------------------------------------- | 1872 //----- (0046172B) -------------------------------------------------------- |
1923 LOD::Directory::Directory() | 1873 LOD::Directory::Directory() |