I think you have wrong approach toward the situation .Seems like you want to stop hurting yourself ,just because you break a rule and not just because you want to heal or help yoursels or appears like this to me .Probbaly you are pretty comfortable with that if we do not count the guilt for breaking the rule in your chosen path .
You need to understand that we heal and help ourselves once we realize that triggers this behaviour and once we no longer need it in our life .
In most cases such behaviour is triggered by selfheatred ,not allowing to let go of past pain and mistakes ,or there is no other way we can ventilate and express pain and anger .After time it becomes a habit in similar way as smocking and drinking .Once you get used to it you always will have the urges ,but once you have healed you should have a will to not act on this urge and just refuse to follow it .
I will recomend to start working on your shadow self and the darker aspects of your personality ,by getting to realize why they have become such a problem in first place .They tell us that something within us i pretty off and not balanced and that unbalance also can often lead us to more abusive relationships and more violence it is like closed circle .
There is special technique or ritual in ceremonial magic which involves giving an identity and face to your bad habits or parts of the self you do not like ,visualizing them ,cutting the cords which connect us to it and then banishing it .Unfortunately i do not know how to translate the name of this technique but it can be found in the book Modern Magick by Donald Michael Kraig (volume 1).However keep in mind by refusing to deal with that aspect and heal it it will probbaly return again ,for by you not realizing things for yourself and your mistakes will create the need of its return .After all feeling unhappy tells us that we have put ourselves in situation which is unhealthy for us and that we need to react upon it without delay .
In short there is not miraculous cure as long as we do not face ourselves and deal with this shadow aspects of ours .
If you like to use spells there are selfhealing spells and also spells for banishing old habits ,which are harmful for us .
Also keep in mind by stopping doing something which you love ,because you can not stop doing something which you hate ,will make you very miserable and i think that will worsen even more your situatin for you will loose belive in your ability to deal with yourself .
You need to have believe in your own ability to heal and your inner power or all will be useless no matter if you use ceremony ,prayer ,chant ,spell or anything else magicaly related .You need to learn to love yourself no matter how many stupid mistakes you did and in how many things you failed .Remember by doing mistakes we learn what is right for us .
To all folks here please inform us how this technique is named in english and post it underneath .
For you i will try to dig out spell in my books for it i remember i saw few and i will send it to you via mail ,but please take in consideration working on your shadow self aside .
In case that things do not improve no matter what you have tried you may consider to visit hypnotherapist who will regress you in the time and space in which original wounding occured which then triggered the selfharming behaviour .
Feel free to message me and ask for help anytime or if you need someone to talk with .