Save and Load List of Texture2d's as binary data?

does anybody know how to save and load a list of texture2d’s as binary data?

I want to make a editor based game where the games are built from users.
I am making my game so its completely tile based., where all graphics are tiles drawn from a larger list of texture2d’s

however I’m not sure how to do this.
basically I want to allow the user to open the editor program and start from a default project and allow them to save and load a .qst file containing all the data for the game;

then they can edit it save it and play it in the engine program.

‘Interpreter’ is the word you are looking for.

EDIT

wait wat no
isn’t a interpreter for programming and scripting languages?
I want a save system basically but everything stored in 1 file including textures

An Archive Package file?

Are you looking for a texture atlas? Or are you asking ‘how to save many objects as a single file’, in your *.qst?

1 Like

Since Texture2D can read from stream, this is possible, but I wouldn’t go to the route. why do the hassle of creating your own binary file data structure and a customl binary reader and writer. I created a level tile editor and save all the information of content and level info in a single text file that describe all content of the level map will use.

E: G:

[ZGDK/JS-LVL01CONTENT]

TXT, 0, …/…/Content/TileMap/Level00/Middle/A001_A.png,0
TXT, 1, …/…/Content/TileMap/Level00/Middle/A001_B.png,0
TXT, 2, …/…/Content/TileMap/Level00/Middle/A001_C.png,0
TXT, 3, …/…/Content/TileMap/Level00/Middle/A001_D.png,0
TXT, 4, …/…/Content/TileMap/Level00/Middle/A001_E.png,0
TXT, 5, …/…/Content/TileMap/Level00/Bottom/B000M800.png,0
TXT, 6, …/…/Content/TileMap/Level00/Bottom/B000M801.png,0
TXT, 7, …/…/Content/TileMap/Level00/Bottom/B000N800.png,0
TXT, 8, …/…/Content/TileMap/Level00/Bottom/B000N801.png,0
TXT, 9, …/…/Content/TileMap/Level00/Bottom/B000N802.png,0
TXT, 10, …/…/Content/TileMap/Level00/Bottom/B000N803.png,0
TXT, 11, …/…/Content/TileMap/Level00/Bottom/B000N804.png,0
TXT, 12, …/…/Content/TileMap/Level00/Bottom/B000N805.png,0
TXT, 13, …/…/Content/TileMap/Level00/Bottom/B000N806.png,0
TXT, 14, …/…/Content/TileMap/Level00/Bottom/B1B0A800.png,0
TXT, 15, …/…/Content/TileMap/Level00/Bottom/B1B0B800.png,0
TXT, 16, …/…/Content/TileMap/Level00/Bottom/B1B0E800.png,0
TXT, 17, …/…/Content/Brush/Double.png,0
TXT, 18, …/…/Content/Brush/TSET01.png,0

BRS, 0, 0,0
BRS, 1, 0,1
BRS, 2, 0,2
BRS, 3, 0,3
BRS, 4, 0,4
BRS, 5, 0,5
BRS, 6, 0,6
BRS, 7, 0,7
BRS, 8, 0,8
BRS, 9, 0,9
BRS, 10, 0,10
BRS, 11, 0,11
BRS, 12, 0,12
BRS, 13, 0,13
BRS, 14, 0,14
BRS, 15, 0,15
BRS, 16, 0,16
BRS, 17, 1,17, D1, 0, 0, 182,90
BRS, 18, 1,17, D2, 182, 0, 364,90
BRS, 19, 2,18, S1, 100, 0, 75,100, 2,2, 0,0
BRS, 20, 2,18, S2, 300,77, 75,100, 3,5, 0,0

LVL,0,2,50,25,90,180

MAP,0,0,1,0|0,0,3,0|0,0,5,0|0,0,7,5|0,1,5,5|0,1,6,5
MAP,0,1,7,5|0,1,8,5|0,1,9,5|0,2,6,5|0,2,7,5|0,2,8,5
MAP,0,2,9,5|0,2,10,5|0,3,8,5

MAP,1,0,6,3|1,0,7,3|1,1,8,3|1,1,9,0|1,2,7,4|1,2,8,4
MAP,1,3,5,4|1,3,6,4

that main reason is I don’t want people editing the file outside of the editor
also I am not looking to save locations of the png but png’s them selves as binary data.

I want all data and resources to be stored in the binary file (aka the quest file)

If that’s the case, assuming you already designed your binary file structure with header info and specific bytes offset of each image e:g 3 image with different bytes offset.

E:G:
Header 100-200,201-300,301-400
[100…image1…200][201…inage2…300][301…image3…400]

Reader to load texture2D from stream :

LOOP until you read all specific bytes range base header info
{

  1. Read the specific bytes range of image from a file to mBytes

  2. Convert mBytes to mStream

  3. m_Texture2D[0].FromStream = mStream // texture from stream

  4. Add to your texture list collection
    __TextureList.Add( mTexture2D )

}

You certainly know that with a simple hex editor or something like DragonPacker it can be edited.
Note you will only prevent the edition from the ones not interested in going deep in their reverse engineering process :wink:

Storing this data could be easily done with 7zip, adding a password known from you when packing the data. So your engine will have to unzip it before calling “content.load”. But i don’t know how content.load can handle in memory data instead of files on the harddrive. It could be a new/future feature of Monogame.

ya idk 7zip with a password just doesn’t feel right.

how hard would it be to code a binary save and load system?

I already linked it… If you look at the left menu, it has encryption too…

How about this?

http://www.monogame.net/documentation/?page=T_MonoGame_Utilities_ZlibStream

thankyou I will look up a tutorial for this later

1 Like

Data would take less memory, and only your app would know the password. It could be retrieved by looking into a disassembly of your code, but in security concept, EVERYTHING is hackable.
Doing your own binaryformat will be a lot more complicated: Storing a table of offsets to know how many textures, or other things, the size of each, the data of each etc…

All Mr Valentine’s solutions can work too. The main question for me is (if you plan to use built data and not directly textures):
How to call content.load method on an xnb without extracting each file to the disk into the ? Can it be done with a MemoryStream object ?

Its not a good idea if you ask me because it complicates things needlessly. However you can do most of this with just file io. You can just read in all bytes combine them into a giant byte array save it. Then open each file as needed at runtime by getting the the xnb data out of your container file.
Write it to disk load it. Delete the file and continue.
The problem is editing. The xnb are built thru the content pipeline so on editing you would need a way to make it rebuild the xnb from say the edited png then insert that to your container file. Lots of work. The container is also not trivial you have to handle insertions deletions and the table.

hmm ok maybe I will use the zip method then.