Ejemplo n.º 1
0
        public MyObjectBuilder_Checkpoint.ModItem GetModItem()
        {
            var modItem = new MyObjectBuilder_Checkpoint.ModItem(WorkshopId, "Steam");

            modItem.SetModData(new WorkshopItem(ModLocation));
            return(modItem);
        }
Ejemplo n.º 2
0
        public void SaveConfig()
        {
            var cf = Torch.Config as TorchConfig;

            if (cf?.ReservedPlayers?.Count > 0)
            {
                foreach (var res in cf.ReservedPlayers)
                {
                    if (!DedicatedConfig.Reserved.Contains(res))
                    {
                        DedicatedConfig.Reserved.Add(res);
                    }
                }
            }

            DedicatedConfig.Save(Path.Combine(Torch.Config.InstancePath, CONFIG_NAME));
            Log.Info("Saved dedicated config.");

            try
            {
                var promotedUsers = DedicatedConfig?.SelectedWorld?.Checkpoint?.PromotedUsers;

                var sandboxPath = Path.Combine(DedicatedConfig.LoadWorld, "Sandbox.sbc");
                MyObjectBuilderSerializer.DeserializeXML(sandboxPath, out MyObjectBuilder_Checkpoint checkpoint, out ulong sizeInBytes);
                if (checkpoint == null)
                {
                    Log.Error($"Failed to load {DedicatedConfig.LoadWorld}, checkpoint null ({sizeInBytes} bytes, instance {Torch.Config.InstancePath})");
                    return;
                }

                if (promotedUsers != null)
                {
                    checkpoint.PromotedUsers = promotedUsers;
                }
                checkpoint.SessionName = DedicatedConfig.WorldName;
                checkpoint.Settings    = DedicatedConfig.SessionSettings;
                checkpoint.Mods.Clear();

                foreach (var mod in DedicatedConfig.Mods)
                {
                    var savedMod = new MyObjectBuilder_Checkpoint.ModItem(mod.Name, mod.PublishedFileId, mod.FriendlyName);
                    savedMod.IsDependency = mod.IsDependency;
                    checkpoint.Mods.Add(savedMod);
                }
                Task.Run(() => DedicatedConfig.UpdateAllModInfosAsync());

                MyObjectBuilderSerializer.SerializeXML(sandboxPath, false, checkpoint);

                //MyLocalCache.SaveCheckpoint(checkpoint, DedicatedConfig.LoadWorld);
                Log.Info("Saved world config.");
            }
            catch (Exception e)
            {
                Log.Error("Failed to write sandbox config, changes will not appear on server");
                Log.Error(e);
            }
        }
Ejemplo n.º 3
0
        private static void CheckModDependencies(List <MyObjectBuilder_Checkpoint.ModItem> mods, List <ulong> publishedFileIds)
        {
            List <MyObjectBuilder_Checkpoint.ModItem> resultModList = new List <MyObjectBuilder_Checkpoint.ModItem>();
            HashSet <ulong> rootMods = new HashSet <ulong>();

            foreach (var mod in mods)
            {
                if (mod.IsDependency)
                {
                    continue;
                }

                if (mod.PublishedFileId == 0)
                {
                    resultModList.Add(mod);
                }
                else
                {
                    rootMods.Add(mod.PublishedFileId);
                }
            }

            bool hasReferenceIssue;

            if (MySteam.IsActive)
            {
                MySandboxGame.IsDedicated = true;
                var dependencies = GetModsDependencyHiearchy(rootMods, out hasReferenceIssue);
                MySandboxGame.IsDedicated = false;
                foreach (var depMod in dependencies)
                {
                    bool isDependency = !rootMods.Contains(depMod.Id);

                    var newMod = new MyObjectBuilder_Checkpoint.ModItem(depMod.Id, isDependency);
                    newMod.FriendlyName = depMod.Title;
                    depMod.UpdateState();

                    // Exclude mods that have not been downloaded.
                    if (depMod.Folder != null)
                    {
                        newMod.SetModData(depMod);
                    }

                    resultModList.Add(newMod);
                    if (!publishedFileIds.Contains(depMod.Id))
                    {
                        publishedFileIds.Add(depMod.Id);
                    }
                }
            }

            mods.Clear();
            mods.AddRange(resultModList);
        }
