DieHard Wolfers Forum Index DieHard Wolfers
A Wolfenstein 3d Fan Community


  Hosted by: MCS & Areyep.com - Designed by: BrotherTank

Original Yahoo Forum - Die Hard Archives

AReyeP HomepageAreyep Homepage DieHard Wolfenstein BunkerDieHard Wolfenstein Bunker Log inLog in RegisterRegister Banlist FAQFAQ Search ForumsSearch

  Username:    Password:      Remember me       

Baffled
Page 1 of 1
DieHard Wolfers Forum Index -> Code Crackers View Previous TopicRefresh this PageAdd Topic to your Browser FavoritesSearch ForumsPrint this TopicE-mail TopicGoto Page BottomView Next Topic
Post new topicReply to topic
Author Message
BrotherTank
Forum Administrator
<B>Forum Administrator</B>


Joined: 01 Mar 2003
Last Visit: 13 Sep 2017

Topics: 153
Posts: 2248
Location: Ontario
canada.gif

PostPosted: Mon Jan 31, 2005 6:25 pm
   Subject: Baffled
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Next PostGoto Bottom of Posts

Ok...

Here's one for the record books.... I hope someone can spot something I have missed or explain why this is happening...

I have two pieces of code... 1 was installed into the wolfenstein source... the other was put into a seperate source to create an editor for the enemy data files in my engine. The code is identical... Nothing changed ... Line for line exact...

When the code runs from the external editor... the file size is right... 329 bytes... When it runs from inside the Wolf source... it generates a file that is 354 bytes..

Here is the code for the external editor:

::: CODE :::
#include <ALLOC.H>
#include <conio.h>
#include <io.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <STRING.H>
#include <sys\stat.h>
#include <ctype.h> // Needed for toupper to work
#pragma hdrstop

//--------------------
//
//--------------------
//--------------------
// True - False
//--------------------
typedef   enum   {false=0,true=1}   boolean;
typedef   unsigned   char      byte;

//--------------------
// Routines in Program
//--------------------
void CreateEnStat(int cheater);
void ReadEnStat(void);
void WriteEnStat (void);
long DoChecksum(byte far *source,unsigned size,long checksum);
void EdGuards (void);
void EdBosses (void);
void EdOthers (void);
void Quit (int err, char *error);
void ProgInfo (void);
boolean CA_FarRead (int handle, byte far *dest, long length);
boolean CA_FarWrite (int handle, byte far *source, long length);
//--------------------
// Variables - File Names
//--------------------
char extension[5]="WL6", enstatname[13]="ENDATA.";

//--------------------
// Enemey Stats
//--------------------
#define NUMENEMIES  25

typedef enum {
   en_guard,      // 0
   en_guard2,      // 1
   en_guard3,      // 2
   en_guard4,      // 3
   en_officer,      // 4
   en_officer2,    // 5
   en_ss,         // 6
   en_ss2,         // 7
   en_dog,         // 8
   en_boss,         // 9
   en_schabbs,      // 10
   en_fake,         // 11
   en_hitler,      // 12
   en_mutant,      // 13
   en_bat,         // 14
   en_turret,      // 15
   en_blinky,      // 16
   en_clyde,      // 17
   en_pinky,      // 18
   en_inky,         // 19
   en_gretel,      // 20
   en_gift,         // 21
   en_fat,         // 22
   en_column,      // 23
   en_barrel      // 24

} enemy_t;

typedef struct en_struct
{
   int    hp[4];     // enemy hitpoints - 4 skill levels
   int    speed;     // speed multiplier * base (base=512)
   int    points;    // points for killing
   byte    drop;     // item enemy drops when killed
} en_struct;

struct en_struct enemystat[NUMENEMIES];


//==========================
// CA_FarRead
// Read from a file to a far pointer
//==========================
boolean CA_FarRead (int handle, byte far *dest, long length)
{
   if (length>0xffffl) Quit (true,"CA_FarRead doesn't support 64K reads yet!");

asm      push   ds
asm      mov   bx,[handle]
asm      mov   cx,[WORD PTR length]
asm      mov   dx,[WORD PTR dest]
asm      mov   ds,[WORD PTR dest+2]
asm      mov   ah,0x3f            // READ w/handle
asm      int   21h
asm      pop   ds
asm      jnc   good
   errno = _AX;
   return   false;
good:
asm      cmp   ax,[WORD PTR length]
asm      je   done
   errno = EINVFMT;         // user manager knows this is bad read
   return   false;
done:
   return   true;
}

