/* * eDiv Executable Stub * Copyleft (C) 2000-2002 Sion Entertainment * http://www.sion-e.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include "extern.h" #include "main.h" //#include "kernel.h" #include "inte.h" #include "varindex.h" #include "fatal.h" #define long_header 9 // Longitud de la cabecera al inicio de los programas /* Main ( argc, argv ) * * Rutina principal. Lee el bytecode del ejecutable, lo descomprime y lo carga en memoria * (La mayoría de las variables y buffers se mantienen con el mismo nombre que en el compilador: * mem, imem_max, etc) */ int main(int argc, char* argv[]) { //FILE *f; int f , i; int stub_size; int mimem[10]; Uint32 tiempo[100] , tiempo_i ; FILE *file_tiempo ; byte * ptr; unsigned long len,len_descomp; byte* vartemp; byte* p; Uint8* teclas; char capturef[50]; //const SDL_version* sdl_version; #ifdef DBG int start_lin; int linsize; int comp_size; int descomp_size; char* progcomp; #endif numdlls=0; n_externs=0; eDIV_InstallParachute(); /*sdl_version=SDL_Linked_Version(); #ifdef _DEBUG printf("Versión SDL del exe: %d.%d.%d\n",SDL_MAJOR_VERSION,SDL_MINOR_VERSION,SDL_PATCHLEVEL); printf("Versión de SDL instalada: %d.%d.%d\n",sdl_version->major,sdl_version->minor,sdl_version->patch); #endif if(sdl_version->majormajor==SDL_MAJOR_VERSION && sdl_version->minormajor==SDL_MAJOR_VERSION && sdl_version->minor==SDL_MINOR_VERSION && sdl_version->patchmajor,sdl_version->minor,sdl_version->patch); } */ for ( i = 0 ; i < 100 ; i++ ) tiempo[ i ] = 0 ; tiempo_i = 0 ; file_tiempo = fopen( "time.txt" , "w+" ) ; #ifdef _WIN32 f=strlen(argv[0]); if(argv[0][f-4]!='.' || (argv[0][f-3]!='e' && argv[0][f-3]!='E') || (argv[0][f-2]!='x' && argv[0][f-2]!='X') || (argv[0][f-1]!='e' && argv[0][f-1]!='E')) { strcat(argv[0],".exe"); } #endif // assert(0) ; if((f=open(argv[0],O_RDONLY | O_BINARY))==-1) { /*#ifdef WIN32 strcat(argv[0],".exe"); printf("%s\n",argv[0]); if((f=open(argv[0],O_RDONLY | O_BINARY))==-1) #endif*/ critical_error(1); // error leyendo el código del programa } lseek(f,-4,SEEK_END); read(f,&stub_size,4); printf("STUB_SIZE: %d\n",stub_size); lseek(f,stub_size,SEEK_SET); p=nombre_program; do { read(f,p,1); } while(*p++!=0); read(f,mimem,4*10); read(f,&len,4); iloc_len=(mimem[5]+mimem[6]); if (iloc_len&1) iloc_len++; if (mimem[3]>0) { imem_max=mimem[8]+mimem[3]*(iloc_len)+iloc_len+2; } else { imem_max=mimem[8]+128*(iloc_len)+iloc_len+2; if (imem_max<256*1024) imem_max=256*1024; if (imem_max>512*1024) imem_max=512*1024; } if ((mem=(int*)malloc(4*imem_max+1032*5+16*1025+3))!=NULL){ mem=(int*)((((int)mem+3)/4)*4); //filenames=(char*)&mem[imem_max+258*5]; // Buffer de 16*1025 para dirinfo[].name memset(mem,0,4*imem_max+1032*5); // Para sumar cadenas "en el aire" /* nullstring[0]=imem_max+1+258*0; mem[nullstring[0]-1]=0xDAD00402; nullstring[1]=imem_max+1+258*1; mem[nullstring[1]-1]=0xDAD00402; nullstring[2]=imem_max+1+258*2; mem[nullstring[2]-1]=0xDAD00402; nullstring[3]=imem_max+1+258*3; mem[nullstring[3]-1]=0xDAD00402;*/ memcpy(mem,mimem,40); if ((ptr=(byte*)malloc(len))!=NULL) { read(f,ptr,len); len_descomp=mem[9]; if (!uncompress((unsigned char *)&mem[9],&len_descomp,ptr,len)) { free(ptr); #ifdef DBG if ((mem[0]&64)==64) { debug=1; mem[0]-=64; } #endif if ((mem[0]&512)==512) { ignore_errors=1; mem[0]-=512; } /*i=imem_max+258*4; if ((_argc=argc-1)>10) _argc=10; for (n=0;n<_argc && n 99 ) tiempo_i = 0 ; tiempo[ tiempo_i ] = SDL_GetTicks() ; if ( tiempo_i == 99 ) global("fps") = 100000 / (tiempo[99] - tiempo[0]) ; else if ( tiempo[tiempo_i] - tiempo[tiempo_i+1] != 0 ) global("fps") = 100000 / (tiempo[tiempo_i] - tiempo[tiempo_i+1] ) ; //SDL_BlitSurface( imagen1 , NULL , screen , NULL ) ; //SDL_Flip(screen); } stub_quit(0); // fin del programa } else { close(f); free(ptr); critical_error(1); // error leyendo el código del programa } } else { close(f); critical_error(1); // error leyendo el código del programa } } else { close(f); error(1); } // error leyendo el código del programa return 0; } //#include void stub_quit(int n) { int i; //assert(0); Call_Entrypoint(EDIV_quit); for(i=0;i