Skip to content

Drop asm usages in game_sa#4793

Closed
sbx320 wants to merge 1165 commits intorelease/1.6.0from
no-asm-for-you
Closed

Drop asm usages in game_sa#4793
sbx320 wants to merge 1165 commits intorelease/1.6.0from
no-asm-for-you

Conversation

@sbx320
Copy link
Copy Markdown
Member

@sbx320 sbx320 commented Apr 12, 2026

Some initial work on automatically rewriting game_sa's inline asm to proper C++ calls via a custom clang-tidy plugin.

See https://github.com/sbx320/mtaasmrewriter for source

Rough approach is:

  • Find all __asm statements
  • Collect all push instructions (arguments)
  • Look for a mov ecx, [something] instruction (__thiscall indicator)
  • Look for a mov [something], [something] instruction (return value)

Then rewrite the statement to a function type declaration and a function call.

Current issues:

  • Does not support other asm instructions (e.g. lea is used in some places)
  • Does not properly escape prefix-less hexadecimal numbers (e.g. push 0B73710h is mapped to a function argument 0B73710h which is a base-2 number
  • If multiple function calls are used, the type declaration collides due to duplicate names
  • clang formatting is disabled
  • needs to be on master, not on 1.6.0

Dutchman101 and others added 30 commits February 14, 2026 07:03
Build Tools 2022: 17.14.36930.0
Build Tools 2026: 18.3.11505.172

This is an automated commit to keep track of toolchain changes on the build server.
It applies to every MTA build after this commit until further notice. [skip ci]
… IPL sector)

- Attach pointer lifetime to actual entity lifetime, preventing leaked tracking refs from building up across IPL stream cycles.
…o client; crash when the bitstream runs out of data mid-deserialization and a failed read leaves m_iType as uninitialized stack garbage)
…rence from recording overlays and such (Avoids crash where possible)
Build Tools 2022: 17.14.36930.0
Build Tools 2026: 18.3.11505.172

This is an automated commit to keep track of toolchain changes on the build server.
It applies to every MTA build after this commit until further notice. [skip ci]
…rashes.

Scenario appears to be related to engineRequestModel vehicles.
… 0x003C91CC, MTA's #1 crash, earlier.

For details of "earlier", see the closing comment at #3840 (comment) or CrashFix_Misc38

Note: this was the next problem after this month's similar fix from 6a3b3af. It's not ruled out that there will be a couple follow ups, depending on crash trends of where out of VMEM-users crash on next.
Dutchman101 and others added 23 commits April 7, 2026 22:31
#### Summary
Fixes #4743

#### Motivation
A very old MTA bug that can cause FPS instability when a player is
affected by it.
…gressions

- SetTextureDictionaryID: transfer entity refs on the field-only path for
  unloaded models without geom, preventing TXD ref count underflow
- Script TXDs: pin the parent TXD slot while script TXD children exist,
  preventing premature unload of the parent and resulting white textures
- RebindLoadedModelToCurrentTxd: apply texture swaps immediately instead
  of deferring via QueuePendingReplacement, closing a frame gap where
  models render with default textures
- TryApplyPendingReplacements: replace silent retry-count drop with a
  slow 5-second retry interval so stuck entries are retried indefinitely
- CleanupReplacementsInTxdSlot: release parent pin before the tracking
  map check so it runs even when RemoveTxdFromReplacementTracking already
  cleard the entry
Build Tools 2022: 17.14.37111.16
Build Tools 2026: 18.4.11626.88

This is an automated commit to keep track of toolchain changes on the build server.
It applies to every MTA build after this commit until further notice. [skip ci]
Build Tools 2022: 17.14.37111.16
Build Tools 2026: 18.4.11626.88

This is an automated commit to keep track of toolchain changes on the build server.
It applies to every MTA build after this commit until further notice. [skip ci]
…s for this crash offset, but they didn't fix all cases/paths.
Build Tools 2022: 17.14.37111.16
Build Tools 2026: 18.4.11626.88

This is an automated commit to keep track of toolchain changes on the build server.
It applies to every MTA build after this commit until further notice. [skip ci]
Build Tools 2022: 17.14.37111.16
Build Tools 2026: 18.4.11626.88

This is an automated commit to keep track of toolchain changes on the build server.
It applies to every MTA build after this commit until further notice. [skip ci]
#### Summary

Add a standalone Google Test project (`Tests_Client`) and GitHub Actions
CI workflow that builds and runs 213 automated tests without requiring
GTA:SA binaries or a running game client.

**Test infrastructure:**
- Vendored Google Test v1.17.0 (`vendor/googletest/`) — sources only, no
prebuilt binaries
- New premake5 project `Tests_Client` under `Tests/client/` producing
`Tests_Client_d.exe`
- Implementation shim (`Tests/client/SharedUtil_Impl.cpp`) that includes
SharedUtil implementations without pulling in full client dependencies
- Links vendor libraries `cryptopp`, `blowfish_bcrypt`, and `zlib` for
hash/crypto coverage

**CI pipeline** (`.github/workflows/tests.yml`):
- Triggers on pushes to `master`/`tests` and all PRs targeting `master`
- Generates premake projects, builds with MSBuild (Debug/Win32), runs
tests, uploads JUnit XML results as artifacts

**213 tests across 11 files:**

