Esempio n. 1
0
            public static bool TryGet(TechType originTech, out TechType recyclingTech, bool initialRun = false)
            {
                recyclingTech = TechType.None;
                if (originTech == TechType.None)
                {
                    return(false);
                }
                if (cache.TryGetValue(originTech, out recyclingTech))
                {
                    return(true);
                }
#if SUBNAUTICA
                RecipeData originData = CraftDataHandler.GetTechData(originTech);
#elif BELOWZERO
                RecipeData originData = CraftDataHandler.GetRecipeData(originTech);
#endif
                if (originData == null)
                {
                    if (!initialRun)
                    {
                        Logger.Log(Logger.Level.Error, $"Failed to load RecipeData for TechType '{originTech}'.");
                    }
                    return(false);
                }

                if (Config.IsBlacklisted(originTech))
                {
                    blacklist.Add(originTech);
                }
                recyclingTech     = CreateRecyclingData(originTech, originData);
                cache[originTech] = recyclingTech;

                return(true);
            }
Esempio n. 2
0
        public static void Load()
        {
            Assembly assembly = Assembly.GetExecutingAssembly();
            Harmony  harmony  = Harmony.CreateAndPatchAll(assembly, $"MrPurple6411_{assembly.GetName().Name}");

            Assembly EasyCraft = AppDomain.CurrentDomain.GetAssemblies()
                                 .Where((x) => x.FullName.StartsWith("EasyCraft"))?
                                 .FirstOrFallback(null);

            if (EasyCraft != null)
            {
                Type ClosestItemContainers = AccessTools.TypeByName("ClosestItemContainers");
                if (ClosestItemContainers != null)
                {
                    containers = AccessTools.Property(ClosestItemContainers, "containers");
                    if (containers != null)
                    {
                        MethodInfo ClosestItemContainers_GetPickupCount = AccessTools.Method(ClosestItemContainers, "GetPickupCount");
                        MethodInfo ClosestItemContainers_DestroyItem    = AccessTools.Method(ClosestItemContainers, "DestroyItem");
                        if (ClosestItemContainers_GetPickupCount != null && ClosestItemContainers_DestroyItem != null)
                        {
                            harmony.Patch(ClosestItemContainers_GetPickupCount, prefix: new HarmonyMethod(typeof(ClosestItemContainers_Patches), nameof(ClosestItemContainers_Patches.ClosestItemContainers_GetPickupCount_Prefix)));
                            harmony.Patch(ClosestItemContainers_DestroyItem, prefix: new HarmonyMethod(typeof(ClosestItemContainers_Patches), nameof(ClosestItemContainers_Patches.ClosestItemContainers_DestroyItem_Prefix)));
                            Logger.Log(Logger.Level.Info, "Succesfully Patched Easycraft Methods.");
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        public void Start()
        {
            PrefabIdentifier prefabIdentifier = GetComponentInParent <PrefabIdentifier>();

            if ((prefabIdentifier ??= GetComponent <PrefabIdentifier>()) is null)
            {
                return;
            }

            ColorInfo colorInfo;
            string    saveFolder = Main.GetSaveFolderPath();
            string    filePath   = Main.Combine(saveFolder, prefabIdentifier.Id + ".json");

            using (StreamReader reader = new StreamReader(filePath))
            {
                var serializer = new JsonSerializer();
                colorInfo = serializer.Deserialize(reader, typeof(ColorInfo)) as ColorInfo;
            }
            if (File.Exists(filePath))
            {
                if (colorInfo != null)
                {
                    savedColor = new Color(colorInfo.RedLevel, colorInfo.GreenLevel, colorInfo.BlueLevel);
                    return;
                }
                Logger.Log(Logger.Level.Warn, "[Spotlight Colorizable] ColorInfo is null");
                return;
            }

            Logger.Log(Logger.Level.Warn, "saved file doesn't exist");
        }
Esempio n. 4
0
        /// <summary>
        /// Load and get the sprite for a given name, looking inside the Sprites folder in the Assets folder of the mod
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static Atlas.Sprite GetSprite(string name)
        {
            var path = Path.Combine(Names.SpritesFolder, $"{name}.png");

            if (File.Exists(path))
            {
                return(ImageUtils.LoadSpriteFromFile(path));
            }

            Logger.Log(Logger.Level.Error, $"Sprite for {name} not found.");
            return(SpriteManager.defaultSprite);
        }
Esempio n. 5
0
        internal static void LoadMaterials()
        {
            var materialsBundle = AssetBundle.LoadFromFile(Path.Combine(Names.AssetsFolder, "defaultmaterials"));

            foreach (var type in SupportedTypes)
            {
                Logger.Log(Logger.Level.Debug, $"Loading material: {type.AsString()}");
                Materials[type] = materialsBundle.LoadAsset <Material>(type.AsString());
                if (Materials[type] is null)
                {
                    Logger.Log(Logger.Level.Error, $"Material not found: {type.AsString()}");
                }
            }
        }
Esempio n. 6
0
        private static void LogStatus(List <QMod> mods, ModStatus statusToReport, string summary, Logger.Level logLevel)
        {
            List <QMod> specificMods = mods.FindAll(mod => mod.Status == statusToReport);

            if (specificMods.Count == 0)
            {
                return;
            }

            Logger.Log(logLevel, summary);
            foreach (QMod mod in specificMods)
            {
                Console.WriteLine($"- {mod.DisplayName} ({mod.Id})");
            }
        }
Esempio n. 7
0
        /// <inheritdoc />
        public override GameObject GetGameObject()
        {
            switch (_type)
            {
            case CompactType.Ingot:
                // ReSharper disable once AccessToStaticMemberViaDerivedType
                var prefab = GameObject.Instantiate(CraftData.GetPrefabForTechType(TechType.TitaniumIngot));
                Logger.Log(Logger.Level.Debug, $"Game Object instantiated for custom ingot ({ClassID})");
                //try to use a custom material
                if (ModAssets.Materials.TryGetValue(_baseType, out var mat))
                {
                    //material exists
                    var renderer = prefab.GetComponentInChildren <Renderer>();
                    renderer.material = mat;
                }

                return(prefab);

            default:
                throw new NotImplementedException($"Compact type {_type.ToString()} does not exist yet.");
            }
        }
Esempio n. 8
0
        public void OnHandHover(GUIHand hand)
        {
            if (!enabled)
            {
                return;
            }

            Light light = this.gameObject.GetComponentInChildren <Light>();

            Renderer[] renderers = this.gameObject.GetComponentsInChildren <Renderer>();
            if (light == null)
            {
                Logger.Log(Logger.Level.Error, "[ColorizableSpotlight] Light Component is missing!");
                return;
            }

            var reticle = HandReticle.main;

            reticle.SetIcon(HandReticle.IconType.Hand, 1f);

            if (Input.GetKeyDown(KeyCode.R))
            {
                if (light.color.r >= 1.0f)
                {
                    light.color = new Color(0f, light.color.g, light.color.b);
                }
                else
                {
                    light.color = new Color(light.color.r + 0.1f, light.color.g, light.color.b);
                }

                savedColor.r = light.color.r;
                ErrorMessage.AddDebug($"Spotlight: Red levels updated ({light.color.r:0.00}/1)");
            }
            else if (Input.GetKeyDown(KeyCode.G))
            {
                if (light.color.g >= 1.0f)
                {
                    light.color = new Color(light.color.r, 0f, light.color.b);
                }
                else
                {
                    light.color = new Color(light.color.r, light.color.g + 0.1f, light.color.b);
                }

                savedColor.g = light.color.g;
                ErrorMessage.AddDebug($"Spotlight: Green levels updated ({light.color.g:0.00}/1)");
            }
            else if (Input.GetKeyDown(KeyCode.B))
            {
                if (light.color.b >= 1.0f)
                {
                    light.color = new Color(light.color.r, light.color.g, 0f);
                }
                else
                {
                    light.color = new Color(light.color.r, light.color.g, light.color.b + 0.1f);
                }

                savedColor.b = light.color.b;
                ErrorMessage.AddDebug($"Spotlight: Blue levels updated ({light.color.b:0.00}/1)");
            }
            foreach (var renderer in renderers)
            {
                foreach (var material in renderer.materials)
                {
                    material.SetColor(ShaderPropertyID._GlowColor, new Color(light.color.r, light.color.g, light.color.b));
                }
            }
            reticle.SetInteractText($"Press \"R\" to change the Red Levels, current red Level: {light.color.r:0.00}\nPress \"G\" to change the Green Levels, current Green Level: {light.color.g:0.00}\nPress \"B\" to change the Blue Levels, current Blue level: {light.color.b:0.00}");
        }