Example #1
0
 internal ModEditor(KMod.Mod target)
 {
     if (target == null)
     {
         throw new ArgumentNullException("target");
     }
     if (target.label.distribution_platform != KMod.Label.DistributionPlatform.Steam)
     {
         throw new ArgumentException("Only works on Steam mods");
     }
     if (!ulong.TryParse(target.label.id, out ulong id))
     {
         throw new ArgumentException("Invalid Steam mod ID!");
     }
     if (!MOD_DETAILS.TryGetValue(id, out details))
     {
         details.m_ulSteamIDOwner   = ulong.MaxValue;
         details.m_nPublishedFileId = new PublishedFileId_t(id);
     }
     DataPath     = Description = PreviewPath = PatchInfo = Title = null;
     Mod          = target;
     updateCaller = new CallResult <RemoteStorageUpdatePublishedFileResult_t>(
         OnUpdateDone);
     uploadCaller = new CallResult <RemoteStorageFileWriteAsyncComplete_t>();
     updateHandle = PublishedFileUpdateHandle_t.Invalid;
 }
Example #2
0
        public static void Postfix(Transform ___entryParent)
        {
            string currentPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            for (int i = 0; i < Global.Instance.modManager.mods.Count; ++i)
            {
                KMod.Mod mod = Global.Instance.modManager.mods[i];

                if ((mod.loaded_content & KMod.Content.DLL) == KMod.Content.DLL)
                {
                    if (string.Equals(Path.GetFullPath(mod.label.install_path), currentPath))
                    {
                        string modTitle = mod.label.title;

                        for (int j = 0; j < ___entryParent.childCount; ++j)
                        {
                            Transform           modSpecificTransform = ___entryParent.GetChild(j);
                            HierarchyReferences hierarchyReferences  = modSpecificTransform.GetComponent <HierarchyReferences>();
                            LocText             titleReference       = hierarchyReferences.GetReference <LocText>("Title");

                            if (titleReference != null && titleReference.text == modTitle)
                            {
                                titleReference.text = "<align=left>" + titleReference.text + " <line-height=0.000000001>\n<align=right>(" + Assembly.GetExecutingAssembly().GetName().Version + ")";
                                titleReference.autoSizeTextContainer = false;

                                break;
                            }
                        }

                        break;
                    }
                }
            }
        }
Example #3
0
 internal VersionCheckMethods(KMod.Mod mod)
 {
     Methods    = new List <IModVersionChecker>(8);
     ModToCheck = mod ?? throw new ArgumentNullException(nameof(mod));
     PUtil.LogDebug("Registered mod ID {0} for automatic version checking".F(
                        ModToCheck.staticID));
 }
Example #4
0
        public static void Postfix(Transform ___entryParent)
        {
            string currentPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            for (int i = 0; i < Global.Instance.modManager.mods.Count; ++i)
            {
                KMod.Mod mod = Global.Instance.modManager.mods[i];
                if ((mod.loaded_content & KMod.Content.DLL) == KMod.Content.DLL)
                {
                    if (string.Equals(Path.GetFullPath(mod.label.install_path), currentPath))
                    {
                        string modTitle = mod.label.title;
                        for (int j = 0; j < ___entryParent.childCount; ++j)
                        {
                            Transform           modSpecificTransform = ___entryParent.GetChild(j);
                            HierarchyReferences hierarchyReferences  = modSpecificTransform.GetComponent <HierarchyReferences>();
                            LocText             titleReference       = hierarchyReferences.GetReference <LocText>("Title");

                            if (titleReference != null && titleReference.text == modTitle)
                            {
                                Version version = Assembly.GetExecutingAssembly().GetName().Version;
                                titleReference.text = $"<align=left>{titleReference.text}\n" +
                                                      $"<size=65%>Last updated {FormatDay(version.Build)} {months[version.Minor-1]} {version.Major} - Revision {version.Revision}";
                                titleReference.autoSizeTextContainer = false;

                                break;
                            }
                        }
                        break;
                    }
                }
            }
        }
Example #5
0
        internal OptionsDialog(Type optionsType, KMod.Mod modSpec)
        {
            dialog           = null;
            modImage         = null;
            this.modSpec     = modSpec ?? throw new ArgumentNullException("modSpec");
            this.optionsType = optionsType ?? throw new ArgumentNullException("optionsType");
            optionCategories = OptionsEntry.BuildOptions(optionsType);
            options          = null;
            // Determine config location
            infoAttr = POptions.GetModInfoAttribute(optionsType);
            typeAttr = POptions.GetConfigFileAttribute(optionsType);
            var src = modSpec.file_source;

            if (src == null)
            {
                path = null;
            }
            else
            {
                path = Path.Combine(src.GetRoot(), typeAttr?.ConfigFileName ?? POptions.
                                    CONFIG_FILE_NAME);
            }
            // Find mod home page
            string url   = infoAttr?.URL;
            var    label = modSpec.label;

            if (string.IsNullOrEmpty(url) && label.distribution_platform == KMod.Label.
                DistributionPlatform.Steam)
            {
                // Steam mods use their workshop ID as the label
                url = "https://steamcommunity.com/sharedfiles/filedetails/?id=" + label.id;
            }
            modURL = url;
        }
