This article describes some of the encryption tips for developing mobile games using Cocos2d-x. If you have any questions, please correct me.
For more information, see: http://blog.csdn.net/chengyingzhilian/article/details/25540441
This address: http://blog.csdn.net/chengyingzhilian/article/details/25076419
Okay, here's the subject of this article-- Resource Encryption :
the packaging of picture resources is of course used It's texturepacker . official website:Http://www.codeandweb.com/texturepacker
Personally feel is the 2d inside the best resource packaging tool, not one.
Texturepacker It is a tool for splicing several resource images into a larger image. Texturepacker can directly select a folder, the small image inside to generate a large picture, and output the Plist file tool. With this tool, the diagram is very simple. Texturepacker comes with the ability to encrypt resources.
about how to use. Don't dwell on it here. You can search for tutorials yourself.
Here I would like to explain what is rarely mentioned on the two dot Web:
1. Command line.
2. Encryption.
One, the command line Texturepacker interface settings can be executed entirely on the command line. The advantage is that you can batch picture resources. Pre-resources are not compressed and encrypted. You only need to replace the compressed picture later. Batch with the command line. Very, very convenient.1. Install the command line. after the Texturepacker is installed by default, the command line is not configured to the system environment. The configuration method is as follows:Click the title bar Texturepacker, and select Install command line. Can. a few common parameter information of 2.TexturePackerThe following is a Texturepackersome commonParameter information. Detailed parameters can be entered directly in the terminal Texturepacker
You can specify one or more. png or. tps files or directories for processing. <folder> recursively adds all known files in the sprite sheet <*.tps> * . tps file created with Texturepackerpro (requires Pro license) Additional SET options Overrid e settings in the *.tps file <*.swf> Flash requires Pro license <images> Image formats, Supported:output:--sheet <filename> Name of the sheet to write, see Texture-format F or formats available--texture-format <id> sets the format for the textures. The format type is automatically derived from the sheet ' s file name if possible. --data <filename> Name of the data file to write--format <format> format to write, Defau LT is cocos2d--force-publish Ignore Smart Update hash and force re-Publishing of the files--texturepath <path> Adds The path to the texture file name stored in the data file. Use this if your sprite sheets is not stored in another folder than your data files. --reduce-border-artifacts removes dark shadows around sprites--extrude <int> extrudes the Sprites by Given value of pixels to fix flickering problems in tiles maps--scale <float> Scales all images before Creating the sheet. e.g. use 0.5 for half size--scale-mode <mode> use mode for scaling:
Two, image encryption Next, some of the techniques of resource encryption, about image encryption in fact, Texturepacker official has detailed instructions, the Official document has a complete introduction .
Http://www.codeandweb.com/texturepacker/contentprotection
However, the Cocosbuilder author has no longer maintained the builder. So the tutorial corresponding to the Cocos2d 2.x is somewhat outdated. so here's a bit of a re-wordy.
1. Preview of the effect:
First look at the effect of the resource bundle encryption vs unencrypted preview:
VS
with Texturepacker encryption, resources cannot be looked at. Ps: In the development process, you can use the development of unencrypted resources, and then packaging the release, the use of command-line batch processing once. 2. Resource Encryption steps:1. Click the lock icon next to Contentprotection. Pop-up Lock window:
You need to fill out a 32-bit key (0-9 a-f)
- Create new key is the system random key
- Clear/disable Enable/disable image encryption function
- Save As global key takes the key as the global key and later encrypts the other image directly using global key.
- Use global key is used to save the globally available key.
2.Save
3.Publish
the next steps are different from the official introduction: The main thing is that 3.0 has integrated the Image encryption feature .
First you need to know:
If your keys are aaaaaaaabbbbbbbbccccccccdddddddd, you must divide them into 4 parts per part 8 bits:
0xAAAAAAAA
0xBBBBBBBB
0xCCCCCCCC
0xDDDDDDDD
The method presented on the Texturepacker website is to download the Ziputils file that it provides to replace COCOS2DX. In the latest version of the COCOS2DX ziputils has integrated the processing of texturepacker decryption, so there is no need to follow its steps to deal with. Ps: Cocos2dx Lib will be faulted after downloading its ziputils copy replacement. we can use the coco2d-x-3.0 directly. The following is the source code to decrypt it:
Cocos2dx/support/zip_support/ziputils.h/** Sets the PVR.CCZ encryption key. * * Example:if the key used to encrypt the Pvr.ccz file was * 0xaaaaaaaabbbbbbbbccccccccdddddddd you'll CA ll this function with * The key split into 4 parts as follows * * Ziputils::ccsetpvrencryptionkey (0xa AAAAAAA, 0XBBBBBBBB, 0XCCCCCCCC, 0xdddddddd); * * Note that using this function makes it easier to reverse engineer and * Discover the complete key Becaus E The key parts is present in one * function call. * * Important:be sure to call Ccsetpvrencryptionkey or * Ccsetpvrencryptionkeypart with all of the key part s *before* loading * The Spritesheet or decryption would fail and the spritesheet * would fail to load. * * @param keyPart1 The key value Part 1. * @param keyPart2 The key value Part 2. * @param keyPart3 The key value Part 3. * @param keyPart4 the key value part 4. */static void Ccsetpvrencryptionkey (unsigned int keyPart1, unsigned int keyPart2, unsigned int keyPart3 , unsigned int keyPart4);
Ps: There are other similar functions in Ziputils. Use one of them. Call:
We add the following code to the AppDelegate.cpp applicationdidfinishlaunching function:
Ziputils::ccsetpvrencryptionkey (0x12345678,0x87654321,0x12345678,0x87654321);
You can use the resources normally.
here is the test code for LUA using resources:
Require "cocos2d" Cclog = function (...) Print (String.Format (...)) end--for Ccluaengine tracebackfunction __g__trackback__ (msg) cclog ("----------------------------------------") Cclo G ("LUA ERROR:"). ToString (msg): "\ n") Cclog (Debug.traceback ()) Cclog ("----------------------------------------") endlocal function Createshowspritescene () cc. Spriteframecache:getinstance (): Addspriteframes ("Files/sprite.plist") Local showsprite = cc. Sprite:createwithspriteframename ("Success_1.png") showsprite:setposition (CC.P (200,200)) return showSpriteendlocal function Main ()--Avoid memory leak collectgarbage ("setpause", +) CollectGarbage ("Setstepmul", lo) Cal scene = cc. Scene:create () Local layer = Createshowspritescene () scene:addchild (layer) cc. Director:getinstance (): Runwithscene (Scene) Endxpcall (Main, __g__trackback__)
when we comment on AppDelegate.cpp, add the code after: will report the following error: