Subversion Repositories spk

Rev

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

Rev 178 Rev 179
Line 5410... Line 5410...
5410
	}
5410
	}
5411
 
5411
 
5412
	return count;
5412
	return count;
5413
}
5413
}
5414
 
5414
 
5415
int CPackages::CountPackages(int type, bool onlyEnabled)
5415
int CPackages::countPackages(int type, bool onlyEnabled) const
5416
{
5416
{
5417
	int count = 0;
5417
	int count = 0;
5418
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
5418
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
5419
	{
5419
	{
5420
		CBaseFile *p = node->Data();
5420
		CBaseFile *p = node->Data();
Line 6059... Line 6059...
6059
		writeData.push_back("	<page id=\"" + (long)gameNumber + Utils::String::PadNumber(PMTEXTFILE, 4) + "\" title=\"Plugin Manager Text File\" descr=\"Contains text used for the plugin manager, packages, settings, wares, ship, etc\">");
6059
		writeData.push_back("	<page id=\"" + (long)gameNumber + Utils::String::PadNumber(PMTEXTFILE, 4) + "\" title=\"Plugin Manager Text File\" descr=\"Contains text used for the plugin manager, packages, settings, wares, ship, etc\">");
6060
 
6060
 
6061
	// write the heading
6061
	// write the heading
6062
	int start = 10000;
6062
	int start = 10000;
6063
	writeData.push_back("		<t id=\"1\">" + Utils::String::Number(m_iLastUpdated) + "</t>");
6063
	writeData.push_back("		<t id=\"1\">" + Utils::String::Number(m_iLastUpdated) + "</t>");
6064
	writeData.push_back("		<t id=\"2\">" + Utils::String::Number(this->CountPackages(TYPE_SPK, true)) + "</t>");
6064
	writeData.push_back("		<t id=\"2\">" + Utils::String::Number(this->countPackages(TYPE_SPK, true)) + "</t>");
6065
	writeData.push_back("		<t id=\"3\">" + Utils::String::Number(start) + "</t>");
6065
	writeData.push_back("		<t id=\"3\">" + Utils::String::Number(start) + "</t>");
6066
	writeData.push_back("		<t id=\"4\">" + Utils::String::Number(lWares.size()) + "</t>");
6066
	writeData.push_back("		<t id=\"4\">" + Utils::String::Number(lWares.size()) + "</t>");
6067
	writeData.push_back("		<t id=\"6\">" + Utils::String::Number(lShips.size()) + "</t>");
6067
	writeData.push_back("		<t id=\"6\">" + Utils::String::Number(lShips.size()) + "</t>");
6068
 
6068
 
6069
	// write some generic texts
6069
	// write some generic texts
Line 6412... Line 6412...
6412
}
6412
}
6413
 
6413
 
6414
void CPackages::CreateDummies()
6414
void CPackages::CreateDummies()
6415
{
6415
{
6416
	// first check we have any ships
6416
	// first check we have any ships
6417
	if ( m_lGameShips.empty() || !this->CountPackages(TYPE_XSP, true) )
6417
	if ( m_lGameShips.empty() || !this->countPackages(TYPE_XSP, true) )
6418
		return;
6418
		return;
6419
 
6419
 
6420
	CLinkList<SDummyEntry> dummyList;
6420
	CLinkList<SDummyEntry> dummyList;
6421
 
6421
 
6422
	// now extract the existing dummies
6422
	// now extract the existing dummies
Line 6592... Line 6592...
6592
}
6592
}
6593
 
6593
 
6594
void CPackages::CreateCutData()
6594
void CPackages::CreateCutData()
6595
{
6595
{
6596
	// first check we have any ships
6596
	// first check we have any ships
6597
	if ( m_lGameShips.empty() || !this->CountPackages(TYPE_XSP, true) )
6597
	if ( m_lGameShips.empty() || !this->countPackages(TYPE_XSP, true) )
6598
		return;
6598
		return;
6599
 
6599
 
6600
	bool found = false;
6600
	bool found = false;
6601
	for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
6601
	for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
6602
	{
6602
	{
Line 6612... Line 6612...
6612
	}
6612
	}
6613
 
6613
 
6614
	if ( !found )
6614
	if ( !found )
6615
		return;
6615
		return;
6616
 
6616
 
6617
	CyStringList cutList;
6617
	std::vector<Utils::String> cutList;
6618
	int e = ExtractGameFile("types/CutData.pck", m_sTempDir + "/CutData.txt");
6618
	int e = ExtractGameFile("types/CutData.pck", m_sTempDir + "/CutData.txt");
6619
	if ( e )
6619
	if ( e )
6620
	{
6620
	{
6621
		CFileIO File;
6621
		CFileIO File;
6622
		if ( File.open((e == -1) ? "CutData.txt" : m_sTempDir + "/CutData.txt") )
6622
		if ( File.open((e == -1) ? "CutData.txt" : m_sTempDir + "/CutData.txt") )
6623
		{
6623
		{
-
 
6624
 
6624
			std::vector<Utils::String> *lines = File.readLines();
6625
			std::vector<Utils::String> lines;
6625
			if ( lines )
6626
			if(File.readLines(lines))
6626
			{
6627
			{
6627
				int entries = -1;
6628
				int entries = -1;
6628
				for ( int j = 0; j < (int)lines->size(); j++ )
6629
				for ( int j = 0; j < (int)lines.size(); j++ )
6629
				{
6630
				{
6630
					Utils::String line(lines->at(j));
6631
					Utils::String line(lines.at(j));
6631
					line.removeChar(9);
6632
					line.removeChar(9);
6632
					line.removeChar('\r');
6633
					line.removeChar('\r');
6633
					line.removeChar(' ');
6634
					line.removeChar(' ');
6634
					if ( line.empty() || line[0] == '/' )
6635
					if ( line.empty() || line[0] == '/' )
6635
						continue;
6636
						continue;
Line 6637... Line 6638...
6637
						entries = line.token(";", 1).toInt();
6638
						entries = line.token(";", 1).toInt();
6638
					else
6639
					else
6639
					{
6640
					{
6640
						if ( line.right(1) != ";" )
6641
						if ( line.right(1) != ";" )
6641
							line += ";";
6642
							line += ";";
6642
						cutList.PushBack(CyString(line));
6643
						cutList.push_back(line);
6643
						if ( cutList.Count() == entries )
6644
						if ( static_cast<int>(cutList.size()) == entries)
6644
							break;
6645
							break;
6645
					}
6646
					}
6646
				}
6647
				}
6647
 
-
 
6648
				delete lines;
-
 
6649
			}
6648
			}
6650
 
6649
 
6651
			File.remove();
6650
			File.remove();
6652
		}
6651
		}
6653
	}
6652
	}
Line 6668... Line 6667...
6668
		{
6667
		{
6669
			Utils::String str = (*itr)->str;
6668
			Utils::String str = (*itr)->str;
6670
			str.removeChar(' ');
6669
			str.removeChar(' ');
6671
			if ( str.right(1) != ";" )
6670
			if ( str.right(1) != ";" )
6672
				str += ";";
6671
				str += ";";
-
 
6672
			if(std::find(cutList.begin(), cutList.end(), str) == cutList.end())
6673
			cutList.PushBack(CyString(str), true);
6673
				cutList.push_back(str);
6674
		}
6674
		}
6675
	}
6675
	}
6676
 
6676
 
6677
	cutList.PushFront(CyString::Number(cutList.Count()) + ";");
6677
	cutList.insert(cutList.begin(), Utils::String::Number(cutList.size()) + ";");
6678
	cutList.PushFront("/cut id;filename (leave blank to use id)");
6678
	cutList.insert(cutList.begin(), "/cut id;filename (leave blank to use id)");
6679
	cutList.PushFront(CyString("// Cut Data file, created by SPK Libraries V") + CyString::CreateFromFloat(GetLibraryVersion(), 2));
6679
	cutList.insert(cutList.begin(), "// Cut Data file, created by SPK Libraries V" + Utils::String::FromFloat(GetLibraryVersion(), 2));
6680
 
6680
 
6681
	// write the file to disk
6681
	// write the file to disk
6682
	CFileIO WriteFile(m_sTempDir + "/CutData.txt");
6682
	CFileIO WriteFile(m_sTempDir + "/CutData.txt");
6683
	if ( WriteFile.WriteFile(&cutList) )
6683
	if ( WriteFile.writeFile(&cutList) )
6684
	{
6684
	{
6685
		this->PackFile(&WriteFile, "types\\CutData.pck");
6685
		this->PackFile(&WriteFile, "types\\CutData.pck");
6686
		WriteFile.remove();
6686
		WriteFile.remove();
6687
	}
6687
	}
6688
}
6688
}
6689
 
