Beispiel #1
0
void spawnAmmunation( LPVOID args ){
	D3D9_item* item = (D3D9_item*) args;
	Memory* m = (Memory*) item->arguments;

	auto			ConsumableTable = ConsumableTable::Singleton();
	auto			ConsumableTableSize = ConsumableTable->getTableSize();

	auto			world = World::Singleton();
	auto			locPlayer = world->getCameraOn()->getUnit();

	auto			InventoryTable = locPlayer->getInventoryTable();
	auto			InventoryTableSize = InventoryTable->getConsumableTableSize();
	auto			InventoryTableMaxSize = InventoryTable->getConsumableTableMaxSize( );
	auto			Inventory = InventoryTable->getConsumableInventory();

	if( item->value > (int)(ConsumableTableSize - 1) ){
		item->value = 0;
		item->isEnabled = false;
		return;
	}

	auto  Consumable = ConsumableTable->getEntryById( item->value );
	if( Consumable->getBase() ){
		if( InventoryTableSize < InventoryTableMaxSize ){
			DWORD memory = m->allocateMemory( 0x2C );
			if (!memory) {
				console->sendInput( "Failed to allocate memory!" );
				return;
			}
				

			DWORD item1 = m->read<DWORD>( m->read<DWORD>( Inventory->getBase( ) + 0x28 ) );
			DWORD item2 = m->read<DWORD>( m->read<DWORD>( Inventory->getBase( ) + 0x4 ) );

			m->write( memory, m->read<DWORD>( Inventory->getBase() ) );
			m->write( memory + 0x4, item2 );
			m->write( memory + 0x8, Consumable->getBase() );

			m->write( memory + 0x28, item1 );
			m->write( memory + 0x2C, itemRef );
			itemRef++;

			/* UNCHECKED */
			int ammoXOR = m->read<DWORD>( Consumable->getBase() + 0x2C ) ^ (int)( 0xBABAC8B6L );
			int ammoVal = ammoXOR << 1;

			m->write( memory + 0xC, int( ammoXOR - ammoVal ) );
			m->write( memory + 0x24, ammoVal );
			/* END UNCHECKED */

			DWORD distance = Inventory->calculateDistance( InventoryTableSize );

			m->write( distance, memory );
			InventoryTable->setConsumableTableSize( InventoryTableSize + 1 );
		}
	}

	item->isEnabled = false;
}
Beispiel #2
0
int main(){

  vector<pair<int,int>>holes;
  int numHoles=0;

  while(numHoles<=0){
    cout<<"Enter number of holes: ";
    cin>>numHoles;
    if(numHoles<=0)
      cout<<"Number of holes must be > 0\n";
    else break;
  }

  int holeStart,holeSize;
  for(int i=0;i<numHoles;i++){
    cout<<"Enter hole starting position and hole size: ";
    cin>>holeStart>>holeSize;
    if(holeStart<0){cout<<"start can't be negative"<<endl;i--;continue;}
    if(holeSize<0){cout<<"size can't be negative"<<endl;i--;continue;}
    holes.push_back({holeStart,holeSize});
  }

  sort(holes.begin(),holes.end());
  int j=0;
  vector<pair<int,int>>merged_holes;
  for(int i=0;i<holes.size();i=j){
    for(j=i+1;j<holes.size();j++){
      if(holes[i].first+holes[i].second>=holes[j].first){
        holes[i].second=max(holes[i].first+holes[i].second,holes[j].first+holes[j].second)-holes[i].first;
      }
      else break;
    }
    merged_holes.push_back({holes[i].first,holes[i].second});
  }

  vector<Block*>initial_blocks;
  int process_counter=-1;
  if(merged_holes[0].first!=0){
    initial_blocks.push_back(new Process(process_counter,0,merged_holes[0].first));
  }
  for(int i=0;i<merged_holes.size();i++){
    initial_blocks.push_back(new Block(merged_holes[i].first,merged_holes[i].second));
    if(i==merged_holes.size()-1)break;
    initial_blocks.push_back(new Process(process_counter,merged_holes[i].first+merged_holes[i].second,merged_holes[i+1].first-(merged_holes[i].first+merged_holes[i].second)));
  }

  Memory *memory;

  int type;
  cout<<"Enter the type of the memory (1- First Fit, 2-Best Fit, 3-Worst Fit): ";
  cin>>type;

  if(type==1){
    memory = new FirstFitMemory(initial_blocks);
  }else if(type==2){
    memory = new BestFitMemory(initial_blocks);
  }else if(type==3){
    memory = new WorstFitMemory(initial_blocks);
  }else{
    cout<<"Type is invalid.";
    return 0;
  }

  cout<<"Memory was successfully created"<<endl;
  memory->print();

  int id,limit;
  
  for(;;){
    int query_type;
    cout<<"Enter the query type (1- Allocate, 2- Deallocate, 3- Finish): ";
    cin>>query_type;
    if(query_type==1){
      cout<<"Enter the id of the process: ";
      cin>>id;
      cout<<"Enter the size of the process: ";
      cin>>limit;
      if(memory->allocateMemory(id,limit)){
        cout<<"The Process was successfully allocated"<<endl;
        memory->print();
      }
      else{
        cout<<"No enough space to add the process"<<endl;
      }
    }else if(query_type==2){