コード例 #1
0
            public void SetMod(ModLoader.LoadingMod mod) {
                if (modFile == null ||
                    modFile.version != mod.modFile.version ||
                    !modFile.hash.SequenceEqual(mod.modFile.hash))
                    SetNeedsReload();

                modFile = mod.modFile;
                properties = mod.properties;
            }
コード例 #2
0
ファイル: Interface.cs プロジェクト: immortalcatz/tModLoader
        //internal static void AddSettingsMenuButtons(Main main, int selectedMenu, string[] buttonNames, float[] buttonScales, int[] virticalSpacing, ref int offY, ref int spacing, ref int buttonIndex, ref int numButtons)
        //{
        //	buttonIndex++;
        //	numButtons++;
        //	buttonNames[buttonIndex] = "Mod " + Lang.menu[66];
        //	if (selectedMenu == buttonIndex)
        //	{
        //		Main.PlaySound(10, -1, -1, 1);
        //		Main.menuMode = modControlsID;
        //	}
        //	for (int k = 0; k < numButtons; k++)
        //	{
        //		buttonScales[k] = 0.73f;
        //		virticalSpacing[k] = 0;
        //	}
        //	virticalSpacing[numButtons - 1] = 8;
        //}

        //add to end of if else chain of Main.menuMode in Terraria.Main.DrawMenu
        //Interface.ModLoaderMenus(this, this.selectedMenu, array9, array7, array4, ref num2, ref num4, ref num5, ref flag5);
        internal static void ModLoaderMenus(Main main, int selectedMenu, string[] buttonNames, float[] buttonScales, int[] buttonVerticalSpacing, ref int offY, ref int spacing, ref int numButtons, ref bool backButtonDown)
        {
            if (Main.menuMode == modsMenuID)
            {
                Main.MenuUI.SetState(modsMenu);
                Main.menuMode = 888;
            }
            else if (Main.menuMode == modSourcesID)
            {
                Main.MenuUI.SetState(modSources);
                Main.menuMode = 888;
            }
            else if (Main.menuMode == loadModsID)
            {
                Main.MenuUI.SetState(loadMods);
                Main.menuMode = 888;
                ModLoader.Load();
            }
            else if (Main.menuMode == buildModID)
            {
                Main.MenuUI.SetState(buildMod);
                Main.menuMode = 888;
                ModLoader.BuildMod();
            }
            else if (Main.menuMode == buildAllModsID)
            {
                Main.MenuUI.SetState(buildMod);
                Main.menuMode = 888;
                ModLoader.BuildAllMods();
            }
            else if (Main.menuMode == errorMessageID)
            {
                Main.MenuUI.SetState(errorMessage);
                Main.menuMode = 888;
            }
            else if (Main.menuMode == reloadModsID)
            {
                ModLoader.Reload();
            }
            else if (Main.menuMode == modBrowserID)
            {
                Main.MenuUI.SetState(modBrowser);
                Main.menuMode = 888;
            }
            else if (Main.menuMode == modInfoID)
            {
                Main.MenuUI.SetState(modInfo);
                Main.menuMode = 888;
            }
            else if (Main.menuMode == downloadModID)
            {
                Main.MenuUI.SetState(downloadMod);
                Main.menuMode = 888;
            }
            else if (Main.menuMode == downloadModsID)
            {
                Main.menuMode = 888;
                Main.MenuUI.SetState(downloadMods);
            }
            else if (Main.menuMode == managePublishedID)
            {
                Main.MenuUI.SetState(managePublished);
                Main.menuMode = 888;
            }
            //else if (Main.menuMode == modControlsID)
            //{
            //	UIModControls.ModLoaderMenus(main, selectedMenu, buttonNames, buttonScales, buttonVerticalSpacing, ref offY, ref spacing, ref numButtons);
            //}
            else if (Main.menuMode == updateMessageID)
            {
                Main.MenuUI.SetState(updateMessage);
                Main.menuMode = 888;
            }
            else if (Main.menuMode == infoMessageID)
            {
                Main.MenuUI.SetState(infoMessage);
                Main.menuMode = 888;
            }
            else if (Main.menuMode == advancedInfoMessageID)
            {
                Main.MenuUI.SetState(advancedInfoMessage);
                Main.menuMode = 888;
            }
            else if (Main.menuMode == enterPassphraseMenuID)
            {
                Main.MenuUI.SetState(enterPassphraseMenu);
                Main.menuMode = 888;
            }
            else if (Main.menuMode == enterSteamIDMenuID)
            {
                Main.MenuUI.SetState(enterSteamIDMenu);
                Main.menuMode = 888;
            }
            else if (Main.menuMode == modPacksMenuID)
            {
                Main.MenuUI.SetState(modPacksMenu);
                Main.menuMode = 888;
            }
            else if (Main.menuMode == extractModID)
            {
                Main.MenuUI.SetState(extractMod);
                Main.menuMode = 888;
            }
            else if (Main.menuMode == uploadModID)
            {
                Main.MenuUI.SetState(uploadMod);
                Main.menuMode = 888;
            }
            else if (Main.menuMode == tModLoaderSettingsID)
            {
                offY       = 210;
                spacing    = 42;
                numButtons = 7;
                buttonVerticalSpacing[numButtons - 1] = 18;
                for (int i = 0; i < numButtons; i++)
                {
                    buttonScales[i] = 0.75f;
                }
                int buttonIndex = 0;
                buttonNames[buttonIndex] = (ModNet.downloadModsFromServers ? Language.GetTextValue("tModLoader.DownloadFromServersYes") : Language.GetTextValue("tModLoader.DownloadFromServersNo"));
                if (selectedMenu == buttonIndex)
                {
                    Main.PlaySound(SoundID.MenuTick);
                    ModNet.downloadModsFromServers = !ModNet.downloadModsFromServers;
                }

                buttonIndex++;
                buttonNames[buttonIndex] = (ModNet.onlyDownloadSignedMods ? Language.GetTextValue("tModLoader.DownloadSignedYes") : Language.GetTextValue("tModLoader.DownloadSignedNo"));
                if (selectedMenu == buttonIndex)
                {
                    Main.PlaySound(SoundID.MenuTick);
                    ModNet.onlyDownloadSignedMods = !ModNet.onlyDownloadSignedMods;
                }

                buttonIndex++;
                buttonNames[buttonIndex] = (ModLoader.musicStreamMode == 0 ? Language.GetTextValue("tModLoader.MusicStreamModeConvert") : Language.GetTextValue("tModLoader.MusicStreamModeStream"));
                if (selectedMenu == buttonIndex)
                {
                    Main.PlaySound(SoundID.MenuTick);
                    ModLoader.musicStreamMode = (byte)((ModLoader.musicStreamMode + 1) % 2);
                }

                buttonIndex++;
                buttonNames[buttonIndex] = (ModLoader.alwaysLogExceptions ? Language.GetTextValue("tModLoader.AlwaysLogExceptionsYes") : Language.GetTextValue("tModLoader.AlwaysLogExceptionsNo"));
                if (selectedMenu == buttonIndex)
                {
                    Main.PlaySound(SoundID.MenuTick);
                    ModLoader.alwaysLogExceptions = !ModLoader.alwaysLogExceptions;
                }

                buttonIndex++;
                buttonNames[buttonIndex] = (Main.UseExperimentalFeatures ? Language.GetTextValue("tModLoader.ExperimentalFeaturesYes") : Language.GetTextValue("tModLoader.ExperimentalFeaturesNo"));
                if (selectedMenu == buttonIndex)
                {
                    Main.PlaySound(SoundID.MenuTick);
                    Main.UseExperimentalFeatures = !Main.UseExperimentalFeatures;
                }

                buttonIndex++;
                buttonNames[buttonIndex] = Language.GetTextValue("tModLoader.ClearMBCredentials");
                if (selectedMenu == buttonIndex)
                {
                    Main.PlaySound(SoundID.MenuTick);
                    ModLoader.modBrowserPassphrase = "";
                    ModLoader.SteamID64            = "";
                }

                buttonIndex++;
                buttonNames[buttonIndex] = Lang.menu[5].Value;
                if (selectedMenu == buttonIndex || backButtonDown)
                {
                    backButtonDown = false;
                    Main.menuMode  = 11;
                    Main.PlaySound(11, -1, -1, 1);
                }
            }
        }
コード例 #3
0
        // Receive a mod when connecting to server
        internal static void ReceiveMod(BinaryReader reader)
        {
            if (downloadingMod == null)
            {
                return;
            }

            try {
                if (downloadingFile == null)
                {
                    Interface.progress.Show(displayText: reader.ReadString(), cancel: CancelDownload);

                    ModLoader.GetMod(downloadingMod.name)?.Close();
                    downloadingLength = reader.ReadInt64();
                    downloadingFile   = new FileStream(downloadingMod.path, FileMode.Create);
                    return;
                }

                var bytes = reader.ReadBytes((int)Math.Min(downloadingLength - downloadingFile.Position, CHUNK_SIZE));
                downloadingFile.Write(bytes, 0, bytes.Length);
                Interface.progress.Progress = downloadingFile.Position / (float)downloadingLength;

                if (downloadingFile.Position == downloadingLength)
                {
                    downloadingFile.Close();
                    var mod = new TmodFile(downloadingMod.path);
                    using (mod.Open()) { }

                    if (!downloadingMod.Matches(mod))
                    {
                        throw new Exception(Language.GetTextValue("tModLoader.MPErrorModHashMismatch"));
                    }

                    if (downloadingMod.signed && !mod.ValidModBrowserSignature)
                    {
                        throw new Exception(Language.GetTextValue("tModLoader.MPErrorModNotSigned"));
                    }

                    ModLoader.EnableMod(mod.name);
                    if (downloadQueue.Count > 0)
                    {
                        DownloadNextMod();
                    }
                    else
                    {
                        OnModsDownloaded(true);
                    }
                }
            }
            catch (Exception e) {
                try {
                    downloadingFile?.Close();
                    File.Delete(downloadingMod.path);
                }
                catch (Exception exc2) {
                    Logging.tML.Error("Unknown error during mod sync", exc2);
                }

                var msg = Language.GetTextValue("tModLoader.MPErrorModDownloadError", downloadingMod.name);
                Logging.tML.Error(msg, e);
                Interface.errorMessage.Show(msg + e, 0);

                Netplay.disconnect = true;
                downloadingMod     = null;
            }
        }
コード例 #4
0
        //change initial size of Terraria.Player.ownedProjectileCounts to ProjectileLoader.ProjectileCount()
        internal static void ResizeArrays()
        {
            Array.Resize(ref Main.projectileLoaded, nextProjectile);
            Array.Resize(ref Main.projectileTexture, nextProjectile);
            Array.Resize(ref Main.projHostile, nextProjectile);
            Array.Resize(ref Main.projHook, nextProjectile);
            Array.Resize(ref Main.projFrames, nextProjectile);
            Array.Resize(ref Main.projPet, nextProjectile);
            Array.Resize(ref Main.projName, nextProjectile);
            Array.Resize(ref ProjectileID.Sets.YoyosLifeTimeMultiplier, nextProjectile);
            Array.Resize(ref ProjectileID.Sets.YoyosMaximumRange, nextProjectile);
            Array.Resize(ref ProjectileID.Sets.YoyosTopSpeed, nextProjectile);
            Array.Resize(ref ProjectileID.Sets.CanDistortWater, nextProjectile);
            Array.Resize(ref ProjectileID.Sets.MinionShot, nextProjectile);
            Array.Resize(ref ProjectileID.Sets.SentryShot, nextProjectile);
            Array.Resize(ref ProjectileID.Sets.ForcePlateDetection, nextProjectile);
            Array.Resize(ref ProjectileID.Sets.TrailingMode, nextProjectile);
            Array.Resize(ref ProjectileID.Sets.TrailCacheLength, nextProjectile);
            Array.Resize(ref ProjectileID.Sets.LightPet, nextProjectile);
            Array.Resize(ref ProjectileID.Sets.Homing, nextProjectile);
            Array.Resize(ref ProjectileID.Sets.IsADD2Turret, nextProjectile);
            Array.Resize(ref ProjectileID.Sets.TurretFeature, nextProjectile);
            Array.Resize(ref ProjectileID.Sets.MinionTargettingFeature, nextProjectile);
            Array.Resize(ref ProjectileID.Sets.MinionSacrificable, nextProjectile);
            Array.Resize(ref ProjectileID.Sets.DontAttachHideToAlpha, nextProjectile);
            Array.Resize(ref ProjectileID.Sets.NeedsUUID, nextProjectile);
            Array.Resize(ref ProjectileID.Sets.StardustDragon, nextProjectile);
            Array.Resize(ref ProjectileID.Sets.NoLiquidDistortion, nextProjectile);
            for (int k = ProjectileID.Count; k < nextProjectile; k++)
            {
                ProjectileID.Sets.YoyosLifeTimeMultiplier[k] = -1;
                ProjectileID.Sets.YoyosMaximumRange[k]       = 200f;
                ProjectileID.Sets.YoyosTopSpeed[k]           = 10f;
                ProjectileID.Sets.CanDistortWater[k]         = true;
                Main.projectileLoaded[k]              = true;
                Main.projFrames[k]                    = 1;
                ProjectileID.Sets.TrailingMode[k]     = -1;
                ProjectileID.Sets.TrailCacheLength[k] = 10;
            }
            Array.Resize(ref Projectile.perIDStaticNPCImmunity, nextProjectile);
            for (int i = 0; i < nextProjectile; i++)
            {
                Projectile.perIDStaticNPCImmunity[i] = new int[200];
            }

            ModLoader.BuildGlobalHook(ref HookSetDefaults, globalProjectiles, g => g.SetDefaults);
            ModLoader.BuildGlobalHook(ref HookPreAI, globalProjectiles, g => g.PreAI);
            ModLoader.BuildGlobalHook(ref HookAI, globalProjectiles, g => g.AI);
            ModLoader.BuildGlobalHook(ref HookPostAI, globalProjectiles, g => g.PostAI);
            ModLoader.BuildGlobalHook(ref HookShouldUpdatePosition, globalProjectiles, g => g.ShouldUpdatePosition);
            ModLoader.BuildGlobalHook(ref HookTileCollideStyle, globalProjectiles, g => g.TileCollideStyle);
            ModLoader.BuildGlobalHook(ref HookOnTileCollide, globalProjectiles, g => g.OnTileCollide);
            ModLoader.BuildGlobalHook(ref HookCanCutTiles, globalProjectiles, g => g.CanCutTiles);
            ModLoader.BuildGlobalHook(ref HookCutTiles, globalProjectiles, g => g.CutTiles);
            ModLoader.BuildGlobalHook(ref HookPreKill, globalProjectiles, g => g.PreKill);
            ModLoader.BuildGlobalHook(ref HookKill, globalProjectiles, g => g.Kill);
            ModLoader.BuildGlobalHook(ref HookCanDamage, globalProjectiles, g => g.CanDamage);
            ModLoader.BuildGlobalHook(ref HookMinionContactDamage, globalProjectiles, g => g.MinionContactDamage);
            ModLoader.BuildGlobalHook(ref HookCanHitNPC, globalProjectiles, g => g.CanHitNPC);
            ModLoader.BuildGlobalHook(ref HookModifyHitNPC, globalProjectiles, g => g.ModifyHitNPC);
            ModLoader.BuildGlobalHook(ref HookOnHitNPC, globalProjectiles, g => g.OnHitNPC);
            ModLoader.BuildGlobalHook(ref HookCanHitPvp, globalProjectiles, g => g.CanHitPvp);
            ModLoader.BuildGlobalHook(ref HookModifyHitPvp, globalProjectiles, g => g.ModifyHitPvp);
            ModLoader.BuildGlobalHook(ref HookOnHitPvp, globalProjectiles, g => g.OnHitPvp);
            ModLoader.BuildGlobalHook(ref HookCanHitPlayer, globalProjectiles, g => g.CanHitPlayer);
            ModLoader.BuildGlobalHook(ref HookModifyHitPlayer, globalProjectiles, g => g.ModifyHitPlayer);
            ModLoader.BuildGlobalHook(ref HookOnHitPlayer, globalProjectiles, g => g.OnHitPlayer);
            ModLoader.BuildGlobalHook(ref HookColliding, globalProjectiles, g => g.Colliding);
            ModLoader.BuildGlobalHook(ref HookGetAlpha, globalProjectiles, g => g.GetAlpha);
            ModLoader.BuildGlobalHook(ref HookPreDrawExtras, globalProjectiles, g => g.PreDrawExtras);
            ModLoader.BuildGlobalHook(ref HookPreDraw, globalProjectiles, g => g.PreDraw);
            ModLoader.BuildGlobalHook(ref HookPostDraw, globalProjectiles, g => g.PostDraw);
            ModLoader.BuildGlobalHook(ref HookCanUseGrapple, globalProjectiles, g => g.CanUseGrapple);
            ModLoader.BuildGlobalHook(ref HookSingleGrappleHook, globalProjectiles, g => g.SingleGrappleHook);
            ModLoader.BuildGlobalHook(ref HookUseGrapple, globalProjectiles, g => g.UseGrapple);
            ModLoader.BuildGlobalHook(ref HookNumGrappleHooks, globalProjectiles, g => g.NumGrappleHooks);
            ModLoader.BuildGlobalHook(ref HookGrappleRetreatSpeed, globalProjectiles, g => g.GrappleRetreatSpeed);
            ModLoader.BuildGlobalHook(ref HookGrapplePullSpeed, globalProjectiles, g => g.GrapplePullSpeed);
            ModLoader.BuildGlobalHook(ref HookDrawBehind, globalProjectiles, g => g.DrawBehind);
        }
コード例 #5
0
        internal static void ServerModMenu()
        {
            bool exit = false;

            while (!exit)
            {
                Console.WriteLine("Terraria Server " + Main.versionNumber2 + " - " + ModLoader.versionedName);
                Console.WriteLine();
                TmodFile[] mods = ModLoader.FindMods();
                for (int k = 0; k < mods.Length; k++)
                {
                    BuildProperties properties = BuildProperties.ReadModFile(mods[k]);
                    string          name       = properties.displayName;
                    name = mods[k].name;
                    string line = (k + 1) + "\t\t" + name + "(";
                    line += (ModLoader.IsEnabled(mods[k]) ? "enabled" : "disabled") + ")";
                    Console.WriteLine(line);
                }
                Console.WriteLine("e\t\tEnable All");
                Console.WriteLine("d\t\tDisable All");
                Console.WriteLine("r\t\tReload and return to world menu");
                Console.WriteLine("Type a number to switch between enabled/disabled");
                Console.WriteLine();
                Console.WriteLine("Type a command: ");
                string command = Console.ReadLine();
                if (command == null)
                {
                    command = "";
                }
                command = command.ToLower();
                Console.Clear();
                if (command == "e")
                {
                    foreach (TmodFile mod in mods)
                    {
                        ModLoader.EnableMod(mod);
                    }
                }
                else if (command == "d")
                {
                    foreach (TmodFile mod in mods)
                    {
                        ModLoader.DisableMod(mod);
                    }
                }
                else if (command == "r")
                {
                    Console.WriteLine("Unloading mods...");
                    ModLoader.Unload();
                    ModLoader.do_Load(null);
                    exit = true;
                }
                else
                {
                    int value;
                    if (Int32.TryParse(command, out value))
                    {
                        value--;
                        if (value >= 0 && value < mods.Length)
                        {
                            ModLoader.SetModActive(mods[value], !ModLoader.IsEnabled(mods[value]));
                        }
                    }
                }
            }
        }
