Skip to content
This repository was archived by the owner on Oct 21, 2022. It is now read-only.

Commit 2f4271c

Browse files
committed
Fix Mods version checker
1 parent 43b7182 commit 2f4271c

1 file changed

Lines changed: 29 additions & 15 deletions

File tree

ModLoader/Loader.cs

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class Loader : MonoBehaviour
3232
private static FolderPath _modsFolder;
3333

3434
// modlaoder version
35-
private const string modLoderVersion = "v1.1.2";
35+
private const string modLoderVersion = "v1.2.0";
3636

3737
public static FolderPath ModsFolder
3838
{
@@ -50,7 +50,6 @@ public static FolderPath ModsFolder
5050
private void Awake()
5151
{
5252
Loader.main = this;
53-
SceneManager.sceneLoaded += this.OnSceneLoaded;
5453
_modsFolder = FileLocations.BaseFolder.Extend("MODS").CreateFolder();
5554

5655
Debug.Log("Early loading mods");
@@ -119,8 +118,14 @@ private void postInit()
119118
/// <returns>instance mod</returns>
120119
public SFSMod getMod(string modId)
121120
{
122-
this._modList.TryGetValue(modId, out SFSMod result);
123-
return result;
121+
foreach(SFSMod mod in this._modsLoaded)
122+
{
123+
if(mod.ModId == modId)
124+
{
125+
return mod;
126+
}
127+
}
128+
return null;
124129
}
125130

126131
/// <summary>
@@ -129,7 +134,7 @@ public SFSMod getMod(string modId)
129134
/// <returns> Loaded mods </returns>
130135
public SFSMod[] getMods()
131136
{
132-
return _modList.Values.ToArray();
137+
return this._modsLoaded.ToArray();
133138
}
134139

135140
/// <summary>
@@ -239,7 +244,7 @@ private void loadMod(SFSMod mod)
239244
Debug.Log("Loading " + mod.Name);
240245

241246
// check if the version is valid for this modloader version
242-
if (verifyVersion(mod.ModLoderVersion, modLoderVersion))
247+
if (verifyVersion(mod.ModLoderVersion, modLoderVersion,true))
243248
{
244249
// Does it have dependencies?
245250
if (mod.Dependencies != null)
@@ -264,7 +269,7 @@ private void loadMod(SFSMod mod)
264269
/// <param name="version1"> version to check</param>
265270
/// <param name="version2"> verison to check</param>
266271
/// <returns>True if they are valid versions</returns>
267-
private bool verifyVersion(string version1, string version2)
272+
private bool verifyVersion(string version1, string version2, bool checkMinVersion = false)
268273
{
269274
Regex rx = new Regex(@"\bv([0-9]+)(\.([0-9]+|x)){2}\b", RegexOptions.Compiled | RegexOptions.IgnoreCase);
270275
// has the format v1.x.x
@@ -277,14 +282,28 @@ private bool verifyVersion(string version1, string version2)
277282
{
278283
for (short index = 0; index < target2.Length; index++)
279284
{
280-
if (target1[index] == "x")
285+
if (target1[index] == "x" || target1[index] == target2[index])
281286
{
282287
continue;
283288
}
284-
if (target1[index] != target2[index])
289+
290+
if (checkMinVersion)
285291
{
286-
return false;
292+
int num1, num2;
293+
if (int.TryParse(target1[index], out num1))
294+
{
295+
if(int.TryParse(target2[index], out num2))
296+
{
297+
298+
if(num1 <= num2)
299+
{
300+
301+
continue;
302+
}
303+
}
304+
}
287305
}
306+
return false;
288307
}
289308
//both are valid for each other
290309
return true;
@@ -295,11 +314,6 @@ private bool verifyVersion(string version1, string version2)
295314
return false;
296315
}
297316

298-
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
299-
{
300-
Debug.Log("Scene change to " + scene.name);
301-
}
302-
303317
/// <summary>
304318
/// This is the mod loader entry point, this is the method that is executed after being injected into the game.
305319
/// </summary>

0 commit comments

Comments
 (0)