void * LinearAllocator::Allocate(Uint32 size, Uint8 alignment)
{
    ASSERT(size != 0, "Size = 0");

    // memaligning it to a word capture
    Uint8 memAlign = AlignForwardAdjustment(mCurrentPos, alignment);

    Uint32 memUsed = size + memAlign;

    if(BaseAllocator::CheckAllocatorOverflow(memUsed))
        return nullptr;

    void * alignedStartAddress = AddOffset(mCurrentPos, memAlign);

    mCurrentPos = AddOffset(mCurrentPos, memUsed);

    LogAllocation(memUsed);

    return (void *)alignedStartAddress;
}
Пример #2
0
void CWeaponOffsetInput::Update()
{
	float moveSpeed = 0;
	switch (m_sensibility)
	{
		case ESensibility_Slow:
			moveSpeed = 0.001f;
			break;
		case ESensibility_Medium:
			moveSpeed = 0.01f;
			break;
		case ESensibility_Fast:
			moveSpeed = 0.1f;
			break;
	}

	Vec2 offset = m_offset * gEnv->pTimer->GetFrameTime() * moveSpeed;

	switch (m_mode)
	{
		case EMode_PositionOffset:
			AddOffset(
				Vec3(offset.x, 0.0f, -offset.y),
				Ang3(0.0f, 0.0f, 0.0f));
			break;

		case EMode_RotationOffset:
			AddOffset(
				Vec3(0.0f, 0.0f, 0.0f),
				Ang3(-offset.y, 0.0f, -offset.x));
			break;

		case EMode_ZAxisOffset:
			AddOffset(
				Vec3(0.0f, -offset.y, 0.0f),
				Ang3(0.0f, offset.x, 0.0f));
			break;
	}

	m_offset = Vec2(ZERO);
}
nsSize
nsGridLayout2::GetMaxSize(nsIBox* aBox, nsBoxLayoutState& aState)
{
  nsSize maxSize = nsStackLayout::GetMaxSize(aBox, aState); 

  // if there are no <rows> tags that will sum up our columns,
  // sum up our columns here.
  nsSize total(NS_INTRINSICSIZE, NS_INTRINSICSIZE);
  nsIBox* rowsBox = mGrid.GetRowsBox();
  nsIBox* columnsBox = mGrid.GetColumnsBox();
  if (!rowsBox || !columnsBox) {
    if (!rowsBox) {
      total.height = 0;
      // max height is the sum of our rows
      PRInt32 rows = mGrid.GetRowCount();
      for (PRInt32 i=0; i < rows; i++)
      {
        nscoord height = mGrid.GetMaxRowHeight(aState, i, PR_TRUE); 
        AddWidth(total, height, PR_FALSE); // AddHeight
      }
    }

    if (!columnsBox) {
      total.width = 0;
      // max height is the sum of our rows
      PRInt32 columns = mGrid.GetColumnCount();
      for (PRInt32 i=0; i < columns; i++)
      {
        nscoord width = mGrid.GetMaxRowHeight(aState, i, PR_FALSE);
        AddWidth(total, width, PR_TRUE); // AddWidth
      }
    }

    AddMargin(aBox, total);
    AddOffset(aState, aBox, total);
    AddSmallestSize(maxSize, total);
  }

  return maxSize;
}
Пример #4
0
nsSize
nsStackLayout::GetMinSize(nsIBox* aBox, nsBoxLayoutState& aState)
{
  nsSize minSize (0, 0);

  // run through all the children and get their min, max, and preferred sizes

  nsIBox* child = aBox->GetChildBox();
  while (child) {  
    nsSize min = child->GetMinSize(aState);
    AddMargin(child, min);
    AddOffset(aState, child, min);
    AddLargestSize(minSize, min);

    child = child->GetNextBox();
  }

  // now add our border and padding
  AddBorderAndPadding(aBox, minSize);

  return minSize;
}
nsSize
nsGridLayout2::GetPrefSize(nsIBox* aBox, nsBoxLayoutState& aState)
{
  nsSize pref = nsStackLayout::GetPrefSize(aBox, aState); 

  // if there are no <rows> tags that will sum up our columns,
  // sum up our columns here.
  nsSize total(0,0);
  nsIBox* rowsBox = mGrid.GetRowsBox();
  nsIBox* columnsBox = mGrid.GetColumnsBox();
  if (!rowsBox || !columnsBox) {
    if (!rowsBox) {
      // max height is the sum of our rows
      PRInt32 rows = mGrid.GetRowCount();
      for (PRInt32 i=0; i < rows; i++)
      {
        nscoord height = mGrid.GetPrefRowHeight(aState, i, PR_TRUE); 
        AddWidth(total, height, PR_FALSE); // AddHeight
      }
    }

    if (!columnsBox) {
      // max height is the sum of our rows
      PRInt32 columns = mGrid.GetColumnCount();
      for (PRInt32 i=0; i < columns; i++)
      {
        nscoord width = mGrid.GetPrefRowHeight(aState, i, PR_FALSE);
        AddWidth(total, width, PR_TRUE); // AddWidth
      }
    }

    AddMargin(aBox, total);
    AddOffset(aState, aBox, total);
    AddLargestSize(pref, total);
  }

  return pref;
}
Пример #6
0
nsSize
nsGridLayout2::GetXULMinSize(nsIFrame* aBox, nsBoxLayoutState& aState)
{
  nsSize minSize = nsStackLayout::GetXULMinSize(aBox, aState); 

  // if there are no <rows> tags that will sum up our columns,
  // sum up our columns here.
  nsSize total(0,0);
  nsIFrame* rowsBox = mGrid.GetRowsBox();
  nsIFrame* columnsBox = mGrid.GetColumnsBox();
  if (!rowsBox || !columnsBox) {
    if (!rowsBox) {
      // max height is the sum of our rows
      int32_t rows = mGrid.GetRowCount();
      for (int32_t i=0; i < rows; i++)
      {
        nscoord height = mGrid.GetMinRowHeight(aState, i, true); 
        AddWidth(total, height, false); // AddHeight
      }
    }

    if (!columnsBox) {
      // max height is the sum of our rows
      int32_t columns = mGrid.GetColumnCount();
      for (int32_t i=0; i < columns; i++)
      {
        nscoord width = mGrid.GetMinRowHeight(aState, i, false); 
        AddWidth(total, width, true); // AddWidth
      }
    }

    AddMargin(aBox, total);
    AddOffset(aBox, total);
    AddLargestSize(minSize, total);
  }
  
  return minSize;
}
Пример #7
0
nsSize
nsStackLayout::GetPrefSize(nsIBox* aBox, nsBoxLayoutState& aState)
{
  nsSize rpref (0, 0);

  // we are as wide as the widest child plus its left offset
  // we are tall as the tallest child plus its top offset

  nsIBox* child = aBox->GetChildBox();
  while (child) {  
    nsSize pref = child->GetPrefSize(aState);

    AddMargin(child, pref);
    AddOffset(aState, child, pref);
    AddLargestSize(rpref, pref);

    child = child->GetNextBox();
  }

  // now add our border and padding
  AddBorderAndPadding(aBox, rpref);

  return rpref;
}
Пример #8
0
nsSize
nsStackLayout::GetMaxSize(nsIBox* aBox, nsBoxLayoutState& aState)
{
  nsSize maxSize (NS_INTRINSICSIZE, NS_INTRINSICSIZE);

  // run through all the children and get their min, max, and preferred sizes

  nsIBox* child = aBox->GetChildBox();
  while (child) {  
    nsSize min = child->GetMinSize(aState);
    nsSize max = nsBox::BoundsCheckMinMax(min, child->GetMaxSize(aState));

    AddMargin(child, max);
    AddOffset(aState, child, max);
    AddSmallestSize(maxSize, max);

    child = child->GetNextBox();
  }

  // now add our border and padding
  AddBorderAndPadding(aBox, maxSize);

  return maxSize;
}
Пример #9
0
NS_IMETHODIMP
nsStackLayout::Layout(nsIBox* aBox, nsBoxLayoutState& aState)
{
  nsRect clientRect;
  aBox->GetClientRect(clientRect);

  PRBool grow;

  do {
    nsIBox* child = aBox->GetChildBox();
    grow = PR_FALSE;

    while (child) 
    {  
      nsMargin margin;
      child->GetMargin(margin);
      nsRect childRect(clientRect);
      childRect.Deflate(margin);

      if (childRect.width < 0)
        childRect.width = 0;

      if (childRect.height < 0)
        childRect.height = 0;

      nsRect oldRect(child->GetRect());
      PRBool sizeChanged = (oldRect != childRect);

      // only lay out dirty children or children whose sizes have changed
      if (sizeChanged || NS_SUBTREE_DIRTY(child)) {
          // add in the child's margin
          nsMargin margin;
          child->GetMargin(margin);

          // obtain our offset from the top left border of the stack's content box.
          nsSize offset(0,0);
          PRBool offsetSpecified = AddOffset(aState, child, offset);

          // Correct the child's x/y position by adding in both the margins
          // and the left/top offset.
          childRect.x = clientRect.x + offset.width + margin.left;
          childRect.y = clientRect.y + offset.height + margin.top;
          
          // If we have an offset, we don't stretch the child.  Just use
          // its preferred size.
          if (offsetSpecified) {
            nsSize pref = child->GetPrefSize(aState);
            childRect.width = pref.width;
            childRect.height = pref.height;
          }

          // Now place the child.
          child->SetBounds(aState, childRect);

          // Flow the child.
          child->Layout(aState);

          // Get the child's new rect.
          nsRect childRectNoMargin;
          childRectNoMargin = childRect = child->GetRect();
          childRect.Inflate(margin);

          // Did the child push back on us and get bigger?
          if (offset.width + childRect.width > clientRect.width) {
            clientRect.width = childRect.width + offset.width;
            grow = PR_TRUE;
          }

          if (offset.height + childRect.height > clientRect.height) {
            clientRect.height = childRect.height + offset.height;
            grow = PR_TRUE;
          }

          if (childRectNoMargin != oldRect)
          {
            // redraw the new and old positions if the 
            // child moved or resized.
            // if the new and old rect intersect meaning we just moved a little
            // then just redraw the union. If they don't intersect (meaning
            // we moved a good distance) redraw both separately.
            if (childRectNoMargin.Intersects(oldRect)) {
              nsRect u;
              u.UnionRect(oldRect, childRectNoMargin);
              aBox->Redraw(aState, &u);
            } else {
              aBox->Redraw(aState, &oldRect);
              aBox->Redraw(aState, &childRectNoMargin);
            }
          }
       }

       child = child->GetNextBox();
     }
   } while (grow);
   
   // if some HTML inside us got bigger we need to force ourselves to
   // get bigger
   nsRect bounds(aBox->GetRect());
   nsMargin bp;
   aBox->GetBorderAndPadding(bp);
   clientRect.Inflate(bp);

   if (clientRect.width > bounds.width || clientRect.height > bounds.height)
   {
     if (clientRect.width > bounds.width)
       bounds.width = clientRect.width;
     if (clientRect.height > bounds.height)
       bounds.height = clientRect.height;

     aBox->SetBounds(aState, bounds);
   }

   return NS_OK;
}
Пример #10
0
//======================================
int DialogBlocks::CrackMethods ()
{
    volatile unsigned int checksum, mchecksum;

    //---
    //---this is for DialogBlocks 0.80 - 1.19 (I think)---
    //---

    //this actually makes the program usable. In the function to enable or disable
    //the "Register DialogBlocks..." menu item, I replace one of the cmp's to a mov. This
    //way it sets in memory that it is registered.
    unsigned char find1_1[]    = {0x80, 0xB8, 0xB8, 0x01, 0x00, 0x00, 0x00}; //cmp byte [eax+0x1b8],bl
    unsigned char replace1_1[] = {0xC6, 0x80, 0xB8, 0x01, 0x00, 0x00, 0x01}; //mov byte [eax+0x1b8],0x1

    //disables the "Register DialogBlocks..." menu
    unsigned char find1_2[]    = {0x8B, 0x44, 0x24, 0x04, //mov eax, dword ptr [esp+04]
                                  0x0F, 0x94, 0xC1
                                 };      //setz cl
    unsigned char replace1_2[] = {0x8B, 0x44, 0x24, 0x04, //mov eax, dword ptr [esp+04]
                                  0xB1, 0x00, 0x90
                                 };      //mov cl,0

    //this just erases unregistered, for the user's sake
    unsigned char find1_3[]    = " [UNREGISTERED]";
    unsigned char replace1_3[] = "               ";

    //must be in the same order as found in the file
    ReplaceEntry entries1[] = {
        {find1_1, sizeof (find1_1), replace1_1, sizeof (replace1_1), 1, 0, 0},
        {find1_2, sizeof (find1_2), replace1_2, sizeof (replace1_2), 1, 0, 0},
        {find1_3, sizeof (find1_3), replace1_3, sizeof (replace1_3), 1, 0, 0}
    };

    //---
    //---this is for DialogBlock 1.20+ (I think)---
    //---

    //makes the program functional
    unsigned char find2_1[]    = {0x80, 0xB8, 0x98, 0x00, 0x00, 0x00, 0x00}; //cmp byte [eax+0x62], 0x0
    unsigned char replace2_1[] = {0x80, 0xB8, 0x98, 0x00, 0x00, 0x00, 0x01}; //cmp byte [eax+0x62], 0x1

    //effectively removes all the nags in the program
    unsigned char find2_2[]    = {0x38, 0x98, 0x98, 0x00, 0x00, 0x00}; //cmp byte [eax+0x62], bl
    unsigned char replace2_2[] = {0x90, 0x90, 0x90, 0x90, 0x90, 0x90}; //NOPs

    //this was found by searching for "Register Dialogblocks" until i found a part in the asm that
    //it was trying to create the dialog, and was using this name as the title bar. i then looked a little
    //above and saw that 6 memory areas were jumping to this location, so obviously this was the memory area
    //where this particular dialog is created
    unsigned char find2_3[]    = {0xB8, 0xCB, 0x74, 0x62, 0x00}; //the start of the Register Dialog creation
    unsigned char replace2_3[] = {0xC3, 0x90, 0x90, 0x90, 0x90}; //put a ret(C3) at the beginning, don't create dialog

    //must be in the same order as found in the file
    ReplaceEntry entries2[] = {
        {find2_1, sizeof (find2_1), replace2_1, sizeof (replace2_1), ONE_MINIMUM, 0, 0},
        {find2_2, sizeof (find2_2), replace2_2, sizeof (replace2_2), ONE_MINIMUM, 0, 0},
        {find2_3, sizeof (find2_3), replace2_3, sizeof (replace2_3), ZERO_MINIMUM, 0, 0}
    };

    //---
    //---our methods---
    //---

    Methods methods[] = {
        {entries1, SCOUNT (entries1, ReplaceEntry)},
        {entries2, SCOUNT (entries2, ReplaceEntry)}
    };

    //---
    //---Algorithm---
    //---

    //since this is a dynamic cracking algorithm, it may take
    //some time to crack the program. It searches for opcode offsets
    //and replaces them with new opcode

    char block[CrackAssist::XSIZE];
    Methods *p;
    ReplaceEntry *p2;
    long lFileSize = m_ca.FSize ();
    for (int i = 0; i < SCOUNT (methods, Methods); i++) {
        long lCurrentOffset = 0;
        checksum = 0;
        p = &methods[i];

        //calculate minimum checksum (checksum much reach this to become a successful crack)
        mchecksum = 0;
        for (unsigned int x = 0; x < p->nEntries; x++) {
            if (p->entries[x].nOccurrences == ZERO_MINIMUM) {
                //don't add anything to minimum checksum
            } else if (p->entries[x].nOccurrences == ONE_MINIMUM) {
                mchecksum += 1;
            } else {
                mchecksum += p->entries[x].nOccurrences;
            }
        }

        while (int nRead = m_ca.FRead (block, 1, sizeof (block))) {
            lCurrentOffset += nRead;
            //repeatedly search the buffer for all occurrences for all entries
            for (unsigned int x = 0; x < p->nEntries; x++) {
                p2 = &p->entries[x];

                //must set search offset back to 0 for each entry when searching the same block. because what if
                //you have 2 matches for the first entry inside a block, and 1 match for another entry inbetween
                //the other 2 matches. once the search offset goes finds the first and the last match, it will completely
                //skip the middle one. this is because it searches 1 entry at a time for one whole block.
                //*Situation 1: not setting search offset to 0:
                //           [-----------------------------block------------------------------]
                //           .....[entry 1 match].....[entry 2 match]........[entry 1 match]...
                //First run:          *MATCH*                                    *MATCH*
                //Second run:  A NEW BLOCK IS LOADED, MISSING entry #2
                //*Situation 2: setting search offset to 0:
                //           [-----------------------------block------------------------------]
                //           .....[entry 1 match].....[entry 2 match]........[entry 1 match]...
                //First run:          *MATCH*                                    *MATCH*
                //Second run:                             *MATCH*
                //lSearchOffset is the offset to start searching from within a block
                //lOffset is the offset to where it found the match, but this is only relative to the
                //block location + where lSearchOffset is
                long lSearchOffset = 0, lOffset;                               //[  effectively shifts where to search  ]
                while ((lOffset = m_ca.Search ((char *)p2->pFind, p2->nFindSize, block+lSearchOffset, nRead-lSearchOffset)) != -1) {
                    if (p2->nOccurrences == ZERO_MINIMUM) {
                        //             [    matched offset   ]    [   block location   ]
                        AddOffset (p2, lOffset + lSearchOffset + (lCurrentOffset - nRead));
                        //skip where you found the match + the size of the match
                        lSearchOffset += lOffset + p2->nFindSize;
                    } else if ((unsigned int)p2->nOccurrences > p2->nOffsets || p2->nOccurrences == ONE_MINIMUM) {
                        if (!(p2->nOccurrences == ONE_MINIMUM && p2->lpOffsets != 0) ||
                                (p2->nOccurrences == ONE_MINIMUM && p2->lpOffsets == 0))
                            checksum++;
                        //             [    matched offset   ]    [   block location   ]
                        AddOffset (p2, lOffset + lSearchOffset + (lCurrentOffset - nRead));
                        //skip where you found the match + the size of the match
                        lSearchOffset += lOffset + p2->nFindSize;
                    } else {
                        break;
                    }
                }
            }

            //indicates progression only by how much of the file was read
            g_Pc->SetValue (100 - static_cast<int>(lFileSize / lCurrentOffset));
        }

        //make sure we found everything we need to replace, then patch those offsets
        //we have to do >=, because if they use -1 for number of occurences, the checksum
        //could be much greater than the minimum checksum
        if (checksum >= mchecksum) {
            //wxString test;
            for (unsigned int x = 0; x < p->nEntries; x++) {
                p2 = &p->entries[x];
                for (unsigned int i = 0; i < p2->nOffsets; i++) {
                    //test += wxString::Format ("%d - %d\n", p2->nOffsets, p2->lpOffsets[i]);
                    m_ca.PatchOffset (p2->lpOffsets[i], p2->pReplace, p2->nReplaceSize);
                }
            }
            //wxMessageBox (test);

            Cleanup (methods, SCOUNT (methods, Methods));
            return CRACK_Success;
        }

        //get ready to try to crack with the next method
        g_Pc->SetValue (0);
        m_ca.FRewind ();
    }

    Cleanup (methods, SCOUNT (methods, Methods));
    return CRACK_Failed;
}
Пример #11
0
 void SetOffset(double x, double y) {
    ClearOffset();
    AddOffset(x, y);
 }