public static void InvalidateAddendum(VersionManifestAddendum addendum)
 {
     if (lookupCache.ContainsKey(addendum.Name))
     {
         RLog.M.WL(0, "Invalidating cache for addendum: " + addendum.Name);
         lookupCache.Remove(addendum.Name);
     }
 }
        public static bool FindInCache(string id, string type, out VersionManifestAddendum addendum)
        {
            string key           = $"{id}_{type}";
            bool   existsInCache = lookupCache.TryGetValue(key, out addendum);

            if (!existsInCache)
            {
                addendum = null;
            }

            return(existsInCache);
        }
        static bool Prefix(string id, string type, ref VersionManifestAddendum __result, List <VersionManifestAddendum> ___addendums)
        {
            VersionManifestAddendum queryValue;

            if (!VersionManifestAddendumCache.FindInCache(id, type, out queryValue))
            {
                queryValue = VersionManifestAddendumCache.FindInAddendums(id, type, ___addendums);
            }

            __result = queryValue;
            return(false);
        }
Beispiel #4
0
        private static bool AddModEntryToVersionManifest(VersionManifest manifest, ModDef.ManifestEntry modEntry, bool addToDB = false)
        {
            if (modEntry.Path == null)
            {
                return(false);
            }

            VersionManifestAddendum addendum = null;

            if (!string.IsNullOrEmpty(modEntry.AddToAddendum))
            {
                addendum = manifest.GetAddendumByName(modEntry.AddToAddendum);

                // create the addendum if it doesn't exist
                if (addendum == null)
                {
                    Log($"\t\tCreated addendum: {modEntry.AddToAddendum}");
                    addendum = new VersionManifestAddendum(modEntry.AddToAddendum);
                    manifest.ApplyAddendum(addendum);
                }
            }

            // add to DB
            if (addToDB && Path.GetExtension(modEntry.Path).ToLower() == ".json")
            {
                var type = (BattleTechResourceType)Enum.Parse(typeof(BattleTechResourceType), modEntry.Type);
                using (var metadataDatabase = new MetadataDatabase())
                {
                    VersionManifestHotReload.InstantiateResourceAndUpdateMDDB(type, modEntry.Path, metadataDatabase);
                    Log($"\t\tAdding to MDDB! {type} {modEntry.Path}");
                }
            }

            // add assetbundle path so it can be changed when the assetbundle path is requested
            if (modEntry.Type == "AssetBundle")
            {
                ModAssetBundlePaths[modEntry.Id] = modEntry.Path;
            }

            // add to addendum instead of adding to manifest
            if (addendum != null)
            {
                Log($"\t\tAddOrUpdate => {modEntry.Id} ({modEntry.Type}) to addendum {addendum.Name}");
                addendum.AddOrUpdate(modEntry.Id, modEntry.Path, modEntry.Type, DateTime.Now, modEntry.AssetBundleName, modEntry.AssetBundlePersistent);
                return(true);
            }

            // not added to addendum, not added to jsonmerges
            Log($"\t\tAddOrUpdate => {modEntry.Id} ({modEntry.Type})");
            manifest.AddOrUpdate(modEntry.Id, modEntry.Path, modEntry.Type, DateTime.Now, modEntry.AssetBundleName, modEntry.AssetBundlePersistent);
            return(true);
        }