Ejemplo n.º 4
0
        /// <inheritdoc/>
        public bool AddOverrideMod(ulong modId)
        {
            if (_overrideMods.ContainsKey(modId))
            {
                return(false);
            }
            var item = new MyObjectBuilder_Checkpoint.ModItem(modId);

            _overrideMods.Add(modId, item);

            OverrideModsChanged?.Invoke(new CollectionChangeEventArgs(CollectionChangeAction.Add, item));
            return(true);
        }
Ejemplo n.º 5
0
        public void SaveConfig()
        {
            if (((TorchServer)Torch).HasRun)
            {
                Log.Warn("Checkpoint cache is stale, not saving dedicated config.");
                return;
            }

            DedicatedConfig.Save(Path.Combine(Torch.Config.InstancePath, CONFIG_NAME));
            Log.Info("Saved dedicated config.");

            try
            {
                var world = DedicatedConfig.Worlds.FirstOrDefault(x => x.WorldPath == DedicatedConfig.LoadWorld) ?? new WorldViewModel(DedicatedConfig.LoadWorld);

                world.Checkpoint.SessionName      = DedicatedConfig.WorldName;
                world.WorldConfiguration.Settings = DedicatedConfig.SessionSettings;
                world.WorldConfiguration.Mods.Clear();

                foreach (var mod in DedicatedConfig.Mods)
                {
                    var savedMod = new MyObjectBuilder_Checkpoint.ModItem(mod.Name, mod.PublishedFileId, mod.FriendlyName);
                    savedMod.IsDependency = mod.IsDependency;
                    world.WorldConfiguration.Mods.Add(savedMod);
                }
                Task.Run(() => DedicatedConfig.UpdateAllModInfosAsync());

                world.SaveSandbox();

                Log.Info("Saved world config.");
            }
            catch (Exception e)
            {
                Log.Error("Failed to write sandbox config, changes will not appear on server");
                Log.Error(e);
            }
        }
Ejemplo n.º 6
0
 public ModViewModel(MyObjectBuilder_Checkpoint.ModItem item, string description = "")
 {
     ModItem     = item;
     Description = description;
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Constructor, returns a new ModItemInfo instance
 /// </summary>
 /// <param name="mod">The wrapped mod</param>
 public ModItemInfo(MyObjectBuilder_Checkpoint.ModItem mod)
 {
     _modItem = mod;
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Compiles the mod
        /// </summary>
        /// <returns></returns>
        public bool Compile()
        {
            // Compile
            if (m_compile)
            {
                if (m_type == WorkshopType.Mod)
                {
                    if (_compileMethod != null)
                    {
                        MySandboxGame.Log.WriteLineAndConsole("Compiling...");
#if SE
                        var mod = new MyModContext();

                        // Because of a regression in SE, we need to create a checkpoint ModItem to set the Id.
                        var modob = new MyObjectBuilder_Checkpoint.ModItem();
                        modob.Name = Path.GetFileName(m_modPath);

                        if (ModId.Length > 0)
                        {
                            modob.PublishedFileId      = m_workshopItems[m_modId[0]].Id;
                            modob.PublishedServiceName = m_workshopItems[m_modId[0]].ServiceName;
                            modob.FriendlyName         = m_workshopItems[m_modId[0]].Title;
                            modob.SetModData(m_workshopItems[m_modId[0]]);
                        }
                        else
                        {
                            // Fake it, so the compile still works
                            modob.PublishedFileId      = 0;
                            modob.PublishedServiceName = MyGameService.GetDefaultUGC().ServiceName;
                            modob.FriendlyName         = Title;
                        }
                        mod.Init(modob);

                        // Call init again, to make sure the path in set properly to the local mod directory
                        mod.Init(m_title, null, m_modPath);
#else
                        var workshopItem = new MyLocalWorkshopItem(new VRage.ObjectBuilders.SerializableModReference(Path.GetFileName(m_modPath), 0));
                        var mod          = new MyModContext(workshopItem, 0);
#endif
                        _compileMethod(
#if SE
                            m_modPath,
#endif
                            mod
                            );

                        // Process any errors
#if SE
                        var errors = MyDefinitionErrors.GetErrors();
#else
                        var compileMessages = _scriptManager.GetType().GetField("m_messages", BindingFlags.NonPublic | BindingFlags.Instance);
                        var errors          = (compileMessages.GetValue(_scriptManager) as List <MyScriptCompiler.Message>) ?? new List <MyScriptCompiler.Message>();
#endif
                        if (errors.Count > 0)
                        {
                            int errorCount   = 0;
                            int warningCount = 0;

                            // This is not efficient, but I'm lazy
                            foreach (var error in errors)
                            {
                                if (error.Severity >= TErrorSeverity.Error)
                                {
                                    errorCount++;
                                }
                                if (error.Severity == TErrorSeverity.Warning)
                                {
                                    warningCount++;
                                }
                            }

                            if (errorCount > 0)
                            {
                                MySandboxGame.Log.WriteLineAndConsole(string.Format("There are {0} compile errors:", errorCount));
                            }
                            if (warningCount > 0)
                            {
                                MySandboxGame.Log.WriteLineAndConsole(string.Format("There are {0} compile warnings:", warningCount));
                            }

                            // Output raw message, which is usually in msbuild friendly format, for automated tools
                            foreach (var error in errors)
#if SE
                            { System.Console.WriteLine(error.Message); }
#else
                            { System.Console.WriteLine(error.Text); }
#endif

#if SE
                            MyDefinitionErrors.Clear();     // Clear old ones, so next mod starts fresh
#endif

                            if (errorCount > 0)
                            {
                                MySandboxGame.Log.WriteLineAndConsole("Compilation FAILED!");
                                return(false);
                            }
                        }
                        MySandboxGame.Log.WriteLineAndConsole("Compilation successful!");
                    }
                    else
                    {
                        MySandboxGame.Log.WriteLineAndConsole(string.Format(Constants.ERROR_Reflection, "LoadScripts"));
                    }
                }
#if SE
                else if (m_type == WorkshopType.IngameScript)
                {
                    // Load the ingame script from the disk
                    // I don't like this, but meh
                    var input   = new StreamReader(Path.Combine(m_modPath, "Script.cs"));
                    var program = input.ReadToEnd();
                    input.Close();
                    var scripts = new List <Script>();
                    scripts.Add(MyScriptCompiler.Static.GetIngameScript(program, "Program", typeof(Sandbox.ModAPI.Ingame.MyGridProgram).Name, "sealed partial"));

                    var messages = new List <Message>();
                    var assembly = MyVRage.Platform.Scripting.CompileIngameScriptAsync(Path.Combine(VRage.FileSystem.MyFileSystem.UserDataPath, "SEWT-Script" + Path.GetFileName(m_modPath)), program, out messages, "SEWT Compiled PB Script", "Program", typeof(Sandbox.ModAPI.Ingame.MyGridProgram).Name).Result;

                    if (messages.Count > 0)
                    {
                        MySandboxGame.Log.WriteLineAndConsole(string.Format("There are {0} compile messages:", messages.Count));
                        int errors = 0;
                        foreach (var msg in messages)
                        {
                            MySandboxGame.Log.WriteLineAndConsole(msg.Text);

                            if (msg.IsError)
                            {
                                errors++;
                            }
                        }
                        if (errors > 0)
                        {
                            return(false);
                        }
                    }

                    if (assembly == null)
                    {
                        return(false);
                    }
                }
#endif
                return(true);
            }
            return(true);
        }
Ejemplo n.º 9
0
        private void AddMod(bool active, StringBuilder title, StringBuilder toolTip, StringBuilder modState, MyGuiHighlightTexture?icon, MyObjectBuilder_Checkpoint.ModItem mod, Color?textColor = null)
        {
            var row = new MyGuiControlTable.Row(mod);

            row.AddCell(new MyGuiControlTable.Cell(text: String.Empty, toolTip: modState.ToString(), icon: icon));
            row.AddCell(new MyGuiControlTable.Cell(text: title, toolTip: toolTip.ToString(), textColor: textColor));

            if (active)
            {
                m_modsTableEnabled.Insert(0, row);
            }
            else
            {
                m_modsTableDisabled.Insert(0, row);
            }
        }
Ejemplo n.º 10
0
 public void Init(MyObjectBuilder_Checkpoint.ModItem modItem)
 {
     ModName     = modItem.FriendlyName;
     ModPath     = Path.Combine(MyFileSystem.ModsPath, modItem.Name);
     ModPathData = Path.Combine(ModPath, "Data");
 }