Rust Save map to file

Discussion in 'Plugin Requests' started by Zhahaman2001, Feb 5, 2017.

  1. I would like to make a plugin that saves the in game map as a png file. Is the code for generating the in game map client side? Has anyone tried this? The saving the image to a png is the easy part with the file storage class, my problem is finding the image and or the code to generate the image.
     
  2. This is indeed possible as rust.io did this if I am correct. Maybe dig into their .dll file (from their plugin using something like dotPeek) and see if you can find anything. They might even have a open-source github somewhere ;)
     
  3. hmm would be a great idea for lustymap
     
  4. its great idea, I think at least you can take luck looking for the map inside the game, I mean the Map that is showed on PaperMap when you press the G.

    Save it on a PNG will be great for some servers that want not use External generators as Rustio or Beacanio
     
  5. Thanks I cant seem to find a Rust IO github with open-source, there is a Rust IO github but I do no think its what I am looking for. I also cant seem to decompile the dll as all the function/variable names are a,A,b,B ect... idk its my decompile (ILSpy) or if they have some anti decompile thing going on.

    Either way I always thought rust.io generated their own map image with their own code based off of the hightmap, road nodes, ect where I am looking for the image generated by the game for the in game paper map. So idk if poking around rust.io is even the right way to go about this.
     
  6. Wulf

    Wulf Community Admin

    Rust:IO isn't open source, and he is fairly protective of it, hence the obfuscation. He's seen it copied before without permission or credit given.
     
  7. That's what it looked like to me, thanks Wulf. Let it be known that I am not after copying his map image (which he did a wonderful job with) I am after copying the in game map generated by the paper map item. XD

    Guess I will just keep looking client side
     
  8. Forget RUST IO, they have done half the process in the server side.

    Create your own code for all of this, and try to do it all server side. Will be the best.

    If you need help recreating new images for the map tell me, I can help, I already create maps for older games.
     
  9. Well this is what I got so far, not what I am looking for but still cool.

    http://i.imgur.com/GOpywxv.jpg

    Code:
    using UnityEngine;
    using System.IO;
    namespace Oxide.Plugins
    {
        [Info("MapImage", "", 1.0, ResourceId = 0)]
        class MapImage : RustPlugin
        {
            private Texture2D RemoveAlpha(Texture2D alphatexture)
            {
                Texture2D texture2d = new Texture2D(alphatexture.width, alphatexture.height);
                Color getcolor = new Color();
                for (int x = 0; x < alphatexture.width; x++)
                {
                    for (int y = 0; y < alphatexture.height; y++)
                    {
                        getcolor = alphatexture.GetPixel(x, y);
                        texture2d.SetPixel(x, y, new Color(getcolor.r, getcolor.g, getcolor.b));
                    }
                }
                return texture2d;
            }
            void OnServerInitialized()
            {
                FileSaverObject = new GameObject();
                FileSaverClass = FileSaverObject.AddComponent<FileSaver>();
                GameObject gameobject = GameObject.Find("Terrain");
                TerrainHeightMap terrainheightmap = gameobject.GetComponent<TerrainHeightMap>();
                terrainheightmap.GenerateTextures();
                FileSaver.SaveFile(RemoveAlpha(terrainheightmap.NormalTexture).EncodeToPNG());
            }
            void Unload()
            {
                UnityEngine.Object.Destroy(FileSaverObject);
            }
            static GameObject FileSaverObject;
            static FileSaver FileSaverClass;
            class FileSaver : MonoBehaviour
            {
                public static void SaveFile(byte[] encoded)
                {
                    MemoryStream stream = new MemoryStream();
                    stream.Write(encoded, 0, encoded.Length);
                    FileStorage.server.Store(stream, FileStorage.Type.png, 0);
                    stream.Close();
                }
            }
        }
    }
     
  10. I've got your code snippet working but I'm struggling to find out how you knew there was a game object called "Terrain" and knew it had a TerrainHightMap component?

    These are broken references for me in Visual Studio within the oxide project at the moment, but it all works when run on the server.

    I would also like to have a go at generating a high quality map.