boolean CA_FarWrite (int handle, byte far *source, long length)
{
   if (length>0xffffl) Quit (true,"CA_FarWrite doesn't support 64K reads yet!");

asm      push   ds
asm      mov   bx,[handle]
asm      mov   cx,[WORD PTR length]
asm      mov   dx,[WORD PTR source]
asm      mov   ds,[WORD PTR source+2]
asm      mov   ah,0x40         // WRITE w/handle
asm      int   21h
asm      pop   ds
asm      jnc   good
   errno = _AX;
   return   false;
good:
asm      cmp   ax,[WORD PTR length]
asm      je   done
   errno = ENOMEM;            // user manager knows this is bad write
   return   false;

done:
   return   true;
}

void Quit (int err, char *error)
{
   clrscr();
   ProgInfo ();
   
   if (err)
   {
     printf("Error: ", error);
     exit(1);
   }
   else
   {
      WriteEnStat ();
      printf("\n\nData File Saved\n\n");
        exit(0);
         
   }
   exit(0);
}
//---------------------
// Checksum from Wolf3d
//---------------------
long DoChecksum(byte far *source,unsigned size,long checksum)
{
 unsigned i;

 for (i=0;i<size-1;i++) checksum += source[i]^source[i+1];
 return checksum;
}

//-------------------
// Enemy Stats
//-------------------
// Create If Cheater or Doesn't Exist
void CreateEnStat(int cheater)
{
   
   enemystat[en_guard].hp[1]= 25 * cheater;
   enemystat[en_guard].hp[2]= 25 * cheater;
   enemystat[en_guard].hp[3]= 30 * cheater;
   enemystat[en_guard].hp[4]= 35 * cheater;
   enemystat[en_guard].speed= 3;
   enemystat[en_guard].points= 100;
   enemystat[en_guard].drop= 1;

   enemystat[en_guard2].hp[1]= 30 * cheater;
   enemystat[en_guard2].hp[2]= 30 * cheater;
   enemystat[en_guard2].hp[3]= 35 * cheater;
   enemystat[en_guard2].hp[4]= 40 * cheater;
   enemystat[en_guard2].speed= 3;
   enemystat[en_guard2].points= 100;
   enemystat[en_guard2].drop=1;

   enemystat[en_guard3].hp[1]= 35 * cheater;
   enemystat[en_guard3].hp[2]= 35 * cheater;
   enemystat[en_guard3].hp[3]= 40 * cheater;
   enemystat[en_guard3].hp[4]= 45 * cheater;
   enemystat[en_guard3].speed= 4;
   enemystat[en_guard3].points= 100 * cheater;
   enemystat[en_guard3].drop=1;

   enemystat[en_guard4].hp[1]= 40 * cheater;
   enemystat[en_guard4].hp[2]= 40 * cheater;
   enemystat[en_guard4].hp[3]= 45 * cheater;
   enemystat[en_guard4].hp[4]= 50 * cheater;
   enemystat[en_guard4].speed= 5;
   enemystat[en_guard4].points= 100;
   enemystat[en_guard4].drop=1;
   
   enemystat[en_officer].hp[1]= 50 * cheater;
   enemystat[en_officer].hp[2]= 50 * cheater;
   enemystat[en_officer].hp[3]= 60 * cheater;
   enemystat[en_officer].hp[4]= 65 * cheater;
   enemystat[en_officer].speed= 4;
   enemystat[en_officer].points= 400;
   enemystat[en_officer].drop=1;

   enemystat[en_officer2].hp[1]= 75 * cheater;
   enemystat[en_officer2].hp[2]= 75 * cheater;
   enemystat[en_officer2].hp[3]= 110 * cheater;
   enemystat[en_officer2].hp[4]= 125 * cheater;
   enemystat[en_officer2].speed= 5;
   enemystat[en_officer2].points= 400;
   enemystat[en_officer2].drop=1;

   enemystat[en_ss].hp[1]= 75 * cheater;
   enemystat[en_ss].hp[2]= 75 * cheater;
   enemystat[en_ss].hp[3]= 100 * cheater;
   enemystat[en_ss].hp[4]= 100 * cheater;
   enemystat[en_ss].speed= 3;
   enemystat[en_ss].points= 500;
   enemystat[en_ss].drop=3;

   enemystat[en_ss2].hp[1]= 100 * cheater;
   enemystat[en_ss2].hp[2]= 100 * cheater;
   enemystat[en_ss2].hp[3]= 150 * cheater;
   enemystat[en_ss2].hp[4]= 150 * cheater;
   enemystat[en_ss2].speed= 4;
   enemystat[en_ss2].points= 500;
   enemystat[en_ss2].drop=3;

   enemystat[en_dog].hp[1]= 10 * cheater;
   enemystat[en_dog].hp[2]= 10 * cheater;
   enemystat[en_dog].hp[3]= 15 * cheater;
   enemystat[en_dog].hp[4]= 15 * cheater;
   enemystat[en_dog].speed= 3;
   enemystat[en_dog].points= 200;
   enemystat[en_dog].drop=0;

   enemystat[en_boss].hp[1]= 850 * cheater;
   enemystat[en_boss].hp[2]= 950 * cheater;
   enemystat[en_boss].hp[3]= 1050 * cheater;
   enemystat[en_boss].hp[4]= 1200 * cheater;
   enemystat[en_boss].speed= 3;
   enemystat[en_boss].points= 5000;
   enemystat[en_boss].drop=0;

   enemystat[en_schabbs].hp[1]= 850 * cheater;
   enemystat[en_schabbs].hp[2]= 950 * cheater;
   enemystat[en_schabbs].hp[3]= 1550 * cheater;
   enemystat[en_schabbs].hp[4]= 2400 * cheater;
   enemystat[en_schabbs].speed= 3;
   enemystat[en_schabbs].points= 5000;
   enemystat[en_schabbs].drop=0;

   enemystat[en_fake].hp[1]= 200 * cheater;
   enemystat[en_fake].hp[2]= 300 * cheater;
   enemystat[en_fake].hp[3]= 400 * cheater;
   enemystat[en_fake].hp[4]= 500 * cheater;
   enemystat[en_fake].speed= 3;
   enemystat[en_fake].points= 2000;
   enemystat[en_fake].drop=0;

   enemystat[en_hitler].hp[1]= 850 * cheater;
   enemystat[en_hitler].hp[2]= 950 * cheater;
   enemystat[en_hitler].hp[3]= 1050 * cheater;
   enemystat[en_hitler].hp[4]= 1200 * cheater;
   enemystat[en_hitler].speed= 3;
   enemystat[en_hitler].points= 5000;
   enemystat[en_hitler].drop=0;

   enemystat[en_mutant].hp[1]= 45 * cheater;
   enemystat[en_mutant].hp[2]= 45 * cheater;
   enemystat[en_mutant].hp[3]= 55 * cheater;
   enemystat[en_mutant].hp[4]= 65 * cheater;
   enemystat[en_mutant].speed= 3;
   enemystat[en_mutant].points= 700;
   enemystat[en_mutant].drop=1;

   enemystat[en_bat].hp[1]= 45 * cheater;
   enemystat[en_bat].hp[2]= 55 * cheater;
   enemystat[en_bat].hp[3]= 65 * cheater;
   enemystat[en_bat].hp[4]= 75 * cheater;
   enemystat[en_bat].speed= 4;
   enemystat[en_bat].points= 700;
   enemystat[en_bat].drop=1;

   enemystat[en_turret].hp[1]= 20 * cheater;
   enemystat[en_turret].hp[2]= 25 * cheater;
   enemystat[en_turret].hp[3]= 35 * cheater;
   enemystat[en_turret].hp[4]= 55 * cheater;
   enemystat[en_turret].speed= 0;
   enemystat[en_turret].points= 200;
   enemystat[en_turret].drop=0;

   enemystat[en_blinky].hp[1]= 0;
   enemystat[en_blinky].hp[2]= 0;
   enemystat[en_blinky].hp[3]= 0;
   enemystat[en_blinky].hp[4]= 0;
   enemystat[en_blinky].speed= 2;
   enemystat[en_blinky].points= 0;
   enemystat[en_blinky].drop=0;

   enemystat[en_clyde].hp[1]= 0;
   enemystat[en_clyde].hp[2]= 0;
   enemystat[en_clyde].hp[3]= 0;
   enemystat[en_clyde].hp[4]= 0;
   enemystat[en_clyde].speed= 2;
   enemystat[en_clyde].points= 0;
   enemystat[en_clyde].drop=0;

   enemystat[en_pinky].hp[1]= 0;
   enemystat[en_pinky].hp[2]= 0;
   enemystat[en_pinky].hp[3]= 0;
   enemystat[en_pinky].hp[4]= 0;
   enemystat[en_pinky].speed= 2;
   enemystat[en_pinky].points= 0;
   enemystat[en_pinky].drop=0;

   enemystat[en_inky].hp[1]= 0;
   enemystat[en_inky].hp[2]= 0;
   enemystat[en_inky].hp[3]= 0;
   enemystat[en_inky].hp[4]= 0;
   enemystat[en_inky].speed= 2;
   enemystat[en_inky].points= 0;
   enemystat[en_inky].drop=0;

   enemystat[en_gretel].hp[1]= 850 * cheater;
   enemystat[en_gretel].hp[2]= 950 * cheater;
   enemystat[en_gretel].hp[3]= 1050 * cheater;
   enemystat[en_gretel].hp[4]= 1200 * cheater;
   enemystat[en_gretel].speed= 3;
   enemystat[en_gretel].points= 5000;
   enemystat[en_gretel].drop=0;

   enemystat[en_gift].hp[1]= 850 * cheater;
   enemystat[en_gift].hp[2]= 950 * cheater;
   enemystat[en_gift].hp[3]= 1050 * cheater;
   enemystat[en_gift].hp[4]= 1200 * cheater;
   enemystat[en_gift].speed= 3;
   enemystat[en_gift].points= 5000;
   enemystat[en_gift].drop=0;

   enemystat[en_fat].hp[1]= 850 * cheater;
   enemystat[en_fat].hp[2]= 950 * cheater;
   enemystat[en_fat].hp[3]= 1050 * cheater;
   enemystat[en_fat].hp[4]= 1200 * cheater;
   enemystat[en_fat].speed= 3;
   enemystat[en_fat].points= 5000;
   enemystat[en_fat].drop=0;

   enemystat[en_column].hp[1]= 50 * cheater;
   enemystat[en_column].hp[2]= 50 * cheater;
   enemystat[en_column].hp[3]= 50 * cheater;
   enemystat[en_column].hp[4]= 50 * cheater;
   enemystat[en_column].speed=0;
   enemystat[en_column].points=0;
   enemystat[en_column].drop=0;

   enemystat[en_barrel].hp[1]= 35 * cheater;
   enemystat[en_barrel].hp[2]= 35 * cheater;
   enemystat[en_barrel].hp[3]= 40 * cheater;
   enemystat[en_barrel].hp[4]= 45 * cheater;
   enemystat[en_barrel].speed=0;
   enemystat[en_barrel].points=0;
   enemystat[en_barrel].drop=0;

//   enemystat[].hp[1]=;
//   enemystat[].hp[2]=;
//   enemystat[].hp[3]=;
//   enemystat[].hp[4]=;
//   enemystat[].speed=5;
//   enemystat[].points=10;
//   enemystat[].drop=0;
   
   WriteEnStat ();
}
// Read Stat File
void ReadEnStat(void)
{
   long       checksum,oldchecksum;
   int       i,file;
   struct    en_struct enemyread;
   
   checksum = 0;
   file = open(enstatname,O_BINARY | O_RDONLY);
   
   if ( file != -1)   // File Exists
   {
      for (i=0; i < NUMENEMIES; i++)
      {
         CA_FarRead (file,(void far *)&enemyread,sizeof(enemyread));
         
         enemystat[i].hp[1]=enemyread.hp[1];
         enemystat[i].hp[2]=enemyread.hp[2];
         enemystat[i].hp[3]=enemyread.hp[3];
         enemystat[i].hp[4]=enemyread.hp[4];
         enemystat[i].speed=enemyread.speed;
         enemystat[i].points=enemyread.points;
         enemystat[i].drop=enemyread.drop;
         checksum = DoChecksum((void far *)&enemyread,sizeof(enemyread),checksum);
      }   
      CA_FarRead (file,(void far *)&oldchecksum,sizeof(oldchecksum));
      close(file);
      if (oldchecksum != checksum) CreateEnStat(2);  // Cheater - Reset Hard!!!!
   }
   else // No Stats File - Create New One
   {
      close(file);
      CreateEnStat(1);   
   }
}
// Write Stat File
void WriteEnStat (void)
{
   long       checksum;
   int       i,file;
   checksum = 0;

   file = open(enstatname,O_CREAT | O_BINARY | O_WRONLY, S_IREAD | S_IWRITE | S_IFREG);
   if (file != -1)
   {
      for(i=0; i<NUMENEMIES; i++)
      {
         CA_FarWrite (file,(void far *)&enemystat[i],sizeof(enemystat[i]));
         checksum = DoChecksum((byte far *)&enemystat[i],sizeof(enemystat[i]),checksum);      
      }
      
      CA_FarWrite (file,(void far *)&checksum,sizeof(checksum));
      close(file);
   }   
}
//--------------------
//
//--------------------
void EdGuards (void)
{
      
   return;
}

