We did this all the time to old vintage motorcycles back when I was fixing them up with a friend. Always in frame as well.
We'd use a lot of sand paper, steel wool, tooth brushes, q tips, and Berryman's b12 aerosol cans. Pressure wash the engine to get it as clean as possible and then lightly sand everything. Use whatever you can to clean away as much old paint as possible. If the paint is sticking tight, just scuff it as it's a great primer. Just go after the loose stuff and feather it down to blend in areas where the paint is missing. Spray it all down well with B12 as the stuff will get every trace of oil removed.
Then using aluminum foil, lot's of foil, you can mask off the engine and frame really well with foil. It clings and take shapes really well. Use tape where you need to. Mask it off well as it will show your craftsmanship when completed.
We used VHT engine paints. They are harder to find and run about $7-9 a can. It's a ceramic polymer, not an average paint. Practice first with the paint as it doesn't really like to get second coated. I think you had to wait a couple of days to do a second coat or it will blister right off. The great thing about the paint is that it lays super flat so it looks professional and the heat from the engine will actually bake the paint to the metal, much like powder coating does. There are instructions on the can as to how to heat cycle the engine a couple of times to get the paint to it's best level of protection.
I have an old Norton that I basically did an entire restoration using only VHT "roll cage and frame" paint and the engine paints. Came out looking great. I was able to spray the frame and left it out for a couple of days in the hot Texas sun, the side covers and tank were baked in the kitchen oven and have lasted chip free for 9 years. It becomes solvent resistant as well.
06 Paul Smart Sport Classic NFS ever.
08 S4RS Tricolore #081 NFS ever.
01 M600, aka, The Pink Monster
97 900SS CR
72 Norton Commando 750
03 KX60 with S4R rear shock,Honda CB350F, Hodaka Ace90, 3x Yam-YGS1, Yam-CS3 200, Vespa small frame, Gilera 106, Puch Sabre, Puch 50 Boy Racer, Ducati 250 bevel, Benelli 250, Benelli 360, Honda CB350T, and many more.