Subversion Repositories spk

Rev

Rev 165 | Rev 171 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 165 Rev 170
Line 11... Line 11...
11
									Utils::CList<STypesSection> list;		\
11
									Utils::CList<STypesSection> list;		\
12
									ADDSECTIONLIST(T, L);					\
12
									ADDSECTIONLIST(T, L);					\
13
									data = CXspFile::TypesListToString(list, true); \
13
									data = CXspFile::TypesListToString(list, true); \
14
								}
14
								}
15
 
15
 
16
#define GENERATESTRINGSECTION(F, L, FIRST) if ( !L.Empty() ) {				\
16
#define GENERATESTRINGSECTION(F, L, FIRST) if ( !L.empty() ) {				\
17
									type = F;								\
17
									type = F;								\
18
									Utils::CList<STypesSection> list;		\
18
									Utils::CList<STypesSection> list;		\
19
									_addDataSection(L, list, FIRST);		\
19
									_addDataSection(L, list, FIRST);		\
20
									data = CXspFile::TypesListToString(list, true); \
20
									data = CXspFile::TypesListToString(list, true); \
21
								}
21
								}
Line 41... Line 41...
41
	for ( CListNode<SCockpit> *n = m_lCockpit.Front(); n; n = n->next() )
41
	for ( CListNode<SCockpit> *n = m_lCockpit.Front(); n; n = n->next() )
42
		n->Data()->lWeaponMask.MemoryClear();
42
		n->Data()->lWeaponMask.MemoryClear();
43
	m_lCockpit.MemoryClear();
43
	m_lCockpit.MemoryClear();
44
	m_lCockpit.destroy();
44
	m_lCockpit.destroy();
45
	_lCutData.clear();
45
	_lCutData.clear();
46
	m_lBodies.Clear();
46
	_lBodies.clear();
-
 
47
	_lAnimations.clear();
47
}
48
}
48
 
49
 
49
void CXspFile::SetDefaults ()
50
void CXspFile::SetDefaults ()
50
{
51
{
51
	CBaseFile::SetDefaults ();
52
	CBaseFile::SetDefaults ();
Line 222... Line 223...
222
 
223
 
223
	for ( CListNode<SWeaponMask> *wNode = m_lWeaponMasks.Front(); wNode; wNode = wNode->next() )
224
	for ( CListNode<SWeaponMask> *wNode = m_lWeaponMasks.Front(); wNode; wNode = wNode->next() )
224
		values += Utils::String("WeaponMask: ") + (long)wNode->Data()->iGame + " " + (long)wNode->Data()->iMask + "\n";
225
		values += Utils::String("WeaponMask: ") + (long)wNode->Data()->iGame + " " + (long)wNode->Data()->iMask + "\n";
225
	for ( CListNode<SWeaponMask> *mNode = m_lMissileMasks.Front(); mNode; mNode = mNode->next() )
226
	for ( CListNode<SWeaponMask> *mNode = m_lMissileMasks.Front(); mNode; mNode = mNode->next() )
226
		values += Utils::String("MissileMask: ") + (long)mNode->Data()->iGame + " " + (long)mNode->Data()->iMask + "\n";
227
		values += Utils::String("MissileMask: ") + (long)mNode->Data()->iGame + " " + (long)mNode->Data()->iMask + "\n";
227
	for(auto itr = _lCutData.begin(); itr != _lCutData.end(); itr++)
228
	for (auto itr = _lCutData.begin(); itr != _lCutData.end(); itr++)
228
		values += "CutData: " + (*itr)->str + "\n";
229
		values += "CutData: " + (*itr)->str + "\n";
229
	for ( SStringList *body = m_lBodies.Head(); body; body = body->;next )
230
	for (auto itr = _lBodies.begin(); itr != _lBodies.end(); itr++)
230
		values += Utils::String("Bodies: ";) + body->str.ToString() + "\n";
231
		values += "Bodies: "; + (*itr)->str + "\n";
231
	for ( SStringList *ani = m_lAnimations.Head(); ani; ani = ani->;next )
232
	for (auto itr = _lAnimations.begin(); itr != _lAnimations.end(); itr++)
232
		values += Utils::String("Animations: ";) + ani->str.ToString() + "\n";
233
		values += "Animations: "; + (*itr)->str + "\n";
233
 
234
 
234
	return values;
235
	return values;
235
}
236
}
236
 
237
 
237
bool CXspFile::ParseValueLine(const Utils::String &sLine)
238
bool CXspFile::ParseValueLine(const Utils::String &sLine)
Line 252... Line 253...
252
	else if ( first.Compare("Shipyard") )
253
	else if ( first.Compare("Shipyard") )
253
		m_iShipyard = rest;
254
		m_iShipyard = rest;
254
	else if ( first.Compare("CutData") )
255
	else if ( first.Compare("CutData") )
255
		this->addCutData(rest);
256
		this->addCutData(rest);
256
	else if ( first.Compare("Bodies") )
257
	else if ( first.Compare("Bodies") )
257
		this->AddBodies(rest);
258
		this->addBodies(rest);
258
	else if ( first.Compare("Animations") )
259
	else if ( first.Compare("Animations") )
259
		this->AddAnimation(rest);
260
		this->addAnimation(rest);
260
	else if ( first.Compare("Cockpit") )
261
	else if ( first.Compare("Cockpit") )
261
		this->AddCockpit(rest, 0);
262
		this->AddCockpit(rest, 0);
262
	else if ( first.Compare("CockpitNew") )
263
	else if ( first.Compare("CockpitNew") )
263
	{
264
	{
264
		Utils::String cockpit = rest.tokens(" ", 2);
265
		Utils::String cockpit = rest.tokens(" ", 2);
Line 325... Line 326...
325
			}
326
			}
326
		}
327
		}
327
	}
328
	}
328
 
329
 
329
	if ( name.empty() )
330
	if ( name.empty() )
330
		name = GetLanguageName(lang).ToString();
331
		name = getLanguageName(lang);
331
 
332
 
332
	return name;
333
	return name;
333
}
334
}
334
 
335
 
335
//TODO: split this up
336
//TODO: split this up
Line 399... Line 400...
399
		else if ( first.Compare("ScreenShot") )
400
		else if ( first.Compare("ScreenShot") )
400
		{
401
		{
401
			int size = rest.token(" ", 1);
402
			int size = rest.token(" ", 1);
402
			Utils::String ext = rest.token(" ", 2);
403
			Utils::String ext = rest.token(" ", 2);
403
 
404
 
404
			C_File *newFile = this->AddFile(m_sID + "_" + (long)(this->CountFiles(FILETYPE_SCREEN) + 1) + "." + ext, "", FILETYPE_SCREEN);
405
			C_File *newFile = this->addFile(m_sID + "_" + (long)(this->countFiles(FILETYPE_SCREEN) + 1) + "." + ext, "", FILETYPE_SCREEN);
405
			newFile->ReadFromData((char *)(compr + pos), size); 
406
			newFile->ReadFromData((char *)(compr + pos), size); 
406
 
407
 
407
			start += (size + 1);
408
			start += (size + 1);
408
		}
409
		}
409
		else if ( first.Compare("SceneFile") )
410
		else if ( first.Compare("SceneFile") )
410
		{
411
		{
411
			Utils::String file = rest.tokens(" ", 3);
412
			Utils::String file = rest.tokens(" ", 3);
412
			m_pSceneFile = this->AddFile(CFileIO(file).filename(), CFileIO(file).dir(), FILETYPE_SHIPSCENE);
413
			m_pSceneFile = this->addFile(CFileIO(file).filename(), CFileIO(file).dir(), FILETYPE_SHIPSCENE);
413
			m_pSceneFile->SetCreationTime((long)rest.token(" ", 1));
414
			m_pSceneFile->SetCreationTime((long)rest.token(" ", 1));
414
			m_pSceneFile->ReadFromData((char *)(compr + pos), rest.token(" ", 2));
415
			m_pSceneFile->ReadFromData((char *)(compr + pos), rest.token(" ", 2));
415
 
416
 
416
			start += m_pSceneFile->GetDataSize();
417
			start += m_pSceneFile->GetDataSize();
417
		}
418
		}
418
		else if ( first.Compare("CockpitFile") )
419
		else if ( first.Compare("CockpitFile") )
419
		{
420
		{
420
			Utils::String file = rest.tokens(" ", 3);
421
			Utils::String file = rest.tokens(" ", 3);
421
			m_pCockpitFile = this->AddFile(CFileIO(file).filename(), CFileIO(file).dir(), FILETYPE_COCKPITSCENE);
422
			m_pCockpitFile = this->addFile(CFileIO(file).filename(), CFileIO(file).dir(), FILETYPE_COCKPITSCENE);
422
			m_pCockpitFile->SetCreationTime((long)rest.token(" ", 1));
423
			m_pCockpitFile->SetCreationTime((long)rest.token(" ", 1));
423
			m_pCockpitFile->ReadFromData((char *)(compr + pos), rest.token(" ", 2));
424
			m_pCockpitFile->ReadFromData((char *)(compr + pos), rest.token(" ", 2));
424
 
425
 
425
			start += m_pCockpitFile->GetDataSize();
426
			start += m_pCockpitFile->GetDataSize();
426
		}
427
		}
427
		else if ( first.Compare("Model") )
428
		else if ( first.Compare("Model") )
428
		{
429
		{
429
			Utils::String file = rest.tokens(" ", 3);
430
			Utils::String file = rest.tokens(" ", 3);
430
			C_File *newFile= this->AddFile(CFileIO(file).filename(), CFileIO(file).dir(), FILETYPE_SHIPMODEL);
431
			C_File *newFile= this->addFile(CFileIO(file).filename(), CFileIO(file).dir(), FILETYPE_SHIPMODEL);
431
			newFile->SetCreationTime((long)rest.token(" ", 1));
432
			newFile->SetCreationTime((long)rest.token(" ", 1));
432
			newFile->ReadFromData((char *)(compr + pos), rest.token(" ", 2));
433
			newFile->ReadFromData((char *)(compr + pos), rest.token(" ", 2));
433
 
434
 
434
			start += (newFile->GetDataSize() + 1);
435
			start += (newFile->GetDataSize() + 1);
435
		}
436
		}
Line 454... Line 455...
454
				newFile = new C_File(file);
455
				newFile = new C_File(file);
455
				special = 3;
456
				special = 3;
456
			}
457
			}
457
			else
458
			else
458
			{
459
			{
459
				newFile = this->AddFile(CFileIO(file).filename(), CFileIO(file).dir(), FILETYPE_SHIPOTHER);
460
				newFile = this->addFile(CFileIO(file).filename(), CFileIO(file).dir(), FILETYPE_SHIPOTHER);
460
				newFile->SetCreationTime((long)rest.token(" ", 1));
461
				newFile->SetCreationTime((long)rest.token(" ", 1));
461
			}
462
			}
462
			newFile->ReadFromData((char *)(compr + pos), rest.token(" ", 2));
463
			newFile->ReadFromData((char *)(compr + pos), rest.token(" ", 2));
463
			start += (newFile->GetDataSize() + 1);
464
			start += (newFile->GetDataSize() + 1);
464
 
465
 
