Hide Content folder in exported game?

Hi, I want to publish my game. To my understanding, if I want to upload to itch, I need to upload what’s inside the bin/Windows/x86/Release folder after zipping it. My problem is that the Content folder that is present here still contains the name of every asset in the game (names of the xnb files), which I want to hide.

I tried looking into obfuscation, but I can only obfuscate assemblies, which isn’t what I’m trying to do.

Is there a way to at least hide the names of the files?

Not entirely, though compressing everything into an archive is an option, albeit maybe too much to be worth it. High-level engines typically go this route, but even they can’t fully hide assets because the game needs to know what to load. Even obscure archive formats in older games/consoles have been cracked and opened. What is your goal in hiding the files?

My two cents: instead, include a license with your game that restricts what the player can do with the game assets.

2 Likes

No worries Xnb is a binary format, people who will play your game, most likely will not dare to touch your game content and reverse engineer it… just to see the actual raw content ^_^Y

2 Likes

The issue is that there is still the name of the files, like car.xnb, which I want to hide. I guess I could juste put random names to prevent that but I would need to change every file reference in the Content load and the code would be really messy. But Iguess I will do that if there is no other way.

My goal is just to avoid the player spoiling themselves and find secrets by looking at the content of the Content folder, it’s not much of a licence issue. I don’t really see how I could use an archive.

Oh, in that case you can simply rename your assets. You can use abbreviations (Ex. “SecretLevel1” -> “SC1”) or some other internal name. This would be the easiest and quickest thing to do.

I like to have constant strings defined for each asset name so if it needs to be renamed, I just change the value of that string and have it propogate to all the instances the asset is loaded. I’m not sure how large your game is, but if you want to rename the asset I’d recommend going about it this way.

1 Like

This is a very basic that I can think of, if you don’t want to use archiving tools.

PSEUDO CODE only :

ContentCatalog[0].TagNAme = "Car";
ContentCatalog[0].SourceFile  = "D:\MyGameContent\Car.Xnb";
ContentCatalog[0].DestFile    = "Content\Mesh\M0001.Xnb";
ContentCatalog[0].MeshContent = null;

ContentCatalog[1].TagNAme    = "Ship"'
ContentCatalog[1].SourceFile  = "D:\MyGameContent\Ship.Xnb";
ContentCatalog[1].DestFile     = "Content\Mesh\M0002.Xnb";
ContentCatalog[1].MeshContent = null;

if( DEBUG or UNRELEASE )
{
  foreach e ...
  {
    copy file from e.SourFile to e.DestFile
  }
}


foreach e ...
{
   e.MeshContent =  Content.Load( e.DestFile );
}
1 Like

@Kimimaru @DexterZ Thanks, I’m going to go the way you suggested.

It’s possible to put content files into the exe file, I found a stack overflow post that talks about it https://stackoverflow.com/questions/41908427/embed-dlls-and-contents-into-exe-in-monogame

The files end up added to the exe after the code so that it runs without any issues and the only hard part is getting the file streams for loading content.

2 Likes

This is what I’ve done. Let me know if you need any code for getting said streams.

Edit: Never mind; I’ll just post it here.

public class EmbeddedResourceContentManager : ContentManager
{
    public System.Reflection.Assembly Assembly { get; private set; }
    public string Prefix;
    public EmbeddedResourceContentManager(System.Reflection.Assembly assembly, IServiceProvider serviceProvider, string prefix)
        : base(serviceProvider)
    {
        Assembly = assembly;
        Prefix = prefix;
    }
    private string Format(string assetName)
    {
        return Prefix + assetName.Replace("\\", ".") + ".xnb";
    }
    // Optional, in case you don't want it to throw an exception upon failure
    public override T Load<T>(string assetName)
    {
        if (Assembly.GetManifestResourceStream(Format(assetName)) == null)
            return default(T);
        return base.Load<T>(assetName);
    }
    protected override Stream OpenStream(string assetName)
    {
        return Assembly.GetManifestResourceStream(Format(assetName));
    }
}
2 Likes