topeterk / HitCounterManager

Free Hit Counter / Death Counter that is running in the background, so you can focus on your stream. No need to keep any windows open for a window capture any more. Initially designed for Dark Souls and similar games but supports any game.
MIT License
86 stars 19 forks source link

Gui Overlays not saved in UTF-8 #38

Open rafajafar opened 1 week ago

rafajafar commented 1 week ago

Describe the bug I just spent an absurd amount of time debugging this. For some reason, when I made a custom CSS for the overlay, no matter what I did, it would come back as chinese characters when viewed in the browser (obs and locally via python server). I could absolutely NOT figure it out. There were no non-UTF8 characters in the file. Going over the code it looked fine and should default to UTF8.

Then I figured it out.

The root files of HitCounterGui.html and javascript.js are both in UTF16 LE BOM encoding. This means the browser is expecting all files to be in that same encoding. Almost no developers will use that encoding by default, especially if coding in english like most are.

Now it's not JUST that. For some reason when I keep the MIT notice on the top of the page, it also came back with encoding issues, despite there being no characters that I could find. I have no idea what's going on with THAT, but if I remove the MIT license (sorry for personal use only though) and I change the encoding on all files to UTF8, my custom CSS is correctly used at UTF8 and doesn't get read as chinese characters on import.

Fix this how you see fit, but it's definitely taken two hours of my life I'll never get back to figure this out.

topeterk commented 1 week ago

As of today there was no other negative feedback about that.

Originally this was by design as this format tends to be more efficient even when file size might be a little more, so I have used that format. https://github.com/topeterk/HitCounterManager/blob/master/.gitattributes Afaik it also was recommended since then but it seems to have shifted back to UTF-8 for compatibility reasons: https://learn.microsoft.com/en-us/windows/win32/intl/using-byte-order-marks?redirectedfrom=MSDN

Does your file have any format specified, e.g. beginning with bytes "EF BB BF" for UTF8 encoding? Then I guess the browser tries to guess the encoding and looks like it chose the wrong one (like assuming the 3rd file from same origin keeps using same format as the other two files)? Afaik there is no rule in any browser that all files must follow the same enconding as most websites are fetching sources from multiple entities that all have different file encodings.

I am not sure yet but yes, I think I will change it back to UTF-8.