6689
 
6690
void CPackages::CreateAnimations()
6690
void CPackages::CreateAnimations()
6691
{
6691
{
6692
	// first check we have any ships
6692
	// first check we have any ships
6693
	if ( m_lGameShips.empty() || !this->CountPackages(TYPE_XSP, true) )
6693
	if ( m_lGameShips.empty() || !this->countPackages(TYPE_XSP, true) )
6694
		return;
6694
		return;
6695
 
6695
 
6696
	bool found = false;
6696
	bool found = false;
6697
	for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
6697
	for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
6698
	{
6698
	{
Line 6839... Line 6839...
6839
}
6839
}
6840
 
6840
 
6841
void CPackages::CreateBodies()
6841
void CPackages::CreateBodies()
6842
{
6842
{
6843
	// first check we have any ships
6843
	// first check we have any ships
6844
	if ( m_lGameShips.empty() || !this->CountPackages(TYPE_XSP, true) )
6844
	if ( m_lGameShips.empty() || !this->countPackages(TYPE_XSP, true) )
6845
		return;
6845
		return;
6846
 
6846
 
6847
	bool found = false;
6847
	bool found = false;
6848
	for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
6848
	for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
6849
	{
6849
	{
Line 6902... Line 6902...
6902
									currentSection->lEntries.pushBack(strs[i] + ";");
6902
									currentSection->lEntries.pushBack(strs[i] + ";");
6903
								--entries;
6903
								--entries;
6904
							}
6904
							}
6905
						}
6905
						}
6906
						CLEANSPLIT(strs, num);
6906
						CLEANSPLIT(strs, num);
6907
					}
6907
					}
