Skip to content

New functions: C

dounai2333 edited this page Jan 24, 2025 · 1 revision

Introduction

dounai_lib has it's own C functions, they are meant to deal with the problems that Lua is just can't be done.

There are 2 references: dounai_lib.c and dounai_lib.C. The lowercase c are the wrapper of the uppercase C, and C will directly access C functions.

Using dounai_lib.c wrapper is always recommended! It contain extra codes with fixes and protection that C can't be done.

LuaInit

dounai_lib.c.LuaInit()

This function is automatic executed, you don't have to do it by yourself.

IsInGame

dounai_lib.c.IsInGame()

Check if the game is fully loaded, not in the map loading screen or so.

Return: true or false

Msg

dounai_lib.c.Msg(message, ...)

-- Wrapper
Msg(message, ...)

Print a message to console.

message: string

Warning

dounai_lib.c.Warning(message, ...)

Print a warning message to console.

message: string

ColorMsg

dounai_lib.c.ColorMsg(color, message, ...)

-- Wrapper
MsgC(color, message, ...)
print(...)

Print a colored message to console.

color: string, Color or number. Example: red, Color(255, 0, 0) or -16776961

message: string

LoadLua

dounai_lib.c.LoadLua(path)

Load a lua file from filesystem, return true on success.

BUG: If the client are old version, loading lua will actually load .elo file.

Return: true or false

path: string. Example: scripts/hello.lua

ReadFileFS

dounai_lib.c.ReadFileFS(path)

Read the file in filesystem and return the whole content.

BUG: This cannot read the encrypted (.e) file properly.

Return: string

path: string. Example: sound/stringtable.txt

FileExists

dounai_lib.c.FileExists(path)

Check if the file are exists in the filesystem.

Return: true or false

path: string. Example: sound/stringtable.txt

IsPlayerFast

dounai_lib.c.IsPlayerFast(pointer)

Check if the entity pointer address is a player.

BUG: You must always give this function a valid pointer or the game will crashes because invalid pointer.

This is a internal function, which means in the most of time you won't need this.

Return: true or false

pointer: number

prop_dynamic_create

dounai_lib.c.prop_dynamic_create(caller, model)

The advanced version of command prop_dynamic_create, can be used on bots and players with no delay (no network traffic).

Return: entity or nil

caller: player

model: string

cso2_canister_shoot

dounai_lib.c.cso2_canister_shoot(caller, damage, radius)

The advanced version of command cso2_canister_shoot, can be used on bots and players with no delay (no network traffic).

The following issues is fixed in our wrapper:

  1. When the airstrike point is too close from the player, the damage will apply instantly.
  2. The airstrike missile can kill your teammate.
  3. The airstrike missile can stuck you for about 0.1 sec, very noticeable when jumping.

Return: entity or nil

caller: player

damage: number

radius: number

ActivateEntity

dounai_lib.c.ActivateEntity(entity)

-- Wrapper
entity:Activate()

Activate the entity. In internal, this call Activate() of the entity.

entity: entity

GetKeyValue

dounai_lib.c.GetKeyValue(entity, key, isstring)

-- Wrapper
entity:GetKeyValue(key, isstring)

Get the key's value.

BUG: If isstring is set to true, but the value isn't a string, game will crash.

Return: string

entity: entity

key: string. Example: origin

isstring: bool

SetKeyValue

dounai_lib.c.SetKeyValue(entity, key, value)

-- Wrapper
entity:SetKeyValue(key, value)

Set the key's value.

entity: entity

key: string. Example: origin

value: string

DeleteWString

dounai_lib.c.DeleteWString(wstr)

Delete wide string buffer to prevent memory leak.

This is a internal function, which means in the most of time you won't need this.

wstr: wchar_t*

DeleteString

dounai_lib.c.DeleteString(str)

Delete string buffer to prevent memory leak.

This is a internal function, which means in the most of time you won't need this.

str: char*

EnDecrypt

dounai_lib.c.EnDecrypt(text, statickey)

Encrypt or decrypt the text, give the plaintext will encrypt it, give the encrypted text will decrypt it.

If statickey is set to false, the encrypted text cannot be decrypted after a game restart.

Return: string

text: string

statickey: bool

StringToWString

dounai_lib.c.StringToWString(str, codepage)

Convert string to wstring (UTF-16).

BUG: If you don't call dounai_lib.c.DeleteWString(wstr) after you don't need variable anymore, a memory leak will happens.

Return: wchar_t*

str: string

codepage: number

WStringToString

dounai_lib.c.WStringToString(wstr, codepage)

Convert wstring (UTF-16) to string.

Return: string

wstr: wchar_t*

codepage: number

Utf8Length

dounai_lib.c.Utf8Length(str)

Calculate the correct UTF-8 text (contain non-ASCII character) length.

Return: number

str: string

Utf8Substring

dounai_lib.c.Utf8Substring(str, start, count)

A bug free substring for UTF-8 text (contain non-ASCII character).

Return: string

str: string

start: number

count: number

IsFlagSet

dounai_lib.c.IsFlagSet(checking_flags, flag)

Check if the flag is present in the flags.

Return: true or false

