/// <summary>Draws the Gizmo itself</summary>
        public override void DrawGizmo(Vector2 position)
        {
            if (Target.HasAttached())
            {
                Texture2D secIcon = ExceptionUtils.IgnoreErrors(() => GameContext.Instance.LookupDirector.GetGadgetDefinition(Target.GetAttachedId())?.icon.texture, MarkerController.MissingImage);

                position += (ICON_SIZE / 2);
                Rect rect = new Rect(position, ICON_SIZE / 1.5f);
                GUI.DrawTexture(rect, secIcon);
            }
        }
 /// <summary>The icon for the marker</summary>
 public override Texture2D GetIcon()
 {
     return(ExceptionUtils.IgnoreErrors(() => GameContext.Instance.LookupDirector.GetIcon(Target.id).texture, MarkerController.MissingImage));
 }
 /// <summary>
 /// Checks if an assembly is loaded (To check for mods by ID use <see cref="IsModLoaded"/>)
 /// </summary>
 /// <param name="name">The name of the assembly</param>
 /// <returns>True if loaded, false otherwise</returns>
 public static bool IsAssemblyLoaded(string name)
 {
     return(ExceptionUtils.IgnoreErrors(() => Assembly.Load(name)) != null);
 }
Exemple #4
0
        // To setup the controller
        internal static void Setup()
        {
            MissingImage = SRObjects.MissingIcon?.texture;
            GadgetSite   = SRObjects.Get <Sprite>("iconPlaceGadget")?.texture;

            foreach (string name in Enum.GetNames(typeof(Identifiable.Id)))
            {
                Identifiable.Id ID = EnumUtils.Parse <Identifiable.Id>(name);
                if (toIgnoreIden.Contains(ID))
                {
                    continue;
                }

                GameObject obj = Identifiable.GORDO_CLASS.Contains(ID)
                                        ? ExceptionUtils.IgnoreErrors(() => GameContext.Instance.LookupDirector.GetGordo(ID))
                                        : ExceptionUtils.IgnoreErrors(() => GameContext.Instance.LookupDirector.GetPrefab(ID));

                if (obj == null)
                {
                    continue;
                }

                InstallIDMarker(ID, obj);
            }

            foreach (string name in Enum.GetNames(typeof(Gadget.Id)))
            {
                Gadget.Id ID = EnumUtils.Parse <Gadget.Id>(name);
                if (toIgnoreGadget.Contains(ID))
                {
                    continue;
                }

                GameObject obj = ExceptionUtils.IgnoreErrors(() => GameContext.Instance.LookupDirector.GetGadgetDefinition(ID).prefab);

                if (obj == null)
                {
                    continue;
                }

                InstallGadgetMarker(ID, obj);
            }

            foreach (Identifiable found in UnityEngine.Object.FindObjectsOfType <Identifiable>())
            {
                if (found.gameObject.scene.buildIndex == 3)
                {
                    InstallIDMarker(found.id, found.gameObject);
                }
            }

            foreach (GordoIdentifiable found in UnityEngine.Object.FindObjectsOfType <GordoIdentifiable>())
            {
                if (found.gameObject.scene.buildIndex == 3)
                {
                    InstallIDMarker(found.id, found.gameObject);
                }
            }

            foreach (Gadget found in UnityEngine.Object.FindObjectsOfType <Gadget>())
            {
                if (found.gameObject.scene.buildIndex == 3)
                {
                    InstallGadgetMarker(found.id, found.gameObject);
                }
            }

            foreach (GadgetSite found in UnityEngine.Object.FindObjectsOfType <GadgetSite>())
            {
                if (found.gameObject.scene.buildIndex == 3)
                {
                    found.gameObject.InstallMarker <GadgetSiteMarker>();
                }
            }

            OnMarkerSetup?.Invoke();
        }
        //+ GUU INJECT
        // Loads the main system of Guu
        internal static void LoadGuu()
        {
            // Prevents the system from being loaded twice
            if (isLoaded)
            {
                LOGGER.Log(new StackTrace().ToString());
                return;
            }

            //& Removes Sentry SDK from the game
            SentrySdk sentrySdk = Object.FindObjectOfType <SentrySdk>();

            if (sentrySdk != null)
            {
                sentrySdk.Dsn = string.Empty;
                sentrySdk.GetType().GetField("_instance", BindingFlags.NonPublic | BindingFlags.Static)?.SetValue(null, null);
                sentrySdk.StopAllCoroutines();
                Application.logMessageReceived -= sentrySdk.OnLogMessageReceived;
                Object.Destroy(sentrySdk, 1);

                LOGGER.Log("Game is modded! Disabling Sentry SDK");
            }

            //& Run required system functions
            if (!CMD_ARGS.Contains("--guuLauncher") && !DEBUG)
            {
                Application.Quit();
            }

            // Generate the dynamic folders if they are not present
            foreach (string folder in DYNAMIC_FOLDERS)
            {
                if (!Directory.Exists(folder))
                {
                    Directory.CreateDirectory(folder);
                }
            }

            //& Starts Eden before everything else
            LogHandler.RegisterIfEmpty(LOGGER.Log, LOGGER.LogWarning, LOGGER.LogError, LOGGER.LogCritical);
            EdenUnity.Entry.EdenUnity.Init();

            // Add exceptions of types
            EdenHarmony.RegisterMethodException("SteamDLCProvider", "*");
            EdenHarmony.RegisterMethodException("EpicDLCProvider", "*");
            EdenHarmony.RegisterMethodException("DLCProvider", "*");
            EdenHarmony.RegisterMethodException("DLCDirector", "*");

            // Add exceptions of methods
            EdenHarmony.RegisterMethodException <GameContext>("Awake");

            // Add Name Resolve
            EdenHarmony.EnumNameResolve += EnumInjector.NameResolve;

            //& Starts the loading process and times it
            DateTime total = DateTime.Now;

            LOGGER.Log(LOG_MSEPARATOR);
            LOGGER.Log("GUU LOADING PROCESS STARTED");
            LOGGER.Log(LOG_SEPARATOR);

            //& Injects all assemblies, section is timed
            DateTime section = DateTime.Now;

            LOGGER.Log("[INJECTING ASSEMBLIES]");

            core     = LoadAssembly(CORE_ASSEM);
            api      = LoadAssembly(API_ASSEM);
            save     = LoadAssembly(SAVE_ASSEM);
            world    = LoadAssembly(WORLD_ASSEM);
            devTools = LoadAssembly(DEV_TOOLS_ASSEM);
            patches  = LoadAssembly(PATCHES_ASSEM);

            game = Assembly.Load("Assembly-CSharp");

            // Load Bridge Assemblies
            if (ExceptionUtils.IgnoreErrors(() => Assembly.Load(SRML_ASSEM)) != null)
            {
                srmlBridge = LoadAssembly(SRML_BRIDGE_ASSEM, "Found SRML! ");
                Loader.ModLoader.srmlLoaderBridge = srmlBridge.ObtainTypeByForce("LoaderBridge");
            }

            LOGGER.Log($"[INJECTION COMPLETED] - {(DateTime.Now - section).TotalMilliseconds} ms");
            LOGGER.Log(LOG_SEPARATOR);

            //& Patches all assemblies, section is timed
            section = DateTime.Now;
            LOGGER.Log("[PATCHING ASSEMBLIES]");

            harmony = new EdenHarmony("Guu");
            if (patches != null)
            {
                PatchAssembly(patches);
            }
            if (srmlBridge != null)
            {
                PatchAssembly(srmlBridge);
            }

            LOGGER.Log($"[PATCHING COMPLETED] - {(DateTime.Now - section).TotalMilliseconds} ms");
            LOGGER.Log(LOG_SEPARATOR);

            //& Loads all asset packs, section is timed
            section = DateTime.Now;
            LOGGER.Log("[LOADING ASSET PACKS]");

            guiPack = LoadPack(GUI_PACK);

            LOGGER.Log($"[LOADING COMPLETED] - {(DateTime.Now - section).TotalMilliseconds} ms");
            LOGGER.Log(LOG_SEPARATOR);

            //& Loads all addon libraries
            section = DateTime.Now;
            LOGGER.Log("[LOADING ADDON LIBRARIES]");

            bool          hasAddons = false;
            DirectoryInfo addons    = new DirectoryInfo(LIBS_FOLDER);

            foreach (FileInfo file in addons.GetFiles($"*{DLL_EXTENSION}"))
            {
                hasAddons = true;

                ExceptionUtils.ThrowSuccessMessage(() =>
                {
                    Assembly loadedLib = AssemblyUtils.LoadWithSymbols(file.FullName);
                    ADDON_ASSEMBLIES.Add(loadedLib);

                    Type mainType = loadedLib.GetTypes().Single(t => t.IsSubclassOf(typeof(IAddonLoad)));

                    if (mainType == null)
                    {
                        return;
                    }

                    IAddonLoad main = Activator.CreateInstance(mainType) as IAddonLoad;
                    main?.Initialize();
                }, $"- Loaded '{file.Name}'");
            }

            if (!hasAddons)
            {
                LOGGER.Log("- No Addons were found");
            }

            LOGGER.Log($"[LOADING COMPLETED] - {(DateTime.Now - section).TotalMilliseconds} ms");
            LOGGER.Log(LOG_SEPARATOR);

            //& Initializes all internal services
            section = DateTime.Now;
            LOGGER.Log("[INITIALIZING INTERNAL SERVICES]");

            GuuServices.CreateServiceObject();
            GuuServices.InitInternalServices();

            LOGGER.Log($"[INITIALIZATION COMPLETED] - {(DateTime.Now - section).TotalMilliseconds} ms");
            LOGGER.Log(LOG_SEPARATOR);

            //& Finalize the loading process
            section = DateTime.Now;
            LOGGER.Log("[FINALIZING]");

            APIHandler.InitializeHandler();

            LOGGER.Log($"[FINALIZING COMPLETED] - {(DateTime.Now - section).TotalMilliseconds} ms");
            LOGGER.Log(LOG_SEPARATOR);
            LOGGER.Log($"SYSTEM IS FULLY OPERATIONAL - {(DateTime.Now - total).TotalMilliseconds} ms");
            LOGGER.Log(LOG_MSEPARATOR);

            // Marks loading completed
            isLoaded = true;

            // Finalizes
            LOGGER.Log("Starting the Mod Loader!");
            InternalLogger.HandleThrow(Loader.ModLoader.GatherMods);
        }