You need to hire and attorney. Its a longshot, but the fact that the little girl has known you as daddy for almost all her life gives you a chance at custody. That you aren't the biological father will work against you, but not too much if he has nothing to do with the child.
If you can show the home situation is detrimental to the girl, you stand a chance.
If you have some kind of legal agreement in place, if you adopted her or have parental responsibility, you may have a chance, if not, chances are pretty slim. You may be awarded access to her, but actual custody is unlikely, unless her mother was deemed unfit and you offered to have her. But even then it would probably only be short term (instead of fostering) I have known so many men be in the same position as you, and it is horrible, but I havent met one who is actually allowed to raise the child themselves. I hope you are that one. Good luck.
I agree with scottgem. you need to get an attorney and see where you stand. you may not be the biological father but the psychological father, that is she knows youre her daddy. does get recognised in court. if the welfare of the child is art risk. once you file with family court. they can send a soical worker out to investigate the home and living conditions. that would have a greater impact on custody if you choose to.