<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Loading bitmap from exe (resource file)</title>
		<link>http://www.allegro.cc/forums/view/614530</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Thu, 14 Aug 2014 04:44:18 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I want to load bitmap like resource file but it crashes every time when it comes to this line:</p><p><span class="source-code"><a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>pozadina <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_bitmap"><span class="a">al_load_bitmap</span></a><span class="k2">(</span>LoadCustomResource<span class="k2">(</span><span class="n">100</span>, hInstance<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></span></p><p>I attached files where you can see how LoadCustomResource function works.</p><p><b>EDIT:</b> I made it not crash at bitmap loading but now it crashes when i try to draw it </p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number"> 1</span><a href="http://www.allegro.cc/manual/al_set_target_bitmap"><span class="a">al_set_target_bitmap</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_get_backbuffer"><span class="a">al_get_backbuffer</span></a><span class="k2">(</span>display<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 2</span><a href="http://www.allegro.cc/manual/al_draw_bitmap"><span class="a">al_draw_bitmap</span></a><span class="k2">(</span>pozadina, <span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
</div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Aleksa)</author>
		<pubDate>Thu, 07 Aug 2014 05:03:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Need to use the memfile addon. Something along these lines:</p><div class="source-code snippet"><div class="inner"><pre>HGLOBAL hMemory <span class="k3">=</span> LoadResource<span class="k2">(</span>hModule, hResource<span class="k2">)</span><span class="k2">;</span>
DWORD dwSize <span class="k3">=</span> SizeofResource<span class="k2">(</span>hModule, hResource<span class="k2">)</span><span class="k2">;</span>
LPVOID lpAddress <span class="k3">=</span> LockResource<span class="k2">(</span>hMemory<span class="k2">)</span><span class="k2">;</span>

<a href="http://www.allegro.cc/manual/ALLEGRO_FILE"><span class="a">ALLEGRO_FILE</span></a><span class="k3">*</span> f <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_open_memfile"><span class="a">al_open_memfile</span></a><span class="k2">(</span>lpAddress, dwSize, <span class="s">"r"</span><span class="k2">)</span><span class="k2">;</span>

<span class="c">// Make sure to specify the right extension here</span>
<a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a><span class="k3">*</span> bmp <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_bitmap_f"><span class="a">al_load_bitmap_f</span></a><span class="k2">(</span>f, <span class="s">".png"</span><span class="k2">)</span><span class="k2">;</span>

