Which model Mainship 34, the 34T or the Pilot 34? Which year? Is your Yanmar maybe one of the new electronically controlled engines?
I owned a 2006 34T years ago and currently own a 2003 P34, both with Yanmar 370s and I am quite sure that neither have/had the box you describe. I sounds like something added on for the newer electronic engine but i can't believe that Yanmar would just let a box dangle by its wires. So maybe it is a boat builder added device but I can't imagine what.
On further thought, since it is right below the alternator could the PO have added a high output alternator and this box is an external regulator like a Balmar? Do the wires run up to the alternator?
Finally, why did the wires get wet? Your raw water pump seal may be leaking or maybe a hose clamp needs tightening.
David