Example #1
0
// In the spirt of so many exceptions! =D blah! https://msdn.microsoft.com/en-us/library/1eyas8tf.aspx
LONG WINAPI vEhTracer(PEXCEPTION_POINTERS ExceptionInfo)
{
	DWORD OldPerm;
	PExecutionBlock pCtx = NULL;

	ULONG64 dwThr = __readgsdword(0x48);


	// TODO: just put the whole context in the array to remove an indirect anyhow
	if (CtxTable != NULL && CtxTable[dwThr].TID != 0)
		pCtx = &CtxTable[dwThr];
	else
		pCtx = InitBlock(dwThr);

	// allow exec
	//pCtx->DisabledUntil = (LPVOID)((ULONG64) ExceptionInfo->ExceptionRecord->ExceptionAddress & ~0x4095);
	
	pCtx->pExeption = ExceptionInfo;
	pCtx->TSC = __rdtsc();

	// check if my thread is a thread that's already entered into the VEH logging something lower on the stack
	// this means were probably getting an exception for something we did ourselves during the logging 
	// which is sort of pointless
	// we could test all Exception address against known entries we provide
	if (AmIinThreadTable())
		return EXCEPTION_CONTINUE_EXECUTION;


	if (ExceptionInfo->ExceptionRecord->ExceptionCode != STATUS_SINGLE_STEP)
		return EXCEPTION_CONTINUE_SEARCH;

	// no re-entrance while servicing exceptions
	EnterThreadTable(dwThr, false);

	// since we like to do logging
	//LogRIP(pCtx);
	// to dump info 
	//_DumpContext(pCtx);

	// Loop through all of the block fighters
	Fight(pCtx);

	// Thanks Feryno
	// http://x86asm.net/articles/backdoor-support-for-control-transfer-breakpoint-features/
	// 
	ExceptionInfo->ContextRecord->EFlags |= 0x100; // single step
	ExceptionInfo->ContextRecord->Dr7 |= 0x300; // setup branch tracing 

	// record keeping
	pCtx->BlockFrom = ExceptionInfo->ContextRecord->Rip;

	// exit lock
	ExitThreadTable(dwThr, false);
	
	return EXCEPTION_CONTINUE_EXECUTION;
}
void Archer::Move(sf::Vector2f pos)
{
    if (numMovesRemaining > 0)
    {
        auto test = MapManager::GetInstance()->GetTileAtPosition(sf::Vector2f(pos.x + 1, pos.y + 1))->GetPosition();
        auto test2 = std::sqrt((test.x - (sprite.getPosition().x - SPRITE_WIDTH)) * (test.x - (sprite.getPosition().x - SPRITE_WIDTH)) + (test.y - sprite.getPosition().y) * (test.y - sprite.getPosition().y));
        if (test2 <= 112)
        {//if distance to point is less than 1 move check if it is an attack command
            auto temp = MapManager::GetInstance()->CheckForEnemyAtPosition(owningPlayer, sf::Vector2f(pos.x + SPRITE_WIDTH, pos.y));
            if (temp)
            {
                switch (temp->getType())
                {
                    case UNITTYPES::SWORDSMAN:
                        Fight(static_cast<Swordsman*>(temp));
                        break;
                    case UNITTYPES::PIKEMAN:
                        Fight(static_cast<Pikeman*>(temp));
                        break;
                    case UNITTYPES::ARCHER:
                        Fight(static_cast<Archer*>(temp));
                        break;
                    case UNITTYPES::KNIGHT:
                        Fight(static_cast<Knight*>(temp));
                        break;
                    default:
                        break;
                }
                numMovesRemaining = 0;
                return;
            } 
        }

        auto Path = PathFinder::GetInstance()->FindPath(sprite.getPosition(), pos);
        if (Path == NULL)
        {
            std::cout << pos.x << "," << pos.y << std::endl;
            return;
        }
        auto temp = sprite.getPosition();
        int directionX = Path->at(1).x - (sprite.getPosition().x - SPRITE_WIDTH);
        int directionY = Path->at(1).y - sprite.getPosition().y;

        if (directionX > 56 || directionX < -56)
        {
            int tempX = 1;
            if (directionX < 0) { tempX = -1; }

            if (directionX != 0) { directionX /= directionX; }

            directionX *= (56 * tempX);
        }
        if (directionY > 56 || directionY < -56)
        {
            int tempY = 1;

            if (directionY < 0) { tempY = -1; }

            if (directionY != 0) { directionY /= directionY; }

            directionY *= (56 * tempY);
        }

        auto oldNodePos = PathFinder::GetInstance()->GetNodeAtPosition(sprite.getPosition());
        auto newNodePos = PathFinder::GetInstance()->GetNodeAtPosition(sf::Vector2f(sprite.getPosition().x + directionX, sprite.getPosition().y + directionY));

        sprite.setPosition(sf::Vector2f(newNodePos->GetPosition().x + SPRITE_WIDTH, newNodePos->GetPosition().y));
        strengthText.setPosition(sprite.getPosition().x + 14, sprite.getPosition().y + 40);
        oldNodePos->setWalkable(true);
        newNodePos->setWalkable(false);
        numMovesRemaining--;
    }
}
Example #3
0
// Player is pizza, encounters ninjas and wizards to gain points... points = levels, different levels mean different points needed to progress
int Play()
{
    int xBossCoord = 2;
    int yBossCoord = 2;
    
    int playerLevel = 1;
    int xpNeeded = playerLevel * 50;
    int playerXp = 0;
    //Local Variables
    /************************************************************************/
    // DELETE
    //	int pizza = 0;   // player
    //	int ninja = 0;   // bad guy
    //	int wizards = 0; // bad guy
    /************************************************************************/
    char direction;  		// player input for direction to go next
    int escape = 0;  		//escape character
    int randEncounter = -1;	//Chance that an Encounter with a Ninja Happens
    
    printf("Welcome to Pizza Ninja Wizards.... you can move north or east from your present location...\n");
    // DELETE
    //	printf("Welcome to Battle Cats.... you can move north or east from your present location...\n");
    
    while(escape == 0){
        
        if ((xCoord > 0 && xCoord < 6) && (yCoord > 0 && yCoord < 6)){ // user is between bottom and top as well as left and right )
            
            printf("You are at location %d,%d.\n", xCoord, yCoord);
            printf("Where do you want to go? (W=North,A=West,S=South,D=East, Q to Quit)\n");
            scanf("%s",&direction);
            
            switch (direction){
                case 'W' : case 'w' : yCoord += 1 ; break;
                case 'A' : case 'a' : xCoord -= 1; break;
                case 'S' : case 's' : yCoord -= 1 ; break;
                case 'D' : case 'd' : xCoord += 1 ; break;
                case 'Q' : case 'q' : escape = 1 ; break;
                default : printf("I do not understand what you are talking about\n\n") ; break;
                    
            }
            
            // DELETE
            //		printf("Where do you want to go? (W=North,A=West,S=South,D=East)\n");
            //		scanf("%c",&direction);
            
        }
        
        else if (xCoord <= 0 || xCoord >= 6 || yCoord <= 0 || yCoord >= 6) // player has moved out of bounds
        {
            
            //bring the player back in bounds, present feedback to the player that they are at the edge of the map
            
            switch(xCoord){
                case 0 : xCoord = 1 ; printf("You are too far west. You can not go further that way.\n") ; break;
                case 6 : xCoord = 5 ; printf("You are too far east. You can not go further that way.\n") ; break;
            }
            
            switch(yCoord){
                case 0 : yCoord = 1 ; printf("You are too far south. You can not go further that way.\n") ; break;
                case 6 : yCoord = 5 ; printf("You are too far north. You can not go further that way.\n") ; break;
            }
            
        }
        
        
        // New code to create monster encounters
        randEncounter = rand() % 11;
        ///DEBUGGING FUNTION
        // randEncounter = 8;
        
        if (randEncounter > 7){	// 1 in 5 (20%) chance moving will find an Encounter
            
            playerXp += Fight(0);
            
        }
        else if (xCoord == xBossCoord && yCoord == yBossCoord)
        {
            printf("YOU ENCOUNTERED THE SUPER NINJA WHO IS GOING TO KILL YOU.\n");
            playerXp += Fight(1);
        }
        else {
            
            // do nothing for now
            //eventually add in a "Counter" mechanism so if you keep not finding encounters, your chances to find one increase
            
        }
        
        printf("Your xp is %d\n", playerXp);
        if(playerXp > xpNeeded)
        {
            printf("LEVEL UP YEYAA!\n");
            playerLevel ++;
            xpNeeded = playerLevel * xpNeeded;
        }
    }
    
    printf("\nThank you for Playing... Have a Great Day!");
    return 0;
    
}