Beispiel #5
0
        // ADDING TO VERSION MANIFEST
        private static bool AddModEntry(VersionManifest manifest, ModDef.ManifestEntry modEntry)
        {
            if (modEntry.Path == null)
            {
                return(false);
            }

            VersionManifestAddendum addendum = null;

            if (!string.IsNullOrEmpty(modEntry.AddToAddendum))
            {
                addendum = manifest.GetAddendumByName(modEntry.AddToAddendum);

                // create the addendum if it doesn't exist
                if (addendum == null)
                {
                    Log($"\t\tCreated addendum: {modEntry.AddToAddendum}");
                    addendum = new VersionManifestAddendum(modEntry.AddToAddendum);
                    manifest.ApplyAddendum(addendum);
                }
            }

            // add special handling for particular types
            switch (modEntry.Type)
            {
            case "AssetBundle":
                ModAssetBundlePaths[modEntry.Id] = modEntry.Path;
                break;

            case "Texture2D":
                ModTexture2Ds.Add(modEntry.Id);
                break;
            }

            // add to addendum instead of adding to manifest
            if (addendum != null)
            {
                Log($"\t\tAddOrUpdate => {modEntry.Id} ({modEntry.Type}) to addendum {addendum.Name}");
                addendum.AddOrUpdate(modEntry.Id, modEntry.Path, modEntry.Type, DateTime.Now, modEntry.AssetBundleName, modEntry.AssetBundlePersistent);
                return(true);
            }

            // not added to addendum, not added to jsonmerges
            Log($"\t\tAddOrUpdate => {modEntry.Id} ({modEntry.Type})");
            manifest.AddOrUpdate(modEntry.Id, modEntry.Path, modEntry.Type, DateTime.Now, modEntry.AssetBundleName, modEntry.AssetBundlePersistent);
            return(true);
        }
Beispiel #6
0
        // ADDING MOD CONTENT TO THE GAME
        private static void AddModEntry(VersionManifest manifest, ModDef.ManifestEntry modEntry)
        {
            if (modEntry.Path == null)
            {
                return;
            }

            VersionManifestAddendum addendum = null;

            if (!string.IsNullOrEmpty(modEntry.AddToAddendum))
            {
                addendum = manifest.GetAddendumByName(modEntry.AddToAddendum);

                if (addendum == null)
                {
                    Log($"\tCannot add {modEntry.Id} to {modEntry.AddToAddendum} because addendum doesn't exist in the manifest.");
                    return;
                }
            }

            // add special handling for particular types
            switch (modEntry.Type)
            {
            case "AssetBundle":
                ModAssetBundlePaths[modEntry.Id] = modEntry.Path;
                break;

            case "Texture2D":
                ModTexture2Ds.Add(modEntry.Id);
                break;
            }

            // add to addendum instead of adding to manifest
            if (addendum != null)
            {
                Log($"\tAdd/Replace: \"{GetRelativePath(modEntry.Path, ModsDirectory)}\" ({modEntry.Type}) [{addendum.Name}]");
            }
            else
            {
                Log($"\tAdd/Replace: \"{GetRelativePath(modEntry.Path, ModsDirectory)}\" ({modEntry.Type})");
            }

            // not added to addendum, not added to jsonmerges
            BTRLEntries.Add(modEntry);
            return;
        }
