An API to generate the Rust server map image

Supported Games
GameServerKingsGameServerKings

Allows creating an image of the current map. The map image can be split into multiple sections with varying number of rows and columns. Custom map images can be created by passing in custom render settings. All images are saved to rusts file storage and only need to be generated once per wipe. Map renders will need to created every restart. Overlays can be added to the map images. There is a built in default overlap map called "Icons". This map image contains an icon for each monument and each icon can be changed in the config.

This plugin is only for generating a PNG, JPG image of the map. It does not do anything to the in game client map

Example Images

Current Version Image

Version 1 Image

Icons Image

Configuration

{
  "Map Colors Version": "Current",
  "Starting Splits (Rows x Columns)": [
    "2x2",
    "3x3",
    "4x4"
  ],
  "IconSettings": {
    "Harbor": {
      "Width": 70,
      "Height": 70,
      "ImageUrl": "https://i.imgur.com/ND4c70v.png",
      "Show": true
    },
    "Giant Excavator Pit": {
      "Width": 70,
      "Height": 70,
      "ImageUrl": "https://i.imgur.com/hmUKFwS.png",
      "Show": true
    },
    "Junkyard": {
      "Width": 70,
      "Height": 70,
      "ImageUrl": "https://i.imgur.com/V8D4ZGc.png",
      "Show": true
    },
    "Launch Site": {
      "Width": 70,
      "Height": 70,
      "ImageUrl": "https://i.imgur.com/gjdynsc.png",
      "Show": true
    },
    "Water Treatment Plant": {
      "Width": 70,
      "Height": 70,
      "ImageUrl": "https://i.imgur.com/5L2Gdag.png",
      "Show": true
    },
    "Military Tunnel": {
      "Width": 70,
      "Height": 70,
      "ImageUrl": "https://i.imgur.com/6RwXvC2.png",
      "Show": true
    },
    "Airfield": {
      "Width": 70,
      "Height": 70,
      "ImageUrl": "https://i.imgur.com/KhQXhIs.png",
      "Show": true
    },
    "Power Plant": {
      "Width": 70,
      "Height": 70,
      "ImageUrl": "https://i.imgur.com/ZxqiBc6.png",
      "Show": true
    },
    "Train Yard": {
      "Width": 70,
      "Height": 70,
      "ImageUrl": "https://i.imgur.com/wVifXqr.png",
      "Show": true
    },
    "Outpost": {
      "Width": 70,
      "Height": 70,
      "ImageUrl": "https://i.imgur.com/hb7JZ9i.png",
      "Show": true
    },
    "Bandit Camp": {
      "Width": 70,
      "Height": 70,
      "ImageUrl": "https://i.imgur.com/cIR4YOt.png",
      "Show": true
    },
    "Sewer Branch": {
      "Width": 70,
      "Height": 70,
      "ImageUrl": "https://i.imgur.com/PbKZQdZ.png",
      "Show": true
    },
    "HQM Quarry": {
      "Width": 70,
      "Height": 70,
      "ImageUrl": "https://i.imgur.com/bGFogbM.png",
      "Show": true
    },
    "Satellite Dish": {
      "Width": 70,
      "Height": 70,
      "ImageUrl": "https://i.imgur.com/XwSpCJY.png",
      "Show": true
    },
    "The Dome": {
      "Width": 70,
      "Height": 70,
      "ImageUrl": "https://i.imgur.com/mPRgBF2.png",
      "Show": true
    },
    "Sulfur Quarry": {
      "Width": 70,
      "Height": 70,
      "ImageUrl": "https://i.imgur.com/bGFogbM.png",
      "Show": true
    },
    "Stone Quarry": {
      "Width": 70,
      "Height": 70,
      "ImageUrl": "https://i.imgur.com/bGFogbM.png",
      "Show": true
    },
    "Power Sub Station": {
      "Width": 70,
      "Height": 70,
      "ImageUrl": "https://i.imgur.com/LQUknms.png",
      "Show": false
    },
    "Water Well": {
      "Width": 70,
      "Height": 70,
      "ImageUrl": "https://i.imgur.com/TASWRD0.png",
      "Show": true
    },
    "Abandoned Cabins": {
      "Width": 70,
      "Height": 70,
      "ImageUrl": "https://i.imgur.com/xigwDcW.png",
      "Show": true
    },
    "Wild Swamp": {
      "Width": 70,
      "Height": 70,
      "ImageUrl": "https://i.imgur.com/2tcTYKA.png",
      "Show": true
    },
    "Abandoned Supermarket": {
      "Width": 70,
      "Height": 70,
      "ImageUrl": "https://i.imgur.com/ZyP2W9F.png",
      "Show": true
    },
    "Mining Outpost": {
      "Width": 70,
      "Height": 70,
      "ImageUrl": "https://i.imgur.com/C0acqvj.png",
      "Show": true
    },
    "Oxum's Gas Station": {
      "Width": 70,
      "Height": 70,
      "ImageUrl": "https://i.imgur.com/oW1bDdF.png",
      "Show": true
    },
    "Cave": {
      "Width": 70,
      "Height": 70,
      "ImageUrl": "https://i.imgur.com/ByKJj9C.png",
      "Show": true
    },
    "Lighthouse": {
      "Width": 70,
      "Height": 70,
      "ImageUrl": "https://i.imgur.com/r5vbzhm.png",
      "Show": true
    },
    "Large Oil Rig": {
      "Width": 70,
      "Height": 70,
      "ImageUrl": "https://i.imgur.com/AAhZO7k.png",
      "Show": true
    },
    "Oil Rig": {
      "Width": 70,
      "Height": 70,
      "ImageUrl": "https://i.imgur.com/AAhZO7k.png",
      "Show": true
    }
  },
  "Custom Icons": [
    {
      "XPos": 0.0,
      "ZPos": 0.0,
      "Width": 200,
      "Height": 200,
      "ImageUrl": "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png",
      "Show": false
    }
  ]
}

Map Colors Version

Version1 - The map colors before the 10/2020 update
Current - The current map colors

Commands

rma_regenerate - removes the existing maps from file storage and regenerates them.This is useful when you change the overlay in the config. This is an admin only command.

rma_upload - uploads the map image to imgur. Requires ImgurApi plugin loaded and configured

Linux Users

This plugin requires LibGDIPlus to be installed on your system.

sudo apt install libgdiplus

Afterwards restart your system for the changes to take effect

Developer API

Allows developers to use images generated by the plugin or to create their own custom image

Input Data

Image Render Config

The image render config is used to configure the map render.Here you can override the default colors and values for the map render.The Render Config is passed in as a Hash<string, object> with the key being the field name and the value being the field value.

StartColor (Vector3) new Vector3(0.324313372f, 0.397058845f, 0.195609868f)
WaterColor (Vector4) new Vector4(0.269668937f, 0.4205476f, 0.5660378f, 1f)
GravelColor (Vector4) new Vector4(0.139705867f, 0.132621378f, 0.114024632f, 0.372f)
DirtColor (Vector4) new Vector4(0.322227329f, 0.375f, 0.228860289f, 1f)
SandColor (Vector4) new Vector4(1f, 0.8250507f, 0.448529422f, 1f)
GrassColor (Vector4) new Vector4(0.4509804f, 0.5529412f, 0.270588249f, 1f)
ForestColor (Vector4) new Vector4(0.5529412f, 0.440000027f, 0.270588249f, 1f)
RockColor (Vector4) new Vector4(0.42344287f, 0.4852941f, 0.314013839f, 1f)
SnowColor (Vector4) new Vector4(0.8088235f, 0.8088235f, 0.8088235f, 1f)
PebbleColor (Vector4) new Vector4(0.121568628f, 0.419607848f, 0.627451f, 1f)
OffShoreColor (Vector4) new Vector4(0.166295841f, 0.259337664f, 0.3490566f, 1f)
SunDirection (Vector3) Vector3.Normalize(new Vector3(0.95f, 2.87f, 2.37f))
Half (Vector3) new Vector3(0.5f, 0.5f, 0.5f)
WaterOffset (int) 0
SunPower (float) 0.5f
Brightness (float) 1f
Contrast (float) 0.87f
OceanWaterLevel (float) 0.0f
Version (string) supports the MapColorVersion enum as string

Overlay Config

The Overlay config allows custom image overlays to be added to the image after being rendered.The Overlay Config is passed in as a Hash<string, object> with the key being the field name and the value being the field value.If an image goes outside the bounds of the map it may be cutoff or not rendered at all.

XPos (int) - X pixel position on the map. Overlay image center will be at this position
YPos (int) - Y pixel on the map. Overlay image center will be at this position
Width (int) - Width of the image to be resized to
height (int) - Height of the image to be resized to
DebugName (string) - Used for error output when image is out of range
Image byte[] - byte[] of the image

Returned Data

Map Split