6908
				}
6908
				}
6909
 
6909
 
6910
				delete lines;
6910
				delete lines;
6911
			}
6911
			}
6912
			File.remove();
6912
			File.remove();
Line 7051... Line 7051...
7051
}
7051
}
7052
 
7052
 
7053
void CPackages::CreateComponants()
7053
void CPackages::CreateComponants()
7054
{
7054
{
7055
	// first check we have any ships
7055
	// first check we have any ships
7056
	if ( m_lGameShips.empty() || !this->CountPackages(TYPE_XSP, true) )
7056
	if ( m_lGameShips.empty() || !this->countPackages(TYPE_XSP, true) )
7057
		return;
7057
		return;
7058
 
7058
 
7059
	CLinkList<SComponantEntry> dummyList;
7059
	CLinkList<SComponantEntry> dummyList;
7060
 
7060
 
7061
	// now extract the existing dummies
7061
	// now extract the existing dummies
Line 7308... Line 7308...
7308
		if ( node->Data()->type == type && node->Data()->bNotority ) {
7308
		if ( node->Data()->type == type && node->Data()->bNotority ) {
7309
			if ( node->Data()->type == Ware_Custom && !id.Compare(node->Data()->id) ) continue;
7309
			if ( node->Data()->type == Ware_Custom && !id.Compare(node->Data()->id) ) continue;
7310
			else if ( node->Data()->type != Ware_Custom && node->Data()->pos != pos ) continue;
7310
			else if ( node->Data()->type != Ware_Custom && node->Data()->pos != pos ) continue;
7311
		
7311
		
7312
			(*noto) = node->Data()->notority;
7312
			(*noto) = node->Data()->notority;
7313
			return true;
7313
			return true;
7314
		}
7314
		}
7315
	}
7315
	}
7316
	return false;
7316
	return false;
7317
}
7317
}
7318
 
7318
 
7319
void CPackages::_removeWareOverride(enum WareTypes type, int pos, const Utils::String &id)
7319
void CPackages::_removeWareOverride(enum WareTypes type, int pos, const Utils::String &id)
7320
{
7320
{
7321
	for(CListNode<SWarePriceOverride> *node = m_lWarePrices.Front(); node; node = node->next()) {
7321
	for(CListNode<SWarePriceOverride> *node = m_lWarePrices.Front(); node; node = node->next()) {
Line 7327... Line 7327...
7327
		}
7327
		}
7328
	}
7328
	}
7329
}
7329
}
7330
 
7330
 
7331
int CPackages::empOveridePrice(int id)
7331
int CPackages::empOveridePrice(int id)
7332
{
7332
{
7333
	return _warePriceOverride(Ware_EMP, id, Utils::String::Null()); 
7333
	return _warePriceOverride(Ware_EMP, id, Utils::String::Null()); 
7334
}
7334
}
7335
 
7335
 
7336
bool CPackages::empOverideNoto(int id, int *noto)
7336
bool CPackages::empOverideNoto(int id, int *noto)
7337
{
7337
{
7338
	return _wareNotoOverride(Ware_EMP, id, Utils::String::Null(), noto);
7338
	return _wareNotoOverride(Ware_EMP, id, Utils::String::Null(), noto);
7339
}
7339
}
7340
 
7340
 
7341
int CPackages::builtInWareOveridePrice(int id)
7341
int CPackages::builtInWareOveridePrice(int id)
7342
{
7342
{
7343
	return _warePriceOverride(Ware_BuiltIn, id, Utils::String::Null()); 
7343
	return _warePriceOverride(Ware_BuiltIn, id, Utils::String::Null()); 
7344
}
7344
}
7345
 
7345
 
7346
bool CPackages::builtInWareOverideNoto(int id, int *noto)
7346
bool CPackages::builtInWareOverideNoto(int id, int *noto)
7347
{
7347
{
7348
	return _wareNotoOverride(Ware_BuiltIn, id, Utils::String::Null(), noto);
7348
	return _wareNotoOverride(Ware_BuiltIn, id, Utils::String::Null(), noto);
7349
}
7349
}
7350
 
7350
 
7351
int CPackages::customWareOveridePrice(const Utils::String &id)
7351
int CPackages::customWareOveridePrice(const Utils::String &id)
7352
{
7352
{
7353
	return _warePriceOverride(Ware_Custom, 0, id); 
7353
	return _warePriceOverride(Ware_Custom, 0, id); 
7354
}
7354
}
7355
 
7355
 
7356
bool CPackages::customWareOverideNoto(const Utils::String &id, int *noto)
7356
bool CPackages::customWareOverideNoto(const Utils::String &id, int *noto)
7357
{
7357
{
7358
	return _wareNotoOverride(Ware_Custom, 0, id, noto);
7358
	return _wareNotoOverride(Ware_Custom, 0, id, noto);
7359
}
7359
}
7360
 
