InSim's MCI packets contain both Heading and Direction values. If you are within the limits of grip, both should be the same (+/- 2 degrees or so). But when you drift, they go further apart, as your heading doesn't change (heading = direction of travel), but your direction changes (direction = where you are pointing). Therefore, by getting the difference between those 2 values, you find how much you're drifting by. But in LFS, the heading and direction units are not degrees, so divide by 180 to get them into degrees.
Well, I suck at maths too so I can't help on whether the formula is correct, but two things I notice in your code. First of all it should be 182 and not 180. Second of all you're inadvertently casting the result of that sum into an integer, when it should really be a float, which in my experience can cause issues when values get rounded in a way you don't expect. Someone with more maths skill can comment on the basis of what you're doing, but from a C# perspective I would try:
Then it's impossible to show it in messages, because what I can see out of that code ((direction - heading) / 182 = angle) is 0, 180 and other random numbers
Doesn't work. I am trying to re-try it because I am a bit bored. Could anyone help me? because this code just gives 'random' stuff, not actual angle, I've looked in lapper, but couldn't really find it