Example #1
0
        public override void Unload()
        {
            ModUtils.DebugText("MobSpawner Unload False");

            _spawnWindow.Loaded = false;
        }
Example #2
0
 public static void LoadSaveData(Action <SaveData> onSuccess)
 {
     ModUtils.LoadSaveData <SaveData>(SaveDataFilename, onSuccess);
 }
Example #3
0
        private async Task <bool> InstallRemoteMod()
        {
            var mod          = this.SelectedRemoteRelease;
            var modDirectory = ModUtils.GetModDirectory(mod.Manifest);

            try
            {
                if (NotifyBackgroundTaskRunning(true) == false)
                {
                    throw new Exception("Mod fetching is currently in progress");
                }

                try
                {
                    this.ProgressText.Text = "Clearing mod directory";

                    var prevInstallationIndex = this.Config.KnownMods.FindIndex(x => x.Guid == this.SelectedRemoteRelease.Manifest.Guid);

                    ModInfo prevModInfo = null;
                    if (prevInstallationIndex >= 0)
                    {
                        prevModInfo = this.Config.KnownMods[prevInstallationIndex];
                        this.Config.KnownMods.RemoveAt(prevInstallationIndex);
                    }

                    await Task.Run(() =>
                    {
                        if (Directory.Exists(modDirectory))
                        {
                            Directory.Delete(modDirectory, true);
                        }

                        Directory.CreateDirectory(modDirectory);
                    });


                    this.ProgressText.Text = "Downloading package";
                    var package = this.SelectedRemoteRelease.Assets.First(x => x.ContentType == PackageTypeZip);
                    await DownloadModPackageAsync(package.BrowserDownloadUrl, modDirectory);

                    this.ProgressText.Text = "Verifying package integrity";
                    var modInfo = await Task.Run(() =>
                    {
                        var manifestPath = ModUtils.GetManifestPath(modDirectory);
                        var manifest     = XML.Deserialize <ModManifest>(manifestPath);

                        var expectedManifest = this.SelectedRemoteRelease.Manifest;
                        if (manifest.Guid != expectedManifest.Guid)
                        {
                            throw new Exception("Mod guid doesn't match");
                        }

                        return(ModUtils.BuildModInfoFromManifest(manifest, prevModInfo?.Active ?? false));
                    });

                    if (prevInstallationIndex >= 0)
                    {
                        this.Config.KnownMods.Insert(prevInstallationIndex, modInfo);
                    }
                    else
                    {
                        this.Config.KnownMods.Add(modInfo);
                    }
                }
                finally
                {
                    //Kill any running queries
                    this.RemoteUrlIndex++;
                    NotifyBackgroundTaskRunning(false);
                }
            }
            catch (Exception e)
            {
                this.ModDescriptionText.Text = e.Message;
                return(false);
            }

            return(true);
        }
Example #4
0
 /// <summary>
 /// Checks whether a given <see cref="Mod"/> is valid for global selection.
 /// </summary>
 /// <param name="mod">The <see cref="Mod"/> to check.</param>
 /// <returns>Whether <paramref name="mod"/> is a valid mod for online play.</returns>
 protected virtual bool IsValidMod(Mod mod) => mod.HasImplementation && ModUtils.FlattenMod(mod).All(m => m.UserPlayable);
 private string GetSaveDataDir()
 {
     return(Path.Combine(ModUtils.GetSaveDataDirectory(), "CustomBeacons"));
 }
Example #6
0
        public void TestAllowedThroughMostDerivedType()
        {
            var mod = new Mock <CustomMod1>();

            Assert.That(ModUtils.CheckAllowed(new[] { mod.Object }, new[] { mod.Object.GetType() }));
        }
Example #7
0
        public void TestModIsCompatibleByItself()
        {
            var mod = new Mock <CustomMod1>();

            Assert.That(ModUtils.CheckCompatibleSet(new[] { mod.Object }));
        }
Example #8
0
        public static void LoadSetting(string settingName)
        {
            ModUtils.DebugText("LoadSetting");
            Directory.CreateDirectory(Main.SavePath);
            string path = string.Concat(new object[]
            {
                Main.SavePath,
                Path.DirectorySeparatorChar,
                settingName,
                ".json"
            });

            if (File.Exists(path))
            {
                ModUtils.DebugText("LoadSetting File Exists");
                using (StreamReader r = new StreamReader(path))
                {
                    string json = r.ReadToEnd();
                    database = JsonConvert.DeserializeObject <HEROsModDatabase>(json);
                }
            }
            else
            {
                ModUtils.DebugText("LoadSetting File Doesn't Exist");
            }
            if (database == null)
            {
                ModUtils.DebugText("Warning: Database null in LoadSetting");
                database = new HEROsModDatabase();
            }
            if (database.players == null)
            {
                ModUtils.DebugText("Warning: Database players null in LoadSetting");
                database.players = new List <DatabasePlayer>();
            }
            if (database.worlds == null)
            {
                ModUtils.DebugText("Warning: Database worlds null in LoadSetting");
                database.worlds = new List <DatabaseWorld>();
            }
            //foreach (var world in database.worlds)
            //{
            //	if(world.worldID == Main.worldID)
            //	{
            //		currentDatabaseWorld = world;
            //	}
            //}
            //if(currentDatabaseWorld == null)
            //{
            //	currentDatabaseWorld = new DatabaseWorld() { worldID = Main.worldID };
            //}
            //if (database.regions == null)
            //{
            //	ModUtils.DebugText("Warning: Database regions null in LoadSetting");
            //	database.regions = new List<DatabaseRegion>();
            //}
            if (database.groups == null)
            {
                ModUtils.DebugText("Warning: Database groups null in LoadSetting");
                database.groups = new List <DatabaseGroup>();
            }
            //Console.WriteLine("LoadSetting End");
            //if (Main.netMode != (int)NetworkMode.Server)
            //{
            //	database.groups.Clear();
            //	database.players.Clear();
            //}
        }
Example #9
0
    public void Test_Round_NegitiveDigits()
    {
        float value_2 = 9.9998f;

        ModUtils.Round(value_2, -2);
    }
        public void OnProtoDeserialize(ProtobufSerializer serializer)
        {
            var saveDataFile = GetSaveDataPath();

            ModUtils.LoadSaveData <PingInstanceSaveData>(saveDataFile, OnLoadSaveData);
        }
Example #11
0
 /// <summary>
 /// Checks whether a given <see cref="Mod"/> is valid for global selection.
 /// </summary>
 /// <param name="mod">The <see cref="Mod"/> to check.</param>
 /// <returns>Whether <paramref name="mod"/> is a valid mod for online play.</returns>
 protected virtual bool IsValidMod(Mod mod) => mod.HasImplementation && !ModUtils.FlattenMod(mod).Any(m => m is ModAutoplay);
        private void CreateMod(object sender, RoutedEventArgs e)
        {
            this.ModNameBox.BorderBrush = this.DefaultBorderBrush;
            this.ModGUIDBox.BorderBrush = this.DefaultBorderBrush;

            var modName = this.ModNameBox.Text;

            if (string.IsNullOrEmpty(modName))
            {
                this.ModNameBox.BorderBrush = Brushes.Red;
                return;
            }

            Guid guid;
            var  guidString = this.ModGUIDBox.Text;

            if (string.IsNullOrEmpty(guidString))
            {
                guid = Guid.NewGuid();
            }
            else
            {
                if (Guid.TryParse(guidString, out guid) == false)
                {
                    this.ModGUIDBox.BorderBrush = Brushes.Red;
                    return;
                }
            }

            var modInfo = new ModInfo
            {
                Guid        = guid,
                Active      = true,
                DisplayName = modName
            };

            var modPath         = ModUtils.GetModDirectory(modInfo);
            var modTemplatePath = Path.Combine(PatchZoneCore.PatchZoneInstallationPath, ModTemplatePath);

            CopyDirectory(modTemplatePath, modPath);

            bool makeNextUpper  = false;
            var  escapedModName = new StringBuilder();

            foreach (char x in modName)
            {
                var toUpper = makeNextUpper;
                makeNextUpper = false;

                if (char.IsNumber(x))
                {
                    escapedModName.Append(x);
                }
                else if ('a' <= x && x <= 'z')
                {
                    escapedModName.Append(toUpper ? char.ToUpper(x) : x);
                }
                else if ('A' <= x && x <= 'Z')
                {
                    escapedModName.Append(x);
                }
                else if (char.IsWhiteSpace(x) || toUpper)
                {
                    makeNextUpper = true;
                }
            }

            if (escapedModName.Length == 0)
            {
                escapedModName.Append("PatchZoneMod");
            }

            var gameRoot = PatchZoneCore.GameInstallationPath;

            if (gameRoot[gameRoot.Length - 1] != Path.DirectorySeparatorChar)
            {
                gameRoot += Path.DirectorySeparatorChar;
            }

            FixupNewModInfo(modPath, new Dictionary <string, string>
            {
                { "___GAME_ROOT___", gameRoot },
                { "___MOD_NAME_FULL___", modName },
                { "___MOD_GUID___", guid.ToString() },
                { "___MOD_NAME___", escapedModName.ToString() },
            });

            this.Config.KnownMods.Add(modInfo);

            if (this.StartVSBox.IsChecked ?? false)
            {
                try
                {
                    var solutionFiles = Directory.EnumerateFiles(modPath, "*.sln", SearchOption.TopDirectoryOnly);
                    Process.Start(solutionFiles.First());
                }
                catch
                { }
            }

            this.Close();
        }
Example #13
0
 public static void Init()
 {
     BaseInitializer.Init(nameof(OxygenPlant), typeof(Initializer).Assembly);
     ModUtils.LogDebug("Loaded " + nameof(OxygenPlant), false);
 }
Example #14
0
        private static void ConfigureDegradeOnUse(ModToolComponent modToolComponent)
        {
            DegradeOnUse degradeOnUse = ModUtils.GetOrCreateComponent <DegradeOnUse>(modToolComponent);

            degradeOnUse.m_DegradeHP = Mathf.Max(degradeOnUse.m_DegradeHP, modToolComponent.DegradeOnUse);
        }
Example #15
0
 /// <summary>
 ///  Gens css file
 /// </summary>
 private static void GenCSS()
 {
     ModUtils.WriteToFile(DOC_PATH + "css.css", DocTemplates.cssfile);
 }
Example #16
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            int unixTimestamp = (int)value;

            return(ModUtils.UnixTimeStampToDateTime(unixTimestamp).ToString());
        }
Example #17
0
 public static void Init()
 {
     BaseInitializer.Init(nameof(BetterChunks), typeof(Initializer).Assembly);
     ModUtils.LogDebug("Loaded " + nameof(BetterChunks), false);
 }
Example #18
0
 private static void LoadConfig()
 {
     config = ModUtils.LoadConfig <Config>(GetModPath() + "/config.json");
     ValidateConfig();
 }
Example #19
0
        public void TestNotAllowedThroughBaseType()
        {
            var mod = new Mock <CustomMod1>();

            Assert.That(ModUtils.CheckAllowed(new[] { mod.Object }, new[] { typeof(Mod) }), Is.False);
        }
Example #20
0
 private void updateIncompatibility()
 {
     incompatible.Value = selectedMods.Value.Count > 0 &&
                          selectedMods.Value.All(selected => selected.GetType() != Mod.GetType()) &&
                          !ModUtils.CheckCompatibleSet(selectedMods.Value.Append(Mod));
 }
 public void OnPrimaryAction()
 {
     ModUtils.PlayAudio("Play_UseRubberDuck");
 }
Example #22
0
        public override void Draw(SpriteBatch spriteBatch)
        {
            if (focused)
            {
                Terraria.GameInput.PlayerInput.WritingText = true;
                Main.instance.HandleIME();
                string oldText = Text;
                Text = Main.GetInputText(Text);
                if (oldText != Text)
                {
                    KeyPressed?.Invoke(this, ' ');
                }
                if (Main.keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Tab) && !Main.oldInputText.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Tab))
                {
                    OnTabPress?.Invoke(this, new EventArgs());
                }
                if (Main.keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Enter) && !Main.oldInputText.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Enter))
                {
                    OnEnterPress?.Invoke(this, new EventArgs());
                }
                spriteBatch.End();
                spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, null, Main.UIScaleMatrix);
                Main.instance.DrawWindowsIMEPanel(new Vector2(98f, (float)(Main.screenHeight - 36)), 0f);
            }

            spriteBatch.Draw(textboxBackground, DrawPosition, null, Color.White, 0f, Origin, 1f, SpriteEffects.None, 0f);
            int     fillWidth = (int)Width - 2 * textboxBackground.Width;
            Vector2 pos       = DrawPosition;

            pos.X += textboxBackground.Width;
            spriteBatch.Draw(TextboxFill, pos - Origin, null, Color.White, 0f, Vector2.Zero, new Vector2(fillWidth, 1f), SpriteEffects.None, 0f);
            pos.X += fillWidth;
            spriteBatch.Draw(textboxBackground, pos, null, Color.White, 0f, Origin, 1f, SpriteEffects.FlipHorizontally, 0f);
            string drawString = Text;

            if (PasswordBox)
            {
                drawString = passwordString;
            }
            if (drawCarrot && focused)
            {
                drawString += "|";
            }
            label.Text = drawString;

            pos = DrawPosition - Origin;

            if (pos.X <= Main.screenWidth && pos.Y <= Main.screenHeight && pos.X + Width >= 0 && pos.Y + Height >= 0)
            {
                spriteBatch.End();
                spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, _rasterizerState, null, Main.UIScaleMatrix);

                Rectangle cutRect = new Rectangle((int)pos.X, (int)pos.Y, (int)Width, (int)Height);

                /*if (cutRect.X < 0)
                 * {
                 *      cutRect.Width += cutRect.X;
                 *      cutRect.X = 0;
                 * }
                 * if (cutRect.Y < 0)
                 * {
                 *      cutRect.Height += cutRect.Y;
                 *      cutRect.Y = 0;
                 * }
                 * if (cutRect.X + Width > Main.screenWidth) cutRect.Width = Main.screenWidth - cutRect.X;
                 * if (cutRect.Y + Height > Main.screenHeight) cutRect.Height = Main.screenHeight - cutRect.Y;*/
                cutRect = ModUtils.GetClippingRectangle(spriteBatch, cutRect);

                Rectangle currentRect = spriteBatch.GraphicsDevice.ScissorRectangle;
                spriteBatch.GraphicsDevice.ScissorRectangle = cutRect;

                base.Draw(spriteBatch);

                spriteBatch.GraphicsDevice.ScissorRectangle = currentRect;
                spriteBatch.End();
                spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied, null, null, null, null, Main.UIScaleMatrix);
            }
        }
Example #23
0
 private bool checkCompatibleFreeMod(Mod mod)
 => Mods.Value.All(m => m.Acronym != mod.Acronym) &&  // Mod must not be contained in the required mods.
 ModUtils.CheckCompatibleSet(Mods.Value.Append(mod).ToArray());           // Mod must be compatible with all the required mods.
        internal static void Postfix(CookingPotItem __instance)
        {
            Water.AdjustWaterToWaterSupply();

            ModUtils.GetOrCreateComponent <OverrideCookingState>(__instance).ForceReady = false;
        }
Example #25
0
 public static void Save(SaveData newSaveData)
 {
     ModUtils.Save <SaveData>(newSaveData, SaveDataFilename);
 }
 internal static void Postfix(CookingPotItem __instance)
 {
     ModUtils.GetOrCreateComponent <OverrideCookingState>(__instance).ForceReady = false;
 }
Example #27
0
        private async void SaveMods_Click(object sender, RoutedEventArgs e)
        {
            var cursor = this.Cursor;

            try
            {
                Application.Current.Dispatcher.Invoke(() => this.Cursor = System.Windows.Input.Cursors.Wait);
                await Task.Delay(500);

                string mapString;
                string totalConversionString;
                string modIdString;

                // check if there are any unknown mod types.
                if (ModDetails.AnyUnknownModTypes)
                {
                    if (MessageBox.Show(_globalizer.GetResourceString("ModDetails_Save_UnknownLabel"), _globalizer.GetResourceString("ModDetails_Save_UnknownTitle"), MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
                    {
                        return;
                    }
                }

                if (ModDetails.GetModStrings(out mapString, out totalConversionString, out modIdString))
                {
                    if (mapString != null)
                    {
                        _profile.ServerMap = mapString;
                    }
                    else if (_profile.ServerMap.Contains('/'))
                    {
                        _profile.ServerMap = string.Empty;
                    }

                    // check if a total conversion mod was found in the mod list
                    if (string.IsNullOrWhiteSpace(totalConversionString))
                    {
                        // total conversion mod not found, was it previously set to an official mod?
                        if (!ModUtils.IsOfficialMod(_profile.TotalConversionModId))
                        {
                            // total conversion was not previoulsly set to an official mod, clear total conversion mod id
                            _profile.TotalConversionModId = string.Empty;
                        }
                    }
                    else
                    {
                        // total conversion mod found, set the found mod id
                        _profile.TotalConversionModId = totalConversionString;
                    }
                    _profile.ServerModIds = modIdString ?? string.Empty;
                }

                await LoadModsFromProfile();

                OnSavePerformed();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, _globalizer.GetResourceString("ModDetails_Save_FailedTitle"), MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                Application.Current.Dispatcher.Invoke(() => this.Cursor = cursor);
            }
        }
Example #28
0
 public int GetHashCode(KeyValuePair <string, object> obj) => HashCode.Combine(obj.Key, ModUtils.GetSettingUnderlyingValue(obj.Value));
 private static void LoadConfig()
 {
     config = ModUtils.LoadConfig <Config>(GetModInfoPath());
     ValidateConfig();
 }
Example #30
0
        public void SetMobType(NPCStats npc)
        {
            this.RemoveAllChildren();
            float yPos = Spacing;

            this.Width = 350;

            //if (npc.NetID < 0) return;
            CurrentNPC = npc;
            ModUtils.LoadNPC(npc.Type);
            mobImage.Texture         = Main.npcTexture[npc.Type];
            mobImage.SourceRectangle = new Rectangle(0, 0, (int)mobImage.Texture.Width, (int)mobImage.Texture.Height / Main.npcFrameCount[npc.Type]);
            //mobImage.ForegroundColor = CurrentNPC.AlphaColor;
            AddChild(mobImage);

            UIImage mobImage2 = new UIImage();

            mobImage2.Texture         = mobImage.Texture;
            mobImage2.SourceRectangle = mobImage.SourceRectangle;
            mobImage2.ForegroundColor = CurrentNPC.Color;
            AddChild(mobImage2);
            //AddChild(mobImage2);

            if (mobImage.Width > this.Width - Spacing * 2)
            {
                this.Width = mobImage.Width + Spacing * 2;
                mobImage.X = Spacing;
            }
            else
            {
                mobImage.X = Width / 2 - mobImage.Width / 2;
            }

            yPos += mobImage.Height;
            mobImage2.Position = mobImage.Position;

            //largestWidth =

            float statScale = .4f;

            UILabel lID = new UILabel("ID");

            lID.Scale = statScale;
            lID.X     = Spacing;
            lID.Y     = yPos;
            AddChild(lID);

            UILabel id = new UILabel(npc.NetID.ToString());

            id.Scale  = statScale;
            id.Anchor = AnchorPosition.TopRight;
            id.X      = Width - Spacing;
            id.Y      = yPos;
            AddChild(id);

            yPos += lID.Height;

            if (npc.Health > 0)
            {
                UILabel lHealth = new UILabel("Health");
                lHealth.Scale = statScale;
                lHealth.X     = Spacing;
                lHealth.Y     = yPos;
                AddChild(lHealth);

                UILabel lValue = new UILabel(npc.Health.ToString());
                lValue.Scale  = statScale;
                lValue.Anchor = AnchorPosition.TopRight;
                lValue.X      = Width - Spacing;
                lValue.Y      = yPos;
                AddChild(lValue);

                yPos += lHealth.Height;
            }

            if (npc.Damage > 0)
            {
                UILabel lDamage = new UILabel("Damage");
                lDamage.Scale = statScale;
                lDamage.X     = Spacing;
                lDamage.Y     = yPos;
                AddChild(lDamage);

                UILabel lValue = new UILabel(npc.Damage.ToString());
                lValue.Scale  = statScale;
                lValue.Anchor = AnchorPosition.TopRight;
                lValue.X      = Width - Spacing;
                lValue.Y      = yPos;
                AddChild(lValue);

                yPos += lDamage.Height;
            }

            if (npc.Defense > 0)
            {
                UILabel lDefense = new UILabel("Defense");
                lDefense.Scale = statScale;
                lDefense.X     = Spacing;
                lDefense.Y     = yPos;
                AddChild(lDefense);

                UILabel lValue = new UILabel(npc.Defense.ToString());
                lValue.Scale  = statScale;
                lValue.Anchor = AnchorPosition.TopRight;
                lValue.X      = Width - Spacing;
                lValue.Y      = yPos;
                AddChild(lValue);

                yPos += lDefense.Height;
            }

            if (npc.KncokbackResist > 0)
            {
                UILabel lKncokbackResist = new UILabel("Knockback Resistance");
                lKncokbackResist.Scale = statScale;
                lKncokbackResist.X     = Spacing;
                lKncokbackResist.Y     = yPos;
                AddChild(lKncokbackResist);

                UILabel lValue = new UILabel(npc.KncokbackResist.ToString());
                lValue.Scale  = statScale;
                lValue.Anchor = AnchorPosition.TopRight;
                lValue.X      = Width - Spacing;
                lValue.Y      = yPos;
                AddChild(lValue);

                yPos += lKncokbackResist.Height;
            }

            //DropTableView tableView = new DropTableView(DropTableBuilder.DropTable.NPCDropTables[npc.Type], this.Width - Spacing * 2);
            //tableView.Y = yPos;
            //tableView.X = Spacing;
            //AddChild(tableView);
            //yPos += tableView.Height;

            //this.Width = mobImage.Width + Spacing * 2;
            this.Height = yPos + Spacing;
        }