[comp.sources.games.bugs] omega 0.70.5 patches so that it can run on a Vax

kyrimis@notecnirp.Princeton.EDU (Kriton Kyrimis) (03/25/88)

Omega 0.70.5 makes some implicit assumptions about being executed
on a sun, which makes it impossible to run under different archi-
tectures (namely, a vax) or compilers. The  problem  is  that  it
reads two binary files, omon.dat and oitem.dat. Not only do these
contain integers, which are stored in machine specific order, but
they  also  contain  structures,  which are padded differently by
different compilers.

Included here is a set of modifications that I made to 0.70.5  to
make  it  run  on  both  suns and vaxes (though they've only been
tested on a vax). They seem to work, but no guarantees are  made.
Yes,  I  know that the code is still machine dependent. (If ints,
longs and pointers aren't four bytes long,  all  bets  are  off!)
This  is  only  a temporary kludge. Hopefully, this will be fixed
more cleanly in 0.70.6. To apply the fixes, follow  the  instruc-
tions in the ReadMe file.

	Kriton	(UUCP: allegra!princeton!kyrimis)
	      	(ARPA: kyrimis@princeton.edu)
-----
"I am not interested in the beliefs of primitives - only in
 what they *taste* like!"
-----
----------------------------CUT  HERE----------------------------
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create:
#	ReadMe
#	convitem.c
#	convmon.c
#	makefile.notsun.diffs
#	odefs.h.diffs
#	oinit.c.diffs
#	structs.h
# This archive created: Thu Mar 24 12:49:01 1988
export PATH; PATH=/bin:/usr/bin:$PATH
echo shar: "extracting 'ReadMe'" '(596 characters)'
if test -f 'ReadMe'
then
	echo shar: "will not over-write existing file 'ReadMe'"
else
sed 's/^	X//' << \SHAR_EOF > 'ReadMe'
	XInstructions for patching omega 0.70.5 to run on a vax:
	X
	XPatch odefs.h:
	X	patch odefs.h odefs.h.diffs
	X
	XPatch oinit.c:
	X	patch oinit.c oinit.c.diffs
	X
	XIf you are using makefile.notsun, patch that, too:
	X	patch makefile.notsun makefile.notsun.diffs
	X
	XConvert omon.dat:
	X	cp omon.dat omon.dat.orig
	X	cc convmon.c
	X	a.out < omon.dat.orig > omon.dat
	X
	XConvert oitem.dat:
	X	cp oitem.dat oitem.dat.orig
	X	cc convitem.c
	X	a.out < oitem.dat.orig > oitem.dat
	X
	XEdit odefs.h:
	X	Make sure that FLIP is defined if your machine stores integers
	X	in the reverse order to that of the sun (eg. it's a vax). Undef
	X	it otherwise.
SHAR_EOF
if test 596 -ne "`wc -c < 'ReadMe'`"
then
	echo shar: "error transmitting 'ReadMe'" '(should have been 596 characters)'
fi
fi
echo shar: "extracting 'convitem.c'" '(729 characters)'
if test -f 'convitem.c'
then
	echo shar: "will not over-write existing file 'convitem.c'"
else
sed 's/^	X//' << \SHAR_EOF > 'convitem.c'
	X#include "stdio.h"
	X#include "structs.h"
	X
	X#define C(x) o.x = Objects[i].x
	X#define CC(x) for(j=0;j<64;j++) o.x[j] = Objects[i].x[j]
	X
	Xmain()
	X{
	X  struct o_object Objects[TOTALITEMS];
	X  struct object o;
	X  int i, j;
	X
	X  fread((char *) Objects,sizeof(struct o_object),TOTALITEMS,stdin);
	X  for (i=0; i<TOTALITEMS; i++) {
	X    C(id); C(weight); C(plus); C(charge); C(dmg); C(hit); C(aux);
	X    C(number); C(fragility);
	X    C(basevalue);
	X    C(known); C(used); C(blessing); C(type);
	X    C(uniqueness); /* 0 common, 1 unique, ungenerated, 2 u, g */
	X    C(usef); /* effect when used */
	X    C(level); /* 0..10 power and frequency of item */
	X    CC(objstr); CC(truename); CC(cursestr);
	X    C(objchar);
	X    fwrite(&o, sizeof(o), 1, stdout);
	X  }
	X}
SHAR_EOF
if test 729 -ne "`wc -c < 'convitem.c'`"
then
	echo shar: "error transmitting 'convitem.c'" '(should have been 729 characters)'
fi
fi
echo shar: "extracting 'convmon.c'" '(834 characters)'
if test -f 'convmon.c'
then
	echo shar: "will not over-write existing file 'convmon.c'"
else
sed 's/^	X//' << \SHAR_EOF > 'convmon.c'
	X#include "stdio.h"
	X#include "structs.h"
	X
	X#define C(x) m.x = Monsters[i].x
	X#define CC(x) for(j=0;j<64;j++) m.x[j] = Monsters[i].x[j]
	X
	Xmain()
	X{
	X  struct o_monster Monsters[NUMMONSTERS];
	X  struct monster m;
	X  int i, j;
	X
	X  fread((char *)Monsters,sizeof(struct o_monster),NUMMONSTERS,stdin);
	X  for (i=0; i<NUMMONSTERS; i++) {
	X    C(id); C(hp); C(hit); C(ac); C(dmg); C(sense); C(wakeup); C(level);
	X    C(speed); C(click);
	X    C(status); C(immunity);
	X    C(sleep);
	X    C(treasure);
	X    C(aux1); C(aux2);
	X    C(x); C(y);
	X    C(xpv);
	X    C(corpseweight); C(corpsevalue); C(transformid); C(startthing);
	X    C(attacked);
	X    C(uniqueness);
	X    C(possessions);
	X    C(talkf);
	X    C(movef);
	X    C(meleef);
	X    C(strikef);
	X    C(specialf);
	X    CC(monstring); CC(corpsestr); CC(meleestr);
	X    C(monchar);
	X    fwrite(&m, sizeof(m), 1, stdout);
	X  }
	X}
SHAR_EOF
if test 834 -ne "`wc -c < 'convmon.c'`"
then
	echo shar: "error transmitting 'convmon.c'" '(should have been 834 characters)'
fi
fi
echo shar: "extracting 'makefile.notsun.diffs'" '(1034 characters)'
if test -f 'makefile.notsun.diffs'
then
	echo shar: "will not over-write existing file 'makefile.notsun.diffs'"
else
sed 's/^	X//' << \SHAR_EOF > 'makefile.notsun.diffs'
	X*** makefile.notsun	Thu Mar 24 12:03:41 1988
	X--- Makefile	Thu Mar 24 12:03:38 1988
	X***************
	X*** 9,19 ****
	X  BINDIR = /u/kyrimis/bin/games
	X  LIBDIR = /u/kyrimis/games/omega
	X  
	X! OBJ = o.o oabyss.o aux1.o oaux2.o ochar.o ocity.o\
	X        ocom1.o ocom2.o ocom3.o\
	X        ocountry.o oeffect1.o oeffect2.o\
	X        oetc.o ofile.o ogen.o oguild.o ohouse.o\
	X!       oinv.o oitem.o oitemf1.o oitemf2.o oitemf3.o olev.o\
	X        ommelee.o ommove.o omon.o omove.o omovef.o omspec.o\
	X        omstrike.o omtalk.o opriest.o\
	X        osave.o oscr.o osite1.o osite2.o\
	X--- 9,19 ----
	X  BINDIR = /u/kyrimis/bin/games
	X  LIBDIR = /u/kyrimis/games/omega
	X  
	X! OBJ = o.o oabyss.o oaux1.o oaux2.o ochar.o ocity.o\
	X        ocom1.o ocom2.o ocom3.o\
	X        ocountry.o oeffect1.o oeffect2.o\
	X        oetc.o ofile.o ogen.o oguild.o ohouse.o\
	X!       oinit.o oinv.o oitem.o oitemf1.o oitemf2.o oitemf3.o olev.o\
	X        ommelee.o ommove.o omon.o omove.o omovef.o omspec.o\
	X        omstrike.o omtalk.o opriest.o\
	X        osave.o oscr.o osite1.o osite2.o\
SHAR_EOF
if test 1034 -ne "`wc -c < 'makefile.notsun.diffs'`"
then
	echo shar: "error transmitting 'makefile.notsun.diffs'" '(should have been 1034 characters)'
fi
fi
echo shar: "extracting 'odefs.h.diffs'" '(1759 characters)'
if test -f 'odefs.h.diffs'
then
	echo shar: "will not over-write existing file 'odefs.h.diffs'"
else
sed 's/^	X//' << \SHAR_EOF > 'odefs.h.diffs'
	X*** odefs.h.orig	Thu Mar 24 12:31:12 1988
	X--- odefs.h	Thu Mar 24 12:31:11 1988
	X***************
	X*** 26,34 ****
	X--- 26,40 ----
	X  
	X  #define CATCH_SIGNALS 1
	X  
	X+ /* This version reads two binary data files created on a sun - if you */
	X+ /* are running omega on a machine with a different byte order (eg. a vax), */
	X+ /* define the FLIP variable */
	X  
	X+ #define FLIP
	X  
	X  
	X+ 
	X+ 
	X  /* Don't change anything from here on (unless you know what you're doing) */
	X  #define VERSION 705
	X  #define VERSIONSTRING "omega version 0.70.5 (alpha)"
	X***************
	X*** 1031,1036 ****
	X--- 1037,1043 ----
	X  } ;
	X  
	X  
	X+ 
	X  struct monster {
	X    int id,hp,hit,ac,dmg,sense,wakeup,level;
	X    int speed,click;
	X***************
	X*** 1043,1050 ****
	X    int corpseweight,corpsevalue,transformid,startthing;
	X    int attacked;
	X    int uniqueness; /* common, unique and unmade, unique and made */
	X-   char monchar;
	X-   char monstring[64],corpsestr[64],meleestr[64];
	X    struct objectlist *possessions;
	X    int talkf;
	X    int movef;
	X--- 1050,1055 ----
	X***************
	X*** 1051,1056 ****
	X--- 1056,1064 ----
	X    int meleef;
	X    int strikef;
	X    int specialf;
	X+   char monstring[64],corpsestr[64],meleestr[64];
	X+   char monchar;
	X+   char pad[3];
	X  };
	X  
	X  
	X***************
	X*** 1091,1098 ****
	X    int uniqueness; /* 0 common, 1 unique, ungenerated, 2 u, g */
	X    int usef; /* effect when used */
	X    int level; /* 0..10 power and frequency of item */
	X-   char objchar;
	X    char objstr[64],truename[64],cursestr[64];
	X  };
	X  
	X  
	X--- 1099,1107 ----
	X    int uniqueness; /* 0 common, 1 unique, ungenerated, 2 u, g */
	X    int usef; /* effect when used */
	X    int level; /* 0..10 power and frequency of item */
	X    char objstr[64],truename[64],cursestr[64];
	X+   char objchar;
	X+   char pad[3];
	X  };
	X  
	X  