Example #6
0
 internal VersionCheckTask(KMod.Mod mod, IModVersionChecker method,
                           ConcurrentDictionary <string, ModVersionCheckResults> results)
 {
     this.mod     = mod ?? throw new ArgumentNullException(nameof(mod));
     this.method  = method ?? throw new ArgumentNullException(nameof(method));
     this.results = results ?? throw new ArgumentNullException(nameof(results));
     Next         = null;
 }
Example #7
0
 internal OptionsDialog(Type optionsType, KMod.Mod modSpec)
 {
     dialog           = null;
     this.modSpec     = modSpec ?? throw new ArgumentNullException("modSpec");
     this.optionsType = optionsType ?? throw new ArgumentNullException(
                                  "optionsType");
     optionEntries = BuildOptions(optionsType);
     options       = null;
     path          = Path.Combine(modSpec.file_source.GetRoot(), POptions.CONFIG_FILE);
 }
Example #8
0
 internal ModEditDialog(GameObject parent, KMod.Mod target)
 {
     if (target == null)
     {
         throw new ArgumentNullException("target");
     }
     if (target.label.distribution_platform != KMod.Label.DistributionPlatform.Steam)
     {
         throw new ArgumentException("Only works on Steam mods");
     }
     mod    = target;
     editor = new ModEditor(target);
     editor.OnModifyComplete += OnModifyComplete;
     editor.OnModifyFailed   += OnModifyFailed;
     this.parent              = parent;
 }
Example #9
0
        /// <summary>
        /// Gets the current version of the mod. If the version is specified in mod_info.yaml,
        /// that version is reported. Otherwise, the assembly file version (and failing that,
        /// the assembly version) of the assembly defining the mod's first UserMod2 instance
        /// is reported.
        ///
        /// This method will only work after mods have loaded.
        /// </summary>
        /// <param name="mod">The mod to check.</param>
        /// <returns>The current version of that mod.</returns>
        public static string GetCurrentVersion(KMod.Mod mod)
        {
            if (mod == null)
            {
                throw new ArgumentNullException(nameof(mod));
            }
            string version = mod.packagedModInfo?.version;

            if (string.IsNullOrEmpty(version))
            {
                // Does it have UM2 instances?
                var instances = mod.loaded_mod_data?.userMod2Instances;
                var dlls      = mod.loaded_mod_data?.dlls;
                if (instances != null)
                {
                    // Use first UserMod2
                    foreach (var um2 in instances)
                    {
                        version = GetCurrentVersion(um2.Key);
                        if (!string.IsNullOrEmpty(version))
                        {
                            break;
                        }
                    }
                }
                else if (dlls != null && dlls.Count > 0)
                {
                    // Use first DLL
                    foreach (var assembly in dlls)
                    {
                        version = GetCurrentVersion(assembly);
                        if (!string.IsNullOrEmpty(version))
                        {
                            break;
                        }
                    }
                }
                else
                {
                    // All methods of determining the version have failed
                    version = "";
                }
            }
            return(version);
        }
Example #10
0
        internal OptionsDialog(Type optionsType, KMod.Mod modSpec)
        {
            dialog           = null;
            this.modSpec     = modSpec ?? throw new ArgumentNullException("modSpec");
            this.optionsType = optionsType ?? throw new ArgumentNullException("optionsType");
            optionCategories = BuildOptions(optionsType);
            options          = null;
            // Determine config location
            typeAttr = POptions.GetConfigFileAttribute(optionsType);
            var src = modSpec.file_source;

            if (src == null)
            {
                path = null;
            }
            else
            {
                path = Path.Combine(src.GetRoot(), typeAttr?.ConfigFileName ?? POptions.
                                    CONFIG_FILE_NAME);
            }
        }
Example #11
0
        internal static void EnableLUTModule(KMod.Mod mod)
        {
            if (mod == null)
            {
                return;
            }

            if (Mod.Registry != null)
            {
                if (ModAssets.lutNight != null)
                {
                    Mod.Registry[RegistryKeys.LUTNotIncluded_NightLUT] = ModAssets.lutNight;
                    LUTEnabled = true;
                }
                else
                {
                    Debug.Log("Festive Decor: Failed to apply night LUT. (No asset)");
                }
            }
            else
            {
                Debug.Log("Festive Decor: Failed to enable LUT Module. (No registry)");
            }
        }
 /// <summary>
 /// Retrieves the normalized path of the mod's active content directory, adjusting if
 /// the mod is running an archived version.
 /// </summary>
 /// <param name="mod">The mod to query.</param>
 /// <returns>The mod's active root directory (where its assembly is located).</returns>
 public static string GetModBasePath(this KMod.Mod mod)
 {
     return(Klei.FileSystem.Normalize(System.IO.Path.Combine(mod.label.install_path,
                                                             mod.relative_root)));
 }