| File | Tests | What's covered |
|------|-------|----------------|
| `CVector_Tests.cpp` | 22 | Constructors, length, normalize, dot/cross
product, arithmetic, validity |
| `CVector2D_Tests.cpp` | 20 | Constructors (from CVector/CVector4D),
length, normalize, dot product, all operators |
| `CVector4D_Tests.cpp` | 10 | Constructors, 4D length/normalize/dot,
arithmetic |
| `CMatrix_Tests.cpp` | 25 | Identity, rotation/position/scale get/set,
inverse, ortho-normalize, transform, buffer layout |
| `CMatrix4_Tests.cpp` | 11 | Identity, RotX/Y/Z, translate, multiply
(vector & matrix), subscript |
| `CRect_Tests.cpp` | 13 | Constructors, stretch-to-point, restrict,
circle intersection, reset, fix-top-left |
| `SharedUtil_Tests.cpp` | 20 | SString format/split/join/replace, path
join, dynamic cast, wildcard matching, container erase patterns, color
code removal |
| `SharedUtilMath_Tests.cpp` | 28 | Square, degrees-to-radians,
should-use-int, float comparison helpers, significant bits |
| `CFastList_Tests.cpp` | 17 | Push/pop, contains, remove, iteration,
suspended modification, revision tracking |
| `CDuplicateLineFilter_Tests.cpp` | 6 | Unique/duplicate line
detection, flush, multi-line patterns |
| `SharedUtilHash_Tests.cpp` | 22 | Hex round-trip, TEA encode/decode,
HMAC (MD5/SHA1/SHA224/SHA256/SHA384/SHA512), RSA keygen +
encrypt/decrypt (1024/2048-bit), RSA known-ciphertext decryption
(1024/2048/4096-bit), AES-128-CTR round-trip, file-based
MD5/SHA1/SHA224/SHA256/SHA384/SHA512 |

All test expectations were ported from the existing
`SharedUtil.Tests.hpp` internal test framework and verified to produce
identical results.

**Implementation notes:**
- `SString(const char*)` is ambiguous with the printf-style
`SString(const char*, ...)` overload in MSVC. Tests use `SStringX` for
plain strings and a `MakeRawString()` helper (constructs via
`std::string`) for binary data with explicit lengths.
- All tested code comes from `Shared/sdk/` headers - no Game SA symbols
are referenced, so no GTA:SA installation is needed.

#### Motivation

MTA has no automated test suite that runs on CI. The existing tests in
`SharedUtil.Tests.hpp` only run inside the game client process, meaning
regressions can only be caught by manually launching the game. This
makes it easy for changes to shared utility code (math, strings, crypto,
collections) to silently break.

This PR establishes the foundation for CI-gated testing. The immediate
value is regression coverage for 213 behaviors across the shared utility
layer. The longer-term goal is to expand coverage into client-specific
logic by mocking the Game SDK interfaces.

**Next phase - Game SDK mocking:**

The current project is limited to `Shared/sdk/` code because anything
touching `Client/game_sa/` requires a running GTA:SA process with hooked
game memory. The next step is to introduce mock/stub implementations of
the Game SDK (`Client/sdk/game/`) interfaces, which would unlock testing
for:

- **CClientEntity hierarchy** - entity creation, parent/child
attachment, element tree traversal, spatial DB updates
- **Lua argument parsing** - `CLuaArguments` round-trip for all types,
argument validation for every exported function
- **Networking / packet handlers** - bitstream serialize/deserialize
round-trips, fuzz-testing packet parsing
- **Resource system** -start/stop lifecycle, file checksum validation,
download retry logic
- **Collision shapes** -hit-test all shape types (sphere, cube, polygon,
tube), edge-case `IsEntityInside` checks
- **Camera system** - mode transitions, interpolation correctness
- **Vehicle handling** - `CHandlingEntry` property round-trips, handling
mod delta computation
- **RTree spatial index** - already header-only (no mock needed), bulk
insert/query/remove verification

The approach: create a `Tests_ClientMocked` project with lightweight
`CGameSA` stubs (Google Mock or hand-written), linking against mocks
instead of the real `game_sa` DLL.

#### Test plan

1. Build locally: run `win-create-projects.bat`, then build
`Tests_Client.vcxproj` (Debug/Win32)
2. Run `Bin\tests\Tests_Client_d.exe --gtest_brief=1` - all 213 tests
pass
3. CI workflow validates the same on `windows-latest` with every push/PR
4. Hash test expectations were cross-checked against the original
`SharedUtil.Tests.hpp` values
5. For future changes to any tested code: run `Tests_Client_d.exe` and
confirm no regressions. The CI workflow will also catch failures
automatically on PRs.

#### Checklist

* [x] Your code should follow the [coding
guidelines](https://wiki.multitheftauto.com/index.php?title=Coding_guidelines).
* [x] Smaller pull requests are easier to review. If your pull request
is beefy, your pull request should be reviewable commit-by-commit.

---------

Co-authored-by: FileEX <kongali@interia.pl>
#### Motivation
<!-- Why are you making this change? Which GitHub issue does this
resolve, if any? Any additional context? -->
Me dislike typos (and awkward grammar)

#### Checklist

* [x] Me fix typos (and awkward grammar)

Co-authored-by: FileEX <kongali@interia.pl>
Make guiSetInputEnabled show cursor when set to true.
- Fixes #4775 

Co-authored-by: FileEX <kongali@interia.pl>
Build Tools 2022: 17.14.37111.16
Build Tools 2026: 18.4.11626.88

This is an automated commit to keep track of toolchain changes on the build server.
It applies to every MTA build after this commit until further notice. [skip ci]
@sbx320
Copy link
Copy Markdown
Member Author

sbx320 commented Apr 12, 2026

Turns out github apparently broke branch retargeting... #4794 for doing things to master

@sbx320 sbx320 closed this Apr 12, 2026
@MTABot
Copy link
Copy Markdown
Collaborator

MTABot commented Apr 12, 2026

(Branch retargeting didn't work because 1.6.0 has lots of cherry-picks that don't exist on master)

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.