Line 466... Line 467...
466
			{
467
			{
467
				if ( newFile->CheckFileExt("pck") )
468
				if ( newFile->CheckFileExt("pck") )
468
					newFile->UnPCKFile();
469
					newFile->UnPCKFile();
469
 
470
 
470
				// read data into lines
471
				// read data into lines
471
				CyString data((const char *)newFile->GetData());
472
				Utils::String data((const char *)newFile->GetData());
472
				data.RemoveChar('\r');
473
				data.removeChar('\r');
473
				int iLines;
474
				int iLines;
474
				CyString *sLines = data.SplitToken("\n", &iLines);
475
				Utils::String *sLines = data.tokenise("\n", &iLines);
475
				
476
				
476
				if ( sLines && iLines )
477
				if ( sLines && iLines )
477
				{
478
				{
478
					// cut data
479
					// cut data
479
					int entries = -1;
480
					size_t entries = -1;
480
					if ( special == 1 )
481
					if ( special == 1 )
481
					{
482
					{
482
						CyStringList newLines;
483
						Utils::CStringList newLines;
483
						for ( int i = 0; i < iLines; i++ )
484
						for ( int i = 0; i < iLines; i++ )
484
						{
485
						{
485
							CyString line = sLines[i];
486
							Utils::String line = sLines[i];
486
							line.RemoveChar(' ');
487
							line.removeChar(' ');
487
							line.RemoveChar(9);
488
							line.removeChar(9);
488
							if ( line.Empty() || line[0] == '/' )
489
							if ( line.empty() || line[0] == '/' )
489
								continue;
490
								continue;
490
							if ( entries == -1 )
491
							if ( entries == -1 )
491
							{
492
							{
492
								entries	= line.GetToken(";", 1, 1).ToInt() - 36;
493
								entries	= line.token(";", 1).toInt() - 36;
493
								if ( entries <= 0 )
494
								if ( entries <= 0 )
494
									break;
495
									break;
495
							}
496
							}
496
							else
497
							else
497
							{
498
							{
498
								int id = line.GetToken(";", 1, 1).ToInt();
499
								int id = line.token(";", 1).toInt();
499
								if ( id >= 9000 && id <= 9017 )
500
								if ( id >= 9000 && id <= 9017 )
500
									continue;
501
									continue;
501
 
502
 
502
								switch (id)
503
								switch (id)
503
								{
504
								{
Line 520... Line 521...
520
									case 4207:
521
									case 4207:
521
									case 4107:
522
									case 4107:
522
										break;
523
										break;
523
 
524
 
524
									default:
525
									default:
525
										newLines.PushBack(line);
526
										newLines.pushBack(line);
526
								}
527
								}
527
								if ( newLines.Count() == entries )
528
								if ( newLines.size() == entries )
528
									break;
529
									break;
529
							}
530
							}
530
						}
531
						}
531
 
532
 
532
						for ( SStringList *strNode = newLines.Head(); strNode; strNode = strNode->;next )
533
						for(auto itr = newLines.begin(); itr != newLines.end(); itr++)
533
							this->addCutData(strNode->str.ToString());
534
							this->addCutData((*itr)->str);
534
					}
535
					}
535
					// bodies
536
					// bodies
536
					else if ( special == 2 )
537
					else if ( special == 2 )
537
					{
538
					{
538
						entries = 0;
539
						entries = 0;
539
						Utils::String section;
540
						Utils::String section;
540
						for ( int i = 0; i < iLines; i++ )
541
						for ( int i = 0; i < iLines; i++ )
541
						{
542
						{
542
							Utils::String line = sLines[i].ToString();
543
							Utils::String line = sLines[i];
543
							line.removeChar(' ');
544
							line.removeChar(' ');
544
							line.removeChar(9);
545
							line.removeChar(9);
545
							if ( line.empty() || line[0] == '/' )
546
							if ( line.empty() || line[0] == '/' )
546
								continue;
547
								continue;
547
							if ( entries <= 0)
548
							if ( entries <= 0)
548
							{
549
							{
549
								section = line.token(";", 1);
550
								section = line.token(";", 1);
550
								entries	= line.token(";", 2);
551
								entries	= line.token(";", 2).toInt();
551
							}
552
							}
552
							else
553
							else
553
							{
554
							{
554
								if ( !line.isin(";") )
555
								if ( !line.isin(";") )
555
									continue;
556
									continue;
556
								if ( line.countToken(";") <= 2 )
557
								if ( line.countToken(";") <= 2 )
557
								{
558
								{
558
									this->AddBodies(section + ";" + line.token(";", 1) + ";");
559
									this->addBodies(section + ";" + line.token(";", 1) + ";");
559
									--entries;
560
									--entries;
560
								}
561
								}
561
								else
562
								else
562
								{
563
								{
563
									bool done = false;
564
									bool done = false;
Line 577... Line 578...
577
											}
578
											}
578
 
579
 
579
											if ( strs[j].empty() )
580
											if ( strs[j].empty() )
580
												continue;
581
												continue;
581
											
582
											
582
											this->AddBodies(section + ";" + strs[j] + ";");
583
											this->addBodies(section + ";" + strs[j] + ";");
583
											--entries;
584
											--entries;
584
										}
585
										}
585
										//we must be at another section
586
										//we must be at another section
586
										if ( !done )
587
										if ( !done )
587
										{
588
										{
588
											section = line.token(";", 1);
589
											section = line.token(";", 1);
589
											entries	= line.token(";", 2);
590
											entries	= line.token(";", 2).toInt();
590
											line = line.remToken(";", 1);
591
											line = line.remToken(";", 1);
591
											line = line.remToken(";", 1);
592
											line = line.remToken(";", 1);
592
 
593
 
593
											if (line.empty())
594
											if (line.empty())
594
												done = true;
595
												done = true;
Line 601... Line 602...
601
						}
602
						}
602
					}
603
					}
603
					// animations
604
					// animations
604
					else if ( special == 3 )
605
					else if ( special == 3 )
605
					{
606
					{
606
						CyStringList in;
607
						Utils::CStringList in;
607
						for ( int i = 0; i < iLines; i++ )
608
						for ( int i = 0; i < iLines; i++ )
608
						{
-
 
609
							CyString line = sLines[i];
-
 
610
							in.PushBack(line);
609
							in.pushBack(sLines[i]);
611
						}
-
 
612
 
610
 
613
						CyStringList out;
611
						Utils::CStringList out;
614
						if ( CXspFile::ReadAnimations(&in, &out, 87) )
612
						if ( CXspFile::ReadAnimations(in, out, 87) )
615
							this->AddAnimation(&out);
613
							this->addAnimation(out);
616
					}
614
					}
617
				}
615
				}
618
				CLEANSPLIT(sLines, iLines)
616
				CLEANSPLIT(sLines, iLines)
619
				delete newFile;
617
				delete newFile;
620
			}
618
			}
621
		}
619
		}
622
		else if ( first.Compare("Script") )
620
		else if ( first.Compare("Script") )
623
		{
621
		{
624
			Utils::String file = rest.words(3);
622
			Utils::String file = rest.words(3);
625
			C_File *newFile= this->AddFile(file, NullString, FILETYPE_SCRIPT);
623
			C_File *newFile= this->addFile(file, Utils::String::Null(), FILETYPE_SCRIPT);
626
			newFile->SetCreationTime((long)rest.word(1));
624
			newFile->SetCreationTime((long)rest.word(1));
627
			newFile->ReadFromData((char *)(compr + pos), rest.word(2));
625
			newFile->ReadFromData((char *)(compr + pos), rest.word(2));
628
 
626
 
629
			start += (newFile->GetDataSize() + 1);
627
			start += (newFile->GetDataSize() + 1);
630
		}
628
		}
Line 763... Line 761...
763
}
761
}
764
 
762
 
765
void CXspFile::clearCutData()
763
void CXspFile::clearCutData()
766
{
764
{
767
	_lCutData.clear();
765
	_lCutData.clear();
-
 
766
}
-
 
767
void CXspFile::clearAnimations()
-
 
768
{
-
 
769
	_lAnimations.clear();
-
 
770
}
-
 
771
void CXspFile::clearBodies()
-
 
772
{
-
 
773
	_lBodies.clear();
768
}
774
}
769
 
775
 
