mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-15 23:50:38 +00:00
feat(cvar): add C_CVar.SetTempCVar and RemoveTempCVar
SetTempCVar changes a cvar for the session without saving it to Config.wtf; RemoveTempCVar restores the value from before the first temp set. The temp set passes a6 = 0 to the engine setter, the only argument that marks the config dirty, so it applies the value and runs the change callback without asking for a save. When something else dirties the config, a co-hook on the config writer (0x0063D980) points each temp cvar's value at its saved string for the write and restores it after. A plain SetCVar over a temp value wins: the entry drops itself, so the user's set is saved and never rolled back. Errors mirror Script_SetCVar. Registered in-game and on glue.
This commit is contained in:
+32
@@ -127,6 +127,7 @@ build instructions.
|
||||
- [`C_CVar.DoesCVarExist(name)`](#c_cvardoescvarexistname)
|
||||
- [`C_CVar.AreCVarsLoaded()`](#c_cvararecvarsloaded)
|
||||
- [`C_CVar.GetCVarBitfield(name, index)` / `C_CVar.SetCVarBitfield(name, index, value)`](#c_cvargetcvarbitfieldname-index--c_cvarsetcvarbitfieldname-index-value)
|
||||
- [`C_CVar.SetTempCVar(name, value)` / `C_CVar.RemoveTempCVar(name)`](#c_cvarsettempcvarname-value--c_cvarremovetempcvarname)
|
||||
- [`C_CVar.GetCVarBool(cvar)`](#c_cvargetcvarboolcvar)
|
||||
- [The interface memory limit](#the-interface-memory-limit)
|
||||
|
||||
@@ -3243,6 +3244,37 @@ for. A successful write saves the cvar the same way `SetCVar` does.
|
||||
Any cvar works, and a cvar you register yourself is the usual way to use
|
||||
these. Every bit is independent, so setting one leaves the rest alone.
|
||||
|
||||
### `C_CVar.SetTempCVar(name, value)` / `C_CVar.RemoveTempCVar(name)`
|
||||
|
||||
`SetTempCVar` changes a cvar for this session only. The game uses the new
|
||||
value at once, but it does not save the value to Config.wtf.
|
||||
`RemoveTempCVar` puts back the value that the cvar had before the first
|
||||
`SetTempCVar`. Neither function returns a value.
|
||||
|
||||
```lua
|
||||
-- Saved value of cameraDistanceMax is "15".
|
||||
C_CVar.SetTempCVar("cameraDistanceMax", "40")
|
||||
GetCVar("cameraDistanceMax") -- "40"
|
||||
-- After /reload or logout, Config.wtf still holds "15".
|
||||
C_CVar.RemoveTempCVar("cameraDistanceMax")
|
||||
GetCVar("cameraDistanceMax") -- "15"
|
||||
```
|
||||
|
||||
Use this pair for a mode that changes many cvars and later turns off, for
|
||||
example a gamepad mode. The saved settings of the user do not change.
|
||||
|
||||
- If you call `SetTempCVar` two times on one cvar, `RemoveTempCVar` puts
|
||||
back the value from before the first call.
|
||||
- If `SetCVar` changes a cvar that has a temp value, the `SetCVar` value
|
||||
replaces the temp value. The game saves it, and `RemoveTempCVar` then does
|
||||
not change the cvar.
|
||||
- If `value` is `nil`, the cvar gets an empty string, as with `SetCVar`.
|
||||
- `RemoveTempCVar` does nothing for a cvar that has no temp value.
|
||||
|
||||
Both functions give the same errors as `SetCVar`: for a name that is not a
|
||||
cvar, and for a read-only cvar. Both are also available on the login and
|
||||
character-select screens.
|
||||
|
||||
### `C_CVar.GetCVarBool(cvar)`
|
||||
|
||||
Returns the cvar's value coerced to a boolean, or `nil` if no cvar
|
||||
|
||||
Reference in New Issue
Block a user