2014-06-05 10:24:12 +08:00
|
|
|
|
/****************************************************************************
|
|
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
|
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "CocoLoader.h"
|
|
|
|
|
|
|
|
|
|
namespace cocostudio {
|
|
|
|
|
const char* kTypeNames[] = { "Null", "False", "True", "Object", "Array", "String", "Number" };
|
|
|
|
|
const char* kObjKeyName[] = { "__type" , "classname" };
|
|
|
|
|
char g_Buff[2048];
|
|
|
|
|
|
|
|
|
|
rapidjson::Type stExpCocoNode::GetType(CocoLoader* pCoco)
|
|
|
|
|
{
|
|
|
|
|
rapidjson::Type tType = rapidjson::kObjectType;
|
|
|
|
|
if(m_ObjIndex >= 0)
|
|
|
|
|
{
|
|
|
|
|
stExpCocoObjectDesc* tpCocoObjectDesc = pCoco->GetCocoObjectDesc();
|
|
|
|
|
if( m_AttribIndex >= 0 )
|
|
|
|
|
{
|
2014-06-11 09:35:24 +08:00
|
|
|
|
stExpCocoAttribDesc* tpAttribDescArray = (stExpCocoAttribDesc*) tpCocoObjectDesc[m_ObjIndex].m_pAttribDescArray;
|
|
|
|
|
tType = tpAttribDescArray[m_AttribIndex].m_Type;
|
|
|
|
|
if(rapidjson::kFalseType == tType || rapidjson::kTrueType == tType)
|
2014-06-05 10:24:12 +08:00
|
|
|
|
{
|
2014-06-11 09:35:24 +08:00
|
|
|
|
char* szValue = (char*)m_szValue;
|
|
|
|
|
if(szValue[0] == '0')
|
2014-06-05 10:24:12 +08:00
|
|
|
|
{
|
|
|
|
|
return rapidjson::kFalseType;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return rapidjson::kTrueType;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
tType = rapidjson::kObjectType;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if(m_AttribIndex >= 0)
|
|
|
|
|
{
|
|
|
|
|
// char* pStringAddr = (char*)pCoco->GetCocoObjectDesc() + pCoco->GetFileHeader()->m_lStringMemAddr ;
|
|
|
|
|
tType = (rapidjson::Type)m_ChildNum;
|
|
|
|
|
|
|
|
|
|
if(rapidjson::kFalseType == tType || rapidjson::kTrueType == tType)
|
|
|
|
|
{
|
2014-06-11 09:35:24 +08:00
|
|
|
|
char* szValue = (char*)m_szValue;
|
|
|
|
|
if(szValue[0] == '0')
|
2014-06-05 10:24:12 +08:00
|
|
|
|
{
|
|
|
|
|
return rapidjson::kFalseType;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return rapidjson::kTrueType;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
tType = rapidjson::kArrayType;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return tType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char* stExpCocoNode::GetName(CocoLoader* pCoco)
|
|
|
|
|
{
|
|
|
|
|
char* szName = NULL ;
|
|
|
|
|
if(m_ObjIndex >= 0)
|
|
|
|
|
{
|
|
|
|
|
stExpCocoObjectDesc* tpCocoObjectDesc = pCoco->GetCocoObjectDesc();
|
|
|
|
|
if( m_AttribIndex >= 0 )
|
|
|
|
|
{
|
2014-06-11 09:35:24 +08:00
|
|
|
|
stExpCocoAttribDesc* tpAttribDescArray = (stExpCocoAttribDesc*) tpCocoObjectDesc[m_ObjIndex].m_pAttribDescArray;
|
|
|
|
|
szName = (char*)tpAttribDescArray[m_AttribIndex].m_szName;
|
2014-06-05 10:24:12 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
|
2014-06-11 09:35:24 +08:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʋ<EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵֵ<CAB5><D6B5><EFBFBD><EFBFBD>
|
|
|
|
|
char* szValue = (char*)m_szValue;
|
|
|
|
|
if(szValue[0])
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
szName = (char*)m_szValue;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//<2F>ṹ
|
|
|
|
|
szName = (char*)tpCocoObjectDesc[m_ObjIndex].m_szName;
|
|
|
|
|
}
|
2014-06-05 10:24:12 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-06-11 09:35:24 +08:00
|
|
|
|
if(m_AttribIndex >= 0)
|
|
|
|
|
{
|
|
|
|
|
char* pStringAddr = (char*)pCoco->GetCocoObjectDesc() + pCoco->GetFileHeader()->m_lStringMemAddr ;
|
|
|
|
|
szName = m_ChildArray + pStringAddr;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
szName = (char*)m_szValue;
|
|
|
|
|
}
|
2014-06-05 10:24:12 +08:00
|
|
|
|
}
|
|
|
|
|
return szName ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char* stExpCocoNode::GetValue()
|
|
|
|
|
{
|
2014-06-11 09:35:24 +08:00
|
|
|
|
return (char*)m_szValue;
|
2014-06-05 10:24:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int stExpCocoNode::GetChildNum()
|
|
|
|
|
{
|
2014-06-11 09:35:24 +08:00
|
|
|
|
return m_ChildNum;
|
2014-06-05 10:24:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stExpCocoNode* stExpCocoNode::GetChildArray()
|
|
|
|
|
{
|
2014-06-11 09:35:24 +08:00
|
|
|
|
return (stExpCocoNode*)m_ChildArray;
|
2014-06-05 10:24:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void stExpCocoNode::ReBuild(char* pCocoNodeAddr,char* pStringMemoryAddr)
|
|
|
|
|
{
|
2014-06-11 09:35:24 +08:00
|
|
|
|
m_szValue = m_szValue + (uint64_t)pStringMemoryAddr;
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>飬<EFBFBD><E9A3AC><EFBFBD><EFBFBD><EFBFBD>ӽ<EFBFBD><D3BD><EFBFBD>
|
|
|
|
|
if( -1 == m_AttribIndex )
|
|
|
|
|
{
|
|
|
|
|
if(m_ChildNum > 0)
|
|
|
|
|
{
|
|
|
|
|
m_ChildArray = m_ChildArray + (uint64_t)pCocoNodeAddr;
|
|
|
|
|
|
|
|
|
|
stExpCocoNode* tpChildArray = (stExpCocoNode*)m_ChildArray;
|
|
|
|
|
for(int i = 0 ; i < m_ChildNum ; i++)
|
|
|
|
|
{
|
|
|
|
|
tpChildArray[i].ReBuild(pCocoNodeAddr,pStringMemoryAddr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-05 10:24:12 +08:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CocoLoader::CocoLoader()
|
|
|
|
|
{
|
|
|
|
|
m_pRootNode = NULL;
|
|
|
|
|
m_pObjectDescArray = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CocoLoader::~CocoLoader()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CocoLoader::ReadCocoBinBuff(char* pBinBuff)
|
|
|
|
|
{
|
|
|
|
|
//Type
|
|
|
|
|
char* pTempBuff = pBinBuff;
|
|
|
|
|
|
|
|
|
|
m_pFileHeader = (stCocoFileHeader*)pTempBuff;
|
|
|
|
|
pTempBuff += sizeof(stCocoFileHeader);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char* pStartAddr = pTempBuff;
|
|
|
|
|
m_pObjectDescArray = (stExpCocoObjectDesc*)pStartAddr;
|
|
|
|
|
|
|
|
|
|
char* pAttrAddr = pStartAddr + m_pFileHeader->m_lAttribMemAddr ;
|
|
|
|
|
char* pCocoMemAddr = pStartAddr + m_pFileHeader->m_CocoNodeMemAddr;
|
|
|
|
|
char* pStringAddr = pStartAddr + m_pFileHeader->m_lStringMemAddr ;
|
|
|
|
|
|
|
|
|
|
m_pRootNode = (stExpCocoNode*)pCocoMemAddr;
|
2014-06-11 09:35:24 +08:00
|
|
|
|
|
2014-06-05 10:24:12 +08:00
|
|
|
|
if(1 == m_pFileHeader->m_nFirstUsed)
|
|
|
|
|
{
|
|
|
|
|
for(int i = 0 ; i < m_pFileHeader->m_ObjectCount ; i++)
|
|
|
|
|
{
|
|
|
|
|
m_pObjectDescArray[i].ReBuild(pAttrAddr,pStringAddr) ;
|
|
|
|
|
}
|
|
|
|
|
m_pRootNode->ReBuild(pCocoMemAddr,pStringAddr);
|
|
|
|
|
|
|
|
|
|
m_pFileHeader->m_nFirstUsed = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|