Saturday, August 4, 2007

Guided Lasers

By: Phasmophage
Okay, I was originally planning to keep this in reserve due to its immense power. But, due to popular demand (namely randomdude), I have decided to post it.

Guided lasers allow you to lock on to an opponent's position and have perfect accuracy when shooting at them. To do this, we will need to edit two source files: playing.cxx and LocalPlayer.cxx.

The reason we will be editing playing.cxx is to allow us to lock on with lasers. So, find these lines of code:

// see if it's inside lock-on angle (if we're trying to lock-on)
if (a < BZDB.eval(StateDatabase::BZDB_LOCKONANGLE) && // about 8.5 degrees
((myTank->getFlag() == Flags::GuidedMissile) || // am i locking on?
tankHasShotType(myTank, Flags::GuidedMissile)) &&
player[i]->getFlag() != Flags::Stealth && // can't lock on stealth
!player[i]->isPaused() && // can't lock on paused
!player[i]->isNotResponding() && // can't lock on not responding
d < bestDistance) {
bestTarget = player[i];
bestDistance = d;
lockedOn = true;
}

and change this line:
((myTank->getFlag() == Flags::GuidedMissile) || // am i locking on?

to this:
((myTank->getFlag() == Flags::GuidedMissile) || (myTank->getFlag() == Flags::Laser) || // am i locking on?


You will also find these lines, very similar to the lines before:
if (a < BZDB.eval(StateDatabase::BZDB_LOCKONANGLE) && // about 8.5 degrees
myTank->getFlag() == Flags::GuidedMissile && // am i locking on?
player[i]->getFlag() != Flags::Stealth && // can't lock on stealth
!player[i]->isPaused() && // can't lock on paused
!player[i]->isNotResponding() && // can't lock on not responding
d < bestDistance) { // is it better?
bestTarget = player[i];
bestDistance = d;
lockedOn = true;
}

Now change this line:
myTank->getFlag() == Flags::GuidedMissile && // am i locking on?

To this:
(myTank->getFlag() == Flags::GuidedMissile || myTank->getFlag() == Flags::Laser) && // am i locking on?

That's all the edits for playing.cxx

We will now edit LocalPlayer.cxx and find these lines of code:
else {
// apply any handicap advantage to shot speed
if (handicap > 0.0f) {
const float speedAd = 1.0f + (handicap * (BZDB.eval(StateDatabase::BZDB_HANDICAPSHOTAD) - 1.0f));
const float* dir = getForward();
const float* tankVel = getVelocity();
const float shotSpeed = speedAd * BZDB.eval(StateDatabase::BZDB_SHOTSPEED);
firingInfo.shot.vel[0] = tankVel[0] + shotSpeed * dir[0];
firingInfo.shot.vel[1] = tankVel[1] + shotSpeed * dir[1];
firingInfo.shot.vel[2] = tankVel[2] + shotSpeed * dir[2];
}

Now add these lines of code after it: (Wrote it myself, so it's pretty cruddy looking)
bool LockedOn = false;
const Player * target = getTarget();
if(target){
//const float* tankVel = getVelocity();
const float shotSpeed = BZDB.eval(StateDatabase::BZDB_SHOTSPEED);
float newAz = TargetingUtils::getTargetAzimuth( getPosition(), target->getPosition() );
float newPos[3];
const float * tarPos = target->getPosition();
float enemyPos[3];
const float *tv = target->getVelocity();
enemyPos[0] = tarPos[0] + (0.3f * tv[0]); //Lag adjustment
enemyPos[1] = tarPos[1] + (0.3f * tv[1]);
enemyPos[2] = tarPos[2] + (0.3f * tv[2]);
const float * myPos = getPosition();
const float * myDir = getForward();
newPos[0] = enemyPos[0] - ( myPos[0] + (myDir[0] * 0.1)); //Muzzlefront?
newPos[1] = enemyPos[1] - ( myPos[1] + (myDir[1] * 0.1)); //Muzzlefront?
newPos[2] = enemyPos[2] - myPos[2];
//newPos[2] += target->getMuzzleHeight(); // right between the eyes
float newElevation = atan2f(newPos[2], hypotf(newPos[1], newPos[0]));
float newDir[3] = {cosf(newAz), sinf(newAz), sinf(newElevation)};
firingInfo.shot.vel[0] = /*tankVel[0] +*/ shotSpeed * newDir[0];
firingInfo.shot.vel[1] = /*tankVel[1] +*/ shotSpeed * newDir[1];
firingInfo.shot.vel[2] = /*tankVel[2] +*/ shotSpeed * newDir[2];
LockedOn = true;
}

// Set _shotsKeepVerticalVelocity on the server if you want shots
// to have the same vertical velocity as the tank when fired.
// keeping shots moving horizontally makes the game more playable.
if (!LockedOn && !BZDB.isTrue(StateDatabase::BZDB_SHOTSKEEPVERTICALV)) firingInfo.shot.vel[2] = 0.0f;

Oh yeah, forgot, the last four lines should replace these lines:

// Set _shotsKeepVerticalVelocity on the server if you want shots
// to have the same vertical velocity as the tank when fired.
// keeping shots moving horizontally makes the game more playable.
if (!BZDB.isTrue(StateDatabase::BZDB_SHOTSKEEPVERTICALV)) firingInfo.shot.vel[2] = 0.0f;

This will allow your lasers to shoot down or up at people, so this cheat sticks out like a sore thumb.

Oh yeah, forgot again. You'll need to put
#include "TargetingUtils.h"
after this line:
#include "effectsRenderer.h"


And that's basically it. This powerful cheat written by phasmophage (aka "Phaz" or me) and brought to you exclusively by bzfcheat.blogspot.com.
If there is anything I might have forgotten, bad math, bad implementation, or if you actually really like it, comments are greatly appreciated.

Have fun!
-Phaz
;)

10 comments:

randomdude said...

You are a god among men. (sorry lord jesus XD). That is one of the coolest cheats around.
I've done nearly all of the cheats on the page, exceptions being instant self-destruct, and blinking st (guided laser will be done after this post). The only thing i thought it could be was the "draw my shots" line in radarrenderer.cxx, but this doesn't make sense, because it is the radar, and it is "my" shots not "others". That said, i think i may have stuffed up the "see invisible bullets" cheat a bit, i may have edited the wrong section.

If you could perhaps tell me the most obvious file that would cause that problem, if that is possible, and i will use a 'regular' version of 2.0.9 to mirror against so i can see where the problem might be.

Thanks anyway.

randomdude said...

aha! don't worry about it, i finally fixed it! it was in the "always see actual tank colours" cheat. i missed a line XD

CRW said...

"...(sorry lord jesus XD)"

No offense taken, randomdude ;)

I'm glad that you were able to find the discrepancy, and I hope everything is working for you as you want. We test out our tips prior to posting; however, getting feedback from others helps us to ensure that the tips we are posting are indeed accurate.

Thank you very much for trying out our tips and for your feed back. We greatly appreciate it :)

And yes, Phaz's cheats really are bad ass :D

Unknown said...

this guy have some awesome cheats jejeje

Unknown said...

hey guys i need help, i'm trying to change the shots properties from the SegmetedShotStrategy.cxx and theShockwaveStrategy.cxx. But looks like the changes only affect my client.
For example, i can change the shockwave radius, but i cant kill anyone.

phasmophage said...

About changing the shot strategies, it will only change the way your client interprets shots. You see, when a shot is fired, the only thing that is sent (unless it's GM) is the initial position, velocity, and shot type of the bullet. It is up the the client to interpret the shockout radius, ricochets and so forth. That's why changing shot strategies really don't do much good.

Oh yeah, and thanks for the comments. I really appreciate it. And sorry, randomdude, that I didn't respond in time to help you out, but you figured it out pretty quickly anyway. ;)

If you guys have any other cheats you would like to see done, I'd love to work on them.
-Phaz

randomdude said...

So if it sends out the shot type, starting point and velocity, then would it be possible to change the shot type of your bullets? i think i have heard of this happening.
some ideas just spawning from that would be also:

possible to make your shots travel faster, while still keeping the same reload time?

possible to have a button which sends out a shot signal to the server without taking up a reload, therefore creating infinite bullets?

obviously i'll be checking those ideas out myself, but you, being more experienced with bz and better at programming, will be able to tell me whether or not those things are possible

phasmophage said...

I've looked at the bzfs (server) source code, and if you try to change your shot type without holding a flag, it will reset the shot type back to normal. This would cause it to look like the new shot type to you, but would look normal to everyone else. If you change your shot type _with_ a flag, the server automatically kicks you. (There is one exception: You can change your shot type to thief without getting kicked.)
You can change the bullet speed to be a little bit faster, but if it is too fast the server will ignore the shot. This means, again, you can see the fast shot, but nobody else can.
This reminds of a cheat I made, but I never posted cause it only works on one server. What this cheat would do is start a bullet out behind an enemy, wherever they were, and drive it right through them. It was effectively a remote kill function. :) The problem was, if I did it on any server besides Urban Jungle, I could see the bullet, but nobody else. The server ignored the shot.
Oh yeah, and about infinite bullets. The bzfs code says that it wont do anything if the player shoots more than allowed:
} else { // more shots fired than allowed
// do nothing for now -- could return and not allow shot
}
But when I tried it on places like pythonian, again, people couldn't get killed by the extra shots.

A really good cheat that I am currently developing reduces the reload time to the lifetime of a bullet. Basically, you know the laser reload time? This will change it to the time it takes for the laser to disappear. If you want to do this without waiting for me to post on it, find where it says setReloadTime or something and change the parameter to the lifetime of the bullet.

Sorry, my comment was way too long.
-Phaz

martinio1448 said...
This comment has been removed by the author.
martinio1448 said...
This comment has been removed by the author.