summaryrefslogtreecommitdiffstats
path: root/api/logic/minecraft/LaunchProfile.cpp
blob: 436a39d9ad5680eaccddd4b9e53bb532f2c4a684 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
#include "LaunchProfile.h"
#include <Version.h>

void LaunchProfile::clear()
{
	m_minecraftVersion.clear();
	m_minecraftVersionType.clear();
	m_minecraftAssets.reset();
	m_minecraftArguments.clear();
	m_tweakers.clear();
	m_mainClass.clear();
	m_appletClass.clear();
	m_libraries.clear();
	m_traits.clear();
	m_jarMods.clear();
	m_mainJar.reset();
	m_problemSeverity = ProblemSeverity::None;
}

static void applyString(const QString & from, QString & to)
{
	if(from.isEmpty())
		return;
	to = from;
}

void LaunchProfile::applyMinecraftVersion(const QString& id)
{
	applyString(id, this->m_minecraftVersion);
}

void LaunchProfile::applyAppletClass(const QString& appletClass)
{
	applyString(appletClass, this->m_appletClass);
}

void LaunchProfile::applyMainClass(const QString& mainClass)
{
	applyString(mainClass, this->m_mainClass);
}

void LaunchProfile::applyMinecraftArguments(const QString& minecraftArguments)
{
	applyString(minecraftArguments, this->m_minecraftArguments);
}

void LaunchProfile::applyMinecraftVersionType(const QString& type)
{
	applyString(type, this->m_minecraftVersionType);
}

void LaunchProfile::applyMinecraftAssets(MojangAssetIndexInfo::Ptr assets)
{
	if(assets)
	{
		m_minecraftAssets = assets;
	}
}

void LaunchProfile::applyTraits(const QSet<QString>& traits)
{
	this->m_traits.unite(traits);
}

void LaunchProfile::applyTweakers(const QStringList& tweakers)
{
	// if the applied tweakers override an existing one, skip it. this effectively moves it later in the sequence
	QStringList newTweakers;
	for(auto & tweaker: m_tweakers)
	{
		if (tweakers.contains(tweaker))
		{
			continue;
		}
		newTweakers.append(tweaker);
	}
	// then just append the new tweakers (or moved original ones)
	newTweakers += tweakers;
	m_tweakers = newTweakers;
}

void LaunchProfile::applyJarMods(const QList<LibraryPtr>& jarMods)
{
	this->m_jarMods.append(jarMods);
}

static int findLibraryByName(QList<LibraryPtr> *haystack, const GradleSpecifier &needle)
{
	int retval = -1;
	for (int i = 0; i < haystack->size(); ++i)
	{
		if (haystack->at(i)->rawName().matchName(needle))
		{
			// only one is allowed.
			if (retval != -1)
				return -1;
			retval = i;
		}
	}
	return retval;
}

void LaunchProfile::applyMods(const QList<LibraryPtr>& mods)
{
	QList<LibraryPtr> * list = &m_mods;
	for(auto & mod: mods)
	{
		auto modCopy = Library::limitedCopy(mod);

		// find the mod by name.
		const int index = findLibraryByName(list, mod->rawName());
		// mod not found? just add it.
		if (index < 0)
		{
			list->append(modCopy);
			return;
		}

		auto existingLibrary = list->at(index);
		// if we are higher it means we should update
		if (Version(mod->version()) > Version(existingLibrary->version()))
		{
			list->replace(index, modCopy);
		}
	}
}

void LaunchProfile::applyLibrary(LibraryPtr library)
{
	if(!library->isActive())
	{
		return;
	}

	QList<LibraryPtr> * list = &m_libraries;
	if(library->isNative())
	{
		list = &m_nativeLibraries;
	}

	auto libraryCopy = Library::limitedCopy(library);

	// find the library by name.
	const int index = findLibraryByName(list, library->rawName());
	// library not found? just add it.
	if (index < 0)
	{
		list->append(libraryCopy);
		return;
	}

	auto existingLibrary = list->at(index);
	// if we are higher it means we should update
	if (Version(library->version()) > Version(existingLibrary->version()))
	{
		list->replace(index, libraryCopy);
	}
}

const LibraryPtr LaunchProfile::getMainJar() const
{
	return m_mainJar;
}

void LaunchProfile::applyMainJar(LibraryPtr jar)
{
	if(jar)
	{
		m_mainJar = jar;
	}
}

void LaunchProfile::applyProblemSeverity(ProblemSeverity severity)
{
	if (m_problemSeverity < severity)
	{
		m_problemSeverity = severity;
	}
}

const QList<PatchProblem> LaunchProfile::getProblems() const
{
	// FIXME: implement something that actually makes sense here
	return {};
}

QString LaunchProfile::getMinecraftVersion() const
{
	return m_minecraftVersion;
}

QString LaunchProfile::getAppletClass() const
{
	return m_appletClass;
}

QString LaunchProfile::getMainClass() const
{
	return m_mainClass;
}

const QSet<QString> &LaunchProfile::getTraits() const
{
	return m_traits;
}

const QStringList & LaunchProfile::getTweakers() const
{
	return m_tweakers;
}

bool LaunchProfile::hasTrait(const QString& trait) const
{
	return m_traits.contains(trait);
}

ProblemSeverity LaunchProfile::getProblemSeverity() const
{
	return m_problemSeverity;
}

QString LaunchProfile::getMinecraftVersionType() const
{
	return m_minecraftVersionType;
}

std::shared_ptr<MojangAssetIndexInfo> LaunchProfile::getMinecraftAssets() const
{
	if(!m_minecraftAssets)
	{
		return std::make_shared<MojangAssetIndexInfo>("legacy");
	}
	return m_minecraftAssets;
}

QString LaunchProfile::getMinecraftArguments() const
{
	return m_minecraftArguments;
}

const QList<LibraryPtr> & LaunchProfile::getJarMods() const
{
	return m_jarMods;
}

const QList<LibraryPtr> & LaunchProfile::getLibraries() const
{
	return m_libraries;
}

const QList<LibraryPtr> & LaunchProfile::getNativeLibraries() const
{
	return m_nativeLibraries;
}

void LaunchProfile::getLibraryFiles(
	const QString& architecture,
	QStringList& jars,
	QStringList& nativeJars,
	const QString& overridePath,
	const QString& tempPath
) const
{
	QStringList native32, native64;
	jars.clear();
	nativeJars.clear();
	for (auto lib : getLibraries())
	{
		lib->getApplicableFiles(currentSystem, jars, nativeJars, native32, native64, overridePath);
	}
	// NOTE: order is important here, add main jar last to the lists
	if(m_mainJar)
	{
		// FIXME: HACK!! jar modding is weird and unsystematic!
		if(m_jarMods.size())
		{
			QDir tempDir(tempPath);
			jars.append(tempDir.absoluteFilePath("minecraft.jar"));
		}
		else
		{
			m_mainJar->getApplicableFiles(currentSystem, jars, nativeJars, native32, native64, overridePath);
		}
	}
	for (auto lib : getNativeLibraries())
	{
		lib->getApplicableFiles(currentSystem, jars, nativeJars, native32, native64, overridePath);
	}
	if(architecture == "32")
	{
		nativeJars.append(native32);
	}
	else if(architecture == "64")
	{
		nativeJars.append(native64);
	}
}