770
Utils::String CXspFile::GetShipClass()
776
Utils::String CXspFile::GetShipClass()
771
{
777
{
772
	if ( !m_sData.empty() )
778
	if ( !m_sData.empty() )
Line 816... Line 822...
816
 
822
 
817
	if ( !m_sData.empty() )
823
	if ( !m_sData.empty() )
818
	{
824
	{
819
		list->pushBack("# Ship Data, the TShip data entry to add to the game (parts of this are adjusted and auto generated by the installer)");
825
		list->pushBack("# Ship Data, the TShip data entry to add to the game (parts of this are adjusted and auto generated by the installer)");
820
		list->pushBack("ShipData: " + m_sData);
826
		list->pushBack("ShipData: " + m_sData);
821
		list->pushBack("");
827
		list->pushBack("");
822
	}
828
	}
823
 
829
 
824
	if ( m_lText.size() ) {
830
	if ( m_lText.size() ) {
825
		list->pushBack("# Ship Texts, the name/description of the ship in each language: <LANGID> <NAME>|<DESCRIPTION>");
831
		list->pushBack("# Ship Texts, the name/description of the ship in each language: <LANGID> <NAME>|<DESCRIPTION>");
826
		for(CListNode<SText> *node = m_lText.Front(); node; node = node->next()) {
832
		for(CListNode<SText> *node = m_lText.Front(); node; node = node->next()) {
827
			list->pushBack(Utils::String("ShipText: ") + (long)node->Data()->iId + " " + node->Data()->sName + "|" + node->Data()->sDesc);
833
			list->pushBack(Utils::String("ShipText: ") + (long)node->Data()->iId + " " + node->Data()->sName + "|" + node->Data()->sDesc);
828
		}
834
		}
Line 858... Line 864...
858
 
864
 
859
	if ( this->m_lDummy.size() ) {
865
	if ( this->m_lDummy.size() ) {
860
		list->pushBack("# Ship Dummies, each dummy entry used in the ships scene: <SECTION> <VALUE>");
866
		list->pushBack("# Ship Dummies, each dummy entry used in the ships scene: <SECTION> <VALUE>");
861
		for(CListNode<SDummy> *node = m_lDummy.Front(); node; node = node->next()) {
867
		for(CListNode<SDummy> *node = m_lDummy.Front(); node; node = node->next()) {
862
			list->pushBack("Dummy: " + node->Data()->sSection + " " + node->Data()->sData);
868
			list->pushBack("Dummy: " + node->Data()->sSection + " " + node->Data()->sData);
863
		}
869
		}
864
		list->pushBack("");
870
		list->pushBack("");
865
	}
871
	}
866
 
872
 
867
	if ( this->m_lCockpit.size() ) {
873
	if ( this->m_lCockpit.size() ) {
868
		list->pushBack("# Cockpit entries, each cockpit value with thier weapons mask");
874
		list->pushBack("# Cockpit entries, each cockpit value with thier weapons mask");
869
		for(CListNode<SCockpit> *node = m_lCockpit.Front(); node; node = node->next()) {
875
		for(CListNode<SCockpit> *node = m_lCockpit.Front(); node; node = node->next()) {
870
			list->pushBack("Cockpit: " + node->Data()->sCockpit.token(";", 19) + " " + node->Data()->sCockpit);
876
			list->pushBack("Cockpit: " + node->Data()->sCockpit.token(";", 19) + " " + node->Data()->sCockpit);
871
			for(SWeaponMask *mask = node->Data()->lWeaponMask.First(); mask; mask = node->Data()->lWeaponMask.Next()) {
877
			for(SWeaponMask *mask = node->Data()->lWeaponMask.First(); mask; mask = node->Data()->lWeaponMask.Next()) {
Line 874... Line 880...
874
		}
880
		}
875
 
881
 
876
		list->pushBack("");
882
		list->pushBack("");
877
	}
883
	}
878
 
884
 
879
	if ( !this->_lCutData.empty() ) {
885
	if (!this->_lCutData.empty())
-
 
886
	{
880
		list->pushBack("# Ship Cut Data");
887
		list->pushBack("# Ship Cut Data");
881
		for(auto itr = _lCutData.begin(); itr != _lCutData.end(); itr++)
888
		for(auto itr = _lCutData.begin(); itr != _lCutData.end(); itr++)
882
			list->pushBack("CutData: " + (*itr)->str);
889
			list->pushBack("CutData: " + (*itr)->str);
883
		list->pushBack("");
890
		list->pushBack("");
884
	}
891
	}
885
 
892
 
886
	if ( !this->m_lBodies.Empty() ) {
893
	if (!this->_lBodies.empty())
-
 
894
	{
887
		list->pushBack("# Ship Bodies");
895
		list->pushBack("# Ship Bodies");
888
		for(SStringList *str = m_lBodies.Head(); str; str = str->;next) {
896
		for(auto itr = _lBodies.begin(); itr != _lBodies.end(); itr++)
889
			list->pushBack(Utils::String("Bodies: ";) + str->str.ToString());
897
			list->pushBack("Bodies: "; + (*itr)->str);
890
		}
-
 
891
		list->pushBack("");
898
		list->pushBack("");
892
	}
899
	}
893
 
900
 
894
	if ( !this->m_lAnimations.Empty() ) {
901
	if (!this->_lAnimations.empty())
-
 
902
	{
895
		list->pushBack("# Ship Animations");
903
		list->pushBack("# Ship Animations");
896
		for(SStringList *str = m_lAnimations.Head(); str; str = str->next) {
904
		for (auto itr = _lAnimations.begin(); itr != _lAnimations.end(); itr++)
897
			list->pushBack(Utils::String("Animation: ";) + str->str.ToString());
905
			list->pushBack("Animation: "; + (*itr)->str);	
898
		}
-
 
899
		list->pushBack("");
906
		list->pushBack("");
900
	}
907
	}
901
 
908
 
902
	if ( !datafile )
909
	if ( !datafile )
903
	{
910
	{
Line 923... Line 930...
923
		currentSubSection->sSection = section;
930
		currentSubSection->sSection = section;
924
		list.push_back(currentSubSection);
931
		list.push_back(currentSubSection);
925
	}
932
	}
926
 
933
 
927
	currentSubSection->lEntries.pushBack(data, "");
934
	currentSubSection->lEntries.pushBack(data, "");
928
}
-
 
929
 
-
 
930
void CXspFile::_addDataSection(CyStringList& list, Utils::CList<STypesSection>& sectionList, bool bUseFirst)
-
 
931
{
-
 
932
	for (SStringList* str = list.Head(); str; str = str->next) {
-
 
933
		if (bUseFirst) {
-
 
934
			Utils::String data = str->str.ToString();
-
 
935
			_addSection(sectionList, data.token(";", 1), data.tokens(";", 2));
-
 
936
		}
-
 
937
		else {
-
 
938
			_addSection(sectionList, str->str.ToString(), str->data.ToString());
-
 
939
		}
-
 
940
	}
-
 
941
}
935
}
942
 
936
 
943
void CXspFile::_addDataSection(Utils::CStringList& list, Utils::CList<STypesSection>& sectionList, bool bUseFirst)
937
void CXspFile::_addDataSection(Utils::CStringList& list, Utils::CList<STypesSection>& sectionList, bool bUseFirst)
944
{
938
{
945
	for(auto itr = list.begin(); itr != list.end(); itr++)
939
	for(auto itr = list.begin(); itr != list.end(); itr++)
Line 985... Line 979...
985
	_addDataSection(this->_lCutData, list, false);
979
	_addDataSection(this->_lCutData, list, false);
986
}
980
}
987
 
981
 
988
void CXspFile::addBodiesToList(Utils::CList<STypesSection> &list)
982
void CXspFile::addBodiesToList(Utils::CList<STypesSection> &list)
989
{
983
{
990
	_addDataSection(this->m_lBodies, list, true);
984
	_addDataSection(this->_lBodies, list, true);
991
}
985
}
992
 
986
 
993
void CXspFile::addAnimationsToList(Utils::CList<STypesSection> &list)
987
void CXspFile::addAnimationsToList(Utils::CList<STypesSection> &list)
994
{
988
{
995
	_addDataSection(this->m_lAnimations, list, false);
989
	_addDataSection(this->_lAnimations, list, false);
996
}
990
}
997
 
991
 
998
 
992
 
999
void CXspFile::addGeneratedFiles(HZIP &hz)
993
void CXspFile::addGeneratedFiles(HZIP &hz)
1000
{
994
{
Line 1032... Line 1026...
1032
				break;
1026
				break;
1033
			case 3:
1027
			case 3:
1034
				GENERATESECTION("Dummies", SDummy, this->m_lDummy);
1028
				GENERATESECTION("Dummies", SDummy, this->m_lDummy);
1035
				break;
1029
				break;
1036
			case 4:
1030
			case 4:
1037
				GENERATESTRINGSECTION("Bodies", this->m_lBodies, true);
1031
				GENERATESTRINGSECTION("Bodies", this->_lBodies, true);
1038
				break;
1032
				break;
1039
		}
1033
		}
1040
 
1034
 
1041
		if ( type.empty() ) continue;
1035
		if ( type.empty() ) continue;
1042
 
1036
 
Line 1100... Line 1094...
1100
	else if ( sFirst.Compare("Dummy") )
1094
	else if ( sFirst.Compare("Dummy") )
1101
		this->AddDummy(sRest.token(" ", 1), sRest.token(" ", 2));
1095
		this->AddDummy(sRest.token(" ", 1), sRest.token(" ", 2));
1102
	else if ( sFirst.Compare("CutData") )
1096
	else if ( sFirst.Compare("CutData") )
1103
		this->addCutData(sRest);
1097
		this->addCutData(sRest);
1104
	else if ( sFirst.Compare("Animation") )
1098
	else if ( sFirst.Compare("Animation") )
1105
		this->AddAnimation(sRest);
1099
		this->addAnimation(sRest);
1106
	else if ( sFirst.Compare("Bodies") )
1100
	else if ( sFirst.Compare("Bodies") )
1107
		this->AddBodies(sRest);
1101
		this->addBodies(sRest);
1108
	else if ( !CBaseFile::LoadPackageData(sFirst, sRest, sMainGame, otherGames, gameAddons, progress) )
1102
	else if ( !CBaseFile::LoadPackageData(sFirst, sRest, sMainGame, otherGames, gameAddons, progress) )
1109
	{
1103
	{
1110
		return false;
1104
		return false;
1111
	}
1105
	}
1112
 
1106
 
Line 1119... Line 1113...
1119
	Utils::String data = m_sData;
1113
	Utils::String data = m_sData;
1120
 
1114
 
1121
	// change the ship subtype, Reunion uses number, TC uses a define
1115
	// change the ship subtype, Reunion uses number, TC uses a define
1122
	Utils::String sSubType = data.token(";", 6);
1116
	Utils::String sSubType = data.token(";", 6);
1123
	if ( !((long)sSubType) && sSubType != "0" )
1117
	if ( !((long)sSubType) && sSubType != "0" )
1124
		data = data.replaceToken(";", 6, (long)CShipData::ConvertShipSubType(CyString(sSubType)));
1118
		data = data.replaceToken(";", 6, (long)CShipData::ConvertShipSubType(sSubType));
1125
 
1119
 
1126
	Utils::String sClass = data.token(";", TSHIPPOS_CLASS);
1120
	Utils::String sClass = data.token(";", TSHIPPOS_CLASS);
1127
	if ( !((long)sClass) && sClass != "0" )
1121
	if ( !((long)sClass) && sClass != "0" )
1128
	{
1122
	{
1129
		int num = 0;
1123
		int num = 0;
Line 1146... Line 1140...
1146
{
1140
{
1147
	Utils::String data = m_sData;
1141
	Utils::String data = m_sData;
1148
 
1142
 
1149
	Utils::String sSubType = data.token(";", 6);
1143
	Utils::String sSubType = data.token(";", 6);
1150
	if ( ((long)sSubType) || sSubType == "0" )
1144
	if ( ((long)sSubType) || sSubType == "0" )
1151
		data = data.replaceToken(";", 6, CShipData::ConvertShipSubType((long)sSubType).ToString());
1145
		data = data.replaceToken(";", 6, CShipData::ConvertShipSubType((long)sSubType));
1152
 
1146
 
1153
	Utils::String sClass = data.token(";", TSHIPPOS_CLASS);
1147
	Utils::String sClass = data.token(";", TSHIPPOS_CLASS);
1154
	if ( ((long)sClass) || sClass == "0" )
1148
	if ( ((long)sClass) || sClass == "0" )
1155
		data = data.replaceToken(";", TSHIPPOS_CLASS, CShipData::ConvertShipClass((long)sClass));
1149
		data = data.replaceToken(";", TSHIPPOS_CLASS, CShipData::ConvertShipClass((long)sClass));
1156
 
1150
 
1157
	return data;
1151
	return data;
1158
}
1152
}
1159
 
1153
 
1160
bool CXspFile::RemoveCockpit(const Utils::String &sCockpitId)
1154
bool CXspFile::removeCockpit(const Utils::String &sCockpitId)
1161
{
1155
{
1162
	Utils::String cockpitid = sCockpitId;
1156
	Utils::String cockpitid = sCockpitId;
1163
	// if its a whole line, just get the end
1157
	// if its a whole line, just get the end
1164
	if ( cockpitid.isin(";") )
1158
	if ( cockpitid.isin(";") )
1165
	{
1159
	{
Line 1183... Line 1177...
1183
	m_lCockpit.RemoveEmpty();
1177
	m_lCockpit.RemoveEmpty();
1184
 
1178
 
1185
	return ret;
1179
	return ret;
1186
}
1180
}
1187
 
1181
 
1188
bool CXspFile::RemoveComponent(const Utils::String &section1, const Utils::String &section2, const Utils::String &data)
1182
bool CXspFile::removeComponent(const Utils::String &section1, const Utils::String &section2, const Utils::String &data)
1189
{
1183
{
1190
	bool ret = false;
1184
	bool ret = false;
1191
	for ( CListNode<SComponent> *node = m_lComponent.Front(); node; node = node->next() )
1185
	for ( CListNode<SComponent> *node = m_lComponent.Front(); node; node = node->next() )
1192
	{
1186
	{
1193
		if ( node->Data()->sSection.Compare(section1) && node->Data()->sSection2.Compare(section2) && node->Data()->sData.Compare(data) )
1187
		if ( node->Data()->sSection.Compare(section1) && node->Data()->sSection2.Compare(section2) && node->Data()->sData.Compare(data) )
Line 1199... Line 1193...
1199
	}
1193
	}
1200
	m_lComponent.RemoveEmpty();
1194
	m_lComponent.RemoveEmpty();
1201
	return ret;
1195
	return ret;
1202
}
1196
}
1203
 
1197
 
1204
bool CXspFile::RemoveDummy(const Utils::String &section, const Utils::String &data)
1198
bool CXspFile::removeDummy(const Utils::String &section, const Utils::String &data)
1205
{
1199
{
1206
	bool ret = false;
1200
	bool ret = false;
1207
	for ( CListNode<SDummy> *node = m_lDummy.Front(); node; node = node->next() )
1201
	for ( CListNode<SDummy> *node = m_lDummy.Front(); node; node = node->next() )
1208
	{
1202
	{
1209
		if ( node->Data()->sSection.Compare(section) && node->Data()->sData.Compare(data) )
1203
		if ( node->Data()->sSection.Compare(section) && node->Data()->sData.Compare(data) )
Line 1295... Line 1289...
1295
	}
1289
	}
1296
 
1290
 
1297
	return ret;
1291
	return ret;
1298
}
1292
}
1299
 
1293
 
1300
bool CXspFile::RemoveBodies(const Utils::String &cut)
1294
bool CXspFile::removeBodies(const Utils::String &cut)
1301
{
1295
{
1302
	bool ret = false;
1296
	bool ret = false;
1303
	for ( SStringList *str = m_lBodies.Head(); str; str = str->;next )
1297
	for (auto itr = _lBodies.begin(); itr != _lBodies.end(); itr++)
1304
	{
1298
	{
1305
		if ( str->str.Remove(' ').Compare(CyString(cut.remove(' '))) )
1299
		if ((*itr)->str.remove(' ').Compare(cut.remove(' ')))
1306
		{
1300
		{
1307
			ret = true;
-
 
1308
			str->remove = true;
1301
			_lBodies.remove(itr);
1309
			break;
1302
			return true;
1310
		}
1303
		}
1311
	}
1304
	}
1312
 
-
 
1313
	m_lBodies.RemoveMarked();
-
 
1314
 
1305
 
1315
	return ret;
1306
	return false;
1316
}
1307
}
1317
 
1308
 
1318
bool CXspFile::RemoveAnimation(const Utils::String &cut)
1309
bool CXspFile::removeAnimation(const Utils::String &cut)
1319
{
1310
{
1320
	bool ret = false;
-
 
1321
	for ( SStringList *str = m_lAnimations.Head(); str; str = str->;next )
1311
	for(auto itr = _lAnimations.begin(); itr != _lAnimations.end(); itr++)
1322
	{
1312
	{
1323
		if ( str->str.Remove(' ').Remove('\n').Compare(CyString(cut.remove(' ').remove('\n'))) )
1313
		if ((*itr)->str.remove(' ').remove('\n').Compare(cut.remove(' ').remove('\n')))
1324
		{
1314
		{
1325
			ret = true;
-
 
1326
			str->remove = true;
1315
			_lAnimations.remove(itr);
1327
			break;
1316
			return true;
1328
		}
1317
		}
1329
	}
1318
	}
1330
 
1319
 
1331
	m_lAnimations.RemoveMarked();
-
 
1332
 
-
 
1333
	return ret;
1320
	return false;
1334
}
1321
}
1335
 
1322
 
1336
SCockpit *CXspFile::_findCockpit(const Utils::String &sID)
1323
SCockpit *CXspFile::_findCockpit(const Utils::String &sID)
1337
{
1324
{
1338
	for ( CListNode<SCockpit> *node = m_lCockpit.Front(); node; node = node->next() ) {
1325
	for ( CListNode<SCockpit> *node = m_lCockpit.Front(); node; node = node->next() ) {
1339
		Utils::String id = node->Data()->sCockpit.token(";", 19);
1326
		Utils::String id = node->Data()->sCockpit.token(";", 19);
1340
		if ( id.Compare(sID) )
1327
		if ( id.Compare(sID) )
1341
			return node->Data();
1328
			return node->Data();
1342
	}
1329
	}
Line 1392... Line 1379...
1392
	if ( game > 0 )
1379
	if ( game > 0 )
1393
		AddCockpitWeapon(cid, game, mask);
1380
		AddCockpitWeapon(cid, game, mask);
1394
	_changed();
1381
	_changed();
1395
}
1382
}
1396
 
1383
 
1397
void CXspFile::AddBody(const Utils::String &section, const Utils::String &data)
1384
void CXspFile::addBody(const Utils::String &section, const Utils::String &data)
1398
{
1385
{
1399
	this->AddBodies(section + ";" + data);
1386
	this->addBodies(section + ";" + data);
1400
	_changed();
1387
	_changed();
1401
}
1388
}
1402
void CXspFile::AddBodies(const Utils::String &sData)
1389
void CXspFile::addBodies(const Utils::String &sData)
1403
{
1390
{
1404
	Utils::String data = sData;
1391
	Utils::String data = sData;
1405
	if ( !data.isNumber() )
1392
	if ( !data.isNumber() )
1406
	{
1393
	{
1407
		if ( data[(int)(data.length() - 5)] == '.' )
1394
		if ( data[(int)(data.length() - 5)] == '.' )
1408
			data = data.left(-5);
1395
			data = data.left(-5);
1409
		else if ( data[(int)(data.length() - 4)] == '.' )
1396
		else if ( data[(int)(data.length() - 4)] == '.' )
1410
			data = data.left(-4);
1397
			data = data.left(-4);
1411
		if ( data.right(1) != ";" )
1398
		if ( data.right(1) != ";" )
1412
			data += ";";
1399
			data += ";";
1413
	}
1400
	}
-
 
1401
	if(!_lBodies.contains(data))
1414
	m_lBodies.PushBack(CyString(data), true);
1402
		_lBodies.pushBack(data);
1415
	_changed();
1403
	_changed();
1416
}
1404
}
1417
 
1405
 
1418
void CXspFile::addCutData(const Utils::String& data)
1406
void CXspFile::addCutData(const Utils::String& data)
1419
{ 
1407
{ 
Line 1434... Line 1422...
1434
				|| type.Compare("TAT_PINGPONG")
1422
				|| type.Compare("TAT_PINGPONG")
1435
				|| type.Compare("TAT_TAGLOOP") )
1423
				|| type.Compare("TAT_TAGLOOP") )
1436
		return TAT_3;
1424
		return TAT_3;
1437
 
1425
 
1438
	return TAT_NONE;
1426
	return TAT_NONE;
1439
}
1427
}
1440
 
1428
 
1441
Utils::String CXspFile::TypesListToString(Utils::CList<STypesSection> &list, bool deleteAfter)
1429
Utils::String CXspFile::TypesListToString(Utils::CList<STypesSection> &list, bool deleteAfter)
1442
{
1430
{
1443
	Utils::String data;
1431
	Utils::String data;
1444
 
1432
 
1445
	for(Utils::CList<STypesSection>::iterator itr = list.begin(); itr != list.end(); itr++) {
1433
	for(Utils::CList<STypesSection>::iterator itr = list.begin(); itr != list.end(); itr++) {
1446
		data += (*itr)->sSection + "; " + (long)(*itr)->lEntries.size() + ";\r\n";
1434
		data += (*itr)->sSection + "; " + (long)(*itr)->lEntries.size() + ";\r\n";
1447
		for(Utils::SStringList *str = (*itr)->lEntries.first(); str; str = (*itr)->lEntries.next()) {
1435
		for(Utils::SStringList *str = (*itr)->lEntries.first(); str; str = (*itr)->lEntries.next()) {
1448
			data += str->str + "\r\n";
1436
			data += str->str + "\r\n";
1449
		}
1437
		}
1450
 
1438
 
1451
		if ( deleteAfter ) {
1439
		if ( deleteAfter ) {
1452
			(*itr)->lEntries.clear();
1440
			(*itr)->lEntries.clear();
1453
		}
1441
		}
1454
	}
1442
	}
1455
 
1443
 
1456
	return data;
1444
	return data;
1457
}
1445
}
1458
 
1446
 
1459
bool CXspFile::ReadAnimations(CyStringList *lIn, CyStringList *lOut, int startRecord)
1447
bool CXspFile::ReadAnimations(const Utils::CStringList &lIn, Utils::CStringList &lOut, int startRecord)
1460
{
1448
{
1461
	Utils::String lastComment;
1449
	Utils::String lastComment;
1462
	Utils::String addEntry;
1450
	Utils::String addEntry;
1463
	int remaining = 0;
1451
	int remaining = 0;
1464
	Utils::String lastType;
1452
	Utils::String lastType;
1465
	int newEntries = 0;
1453
	int newEntries = 0;
1466
	int entries = -1;
1454
	int entries = -1;
1467
	for ( SStringList *strNode = lIn->Head(); strNode; strNode = strNode->;next )
1455
	for(auto itr = lIn.begin(); itr != lIn.end(); itr++)
1468
	{
1456
	{
1469
		Utils::String line = strNode->str.ToString();
1457
		Utils::String line = (*itr)->str;
1470
		line.removeChar('\r');
1458
		line.removeChar('\r');
1471
		line.removeChar(9);
1459
		line.removeChar(9);
1472
		if ( line.empty() || line[0] == '/' )
1460
		if ( line.empty() || line[0] == '/' )
1473
			continue;
1461
			continue;
1474
		if ( entries == -1)
1462
		if ( entries == -1)
Line 1577... Line 1565...
1577
			{
1565
			{
1578
				if ( entries <= newEntries && !addEntry.empty())
1566
				if ( entries <= newEntries && !addEntry.empty())
1579
				{
1567
				{
1580
					if ( addEntry[(int)addEntry.length() - 1] != ';' )
1568
					if ( addEntry[(int)addEntry.length() - 1] != ';' )
1581
						addEntry += ";";
1569
						addEntry += ";";
1582
					lOut->PushBack(CyString(addEntry + lastComment));
1570
					lOut.pushBack(addEntry + lastComment);
1583
				}
1571
				}
1584
				--entries;
1572
				--entries;
1585
			}
1573
			}
1586
		}
1574
		}
1587
	}
1575
	}
1588
 
1576
 
1589
	return !lOut->Empty();
1577
	return !lOut.empty();
1590
}
1578
}
1591
 
1579
 
1592
void CXspFile::AddAnimation(CyStringList *list)
1580
void CXspFile::addAnimation(const Utils::CStringList &list)
1593
{
1581
{
1594
	for ( SStringList *strNode = list->Head(); strNode; strNode = strNode->;next )
1582
	for(auto itr = list.begin(); itr != list.end(); itr++)
1595
		this->AddAnimation(strNode->str.ToString());
1583
		this->addAnimation((*itr)->str);
1596
	_changed();
1584
	_changed();
-
 
1585
}
-
 
1586
 
-
 
1587
void CXspFile::addAnimation(const Utils::String& data) 
-
 
1588
{ 
-
 
1589
	if (!_lAnimations.contains(data))
-
 
1590
	{
-
 
1591
		_lAnimations.pushBack(data);
-
 
1592
		_changed();
-
 
1593
	}
1597
}
1594
}
1598
 
1595
 
1599
SText *CXspFile::FindShipText(int lang)
1596
SText *CXspFile::FindShipText(int lang)
1600
{
1597
{
1601
	if ( m_lText.empty() )
1598
	if ( m_lText.empty() )
Line 1634... Line 1631...
1634
	if ( t )
1631
	if ( t )
1635
	{
1632
	{
1636
		// return the correct language text
1633
		// return the correct language text
1637
		if ( !t->sName.empty() )
1634
		if ( !t->sName.empty() )
1638
			return t->sName;
1635
			return t->sName;
1639
		// we have found a text, but there is no ship name ??
1636
		// we have found a text, but there is no ship name ??
1640
		else if ( lang != 44 )
1637
		else if ( lang != 44 )
1641
		{
1638
		{
1642
			// reget the english one
1639
			// reget the english one
1643
			t = FindShipText(44);
1640
			t = FindShipText(44);
1644
			if ( t && !t->sName.empty() )
1641
			if ( t && !t->sName.empty() )
Line 1692... Line 1689...
1692
bool CXspFile::extractShip(CVirtualFileSystem *pVfs, const Utils::String &sId, CProgressInfo *progress)
1689
bool CXspFile::extractShip(CVirtualFileSystem *pVfs, const Utils::String &sId, CProgressInfo *progress)
1693
{
1690
{
1694
	if ( !this->startExtractShip(pVfs, sId, progress) )
1691
	if ( !this->startExtractShip(pVfs, sId, progress) )
1695
		return false;
1692
		return false;
1696
 
1693
 
1697
	// read the scene file and get the files list
1694
	// read the scene file and get the files list
1698
	if ( !this->processSceneFiles(pVfs, progress) )
1695
	if ( !this->processSceneFiles(pVfs, progress) )
1699
		return false;
1696
		return false;
1700
 
1697
 
1701
	// pack all the ship files
1698
	// pack all the ship files
1702
	this->PackAllFiles();
1699
	this->PackAllFiles();
1703
 
1700
 
1704
	return true;
1701
	return true;
1705
}
1702
}
1706
 
1703
 
1707
bool CXspFile::extractSceneFiles(CVirtualFileSystem *pVfs)
1704
bool CXspFile::extractSceneFiles(CVirtualFileSystem *pVfs)
1708
{
1705
{
Line 1711... Line 1708...
1711
	m_pCockpitFile = pVfs->extractGameFileToPackage(this, "objects\\" + m_sData.token(";", 18) + ".pbd", FILETYPE_COCKPITSCENE, "objects\\" + m_sData.token(";", 18) + ".bod");
1708
	m_pCockpitFile = pVfs->extractGameFileToPackage(this, "objects\\" + m_sData.token(";", 18) + ".pbd", FILETYPE_COCKPITSCENE, "objects\\" + m_sData.token(";", 18) + ".bod");
1712
 
1709
 
1713
	return true;
1710
	return true;
1714
}
1711
}
1715
 
1712
 
1716
CyStringList *CXspFile::ReadSceneModels()
1713
bool CXspFile::readSceneModels(Utils::CStringList& out)
1717
{
1714
{
1718
	// read the scene file
1715
	// read the scene file
1719
	if ( !m_pSceneFile )
1716
	if (!m_pSceneFile)
1720
		m_pSceneFile = this->GetFirstFile(FILETYPE_SHIPSCENE);
1717
		m_pSceneFile = this->GetFirstFile(FILETYPE_SHIPSCENE);
1721
 
1718
 
1722
	if ( !m_pSceneFile )
1719
	if (!m_pSceneFile)
1723
		return NULL;
1720
		return false;
1724
 
1721
 
1725
	// check if its packed
1722
	// check if its packed
1726
	size_t datasize;
1723
	size_t datasize;
1727
	unsigned char *data = m_pSceneFile->UncompressData((long *)&datasize, 0);
1724
	unsigned char* data = m_pSceneFile->UncompressData((long*)&datasize, 0);
1728
	
1725
 
1729
	// if data wasn't compressed, then copy it itself as we are editing it
1726
	// if data wasn't compressed, then copy it itself as we are editing it
1730
	bool deleteData = false;
1727
	bool deleteData = false;
1731
	if ( data == m_pSceneFile->GetData() )
1728
	if (data == m_pSceneFile->GetData())
1732
	{
1729
	{
1733
		data = new unsigned char[m_pSceneFile->GetDataSize()];
1730
		data = new unsigned char[m_pSceneFile->GetDataSize()];
1734
		memcpy(data, m_pSceneFile->GetData(), m_pSceneFile->GetDataSize());
1731
		memcpy(data, m_pSceneFile->GetData(), m_pSceneFile->GetDataSize());
1735
		deleteData = true;
1732
		deleteData = true;
1736
	}
1733
	}
1737
 
1734
 
1738
	if ( data && datasize )
1735
	if (data && datasize)
1739
	{
1736
	{
1740
		if ( m_pSceneFile->CheckPackedExtension() )
1737
		if (m_pSceneFile->CheckPackedExtension())
1741
			data = UnPCKData(data, datasize, &datasize);
1738
			data = UnPCKData(data, datasize, &datasize);
1742
	}
1739
	}
1743
 
1740
 
1744
	if ( !data || !datasize )
1741
	if (!data || !datasize)
1745
		return NULL;
1742
		return false;
1746
 
-
 
1747
	CyStringList *lModels = new CyStringList;
-
 
1748
 
1743
 
1749
	size_t pos = 0;
1744
	size_t pos = 0;
1750
	bool newline = true;
1745
	bool newline = true;
1751
	bool online = false;
1746
	bool online = false;
1752
	while ( pos < datasize )
1747
	while (pos < datasize)
1753
	{
1748
	{
1754
		char c = data[pos];
1749
		char c = data[pos];
1755
		++pos;
1750
		++pos;
1756
 
1751
 
1757
		// skip until next line
1752
		// skip until next line
1758
		if ( !newline && !online )
1753
		if (!newline && !online)
1759
		{
1754
		{
1760
			if ( c == '\n' )
1755
			if (c == '\n')
1761
				newline = true;
1756
				newline = true;
1762
			continue;
1757
			continue;
1763
		}
1758
		}
1764
 
1759
 
1765
		if ( newline )
1760
		if (newline)
1766
		{
1761
		{
1767
			if ( c == ' ' || c == 9 || c == '\n' || c == '\r' )
1762
			if (c == ' ' || c == 9 || c == '\n' || c == '\r')
1768
				continue;
1763
				continue;
1769
 
1764
 
1770
			newline = false;
1765
			newline = false;
1771
 
1766
 
1772
			if ( c == 'P' || c == &apos;p' )
1767
			if (c == 'P' || c == &apos;p')
1773
			{
1768
			{
1774
				while ( data[pos] == ' ' ) pos++;
1769
				while (data[pos] == ' ') pos++;
1775
				unsigned char *line = (data + pos);
1770
				unsigned char* line = (data + pos);
1776
				while ( data[pos] != ' ' && data[pos] != &apos;;' ) pos++;
1771
				while (data[pos] != &apos; ' && data[pos] != ';') pos++;
1777
				data[pos] = '\0';
1772
				data[pos] = '\0';
1778
				if ( atoi((const char *)line) == lModels->Count() )
1773
				if (atoi((const char*)line) == out.size())
1779
					online = true;
1774
					online = true;
1780
			}
1775
			}
1781
		}
1776
		}
1782
		// this line is out model
1777
		// this line is out model
1783
		else if ( online )
1778
		else if (online)
1784
		{
1779
		{
1785
			if ( c == 'B' || c == &apos;b' )
1780
			if (c == 'B' || c == &apos;b')
1786
			{
1781
			{
1787
				while(data[pos] == ' ') pos++;
1782
				while (data[pos] == ' ') pos++;
1788
				unsigned char *line = (data + pos);
1783
				unsigned char* line = (data + pos);
1789
				while(data[pos] != ';') pos++;
1784
				while (data[pos] != ';') pos++;
1790
				data[pos] = '\0';
1785
				data[pos] = '\0';
1791
 
1786
 
1792
				lModels->PushBack((char *)line);
1787
				out.pushBack((char*)line);
1793
				online = false;
1788
				online = false;
1794
			}
1789
			}
1795
		}
1790
		}
1796
	}
1791
	}
1797
 
1792
 
1798
	if ( deleteData )
1793
	if (deleteData)
1799
		delete data;
1794
		delete data;
1800
 
1795
 
1801
	return lModels;
1796
	return true;
1802
}
1797
}
1803
 
1798
 
1804
void CXspFile::extractCutData(CVirtualFileSystem *pVfs, CyStringList *sceneModels, bool add)
1799
void CXspFile::extractCutData(CVirtualFileSystem *pVfs, Utils::CStringList &sceneModels, bool add)
1805
{
1800
{
1806
	std::vector<int> cuts;
1801
	std::vector<int> cuts;
1807
	for ( CListNode<SDummy> *node = m_lDummy.Front(); node; node = node->next() ) {
1802
	for ( CListNode<SDummy> *node = m_lDummy.Front(); node; node = node->next() )
-
 
1803
	{
1808
		Utils::String data = node->Data()->sData;
1804
		Utils::String data = node->Data()->sData;
1809
		int states = data.token(";", 3);
1805
		int states = data.token(";", 3);
1810
		for ( int i = 0; i < states; i++ ) {
1806
		for ( int i = 0; i < states; i++ ) {
1811
			int cutid = data.token(";", (i * 2) + 5);
1807
			int cutid = data.token(";", (i * 2) + 5);
1812
			if ( !cutid ) continue;
1808
			if ( !cutid ) continue;
Line 1819... Line 1815...
1819
	if ( pVfs->ExtractGameFile("types/CutData.pck", CPackages::tempDirectory() + "tmp.dat").empty() ) return;
1815
	if ( pVfs->ExtractGameFile("types/CutData.pck", CPackages::tempDirectory() + "tmp.dat").empty() ) return;
1820
	
1816
	
1821
	CFileIO File(CPackages::tempDirectory() + "tmp.dat");
1817
	CFileIO File(CPackages::tempDirectory() + "tmp.dat");
1822
	if ( !File.exists() ) return;
1818
	if ( !File.exists() ) return;
1823
	
1819
	
-
 
1820
	std::vector<Utils::String> lines;
1824
	CyStringList *lines = File.ReadLinesStr();
1821
	File.readLines(lines);
1825
	int count = -1;
1822
	int count = -1;
1826
	for ( SStringList *node = lines->Head(); node; node = node->;next ) {
1823
	for (auto itr = lines.begin(); itr != lines.end(); itr++) {
1827
		Utils::String line = node->str.ToString();
1824
		Utils::String line = *itr;
1828
		line.removeChar('\r');
1825
		line.removeChar('\r');
1829
		line.removeChar(' ');
1826
		line.removeChar(' ');
1830
		line.removeFirstSpace();
1827
		line.removeFirstSpace();
1831
		if ( line[0] == '/' ) continue;
1828
		if ( line[0] == '/' ) continue;
1832
		if ( count == -1 ) count = line.token(";", 1);
1829
		if ( count == -1 ) count = line.token(";", 1);
Line 1839... Line 1836...
1839
					if ( !cutid ) continue;
1836
					if ( !cutid ) continue;
1840
					for ( std::vector<int>::iterator itr = cuts.begin(); itr != cuts.end(); itr++ ) {
1837
					for ( std::vector<int>::iterator itr = cuts.begin(); itr != cuts.end(); itr++ ) {
1841
						if ( (*itr) == cutid ) {
1838
						if ( (*itr) == cutid ) {
1842
							this->addCutData(words[i] + ";" + words[i + 1] + ";");
1839
							this->addCutData(words[i] + ";" + words[i + 1] + ";");
1843
							if ( add ) {
1840
							if ( add ) {
1844
								sceneModels->PushBack(CyString(words[i + 1]));
1841
								sceneModels.pushBack(words[i + 1]);
1845
							}
1842
							}
1846
							break;
1843
							break;
1847
						}
1844
						}
1848
					}
1845
					}
1849
				}
1846
				}
Line 1851... Line 1848...
1851
			}
1848
			}
1852
		}
1849
		}
1853
	}
1850
	}
1854
}
1851
}
1855
 
1852
 
1856
void CXspFile::extractDummies(CVirtualFileSystem *pVfs, CyStringList *sceneModels, bool add)
1853
void CXspFile::extractDummies(CVirtualFileSystem *pVfs, Utils::CStringList& sceneModels, bool add)
1857
{
1854
{
1858
	if ( !sceneModels ) return;
1855
	if (sceneModels.empty()) return;
1859
 
1856
 
1860
	bool extracted = false;
1857
	bool extracted = false;
1861
	if ( !pVfs->ExtractGameFile("types/dummies.pck", CPackages::tempDirectory() + "tmp.dat").empty() ) {
1858
	if ( !pVfs->ExtractGameFile("types/dummies.pck", CPackages::tempDirectory() + "tmp.dat").empty() ) {
1862
		CFileIO File(CPackages::tempDirectory() + "tmp.dat");
1859
		CFileIO File(CPackages::tempDirectory() + "tmp.dat");
1863
		if ( File.exists() )
1860
		if ( File.exists() )
1864
		{
1861
		{
1865
			Utils::String section;
1862
			Utils::String section;
1866
			int secCount = 0;
1863
			int secCount = 0;
1867
			CyStringList *lines = File.ReadLinesStr();
1864
			std::vector<Utils::String> lines;
1868
			for ( SStringList *node = lines->Head(); node; node = node->next )
1865
			if (File.readLines(lines))
1869
			{
1866
			{
1870
				node->str.RemoveFirstSpace();
1867
				for(auto itr = lines.begin(); itr != lines.end(); itr++)
-
 
1868
				{
1871
				node-&gt;str.RemoveChar(9);
1869
					Utils::String str = itr-&gt;remove(9).remove('\r');
1872
				node->str.RemoveChar('\r');
1870
					str.removeFirstSpace();
1873
				if ( node->str.Empty() )
1871
					if (str.empty())
1874
					continue;
1872
						continue;
1875
				if ( node->str[0] == &apos;/' )
1873
					if (str[0] == &apos;/')
1876
					continue;
1874
						continue;
1877
 
1875
 
1878
				// not in a section yet
1876
					// not in a section yet
1879
				if ( secCount <= 0 )
1877
					if (secCount <= 0)
1880
				{
1878
					{
1881
					section = node->str.GetToken(";;", 1, 1).ToString();
1879
						section = str.token(";;", 1);
1882
					secCount = node->str.GetToken(";", 2, 2).ToInt();
1880
						secCount = str.token(";", 2).toInt();
1883
				}
1881
					}
1884
				else
1882
					else
1885
				{
1883
					{
1886
					Utils::String first = node->str.GetToken(";;", 1, 1).ToString();
1884
						Utils::String first = str.token(";;", 1);
1887
					if ( sceneModels->FindString(first) )
1885
						if (sceneModels.contains(first))
1888
					{
-
 
1889
						this->AddDummy(section, node->str.ToString());
-
 
1890
 
-
 
1891
						if ( add )
-
 
1892
						{
1886
						{
1893
							int pos = 4;
-
 
1894
							int scene = node-&gt;str.GetToken(";", 3, 3).ToInt();
1887
							this-&gt;AddDummy(section, str);
-
 
1888
 
1895
							for ( int i = 0; i < scene; i++ )
1889
							if (add)
1896
							{
1890
							{
-
 
1891
								int pos = 4;
-
 
1892
								int scene = str.token(";", 3).toInt();
-
 
1893
								for (int i = 0; i < scene; i++)
-
 
1894
								{
1897
								sceneModels->PushBack(node->str.GetToken(";", 5 + (i * 2), 5 + (i * 2)));
1895
									sceneModels.pushBack(str.token(";", 5 + (i * 2)));
1898
								pos += 2;
1896
									pos += 2;
-
 
1897
								}
-
 
1898
 
-
 
1899
								int model = str.token(";", pos).toInt();
-
 
1900
								for (int i = 0; i < model; i++)
-
 
1901
									sceneModels.pushBack(str.token(";", pos + (i * 2) + 1));
1899
							}
1902
							}
1900
 
-
 
1901
							int model = node->str.GetToken(";", pos, pos).ToInt();
-
 
1902
							for ( int i = 0; i < model; i++ )
-
 
1903
								sceneModels->PushBack(node->str.GetToken(";", pos + (i * 2) + 1, pos + (i * 2) + 1));
-
 
1904
						}
1903
						}
-
 
1904
						--secCount;
-
 
1905
 
1905
					}
1906
					}
1906
					--secCount;
-
 
1907
 
-
 
1908
				}
1907
				}
1909
			}
1908
			}
1910
 
1909
 
1911
			delete lines;
-
 
1912
			File.remove();
1910
			File.remove();
1913
		}
1911
		}
1914
	}
1912
	}
1915
}
1913
}
1916
 
1914
 
1917
void CXspFile::extractComponants(CVirtualFileSystem *pVfs, CyStringList *sceneModels)
1915
void CXspFile::extractComponants(CVirtualFileSystem *pVfs, const Utils::CStringList& sceneModels)
1918
{
1916
{
1919
	if ( !sceneModels ) return;
1917
	if (sceneModels.empty()) return;
1920
	if ( !pVfs->ExtractGameFile("types/components.pck", CPackages::tempDirectory() + "tmp.dat").empty() )
1918
	if ( !pVfs->ExtractGameFile("types/components.pck", CPackages::tempDirectory() + "tmp.dat").empty() )
1921
	{
1919
	{
1922
		CFileIO File(CPackages::tempDirectory() + "tmp.dat");
1920
		CFileIO File(CPackages::tempDirectory() + "tmp.dat");
1923
		if ( File.exists() )
1921
		if ( File.exists() )
1924
		{
1922
		{
1925
			Utils::String file;
1923
			Utils::String file;
1926
			Utils::String section;
1924
			Utils::String section;
1927
			int secCount = 0;
1925
			int secCount = 0;
1928
			int secCount2 = 0;
1926
			int secCount2 = 0;
1929
			CyStringList *lines = File.ReadLinesStr();
1927
			std::vector<Utils::String> lines;
1930
			for ( SStringList *node = lines->Head(); node; node = node->next )
1928
			if (File.readLines(lines))
1931
			{
1929
			{
1932
				node->str.RemoveFirstSpace();
1930
				for(auto itr = lines.begin(); itr != lines.end(); itr++)
1933
				node->str.RemoveChar(9);
-
 
1934
				node->str.RemoveChar('\r');
-
 
1935
				if ( node->str.Empty() )
-
 
1936
					continue;
-
 
1937
				if ( node->str[0] == '/' )
-
 
1938
					continue;
-
 
1939
 
-
 
1940
				// not in a section yet
-
 
1941
				if ( secCount2 )
-
 
1942
				{
1931
				{
-
 
1932
					Utils::String str = itr->remove(9).remove('\r');
-
 
1933
					str.removeFirstSpace();
-
 
1934
					if (str.empty())
-
 
1935
						continue;
-
 
1936
					if (str[0] == '/')
-
 
1937
						continue;
-
 
1938
 
-
 
1939
					// not in a section yet
-
 
1940
					if (secCount2)
-
 
1941
					{
1943
					if ( sceneModels->FindString(file) )
1942
						if (sceneModels.contains(file))
1944
						this->AddComponent(section, file, node->str.ToString());
1943
							this->AddComponent(section, file, str);
1945
					--secCount2;
1944
						--secCount2;
1946
				}
1945
					}
1947
				else if ( secCount <= 0 )
1946
					else if (secCount <= 0)
1948
				{
1947
					{
1949
					section = node->str.GetToken(";;", 1, 1).ToString();
1948
						section = str.token(";;", 1);
1950
					secCount = node->str.GetToken(";", 2, 2).ToInt();
1949
						secCount = str.token(";", 2).toInt();
1951
				}
1950
					}
1952
				else
1951
					else
1953
				{
1952
					{
1954
					file = node->str.GetToken(";;", 1, 1).ToString();
1953
						file = str.token(";;", 1);
1955
					secCount2 = node->str.GetToken(";", 2, 2).ToInt();
1954
						secCount2 = str.token(";", 2).toInt();
1956
					--secCount;
1955
						--secCount;
-
 
1956
					}
1957
				}
1957
				}
1958
			}
1958
			}
1959
 
1959
 
1960
			delete lines;
-
 
1961
			File.remove();
1960
			File.remove();
1962
		}
1961
		}
1963
	}
1962
	}
1964
}
1963
}
1965
 
1964
 
1966
bool CXspFile::GetTextureList(CyStringList *list, const unsigned char *olddata, size_t size)
1965
bool CXspFile::getTextureList(Utils::CStringList &list, const unsigned char *olddata, size_t size) const
1967
{
1966
{
1968
	if ( !olddata || !size )
1967
	if ( !olddata || !size )
1969
		return false;
1968
		return false;
1970
 
1969
 
1971
	size_t startLine = 0;
1970
	size_t startLine = 0;
Line 2000... Line 1999...
2000
						for(int i = 0; i < max; i++) {
1999
						for(int i = 0; i < max; i++) {
2001
							Utils::String type = strs[i].token(";", 1);
2000
							Utils::String type = strs[i].token(";", 1);
2002
							Utils::String valtype = strs[i].token(";", 2);			
2001
							Utils::String valtype = strs[i].token(";", 2);			
2003
							if ( valtype.Compare("SPTYPE_STRING") ) {
2002
							if ( valtype.Compare("SPTYPE_STRING") ) {
2004
								Utils::String file = strs[i].token(";", 3);
2003
								Utils::String file = strs[i].token(";", 3);
-
 
2004
								if(!list.contains(file))
2005
								list->PushBack(CyString(file), "", true);
2005
									list.pushBack(file, "");
2006
							}
2006
							}
2007
						}
2007
						}
2008
					}
2008
					}
2009
 
2009
 
2010
					CLEANSPLIT(strs, max)
2010
					CLEANSPLIT(strs, max)
2011
				}
2011
				}
2012
			}
2012
			}
2013
 
2013
 
2014
			startLine = pos + 1;
2014
			startLine = pos + 1;
Line 2020... Line 2020...
2020
	return true;
2020
	return true;
2021
}
2021
}
2022
 
2022
 
2023
void CXspFile::extractTextures(CVirtualFileSystem *pVfs)
2023
void CXspFile::extractTextures(CVirtualFileSystem *pVfs)
2024
{
2024
{
2025
	CyStringList lTextures;
2025
	Utils::CStringList lTextures;
2026
 
2026
 
2027
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
2027
	for ( CListNode<C_File> *node = m_lFiles.Front(); node; node = node->next() )
2028
	{
2028
	{
2029
		C_File *f = node->Data();
2029
		C_File *f = node->Data();
2030
		if ( f->GetFileType() != FILETYPE_SHIPMODEL )
2030
		if ( f->GetFileType() != FILETYPE_SHIPMODEL )
Line 2053... Line 2053...
2053
				if ( !file.empty() ) {
2053
				if ( !file.empty() ) {
2054
					CFileIO File(file);
2054
					CFileIO File(file);
2055
					if ( File.exists() ) {
2055
					if ( File.exists() ) {
2056
						data = File.readAll(&size);
2056
						data = File.readAll(&size);
2057
						File.remove();
2057
						File.remove();
2058
					}
2058
					}
2059
				}
2059
				}
2060
 
2060
 
2061
				if ( data && size ) 
2061
				if ( data && size ) 
2062
					this->GetTextureList(&lTextures, data, size);
2062
					this->getTextureList(lTextures, data, size);
2063
				continue;
2063
				continue;
2064
			}
2064
			}
2065
 
2065
 
2066
			deleteData = true;
2066
			deleteData = true;
2067
		}
2067
		}
Line 2080... Line 2080...
2080
			{
2080
			{
2081
				data = f->GetData();
2081
				data = f->GetData();
2082
				size = f->GetDataSize();
2082
				size = f->GetDataSize();
2083
			}
2083
			}
2084
		}
2084
		}
2085
		this->GetTextureList(&lTextures, data, size);
2085
		this->getTextureList(lTextures, data, size);
2086
 
2086
 
2087
		if ( deleteData ) delete data;
2087
		if ( deleteData ) delete data;
2088
	}
2088
	}
2089
 
2089
 
2090
	for ( SStringList *node = lTextures.Head(); node; node = node->;next )
2090
	for(auto itr = lTextures.begin(); itr != lTextures.end(); itr++)
2091
	{
2091
	{
2092
		CFileIO F(node->str);
2092
		CFileIO F((*itr)->str);
2093
		if ( F.isFileExtension("fx") ) {
2093
		if ( F.isFileExtension("fx") ) {
2094
			/*
2094
			/*
2095
			if ( !pVfs->extractGameFileToPackage(this, "shader\\1_1\\" + Utils::String(node->str.ToString()), FILETYPE_SHIPOTHER) )
2095
			if ( !pVfs->extractGameFileToPackage(this, "shader\\1_1\\" + Utils::String(node->str.ToString()), FILETYPE_SHIPOTHER) )
2096
				pVfs->extractGameFileToPackage(this, "shader\\1_1\\" + CFileIO(node->str.ToString()).ChangeFileExtension("fb").ToString(), FILETYPE_SHIPOTHER);
2096
				pVfs->extractGameFileToPackage(this, "shader\\1_1\\" + CFileIO(node->str.ToString()).ChangeFileExtension("fb").ToString(), FILETYPE_SHIPOTHER);
2097
			if ( !pVfs->extractGameFileToPackage(this, "shader\\1_4\\" + Utils::String(node->str.ToString()), FILETYPE_SHIPOTHER) )
2097
			if ( !pVfs->extractGameFileToPackage(this, "shader\\1_4\\" + Utils::String(node->str.ToString()), FILETYPE_SHIPOTHER) )
Line 2105... Line 2105...
2105
			if ( !pVfs->extractGameFileToPackage(this, "shader\\3_0\\" + Utils::String(node->str.ToString()), FILETYPE_SHIPOTHER) )
2105
			if ( !pVfs->extractGameFileToPackage(this, "shader\\3_0\\" + Utils::String(node->str.ToString()), FILETYPE_SHIPOTHER) )
2106
				pVfs->extractGameFileToPackage(this, "shader\\3_0\\" + CFileIO(node->str.ToString()).ChangeFileExtension("fb").ToString(), FILETYPE_SHIPOTHER);
2106
				pVfs->extractGameFileToPackage(this, "shader\\3_0\\" + CFileIO(node->str.ToString()).ChangeFileExtension("fb").ToString(), FILETYPE_SHIPOTHER);
2107
				*/
2107
				*/
2108
		}
2108
		}
2109
		else {
2109
		else {
2110
			if ( pVfs->extractGameFileToPackage(this, "dds\\" + Utils::String(node->str.ToString()), FILETYPE_SHIPOTHER) )
2110
			if ( pVfs->extractGameFileToPackage(this, "dds\\" + (*itr)->str, FILETYPE_SHIPOTHER) )
2111
				continue;
2111
				continue;
2112
 
2112
 
2113
			if ( pVfs->extractGameFileToPackage(this, "dds\\" + Utils::String(node->str.ToString()).token(".", -1), FILETYPE_SHIPOTHER) )
2113
			if ( pVfs->extractGameFileToPackage(this, "dds\\" + (*itr)->str.token(".", -1), FILETYPE_SHIPOTHER) )
2114
				continue;
2114
				continue;
2115
 
2115
 
2116
			if ( pVfs->extractGameFileToPackage(this, "dds\\" + Utils::String(node->str.ToString()) + ".dds", FILETYPE_SHIPOTHER) )
2116
			if ( pVfs->extractGameFileToPackage(this, "dds\\" + (*itr)->str + ".dds", FILETYPE_SHIPOTHER) )
2117
				continue;
2117
				continue;
2118
 
2118
 
2119
			if ( pVfs->extractGameFileToPackage(this, "dds\\" + Utils::String(F.changeFileExtension("dds")), FILETYPE_SHIPOTHER) )
2119
			if ( pVfs->extractGameFileToPackage(this, "dds\\" + Utils::String(F.changeFileExtension("dds")), FILETYPE_SHIPOTHER) )
2120
				continue;
2120
				continue;
2121
 
2121
 
2122
			if ( pVfs->extractGameFileToPackage(this, "textures\\" + Utils::String(node->str.ToString()), FILETYPE_SHIPOTHER) )
2122
			if ( pVfs->extractGameFileToPackage(this, "textures\\" + (*itr)->str, FILETYPE_SHIPOTHER) )
2123
				continue;
2123
				continue;
2124
 
2124
 
2125
			if ( pVfs->extractGameFileToPackage(this, "textures\\" + Utils::String(node->str.ToString()).token(".", -1), FILETYPE_SHIPOTHER) )
2125
			if ( pVfs->extractGameFileToPackage(this, "textures\\" + (*itr)->str.token(".", -1), FILETYPE_SHIPOTHER) )
2126
				continue;
2126
				continue;
2127
 
2127
 
2128
			if ( pVfs->extractGameFileToPackage(this, "textures\\" + Utils::String(node->str.ToString()) + ".jpg", FILETYPE_SHIPOTHER) )
2128
			if ( pVfs->extractGameFileToPackage(this, "textures\\" + (*itr)->str + ".jpg", FILETYPE_SHIPOTHER) )
2129
				continue;
2129
				continue;
2130
 
2130
 
2131
			if ( pVfs->extractGameFileToPackage(this, "textures\\" + Utils::String(F.changeFileExtension("jpg")), FILETYPE_SHIPOTHER) )
2131
			if ( pVfs->extractGameFileToPackage(this, "textures\\" + Utils::String(F.changeFileExtension("jpg")), FILETYPE_SHIPOTHER) )
2132
				continue;
2132
				continue;
2133
		}
2133
		}
Line 2140... Line 2140...
2140
 
2140
 
2141
	bool remove = false;
2141
	bool remove = false;
2142
	if ( CFileIO(file).isFileExtension("pck") )
2142
	if ( CFileIO(file).isFileExtension("pck") )
2143
	{
2143
	{
2144
		C_File F;
2144
		C_File F;
2145
		F.SetFilename(CyString(file));
2145
		F.setFilename(file);
2146
		F.UnPCKFile();
2146
		F.UnPCKFile();
2147
		if (F.writeToFile(CPackages::tempDirectory() + "tmp.dat"))
2147
		if (F.writeToFile(CPackages::tempDirectory() + "tmp.dat"))
2148
		{
2148
		{
2149
			remove = true;
2149
			remove = true;
2150
			file = CPackages::tempDirectory() + "tmp.dat";
2150
			file = CPackages::tempDirectory() + "tmp.dat";
Line 2174... Line 2174...
2174
	}
2174
	}
2175
 
2175
 
2176
	return false;
2176
	return false;
2177
}
2177
}
2178
 
2178
 
2179
bool CXspFile::ImportBodies(CyStringList *sceneModels, const Utils::String &filename)
2179
bool CXspFile::importBodies(const Utils::CStringList &sceneModels, const Utils::String &filename)
2180
{
2180
{
2181
	CFileIO File(filename);
2181
	CFileIO File(filename);
2182
	if ( File.exists() )
2182
	if ( File.exists() )
2183
	{
2183
	{
2184
		Utils::String sSection;
2184
		Utils::String sSection;
2185
		int section = 0;
2185
		int section = 0;
2186
		CyStringList *lines = File.ReadLinesStr();
2186
		std::vector<Utils::String> lines;
2187
		for ( SStringList *node = lines->Head(); node; node = node->next )
2187
		if (File.readLines(lines))
2188
		{
2188
		{
2189
			node->str.RemoveChar(9);
-
 
2190
			node->str.RemoveChar('\r');
-
 
2191
			node->str.RemoveFirstSpace();
-
 
2192
			if ( node->str.Empty() )
-
 
2193
				continue;
-
 
2194
			if ( node->str[0] == '/' )
-
 
2195
				continue;
-
 
2196
			
-
 
2197
			// are we looking for a section
2189
			for(auto itr = lines.begin(); itr != lines.end(); itr++)
2198
			if ( section <= 0 )
-
 
2199
			{
2190
			{
2200
				sSection = node->str.GetToken(";", 1, 1).ToString();
2191
				Utils::String l = *itr;
-
 
2192
				l.removeChar(9);
-
 
2193
				l.removeChar('\r');
2201
				section = node->str.GetToken(";", 2, 2).ToInt();
2194
				l.removeFirstSpace();
-
 
2195
				if (l.empty())
2202
			}
2196
					continue;
-
 
2197
				if (l[0] == '/')
2203
			else
2198
					continue;
-
 
2199
 
-
 
2200
				// are we looking for a section
-
 
2201
				if (section <= 0)
2204
			{
2202
				{
2205
				int max;
2203
					sSection = l.token(";", 1);
2206
				CyString *strs = node->str.SplitToken(";", &max);
2204
					section = l.token(";", 2).toInt();
-
 
2205
				}
2207
				if ( strs && max )
2206
				else
2208
				{
2207
				{
-
 
2208
					int max;
-
 
2209
					Utils::String* strs = l.tokenise(";", &max);
2209
					for ( int i = 0; i &lt; max; i++ )
2210
					if (strs &amp;&; max)
2210
					{
2211
					{
-
 
2212
						for (int i = 0; i < max; i++)
-
 
2213
						{
2211
						strs[i].RemoveSpaces();
2214
							strs[i].removeEndSpace();
-
 
2215
							strs[i].removeFirstSpace();
2212
						if (strs[i].Empty() )
2216
							if (strs[i].empty())
2213
							continue;
2217
								continue;
2214
						if ( sceneModels->FindString(strs[i]) )
2218
							if (sceneModels.contains(strs[i]))
2215
							this->AddBody(sSection, strs[i].ToString());
2219
								this->addBody(sSection, strs[i]);
2216
						--section;
2220
							--section;
-
 
2221
						}
2217
					}
2222
					}
-
 
2223
					CLEANSPLIT(strs, max)
2218
				}
2224
				}
2219
				CLEANSPLIT(strs, max)
-
 
2220
			}
2225
			}
-
 
2226
			return true;
2221
		}
2227
		}
2222
		delete lines;
-
 
2223
		return true;
-
 
2224
	}
2228
	}
2225
 
2229
 
2226
	return false;
2230
	return false;
2227
}
2231
}
2228
 
2232
 
2229
bool CXspFile::ImportCockpits(const Utils::String &filename)
2233
bool CXspFile::ImportCockpits(const Utils::String &filename)
2230
{
2234
{
2231
	CFileIO File(filename);
2235
	CFileIO File(filename);
2232
	if ( File.exists() )
2236
	if ( File.exists() )
2233
	{
2237
	{
2234
		CyStringList *lines = File.ReadLinesStr();
2238
		std::vector<Utils::String> lines;
2235
		int entries = 0;
2239
		if (File.readLines(lines))
2236
		for ( SStringList *node = lines->Head(); node; node = node->next )
-
 
2237
		{
2240
		{
2238
			node->str.RemoveChar(9);
-
 
2239
			node->str.RemoveChar('\r');
-
 
2240
			node->str.RemoveFirstSpace();
-
 
2241
			if ( node->str.Empty() )
-
 
2242
				node->remove = true;
2241
			int entries = 0;
2243
			else if ( node->str[0] == '/' )
-
 
2244
				node->remove = true;
2242
			auto itr = lines.begin();
2245
			else if ( !entries )
2243
			while(itr != lines.end())
2246
			{
2244
			{
-
 
2245
				Utils::String str = itr->remove(9).remove('\r');
-
 
2246
				str.removeFirstSpace();
-
 
2247
				if (str.empty())
-
 
2248
					itr = lines.erase(itr);
-
 
2249
				else if (str[0] == '/')
-
 
2250
					itr = lines.erase(itr);
-
 
2251
				else if (!entries)
-
 
2252
				{
2247
				entries = node->str.GetToken(";", 2, 2).ToInt();
2253
					entries = str.token(";", 2).toInt();
2248
				node->remove = true;
2254
					itr = lines.erase(itr);
-
 
2255
				}
-
 
2256
				else
-
 
2257
					itr++;
2249
			}
2258
			}
2250
		}
-
 
2251
		lines->RemoveMarked();
-
 
2252
 
2259
 
2253
		// now get all the entries from TShips
2260
			// now get all the entries from TShips
2254
		for ( int i = 0; i <; 6; i++ )
2261
			for (int i = 0; i <; 6; i++)
2255
		{
2262
			{
2256
			int idx = m_sData.token(";", 32 + (i * 2));
2263
				int idx = m_sData.token(";", 32 + (i * 2));
2257
			if ( idx < lines->Count() &amp;&amp; idx )
2264
				if (static_cast<size_t>(idx) < lines.size() &amp;&amp; idx)
2258
			{
2265
				{
2259
				Utils::String turret = lines->GetAt(idx)->str.ToString();
2266
					Utils::String turret = lines[idx];
2260
				int pos = -1;
2267
					int pos = -1;
2261
				Utils::String id;
2268
					Utils::String id;
2262
				while ( id.empty() &;& pos > -100 ) id = turret.token(";", pos--);
2269
					while (id.empty() &&; pos > -100) id = turret.token(";", pos--);
2263
				m_sData = m_sData.replaceToken(";", 32 + (i * 2), id + "(" + (long)idx + ")");
2270
					m_sData = m_sData.replaceToken(";", 32 + (i * 2), id + "(" + (long)idx + ")");
2264
 
2271
 
2265
				this->AddCockpit(turret, 0);
2272
					this->AddCockpit(turret, 0);
-
 
2273
				}
2266
			}
2274
			}
2267
		}
2275
		}
2268
 
-
 
2269
		delete lines;
-
 
2270
		return true;
2276
		return true;
2271
	}
2277
	}
2272
	return false;
2278
	return false;
2273
}
2279
}
2274
 
2280
 
Line 2282... Line 2288...
2282
	}
2288
	}
2283
 
2289
 
2284
	return false;
2290
	return false;
2285
}
2291
}
2286
 
2292
 
2287
bool CXspFile::extractBodies(CVirtualFileSystem *pVfs, CyStringList *sceneModels)
2293
bool CXspFile::extractBodies(CVirtualFileSystem *pVfs, const Utils::CStringList &sceneModels)
2288
{
2294
{
2289
	if ( !sceneModels ) return false;
2295
	if (sceneModels.empty()) return false;
2290
 
2296
 
2291
	if ( !pVfs->ExtractGameFile("types/Bodies.pck", CPackages::tempDirectory() + "tmp.dat").empty() ) {
2297
	if ( !pVfs->ExtractGameFile("types/Bodies.pck", CPackages::tempDirectory() + "tmp.dat").empty() ) {
2292
		bool ret = this->ImportBodies(sceneModels, CPackages::tempDirectory() + "tmp.dat");
2298
		bool ret = this->importBodies(sceneModels, CPackages::tempDirectory() + "tmp.dat");
2293
		CFileIO::Remove(CPackages::tempDirectory() + "tmp.dat");
2299
		CFileIO::Remove(CPackages::tempDirectory() + "tmp.dat");
2294
 
2300
 
2295
		return ret;
2301
		return ret;
2296
	}
2302
	}
2297
 
2303
 
Line 2444... Line 2450...
2444
			CFileIO::Remove(CPackages::tempDirectory() + "/tmp.dat");
2450
			CFileIO::Remove(CPackages::tempDirectory() + "/tmp.dat");
2445
		}
2451
		}
2446
	}
2452
	}
2447
}
2453
}
2448
 