A map split contains all the images for a map image based on the number of rows and columns requested for the split.Map splits are returns as a Hash<string, Hash<string,object>>.The first hash key is the row and column of the split as "{row}x{column}" Ex. 5x4The inner hash contains a Map Section.

Map Section

A map section of a section of the map that based on the entered split.The sections consists of a Hash<string, object> with the following keys
image (byte[]) - byte[] of the image
width (int) - width of the image
height (int) - height of the image

Map Render

A map render consists of the raw color data before it is transformed into the image.The information from this hash can be passed into a Texture2D to turn the colors into an actual imageA map render is returned as a Hash<string, object> with the following keys
colors (UnityEngine.Color[]) - An array of colors for each pixel
width (int) - width of the image
height (int) - height of the image.

Hooks

Returns if the plugin is ready to be used

private bool IsReady()

Creates a new map render using the passed in config and overlay settings
mapName - name to save the render under. Used in methods to create map images and apply overlays
imageConfig - See Image Render Config under Input Data
Returns Hash<string, object> See Map Render under Returned Data

private void CreateRender(string mapName, Hash<string, object> imageConfig)

Creates a new map render from an existing render and applying the overlay config.
renderName - Existing render to apply the overlay to
newMapName - New render created with the overlay
overlay - List of Overlay configs. See Overlay Config under Input data
Returns Hash<string, object> See Map Render under Returned Data

private void CreateRenderOverlay(string renderName, string newMapName, List<Hash<string, object>> overlay)

Returns Hash<string, object> See Map Render under Returned data
mapName - the name of the render

private Hash<string, object> GetRender(string mapName)

Creates a single map image and returns it. This image is not saved
mapName - name of the map used to create the render
encodingMode - Jpg = 1 Png = 2
Returns Hash<string, Hash<string, object>> See Map Split under Input Data

private Hash<string, Hash<string, object>> CreateSingle(string mapName, int encodingMode)

Creates a split of the image based on the number of rows and columns and returns it. This image is not saved.
mapName - name of the map used to create the render
numRows - the number of rows you want the split to have
numCols - the number of cols you want the split to have
encodingMode - Jpg = 1 Png = 2
Returns Hash<string, Hash<string, object>> See Map Split under Input Data

private Hash<string, Hash<string,object>> CreateSplice(string mapName, int numRows, int numCols, int encodingMode)

Creates a single image and saves it to storage. Returns the created image data. Image is JPG encoded.
mapName - name of the map used to create the render
Returns Hash<string, Hash<string, object>> See Map Split under Input Data

private Hash<string, Hash<string, object>> SaveSingleImage(string mapName)

Create a split image and saves it to storage. Returns the created image data. Image is JPG encoded
mapName - name of the map used to create the render
numRows - how many rows the image should have
numCols - how many cols the image should have
Returns Hash<string, Hash<string, object>> See Map Split under Input Data

private Hash<string, Hash<string, object>> SaveSplitImage(string mapName, int numRows, int numCols)

Returns a list of all currently registered map render names

private List<string> GetRenderNames()

Returns a list of all saved splits for a specific render name

private List<string> GetSavedSplits(string mapName)

Returns a full map for the specified render name
Returns Hash<string, Hash<string, object>> See Map Section under Input Data

private Hash<string, object> GetFullMap(string mapName)

Returns a List<Hash<string, object>> list of Icon Overlays from the config.
Icon Overlay can be found in Overlay Config under the Input Data section

private List<Hash<string, object>> GetIconOverlay()

Returns if a map split has already been generated for the render name with the given rows and columns
mapName the name of the map render
numRows the number of rows in the render
numCols the number of columns in the render
Returns true if exists false otherwise

private bool HasSplit(string mapName, int numRows, int numCols)

Returns a section of the map for the given render name with the given number of rows and columns.If the split doesn't exist it is generated and saved to file storage.
mapName - the name of the render
numRows - the number of rows in the split
numCols - the number of columns in the split
row the row index for the split. Must be < numRows and > 0
col the column index for the split. Must be < numCols and > 0
Returns Hash<string, object> See Map Section under Input Data

private Hash<string, object> GetSection(string mapName, int numRows, int numCols, int row, int col)

Returns a split of the map for the given render name with the given number of rows and columns.If the split doesn't exist it is generated and saved to file storage.
mapName - the name of the render
numRows - the number of rows in the split
numCols - the number of columns in the split
Returns Hash<string, Hash<string, object>> See Map Split under Input Data

private Hash<string, Hash<string, object>> GetSplit(string mapName, int numRows, int numCols)
MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.