Skip to content

Add Asset Security and Protection Guidance to Packaging Games Guide #161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions articles/tutorials/building_2d_games/25_packaging_game/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,58 @@ Try to minimize external dependencies. If your game requires additional librari
>
> Check specific requirements for each distribution platform you plant to target, as well as requirements by third-party libraries for using them, as disclosure requirements may vary.

## Asset Security and Protection

When distributing your game, you may have concerns about protecting your assets and code from unauthorized access or reverse engineering. It is important to understand the practical limitations and trade-offs involved in various security approaches.

### XNB Asset Protection

MonoGame's content pipeline compiles assets into compressed XNB format, which provides a basic level of protection for your game content. For the majority of indie game projects, this compression is sufficient protection for several reasons:

- **XNB files are not standard formats**: Unlike raw images or audio files, XNB files require specific knowledge and tools to extract. While the XNB format is documented and part of the MonoGame open source code, this still creates a barrier for the casual user.
- **Practical protection**: While not cryptographically secure, XNB compression deters casual attempts at asset extraction.
- **Performance benefits**: The primary purpose of XNB compilation is optimization, with content protection being a secondary benefit.
- **Cross-platform consistency**: The same XNB format works across all MonoGame platforms without additional configuration.

> [!TIP]
> Unless you are working with highly valuable or sensitive assets (such as unreleased music from major artists or proprietary artwork), the standard XNB compression provides adequate protection for most games.

### Code Obfuscation

For protecting your game's source code logic, obfuscation tools can make reverse engineering more difficult by renaming variables, restructuring code flow, and adding dummy logic paths. However, code obfuscation comes with significant trade-offs:

- **Performance impact**: Obfuscated code often runs slower than clean, optimized code due to additional indirection and complexity.
- **Debugging complexity**: Stack traces become unreadable, making it nearly impossible to diagnose issues reported by players.
- **Build process overhead**: Additional build steps, tools, and integration are required in your development workflow.
- **Platform limitations**: Some obfuscation techniques may not work correctly across all target platforms or may interfere with .NET features that MonoGame uses internally.
- **Compatibility issues**: Obfuscation can break reflection-based code or third-party libraries.

> [!IMPORTANT]
> Consider whether the performance cost of obfuscation is worth the potential security benefits for your specific project. For most indie game, the impact on player experience may outweigh the security advantages.

### The Reality of Modern Society

It is crucial to understand that in the modern digital landscape, no security measure is truly impenetrable:

- **Corporate security investments**: Major corporations invest millions of dollars annually in security research and implementation, yet breaches still occur regularly. This demonstrates the fundamental challenge of client-side protection.
- **Advanced tools**: Sophisticated reverse engineering tools are readily available and constantly improving, making traditional protection less effective.
- **AI-assisted analysis**: Artificial intelligence can now assist in code analysis and pattern recognition, making traditional obfuscation techniques less reliable.
- **Determined attackers**: If someone is sufficiently motived to extract your assets or reverse engineer your code, they will likely succeed regardless of protection measures.
- **Diminished returns**: For indie developers, time spent on extensive security measures often exceeds the value of the content being protected and could be better invested in core development.

### Practical Security Recommendations

For most MonoGame projects, consider these practical approaches to content protection:

1. **Accept standard protection**: The built-in XNB compression is sufficient for typical use cases and provides the good balance of protection and performance.
2. **Focus on gameplay**: Invest development time in creating compelling gameplay rather than extensive security measures.
3. **Legal protection**: Consider proper licensing, terms of service, and copyright notices as your primary protection—intellectual property law provides stronger protection than technical measures.
4. **Contractual compliance**: If using licensed assets with specific protection requirements, work with the licensor to understand what constitutes "reasonable protection."
5. **Threat assessment**: Realistically evaluate whether your game is likely to be a target for asset extraction or reverse engineering.

> [!NOTE]
> Remember that the goal of asset protection should be to deter the casual extraction, not to create an impenetrable fortress. The time and resources spent on extensive security measures are often better invested in improving the game itself.

## Mobile Platforms

While this tutorial series has focused on creating a 2D game for desktop platforms, MonoGame also offers support for mobile development on Android and iOS. The game we have built throughout this series could be adapted for touch controls and distributed through mobile app stores with additional work.
Expand Down