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...
.
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.