Ejemplo n.º 1
0
        /// <summary>
        /// 添加全局方法
        /// </summary>
        /// <param name="method"></param>
        /// <param name="fun"></param>
        public void AddGlobalMethod(MethodInfo method, Action <ILGenerator> fun)
        {
            ParameterInfo[] ps         = method.GetParameters();
            ListX <Type>    paramTypes = ListX <Type> .From <ParameterInfo>(ps, delegate(ParameterInfo item) { return(item.ParameterType); });

            //TypeBuilder tbuilder = mbuilder.DefineType(method.DeclaringType.Name, TypeAttributes.Public);
            //MethodBuilder mb = tbuilder.DefineMethod(method.Name.Replace(".", "_"), method.Attributes, method.ReturnType, paramTypes);
            if (TypeBuilder == null)
            {
                TypeBuilder = ModBuilder.DefineType(Name, TypeAttributes.Public);
            }

            String name = method.Name.Replace(".", "_");

            if (String.IsNullOrEmpty(name))
            {
                name = "Test" + DateTime.Now.Ticks;
            }
            //MethodBuilder mb = ModBuilder.DefineGlobalMethod(name, method.Attributes, method.ReturnType, paramTypes.ToArray());
            MethodBuilder mb = TypeBuilder.DefineMethod(name, method.Attributes, method.ReturnType, paramTypes.ToArray());

            ILGenerator il = mb.GetILGenerator();

            fun(il);
        }
        public override void OnInspectorGUI()
        {
            var assetPackage = ((BuildPlugin)serializedObject.targetObject).pluginBaseClass;

            if (GUILayout.Button("Build AssetBundle"))
            {
                var uniqueID = GUID.Generate();
                var prefab   = PrefabUtility.SaveAsPrefabAsset(assetPackage.gameObject, $"Assets/Plugin_{uniqueID}.prefab", out bool succeeded);

                if (succeeded)
                {
                    var bundle = new Bundle();
                    bundle.Prefab = prefab;
                    bundle.Name   = assetPackage.pluginName;

                    AssetDatabase.CreateAsset(bundle, $"Assets/Plugin_{uniqueID}.asset");
                    try
                    {
                        ModBuilder.BuildBundleFromAsset(bundle);
                    }
                    catch { }

                    AssetDatabase.DeleteAsset($"Assets/Plugin_{uniqueID}.prefab");
                    AssetDatabase.DeleteAsset($"Assets/Plugin_{uniqueID}.asset");
                }
                else
                {
                    Debug.LogError("Failed to create avatar prefab");
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Build a mod file at the given path from the current <see cref="Project"/>.
        /// </summary>
        /// <param name="p_strPath">The file path at which to build the mod.</param>
        protected void BuildMod(string p_strPath)
        {
            if (!Validate())
            {
                return;
            }
            if ((Warnings.Count > 0) && !GetIgnoreWarnings())
            {
                return;
            }
            //save project
            string strProjectPath = ModProject.FilePath;

            if (String.IsNullOrEmpty(strProjectPath))
            {
                strProjectPath = GetProjectSavePath();
            }
            if (String.IsNullOrEmpty(strProjectPath))
            {
                return;
            }
            ModProject.Save(strProjectPath);

            if (String.IsNullOrEmpty(p_strPath))
            {
                p_strPath = GetNewModSavePath();
            }
            if (!String.IsNullOrEmpty(p_strPath))
            {
                ModBuilder.PackageMod(p_strPath, ModProject);
                ModPackingStarted(this, new EventArgs <IBackgroundTask>(ModBuilder));
            }
        }
Ejemplo n.º 4
0
        public Mod Load(string baseDirectoryPath)
        {
            Log.Loader.Trace($"Loading mod directory: {baseDirectoryPath}");

            // Check if Mod.xml exists
            var xmlPath = Path.Combine(baseDirectoryPath, "Mod.xml");

            if (!File.Exists(xmlPath))
            {
                throw new ModXmlFileMissingException(xmlPath);
            }

            // Check if Data directory exists
            var dataDirectoryPath = Path.Combine(baseDirectoryPath, "Data");

            if (!Directory.Exists(dataDirectoryPath))
            {
                Log.Loader.Error($"Data directory is missing: {dataDirectoryPath}");
                Directory.CreateDirectory(dataDirectoryPath);
            }

            // Set data directory
            var modBuilder = new ModBuilder();

            modBuilder.SetBaseDirectoryPath(baseDirectoryPath);
            modBuilder.SetDataDirectoryPath(dataDirectoryPath);

            return(LoadModXml(xmlPath, modBuilder));
        }
Ejemplo n.º 5
0
        private void NewButton_Click(object sender, RoutedEventArgs e)
        {
            var newMod = new NewModDialog()
            {
                Owner = this
            };
            var result = newMod.ShowDialog();

            if (!result.HasValue || !result.Value)
            {
                return;
            }

            // Get unique directory
            string modPath = Path.Combine(ModDatabase.ModDirectory, SelectedGame.ToString(), newMod.ModTitle);

            if (Directory.Exists(modPath))
            {
                var newModPath = modPath;
                int i          = 0;

                while (Directory.Exists(newModPath))
                {
                    newModPath = modPath + "_" + i++;
                }

                modPath = newModPath;
            }

            // Build mod
            var mod = new ModBuilder()
                      .SetGame(SelectedGame)
                      .SetTitle(newMod.ModTitle)
                      .SetDescription(newMod.Description)
                      .SetVersion(newMod.Version)
                      .SetDate(DateTime.UtcNow.ToShortDateString())
                      .SetAuthor(newMod.Author)
                      .SetUrl(newMod.Url)
                      .SetUpdateUrl(newMod.UpdateUrl)
                      .SetBaseDirectoryPath(modPath)
                      .Build();

            // Do actual saving
            var modLoader = new XmlModLoader();

            modLoader.Save(mod);

            // Reload
            RefreshModDatabase();
        }
Ejemplo n.º 6
0
    protected void newmodclick(object sender, EventArgs e)
    {
        GTKFrontend.NewModDialog newMod = new GTKFrontend.NewModDialog();
        if (newMod.Run() != (int)ResponseType.Ok)
        {
            newMod.Destroy();
            return;
        }

        // Get unique directory
        string modPath = System.IO.Path.Combine(ModDatabase.ModDirectory, SelectedGame.ToString(), newMod.ModTitle);

        if (Directory.Exists(modPath))
        {
            var newModPath = modPath;
            int i          = 0;

            while (Directory.Exists(newModPath))
            {
                newModPath = modPath + "_" + i++;
            }

            modPath = newModPath;
        }

        // Build mod
        var mod = new ModBuilder()
                  .SetGame(SelectedGame)
                  .SetTitle(newMod.ModTitle)
                  .SetDescription(newMod.Description)
                  .SetVersion(newMod.Version)
                  .SetDate(DateTime.UtcNow.ToShortDateString())
                  .SetAuthor(newMod.Author)
                  .SetUrl(newMod.Url)
                  .SetUpdateUrl(newMod.UpdateUrl)
                  .SetBaseDirectoryPath(modPath)
                  .Build();

        // Do actual saving
        var modLoader = new XmlModLoader();

        modLoader.Save(mod);

        // Reload
        RefreshModDatabase();
    }
Ejemplo n.º 7
0
        private void NewButton_Click(object sender, RoutedEventArgs e)
        {
            var newMod = new NewModDialog()
            {
                Owner = this
            };
            var result = newMod.ShowDialog();

            if (!result.HasValue || !result.Value)
            {
                return;
            }

            // Get unique directory
            string folderPath = Path.Combine(ModDatabase.ModDirectory, SelectedGame.ToString());

            string[] gamePath = Directory.GetDirectories(folderPath, "*", SearchOption.AllDirectories);
            if (FolderComboBox.SelectedItem.ToString() != "All Folders")
            {
                foreach (string folder in gamePath)
                {
                    if (Path.GetFileName(folder) == FolderComboBox.SelectedItem.ToString())
                    {
                        folderPath = folder;
                    }
                }
            }
            string modPath = Path.Combine(folderPath, newMod.ModTitle);

            if (Directory.Exists(modPath))
            {
                var newModPath = modPath;
                int i          = 0;

                while (Directory.Exists(newModPath))
                {
                    newModPath = modPath + "_" + i++;
                }

                modPath = newModPath;
            }

            // Build mod
            var mod = new ModBuilder()
                      .SetGame(SelectedGame)
                      .SetTitle(newMod.ModTitle)
                      .SetDescription(newMod.Description)
                      .SetVersion(newMod.Version)
                      .SetDate(DateTime.UtcNow.ToShortDateString())
                      .SetAuthor(newMod.Author)
                      .SetUrl(newMod.Url)
                      .SetUpdateUrl(newMod.UpdateUrl)
                      .SetBaseDirectoryPath(modPath)
                      .Build();

            // Do actual saving
            var modLoader = new XmlModLoader();

            modLoader.Save(mod);

            // Reload
            RefreshModDatabase();
            RefreshMods();
        }
Ejemplo n.º 8
0
        private Mod LoadModXml(string xmlPath, ModBuilder modBuilder)
        {
            Log.Loader.Trace($"Loading mod xml: {xmlPath}");
            var document = XDocument.Load(xmlPath, LoadOptions.None);
            var rootNode = document.Root;

            if (rootNode == null)
            {
                throw new ModXmlFileInvalidException("Root node is missing");
            }

            bool hasId = false;

            foreach (var element in rootNode.Elements())
            {
                switch (element.Name.LocalName)
                {
                case nameof(Mod.Id):
                    if (Guid.TryParse(element.Value, out var id) && id != Guid.Empty)
                    {
                        modBuilder.SetId(id);
                        hasId = true;
                    }
                    break;

                case nameof(Mod.Game):
                {
                    if (Enum.TryParse <Game>(element.Value, true, out var game))
                    {
                        modBuilder.SetGame(game);
                    }
                    else
                    {
                        throw new ModXmlFileInvalidException($"Invalid game specified: {element.Value}");
                    }
                }
                break;

                case nameof(Mod.Title):
                    modBuilder.SetTitle(element.Value);
                    break;

                case nameof(Mod.Description):
                    modBuilder.SetDescription(element.Value);
                    break;

                case nameof(Mod.Version):
                    modBuilder.SetVersion(element.Value);
                    break;

                case nameof(Mod.Date):
                    modBuilder.SetDate(element.Value);
                    break;

                case nameof(Mod.Author):
                    modBuilder.SetAuthor(element.Value);
                    break;

                case nameof(Mod.Url):
                    modBuilder.SetUrl(element.Value);
                    break;

                case nameof(Mod.UpdateUrl):
                    modBuilder.SetUpdateUrl(element.Value);
                    break;
                }
            }

            var mod = modBuilder.Build();

            if (!hasId)
            {
                // Save xml if GUID is missing
                Log.Loader.Info("Mod GUID is missing. Resaving xml...");
                Save(mod);
            }

            return(mod);
        }