Hi there. I was in very similar situation as you, maybe my story will help you to find a way to cope with this and get out of this mess.
A small retail company (had nothing to do with software development) I worked for over 3 years decided to screw me over grandiosely. Without going into much detail, the company decided to tie me up as an employee for decades and to claim the ownership of a software that I had been working on since my college days (aka my big project), contrary to our initial agreement (between the company and I) that I would keep the full rights to my software while the company would be granted perpetual non-exclusive license to use it for their operations. To make things worse, they didn’t even bother to tell me this face to face, they just conveniently added a clause to a renewing contract that they hired an attorney to draft out a special version of the contract specifically for me - I found out by a chance reading through the small print.
When I found out what was going on I was hurt, scared, it was extremely personal and I had no f…ing clue what to do - I was stuck in limbo trying to survive this mentally and physically. The only way out of this I could think of was to isolate my spiking emotions as much as I could and evaluate the situation objectively, rationally, take the analytical approach, the same way I approached things in software development. The way I saw it was that we, software engineers, solve problems every day - problem solving is the very definition of computer science, and this was nothing more than one big f…ing problem, wasn’t it?
The intuitive response was to do whatever it takes to dodge the bullet, buy myself some time, learn the legal definitions and their implications and come up with a plan to get out of this mess and execute my bloody revenge.
The first thing I did was to tell them up front that I was going to discuss the contract they gave me with an employment and IP attorneys, that I would give the company my official response as soon as I have the legal advice available. I did this via email and printed letter to have valid records of the communication. I can’t know if this applies to your situation, but remember that you are not obligated to sign anything, your employer cannot legally force you no matter how hard they try - thus do not sign anything without having full legal understanding of what it is that you are about to sign. Keep in mind that legal understanding can be, and often is, in order of magnitude different than common sense.
At this point I no longer though of myself as part of the company, I was a lone warrior on my own, I didn’t talk to anyone, just showed up, plugged in my headphones, did some work and left around the clock. Please understand that at this point no one in the company is your friend, doesn’t matter if the they hang out with you after work and you play games with them, everyone is potential threat/leak to your plans and well being. I can’t stress this enough, do not share what you are doing with anyone at work, period.
The next step was to find an attorney, this was actually much easier than I thought. I googled “Intellectual Property Rights Attorneys” in my area and read reviews to find I though was a good match. Once I had a list I made phone calls and asked for free consultations - most lawyers do that, the ones that don’t are not worth it. Once I found one and met with him, I explained my situation, expressed my concerns and gave him all relevant documents. The attorney read through the contract from the company and said that it was a total joke, that the company was greedy desperate and is trying to get a piece of something they have no clue about. He advised me to quit, give them one copy of the software on a CD without any documentation and leave. He also clarified that unless patents were involved, the copyright itself is virtually unenforceable for source code, given that you can change the structure and names used in your code beyond recognition without changing the functionality. Or you can rewrite it from scratch. Again, I can’t know if this applies to your mess, but remember that seeking an attorney doesn’t imply suing or going to court, or anything bad, you are only seeking legal advice/help - you have constitutional rights to do so.
The attorney gave me huge relief, that was a critical moment because I had firm knowledge and understanding of legalities of the situation (in software dev analogy I learned the documentation and knew the default values for variables). I took this as an opportunity and decided to rewrite my software from scratch in different language (C# opposed to PHP). That was something I contemplated upon doing for long time anyways as the the PHP was not sophisticated enough for the framework I created. I got busy looking for jobs. While at it I ran across a company that very much liked what I had from business perspective, and offered me investments/partnership instead of employment! I wrote my one sentence resignation letter, burned the source code on a CD and called for a meeting at the old company to discuss the “contract”. I gave them the resignation letter with the CD and walked out - their faces went snow white and with an expression of total terror, I enjoyed it very much I think this should apply to your situation, if you can quit, quit now, find alternatives, even if it means moving in with your parents, and find a company worthy your capabilities and intellect. In other words f…k them, f…k them hard, the sooner the better, it will help you to move on.
After all this happened, the old company quickly realized what sh.t they got into and started contacting me, trying “to find a solution” to their problem. At first they offered double salary and all rights to software, I politely refused without saying why. I let them struggle for a few weeks and then called them back with a proposal. I proposed that they formally acknowledge me as the only owner/author of the software (with an IP contract) and that they would become a client of my newly formed business where any further development would be on project-by-project basis and regular maintenance for monthly fee. They gladly accepted my proposal, they are now paying me $5K a month for automated database backup and cron-job self cleaning scripts (aka maintenance), and they already asked for new modules for their old PHP platform for additional $15K. Again this may not apply to you, but what I want you to take from this is that whatever you are going through does not mean it’s the end of the world, it can in fact be the exact opposite and you will be the winner after all
Just remember that the most important thing of all is to take the analytical, logical, approach, control your emotions, focus on taking yourself out of the equation, find legal help if necessary, and take from this the good things that you have. Once you are out of that toxic corrupted environment you will get fresh perspective on life and you will return to normal or better. New opportunities will arise, then you will look back at this tough time as a learning experience and laugh at the idiots that tried to screw you over.
I wish you the best of luck, let me know if you have any questions or if I could be any help.