home *** CD-ROM | disk | FTP | other *** search
- // Immortal Player V2.0 Copyright (c) 1991 IP Makers
-
- // This module inputs data for crack; runtime part is hidden in class IP
- // Compile this file in tiny model
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <string.h>
- #include <dir.h>
- #include "ip.h"
-
- extern getWord( char*, FILE* );
- extern void getData( DataIP&, char* );
- extern void eatExtension( char* );
-
- char CommandLine[ 128 ];
- int Line = 1;
- DataIP Data;
-
- main( int nargs, char* arg[] )
- {
- printf( "The Immortal Player Version 2.0 Copyright (c) 1991 IP Makers\n" );
-
- if( nargs < 2 ) { // Argument is the name
- printf( "Game is not specified\n" ); // of game;
- exit(0); // two files with the same
- } // name and extension
- strcpy( CommandLine, arg[1] ); // ip & ( bat | com | exe )
- // must exist in a directory
- eatExtension( CommandLine );
- strcat( CommandLine, ".ip" );
- getData( Data, CommandLine ); // Get data from .ip file
-
- struct ffblk ffblk; // Check if .bat,
- eatExtension( CommandLine ); // .com or .exe
- strcat( CommandLine, ".bat" ); // file exists in a
- if( findfirst( CommandLine, &ffblk, 0 )){ // directory
- eatExtension( CommandLine );
- strcat( CommandLine, ".com" );
- if( findfirst( CommandLine, &ffblk, 0 )){
- eatExtension( CommandLine );
- strcat( CommandLine, ".exe" );
- if( findfirst( CommandLine, &ffblk, 0 )){
- eatExtension( CommandLine );
- printf( "%s: can't find executable file\n", CommandLine );
- exit(1);
- }
- }
- }
- int i = 2;
- while( strcmp( arg[i],"")){ // Form command line
- strcat( CommandLine, " " ); // for function "sytsem"
- strcat( CommandLine, arg[i++] );
- }
-
- IP Game( CommandLine, &Data ); // Create object of class IP
- }
-
- // getData: opens file and gets data in convinient format
- // exits on a first wrong number
-
- void getData( DataIP& data, char* FileName )
- {
- char buffer[ 256 ];
- char* endptr;
- FILE* in = fopen( FileName, "r" );
-
- if( !in ) {
- printf( "Can't open file %s\n", FileName );
- exit(1);
- }
- do {
- if( !getWord( buffer, in )) {
- printf( "Error in file %s: delay is not specified\n", FileName );
- exit(1);
- }
- } while( !( data.delay = strtoul( buffer, &endptr, 16 )));
-
- int i = 0;
- while( 2*2 == 4 )
- {
- do {
- if( !getWord( buffer, in ))
- if( !i ) {
- printf( "Error in file %s: offset is not specified\n", FileName );
- exit(1);
- }
- else
- return;
- } while( !( data.change[i].offset = strtoul( buffer, &endptr, 16 )));
- if( data.change[i].offset < 256 ){
- printf( "Error in file %s, Line %d: offset must exceed 0FF\n", FileName, Line );
- exit(1);
- }
- unsigned long tmp;
- do {
- if( !getWord( buffer, in )) {
- printf( "Error in file %s, Line %d: value is not specified\n", FileName, Line );
- exit(1);
- }
- } while( !( tmp = strtoul( buffer, &endptr, 16 )));
- if( tmp > 255 ){
- printf( "Error in file %s, Line %d: value must not exceed 0FF\n", FileName, Line );
- exit(1);
- }
- data.change[i].value = tmp;
- i++;
- }
- }
-
- // getWord: takes one word from stream and returns its length,
- // returns 0 if the end of file has been reached;
- // word :: digit { digit | char }
-
- getWord( char *s, FILE* in )
- {
- static char ch = ' ';
- int n = 0;
-
- if( ch == '\n' )
- Line--;
- while( !isdigit( ch )){
- if( feof( in ))
- return 0;
- if( ch == '\n' )
- Line++;
- ch = fgetc( in );
- }
- do {
- *s++ = ch;
- n++;
- ch = fgetc( in );
- if( ch == '\n' )
- Line++;
- if( feof( in )){
- *s = 0;
- return n;
- }
- } while( isalnum( ch ));
- *s = 0;
- return n;
- }
-
- // eatExtension: silently eats extension of dos file
-
- void eatExtension( char* s ){ while( *s != '.' && *s++ != 0 ); *s = 0; }