void EdBosses (void)
{
   return;
}

void EdOthers (void)
{
   return;   
}
//--------------------
//
//--------------------
void ProgInfo (void)
{
   printf("Wolfenstein Advanced Editor V1.0103104\n\n");
   printf("By: BrotherTank\n\n");
   printf("Core Memory Remaining: %lu bytes\n", (unsigned long) coreleft());
   printf(" Far Memory Remaining: %lu bytes\n\n", (unsigned long) farcoreleft());
   printf("                      -----------\n");
   printf("    Total Free Memory: %lu bytes\n\n", (unsigned long) coreleft()+farcoreleft());   
}
//--------------------
//
//--------------------

//--------------------
// Start Routine
//--------------------
void main (void)
{
   // Set Filename
   strcat(enstatname,extension);
   // Read Stats Config File
   ReadEnStat ();

MenuTop:      
   clrscr();
   
   ProgInfo ();
         
   printf ("Edit Which?\n\n");
   printf ("1 - Edit Guards Data\n");
   printf ("2 - Edit Boss Data\n");
   printf ("3 - Barrels & Columns Data\n\n");
   printf ("Any Other Key Exits ->");

   switch (getch())
   {
      case '1':
         EdGuards();
         break;
      case '2':
         EdBosses();
         break;
      case '3':
         EdOthers();
         break;
      default:
         Quit (false,"");
         break;
   }
   goto MenuTop;   
}


