예제 #1
0
        private string getAssemblyRealPath(string assemblyPathExpression, out bool isCurrentMod)
        {
            isCurrentMod = false;
            if (string.IsNullOrEmpty(assemblyPathExpression))
            {
                return(string.Empty);
            }

            var expression = ModPathExpressionResolver.Resolve(assemblyPathExpression);

            if (expression.Prefix != "this")
            {
                if (installedMods.ContainsKey(expression.Prefix))
                {
                    ModManifest modManifest = installedMods[expression.Prefix];
                    return(modManifest.InstalledPath + "\\" + expression.Value + ".dll");
                }
                return(null);
            }
            else
            {
                isCurrentMod = true;
                return(expression.Value + ".dll");
            }
        }
예제 #2
0
        public Mods GetInstalledMods()
        {
            getModInstallRootDir();

            if (!string.IsNullOrEmpty(modInstallRootDir))
            {
                DirectoryInfo d = new DirectoryInfo(modInstallRootDir);

                FileSystemInfo[] modDirs = d.GetFileSystemInfos();

                foreach (var dir in modDirs)
                {
                    if (File.Exists(string.Format("{0}/Module.xml", dir.FullName)))
                    {
                        ModManifest manifest = new ModManifest(dir.FullName);
                        if (!installedMods.ContainsKey(dir.Name))
                        {
                            installedMods.Add(dir.Name, manifest);
                            LoadModLocalization(manifest);
                            ResourceGroupManager.Singleton.AddResourceLocation(manifest.InstalledPath, "FileSystem", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
                        }
                    }
                }
            }

            return(installedMods);
        }
예제 #3
0
파일: ModData.cs 프로젝트: lennyhans/OpenMB
        public ModData(ModManifest manifest)
        {
            this.manifest = manifest;

            characterInfos = new List <ModCharacterDfnXML>();
            itemInfos      = new List <ModItemDfnXML>();
            musicInfos     = new List <ModTrackDfnXML>();
            sideInfos      = new List <ModSideDfnXML>();
            soundInfos     = new List <ModSoundDfnXML>();
            skinInfos      = new List <ModCharacterSkinDfnXML>();
            mapInfos       = new List <ModMapDfnXml>();
            worldMapInfos  = new List <ModWorldMapDfnXml>();
            locationInfos  = new List <ModLocationDfnXml>();
            SkeletonInfos  = new List <ModSkeletonDfnXML>();
            ItemTypeInfos  = new List <ModItemTypeDfnXml>();
            menuInfos      = new List <ModMenuDfnXml>();
            modMediaData   = new List <ModMediaData>();
            cursorInfos    = new List <ModCursorDfnXml>();
            vehicleInfos   = new List <ModVehicleDfnXml>();

            HasSinglePlayer = true;
            HasMultiplater  = true;
            HasCredit       = true;
            HasSavedGame    = true;

            ModModelTypes          = new List <IModModelType>();
            ModSettings            = new List <IModSetting>();
            ModTriggerConditions   = new List <IModTriggerCondition>();
            ItemTypes              = new List <IItemType>();
            MapLoaders             = new List <IGameMapLoader>();
            StartupBackgroundTypes = new List <IModStartupBackgroundType>();

            assemblies = new List <Assembly>();
        }
예제 #4
0
        private void LoadModMedia(ModManifest manifest)
        {
            //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("/", "//"));
                if (Directory.Exists(fullMediaDir))
                {
                    ResourceGroupManager.Singleton.AddResourceLocation(fullMediaDir, mediaSection.ResourceLoadType, ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
                    DirectoryInfo di = new DirectoryInfo(fullMediaDir);
                    var           fileSystemInfos = di.EnumerateFileSystemInfos();
                    foreach (var fileSystemInfo in fileSystemInfos)
                    {
                        if (fileSystemInfo.Attributes != FileAttributes.Directory)
                        {
                            if (mediaSection.ResourceType != ResourceType.Other)
                            {
                                ResourceGroupManager.Singleton.DeclareResource(fileSystemInfo.Name, mediaSection.ResourceType.ToString(), ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
                            }
                            currentMod.ModMediaData.Add(new ModMediaData(fileSystemInfo.Name, fileSystemInfo.FullName, mediaSection.ResourceType));
                        }
                    }
                }
            }

            ResourceGroupManager.Singleton.InitialiseResourceGroup(ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
        }
예제 #5
0
        private void LoadInternalTypes(ModManifest manifest)
        {
            //--------------------------------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);
                }
                else if (internalType.GetInterface("IModStartupBackgroundType") != null)
                {
                    var instance = thisAssembly.CreateInstance(internalType.FullName) as IModStartupBackgroundType;
                    currentMod.StartupBackgroundTypes.Add(instance);
                }
                else if (internalType.GetInterface("IScriptCommand") != null)                //avaiable customized script command
                {
                    var instance = thisAssembly.CreateInstance(internalType.FullName) as ScriptCommand;
                    ScriptCommandRegister.Instance.RegisterNewCommand(instance.CommandName, internalType);                     //register this command
                }
            }
            currentMod.Assemblies.Add(thisAssembly);
        }
예제 #6
0
        void loadModWorker_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;
                loadModWorker.ReportProgress(25);

                ChangeModIcon(manifest);

                LoadXmlData(manifest);

                LoadInternalTypes(manifest);

                LoadExternalTypes(manifest);

                VerifyItemTypes();

                LoadModMedia(manifest);

                LoadModLocalization(manifest);

                GameMapManager.Instance.InitMod(currentMod);
                ScreenManager.Instance.InitMod(currentMod);
                MusicSoundManager.Instance.InitMod(currentMod);
                UIManager.Instance.InitMod(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;

                loadModWorker.ReportProgress(100);

                System.Threading.Thread.Sleep(1000);
            }
            catch
            {
                return;
            }
        }
