Subversion Repositories spk

Rev

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

Rev 196 Rev 197
Line 1051... Line 1051...
1051
			ZipAdd(hz, buf, data, dataSize);
1051
			ZipAdd(hz, buf, data, dataSize);
1052
		}
1052
		}
1053
	}
1053
	}
1054
}
1054
}
1055
 
1055
 
1056
bool CXspFile::LoadPackageData(const Utils::String &sFirst, const Utils::String &sRest, const Utils::String &sMainGame, Utils::CStringList &otherGames, Utils::CStringList &gameAddons, CProgressInfo *progress)
1056
bool CXspFile::loadPackageData(const Utils::WString &sFirst, const Utils::WString &sRest, const Utils::WString &sMainGame, Utils::WStringList &otherGames, Utils::WStringList &gameAddons, CProgressInfo *progress)
1057
{
1057
{
1058
	if ( sFirst.Compare("Shipyard") )
1058
	if ( sFirst.Compare(L"Shipyard") )
1059
	{
1059
	{
1060
		for ( int i = SHIPYARD_ARGON; i <= SHIPYARD_MAX; i *= 2 )
1060
		for ( int i = SHIPYARD_ARGON; i <= SHIPYARD_MAX; i *= 2 )
1061
		{
1061
		{
1062
			if ( sRest.Compare(GetShipyardName(i)) )
1062
			if ( sRest.Compare(GetShipyardName(i)) )
1063
			{
1063
			{
1064
				this->AddShipyard(i);
1064
				this->AddShipyard(i);
1065
				break;
1065
				break;
1066
			}
1066
			}
1067
		}
1067
		}
1068
	}
1068
	}
1069
	else if ( sFirst.Compare("OriginalDescription") )
1069
	else if ( sFirst.Compare(L"OriginalDescription") )
1070
		m_iOrgDesc = sRest;
1070
		m_iOrgDesc = sRest;
1071
	else if ( sFirst.Compare("ShipData") )
1071
	else if ( sFirst.Compare(L"ShipData") )
1072
		m_sData = sRest;
1072
		m_sData = sRest.toString();
1073
	else if ( sFirst.Compare("ReadData") ) // read data from a tships file
1073
	else if ( sFirst.Compare(L"ReadData") ) // read data from a tships file
1074
	{
1074
	{
1075
		CPackages p;
1075
		CPackages p;
1076
		m_sData = p.readShipData(sRest.tokens(" ", 2), sRest.token(" ", 1));
1076
		m_sData = p.readShipData(sRest.tokens(L" ", 2).toString(), sRest.token(L" ", 1).toString());
1077
	}
1077
	}
1078
	else if ( sFirst.Compare("ExistingShip") )
1078
	else if ( sFirst.Compare(L"ExistingShip") )
1079
		m_bExistingShip = true;
1079
		m_bExistingShip = true;
1080
	else if ( sFirst.Compare("ShipID") )
1080
	else if ( sFirst.Compare(L"ShipID") )
1081
		m_sID = sRest;
1081
		m_sID = sRest.toString();
1082
	else if ( sFirst.Compare("ShipText") )
1082
	else if ( sFirst.Compare(L"ShipText") )
1083
		this->AddText(sRest.token(" ", 1).toLong(), sRest.tokens(" ", 2).token("|", 1), sRest.tokens(" ", 2).tokens("|", 2));
1083
		this->AddText(sRest.token(L" ", 1).toLong(), sRest.tokens(L" ", 2).token(L"|", 1).toString(), sRest.tokens(L" ", 2).tokens(L"|", 2).toString());
1084
	else if ( sFirst.Compare("Component") )
1084
	else if ( sFirst.Compare(L"Component") )
1085
		this->AddComponent(sRest.token(" ", 1), sRest.token(" ", 2), sRest.tokens(" ", 3));
1085
		this->AddComponent(sRest.token(L" ", 1).toString(), sRest.token(L" ", 2).toString(), sRest.tokens(L" ", 3).toString());
1086
	else if ( sFirst.Compare("Cockpit") )
1086
	else if ( sFirst.Compare(L"Cockpit") )
1087
		this->AddCockpit(sRest.tokens(" ", 2).replaceToken(";", 19, sRest.token(" ", 1)), 0);
1087
		this->AddCockpit(sRest.tokens(L" ", 2).replaceToken(L";", 19, sRest.token(L" ", 1)).toString(), 0);
1088
	else if ( sFirst.Compare("CockpitWeapon") )
1088
	else if ( sFirst.Compare(L"CockpitWeapon") )
1089
		this->AddCockpitWeapon(sRest.token(" ", 1), sRest.token(" ", 2), sRest.token(" ", 3));
1089
		this->AddCockpitWeapon(sRest.token(L" ", 1).toString(), sRest.token(L" ", 2), sRest.token(L" ", 3));
1090
	else if ( sFirst.Compare("WeaponMask") )
1090
	else if ( sFirst.Compare(L"WeaponMask") )
1091
		this->AddWeaponMask(sRest.token(" ", 1), sRest.token(" ", 2));
1091
		this->AddWeaponMask(sRest.token(L" ", 1), sRest.token(L" ", 2));
1092
	else if ( sFirst.Compare("MissileMask") )
1092
	else if ( sFirst.Compare(L"MissileMask") )
1093
		this->AddMissileMask(sRest.token(" ", 1), sRest.token(" ", 2));
1093
		this->AddMissileMask(sRest.token(L" ", 1), sRest.token(L" ", 2));
1094
	else if ( sFirst.Compare("Dummy") )
1094
	else if ( sFirst.Compare(L"Dummy") )
1095
		this->AddDummy(sRest.token(" ", 1), sRest.token(" ", 2));
1095
		this->AddDummy(sRest.token(L" ", 1).toString(), sRest.token(L" ", 2).toString());
1096
	else if ( sFirst.Compare("CutData") )
1096
	else if ( sFirst.Compare(L"CutData") )
1097
		this->addCutData(sRest);
1097
		this->addCutData(sRest.toString());
1098
	else if ( sFirst.Compare("Animation") )
1098
	else if ( sFirst.Compare(L"Animation") )
1099
		this->addAnimation(sRest);
1099
		this->addAnimation(sRest.toString());
1100
	else if ( sFirst.Compare("Bodies") )
1100
	else if ( sFirst.Compare(L"Bodies") )
1101
		this->addBodies(sRest);
1101
		this->addBodies(sRest.toString());
1102
	else if ( !CBaseFile::LoadPackageData(sFirst, sRest, sMainGame, otherGames, gameAddons, progress) )
1102
	else if ( !CBaseFile::loadPackageData(sFirst, sRest, sMainGame, otherGames, gameAddons, progress) )
1103
	{
1103
	{
1104
		return false;
1104
		return false;
1105
	}
1105
	}
1106
 
1106
 
1107
	return true;
1107
	return true;
Line 1674... Line 1674...
1674
{
1674
{
1675
	m_sID = sId.remove('\r');
1675
	m_sID = sId.remove('\r');
1676
	while ( m_sID.right(1) == ";" )
1676
	while ( m_sID.right(1) == ";" )
1677
		m_sID.truncate(-1);
1677
		m_sID.truncate(-1);
1678
 
1678
 
1679
	m_sData = pVfs->getTShipsEntry(m_sID);
1679
	m_sData = pVfs->getTShipsEntry(m_sID).toString();
1680
 
1680
 
1681
	// get scene files
1681
	// get scene files
1682
	if ( pProgress ) pProgress->UpdateStatus(IMPORTSHIP_SCENE);
1682
	if ( pProgress ) pProgress->UpdateStatus(IMPORTSHIP_SCENE);
1683
	if ( !this->extractSceneFiles(pVfs) )
1683
	if ( !this->extractSceneFiles(pVfs) )
1684
		return false;
1684
		return false;
Line 1810... Line 1810...
1810
		}
1810
		}
1811
	}
1811
	}
