public static void PreLoad() { if (isPreInitialized) { return; } isPreInitialized = true; Debug.Log("SRML has successfully invaded the game!"); HarmonyPatcher.PatchAll(); try { SRModLoader.LoadMods(); } catch (Exception e) { ErrorGUI.CreateError($"{e.GetType().Name}: {e.Message}"); return; } try { SRModLoader.PreLoadMods(); } catch (Exception e) { ErrorGUI.CreateError($"{e.Message}"); } ReplacerCache.ClearCache(); HarmonyPatcher.Instance.Patch(typeof(GameContext).GetMethod("Start"), new HarmonyMethod(typeof(Main).GetMethod("PostLoad", BindingFlags.NonPublic | BindingFlags.Static))); }
/// <summary> /// Called before GameContext.Awake() /// </summary> internal static void PreLoad() { if (isPreInitialized) { return; } isPreInitialized = true; Debug.Log("SRML has successfully invaded the game!"); prefabParent = new GameObject("PrefabParent").transform; prefabParent.gameObject.SetActive(false); GameObject.DontDestroyOnLoad(prefabParent.gameObject); foreach (var v in Assembly.GetExecutingAssembly().GetTypes()) { System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(v.TypeHandle); } HarmonyPatcher.PatchAll(); try { SRModLoader.InitializeMods(); } catch (Exception e) { Debug.LogError(e); ErrorGUI.CreateError($"{e.GetType().Name}: {e.Message}"); return; } FileLogger.Init(); Console.Console.Init(); HarmonyOverrideHandler.PatchAll(); try { SRModLoader.PreLoadMods(); } catch (Exception e) { Debug.LogError(e); ErrorGUI.CreateError($"{e.Message}"); return; } IdentifiableRegistry.CategorizeAllIds(); GadgetRegistry.CategorizeAllIds(); ReplacerCache.ClearCache(); HarmonyPatcher.Instance.Patch(typeof(GameContext).GetMethod("Start"), prefix: new HarmonyMethod(typeof(Main).GetMethod("Load", BindingFlags.NonPublic | BindingFlags.Static))); }
static void FixPrefabFieldsInternal(GameObject prefab, IFieldReplacer replacementInfo) { var replacer = ReplacerCache.GetReplacer(replacementInfo); var components = replacementInfo.ReplaceInChildren? prefab.GetComponentsInChildren <Component>(true):prefab.GetComponents <Component>(); foreach (var comp in components) { if (!comp) { continue; } foreach (var field in replacer.FieldToField.Where((x) => x.Value.DeclaringType == comp.GetType())) { field.Value.SetValue(comp, field.Key.GetValue((replacer.InstanceInfo.Instance as GameObject).GetComponentInChildren(comp.GetType()))); } } }