You're now inside the game's final dungeon, and I'd like to personally commend you for having the patience to make it this far. This game goes quite far in rewarding the most patient of players and it certainly shows. Anyway, get a move on and defeat the infected YoRHa units when you see them. There is also a locked chest that contains an archive (Project Gestalt Report 9). Waiting beyond the doorway at the end is a group of 2B clones, and it is here that 9S officially goes insane.
Kill all of them just like he wanted and approach one of the bodies to trigger a scene. Control will switch to A2 soon after. Enter the tower and continue passed 9S's trail to reach a library at the end. Here, you have to look for shiny spots on the shelves and examine them.
Complete the hacking game that follows to access the archive entry within and add it to your collection. Also on the second floor are two side rooms that contain loot. Upon checking the final sparkle, A2 will be attacked by Ko-Shi and control will once again shift to 9S.
Perform a self-hack to elimate the virus from his new arm, and open the locked chest in the corner for an archive entry (Project Gestalt Report 11). Moving forward, defeat all the enemies at the next open area to be rewarded with the YoRHa Disposal archive entry.
Further ahead is a group of hostile flight units you must destroy to progress. 9S will take one of these for himself. Back with A2, you will be fighting Ko-Shi. Damage it enough so it goes away then leave the library. At the open area is a large item box with a Powerup Part L. Touch the switch and you'll end up inside a hacking space. Waiting at the end is an endless horde of those machine women. Keep destroying them until your pod offers a strategy, which will be explained further after he essentially calls A2 stupid.
The idea is to not destroy any enemies so they can multiply and ultimately destroy themselves. At this point, all you need to do is watch the women kill each other, then move in to finish off the one that remains. From here, the game becomes combat-focused, constantly alternating between A2 and 9S as they battle the seemingly immortal Ko-Shi and Ro-Shi.
This all culminates to one final encounter with a fused version of Ko-Shi and Ro-Shi, where your two characters get to team up briefly. Notice that the character switching continues even here. Finish the machine so your two characters can turn on each other.
Here, you will be given the option to play as either character, and whoever you choose will lead to a different ending. Play as A2 to get Ending C or play as 9S then leave with the machines to get Ending D. By the way if you can defeat A2 solely through hacking, the 4th hacking game will turn into a really cool easter egg when you get close to the end. So I strongly suggest trying if you excel at these bullet-hell segments. And finally, the true ending (Ending E) is unlocked after having seen all the other main endings (A, B, C and D), then saying "yes" to both of Pod 153's queries during the credits.
It is after seeing the true ending that the game presents you with a final request, which I of course acquiesced to. Whether or not you do the same is your choice. But after having such a beautiful experience with this game, it was an easy decision for me.