Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: How protect the game's image files?  (Read 11485 times)

0 Members and 1 Guest are viewing this topic.

djm_jm

  • Newbie
  • *
  • Posts: 23
    • View Profile
How protect the game's image files?
« on: November 07, 2016, 12:12:46 pm »
I am new to SMF/programing of games and only know import images to textures with the method "loadFromFile()", but, the imagens are external and can be modifiedy by anyone. How I can hide the images and put its inside the project?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: How protect the game's image files?
« Reply #1 on: November 07, 2016, 12:39:40 pm »
There's no real protection against people somehow accessing your game assets - look at all the AAA games that people manage to extract textures, sound files, models, etc.
As such you have to really ask yourself, how much "obfuscation" should I add and how much time should I invest into this? Is it really worth while for the assets that you're using?

If you still want to include it into you application, you could convert the image into a byte array and then use loadFromMemory. You can find small applications that do this kind of conversion by googling a bit.

Alternatively you can package your data into a common archive format and directly stream the data from there or create your own custom format.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

djm_jm

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: How protect the game's image files?
« Reply #2 on: November 07, 2016, 02:33:14 pm »
There's no real protection against people somehow accessing your game assets - look at all the AAA games that people manage to extract textures, sound files, models, etc.
As such you have to really ask yourself, how much "obfuscation" should I add and how much time should I invest into this? Is it really worth while for the assets that you're using?

If you still want to include it into you application, you could convert the image into a byte array and then use loadFromMemory. You can find small applications that do this kind of conversion by googling a bit.

Alternatively you can package your data into a common archive format and directly stream the data from there or create your own custom format.

Say more about "Create your own format", I don't right understand this.

sjaustirni

  • Jr. Member
  • **
  • Posts: 94
    • View Profile
Re: How protect the game's image files?
« Reply #3 on: November 07, 2016, 05:20:16 pm »
It basically means that you create your own way of storing information about the color of pixels at certain position for raster graphics or your own way of storing curves and shapes and their properties and whatnot for vector graphics. You could look at the existing formats and get inspired by them. For instance, GIF: http://www.martinreddy.net/gfx/2d/GIF87a.txt

Before you fire up your favorite IDE though, let me tell you something.
You're making a game, not a new image format. To create an efficient format of any kind, you'd need to spend some time researching the thing, which is probably going to take you longer than to make any kind of a simple game in SFML. Realistically, you're going to create an image format with the following cons:
  • its files are going to be way bigger than they actually need to be, because you're simply not that good at creating more efficient image format just as a side project for your game as opposed to a whole bunch of people doing just the format thing
  • because the images are too big, they're going to take ages to load and possibly use up all the RAM on mobile devices
  • its implementation will take quite some time relative to the time it will take you to create your game. Time you could spend on delivering features
  • the implementation will be buggy as hell, because it won't have the time to mature and it will not be the primary dev effort
  • not only that, you will have to create conversion programs that will take GIF let's say and convert them to your format. That's because you don't have any tools that would generate images in your format. This means even more bugs to fix.