al_destroy_file<span class="k2">(</span>f<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Thu, 07 Aug 2014 19:41:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks! But that is just too much for my level of programming <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /><br />I will just stick to grabber and .dat file <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Aleksa)</author>
		<pubDate>Thu, 07 Aug 2014 22:19:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/614530/1003843#target">Aleksa</a> said:</div><div class="quote"><p> I will just stick to grabber and .dat file <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /> </p></div></div><p>I wonder how you will do that if there&#39;s no grabber or .dat files for A5 <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Fri, 08 Aug 2014 02:48:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well there are no .dat files anymore in Allegro5 but you can use the physfs add-on to get a similar result. You can then just put your game resources in a zip file.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (beoran)</author>
		<pubDate>Fri, 08 Aug 2014 04:56:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Using physfs is also cross-platform, unlike using Windows only methods.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (LennyLen)</author>
		<pubDate>Fri, 08 Aug 2014 10:17:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yea I realized that few minutes after posting that <img src="http://www.allegro.cc/forums/smileys/sad.gif" alt=":(" /> This supposed to be my first A5 project but I think now I am going back to A4 <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /><br />I don&#39;t want to use physfs and zip files because they are much easier for end user to open and edit. I know they can open dat file too but I just like it to be dat <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Aleksa)</author>
		<pubDate>Fri, 08 Aug 2014 15:37:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Allegro4 .dat files are also easy to open. If you worry about people using your art resources, you&#39;ll have to properly encrypt the data. Maybe with this: <a href="http://code.google.com/p/openaes/">http://code.google.com/p/openaes/</a>. Then even if the data isn&#39;t wrapped, no one is able to use it. However, you could simply rename the .zip file to a .bla file and chance is 80% of the users won&#39;t know what to do with it, at least not for a while. </p><p>&lt;rant&gt;<br />And also, Allegro 4 is obsolete now. Please don&#39;t use it for new projects.<br />&lt;/rant&gt;
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (beoran)</author>
		<pubDate>Fri, 08 Aug 2014 22:31:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I think that for this project I will go for a4 and later I will try a5 again. I am not high level programmer so a4 will do the job for me
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Aleksa)</author>
		<pubDate>Fri, 08 Aug 2014 22:50:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Just renaming a zip to .dat is probably enough to stop the users you are woried about <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /> the more determined ones will be able to access your data even if you encrypted it, so meh.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Fri, 08 Aug 2014 23:55:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I will just continue with a4 for now. There is plenty of time for a5 as I am still young enough to learn it <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Aleksa)</author>
		<pubDate>Sat, 09 Aug 2014 00:38:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I renamed the data for my A5 game to .pak and one person who loved my game and played around with it A LOT (he created over 500 levels! <img src="http://www.allegro.cc/forums/smileys/shocked.gif" alt=":o" /> ) did not know it was a ZIP file until I told him. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>I used to be worried about that, like you, but honestly, I just don&#39;t see it as much of a problem as I used to anymore, especially when the users you&#39;re worried about won&#39;t realize how to access it.  Allegro 4 .DAT files on the other hand = easy.  Just download grabber and presto, you can open it.  I have even opened up other people&#39;s encrypted Allegro 4 DAT files, and it wasn&#39;t much work to do it.  A determined person will.  Just throw up the usual copyrights and rename it as suggested.  Allegro 5 is FAR superior and not that difficult to use once you take some time to get used to it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Roy)</author>
		<pubDate>Tue, 12 Aug 2014 08:45:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I forget which, but some game use a zip file but they mess the header up somehow (like a XOR pattern on first 20 bytes or something I don&#39;t remember details) and then their game just transparently undid the mess up, but winzip or WinRAR had trouble recognizing the file as a not valid file.</p><p>Rename the extension is easier. Everyone says who cares about trying hard and I agree.</p><p>I wonder if any program has done this:</p><p>Store .zip file as a different extension, possibly split up into 2 files or more as well, with every unsigned byte stored + 47.</p><p>When the game starts, it reads this file, subtracts 47 from every unsigned byte, and writes the result to a temporary single file with a different extension but is now a valid original zip file.</p><p>Then it opens that with the normal function. And then deletes it when it closes the file and doesn&#39;t need it anymore. I think that take about 1 minute to code.</p><p>And a command line utility that take the 1st arg as a original file, and write the messed up files into same directory, then it is just drag and drop of new version of your zip file onto that program in windows and you have the new corrupted files for the game to read.</p><p>Because that sounds a little bit sneaky and also easy in terms of complication I bet someone has done that before for a less than 50 megabyte game anyway.</p><p>I did something similar for a library that was difficult to use/build, I instead use the pre-compiled binary, and instead of calling library function I wrote data to file, executed the binary (which was inside the program folder) on the file with results to another file, and then read that other file back in, and then deleted everything, and to a normal user they didn&#39;t know the difference and it took me like 15 minutes instead of days.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (m c)</author>
		<pubDate>Tue, 12 Aug 2014 10:18:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What&#39;s the problem with users accessing the data?</p><p>Do you think they&#39;ll use the assets in their own game?</p><p>Will they alter them to cheat?  If it&#39;s not a multiplayer game, what&#39;s the harm?</p><p>BTW, id Software renamed zip files to have a pk4 extension without any extra encryption whatever.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Tue, 12 Aug 2014 10:21:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Its not that important that files cant be opened. Its just that from angle of user my program looks more pro if he cant open it <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /> (I&#39;m talking about 99% of users, other 1% will open it anyway)<br />Main reason for me currently using datafiles is because I already know basics of using them. For this project I don&#39;t have time to learn other ways of doing it but with next project I will switch to A5
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Aleksa)</author>
		<pubDate>Tue, 12 Aug 2014 17:50:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What are the basics to using zip files? <img src="http://www.allegro.cc/forums/smileys/shocked.gif" alt=":o" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Wed, 13 Aug 2014 04:52:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well, your program source code will have to be changed.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (m c)</author>
		<pubDate>Wed, 13 Aug 2014 08:44:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ummm... zip files are infinitely easier to use!  There&#39;s nothing really to learn.  You code your program to... well, here, it will take less text for me to show you the code than to explain it! It&#39;s just that easy...</p><div class="source-code snippet"><div class="inner"><pre>PHYSFS_init<span class="k2">(</span>NULL<span class="k2">)</span><span class="k2">;</span>
