From 2939e3598c876fbf677a672582a3ca3f7717f23b Mon Sep 17 00:00:00 2001 From: JavidPack Date: Sat, 20 Jul 2019 01:34:53 -0600 Subject: [PATCH] v0.2, update to tModLoader 0.11.2.2, much smarter approach. --- LargeWorldEnabler.cs | 65 ++++++++++++++++++++------------- LargeWorldEnabler.csproj | 67 ++++------------------------------ Properties/launchSettings.json | 14 +++++++ build.txt | 4 +- description.txt | 2 - 5 files changed, 64 insertions(+), 88 deletions(-) create mode 100644 Properties/launchSettings.json diff --git a/LargeWorldEnabler.cs b/LargeWorldEnabler.cs index 24e9f6f..bb44c9d 100644 --- a/LargeWorldEnabler.cs +++ b/LargeWorldEnabler.cs @@ -1,46 +1,61 @@ using Microsoft.Xna.Framework.Graphics; using System; +using System.Reflection; using Terraria; using Terraria.Map; using Terraria.ModLoader; namespace LargeWorldEnabler { - // TODO: Fix map drawing in tModLoader. (bounds, but maybe also something else apparently) public class LargeWorldEnabler : Mod { - public LargeWorldEnabler() - { - Properties = new ModProperties(); + FieldInfo WorldGen_lastMaxTilesX; + FieldInfo WorldGen_lastMaxTilesY; + + public override void Load() { + //if (ModLoader.version < new Version(0, 10)) + //{ + // throw new Exception("\nThis mod uses functionality only present in the latest tModLoader versions. Please update tModLoader to use this mod\n\n"); + //} + + On.Terraria.WorldGen.clearWorld += WorldGen_clearWorld; + + WorldGen_lastMaxTilesX = typeof(WorldGen).GetField("lastMaxTilesX", BindingFlags.Static | BindingFlags.NonPublic); + WorldGen_lastMaxTilesY = typeof(WorldGen).GetField("lastMaxTilesY", BindingFlags.Static | BindingFlags.NonPublic); } - public override void Load() - { - // Older versions don't have the correct variables. - if (ModLoader.version < new Version(0, 10)) - { - throw new Exception("\nThis mod uses functionality only present in the latest tModLoader versions. Please update tModLoader to use this mod\n\n"); - } + private void WorldGen_clearWorld(On.Terraria.WorldGen.orig_clearWorld orig) { + int lastMaxTilesX = (int)WorldGen_lastMaxTilesX.GetValue(null); + int lastMaxTilesY = (int)WorldGen_lastMaxTilesY.GetValue(null); - //8400 x 2400 -- Actual dimensions of tile array - Main.maxTilesX = 16800; - Main.maxTilesY = 4800; + // TODO: investigate cpu/ram trade-off for reducing this later when regular-sized worlds loaded. + if (Main.maxTilesX > 8400 && Main.maxTilesX > lastMaxTilesX || Main.maxTilesY > 2400 && Main.maxTilesY > lastMaxTilesY) { + // Goal: Increase limits, don't decrease anything lower than normal max for compatibility. - // Map render targets. -- ingame map number of images to write to. The textures themselves - Main.mapTargetX = 10; // change that 4 in vanilla to target-x - Main.mapTargetY = 4; // change that - Main.instance.mapTarget = new RenderTarget2D[Main.mapTargetX, Main.mapTargetY]; + // TODO: dynamically change mapTargetX and Y to support any dimensions. (simple division.) + // Map render targets. -- ingame map number of images to write to. The textures themselves + Main.mapTargetX = 10; // change that 4 in vanilla to target-x + Main.mapTargetY = 4; // change that + Main.instance.mapTarget = new RenderTarget2D[Main.mapTargetX, Main.mapTargetY]; - // Individual map tiles - Main.Map = new WorldMap(Main.maxTilesX, Main.maxTilesY); + int intendedMaxX = Math.Max(Main.maxTilesX + 1, 8401); + int intendedMaxY = Math.Max(Main.maxTilesY + 1, 2401); - // Space for more tiles -- Actual tiles - Main.tile = new Tile[Main.maxTilesX + 1, Main.maxTilesY + 1]; - // Color for each tile + // Individual map tiles + Main.Map = new WorldMap(intendedMaxX, intendedMaxY); - Main.initMap = new bool[Main.mapTargetX, Main.mapTargetY]; - Main.mapWasContentLost = new bool[Main.mapTargetX, Main.mapTargetY]; + // Space for more tiles -- Actual tiles + Main.tile = new Tile[intendedMaxX, intendedMaxY]; + // Color for each tile + Main.initMap = new bool[Main.mapTargetX, Main.mapTargetY]; + Main.mapWasContentLost = new bool[Main.mapTargetX, Main.mapTargetY]; + } + orig(); + + //8400 x 2400 -- Actual dimensions of tile array + //Main.maxTilesX = 16800; + //Main.maxTilesY = 4800; // Initialized later, not needed. //RemoteClient.TileSections = new bool[Main.maxTilesX / 200 + 1, Main.maxTilesY / 150 + 1]; diff --git a/LargeWorldEnabler.csproj b/LargeWorldEnabler.csproj index 7737e83..ba7d21d 100644 --- a/LargeWorldEnabler.csproj +++ b/LargeWorldEnabler.csproj @@ -1,64 +1,13 @@ - - - + + + - Debug - AnyCPU - {79E45A3D-A6F7-4B9D-9B2C-D3ED099C2E2D} - Exe - Properties - LargeWorldEnabler LargeWorldEnabler - v4.5.2 - 512 - true + net45 + x86 + latest - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - - {3996d5fa-6e59-4fe4-9f2b-40eeef9645d5} - Terraria - - - - - - - - \ No newline at end of file diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json new file mode 100644 index 0000000..14574ad --- /dev/null +++ b/Properties/launchSettings.json @@ -0,0 +1,14 @@ +{ + "profiles": { + "Terraria": { + "commandName": "Executable", + "executablePath": "$(tMLPath)", + "workingDirectory": "$(TerrariaSteamPath)" + }, + "TerrariaServer": { + "commandName": "Executable", + "executablePath": "$(tMLServerPath)", + "workingDirectory": "$(TerrariaSteamPath)" + } + } +} \ No newline at end of file diff --git a/build.txt b/build.txt index 191a895..5af154a 100644 --- a/build.txt +++ b/build.txt @@ -1,8 +1,8 @@ author = jopojelly -version = 0.1.2 +version = 0.2 displayName = Large World Enabler homepage = http://forums.terraria.org/index.php?threads/large-world-enabler.47751/ hideCode = false hideResources = false includeSource = true -buildIgnore = .vs\*, Properties\*, *.csproj, *.user, obj\*, bin\*, *.config, lib\*, .gitignore +buildIgnore = .vs\*, Properties\*, *.csproj, *.user, *.config, .gitignore diff --git a/description.txt b/description.txt index a8cfc27..5c51f4d 100644 --- a/description.txt +++ b/description.txt @@ -3,5 +3,3 @@ Note that with mods loaded, it may not be possible to load a world that large due to memory limits. I recommend a 16800x1200 or 16800x2400 world as worlds that are taller than Large worlds tend to be boring. Generate a world to use with this mod using TerraCustom. TerraCustom will load tmodloader mods, so you don't have to worry about missing out on mod biomes. (http://forums.terraria.org/index.php?threads/terracustom-for-1-3.35346/) - -This mod is also necessary if loading a world generated using Alternate Dimensions Mod (WIP) that is more than 8400 tiles in width.