1812
 
1812
 
1813
	if ( cuts.empty() ) return;
1813
	if ( cuts.empty() ) return;
1814
 
1814
 
1815
	if ( pVfs->ExtractGameFile("types/CutData.pck", CPackages::tempDirectory() + "tmp.dat").empty() ) return;
1815
	if ( pVfs->extractGameFile(L"types/CutData.pck", CPackages::tempDirectory() + L"tmp.dat").empty()) return;
1816
	
1816
	
1817
	CFileIO File(CPackages::tempDirectory() + "tmp.dat");
1817
	CFileIO File(CPackages::tempDirectory() + L"tmp.dat");
1818
	if ( !File.exists() ) return;
1818
	if ( !File.exists() ) return;
1819
	
1819
	
1820
	std::vector<Utils::String> lines;
1820
	std::vector<Utils::String> lines;
1821
	File.readLines(lines);
1821
	File.readLines(lines);
1822
	int count = -1;
1822
	int count = -1;
Line 1853... Line 1853...
1853
void CXspFile::extractDummies(CVirtualFileSystem *pVfs, Utils::CStringList& sceneModels, bool add)
1853
void CXspFile::extractDummies(CVirtualFileSystem *pVfs, Utils::CStringList& sceneModels, bool add)
1854
{
1854
{
1855
	if (sceneModels.empty()) return;
1855
	if (sceneModels.empty()) return;
1856
 
1856
 
1857
	bool extracted = false;
1857
	bool extracted = false;
1858
	if ( !pVfs->ExtractGameFile("types/dummies.pck", CPackages::tempDirectory() + "tmp.dat").empty() ) {
1858
	if ( !pVfs->extractGameFile(L"types/dummies.pck", CPackages::tempDirectory() + L"tmp.dat").empty()) {
1859
		CFileIO File(CPackages::tempDirectory() + "tmp.dat");
1859
		CFileIO File(CPackages::tempDirectory() + L"tmp.dat");
1860
		if ( File.exists() )
1860
		if ( File.exists() )
1861
		{
1861
		{
1862
			Utils::String section;
1862
			Utils::String section;
1863
			int secCount = 0;
1863
			int secCount = 0;
1864
			std::vector<Utils::String> lines;
1864
			std::vector<Utils::String> lines;
Line 1913... Line 1913...
1913
}
1913
}
1914
 
1914
 
1915
void CXspFile::extractComponants(CVirtualFileSystem *pVfs, const Utils::CStringList& sceneModels)
1915
void CXspFile::extractComponants(CVirtualFileSystem *pVfs, const Utils::CStringList& sceneModels)
1916
{
1916
{
1917
	if (sceneModels.empty()) return;
1917
	if (sceneModels.empty()) return;
1918
	if ( !pVfs->ExtractGameFile("types/components.pck", CPackages::tempDirectory() + "tmp.dat").empty() )
1918
	if ( !pVfs->extractGameFile(L"types/components.pck", CPackages::tempDirectory() + L"tmp.dat").empty())
1919
	{
1919
	{
1920
		CFileIO File(CPackages::tempDirectory() + "tmp.dat");
1920
		CFileIO File(CPackages::tempDirectory() + L"tmp.dat");
1921
		if ( File.exists() )
1921
		if ( File.exists() )
1922
		{
1922
		{
1923
			Utils::String file;
1923
			Utils::String file;
1924
			Utils::String section;
1924
			Utils::String section;
1925
			int secCount = 0;
1925
			int secCount = 0;
Line 1960... Line 1960...
1960
			File.remove();
1960
			File.remove();
1961
		}
1961
		}
1962
	}
1962
	}
1963
}
1963
}
1964
 
1964
 
1965
bool CXspFile::getTextureList(Utils::CStringList &list, const unsigned char *olddata, size_t size) const
1965
bool CXspFile::getTextureList(Utils::WStringList &list, const unsigned char *olddata, size_t size) const
1966
{
1966
{
1967
	if ( !olddata || !size )
1967
	if ( !olddata || !size )
1968
		return false;
1968
		return false;
1969
 
1969
 
1970
	size_t startLine = 0;
1970
	size_t startLine = 0;
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
	Utils::CStringList lTextures;
2025
	Utils::WStringList 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 2033... Line 2033...
2033
		bool deleteData = false;
2033
		bool deleteData = false;
2034
		unsigned char *data = NULL;
2034
		unsigned char *data = NULL;
2035
		size_t size;
2035
		size_t size;
2036
 
2036
 
2037
		// cant do these yet
2037
		// cant do these yet
2038
		if (f->checkFileExt("pbb") || f->checkFileExt("bob"))
2038
		if (f->checkFileExt(L"pbb") || f->checkFileExt(L"bob"))
2039
		{
2039
		{
2040
			data = f->BobDecompile(&size);
2040
			data = f->BobDecompile(&size);
2041
			if ( !data || !size ) {
2041
			if ( !data || !size ) {
2042
				// search for the pbd or bod files that match and use them instead
2042
				// search for the pbd or bod files that match and use them instead
2043
				Utils::String file;
2043
				Utils::WString file;
2044
 
2044
 
2045
				file = CFileIO(f->getNameDirectory(NULL)).changeFileExtension(L"pbd").toString();
2045
				file = CFileIO(f->getNameDirectory(NULL)).changeFileExtension(L"pbd");
2046
				file = pVfs->ExtractGameFile(file, CPackages::tempDirectory() + "tmp.tmp");
2046
				file = pVfs->extractGameFile(file, CPackages::tempDirectory() + L"tmp.tmp");
2047
	
2047
	
2048
				if ( file.empty() ) {
2048
				if ( file.empty() ) {
2049
					file = CFileIO(f->getNameDirectory(NULL)).changeFileExtension(L"bod").toString();
2049
					file = CFileIO(f->getNameDirectory(NULL)).changeFileExtension(L"bod");
2050
					file = pVfs->ExtractGameFile(file, CPackages::tempDirectory() + "tmp.tmp");
2050
					file = pVfs->extractGameFile(file, CPackages::tempDirectory() + L"tmp.tmp");
2051
				}
2051
				}
2052
 
2052
 
2053
				if ( !file.empty() ) {
2053
				if ( !file.empty() ) {
2054
					CFileIO File(file);
2054
					CFileIO File(file);
2055
					if ( File.exists() ) {
2055
					if ( File.exists() ) {
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\\" + (*itr)->str, FILETYPE_SHIPOTHER) )
2110
			if ( pVfs->extractGameFileToPackage(this, L"dds\\" + (*itr)->str, FILETYPE_SHIPOTHER) )
2111
				continue;
2111
				continue;
2112
 
2112
 
2113
			if ( pVfs->extractGameFileToPackage(this, "dds\\" + (*itr)->str.token(".", -1), FILETYPE_SHIPOTHER) )
2113
			if ( pVfs->extractGameFileToPackage(this, L"dds\\" + (*itr)->str.token(L".", -1), FILETYPE_SHIPOTHER) )
2114
				continue;
2114
				continue;
2115
 
2115
 
2116
			if ( pVfs->extractGameFileToPackage(this, "dds\\" + (*itr)->str + ".dds", FILETYPE_SHIPOTHER) )
2116
			if ( pVfs->extractGameFileToPackage(this, L"dds\\" + (*itr)->str + L".dds", FILETYPE_SHIPOTHER) )
2117
				continue;
2117
				continue;
2118
 
2118
 
2119
			if ( pVfs->extractGameFileToPackage(this, "dds\\" + Utils::String(F.changeFileExtension(L";dds").toString()), FILETYPE_SHIPOTHER) )
2119
			if ( pVfs->extractGameFileToPackage(this, L"dds\\" + F.changeFileExtension(L";dds"), FILETYPE_SHIPOTHER) )
2120
				continue;
2120
				continue;
2121
 
2121
 
2122
			if ( pVfs->extractGameFileToPackage(this, "textures\\" + (*itr)->str, FILETYPE_SHIPOTHER) )
2122
			if ( pVfs->extractGameFileToPackage(this, L"textures\\" + (*itr)->str, FILETYPE_SHIPOTHER) )
2123
				continue;
2123
				continue;
2124
 
2124
 
2125
			if ( pVfs->extractGameFileToPackage(this, "textures\\" + (*itr)->str.token(".", -1), FILETYPE_SHIPOTHER) )
2125
			if ( pVfs->extractGameFileToPackage(this, L"textures\\" + (*itr)->str.token(L".", -1), FILETYPE_SHIPOTHER) )
2126
				continue;
2126
				continue;
2127
 
2127
 
2128
			if ( pVfs->extractGameFileToPackage(this, "textures\\" + (*itr)->str + ".jpg", FILETYPE_SHIPOTHER) )
2128
			if ( pVfs->extractGameFileToPackage(this, L"textures\\" + (*itr)->str + L".jpg", FILETYPE_SHIPOTHER) )
2129
				continue;
2129
				continue;
2130
 
2130
 
2131
			if ( pVfs->extractGameFileToPackage(this, "textures\\" + Utils::String(F.changeFileExtension(L";jpg").toString()), FILETYPE_SHIPOTHER) )
2131
			if ( pVfs->extractGameFileToPackage(this, L"textures\\" + F.changeFileExtension(L";jpg"), FILETYPE_SHIPOTHER) )
2132
				continue;
2132
				continue;
2133
		}
2133
		}
2134
	}
2134
	}
2135
}
2135
}
2136
 
2136
 
2137
bool CXspFile::AddTextFromFile(const Utils::String &sFile, int textId)
2137
bool CXspFile::addTextFromFile(const Utils::WString &sFile, int textId)
2138
{
2138
{
2139
	Utils::String file = sFile;
2139
	Utils::WString file = sFile;
2140
 
2140
 
2141
	bool remove = false;
2141
	bool remove = false;
2142
	if ( CFileIO(file).isFileExtension(L"pck") )
2142
	if ( CFileIO(file).isFileExtension(L"pck") )
2143
	{
2143
	{
2144
		C_File F;
2144
		C_File F;
2145
		F.setFilename(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() + L"tmp.dat"))
2148
		{
2148
		{
2149
			remove = true;
2149
			remove = true;
2150
			file = CPackages::tempDirectory() + "tmp.dat";
2150
			file = CPackages::tempDirectory() + L"tmp.dat";
2151
		}
2151
		}
2152
	}
2152
	}
2153
 
2153
 
2154
	/*
2154
	/*
2155
	std::wfstream fileStream(file.c_str());
2155
	std::wfstream fileStream(file.c_str());
Line 2278... Line 2278...
2278
	return false;
2278
	return false;
2279
}
2279
}
2280
 
2280
 
2281
bool CXspFile::extractCockpits(CVirtualFileSystem *pVfs)
2281
bool CXspFile::extractCockpits(CVirtualFileSystem *pVfs)
2282
{
2282
{
2283
	if ( !pVfs->ExtractGameFile("types/TCockpits.pck", CPackages::tempDirectory() + "tmp.dat").empty() ) {
2283
	if ( !pVfs->extractGameFile(L"types/TCockpits.pck", CPackages::tempDirectory() + L"tmp.dat").empty() ) {
2284
		bool ret = this->ImportCockpits(CPackages::tempDirectory() + "tmp.dat");
2284
		bool ret = this->ImportCockpits((CPackages::tempDirectory() + L"tmp.dat").toString());
2285
		CFileIO::Remove(CPackages::tempDirectory() + "tmp.dat");
2285
		CFileIO::Remove(CPackages::tempDirectory() + L"tmp.dat");
2286
 
2286
 
2287
		return ret;
2287
		return ret;
2288
	}
2288
	}
2289
 
2289
 
2290
	return false;
2290
	return false;
Line 2292... Line 2292...
2292
 
2292
 
2293
bool CXspFile::extractBodies(CVirtualFileSystem *pVfs, const Utils::CStringList &sceneModels)
2293
bool CXspFile::extractBodies(CVirtualFileSystem *pVfs, const Utils::CStringList &sceneModels)
2294
{
2294
{
2295
	if (sceneModels.empty()) return false;
2295
	if (sceneModels.empty()) return false;
2296
 
2296
 
2297
	if ( !pVfs->ExtractGameFile("types/Bodies.pck", CPackages::tempDirectory() + "tmp.dat").empty() ) {
2297
	if ( !pVfs->extractGameFile(L"types/Bodies.pck", CPackages::tempDirectory() + L"tmp.dat").empty() ) {
2298
		bool ret = this->importBodies(sceneModels, CPackages::tempDirectory() + "tmp.dat");
2298
		bool ret = this->importBodies(sceneModels, (CPackages::tempDirectory() + L"tmp.dat").toString());
2299
		CFileIO::Remove(CPackages::tempDirectory() + "tmp.dat");
2299
		CFileIO::Remove(CPackages::tempDirectory() + L"tmp.dat");
2300
 
2300
 
2301
		return ret;
2301
		return ret;
2302
	}
2302
	}
2303
 
2303
 
2304
	return false;
2304
	return false;
Line 2330... Line 2330...
2330
		{
2330
		{
2331
			added = true;
2331
			added = true;
2332
			break;
2332
			break;
2333
		}
2333
		}
2334
 
2334
 
2335
		Utils::String line = F.readEndOfLine();
2335
		Utils::String line = F.readEndOfLineStr();
2336
		line.removeChar(9);
2336
		line.removeChar(9);
2337
		line.removeChar('\r');
2337
		line.removeChar('\r');
2338
		line.removeFirstSpace();
2338
		line.removeFirstSpace();
2339
	
2339
	
2340
		if ( inpage )
2340
		if ( inpage )
Line 2444... Line 2444...
2444
 
2444
 
2445
		// extract the text file and read in the data
2445
		// extract the text file and read in the data
2446
		bool extracted = catFile->extractFile(f->sFile, CPackages::tempDirectory() + "/tmp.dat");
2446
		bool extracted = catFile->extractFile(f->sFile, CPackages::tempDirectory() + "/tmp.dat");
2447
		if ( !extracted && secondCatFile ) extracted = secondCatFile->extractFile(f->sFile, CPackages::tempDirectory() + "/tmp.dat");
2447
		if ( !extracted && secondCatFile ) extracted = secondCatFile->extractFile(f->sFile, CPackages::tempDirectory() + "/tmp.dat");
2448
		if ( extracted ) {
2448
		if ( extracted ) {
2449
			this->AddTextFromFile(CPackages::tempDirectory() + "/tmp.dat", textId);
2449
			this->addTextFromFile(CPackages::tempDirectory() + L"/tmp.dat", textId);
2450
			CFileIO::Remove(CPackages::tempDirectory() + "/tmp.dat");
2450
			CFileIO::Remove(CPackages::tempDirectory() + L"/tmp.dat");
2451
		}
2451
		}
2452
	}
2452
	}
2453
}
2453
}
2454
 
2454
 
2455
bool CXspFile::processSceneFileSection(int section, CVirtualFileSystem *pVfs, Utils::CStringList &lModels, CProgressInfo *progress)
2455
bool CXspFile::processSceneFileSection(int section, CVirtualFileSystem *pVfs, Utils::CStringList &lModels, CProgressInfo *progress)