SHAR_EOF
if test 1759 -ne "`wc -c < 'odefs.h.diffs'`"
then
	echo shar: "error transmitting 'odefs.h.diffs'" '(should have been 1759 characters)'
fi
fi
echo shar: "extracting 'oinit.c.diffs'" '(2030 characters)'
if test -f 'oinit.c.diffs'
then
	echo shar: "will not over-write existing file 'oinit.c.diffs'"
else
sed 's/^	X//' << \SHAR_EOF > 'oinit.c.diffs'
	X*** oinit.c.orig	Thu Mar 24 12:04:13 1988
	X--- oinit.c	Thu Mar 24 12:04:13 1988
	X***************
	X*** 62,85 ****
	X--- 62,153 ----
	X  
	X  
	X  
	X+ #ifdef FLIP
	X+ #define C(x) Monsters[i].x = flip(Monsters[i].x)
	X+ #endif FLIP
	X  
	X  void read_monsters()
	X  {
	X    FILE *fd;
	X+   int i;
	X    strcpy(Str1,OMEGALIB);
	X    strcat(Str1,"omon.dat");
	X    fd = checkfopen(Str1,"r");
	X    fread((char *)Monsters,sizeof(montype),NUMMONSTERS,fd);
	X    fclose(fd);
	X+ #ifdef FLIP
	X+   for (i=0; i<NUMMONSTERS; i++) {
	X+     C(id); C(hp); C(hit); C(ac); C(dmg); C(sense); C(wakeup); C(level);
	X+     C(speed); C(click);
	X+     C(status); C(immunity);
	X+     C(sleep);
	X+     C(treasure);
	X+     C(aux1); C(aux2);
	X+     C(x); C(y);
	X+     C(xpv);
	X+     C(corpseweight); C(corpsevalue); C(transformid); C(startthing);
	X+     C(attacked);
	X+     C(uniqueness);
	X+     Monsters[i].possessions =
	X+ 	(struct objectlist *) flip((int)Monsters[i].possessions);
	X+     C(talkf);
	X+     C(movef);
	X+     C(meleef);
	X+     C(strikef);
	X+     C(specialf);
	X+   }
	X+ #endif FLIP
	X  }
	X  
	X+ #ifdef FLIP
	X+ #undef C
	X+ #endif FLIP
	X  
	X+ #ifdef FLIP
	X+ #define C(x) Objects[i].x = flip(Objects[i].x)
	X+ #endif FLIP
	X+ 
	X  void read_items()
	X  {
	X    FILE *fd;
	X+   int i;
	X    strcpy(Str1,OMEGALIB);
	X    strcat(Str1,"oitem.dat");
	X    fd = checkfopen(Str1,"r");
	X    fread((char *) Objects,sizeof(objtype),TOTALITEMS,fd);
	X    fclose(fd);
	X+ #ifdef FLIP
	X+   for (i=0; i<TOTALITEMS; i++) {
	X+     C(id); C(weight); C(plus); C(charge); C(dmg); C(hit); C(aux);
	X+     C(number); C(fragility);
	X+     C(basevalue);
	X+     C(known); C(used); C(blessing); C(type);
	X+     C(uniqueness); /* 0 common, 1 unique, ungenerated, 2 u, g */
	X+     C(usef); /* effect when used */
	X+     C(level); /* 0..10 power and frequency of item */
	X+   }
	X+ #endif FLIP
	X  }
	X+ 
	X+ #ifdef FLIP
	X+ #undef C
	X+ 
	X+ int flip(x)
	X+   int x;
	X+ {
	X+   union {
	X+     struct {
	X+       char a, b, c, d
	X+     } b;
	X+     int i;
	X+   } a, b;
	X+ 
	X+   a.i = x;
	X+   b.b.a = a.b.d;
	X+   b.b.b = a.b.c;
	X+   b.b.c = a.b.b;
	X+   b.b.d = a.b.a;
	X+ 
	X+   return(b.i);
	X+ }
	X+ #endif FLIP