7360
 
7361
void CPackages::removeEmpOverride(int pos)
7361
void CPackages::removeEmpOverride(int pos)
7362
{
7362
{
7363
	_removeWareOverride(Ware_EMP, pos, Utils::String::Null());
7363
	_removeWareOverride(Ware_EMP, pos, Utils::String::Null());
7364
}
7364
}
7365
 
7365
 
7366
void CPackages::removeBuiltinWareOverride(int pos)
7366
void CPackages::removeBuiltinWareOverride(int pos)
7367
{
7367
{
7368
	_removeWareOverride(Ware_BuiltIn, pos, Utils::String::Null());
7368
	_removeWareOverride(Ware_BuiltIn, pos, Utils::String::Null());
7369
}
7369
}
7370
 
7370
 
7371
void CPackages::removeCustomWareOverride(const Utils::String &id)
7371
void CPackages::removeCustomWareOverride(const Utils::String &id)
7372
{
7372
{
7373
	_removeWareOverride(Ware_Custom, 0, id);
7373
	_removeWareOverride(Ware_Custom, 0, id);
7374
}
7374
}
7375
 
7375
 
7376
 
7376
 
7377
bool CPackages::readGlobals(Utils::CStringList &globals) const
7377
bool CPackages::readGlobals(Utils::CStringList &globals) const
7378
{
7378
{
7379
	int e = extractGameFile("types/Globals.pck", m_sTempDir);
7379
	int e = extractGameFile("types/Globals.pck", m_sTempDir);
7380
	if ( e )
7380
	if ( e )
7381
	{
7381
	{
7382
		CFileIO File((e == -1) ? "Globals.txt" : m_sTempDir + "/Globals.txt");
7382
		CFileIO File((e == -1) ? "Globals.txt" : m_sTempDir + "/Globals.txt");
7383
		if ( File.exists() )
7383
		if ( File.exists() )
7384
		{
7384
		{
7385
			std::vector<Utils::String> lines;
7385
			std::vector<Utils::String> lines;
7386
			if(File.readLines(lines))
7386
			if(File.readLines(lines))
7387
			{
7387
			{
7388
				int entries = -1;
7388
				int entries = -1;
7389
				for(auto itr = lines.begin(); itr != lines.end(); itr++)
7389
				for(auto itr = lines.begin(); itr != lines.end(); itr++)
Line 7413... Line 7413...
7413
 
7413
 
7414
	return false;
7414
	return false;
7415
}
7415
}
7416
 
7416
 
7417
void CPackages::CreateGlobals()
7417
void CPackages::CreateGlobals()
7418
{
7418
{
7419
	if ( m_lGlobals.empty() )
7419
	if ( m_lGlobals.empty() )
7420
		return; // no global settings
7420
		return; // no global settings
7421
 
7421
 
7422
	Utils::CStringList globals;
7422
	Utils::CStringList globals;
7423
	if (readGlobals(globals))
7423
	if (readGlobals(globals))
Line 7447... Line 7447...
7447
void CPackages::CreateTShips()
7447
void CPackages::CreateTShips()
7448
{
7448
{
7449
	// no ships ?
7449
	// no ships ?
7450
	if ( m_lGameShips.empty() )
7450
	if ( m_lGameShips.empty() )
7451
		return;
7451
		return;
7452
 
7452
 
7453
	// get the cockpit list to match with ships turrets
7453
	// get the cockpit list to match with ships turrets
7454
	Utils::CStringList Cockpits;
7454
	Utils::CStringList Cockpits;
7455
	CyStringList *cockpitList = this->CreateCockpits();
7455
	Utils::CStringList cockpitList;
7456
	if ( cockpitList )
7456
	if(_createCockpits(cockpitList))
7457
	{
7457
	{
7458
		for ( SStringList *str = cockpitList->Head(); str; str = str->;next )
7458
		for(auto itr = cockpitList.begin(); itr != cockpitList.end(); itr++)
7459
		{
7459
		{
7460
			CyString id = str->str.GetToken(";;", 19, 19);
7460
			Utils::String id = (*itr)->str.token(";;", 19);
7461
			Cockpits.pushBack(id.ToString());
7461
			Cockpits.pushBack(id);
7462
		}
7462
		}
7463
 
-
 
7464
		delete cockpitList;
-
 
7465
	}
7463
	}
7466
 
7464
 
7467
	CLinkList<SGameShip> shipOverrides;
7465
	CLinkList<SGameShip> shipOverrides;
7468
	for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
7466
	for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
7469
	{
7467
	{
Line 7477... Line 7475...
7477
	// read the existing tships file
7475
	// read the existing tships file
7478
	int e = ExtractGameFile("types/TShips.pck", m_sTempDir + "/TShips.txt");
7476
	int e = ExtractGameFile("types/TShips.pck", m_sTempDir + "/TShips.txt");
7479
	if ( e )
7477
	if ( e )
7480
	{
7478
	{
7481
		int fileType = 51;
7479
		int fileType = 51;
7482
		CyStringList tshipsList;
7480
		std::vector<Utils::String> tshipsList;
7483
 
7481
 
7484
		// if we have no buffer, lets create one
7482
		// if we have no buffer, lets create one
7485
		CFileIO File;
7483
		CFileIO File;
7486
		if ( File.open((e == -1) ? "TShips.txt" : m_sTempDir + "/TShips.txt") )
7484
		if ( File.open((e == -1) ? "TShips.txt" : m_sTempDir + "/TShips.txt") )
7487
		{
7485
		{
7488
			int shiptext = SHIPSTARTTEXT;
7486
			int shiptext = SHIPSTARTTEXT;
7489
 
7487
 
7490
			std::vector<Utils::String> *lines = File.readLines();
7488
			std::vector<Utils::String> *lines = File.readLines();
7491
			if ( lines )
7489
			if ( lines )
7492
			{
7490
			{
7493
				int count = -1;
7491
				int count = -1;
7494
				for ( int j = 0; j < (int)lines->size(); j++ )
7492
				for ( int j = 0; j < (int)lines->size(); j++ )
7495
				{
7493
				{
7496
					Utils::String line(lines->at(j));
7494
					Utils::String line(lines->at(j));
7497
					if ( line[0] == '/' )
7495
					if ( line[0] == '/' )
Line 7526... Line 7524...
7526
									if ( !s->pPackage->GetShipID().Compare(shipData.sID) )
7524
									if ( !s->pPackage->GetShipID().Compare(shipData.sID) )
7527
										continue;
7525
										continue;
7528
									s->iText = shiptext;
7526
									s->iText = shiptext;
7529
									if ( !s->pPackage->GetOriginalDescription() )
7527
									if ( !s->pPackage->GetOriginalDescription() )
7530
										shiptext += 2;
7528
										shiptext += 2;
7531
									s->iPos = tshipsList.Count();
7529
									s->iPos = tshipsList.size();
7532
									added = true;
7530
									added = true;
7533
									tshipsList.PushBack(CyString(s->pPackage->formatShipData(Cockpits, &s->iText, m_iGame)));
7531
									tshipsList.push_back(s->pPackage->formatShipData(Cockpits, &s->iText, m_iGame));
7534
									shipOverrides.remove(node);
7532
									shipOverrides.remove(node);
7535
									break;
7533
									break;
7536
								}
7534
								}
7537
							}
7535
							}
7538
						}
7536
						}
7539
 
7537
 
7540
						if ( !added )
7538
						if ( !added )
7541
							tshipsList.PushBack(CyString(line));
7539
							tshipsList.push_back(line);
7542
						--count;
7540
						--count;
7543
						if ( count < 0 )
7541
						if ( count < 0 )
7544
							break;
7542
							break;
7545
					}
7543
					}
7546
				}
7544
				}
Line 7551... Line 7549...
7551
 
7549
 
7552
			File.remove();
7550
			File.remove();
7553
 
7551
 
7554
			// assign the ship buffer
7552
			// assign the ship buffer
7555
			if ( !m_iShipBuffer )
7553
			if ( !m_iShipBuffer )
7556
				m_iShipBuffer = tshipsList.Count() + 15;
7554
				m_iShipBuffer = tshipsList.size() + 15;
7557
			// there seems to be too many additional entries, we have no choise but to change the buffer
7555
			// there seems to be too many additional entries, we have no choise but to change the buffer
7558
			else if ( m_iShipBuffer <= tshipsList.Count() )
7556
			else if ( static_cast<size_t>(m_iShipBuffer) <= tshipsList.size() )
7559
				m_iShipBuffer = tshipsList.Count() + 15;
7557
				m_iShipBuffer = tshipsList.size() + 15;
7560
 
7558
 
7561
			CyString bufferStart;
7559
			Utils::String bufferStart;
7562
			if ( m_iGame == GAME_X3 )
7560
			if ( m_iGame == GAME_X3 )
7563
				bufferStart = "0;0;0;0;0;2;499999;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0.049988;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;4;1;0;0;0;0;0;0;2092;1;1;-1;0;0;1;1;0;1;1;1;0;0;0;;-1;0;0;0;0;0;0;0;0;0;";
7561
				bufferStart = "0;0;0;0;0;2;499999;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0.049988;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;4;1;0;0;0;0;0;0;2092;1;1;-1;0;0;1;1;0;1;1;1;0;0;0;;-1;0;0;0;0;0;0;0;0;0;";
7564
			else
7562
			else
7565
				bufferStart = "0;0;0;0;0;SG_SH_M5;499999;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0.049988;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;4;1;0;0;0;0;0;0;OBJ_BEACON;1;1;-1;0;0;1;1;0;1;1;1;0;0;0;;-1;0;0;0;0;0;0;0;0;0;";
7563
				bufferStart = "0;0;0;0;0;SG_SH_M5;499999;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0.049988;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;4;1;0;0;0;0;0;0;OBJ_BEACON;1;1;-1;0;0;1;1;0;1;1;1;0;0;0;;-1;0;0;0;0;0;0;0;0;0;";
7566
			// add the buffers now
7564
			// add the buffers now
7567
			for ( int i = tshipsList.Count(); i < m_iShipBuffer; i++ )
7565
			for ( int i = tshipsList.size(); i < m_iShipBuffer; i++ )
7568
				tshipsList.PushBack(bufferStart + "SHIP_BUFFER;");
7566
				tshipsList.push_back(bufferStart + "SHIP_BUFFER;");
7569
 
7567
 
7570
			// now lets add our tships line
7568
			// now lets add our tships line
7571
			for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
7569
			for ( CListNode<SGameShip> *node = m_lGameShips.Front(); node; node = node->next() )
7572
			{
7570
			{
7573
				SGameShip *s = node->Data();
7571
				SGameShip *s = node->Data();
7574
				if ( s->pPackage && s->pPackage->IsExistingShip() )
7572
				if ( s->pPackage && s->pPackage->IsExistingShip() )
7575
					continue;
7573
					continue;
7576
				s->iPos = tshipsList.Count();
7574
				s->iPos = tshipsList.size();
7577
				if ( s->iType == WARETYPE_ADDED && s->pPackage )
7575
				if ( s->iType == WARETYPE_ADDED && s->pPackage )
7578
				{
7576
				{
7579
					s->iText = shiptext;
7577
					s->iText = shiptext;
7580
					if ( !s->pPackage->GetOriginalDescription() )
7578
					if ( !s->pPackage->GetOriginalDescription() )
7581
						shiptext += 2;
7579
						shiptext += 2;
7582
 
7580
 
7583
					tshipsList.PushBack(CyString(s->pPackage->formatShipData(Cockpits, &s->iText, m_iGame)));
7581
					tshipsList.push_back(s->pPackage->formatShipData(Cockpits, &s->iText, m_iGame));
7584
				}
7582
				}
7585
				else if ( s->iType == WARETYPE_DELETED )
7583
				else if ( s->iType == WARETYPE_DELETED )
7586
					tshipsList.PushBack(bufferStart + "SHIP_DELETED;");
7584
					tshipsList.push_back(bufferStart + "SHIP_DELETED;");
7587
				else if ( s->iType == WARETYPE_DISABLED )
7585
				else if ( s->iType == WARETYPE_DISABLED )
7588
					tshipsList.PushBack(bufferStart + "SHIP_DISABLED;");
7586
					tshipsList.push_back(bufferStart + "SHIP_DISABLED;");
7589
				else
7587
				else
7590
					tshipsList.PushBack(bufferStart + "SHIP_SPACER;");
7588
					tshipsList.push_back(bufferStart + "SHIP_SPACER;");
7591
			}
7589
			}
7592
 
7590
 
7593
			// finally, write the file
7591
			// finally, write the file
7594
			tshipsList.PushFront(CyString::Number(fileType) + ";" + CyString::Number(tshipsList.Count()) + ";", ";");
7592
			tshipsList.insert(tshipsList.begin(), Utils::String::Number(fileType) + ";" + Utils::String::Number(tshipsList.size()) + ";");
7595
			tshipsList.PushFront(CyString(";// TShips file, created by SPK Libraries V") + CyString::CreateFromFloat(GetLibraryVersion(), 2), "");
7593
			tshipsList.insert(tshipsList.begin(), ";// TShips file, created by SPK Libraries V" + Utils::String::FromFloat(GetLibraryVersion(), 2));
7596
 
7594
 
7597
			CFileIO WriteFile(m_sTempDir + "/TShips.txt");
7595
			CFileIO WriteFile(m_sTempDir + "/TShips.txt");
7598
			if ( WriteFile.WriteFile(&tshipsList) )
7596
			if ( WriteFile.writeFile(&tshipsList) )
7599
			{
7597
			{
7600
				this->PackFile(&WriteFile, "types/TShips.pck");
7598
				this->PackFile(&WriteFile, "types/TShips.pck");
7601
				WriteFile.remove();
7599
				WriteFile.remove();
7602
			}
7600
			}
7603
		}
7601
		}
7604
	}
7602
	}
7605
 
7603
 
7606
}
7604
}
7607
 
7605
 
7608
bool CPackages::PackFile(CyString filename)
7606
bool CPackages::PackFile(CyString filename)
7609
{
7607
{
7610
	// compress the file
7608
	// compress the file
7611
	CFileIO File(filename);
7609
	CFileIO File(filename);
7612
	size_t fileSize;
7610
	size_t fileSize;
7613
	char *fileData = File.ReadToData(&fileSize);
7611
	char *fileData = File.ReadToData(&fileSize);
7614
 
7612
 
7615
	if ( fileData && fileSize)
7613
	if ( fileData && fileSize)
7616
	{
7614
	{
7617
		size_t newFileSize;
7615
		size_t newFileSize;
7618
		unsigned char *pckData = PCKData((unsigned char *)fileData, fileSize, &newFileSize, true);
7616
		unsigned char *pckData = PCKData((unsigned char *)fileData, fileSize, &newFileSize, true);
Line 7621... Line 7619...
7621
			Utils::String ext = "pck";
7619
			Utils::String ext = "pck";
7622
			if ( File.isFileExtension("bob") )
7620
			if ( File.isFileExtension("bob") )
7623
				ext = "pbb";
7621
				ext = "pbb";
7624
			else if ( File.isFileExtension("bod") )
7622
			else if ( File.isFileExtension("bod") )
7625
				ext = "pbd";
7623
				ext = "pbd";
7626
			CFileIO pckFile(File.changeFileExtension(ext));
7624
			CFileIO pckFile(File.changeFileExtension(ext));
7627
			if ( !CDirIO(pckFile.dir()).exists() )
7625
			if ( !CDirIO(pckFile.dir()).exists() )
7628
				CDirIO(pckFile.dir()).create();
7626
				CDirIO(pckFile.dir()).create();
7629
			pckFile.WriteData((char *)pckData, newFileSize);
7627
			pckFile.WriteData((char *)pckData, newFileSize);
7630
			return true;
7628
			return true;
7631
		}
7629
		}
7632
	}
7630
	}
7633
 
7631
 
7634
	return false;
7632
	return false;
7635
}
7633
}
Line 7690... Line 7688...
7690
				if ( pckFile.isOpened() )
7688
				if ( pckFile.isOpened() )
7691
					pckFile.close();
7689
					pckFile.close();
7692
 
7690
 
7693
				if ( isxml )
7691
				if ( isxml )
7694
					pckFile.Rename(pckFile.changeFileExtension("xml"));
7692
					pckFile.Rename(pckFile.changeFileExtension("xml"));
7695
			}
7693
			}
