2 registered members (AndrewAMD, TipmyPip),
12,672
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Your own RESOURCE file without A6PRO edition
#55025
09/15/05 18:43
09/15/05 18:43
|
Joined: Aug 2005
Posts: 1,185 Ukraine
Lion_Ts
OP
Serious User
|
OP
Serious User
Joined: Aug 2005
Posts: 1,185
Ukraine
|
Hi ! Do you want to have your own easy managable resource? Or your funny small game eats about 200Mb on HDD but same game from competitor is 70Mb size? And you don't have 3DGS PRO edition? With some restrictions I'll give it to you... It's free, and it can be adjusted for your need by yourself  . But if you use this, you must provide credits in your game:
to Jean-loup Gailly and Mark Adler - www.zlib.org to Gilles Vollant - www.winimage.com to LionTs (Leonid Tsinitskiy) - www.lionts.com
Quote:
... Condition of use and distribution are the same than zlib : This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. ...
From the 3dgs manual: Quote:
add_buffer(char* name,void* buffer) Adds a named buffer to the engine file system. If the engine afterwards attempts to open a file with the given name, it reads out of the buffer rather than loading the file from the hard disk. This allows to add a user defined file resource system in an external language.
We have an idea... And implementation (C++): Code:
//Place this into sample.cpp in sdk ... #include "unzip.h" #include "iowin32.h" const char *zipfilename="RESOURCE.ZIP\0"; ... int do_extract_currentfile(unzFile uf) { char filename_inzip[256]; char* filename_withoutpath; char* p; int err=UNZ_OK; FILE *fout=NULL; void* buf; uInt size_buf;
unz_file_info file_info; uLong ratio=0; err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0); if (err!=UNZ_OK) return err; size_buf = file_info.uncompressed_size ; buf = (void*)malloc(size_buf); if (buf==NULL) return UNZ_INTERNALERROR; p = filename_withoutpath = filename_inzip; while ((*p) != '\0') { if (((*p)=='/') || ((*p)=='\\')) filename_withoutpath = p+1; p++; } //you can pass zip password for your resource err = unzOpenCurrentFilePassword(uf,NULL); err = unzReadCurrentFile(uf,buf,size_buf); add_buffer(filename_withoutpath,buf); unzCloseCurrentFile (uf); //you have to return error code //this is quick example, so I don't //engine may crash if zip is errornous return 0; }
int do_extract(unzFile uf) { uLong i; unz_global_info gi; int err=UNZ_OK; FILE *fout=NULL;
err = unzGetGlobalInfo (uf,&gi); if (err==UNZ_OK) { for (i=0;i<gi.number_entry;i++){ err = do_extract_currentfile(uf); if ( err != UNZ_OK) break; if ((i+1)<gi.number_entry){ err = unzGoToNextFile(uf); if (err!=UNZ_OK) break; } } } return err; } DLLFUNC var add_zip_resource() { unzFile uf=NULL; int err; char* pass; //you can pass resource name and password for zip archive from c-script //this is quick example, so I don't uf = unzOpen(zipfilename); if (uf == NULL) return var(-1); err = do_extract(uf); unzClose(uf); return var(err); }
Needed files to compile project you can download from http://www.zlib.org If you don't need to change my code or want to try it: Place ZIPRES.DLL into your plugin folder. Create simple zip v2.0 (deflate method) archive with your models, images, sounds (without subdirs and password). Name it RESOURCE.ZIP and place into game folder. In your c-script: Code:
... dllfunction add_zip_resource() var; ... function main(){ if (add_zip_resource() != 0 ) { ...show message... exit; } ...
Somewhere in your code (it's example, provide your own resources & code): Code:
... entity* temp_entity; bmap* temp_bmap; ... temp_entity=ent_create("yor_model.mdl",temp_pos,temp_action); temp_bmap=bmap_create("your_image.tga"); ... bmap_lock(temp_bmap,0); ... ent_playloop (temp_entity, temp_sound, 100); ...
You can place into archive c-script files also, then load it and execute with console ( execute(STRING) ). In small test level you'll can see, that WMB and MDL files loaded automatically, when level has been loaded. To manage resources (add, remove,replace) you can use your archivator (WinRar, WinZip or alike, just don't forget to create .zip v2.0), not BIND... and 'File|Resource...'  All code tested and working well. Same technique I'm using in my game project (I don't have 3DGSpro, may be Conitec has one for free ? ). And for last word, you may write your own archiving/encrypting methods, may be better than zlib. And use similar code to add buffers to engine file system.
That's all and thank you for reading my bad English.
Last edited by Lion_Ts; 09/15/05 18:54.
|
|
|
Re: Your own RESOURCE file without A6PRO edition
[Re: Matt_Coles]
#55028
09/15/05 22:58
09/15/05 22:58
|
Joined: Sep 2003
Posts: 5,900 Bielefeld, Germany
Pappenheimer
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
|
Quote:
extremely handy contribution, it won't let me download the test level, but the dll downloads fine, thanks Lion TS
The same!
Thanks a lot!
|
|
|
Re: Your own RESOURCE file without A6PRO edition
[Re: Christian__A]
#55032
09/16/05 10:45
09/16/05 10:45
|
Joined: Sep 2003
Posts: 9,859
FBL
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 9,859
|
Quote:
maybe i didnt see that, but is it possible to set a password for the .zip-file ? otherwise everybody would be able to open the .zip and get everything he wants...
i will test this soon. thank you for sharing it!
yes. See Source above.
|
|
|
Re: Your own RESOURCE file without A6PRO edition
[Re: FBL]
#55033
09/16/05 11:11
09/16/05 11:11
|
Joined: Aug 2005
Posts: 1,185 Ukraine
Lion_Ts
OP
Serious User
|
OP
Serious User
Joined: Aug 2005
Posts: 1,185
Ukraine
|
Hi! I'm confused with 3dgs... In manual described functions: - ent_create - bmap_create - snd_create With third I have problem: sound* give to me an errror while interpreted by engine (yes, sound* not recognized by engine as type, so snd_create from help is useless). I change code to: Code:
function* temp_snd; //it's a pointer to a byte (like void*) ... temp_snd=snd_create("temp.wav"); ...
All ok. It's worked, when "temp.zip" is presented in game dir. But when I place "temp.wav" to zipped resource, engine says "format or device unavailable". Can somebody to think about it with me ? Oh, I'm using GS Commercial v6.31.4 / WED v6.259 (as reported by WED).
|
|
|
|