Depends how you do it. It is not "illegal" in the traditional sense. Typically what happens is the company will sue you claiming lost revenue through ruining other players enjoyment. They can also claim you modified their propietary code for profit which is illegal.
So there is a potential risk, but if you are smart you can get around it. Make sure your name isn't attached to anywhere they can find you, and ensure you comply with any cease & desist orders. Do this and you should be fine.