2018-01-29 16:25:32 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-07-09 22:23:34 +08:00
|
|
|
https://axis-project.github.io/
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-04-26 01:40:49 +08:00
|
|
|
#include "TextureAtlasEncryptionTest.h"
|
|
|
|
#include "../testResource.h"
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
USING_NS_AX;
|
2015-04-09 08:37:30 +08:00
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
TextureAtlasEncryptionTests::TextureAtlasEncryptionTests()
|
2013-04-26 01:40:49 +08:00
|
|
|
{
|
2015-04-03 14:31:03 +08:00
|
|
|
ADD_TEST_CASE(TextureAtlasEncryptionDemo);
|
2013-04-26 01:40:49 +08:00
|
|
|
}
|
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
std::string TextureAtlasEncryptionDemo::title() const
|
2013-04-26 01:40:49 +08:00
|
|
|
{
|
2015-04-03 14:31:03 +08:00
|
|
|
return "Texture Atlas Encryption";
|
2013-04-26 01:40:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextureAtlasEncryptionDemo::onEnter()
|
|
|
|
{
|
2015-04-03 14:31:03 +08:00
|
|
|
TestCase::onEnter();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2015-04-09 16:23:29 +08:00
|
|
|
|
2013-04-26 01:40:49 +08:00
|
|
|
// Load the non-encrypted atlas
|
2021-12-28 16:06:23 +08:00
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("Images/nonencryptedAtlas.plist",
|
|
|
|
"Images/nonencryptedAtlas.pvr.ccz");
|
|
|
|
|
2013-04-26 01:40:49 +08:00
|
|
|
// Create a sprite from the non-encrypted atlas
|
2013-08-16 16:05:27 +08:00
|
|
|
auto nonencryptedSprite = Sprite::createWithSpriteFrameName("Icon.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
nonencryptedSprite->setPosition(Vec2(s.width * 0.25f, s.height * 0.5f));
|
2013-04-26 01:40:49 +08:00
|
|
|
this->addChild(nonencryptedSprite);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-04-09 23:31:05 +08:00
|
|
|
auto nonencryptedSpriteLabel = Label::createWithTTF("non-encrypted", "fonts/arial.ttf", 28);
|
2021-12-28 16:06:23 +08:00
|
|
|
nonencryptedSpriteLabel->setPosition(Vec2(s.width * 0.25f, nonencryptedSprite->getBoundingBox().getMinY() -
|
|
|
|
nonencryptedSprite->getContentSize().height / 2));
|
2013-04-26 01:40:49 +08:00
|
|
|
this->addChild(nonencryptedSpriteLabel, 1);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2013-04-26 01:40:49 +08:00
|
|
|
// Load the encrypted atlas
|
|
|
|
// 1) Set the encryption keys or step 2 will fail
|
2013-05-07 22:14:38 +08:00
|
|
|
// In this case the encryption key 0xaaaaaaaabbbbbbbbccccccccdddddddd is
|
|
|
|
// split into four parts. See the header docs for more information.
|
2013-11-12 10:09:47 +08:00
|
|
|
ZipUtils::setPvrEncryptionKeyPart(0, 0xaaaaaaaa);
|
|
|
|
ZipUtils::setPvrEncryptionKeyPart(1, 0xbbbbbbbb);
|
|
|
|
ZipUtils::setPvrEncryptionKeyPart(2, 0xcccccccc);
|
|
|
|
ZipUtils::setPvrEncryptionKeyPart(3, 0xdddddddd);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2013-05-07 22:14:38 +08:00
|
|
|
// Alternatively, you can call the function that accepts the key in a single
|
|
|
|
// function call.
|
|
|
|
// This is slightly less secure because the entire key is more easily
|
|
|
|
// found in the compiled source. See the header docs for more information.
|
|
|
|
// ZipUtils::ccSetPvrEncryptionKey(0xaaaaaaaa, 0xbbbbbbbb, 0xcccccccc, 0xdddddddd);
|
|
|
|
|
2013-04-26 01:40:49 +08:00
|
|
|
// 2) Load the encrypted atlas
|
2021-12-28 16:06:23 +08:00
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("Images/encryptedAtlas.plist",
|
|
|
|
"Images/encryptedAtlas.pvr.ccz");
|
|
|
|
|
2013-04-26 01:40:49 +08:00
|
|
|
// 3) Create a sprite from the encrypted atlas
|
2013-08-16 16:05:27 +08:00
|
|
|
auto encryptedSprite = Sprite::createWithSpriteFrameName("powered.png");
|
2014-05-15 01:07:09 +08:00
|
|
|
encryptedSprite->setPosition(Vec2(s.width * 0.75f, s.height * 0.5f));
|
2013-04-26 01:40:49 +08:00
|
|
|
this->addChild(encryptedSprite);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-04-09 23:31:05 +08:00
|
|
|
auto encryptedSpriteLabel = Label::createWithTTF("encrypted", "fonts/arial.ttf", 28);
|
2021-12-28 16:06:23 +08:00
|
|
|
encryptedSpriteLabel->setPosition(Vec2(s.width * 0.75f, encryptedSprite->getBoundingBox().getMinY() -
|
|
|
|
encryptedSpriteLabel->getContentSize().height / 2));
|
2013-04-26 01:40:49 +08:00
|
|
|
this->addChild(encryptedSpriteLabel, 1);
|
|
|
|
}
|