Custom UI Shader Stencil Problem [willing to pay for fix]

custom shader on UI element that needs stencil to work with UI MASK.

The problem is, if the stencil code is used, I can no longer set material colors for the subshader to work correctly, so the palette swap no longer works.

https://i.imgur.com/6esNou6.png (palette swap broken, but ui mask works)

https://i.imgur.com/ZYFFB2x.png (palette swap works, but ui mask broken)