You present a lot of issues. I am not sure what you are asking. But, if I read between the lines, it seems like you are asking how to get back on top of your academics and in better control of your life. You need some healthy support. That is not to say that you need to cut ties completely from your friends, but your choices when you are with certain friends are leading you down roads that impact your life negatively versus postivitely.
No doubt your school has a student counseling center which might be a great place to start. Tell a counselor the same story you told here and work through a step by step process of getting in better control of your life in a positive direction.