7696
 
7694
 
7697
			return true;
7695
			return true;
7698
		}
7696
		}
7699
	}
7697
	}
7700
 
7698
 
7701
	return false;
7699
	return false;
7702
}
7700
}
7703
 
7701
 
7704
bool CPackages::PackFile(CFileIO *File, CyString sFilename)
7702
bool CPackages::PackFile(CFileIO* File, CyString sFilename)
-
 
7703
{
-
 
7704
	return packFile(File, sFilename.ToString());
-
 
7705
}
-
 
7706
bool CPackages::packFile(CFileIO* File, const Utils::String &sFilename)
7705
{
7707
{
7706
	Utils::String filename = sFilename.FindReplace("\\", "/").ToString();
7708
	Utils::String filename = sFilename.findReplace("\\", "/");
7707
	if ( m_iGame == GAME_X3 )
7709
	if ( m_iGame == GAME_X3 )
7708
	{
7710
	{
7709
		CCatFile catFile;
7711
		CCatFile catFile;
7710
		int error = catFile.open(m_sCurrentDir + "/mods/PluginManager.cat", this->getAddonDir(), CATREAD_CATDECRYPT, true);
7712
		int error = catFile.open(m_sCurrentDir + "/mods/PluginManager.cat", this->getAddonDir(), CATREAD_CATDECRYPT, true);
7711
		if ( error == CATERR_NONE || error == CATERR_CREATED )
7713
		if ( error == CATERR_NONE || error == CATERR_CREATED )
Line 7741... Line 7743...
7741
	}
7743
	}
7742
 
7744
 
7743
	return false;
7745
	return false;
7744
}
7746
}
7745
 