And finally you realize it wasn't worth it at all, since your game won't even get popular for anyone to care enough to steal your assets (that's because your game is just a Mario clone with custom image format, as you have invested all your time into developing the format and completely forgot about the game).

But let's say your game does get popular. In this case, it's probably time to create your own sound format too, because, hell, sound is important and you don't want anyone to steal it from 'ya, do you? And I could go on with animation files, config files (you wouldn't like if someone changed your gravity to 0 so they could fly, right?)...
But I tell you something. Even in this case developing your own format of anything is a stupid idea. Why? Reverse engineering. If someone knowledgeable enough wants to steal your assets, they will do it anyway, no matter how hard you try to prevent them.

After all, even if someone does steal your assets, it doesn't hurt you at all. If they use them in a commercial project, you may sue them and make some extra money from it (which you then use to market your own game ;-). I mean, to cover legal expenses. Whatever).


Now, I don't think that creating a new image format is a bad idea. It's a wonderful idea, if you know what you're doing - for instance, learning about how are images represented and stored in computers, or solving a particular problem (you could be trying to make big images stream-able, in which case a new format is a suitable strategy) are valid reasons to start developing your own image format. But asset files protection? No. No, don't do that.
« Last Edit: November 07, 2016, 05:26:58 pm by sjaustirni »

djm_jm

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: How protect the game's image files?
« Reply #4 on: November 07, 2016, 05:56:08 pm »
I think the topic's title has a wrong mean about what I want it. I justly want learn and only it. As I am new in the games's programming, I need some tips about this.

How you make your project like this? usually load from final directory of the game?
« Last Edit: November 07, 2016, 05:57:56 pm by djm_jm »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
AW: How protect the game's image files?
« Reply #5 on: November 07, 2016, 06:17:50 pm »
With custom format I meant some binary format that holds your assets, like something as simple as: \0 terminated string of filename, number of bytes of data, data blob
But it's probably easier to use a known archive type like zip or tar.

For all my little games so far I've just put the assets into a directory alongside the executable.
For some small standalone apps that used like one or two images, I converted them to byte arrays and "built" them into the executable.
For larger projects I probably would go with PhysicsFS or a simple archive format.

In the end the fear that your assets get "stolen" is mostly larger than it actually happening. The first priority is to build a game that people want to download and play in the first place!
And even if some assets get reused, you can feel proud that your assets seem polished enough for other people wanting to use them. Plus they potentially get generate more attention for your game, etc. Not everything is just black and white. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Carlitox

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: How protect the game's image files?
« Reply #6 on: November 08, 2016, 12:14:56 am »
Maibe there exists a way to hide resources putting everything into one executable leaving only the data that will be modified like save game data.

player931402

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Re: How protect the game's image files?
« Reply #7 on: November 08, 2016, 06:14:30 pm »
Maibe there exists a way to hide resources putting everything into one executable leaving only the data that will be modified like save game data.

You can do what you want but the moment you load the image on your ram that's the moment you lost the war.

korczurekk

  • Full Member
  • ***
  • Posts: 150
    • View Profile
    • Email
Re: How protect the game's image files?
« Reply #8 on: November 08, 2016, 07:17:08 pm »
@UP You still can store it encrypted in memory and decrypt byte-per-byte while copying to vRAM, reading from that place is way harder, but still possibile.

@OP
If you want to store resources in executable you can use Qt's resources and my library QSFML to load them (end maybe encrypt), but  it's not really recommended, just let the assets go. :D

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: How protect the game's image files?
« Reply #9 on: November 09, 2016, 05:03:13 pm »
@UP You still can store it encrypted in memory and decrypt byte-per-byte while copying to vRAM, reading from that place is way harder, but still possibile.
That's doing nothing, because you're still just copying to system RAM. You don't have direct control over the GPU's RAM and the driver might move textures between GPU and system RAM at any time. So this would be unnecessary overhead with little to  no gain.

Carlitox

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: How protect the game's image files?
« Reply #10 on: November 09, 2016, 07:13:54 pm »
I'm triying the simple solution of compressing the data adding a password. I'm using minizip library provided in the zlib homepage.

Now i can read info from zips but the problem comes when adding a password. There aren't tutorials on the internet. Minizip library is well documented but there aren''t examples. They provide unzOpenCurrentFilePassword function that is the same as unzOpenCurrentFile but adding a second parameter for password. I don't understand why the password function fails.

This code works.


            unzFile unz_file = unzOpen("tilesets/tileset_01.zip");
                if (unz_file == nullptr) std::cout << "Unz_file is nullptr" << std::endl;
                unz_file_info info;
                unzGetCurrentFileInfo(unz_file, &info, NULL, 0, NULL, 0, NULL, 0);
       
                char *file = (char*)malloc(info.uncompressed_size);
                //std::string password = "lapislazuli";
                //if(unzOpenCurrentFilePassword(unz_file, password.c_str()) == UNZ_OK) std::cout << "OPENED" << std::endl;
                if (unzOpenCurrentFile(unz_file) == UNZ_OK) std::cout << "OPENED" << std::endl;
                unzReadCurrentFile(unz_file, file, info.uncompressed_size);

                sf::Image image;
                image.loadFromMemory(&file[0], info.uncompressed_size);
                tileset_texture.loadFromImage(image);
               
                free(file);


Anyone knows how to do it with this library or with a differentr one?
« Last Edit: November 09, 2016, 07:26:13 pm by Carlitox »

korczurekk

  • Full Member
  • ***
  • Posts: 150
    • View Profile
    • Email
Re: How protect the game's image files?
« Reply #11 on: November 09, 2016, 08:55:49 pm »
@UP You still can store it encrypted in memory and decrypt byte-per-byte while copying to vRAM, reading from that place is way harder, but still possibile.
That's doing nothing, because you're still just copying to system RAM. You don't have direct control over the GPU's RAM and the driver might move textures between GPU and system RAM at any time. So this would be unnecessary overhead with little to  no gain.
Not if you send data to GPU with Vulkan. ;)
But it's still pointless IMHO.

//edit: @OP
I don't understand why the password function fails.
What is the error code?
« Last Edit: November 09, 2016, 09:03:35 pm by korczurekk »

Carlitox

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: How protect the game's image files?
« Reply #12 on: November 09, 2016, 10:34:50 pm »
There is no error compiling.

if(unzOpenCurrentFilePassword(unz_file, password) == UNZ_OK) std::cout << "OPENED" << std::endl;

The unzipping fails because the return of the function it's not UNZ_OK.

« Last Edit: November 09, 2016, 11:26:49 pm by Carlitox »

korczurekk

  • Full Member
  • ***
  • Posts: 150
    • View Profile
    • Email
Re: How protect the game's image files?
« Reply #13 on: November 09, 2016, 11:22:44 pm »
There is no error compiling.

if(unzOpenCurrentFilePassword(unz_file, password) == UNZ_OK) std::cout << "OPENED" << std::endl;

The unzipping fails because the return of the function it's not UNZ_OK.
I know, but what is it then? Check what values can return unzOpenCurrentFilePassword and what it actually returns.

Carlitox

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: How protect the game's image files?
« Reply #14 on: November 09, 2016, 11:27:03 pm »
There is no error compiling.

if(unzOpenCurrentFilePassword(unz_file, password) == UNZ_OK) std::cout << "OPENED" << std::endl;

The unzipping fails because the return of the function it's not UNZ_OK.
I know, but what is it then? Check what values can return unzOpenCurrentFilePassword and what it actually returns.

Solved.

The problem was in the encrytion method. In winzip you have to choose "inherit Zip 2.0". 

There is only one valid return value wich is UNZ_OK. This is from the library.

extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
                                                  const char* password));
/*
  Open for reading data the current file in the zipfile.
  password is a crypting password
  If there is no error, the return value is UNZ_OK.
*/

 
« Last Edit: November 09, 2016, 11:34:25 pm by Carlitox »