88using UnityEngine . Events ;
99using System . IO ;
1010using System . Text . RegularExpressions ;
11+ using SFS . UI ;
12+ using SFS . Translations ;
13+ using SFS . Input ;
1114
1215namespace ModLoader
1316{
1417 /// <summary>
15- /// This is the main class of ModLoader. this class is injected into the game with Unity Doorstop injector.
18+ /// This is the main class of ModLoader. this class is injected into the game with the Unity Doorstop injector.
1619 /// </summary>
1720 public class Loader : MonoBehaviour
1821 {
1922
2023 // This save Loader instance
2124 public static Loader main ;
22- private Console _console ;
25+ // private Console _console;
2326
2427 // This save the gameObject that implement Loader class
2528 public static GameObject root ;
2629
2730 private static FolderPath _modsFolder ;
2831
32+ // modlaoder version
2933 private const string modLoderVersion = "v1.1.0" ;
3034
3135 public static FolderPath ModsFolder
@@ -38,21 +42,21 @@ public static FolderPath ModsFolder
3842
3943 private List < string > _modsLoaded ;
4044
41- // List of all mods loaded in the folder MODS
45+ // List of all mods loaded in the MODS folder
4246 private Dictionary < string , SFSMod > _modList ;
4347
4448 /// <summary>
45- /// first method executed. Save loader instance in static var and suscribe to scene event.
49+ /// first executed method . Save the loader instance to static var and subscribe to the scene event.
4650 /// </summary>
4751 private void Awake ( )
4852 {
4953 Loader . main = this ;
50- this . suscribeOnChangeScene ( this . OnSceneLoaded ) ;
54+ SceneManager . sceneLoaded += this . OnSceneLoaded ;
5155 _modsFolder = FileLocations . BaseFolder . Extend ( "MODS" ) . CreateFolder ( ) ;
5256 }
5357
5458 /// <summary>
55- /// This method start to read mods and is executed automatically when this class is created after Awake method.
59+ /// This method starts reading mods and runs automatically when this class is created after the Awake method.
5660 /// </summary>
5761 private void Start ( )
5862 {
@@ -76,19 +80,8 @@ private void Start()
7680 Debug . LogException ( e ) ;
7781 }
7882 }
79- //this.postloading();
80- Debug . Log ( "All Ready" ) ;
81- }
82-
83- /*private void postloading()
84- {
85- this._console = Console.root.GetComponent<Console>();
86- this._console.ConsoleGui.Mods = this.getMods();
87- this._console.ConsoleGui.SceneGameObjects = UnityEngine.Object.FindObjectsOfType<GameObject>();
88- }*/
89-
90- //this._consoleGui.Mods = Loader.main.getMods();
91- //Loader.main.suscribeOnChangeScene(this.OnSceneLoaded);
83+ Debug . Log ( "Already" ) ;
84+ }
9285
9386 /// <summary>
9487 /// get mod instance.
@@ -97,9 +90,17 @@ private void Start()
9790 /// <returns>instance mod</returns>
9891 public SFSMod getMod ( string modId )
9992 {
100- return this . _modList [ modId ] ;
93+ if ( this . _modList . ContainsKey ( modId ) )
94+ {
95+ return this . _modList [ modId ] ;
96+ }
97+ return null ;
10198 }
10299
100+ /// <summary>
101+ /// Get a list of all loaded mods
102+ /// </summary>
103+ /// <returns> loaded mods </returns>
103104 public SFSMod [ ] getMods ( )
104105 {
105106 List < SFSMod > mods = new List < SFSMod > ( ) ;
@@ -111,14 +112,14 @@ public SFSMod[] getMods()
111112 }
112113
113114 /// <summary>
114- /// This method read MODS folder and identify what is the entry point for each folder.
115+ /// This method reads the MODS folder and identifies what the entry point is for each folder.
115116 /// </summary>
116- /// <returns> dictionary whit modid as key and SFSMod instance as value</returns>
117+ /// <returns> dictionary with modid as key and SFSMod instance as value</returns>
117118 private Dictionary < string , SFSMod > getModList ( )
118119 {
119120 Dictionary < string , SFSMod > modList = new Dictionary < string , SFSMod > ( ) ;
120121
121- // get list of mod Folders in MODS folder
122+ // get a list of mod folders in the MODS folder
122123 IEnumerable < FolderPath > modsFolders = _modsFolder . GetFoldersInFolder ( false ) ;
123124 string basePath = Path . Combine ( FileLocations . BaseFolder , "MODS" ) ;
124125
@@ -131,7 +132,7 @@ private Dictionary<string, SFSMod> getModList()
131132 Assembly assembly = Assembly . LoadFrom ( fileModPath ) ;
132133 SFSMod mod = null ;
133134
134- // verfiy if hace SFSMod class
135+ // check if you have SFSMod class
135136 foreach ( Type typeClass in assembly . GetTypes ( ) )
136137 {
137138 if ( typeClass . IsSubclassOf ( typeof ( SFSMod ) ) )
@@ -150,7 +151,7 @@ private Dictionary<string, SFSMod> getModList()
150151
151152 if ( modList . ContainsKey ( mod . ModId ) )
152153 {
153- throw new Exception ( "Already existe another mod whit id " + mod . ModId ) ;
154+ throw new Exception ( "There is already another mod with id 12 " + mod . ModId ) ;
154155 }
155156
156157 modList . Add ( mod . ModId , mod ) ;
@@ -165,23 +166,23 @@ private Dictionary<string, SFSMod> getModList()
165166 }
166167
167168 /// <summary>
168- /// Load mod dependecies and chec if is already loaded and check their version.
169+ ///Load the mod dependencies and check if it is already loaded and check its version.
169170 /// </summary>
170- /// <param name="dependencies"> list of dependecies that you need to load first </param>
171- /// <returns> true if all dependecies have been loaded </returns>
171+ /// <param name="dependencies"> lista de dependencias que necesitas cargar primero </param>
172+ /// <returns> verdadero si se han cargado todas las dependencias </returns>
172173 private bool loadDependencies ( Dictionary < string , string [ ] > dependencies )
173174 {
174-
175- // for each mod dependencie
175+
176+ // for each mod dependency
176177 foreach ( var item in dependencies )
177178 {
178- // exist mod in the list?
179+ // is there a mod in the list?
179180 if ( this . _modList . ContainsKey ( item . Key ) )
180181 {
181- // get mod dependecie
182+ // get mod dependencies
182183 SFSMod dependencieMod = this . _modList [ item . Key ] ;
183184
184- // verify if the dependencie version is the same that mod need
185+ // check if the dependency version is the same as the one needed by the mod
185186 bool versionFlag = false ;
186187 foreach ( string version in item . Value )
187188 {
@@ -195,24 +196,24 @@ private bool loadDependencies(Dictionary<string, string[]> dependencies)
195196 // the version is valid
196197 if ( versionFlag )
197198 {
198- // start load dependencie first
199+ // start load dependency first
199200 this . loadMod ( dependencieMod ) ;
200201 continue ;
201202 }
202203 }
203- // dependencie not exist or is diferent version
204+ // dependency does not exist or is a different version
204205 throw new Exception ( "Is necesary install " + item . Key + " " + string . Join ( ", " , item . Value ) ) ;
205206 }
206207 return true ;
207208 }
208209
209210 /// <summary>
210- /// start to check version mod and run load method
211+ /// start checking mod version and run load method
211212 /// </summary>
212213 /// <param name="mod">mod to start load</param>
213214 private void loadMod ( SFSMod mod )
214215 {
215- // this mod has been load ?, if not start load
216+ // has this mod been loaded ?, if it does not start loading
216217 if ( this . _modsLoaded . Contains ( mod . ModId ) )
217218 {
218219 return ;
@@ -224,10 +225,10 @@ private void loadMod(SFSMod mod)
224225 // check if the version is valid for this modloader version
225226 if ( verifyVersion ( mod . ModLoderVersion , modLoderVersion ) )
226227 {
227- // Have dependencies?
228- if ( mod . Dependencies != null )
228+ // Does it have dependencies?
229+ if ( mod . Dependencies != null )
229230 {
230- // load them
231+ // charge them
231232 this . loadDependencies ( mod . Dependencies ) ;
232233 }
233234
@@ -236,39 +237,39 @@ private void loadMod(SFSMod mod)
236237 return ;
237238 }
238239
239- // the mod loader version is not valid
240+ //mod loader version is invalid
240241 throw new Exception ( mod . Name + " need ModLoader " + mod . Version ) ;
241242 }
242243
243244 /// <summary>
244- /// check two versions string to identify if are the same
245+ /// check the string of two versions to identify if they are the same
245246 /// </summary>
246247 /// <param name="version1"> version to check</param>
247248 /// <param name="version2"> verison to check</param>
248- /// <returns>true if are valid versions</returns>
249+ /// <returns>true if they are valid versions</returns>
249250 private bool verifyVersion ( string version1 , string version2 )
250251 {
251252 Regex rx = new Regex ( @"\bv([0-9]|[1-9][0-9]).([0-9]|[1-9][0-9]|x).([0-9]|[1-9][0-9]|x)\b" , RegexOptions . Compiled | RegexOptions . IgnoreCase ) ;
252- // have the formal v1.x.x
253+ // has the format v1.x.x
253254 if ( rx . IsMatch ( version1 ) && rx . IsMatch ( version2 ) )
254255 {
255- string [ ] modVersion = version1 . Split ( '.' ) ;
256- string [ ] target = version2 . Split ( '.' ) ;
256+ string [ ] target1 = version1 . Split ( '.' ) ;
257+ string [ ] target2 = version2 . Split ( '.' ) ;
257258
258- if ( modVersion . Length == target . Length )
259+ if ( target1 . Length == target2 . Length )
259260 {
260- for ( short index = 0 ; index < target . Length ; index ++ )
261+ for ( short index = 0 ; index < target2 . Length ; index ++ )
261262 {
262- if ( modVersion [ index ] == "x" )
263+ if ( target1 [ index ] == "x" )
263264 {
264265 continue ;
265266 }
266- if ( modVersion [ index ] != target [ index ] )
267+ if ( target1 [ index ] != target2 [ index ] )
267268 {
268269 return false ;
269270 }
270271 }
271- // have the format and is valid version for this modloader version
272+ //both are valid for each other
272273 return true ;
273274
274275 }
@@ -279,33 +280,16 @@ private bool verifyVersion(string version1, string version2)
279280
280281 private void OnSceneLoaded ( Scene scene , LoadSceneMode mode )
281282 {
282- Debug . Log ( "Scene change to " + scene . name ) ;
283- /*if (this._console)
284- {
285- this._console.ConsoleGui.SceneGameObjects = UnityEngine.Object.FindObjectsOfType<GameObject>();
286- }*/
287-
288- }
289-
290- /// <summary>
291- /// suscribe to scene change event
292- /// </summary>
293- /// <param name="method">method what do you want to suscribe</param>
294- /// <returns>true if subscribed</returns>
295- public bool suscribeOnChangeScene ( UnityAction < Scene , LoadSceneMode > method )
296- {
297- SceneManager . sceneLoaded += method ;
298- return true ;
283+ Debug . Log ( "Scene change to " + scene . name ) ;
299284 }
300285
301-
302286 /// <summary>
303- /// This is the mod loader entry point, this is the method execute after be injected in the game
287+ /// This is the mod loader entry point, this is the method that is executed after being injected into the game.
304288 /// </summary>
305289 /// <param name="args"></param>
306290 public static void Main ( string [ ] args )
307291 {
308- Harmony patcher = new Harmony ( "SFS .mod.loader " ) ;
292+ Harmony patcher = new Harmony ( "sfs .mod.modloader " ) ;
309293 patcher . PatchAll ( ) ;
310294 }
311295 }
0 commit comments