7747
 
7746
CyStringList *CPackages::CreateCockpits()
7748
size_t CPackages::_createCockpits(Utils::CStringList &list)
7747
{
7749
{
7748
	// first check we have any ships
7750
	// first check we have any ships
7749
	if ( m_lGameShips.empty() || !this->CountPackages(TYPE_XSP, true) )
7751
	if ( m_lGameShips.empty() || !this->countPackages(TYPE_XSP, true) )
7750
		return NULL;
7752
		return NULL;
7751
 
-
 
7752
	CyStringList *cockpitList = new CyStringList;
-
 
7753
 
7753
 
7754
	// now extract the existing cockpits
7754
	// now extract the existing cockpits
7755
	int fileType = 51;
7755
	int fileType = 51;
7756
	int e = ExtractGameFile("types/TCockpits.pck", m_sTempDir + "/TCockpits.txt");
7756
	int e = extractGameFile("types/TCockpits.pck", m_sTempDir + "/TCockpits.txt");
7757
	if ( e )
7757
	if ( e )
7758
	{
7758
	{
7759
		// read the dummies
7759
		// read the dummies
7760
		CFileIO File;
7760
		CFileIO File;
7761
		if ( File.open((e == -1) ? "TCockpits.txt" : m_sTempDir + "/TCockpits.txt") )
7761
		if ( File.open((e == -1) ? "TCockpits.txt" : m_sTempDir + "/TCockpits.txt") )
Line 7784... Line 7784...
7784
					else
7784
					else
7785
					{
7785
					{
7786
						while ( !line.empty() )
7786
						while ( !line.empty() )
7787
						{
7787
						{
7788
							Utils::String data = line.tokens(";", 1, 19);
7788
							Utils::String data = line.tokens(";", 1, 19);
7789
							cockpitList->PushBack(CyString(data + ";"));
7789
							list.pushBack(data + ";");
7790
							line = line.remTokens(";", 1, 19);
7790
							line = line.remTokens(";", 1, 19);
7791
 
7791
 
7792
							--count;
7792
							--count;
7793
							if ( count < 1 )
7793
							if ( count < 1 )
7794
								break;
7794
								break;
Line 7811... Line 7811...
7811
				continue;
7811
				continue;
7812
 
7812
 
7813
			for ( CListNode<SCockpit> *cn = s->pPackage->GetCockpits()->Front(); cn; cn = cn->next() )
7813
			for ( CListNode<SCockpit> *cn = s->pPackage->GetCockpits()->Front(); cn; cn = cn->next() )
7814
			{
7814
			{
7815
				bool foundEntry = false;
7815
				bool foundEntry = false;
7816
				CyString cockpitStr = cn->Data()->sCockpit;
7816
				Utils::String cockpitStr = cn->Data()->sCockpit;
7817
				// search for matching game entry
7817
				// search for matching game entry
7818
				for ( CListNode<SWeaponMask> *wm = cn->Data()->lWeaponMask.Front(); wm; wm = wm->next() )
7818
				for ( CListNode<SWeaponMask> *wm = cn->Data()->lWeaponMask.Front(); wm; wm = wm->next() )
7819
				{
7819
				{
7820
					if ( wm->Data()->iGame == (m_iGame - 1) )
7820
					if ( wm->Data()->iGame == (m_iGame - 1) )
7821
					{
7821
					{
7822
						if ( wm->Data()->iMask != -1 )
7822
						if ( wm->Data()->iMask != -1 )
7823
							cockpitStr = cockpitStr.RepToken(";", 9, CyString::Number(wm->Data()->iMask));
7823
							cockpitStr = cockpitStr.replaceToken(";", 9, Utils::String::Number(wm->Data()->iMask));
7824
						foundEntry = true;
7824
						foundEntry = true;
7825
						break;
7825
						break;
7826
					}
7826
					}
7827
				}
7827
				}
7828
 
7828
 
7829
				bool found = false;
7829
				bool found = false;
7830
				for ( SStringList *str = cockpitList->Head(); str; str = str->;next )
7830
				for(auto itr = list.begin(); itr != list.end(); itr++)
7831
				{
7831
				{
7832
					if ( str->str.GetToken(";", 19, 19).Compare(CyString(cn->Data()->sCockpit.token(";", 19))) )
7832
					if ((*itr)->str.token(";", 19).Compare(cn->Data()->sCockpit.token(";", 19)))
7833
					{
7833
					{
7834
						// only replace existing entry if we have sepeperate weapon masks set
7834
						// only replace existing entry if we have sepeperate weapon masks set
7835
						if ( foundEntry )
7835
						if ( foundEntry )
7836
							str->str = cockpitStr;
7836
							(*itr)->str = cockpitStr;
7837
						found = true;
7837
						found = true;
7838
						break;
7838
						break;
7839
					}
7839
					}
7840
				}
7840
				}
7841
 
7841
 
7842
				if ( !found )
7842
				if ( !found )
7843
					cockpitList->PushBack(cockpitStr);
7843
					list.pushBack(cockpitStr);
7844
			}
7844
			}
7845
		}
7845
		}
7846
 
7846
 
7847
		// finally, write the file
7847
		// finally, write the file
7848
		cockpitList->PushFront(CyString::Number(fileType) + ";" + CyString::Number(cockpitList->Count()) + ";;", "");
7848
		list.pushFront(Utils::String::Number(fileType) + ";;" + Utils::String::Number(list.size()) + ";;");
7849
		cockpitList->PushFront(CyString("// TCockpits file, created by SPK Libraries V") + CyString::CreateFromFloat(GetLibraryVersion(), 2), "");
7849
		list.pushFront("// TCockpits file, created by SPK Libraries V" + Utils::String::FromFloat(GetLibraryVersion(), 2));
7850
 
7850
 
7851
		CFileIO WriteFile(m_sTempDir + "/TCockpits.txt");
7851
		CFileIO WriteFile(m_sTempDir + "/TCockpits.txt");
7852
		if ( WriteFile.WriteFile(cockpitList) )
7852
		if ( WriteFile.writeFile(&list) )
7853
		{
7853
		{
7854
			this->PackFile(&WriteFile, "types\\TCockpits.pck");
7854
			this->packFile(&WriteFile, "types\\TCockpits.pck");
7855
			WriteFile.remove();
7855
			WriteFile.remove();
7856
		}
7856
		}
7857
 
7857
 
7858
		// remove those entrys
7858
		// remove those entrys
7859
		cockpitList->PopFront();
7859
		list.popFront();
7860
		cockpitList->PopFront();
7860
		list.popFront();
7861
	}
7861
	}
7862
 
7862
 
7863
	return cockpitList;
7863
	return list.size();
7864
}
7864
}
7865
 
7865
 
7866
CBaseFile *CPackages::FindScriptByAuthor(CyString author, CBaseFile *prev)
7866
CBaseFile *CPackages::FindScriptByAuthor(CyString author, CBaseFile *prev)
7867
{
7867
{
7868
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )
7868
	for ( CListNode<CBaseFile> *node = m_lPackages.Front(); node; node = node->next() )