From 4eb243c21d377ee7275817d173c8cea5f3434a5d Mon Sep 17 00:00:00 2001 From: Wanne Date: Tue, 18 Feb 2014 07:14:17 +0000 Subject: [PATCH] Merged from revision: 6937 - Added support for language specific *.AttachmentSlots.xml files git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@6938 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Init.cpp | 11 +++++++- Tactical/XML.h | 2 +- Tactical/XML_AttachmentSlots.cpp | 46 ++++++++++++++++++++------------ 3 files changed, 40 insertions(+), 19 deletions(-) diff --git a/Init.cpp b/Init.cpp index 3bd512b2..e2f6fc59 100644 --- a/Init.cpp +++ b/Init.cpp @@ -470,7 +470,16 @@ BOOLEAN LoadExternalGameplayData(STR directoryName) //WarmSteel - Attachment slots related xml's strcpy(fileName, directoryName); strcat(fileName, ATTACHMENTSLOTSFILENAME); - SGP_THROW_IFFALSE(ReadInAttachmentSlotsStats(fileName),ATTACHMENTSLOTSFILENAME); + SGP_THROW_IFFALSE(ReadInAttachmentSlotsStats(fileName, FALSE),ATTACHMENTSLOTSFILENAME); + + #ifndef ENGLISH + AddLanguagePrefix(fileName); + if ( FileExists(fileName) ) + { + DebugMsg (TOPIC_JA2,DBG_LEVEL_3,String("LoadExternalGameplayData, fileName = %s", fileName)); + SGP_THROW_IFFALSE(ReadInAttachmentSlotsStats(fileName,TRUE), fileName); + } + #endif // Flugente: created separate gun and item choices for different soldier classes - read in different xmls strcpy(fileName, directoryName); diff --git a/Tactical/XML.h b/Tactical/XML.h index b998b199..1650324e 100644 --- a/Tactical/XML.h +++ b/Tactical/XML.h @@ -337,7 +337,7 @@ extern BOOLEAN WriteIncompatibleAttachmentStats(); extern BOOLEAN ReadInIncompatibleAttachmentStats(STR fileName); //WarmSteel - for New Attachment System extern BOOLEAN WriteAttachmentSlotsStats(); -extern BOOLEAN ReadInAttachmentSlotsStats(STR fileName); +extern BOOLEAN ReadInAttachmentSlotsStats(STR fileName, BOOLEAN localizedVersion); extern BOOLEAN WriteExtendedArmyGunChoicesStats(); extern BOOLEAN ReadInExtendedArmyGunChoicesStats(ARMY_GUN_CHOICE_TYPE* pGunChoice, STR fileName); diff --git a/Tactical/XML_AttachmentSlots.cpp b/Tactical/XML_AttachmentSlots.cpp index 776198c9..fa03b472 100644 --- a/Tactical/XML_AttachmentSlots.cpp +++ b/Tactical/XML_AttachmentSlots.cpp @@ -27,6 +27,8 @@ struct } typedef attachmentslotParseData; +BOOLEAN localizedTextOnly_AttachmentSlots; + static void XMLCALL attachmentslotStartElementHandle(void *userData, const XML_Char *name, const XML_Char **atts) { @@ -38,7 +40,9 @@ attachmentslotStartElementHandle(void *userData, const XML_Char *name, const XML { pData->curElement = ELEMENT_LIST; - memset(pData->curArray,0,sizeof(AttachmentSlotStruct)*pData->maxArraySize); + // WANNE: Only init memory, when we read the complete data, otherwise the data will be erased! + if (!localizedTextOnly_AttachmentSlots) + memset(pData->curArray,0,sizeof(AttachmentSlotStruct)*pData->maxArraySize); pData->maxReadDepth++; //we are not skipping this element } @@ -46,7 +50,9 @@ attachmentslotStartElementHandle(void *userData, const XML_Char *name, const XML { pData->curElement = ELEMENT; - memset(&pData->curAttachmentSlot,0,sizeof(AttachmentSlotStruct)); + // WANNE: Only init memory, when we read the complete data, otherwise the data will be erased! + if (!localizedTextOnly_AttachmentSlots) + memset(&pData->curAttachmentSlot,0,sizeof(AttachmentSlotStruct)); pData->maxReadDepth++; //we are not skipping this element } @@ -102,12 +108,21 @@ attachmentslotEndElementHandle(void *userData, const XML_Char *name) pData->curElement = ELEMENT_LIST; if(pData->curAttachmentSlot.uiSlotIndex < pData->maxArraySize) - { - pData->curArray[pData->curAttachmentSlot.uiSlotIndex] = pData->curAttachmentSlot; //write the attachmentinfo into the table - //Save the highest known index up till now. - if(LAST_SLOT_INDEX < pData->curAttachmentSlot.uiSlotIndex){ - LAST_SLOT_INDEX = (UINT16) pData->curAttachmentSlot.uiSlotIndex; + { + if (!localizedTextOnly_AttachmentSlots) + { + pData->curArray[pData->curAttachmentSlot.uiSlotIndex] = pData->curAttachmentSlot; //write the attachmentinfo into the table + + //Save the highest known index up till now. + if(LAST_SLOT_INDEX < pData->curAttachmentSlot.uiSlotIndex) + { + LAST_SLOT_INDEX = (UINT16) pData->curAttachmentSlot.uiSlotIndex; + } } + else + { + wcscpy(AttachmentSlots[pData->curAttachmentSlot.uiSlotIndex].szSlotName, pData->curAttachmentSlot.szSlotName); + } } } else if(strcmp(name, "uiSlotIndex") == 0) @@ -164,7 +179,7 @@ attachmentslotEndElementHandle(void *userData, const XML_Char *name) } -BOOLEAN ReadInAttachmentSlotsStats(STR fileName) +BOOLEAN ReadInAttachmentSlotsStats(STR fileName, BOOLEAN localizedVersion) { HWFILE hFile; UINT32 uiBytesRead; @@ -174,6 +189,8 @@ BOOLEAN ReadInAttachmentSlotsStats(STR fileName) attachmentslotParseData pData; + localizedTextOnly_AttachmentSlots = localizedVersion; + DebugMsg(TOPIC_JA2, DBG_LEVEL_3, "Loading AttachmentSlots.xml" ); // Open attachmentinfo file @@ -195,24 +212,21 @@ BOOLEAN ReadInAttachmentSlotsStats(STR fileName) FileClose( hFile ); - XML_SetElementHandler(parser, attachmentslotStartElementHandle, attachmentslotEndElementHandle); XML_SetCharacterDataHandler(parser, attachmentslotCharacterDataHandle); - // This should fix the crash in a Release Version with VS 2008 //memset(&pData,0,sizeof(pData)); + pData.curElement = ELEMENT_NONE; pData.szCharData[0] = 0; pData.currentDepth = 0; pData.maxReadDepth = 0; - pData.curArray = AttachmentSlots; - pData.maxArraySize = MAXITEMS; - - + pData.curArray = AttachmentSlots; + pData.maxArraySize = MAXITEMS; + XML_SetUserData(parser, &pData); - if(!XML_Parse(parser, lpcBuffer, uiFSize, TRUE)) { CHAR8 errorBuf[511]; @@ -226,9 +240,7 @@ BOOLEAN ReadInAttachmentSlotsStats(STR fileName) MemFree(lpcBuffer); - XML_ParserFree(parser); - return( TRUE ); }