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

Commit dcdbe23

Browse files
committed
Add documentation
1 parent ebc74f0 commit dcdbe23

9 files changed

Lines changed: 189 additions & 56 deletions

File tree

ModLoader/IO/Console.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,30 @@
66

77
namespace ModLoader.IO
88
{
9-
9+
/// <summary>
10+
/// This is the mod loader console. It is used for debugging and displaying errors.
11+
/// </summary>
1012
public class Console : MonoBehaviour
1113
{
14+
/// <summary>
15+
/// Store the main Console instance
16+
/// </summary>
1217
public static Console Main;
18+
/// <summary>
19+
/// Store the gameobject that implements the Console class
20+
/// </summary>
1321
public static GameObject root;
1422

1523
private ConsoleGUI _consoleGui;
24+
25+
/// <summary>
26+
/// Store the ConsoleGui instance
27+
/// </summary>
1628
public ConsoleGUI ConsoleGui
1729
{
1830
get { return this._consoleGui; }
1931
}
32+
2033
private const int _maxLines = 150;
2134
private FilePath logFile;
2235
private Queue<string> _queue;
@@ -47,7 +60,7 @@ private void OnDisable()
4760
}
4861

4962
/// <summary>
50-
/// process all game logs
63+
/// Process all game logs
5164
/// </summary>
5265
/// <param name="message">log message </param>
5366
/// <param name="stackTrace"> error stackTrace </param>

ModLoader/IO/ConsoleGUI.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,31 @@
22

33
namespace ModLoader.IO
44
{
5-
5+
/// <summary>
6+
/// This class is used to display console GUI.
7+
/// </summary>
68
public class ConsoleGUI : MonoBehaviour
79
{
810
// show in what position is the scroll of console
911
private Vector2 _scrollConsole = Vector2.zero;
1012

1113
// show if the console is visible for user
1214
private bool _isVisible;
15+
16+
/// <summary>
17+
/// Get if the console gui is visible or not
18+
/// </summary>
1319
public bool IsVisible
1420
{
1521
get { return this._isVisible; }
1622
}
1723

1824
// store all records in the game
1925
private GUIContent _logs;
26+
27+
/// <summary>
28+
/// Set console text
29+
/// </summary>
2030
public string Logs
2131
{
2232
set

ModLoader/Loader.cs

Lines changed: 62 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,37 @@
1414
using SFS.Adapter;
1515
using SFS.Translations;
1616
using ModLoader.UI;
17+
using ModLoader.Helpers;
1718

1819
namespace ModLoader
1920
{
2021
/// <summary>
21-
/// This is the main class of ModLoader. this class is injected into the game with the Unity Doorstop injector.
22+
/// This is the main class of ModLoader. this class is injected into the game with the Unity Doorstop injector.
2223
/// </summary>
2324
public class Loader : MonoBehaviour
2425
{
25-
// This save Loader instance
26+
27+
/// <summary>
28+
/// This save Loader instance
29+
/// </summary>
2630
public static Loader main;
27-
//private Console _console;
2831

29-
// This save the gameObject that implement Loader class
32+
/// <summary>
33+
/// This save the gameObject that implement Loader class
34+
/// </summary>
3035
public static GameObject root;
3136

32-
private static FolderPath _modsFolder;
33-
34-
// modlaoder version
35-
private const string modLoderVersion = "v1.2.0";
37+
/// <summary>
38+
/// Current Modlaoder version
39+
/// </summary>
40+
private const string modLoderVersion = "v1.3.0";
3641

42+
/// <summary>
43+
/// Get folder where mods are
44+
/// </summary>
3745
public static FolderPath ModsFolder
3846
{
39-
get { return _modsFolder; }
47+
get { return FileLocations.BaseFolder.Extend("MODS"); }
4048
}
4149

4250
private List<SFSMod> _modsLoaded = new List<SFSMod>();
@@ -45,12 +53,12 @@ public static FolderPath ModsFolder
4553
private Dictionary<string, SFSMod> _modList;
4654

4755
/// <summary>
48-
/// First executed method. Save the loader instance to static var, subscribe to the scene event and load mods for early patches.
56+
/// First executed method. Save the loader instance to static var, subscribe to the scene event and load mods for early patches.
4957
/// </summary>
5058
private void Awake()
5159
{
5260
Loader.main = this;
53-
_modsFolder = FileLocations.BaseFolder.Extend("MODS").CreateFolder();
61+
FolderPath modsFolder = ModsFolder.CreateFolder();
5462

5563
Debug.Log($"--- ModLoader {modLoderVersion} ---");
5664

@@ -75,26 +83,29 @@ private void Awake()
7583
}
7684

7785
Debug.Log("Early load finished");
78-
Helper.OnHomeSceneLoaded += this.OnGomeSceneLoaded;
86+
SceneHelper.OnHomeSceneLoaded += this.OnHomeSceneLoaded;
7987
}
8088

81-
private void OnGomeSceneLoaded(object sender, EventArgs args)
89+
/// <summary>
90+
/// Is called when Home scenes has been loaded
91+
/// </summary>
92+
/// <param name="sender">Who send this event</param>
93+
/// <param name="scene">Scene information</param>
94+
private void OnHomeSceneLoaded(object sender, Scene scene)
8295
{
8396
this.insertModsButton();
8497
}
8598

8699
/// <summary>
87-
/// This method starts reading mods and runs automatically when this class is created after the Awake method.
100+
/// This method starts reading mods and runs automatically when this class is created after the Awake method.
88101
/// </summary>
89102
private void Start()
90103
{
91-
Debug.Log("Loading mods");
104+
Debug.Log("Starting mods");
92105
foreach (SFSMod mod in _modsLoaded)
93106
{
94107
mod.load();
95108
}
96-
97-
Debug.Log("Loading finished");
98109
this.insertModsButton();
99110
}
100111

@@ -120,7 +131,7 @@ private void insertModsButton()
120131
}
121132

122133
/// <summary>
123-
/// get mod instance.
134+
/// Get mod instance.
124135
/// </summary>
125136
/// <param name="modId">Mod ID you need</param>
126137
/// <returns>instance mod</returns>
@@ -137,7 +148,7 @@ public SFSMod getMod(string modId)
137148
}
138149

139150
/// <summary>
140-
/// Get a list of all loaded mods
151+
/// Get a list of all loaded mods
141152
/// </summary>
142153
/// <returns> Loaded mods </returns>
143154
public SFSMod[] getMods()
@@ -157,7 +168,7 @@ private Dictionary<string, SFSMod> getModList()
157168
this.detectIndividualDlls();
158169

159170
// get a list of mod folders in the MODS folder
160-
IEnumerable<FolderPath> modsFolders = _modsFolder.GetFoldersInFolder(false);
171+
IEnumerable<FolderPath> modsFolders = ModsFolder.GetFoldersInFolder(false);
161172
string basePath = Path.Combine(FileLocations.BaseFolder, "MODS");
162173

163174
foreach (FolderPath folder in modsFolders)
@@ -201,10 +212,14 @@ private Dictionary<string, SFSMod> getModList()
201212
}
202213

203214
/// <summary>
204-
/// Load the mod dependencies and check if it is already loaded and check its version.
215+
/// Load the mod dependencies and check if it is already loaded and check its version.
205216
/// </summary>
206-
/// <param name="dependencies"> lista de dependencias que necesitas cargar primero</param>
207-
/// <returns> verdadero si se han cargado todas las dependencias</returns>
217+
/// <param name="dependencies">
218+
/// List of dependencies that need to be loaded first
219+
/// </param>
220+
/// <returns>
221+
/// True if all dependencies have been loaded
222+
/// </returns>
208223
private bool loadDependencies(Dictionary<string, string[]> dependencies)
209224
{
210225
// for each mod dependency
@@ -241,9 +256,11 @@ private bool loadDependencies(Dictionary<string, string[]> dependencies)
241256
}
242257

243258
/// <summary>
244-
/// Start checking mod version and run load method
259+
/// Start checking mod version and run load method
245260
/// </summary>
246-
/// <param name="mod">Mod to start load</param>
261+
/// <param name="mod">
262+
/// Mod to start load
263+
/// </param>
247264
private void loadMod(SFSMod mod)
248265
{
249266
// has this mod been loaded?, if it does not start loading
@@ -275,11 +292,20 @@ private void loadMod(SFSMod mod)
275292
}
276293

277294
/// <summary>
278-
/// Check the string of two versions to identify if they are the same
295+
/// Check the string of two versions to identify if they are the same
279296
/// </summary>
280-
/// <param name="version1"> version to check</param>
281-
/// <param name="version2"> verison to check</param>
282-
/// <returns>True if they are valid versions</returns>
297+
/// <param name="version1">
298+
/// Version to check
299+
/// </param>
300+
/// <param name="version2">
301+
/// Verison to check
302+
/// </param>
303+
/// <param name="checkMinVersion">
304+
/// check if version 1 is is less than or equal to version 2
305+
/// </param>
306+
/// <returns>
307+
/// True if they are valid versions
308+
/// </returns>
283309
private bool verifyVersion(string version1, string version2, bool checkMinVersion = false)
284310
{
285311
Regex rx = new Regex(@"\bv([0-9]+)(\.([0-9]+|x)){2}\b", RegexOptions.Compiled | RegexOptions.IgnoreCase);
@@ -288,7 +314,7 @@ private bool verifyVersion(string version1, string version2, bool checkMinVersio
288314
{
289315
string[] target1 = version1.Split('.');
290316
string[] target2 = version2.Split('.');
291-
317+
int num1, num2;
292318
if (target1.Length == target2.Length)
293319
{
294320
for (short index = 0; index < target2.Length; index++)
@@ -300,7 +326,7 @@ private bool verifyVersion(string version1, string version2, bool checkMinVersio
300326

301327
if (checkMinVersion)
302328
{
303-
int num1, num2;
329+
304330
if (int.TryParse(target1[index], out num1))
305331
{
306332
if(int.TryParse(target2[index], out num2))
@@ -326,32 +352,30 @@ private bool verifyVersion(string version1, string version2, bool checkMinVersio
326352
}
327353

328354
/// <summary>
329-
/// This function looks in the MODS folder for incorrectly installed mods and moves them to a new folder
330-
/// where they should be.
355+
/// This function looks in the MODS folder for incorrectly installed mods and moves them to a new folder
356+
/// where they should be.
331357
/// </summary>
332358
private void detectIndividualDlls()
333359
{
334360
try
335361
{
336362
Debug.Log("Searching mods improperly installed");
337363
FolderPath newFolder;
338-
foreach (FilePath file in _modsFolder.GetFilesInFolder(false))
364+
foreach (FilePath file in ModsFolder.GetFilesInFolder(false))
339365
{
340366

341367
if(file.Extension == "dll")
342368
{
343369
Debug.Log($"{file.FileName} incorrectly installed!");
344-
newFolder = _modsFolder.Extend(file.CleanFileName);
370+
newFolder = ModsFolder.Extend(file.CleanFileName);
345371
if (!newFolder.FolderExists())
346372
{
347373
newFolder = newFolder.CreateFolder();
348374
}
349375
Debug.Log($"{file.FileName} moved!");
350376
file.Move(newFolder.ExtendToFile(file.FileName));
351-
_modsFolder = FileLocations.BaseFolder.Extend("MODS");
352377
}
353378
}
354-
Debug.Log("Everything moved!");
355379
}
356380
catch(Exception e)
357381
{
@@ -361,7 +385,7 @@ private void detectIndividualDlls()
361385
}
362386

363387
/// <summary>
364-
/// This is the mod loader entry point, this is the method that is executed after being injected into the game.
388+
/// This is the mod loader entry point, this is the method that is executed after being injected into the game.
365389
/// </summary>
366390
/// <param name="args"></param>
367391
public static void Main(string[] args)

ModLoader/ModLoader.csproj

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<DefineConstants>TRACE</DefineConstants>
3232
<ErrorReport>prompt</ErrorReport>
3333
<WarningLevel>4</WarningLevel>
34+
<DocumentationFile>bin\Release\documentation.xml</DocumentationFile>
3435
</PropertyGroup>
3536
<ItemGroup>
3637
<Reference Include="0Harmony, Version=2.2.0.0, Culture=neutral, processorArchitecture=MSIL">
@@ -41,9 +42,9 @@
4142
<HintPath>..\Dependencies\Assembly-CSharp.dll</HintPath>
4243
<Private>False</Private>
4344
</Reference>
44-
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
45-
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
46-
<Private>False</Private>
45+
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
46+
<SpecificVersion>False</SpecificVersion>
47+
<HintPath>..\Dependencies\Newtonsoft.Json.dll</HintPath>
4748
</Reference>
4849
<Reference Include="System" />
4950
<Reference Include="System.Core" />
@@ -102,7 +103,9 @@
102103
<Compile Include="IO\Console.cs" />
103104
<Compile Include="IO\ConsoleGUI.cs" />
104105
<Compile Include="Helper.cs" />
106+
<Compile Include="Helpers\KeybindingHelper.cs" />
105107
<Compile Include="Loader.cs" />
108+
<Compile Include="Helpers\SceneHelper.cs" />
106109
<Compile Include="UI\ModsMenu.cs" />
107110
<Compile Include="Patcher.cs" />
108111
<Compile Include="Properties\AssemblyInfo.cs" />

0 commit comments

Comments
 (0)