Change the convert.h structures to your old structures, put the files in src/util, compile convert.c, debug it. If you got it runnig, keep the convert.h up to date so if you change the structures again you just need to compile convert.c and it works again. -Jaco- /* * file: convert.c * Part of DiamondMud * Usage: Converts the PlayerFile to new structure. * Written by Jaco van Iterson */ #include <stdio.h> #include <ctype.h> #include "../structs.h" #include "convert.h" void convplay(char *); main(int argc, char *argv[]) { if (argc != 2) printf("Usage: %s playerfile-name\n", argv[0]); else convplay(argv[1]); } void convplay(char *filename) { FILE *ifp,*ofp; struct old_char_file_u old; struct char_file_u new; int i, len_oldbloc, len_newbloc; if (!(ifp = fopen(filename, "rb"))) { printf("Can't open %s.", filename); exit(); } ofp = fopen("players.new", "wb"); len_oldbloc = sizeof(old); len_newbloc = sizeof(new); printf("Length of old block is %d, length of new block is %d\n", len_oldbloc, len_newbloc); fseek(ifp, 0L, SEEK_END); if (ftell(ifp)%len_oldbloc) printf("Length of old file isn't a multiple of old block length\n"); rewind(ifp); while(fread(&old, len_oldbloc, 1, ifp), !feof(ifp)) { strcpy(new.name, old.name); strcpy(new.description, old.description); strcpy(new.title, old.title); strcpy(new.host, old.host); strcpy(new.poofin, old.poofin_txt); strcpy(new.poofout, old.poofout_txt); new.birth = old.birth; new.played = old.played; new.sex = old.sex; switch (old.race) { case 1: new.race = RACE_HUMAN; break; case 2: new.race = RACE_ELF; break; case 3: new.race = RACE_DWARF; break; case 4: new.race = RACE_HALFLING; break; case 5: new.race = RACE_GIANT; break; case 6: new.race = RACE_TROLL; break; default:new.race = -1; break; } switch (old.class) { case 1: new.class = CLASS_MAGE; break; case 2: new.class = CLASS_CLERIC; break; case 3: new.class = CLASS_THIEF; break; case 4: new.class = CLASS_FIGHTER; break; case 5: new.class = CLASS_SOHEI; break; case 6: new.class = CLASS_TEMPLAR; break; case 7: new.class = CLASS_DESPOILER; break; case 8: new.class = CLASS_RANGER; break; case 9: new.class = CLASS_ASSASSIN; break; default:new.class = -1; break; } new.level = old.level; new.weight = old.weight; new.height = old.height; new.righthanded = old.righthanded; new.hometown = old.hometown; strcpy(new.pwd, old.pwd); new.char_specials_saved.alignment = old.specials2.alignment; new.char_specials_saved.idnum = old.specials2.idnum; new.char_specials_saved.act = old.specials2.act; new.char_specials_saved.affected_by = 0; for(i=0;i<MAX_SKILLS;i++) new.player_specials_saved.skills[i] = old.skills[i]; new.player_specials_saved.spells_to_learn = old.specials2.spells_to_learn; for(i=0;i<MAX_TONGUE;i++) new.player_specials_saved.talks[i] = old.talks[i]; new.player_specials_saved.wimp_level = old.specials2.wimp_level; new.player_specials_saved.freeze_level = old.specials2.freeze_level; new.player_specials_saved.invis_level = 0; if (old.specials2.load_room < 1300) new.player_specials_saved.load_room = old.specials2.load_room-1100; else new.player_specials_saved.load_room = old.specials2.load_room; new.player_specials_saved.pref = old.specials2.pref; new.player_specials_saved.bad_pws = old.specials2.bad_pws; for (i=0;i<3;i++) new.player_specials_saved.conditions[i] = old.specials2.conditions[i]; new.abilities.str = old.abilities.str; new.abilities.str_add = old.abilities.str_add; new.abilities.intel = old.abilities.intel; new.abilities.wis = old.abilities.wis; new.abilities.dex = old.abilities.dex; new.abilities.con = old.abilities.con; new.abilities.cha = old.abilities.cha; new.points.mana = old.points.mana; new.points.max_mana = old.points.max_mana; new.points.hit = old.points.max_mana; new.points.max_hit = old.points.max_hit; new.points.move = old.points.move; new.points.max_move = old.points.max_move; new.points.armor = old.points.armor; new.points.gold = old.points.gold; new.points.bank_gold = old.points.bank_gold; new.points.exp = old.points.exp; new.points.hitroll = old.points.hitroll; new.points.damroll = old.points.damroll; for(i=0;i<MAX_AFFECT;i++) { new.affected[i].type = old.affected[i].type; new.affected[i].duration = old.affected[i].duration; new.affected[i].modifier = old.affected[i].modifier; new.affected[i].location = old.affected[i].location; new.affected[i].bitvector = old.affected[i].bitvector; new.affected[i].next = (struct affected_type *) -1; } new.last_logon = old.last_logon; fwrite(&new, len_newbloc, 1, ofp); } fclose(ifp); fclose(ofp); } /* ************************************************************************ * File: convert.h * * Usage: header file for conversion of the player file * * * * All rights reserved. See license.doc for complete information. * * * ************************************************************************ */ #define OLD_MAX_PWD_LENGTH 10 #define OLD_HOST_LENGTH 30 #define OLD_MAX_TONGUE 3 #define OLD_MAX_SKILLS 128 #define OLD_MAX_AFFECT 32 typedef signed char old_sbyte; typedef signed short int old_sh_int; typedef char old_byte; typedef unsigned char old_ubyte; typedef char old_bool; /* Used in CHAR_FILE_U *DO*NOT*CHANGE* */ struct old_char_ability_data { old_sbyte str; old_sbyte str_add; /* 000 - 100 if strength 18 */ old_sbyte intel; old_sbyte wis; old_sbyte dex; old_sbyte con; old_sbyte cha; }; /* Used in CHAR_FILE_U *DO*NOT*CHANGE* */ struct old_char_point_data { old_sh_int mana; old_sh_int max_mana; /* Max move for PC/NPC */ old_sh_int hit; old_sh_int max_hit; /* Max hit for PC/NPC */ old_sh_int move; old_sh_int max_move; /* Max move for PC/NPC */ old_sh_int armor; /* Internal -100..100, external -10..10 AC */ int gold; /* Money carried */ int bank_gold; /* Gold the char has in a bank account */ int exp; /* The experience of the player */ old_sbyte hitroll; /* Any bonus or penalty to the hit roll */ old_sbyte damroll; /* Any bonus or penalty to the damage roll */ }; struct old_char_special2_data { long idnum; /* player's idnum */ old_sh_int load_room; /* Which room to place char in */ old_byte spells_to_learn;/* How many can you learn yet this level*/ int alignment; /* +-1000 for alignments */ long act; /* act flag for NPC's; player flag for PC's */ long pref; /* preference flags for PC's. */ int wimp_level; /* Below this # of hit points, flee! */ old_byte freeze_level; /* Level of god who froze char, if any */ old_ubyte bad_pws; /* number of bad password attemps */ old_sh_int apply_saving_throw[5]; /* Saving throw (Bonuses) */ old_sbyte conditions[3]; /* Drunk full etc. */ }; /* Used in CHAR_FILE_U *DO*NOT*CHANGE* */ struct old_affected_type { old_sbyte type; /* The type of spell that caused this */ old_sh_int duration; /* For how long its effects will last */ old_sbyte modifier; /* This is added to apropriate ability */ old_byte location; /* Tells which ability to change(APPLY_XXX)*/ long bitvector; /* Tells which bits to set (AFF_XXX) */ struct old_affected_type *next; }; /* *********************************************************************** * file element for player file. BEWARE: Changing it will ruin the file * *********************************************************************** */ struct old_char_file_u { time_t birth; /* Time of birth of character */ int played; /* Number of secs played in total */ old_byte sex; old_byte race; old_byte class; old_byte level; old_ubyte weight; old_ubyte height; old_ubyte hometown; old_ubyte clan; old_ubyte guild; old_ubyte subguild; old_bool righthanded; old_byte skills[OLD_MAX_SKILLS]; old_bool talks[OLD_MAX_TONGUE]; struct old_affected_type affected[OLD_MAX_AFFECT]; struct old_char_special2_data specials2; struct old_char_ability_data abilities; struct old_char_point_data points; time_t last_logon; /* Time (in secs) of last logon */ char host[OLD_HOST_LENGTH+1]; /* host of last logon */ /* char data */ char name[20]; char pwd[OLD_MAX_PWD_LENGTH+1]; char title[80]; char description[240]; char poofin_txt[80]; char poofout_txt[80]; };
This archive was generated by hypermail 2b30 : 12/18/00 PST