Plain framework 1 Pak plug-in description (resource compression encryption)

Source: Internet
Author: User

In the development of the Internet, the arrangement of resources has become an urgent task of releasing software applications. unpackaged resources are often exposed and many files make the copy wait time longer. In this case, an application is born, and its origin is from the compression software. This is the packaging plug-in we will introduce today.

Resources package

1. World of Warcraft

2. tianlong Babu

\

3. Jian Xia

4. swordsman

5. Sword 2ol

Pak Source

Pak simple tutorials

Legend

Overview

    1. Explanation
      The Pak package is generally used for packaging and encryption of resources, that is, many files are inserted into a file and compressed and encrypted. It is generally used for packaging and publishing game resources and configurations, such as the World of Warcraft classic mpq resource package.

    2. Category

      • Common data packets. These data packets are generally used directly to read application data.
      • Patch data packets. These data packets are generally used when application data packets need to be updated.
    3. Basic Structure file mark | header data | file data... (basic structure)
      File tag | Baotou data | hashkey table | block table | list information file data | attribute information file data | file data... (Pak structure)

    4. The Baotou data structure refers to a fixed struct, which stores some basic information about the Pak package, such as version information, file size, and file type.

    5. File data structure file block location data | file block data...

    6. As the name suggests, hashkey table stores the file name and is used to locate the index of the file block data.

    7. Block table: array of file block data. You can obtain the data storage location (Pak file), compressed size, uncompressed size, and status mark of the corresponding file block data through the file block data index.

    8. List information file data both common package and patch package have this file, and put it in the first file location, that is, after the block table, it mainly stores the data about the file name.

    9. Attribute information file data both common package and patch package have this file, and put it in the second file location, followed by the list information file, it stores the file version, Tag, CRC32 data, time data, and MD5 data.

    10. File block data and location the file block data location is an array that stores the location of file block data. The file block data is the basic unit of file data, in Pak, the basic size of a file block data is 4096 bytes, that is, 4 K.

    11. The difference between a common package and a patch package is significantly different in size, because the common package will keep the file list information data large enough, therefore, the file data will be allocated to a space of 2 MB, and the patch file will be recorded based on the number of files.

Pak simple code.
#include "pak/interface.h"#include "pak/file.h"#include "pak/util.h"#include "main.h"int32_t main(int32_t argc, char * argv[]) {  uint64_t result = 0;  pak::archive_t *archive = pak::archivecreate("test.pak",                                                result,                                                0x10000,                                                PAK_TYPE_PATCH);  if (NULL == archive) return -1;  pak::fileadd(archive,                "files\\filelist.txt",                "files\\filelist.txt",               PAK_FILE_ENCRYPTED | PAK_FILE_COMPRESS,                0,                pak::kFileTypeData);  pak::fileadd(archive,                "files\\filelist.txt",                "files\\filelist.txt",               PAK_FILE_ENCRYPTED | PAK_FILE_COMPRESS | PAK_FILE_REPLACEEXISTING,                0,                pak::kFileTypeData);  ERRORPRINTF("pak::fileadd end 1.file");  pak::fileadd(archive,                "files\\global.txt",                "2.file",               PAK_FILE_ENCRYPTED | PAK_FILE_COMPRESS,                0,                pak::kFileTypeData);  ERRORPRINTF("pak::fileadd end 2.file");  pak::archive_t *clonearchive = archive->createclone(result);  pak::file_t *file = pak::fileopen(clonearchive, "files\\filelist.txt", result);  DEBUGPRINTF("result: %d", result);  if (!file) return -1;  char *buffer = new char[1024 * 1024];  if (!buffer) return -1;  memset(buffer, 0, 1024 * 1024);  uint64_t readed, size;  size = pak::filesize(file);  ERRORPRINTF("size: %d", size);  pak::fileread(file, buffer, size, &readed);  DEBUGPRINTF("buffer: %s, readed: %d", buffer, readed);  pak::fileeof(file);  pak::fileclose(file);  archive->destoryclone(clonearchive);  pak::archiveclose(archive);  DEBUGPRINTF("1 archiveclose");  uint64_t size, readed;  char *buffer = new char[1024 * 1024];  if (!buffer) return -1;  memset(buffer, 0, 1024 * 1024);  pak::archive_t *archive = pak::archiveopen("test.pak", result, true);  DEBUGPRINTF("result: %d", result);  if (!archive) return -1;  DEBUGPRINTF("archive not NULL");  pak::file_t *file = pak::fileopen(archive, "files\\filelist.txt", result);  if (!file) return -1;  pak::fileread(file, buffer, size, &readed);  DEBUGPRINTF("1 buffer: %s, readed: %d", buffer, readed);  pak::fileeof(file);  pak::fileclose(file);  pak::fileadd(archive,               "files\\task.txt",               "2.file",               PAK_FILE_ENCRYPTED | PAK_FILE_COMPRESS | PAK_FILE_REPLACEEXISTING,               0,               pak::kFileTypeData);  file = pak::fileopen(archive, "2.file", result);  if (!file) return -1;  size = pak::filesize(file);  pak::fileread(file, buffer, size, &readed);  DEBUGPRINTF("1 buffer: %s, readed: %d", buffer, readed);  pak::fileeof(file);  pak::fileclose(file);  pak::archiveclose(archive);  archive = pak::archiveopen("test.pak", result, true);  DEBUGPRINTF("result: %d", result);  if (!archive) return -1;  DEBUGPRINTF("archive not NULL");  file = pak::fileopen(archive, "2.file", result);  if (!file) return -1;  size = pak::filesize(file);  pak::fileread(file, buffer, size, &readed);  DEBUGPRINTF("1 buffer: %s, readed: %d", buffer, readed);  pak::fileclose(file);  pak::fileeof(file);  pak::archiveclose(archive);#if __WINDOWS__  system("pause");#endif  return 0;}
Result.

1. Windows

 

2. Linux

 

Source Code Description

In particular, this part of the source code comes from the classic World of Warcraft mpq package algorithm and kpm, in order to respect the original author's retention of most of the English comments in the source code. The source code, like the comments of the author in the Code, has some strange and insufficient points. You can find a solution to these problems on your own, contact me if you have found a complete solution. In view of the old Code, most of the structure is rewritten without violating the Code work, and supports multi-platform use at the same time, so there is no need to worry about the problems arising from the 64/32-bit use.

Member recruitment (valid for a long term)

If you are also interested in open-source knowledge, if you are also interested in network applications or online games, if you are also interested in this framework, you can join our QQ group (348477824).

You are welcome to join the group for mutual exchange and learning. You are also welcome to share your efforts with this framework.

Plain framework 1 Pak plug-in description (resource compression encryption)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.