Wouldn't it be easier and more effective, and additionally for free, to simply download the latest firmware for your model using the SamFirm pc app/ Samsung firmware website (there is plenty of them)? Then just run with admin priviliges latest Odin -> phone in Download mode -> flash BL, AP, CP, and CSC = problem solved in 99% cases. The phone is back to factory condition and you can play with Custom Roms and other modifications again. When you reinstall the latest / bl modem and a new rom, I recommend that you backup each system partition using TWRP or another tool (EFS, additionally Vendor, etc.). Then when the problem reappears, and it's almost certain if you like to play with phone modding, you just need to do a quick EFS / Vendor partition recovery etc. using e.g. TWRP and problem fixed in 3 minutes.
By the way, I would like to add that I had a problem with Imei on my G960F once. I don't remember exactly, but it was a period when I tested various custom roms. I remember that flashing a new complete stock firmware did not solve the problem and I almost gave up. Many days later I decided to install some ported rom, in my case it was probably some version of Alexis Rom OneUI port Android 9/10. Ofc its just an example based on my Samsung model, try to find similiar soft for your phone, it is important that this type of soft is a large package of software with the latest security patch implemented, modem, a lot of tweaks, modifications that when uploading the software outside of Android, strongly interfere with our partitions, which in my case happily restored the phone to normal somehow. After its installation, Imei magically was restored and the phone was fully functional again. I think it's worth a try for a price of your extra time only.
Good luck guys! Cheers