#include #include #include // exit, atexit #include #include #include #define llen1 38 #define llen2 14 #define undefined 500 FILE *fp; /* Player file */ FILE *fd; /* Data file */ // FILE *fo; /* Old file, player.bak */ char array2[255][81]; // Array that holds the total descriptions for one page. char dstring[llen1+1]; // String that holds the description of one item. char *fpdir="savex/player.dat"; char *fpbakdir="savex/player.bak"; // Player file dir & backup dir. int dquit=0; // Quit the program when dquit!=0. int page=0; // Each page=26 lines. Alter this for screen. int errtype=0; // Used on exit. int dn; // Number of bytes in the equip area of player.dat. unsigned char i[2048]; // Array. Holds equip area of player.dat. Must be last globally declared. void dexit(void) { char errfile[12]; if (errtype==(errtype&1)) { strcpy(errfile,"data.dat"); } else strcpy(errfile,"player.dat"); switch (errtype) { case 0 : puts("Program terminated normally."); break; case 1 : case 2 : printf("Error during file seek in %s.\n",errfile); puts("File may be truncated or missing."); break; case 3 : case 4 : printf("Error during file access in %s.\n",errfile); puts("file may be truncated or missing."); break; case 5 : case 6 : printf("Cannot open %s. Aren't you in the UW2 directory?\n",errfile); puts("File may be missing."); if (errtype==6) { puts("Disk may be full or the file write protected."); puts("Are you sure you have made this save?"); } break; case 7 : puts("Memory request failed; try removing some of that TSR crap"); puts("from memory. Or maybe buy me some more RAM. You think I'm"); puts("happy having to make do with as much memory as a goldfish?"); break; case 8 : puts("Couldn't open charactr.inf file in your UW directory."); puts("Can't think of any logical reason, but I have"); puts(" errortrapped against it just in case. Fortunately for you."); break; case 9 : printf("Couldn't create backup file %s",fpbakdir); puts(" in your uw2 directory."); default : puts("Unknown error in program."); puts("Might be best to delete it and recompile."); break; } fcloseall(); } char *getdesc(int itemtype,int offset) { // ( byte1 ,low bit of byte 2). int offset2; offset2=(offset*256*llen1); /* above is the offset for file position if 2nd byte is odd, else 0 */ if (fseek(fd,(itemtype*llen1)+offset2,SEEK_SET)) { errtype=1; exit(1); } /* moved to right place in file */ if(!fgets(dstring,llen1,fd)) { errtype=3; exit(3); } /* get the description string to dstring */ dstring[llen1-2]='\0'; return(dstring); } void ddotop(void) { printf("ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÑÍÍÍÍ"); puts("ÍÍÍÍÍÑÍÍÍÍÍÍÍÍÍÍÍÍÑÍÍÍÍÍÍÍÍÍÍÍÍ»"); printf("º Item(s) from %16s, page %2d ³ Qua",fpdir,page+1); puts("lity ³ Number ³ Position º"); printf("ÇÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄ"); puts("ÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄĶ"); } void ddobot(void) { printf("ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÏÍÍÍÍ"); puts("ÍÍÍÍÍÏÍÍÍÍÍÍÍÍÍÍÍÍÏÍÍÍÍÍÍÍÍÍÍÍͼ"); } void dtypeed(int dch) { int changeto,doffed; puts("Editing the type of item."); puts(" Input the item number, followed by the offset.\n"); changeto=undefined; while ((changeto<0x0)||(changeto>0xFF)) { printf("Item number (00-FF): "); scanf("%x",&changeto); } doffed=undefined; while ((doffed<0x0)||(doffed>0x1)) { printf("Offset (0/1): "); scanf("%d",&doffed); } puts("The item has been changed to:"); stpcpy(&array2[dch][4],getdesc(changeto,doffed)); array2[dch][39]=' '; i[dch*8+(page*26*8)]=changeto; i[dch*8+(page*26*8)+1]=(i[dch+1]&254)|doffed; // added the '*8+(page*26*8)'. ddotop(); printf("%s\n",array2[dch]); ddobot(); // Should check for changing bags to other objects. /* Could check for certain linked objects (information scrolls, blackrock jems, map fragments) and offer to give the correct link. */ } void dqualed(int dch) { int changeto; puts("Editing the item quality."); puts("Input the quality in decimal."); changeto=undefined; while ((changeto<0)||(changeto>255)) { printf("Quality (0-255): "); scanf("%d",&changeto); } puts("The item's quality has been changed to:"); sprintf(&array2[dch][44],"%3d",changeto); array2[dch][47]='/'; i[dch+3]=(i[dch+3]&63) |(changeto<<6); i[dch+4]=(i[dch+4]&192)|(changeto>>2); ddotop(); printf("%s\n",array2[dch]); ddobot(); } void dnumbed(int dch) { int changeto; puts("Editing the number of items."); puts("Input the quantity in decimal."); changeto=undefined; while ((changeto<0)||(changeto>255)) { printf("Quantity (0-255): "); scanf("%d",&changeto); } puts("The item's quality has been changed to:"); sprintf(&array2[dch][57],"%3d",changeto); array2[dch][60]=' '; i[dch+6]=(i[dch+6]&63) |(changeto<<6); i[dch+7]=(i[dch+7]&192)|(changeto>>2); ddotop(); printf("%s\n",array2[dch]); ddobot(); } void dposied(int dch) { dch++; //temporary...prevents warnings. puts("dposied"); //will have to check for duplicate positions. } void dsave(void) { int alwp; if (fseek(fp, 995L, SEEK_SET)) { errtype=1; exit(1); } for (alwp=0;alwp<=dn;alwp++) { fwrite(&i[alwp],1, 1,fp); /* write struct s to file */ } } void dfillstring(void) { unsigned int posit,pagen,alwp,blwp,za,zb,dofset; int tmp1,tmp2; char iplace[llen2+1]; pagen=26*8*page; // number of bytes in data descriptions of all the previous pages. for (alwp=pagen; (alwp<(pagen+8*26))&&(alwp>2; // byte2 (all) if (fseek(fp,0x3a3,SEEK_SET)) { errtype=1; exit(1); } for (blwp=0;blwp<19;blwp++) { /* loop to check for a match in the position list. */ tmp1=fgetc(fp); tmp2=fgetc(fp); if ((tmp1==EOF)||(tmp2==EOF)) { errtype=3; exit(3); } if ((tmp1==za)&&(zb==tmp2)) { /* if match found then get the name of the place. */ if (fseek(fd,(blwp*llen2)+(512*llen1),SEEK_SET)) { errtype=1; exit(1); } if (!fgets(iplace,llen2-2,fd)) { errtype=3; exit(3); } blwp=19; } else strcpy(iplace," Container."); } // *** Fill out strings. *** dofset=(i[alwp+1]&1); /* above is the offset: 1 if 2nd byte is odd, else 0. */ strcpy(dstring,getdesc(i[alwp],dofset)); posit=(alwp/8)-(pagen/8); // Gives item number in page. sprintf(&array2[posit][0],"º%c",(char)((alwp/8)-pagen/8+'A')); // letter (%c) used to select item. sprintf(&array2[posit][2],") %s ³ ",dstring); // name (%s) sprintf(&array2[posit][44],"%3d/255 ³ ",(i[alwp+3]>>6)|((i[alwp+4]<<2)&252)); // quality/63 (%d) sprintf(&array2[posit][54],"%6d ³", (i[alwp+6]>>6)|((i[alwp+7]<<2)&252)); // quantity (%d) sprintf(&array2[posit][66]," %10sº",iplace); } } void dchange(void) { FILE *chrinf; // save file for save screen. int alwp, numpage; numpage=page*26; // number of lines in the pages before the present one. ddotop(); for (alwp=0;(alwp<(dn/8)-(numpage))&&(alwp<26);alwp++) { printf("%s\n",array2[alwp]); } printf("º1) Create a new item. <,> Change page. ³ --/"); puts("-- ³ --- ³ ---------- º"); printf("º2) Save alterations. 3) Change file. ³ --/"); puts("-- ³ --- ³ ---------- º"); printf("º4) Save screen 0) Exit editor. ³ --/"); puts("-- ³ --- ³ ---------- º"); ddobot(); char dch,dletdet; int dchosen; puts("Change which item? (a-z,1-4,<,>,0)"); dch='0'; while (dch!='ª') { dch=toupper(getche()); clrscr(); switch (dch) { case 'ª' : dch='0'; break; case '1' : case '!' : puts("Sorry, I haven't got create item yet."); dch='ª'; break; case '2' : case '"' : puts("Save: save all changes? (y/N)"); dch=toupper(getche()); if ((dch=='Y')||(dch=='y')) { clrscr(); puts("Saving changes."); dsave(); } else puts("Changes NOT saved."); dch='ª'; break; case '3' : case 'œ' : puts("Load new file: save all changes? (y/N)"); dch=toupper(getche()); if ((dch=='Y')||(dch=='y')) { clrscr(); puts("Saving changes..."); dsave(); } else puts("Changes NOT saved."); if (fclose(fp)==EOF) { errtype=4; exit(4); } fpdir[4]='x'; while (fpdir[4]<'1'||fpdir[4]>'4') { clrscr(); puts("Which save now?"); fpdir[4]=getche(); } if ((fp=fopen((const char *)fpdir,"r+b"))==NULL) { errtype=6; exit(6); } if (fseek(fp, 995L, SEEK_SET)) { errtype=2; exit(2); } for(dn=0; (fread(&i[dn],1,1,fp))==1;dn++); dfillstring(); page=0; dch='ª'; break; case '4' : case '$' : puts("Saving screen to file named charactr.inf in UW directory."); if ((chrinf = fopen("charactr.inf", "at")) == NULL) { errtype=8; exit(8); } fprintf(chrinf,"ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÑÍÍÍÍ"); fprintf(chrinf,"ÍÍÍÍÍÑÍÍÍÍÍÍÍÍÍÍÍÍÑÍÍÍÍÍÍÍÍÍÍÍÍ»\n"); fprintf(chrinf,"º Item(s) from %16s, page %2d ³ Qua",fpdir,page+1); fprintf(chrinf,"lity ³ Number ³ Position º\n"); fprintf(chrinf,"ÇÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄ"); fprintf(chrinf,"ÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄĶ\n"); for (alwp=0;(alwp<(dn/8)-(numpage))&&(alwp<26);alwp++) { fprintf(chrinf,"%s\n",array2[alwp]); } fprintf(chrinf,"ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÏÍÍÍÍ"); fprintf(chrinf,"ÍÍÍÍÍÏÍÍÍÍÍÍÍÍÍÍÍÍÏÍÍÍÍÍÍÍÍÍÍÍͼ\n"); fclose(chrinf); dch='ª'; break; case '0' : case ')' : puts("Exit program: save first? (Y/n)."); dch=toupper(getche()); if ((dch=='N')||(dch=='n')) { clrscr(); puts("File NOT saved. Bye!"); exit(0); } else { puts("Saving player.dat..."); dsave(); // clrscr(); puts("File saved. Have a nice game!"); exit(0); } dch='ª'; break; case '.' : case '>' : if (page<(dn/(26*8))) { page++; dfillstring(); } dch='ª'; break; case ',' : case '<' : if (page>0) { page--; dfillstring(); } dch='ª'; break; default : if ((dch>='A')&&(dch<='Z')&&(dch<(dn/8-page*26+'A'))) { dchosen=(int)(dch-'A'); // details are now in array2[dchosen] printf("You have chosen %c, or number %d\n",dch,dchosen); ddotop(); printf("%s\n",array2[dchosen]); //removed the +numpage from here. ddobot(); puts("Type the first letter of the field you want to edit."); dletdet='0'; while (dletdet!='ª') { dletdet=toupper(getche()); switch(dletdet) { case 'ª' : dletdet='0'; break; case 'I' : dtypeed(dchosen); dletdet='ª'; break; case 'Q' : dqualed(dchosen); dletdet='ª'; break; case 'N' : dnumbed(dchosen); dletdet='ª'; break; case 'P' : dposied(dchosen); dletdet='ª'; break; } } } dch='ª'; break; } } } void dmenu(void) { puts("Display menu."); } void drunuw(void) { puts("Run UW2."); } void main(void) { FILE *fpbak; atexit(dexit); if (!i) { errtype=7; exit(7); } while (fpdir[4]<'1'||fpdir[4]>'4') { clrscr(); puts("Hello you lame hacker, which of your wimpy"); puts(" saves do you want to improve?"); fpdir[4]=getche(); fpbakdir[4]=fpdir[4]; } if ((fd=fopen("data.dat","r"))==NULL) { //should this be rb or rt? errtype=5; exit(5); } if ((fp=fopen((const char *)fpdir,"r+b"))==NULL) { errtype=6; exit(6); } /* Program to create backup of the player.dat file */ if ((fpbak=fopen((const char *)fpbakdir, "wb"))== NULL) { errtype=9; exit(9); } do { fputc(fgetc(fp), fpbak); } while (!feof(fp)); fclose(fpbak); if (fseek(fp, 995L, SEEK_SET)) { errtype=2; exit(2); } //backup file is one byte longer than the original...I wouldn't risk it. for(dn=0; (fread(&i[dn],1,1,fp))==1;dn++); printf("\n"); dfillstring(); while(dquit==0) { dchange(); /* clrscr(); */ } exit(0); }