Beispiel #7
0
        internal static void TryAddToVersionManifest(VersionManifest manifest)
        {
            if (!hasLoadedMods)
            {
                LoadMods();
            }

            var breakMyGame = File.Exists(Path.Combine(ModDirectory, "break.my.game"));

            LogWithDate("Adding in mod manifests!");

            if (breakMyGame)
            {
                var mddPath       = Path.Combine(Path.Combine(StreamingAssetsDirectory, "MDD"), "MetadataDatabase.db");
                var mddBackupPath = mddPath + ".orig";

                Log($"\tBreak my game mode enabled! All new modded content (doesn't currently support merges) will be added to the DB.");

                if (!File.Exists(mddBackupPath))
                {
                    Log($"\t\tBacking up metadata database to {Path.GetFileName(mddBackupPath)}");
                    File.Copy(mddPath, mddBackupPath);
                }
            }

            foreach (var modName in modLoadOrder)
            {
                if (!ModManifest.ContainsKey(modName))
                {
                    continue;
                }

                Log($"\t{modName}:");
                foreach (var modEntry in ModManifest[modName])
                {
                    var existingEntry = manifest.Find(x => x.Id == modEntry.Id);
                    VersionManifestAddendum addendum = null;

                    if (!string.IsNullOrEmpty(modEntry.AddToAddendum))
                    {
                        addendum = manifest.GetAddendumByName(modEntry.AddToAddendum);

                        // create the addendum if it doesn't exist
                        if (addendum == null)
                        {
                            Log($"\t\tCreated addendum {modEntry.AddToAddendum}:");
                            addendum = new VersionManifestAddendum(modEntry.AddToAddendum);
                            manifest.ApplyAddendum(addendum);
                        }
                    }

                    if (modEntry.Type == null)
                    {
                        // null type means that we have to find existing entry with the same rel path to fill in the entry
                        // TODO: + 16 is a little bizzare looking, it's the length of the substring + 1 because we want to get rid of it and the \
                        var relPath = modEntry.Path.Substring(modEntry.Path.LastIndexOf("StreamingAssets", StringComparison.Ordinal) + 16);
                        var fakeStreamingAssetsPath = Path.Combine(StreamingAssetsDirectory, relPath);

                        existingEntry = manifest.Find(x => Path.GetFullPath(x.FilePath) == Path.GetFullPath(fakeStreamingAssetsPath));

                        if (existingEntry == null)
                        {
                            continue;
                        }

                        modEntry.Id   = existingEntry.Id;
                        modEntry.Type = existingEntry.Type;
                    }

                    if (Path.GetExtension(modEntry.Path).ToLower() == ".json" && modEntry.ShouldMergeJSON && existingEntry != null)
                    {
                        // read the manifest pointed entry and hash the contents
                        JsonHashToId[File.ReadAllText(existingEntry.FilePath).GetHashCode()] = modEntry.Id;

                        // The manifest already contains this information, so we need to queue it to be merged
                        var partialJson = File.ReadAllText(modEntry.Path);

                        if (!JsonMerges.ContainsKey(modEntry.Id))
                        {
                            JsonMerges.Add(modEntry.Id, new List <string>());
                        }

                        if (JsonMerges[modEntry.Id].Contains(partialJson))
                        {
                            Log($"\t\tAlready added {modEntry.Id} to JsonMerges");
                            continue;
                        }

                        Log($"\t\tAdding {modEntry.Id} to JsonMerges");
                        JsonMerges[modEntry.Id].Add(partialJson);
                        continue;
                    }

                    if (breakMyGame && Path.GetExtension(modEntry.Path).ToLower() == ".json")
                    {
                        var type = (BattleTechResourceType)Enum.Parse(typeof(BattleTechResourceType), modEntry.Type);
                        using (var metadataDatabase = new MetadataDatabase())
                        {
                            VersionManifestHotReload.InstantiateResourceAndUpdateMDDB(type, modEntry.Path, metadataDatabase);
                            Log($"\t\tAdding to MDDB! {type} {modEntry.Path}");
                        }
                    }

                    if (!string.IsNullOrEmpty(modEntry.AddToAddendum))
                    {
                        Log($"\t\tAddOrUpdate {modEntry.Type} {modEntry.Id} to addendum {addendum.Name}");
                        addendum.AddOrUpdate(modEntry.Id, modEntry.Path, modEntry.Type, DateTime.Now, modEntry.AssetBundleName, modEntry.AssetBundlePersistent);
                        continue;
                    }

                    // This is a new definition or a replacement that doesn't get merged, so add or update the manifest
                    Log($"\t\tAddOrUpdate {modEntry.Type} {modEntry.Id}");
                    manifest.AddOrUpdate(modEntry.Id, modEntry.Path, modEntry.Type, DateTime.Now, modEntry.AssetBundleName, modEntry.AssetBundlePersistent);
                }
            }

            Log("");
        }
 public static void Postfix(BattleTechResourceLocator __instance, BattleTechResourceType type, VersionManifestAddendum addendum, ref VersionManifestEntry[] __result)
 {
     RLog.M.TWL(0, "BattleTechResourceLocator.AllEntriesOfResourceFromAddendum " + addendum.Name + " type:" + type);
     RLog.M.TWL(0, "BattleTechResourceLocator.AllEntriesOfResourceFromAddendum " + addendum.Name + " type:" + type);
     foreach (VersionManifestEntry entry in __result)
     {
         RLog.M.WL(1, entry.FileName);
     }
 }