Princess Diana leaked information about the Prince of Wales to "an ally" in the press in order to "take on" her estranged husband, former News of the World reporter Clive Goodman told the phone hacking trial.
Goodman said Diana, who separated from her husband in 1992 after 11 years of marriage, passed him information relating to the royal household and staff in an envelope sent to his office in Wapping.
The now-defunct tabloid's former royal editor, of Addlestone in Surrey, said: "She was going through a very, very difficult time.
"She told me she wanted me to see the scale of her husband's staff and household, compared with others.
"She felt she was being swamped by people close to his household.
"She was looking for an ally to take him on - to show there were forces that would rage against him."
Goodman, 56, denies two counts of conspiracy to commit misconduct in a public office.
Diana and Charles divorced in 1996. She was killed in a car crash in Paris a year later.
Goodman said he used "Green Books" and internal telephone directories (ITDs), containing contact numbers for royal staff and senior members of the household, for stories.
Asked by his counsel David Spens QC how he received them, he recalled how one Green Book was given to him in 1992 by the Princess of Wales.
He said: "That arrived at my office in Wapping with my name on it.
"She (Princess Diana) had a (good) relationship with several journalists - Richard Kay at the Daily Mail, Martin Bashir of Panorama."
Asked by Mr Spens if Diana gave a reason for leaking the details, Goodman said the royal had been going through "a very tough time" - only to be cut off by judge Mr Justice Saunders and asked to stick to what she had told him.
Goodman said he did not pay for the books.
The former journalist said the information was largely available from various sources in the public domain - but that the books and ITDs collated it into easily readable documents.
Asked how he used information contained within them, Goodman recalled several stories from his personal collection which benefited from having royal contact numbers.
In one example, he recalled how he contacted a source the night of Diana's death, after the royal press office "was frankly useless".
Goodman said: "I explained what was going on in Paris -.that helped mobilise him.
"I called him at home at 1am on the Sunday - I had his number."
For another story immediately following Diana's death, Goodman said there was public upset at an apparent "lack of respect" being shown by senior members of the royal family in not flying a Buckingham Palace flag at half mast.
He told the Old Bailey: "People wanted the flag at half-mast but the palace got caught up in stuffy protocol because the Queen wasn't there.
"Then a flag shot up a pole for about 20 minutes and then came down again. The palace said it was a mistake but we had a tip-off that it was a palace fireman who was so enraged."
Goodman said he used the contacts book to track down the fireman, who confirmed the story off the record.
The witness said he also used the information database to stand up a story that an intruder dressed as Osama bin Laden gatecrashed Prince William's 21st birthday.
Earlier, Goodman said that competition at the NotW was so fierce that a colleague deliberately bungled an expose that an A-list model was moon-lighting as a high-class prostitute.
Goodman said its investigative reporter Mazher Mahmood was setting up a sting involving the £2,000-a-night model - who he declined to name in court - only for a jealous NotW colleague to call the model's agent and warn them.
Goodman described the "extreme" culture of trying to get results.
He said: "There were regular byline counts - who wasn't performing.
"It was extremely competitive - very fast, busy. It was competitive between everyone, with each other and other departments."
Goodman, who worked at the tabloid from 1986 until he was dismissed in 2007 following his conviction, described how a colleague blocked a scoop by investigative journalist Mr Mahmood - also known as "the fake sheikh".
He said: "Maz had a household name - a model. The suggestion was that she was working as an up-market prostitute in Europe.
"If Mazher had a huge hit in the paper, [the colleague] didn't. So he (the colleague) quietly phoned the model's people and the meeting never took place."
Goodman appeared in the dock for the first time today, having undergone heart and eye surgery during the course of the trial.
He told the court he left school at 18 and joined a local newspaper group in Kent before freelancing on Fleet Street.
He joined the Daily Mail in 1985 and moved to the News of the World a year later.
He said an agreement not to cover Princes William and Harry during their childhood following the death of their mother had a "depressive" impact on royal coverage.
Goodman said: "All we had left to write about was Camilla and Charles."
He was left feeling "where I would fit in" after his royal duties were shared with another reporter in 2005, as a consequence of having to pull out of a royal foreign visit due to family commitments, the witness said.
Goodman also described how his position as royal editor was "eroded" due to the influence of a colleague.
He said: "By the time I left (the NotW), I was behind Jamie Oliver's recipes (in the newspaper)."
The court has already heard how Brooks offered Goodman a backroom job in 2007 following his release from prison for his part in phone hacking.
But he declined the job offer and instead accepted a financial settlement from the company, Brooks told the court previously.
Goodman and six other defendants deny all charges. The trial continues.