2454
 
2449
bool CXspFile::processSceneFileSection(int section, CVirtualFileSystem *pVfs, CyStringList *lModels, CProgressInfo *progress)
2455
bool CXspFile::processSceneFileSection(int section, CVirtualFileSystem *pVfs, Utils::CStringList &lModels, CProgressInfo *progress)
2450
{
2456
{
2451
	if ( progress ) progress->UpdateStatus(section);
2457
	if ( progress ) progress->UpdateStatus(section);
2452
 
2458
 
2453
	switch ( section )
2459
	switch ( section )
2454
	{
2460
	{
2455
		case IMPORTSHIP_COMPONANT:
2461
		case IMPORTSHIP_COMPONANT:
2456
			if ( !lModels ) return false;
2462
			if (lModels.empty()) return false;
2457
			this->extractComponants(pVfs, lModels);
2463
			this->extractComponants(pVfs, lModels);
2458
			break;
2464
			break;
2459
 
2465
 
2460
		case IMPORTSHIP_MODELS:
2466
		case IMPORTSHIP_MODELS:
2461
			{
2467
			{
2462
				if ( !lModels ) return false;
2468
				if (lModels.empty()) return false;
2463
				for ( SStringList *node = lModels->Head(); node; node = node->;next )
2469
				for(auto itr = lModels.begin(); itr != lModels.end(); itr++)
2464
				{
2470
				{
2465
					if ( node->str.IsNumber() ) // count be componants or dummy
2471
					if ((*itr)->str.isNumber() ) // count be componants or dummy
2466
						continue;
2472
						continue;
2467
					if ( pVfs->extractGameFileToPackage(this, "objects\\" + Utils::String(node->str.ToString()) + ".pbb&quot;, FILETYPE_SHIPMODEL, "objects\\" + Utils::String(node->str.ToString()) + ".bob") )
2473
					if ( pVfs->extractGameFileToPackage(this, "objects\\" + (*itr)->str + ".pbb&quot;, FILETYPE_SHIPMODEL, "objects\\" + (*itr)->str + ".bob") )
2468
						continue;
2474
						continue;
2469
					if ( pVfs->extractGameFileToPackage(this, "objects\\" + Utils::String(node->str.ToString()) + ".pbd&quot;, FILETYPE_SHIPMODEL, "objects\\" + Utils::String(node->str.ToString()) + ".bod") )
2475
					if ( pVfs->extractGameFileToPackage(this, "objects\\" + (*itr)->str + ".pbd&quot;, FILETYPE_SHIPMODEL, "objects\\" + (*itr)->str + ".bod") )
2470
						continue;
2476
						continue;
2471
				}
2477
				}
2472
			}
2478
			}
2473
			break;
2479
			break;
2474
 
2480
 
2475
		case IMPORTSHIP_DUMMIES:
2481
		case IMPORTSHIP_DUMMIES:
2476
			if ( !lModels ) return false;
2482
			if (lModels.empty()) return false;
2477
			this->extractDummies(pVfs, lModels, true);
2483
			this->extractDummies(pVfs, lModels, true);
2478
			this->extractCutData(pVfs, lModels, true);
2484
			this->extractCutData(pVfs, lModels, true);
2479
			break;
2485
			break;
2480
 
2486
 
2481
		// extract the textures
2487
		// extract the textures
Line 2488... Line 2494...
2488
			pVfs->extractTexts(this, m_sData.token(";", 7));
2494
			pVfs->extractTexts(this, m_sData.token(";", 7));
2489
			break;
2495
			break;
2490
 
2496
 
2491
		case IMPORTSHIP_BODIES:
2497
		case IMPORTSHIP_BODIES:
2492
			// extract the bodies entries
2498
			// extract the bodies entries
2493
			if ( !lModels ) return false;
2499
			if (lModels.empty()) return false;
2494
			this->extractBodies(pVfs, lModels);
2500
			this->extractBodies(pVfs, lModels);
2495
			break;
2501
			break;
2496
 
2502
 
2497
		case IMPORTSHIP_COCKPITS:
2503
		case IMPORTSHIP_COCKPITS:
2498
			// extract the cockpit entries
2504
			// extract the cockpit entries
Line 2505... Line 2511...
2505
 
2511
 
2506
bool CXspFile::processSceneFiles(CVirtualFileSystem *pVfs, CProgressInfo *progress)
2512
bool CXspFile::processSceneFiles(CVirtualFileSystem *pVfs, CProgressInfo *progress)
2507
{
2513
{
2508
	// now lets parse our files
2514
	// now lets parse our files
2509
	if ( progress ) progress->UpdateStatus(IMPORTSHIP_EXTRACTSCENE);
2515
	if ( progress ) progress->UpdateStatus(IMPORTSHIP_EXTRACTSCENE);
2510
	CyStringList *lModels = this->ReadSceneModels();
2516
	Utils::CStringList lModels;
2511
	if ( !lModels )
2517
	if(!readSceneModels(lModels))
2512
		return false;
2518
		return false;
2513
 
2519
 
2514
	// extract componants, and add extra items to list
2520
	// extract componants, and add extra items to list
2515
	if ( !this->processSceneFileSection(IMPORTSHIP_COMPONANT, pVfs, lModels, progress) )
2521
	if ( !this->processSceneFileSection(IMPORTSHIP_COMPONANT, pVfs, lModels, progress) )
2516
		return false;
2522
		return false;
Line 2536... Line 2542...
2536
		return false;
2542
		return false;
2537
 
2543
 
2538
	// extract the cockpit entries
2544
	// extract the cockpit entries
2539
	if ( !this->processSceneFileSection(IMPORTSHIP_COCKPITS, pVfs, lModels, progress) )
2545
	if ( !this->processSceneFileSection(IMPORTSHIP_COCKPITS, pVfs, lModels, progress) )
2540
		return false;
2546
		return false;
2541
 
-
 
2542
	delete lModels;
-
 
2543
 
2547
 
2544
	return true;
2548
	return true;
2545
}
2549
}
2546
 
2550
 
2547
 
2551
 
Line 2585... Line 2589...
2585
				m_sData = m_sData.replaceToken(";", 32 + (i * 2), (id + "(" + Utils::String::Number(c->iIndex) + ")").c_str());
2589
				m_sData = m_sData.replaceToken(";", 32 + (i * 2), (id + "(" + Utils::String::Number(c->iIndex) + ")").c_str());
2586
		}
2590
		}
2587
	}
2591
	}
2588
}
2592
}
2589
 
2593
 
2590
Utils::String CXspFile::FormatShipData(CyStringList *cockpits, int *text, int game)
2594
Utils::String CXspFile::formatShipData(const Utils::CStringList &cockpits, int *text, int game)
2591
{
2595
{
2592
	Utils::String data = (game == GAME_X3) ? this->GetX3ShipData() : this->GetTCShipData();
2596
	Utils::String data = (game == GAME_X3) ? this->GetX3ShipData() : this->GetTCShipData();
2593
	// do turrets
2597
	// do turrets
2594
	for ( int t = 0; t < 6; t++ )
2598
	for ( int t = 0; t < 6; t++ )
2595
	{
2599
	{
Line 2600... Line 2604...
2600
			if ( turret.isin("(") )
2604
			if ( turret.isin("(") )
2601
			{
2605
			{
2602
				oldPos = turret.tokens("(", 2).token(")", 1);
2606
				oldPos = turret.tokens("(", 2).token(")", 1);
2603
				turret = turret.token("(", 1);
2607
				turret = turret.token("(", 1);
2604
			}
2608
			}
2605
			int pos = cockpits->FindStringPos(turret);
2609
			int pos = cockpits.findPos(turret);
2606
			if ( pos < 0 )	pos = oldPos;
2610
			if ( pos < 0 )	pos = oldPos;
2607
			if ( pos >= cockpits->Count() ) pos = 0;
2611
			if (static_cast<size_t>(pos) >= cockpits.size()) pos = 0;
2608
			data = data.replaceToken(";", 32 + (t * 2), (long)pos);
2612
			data = data.replaceToken(";", 32 + (t * 2), (long)pos);
2609
		}
2613
		}
2610
	}
2614
	}
2611
	// adjust the weapons
2615
	// adjust the weapons
2612
	int mask = this->GetLaserMask(game - 1);
2616
	int mask = this->GetLaserMask(game - 1);