BOOL KIniFile::GetNextSection(LPCSTR pSection, LPSTR pNextSection) { if (!pSection[0]) // 传入参数为""时就是取第一个Section { if (!m_Header.pNextNode) return FALSE; else { g_StrCpy(pNextSection, m_Header.pNextNode->pSection); return TRUE; } } else { char szSection[32] = "["; if (pSection[0] != '[') { g_StrCat(szSection, pSection); g_StrCat(szSection, "]"); } else { g_StrCpy(szSection, pSection); } // 查找参数给定的Section SECNODE* pThisSecNode = &m_Header; SECNODE* pNextSecNode = pThisSecNode->pNextNode; DWORD dwID = String2Id(szSection); while (pNextSecNode != NULL) { if (dwID == pNextSecNode->dwID) { break; } pThisSecNode = pNextSecNode; pNextSecNode = pThisSecNode->pNextNode; } // 没有这个Section,无所谓下一个 if (!pNextSecNode) { return FALSE; } else { // 参数给定的Section已经是最后一个了 if (!pNextSecNode->pNextNode) { return FALSE; } else { g_StrCpy(pNextSection, pNextSecNode->pNextNode->pSection); return TRUE; } } } }
//--------------------------------------------------------------------------- // 函数: GetKeyValue // 功能: 取得Key的Value // 参数: pSection 节名 // pKey 建名 // pValue 建值 // 返回: TRUE-成功 FALSE-失败 //--------------------------------------------------------------------------- BOOL KIniFile::GetKeyValue( LPCSTR pSection, LPCSTR pKey, LPSTR pValue, DWORD dwSize) { DWORD dwID; // setup section name char szSection[32] = "["; if (pSection[0] != '[') { g_StrCat(szSection, pSection); g_StrCat(szSection, "]"); } else { g_StrCpy(szSection, pSection); } // search for the matched section SECNODE* pSecNode = m_Header.pNextNode; dwID = String2Id(szSection); while (pSecNode != NULL) { if (dwID == pSecNode->dwID) { break; } pSecNode = pSecNode->pNextNode; } // if no such section founded if (pSecNode == NULL) { return FALSE; } // search for the same key KEYNODE* pKeyNode = pSecNode->pKeyNode.pNextNode; dwID = String2Id(pKey); while (pKeyNode != NULL) { if (dwID == pKeyNode->dwID) { break; } pKeyNode = pKeyNode->pNextNode; } // if no such key found if (pKeyNode == NULL) { return FALSE; } // copy the value of the key g_StrCpyLen(pValue, pKeyNode->pValue, dwSize); return TRUE; }
//--------------------------------------------------------------------------- // 功能:获得某个动作对应的音效文件名 //--------------------------------------------------------------------------- void KNpcResNode::GetActionSoundName(int nAction, char *lpszSoundName) { if (nAction < 0 || nAction >= MAX_ACTION) return; if (!lpszSoundName) return; g_StrCpy(lpszSoundName, m_szSoundName[nAction]); }
//--------------------------------------------------------------------------- // 函数: Str2Column // 功能: 取得某行某列字符串的值 // 参数: szColumn // 返回: 第几列 //--------------------------------------------------------------------------- int KTabFile::Str2Col(LPSTR szColumn) { int nStrLen = g_StrLen(szColumn); char szTemp[4]; g_StrCpy(szTemp, szColumn); g_StrUpper(szTemp); if (nStrLen == 1) { return (szTemp[0] - 'A'); } return ((szTemp[0] - 'A' + 1) * 26 + szTemp[1] - 'A') + 1; }
//--------------------------------------------------------------------------- // 功能: 初始化 //--------------------------------------------------------------------------- BOOL CStateMagicTable::Init() { KTabFile cTabFile; int i; char szBuffer[80], szTemp[80]; // g_SetFilePath(RES_INI_FILE_PATH); if ( !cTabFile.Load(STATE_MAGIC_TABLE_NAME) ) return FALSE; //KNpcResNode Temp; for (i = 0; i < MAX_RES_STATE; i++) { cTabFile.GetString(i + 2, 3, "", szBuffer, sizeof(szBuffer)); if (strcmp(szBuffer, "头顶") == 0) m_nType[i] = STATE_MAGIC_HEAD; else if (strcmp(szBuffer, "脚底") == 0) m_nType[i] = STATE_MAGIC_FOOT; else m_nType[i] = STATE_MAGIC_BODY; cTabFile.GetString(i + 2, 4, "", szBuffer, sizeof(szBuffer)); if (strcmp(szBuffer, "循环") == 0) m_nPlayType[i] = 0; else m_nPlayType[i] = 1; cTabFile.GetInteger(i + 2, 5, 0, &m_nBackStart[i]); cTabFile.GetInteger(i + 2, 6, 0, &m_nBackEnd[i]); cTabFile.GetInteger(i + 2, 7, 1, &m_nTotalFrame[i]); cTabFile.GetInteger(i + 2, 8, 1, &m_nTotalDir[i]); cTabFile.GetInteger(i + 2, 9, 1, &m_nInterVal[i]); cTabFile.GetString(i + 2, 2, "", szTemp, sizeof(szTemp)); g_StrCpy(m_szName[i], szTemp); // Temp.ComposePathAndName(m_szName[i], RES_NPC_STYLE_PATH, szTemp); } return TRUE; }
BOOL KIniFile::GetNextKey(LPCSTR pSection, LPCSTR pKey, LPSTR pNextKey) { char szSection[32] = "["; if (pSection[0] != '[') { g_StrCat(szSection, pSection); g_StrCat(szSection, "]"); } else { g_StrCpy(szSection, pSection); } // 查找参数给定的Section SECNODE* pThisSecNode = &m_Header; SECNODE* pNextSecNode = pThisSecNode->pNextNode; DWORD dwID = String2Id(szSection); while (pNextSecNode != NULL) { if (dwID == pNextSecNode->dwID) { break; } pThisSecNode = pNextSecNode; pNextSecNode = pThisSecNode->pNextNode; } // 没有这个Section,无所谓取Key if (!pNextSecNode) { return FALSE; } KEYNODE* pThisKeyNode = &pNextSecNode->pKeyNode; KEYNODE* pNextKeyNode = pThisKeyNode->pNextNode; // Key给的参数为""的话,取第一个Key if (!pKey[0]) { // 没有Key,返回失败 if (!pNextKeyNode->pKey) { return FALSE; } else { g_StrCpy(pNextKey, pNextKeyNode->pKey); return TRUE; } } dwID = String2Id(pKey); while(pNextKeyNode != NULL) { if (dwID == pNextKeyNode->dwID) { break; } pThisKeyNode = pNextKeyNode; pNextKeyNode = pThisKeyNode->pNextNode; } // 找不到所给的Key,无所谓下一个 if (!pNextKeyNode) { return FALSE; } // 参数给定的Key已经是最后一个了 if (!pNextKeyNode->pNextNode) { return FALSE; } else { g_StrCpy(pNextKey, pNextKeyNode->pNextNode->pKey); return TRUE; } }
//--------------------------------------------------------------------------- // 函数: SetKeyValue // 功能: 设置Key的Value // 参数: pSection 节名 // pKey 建名 // pValue 建值 // 返回: TRUE-成功 FALSE-失败 //--------------------------------------------------------------------------- BOOL KIniFile::SetKeyValue( LPCSTR pSection, LPCSTR pKey, LPCSTR pValue) { int nLen; DWORD dwID; // setup section name char szSection[32] = "["; if (pSection[0] != '[') { g_StrCat(szSection, pSection); g_StrCat(szSection, "]"); } else { g_StrCpy(szSection, pSection); } // search for the matched section SECNODE* pThisSecNode = &m_Header; SECNODE* pNextSecNode = pThisSecNode->pNextNode; dwID = String2Id(szSection); while (pNextSecNode != NULL) { if (dwID == pNextSecNode->dwID) { break; } pThisSecNode = pNextSecNode; pNextSecNode = pThisSecNode->pNextNode; } // if no such section found create a new section if (pNextSecNode == NULL) { nLen = g_StrLen(szSection) + 1; pNextSecNode = (SECNODE *)m_MemStack.Push(sizeof(SECNODE)); pNextSecNode->pSection = (char *)m_MemStack.Push(nLen); g_MemCopy(pNextSecNode->pSection, szSection, nLen); pNextSecNode->dwID = dwID; pNextSecNode->pKeyNode.pNextNode = NULL; pNextSecNode->pNextNode = NULL; pThisSecNode->pNextNode = pNextSecNode; } // search for the same key KEYNODE* pThisKeyNode = &pNextSecNode->pKeyNode; KEYNODE* pNextKeyNode = pThisKeyNode->pNextNode; dwID = String2Id(pKey); while (pNextKeyNode != NULL) { if (dwID == pNextKeyNode->dwID) { break; } pThisKeyNode = pNextKeyNode; pNextKeyNode = pThisKeyNode->pNextNode; } // if no such key found create a new key if (pNextKeyNode == NULL) { pNextKeyNode = (KEYNODE *)m_MemStack.Push(sizeof(KEYNODE)); nLen = g_StrLen(pKey) + 1; pNextKeyNode->pKey = (char *)m_MemStack.Push(nLen); g_MemCopy(pNextKeyNode->pKey, (void*)pKey, nLen); nLen = g_StrLen(pValue) + 1; pNextKeyNode->pValue = (char *)m_MemStack.Push(nLen); g_MemCopy(pNextKeyNode->pValue, (void*)pValue, nLen); pNextKeyNode->dwID = dwID; pNextKeyNode->pNextNode = NULL; pThisKeyNode->pNextNode = pNextKeyNode; } // replace the old value with new else { m_MemStack.Free(pNextKeyNode->pValue); nLen = g_StrLen(pValue) + 1; pNextKeyNode->pValue = (char *)m_MemStack.Push(nLen); g_MemCopy(pNextKeyNode->pValue, (void*)pValue, nLen); } return TRUE; }