3
\$\begingroup\$

I'm fairly new to XNA (only a week into C# and XNA at this point) but I have been developing games for a while now, and the program I used did not require any/many external files in creating an executable. I am perfectly fine with external files (for the most part) but reading around, it seems as if .XNB files are easily accessed for others to pull your resources out of.

After some thinking, I was wondering if it was possible to do any of these 3 things: 1. Hide the .XNB files within the .exe in which case it would likely create them in an external location only during run-time (wouldn't really solve the main issue, but still)? 2. Compress many of the .XNB binaries into a single binary (such as 1 for sounds, 1 for sprites, etc.) 3. (This one is one simply for my own OCD) Change the extension name from .XNB to something of my choosing? For example, to .DAT instead to make it less of a direct indicator I used XNA and/or these files can be accessed with an .XNB ripper?

None of these would particularly solve my initial problem, but I still wonder if they are possible. Anyhow, thanks in advance guys!

\$\endgroup\$
1

2 Answers 2

1
\$\begingroup\$

To answer the three of your questions with one answer: sure you could, but you wouldn't be able to use the default content manager.

However, you can create custom content processors to output file data in a format that only you would immediately know. This would still allow you to use the default XNA content manager (this.Content in any Game-derived class) as well as allow you to protect your assets in any way you want. The generated content files would still have the .xnb extension, but they would not have the typical .xnb format. (You may be able to change the extension, but I'm not sure.)

\$\endgroup\$
6
  • \$\begingroup\$ Alright thank you for the answer! Would you happen to know if there is a tutorial for this process somewhere? Or will I have to figure this out on my own. Being so new, I'm not sure the second option will happen for a while! \$\endgroup\$ Commented Aug 1, 2014 at 3:41
  • \$\begingroup\$ If you click on the link I gave you, Microsoft has a bunch of pages on creating your own processors and at least one example project. Plus a quick Google search revealed quite a few examples posted on blogs. \$\endgroup\$ Commented Aug 1, 2014 at 3:58
  • 1
    \$\begingroup\$ To expand on the answer above, you can load textures and other resources into their XNA representation from a filestream, as you would usually load any file. You can then use Texture2D.FromStream() to simply load the files into a texture variable. This way, you can compress/hide the files any way you choose. Here's a pastebin of the contentManager i'm using for my engine. pastebin.com/0j6TAdHh \$\endgroup\$
    – Lex Webb
    Commented Aug 1, 2014 at 16:14
  • 1
    \$\begingroup\$ Awesome answers thanks you guys! Thanks for being so welcoming to a new member. Mainly, just the knowledge that it was possible is helpful for me but the examples are great. \$\endgroup\$ Commented Aug 3, 2014 at 0:13
  • \$\begingroup\$ If you want to get really advanced, you could use the content pipeline to compile your content at run-time from hard-coded variables, and then change the name of the output file or hide it or whatever you want. Presumably, you would then use the content pipeline again later in the game to unhide/rename the files and deserialize them. This solution is very security-friendly, but it would require your players to install the content pipeline with your game instead of just the XNA runtime. \$\endgroup\$ Commented Aug 4, 2014 at 7:25
0
\$\begingroup\$

Yes, you can implement your own content manager.

http://romsteady.blogspot.com.es/2011/07/use-zip-files-to-hold-your-xna-content.html

public class ZipContentManager : ContentManager
{
  private ZipFile zipFile = null;

  public ZipContentManager(IServiceProvider services, string zipFile) : base(services, "")
  {
      this.zipFile = new ZipFile(zipFile);
  }

  protected override System.IO.Stream OpenStream(string assetName)
  {          
      var entry = zipFile.GetEntry(assetName.Replace('\\','/') + ".xnb");
      if (entry != null)
      {
          return zipFile.GetInputStream(entry);
      }
      return null;
  }
}
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .