Uncertain Sky - how it works (EN)
=================================

WHAT IT IS
A small Win32 helper for Planescape: Torment: Enhanced Edition (x64) for game ver 3.2.2,
that unlocks hidden weather, makes rain, snow, fog, lightning actually 
work in the game. 

Additionally, It enables with flag 13 in animation (.are file), use of WBM files 
(flag 13 must be set, and "is shown" in animation section).

It never modifies Torment.exe on disk - everything happens in the game's memory!

You can use the program in two ways: force the weather using the control panel, 
or specify the probability of each weather condition in the .are file.

Debug console: C:SetWeather(1) - rain, 2 - snow, 3-fog, 0 - off.

STARTUP
0. Copy the exe file and “override” folder to the game folder  and run Uncertain_Sky.exe.
1. "Launch game" starts Torment.exe suspended, patches it, then resumes it.
   "Attach" does the same to an already running game.
2. The helper reads the game's .text section and finds each patch location by
   byte signatures (with wildcards). A signature must match exactly once,
   otherwise it counts as not found or ambiguous.
3. Patches are grouped (noop, render, fog, fastroll). A group is applied
   atomically: if any site fails, the whole group is skipped.
   - "noop" is required. If it fails, nothing is written and a launched game is closed.
   - The other groups are optional and only logged as skipped.
4. It then locates the game context (CChitin, CGame, the current area's ARE
   header, the weather object) through further signatures.
5. With certain settings, you don't need to restart the game for the changes to take effect.

LIVE LOOP (every 100 ms)
- Probabilities: for rain, snow, fog and lightning choose Auto (value from the
  area's ARE file), Disabled (0%) or Force (your value). The result is written
  into the area header.
- Immediate roll: the engine rolls weather only once per game hour (about 5 real
  minutes). When you force a probability, or enter a new area with a forced
  value, the helper triggers one roll right away. It briefly sets the engine's
  hour divisor to 1 and restores 4500 after the engine consumes the tick.
- Fog fix: PST has no fog-type table, so fog would be black and invisible. The
  helper then writes contrast 85, your colour and alpha 0.85. It also fills the
  density grid itself, either as drifting patches (smooth noise; density,
  coverage and patch size controls) or as uniform fog.
- Time-skip repair (Ctrl+T): a time skip can jump over the exact tick of the
  hourly roll. The helper detects the jump, clears markers left "in the future"
  and runs the missed roll(s). After a long time without weather it unblocks
  the roll gates.
- Lightning: the engine sets lightning intensity from the ARE value when rain
  starts, so lightning appears only together with rain.

NEUTRAL NIGHT FOG (checkbox)
The fog function multiplies the fog colour by the area's lighting colour, which
can be red at night. With the option on, a small stub is installed at RVA
0x305FD8. It calls the original function and replaces the returned colour with
its gray average, so night still darkens the fog but without the colour cast.
The site is verified at runtime (E8 opcode and call target) before anything is
written. The checkbox switches the effect live.

GLICHES ETC.
The weather feature darkens the scene slightly, so when creating BAM or WBM animations 
for the environment, you should take lighting changes into account; otherwise, 
the background outline will be visible when the weather effect is enabled.
Or use black in BAM and set the flag to blended.

Max and min sliders values for fog are not recomended ;).

OTHER
An INI file next to the exe (settings, language, window position). 
The helper looks for Torment.exe next to itself or in the working directory. 
Keep its window open while you play. After "Stop" the patches stay in the game 
until it is closed.

COMPATIBILITY
- Patch sites and context are found by signatures, so small rebuilds of the
  game usually still work, and an unmatched signature stops the patching
  instead of writing blindly.
- Some engine field offsets (game time, weather object, fog object) and the
  night-fog call site (RVA 0x305FD8) are fixed for the verified build of
  Torment.exe. On another build, check the log; if in doubt, do not use it.
- x64 Enhanced Edition only.

CREDITS:
The program icon comes from the beamdog forum, from a user named: Buttercheese.

DISCLAIMER:
AI (mainly Claude) helped create this program. Without it, nothing would have been created.

---
szef (501)
