Posted: Sat Jan 04, 2020 9:31 pm Post subject:
TSMapPreviewToolIran
This is my map preview tool. It uses the in-game renderer and a command-line tool. Run TSMapPreviewToolIran.exe.
Uses cnc-ddraw GDI renderer with 14000x6500 resolution. A modified ts-spawner is used to spawn into the game and automatically grab a screenshot and then exit the game. The command-line tools opens the screenshots, gets map size from map INI and crops out map size roughly.
Spawner loads spawnmap.ini. Spawn.ini has two new options:
DoScreenshotOnceThenExit=Yes/No
DoScreenshotOnceThenExitFrame=0 (on which frame do we screenshot and then exit?)
The command line tool has two arguments. First argument is ShowSpawnIndicators/DontShowSpawnIndicator.s This will copy spawn_indicator.ini in the folder into spawnmap.ini. The idea is that you modify the MCV to show a spawn indicator and place this mod inside spawn_indicator.ini (you need to do this yourself).
Second argument is the map file to make a screenshot of, if this arg is missing then spawnmap.ini is used.
Note: this should also work with savegames, you might need to set DoScreenshotOnceThenExitFrame=-1 then though.
using ImageMagick;
using IniParser;
using IniParser.Model;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TSMapPreviewToolIran
{
class Program
{
static void Main(string[] args)
{
if (args.Length > 0 && args[0] == "ShowSpawnIndicators")
{
string[] Lines = File.ReadAllLines("spawn_indicators.ini");
File.AppendAllLines("spawnmap.ini", Lines);
}
var parser = new FileIniDataParser();
IniData data = parser.ReadFile("spawnmap.ini");
//string MapSize = data["Map"]["Size"];
//Left,Top,Width,Height
string LocalSize = data["Map"]["LocalSize"];
string[] split = LocalSize.Split(',');
int left = int.Parse(split[0]);
int top = int.Parse(split[1]);
int width = int.Parse(split[2]);
int height = int.Parse(split[3]);
int previewWidth = (width - left) * 48;
int previewHeight = (height - top) * 24;
var process = Process.Start("mappreview.exe", "-SPAWN");
process.WaitForExit();
var image = new MagickImage("SCRN0000.pcx");
image.Crop(new MagickGeometry(0, 20, previewWidth, previewHeight));
image.ToBitmap().Save("out.png");
}
}
}
Custom ts-patches for this will be posted on github.com/cncnet/ts-patches when I do a pull request. Last edited by Iran on Tue Feb 04, 2020 10:13 pm; edited 1 time in total QUICK_EDIT
As the map sizes are a variable, so should be the resolution in sun.ini or ddraw parameter. Theoretical max map size is 511x1 or 1x511. With a cell size in TS being 48x24, max width needed is 24528 and can round it off for sidebar to 25000. Max height needed is 511*24 = 12264, rounding it to 12300. But we can't have a resolution of 25000x12300 as the game crashes at about 95275000 area value (w*h) at the extreme. So, the resolution could use the map size multiplied by 48x24 and with some buffer for the sidebar and topbar. QUICK_EDIT
1 cell width maps are not practical and have problems with the game. Attaching 492x20 and 20x492 sized maps. You can create such maps yourself with patched FinalSun for TSClient.
Game limit is W+H <= 512. FinalSun crashes at about W*H more than 43500. Included a map of size 256x256 that crashes FinalSun. If you get time can you check the problem with larger area maps in FinalSun. Can make blank maps and its [Map] Size can be changed in a text editor to get different sized maps also.
The patches for this have now been merged with github.com/cncnet/ts-patches .
This will enable
Spawner loads spawnmap.ini. Spawn.ini has two new options:
DoScreenshotOnceThenExit=Yes/No
DoScreenshotOnceThenExitFrame=0 (on which frame do we screenshot and then exit?)
Use it in combination with the C# code from my first post. QUICK_EDIT
Is resolution fixed still or varies with map size? May be the client would have to check renderer(s) or sun.ini, change the resolution and restore current resolution after screenshot. QUICK_EDIT
Users might be using cnc-ddraw or ts-ddraw or may be using resolution from sun.ini. Those renderers currently use ddraw.ini with or without resolution override. Wouldn't it be better in this case to feed the needed resolution directly to the game.exe so that none of the INI files need to be altered? QUICK_EDIT
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum