SFML community forums

Help => Graphics => Topic started by: Redee on November 04, 2014, 04:29:38 pm

Title: How access to resource from DLL or resource package from SFML
Post by: Redee on November 04, 2014, 04:29:38 pm
I have resource DLL with one PNG file with ID = 101
And we have 3 functions at SFML Image class to load image

Quote
       loadFromFile (const std::string &filename)

    loadFromMemory (const void *data, std::size_t size)

    loadFromStream (InputStream &stream)
http://sfml-dev.org/documentation/2.1/classsf_1_1Image.php

Me need to load my Png from DLL but I no see functions to do this.
And no ideas how use loadFromMemory / loadFromStream

Pls, help, a lot of time spent to search solution.
Title: Re: How access to resource in DLL from SFML
Post by: Ixrec on November 04, 2014, 04:32:56 pm
As far as I can tell, resource DLLs are unique to Windows.  Since SFML is a cross-platform library, it doesn't provide any direct support for Windows-only features.

You'll have to look up how to work with resource DLLs on your own.  But once you have the png data loaded into memory using (presumably) the right Windows systems calls, using loadFromMemory on that data should be trivial.
Title: Re: How access to resource in DLL from SFML
Post by: Jesper Juhl on November 04, 2014, 04:50:55 pm
If you want a simple to use and cross-platform way to manage and load resources, take a look at PhysFs (http://icculus.org/physfs/) or maybe the Thor Resources (http://www.bromeon.ch/libraries/thor/v2.0/tutorial-resources.html) module.
Title: Re: How access to resource in DLL from SFML
Post by: Redee on November 04, 2014, 05:03:53 pm
Thx for fast replies!
U can create project at Visual Studio with simple example and share it 2 me ?

Ok I go read abourt cross-platform resource managers.
Its I think be helpful.

Me simply need 2 read data from DLL(or some unique package) and pass 2 loadFromMemory
Title: Re: How access to resource in DLL from SFML
Post by: Redee on November 17, 2014, 02:06:49 pm
Hi, Its I again.
Some problem with Thor and SFML 2.1

Give me links to version of Thor which compatible with SFML 2.1

I no understand at
http://www.bromeon.ch/libraries/thor/download.html
what version is correct to SFML 2.1

Thanks in advance.
Title: Re: How access to resource in DLL from SFML
Post by: eXpl0it3r on November 17, 2014, 02:10:23 pm
This has nothing to do with the original thread.

You better build SFML and Thor from source instead. If you want a SFML 2.1 compatible version, you need to checkout this commit (https://github.com/Bromeon/Thor/commit/f57666db6f187eb57bbc0947456cce2159a9b617) and build Thor yourself.
Title: Re: How access to resource in DLL from SFML
Post by: Redee on November 17, 2014, 02:24:47 pm
Ok I will simply do it from Thor source uses CMake.
And All will be ok?
How 2 test Thor dev version with SFML 2.1 release version? (http://sfml-dev.org/download/sfml/2.1)

But at Thor site at download page says >>
Quote
Important: The Thor development version is not compatible with SFML 2.0 or SFML 2.1. It always matches the master branch of the SFML Git version.

Its means need dev master version of SFML?
But me need 2 use with release version of SFML 2.1

Me need 2 read Images / Sounds from Thor resource.

U can write simple example 2 me ?
Title: AW: How access to resource in DLL from SFML
Post by: eXpl0it3r on November 17, 2014, 02:35:01 pm
If Thor and its shipped examples build and run, you should be fine.

Why should I write examples for you? You want to program, so you write your own examples.

Also I'm typing on a phone and yet I can still write "you" instead of "u", please do the same.
Title: Re: How access to resource in DLL from SFML
Post by: Redee on November 17, 2014, 02:47:09 pm
Okey, thank You.
I а little bit understand and try build >
Thor dev ver + SFML 2.1 rel ver + this example from Thor git repository.

I disappointed with no release version of Thor to SFML 2.1 release.

Maybe in latter versions of SFML will be integrate own resource manager?
Title: Re: How access to resource in DLL from SFML
Post by: Redee on November 17, 2014, 03:25:23 pm
Errors appeared.
Will try with SFML2 dev ver.

(https://farm6.staticflickr.com/5615/15625720019_13de60de6b_n.jpg) (https://farm6.staticflickr.com/5615/15625720019_13de60de6b_b.jpg)

I found extlibs and linked them.
Then need link DOXYGEN_EXECUTABLE.
Title: Re: How access to resource in DLL from SFML
Post by: Nexus on November 17, 2014, 05:44:38 pm
Yes, you need the latest GitHub revisions for both SFML and Thor.

Please read the installation tutorial (http://www.bromeon.ch/libraries/thor/v2.0/tutorial-installation.html), I've written it for a reason. And I've also tried to make the error message as expressive as possible. Regarding Doxygen, you must install it if you want to generate the documentation. Otherwise, just remove the corresponding tick.
Title: Re: How access to resource in DLL from SFML
Post by: Redee on November 18, 2014, 04:34:35 pm
Ok I read all in depth a few times.
Cloned repository https://github.com/Bromeon/Thor
And Export version f57666db6f187eb57bbc0947456cce2159a9b617 using TortoiseGit GUI.
(https://farm9.staticflickr.com/8258/15200455003_17528a1b5a_n.jpg) (https://farm9.staticflickr.com/8258/15200455003_fe62f76bfa_o.png)

If I all understand it fully support with SFML2.1 release version.
Then I try test with included examples at Thor directory.
Title: Re: How access to resource in DLL from SFML
Post by: Nexus on November 18, 2014, 04:55:07 pm
Why "export this version"? "Reset 'master' to this" (with "hard" flag) should be the correct one.

But don't you want to use the latest versions? And by the way, eXpl0it3r provides nightly builds for Thor, if you don't want to compile on your own.
Title: Re: How access to resource in DLL from SFML
Post by: Redee on November 18, 2014, 09:23:32 pm
Thanks for this great Library.
Me need test both versions for SFML2.1 and SFML dev master ver.
And need compile at this comp.

Now test for SFML2.1.

Everything successfully compiled >>

(https://farm8.staticflickr.com/7509/15798099206_c27a004bc0_n.jpg) (https://farm8.staticflickr.com/7509/15798099206_8d1a4f0736_o.png)

But when run I get exactly error at all examples >>

(https://farm9.staticflickr.com/8580/15635950449_2bcb18ec58_n.jpg) (https://farm9.staticflickr.com/8580/15635950449_a20329fcb8_o.png)

Sorry, one of examples normal run >>
It means no correct with SFML2.1 (yes like this because no use sfml dlls ::))

(https://farm8.staticflickr.com/7497/15636656317_d9b28a8ece_n.jpg) (https://farm8.staticflickr.com/7497/15636656317_5a273ed1a0_o.png)

Then try with both latest dev versions of Thor and SFML.
And then another earlier versions of Thor with Sfml2.1.

A lot of time else need but its many reasons to do this.
Compile at MSVC++10 Express on WinXP SP3.
Title: Re: How access to resource in DLL from SFML
Post by: Nexus on November 18, 2014, 09:36:42 pm
There might still be a misconfiguration (make sure you read both SFML and Thor tutorials carefully). But in the e-mail, you mentioned Windows XP? I'm not sure whether SFML is still compatible with XP; as far as I remember there have been some issues, but other people probably know better. Do you have the possibility to use a more modern Windows operating system (or maybe Linux)? Keep also in mind that Windows XP is not supported anymore by Microsoft, so security problems won't be fixed.

When you try the SFML examples (not Thor), do they run correctly?
Title: Re: How access to resource in DLL from SFML
Post by: Redee on November 18, 2014, 09:39:46 pm
Yes normal run my SFML2.1 test game engine.
Title: Re: How access to resource in DLL from SFML
Post by: Nexus on November 18, 2014, 09:50:13 pm
And the examples that you download with SFML? OpenGL, Pong, Shader, etc... Do they work flawlessly too?

If so, then it's a configuration problem. Make sure that the .dll files match the compiled .lib libraries for both Thor and SFML. Compile both projects with exactly the same configurations, settings and compiler flags. And most important: read the tutorial very carefully. You say the problem appears also when you use latest SFML and latest Thor revisions? Check if there are no old SFML/Thor versions left on your computer that are used accidentally.
Title: Re: How access to resource in DLL from SFML
Post by: Redee on November 18, 2014, 09:54:01 pm
Damn(sry), maybe I found problem.

Its SFML2.1 > Visual C++ 9 (2008) - 32 bits
I dl exactly this ver.

And because Aurora using at least Visual C++ 10 (2010) need the same.

Try this now.

Yes it was problem - successfully runs now!))).

(https://farm6.staticflickr.com/5615/15202713323_c9f3536a23_n.jpg) (https://farm6.staticflickr.com/5615/15202713323_1ec210af8b_o.png)
Title: Re: How access to resource in DLL from SFML
Post by: Redee on November 19, 2014, 10:14:05 pm
Ok, I read tutorial where explains about resources from files.
http://www.bromeon.ch/libraries/thor/v2.0/tutorial-resources.html

But me need get resource from file in some resource package  / DLL.

Any ideas to do this?

In game Zloxx v2.2
http://www.bromeon.ch/games/zloxx/index.html
we can see resource files > *.zlx
For example in Resources2.zlx a lot of *.png

Exactly it me need - like in game Zloxx for windows.
Compiling images / sounds to resource file and access from him.
Title: Re: How access to resource in DLL from SFML
Post by: Nexus on November 19, 2014, 11:03:58 pm
Good to hear that it runs :)

This is usually done in archive files. What they do is packing multiple files into a single one. There are already many existing formats like tar (https://en.wikipedia.org/wiki/Tar_(computing)). Sometimes they are coupled with compression and/or encryption. For an overview, see this Wikipedia article (https://en.wikipedia.org/wiki/Comparison_of_archive_formats).

You also need C or C++ libraries that support such formats. PhysicsFS is such an example.
Title: Re: How access to resource in DLL from SFML
Post by: Redee on November 20, 2014, 12:43:12 pm
Thank You for advices.
Many information need read else.
Its make my life harder).
Title: Re: How access to resource from DLL or resource package from SFML
Post by: Redee on November 21, 2014, 10:35:46 pm
Ok I completely read PNG file from ZIP and parse to SFML Image object using PhysicsFS 2.0.3
But... Its still accessible.
Need encryption with encryption catalogs and filenames.

Ok, we see PhysicsFS 2.1.0 support *.7z archives, which can do this.
http://icculus.org/physfs/docs-devel/html

Quote
Currently supported archive types:

    .ZIP (pkZip/WinZip/Info-ZIP compatible)
    .7Z (7zip archives)
    .ISO (ISO9660 files, CD-ROM images)
    .GRP (Build Engine groupfile archives)
    .PAK (Quake I/II archive format)
    .HOG (Descent I/II HOG file archives)
    .MVL (Descent II movielib archives)
    .WAD (DOOM engine archives)

Anyone knows - PhysicsFS 2.1.0 have access to *.7z with encryption password ?
I no see any function to do this.

Or me better use some unique Archive with reading Library for C++ ?

Now searching for information how more protect and block access to renamed zip files.
Maybe we can hardcodes - add some symbols to begin of archives ?
And access to archives skipping this symbols ?

But I think will be good use some 7z load Library for C++ which can do encryption access.
I read - in many sites says - PhysFS can't read archives with encryption.

Maybe good way use Crypto++ ?
Then question how read zip from memory using PhysFS ?

How about LZMA SDK ?
http://www.7-zip.org/sdk.html
Hmmmm, no solution for Visual Studio build.

Some answer at
http://stackoverflow.com/questions/18943794/compiling-lzma-sdk-in-c-creates-a-lib-and-i-want-a-dll-how-can-i-do-this

Will try do this later. A bit tired to search solutions.
Title: Re: How access to resource from DLL or resource package from SFML
Post by: Nexus on November 24, 2014, 02:19:19 am
Anyone knows - PhysicsFS 2.1.0 have access to *.7z with encryption password ?
I no see any function to do this.
The last time I tried, this was not possible. I doubt this has changed meanwhile.

How about LZMA SDK ?
http://www.7-zip.org/sdk.html
You don't want to use that. It's one of the ugliest C++ APIs I have ever seen, especially given its widespread use. At that time, the documentation was limited to one example code (the 7Zip application itself), which makes it very funny to figure things out. There is almost no abstraction, as a user you need to know how the algorithm works and deal with tedious low-level tasks like buffer allocations.

I can really not recommend using the LZMA functions directly. You're much better off writing an API to the 7Zip command line interface (which is far more intuitive). You can still do that through C++ code, just write functions that forward the CLI arguments to the 7Zip application ;)

Maybe we can hardcodes - add some symbols to begin of archives ?
And access to archives skipping this symbols ?
If you don't need compression, you can build a format yourself. It takes some work, but if you have experience with binary file reading/writing, it should be doable. If you don't, then learn it first, because debugging binary data is not too funny.

What you can do is have a index at the beginning of the file. In that index you store a resource name and its address within the file (i.e. number of bytes from the beginning). Every such entry has a fixed size, so you know where to look. The whole index can either be fixed-size or resizable, in the latter case you need to move the binary data within the archive, if there is no more space for the index entries.

Maybe good way use Crypto++ ?
Do you really need that sophisticated level of encryption? Just keep in mind that you will store the key somewhere in your executable or an external file, so an attacker is potentially able to gain access, regardless of your efforts. Considering that, you could also try something simpler like XOR... what do you need to encrypt?
Title: Re: How access to resource from DLL or resource package from SFML
Post by: Redee on November 24, 2014, 04:00:55 pm
Great responds!
I see encryption is no good solution and very vulnerable.
Case with build own format with read/write library looks pretty >Nice< but no way exactly for me - no enough level of C++.
Yes, extra symbols in archive bad decision too.

My main goal - protect resources from players / users, who tries simply rename to zip / rar and get access from TotalCommander for example. To see levels / bosses / abilities / textures / etc...
And encryption can be effective shield.
I no care about encryption key, its only to basic protect.
If they will know about key - they will )).

Ok, we have 7z resource archive package with AES-256 encryption with hide tree of catalogs and files.
Need C++ library to access to 7z archive (read from him).
Or access to resources to another archive format which do encryption with hide files and directories.