There's actually really no knowledge of cloth involved, it's just a bunch of spring constraints: https://github.com/mkhan45/clothsim
AFAIK more advanced realism-focused cloth sims are still mostly bundles of spring constraints, and most fabric behaviors are encoded as different spring tolerances, forces, and friction.
Cloth self-collision and friction seem to be a very difficult problem in which progress has been made recently: https://graphics.cs.utah.edu/research/projects/ogc/Offset_Ge...