Пример #1
0
        public ModManifest(string path)
        {
            InstalledPath = path;
            path          = path + "/module.xml";
            ModXmlLoader loader = new ModXmlLoader(path);
            ModXML       xmldata;

            if (loader.Load <XML.ModXML>(out xmldata))
            {
                MetaData = new ModBaseInfo(InstalledPath,
                                           xmldata.ModInfo.Name,
                                           xmldata.ModInfo.Description,
                                           xmldata.ModInfo.Version,
                                           xmldata.ModInfo.Thumb,
                                           xmldata.ModInfo.Movie);
                AssemblyName = xmldata.Assembly;
                Data         = new ModDataInfo(xmldata.Data.characterXML,
                                               xmldata.Data.soundXML,
                                               xmldata.Data.musicXML,
                                               xmldata.Data.itemXML,
                                               xmldata.Data.sideXML,
                                               xmldata.Data.skinXML,
                                               xmldata.Data.mapsXml,
                                               xmldata.Data.worldMapsXML,
                                               xmldata.Data.locationsXML,
                                               xmldata.Data.skeletonsXML,
                                               xmldata.Data.DataDir.MapDir,
                                               xmldata.Data.DataDir.MusicDir,
                                               xmldata.Data.DataDir.ScriptDir);

                Media = xmldata.Media;
            }
        }
Пример #2
0
        public ModManifest(string path)
        {
            InstalledPath = path;
            path          = path + "/module.xml";
            ModXmlLoader loader = new ModXmlLoader(path);
            ModXML       xmldata;

            if (loader.Load <XML.ModXML>(out xmldata))
            {
                MetaData = new ModBaseInfo(InstalledPath,
                                           xmldata.ModInfo.Name,
                                           xmldata.ModInfo.Description,
                                           xmldata.ModInfo.Version,
                                           xmldata.ModInfo.Thumb,
                                           xmldata.ModInfo.Movie,
                                           xmldata.ModInfo.Assemblies,
                                           xmldata.ModInfo.DisplayInChooser);
                Data = new ModDataInfo(xmldata.Data.characterXML,
                                       xmldata.Data.soundXML,
                                       xmldata.Data.musicXML,
                                       xmldata.Data.itemXML,
                                       xmldata.Data.itemTypeXML,
                                       xmldata.Data.sideXML,
                                       xmldata.Data.skinXML,
                                       xmldata.Data.mapsXml,
                                       xmldata.Data.worldMapsXML,
                                       xmldata.Data.locationsXML,
                                       xmldata.Data.skeletonsXML,
                                       xmldata.Data.modelsXml,
                                       xmldata.Data.scenePropsXML,
                                       xmldata.Data.menusXml,
                                       xmldata.Data.DataDir.MapDir,
                                       xmldata.Data.DataDir.MusicDir,
                                       xmldata.Data.DataDir.ScriptDir);
                Media = xmldata.Media;

                Settings = xmldata.Settings.Settings;
            }
        }