The only routines in the wolf source are the Read - Write and Create... the other routines in this code (above) are from the original Wolf3d source code so I can check for cheaters editing the file ... etc...

I haven't got a clue... the code above produces the 329 byte file... which is right... 25 enemies... times 13 bytes per enemy for the file plus 4 bytes for the checksum.

I have also got the two different versions of the data files in hex... and as you can see it seems to be shifting each record writen by exactly 1 byte... hence 329 + 25 enemy records = 354 file size of the one produced within the game itself...

Here is the Proper Data File:

::: CODE :::

00 00 19 00 19 00 1E 00 03 00 64 00 01 00 00 1E
00 1E 00 23 00 03 00 64 00 01 00 00 23 00 23 00
28 00 04 00 64 00 01 00 00 28 00 28 00 2D 00 05
00 64 00 01 00 00 32 00 32 00 3C 00 04 00 90 01
01 00 00 4B 00 4B 00 6E 00 05 00 90 01 01 00 00
4B 00 4B 00 64 00 03 00 F4 01 03 00 00 64 00 64
00 96 00 04 00 F4 01 03 00 00 0A 00 0A 00 0F 00
03 00 C8 00 00 00 00 52 03 B6 03 1A 04 03 00 88
13 00 00 00 52 03 B6 03 0E 06 03 00 88 13 00 00
00 C8 00 2C 01 90 01 03 00 D0 07 00 00 00 52 03
B6 03 1A 04 03 00 88 13 00 00 00 2D 00 2D 00 37
00 03 00 BC 02 01 00 00 2D 00 37 00 41 00 04 00
BC 02 01 00 00 14 00 19 00 23 00 00 00 C8 00 00
00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00
00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00
00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 02
00 00 00 00 00 00 52 03 B6 03 1A 04 03 00 88 13
00 00 00 52 03 B6 03 1A 04 03 00 88 13 00 00 00
52 03 B6 03 1A 04 03 00 88 13 00 00 00 32 00 32
00 32 00 00 00 00 00 00 00 00 23 00 23 00 28 00
00 00 00 00 00 F0 39 00 00