<span class="k1">if</span><span class="k2">(</span><span class="k3">!</span>PHYSFS_mount<span class="k2">(</span><span class="s">"MyDataFile.dat"</span>, <span class="s">"/"</span>, <span class="n">1</span><span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span>
   <span class="c">// On error, do something here</span>
<span class="k2">}</span>
<a href="http://www.allegro.cc/manual/al_set_physfs_file_interface"><span class="a">al_set_physfs_file_interface</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

With the above code, you can now load your bitmap files etc... (even from folders inside the zip) normally, the same way you load them straight from your hard drive!  Except Allegro 5 grabs them from inside the zip. </p><p>If you need to access your hard drive, it&#39;s a simple one line command to switch back to the hard drive, and then when you need to access the zip again, you use <span class="source-code"><a href="http://www.allegro.cc/manual/al_set_physfs_file_interface"><span class="a">al_set_physfs_file_interface</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></span> again.</p><p>For example, I needed to check for user made levels in my game folder, so I done the following...</p><div class="source-code snippet"><div class="inner"><pre><span class="c">// switch to loading from the game folder</span>
<a href="http://www.allegro.cc/manual/al_set_standard_file_interface"><span class="a">al_set_standard_file_interface</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="c">// Load user made levels from hard drive here</span>

<span class="c">// switch back to the zip file...</span>
<a href="http://www.allegro.cc/manual/al_set_physfs_file_interface"><span class="a">al_set_physfs_file_interface</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

That&#39;s it!  Nothing to it.</p><p>I was like you when Allegro 5 came out.  Learning it seemed a little daunting, but once I gave it a chance and started to use it, I was really impressed with it.</p><p>I use 7Zip and while my data file will not open up automatically, so nobody will know it&#39;s a zip by accident, all one needs to do, at least with 7zip is select to OPEN it from the 7Zip right click menu and presto, it&#39;s open like any other zip, then just drag and drop your files in, organize them as you would normally (no grabber program needed, which is a lot nicer as well).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Roy)</author>
		<pubDate>Wed, 13 Aug 2014 09:41:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ok you convinced me to give it another shot <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Aleksa)</author>
		<pubDate>Wed, 13 Aug 2014 16:08:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/614530/1004044#target">Arthur Kalliokoski</a> said:</div><div class="quote"><p>Do you think they&#39;ll use the assets in their own game?</p></div></div><p>
Is this a legitimate concern?  I hear people talk about this possibility, but I&#39;ve yet to hear of it actually happening.</p><p>One thing&#39;s for sure:  It would suck to spend time making original resources, only to have someone render them unoriginal by ripping them off.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Gideon Weems)</author>
		<pubDate>Wed, 13 Aug 2014 22:25:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Is file search case-sensitive in a ZIP archive ?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Thu, 14 Aug 2014 02:02:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/614530/1004102#target">Aleksa</a> said:</div><div class="quote"><p>Ok you convinced me to give it another shot <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p></div></div><p>

Awesome!  Stick with it, it&#39;s well worth it.  And people here are very helpful in that regard.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/614530/1004123#target">Audric</a> said:</div><div class="quote"><p>Is file search case-sensitive in a ZIP archive ? </p></div></div><p>

I think a zip archive is basically the same as filenames on your hard drive.  I don&#39;t think it is.  For my own game though, I came up with some basic naming rules which actually make things easier for me.</p><p>I have all my file names start with a capital letter, followed by small letters, if they consist of multiple words in  the name that the words are separated by an underscore.  So something like a background image might be named &quot;Background_Image.png&quot;.  I also have a rule that all extensions (like &quot;png&quot;) are lowercase.  I have similar rules for naming my variables, all lower case separated by underscores etc... etc... I found this has really helped me.  When programming I can spot an error in a name quickly because I know my rules, I can also remember the name of it and how I saved it on disk easy without looking because of these, so I suggest you come up with some of your own naming rules you&#39;re comfortable with and then stick with them.  Helps in spotting bugs and makes things look cleaner and more professional.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Roy)</author>
		<pubDate>Thu, 14 Aug 2014 04:44:18 +0000</pubDate>
	</item>
</rss>
