Exemplo n.º 1
0
 public static SObject PullModItemFromDict(Int32 id, bool isIndex)
 {
     if (isIndex)
     {
         if (ModItems.ElementAtOrDefault(id).Value != null)
         {
             return(ModItems.ElementAt(id).Value.Clone());
         }
         else
         {
             Program.LogError("ModItem Dictionary does not contain index: " + id);
             return(null);
         }
     }
     else
     {
         if (ModItems.ContainsKey(id))
         {
             return(ModItems[id].Clone());
         }
         else
         {
             Program.LogError("ModItem Dictionary does not contain ID: " + id);
             return(null);
         }
     }
 }
Exemplo n.º 2
0
        public OptionsPanel(System.Collections.ObjectModel.ObservableCollection <LauncherOptionItem> OptionsList)
        {
            InitializeComponent();
            List <string> ShaderOption = new List <string>()
            {
                string.Empty
            }
            .Union(Directory.GetFiles(@"..\Shaders", "*.glsl", SearchOption.AllDirectories))
            .Select(dr => dr.TrimStart('.', '\\'))
            .ToList();

            ShaderOption.ForEach(dr =>
            {
                Ddraw_ddraw_shader.Items.Add(dr);
            });

            parser = new IniDataParser();
            ReadIniTactics();
            ReadIniDdraw();

            Binding binding1 = new Binding();

            binding1.Source = OptionsList;
            ModItems.SetBinding(ItemsControl.ItemsSourceProperty, binding1);

            loading = false;
        }
        private void Specific_Mod_Remove_Click(object sender, RoutedEventArgs e)
        {
            var tag     = ((Button)sender).Tag.ToString();
            var modItem = ModItems.First(p => p.UUID == tag);

            if (RemoveModWindow == null)
            {
                return;
            }

            RemoveModWindow.SetModTitle(modItem.Title);
            RemoveModWindow.RemovedMod = () =>
            {
                var deleted = Shrek2MM.DeleteModFromDataFolder(modItem.FileName);

                if (deleted == false)
                {
                    MessageBox.Show("Failed to delete the mod file/zip from Data folder, this can be becaues of read/write permissions. You can delete this file yourself if you go to 'Your PC/My Documents/Shrek 2 Mod Manager/Added mods'.");
                }

                ModItems.Remove(modItem);
                var saved = Shrek2MM.SaveMods(ModItems.ToList());
                if (saved == false)
                {
                    MessageBox.Show("Failed to update mod list, this can be becaues of read/write permissions.");
                }
            };

            DialogHost.Show(RemoveModWindow.Content);
        }
        private void Specific_Mod_Settings_Click(object sender, RoutedEventArgs e)
        {
            var tag     = ((Button)sender).Tag.ToString();
            var modItem = ModItems.First(p => p.UUID == tag);

            if (EditModWindow == null)
            {
                return;
            }

            EditModWindow.InitEditMod(modItem);
            EditModWindow.EditedMod = (updatedMod) =>
            {
                if (updatedMod == null)
                {
                    return;
                }

                var modItemsList = ModItems.ToList();

                var index = modItemsList.FindIndex(p => p.UUID == updatedMod.UUID);
                modItemsList[index] = updatedMod;

                var saved = Shrek2MM.SaveMods(modItemsList);
                if (saved == false)
                {
                    MessageBox.Show("Failed to update mod list, this can be becaues of read/write permissions.");
                }

                ModItems.Clear();
                modItemsList.ForEach(mod => ModItems.Add(mod));
            };

            DialogHost.Show(EditModWindow.Content);
        }
Exemplo n.º 5
0
        public ModsViewModel(IScreen screen, DowModLoader?dowModService = null) : base(screen, "mods")
        {
            this.logger        = this.Log();
            this.dowModService = dowModService ?? Locator.Current.GetService <DowModLoader>();

            var whenNotLoading = this.WhenAnyValue(x => x.Loading).Select(loading => !loading).DistinctUntilChanged();

            var whenItemSelected = this.WhenAnyValue(x => x.SelectedBaseItem, x => x.SelectedModItem,
                                                     (baseItem, modItem) => baseItem != null || modItem != null).DistinctUntilChanged();

            var canLoadSpecific = whenNotLoading.CombineLatest(whenItemSelected, (notLoading, itemSelected) => notLoading && itemSelected).DistinctUntilChanged();

            ReloadMods = ReactiveCommand.CreateFromTask(LoadAllMods, whenNotLoading);

            RefreshMods = ReactiveCommand.CreateFromTask(GetModsAsync);
            RefreshMods.ThrownExceptions.Subscribe(exception => logger.Error(exception));
            RefreshMods.Execute().Subscribe();

            RefreshMods.Select(mods => mods.Where(x => !x.Module.File.IsVanilla))
            .Subscribe(mods =>
            {
                ModItems.Clear();
                ModItems.AddRange(mods);
            });

            RefreshMods.Select(mods => mods.Where(x => x.Module.File.IsVanilla))
            .Subscribe(mods =>
            {
                BaseGameItems.Clear();
                BaseGameItems.AddRange(mods);
            });
        }
        private void Play_Mods_Click(object sender, RoutedEventArgs e)
        {
            var settings = Shrek2MM.LoadSettings();

            if (settings == null || string.IsNullOrWhiteSpace(settings.GameFolderPath))
            {
                MessageBox.Show("Unable to 'Play' yet as you have not set up Settings correctly yet. Please ensure your Game Folder is selected before proceeding!");
                return;
            }

            if (ModItems == null || ModItems.Count <= 0)
            {
                MessageBox.Show("You currently have no added mods in the Shrek 2 Mod Manager so you cannot 'Play' yet.");
                return;
            }

            if (ModItems.Any(p => p.IsActive) == false)
            {
                MessageBox.Show("You have no Enabled Mods in the Shrek 2 Mod Manager. Ensure atleast 1 mod is enabled before proceeding.");
                return;
            }

            var installed = Shrek2MM.InstallModLoader(settings.GameFolderPath);

            if (installed == false)
            {
                MessageBox.Show("Failed to install Mod Loader into the selected Game Folder you chose in Settings. This could be a Read/write Permission issue. Check the error_log in 'Documents/Shrek 2 Mod Manager' for more details.");
                return;
            }

            if (Shrek2MM.ReinstallMods(settings.GameFolderPath, ModItems.Where(p => p.IsActive).ToList()) == false)
            {
                MessageBox.Show("Failed to install the enabled mods. This could be a Read/write Permission issue. Check the error_log in 'Documents/Shrek 2 Mod Manager' for more details.");
                return;
            }

            if (Shrek2MM.UpdateDefUserFile(settings.GameFolderPath, ModItems.Where(p => p.IsActive).ToList()) == false)
            {
                MessageBox.Show("Failed to update DefUser.ini file, this could be a Read/write Permission issue. Check the error_log in 'Documents/Shrek 2 Mod Manager' for more details.");
                return;
            }



            GameProcess = Process.Start(Shrek2Utils.GetModdedGameExeFilePath(settings.GameFolderPath), settings.DisplayMode == 0 ? "-windowed" : "");
            GameProcess.EnableRaisingEvents = true;

            Play_Button.IsEnabled = false;
            Play_Button.Content   = "Running";

            GameProcess.Exited += (sender, e) =>
            {
                Dispatcher.Invoke(() =>
                {
                    Play_Button.IsEnabled = true;
                    Play_Button.Content   = "Play";
                });
            };
        }
        private void Specific_Mod_ToggleIsActive_Click(object sender, RoutedEventArgs e)
        {
            var tag     = ((CheckBox)sender).Tag.ToString();
            var modItem = ModItems.First(p => p.UUID == tag);

            var saved = Shrek2MM.SaveMods(ModItems.ToList());

            if (saved == false)
            {
                MessageBox.Show("Failed to update mod list, this can be becaues of read/write permissions.");
            }
        }
        private async void Window_Initialized(object sender, EventArgs e)
        {
            RemoveModWindow = new RemoveModWindow
            {
                CloseModal = () =>
                {
                    DialogHost.Close(null);
                }
            };

            EditModWindow = new EditModWindow
            {
                CloseModal = () =>
                {
                    DialogHost.Close(null);
                }
            };

            SettingsWindow = new SettingsWindow
            {
                CloseModal = () =>
                {
                    DialogHost.Close(null);
                }
            };

            var mods = Shrek2MM.LoadMods();

            if (mods == null)
            {
                MessageBox.Show("Failed to load Added Mods correctly, this might indicate that the JSON file is corrupted or damaged! Please close this application and ensure the JSON file isn't damaged in any way before proceeding.");
                Add_Mod_Button.IsEnabled = false;
                Play_Button.IsEnabled    = false;
                ModItemsList.ItemsSource = ModItems;
                return;
            }

            var extractedModLoader = await Shrek2MM.ExtractModLoader();

            if (extractedModLoader == false)
            {
                MessageBox.Show("Couldn't extract the Mod Loader which is embedded in the Shrek 2 Mod Manager Program. Please check that the program has permissions to read/write on disk, and if the issue still persists please contact the developer.");
                Add_Mod_Button.IsEnabled = false;
                Play_Button.IsEnabled    = false;
                ModItemsList.ItemsSource = ModItems;
                return;
            }

            mods.ForEach(mod => ModItems.Add(mod));

            ModItemsList.ItemsSource = ModItems;
        }
Exemplo n.º 9
0
        public static SKSurface BuildImage(Lang lang, out SKRectI rect)
        {
            int x = itemMargin, y = 0;
            var surface = SKSurface.Create(new SKImageInfo(canvasMaxWidth, canvasMaxHeight));
            var canvas  = surface.Canvas;

            foreach (var groupItems in ModItems.GroupBy(x => x.metaType))
            {
                // Draw Label

                #region Draw Label

                var metaType = groupItems.First().metaType;
                x = 0;
                if (y != 0)
                {
                    y += itemHeight + itemMargin + 1;
                }
                DrawLabel(canvas, metaType, lang, SKRect.Create(x, y, canvasMaxWidth, labelHeight));
                x  = itemMargin;
                y += labelHeight + itemMargin * 2;

                #endregion Draw Label

                foreach (var item in groupItems.OrderBy(x => x.name.GetText(Lang.Default)).OrderBy(x => x.order))
                {
                    #region Move Y if needed

                    if ((x + itemWidth + itemMargin) > canvasMaxWidth)
                    {
                        x  = itemMargin;
                        y += itemHeight + itemMargin + 1;
                    }

                    #endregion Move Y if needed

                    var itemRect = new SKRect(x, y, x + itemWidth, y + itemHeight);
                    DrawItem(canvas, item, lang, itemRect);

                    #region Move X

                    x += itemWidth + itemMargin + 1;

                    #endregion Move X
                }
            }
            rect = new SKRectI(0, 0, canvasMaxWidth, y + itemHeight + itemMargin);
            return(surface);
        }
        private void Add_Mod_Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                OpenFileDialog ofd = new()
                {
                    Filter = "Shrek 2 Mod File (.dll)|*.dll|Shrek 2 Mod Zip (.zip)|*.zip"
                };
                ofd.ShowDialog();

                if (string.IsNullOrEmpty(ofd.FileName))
                {
                    return;
                }

                var modTitle  = System.IO.Path.GetFileNameWithoutExtension(ofd.FileName);
                var fileName  = System.IO.Path.GetFileName(ofd.FileName);
                var extension = System.IO.Path.GetExtension(ofd.FileName);
                var uuid      = Guid.NewGuid().ToString();

                var copied = Shrek2MM.CopyModToDataFolder(ofd.FileName, uuid);

                if (copied == false)
                {
                    MessageBox.Show("Couldn't add the selected mod. Please check that the program has permissions to read/write on disk, and if the issue still persists please contact the developer.");
                    return;
                }

                ModItems.Add(new Shrek2ModListItem(
                                 modTitle,
                                 extension == ".dll" ? Shrek2ModListItem.ModTypes.ModFile : Shrek2ModListItem.ModTypes.ModZip,
                                 true,
                                 uuid
                                 ));

                if (Shrek2MM.SaveMods(ModItems.ToList()) == false)
                {
                    MessageBox.Show("Failed to save the selected mod you wanted to add. We correctly copied the mod data but we couldn't save the metadata. Please check that the program has permissions to read/write on disk, and if the issue still persists please contact the developer.");
                    return;
                }
            }
            catch (Exception ex)
            {
                Shrek2Utils.LogError(ex);
                MessageBox.Show("Error occured when trying to add a mod. For more details check the Error Log in 'This PC/My Documents/Shrek 2 Mod Manager'.");
            }
        }
Exemplo n.º 11
0
        public static Int32 RegisterModItem(SObject modItem)
        {
            if (modItem.HasBeenRegistered)
            {
                Program.LogError("The item {0} has already been registered with ID {1}", modItem.Name, modItem.RegisteredId);
                return(modItem.RegisteredId);
            }
            Int32 newId = LowestModItemID;

            if (ModItems.Count > 0)
            {
                newId = Math.Max(LowestModItemID, ModItems.OrderBy(x => x.Key).First().Key + 1);
            }
            ModItems.Add(newId, modItem);
            modItem.HasBeenRegistered = true;
            modItem.RegisteredId      = newId;
            return(newId);
        }
Exemplo n.º 12
0
 // ReSharper disable once UnusedMember.Local
 private static SObject PullModItemFromDict(int id, bool isIndex)
 {
     if (isIndex)
     {
         if (ModItems.ElementAtOrDefault(id).Value != null)
         {
             return(ModItems.ElementAt(id).Value.Clone());
         }
         Log.AsyncR("ModItem Dictionary does not contain index: " + id);
         return(null);
     }
     if (ModItems.ContainsKey(id))
     {
         return(ModItems[id].Clone());
     }
     Log.AsyncR("ModItem Dictionary does not contain ID: " + id);
     return(null);
 }
Exemplo n.º 13
0
        // ReSharper disable once UnusedMember.Local
        private static int RegisterModItem(SObject modItem)
        {
            if (modItem.HasBeenRegistered)
            {
                Log.AsyncR($"The item {modItem.Name} has already been registered with ID {modItem.RegisteredId}");
                return(modItem.RegisteredId);
            }
            var newId = LowestModItemID;

            if (ModItems.Count > 0)
            {
                newId = Math.Max(LowestModItemID, ModItems.OrderBy(x => x.Key).First().Key + 1);
            }
            ModItems.Add(newId, modItem);
            modItem.HasBeenRegistered = true;
            modItem.RegisteredId      = newId;
            return(newId);
        }
Exemplo n.º 14
0
        public void LoadYamlCode(List <ModClass> modClassParent, TreeViewItem modCTIParent = null, TreeView rootModCTIParent = null)
        {
            for (int i = 0; i < modClassParent.Count; i++)
            {
                if (modClassParent[i].type == Type.variable)
                {
                    string op;
                    if (modClassParent[i].op == ">")
                    {
                        op = ">";
                    }
                    else if (modClassParent[i].op == "<")
                    {
                        op = "<";
                    }
                    else if (modClassParent[i].op == "=")
                    {
                        op = "=";
                    }
                    else
                    {
                        op = " ";
                    }

                    TreeViewItem tviChild;

                    if (string.IsNullOrWhiteSpace(op))
                    {
                        //空
                        tviChild = mainWindow.SetModTreeViewItem("Resources/Images/FX.png", string.Format("{0} {1} {2}", modClassParent[i].name, op, modClassParent[i].val));
                        ModItems modItemsChild = new ModItems();
                        modItemsChild.ViewItem = tviChild;
                        modItemsChild.Level    = modClassParent[i].level;
                        modItemsChild.Id       = modClassParent[i].id;
                        modItemsChild.Type     = modClassParent[i].type;
                        modItemsChild.Name     = modClassParent[i].name;
                        modItemsChild.Op       = modClassParent[i].op;
                        modItemsChild.Val      = modClassParent[i].val;
                        modItemsParent.Add(modItemsChild);
                    }
                    else
                    {
                        tviChild = mainWindow.SetModTreeViewItem("Resources/Images/FX.png", string.Format("{0} {1} {2}", modClassParent[i].name, op, modClassParent[i].val));
                        ModItems modItemsChild = new ModItems();
                        modItemsChild.ViewItem = tviChild;
                        modItemsChild.Level    = modClassParent[i].level;
                        modItemsChild.Id       = modClassParent[i].id;
                        modItemsChild.Type     = modClassParent[i].type;
                        modItemsChild.Name     = modClassParent[i].name;
                        modItemsChild.Op       = modClassParent[i].op;
                        modItemsChild.Val      = modClassParent[i].val;
                        modItemsParent.Add(modItemsChild);
                    }

                    if (modCTIParent == null)
                    {
                        rootModCTIParent.Items.Add(tviChild);
                        tviChild.IsExpanded = true;
                    }
                    else
                    {
                        modCTIParent.Items.Add(tviChild);
                    }
                }
                else if (modClassParent[i].type == Type.function)
                {
                    TreeViewItem tviChild      = mainWindow.SetModTreeViewItem("Resources/Images/Trigger.png", string.Format("{0}", modClassParent[i].name));
                    ModItems     modItemsChild = new ModItems();
                    modItemsChild.ViewItem = tviChild;
                    modItemsChild.Level    = modClassParent[i].level;
                    modItemsChild.Id       = modClassParent[i].id;
                    modItemsChild.Type     = modClassParent[i].type;
                    modItemsChild.Name     = modClassParent[i].name;
                    modItemsChild.Op       = modClassParent[i].op;
                    modItemsChild.Val      = modClassParent[i].val;
                    modItemsParent.Add(modItemsChild);

                    if (modCTIParent == null)
                    {
                        rootModCTIParent.Items.Add(tviChild);
                        tviChild.IsExpanded = true;
                    }
                    else
                    {
                        modCTIParent.Items.Add(tviChild);
                    }

                    LoadYamlCode(modClassParent[i].child, tviChild);
                }
            }
        }
Exemplo n.º 15
0
 private void Author_Sort_PreviewMouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
 {
     lvMods.ItemsSource = new ObservableCollection <ModItem>(ModItems.OrderBy(s => s.Author));
 }
Exemplo n.º 16
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     ModItems.Clear();
     lvMods.ItemsSource = AddModsToList(@"D:\Steam\steamapps\common\Discord Bot Maker\actions").OrderBy(x => x.Section);
 }