checking_flags: number

flag: number

AddFlag

dounai_lib.c.AddFlag(adding_flags, flag)

Add the flag to the flags, if flag is already present, does nothing.

Return: number

adding_flags: number

flag: number

RemoveFlag

dounai_lib.c.RemoveFlag(removing_flags, flag)

Remove the flag from the flags, if flag is not present, does nothing.

Return: number

removing_flags: number

flag: number

HandleToIndex

dounai_lib.c.HandleToIndex(handle)

Convert entity handle to index.

This is a internal function, which means in the most of time you won't need this.

Return: number

handle: number

GetLastCreatedEntityIndex

dounai_lib.c.GetLastCreatedEntityIndex()

Get the last created entity index.

Return: number

OverrideGetListenServerHostIndex

dounai_lib.c.OverrideGetListenServerHostIndex(index)

Override the engine function GetListenServerHost() index to given value.

This is a internal function, which means in the most of time you won't need this.

index: number

BaseGameFixes

dounai_lib.c.BaseGameFixes()

Executing this function will fixes the following issues that exist in the base game:

  1. "Bad SetLocalAngles", this make the rotating entities does not rotate anymore.
  2. "Bad SetLocalAngularVelocity", this make the rotating entities does not properly rotating (rotate speed).
  3. "Clamping SetLocalVelocity", this make the non-physics entities cannot have a faster movement speed.
  4. When player has a activated "game_ui" entity but "Freeze Player" flag isn't preset, the player movement begin lagging.
  5. When player touches the ladder and then exit, his gravity setting will reset to default 100%.
  6. Lua API "GetMapName()" return incomplete name if the map name is larger than 32 characters.
  7. "sv_maxrate" command has a internal hard-coded 1048576 value limit.
  8. "Unknown command: xxx" message doesn't properly print to the console.
  9. Modifying "modelscale" keyvalue in the entity doesn't take any affect.
  10. Lua API "GetEntityByIndex()" doesn't return "worldspawn" when given index is 0.
  11. Debugging keyword "!picker" is not working.
  12. "m_iPing" netvar in "CCSPlayerResource" are updating slow and cannot effectively show the player latency.

ZombieEscapePatches

dounai_lib.c.ZombieEscapePatches(overrideSmokeGrenade)

Executing this function will apply several patches to different features to make zombie escape run smoother:

  1. Disable the 0.66 seconds in-game chat ("say" and "say_team" commands) cooldown.
  2. Make every grenade projectiles doesn't collide with player.
  3. Override "env_shake" entity input "StartShake" to "StartShake_2".
  4. Add "FCVAR_NOTIFY" flag to "mp_restartgame" command, so the "server_cvar" event can detect it.

When overrideSmokeGrenade is true:

  1. Override the "smokegrenade_projectile" detonate sound ("BaseSmokeEffect.Sound" to "IncGrenade.Explode").
  2. Override the "smokegrenade_projectile" model name ("w_smokegrenade_thrown.mdl" to "w_incendary_grenade_thrown.mdl").

overrideSmokeGrenade: bool

GetListenServerHostOid

dounai_lib.c.GetListenServerHostOid()

-- Wrapper
player:IsListenServerHost()

Get the listenserver host's server UserID.

This is a internal function, which means in the most of time you won't need this.

Return: number

GetGameTickCount

dounai_lib.c.GetGameTickCount()

Get how many tick has passed in server, 1 second = 66 ticks.

Return: number

GetEntityPointer

dounai_lib.c.GetEntityPointer(index)

-- Wrapper
entity:GetPointer()

Get the pointer address of entity.

This is a internal function, which means in the most of time you won't need this.

Return: number

index: number

GetEntityIndexByPointer

dounai_lib.c.GetEntityIndexByPointer(pointer)

Get the entity index by pointer address.

This is a internal function, which means in the most of time you won't need this.

Return: number

pointer: number

GetPlayerResourcePointer

dounai_lib.c.GetPlayerResourcePointer()

-- Wrapper
player:GetResourcePointer()

Get the player statistics (scoreboard) pointer.

This is a internal function, which means in the most of time you won't need this.

Return: number

GetGameRulesProxyPointer

dounai_lib.c.GetGameRulesProxyPointer()

Get the game rules proxy pointer.

This is a internal function, which means in the most of time you won't need this.

Return: number

MemWriteString

dounai_lib.c.MemWriteString(address, value, ispointer)

Write a string to the memory.

This is a internal function, which means in the most of time you won't need this.

address: number

value: string

ispointer: bool

MemWriteWString

dounai_lib.c.MemWriteWString(address, value, ispointer)

Write a wide string to the memory.

This is a internal function, which means in the most of time you won't need this.

address: number

value: string

ispointer: bool

UnlockMemProt

dounai_lib.c.UnlockMemProt(address, size)

Unlock the memory protection, make them writable.

This is a internal function, which means in the most of time you won't need this.

Return: number

address: number

size: number

LockMemProt

dounai_lib.c.LockMemProt(address, size, protect)

Lock the memory to given protection.

This is a internal function, which means in the most of time you won't need this.

address: number

size: number

protect: number

Clone this wiki locally