Waalykum assalam,
First of all, my dear brother, we must emphasize the principle of treating any problem, or the approach to changing our general behavior, which is that behavior is a translation of feelings generated from thoughts. A thought plants a feeling that prompts the body to translate it into behavior. For example, criminal thoughts cultivate constricting feelings that lead to hostile behavior, whereas compassionate thoughts cultivate friendly feelings and lead to positive emotional behavior.
Applying this issue to an example:
A man's decision to help the poor as a behavior is preceded by feelings of mercy, preceded by thoughts about the importance of this act.
As such it has been said: “Watch your thoughts because they will become actions, and watch your actions because they will become habits, and watch your habits because they will change your destiny.” The Almighty has similarly said in the Holy Qur'an: (Say, “Everyone acts according to his own style.”)
How to change behavior systematically:
Changing one's behavior is the result of changing one's feelings and changing one's thoughts, as such, systematically, if I want to change my behavior, I must work on a theoretical aspect and a practical one:
The Theoretical Aspect:
It contains the intellectual foundation for the desired result and the issue at hand (i.e. addiction to watching pornography and masturbation). Perhaps, my brother, you have information about the ugliness of this matter, the seriousness of committing it, and the punishment that one who commits it deserves, but it remains useful, after what was presented previously, to collect all the theoretical information about this act because it enhances the intellectual aspect that will help you to change your feelings and thus reduce the behavior. As such my dear brother, do not be satisfied with what you have read with one or two narrations denouncing this act, but rather strive to read more, because reading here is not for the sake of knowledge but for the sake of theoretical mobilization, so there is no ceiling for it even if it becomes repetitive.
In the intellectual field as well, my brother, you are advised to learn about the implications and results of this habit. Do not limit yourself to gathering thoughts about it, but rather think about all the matters related to it. How many bad moods have befallen you that have led you to regress on many levels? Gather these thoughts and accompany them to form a complete scientific file on this matter. The matter, as I mentioned, is not for knowledge, but for mobilization for self-improvement, so do not let yourself think that you are aware of everything [such that looking further is of no benefit], as perhaps a certain expression in a narration will have an impact in this specific time and circumstance, as the spiritual world is hidden from us and we have been commanded to always gather for it.
Summary of the Theoretical Aspect:
So the summary of what is intended first from the theoretical aspect is to establish and build a scientific foundation on the issue: the positives of abandoning it and the negatives of the committing the act, and the religious and psychological scientific sources in this regard are plentiful, and you are among the people of knowledge and experience...
The Practical Aspect:
1- Occupy your spare time.
2- Stay away from places that you know will remind you and help you fall into committing this sin.
3- Reduce foods that stimulate sexual drive (i.e. avocado fish, nuts, honey, etc.).
4- Occupy the body with activities that drain its energy, such as sports and swimming.
5- If you can, get rid of everything that reminds you of that matter (change your phone or certain items to create a new beginning for yourself).
Note : I did not address, my dear brother, the other matters that you mentioned that you were aware of or had done, such as fasting, vows, the Qur’an, etc.
A Different Approach
If we want to move away from the language of science and methods, and open the way to words of a different kind, then I say to you, my dear brother:
Declare defeat and brokenness. Say to God Almighty: “I am pure inability and pure weakness.” Tell Him, “I am the sinner if you do not protect me, and I am the lost one if you do not guide me.”
Perhaps we may rely on ourselves in a manner which is, in reality, a form of hidden polytheism without knowing it, and God wants to lead us to the truth about trusting in Him [al-tawakkul] and introduce us to a drop from the sea of monotheism that decrees that everything is in His Hand.
Maybe all paths are closed to you, so that you know with certainty that you can do nothing in this matter alone, so either you turn to Him with all your might to declare defeat and declare your need for His Security after you have despaired from yourself and others, or you make Him, God forbid, the least important of those looking at you and become arrogant with yourself that you are fine and there is no failure in your affairs.
My dear brother, who among us does not make mistakes?
Who among us does not become weak?
The unfortunate thing is that we deceived ourselves with God's Mercy and Protection, knowing that He would not expose us and would not be quick to punish us for our actions.
We are sorry, dear brother, that this sin on our part turns into a reason for our love, so we recognize beauty from the ugliness of these sins. It is sad for us, dear brother, that our good deeds may in fact be sins that were replaced.
One of the beauties of Almighty Lord is that He does not remind us of anything we have done in the past if we want to change. He does not accept that we turn to our past (sins committed) as long as we have changed.
He does not reproach,
He leaves no trace of our sins,
He forgives and does not care,
Rather, my dear brother He commanded us not to consider His Pardon too great if He pardons us, for God Almighty is The Oft-Forgiving, meaning: He goes to extremes in forgiving.
It is as if He is saying to you, your file is with Me, do not worry about it, just say that you want to change… and if this is your intention, then every person shall receive based on what they intended.
We do not disobey God out of defiance or arrogance, and God knows that this is our state.
Rather, we disobey Him out of weakness and are tempted by His Concealment and Love. Otherwise, if we knew that He would be quick to punish us, no one would hasten to disobey Him.
How shameful that we treat this beauty with such exploitation!
We take advantage of His Beauty, my dear brother. Unfortunately, this is our condition, and He knows our weakness. But few of us declare our surrender and defeat and turn in this state to God Almighty and say to Him: “My God, this is the position of the one who sought refuge in You and turned to You. This is the position of the one who was trampled by the hands of sins and led by the blame of mistakes and who was overtaken by Satan".
Confession, confession. Whenever you sin, do not allow yourself to belittle the sin. Confess, say, “My God, I am a sinner, and my soul is deceiving me and wants to belittle its sin, so help me”.
Do not abandon this matter. If your soul tells you to despair from the Mercy of God Almighty, just remember that you have two options: either to despair and remain as you are and continue with your actions, or to accept repentance, which you may doubt that you may violate at a later time. God is not satisfied with the first, and He requires the second from you.
Limit yourself to what you want to repent from, and do not worry yourself that you may disobey God Almighty again after that, for repentance in the face of despair is salvation.
Perhaps death will overtake you during your repentance before your transgression again, so you will be saved, and perhaps death will overtake you before your repentance, while you procrastinated, so you will perish.
Whoever is upset about his sins, and seeks all these steps to change that which you mentioned in your question, then this is evidence of his goodness and righteousness, so do not beat yourself up too much, and beware in this state, my dear brother, of falling short in covering and forgiving people’s sins, and beware, then dear brother, of looking at the sinner among them, no matter how much you think that you are better than him. Increase your humility, mercy, kindness, and protection for God’s creation, and help them as much as you can. Let that be your way of asking for mercy, protection, and help from God Almighty. You have disobeyed Him with your actions, so ask for forgiveness with your actions, not just with your tongue, and pray with a sincere prayer for one of your brothers to seek protection and forgiveness of sins.
Keep that brother before the eyes of your heart, and ask God Almighty with a sincere heart to forgive him, protect him, and grant him success. Far be it from the Generous One to always accept your prayers for your brother and withhold His Goodness from you, for God’s Abundance is ever-present. You only have to open the gates of your heart through your kindness to His creation...
May God protect you, watch over you, and guide you. May He support you and forgive us and you.