And this is what is generated by the wolf3d source code with the exact same routines:

::: CODE :::

00 00 19 00 19 00 1E 00 03 00 64 00 01 00 00 00
1E 00 1E 00 23 00 03 00 64 00 01 00 00 00 23 00
23 00 28 00 04 00 64 00 01 00 00 00 28 00 28 00
2D 00 05 00 64 00 01 00 00 00 32 00 32 00 3C 00
04 00 90 01 01 00 00 00 4B 00 4B 00 6E 00 05 00
90 01 01 00 00 00 4B 00 4B 00 64 00 03 00 F4 01
03 00 00 00 64 00 64 00 96 00 04 00 F4 01 03 00
00 00 0A 00 0A 00 0F 00 03 00 C8 00 00 00 00 00
52 03 B6 03 1A 04 03 00 88 13 00 00 00 00 52 03
B6 03 0E 06 03 00 88 13 00 00 00 00 C8 00 2C 01
90 01 03 00 D0 07 00 00 00 00 52 03 B6 03 1A 04
03 00 88 13 00 00 00 00 2D 00 2D 00 37 00 03 00
BC 02 01 00 00 00 2D 00 37 00 41 00 04 00 BC 02
01 00 00 00 14 00 19 00 23 00 00 00 C8 00 00 00
00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00
00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00
00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00
00 00 02 00 00 00 00 00 00 00 52 03 B6 03 1A 04
03 00 88 13 00 00 00 00 52 03 B6 03 1A 04 03 00
88 13 00 00 00 00 52 03 B6 03 1A 04 03 00 88 13
00 00 00 00 32 00 32 00 32 00 00 00 00 00 00 00
00 00 00 23 00 23 00 28 00 00 00 00 00 00 F0 39
00 00