SHAR_EOF
if test 2030 -ne "`wc -c < 'oinit.c.diffs'`"
then
	echo shar: "error transmitting 'oinit.c.diffs'" '(should have been 2030 characters)'
fi
fi
echo shar: "extracting 'structs.h'" '(3610 characters)'
if test -f 'structs.h'
then
	echo shar: "will not over-write existing file 'structs.h'"
else
sed 's/^	X//' << \SHAR_EOF > 'structs.h'
	X/* include enough stuff to define NUMMONSTERS and TOTALITEMS */
	X
	X/* This has to be changed whenever an item is added */
	X#define NUMSCROLLS 24
	X#define NUMPOTIONS 18
	X#define NUMFOODS 15
	X#define NUMTHINGS 26
	X#define NUMWEAPONS 41
	X#define NUMARMOR 17
	X#define NUMSHIELDS 8
	X#define NUMCLOAKS 7
	X#define NUMBOOTS 6
	X#define NUMRINGS 10
	X#define NUMSTICKS 17
	X#define NUMARTIFACTS 24
	X
	X/* running sum of itemtypes, for indexing into Objects array */
	X#define THINGID 0 
	X#define FOODID NUMTHINGS
	X#define SCROLLID (FOODID + NUMFOODS)
	X#define POTIONID (SCROLLID + NUMSCROLLS)
	X#define WEAPONID (POTIONID + NUMPOTIONS)
	X#define ARMORID (WEAPONID + NUMWEAPONS)
	X#define SHIELDID (ARMORID + NUMARMOR)
	X#define CLOAKID (SHIELDID + NUMSHIELDS)
	X#define BOOTID (CLOAKID + NUMCLOAKS)
	X#define RINGID (BOOTID + NUMBOOTS)
	X#define STICKID (RINGID + NUMRINGS)
	X#define ARTIFACTID (STICKID + NUMSTICKS)
	X#define CASHID (ARTIFACTID+NUMARTIFACTS)
	X/* Corpse's aux field is monster id */
	X#define CORPSEID (CASHID+1)
	X
	X#define TOTALITEMS (CORPSEID+1) 
	X
	X#define ML0 0
	X#define NML_0 9
	X#define ML1 (ML0 + NML_0)
	X#define NML_1 22
	X#define ML2 (ML1 + NML_1)
	X#define NML_2 14
	X#define ML3 (ML2 + NML_2)
	X#define NML_3 15
	X#define ML4 (ML3 + NML_3)
	X#define NML_4 18
	X#define ML5 (ML4 + NML_4)
	X#define NML_5 14
	X#define ML6 (ML5 + NML_5)
	X#define NML_6 13
	X#define ML7 (ML6 + NML_6)
	X#define NML_7 15
	X#define ML8 (ML7 + NML_7)
	X#define NML_8 12
	X#define ML9 (ML8 + NML_8)
	X#define NML_9 8
	X#define ML10 (ML9 + NML_9)
	X#define NML_10 11
	X
	X#define NUMMONSTERS (ML10 + NML_10)
	X
	X/* old definitions, different compilers pad them differently */
	X
	Xstruct o_monster {
	X  int id,hp,hit,ac,dmg,sense,wakeup,level;
	X  int speed,click;
	X  long status,immunity;
	X  int sleep; /* percent chance starts out asleep */
	X  int treasure; /* percent chance starts with treasure */
	X  int aux1,aux2; /* random information */
	X  int x,y;
	X  int xpv;
	X  int corpseweight,corpsevalue,transformid,startthing;
	X  int attacked;
	X  int uniqueness; /* common, unique and unmade, unique and made */
	X  char monchar;
	X  char monstring[64],corpsestr[64],meleestr[64];
	X  struct objectlist *possessions;
	X  int talkf;
	X  int movef;
	X  int meleef;
	X  int strikef;
	X  int specialf;
	X};
	X
	Xstruct o_object {
	X  int id,weight,plus,charge,dmg,hit,aux,number,fragility;
	X  int basevalue;
	X  int known, used, blessing,type;
	X  int uniqueness; /* 0 common, 1 unique, ungenerated, 2 u, g */
	X  int usef; /* effect when used */
	X  int level; /* 0..10 power and frequency of item */
	X  char objchar;
	X  char objstr[64],truename[64],cursestr[64];
	X};
	X
	Xstruct objectlist {
	X  struct object *thing;
	X  struct objectlist *next;
	X};
	X
	X/* New definitions, no padding should be made by the compiler */
	X
	Xstruct monster {
	X  int id,hp,hit,ac,dmg,sense,wakeup,level;
	X  int speed,click;
	X  long status,immunity;
	X  int sleep; /* percent chance starts out asleep */
	X  int treasure; /* percent chance starts with treasure */
	X  int aux1,aux2; /* random information */
	X  int x,y;
	X  int xpv;
	X  int corpseweight,corpsevalue,transformid,startthing;
	X  int attacked;
	X  int uniqueness; /* common, unique and unmade, unique and made */
	X  struct objectlist *possessions;
	X  int talkf;
	X  int movef;
	X  int meleef;
	X  int strikef;
	X  int specialf;
	X  char monstring[64],corpsestr[64],meleestr[64];
	X  char monchar;
	X  char pad[3];
	X};
	X
	Xstruct object {
	X  int id,weight,plus,charge,dmg,hit,aux,number,fragility;
	X  int basevalue;
	X  int known, used, blessing,type;
	X  int uniqueness; /* 0 common, 1 unique, ungenerated, 2 u, g */
	X  int usef; /* effect when used */
	X  int level; /* 0..10 power and frequency of item */
	X  char objstr[64],truename[64],cursestr[64];
	X  char objchar;
	X  char pad[3];
	X};
