Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Patch for Issue with Hacking  (Read 1603 times)

Rakeela

  • Bay Watcher
    • View Profile
Patch for Issue with Hacking
« on: February 05, 2011, 11:02:37 pm »

Credit Card Fraud was broken for me in the latest version, as were several hacking operations.  I looked into the source and made the following change, fixing the problem.  I hope this isn't terribly presumptuous of me.

The causes of the crash were unsigned integers in activities.ccp, specifically lines 1198 and 1298.  An if statement was incorrectly evaluating to true due to a negative number being treated as unsigned because truehack.size was unsigned.  This was enabling illegal vector access.  Implementing these changes should stop that from happening.  Testing indicates changing both files is necessary.

Code: [Select]
Index: creature.h
===================================================================
--- creature.h (revision 492)
+++ creature.h (working copy)
@@ -25,20 +25,18 @@
 #define GENDER_FEMALE  2
 #define GENDER_WHITEMALEPATRIARCH 3
 
-enum CheckDifficulty
-{
-   DIFFICULTY_AUTOMATIC    = 1,
-   DIFFICULTY_VERYEASY     = 3,
-   DIFFICULTY_EASY         = 5,
-   DIFFICULTY_AVERAGE      = 7,
-   DIFFICULTY_CHALLENGING  = 9,
-   DIFFICULTY_HARD         = 11,
-   DIFFICULTY_FORMIDABLE   = 13,
-   DIFFICULTY_HEROIC       = 15,
-   DIFFICULTY_SUPERHEROIC  = 17,
-   DIFFICULTY_IMPOSSIBLE   = 19
-};
 
+const int DIFFICULTY_AUTOMATIC    = 1;
+const int   DIFFICULTY_VERYEASY     = 3;
+const int DIFFICULTY_EASY         = 5;
+const int DIFFICULTY_AVERAGE      = 7;
+const int DIFFICULTY_CHALLENGING  = 9;
+const int DIFFICULTY_HARD         = 11;
+const int DIFFICULTY_FORMIDABLE   = 13;
+const int DIFFICULTY_HEROIC       = 15;
+const int DIFFICULTY_SUPERHEROIC  = 17;
+const int DIFFICULTY_IMPOSSIBLE   = 19;
+
 enum CreatureAttribute
 {
    ATTRIBUTE_STRENGTH,
Code: [Select]
Index: activities.cpp
===================================================================
--- activities.cpp (revision 492)
+++ activities.cpp (working copy)
@@ -1195,7 +1195,7 @@
 
       int difficulty = DIFFICULTY_HEROIC;
         
-      if(DIFFICULTY_HEROIC<=hack_skill+truehack.size()-1)
+      if(DIFFICULTY_HEROIC<=hack_skill+((int)truehack.size())-1)
       {
          if(truehack.size()>1)strcpy(msg,"Your Hackers have ");
          else {strcpy(msg,truehack[0]->name);strcat(msg," has ");}
@@ -1295,7 +1295,7 @@
          for(int h=0;h<truehack.size();h++)
             addjuice(*truehack[h],juiceval,200);
       }
-      else if(DIFFICULTY_FORMIDABLE<=hack_skill+truehack.size()-1)
+      else if(DIFFICULTY_FORMIDABLE<=hack_skill+((int)truehack.size())-1)
       {
          int issue=LCSrandom(VIEWNUM-5);
          int crime;
Logged
Let him who hath understanding reckon the number of the blood god, for it is a dwarven number.  It's number is five-hundred and eighty nine.
http://www.bay12games.com/forum/index.php?topic=53222.0

mainiac

  • Bay Watcher
  • Na vazeal kwah-kai
    • View Profile
Re: Patch for Issue with Hacking
« Reply #1 on: February 06, 2011, 12:32:10 am »

That is epic user feedback.
Logged
Ancient Babylonian god of RAEG
--------------
[CAN_INTERNET]
[PREFSTRING:google]
"Don't tell me what you value. Show me your budget and I will tell you what you value"
« Last Edit: February 10, 1988, 03:27:23 pm by UR MOM »
mainiac is always a little sarcastic, at least.

EuchreJack

  • Bay Watcher
  • Lord of Norderland - Lv 20 SKOOKUM ROC
    • View Profile
Re: Patch for Issue with Hacking
« Reply #2 on: February 06, 2011, 07:16:06 pm »

I agree with mainiac, this is awesome.  This community greatly encourages user input, code corrections, and more.

Carlos Gustavos

  • Bay Watcher
    • View Profile
Re: Patch for Issue with Hacking
« Reply #3 on: February 07, 2011, 04:45:23 pm »

I've put in the second part. The first part wasn't necessary for me.

I don't get why this error occurs on those two lines, but not on any of the other (vector).size()-1 that are in the same file.
Logged

Rakeela

  • Bay Watcher
    • View Profile
Re: Patch for Issue with Hacking
« Reply #4 on: February 07, 2011, 05:07:52 pm »

I've put in the second part. The first part wasn't necessary for me.

I don't get why this error occurs on those two lines, but not on any of the other (vector).size()-1 that are in the same file.

I wouldn't call myself a skilled coder.  I wonder why the first part was necessary for me, but not for you, and I wonder if there's similar variance elsewhere.  Questions abound all around, and having done this tempts me to try to test the game more thoroughly and see if I can trigger any other crashes.
Logged
Let him who hath understanding reckon the number of the blood god, for it is a dwarven number.  It's number is five-hundred and eighty nine.
http://www.bay12games.com/forum/index.php?topic=53222.0

EuchreJack

  • Bay Watcher
  • Lord of Norderland - Lv 20 SKOOKUM ROC
    • View Profile
Re: Patch for Issue with Hacking
« Reply #5 on: February 08, 2011, 06:01:06 pm »

I've put in the second part. The first part wasn't necessary for me.

I don't get why this error occurs on those two lines, but not on any of the other (vector).size()-1 that are in the same file.

I wouldn't call myself a skilled coder.  I wonder why the first part was necessary for me, but not for you, and I wonder if there's similar variance elsewhere.  Questions abound all around, and having done this tempts me to try to test the game more thoroughly and see if I can trigger any other crashes.

If you fix every crash that you find, then I wish you happy crashday!

Rakeela

  • Bay Watcher
    • View Profile
Re: Patch for Issue with Hacking
« Reply #6 on: February 15, 2011, 02:12:05 pm »

I found several!  I even reproduced a few of them.  Alas, I suck as a coder, and haven't been able to fix any of the others so far.  I'll keep trying.
Logged
Let him who hath understanding reckon the number of the blood god, for it is a dwarven number.  It's number is five-hundred and eighty nine.
http://www.bay12games.com/forum/index.php?topic=53222.0

InfernoZeus

  • Bay Watcher
    • View Profile
Re: Patch for Issue with Hacking
« Reply #7 on: February 16, 2011, 11:47:24 am »

I found several!  I even reproduced a few of them.  Alas, I suck as a coder, and haven't been able to fix any of the others so far.  I'll keep trying.

It'd be good if you posted them somewhere, just in case they haven't already been acknowledged. I'm not sure if there's a proper issue tracker though.
« Last Edit: February 16, 2011, 11:49:33 am by InfernoZeus »
Logged