Back to projects
Game DevComplete

Kenshi RNG Fix

A memory patching tool addressing Kenshi's fixed RNG seed issue, exploring game reverse engineering for bug fixing.

C++CMakeWin32 APIDLL Injection

Overview

Kenshi produces identical random results (NPC positions, loot drops, etc.) when starting new games with the same MOD list, due to a fixed RNG seed. This tool replaces the runtime random seed via DLL injection to achieve varied randomization per playthrough.

Implementation

Reference implementation based on RE_Kenshi FixRNG, hooks MSVCR100 runtime functions and in-game functions:

Hook TargetDescription
srandMSVCR100 seed replacement (timestamp or custom value)
randTLS switching: true random / deterministic mode
randomIntBuilding::selectParts +0x113, integer randomization
random (float)Building::selectParts +0x26D, float randomization
getFoliageRotationRVA 0x6CB8A0, foliage rotation randomization

All five hooks are implemented via reverse-engineered fixed offset addresses.

Verification

  • Log entry "Full RNG fix active (RE-style)" confirms all hooks active
  • Compare NPC positions across new games to verify randomization
  • Enable use_custom_seed to reproduce identical results with the same seed

Limitation

Hooks depend on specific game version memory offsets; game updates may require offset adjustments.