SHAR_EOF
if test 3610 -ne "`wc -c < 'structs.h'`"
then
	echo shar: "error transmitting 'structs.h'" '(should have been 3610 characters)'
fi
fi
exit 0
#	End of shell archive

	Kriton	(UUCP: allegra!princeton!kyrimis)
	      	(ARPA: kyrimis@princeton.edu)
-----
"I am not interested in the beliefs of primitives - only in
 what they *taste* like!"
-----

kyrimis@notecnirp.Princeton.EDU (Kriton Kyrimis) (03/27/88)

I just realised that I made the same mistake that the  omega  au-
thor  did, when writing the programs that convert the binary data
to a form usable on both the sun and the vax. These programs have
to be run on a sun. If you don't have access to a sun, you should
rewrite those programs so that instead of reading each  structure
with  a  single  fread, you read each structure element, one at a
time.  Notice that each structure has one  byte  of  padding.  In
struct  o_monster  it  is immediately after the meleestr[] array,
and in struct o_object it is immediately after the cursestr[] ar-
ray.

Sorry about the inconvenience,

	Kriton	(UUCP: allegra!princeton!kyrimis)
	      	(ARPA: kyrimis@princeton.edu)
-----
"I haven't changed the course of history;  indeed,  I'm  expressly
 forbidden to do so!"
-----