コード例 #6
0
        internal static void ResizeArrays(bool unloading = false)
        {
            Array.Resize(ref Main.tileSetsLoaded, nextTile);
            for (int k = TileID.Count; k < nextTile; k++)
            {
                Main.tileSetsLoaded[k] = true;
            }
            Array.Resize(ref Main.highlightMaskTexture, nextTile);
            Resize2DArray(ref Main.tileAltTexture, nextTile);
            Resize2DArray(ref Main.tileAltTextureInit, nextTile);
            Resize2DArray(ref Main.tileAltTextureDrawn, nextTile);
            Array.Resize(ref Main.tileTexture, nextTile);
            Array.Resize(ref Main.tileLighted, nextTile);
            Array.Resize(ref Main.tileMergeDirt, nextTile);
            Array.Resize(ref Main.tileCut, nextTile);
            Array.Resize(ref Main.tileAlch, nextTile);
            Array.Resize(ref Main.tileShine, nextTile);
            Array.Resize(ref Main.tileShine2, nextTile);
            Array.Resize(ref Main.tileStone, nextTile);
            Array.Resize(ref Main.tileAxe, nextTile);
            Array.Resize(ref Main.tileHammer, nextTile);
            Array.Resize(ref Main.tileWaterDeath, nextTile);
            Array.Resize(ref Main.tileLavaDeath, nextTile);
            Array.Resize(ref Main.tileTable, nextTile);
            Array.Resize(ref Main.tileBlockLight, nextTile);
            Array.Resize(ref Main.tileNoSunLight, nextTile);
            Array.Resize(ref Main.tileDungeon, nextTile);
            Array.Resize(ref Main.tileSpelunker, nextTile);
            Array.Resize(ref Main.tileSolidTop, nextTile);
            Array.Resize(ref Main.tileSolid, nextTile);
            Array.Resize(ref Main.tileBouncy, nextTile);
            Array.Resize(ref Main.tileValue, nextTile);
            Array.Resize(ref Main.tileLargeFrames, nextTile);
            Array.Resize(ref Main.tileRope, nextTile);
            Array.Resize(ref Main.tileBrick, nextTile);
            Array.Resize(ref Main.tileMoss, nextTile);
            Array.Resize(ref Main.tileNoAttach, nextTile);
            Array.Resize(ref Main.tileNoFail, nextTile);
            Array.Resize(ref Main.tileObsidianKill, nextTile);
            Array.Resize(ref Main.tileFrameImportant, nextTile);
            Array.Resize(ref Main.tilePile, nextTile);
            Array.Resize(ref Main.tileBlendAll, nextTile);
            Array.Resize(ref Main.tileGlowMask, nextTile);
            Array.Resize(ref Main.tileContainer, nextTile);
            Array.Resize(ref Main.tileSign, nextTile);
            Array.Resize(ref Main.tileMerge, nextTile);
            for (int k = 0; k < nextTile; k++)             //oh dear
            {
                Array.Resize(ref Main.tileMerge[k], nextTile);
            }
            Array.Resize(ref Main.tileSand, nextTile);
            Array.Resize(ref Main.tileFlame, nextTile);
            Array.Resize(ref Main.tileFrame, nextTile);
            Array.Resize(ref Main.tileFrameCounter, nextTile);
            Array.Resize(ref WorldGen.tileCounts, nextTile);
            Array.Resize(ref WorldGen.houseTile, nextTile);
            Array.Resize(ref GameContent.Biomes.CaveHouseBiome._blacklistedTiles, nextTile);
            Array.Resize(ref GameContent.Biomes.CorruptionPitBiome.ValidTiles, nextTile);
            Array.Resize(ref TileID.Sets.Conversion.Grass, nextTile);
            Array.Resize(ref TileID.Sets.Conversion.Stone, nextTile);
            Array.Resize(ref TileID.Sets.Conversion.Ice, nextTile);
            Array.Resize(ref TileID.Sets.Conversion.Sand, nextTile);
            Array.Resize(ref TileID.Sets.Conversion.HardenedSand, nextTile);
            Array.Resize(ref TileID.Sets.Conversion.Sandstone, nextTile);
            Array.Resize(ref TileID.Sets.Conversion.Thorn, nextTile);
            Array.Resize(ref TileID.Sets.Conversion.Moss, nextTile);
            Array.Resize(ref TileID.Sets.Platforms, nextTile);
            Array.Resize(ref TileID.Sets.GemsparkFramingTypes, nextTile);
            Array.Resize(ref TileID.Sets.TeamTiles, nextTile);
            Array.Resize(ref TileID.Sets.ConveyorDirection, nextTile);
            Array.Resize(ref TileID.Sets.HasSlopeFrames, nextTile);
            Array.Resize(ref TileID.Sets.TileInteractRead, nextTile);
            Array.Resize(ref TileID.Sets.HasOutlines, nextTile);
            Array.Resize(ref TileID.Sets.AllTiles, nextTile);
            Array.Resize(ref TileID.Sets.Mud, nextTile);
            Array.Resize(ref TileID.Sets.Snow, nextTile);
            Array.Resize(ref TileID.Sets.Ices, nextTile);
            Array.Resize(ref TileID.Sets.IcesSlush, nextTile);
            Array.Resize(ref TileID.Sets.IcesSnow, nextTile);
            Array.Resize(ref TileID.Sets.GrassSpecial, nextTile);
            Array.Resize(ref TileID.Sets.JungleSpecial, nextTile);
            Array.Resize(ref TileID.Sets.HellSpecial, nextTile);
            Array.Resize(ref TileID.Sets.Leaves, nextTile);
            Array.Resize(ref TileID.Sets.GeneralPlacementTiles, nextTile);
            Array.Resize(ref TileID.Sets.CanBeClearedDuringGeneration, nextTile);
            Array.Resize(ref TileID.Sets.Corrupt, nextTile);
            Array.Resize(ref TileID.Sets.Hallow, nextTile);
            Array.Resize(ref TileID.Sets.Crimson, nextTile);
            Array.Resize(ref TileID.Sets.BlocksStairs, nextTile);
            Array.Resize(ref TileID.Sets.BlocksStairsAbove, nextTile);
            Array.Resize(ref TileID.Sets.NotReallySolid, nextTile);
            Array.Resize(ref TileID.Sets.ChecksForMerge, nextTile);
            Array.Resize(ref TileID.Sets.FramesOnKillWall, nextTile);
            Array.Resize(ref TileID.Sets.AvoidedByNPCs, nextTile);
            Array.Resize(ref TileID.Sets.InteractibleByNPCs, nextTile);
            Array.Resize(ref TileID.Sets.HousingWalls, nextTile);
            Array.Resize(ref TileID.Sets.BreakableWhenPlacing, nextTile);
            Array.Resize(ref TileID.Sets.TouchDamageVines, nextTile);
            Array.Resize(ref TileID.Sets.TouchDamageSands, nextTile);
            Array.Resize(ref TileID.Sets.TouchDamageHot, nextTile);
            Array.Resize(ref TileID.Sets.TouchDamageOther, nextTile);
            Array.Resize(ref TileID.Sets.Falling, nextTile);
            Array.Resize(ref TileID.Sets.Ore, nextTile);
            Array.Resize(ref TileID.Sets.ForceObsidianKill, nextTile);
            for (int k = TileID.Count; k < nextTile; k++)
            {
                TileID.Sets.AllTiles[k] = true;
                TileID.Sets.GeneralPlacementTiles[k]        = true;
                TileID.Sets.CanBeClearedDuringGeneration[k] = true;
            }
            while (TileObjectData._data.Count < nextTile)
            {
                TileObjectData._data.Add(null);
            }

            ModLoader.BuildGlobalHook(ref HookKillSound, globalTiles, g => g.KillSound);
            ModLoader.BuildGlobalHook(ref HookNumDust, globalTiles, g => g.NumDust);
            ModLoader.BuildGlobalHook(ref HookCreateDust, globalTiles, g => g.CreateDust);
            ModLoader.BuildGlobalHook(ref HookDropCritterChance, globalTiles, g => g.DropCritterChance);
            ModLoader.BuildGlobalHook(ref HookDrop, globalTiles, g => g.Drop);
            ModLoader.BuildGlobalHook(ref HookCanKillTile, globalTiles, g => g.CanKillTile);
            ModLoader.BuildGlobalHook(ref HookKillTile, globalTiles, g => g.KillTile);
            ModLoader.BuildGlobalHook(ref HookCanExplode, globalTiles, g => g.CanExplode);
            ModLoader.BuildGlobalHook(ref HookNearbyEffects, globalTiles, g => g.NearbyEffects);
            ModLoader.BuildGlobalHook(ref HookModifyLight, globalTiles, g => g.ModifyLight);
            ModLoader.BuildGlobalHook(ref HookDangersense, globalTiles, g => g.Dangersense);
            ModLoader.BuildGlobalHook(ref HookSetSpriteEffects, globalTiles, g => g.SetSpriteEffects);
            ModLoader.BuildGlobalHook(ref HookAnimateTile, globalTiles, g => g.AnimateTile);
            ModLoader.BuildGlobalHook(ref HookPreDraw, globalTiles, g => g.PreDraw);
            ModLoader.BuildGlobalHook(ref HookDrawEffects, globalTiles, g => g.DrawEffects);
            ModLoader.BuildGlobalHook(ref HookPostDraw, globalTiles, g => g.PostDraw);
            ModLoader.BuildGlobalHook(ref HookRandomUpdate, globalTiles, g => g.RandomUpdate);
            ModLoader.BuildGlobalHook(ref HookTileFrame, globalTiles, g => g.TileFrame);
            ModLoader.BuildGlobalHook(ref HookCanPlace, globalTiles, g => g.CanPlace);
            ModLoader.BuildGlobalHook(ref HookAdjTiles, globalTiles, g => g.AdjTiles);
            ModLoader.BuildGlobalHook(ref HookRightClick, globalTiles, g => g.RightClick);
            ModLoader.BuildGlobalHook(ref HookMouseOver, globalTiles, g => g.MouseOver);
            ModLoader.BuildGlobalHook(ref HookMouseOverFar, globalTiles, g => g.MouseOverFar);
            ModLoader.BuildGlobalHook(ref HookAutoSelect, globalTiles, g => g.AutoSelect);
            ModLoader.BuildGlobalHook(ref HookHitWire, globalTiles, g => g.HitWire);
            ModLoader.BuildGlobalHook(ref HookSlope, globalTiles, g => g.Slope);
            ModLoader.BuildGlobalHook(ref HookChangeWaterfallStyle, globalTiles, g => g.ChangeWaterfallStyle);
            ModLoader.BuildGlobalHook(ref HookSaplingGrowthType, globalTiles, g => g.SaplingGrowthType);

            if (!unloading)
            {
                loaded = true;
            }
        }
コード例 #7
0
ファイル: Mod.cs プロジェクト: Unowndeveloper/tModLoader
 public bool SoundExists(string name)
 {
     return(ModLoader.SoundExists(FileName(name)));
 }
コード例 #8
0
ファイル: Mod.cs プロジェクト: Unowndeveloper/tModLoader
 public void AddTexture(string name, Texture2D texture)
 {
     ModLoader.AddTexture(FileName(name), texture);
 }
コード例 #9
0
        public void TestVersionRequirements()
        {
            //test version on missing mod
            var list1 = new List <ModLoader.LoadingMod> {
                Make("A", refs: new[] { "[email protected]" })
            };

            ModLoader.EnsureTargetVersionsMet(list1);

            //test passed version check
            var list2 = new List <ModLoader.LoadingMod> {
                Make("A", refs: new[] { "[email protected]" }),
                Make("B", version: "1.2")
            };

            ModLoader.EnsureTargetVersionsMet(list2);

            //test failed version check
            var list3 = new List <ModLoader.LoadingMod> {
                Make("A", refs: new[] { "[email protected]" }),
                Make("B")
            };

            AssertModException(
                () => ModLoader.EnsureTargetVersionsMet(list3),
                new[] { "A" },
                "A requires version 1.2+ of B but version 1.0.0.0 is installed");

            //test one pass, two fail version check
            var list4 = new List <ModLoader.LoadingMod> {
                Make("A"),
                Make("B", refs: new[] { "[email protected]" }),
                Make("C", refs: new[] { "[email protected]" }),
                Make("D", refs: new[] { "[email protected]" })
            };

            AssertModException(
                () => ModLoader.EnsureTargetVersionsMet(list4),
                new[] { "C", "D" },
                "C requires version 1.1+ of A but version 1.0.0.0 is installed\r\n" +
                "D requires version 1.0.0.1+ of A but version 1.0.0.0 is installed");

            //test weak version check (missing)
            var list5 = new List <ModLoader.LoadingMod> {
                Make("A", weakRefs: new[] { "[email protected]" })
            };

            ModLoader.EnsureDependenciesExist(list5, false);
            ModLoader.EnsureTargetVersionsMet(list5);

            //test weak version check (too low)
            var list6 = new List <ModLoader.LoadingMod> {
                Make("A", weakRefs: new[] { "[email protected]" }),
                Make("B")
            };

            AssertModException(
                () => ModLoader.EnsureTargetVersionsMet(list6),
                new[] { "A" },
                "A requires version 1.1+ of B but version 1.0.0.0 is installed");
        }
コード例 #10
0
        public void TestDependenciesExist()
        {
            //test A -> B
            var list1 = new List <ModLoader.LoadingMod> {
                Make("A", refs: new[] { "B" }),
                Make("B"),
            };

            ModLoader.EnsureDependenciesExist(list1, false);

            //test A -> B (missing)
            var list2 = new List <ModLoader.LoadingMod> {
                Make("A", refs: new[] { "B" })
            };

            AssertModException(
                () => ModLoader.EnsureDependenciesExist(list2, false),
                new[] { "A" },
                "Missing mod: B required by A");

            //test multi reference
            var list3 = new List <ModLoader.LoadingMod> {
                Make("A", refs: new[] { "B" }),
                Make("B"),
                Make("C", refs: new[] { "A" })
            };

            ModLoader.EnsureDependenciesExist(list3, false);

            //test one missing reference
            var list4 = new List <ModLoader.LoadingMod> {
                Make("A", refs: new[] { "B" }),
                Make("B", refs: new[] { "C" })
            };

            AssertModException(
                () => ModLoader.EnsureDependenciesExist(list4, false),
                new[] { "B" },
                "Missing mod: C required by B");

            //test weak reference (missing)
            var list5 = new List <ModLoader.LoadingMod> {
                Make("A", weakRefs: new[] { "B" })
            };

            ModLoader.EnsureDependenciesExist(list5, false);
            AssertModException(
                () => ModLoader.EnsureDependenciesExist(list5, true),
                new[] { "A" },
                "Missing mod: B required by A");

            //test weak reference (found)
            var list6 = new List <ModLoader.LoadingMod> {
                Make("A", weakRefs: new[] { "B" }),
                Make("B")
            };

            ModLoader.EnsureDependenciesExist(list6, true);

            //test strong (found) and weak (missing)
            var list7 = new List <ModLoader.LoadingMod> {
                Make("A", refs: new[] { "B" }),
                Make("B", weakRefs: new[] { "C" })
            };

            ModLoader.EnsureDependenciesExist(list7, false);
            AssertModException(
                () => ModLoader.EnsureDependenciesExist(list7, true),
                new[] { "B" },
                "Missing mod: C required by B");

            //multi test case (missing)
            var list8 = new List <ModLoader.LoadingMod> {
                Make("A", refs: new[] { "X" }),
                Make("B", refs: new[] { "Y" }),
                Make("C", refs: new[] { "D" }),
                Make("D", weakRefs: new[] { "E" }),
                Make("E", weakRefs: new[] { "Z" }),
                Make("F", weakRefs: new[] { "Z" })
            };

            AssertModException(
                () => ModLoader.EnsureDependenciesExist(list8, false),
                new[] { "A", "B" },
                "Missing mod: X required by A\r\n" +
                "Missing mod: Y required by B");
            AssertModException(
                () => ModLoader.EnsureDependenciesExist(list8, true),
                new[] { "A", "B", "E", "F" },
                "Missing mod: X required by A\r\n" +
                "Missing mod: Y required by B\r\n" +
                "Missing mod: Z required by E\r\n" +
                "Missing mod: Z required by F");

            //multi test case (found)
            var list9 = new List <ModLoader.LoadingMod> {
                Make("A", refs: new[] { "C" }),
                Make("B", refs: new[] { "C" }),
                Make("C", refs: new[] { "D" }),
                Make("D", weakRefs: new[] { "E" }),
                Make("E", weakRefs: new[] { "F" }),
                Make("F")
            };

            ModLoader.EnsureDependenciesExist(list9, false);
            ModLoader.EnsureDependenciesExist(list9, true);
        }
コード例 #11
0
        internal static List <Mod> InstantiateMods(List <ModLoader.LoadingMod> modsToLoad)
        {
            var modList = new List <LoadedMod>();

            foreach (var loading in modsToLoad)
            {
                LoadedMod mod;
                if (!loadedMods.TryGetValue(loading.Name, out mod))
                {
                    mod = loadedMods[loading.Name] = new LoadedMod();
                }

                mod.SetMod(loading);
                modList.Add(mod);
            }

            RecalculateReferences();

            if (Debugger.IsAttached)
            {
                ModLoader.isModder = true;
                foreach (var mod in modList.Where(mod => mod.properties.editAndContinue && mod.CanEaC))
                {
                    mod.EnableEaC();
                }
            }

            var modInstances = new List <Mod>();

            int i = 0;

            foreach (var mod in modList)
            {
                Interface.loadMods.SetProgressCompatibility(mod.Name, i++, modsToLoad.Count);
                try {
                    Interface.loadMods.SetProgressReading(mod.Name, 0, 1);
                    mod.LoadAssemblies();

                    Interface.loadMods.SetProgressReading(mod.Name, 1, 2);
                    Type modType;
                    try
                    {
                        modType = mod.assembly.GetTypes().Single(t => t.IsSubclassOf(typeof(Mod)));
                    }
                    catch (Exception e)
                    {
                        throw new Exception("It looks like this mod doesn't have a class extending Mod. Mods need a Mod class to function.", e)
                              {
                                  HelpLink = "https://github.com/blushiemagic/tModLoader/wiki/Basic-tModLoader-Modding-FAQ#sequence-contains-no-matching-element-error"
                              };
                    }
                    var m = (Mod)Activator.CreateInstance(modType);
                    m.File        = mod.modFile;
                    m.Code        = mod.assembly;
                    m.Side        = mod.properties.side;
                    m.DisplayName = mod.properties.displayName;
                    modInstances.Add(m);
                }
                catch (Exception e) {
                    ModLoader.DisableMod(mod.modFile);
                    ErrorLogger.LogLoadingError(mod.Name, mod.modFile.tModLoaderVersion, e);
                    return(null);
                }
            }

            return(modInstances);
        }
コード例 #12
0
ファイル: ModNet.cs プロジェクト: imkSushi/tModLoader
        internal static void SyncClientMods(BinaryReader reader)
        {
            AllowVanillaClients = reader.ReadBoolean();

            Main.statusText = Language.GetTextValue("tModLoader.MPSyncingMods");
            var clientMods  = ModLoader.Mods;
            var modFiles    = ModOrganizer.FindMods();
            var needsReload = false;

            downloadQueue.Clear();
            var syncSet     = new HashSet <string>();
            var blockedList = new List <ModHeader>();

            int n = reader.ReadInt32();

            for (int i = 0; i < n; i++)
            {
                var header = new ModHeader(reader.ReadString(), new Version(reader.ReadString()), reader.ReadBytes(20), reader.ReadBoolean());
                syncSet.Add(header.name);

                var clientMod = clientMods.SingleOrDefault(m => m.Name == header.name);
                if (clientMod != null)
                {
                    if (header.Matches(clientMod.File))
                    {
                        continue;
                    }

                    header.path = clientMod.File.path;
                }
                else
                {
                    var disabledVersions = modFiles.Where(m => m.Name == header.name).ToArray();
                    var matching         = disabledVersions.FirstOrDefault(mod => header.Matches(mod.modFile));
                    if (matching != null)
                    {
                        matching.Enabled = true;
                        needsReload      = true;
                        continue;
                    }

                    if (disabledVersions.Length > 0)
                    {
                        header.path = disabledVersions[0].modFile.path;
                    }
                }

                if (downloadModsFromServers && (header.signed || !onlyDownloadSignedMods))
                {
                    downloadQueue.Enqueue(header);
                }
                else
                {
                    blockedList.Add(header);
                }
            }

            foreach (var mod in clientMods)
            {
                if (mod.Side == ModSide.Both && !syncSet.Contains(mod.Name))
                {
                    ModLoader.DisableMod(mod.Name);
                    needsReload = true;
                }
            }

            if (blockedList.Count > 0)
            {
                var msg = Language.GetTextValue("tModLoader.MPServerModsCantDownload");
                msg += downloadModsFromServers
                                        ? Language.GetTextValue("tModLoader.MPServerModsCantDownloadReasonSigned")
                                        : Language.GetTextValue("tModLoader.MPServerModsCantDownloadReasonAutomaticDownloadDisabled");
                msg += ".\n" + Language.GetTextValue("tModLoader.MPServerModsCantDownloadChangeSettingsHint") + "\n";
                foreach (var mod in blockedList)
                {
                    msg += "\n    " + mod;
                }

                Logging.tML.Warn(msg);
                Interface.errorMessage.SetMessage(msg);
                Interface.errorMessage.SetGotoMenu(0);
                Main.gameMenu = true;
                Main.menuMode = Interface.errorMessageID;
                return;
            }

            if (downloadQueue.Count > 0)
            {
                DownloadNextMod();
            }
            else
            {
                OnModsDownloaded(needsReload);
            }
        }
コード例 #13
0
ファイル: ModNet.cs プロジェクト: imkSushi/tModLoader
        internal static void ReceiveMod(BinaryReader reader)
        {
            if (downloadingMod == null)
            {
                return;
            }

            try
            {
                if (downloadingFile == null)
                {
                    Interface.downloadMod.SetDownloading(reader.ReadString());
                    Interface.downloadMod.SetCancel(() =>
                    {
                        downloadingFile?.Close();
                        downloadingMod     = null;
                        Netplay.disconnect = true;
                        Main.menuMode      = 0;
                    });
                    Main.menuMode = Interface.downloadModID;

                    downloadingLength = reader.ReadInt64();
                    downloadingFile   = new FileStream(downloadingMod.path, FileMode.Create);
                    return;
                }

                var bytes = reader.ReadBytes((int)Math.Min(downloadingLength - downloadingFile.Position, CHUNK_SIZE));
                downloadingFile.Write(bytes, 0, bytes.Length);
                Interface.downloadMod.SetProgress(downloadingFile.Position, downloadingLength);

                if (downloadingFile.Position == downloadingLength)
                {
                    downloadingFile.Close();
                    var mod = new TmodFile(downloadingMod.path);
                    mod.Read(TmodFile.LoadedState.Info);

                    if (!downloadingMod.Matches(mod))
                    {
                        throw new Exception(Language.GetTextValue("tModLoader.MPErrorModHashMismatch"));
                    }

                    if (downloadingMod.signed && !mod.ValidModBrowserSignature)
                    {
                        throw new Exception(Language.GetTextValue("tModLoader.MPErrorModNotSigned"));
                    }

                    ModLoader.EnableMod(mod.name);

                    if (downloadQueue.Count > 0)
                    {
                        DownloadNextMod();
                    }
                    else
                    {
                        OnModsDownloaded(true);
                    }
                }
            }
            catch (Exception e)
            {
                try
                {
                    downloadingFile?.Close();
                }
                catch { }

                File.Delete(downloadingMod.path);
                Logging.tML.Error(Language.GetTextValue("tModLoader.MPErrorModDownloadError", downloadingMod.name), e);
                downloadingMod = null;
            }
        }
コード例 #14
0
        //internal static void AddSettingsMenuButtons(Main main, int selectedMenu, string[] buttonNames, float[] buttonScales, int[] virticalSpacing, ref int offY, ref int spacing, ref int buttonIndex, ref int numButtons)
        //{
        //	buttonIndex++;
        //	numButtons++;
        //	buttonNames[buttonIndex] = "Mod " + Lang.menu[66];
        //	if (selectedMenu == buttonIndex)
        //	{
        //		Main.PlaySound(10, -1, -1, 1);
        //		Main.menuMode = modControlsID;
        //	}
        //	for (int k = 0; k < numButtons; k++)
        //	{
        //		buttonScales[k] = 0.73f;
        //		virticalSpacing[k] = 0;
        //	}
        //	virticalSpacing[numButtons - 1] = 8;
        //}

        //add to end of if else chain of Main.menuMode in Terraria.Main.DrawMenu
        //Interface.ModLoaderMenus(this, this.selectedMenu, array9, array7, array4, ref num2, ref num4, ref num5, ref flag5);
        internal static void ModLoaderMenus(Main main, int selectedMenu, string[] buttonNames, float[] buttonScales, int[] buttonVerticalSpacing, ref int offY, ref int spacing, ref int numButtons, ref bool backButtonDown)
        {
            if (Main.menuMode == modsMenuID)
            {
                Main.MenuUI.SetState(modsMenu);
                Main.menuMode = 888;
            }
            else if (Main.menuMode == modSourcesID)
            {
                Main.MenuUI.SetState(modSources);
                Main.menuMode = 888;
            }
            else if (Main.menuMode == createModID)
            {
                Main.MenuUI.SetState(createMod);
                Main.menuMode = 888;
            }
            else if (Main.menuMode == developerModeHelpID)
            {
                Main.MenuUI.SetState(developerModeHelp);
                Main.menuMode = 888;
            }
            else if (Main.menuMode == loadModsProgressID)
            {
                Main.menuMode = 888;
                Main.MenuUI.SetState(loadModsProgress);
            }
            else if (Main.menuMode == buildModProgressID)
            {
                Main.MenuUI.SetState(buildMod);
                Main.menuMode = 888;
            }
            else if (Main.menuMode == errorMessageID)
            {
                Main.MenuUI.SetState(errorMessage);
                Main.menuMode = 888;
            }
            else if (Main.menuMode == reloadModsID)
            {
                ModLoader.Reload();
            }
            else if (Main.menuMode == modBrowserID)
            {
                Main.MenuUI.SetState(modBrowser);
                Main.menuMode = 888;
            }
            else if (Main.menuMode == modInfoID)
            {
                Main.MenuUI.SetState(modInfo);
                Main.menuMode = 888;
            }
            else if (Main.menuMode == managePublishedID)
            {
                Main.MenuUI.SetState(managePublished);
                Main.menuMode = 888;
            }
            //else if (Main.menuMode == modControlsID)
            //{
            //	UIModControls.ModLoaderMenus(main, selectedMenu, buttonNames, buttonScales, buttonVerticalSpacing, ref offY, ref spacing, ref numButtons);
            //}
            else if (Main.menuMode == updateMessageID)
            {
                Main.MenuUI.SetState(updateMessage);
                Main.menuMode = 888;
            }
            else if (Main.menuMode == infoMessageID)
            {
                Main.MenuUI.SetState(infoMessage);
                Main.menuMode = 888;
            }
            else if (Main.menuMode == enterPassphraseMenuID)
            {
                Main.MenuUI.SetState(enterPassphraseMenu);
                Main.menuMode = 888;
            }
            else if (Main.menuMode == enterSteamIDMenuID)
            {
                Main.MenuUI.SetState(enterSteamIDMenu);
                Main.menuMode = 888;
            }
            else if (Main.menuMode == modPacksMenuID)
            {
                Main.MenuUI.SetState(modPacksMenu);
                Main.menuMode = 888;
            }
            else if (Main.menuMode == extractModProgressID)
            {
                Main.MenuUI.SetState(extractMod);
                Main.menuMode = 888;
            }
            else if (Main.menuMode == uploadModProgressID)
            {
                Main.MenuUI.SetState(uploadModProgress);
                Main.menuMode = 888;
            }
            else if (Main.menuMode == progressID)
            {
                Main.MenuUI.SetState(progress);
                Main.menuMode = 888;
            }
            else if (Main.menuMode == downloadProgressID)
            {
                Main.MenuUI.SetState(downloadProgress);
                Main.menuMode = 888;
            }
            else if (Main.menuMode == unloadModsID)
            {
                Main.MenuUI.SetState(unloadModsProgress);
                Main.menuMode = 888;
            }
            else if (Main.menuMode == tModLoaderSettingsID)
            {
                offY       = 210;
                spacing    = 42;
                numButtons = 11;
                buttonVerticalSpacing[numButtons - 1] = 18;
                for (int i = 0; i < numButtons; i++)
                {
                    buttonScales[i] = 0.75f;
                }
                int buttonIndex = 0;
                buttonNames[buttonIndex] = (ModNet.downloadModsFromServers ? Language.GetTextValue("tModLoader.DownloadFromServersYes") : Language.GetTextValue("tModLoader.DownloadFromServersNo"));
                if (selectedMenu == buttonIndex)
                {
                    Main.PlaySound(SoundID.MenuTick);
                    ModNet.downloadModsFromServers = !ModNet.downloadModsFromServers;
                }

                buttonIndex++;
                buttonNames[buttonIndex] = (ModNet.onlyDownloadSignedMods ? Language.GetTextValue("tModLoader.DownloadSignedYes") : Language.GetTextValue("tModLoader.DownloadSignedNo"));
                if (selectedMenu == buttonIndex)
                {
                    Main.PlaySound(SoundID.MenuTick);
                    ModNet.onlyDownloadSignedMods = !ModNet.onlyDownloadSignedMods;
                }

                buttonIndex++;
                buttonNames[buttonIndex] = (ModLoader.autoReloadAndEnableModsLeavingModBrowser ? Language.GetTextValue("tModLoader.AutomaticallyReloadAndEnableModsLeavingModBrowserYes") : Language.GetTextValue("tModLoader.AutomaticallyReloadAndEnableModsLeavingModBrowserNo"));
                if (selectedMenu == buttonIndex)
                {
                    Main.PlaySound(SoundID.MenuTick);
                    ModLoader.autoReloadAndEnableModsLeavingModBrowser = !ModLoader.autoReloadAndEnableModsLeavingModBrowser;
                }

                buttonIndex++;
                buttonNames[buttonIndex] = (Main.UseExperimentalFeatures ? Language.GetTextValue("tModLoader.ExperimentalFeaturesYes") : Language.GetTextValue("tModLoader.ExperimentalFeaturesNo"));
                if (selectedMenu == buttonIndex)
                {
                    Main.PlaySound(SoundID.MenuTick);
                    Main.UseExperimentalFeatures = !Main.UseExperimentalFeatures;
                }

                buttonIndex++;
                buttonNames[buttonIndex] = Language.GetTextValue($"tModLoader.RemoveForcedMinimumZoom{(ModLoader.removeForcedMinimumZoom ? "Yes" : "No")}");
                if (selectedMenu == buttonIndex)
                {
                    Main.PlaySound(SoundID.MenuTick);
                    ModLoader.removeForcedMinimumZoom = !ModLoader.removeForcedMinimumZoom;
                }

                buttonIndex++;
                buttonNames[buttonIndex] = Language.GetTextValue($"tModLoader.ShowMemoryEstimates{(ModLoader.showMemoryEstimates ? "Yes" : "No")}");
                if (selectedMenu == buttonIndex)
                {
                    Main.PlaySound(SoundID.MenuTick);
                    ModLoader.showMemoryEstimates = !ModLoader.showMemoryEstimates;
                }

                buttonIndex++;
                buttonNames[buttonIndex] = Language.GetTextValue("tModLoader.ClearMBCredentials");
                if (selectedMenu == buttonIndex)
                {
                    Main.PlaySound(SoundID.MenuTick);
                    ModLoader.modBrowserPassphrase = "";
                    ModLoader.SteamID64            = "";
                }

                buttonIndex++;
                buttonNames[buttonIndex] = Lang.menu[5].Value;
                if (selectedMenu == buttonIndex || backButtonDown)
                {
                    backButtonDown = false;
                    Main.menuMode  = 11;
                    Main.PlaySound(11, -1, -1, 1);
                }
            }
            else if (Main.menuMode == modConfigID)
            {
                Main.MenuUI.SetState(modConfig);
                Main.menuMode = 888;
            }
            else if (Main.menuMode == exitID)
            {
                Environment.Exit(0);
            }
        }
コード例 #15
0
ファイル: WorldHooks.cs プロジェクト: raydeejay/tModLoader
 internal static void ResizeArrays()
 {
     NetWorlds = ModLoader.BuildGlobalHook <ModWorld, Action <BinaryWriter> >(worlds, w => w.NetSend);
 }
コード例 #16
0
ファイル: Mod.cs プロジェクト: Unowndeveloper/tModLoader
 public bool TextureExists(string name)
 {
     return(ModLoader.TextureExists(FileName(name)));
 }
コード例 #17
0
ファイル: ModNet.cs プロジェクト: raydeejay/tModLoader
        internal static void ReceiveMod(BinaryReader reader)
        {
            if (downloadingMod == null)
            {
                return;
            }

            try
            {
                if (downloadingFile == null)
                {
                    Interface.downloadMod.SetDownloading(reader.ReadString());
                    Interface.downloadMod.SetCancel(() =>
                    {
                        downloadingFile?.Close();
                        downloadingMod     = null;
                        Netplay.disconnect = true;
                        Main.menuMode      = 0;
                    });
                    Main.menuMode = Interface.downloadModID;

                    downloadingLength = reader.ReadInt64();
                    downloadingFile   = new FileStream(downloadingMod.path, FileMode.Create);
                    return;
                }

                var bytes = reader.ReadBytes((int)Math.Min(downloadingLength - downloadingFile.Position, CHUNK_SIZE));
                downloadingFile.Write(bytes, 0, bytes.Length);
                Interface.downloadMod.SetProgress(downloadingFile.Position, downloadingLength);

                if (downloadingFile.Position == downloadingLength)
                {
                    downloadingFile.Close();
                    var mod = new TmodFile(downloadingMod.path);
                    mod.Read();
                    var ex = mod.ValidMod();
                    if (ex != null)
                    {
                        throw ex;
                    }

                    if (!downloadingMod.Matches(mod))
                    {
                        throw new Exception("Hash mismatch");
                    }

                    if (downloadingMod.signed && !mod.ValidModBrowserSignature)
                    {
                        throw new Exception("Mod was not signed by the Mod Browser");
                    }

                    ModLoader.EnableMod(mod);

                    if (downloadQueue.Count > 0)
                    {
                        DownloadNextMod();
                    }
                    else
                    {
                        OnModsDownloaded(true);
                    }
                }
            }
            catch (Exception e)
            {
                try
                {
                    downloadingFile?.Close();
                }
                catch { }

                File.Delete(downloadingMod.path);
                ErrorLogger.LogException(e, "An error occured while downloading " + downloadingMod.name);
                downloadingMod = null;
            }
        }
コード例 #18
0
ファイル: Mod.cs プロジェクト: Unowndeveloper/tModLoader
 public SoundEffect GetSound(string name)
 {
     return(ModLoader.GetSound(FileName(name)));
 }
コード例 #19
0
ファイル: ModNet.cs プロジェクト: raydeejay/tModLoader
        internal static void SyncClientMods(BinaryReader reader)
        {
            AllowVanillaClients = reader.ReadBoolean();

            Main.statusText = "Syncing Mods";
            var clientMods  = ModLoader.LoadedMods;
            var modFiles    = ModLoader.FindMods();
            var needsReload = false;

            downloadQueue.Clear();
            var syncSet     = new HashSet <string>();
            var blockedList = new List <ModHeader>();

            int n = reader.ReadInt32();

            for (int i = 0; i < n; i++)
            {
                var header = new ModHeader(reader.ReadString(), new Version(reader.ReadString()), reader.ReadBytes(20), reader.ReadBoolean());
                syncSet.Add(header.name);

                var clientMod = clientMods.SingleOrDefault(m => m.Name == header.name);
                if (clientMod != null)
                {
                    if (header.Matches(clientMod.File))
                    {
                        continue;
                    }

                    header.path = clientMod.File.path;
                }
                else
                {
                    var disabledVersions = modFiles.Where(m => m.name == header.name).ToArray();
                    var matching         = disabledVersions.FirstOrDefault(header.Matches);
                    if (matching != null)
                    {
                        ModLoader.EnableMod(matching);
                        needsReload = true;
                        continue;
                    }

                    if (disabledVersions.Length > 0)
                    {
                        header.path = disabledVersions[0].path;
                    }
                }

                if (downloadModsFromServers && (header.signed || !onlyDownloadSignedMods))
                {
                    downloadQueue.Enqueue(header);
                }
                else
                {
                    blockedList.Add(header);
                }
            }

            foreach (var mod in clientMods)
            {
                if (mod.Side == ModSide.Both && !syncSet.Contains(mod.Name))
                {
                    ModLoader.DisableMod(mod.File);
                    needsReload = true;
                }
            }

            if (blockedList.Count > 0)
            {
                var msg = "The following mods are installed on the server but cannot be downloaded ";
                msg += downloadModsFromServers
                                        ? "because you only accept mods signed by the mod browser"
                                        : "because you have disabled automatic mod downloading";
                msg += ".\nYou will need to change your settings or acquire the mods from the server owner.\n";
                foreach (var mod in blockedList)
                {
                    msg += "\n    " + mod;
                }

                ErrorLogger.LogMissingMods(msg);
                return;
            }

            if (downloadQueue.Count > 0)
            {
                DownloadNextMod();
            }
            else
            {
                OnModsDownloaded(needsReload);
            }
        }
コード例 #20
0
ファイル: Mod.cs プロジェクト: Unowndeveloper/tModLoader
 public void AddFlameTexture(ModItem item, string texture)
 {
     ModLoader.GetTexture(texture);
     item.flameTexture = texture;
 }
コード例 #21
0
ファイル: Mod.cs プロジェクト: Unowndeveloper/tModLoader
        public void AddMount(string name, ModMountData mount, string texture,
                             IDictionary <MountTextureType, string> extraTextures = null)
        {
            int id;

            if (Mount.mounts == null || Mount.mounts.Length == MountID.Count)
            {
                Mount.Initialize();
            }
            id                         = MountLoader.ReserveMountID();
            mount.Name                 = name;
            mount.Type                 = id;
            mountDatas[name]           = mount;
            MountLoader.mountDatas[id] = mount;
            mount.texture              = texture;
            mount.mod                  = this;
            if (extraTextures != null)
            {
                foreach (MountTextureType textureType in Enum.GetValues(typeof(MountTextureType)))
                {
                    if (extraTextures.ContainsKey(textureType) && ModLoader.TextureExists(extraTextures[textureType]))
                    {
                        Texture2D extraTexture = ModLoader.GetTexture(extraTextures[textureType]);
                        switch (textureType)
                        {
                        case MountTextureType.Back:
                            mount.mountData.backTexture = extraTexture;
                            break;

                        case MountTextureType.BackGlow:
                            mount.mountData.backTextureGlow = extraTexture;
                            break;

                        case MountTextureType.BackExtra:
                            mount.mountData.backTextureExtra = extraTexture;
                            break;

                        case MountTextureType.BackExtraGlow:
                            mount.mountData.backTextureExtraGlow = extraTexture;
                            break;

                        case MountTextureType.Front:
                            mount.mountData.frontTexture = extraTexture;
                            break;

                        case MountTextureType.FrontGlow:
                            mount.mountData.frontTextureGlow = extraTexture;
                            break;

                        case MountTextureType.FrontExtra:
                            mount.mountData.frontTextureExtra = extraTexture;
                            break;

                        case MountTextureType.FrontExtraGlow:
                            mount.mountData.frontTextureExtraGlow = extraTexture;
                            break;
                        }
                    }
                }
            }
        }
コード例 #22
0
ファイル: TileLoader.cs プロジェクト: vSLG/tModLoader
        internal static void ResizeArrays(bool unloading = false)
        {
            //Textures
            Array.Resize(ref TextureAssets.Tile, nextTile);
            Array.Resize(ref TextureAssets.HighlightMask, nextTile);

            //Sets
            LoaderUtils.ResetStaticMembers(typeof(TileID), true);

            //Etc
            Array.Resize(ref Main.SceneMetrics._tileCounts, nextTile);
            Array.Resize(ref Main.PylonSystem._sceneMetrics._tileCounts, nextTile);
            Array.Resize(ref Main.tileLighted, nextTile);
            Array.Resize(ref Main.tileMergeDirt, nextTile);
            Array.Resize(ref Main.tileCut, nextTile);
            Array.Resize(ref Main.tileAlch, nextTile);
            Array.Resize(ref Main.tileShine, nextTile);
            Array.Resize(ref Main.tileShine2, nextTile);
            Array.Resize(ref Main.tileStone, nextTile);
            Array.Resize(ref Main.tileAxe, nextTile);
            Array.Resize(ref Main.tileHammer, nextTile);
            Array.Resize(ref Main.tileWaterDeath, nextTile);
            Array.Resize(ref Main.tileLavaDeath, nextTile);
            Array.Resize(ref Main.tileTable, nextTile);
            Array.Resize(ref Main.tileBlockLight, nextTile);
            Array.Resize(ref Main.tileNoSunLight, nextTile);
            Array.Resize(ref Main.tileDungeon, nextTile);
            Array.Resize(ref Main.tileSpelunker, nextTile);
            Array.Resize(ref Main.tileSolidTop, nextTile);
            Array.Resize(ref Main.tileSolid, nextTile);
            Array.Resize(ref Main.tileBouncy, nextTile);
            Array.Resize(ref Main.tileLargeFrames, nextTile);
            Array.Resize(ref Main.tileRope, nextTile);
            Array.Resize(ref Main.tileBrick, nextTile);
            Array.Resize(ref Main.tileMoss, nextTile);
            Array.Resize(ref Main.tileNoAttach, nextTile);
            Array.Resize(ref Main.tileNoFail, nextTile);
            Array.Resize(ref Main.tileObsidianKill, nextTile);
            Array.Resize(ref Main.tileFrameImportant, nextTile);
            Array.Resize(ref Main.tilePile, nextTile);
            Array.Resize(ref Main.tileBlendAll, nextTile);
            Array.Resize(ref Main.tileContainer, nextTile);
            Array.Resize(ref Main.tileSign, nextTile);
            Array.Resize(ref Main.tileSand, nextTile);
            Array.Resize(ref Main.tileFlame, nextTile);
            Array.Resize(ref Main.tileFrame, nextTile);
            Array.Resize(ref Main.tileFrameCounter, nextTile);
            Array.Resize(ref Main.tileMerge, nextTile);
            Array.Resize(ref Main.tileOreFinderPriority, nextTile);
            Array.Resize(ref Main.tileGlowMask, nextTile);
            Array.Resize(ref Main.tileCracked, nextTile);

            Array.Resize(ref WorldGen.tileCounts, nextTile);
            Array.Resize(ref WorldGen.houseTile, nextTile);
            //Array.Resize(ref GameContent.Biomes.CaveHouseBiome._blacklistedTiles, nextTile);
            Array.Resize(ref GameContent.Biomes.CorruptionPitBiome.ValidTiles, nextTile);
            Array.Resize(ref HouseUtils.BlacklistedTiles, nextTile);
            Array.Resize(ref HouseUtils.BeelistedTiles, nextTile);

            for (int i = 0; i < nextTile; i++)               //oh dear
            {
                Array.Resize(ref Main.tileMerge[i], nextTile);
            }

            for (int i = TileID.Count; i < nextTile; i++)
            {
                Main.tileGlowMask[i] = -1;                 //If we don't this, every modded tile will have a glowmask by default.
            }

            while (TileObjectData._data.Count < nextTile)
            {
                TileObjectData._data.Add(null);
            }

            //Hooks
            ModLoader.BuildGlobalHook(ref HookKillSound, globalTiles, g => g.KillSound);
            ModLoader.BuildGlobalHook(ref HookNumDust, globalTiles, g => g.NumDust);
            ModLoader.BuildGlobalHook(ref HookCreateDust, globalTiles, g => g.CreateDust);
            ModLoader.BuildGlobalHook(ref HookDropCritterChance, globalTiles, g => g.DropCritterChance);
            ModLoader.BuildGlobalHook(ref HookDrop, globalTiles, g => g.Drop);
            ModLoader.BuildGlobalHook(ref HookCanKillTile, globalTiles, g => g.CanKillTile);
            ModLoader.BuildGlobalHook(ref HookKillTile, globalTiles, g => g.KillTile);
            ModLoader.BuildGlobalHook(ref HookCanExplode, globalTiles, g => g.CanExplode);
            ModLoader.BuildGlobalHook(ref HookNearbyEffects, globalTiles, g => g.NearbyEffects);
            ModLoader.BuildGlobalHook(ref HookModifyLight, globalTiles, g => g.ModifyLight);
            ModLoader.BuildGlobalHook(ref HookDangersense, globalTiles, g => g.Dangersense);
            ModLoader.BuildGlobalHook(ref HookSetSpriteEffects, globalTiles, g => g.SetSpriteEffects);
            ModLoader.BuildGlobalHook(ref HookAnimateTile, globalTiles, g => g.AnimateTile);
            ModLoader.BuildGlobalHook(ref HookPreDraw, globalTiles, g => g.PreDraw);
            ModLoader.BuildGlobalHook(ref HookDrawEffects, globalTiles, g => g.DrawEffects);
            ModLoader.BuildGlobalHook(ref HookPostDraw, globalTiles, g => g.PostDraw);
            ModLoader.BuildGlobalHook(ref HookSpecialDraw, globalTiles, g => g.SpecialDraw);
            ModLoader.BuildGlobalHook(ref HookRandomUpdate, globalTiles, g => g.RandomUpdate);
            ModLoader.BuildGlobalHook(ref HookTileFrame, globalTiles, g => g.TileFrame);
            ModLoader.BuildGlobalHook(ref HookCanPlace, globalTiles, g => g.CanPlace);
            ModLoader.BuildGlobalHook(ref HookAdjTiles, globalTiles, g => g.AdjTiles);
            ModLoader.BuildGlobalHook(ref HookRightClick, globalTiles, g => g.RightClick);
            ModLoader.BuildGlobalHook(ref HookMouseOver, globalTiles, g => g.MouseOver);
            ModLoader.BuildGlobalHook(ref HookMouseOverFar, globalTiles, g => g.MouseOverFar);
            ModLoader.BuildGlobalHook(ref HookAutoSelect, globalTiles, g => g.AutoSelect);
            ModLoader.BuildGlobalHook(ref HookPreHitWire, globalTiles, g => g.PreHitWire);
            ModLoader.BuildGlobalHook(ref HookHitWire, globalTiles, g => g.HitWire);
            ModLoader.BuildGlobalHook(ref HookSlope, globalTiles, g => g.Slope);
            ModLoader.BuildGlobalHook(ref HookFloorVisuals, globalTiles, g => g.FloorVisuals);
            ModLoader.BuildGlobalHook(ref HookChangeWaterfallStyle, globalTiles, g => g.ChangeWaterfallStyle);
            ModLoader.BuildGlobalHook(ref HookSaplingGrowthType, globalTiles, g => g.SaplingGrowthType);
            ModLoader.BuildGlobalHook(ref HookPlaceInWorld, globalTiles, g => g.PlaceInWorld);

            if (!unloading)
            {
                loaded = true;
            }
        }
コード例 #23
0
ファイル: Mod.cs プロジェクト: Unowndeveloper/tModLoader
 public void RegisterHotKey(string name, string defaultKey)
 {
     ModLoader.RegisterHotKey(this, name, defaultKey);
 }
コード例 #24
0
 //internal static void AddSettingsMenuButtons(Main main, int selectedMenu, string[] buttonNames, float[] buttonScales, int[] virticalSpacing, ref int offY, ref int spacing, ref int buttonIndex, ref int numButtons)
 //{
 //	buttonIndex++;
 //	numButtons++;
 //	buttonNames[buttonIndex] = "Mod " + Lang.menu[66];
 //	if (selectedMenu == buttonIndex)
 //	{
 //		Main.PlaySound(10, -1, -1, 1);
 //		Main.menuMode = modControlsID;
 //	}
 //	for (int k = 0; k < numButtons; k++)
 //	{
 //		buttonScales[k] = 0.73f;
 //		virticalSpacing[k] = 0;
 //	}
 //	virticalSpacing[numButtons - 1] = 8;
 //}
 //add to end of if else chain of Main.menuMode in Terraria.Main.DrawMenu
 //Interface.ModLoaderMenus(this, this.selectedMenu, array9, array7, ref num, ref num3, ref num4);
 internal static void ModLoaderMenus(Main main, int selectedMenu, string[] buttonNames, float[] buttonScales, int[] buttonVerticalSpacing, ref int offY, ref int spacing, ref int numButtons)
 {
     if (Main.menuMode == modsMenuID)
     {
         Main.MenuUI.SetState(modsMenu);
         Main.menuMode = 888;
     }
     else if (Main.menuMode == modSourcesID)
     {
         Main.MenuUI.SetState(modSources);
         Main.menuMode = 888;
     }
     else if (Main.menuMode == loadModsID)
     {
         Main.MenuUI.SetState(loadMods);
         Main.menuMode = 888;
         ModLoader.Load();
     }
     else if (Main.menuMode == buildModID)
     {
         Main.MenuUI.SetState(buildMod);
         Main.menuMode = 888;
         ModLoader.BuildMod();
     }
     else if (Main.menuMode == buildAllModsID)
     {
         Main.MenuUI.SetState(buildMod);
         Main.menuMode = 888;
         ModLoader.BuildAllMods();
     }
     else if (Main.menuMode == errorMessageID)
     {
         Main.MenuUI.SetState(errorMessage);
         Main.menuMode = 888;
     }
     else if (Main.menuMode == reloadModsID)
     {
         ModLoader.Reload();
     }
     else if (Main.menuMode == modBrowserID)
     {
         Main.MenuUI.SetState(modBrowser);
         Main.menuMode = 888;
     }
     else if (Main.menuMode == modInfoID)
     {
         Main.MenuUI.SetState(modInfo);
         Main.menuMode = 888;
     }
     else if (Main.menuMode == downloadModID)
     {
         Main.MenuUI.SetState(downloadMod);
         Main.menuMode = 888;
     }
     else if (Main.menuMode == managePublishedID)
     {
         Main.MenuUI.SetState(managePublished);
         Main.menuMode = 888;
     }
     //else if (Main.menuMode == modControlsID)
     //{
     //	UIModControls.ModLoaderMenus(main, selectedMenu, buttonNames, buttonScales, buttonVerticalSpacing, ref offY, ref spacing, ref numButtons);
     //}
     else if (Main.menuMode == updateMessageID)
     {
         Main.MenuUI.SetState(updateMessage);
         Main.menuMode = 888;
     }
     else if (Main.menuMode == infoMessageID)
     {
         Main.MenuUI.SetState(infoMessage);
         Main.menuMode = 888;
     }
     else if (Main.menuMode == enterPassphraseMenuID)
     {
         Main.MenuUI.SetState(enterPassphraseMenu);
         Main.menuMode = 888;
     }
 }
コード例 #25
0
ファイル: Mod.cs プロジェクト: Unowndeveloper/tModLoader
 internal void SetupContent()
 {
     foreach (ModItem item in items.Values)
     {
         Main.itemTexture[item.item.type] = ModLoader.GetTexture(item.texture);
         Main.itemName[item.item.type]    = item.item.name;
         EquipLoader.SetSlot(item.item);
         item.SetDefaults();
         DrawAnimation animation = item.GetAnimation();
         if (animation != null)
         {
             Main.RegisterItemAnimation(item.item.type, animation);
             ItemLoader.animations.Add(item.item.type);
         }
         if (item.flameTexture.Length > 0)
         {
             Main.itemFlameTexture[item.item.type] = ModLoader.GetTexture(item.flameTexture);
         }
     }
     foreach (ModDust dust in dusts.Values)
     {
         dust.SetDefaults();
     }
     foreach (ModTile tile in tiles.Values)
     {
         Main.tileTexture[tile.Type] = ModLoader.GetTexture(tile.texture);
         TileLoader.SetDefaults(tile);
     }
     foreach (GlobalTile globalTile in globalTiles.Values)
     {
         globalTile.SetDefaults();
     }
     foreach (ModWall wall in walls.Values)
     {
         Main.wallTexture[wall.Type] = ModLoader.GetTexture(wall.texture);
         wall.SetDefaults();
     }
     foreach (GlobalWall globalWall in globalWalls.Values)
     {
         globalWall.SetDefaults();
     }
     foreach (ModProjectile projectile in projectiles.Values)
     {
         Main.projectileTexture[projectile.projectile.type] = ModLoader.GetTexture(projectile.texture);
         Main.projFrames[projectile.projectile.type]        = 1;
         projectile.SetDefaults();
         if (projectile.projectile.hostile)
         {
             Main.projHostile[projectile.projectile.type] = true;
         }
         if (projectile.projectile.aiStyle == 7)
         {
             Main.projHook[projectile.projectile.type] = true;
         }
     }
     foreach (ModNPC npc in npcs.Values)
     {
         Main.npcTexture[npc.npc.type] = ModLoader.GetTexture(npc.texture);
         Main.npcName[npc.npc.type]    = npc.npc.name;
         npc.SetDefaults();
         if (npc.npc.lifeMax > 32767 || npc.npc.boss)
         {
             Main.npcLifeBytes[npc.npc.type] = 4;
         }
         else if (npc.npc.lifeMax > 127)
         {
             Main.npcLifeBytes[npc.npc.type] = 2;
         }
         else
         {
             Main.npcLifeBytes[npc.npc.type] = 1;
         }
     }
     foreach (ModMountData modMountData in mountDatas.Values)
     {
         Mount.MountData temp = modMountData.mountData;
         temp.modMountData = modMountData;
         MountLoader.SetupMount(modMountData.mountData);
         Mount.mounts[modMountData.Type] = temp;
     }
     foreach (ModBuff buff in buffs.Values)
     {
         Main.buffTexture[buff.Type] = ModLoader.GetTexture(buff.texture);
         Main.buffName[buff.Type]    = buff.Name;
         buff.SetDefaults();
     }
 }
コード例 #26
0
        // This method is split so that the local variables aren't held by the GC when reloading
        internal static bool SyncClientMods(BinaryReader reader, out bool needsReload)
        {
            AllowVanillaClients = reader.ReadBoolean();
            Logging.tML.Info($"Server reports AllowVanillaClients set to {AllowVanillaClients}");

            Main.statusText = Language.GetTextValue("tModLoader.MPSyncingMods");
            var clientMods = ModLoader.Mods;
            var modFiles   = ModOrganizer.FindMods();

            needsReload = false;
            downloadQueue.Clear();
            pendingConfigs.Clear();
            var syncSet     = new HashSet <string>();
            var blockedList = new List <ModHeader>();

            int n = reader.ReadInt32();

            for (int i = 0; i < n; i++)
            {
                var header = new ModHeader(reader.ReadString(), new Version(reader.ReadString()), reader.ReadBytes(20), reader.ReadBoolean());
                syncSet.Add(header.name);

                int configCount = reader.ReadInt32();
                for (int c = 0; c < configCount; c++)
                {
                    pendingConfigs.Add(new NetConfig(header.name, reader.ReadString(), reader.ReadString()));
                }

                var clientMod = clientMods.SingleOrDefault(m => m.Name == header.name);
                if (clientMod != null && header.Matches(clientMod.File))
                {
                    continue;
                }

                needsReload = true;

                var localVersions = modFiles.Where(m => m.Name == header.name).ToArray();
                var matching      = Array.Find(localVersions, mod => header.Matches(mod.modFile));
                if (matching != null)
                {
                    matching.Enabled = true;
                    continue;
                }

                // overwrite an existing version of the mod if there is one
                if (localVersions.Length > 0)
                {
                    header.path = localVersions[0].modFile.path;
                }

                if (downloadModsFromServers && (header.signed || !onlyDownloadSignedMods))
                {
                    downloadQueue.Enqueue(header);
                }
                else
                {
                    blockedList.Add(header);
                }
            }

            foreach (var mod in clientMods)
            {
                if (mod.Side == ModSide.Both && !syncSet.Contains(mod.Name))
                {
                    ModLoader.DisableMod(mod.Name);
                    needsReload = true;
                }
            }

            if (blockedList.Count > 0)
            {
                var msg = Language.GetTextValue("tModLoader.MPServerModsCantDownload");
                msg += downloadModsFromServers
                                        ? Language.GetTextValue("tModLoader.MPServerModsCantDownloadReasonSigned")
                                        : Language.GetTextValue("tModLoader.MPServerModsCantDownloadReasonAutomaticDownloadDisabled");
                msg += ".\n" + Language.GetTextValue("tModLoader.MPServerModsCantDownloadChangeSettingsHint") + "\n";
                foreach (var mod in blockedList)
                {
                    msg += "\n    " + mod;
                }

                Logging.tML.Warn(msg);
                Interface.errorMessage.Show(msg, 0);
                return(false);
            }

            // ready to connect, apply configs. Config manager will apply the configs on reload automatically
            if (!needsReload)
            {
                foreach (var pendingConfig in pendingConfigs)
                {
                    JsonConvert.PopulateObject(pendingConfig.json, ConfigManager.GetConfig(pendingConfig), ConfigManager.serializerSettingsCompact);
                }

                if (ConfigManager.AnyModNeedsReload())
                {
                    needsReload = true;
                }
                else
                {
                    foreach (var pendingConfig in pendingConfigs)
                    {
                        ConfigManager.GetConfig(pendingConfig).OnChanged();
                    }
                }
            }

            return(true);
        }