If you can spot the problem.... Please post a reply... (ie: The code Masters... like MCS, Ripper, Adam, Chris, and so on... )

Greg
BrotherTank
Chris
DieHard Wolfer
DieHard Wolfer


Joined: 11 Mar 2003
Last Visit: 16 Jul 2019

Topics: 56
Posts: 2234
Location: Canada
blank.gif

PostPosted: Mon Jan 31, 2005 7:06 pm
   Subject: Re: Baffled
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

I think it has to do with how struct itself is set up in the Source Code. Your external editor test (that works) sounds interesting.

Not sure if this will help, but when I turned the tictime from an int into a byte in the "statetype" struct of WL_DEF.H, nothing happend (naturally, you'd think it would make each statetype 1 byte smaller). Here's what it looks like:

::: CODE :::
typedef struct   statestruct
{
   boolean   rotate;
   int      shapenum;         // a shapenum of -1 means get from ob->temp1
   int      tictime;
   void   (*think) (),(*action) ();
   struct   statestruct   *next;
} statetype;

If I kept it as a byte and added another byte variable, nothing increased; either. Perhaps struct is set to run in blocks of two in wolf3d? That's the most logical reason I can think of. It'd be cool to find a way around this, though. I haven't really looked into it yet, but seeing as this happened to you too (and I think Dugtrio17 also), it'd be interesting to see what else is possible (maybe using enum works as a 1-byte variation of struct, or there's somewhere where we can alter it's default; or something).
Adam Biser
Utility Developer
Utility Developer


Joined: 06 Jun 2003
Last Visit: 11 Jul 2019

Topics: 46
Posts: 2331
Location: USA
usa.gif

PostPosted: Mon Jan 31, 2005 7:18 pm
   Subject: Re: Baffled
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

What Chris said is quite possible. There might be a setting someplace that optimizes writes to 2 bytes, since BC 3 is a 16 bit compiler. I know that I've read that 32-bit programs should use longs (32-bit numbers) because they can be read faster than others.
When I added
::: CODE :::
   byte      test[3];

to the gametype structure, my savegame file size increased by 4, not the expected 3.

EDIT: It might not be in the disk functions, but rather a memory setting. Things are probably being stored in memory so that their start and length are multiples of 2.

_________________
Orb of Dilaaria now has a Facebook page
Star Wars: Bloodlines now has a Facebook page
Dugtrio17
Code Master
Code Master


Joined: 11 Mar 2003
Last Visit: 03 Oct 2013

Topics: 49
Posts: 901
Location: Seattle
usa.gif

PostPosted: Mon Jan 31, 2005 7:30 pm
   Subject: Re: Baffled
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Heh, I know this is for the "Code Masters", but I looked at this and found something interesting between the correct file and the incorrect one. The bytes seem to be thrown off whenever there is a group of two bytes as 00 00. Whenever that occurs (for every instance I can see), an extra byte with a value of 00 is thrown in there. I'm not entirely sure what this means (or if it bears any relevance), but it was interesting to see the pattern seem to follow that format. I don't think it did so for larger groups of 00 bytes, but I may be wrong.
Now, I'm likely just shooting my mouth off here, but it's nonetheless something interesting I found in the file. Adam and Chris've prolly got this one nailed down better than I have. Something to trace would likely be the positions in the file, but I have to go to bed, so that will have to be done later.

A stab in the dark, but it's an attempt to help Smile
-Dugtrio17

_________________
BrotherTank
Forum Administrator
<B>Forum Administrator</B>


Joined: 01 Mar 2003
Last Visit: 13 Sep 2017

Topics: 153
Posts: 2248
Location: Ontario
canada.gif

PostPosted: Mon Jan 31, 2005 7:37 pm
   Subject: Re: Baffled
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

I know, but in code logic, there should be no difference... Seeing as the lines of code are exact. I'll give changing the byte in the structure to an int and report back on what it does. What doesn't make sense is that it is doing this.. It's almost like it is adding 1 byte of "00" between each write or structure record written, but only in the wolf source... Seperate as the code I posted above... It works 100% as it should.

Greg
BrotherTank

Edit: Changing the structure to:

::: CODE :::

typedef struct en_struct
{
   int    hp[4];     // enemy hitpoints - 4 skill levels
   int    speed;     // speed multiplier * base (base=512)
   int    points;    // points for killing
   int    drop;     // item enemy drops when killed
} en_struct;


Has made both sources generate the same file. For some reason the wolf source will not accept a byte the same as the code above... Both now generate a 354 byte file... and the data aligns perfectly.

Although, I'm still baffled as to why it does that in the first place.. Seeing as the code is "Identical" from both projects.

Greg
BrotherTank
BrotherTank
Forum Administrator
<B>Forum Administrator</B>


Joined: 01 Mar 2003
Last Visit: 13 Sep 2017

Topics: 153
Posts: 2248
Location: Ontario
canada.gif

PostPosted: Mon Jan 31, 2005 7:52 pm
   Subject: Re: Baffled
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Dugtrio17 wrote:
Heh, I know this is for the "Code Masters", but I looked at this and found something interesting between the correct file and the incorrect one. The bytes seem to be thrown off whenever there is a group of two bytes as 00 00. Whenever that occurs (for every instance I can see), an extra byte with a value of 00 is thrown in there. I'm not entirely sure what this means (or if it bears any relevance), but it was interesting to see the pattern seem to follow that format. I don't think it did so for larger groups of 00 bytes, but I may be wrong.
Now, I'm likely just shooting my mouth off here, but it's nonetheless something interesting I found in the file. Adam and Chris've prolly got this one nailed down better than I have. Something to trace would likely be the positions in the file, but I have to go to bed, so that will have to be done later.

A stab in the dark, but it's an attempt to help Smile
-Dugtrio17


No problem Dan... Yes... It's placing 1 extra byte of "00" at the end of each 13 byte segment (the length of the original structure) thus making it 14 bytes per record... even though the 14th byte is never defined. I know the checksum would change from one file to the other.. but if the structure and data fed into it were identical, then it should have produced identical results. I wonder if there is another hidden define for "Byte" somewhere in the code (other than the id_heads.h file).... that changes the definition from:

typedef unsigned char byte; // id_heads.h file

to something else...

Greg
BrotherTank
Adam Biser
Utility Developer
Utility Developer


Joined: 06 Jun 2003
Last Visit: 11 Jul 2019

Topics: 46
Posts: 2331
Location: USA
usa.gif

PostPosted: Mon Jan 31, 2005 7:57 pm
   Subject: Re: Baffled
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

In BC3, try going to Options->Compiler->Code Generation. Is "Word Alignment" checked in the game project and not in your editor project?

_________________
Orb of Dilaaria now has a Facebook page
Star Wars: Bloodlines now has a Facebook page
Chris
DieHard Wolfer
DieHard Wolfer


Joined: 11 Mar 2003
Last Visit: 16 Jul 2019

Topics: 56
Posts: 2234
Location: Canada
blank.gif

PostPosted: Mon Jan 31, 2005 8:13 pm
   Subject: Re: Baffled
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Adam Biser wrote:
Is "Word Alignment" checked in the game project and not in your editor project?

That's the one! It's default to ON, and when you turn it OFF, it compiles structs to the exact byte. Nice find. Smile

@Greg: I was going to say, one way to keep drop as a byte would be to change the "int points" to a byte, divide each points in CreateEnStat() by 100 (eg. enemystat[en_fat].points = 50 instead of 5000), then wherever enemystat[].points is calculated afterwards, multiply that result by 100. Then your struct will be 12 bytes; which would compile the same on both compiling platforms. Looks like Adam found the solution, but you can still try this to save another byte... if you wish.
BrotherTank
Forum Administrator
<B>Forum Administrator</B>


Joined: 01 Mar 2003
Last Visit: 13 Sep 2017

Topics: 153
Posts: 2248
Location: Ontario
canada.gif

PostPosted: Tue Feb 01, 2005 10:20 am
   Subject: Re: Baffled
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Thanks Adam... and Chris... It was the word alignment setting in the options menu. That made all the difference. I wonder if that will throw off the regular config file or any of the saved games with this setting changed... Will have to look at those other structures and make sure, but then again... I guess it really doesn't matter.. Just delete the config file and it's recreated anyways..

Thanks again guys... I'm sure that this has helped us all..

Greg
BrotherTank
Chris
DieHard Wolfer
DieHard Wolfer


Joined: 11 Mar 2003
Last Visit: 16 Jul 2019

Topics: 56
Posts: 2234
Location: Canada
blank.gif

PostPosted: Fri Feb 04, 2005 5:59 pm
   Subject: Re: Baffled
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

I wonder if there's a similar explanation for why there's over 26,000 zeros in a row near the lower-middle the wolf3d exe.

Did anyone every notice that? It's a little after where the Signon is stored, and right before the "Borland C++ - Copyright 1991 Borland Int" text. Seems to stay at around 26,000 zeros; even if you change alot of code. Not that it's a big deal, as that section just gets crushed into nothing after it's compressed, but I wonder if it has any real purpose (like, making the exe run faster? or it's just a random blurb so you'll see the Borland sign); or if there's a similar option to turn that one off.

Just something random I felt like talking about before going to work; not sure if it will spark any kind of conversation - lol.
Ripper
Code Master - Developer
Code Master - Developer


Joined: 15 Mar 2003
Last Visit: 30 Sep 2008

Topics: 21
Posts: 527
Location: Germany
blank.gif

PostPosted: Fri Feb 04, 2005 7:44 pm
   Subject: Re: Baffled
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Well, if you have a look at the map file, you'll see (if you keep in mind that the memory begins at offset 0x2c00 in this exe file) that the signon screen will reach from 2422:0000 to 33c1:000f which equals 00026e20 to 0003681f in file offsets. After that there seem to be some keyboard mappings which are not listed in the map file. But the next, areaconnect, is listed to be at 33da:0000 = 000369a0 in file which is already inside the zeroed area. This reaches up to 0003cf8f = 3a38:000f where the palette field ends. After that the data segment begins (yes, borland steals some of our precious near memory and fills it with that crap!).
So the empty areas in this file are just uninitialized variables.
Chris
DieHard Wolfer
DieHard Wolfer


Joined: 11 Mar 2003
Last Visit: 16 Jul 2019

Topics: 56
Posts: 2234
Location: Canada
blank.gif

PostPosted: Mon Feb 07, 2005 10:04 pm
   Subject: Re: Baffled
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Bottom of Posts

Ripper wrote:
Well, if you have a look at the map file, you'll see (if you keep in mind that the memory begins at offset 0x2c00 in this exe file) that the signon screen will reach from 2422:0000 to 33c1:000f which equals 00026e20 to 0003681f in file offsets. After that there seem to be some keyboard mappings which are not listed in the map file. But the next, areaconnect, is listed to be at 33da:0000 = 000369a0 in file which is already inside the zeroed area. This reaches up to 0003cf8f = 3a38:000f where the palette field ends. After that the data segment begins (yes, borland steals some of our precious near memory and fills it with that crap!).
So the empty areas in this file are just uninitialized variables.

Thanks for the info Ripper. I expected maybe someone to say "woah, I noticed that too" or "that's weird"; didn't think someone would actually have a logical explanation so fast. I'll take a look at that; seems pretty interesting. Mr Green
Display posts from previous:   
Post new topicReply to topic Time synchronized with the forum server time
DieHard Wolfers Forum Index -> Code Crackers View Previous TopicRefresh this PageAdd Topic to your Browser FavoritesSearch ForumsPrint this TopicE-mail TopicGoto Page TopView Next Topic
Page 1 of 1
Jump to:  

Related topics
 Topics   Replies   Views   Last Post 
No new posts [Info] Black & White Effect - Tutorial
Author: Guest
10 299 Thu Mar 17, 2005 6:24 pm
Dugtrio17 View latest post
No new posts [Info] Breakable or Exploding Objects (colums or barrels)
Author: wolf3dbreaker
37 10946 Tue Feb 08, 2005 5:44 am
Guest View latest post
No new posts [Info] Swap file decompiler
Author: DarkOne
3 4879 Wed Jul 09, 2003 10:34 pm
Guest View latest post
No new posts [Info] Assigning Static Objects problem.
Author: Guest
1 104 Sun Jul 06, 2003 1:25 pm
Guest View latest post
No new posts [Info] Alarm Sounding in game?? WSJ...??
Author: Guest
7 310 Tue Jun 17, 2003 10:04 pm
Reivax44 View latest post
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
   You cannot delete your posts in this forum
You cannot vote in polls in this forum


Copyright ©2003-2008 DieHard Wolfers
A Modified subBunker Theme by BrotherTank
Powered by phpBB © 2001, 2005 phpBB Group