PuzzleSDK
TextureAtlasEncryptionTest.cpp
浏览该文件的文档.
1/****************************************************************************
2 Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
3
4 http://www.cocos2d-x.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 THE SOFTWARE.
23 ****************************************************************************/
24
26#include "../testResource.h"
27
29
30TextureAtlasEncryptionTests::TextureAtlasEncryptionTests()
31{
33}
34
36{
37 return "Texture Atlas Encryption";
38}
39
41{
43
44 auto s = Director::getInstance()->getWinSize();
45
46 // Load the non-encrypted atlas
47 SpriteFrameCache::getInstance()->addSpriteFramesWithFile("Images/nonencryptedAtlas.plist", "Images/nonencryptedAtlas.pvr.ccz");
48
49 // Create a sprite from the non-encrypted atlas
50 auto nonencryptedSprite = Sprite::createWithSpriteFrameName("Icon.png");
51 nonencryptedSprite->setPosition(Vec2(s.width * 0.25f, s.height * 0.5f));
52 this->addChild(nonencryptedSprite);
53
54 auto nonencryptedSpriteLabel = Label::createWithTTF("non-encrypted", "fonts/arial.ttf", 28);
55 nonencryptedSpriteLabel->setPosition(Vec2(s.width * 0.25f, nonencryptedSprite->getBoundingBox().getMinY() - nonencryptedSprite->getContentSize().height/2));
56 this->addChild(nonencryptedSpriteLabel, 1);
57
58 // Load the encrypted atlas
59 // 1) Set the encryption keys or step 2 will fail
60 // In this case the encryption key 0xaaaaaaaabbbbbbbbccccccccdddddddd is
61 // split into four parts. See the header docs for more information.
62 ZipUtils::setPvrEncryptionKeyPart(0, 0xaaaaaaaa);
63 ZipUtils::setPvrEncryptionKeyPart(1, 0xbbbbbbbb);
64 ZipUtils::setPvrEncryptionKeyPart(2, 0xcccccccc);
65 ZipUtils::setPvrEncryptionKeyPart(3, 0xdddddddd);
66
67 // Alternatively, you can call the function that accepts the key in a single
68 // function call.
69 // This is slightly less secure because the entire key is more easily
70 // found in the compiled source. See the header docs for more information.
71 // ZipUtils::ccSetPvrEncryptionKey(0xaaaaaaaa, 0xbbbbbbbb, 0xcccccccc, 0xdddddddd);
72
73 // 2) Load the encrypted atlas
74 SpriteFrameCache::getInstance()->addSpriteFramesWithFile("Images/encryptedAtlas.plist", "Images/encryptedAtlas.pvr.ccz");
75
76 // 3) Create a sprite from the encrypted atlas
77 auto encryptedSprite = Sprite::createWithSpriteFrameName("powered.png");
78 encryptedSprite->setPosition(Vec2(s.width * 0.75f, s.height * 0.5f));
79 this->addChild(encryptedSprite);
80
81 auto encryptedSpriteLabel = Label::createWithTTF("encrypted", "fonts/arial.ttf", 28);
82 encryptedSpriteLabel->setPosition(Vec2(s.width * 0.75f, encryptedSprite->getBoundingBox().getMinY() - encryptedSpriteLabel->getContentSize().height/2));
83 this->addChild(encryptedSpriteLabel, 1);
84}
#define ADD_TEST_CASE(__className__)
Definition: BaseTest.h:211
virtual void onEnter() override
Definition: BaseTest.cpp:430
virtual std::string title() const override