Пример #3
0
        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                if (installedMods == null || installedMods.Count <= 0)
                {
                    return;
                }
                ModManifest manifest = installedMods.Where(o => o.Key == currentModName).SingleOrDefault().Value;
                currentMod           = new OpenMB.Mods.ModData();
                currentMod.BasicInfo = manifest.MetaData;
                worker.ReportProgress(25);

                ModXmlLoader loader = null;

                if (!string.IsNullOrEmpty(manifest.Data.Characters))
                {
                    loader = new ModXmlLoader(manifest.InstalledPath + "/" + manifest.Data.Characters);
                    ModCharactersDfnXML characterDfn;
                    loader.Load(out characterDfn);
                    currentMod.CharacterInfos = characterDfn.CharacterDfns;
                    worker.ReportProgress(50);
                }

                if (!string.IsNullOrEmpty(manifest.Data.ItemTypes))
                {
                    loader = new ModXmlLoader(manifest.InstalledPath + "/" + manifest.Data.ItemTypes);
                    ModItemTypesDfnXml itemTypesDfn;
                    loader.Load(out itemTypesDfn);
                    currentMod.ItemTypeInfos = itemTypesDfn != null ? itemTypesDfn.ItemTypes : null;
                    worker.ReportProgress(75);
                }

                if (!string.IsNullOrEmpty(manifest.Data.Items))
                {
                    loader = new ModXmlLoader(manifest.InstalledPath + "/" + manifest.Data.Items);
                    ModItemsDfnXML itemDfn;
                    loader.Load(out itemDfn);
                    currentMod.ItemInfos = itemDfn != null ? itemDfn.Items : null;
                    worker.ReportProgress(75);
                }

                if (!string.IsNullOrEmpty(manifest.Data.Sides))
                {
                    loader = new ModXmlLoader(manifest.InstalledPath + "/" + manifest.Data.Sides);
                    ModSidesDfnXML sideDfn;
                    loader.Load(out sideDfn);
                    currentMod.SideInfos = sideDfn.Sides;
                    worker.ReportProgress(80);
                }

                if (!string.IsNullOrEmpty(manifest.Data.Skin))
                {
                    loader = new ModXmlLoader(manifest.InstalledPath + "/" + manifest.Data.Skin);
                    ModSkinDfnXML skinDfn;
                    loader.Load(out skinDfn);
                    currentMod.SkinInfos = skinDfn.CharacterSkinList;
                }

                if (!string.IsNullOrEmpty(manifest.Data.Music))
                {
                    loader = new ModXmlLoader(manifest.InstalledPath + "/" + manifest.Data.Music);
                    ModTracksDfnXML trackDfn;
                    loader.Load(out trackDfn);
                    currentMod.MusicInfos = trackDfn.Tracks;
                }

                if (!string.IsNullOrEmpty(manifest.Data.Sound))
                {
                    loader = new ModXmlLoader(manifest.InstalledPath + "/" + manifest.Data.Sound);
                    ModSoundsDfnXML soundDfn;
                    loader.Load(out soundDfn);
                    currentMod.SoundInfos = soundDfn.Sounds;
                }

                if (!string.IsNullOrEmpty(manifest.Data.Maps))
                {
                    loader = new ModXmlLoader(manifest.InstalledPath + "/" + manifest.Data.Maps);
                    ModMapsDfnXml mapsDfn;
                    loader.Load <XML.ModMapsDfnXml>(out mapsDfn);
                    currentMod.MapInfos = mapsDfn.Maps;
                }

                if (!string.IsNullOrEmpty(manifest.Data.WorldMaps))
                {
                    loader = new ModXmlLoader(manifest.InstalledPath + "/" + manifest.Data.WorldMaps);
                    ModWorldMapsDfnXml worldMapsDfn;
                    loader.Load(out worldMapsDfn);
                    currentMod.WorldMapInfos = worldMapsDfn.WorldMaps;
                }

                if (!string.IsNullOrEmpty(manifest.Data.Locations))
                {
                    loader = new ModXmlLoader(manifest.InstalledPath + "/" + manifest.Data.Locations);
                    XML.ModLocationsDfnXml locationsDfn;
                    loader.Load <XML.ModLocationsDfnXml>(out locationsDfn);
                    currentMod.LocationInfos = locationsDfn.Locations;
                }

                if (!string.IsNullOrEmpty(manifest.Data.Skeletons))
                {
                    loader = new ModXmlLoader(manifest.InstalledPath + "/" + manifest.Data.Skeletons);
                    ModSkeletonsDfnXML skeletonsDfn;
                    loader.Load(out skeletonsDfn);
                    currentMod.SkeletonInfos = skeletonsDfn.Skeletons;
                }

                if (!string.IsNullOrEmpty(manifest.Data.SceneProps))
                {
                    loader = new ModXmlLoader(manifest.InstalledPath + "/" + manifest.Data.SceneProps);
                    ModScenePropsDfnXml scenePropsDfnXml;
                    loader.Load(out scenePropsDfnXml);
                    currentMod.SceneProps = scenePropsDfnXml.SceneProps;
                }

                if (!string.IsNullOrEmpty(manifest.Data.Models))
                {
                    loader = new ModXmlLoader(manifest.InstalledPath + "/" + manifest.Data.Models);
                    ModModelsDfnXml modelsDfnXml;
                    loader.Load(out modelsDfnXml);
                    currentMod.Models = modelsDfnXml.Models;
                }

                if (!string.IsNullOrEmpty(manifest.Data.Menus))
                {
                    loader = new ModXmlLoader(manifest.InstalledPath + "/" + manifest.Data.Menus);
                    ModMenusDfnXml menusDfnXml;
                    loader.Load(out menusDfnXml);
                    currentMod.MenuInfos = menusDfnXml.Menus;
                }

                //--------------------------------Load Types-------------------------
                //Load Internal types
                Assembly thisAssembly  = GetType().Assembly;
                Type[]   internalTypes = thisAssembly.GetTypes();
                foreach (var internalType in internalTypes)
                {
                    if (internalType.GetInterface("IModSetting") != null)
                    {
                        var instance           = thisAssembly.CreateInstance(internalType.FullName) as IModSetting;
                        var findedSettingInMod = manifest.Settings.Where(o => o.Name == instance.Name);
                        if (findedSettingInMod.Count() > 0)
                        {
                            instance.Value = findedSettingInMod.ElementAt(0).Value;
                            instance.Load(currentMod);
                        }
                        currentMod.ModSettings.Add(instance);
                    }
                    else if (internalType.GetInterface("IModModelType") != null)
                    {
                        var instance = thisAssembly.CreateInstance(internalType.FullName) as IModModelType;
                        currentMod.ModModelTypes.Add(instance);
                    }
                    else if (internalType.GetInterface("IModTriggerCondition") != null)
                    {
                        var instance = thisAssembly.CreateInstance(internalType.FullName) as IModTriggerCondition;
                        currentMod.ModTriggerConditions.Add(instance);
                    }
                    else if (internalType.GetInterface("IGameMapLoader") != null)
                    {
                        var instance = thisAssembly.CreateInstance(internalType.FullName) as IGameMapLoader;
                        currentMod.MapLoaders.Add(instance);
                    }
                }

                //Load Customized type from the assembly
                for (int i = 0; i < manifest.MetaData.Assemblies.Count; i++)
                {
                    string assemblyXml = manifest.MetaData.Assemblies[i];
                    bool   isCurrentMod;
                    string assemblyPath = getAssemblyRealPath(assemblyXml, out isCurrentMod);
                    if (string.IsNullOrEmpty(assemblyPath))
                    {
                        continue;
                    }
                    if (isCurrentMod)
                    {
                        assemblyPath = manifest.InstalledPath + "\\" + assemblyPath;
                    }
                    if (File.Exists(assemblyPath))
                    {
                        try
                        {
                            Assembly assemblyDll = Assembly.LoadFile(assemblyPath);
                            Type[]   types       = assemblyDll.GetTypes();
                            foreach (var type in types)
                            {
                                if (type.GetInterface("IScriptCommand") != null)//avaiable customized script command
                                {
                                    var instance = assemblyDll.CreateInstance(type.FullName) as ScriptCommand;
                                    ScriptCommandRegister.Instance.RegisterNewCommand(instance.CommandName, type); //register this command
                                }
                                else if (type.GetInterface("IModSetting") != null)
                                {
                                    var instance           = assemblyDll.CreateInstance(type.FullName) as IModSetting;
                                    var findedSettingInMod = manifest.Settings.Where(o => o.Name == instance.Name);
                                    if (findedSettingInMod.Count() > 0)
                                    {
                                        instance.Value = findedSettingInMod.ElementAt(0).Value;
                                        instance.Load(currentMod);
                                    }
                                    currentMod.ModSettings.Add(instance);
                                }
                                else if (type.GetInterface("IModModelType") != null)
                                {
                                    var instance = assemblyDll.CreateInstance(type.FullName) as IModModelType;
                                    currentMod.ModModelTypes.Add(instance);
                                }
                                else if (type.GetInterface("IModTriggerCondition") != null)
                                {
                                    var instance = assemblyDll.CreateInstance(type.FullName) as IModTriggerCondition;
                                    currentMod.ModTriggerConditions.Add(instance);
                                }
                                else if (type.GetInterface("IItemType") != null)
                                {
                                    var instance = assemblyDll.CreateInstance(type.FullName) as IItemType;
                                    currentMod.ItemTypes.Add(instance);
                                }
                                else if (type.GetInterface("IGameMapLoader") != null)
                                {
                                    var instance = assemblyDll.CreateInstance(type.FullName) as IGameMapLoader;
                                    currentMod.MapLoaders.Add(instance);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            GameManager.Instance.log.LogMessage("Error Loading Assembly, Details: " + ex.ToString(), LogMessage.LogType.Error);
                        }
                    }
                    else
                    {
                        GameManager.Instance.log.LogMessage("Requested Assembly Path don't exist!", LogMessage.LogType.Error);
                    }
                }
                //--------------------------------------------

                //Valid Item Type
                for (int j = currentMod.ItemInfos.Count - 1; j >= 0; j--)
                {
                    if (!validItemType(currentMod, currentMod.ItemInfos[j].Type))
                    {
                        string itemType = currentMod.ItemInfos[j].Type;
                        string itemID   = currentMod.ItemInfos[j].ID;
                        currentMod.ItemInfos.Remove(currentMod.ItemInfos[j]);
                        GameManager.Instance.log.LogMessage(
                            string.Format("Unrecognized Item Type `{0}` in Item `{1}`", itemType, itemID),
                            LogMessage.LogType.Error
                            );
                    }
                }

                //load mod media
                for (int i = 0; i < manifest.Media.MediaSections.Count; i++)
                {
                    var    mediaSection = manifest.Media.MediaSections[i];
                    string fullMediaDir = string.Format("{0}\\{1}", manifest.InstalledPath, mediaSection.Directory.Replace("/", "//"));
                    ResourceGroupManager.Singleton.AddResourceLocation(fullMediaDir, mediaSection.ResourceLoadType, ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
                    if (Directory.Exists(fullMediaDir))
                    {
                        DirectoryInfo di = new DirectoryInfo(fullMediaDir);
                        var           fileSystemInfos = di.EnumerateFileSystemInfos();
                        foreach (var fileSystemInfo in fileSystemInfos)
                        {
                            if (fileSystemInfo.Attributes != FileAttributes.Directory)
                            {
                                currentMod.ModMediaData.Add(new ModMediaData(fileSystemInfo.Name, fileSystemInfo.FullName, mediaSection.ResourceType));
                            }
                        }
                    }
                }

                //load mod localization files
                string        localizationFolder    = "Locate";
                string        localizationFullPath  = manifest.InstalledPath + "//" + localizationFolder;
                string        currentLocateFullPath = localizationFullPath + "//" + LocateSystem.Instance.Locate.ToString();
                DirectoryInfo directory             = new DirectoryInfo(currentLocateFullPath);
                if (!Directory.Exists(currentLocateFullPath))
                {
                    Directory.CreateDirectory(currentLocateFullPath);
                }
                else
                {
                    var fileSystemInfos = directory.EnumerateFileSystemInfos();
                    foreach (var fileSystemInfo in fileSystemInfos)
                    {
                        if (fileSystemInfo.Attributes != FileAttributes.Directory && Path.GetExtension(fileSystemInfo.Name) == "ucs")
                        {
                            LocateSystem.Instance.AddModLocateFile(fileSystemInfo.FullName);
                        }
                    }
                }

                ScreenManager.Instance.ModData = currentMod;

                StringVector resources = ResourceGroupManager.Singleton.FindResourceNames(ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, "*.script");
                ScriptPreprocessor.Instance.Process(resources.ToList());

                currentMod.MapDir    = manifest.Data.MapDir;
                currentMod.MusicDir  = manifest.Data.MusicDir;
                currentMod.ScriptDir = manifest.Data.ScriptDir;

                worker.ReportProgress(100);

                System.Threading.Thread.Sleep(1000);
            }
            catch
            {
                return;
            }
        }
Пример #4
0
        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                if (installedMods == null || installedMods.Count <= 0)
                {
                    return;
                }
                ModManifest manifest = installedMods.Where(o => o.Key == currentModName).SingleOrDefault().Value;
                currentMod           = new OpenMB.Mods.ModData();
                currentMod.BasicInfo = manifest.MetaData;
                worker.ReportProgress(25);

                ModXmlLoader            loader = new ModXmlLoader(manifest.InstalledPath + "/" + manifest.Data.Characters);
                XML.ModCharactersDfnXML characterDfn;
                loader.Load <XML.ModCharactersDfnXML>(out characterDfn);
                currentMod.CharacterInfos = characterDfn.CharacterDfns;
                worker.ReportProgress(50);

                loader = new ModXmlLoader(manifest.InstalledPath + "/" + manifest.Data.Items);
                XML.ModItemsDfnXML itemDfn;
                loader.Load <XML.ModItemsDfnXML>(out itemDfn);
                currentMod.ItemInfos = itemDfn != null ? itemDfn.Items : null;
                worker.ReportProgress(75);

                loader = new ModXmlLoader(manifest.InstalledPath + "/" + manifest.Data.Sides);
                XML.ModSidesDfnXML sideDfn;
                loader.Load <XML.ModSidesDfnXML>(out sideDfn);
                currentMod.SideInfos = sideDfn.Sides;
                worker.ReportProgress(80);

                loader = new ModXmlLoader(manifest.InstalledPath + "/" + manifest.Data.Skin);
                XML.ModSkinDfnXML skinDfn;
                loader.Load <XML.ModSkinDfnXML>(out skinDfn);
                currentMod.SkinInfos = skinDfn.CharacterSkinList;

                loader = new ModXmlLoader(manifest.InstalledPath + "/" + manifest.Data.Music);
                XML.ModTracksDfnXML trackDfn;
                loader.Load <XML.ModTracksDfnXML>(out trackDfn);
                currentMod.MusicInfos = trackDfn.Tracks;

                loader = new ModXmlLoader(manifest.InstalledPath + "/" + manifest.Data.Sound);
                XML.ModSoundsDfnXML soundDfn;
                loader.Load <XML.ModSoundsDfnXML>(out soundDfn);
                currentMod.SoundInfos = soundDfn.Sounds;

                loader = new ModXmlLoader(manifest.InstalledPath + "/" + manifest.Data.Maps);
                XML.ModMapsDfnXml mapsDfn;
                loader.Load <XML.ModMapsDfnXml>(out mapsDfn);
                currentMod.MapInfos = mapsDfn.Maps;

                loader = new ModXmlLoader(manifest.InstalledPath + "/" + manifest.Data.WorldMaps);
                XML.ModWorldMapsDfnXml worldMapsDfn;
                loader.Load <XML.ModWorldMapsDfnXml>(out worldMapsDfn);
                currentMod.WorldMapInfos = worldMapsDfn.WorldMaps;

                loader = new ModXmlLoader(manifest.InstalledPath + "/" + manifest.Data.Locations);
                XML.ModLocationsDfnXml locationsDfn;
                loader.Load <XML.ModLocationsDfnXml>(out locationsDfn);
                currentMod.LocationInfos = locationsDfn.Locations;

                loader = new ModXmlLoader(manifest.InstalledPath + "/" + manifest.Data.Skeletons);
                XML.ModSkeletonsDfnXML skeletonsDfn;
                loader.Load <XML.ModSkeletonsDfnXML>(out skeletonsDfn);
                currentMod.SkeletonInfos = skeletonsDfn.Skeletons;

                currentMod.MapDir    = manifest.Data.MapDir;
                currentMod.MusicDir  = manifest.Data.MusicDir;
                currentMod.ScriptDir = manifest.Data.ScriptDir;

                worker.ReportProgress(100);

                System.Threading.Thread.Sleep(1000);
            }
            catch
            {
                return;
            }
        }