Skip to content

Add node.codepage option for string conversion between JS and server - #9

Open
noexabwuy wants to merge 2 commits into
AmyrAhmady:masterfrom
noexabwuy:feature/node-codepage
Open

noexabwuy wants to merge 2 commits into
AmyrAhmady:masterfrom
noexabwuy:feature/node-codepage

Conversation

@noexabwuy

@noexabwuy noexabwuy commented Sep 20, 2026 •

Copy link
Copy Markdown

Problem

The server core and the SA-MP client use single-byte Windows codepages (for example windows-1251), while V8 uses Unicode. omp-node passes strings as raw UTF-8, so all non-ASCII text is broken in both directions:
изображение

  • JS to server: SafeToString sends UTF-8, and the client shows mojibake ("Привет" = Привет). Affects sendClientMessage, dialogs, text draws, etc.
  • server to JS: NewFromUtf8 turns codepage bytes into U+FFFD before any script runs. Affects playerText, playerCommandText, dialog input, Player.GetName, etc.

There is no workaround in JS: V8 can't emit a single byte ≥ 0x80, and U+FFFD can't be recovered.

Solution

New option node.codepage (default utf-8, i.e. no conversion):

"node": { "resources": ["resources"], "codepage": "windows-1251" }
  • Values: utf-8, windows-1250 … windows-1258 (case-insensitive, cp1251 / 1251 also accepted). An unknown value logs a warning and leaves the conversion off.
  • Characters missing from the codepage (e.g. emoji) become ?.
  • console.log is converted too, so the server log stays in one encoding.
  • The conversion is table-driven (tables are generated by tools/generate_codepages.js) and uses no platform APIs, so it behaves the same on every OS. Multi-byte codepages are out of scope.
  • Only game strings are converted; paths, resource names, config values and API names stay UTF-8.

Testing

  • CI builds: Windows x64/x86, Linux x64/x86
  • Manual test with "codepage": "windows-1251": Cyrillic dialogs, player input, console.log
изображение

@noexabwuy noexabwuy changed the title Feature/node codepage Add node.codepage option for string conversion between JS and server Sep 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant