There is a really good movie just within reach of “Central Intelligence.” The casting is impeccable (no joke, Dwayne Johnson has never been better), and the premise is a strangely beautiful marriage of “Grosse Pointe Blank” and “True Lies,” with a few jabs at Facebook for good measure. They even used their PG-13, one-time-only F-bomb to tell Mark Zuckerberg to, well, you know.

Unfortunately, the dialogue reads like it was written by horny tweens who are really, really into toilet humor. It also falls prey to the age-old movie cliché that the most highly skilled soldiers in the world happen to all be lousy shots. No, no, no.

It is 1996, and Calvin Joyner (Kevin Hart) is riding high as a high school senior and multi-sport all-star. In the middle of his speech at the last assembly of the year, Robbie Weirdicht (Johnson), an awkward, overweight, overlooked kid, is thrown into the gym, naked as a jailbird, by a group of bullies. Calvin offers him his letterman jacket so he can cover himself up, and Robbie is eternally grateful. Twenty years later, Calvin is an accountant but frustrated that he, in his mind, peaked too soon. A day before his 20-year high school reunion, Calvin receives a Facebook friend request from a Bob Stone and accepts it. Bob Stone turns out to be Robbie, only now he’s tall and ripped, and he hasn’t forgotten that Calvin offered to help him during the most humiliating experience of his life.

Bob tells Calvin that he now works for the CIA, and he needs Calvin’s help accessing certain web sites in order to stop an enemy of the state from selling access codes to US satellites to the highest bidder. Calvin is both overwhelmed and freaked out by Bob’s overall approach to life, so when Agent Pamela Harris (Amy Ryan) shows up at Calvin’s door looking for Bob, claiming that Bob is emotionally unstable and extremely dangerous, Calvin is easily convinced. Bob assures Calvin that he’s being framed, and that he has a handle on the situation, but based on the number of near-death experiences Calvin just happens to survive whenever Bob appears, Calvin has no idea whom to trust.

The script for “Central Intelligence” was co-written by Ike Barinholtz (Seth Rogen’s idiot buddy in the “Neighbors” movies) and executive produced by Ed Helms. Is it wrong to think that both were hoping that Will Ferrell and Adam McKay would make this movie instead of Rawson Marshall Thurber (“Meet the Millers”)? As strange as this might sound from someone who has mostly put down Ferrell/McKay films, they would have been perfect for this. The poop jokes, for one, would be gone in an instant. (They might have been replaced with something more vulgar, but never mind that right now.) They definitely would have resolved the film in a more coherent manner, or at the very least made a joke about what bad shots these skilled assassins are. For crying out loud, two people skilled with weapons are shooting at each other at close range on a bridge, and neither of them hits his target. What?

Dwayne Johnson has always been a likable actor, even in bad films. This time, well, he’s still in a less-than-great film, but he delivers the performance of his life here, where kicking ass is a distant second to some fantastic deadpan comic timing. Hart, meanwhile, is the straight man, and that’s a great idea, but he is saddled with lines so awful that he had to be screaming for rewrites between cuts. Amy Ryan, though, is the glue that holds it all together as the unshakable Agent Harris. It takes an actor with serious dramatic chops to sell the silliest films, and Ryan does that in spades. There are also two big-time cameos that will not be spoiled here and fit their characters to a tee.

The main problem with “Central Intelligence” is that it doesn’t realize when the anti-bullying movie is being the bully. The script opens with that horrible scene of Robbie, yet they throw in a scene at the very end (one of the big-time cameos) where everyone laughs at the disabled person. That’s still bullying, people. There are smart jokes dispersed here and there, but “Central Intelligence” feels like it was written by Calvin and Robbie’s classmates two days after the first scene happened. Not cool.