• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
mikenovemberoscar

File input/output in C++ Question

13 posts in this topic

Hi all,

 

I am making a game in Visual C++ 2010, and I want to have my levels stored as text files generated by my level editor.

 

I know how to make it so the compiled finished executables can read files from a fixed path (C:/etc/etc), and a rough idea of how to make it read files relative to the executable itself.

 

But how do I make it so I can include a level file (in my Visual C++ solution) which is read by the program at runtime (using file streams) - but will be packaged with the executable when compiled and finished and invisible to the users?

 

 

Thanks in advance,

 

mikenovemberoscar

0

Share this post


Link to post
Share on other sites
I am not sure what functions you are using for file access, but they typically specify the name of the file as a `char const *'. You should probably use `std::string' for most things, and when it is time to call the function that expects a `char const *' you can use `my_string.c_str()'.
0

Share this post


Link to post
Share on other sites

The program will look for the file in the executable's directory.

You can't really make your level files invisible, but you can hide them by packing all your level files in a "level" folder and placing the folder in your executable's directory.

Then you can load the levels like

 

loadLevel("level/level1.txt");

loadLevel("level/level2.txt");

Edited by lride
1

Share this post


Link to post
Share on other sites

If you aren't using files, you don't need to use file streams. If you are bundling your data into the executable, it is at some level merely memory that you are reading. I believe there are APIs for reading resources in Windows for example, but I don't have any experience with them so I will say no more.

 

One option is to use something like [url="http://icculus.org/physfs/"]physfs[/url] and bundle all the resources for your game into a second file. So you end up with two files, your "game.exe" and your "game.data" (or whatever you want to call it). The data file is actually some kind of ZIP archive containing the same directory layout you use during development.

0

Share this post


Link to post
Share on other sites
Okay thanks all,

If you are bundling your data into the executable, it is at some level merely memory that you are reading
Yeah this one.

I can include header files and use them in my game, but they aren't invisible to the end user?
Can I do the same thing with level files? I like the idea of resource files (.rez if i remember correctly?) but most professional games nowadays can be run with just the executable, or am I missing something?

Sorry I'm kind of new to Windows. Edited by mikenovemberoscar
0

Share this post


Link to post
Share on other sites

[quote name='mikenovemberoscar' timestamp='1357214576' post='5017062']
Can I do the same thing with level files? I like the idea of resource files (.rez if i remember correctly?) but most professional games nowadays can be run with just the executable, or am I missing something?
[/quote]

Resources are embedded inside the executable, so I suppose yes. That said, I don't know many AAA games that can be run with just an executable, usually they have a data folder containing tons of data. If the game packed everything inside a single .exe, that file would be absurdly large and it would make patching rather difficult.

0

Share this post


Link to post
Share on other sites

Ah I see... I examined my games and I realise they're all shortcuts. But can't resource files be read and modified by the user?

0

Share this post


Link to post
Share on other sites
Ah I see... I examined my games and I realise they're all shortcuts. But can't resource files be read and modified by the user?

 

Yes, they can, just like everything else on their computer. There is no good rationale to actively prevent the user from modifying data files, at least in a single player game. If the player wants to mess with the data files (perhaps to edit textures or change stats) you should let him. It's not like it's harming anyone, and it adds replay value to the game in the form of unofficial modding.

0

Share this post


Link to post
Share on other sites
Well I see your point, but what if my game was multiplayer? Just write the files in a binary format and hope for the best?

 

There is not much you can do against a determined attacker. Whatever is on his computer can be read and modified by design. You cannot prevent that short of keeping assets away from the user and rendering the game on dedicated servers, delivering the results via the internet (see OnLive) which is really overkill. And even then he might still be able to recover the assets to some extent (e.g. stare at a wall and screenshot the texture on his computer). It's just not a 100% solvable problem in practice.

 

To be honest, just packing all your assets in a zip file and renaming the extension will discourage 99.9% of people out there from snooping into your assets. That's probably good enough unless you have an AAA game in the works.

 

Basically, you are attempting to solve the DRM problem, which in short is "how do I make sure someone cannot copy X while still having access to it" which is fundamentally flawed in the abstract computer realm, because while it is difficult to replicate a physical object, all information in the form of bits (i.e. everything on a computer) can by definition be copied.

Edited by Bacterius
0

Share this post


Link to post
Share on other sites

Woah. I can see what you mean now Bacterius, and yeah I'll probably do what you said with the zip file. Thats an interesting point with the DRM problem.

 

Thanks very much for taking time to share your knowledge :)

 

mikenovemberoscar

1

Share this post


Link to post
Share on other sites
Well I see your point, but what if my game was multiplayer? Just write the files in a binary format and hope for the best?

 

If it's that important, you send the client a 'seed' value, hash the file with it, and send the results to the server.

Only the server knows the correct result to the challenge and since the seed value keeps changing they can't just send you the correct result from last time you asked.

And that's the start of cryptography...

0

Share this post


Link to post
Share on other sites
Well I see your point, but what if my game was multiplayer? Just write the files in a binary format and hope for the best?

 

If it's that important, you send the client a 'seed' value, hash the file with it, and send the results to the server.

Only the server knows the correct result to the challenge and since the seed value keeps changing they can't just send you the correct result from last time you asked.

And that's the start of cryptography...

 

That would not help, the pirate would just keep the original assets stashed somewhere, hash them for verification, then go back to using the altered ones.

 

Cryptography does not help, it solves an entirely different problem.

Edited by Bacterius
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0