예제 #7
0
        private void ChangeModIcon(ModManifest manifest)
        {
            if (string.IsNullOrEmpty(manifest.MetaData.Icon))
            {
                return;
            }

            if (ResourceGroupManager.Singleton.ResourceExists(
                    ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME,
                    manifest.MetaData.Icon))
            {
                var dataStreamPtr = ResourceGroupManager.Singleton.OpenResource(manifest.MetaData.Icon);
                var stream        = Utilities.Helper.DataPtrToStream(dataStreamPtr);

                IntPtr hwnd;
                EngineManager.Instance.renderWindow.GetCustomAttribute("WINDOW", out hwnd);
                Utilities.Helper.SetRenderWindowIcon(new System.Drawing.Icon(stream), hwnd);
            }
        }
예제 #8
0
파일: ModManager.cs 프로젝트: AlkanV/OpenMB
 private string getAssemblyRealPath(string assemblyXml, out bool isCurrentMod)
 {
     isCurrentMod = false;
     if (string.IsNullOrEmpty(assemblyXml))
     {
         return(string.Empty);
     }
     string[] tokens = assemblyXml.Split('|');
     if (tokens[0] != "this")
     {
         if (installedMods.ContainsKey(tokens[0]))
         {
             ModManifest mod = installedMods[tokens[0]];
             return(mod.InstalledPath + "\\" + tokens[1] + ".dll");
         }
         return(null);
     }
     else
     {
         isCurrentMod = true;
         return(tokens[1] + ".dll");
     }
 }
예제 #9
0
        private void LoadModLocalization(ModManifest manifest)
        {
            //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(manifest.ID, fileSystemInfo.FullName);
                    }
                }
            }
        }
예제 #10
0
        public Mods GetInstalledMods()
        {
            GetModInstallRootDir();

            if (!string.IsNullOrEmpty(modInstallRootDir))
            {
                DirectoryInfo d = new DirectoryInfo(modInstallRootDir);

                FileSystemInfo[] modDirs = d.GetFileSystemInfos();

                foreach (var dir in modDirs)
                {
                    if (File.Exists(string.Format("{0}/Module.xml", dir.FullName)))
                    {
                        ModManifest manifest = new ModManifest(dir.FullName);
                        if (installedMods.ContainsKey(manifest.MetaData.Name))
                        {
                            continue;
                        }
                        installedMods.Add(manifest.MetaData.Name, manifest);

                        for (int i = 0; i < manifest.Media.MediaSections.Count; i++)
                        {
                            var mediaSection = manifest.Media.MediaSections[i];
                            ResourceGroupManager.Singleton.AddResourceLocation(
                                string.Format("{0}\\{1}", dir.FullName, mediaSection.Directory.Replace("/", "//")), mediaSection.Type, ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME);
                        }

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

            return(installedMods);
        }
예제 #11
0
 private void LoadExternalTypes(ModManifest manifest)
 {
     //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 externalAssembly = Assembly.LoadFile(assemblyPath);
                 loadAssemblyTypes(externalAssembly);
                 currentMod.Assemblies.Add(externalAssembly);
             }
             catch (Exception ex)
             {
                 EngineManager.Instance.log.LogMessage("Error Loading Assembly, Details: " + ex.ToString(), LogMessage.LogType.Error);
             }
         }
         else
         {
             EngineManager.Instance.log.LogMessage("Requested Assembly Path don't exist!", LogMessage.LogType.Error);
         }
     }
     //--------------------------------------------
 }
예제 #12
0
 private void LoadExternalTypes(ModManifest manifest)
 {
     //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);
                     }
                     else if (type.GetInterface("IModStartupBackgroundType") != null)
                     {
                         var instance = assemblyDll.CreateInstance(type.FullName) as IModStartupBackgroundType;
                         currentMod.StartupBackgroundTypes.Add(instance);
                     }
                 }
                 currentMod.Assemblies.Add(assemblyDll);
             }
             catch (Exception ex)
             {
                 EngineManager.Instance.log.LogMessage("Error Loading Assembly, Details: " + ex.ToString(), LogMessage.LogType.Error);
             }
         }
         else
         {
             EngineManager.Instance.log.LogMessage("Requested Assembly Path don't exist!", LogMessage.LogType.Error);
         }
     }
     //--------------------------------------------
 }
예제 #13
0
        private void LoadXmlData(ModManifest manifest)
        {
            XmlObjectLoader loader = null;

            if (!string.IsNullOrEmpty(manifest.Data.Animations))
            {
                loader = new XmlObjectLoader(manifest.InstalledPath + "/" + manifest.Data.Animations);
                ModAnimationsDfnXml animationDfn;
                loader.Load(out animationDfn);
                currentMod.AnimationInfos = animationDfn.Animations;
                loadModWorker.ReportProgress(20);
            }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            if (!string.IsNullOrEmpty(manifest.Data.UILayouts))
            {
                loader = new XmlObjectLoader(manifest.InstalledPath + "/" + manifest.Data.UILayouts);
                ModUILayoutsDfnXml uiLayoutsDfnXml;
                loader.Load(out uiLayoutsDfnXml);
                currentMod.UILayoutInfos = uiLayoutsDfnXml.UILayouts;
            }

            if (!string.IsNullOrEmpty(manifest.Data.Strings))
            {
                loader = new XmlObjectLoader(manifest.InstalledPath + "/" + manifest.Data.Strings);
                ModStringsDfnXml stringsDfnXml;
                loader.Load(out stringsDfnXml);
                currentMod.StringInfos = stringsDfnXml.Strings;
            }

            if (!string.IsNullOrEmpty(manifest.Data.Cursors))
            {
                loader = new XmlObjectLoader(manifest.InstalledPath + "/" + manifest.Data.Cursors);
                ModCursorsDfnXml cursorsDfnXml;
                loader.Load(out cursorsDfnXml);
                currentMod.CursorInfos = cursorsDfnXml.Cursors;
            }

            if (!string.IsNullOrEmpty(manifest.Data.MapTemplates))
            {
                loader = new XmlObjectLoader(manifest.InstalledPath + "/" + manifest.Data.MapTemplates);
                ModMapTemplatesDfnXml mapTemplatesDfnXml;
                loader.Load(out mapTemplatesDfnXml);
                currentMod.MapTemplateInfos = mapTemplatesDfnXml.MapTemplates;
            }

            if (!string.IsNullOrEmpty(manifest.Data.Vehicles))
            {
                loader = new XmlObjectLoader(manifest.InstalledPath + "/" + manifest.Data.Vehicles);
                ModVehiclesDfnXml vehiclesDfnXml;
                loader.Load(out vehiclesDfnXml);
                currentMod.VehicleInfos = vehiclesDfnXml.VehicleDfns;
            }
        }
예제 #14
0
파일: ModManager.cs 프로젝트: AlkanV/OpenMB
        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;
            }
        }
예제 #15
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;
            }
        }