コード例 #27
0
ファイル: Mod.cs プロジェクト: Unowndeveloper/tModLoader
 public byte[] GetFileBytes(string name)
 {
     return(ModLoader.GetFileBytes(FileName(name)));
 }
コード例 #28
0
        internal static List <Mod> InstantiateMods(List <LocalMod> modsToLoad)
        {
            var modList = new List <LoadedMod>();

            foreach (var loading in modsToLoad)
            {
                if (!loadedMods.TryGetValue(loading.Name, out LoadedMod mod))
                {
                    mod = loadedMods[loading.Name] = new LoadedMod();
                }

                mod.SetMod(loading);
                modList.Add(mod);
            }

            RecalculateReferences();

            if (Debugger.IsAttached)
            {
                ModLoader.isModder = true;
                foreach (var mod in modList.Where(mod => mod.properties.editAndContinue && mod.CanEaC))
                {
                    mod.EnableEaC();
                }
            }
            if (ModLoader.alwaysLogExceptions)
            {
                ModCompile.ActivateExceptionReporting();
            }

            try
            {
                //load all the assemblies in parallel.
                Interface.loadMods.SetLoadStage("tModLoader.MSSandboxing", modsToLoad.Count);
                int i = 0;
                Parallel.ForEach(modList, mod =>
                {
                    Interface.loadMods.SetCurrentMod(i++, mod.Name);
                    mod.LoadAssemblies();
                });

                Interface.loadMods.SetLoadStage("tModLoader.MSInstantiating");
                //Assemblies must be loaded before any instantiation occurs to satisfy dependencies
                return(modList.Select(Instantiate).ToList());
            }
            catch (AggregateException ae)
            {
                ErrorLogger.LogMulti(ae.InnerExceptions.Select(e => new Action(() =>
                {
                    var mod = modList.Single(m => m.Name == (string)e.Data["mod"]);
                    ModLoader.DisableMod(mod.Name);
                    ErrorLogger.LogLoadingError(mod.Name, mod.modFile.tModLoaderVersion, e);
                })));
                Main.menuMode = Interface.errorMessageID;
                return(null);
            }
            catch (Exception e)
            {
                var mod = modList.Single(m => m.Name == (string)e.Data["mod"]);
                ModLoader.DisableMod(mod.Name);
                ErrorLogger.LogLoadingError(mod.Name, mod.modFile.tModLoaderVersion, e);
                Main.menuMode = Interface.errorMessageID;
                return(null);
            }
        }
コード例 #29
0
ファイル: Mod.cs プロジェクト: Unowndeveloper/tModLoader
 public Texture2D GetTexture(string name)
 {
     return(ModLoader.GetTexture(FileName(name)));
 }
コード例 #30
0
ファイル: Interface.cs プロジェクト: immortalcatz/tModLoader
        internal static void ServerModMenu()
        {
            bool exit = false;

            while (!exit)
            {
                Console.WriteLine("Terraria Server " + Main.versionNumber2 + " - " + ModLoader.versionedName);
                Console.WriteLine();
                TmodFile[] mods = ModLoader.FindMods();
                for (int k = 0; k < mods.Length; k++)
                {
                    BuildProperties properties = BuildProperties.ReadModFile(mods[k]);
                    string          name       = properties.displayName;
                    name = mods[k].name;
                    string line = (k + 1) + "\t\t" + name + "(";
                    line += (ModLoader.IsEnabled(mods[k]) ? "enabled" : "disabled") + ")";
                    Console.WriteLine(line);
                }
                if (mods.Length == 0)
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine($"No mods were found in: \"{ModLoader.ModPath}\"\nIf you are running a dedicated server, you may wish to use the 'modpath' command line switch or server config setting to specify a custom mods directory.\n");
                    Console.ResetColor();
                }
                Console.WriteLine("e\t\tEnable All");
                Console.WriteLine("d\t\tDisable All");
                Console.WriteLine("r\t\tReload and return to world menu");
                Console.WriteLine("Type a number to switch between enabled/disabled");
                Console.WriteLine();
                Console.WriteLine("Type a command: ");
                string command = Console.ReadLine();
                if (command == null)
                {
                    command = "";
                }
                command = command.ToLower();
                Console.Clear();
                if (command == "e")
                {
                    foreach (TmodFile mod in mods)
                    {
                        ModLoader.EnableMod(mod);
                    }
                }
                else if (command == "d")
                {
                    foreach (TmodFile mod in mods)
                    {
                        ModLoader.DisableMod(mod);
                    }
                }
                else if (command == "r")
                {
                    Console.WriteLine("Unloading mods...");
                    ModLoader.Unload();
                    ModLoader.do_Load(null);
                    exit = true;
                }
                else
                {
                    int value;
                    if (Int32.TryParse(command, out value))
                    {
                        value--;
                        if (value >= 0 && value < mods.Length)
                        {
                            ModLoader.SetModActive(mods[value], !ModLoader.IsEnabled(mods[value]));
                        }
                    }
                }
            }
        }
コード例 #31
0
ファイル: EquipLoader.cs プロジェクト: xenatapes/tModLoader
 internal static void ResizeAndFillArrays()
 {
     Array.Resize(ref Main.armorHeadLoaded, nextEquip[EquipType.Head]);
     Array.Resize(ref Main.armorBodyLoaded, nextEquip[EquipType.Body]);
     Array.Resize(ref Main.armorLegsLoaded, nextEquip[EquipType.Legs]);
     Array.Resize(ref Main.accHandsOnLoaded, nextEquip[EquipType.HandsOn]);
     Array.Resize(ref Main.accHandsOffLoaded, nextEquip[EquipType.HandsOff]);
     Array.Resize(ref Main.accBackLoaded, nextEquip[EquipType.Back]);
     Array.Resize(ref Main.accFrontLoaded, nextEquip[EquipType.Front]);
     Array.Resize(ref Main.accShoesLoaded, nextEquip[EquipType.Shoes]);
     Array.Resize(ref Main.accWaistLoaded, nextEquip[EquipType.Waist]);
     Array.Resize(ref Main.wingsLoaded, nextEquip[EquipType.Wings]);
     Array.Resize(ref Main.accShieldLoaded, nextEquip[EquipType.Shield]);
     Array.Resize(ref Main.accNeckLoaded, nextEquip[EquipType.Neck]);
     Array.Resize(ref Main.accFaceLoaded, nextEquip[EquipType.Face]);
     Array.Resize(ref Main.accballoonLoaded, nextEquip[EquipType.Balloon]);
     foreach (EquipType type in EquipTypes)
     {
         for (int k = GetNumVanilla(type); k < nextEquip[type]; k++)
         {
             GetLoadedArray(type)[k] = true;
         }
     }
     Array.Resize(ref Main.armorHeadTexture, nextEquip[EquipType.Head]);
     Array.Resize(ref Main.armorBodyTexture, nextEquip[EquipType.Body]);
     Array.Resize(ref Main.femaleBodyTexture, nextEquip[EquipType.Body]);
     Array.Resize(ref Main.armorArmTexture, nextEquip[EquipType.Body]);
     Array.Resize(ref Main.armorLegTexture, nextEquip[EquipType.Legs]);
     Array.Resize(ref Main.accHandsOnTexture, nextEquip[EquipType.HandsOn]);
     Array.Resize(ref Main.accHandsOffTexture, nextEquip[EquipType.HandsOff]);
     Array.Resize(ref Main.accBackTexture, nextEquip[EquipType.Back]);
     Array.Resize(ref Main.accFrontTexture, nextEquip[EquipType.Front]);
     Array.Resize(ref Main.accShoesTexture, nextEquip[EquipType.Shoes]);
     Array.Resize(ref Main.accWaistTexture, nextEquip[EquipType.Waist]);
     Array.Resize(ref Main.wingsTexture, nextEquip[EquipType.Wings]);
     Array.Resize(ref Main.accShieldTexture, nextEquip[EquipType.Shield]);
     Array.Resize(ref Main.accNeckTexture, nextEquip[EquipType.Neck]);
     Array.Resize(ref Main.accFaceTexture, nextEquip[EquipType.Face]);
     Array.Resize(ref Main.accBalloonTexture, nextEquip[EquipType.Balloon]);
     foreach (EquipType type in EquipTypes)
     {
         foreach (var entry in equipTextures[type])
         {
             int          slot    = entry.Key;
             EquipTexture texture = entry.Value;
             GetTextureArray(type)[slot] = ModLoader.GetTexture(texture.Texture);
             if (type == EquipType.Body)
             {
                 Main.femaleBodyTexture[slot] = ModLoader.GetTexture(femaleTextures[slot]);
                 Main.armorArmTexture[slot]   = ModLoader.GetTexture(armTextures[slot]);
             }
         }
     }
     Array.Resize(ref Item.headType, nextEquip[EquipType.Head]);
     foreach (var entry in slotToId[EquipType.Head])
     {
         Item.headType[entry.Key] = entry.Value;
     }
     Array.Resize(ref Item.bodyType, nextEquip[EquipType.Body]);
     foreach (var entry in slotToId[EquipType.Body])
     {
         Item.bodyType[entry.Key] = entry.Value;
     }
     Array.Resize(ref Item.legType, nextEquip[EquipType.Legs]);
     foreach (var entry in slotToId[EquipType.Legs])
     {
         Item.legType[entry.Key] = entry.Value;
     }
 }