├── .github └── workflows │ └── build-deploy.yml ├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── CMakeSettings.json ├── README.md ├── build_client_win.bat ├── build_server_linux.sh ├── build_server_win.bat ├── cmake-variants.yaml ├── libs ├── lua51 │ ├── linux64 │ │ └── lua51.so │ └── win64 │ │ └── lua51.dll ├── mariadb │ ├── linux64 │ │ └── libmariadb.so │ └── win64 │ │ └── libmariadb.dll └── sqlite3 │ ├── linux64 │ └── sqlite3.so │ └── win64 │ └── sqlite3.dll ├── scripts ├── json │ └── json.lua ├── mysql │ ├── MySQL │ │ ├── libs │ │ │ ├── linux64 │ │ │ │ └── libmariadb.so │ │ │ └── win64 │ │ │ │ └── libmariadb.dll │ │ ├── mysql_ffi.lua │ │ └── mysql_row.lua │ └── mysql.lua └── sqlite3 │ ├── SQLite3 │ ├── libs │ │ ├── linux64 │ │ │ └── sqlite3.so │ │ └── win64 │ │ │ └── sqlite3.dll │ ├── sqlite3_ffi.lua │ └── sqlite3_row.lua │ └── sqlite3.lua ├── src ├── Defs │ ├── Alt.cpp │ ├── Alt.h │ ├── Client │ │ ├── Audio.cpp │ │ ├── Audio.h │ │ ├── DiscordManager.cpp │ │ ├── DiscordManager.h │ │ ├── HandlingData.cpp │ │ ├── HandlingData.h │ │ ├── MapData.cpp │ │ ├── MapData.h │ │ ├── Native.cpp │ │ ├── Native.h │ │ ├── RmlDocument.cpp │ │ ├── RmlDocument.h │ │ ├── RmlElement.cpp │ │ ├── RmlElement.h │ │ ├── WebSocket.cpp │ │ ├── WebSocket.h │ │ ├── WebView.cpp │ │ └── WebView.h │ ├── Config.cpp │ ├── Config.h │ ├── Entity │ │ ├── BaseObject.cpp │ │ ├── BaseObject.h │ │ ├── Blip.cpp │ │ ├── Blip.h │ │ ├── Checkpoint.cpp │ │ ├── Checkpoint.h │ │ ├── ColShape.cpp │ │ ├── ColShape.h │ │ ├── Entity.cpp │ │ ├── Entity.h │ │ ├── Player.cpp │ │ ├── Player.h │ │ ├── Vehicle.cpp │ │ ├── Vehicle.h │ │ ├── VoiceChannel.cpp │ │ ├── VoiceChannel.h │ │ ├── WorldObject.cpp │ │ └── WorldObject.h │ ├── Resource.cpp │ ├── Resource.h │ ├── Shared │ │ ├── MiscScripts.cpp │ │ ├── MiscScripts.h │ │ ├── RGBA.cpp │ │ ├── RGBA.h │ │ ├── Vector2.cpp │ │ ├── Vector2.h │ │ ├── Vector3.cpp │ │ └── Vector3.h │ ├── Voice.cpp │ └── Voice.h ├── EventManager.cpp ├── EventManager.h ├── Events │ ├── Client │ │ ├── EntityEvents.cpp │ │ └── MiscEvents.cpp │ ├── Server │ │ ├── MiscEvents.cpp │ │ ├── PlayerEvents.cpp │ │ └── VehicleEvents.cpp │ └── Shared │ │ ├── MetaEvents.cpp │ │ ├── MiscEvents.cpp │ │ └── ResourceEvents.cpp ├── Helpers │ ├── ArgumentReader.h │ ├── LuaHelpers.cpp │ ├── LuaHelpers.h │ ├── MetaFunction.cpp │ └── MetaFunction.h ├── LuaResourceImpl.cpp ├── LuaResourceImpl.h ├── LuaScriptRuntime.cpp ├── LuaScriptRuntime.h ├── LuaWrapper.hpp ├── Main.cpp ├── Main.h ├── VehicleModels.hpp └── semver.hpp └── vendors └── luajit ├── bin ├── linux64 │ ├── lua51.so │ └── luajit └── win64 │ ├── lua51.dll │ └── luajit.exe ├── include ├── lauxlib.h ├── lua.h ├── lua.hpp ├── luaconf.h ├── luajit.h └── lualib.h └── lib ├── linux64 ├── libluajit.a └── libluajit.so └── win64 ├── lua51.lib └── luajit.lib /.github/workflows/build-deploy.yml: -------------------------------------------------------------------------------- 1 | name: Build & deploy 2 | on: 3 | push: 4 | tags: 5 | - "server/*.*" 6 | - "client/*.*" 7 | 8 | jobs: 9 | create_release: 10 | name: Setup outputs 11 | runs-on: ubuntu-latest 12 | outputs: 13 | upload_url: ${{ steps.create_release.outputs.upload_url }} 14 | steps: 15 | - name: Create release 16 | id: create_release 17 | uses: actions/create-release@v1 18 | env: 19 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 20 | with: 21 | tag_name: ${{ github.ref }} 22 | release_name: Release ${{ github.ref }} 23 | draft: false 24 | prerelease: false 25 | build-windows-server: 26 | name: Build Windows server release 27 | runs-on: windows-2019 28 | needs: [create_release] 29 | if: startsWith(github.ref, 'refs/tags/server') 30 | steps: 31 | - name: Checkout repository 32 | uses: actions/checkout@v2 33 | with: 34 | submodules: recursive 35 | lfs: true 36 | - name: Build 37 | shell: cmd 38 | run: build_server_win.bat 39 | - name: Upload Windows artifacts 40 | uses: actions/upload-release-asset@v1 41 | env: 42 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 43 | with: 44 | upload_url: ${{ needs.create_release.outputs.upload_url }} 45 | asset_path: artifacts/lua-server-module-windows.zip 46 | asset_name: lua-server-module-windows.zip 47 | asset_content_type: application/zip 48 | build-linux-server: 49 | name: Build Linux server release 50 | runs-on: ubuntu-18.04 51 | needs: [create_release] 52 | if: startsWith(github.ref, 'refs/tags/server') 53 | steps: 54 | - name: Checkout repository 55 | uses: actions/checkout@v2 56 | with: 57 | submodules: recursive 58 | lfs: true 59 | - name: Make it executeable 60 | run: chmod +x ./build_server_linux.sh 61 | - name: Build 62 | run: ./build_server_linux.sh 63 | - name: Upload linux artifacts 64 | uses: actions/upload-release-asset@v1 65 | env: 66 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 67 | with: 68 | upload_url: ${{ needs.create_release.outputs.upload_url }} 69 | asset_path: artifacts/lua-server-module-linux.zip 70 | asset_name: lua-server-module-linux.zip 71 | asset_content_type: application/zip 72 | build-windows-client: 73 | name: Build Windows client release 74 | runs-on: windows-2019 75 | needs: [create_release] 76 | if: startsWith(github.ref, 'refs/tags/client') 77 | steps: 78 | - name: Checkout repository 79 | uses: actions/checkout@v2 80 | with: 81 | submodules: recursive 82 | lfs: true 83 | - name: Build 84 | shell: cmd 85 | run: build_client_win.bat 86 | - name: Upload Windows client module 87 | uses: actions/upload-release-asset@v1 88 | env: 89 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 90 | with: 91 | upload_url: ${{ needs.create_release.outputs.upload_url }} 92 | asset_path: artifacts/lua-client-module.zip 93 | asset_name: lua-client-module.zip 94 | asset_content_type: application/zip 95 | - name: Upload Windows client library 96 | uses: actions/upload-release-asset@v1 97 | env: 98 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 99 | with: 100 | upload_url: ${{ needs.create_release.outputs.upload_url }} 101 | asset_path: artifacts/lua-client-module-static.zip 102 | asset_name: lua-client-module-static.zip 103 | asset_content_type: application/zip 104 | publish-artifacts: 105 | name: Publish Lua modules 106 | runs-on: windows-2019 107 | needs: [create_release] 108 | if: startsWith(github.ref, 'refs/tags/server') 109 | steps: 110 | - name: Checkout repository 111 | uses: actions/checkout@v2 112 | with: 113 | submodules: recursive 114 | lfs: true 115 | - name: Zipping Lua modules 116 | shell: cmd 117 | run: | 118 | if not exist "artifacts" mkdir artifacts 119 | echo %CD% 120 | dir 121 | cd .\scripts 122 | FOR /D %%G in (*) DO ( 123 | echo Try to 7Zip the following folder: %%~nxG 124 | 7z a -tzip "%%G-module.zip" -r %%G 125 | move /Y "%%G-module.zip" ..\artifacts 126 | ) 127 | - name: Uploading Lua modules artifact 128 | uses: csexton/release-asset-action@v2 129 | with: 130 | release-url: ${{ needs.create_release.outputs.upload_url }} 131 | github-token: ${{ secrets.GITHUB_TOKEN }} 132 | pattern: "artifacts/*-module.zip" 133 | 134 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /CMakeFiles 2 | /out 3 | /.vs 4 | /.vscode 5 | /build 6 | /lua-module 7 | /artifacts 8 | 9 | CMakeCache.txt 10 | Makefile 11 | cmake_install.cmake 12 | cpp.hint -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "src/vendors/cpp-sdk"] 2 | path = vendors/cpp-sdk 3 | url = https://github.com/altmp/cpp-sdk 4 | branch = dev 5 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # CMakeList.txt : Top-level CMake project file, do global configuration 2 | # and include sub-projects here. 3 | # 4 | cmake_minimum_required (VERSION 3.8) 5 | 6 | project ("altv-lua-module") 7 | 8 | include("vendors/cpp-sdk/CMakeLists.txt") 9 | 10 | set(PROJECT_MODULE_NAME "lua-module") 11 | if("${MODULE_TYPE}" STREQUAL "CLIENT") 12 | set(PROJECT_MODULE_NAME "lua-client-module") 13 | endif() 14 | 15 | set(CMAKE_CXX_STANDARD 17) 16 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 17 | 18 | add_definitions(-DMODULE_NAME="${PROJECT_MODULE_NAME}") 19 | add_definitions(-DALT_${MODULE_TYPE}_API) 20 | add_definitions(-D_CRT_SECURE_NO_WARNINGS) 21 | 22 | if(UNIX) 23 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/build/linux64/${CMAKE_BUILD_TYPE}) 24 | else() 25 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/build/win64/${CMAKE_BUILD_TYPE}) 26 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/build/win64/${CMAKE_BUILD_TYPE}) 27 | # set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MD") 28 | endif() 29 | # set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") 30 | set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MD") 31 | 32 | file(GLOB_RECURSE PROJECT_SOURCE_FILES "./src/*.h" "./src/*.hpp" "./src/*.cpp") 33 | 34 | include_directories( 35 | "${PROJECT_SOURCE_DIR}/src" 36 | "${PROJECT_SOURCE_DIR}/vendors/luajit/include" 37 | "${PROJECT_SOURCE_DIR}/vendors/cpp-sdk" 38 | ) 39 | 40 | add_library( 41 | ${PROJECT_MODULE_NAME} SHARED 42 | ${PROJECT_SOURCE_FILES} 43 | ) 44 | 45 | add_dependencies(${PROJECT_MODULE_NAME} alt-sdk) 46 | 47 | if("${MODULE_TYPE}" STREQUAL "CLIENT") 48 | add_library( 49 | ${PROJECT_MODULE_NAME}-static STATIC 50 | ${PROJECT_SOURCE_FILES} 51 | ) 52 | endif() 53 | 54 | # target_compile_definitions(${PROJECT_MODULE_NAME} PRIVATE 55 | # -DALT_SERVER_API 56 | # ) 57 | 58 | if(UNIX) 59 | target_link_libraries(${PROJECT_MODULE_NAME} ${PROJECT_SOURCE_DIR}/vendors/luajit/lib/linux64/libluajit.so) 60 | #target_compile_options(${PROJECT_MODULE_NAME} PRIVATE 61 | # -fuse-ld=lld 62 | # -std=c++17 63 | # -lstdc++fs 64 | #) 65 | else() 66 | target_link_libraries(${PROJECT_MODULE_NAME} 67 | ${PROJECT_SOURCE_DIR}/vendors/luajit/lib/win64/lua51.lib 68 | ${PROJECT_SOURCE_DIR}/vendors/luajit/lib/win64/luajit.lib 69 | ) 70 | endif() -------------------------------------------------------------------------------- /CMakeSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Server - Debug", 5 | "generator": "Ninja", 6 | "configurationType": "Debug", 7 | "inheritEnvironments": [ "msvc_x64_x64" ], 8 | "buildRoot": "${projectDir}\\out\\build\\${name}", 9 | "installRoot": "${projectDir}\\out\\install\\${name}", 10 | "cmakeCommandArgs": "-DMODULE_TYPE=SERVER", 11 | "buildCommandArgs": "", 12 | "ctestCommandArgs": "", 13 | "variables": [] 14 | }, 15 | { 16 | "name": "Server - Release", 17 | "generator": "Ninja", 18 | "configurationType": "Release", 19 | "buildRoot": "${projectDir}\\out\\build\\${name}", 20 | "installRoot": "${projectDir}\\out\\install\\${name}", 21 | "cmakeCommandArgs": "-DMODULE_TYPE=SERVER", 22 | "buildCommandArgs": "", 23 | "ctestCommandArgs": "", 24 | "inheritEnvironments": [ "msvc_x64_x64" ], 25 | "variables": [] 26 | }, 27 | { 28 | "name": "Client - Debug", 29 | "generator": "Ninja", 30 | "configurationType": "Debug", 31 | "buildRoot": "${projectDir}\\out\\build\\${name}", 32 | "installRoot": "${projectDir}\\out\\install\\${name}", 33 | "cmakeCommandArgs": "-DMODULE_TYPE=CLIENT", 34 | "buildCommandArgs": "", 35 | "ctestCommandArgs": "", 36 | "inheritEnvironments": [ "msvc_x64_x64" ], 37 | "variables": [] 38 | }, 39 | { 40 | "name": "Client - Release", 41 | "generator": "Ninja", 42 | "configurationType": "Release", 43 | "buildRoot": "${projectDir}\\out\\build\\${name}", 44 | "installRoot": "${projectDir}\\out\\install\\${name}", 45 | "cmakeCommandArgs": "-DMODULE_TYPE=CLIENT", 46 | "buildCommandArgs": "", 47 | "ctestCommandArgs": "", 48 | "inheritEnvironments": [ "msvc_x64_x64" ], 49 | "variables": [] 50 | } 51 | ] 52 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # altv-lua-module 2 | Keep in mind that this module is still WIP (so it should lack some of the functions) and its in beta phase. If you find a bug or missing a function which you think it would be awesome to exists don't hesitate just open an issue for it. The structure and function names are equal to the JavaScript module. 3 | If you have questions feel free to ask on [alt:V's Discord](https://discord.altv.mp) channel (#lua). 4 | 5 | ## Installing 6 | Installing the module is very simple: 7 | 1. Download one of the release from [Releases](https://github.com/drakeee/altv-lua-module/releases). 8 | 2. Open the zip file. 9 | 3. Drag & Drop the folder from the archive into your server's modules folder. 10 | 4. Open your server's server.cfg and add the module: 11 | ``` 12 | modules: [ lua-module ] 13 | ``` 14 | 15 | ## Installing Lua modules 16 | The module itself doesn't come with MySQL/SQLite3, json implemented but you can install it very easily. 17 | 1. Download which module you need (mysql-module, sqlite3-module, json-module). 18 | 2. Open the zip file. 19 | 3. Drag & Drop the folder inside the archive file to your server's modules/lua-module/modules folder. 20 | 4. Include the corresponding module in your script: 21 | ```lua 22 | -- local sqlite = require("sqlite3") 23 | -- local mysql = require("mysql") 24 | -- local json = require("json") 25 | ``` 26 | 27 | ## Example 28 | https://github.com/drakeee/altv-quickstart-lua 29 | 30 | I would like to thank [Stuyk](https://github.com/Stuyk) for its [Boilerplate](https://github.com/Stuyk/AltV-JS-Boilerplate) written in JavaScript which is ported to Lua as a good example. 31 | 32 | ## Wiki 33 | https://wiki.itsdrake.com/index.php/Main_Page 34 | 35 | (Wiki is still WIP and I will fill it up with examples if i have free time for it) 36 | -------------------------------------------------------------------------------- /build_client_win.bat: -------------------------------------------------------------------------------- 1 | @echo on 2 | 3 | REM git submodule update --init --recursive --remote 4 | 5 | if not exist build mkdir build 6 | cd build 7 | 8 | cmake -G"Visual Studio 16 2019" -DMODULE_TYPE=CLIENT -A x64 ..\\ 9 | cmake --build . --config Release 10 | 11 | cd .. 12 | 13 | mkdir artifacts 14 | 15 | xcopy libs\lua51\win64\lua51.dll artifacts\lua-client-module\ /Y 16 | REM xcopy libs\mariadb\win64\libmariadb.dll build\win64\Release\modules\lua-module\ /Y 17 | REM xcopy libs\sqlite3\win64\sqlite3.dll build\win64\Release\modules\lua-module\ /Y 18 | xcopy build\win64\Release\lua-client-module.dll artifacts\lua-client-module\ /Y 19 | xcopy build\win64\Release\lua-client-module-static.lib artifacts\ /Y 20 | 21 | cd artifacts 22 | REM if not exist "lua-client-module\modules" mkdir "lua-client-module\modules" 23 | 7z a -tzip "lua-client-module.zip" -r lua-client-module 24 | 7z a -tzip "lua-client-module-static.zip" lua-client-module-static.lib 25 | 26 | cd .. 27 | -------------------------------------------------------------------------------- /build_server_linux.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #git submodule update --init --recursive --remote 4 | 5 | cmake -DCMAKE_BUILD_TYPE=Release -DMODULE_TYPE=SERVER ./ 6 | cmake --build . --config Release 7 | 8 | mkdir -p artifacts/lua-module/modules 9 | cp ./libs/lua51/linux64/lua51.so ./artifacts/lua-module 10 | cp ./build/linux64/Release/liblua-module.so ./artifacts/lua-module 11 | ln -rs ./artifacts/lua-module/lua51.so ./artifacts/lua-module/libluajit-5.1.so.2 12 | 13 | cd artifacts 14 | zip --symlinks -r lua-server-module-linux.zip lua-module/* 15 | cd .. 16 | 17 | #mkdir -p ./build/linux64/Release/modules/lua-module 18 | #cp -r ./scripts ./build/linux64/Release/modules/lua-module/ 19 | #cp ./libs/lua51/linux64/lua51.so ./build/linux64/Release/modules/lua-module/ 20 | #cp ./libs/mariadb/linux64/libmariadb.so ./build/linux64/Release/modules/lua-module/ 21 | #cp ./libs/sqlite3/linux64/sqlite3.so ./build/linux64/Release/modules/lua-module/ 22 | #cp ./build/linux64/Release/liblua-module.so ./build/linux64/Release/modules/lua-module/ 23 | 24 | -------------------------------------------------------------------------------- /build_server_win.bat: -------------------------------------------------------------------------------- 1 | @echo on 2 | 3 | REM git submodule update --init --recursive --remote 4 | 5 | if not exist build mkdir build 6 | cd build 7 | 8 | cmake -G"Visual Studio 16" -DMODULE_TYPE=SERVER -A x64 ..\\ 9 | cmake --build . --config Release 10 | 11 | cd .. 12 | 13 | mkdir artifacts 14 | 15 | xcopy libs\lua51\win64\lua51.dll artifacts\lua-module\ /Y 16 | REM xcopy libs\mariadb\win64\libmariadb.dll build\win64\Release\modules\lua-module\ /Y 17 | REM xcopy libs\sqlite3\win64\sqlite3.dll build\win64\Release\modules\lua-module\ /Y 18 | xcopy build\win64\Release\lua-module.dll artifacts\lua-module\ /Y 19 | 20 | cd artifacts 21 | if not exist "lua-module\modules" mkdir "lua-module\modules" 22 | 7z a -tzip "lua-server-module-windows.zip" -r lua-module 23 | 24 | cd .. 25 | -------------------------------------------------------------------------------- /cmake-variants.yaml: -------------------------------------------------------------------------------- 1 | buildType: 2 | default: debug 3 | choices: 4 | debug: 5 | short: Debug 6 | long: Build with debugging information. 7 | buildType: Debug 8 | release: 9 | short: Release 10 | long: Optimize generated code. 11 | buildType: Release 12 | 13 | moduletype: 14 | default: server 15 | choices: 16 | server: 17 | short: Server 18 | long: Build server module. 19 | settings: 20 | MODULE_TYPE: "SERVER" 21 | client: 22 | short: Client 23 | long: Build client module. 24 | settings: 25 | MODULE_TYPE: "CLIENT" -------------------------------------------------------------------------------- /libs/lua51/linux64/lua51.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drakeee/altv-lua-module/f3d18e7ef7f5c7ec089a8652ce02865720385960/libs/lua51/linux64/lua51.so -------------------------------------------------------------------------------- /libs/lua51/win64/lua51.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drakeee/altv-lua-module/f3d18e7ef7f5c7ec089a8652ce02865720385960/libs/lua51/win64/lua51.dll -------------------------------------------------------------------------------- /libs/mariadb/linux64/libmariadb.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drakeee/altv-lua-module/f3d18e7ef7f5c7ec089a8652ce02865720385960/libs/mariadb/linux64/libmariadb.so -------------------------------------------------------------------------------- /libs/mariadb/win64/libmariadb.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drakeee/altv-lua-module/f3d18e7ef7f5c7ec089a8652ce02865720385960/libs/mariadb/win64/libmariadb.dll -------------------------------------------------------------------------------- /libs/sqlite3/linux64/sqlite3.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drakeee/altv-lua-module/f3d18e7ef7f5c7ec089a8652ce02865720385960/libs/sqlite3/linux64/sqlite3.so -------------------------------------------------------------------------------- /libs/sqlite3/win64/sqlite3.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drakeee/altv-lua-module/f3d18e7ef7f5c7ec089a8652ce02865720385960/libs/sqlite3/win64/sqlite3.dll -------------------------------------------------------------------------------- /scripts/mysql/MySQL/libs/linux64/libmariadb.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drakeee/altv-lua-module/f3d18e7ef7f5c7ec089a8652ce02865720385960/scripts/mysql/MySQL/libs/linux64/libmariadb.so -------------------------------------------------------------------------------- /scripts/mysql/MySQL/libs/win64/libmariadb.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drakeee/altv-lua-module/f3d18e7ef7f5c7ec089a8652ce02865720385960/scripts/mysql/MySQL/libs/win64/libmariadb.dll -------------------------------------------------------------------------------- /scripts/mysql/MySQL/mysql_ffi.lua: -------------------------------------------------------------------------------- 1 | local ffi = require('ffi') 2 | ffi.cdef [[ 3 | typedef void MYSQL; 4 | typedef char** MYSQL_ROW; 5 | typedef void MYSQL_RES; 6 | 7 | enum enum_field_types { 8 | MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY, 9 | MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG, 10 | MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE, 11 | MYSQL_TYPE_NULL, MYSQL_TYPE_TIMESTAMP, 12 | MYSQL_TYPE_LONGLONG,MYSQL_TYPE_INT24, 13 | MYSQL_TYPE_DATE, MYSQL_TYPE_TIME, 14 | MYSQL_TYPE_DATETIME, MYSQL_TYPE_YEAR, 15 | MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR, 16 | MYSQL_TYPE_BIT, 17 | /* 18 | the following types are not used by client, 19 | only for mysqlbinlog!! 20 | */ 21 | MYSQL_TYPE_TIMESTAMP2, 22 | MYSQL_TYPE_DATETIME2, 23 | MYSQL_TYPE_TIME2, 24 | /* --------------------------------------------- */ 25 | MYSQL_TYPE_JSON=245, 26 | MYSQL_TYPE_NEWDECIMAL=246, 27 | MYSQL_TYPE_ENUM=247, 28 | MYSQL_TYPE_SET=248, 29 | MYSQL_TYPE_TINY_BLOB=249, 30 | MYSQL_TYPE_MEDIUM_BLOB=250, 31 | MYSQL_TYPE_LONG_BLOB=251, 32 | MYSQL_TYPE_BLOB=252, 33 | MYSQL_TYPE_VAR_STRING=253, 34 | MYSQL_TYPE_STRING=254, 35 | MYSQL_TYPE_GEOMETRY=255, 36 | MAX_NO_FIELD_TYPES 37 | }; 38 | 39 | typedef struct st_mysql_field { 40 | char *name; /* Name of column */ 41 | char *org_name; /* Name of original column (added after 3.23.58) */ 42 | char *table; /* Table of column if column was a field */ 43 | char *org_table; /* Name of original table (added after 3.23.58 */ 44 | char *db; /* table schema (added after 3.23.58) */ 45 | char *catalog; /* table catalog (added after 3.23.58) */ 46 | char *def; /* Default value (set by mysql_list_fields) */ 47 | unsigned long length; /* Width of column */ 48 | unsigned long max_length; /* Max width of selected set */ 49 | /* added after 3.23.58 */ 50 | unsigned int name_length; 51 | unsigned int org_name_length; 52 | unsigned int table_length; 53 | unsigned int org_table_length; 54 | unsigned int db_length; 55 | unsigned int catalog_length; 56 | unsigned int def_length; 57 | /***********************/ 58 | unsigned int flags; /* Div flags */ 59 | unsigned int decimals; /* Number of decimals in field */ 60 | unsigned int charsetnr; /* char set number (added in 4.1) */ 61 | enum enum_field_types type; /* Type of field. Se mysql_com.h for types */ 62 | void *extension; /* added in 4.1 */ 63 | } MYSQL_FIELD; 64 | 65 | MYSQL *mysql_init(MYSQL *mysql); 66 | MYSQL *mysql_real_connect( 67 | MYSQL *mysql, 68 | const char *host, 69 | const char *user, 70 | const char *passwd, 71 | const char *db, 72 | unsigned int port, 73 | const char *unix_socket, 74 | unsigned long clientflag); 75 | int mysql_ping(MYSQL *mysql); 76 | unsigned int mysql_errno(MYSQL *mysql); 77 | const char * mysql_error(MYSQL *mysql); 78 | void mysql_close(MYSQL *sock); 79 | unsigned long mysql_real_escape_string(MYSQL *mysql, char *to, const char *from, unsigned long length); 80 | int mysql_query(MYSQL *mysql, const char *q); 81 | MYSQL_RES* mysql_store_result(MYSQL *mysql); 82 | MYSQL_RES* mysql_use_result(MYSQL *mysql); 83 | unsigned long long mysql_insert_id(MYSQL *mysql); 84 | unsigned long long mysql_affected_rows(MYSQL *mysql); 85 | unsigned long long mysql_num_rows(MYSQL_RES *res); 86 | unsigned int mysql_num_fields(MYSQL_RES *res); 87 | MYSQL_FIELD* mysql_fetch_fields(MYSQL_RES *result); 88 | unsigned int mysql_num_fields(MYSQL_RES *res); 89 | MYSQL_ROW mysql_fetch_row(MYSQL_RES *result); 90 | void mysql_free_result(MYSQL_RES *result); 91 | ]] 92 | local nullptr = ffi.cast("void*", 0) 93 | local extension = (ffi.os == "Windows" and ".dll" or ".so") 94 | 95 | function script_path() 96 | local str = debug.getinfo(1, "S").source:sub(2) 97 | 98 | if ffi.os == "Windows" then 99 | return str:match("(.*[/\\])") 100 | else 101 | return str:match("(.*/)") 102 | end 103 | end 104 | 105 | local lib = nil 106 | local result = pcall(function() 107 | local library = string.format("%s/libs/%s/libmariadb%s", script_path(), (ffi.os == "Windows" and "win64" or "linux64"), extension) 108 | lib = ffi.load(library, true) 109 | end) 110 | 111 | logInfo(inspect(script_path())) 112 | 113 | if not result then 114 | logError(string.format("[MySQL] Unable to load libmariadb: couldn't find \"libmariadb%s\" library", extension)) 115 | logError(string.format("[MySQL] Please make sure that \"libmariadb%s\" exists inside \"modules/lua-module\" folder.", extension)) 116 | return false 117 | end 118 | 119 | return lib -------------------------------------------------------------------------------- /scripts/mysql/MySQL/mysql_row.lua: -------------------------------------------------------------------------------- 1 | local lib = require("MySQL.mysql_ffi") 2 | 3 | if not lib then 4 | return false 5 | end 6 | 7 | -- Source: https://github.com/pguillory/luajit-mysql/blob/136a3f1833db68a608a56c662cda5f4c295a2395/src/mysql/st_mysql_field.lua#L7 8 | local read_funcs = {} 9 | read_funcs[lib.MYSQL_TYPE_DECIMAL] = tonumber 10 | read_funcs[lib.MYSQL_TYPE_TINY] = tonumber 11 | read_funcs[lib.MYSQL_TYPE_SHORT] = tonumber 12 | read_funcs[lib.MYSQL_TYPE_LONG] = tonumber 13 | read_funcs[lib.MYSQL_TYPE_FLOAT] = tonumber 14 | read_funcs[lib.MYSQL_TYPE_DOUBLE] = tonumber 15 | read_funcs[lib.MYSQL_TYPE_NULL] = tostring 16 | read_funcs[lib.MYSQL_TYPE_TIMESTAMP] = tostring 17 | read_funcs[lib.MYSQL_TYPE_LONGLONG] = tostring 18 | read_funcs[lib.MYSQL_TYPE_INT24] = tonumber 19 | read_funcs[lib.MYSQL_TYPE_DATE] = tostring 20 | read_funcs[lib.MYSQL_TYPE_TIME] = tostring 21 | read_funcs[lib.MYSQL_TYPE_DATETIME] = tostring 22 | read_funcs[lib.MYSQL_TYPE_YEAR] = tostring 23 | read_funcs[lib.MYSQL_TYPE_NEWDATE] = tostring 24 | read_funcs[lib.MYSQL_TYPE_VARCHAR] = tostring 25 | read_funcs[lib.MYSQL_TYPE_BIT] = tostring 26 | read_funcs[lib.MYSQL_TYPE_TIMESTAMP2] = tostring 27 | read_funcs[lib.MYSQL_TYPE_DATETIME2] = tostring 28 | read_funcs[lib.MYSQL_TYPE_TIME2] = tostring 29 | read_funcs[lib.MYSQL_TYPE_NEWDECIMAL] = tonumber 30 | read_funcs[lib.MYSQL_TYPE_ENUM] = tostring 31 | read_funcs[lib.MYSQL_TYPE_SET] = tostring 32 | read_funcs[lib.MYSQL_TYPE_TINY_BLOB] = tostring 33 | read_funcs[lib.MYSQL_TYPE_MEDIUM_BLOB] = tostring 34 | read_funcs[lib.MYSQL_TYPE_LONG_BLOB] = tostring 35 | read_funcs[lib.MYSQL_TYPE_BLOB] = tostring 36 | read_funcs[lib.MYSQL_TYPE_VAR_STRING] = tostring 37 | read_funcs[lib.MYSQL_TYPE_STRING] = tostring 38 | read_funcs[lib.MYSQL_TYPE_GEOMETRY] = tostring 39 | 40 | return read_funcs -------------------------------------------------------------------------------- /scripts/mysql/mysql.lua: -------------------------------------------------------------------------------- 1 | local ffi = require("ffi") 2 | local lib = require("MySQL.mysql_ffi") 3 | local rowType = require("MySQL.mysql_row") 4 | 5 | local MySQL = {} 6 | MySQL.__index = MySQL 7 | 8 | function MySQL:connect(host, user, passwd, db, port) 9 | 10 | assert(host, "[MySQL:connect] Hostname is required. Line: " .. tostring(debug.getinfo(2).currentline)) 11 | assert(user, "[MySQL:connect] Username is required. Line: " .. tostring(debug.getinfo(2).currentline)) 12 | assert(passwd, "[MySQL:connect] Password is required. Line: " .. tostring(debug.getinfo(2).currentline)) 13 | assert(db, "[MySQL:connect] Database is required. Line: " .. tostring(debug.getinfo(2).currentline)) 14 | 15 | port = port or 3306 16 | 17 | local obj = {} 18 | obj.__connection = lib.mysql_init(nil) 19 | 20 | if lib.mysql_real_connect(obj.__connection, host, user, passwd, db, port, nil, 0) == nullptr then 21 | logError("[MySQL] Could not connect to the database: ") 22 | logError(" Error Code: " .. tostring(lib.mysql_errno(obj.__connection))) 23 | logError(" Error: " .. tostring(ffi.string(lib.mysql_error(obj.__connection)))) 24 | 25 | lib.mysql_close(obj.__connection) 26 | 27 | return false 28 | end 29 | 30 | setmetatable(obj, MySQL) 31 | return obj 32 | end 33 | 34 | function MySQL:ping() 35 | return lib.mysql_ping(self.__connection) 36 | end 37 | 38 | function MySQL:query(query, ...) 39 | 40 | assert(query, "[MySQL:query] Query is required. Line: " .. tostring(debug.getinfo(2).currentline)) 41 | 42 | if self:ping() ~= 0 then 43 | logError("[MySQL:query] Couldn't execute query: connection is probably dead. Line: " .. tostring(debug.getinfo(2).currentline)) 44 | return false 45 | end 46 | 47 | local arguments = {select(1, ...)} 48 | if type(arguments[1]) == "table" then 49 | for key, value in pairs(arguments[1]) do 50 | query = query:gsub(string.format(":%s", key), self:escape(value)[1], 1) 51 | end 52 | else 53 | local escapedArguments = self:escape(unpack(arguments)) 54 | for i, argument in ipairs(escapedArguments) do 55 | if type(argument) == "string" then argument = string.format('"%s"', argument) end 56 | query = query:gsub("?", argument, 1) 57 | end 58 | end 59 | 60 | local result = lib.mysql_query(self.__connection, query) 61 | if result ~= 0 then 62 | logError("[MySQL] Could not execute query @ line " .. tostring(debug.getinfo(2).currentline) .. ":") 63 | logError(" Error Code: " .. tostring(lib.mysql_errno(self.__connection))) 64 | logError(" Error: " .. tostring(ffi.string(lib.mysql_error(self.__connection)))) 65 | 66 | return false 67 | end 68 | 69 | local result = lib.mysql_store_result(self.__connection) 70 | if result == nullptr then 71 | return { 72 | insertId = tonumber(lib.mysql_insert_id(self.__connection)), 73 | affectedRows = tonumber(lib.mysql_affected_rows(self.__connection)) 74 | } 75 | end 76 | 77 | local fieldsNum = lib.mysql_num_fields(result) 78 | local fields = lib.mysql_fetch_fields(result) 79 | local fieldTable = {} 80 | 81 | for i = 0, fieldsNum - 1 do 82 | local field = fields[i] 83 | table.insert(fieldTable, {name = ffi.string(field.name), func = rowType[tonumber(field.type)]}) 84 | end 85 | 86 | local resultSet = {} 87 | local rowsNum = tonumber(lib.mysql_num_rows(result)) 88 | for i = 0, rowsNum - 1 do 89 | local row = lib.mysql_fetch_row(result) 90 | local rowData = {} 91 | 92 | for i = 1, fieldsNum do 93 | local field = fieldTable[i] 94 | 95 | rowData[field.name] = field.func(ffi.string(row[i - 1])) 96 | end 97 | 98 | table.insert(resultSet, rowData) 99 | end 100 | 101 | if rowsNum == 1 then 102 | resultSet = resultSet[1] 103 | end 104 | 105 | lib.mysql_free_result(result) 106 | 107 | return resultSet 108 | end 109 | 110 | function MySQL:escape(...) 111 | 112 | local result = {} 113 | for _, v in ipairs({select(1, ...)}) do 114 | local insert = nil 115 | 116 | if(type(v) == "string") then 117 | local source = ffi.new("char[?]", v:len()) 118 | ffi.copy(source, v) 119 | 120 | local destination = ffi.new("char[?]", v:len() * 2 + 1) 121 | lib.mysql_real_escape_string(self.__connection, destination, source, v:len()) 122 | 123 | insert = ffi.string(destination) 124 | elseif type(v) == "number" then 125 | insert = v 126 | end 127 | 128 | table.insert(result, insert) 129 | end 130 | 131 | return result 132 | end 133 | 134 | function MySQL:close() 135 | if self.__connection then 136 | lib.mysql_close(self.__connection) 137 | 138 | return true 139 | end 140 | 141 | return false 142 | end 143 | 144 | return MySQL -------------------------------------------------------------------------------- /scripts/sqlite3/SQLite3/libs/linux64/sqlite3.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drakeee/altv-lua-module/f3d18e7ef7f5c7ec089a8652ce02865720385960/scripts/sqlite3/SQLite3/libs/linux64/sqlite3.so -------------------------------------------------------------------------------- /scripts/sqlite3/SQLite3/libs/win64/sqlite3.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drakeee/altv-lua-module/f3d18e7ef7f5c7ec089a8652ce02865720385960/scripts/sqlite3/SQLite3/libs/win64/sqlite3.dll -------------------------------------------------------------------------------- /scripts/sqlite3/SQLite3/sqlite3_ffi.lua: -------------------------------------------------------------------------------- 1 | local ffi = require("ffi") 2 | local bit = require("bit") 3 | 4 | ffi.cdef [[ 5 | typedef struct sqlite3 sqlite3; 6 | typedef struct sqlite3_stmt sqlite3_stmt; 7 | typedef long long int sqlite3_int64; 8 | 9 | enum sqlite3_bit_flags { 10 | SQLITE_OPEN_READONLY = 0x00000001, /* Ok for sqlite3_open_v2() */ 11 | SQLITE_OPEN_READWRITE = 0x00000002, /* Ok for sqlite3_open_v2() */ 12 | SQLITE_OPEN_CREATE = 0x00000004, /* Ok for sqlite3_open_v2() */ 13 | SQLITE_OPEN_URI = 0x00000040, /* Ok for sqlite3_open_v2() */ 14 | SQLITE_OPEN_MEMORY = 0x00000080, /* Ok for sqlite3_open_v2() */ 15 | SQLITE_OPEN_NOMUTEX = 0x00008000, /* Ok for sqlite3_open_v2() */ 16 | SQLITE_OPEN_FULLMUTEX = 0x00010000, /* Ok for sqlite3_open_v2() */ 17 | SQLITE_OPEN_SHAREDCACHE = 0x00020000, /* Ok for sqlite3_open_v2() */ 18 | SQLITE_OPEN_PRIVATECACHE = 0x00040000, /* Ok for sqlite3_open_v2() */ 19 | SQLITE_OPEN_NOFOLLOW = 0x01000000 /* Ok for sqlite3_open_v2() */ 20 | }; 21 | 22 | enum sqlite3_error_codes { 23 | SQLITE_OK = 0, /* Successful result */ 24 | SQLITE_ERROR = 1, /* Generic error */ 25 | SQLITE_INTERNAL = 2, /* Internal logic error in SQLite */ 26 | SQLITE_PERM = 3, /* Access permission denied */ 27 | SQLITE_ABORT = 4, /* Callback routine requested an abort */ 28 | SQLITE_BUSY = 5, /* The database file is locked */ 29 | SQLITE_LOCKED = 6, /* A table in the database is locked */ 30 | SQLITE_NOMEM = 7, /* A malloc() failed */ 31 | SQLITE_READONLY = 8, /* Attempt to write a readonly database */ 32 | SQLITE_INTERRUPT = 9, /* Operation terminated by sqlite3_interrupt()*/ 33 | SQLITE_IOERR = 10, /* Some kind of disk I/O error occurred */ 34 | SQLITE_CORRUPT = 11, /* The database disk image is malformed */ 35 | SQLITE_NOTFOUND = 12, /* Unknown opcode in sqlite3_file_control() */ 36 | SQLITE_FULL = 13, /* Insertion failed because database is full */ 37 | SQLITE_CANTOPEN = 14, /* Unable to open the database file */ 38 | SQLITE_PROTOCOL = 15, /* Database lock protocol error */ 39 | SQLITE_EMPTY = 16, /* Internal use only */ 40 | SQLITE_SCHEMA = 17, /* The database schema changed */ 41 | SQLITE_TOOBIG = 18, /* String or BLOB exceeds size limit */ 42 | SQLITE_CONSTRAINT = 19, /* Abort due to constraint violation */ 43 | SQLITE_MISMATCH = 20, /* Data type mismatch */ 44 | SQLITE_MISUSE = 21, /* Library used incorrectly */ 45 | SQLITE_NOLFS = 22, /* Uses OS features not supported on host */ 46 | SQLITE_AUTH = 23, /* Authorization denied */ 47 | SQLITE_FORMAT = 24, /* Not used */ 48 | SQLITE_RANGE = 25, /* 2nd parameter to sqlite3_bind out of range */ 49 | SQLITE_NOTADB = 26, /* File opened that is not a database file */ 50 | SQLITE_NOTICE = 27, /* Notifications from sqlite3_log() */ 51 | SQLITE_WARNING = 28, /* Warnings from sqlite3_log() */ 52 | SQLITE_ROW = 100, /* sqlite3_step() has another row ready */ 53 | SQLITE_DONE = 101 /* sqlite3_step() has finished executing */ 54 | }; 55 | 56 | enum sqlite3_column_types { 57 | SQLITE_INTEGER = 1, 58 | SQLITE_FLOAT = 2, 59 | SQLITE_TEXT = 3, 60 | SQLITE_BLOB = 4, 61 | SQLITE_NULL = 5 62 | }; 63 | 64 | int sqlite3_open_v2( 65 | const char *filename, /* Database filename (UTF-8) */ 66 | sqlite3 **ppDb, /* OUT: SQLite db handle */ 67 | int flags, /* Flags */ 68 | const char *zVfs /* Name of VFS module to use */ 69 | ); 70 | int sqlite3_close_v2(sqlite3*); 71 | 72 | int sqlite3_errcode(sqlite3 *db); 73 | int sqlite3_extended_errcode(sqlite3 *db); 74 | const char *sqlite3_errmsg(sqlite3*); 75 | const char *sqlite3_errstr(int); 76 | 77 | int sqlite3_prepare_v2( 78 | sqlite3 *db, /* Database handle */ 79 | const char *zSql, /* SQL statement, UTF-8 encoded */ 80 | int nByte, /* Maximum length of zSql in bytes. */ 81 | sqlite3_stmt **ppStmt, /* OUT: Statement handle */ 82 | const char **pzTail /* OUT: Pointer to unused portion of zSql */ 83 | ); 84 | 85 | int sqlite3_bind_double(sqlite3_stmt*, int, double); 86 | int sqlite3_bind_int(sqlite3_stmt*, int, int); 87 | //int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64); 88 | int sqlite3_bind_null(sqlite3_stmt*, int); 89 | int sqlite3_bind_text(sqlite3_stmt*,int,const char*,int,void(*)(void*)); 90 | 91 | int sqlite3_column_count(sqlite3_stmt *pStmt); 92 | int sqlite3_column_type(sqlite3_stmt*, int iCol); 93 | const char *sqlite3_column_name(sqlite3_stmt*, int N); 94 | const unsigned char *sqlite3_column_text(sqlite3_stmt*, int iCol); 95 | 96 | int sqlite3_step(sqlite3_stmt*); 97 | int sqlite3_finalize(sqlite3_stmt *pStmt); 98 | int sqlite3_bind_parameter_count(sqlite3_stmt*); 99 | sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*); 100 | int sqlite3_changes(sqlite3*); 101 | ]] 102 | 103 | local nullptr = ffi.cast("void*", 0) 104 | local extension = (ffi.os == "Windows" and ".dll" or ".so") 105 | 106 | function script_path() 107 | local str = debug.getinfo(1, "S").source:sub(2) 108 | 109 | if ffi.os == "Windows" then 110 | return str:match("(.*[/\\])") 111 | else 112 | return str:match("(.*/)") 113 | end 114 | end 115 | 116 | local lib = nil 117 | local result = pcall(function() 118 | local library = string.format("%s/libs/%s/sqlite3%s", script_path(), (ffi.os == "Windows" and "win64" or "linux64"), extension) 119 | lib = ffi.load(library, true) 120 | end) 121 | 122 | if not result then 123 | logError(string.format("[SQLite3] Unable to load sqlite3: couldn't find \"sqlite3%s\" library", extension)) 124 | logError(string.format("[SQLite3] Please make sure that \"sqlite3%s\" exists inside \"modules/lua-module\" folder.", extension)) 125 | return false 126 | end 127 | 128 | return lib -------------------------------------------------------------------------------- /scripts/sqlite3/SQLite3/sqlite3_row.lua: -------------------------------------------------------------------------------- 1 | local lib = require("SQLite3.sqlite3_ffi") 2 | 3 | local read_funcs = {} 4 | read_funcs[lib.SQLITE_INTEGER] = tonumber 5 | read_funcs[lib.SQLITE_FLOAT] = tonumber 6 | read_funcs[lib.SQLITE_TEXT] = tostring 7 | read_funcs[lib.SQLITE_BLOB] = tostring 8 | read_funcs[lib.SQLITE_NULL] = tostring 9 | 10 | return read_funcs -------------------------------------------------------------------------------- /scripts/sqlite3/sqlite3.lua: -------------------------------------------------------------------------------- 1 | local ffi = require("ffi") 2 | local lib = require("SQLite3.sqlite3_ffi") 3 | local rowType = require("SQLite3.sqlite3_row") 4 | 5 | local function isInteger(number) 6 | return math.floor(number) == number 7 | end 8 | 9 | local SQLite = {} 10 | SQLite.__index = SQLite 11 | 12 | function SQLite:connect(database, readOnly) 13 | 14 | assert(database, "[SQLite3:connect] Database is required. Line: " .. tostring(debug.getinfo(2).currentline)) 15 | readOnly = readOnly or false 16 | local flags = readOnly and lib.SQLITE_OPEN_READONLY or bit.bor(lib.SQLITE_OPEN_READWRITE, lib.SQLITE_OPEN_CREATE) 17 | 18 | local obj = {} 19 | obj.__connection = ffi.new("sqlite3*[1]") 20 | 21 | if lib.sqlite3_open_v2(localResource.path .. "test.db", obj.__connection, flags, nil) ~= lib.SQLITE_OK then 22 | logError("[SQLite3] Could not open the database: ") 23 | logError(" Error Code: " .. tostring(lib.sqlite3_errcode(obj.__connection[0]))) 24 | logError(" Error: " .. tostring(ffi.string(lib.sqlite3_errmsg(obj.__connection[0])))) 25 | 26 | lib.sqlite3_close_v2(obj.__connection[0]) 27 | 28 | return false 29 | end 30 | 31 | setmetatable(obj, SQLite) 32 | return obj 33 | end 34 | 35 | function SQLite:query(query, ...) 36 | 37 | assert(query, "[SQLite3] Query parameter is required. Line: " .. tostring(debug.getinfo(2).currentline)) 38 | 39 | if not self.__connection then 40 | logError("[SQLite3:query] Couldn't execute query: connection is probably dead. Line: " .. tostring(debug.getinfo(2).currentline)) 41 | return false 42 | end 43 | 44 | local arguments = {select(1, ...)} 45 | 46 | local stmt = ffi.new("sqlite3_stmt*[1]") 47 | local result = lib.sqlite3_prepare_v2(self.__connection[0], query, -1, stmt, nil) 48 | 49 | if result ~= lib.SQLITE_OK then 50 | logError("[SQLite3:query] Could not prepare query @ line " .. tostring(debug.getinfo(2).currentline) .. ":") 51 | logError(" Error Code: " .. tostring(lib.sqlite3_errcode(self.__connection[0]))) 52 | logError(" Error: " .. tostring(ffi.string(lib.sqlite3_errmsg(self.__connection[0])))) 53 | 54 | return false 55 | end 56 | 57 | local paramCount = lib.sqlite3_bind_parameter_count(stmt[0]) 58 | if paramCount ~= #arguments then 59 | logError("[SQLite3:query] Function arguments count doesn't match query parameter count.") 60 | 61 | lib.sqlite3_finalize(stmt[0]) 62 | return false 63 | end 64 | 65 | for index, argument in ipairs(arguments) do 66 | if type(argument) == "string" then 67 | lib.sqlite3_bind_text(stmt[0], index, argument, argument:len(), nil) 68 | elseif type(argument) == "number" then 69 | lib[isInteger(argument) and "sqlite3_bind_int" or "sqlite3_bind_double"](stmt[0], index, argument) 70 | elseif type(argument) == "nil" then 71 | lib.sqlite3_bind_null(stmt[0], index) 72 | end 73 | end 74 | 75 | local columnCount = tonumber(lib.sqlite3_column_count(stmt[0])) 76 | local processedRow = 0 77 | local resultSet = {} 78 | while lib.sqlite3_step(stmt[0]) == lib.SQLITE_ROW do 79 | processedRow = processedRow + 1 80 | local rowData = {} 81 | 82 | for i = 0, columnCount - 1 do 83 | local columnType = tonumber(lib.sqlite3_column_type(stmt[0], i)) 84 | local columnName = tostring(ffi.string(lib.sqlite3_column_name(stmt[0], i))) 85 | local columnData = rowType[columnType](ffi.string(lib.sqlite3_column_text(stmt[0], i))) 86 | 87 | if columnName == "?" then columnName = columnData end 88 | 89 | rowData[columnName] = columnData 90 | end 91 | 92 | table.insert(resultSet, rowData) 93 | end 94 | 95 | if processedRow == 1 then 96 | resultSet = resultSet[1] 97 | elseif processedRow == 0 then 98 | resultSet = { 99 | lastInsertId = tonumber(lib.sqlite3_last_insert_rowid(self.__connection[0])), 100 | affectedRows = tonumber(lib.sqlite3_changes(self.__connection[0])) 101 | } 102 | end 103 | 104 | lib.sqlite3_finalize(stmt[0]) 105 | 106 | return resultSet 107 | end 108 | 109 | function SQLite:close() 110 | 111 | if not self.__connection then 112 | logError("[SQLite3] Connection is not open") 113 | return false 114 | end 115 | 116 | lib.sqlite3_close_v2(self.__connection[0]) 117 | 118 | return true 119 | end 120 | 121 | return SQLite -------------------------------------------------------------------------------- /src/Defs/Alt.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace lua::Class 6 | { 7 | class Alt 8 | { 9 | public: 10 | enum class LogType 11 | { 12 | LOG_INFO = 0, 13 | LOG_DEBUG, 14 | LOG_WARNING, 15 | LOG_ERROR, 16 | LOG_COLORED 17 | }; 18 | 19 | public: 20 | static const char* ClassName; 21 | static void Init(lua_State* L); 22 | 23 | private: 24 | static int AltIndex(lua_State* L); 25 | 26 | static int dofile(lua_State* L); 27 | static int inext(lua_State* L); 28 | static int pairs(lua_State* L); 29 | static int ipairs(lua_State* L); 30 | static int ipairsaux(lua_State* L); 31 | 32 | static int NextTick(lua_State* L); 33 | static int EveryTick(lua_State* L); 34 | static int SetTimeout(lua_State* L); 35 | static int SetInterval(lua_State* L); 36 | static int ClearTimer(lua_State* L); 37 | 38 | static int Log(lua_State* L, LogType logtype = LogType::LOG_INFO); 39 | static int LogInfo(lua_State* L); 40 | static int LogDebug(lua_State* L); 41 | static int LogWarning(lua_State* L); 42 | static int LogError(lua_State* L); 43 | static int LogColored(lua_State* L); 44 | 45 | static int SetMetaData(lua_State* L); 46 | static int GetMetaData(lua_State* L); 47 | static int DeleteMetaData(lua_State* L); 48 | static int HasMetaData(lua_State* L); 49 | static int GetSyncedMetaData(lua_State* L); 50 | static int HasSyncedMetaData(lua_State* L); 51 | 52 | static int GetRequiredPermissions(lua_State* L); 53 | static int GetOptionalPermissions(lua_State* L); 54 | 55 | static int OnServer(lua_State* L); 56 | static int OffServer(lua_State* L); 57 | static int OnClient(lua_State* L); 58 | static int OffClient(lua_State* L); 59 | 60 | static int EmitServer(lua_State* L); 61 | static int EmitClient(lua_State* L); 62 | 63 | static int Export(lua_State* L); 64 | 65 | static int IsDebug(lua_State* L); 66 | static int FileExists(lua_State* L); 67 | static int FileRead(lua_State* L); 68 | static int GetEntityByID(lua_State* L); 69 | static int GetVersion(lua_State* L); 70 | static int GetBranch(lua_State* L); 71 | 72 | static int Hash(lua_State* L); 73 | static int StringToSHA256(lua_State* L); 74 | 75 | static int GetModuleTime(lua_State* L); 76 | 77 | #ifdef ALT_SERVER_API 78 | static int EmitClientAll(lua_State* L); 79 | 80 | static int GetRootDirectory(lua_State* L); 81 | 82 | static int StartResource(lua_State* L); 83 | static int StopResource(lua_State* L); 84 | static int RestartResource(lua_State* L); 85 | 86 | static int SetSyncedMetaData(lua_State* L); 87 | static int DeleteSyncedMetaData(lua_State* L); 88 | 89 | static int GetPlayersByName(lua_State* L); 90 | 91 | static int GetNetTime(lua_State* L); 92 | 93 | static int SetPassword(lua_State* L); 94 | static int HashServerPassword(lua_State* L); 95 | 96 | static int StopServer(lua_State* L); 97 | 98 | static int GetVehicleModelByHash(lua_State* L); 99 | #else 100 | static int require(lua_State* L); 101 | 102 | //virtual alt::IPackage::PathInfo Resolve(IResource* resource, alt::StringView path, StringView currentModulePath) const = 0; //TODO? 103 | static int SetCharStat(lua_State* L); //done 104 | static int GetCharStat(lua_State* L); //done 105 | static int ResetCharStat(lua_State* L); //done 106 | 107 | //static int IsSandbox(lua_State* L); //done 108 | static int IsKeyDown(lua_State* L); //done 109 | static int IsKeyToggled(lua_State* L); //done 110 | static int AreControlsEnabled(lua_State* L); //done 111 | static int SetCursorPosition(lua_State* L); //done 112 | static int GetCursorPosition(lua_State* L); //done 113 | static int SetConfigFlag(lua_State* L); //done 114 | static int GetConfigFlag(lua_State* L); //done 115 | static int DoesConfigFlagExist(lua_State* L); //done 116 | 117 | static int GetLicenseHash(lua_State* L); //done 118 | static int GetLocale(lua_State* L); //done 119 | static int IsInStreamerMode(lua_State* L); //done 120 | static int IsMenuOpen(lua_State* L); //done 121 | static int IsConsoleOpen(lua_State* L); //done 122 | 123 | static int ToggleGameControls(lua_State* L); 124 | static int ShowCursor(lua_State* L); 125 | 126 | //virtual const Array GetAllNatives() const = 0; 127 | //virtual Ref CreateNativesContext() const = 0; 128 | 129 | static int GetTextureFromDrawable(lua_State* L); //done 130 | 131 | static int RequestIPL(lua_State* L); //done 132 | static int RemoveIPL(lua_State* L); //done 133 | 134 | static int BeginScaleformMovieMethodMinimap(lua_State* L); //done 135 | 136 | static int GetMsPerGameMinute(lua_State* L); //done 137 | static int SetMsPerGameMinute(lua_State* L); //done 138 | static int SetWeatherCycle(lua_State* L); //done 139 | static int SetWeatherSyncActive(lua_State* L); //done 140 | 141 | static int SetCamFrozen(lua_State* L); //done 142 | 143 | static int GetPermissionState(lua_State* L); //done 144 | 145 | static int TakeScreenshot(lua_State* L); //done 146 | static int TakeScreenshotGameOnly(lua_State* L); //done 147 | 148 | static int SetAngularVelocity(lua_State* L); //done 149 | 150 | static int IsGameFocused(lua_State* L); //done 151 | 152 | static int LoadModel(lua_State* L); 153 | static int LoadModelAsync(lua_State* L); 154 | 155 | static int LoadYtyp(lua_State* L); 156 | static int UnloadYtyp(lua_State* L); 157 | 158 | static int GetHeadshotBase64(lua_State* L); 159 | 160 | static int SetDlcClothes(lua_State* L); 161 | static int SetDlcProps(lua_State* L); 162 | static int ClearProps(lua_State* L); 163 | 164 | static int SetWatermarkPosition(lua_State* L); 165 | 166 | static int GetFps(lua_State* L); 167 | static int GetPing(lua_State* L); 168 | static int GetTotalPacketsSent(lua_State* L); 169 | static int GetTotalPacketsLost(lua_State* L); 170 | static int GetServerIp(lua_State* L); 171 | static int GetServerPort(lua_State* L); 172 | static int GetClientPath(lua_State* L); 173 | 174 | static int HasLocalMetaData(lua_State* L); 175 | static int GetLocalMetaData(lua_State* L); 176 | 177 | static int CopyToClipboard(lua_State* L); 178 | 179 | static int ToggleRmlDebugger(lua_State* L); 180 | static int LoadRmlFontFace(lua_State* L); 181 | static int ToggleRmlControls(lua_State* L); 182 | 183 | static int WorldToScreen(lua_State* L); 184 | static int ScreenToWorld(lua_State* L); 185 | static int GetCamPos(lua_State* L); 186 | static int GetScreenResolution(lua_State* L); 187 | 188 | static int SetMinimapComponentPosition(lua_State* L); 189 | static int SetMinimapIsRectangle(lua_State* L); 190 | #endif 191 | }; 192 | } -------------------------------------------------------------------------------- /src/Defs/Client/Audio.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #ifdef ALT_CLIENT_API 6 | 7 | namespace lua::Class 8 | { 9 | class Audio 10 | { 11 | public: 12 | static const char* ClassName; 13 | static void Init(lua_State* L); 14 | 15 | private: 16 | static int CreateAudio(lua_State* L); 17 | static int On(lua_State* L); 18 | static int Off(lua_State* L); 19 | 20 | static int SetSource(lua_State* L); //data/file/url 21 | static int GetSource(lua_State* L); 22 | 23 | static int SetLoop(lua_State* L); 24 | static int SetVolume(lua_State* L); //0.0 - 1.0 range 25 | static int SetCategory(lua_State* L); //default: radio 26 | 27 | static int IsLoop(lua_State* L); 28 | static int GetVolume(lua_State* L); 29 | static int GetCategory(lua_State* L); 30 | 31 | static int IsFrontendPlay(lua_State* L); 32 | 33 | static int AddOutput(lua_State* L); 34 | static int RemoveOutput(lua_State* L); 35 | static int GetOutputs(lua_State* L); 36 | 37 | static int Play(lua_State* L); 38 | static int Pause(lua_State* L); 39 | static int Reset(lua_State* L); 40 | static int GetCurrentTime(lua_State* L); //seconds 41 | static int GetMaxTime(lua_State* L); //seconds 42 | static int Seek(lua_State* L); //seconds 43 | static int IsPlaying(lua_State* L); 44 | }; 45 | } 46 | 47 | #endif -------------------------------------------------------------------------------- /src/Defs/Client/DiscordManager.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifdef ALT_CLIENT_API 4 | namespace lua::Class 5 | { 6 | const char* DiscordManager::ClassName = "Discord"; 7 | void DiscordManager::Init(lua_State* L) 8 | { 9 | DEBUG_INFO("DiscordManager::Init"); 10 | 11 | lua_globalfunction(L, "getCurrentUser", GetCurrentUser); 12 | 13 | lua_beginclass(L, DiscordManager::ClassName); 14 | { 15 | lua_classfunction(L, "getCurrentUser", GetCurrentUser); 16 | 17 | lua_classvariable(L, "currentUser", nullptr, "getCurrentUser"); 18 | } 19 | lua_endclass(L); 20 | 21 | DEBUG_INFO("DiscordManager::Init ...done"); 22 | } 23 | 24 | int DiscordManager::GetCurrentUser(lua_State* L) 25 | { 26 | auto discord = alt::ICore::Instance().GetDiscordManager(); 27 | if (discord->IsUserDataReady()) 28 | { 29 | lua_newtable(L); 30 | 31 | lua_pushstring(L, std::to_string(discord->GetUserID())); 32 | lua_setfield(L, -2, "id"); 33 | 34 | lua_pushstring(L, discord->GetUsername()); 35 | lua_setfield(L, -2, "name"); 36 | 37 | lua_pushstring(L, discord->GetDiscriminator()); 38 | lua_setfield(L, -2, "discriminator"); 39 | 40 | lua_pushstring(L, discord->GetAvatar()); 41 | lua_setfield(L, -2, "avatar"); 42 | } 43 | else 44 | { 45 | lua_pushnil(L); 46 | } 47 | 48 | return 1; 49 | } 50 | } 51 | #endif -------------------------------------------------------------------------------- /src/Defs/Client/DiscordManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #ifdef ALT_CLIENT_API 6 | namespace lua::Class 7 | { 8 | class DiscordManager 9 | { 10 | public: 11 | static const char* ClassName; 12 | static void Init(lua_State* L); 13 | 14 | private: 15 | static int GetCurrentUser(lua_State* L); 16 | }; 17 | } 18 | #endif -------------------------------------------------------------------------------- /src/Defs/Client/HandlingData.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #ifdef ALT_CLIENT_API 6 | namespace lua::Class 7 | { 8 | class HandlingData 9 | { 10 | public: 11 | static const char* ClassName; 12 | static void Init(lua_State* L); 13 | 14 | private: 15 | static int GetHandlingData(lua_State* L); 16 | static int GetHandlingNameHash(lua_State* L); 17 | static int GetMass(lua_State* L); 18 | static int GetInitialDragCoeff(lua_State* L); 19 | static int GetDownforceModifier(lua_State* L); 20 | static int GetunkFloat1(lua_State* L); 21 | static int GetunkFloat2(lua_State* L); 22 | static int GetCentreOfMassOffset(lua_State* L); 23 | static int GetInertiaMultiplier(lua_State* L); 24 | static int GetPercentSubmerged(lua_State* L); 25 | static int GetPercentSubmergedRatio(lua_State* L); 26 | static int GetDriveBiasFront(lua_State* L); 27 | static int GetAcceleration(lua_State* L); 28 | static int GetInitialDriveGears(lua_State* L); 29 | static int GetDriveInertia(lua_State* L); 30 | static int GetClutchChangeRateScaleUpShift(lua_State* L); 31 | static int GetClutchChangeRateScaleDownShift(lua_State* L); 32 | static int GetInitialDriveForce(lua_State* L); 33 | static int GetDriveMaxFlatVel(lua_State* L); 34 | static int GetInitialDriveMaxFlatVel(lua_State* L); 35 | static int GetBrakeForce(lua_State* L); 36 | static int GetunkFloat4(lua_State* L); 37 | static int GetBrakeBiasFront(lua_State* L); 38 | static int GetBrakeBiasRear(lua_State* L); 39 | static int GetHandBrakeForce(lua_State* L); 40 | static int GetSteeringLock(lua_State* L); 41 | static int GetSteeringLockRatio(lua_State* L); 42 | static int GetTractionCurveMax(lua_State* L); 43 | static int GetTractionCurveMaxRatio(lua_State* L); 44 | static int GetTractionCurveMin(lua_State* L); 45 | static int GetTractionCurveMinRatio(lua_State* L); 46 | static int GetTractionCurveLateral(lua_State* L); 47 | static int GetTractionCurveLateralRatio(lua_State* L); 48 | static int GetTractionSpringDeltaMax(lua_State* L); 49 | static int GetTractionSpringDeltaMaxRatio(lua_State* L); 50 | static int GetLowSpeedTractionLossMult(lua_State* L); 51 | static int GetCamberStiffness(lua_State* L); 52 | static int GetTractionBiasFront(lua_State* L); 53 | static int GetTractionBiasRear(lua_State* L); 54 | static int GetTractionLossMult(lua_State* L); 55 | static int GetSuspensionForce(lua_State* L); 56 | static int GetSuspensionCompDamp(lua_State* L); 57 | static int GetSuspensionReboundDamp(lua_State* L); 58 | static int GetSuspensionUpperLimit(lua_State* L); 59 | static int GetSuspensionLowerLimit(lua_State* L); 60 | static int GetSuspensionRaise(lua_State* L); 61 | static int GetSuspensionBiasFront(lua_State* L); 62 | static int GetSuspensionBiasRear(lua_State* L); 63 | static int GetAntiRollBarForce(lua_State* L); 64 | static int GetAntiRollBarBiasFront(lua_State* L); 65 | static int GetAntiRollBarBiasRear(lua_State* L); 66 | static int GetRollCentreHeightFront(lua_State* L); 67 | static int GetRollCentreHeightRear(lua_State* L); 68 | static int GetCollisionDamageMult(lua_State* L); 69 | static int GetWeaponDamageMult(lua_State* L); 70 | static int GetDeformationDamageMult(lua_State* L); 71 | static int GetEngineDamageMult(lua_State* L); 72 | static int GetPetrolTankVolume(lua_State* L); 73 | static int GetOilVolume(lua_State* L); 74 | static int GetunkFloat5(lua_State* L); 75 | static int GetSeatOffsetDistX(lua_State* L); 76 | static int GetSeatOffsetDistY(lua_State* L); 77 | static int GetSeatOffsetDistZ(lua_State* L); 78 | static int GetMonetaryValue(lua_State* L); 79 | static int GetModelFlags(lua_State* L); 80 | static int GetHandlingFlags(lua_State* L); 81 | static int GetDamageFlags(lua_State* L); 82 | 83 | static int SetMass(lua_State* L); 84 | static int SetInitialDragCoeff(lua_State* L); 85 | static int SetDownforceModifier(lua_State* L); 86 | static int SetunkFloat1(lua_State* L); 87 | static int SetunkFloat2(lua_State* L); 88 | static int SetCentreOfMassOffset(lua_State* L); 89 | static int SetInertiaMultiplier(lua_State* L); 90 | static int SetPercentSubmerged(lua_State* L); 91 | static int SetPercentSubmergedRatio(lua_State* L); 92 | static int SetDriveBiasFront(lua_State* L); 93 | static int SetAcceleration(lua_State* L); 94 | static int SetInitialDriveGears(lua_State* L); 95 | static int SetDriveInertia(lua_State* L); 96 | static int SetClutchChangeRateScaleUpShift(lua_State* L); 97 | static int SetClutchChangeRateScaleDownShift(lua_State* L); 98 | static int SetInitialDriveForce(lua_State* L); 99 | static int SetDriveMaxFlatVel(lua_State* L); 100 | static int SetInitialDriveMaxFlatVel(lua_State* L); 101 | static int SetBrakeForce(lua_State* L); 102 | static int SetunkFloat4(lua_State* L); 103 | static int SetBrakeBiasFront(lua_State* L); 104 | static int SetBrakeBiasRear(lua_State* L); 105 | static int SetHandBrakeForce(lua_State* L); 106 | static int SetSteeringLock(lua_State* L); 107 | static int SetSteeringLockRatio(lua_State* L); 108 | static int SetTractionCurveMax(lua_State* L); 109 | static int SetTractionCurveMaxRatio(lua_State* L); 110 | static int SetTractionCurveMin(lua_State* L); 111 | static int SetTractionCurveMinRatio(lua_State* L); 112 | static int SetTractionCurveLateral(lua_State* L); 113 | static int SetTractionCurveLateralRatio(lua_State* L); 114 | static int SetTractionSpringDeltaMax(lua_State* L); 115 | static int SetTractionSpringDeltaMaxRatio(lua_State* L); 116 | static int SetLowSpeedTractionLossMult(lua_State* L); 117 | static int SetCamberStiffness(lua_State* L); 118 | static int SetTractionBiasFront(lua_State* L); 119 | static int SetTractionBiasRear(lua_State* L); 120 | static int SetTractionLossMult(lua_State* L); 121 | static int SetSuspensionForce(lua_State* L); 122 | static int SetSuspensionCompDamp(lua_State* L); 123 | static int SetSuspensionReboundDamp(lua_State* L); 124 | static int SetSuspensionUpperLimit(lua_State* L); 125 | static int SetSuspensionLowerLimit(lua_State* L); 126 | static int SetSuspensionRaise(lua_State* L); 127 | static int SetSuspensionBiasFront(lua_State* L); 128 | static int SetSuspensionBiasRear(lua_State* L); 129 | static int SetAntiRollBarForce(lua_State* L); 130 | static int SetAntiRollBarBiasFront(lua_State* L); 131 | static int SetAntiRollBarBiasRear(lua_State* L); 132 | static int SetRollCentreHeightFront(lua_State* L); 133 | static int SetRollCentreHeightRear(lua_State* L); 134 | static int SetCollisionDamageMult(lua_State* L); 135 | static int SetWeaponDamageMult(lua_State* L); 136 | static int SetDeformationDamageMult(lua_State* L); 137 | static int SetEngineDamageMult(lua_State* L); 138 | static int SetPetrolTankVolume(lua_State* L); 139 | static int SetOilVolume(lua_State* L); 140 | static int SetunkFloat5(lua_State* L); 141 | static int SetSeatOffsetDistX(lua_State* L); 142 | static int SetSeatOffsetDistY(lua_State* L); 143 | static int SetSeatOffsetDistZ(lua_State* L); 144 | static int SetMonetaryValue(lua_State* L); 145 | static int SetModelFlags(lua_State* L); 146 | static int SetHandlingFlags(lua_State* L); 147 | static int SetDamageFlags(lua_State* L); 148 | }; 149 | } 150 | #endif -------------------------------------------------------------------------------- /src/Defs/Client/MapData.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifdef ALT_CLIENT_API 4 | namespace lua::Class 5 | { 6 | const char* MapData::ClassName = "MapZoomData"; 7 | void MapData::Init(lua_State* L) 8 | { 9 | DEBUG_INFO("MapData::Init"); 10 | 11 | lua_beginclass(L, MapData::ClassName); 12 | { 13 | lua_classfunction(L, "get", Get); 14 | lua_classfunction(L, "reset", Reset); 15 | lua_classfunction(L, "resetAll", ResetAll); 16 | 17 | lua_classfunction(L, "getZoomScale", GetZoomScale); 18 | lua_classfunction(L, "getZoomSpeed", GetZoomSpeed); 19 | lua_classfunction(L, "getScrollSpeed", GetScrollSpeed); 20 | lua_classfunction(L, "getTilesCountX", GetTilesCountX); 21 | lua_classfunction(L, "getTilesCountY", GetTilesCountY); 22 | 23 | lua_classfunction(L, "setZoomScale", SetZoomScale); 24 | lua_classfunction(L, "setZoomSpeed", SetZoomSpeed); 25 | lua_classfunction(L, "setScrollSpeed", SetScrollSpeed); 26 | lua_classfunction(L, "setTilesCountX", SetTilesCountX); 27 | lua_classfunction(L, "setTilesCountY", SetTilesCountY); 28 | 29 | lua_classvariable(L, "zoomScale", SetZoomScale, GetZoomScale); 30 | lua_classvariable(L, "zoomSpeed", SetZoomSpeed, GetZoomSpeed); 31 | lua_classvariable(L, "scrollSpeed", SetScrollSpeed, GetScrollSpeed); 32 | lua_classvariable(L, "tilesCountX", SetTilesCountX, GetTilesCountX); 33 | lua_classvariable(L, "tilesCountY", SetTilesCountY, GetTilesCountY); 34 | 35 | //JS alias 36 | lua_classvariable(L, "fZoomScale", SetZoomScale, GetZoomScale); 37 | lua_classvariable(L, "fZoomSpeed", SetZoomSpeed, GetZoomSpeed); 38 | lua_classvariable(L, "fScrollSpeed", SetScrollSpeed, GetScrollSpeed); 39 | lua_classvariable(L, "vTilesX", SetTilesCountX, GetTilesCountX); 40 | lua_classvariable(L, "vTilesY", SetTilesCountY, GetTilesCountY); 41 | } 42 | lua_endclass(L); 43 | 44 | DEBUG_INFO("MapData::Init ...done"); 45 | } 46 | 47 | int MapData::CreateMapZoom(lua_State* L) 48 | { 49 | ArgumentReader argReader(L); 50 | 51 | if (argReader.IsCurrentType(LUA_TNUMBER)) 52 | { 53 | uint8_t zoomDataId; 54 | argReader.ReadNumber(zoomDataId); 55 | 56 | auto data = Core->GetMapData(zoomDataId); 57 | L_ASSERT(data, "zoomData with this id not found"); 58 | 59 | lua_pushmapdata(L, data); 60 | } 61 | else 62 | { 63 | std::string zoomDataAlias; 64 | argReader.ReadString(zoomDataAlias); 65 | 66 | auto data = Core->GetMapData(zoomDataAlias); 67 | L_ASSERT(data, "zoomData with this id not found"); 68 | 69 | uint8_t id = Core->GetMapDataIDFromAlias(zoomDataAlias); 70 | lua_pushnumber(L, id); 71 | } 72 | 73 | return 1; 74 | } 75 | 76 | int MapData::Get(lua_State* L) 77 | { 78 | ArgumentReader argReader(L); 79 | 80 | L_ASSERT(argReader.IsCurrentType(LUA_TNUMBER) || argReader.IsCurrentType(LUA_TSTRING), "zoomDataId must be a number or string"); 81 | 82 | return CreateMapZoom(L); 83 | } 84 | 85 | int MapData::Reset(lua_State* L) 86 | { 87 | uint8_t zoomDataId; 88 | 89 | ArgumentReader argReader(L); 90 | argReader.ReadNumber(zoomDataId); 91 | 92 | if (argReader.HasAnyError()) 93 | { 94 | argReader.GetErrorMessages(); 95 | return 0; 96 | } 97 | 98 | Core->ResetMapData(zoomDataId); 99 | 100 | return 0; 101 | } 102 | 103 | int MapData::ResetAll(lua_State* L) 104 | { 105 | Core->ResetAllMapData(); 106 | return 0; 107 | } 108 | 109 | #define MAPDATA_GET_DEFINE(GET) \ 110 | int MapData::GET(lua_State* L) { alt::IMapData* mapData; ArgumentReader argReader(L); argReader.ReadUserData(mapData); if (argReader.HasAnyError()) { argReader.GetErrorMessages(); return 0; } lua_pushnumber(L, mapData->GET()); return 1;} 111 | 112 | #define MAPDATA_SET_DEFINE(SET) \ 113 | int MapData::SET(lua_State* L) { alt::IMapData* mapData; float value; ArgumentReader argReader(L); argReader.ReadUserData(mapData); argReader.ReadNumber(value); if (argReader.HasAnyError()) { argReader.GetErrorMessages(); return 0; } mapData->SET(value); return 0;} 114 | 115 | MAPDATA_GET_DEFINE(GetZoomScale) 116 | MAPDATA_GET_DEFINE(GetZoomSpeed) 117 | MAPDATA_GET_DEFINE(GetScrollSpeed) 118 | MAPDATA_GET_DEFINE(GetTilesCountX) 119 | MAPDATA_GET_DEFINE(GetTilesCountY) 120 | 121 | MAPDATA_SET_DEFINE(SetZoomScale) 122 | MAPDATA_SET_DEFINE(SetZoomSpeed) 123 | MAPDATA_SET_DEFINE(SetScrollSpeed) 124 | MAPDATA_SET_DEFINE(SetTilesCountX) 125 | MAPDATA_SET_DEFINE(SetTilesCountY) 126 | } 127 | #endif -------------------------------------------------------------------------------- /src/Defs/Client/MapData.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #ifdef ALT_CLIENT_API 6 | namespace lua::Class 7 | { 8 | class MapData 9 | { 10 | public: 11 | static const char* ClassName; 12 | static void Init(lua_State* L); 13 | 14 | private: 15 | static int CreateMapZoom(lua_State* L); 16 | 17 | static int Get(lua_State* L); 18 | static int Reset(lua_State* L); 19 | static int ResetAll(lua_State* L); 20 | 21 | static int GetZoomScale(lua_State* L); 22 | static int GetZoomSpeed(lua_State* L); 23 | static int GetScrollSpeed(lua_State* L); 24 | static int GetTilesCountX(lua_State* L); 25 | static int GetTilesCountY(lua_State* L); 26 | 27 | static int SetZoomScale(lua_State* L); 28 | static int SetZoomSpeed(lua_State* L); 29 | static int SetScrollSpeed(lua_State* L); 30 | static int SetTilesCountX(lua_State* L); 31 | static int SetTilesCountY(lua_State* L); 32 | }; 33 | } 34 | #endif -------------------------------------------------------------------------------- /src/Defs/Client/Native.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifdef ALT_CLIENT_API 4 | #include 5 | 6 | namespace lua::Class 7 | { 8 | const char* Native::ClassName = "native"; 9 | void Native::Init(lua_State* L) 10 | { 11 | lua_beginclass(L, Native::ClassName); 12 | { 13 | for (auto native : Core->GetAllNatives()) 14 | { 15 | lua_classnative(L, native->GetName().c_str(), InvokeNative, native); 16 | } 17 | } 18 | lua_endclass(L); 19 | 20 | lua_beginclass(L, "game", Native::ClassName); 21 | lua_endclass(L); 22 | } 23 | 24 | struct Ptr { 25 | void* ptr; 26 | alt::INative::Type ptrType; 27 | }; 28 | 29 | std::list pointers; 30 | 31 | template 32 | T* CreatePtr(T value, alt::INative::Type argType, size_t additionalSize = 1) 33 | { 34 | T* ptr = static_cast(malloc(additionalSize * sizeof(T))); 35 | *ptr = value; 36 | 37 | pointers.push_back({ ptr, argType }); 38 | 39 | return ptr; 40 | } 41 | 42 | void PushArg(alt::Ref ctx, alt::INative::Type argType, alt::MValueConst &value) 43 | { 44 | switch (argType) 45 | { 46 | case alt::INative::Type::ARG_BOOL: 47 | { 48 | ctx->Push((int32_t)value.As()->Value()); 49 | break; 50 | } 51 | case alt::INative::Type::ARG_BOOL_PTR: 52 | ctx->Push(CreatePtr((int32_t)value.As()->Value(), argType)); 53 | break; 54 | case alt::INative::Type::ARG_INT32: 55 | { 56 | if (value->GetType() == alt::IMValue::Type::BASE_OBJECT) 57 | { 58 | auto baseObject = value.As()->Value().Get(); 59 | if ( 60 | baseObject->GetType() == alt::IBaseObject::Type::PLAYER || 61 | baseObject->GetType() == alt::IBaseObject::Type::VEHICLE 62 | ) { 63 | ctx->Push((dynamic_cast(baseObject)->GetScriptGuid())); 64 | } 65 | } 66 | else { 67 | ctx->Push((int32_t)value.As()->Value()); 68 | } 69 | 70 | break; 71 | } 72 | case alt::INative::Type::ARG_INT32_PTR: 73 | ctx->Push(CreatePtr((int32_t)value.As()->Value(), argType)); 74 | break; 75 | case alt::INative::Type::ARG_UINT32: 76 | { 77 | ctx->Push((uint32_t)value.As()->Value()); //numbers are either converted to IMValueInt or IMValueDouble 78 | break; 79 | } 80 | case alt::INative::Type::ARG_UINT32_PTR: 81 | ctx->Push(CreatePtr((uint32_t)value.As()->Value(), argType)); //numbers are either converted to IMValueInt or IMValueDouble 82 | break; 83 | case alt::INative::Type::ARG_FLOAT: 84 | { 85 | if(value->GetType() == alt::IMValue::Type::INT) 86 | ctx->Push((float)value.As()->Value()); 87 | else if(value->GetType() == alt::IMValue::Type::DOUBLE) 88 | ctx->Push((float)value.As()->Value()); 89 | //ctx->Push((float)value.As()->Value()); 90 | break; 91 | } 92 | case alt::INative::Type::ARG_FLOAT_PTR: 93 | ctx->Push(CreatePtr((float)value.As()->Value(), argType)); 94 | break; 95 | case alt::INative::Type::ARG_VECTOR3_PTR: 96 | ctx->Push(CreatePtr(alt::INative::Vector3{}, argType)); 97 | break; 98 | case alt::INative::Type::ARG_STRING: 99 | { 100 | ctx->Push(*CreatePtr(_strdup(value.As()->Value().data()), argType)); 101 | break; 102 | } 103 | case alt::INative::Type::ARG_STRUCT: 104 | Core->LogInfo("TODO: Native->PushArg(Struct)"); 105 | break; 106 | default: 107 | Core->LogError("Unknown native arg type" + std::to_string((int)argType)); 108 | break; 109 | } 110 | } 111 | 112 | void GetReturn(lua_State* L, alt::INative::Context* ctx, alt::INative::Type returnType) 113 | { 114 | switch (returnType) 115 | { 116 | case alt::INative::Type::ARG_BOOL: 117 | lua_pushboolean(L, ctx->ResultBool()); 118 | break; 119 | case alt::INative::Type::ARG_INT32: 120 | lua_pushnumber(L, ctx->ResultInt()); 121 | break; 122 | case alt::INative::Type::ARG_UINT32: 123 | { 124 | lua_pushnumber(L, (lua_Number)ctx->ResultUint()); 125 | break; 126 | } 127 | case alt::INative::Type::ARG_FLOAT: 128 | lua_pushnumber(L, ctx->ResultFloat()); 129 | break; 130 | case alt::INative::Type::ARG_VECTOR3: 131 | { 132 | auto vector = ctx->ResultVector3(); 133 | lua_pushvector3(L, alt::Vector3f(vector.x, vector.y, vector.z)); 134 | break; 135 | } 136 | case alt::INative::Type::ARG_STRING: 137 | if (!ctx->ResultString()) 138 | lua_pushnil(L); 139 | else 140 | lua_pushstring(L, ctx->ResultString()); 141 | break; 142 | case alt::INative::Type::ARG_VOID: 143 | //lua_pushnil(L); 144 | break; 145 | default: 146 | Core->LogError("Unknown native return type" + std::to_string((int)returnType)); 147 | lua_pushnil(L); 148 | break; 149 | } 150 | } 151 | 152 | bool GetPtrReturn(lua_State* L, alt::INative::Type returnType, void* ptr) 153 | { 154 | bool ret = true; 155 | 156 | switch (returnType) 157 | { 158 | case alt::INative::Type::ARG_BOOL_PTR: 159 | lua_pushboolean(L, *static_cast(ptr)); 160 | break; 161 | case alt::INative::Type::ARG_INT32_PTR: 162 | lua_pushnumber(L, *static_cast(ptr)); 163 | break; 164 | case alt::INative::Type::ARG_UINT32_PTR: 165 | lua_pushnumber(L, *static_cast(ptr)); 166 | break; 167 | case alt::INative::Type::ARG_FLOAT_PTR: 168 | lua_pushnumber(L, *static_cast(ptr)); 169 | break; 170 | case alt::INative::Type::ARG_VECTOR3_PTR: 171 | { 172 | auto vector = static_cast(ptr); 173 | lua_pushvector3(L, alt::Vector3f(vector->x, vector->y, vector->z)); 174 | break; 175 | } 176 | default: 177 | ret = false; 178 | break; 179 | } 180 | 181 | return ret; 182 | } 183 | 184 | int Native::InvokeNative(lua_State* L) 185 | { 186 | auto native = static_cast(lua_touserdata(L, lua_upvalueindex(1))); 187 | if (!native->IsValid()) 188 | { 189 | lua_pushboolean(L, false); 190 | return 1; 191 | } 192 | 193 | alt::MValueArgs arguments; 194 | 195 | ArgumentReader argReader(L); 196 | argReader.ReadArguments(arguments); 197 | 198 | static auto nativeCtx = Core->CreateNativesContext(); 199 | 200 | auto args = native->GetArgTypes(); 201 | auto argsCount = args.GetSize(); 202 | 203 | nativeCtx->Reset(); 204 | 205 | if (arguments.GetSize() != argsCount) 206 | { 207 | Core->LogError("[Lua] Error when invoking native \"" + native->GetName() + "\": argument count doesn't match."); 208 | 209 | lua_pushboolean(L, false); 210 | return 1; 211 | } 212 | 213 | for (int i = 0; i < argsCount; i++) 214 | PushArg(nativeCtx, args[i], arguments[i]); 215 | 216 | if (!native->Invoke(nativeCtx)) 217 | { 218 | Core->LogError("[Lua] Native call failed"); 219 | 220 | lua_pushboolean(L, false); 221 | return 1; 222 | } 223 | 224 | GetReturn(L, nativeCtx.Get(), native->GetRetnType()); 225 | 226 | uint16_t ptrCount = 0; 227 | if (pointers.size() > 0) 228 | { 229 | for (auto&& pointer : pointers) 230 | if (GetPtrReturn(L, pointer.ptrType, pointer.ptr)) 231 | ptrCount++; 232 | } 233 | 234 | //Delete pointers we allocated 235 | { 236 | for (auto&& pointer : pointers) 237 | free(pointer.ptr); 238 | 239 | pointers.clear(); 240 | } 241 | 242 | return ((uint8_t)(native->GetRetnType() != alt::INative::Type::ARG_VOID)) + ptrCount; 243 | } 244 | } 245 | #endif -------------------------------------------------------------------------------- /src/Defs/Client/Native.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef ALT_CLIENT_API 4 | #include 5 | 6 | namespace lua::Class 7 | { 8 | class Native 9 | { 10 | public: 11 | static const char* ClassName; 12 | static void Init(lua_State* L); 13 | 14 | private: 15 | static int InvokeNative(lua_State* L); 16 | }; 17 | } 18 | #endif -------------------------------------------------------------------------------- /src/Defs/Client/RmlDocument.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifdef ALT_CLIENT_API 4 | 5 | namespace lua::Class 6 | { 7 | const char* RmlDocument::ClassName = "RmlDocument"; 8 | void RmlDocument::Init(lua_State* L) 9 | { 10 | lua_beginclass(L, RmlDocument::ClassName, RmlElement::ClassName); 11 | { 12 | lua_classmeta(L, "__tostring", tostring); 13 | 14 | lua_classfunction(L, "new", CreateRmlDocument); 15 | 16 | lua_classfunction(L, "show", Show); 17 | lua_classfunction(L, "hide", Hide); 18 | 19 | lua_classfunction(L, "update", Update); 20 | 21 | lua_classfunction(L, "createElement", CreateElement); 22 | lua_classfunction(L, "createTextNode", CreateTextNode); 23 | 24 | lua_classvariable(L, "title", SetTitle, GetTitle); 25 | lua_classvariable(L, "sourceUrl", nullptr, GetSourceUrl); 26 | lua_classvariable(L, "isVisible", nullptr, IsVisible); 27 | lua_classvariable(L, "isModal", nullptr, IsModal); 28 | 29 | lua_classvariable(L, "body", nullptr, GetBody); 30 | } 31 | lua_endclass(L); 32 | } 33 | 34 | int RmlDocument::tostring(lua_State* L) 35 | { 36 | lua_pushstring(L, "userdata:RmlDocument"); 37 | 38 | return 1; 39 | } 40 | 41 | int RmlDocument::CreateRmlDocument(lua_State* L) 42 | { 43 | std::string url; 44 | 45 | ArgumentReader argReader(L); 46 | argReader.ReadString(url); 47 | 48 | if (argReader.HasAnyError()) 49 | { 50 | argReader.GetErrorMessages(); 51 | return 0; 52 | } 53 | 54 | LuaResourceImpl* resourceImpl = LuaScriptRuntime::Instance().GetResourceImplFromState(L); 55 | DEBUG_INFO("CreateRmlDocument: working path: " + resourceImpl->GetWorkingPath()); 56 | 57 | lua_pushbaseobject(L, Core->CreateDocument(url, resourceImpl->GetWorkingPath(), resourceImpl->GetResource())); 58 | 59 | return 1; 60 | } 61 | 62 | int RmlDocument::SetTitle(lua_State* L) 63 | { 64 | alt::IRmlDocument* document; 65 | std::string title; 66 | 67 | ArgumentReader argReader(L); 68 | argReader.ReadBaseObject(document); 69 | argReader.ReadString(title); 70 | 71 | if (argReader.HasAnyError()) 72 | { 73 | argReader.GetErrorMessages(); 74 | return 0; 75 | } 76 | 77 | document->SetTitle(title); 78 | 79 | return 0; 80 | } 81 | 82 | int RmlDocument::GetTitle(lua_State* L) 83 | { 84 | alt::IRmlDocument* document; 85 | 86 | ArgumentReader argReader(L); 87 | argReader.ReadBaseObject(document); 88 | 89 | if (argReader.HasAnyError()) 90 | { 91 | argReader.GetErrorMessages(); 92 | return 0; 93 | } 94 | 95 | lua_pushstring(L, document->GetTitle()); 96 | 97 | return 1; 98 | } 99 | 100 | int RmlDocument::GetSourceUrl(lua_State* L) 101 | { 102 | alt::IRmlDocument* document; 103 | 104 | ArgumentReader argReader(L); 105 | argReader.ReadBaseObject(document); 106 | 107 | if (argReader.HasAnyError()) 108 | { 109 | argReader.GetErrorMessages(); 110 | return 0; 111 | } 112 | 113 | lua_pushstring(L, document->GetSourceUrl()); 114 | 115 | return 1; 116 | } 117 | 118 | int RmlDocument::CreateElement(lua_State* L) 119 | { 120 | alt::IRmlDocument* document; 121 | std::string name; 122 | 123 | ArgumentReader argReader(L); 124 | argReader.ReadBaseObject(document); 125 | argReader.ReadString(name); 126 | 127 | if (argReader.HasAnyError()) 128 | { 129 | argReader.GetErrorMessages(); 130 | return 0; 131 | } 132 | 133 | lua_pushbaseobject(L, document->CreateElement(name)); 134 | 135 | return 1; 136 | } 137 | 138 | int RmlDocument::CreateTextNode(lua_State* L) 139 | { 140 | alt::IRmlDocument* document; 141 | std::string text; 142 | 143 | ArgumentReader argReader(L); 144 | argReader.ReadBaseObject(document); 145 | argReader.ReadString(text); 146 | 147 | if (argReader.HasAnyError()) 148 | { 149 | argReader.GetErrorMessages(); 150 | return 0; 151 | } 152 | 153 | lua_pushbaseobject(L, document->CreateTextNode(text)); 154 | 155 | return 1; 156 | } 157 | 158 | int RmlDocument::Hide(lua_State* L) 159 | { 160 | alt::IRmlDocument* document; 161 | 162 | ArgumentReader argReader(L); 163 | argReader.ReadBaseObject(document); 164 | 165 | if (argReader.HasAnyError()) 166 | { 167 | argReader.GetErrorMessages(); 168 | return 0; 169 | } 170 | 171 | document->Hide(); 172 | 173 | return 0; 174 | } 175 | 176 | int RmlDocument::Show(lua_State* L) 177 | { 178 | alt::IRmlDocument* document; 179 | bool isModal; 180 | bool focused; 181 | 182 | ArgumentReader argReader(L); 183 | argReader.ReadBaseObject(document); 184 | argReader.ReadBoolDefault(isModal, false); 185 | argReader.ReadBoolDefault(focused, true); 186 | 187 | if (argReader.HasAnyError()) 188 | { 189 | argReader.GetErrorMessages(); 190 | return 0; 191 | } 192 | 193 | document->Show(isModal, focused); 194 | 195 | return 0; 196 | } 197 | 198 | int RmlDocument::IsVisible(lua_State* L) 199 | { 200 | alt::IRmlDocument* document; 201 | 202 | ArgumentReader argReader(L); 203 | argReader.ReadBaseObject(document); 204 | 205 | if (argReader.HasAnyError()) 206 | { 207 | argReader.GetErrorMessages(); 208 | return 0; 209 | } 210 | 211 | lua_pushboolean(L, document->IsVisible()); 212 | 213 | return 1; 214 | } 215 | 216 | int RmlDocument::IsModal(lua_State* L) 217 | { 218 | alt::IRmlDocument* document; 219 | 220 | ArgumentReader argReader(L); 221 | argReader.ReadBaseObject(document); 222 | 223 | if (argReader.HasAnyError()) 224 | { 225 | argReader.GetErrorMessages(); 226 | return 0; 227 | } 228 | 229 | lua_pushboolean(L, document->IsModal()); 230 | 231 | return 1; 232 | } 233 | 234 | int RmlDocument::GetBody(lua_State* L) 235 | { 236 | alt::IRmlDocument* document; 237 | 238 | ArgumentReader argReader(L); 239 | argReader.ReadBaseObject(document); 240 | 241 | if (argReader.HasAnyError()) 242 | { 243 | argReader.GetErrorMessages(); 244 | return 0; 245 | } 246 | 247 | lua_pushboolean(L, document->GetBody()); 248 | 249 | return 1; 250 | } 251 | 252 | int RmlDocument::Update(lua_State* L) 253 | { 254 | alt::IRmlDocument* document; 255 | 256 | ArgumentReader argReader(L); 257 | argReader.ReadBaseObject(document); 258 | 259 | if (argReader.HasAnyError()) 260 | { 261 | argReader.GetErrorMessages(); 262 | return 0; 263 | } 264 | 265 | document->Update(); 266 | 267 | return 0; 268 | } 269 | } 270 | 271 | #endif -------------------------------------------------------------------------------- /src/Defs/Client/RmlDocument.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #ifdef ALT_CLIENT_API 6 | 7 | namespace lua::Class 8 | { 9 | class RmlDocument 10 | { 11 | public: 12 | static const char* ClassName; 13 | static void Init(lua_State* L); 14 | 15 | private: 16 | static int tostring(lua_State* L); 17 | 18 | static int CreateRmlDocument(lua_State* L); 19 | 20 | static int SetTitle(lua_State* L); 21 | static int GetTitle(lua_State* L); 22 | static int GetSourceUrl(lua_State* L); 23 | 24 | static int CreateElement(lua_State* L); 25 | static int CreateTextNode(lua_State* L); 26 | 27 | static int Hide(lua_State* L); 28 | static int Show(lua_State* L); 29 | static int IsVisible(lua_State* L); 30 | static int IsModal(lua_State* L); 31 | 32 | static int GetBody(lua_State* L); 33 | 34 | static int Update(lua_State* L); 35 | }; 36 | } 37 | 38 | #endif -------------------------------------------------------------------------------- /src/Defs/Client/RmlElement.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #ifdef ALT_CLIENT_API 6 | 7 | namespace lua::Class 8 | { 9 | class RmlElement 10 | { 11 | public: 12 | static const char* ClassName; 13 | static void Init(lua_State* L); 14 | 15 | private: 16 | static int tostring(lua_State* L); 17 | 18 | static int CreateRmlElement(lua_State* L); 19 | static int On(lua_State* L); 20 | static int Off(lua_State* L); 21 | 22 | static int AddClass(lua_State* L); 23 | static int RemoveClass(lua_State* L); 24 | static int HasClass(lua_State* L); 25 | static int GetClassList(lua_State* L); 26 | 27 | static int AddPseudoClass(lua_State* L); 28 | static int RemovePseudoClass(lua_State* L); 29 | static int HasPseudoClass(lua_State* L); 30 | static int GetPseudoClassList(lua_State* L); 31 | 32 | static int SetOffset(lua_State* L); 33 | static int GetRelativeOffset(lua_State* L); 34 | static int GetAbsoluteOffset(lua_State* L); 35 | static int GetBaseline(lua_State* L); 36 | static int GetZIndex(lua_State* L); 37 | 38 | static int IsPointWithinElement(lua_State* L); 39 | 40 | static int SetProperty(lua_State* L); 41 | static int RemoveProperty(lua_State* L); 42 | // Checks property for local element and all inherited from ancestors 43 | static int HasProperty(lua_State* L); 44 | // Only check property for local element 45 | static int HasLocalProperty(lua_State* L); 46 | static int GetProperty(lua_State* L); 47 | static int GetLocalProperty(lua_State* L); 48 | // Returns the relative unit (e.g. 'percent' or 'angle') as absolute value ('px' or 'rad') 49 | static int GetPropertyAbsoluteValue(lua_State* L); 50 | 51 | static int GetContainingBlock(lua_State* L); 52 | 53 | static int GetFocusedElement(lua_State* L); 54 | 55 | static int GetTagName(lua_State* L); 56 | static int GetID(lua_State* L); 57 | static int SetID(lua_State* L); 58 | 59 | static int IsOwned(lua_State* L); 60 | 61 | static int SetAttribute(lua_State* L); 62 | static int RemoveAttribute(lua_State* L); 63 | static int HasAttribute(lua_State* L); 64 | static int GetAttribute(lua_State* L); 65 | static int GetAttributes(lua_State* L); 66 | 67 | static int GetAbsoluteLeft(lua_State* L); 68 | static int GetAbsoluteTop(lua_State* L); 69 | static int GetClientLeft(lua_State* L); 70 | static int GetClientTop(lua_State* L); 71 | static int GetClientWidth(lua_State* L); 72 | static int GetClientHeight(lua_State* L); 73 | static int GetOffsetParent(lua_State* L); 74 | static int GetOffsetLeft(lua_State* L); 75 | static int GetOffsetTop(lua_State* L); 76 | static int GetOffsetWidth(lua_State* L); 77 | static int GetOffsetHeight(lua_State* L); 78 | 79 | static int GetScrollLeft(lua_State* L); 80 | static int SetScrollLeft(lua_State* L); 81 | static int GetScrollTop(lua_State* L); 82 | static int SetScrollTop(lua_State* L); 83 | static int GetScrollWidth(lua_State* L); 84 | static int GetScrollHeight(lua_State* L); 85 | 86 | static int IsVisible(lua_State* L); 87 | 88 | static int GetParent(lua_State* L); 89 | static int GetClosest(lua_State* L); 90 | static int GetNextSibling(lua_State* L); 91 | static int GetPreviousSibling(lua_State* L); 92 | static int GetFirstChild(lua_State* L); 93 | static int GetLastChild(lua_State* L); 94 | static int GetChild(lua_State* L); 95 | static int GetChildCount(lua_State* L); 96 | static int AppendChild(lua_State* L); 97 | static int InsertBefore(lua_State* L); 98 | static int ReplaceChild(lua_State* L); 99 | static int RemoveChild(lua_State* L); 100 | static int HasChildren(lua_State* L); 101 | 102 | static int GetInnerRML(lua_State* L); 103 | static int SetInnerRML(lua_State* L); 104 | 105 | static int Focus(lua_State* L); 106 | static int Blur(lua_State* L); 107 | static int Click(lua_State* L); 108 | static int ScrollIntoView(lua_State* L); 109 | 110 | static int GetElementByID(lua_State* L); 111 | static int GetElementsByTagName(lua_State* L); 112 | static int GetElementsByClassName(lua_State* L); 113 | static int QuerySelector(lua_State* L); 114 | static int QuerySelectorAll(lua_State* L); 115 | 116 | static int GetOwnerDocument(lua_State* L); 117 | 118 | static int GetChildNodes(lua_State* L); 119 | }; 120 | } 121 | 122 | #endif -------------------------------------------------------------------------------- /src/Defs/Client/WebSocket.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef ALT_CLIENT_API 4 | #include 5 | 6 | namespace lua::Class 7 | { 8 | class WebSocket 9 | { 10 | public: 11 | static const char* ClassName; 12 | static void Init(lua_State* L); 13 | 14 | private: 15 | static int On(lua_State* L); 16 | static int Off(lua_State* L); 17 | 18 | static int Start(lua_State* L); 19 | static int Send(lua_State* L); 20 | static int Stop(lua_State* L); 21 | 22 | static int AddSubProtocol(lua_State* L); 23 | static int GetSubProtocols(lua_State* L); 24 | 25 | static int SetExtraHeader(lua_State* L); 26 | static int GetExtraHeaders(lua_State* L); 27 | 28 | static int SetAutoReconnect(lua_State* L); 29 | static int GetAutoReconnect(lua_State* L); 30 | static int SetPerMessageDeflate(lua_State* L); 31 | static int GetPerMessageDeflate(lua_State* L); 32 | static int SetPingInterval(lua_State* L); 33 | static int GetPingInterval(lua_State* L); 34 | static int SetURL(lua_State* L); 35 | static int GetURL(lua_State* L); 36 | static int GetReadyState(lua_State* L); 37 | }; 38 | } 39 | #endif -------------------------------------------------------------------------------- /src/Defs/Client/WebView.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #ifdef ALT_CLIENT_API 6 | namespace lua::Class 7 | { 8 | class WebView 9 | { 10 | public: 11 | static const char* ClassName; 12 | static void Init(lua_State* L); 13 | 14 | private: 15 | static int tostring(lua_State* L); 16 | 17 | static int CreateWebView(lua_State* L); 18 | static int On(lua_State* L); 19 | static int Off(lua_State* L); 20 | static int Trigger(lua_State* L); 21 | static int Focus(lua_State* L); 22 | static int Unfocus(lua_State* L); 23 | static int IsFocused(lua_State* L); 24 | static int GetUrl(lua_State* L); 25 | static int SetUrl(lua_State* L); 26 | static int IsVisible(lua_State* L); 27 | static int SetVisible(lua_State* L); 28 | static int IsOverlay(lua_State* L); 29 | static int IsReady(lua_State* L); 30 | static int SetExtraHeader(lua_State* L); 31 | static int SetZoomLevel(lua_State* L); 32 | static int GetSize(lua_State* L); 33 | static int SetSize(lua_State* L); 34 | static int GetPosition(lua_State* L); 35 | static int SetPosition(lua_State* L); 36 | }; 37 | } 38 | #endif -------------------------------------------------------------------------------- /src/Defs/Config.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace lua::Class 4 | { 5 | const char* Config::ClassName = "Config"; 6 | void Config::Init(lua_State* L) 7 | { 8 | DEBUG_INFO("Config::Init"); 9 | 10 | lua_beginclass(L, Config::ClassName); 11 | { 12 | lua_classmeta(L, "__tostring", tostring); 13 | 14 | lua_classfunction(L, "getKey", GetKey); 15 | } 16 | lua_endclass(L); 17 | 18 | DEBUG_INFO("Config::Init ...done"); 19 | } 20 | 21 | int Config::tostring(lua_State* L) 22 | { 23 | lua_pushstring(L, "userdata:Config"); 24 | 25 | return 1; 26 | } 27 | 28 | int Config::GetKey(lua_State* L) 29 | { 30 | alt::config::Node::Dict* nodeDict; 31 | std::string key; 32 | 33 | ArgumentReader argReader(L); 34 | argReader.ReadUserData(nodeDict); 35 | argReader.ReadString(key); 36 | 37 | if (argReader.HasAnyError()) 38 | { 39 | argReader.GetErrorMessages(); 40 | return 0; 41 | } 42 | 43 | if (nodeDict->find(key) == nodeDict->end()) 44 | { 45 | lua_pushnil(L); 46 | } 47 | else 48 | { 49 | lua_pushnode(L, (*nodeDict)[key]); 50 | } 51 | 52 | return 1; 53 | } 54 | } -------------------------------------------------------------------------------- /src/Defs/Config.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace lua::Class 6 | { 7 | class Config 8 | { 9 | public: 10 | static const char* ClassName; 11 | static void Init(lua_State* L); 12 | 13 | private: 14 | static int tostring(lua_State* L); 15 | 16 | static int GetKey(lua_State* L); 17 | }; 18 | } -------------------------------------------------------------------------------- /src/Defs/Entity/BaseObject.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace lua::Class 4 | { 5 | const char* BaseObject::ClassName = "BaseObject"; 6 | void BaseObject::Init(lua_State* L) 7 | { 8 | DEBUG_INFO("BaseObject::Init"); 9 | 10 | lua_beginclass(L, ClassName); 11 | { 12 | lua_classfunction(L, "getType", GetType); 13 | lua_classfunction(L, "hasMetaData", HasMetaData); 14 | lua_classfunction(L, "getMetaData", GetMetaData); 15 | lua_classfunction(L, "setMetaData", SetMetaData); 16 | lua_classfunction(L, "deleteMetaData", DeleteMetaData); 17 | lua_classfunction(L, "destroy", Destroy); 18 | 19 | lua_classvariable(L, "type", nullptr, GetType); 20 | } 21 | lua_endclass(L); 22 | 23 | DEBUG_INFO("BaseObject::Init ...done"); 24 | } 25 | 26 | int BaseObject::Destroy(lua_State* L) 27 | { 28 | alt::IBaseObject* baseObject; 29 | 30 | ArgumentReader argReader(L); 31 | argReader.ReadBaseObject(baseObject); 32 | 33 | if (argReader.HasAnyError()) 34 | { 35 | argReader.GetErrorMessages(); 36 | return 0; 37 | } 38 | 39 | lua_removedata(L, baseObject); 40 | 41 | auto resourceImpl = LuaScriptRuntime::Instance().GetResourceImplFromState(L); 42 | resourceImpl->RemoveEntity(baseObject); 43 | Core->DestroyBaseObject(baseObject); 44 | 45 | lua_pushboolean(L, true); 46 | 47 | return 1; 48 | } 49 | 50 | /** 51 | * @luafunc BaseObject::getType() 52 | * 53 | * @brief Gets a BaseObject's type. 54 | */ 55 | int BaseObject::GetType(lua_State* L) 56 | { 57 | alt::IBaseObject* baseObject; 58 | 59 | ArgumentReader argReader(L); 60 | argReader.ReadBaseObject(baseObject); 61 | 62 | if (argReader.HasAnyError()) 63 | { 64 | argReader.GetErrorMessages(); 65 | return 0; 66 | } 67 | 68 | auto type = LuaScriptRuntime::Instance().GetBaseObjectType(baseObject->GetType()); 69 | lua_pushstring(L, type.c_str()); 70 | 71 | return 1; 72 | } 73 | 74 | int BaseObject::HasMetaData(lua_State* L) 75 | { 76 | alt::IBaseObject* baseObject; 77 | std::string key; 78 | 79 | ArgumentReader argReader(L); 80 | argReader.ReadBaseObject(baseObject); 81 | argReader.ReadString(key); 82 | 83 | if (argReader.HasAnyError()) 84 | { 85 | argReader.GetErrorMessages(); 86 | return 0; 87 | } 88 | 89 | lua_pushboolean(L, baseObject->HasMetaData(key)); 90 | 91 | return 1; 92 | } 93 | 94 | int BaseObject::GetMetaData(lua_State* L) 95 | { 96 | alt::IBaseObject* baseObject; 97 | std::string key; 98 | 99 | ArgumentReader argReader(L); 100 | argReader.ReadBaseObject(baseObject); 101 | argReader.ReadString(key); 102 | 103 | if (argReader.HasAnyError()) 104 | { 105 | argReader.GetErrorMessages(); 106 | return 0; 107 | } 108 | 109 | lua_pushmvalue(L, baseObject->GetMetaData(key)); 110 | 111 | return 1; 112 | } 113 | 114 | int BaseObject::SetMetaData(lua_State* L) 115 | { 116 | alt::IBaseObject* baseObject; 117 | std::string key; 118 | alt::MValue value; 119 | 120 | ArgumentReader argReader(L); 121 | argReader.ReadBaseObject(baseObject); 122 | argReader.ReadString(key); 123 | argReader.ReadMValue(value); 124 | 125 | if (argReader.HasAnyError()) 126 | { 127 | argReader.GetErrorMessages(); 128 | return 0; 129 | } 130 | 131 | baseObject->SetMetaData(key, value); 132 | 133 | return 0; 134 | } 135 | 136 | int BaseObject::DeleteMetaData(lua_State* L) 137 | { 138 | alt::IBaseObject* baseObject; 139 | std::string key; 140 | 141 | ArgumentReader argReader(L); 142 | argReader.ReadBaseObject(baseObject); 143 | argReader.ReadString(key); 144 | 145 | if (argReader.HasAnyError()) 146 | { 147 | argReader.GetErrorMessages(); 148 | return 0; 149 | } 150 | 151 | baseObject->DeleteMetaData(key); 152 | 153 | return 0; 154 | } 155 | } -------------------------------------------------------------------------------- /src/Defs/Entity/BaseObject.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace lua::Class 6 | { 7 | class BaseObject 8 | { 9 | public: 10 | static const char* ClassName; 11 | static void Init(lua_State* L); 12 | 13 | private: 14 | static int GetType(lua_State* L); 15 | static int HasMetaData(lua_State* L); 16 | static int GetMetaData(lua_State* L); 17 | static int SetMetaData(lua_State* L); 18 | static int DeleteMetaData(lua_State* L); 19 | static int Destroy(lua_State* L); 20 | }; 21 | } -------------------------------------------------------------------------------- /src/Defs/Entity/Blip.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace lua::Class 6 | { 7 | class Blip 8 | { 9 | public: 10 | static const char* ClassName; 11 | static void Init(lua_State* L); 12 | 13 | private: 14 | #ifdef ALT_SERVER_API 15 | static int Create(lua_State* L); 16 | static int CreateAttached(lua_State* L); 17 | #else 18 | static int CreateAreaBlip(lua_State* L); 19 | static int CreateRadiusBlip(lua_State* L); 20 | static int CreatePointBlip(lua_State* L); 21 | static int CreatePedBlip(lua_State* L); 22 | static int CreateVehicleBlip(lua_State* L); 23 | #endif 24 | 25 | static int IsGlobal(lua_State* L); 26 | static int GetTarget(lua_State* L); 27 | 28 | static int IsAttached(lua_State* L); 29 | static int AttachedTo(lua_State* L); 30 | static int GetBlipType(lua_State* L); 31 | 32 | #ifdef ALT_CLIENT_API 33 | static int GetScaleXY(lua_State* L); 34 | static int GetDisplay(lua_State* L); 35 | static int GetSprite(lua_State* L); 36 | static int GetColor(lua_State* L); 37 | static int GetSecondaryColor(lua_State* L); 38 | static int GetAlpha(lua_State* L); 39 | static int GetFlashTimer(lua_State* L); 40 | static int GetFlashInterval(lua_State* L); 41 | static int GetAsFriendly(lua_State* L); 42 | static int GetRoute(lua_State* L); 43 | static int GetBright(lua_State* L); 44 | static int GetNumber(lua_State* L); 45 | static int GetShowCone(lua_State* L); 46 | static int GetFlashes(lua_State* L); 47 | static int GetFlashesAlternate(lua_State* L); 48 | static int GetAsShortRange(lua_State* L); 49 | static int GetPriority(lua_State* L); 50 | static int GetRotation(lua_State* L); 51 | static int GetGxtName(lua_State* L); 52 | static int GetName(lua_State* L); 53 | static int GetRouteColor(lua_State* L); 54 | static int GetPulse(lua_State* L); 55 | static int GetAsMissionCreator(lua_State* L); 56 | static int GetTickVisible(lua_State* L); 57 | static int GetHeadingIndicatorVisible(lua_State* L); 58 | static int GetOutlineIndicatorVisible(lua_State* L); 59 | static int GetFriendIndicatorVisible(lua_State* L); 60 | static int GetCrewIndicatorVisible(lua_State* L); 61 | static int GetCategory(lua_State* L); 62 | static int GetAsHighDetail(lua_State* L); 63 | static int GetShrinked(lua_State* L); 64 | 65 | static int SetDisplay(lua_State* L); 66 | static int SetScaleXY(lua_State* L); 67 | static int SetSprite(lua_State* L); 68 | static int SetColor(lua_State* L); 69 | static int SetRoute(lua_State* L); 70 | static int SetRouteColor(lua_State* L); 71 | static int SetSecondaryColor(lua_State* L); 72 | static int SetAlpha(lua_State* L); 73 | static int SetFlashTimer(lua_State* L); 74 | static int SetFlashInterval(lua_State* L); 75 | static int SetAsFriendly(lua_State* L); 76 | static int SetBright(lua_State* L); 77 | static int SetNumber(lua_State* L); 78 | static int SetShowCone(lua_State* L); 79 | static int SetFlashes(lua_State* L); 80 | static int SetFlashesAlternate(lua_State* L); 81 | static int SetAsShortRange(lua_State* L); 82 | static int SetPriority(lua_State* L); 83 | static int SetRotation(lua_State* L); 84 | static int SetGxtName(lua_State* L); 85 | static int SetName(lua_State* L); 86 | static int SetPulse(lua_State* L); 87 | static int SetAsMissionCreator(lua_State* L); 88 | static int SetTickVisible(lua_State* L); 89 | static int SetHeadingIndicatorVisible(lua_State* L); 90 | static int SetOutlineIndicatorVisible(lua_State* L); 91 | static int SetFriendIndicatorVisible(lua_State* L); 92 | static int SetCrewIndicatorVisible(lua_State* L); 93 | static int SetCategory(lua_State* L); 94 | static int SetAsHighDetail(lua_State* L); 95 | static int SetShrinked(lua_State* L); 96 | static int Fade(lua_State* L); 97 | #endif 98 | 99 | /*static int SetSprite(lua_State* L); 100 | static int SetColor(lua_State* L); 101 | static int SetRoute(lua_State* L); 102 | static int SetRouteColor(lua_State* L);*/ 103 | }; 104 | } -------------------------------------------------------------------------------- /src/Defs/Entity/Checkpoint.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace lua::Class 4 | { 5 | const char* Checkpoint::ClassName = "Checkpoint"; 6 | void Checkpoint::Init(lua_State* L) 7 | { 8 | DEBUG_INFO("Checkpoint::Init"); 9 | 10 | lua_beginclass(L, ClassName); 11 | { 12 | lua_classfunction(L, "new", Create); 13 | lua_classfunction(L, "getCheckpointType", GetCheckpointType); 14 | lua_classfunction(L, "getHeight", GetHeight); 15 | lua_classfunction(L, "getRadius", GetRadius); 16 | lua_classfunction(L, "getColor", GetColor); 17 | 18 | lua_classvariable(L, "checkpointType", nullptr, GetCheckpointType); 19 | lua_classvariable(L, "height", nullptr, GetHeight); 20 | lua_classvariable(L, "radius", nullptr, GetRadius); 21 | lua_classvariable(L, "color", nullptr, GetColor); 22 | } 23 | lua_endclass(L); 24 | 25 | DEBUG_INFO("Checkpoint::Init ...done"); 26 | } 27 | 28 | int Checkpoint::Create(lua_State* L) 29 | { 30 | uint8_t type; 31 | alt::Position position; 32 | alt::Position nextPosition; 33 | float radius; 34 | float height; 35 | alt::RGBA color; 36 | 37 | ArgumentReader argReader(L); 38 | argReader.ReadNumber(type); 39 | argReader.ReadVector(position); 40 | #ifdef ALT_CLIENT_API 41 | argReader.ReadVector(nextPosition); 42 | #endif 43 | argReader.ReadNumber(radius); 44 | argReader.ReadNumber(height); 45 | argReader.ReadRGBA(color); 46 | 47 | if (argReader.HasAnyError()) 48 | { 49 | argReader.GetErrorMessages(); 50 | return 0; 51 | } 52 | 53 | #ifdef ALT_SERVER_API 54 | auto checkpoint = Core->CreateCheckpoint(type, position, radius, height, color); 55 | #else 56 | auto checkpoint = Core->CreateCheckpoint(type, position, nextPosition, radius, height, color); 57 | #endif 58 | if (checkpoint) 59 | { 60 | lua_pushbaseobject(L, checkpoint.Get()); 61 | 62 | auto resourceImpl = LuaScriptRuntime::Instance().GetResourceImplFromState(L); 63 | resourceImpl->AddEntity(checkpoint.Get()); 64 | } 65 | else 66 | lua_pushnil(L); 67 | 68 | return 1; 69 | } 70 | 71 | int Checkpoint::GetCheckpointType(lua_State* L) 72 | { 73 | alt::ICheckpoint* checkpoint; 74 | 75 | ArgumentReader argReader(L); 76 | argReader.ReadBaseObject(checkpoint); 77 | 78 | if (argReader.HasAnyError()) 79 | { 80 | argReader.GetErrorMessages(); 81 | return 0; 82 | } 83 | 84 | lua_pushnumber(L, checkpoint->GetCheckpointType()); 85 | 86 | return 1; 87 | } 88 | 89 | int Checkpoint::GetHeight(lua_State* L) 90 | { 91 | alt::ICheckpoint* checkpoint; 92 | 93 | ArgumentReader argReader(L); 94 | argReader.ReadBaseObject(checkpoint); 95 | 96 | if (argReader.HasAnyError()) 97 | { 98 | argReader.GetErrorMessages(); 99 | return 0; 100 | } 101 | 102 | lua_pushnumber(L, checkpoint->GetHeight()); 103 | 104 | return 1; 105 | } 106 | 107 | int Checkpoint::GetRadius(lua_State* L) 108 | { 109 | alt::ICheckpoint* checkpoint; 110 | 111 | ArgumentReader argReader(L); 112 | argReader.ReadBaseObject(checkpoint); 113 | 114 | if (argReader.HasAnyError()) 115 | { 116 | argReader.GetErrorMessages(); 117 | return 0; 118 | } 119 | 120 | lua_pushnumber(L, checkpoint->GetRadius()); 121 | 122 | return 1; 123 | } 124 | 125 | int Checkpoint::GetColor(lua_State* L) 126 | { 127 | alt::ICheckpoint* checkpoint; 128 | 129 | ArgumentReader argReader(L); 130 | argReader.ReadBaseObject(checkpoint); 131 | 132 | if (argReader.HasAnyError()) 133 | { 134 | argReader.GetErrorMessages(); 135 | return 0; 136 | } 137 | 138 | lua_pushrgba(L, checkpoint->GetColor()); 139 | 140 | return 1; 141 | } 142 | } -------------------------------------------------------------------------------- /src/Defs/Entity/Checkpoint.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace lua::Class 6 | { 7 | class Checkpoint 8 | { 9 | public: 10 | static const char* ClassName; 11 | static void Init(lua_State* L); 12 | 13 | private: 14 | static int Create(lua_State* L); 15 | static int GetCheckpointType(lua_State* L); 16 | static int GetHeight(lua_State* L); 17 | static int GetRadius(lua_State* L); 18 | static int GetColor(lua_State* L); 19 | }; 20 | } -------------------------------------------------------------------------------- /src/Defs/Entity/ColShape.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifdef ALT_SERVER_API 4 | namespace lua::Class 5 | { 6 | const char* ColShape::ClassName = "ColShape"; 7 | void ColShape::Init(lua_State* L) 8 | { 9 | DEBUG_INFO("ColShape::Init"); 10 | 11 | lua_beginclass(L, ClassName, WorldObject::ClassName); 12 | { 13 | lua_classfunction(L, "Circle", CreateCircle); 14 | lua_classfunction(L, "Cube", CreateCube); 15 | lua_classfunction(L, "Cylinder", CreateCylinder); 16 | lua_classfunction(L, "Rectangle", CreateRectangle); 17 | lua_classfunction(L, "Sphere", CreateSphere); 18 | 19 | lua_classfunction(L, "getColShapeType", GetColshapeType); 20 | lua_classfunction(L, "isEntityIn", IsEntityIn); 21 | lua_classfunction(L, "isPointIn", IsPointIn); 22 | 23 | lua_classvariable(L, "colshapeType", nullptr, "getColShapeType"); 24 | } 25 | lua_endclass(L); 26 | 27 | DEBUG_INFO("ColShape::Init ...done"); 28 | } 29 | 30 | int ColShape::CreateCircle(lua_State* L) 31 | { 32 | alt::Position position; 33 | float radius; 34 | 35 | ArgumentReader argReader(L); 36 | argReader.ReadVector(position); 37 | argReader.ReadNumber(radius); 38 | 39 | if (argReader.HasAnyError()) 40 | { 41 | argReader.GetErrorMessages(); 42 | return 0; 43 | } 44 | 45 | auto colshape = Core->CreateColShapeCircle(position, radius); 46 | if (colshape) 47 | lua_pushbaseobject(L, colshape.Get()); 48 | else 49 | lua_pushnil(L); 50 | 51 | return 1; 52 | } 53 | 54 | int ColShape::CreateCube(lua_State* L) 55 | { 56 | alt::Position position; 57 | alt::Position position2; 58 | 59 | ArgumentReader argReader(L); 60 | argReader.ReadVector(position); 61 | argReader.ReadVector(position2); 62 | 63 | if (argReader.HasAnyError()) 64 | { 65 | argReader.GetErrorMessages(); 66 | return 0; 67 | } 68 | 69 | auto colshape = Core->CreateColShapeCube(position, position2); 70 | if (colshape) 71 | { 72 | lua_pushbaseobject(L, colshape.Get()); 73 | 74 | auto resourceImpl = LuaScriptRuntime::Instance().GetResourceImplFromState(L); 75 | resourceImpl->AddEntity(colshape.Get()); 76 | } 77 | else 78 | lua_pushnil(L); 79 | 80 | return 1; 81 | } 82 | 83 | int ColShape::CreateCylinder(lua_State* L) 84 | { 85 | alt::Position position; 86 | float radius; 87 | float height; 88 | 89 | ArgumentReader argReader(L); 90 | argReader.ReadVector(position); 91 | argReader.ReadNumber(radius); 92 | argReader.ReadNumber(height); 93 | 94 | if (argReader.HasAnyError()) 95 | { 96 | argReader.GetErrorMessages(); 97 | return 0; 98 | } 99 | 100 | auto colshape = Core->CreateColShapeCylinder(position, radius, height); 101 | if (colshape) 102 | { 103 | lua_pushbaseobject(L, colshape.Get()); 104 | 105 | auto resourceImpl = LuaScriptRuntime::Instance().GetResourceImplFromState(L); 106 | resourceImpl->AddEntity(colshape.Get()); 107 | } 108 | else 109 | lua_pushnil(L); 110 | 111 | return 1; 112 | } 113 | 114 | int ColShape::CreateRectangle(lua_State* L) 115 | { 116 | float x1, y1; 117 | float x2, y2; 118 | float z; 119 | 120 | ArgumentReader argReader(L); 121 | argReader.ReadNumber(x1); 122 | argReader.ReadNumber(y1); 123 | argReader.ReadNumber(x2); 124 | argReader.ReadNumber(y2); 125 | argReader.ReadNumber(z); 126 | 127 | if (argReader.HasAnyError()) 128 | { 129 | argReader.GetErrorMessages(); 130 | return 0; 131 | } 132 | 133 | auto colshape = Core->CreateColShapeRectangle(x1, y1, x2, y2, z); 134 | if (colshape) 135 | { 136 | lua_pushbaseobject(L, colshape.Get()); 137 | 138 | auto resourceImpl = LuaScriptRuntime::Instance().GetResourceImplFromState(L); 139 | resourceImpl->AddEntity(colshape.Get()); 140 | } 141 | else 142 | lua_pushnil(L); 143 | 144 | return 1; 145 | } 146 | 147 | int ColShape::CreateSphere(lua_State* L) 148 | { 149 | alt::Position position; 150 | float radius; 151 | 152 | ArgumentReader argReader(L); 153 | argReader.ReadVector(position); 154 | argReader.ReadNumber(radius); 155 | 156 | if (argReader.HasAnyError()) 157 | { 158 | argReader.GetErrorMessages(); 159 | return 0; 160 | } 161 | 162 | auto colshape = Core->CreateColShapeSphere(position, radius); 163 | if (colshape) 164 | { 165 | lua_pushbaseobject(L, colshape.Get()); 166 | 167 | auto resourceImpl = LuaScriptRuntime::Instance().GetResourceImplFromState(L); 168 | resourceImpl->AddEntity(colshape.Get()); 169 | } 170 | else 171 | lua_pushnil(L); 172 | 173 | return 1; 174 | } 175 | 176 | int ColShape::GetColshapeType(lua_State* L) 177 | { 178 | alt::IColShape* colshape; 179 | 180 | ArgumentReader argReader(L); 181 | argReader.ReadBaseObject(colshape); 182 | 183 | if (argReader.HasAnyError()) 184 | { 185 | argReader.GetErrorMessages(); 186 | return 0; 187 | } 188 | 189 | lua_pushnumber(L, static_cast(colshape->GetColshapeType())); 190 | 191 | return 1; 192 | } 193 | 194 | int ColShape::IsEntityIn(lua_State* L) 195 | { 196 | alt::IColShape* colshape; 197 | alt::IEntity* entity; 198 | 199 | ArgumentReader argReader(L); 200 | argReader.ReadBaseObject(colshape); 201 | argReader.ReadBaseObject(entity); 202 | 203 | if (argReader.HasAnyError()) 204 | { 205 | argReader.GetErrorMessages(); 206 | return 0; 207 | } 208 | 209 | lua_pushboolean(L, colshape->IsEntityIn(entity)); 210 | 211 | return 1; 212 | } 213 | 214 | int ColShape::IsPointIn(lua_State* L) 215 | { 216 | alt::IColShape* colshape; 217 | alt::Position position; 218 | 219 | ArgumentReader argReader(L); 220 | argReader.ReadBaseObject(colshape); 221 | argReader.ReadVector(position); 222 | 223 | if (argReader.HasAnyError()) 224 | { 225 | argReader.GetErrorMessages(); 226 | return 0; 227 | } 228 | 229 | lua_pushboolean(L, colshape->IsPointIn(position)); 230 | 231 | return 1; 232 | } 233 | } 234 | #endif -------------------------------------------------------------------------------- /src/Defs/Entity/ColShape.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #ifdef ALT_SERVER_API 6 | namespace lua::Class 7 | { 8 | class ColShape 9 | { 10 | public: 11 | static const char* ClassName; 12 | static void Init(lua_State* L); 13 | 14 | private: 15 | static int CreateCircle(lua_State* L); 16 | static int CreateCube(lua_State* L); 17 | static int CreateCylinder(lua_State* L); 18 | static int CreateRectangle(lua_State* L); 19 | static int CreateSphere(lua_State* L); 20 | 21 | static int GetColshapeType(lua_State* L); 22 | 23 | static int IsEntityIn(lua_State* L); 24 | static int IsPointIn(lua_State* L); 25 | }; 26 | } 27 | #endif -------------------------------------------------------------------------------- /src/Defs/Entity/Entity.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace lua::Class 6 | { 7 | class Entity 8 | { 9 | public: 10 | static const char* ClassName; 11 | static void Init(lua_State* L); 12 | 13 | private: 14 | static int tostring(lua_State* L); 15 | static int pairs(lua_State* L); 16 | static int ipairs(lua_State* L); 17 | 18 | static int GetID(lua_State* L); 19 | 20 | static int GetNetworkOwner(lua_State* L); 21 | 22 | static int GetModel(lua_State* L); 23 | 24 | //static int SetPosition(lua_State* L); 25 | //static int GetPosition(lua_State* L); 26 | static int SetRotation(lua_State* L); 27 | static int GetRotation(lua_State* L); 28 | 29 | static int GetVisible(lua_State* L); 30 | 31 | static int HasSyncedMetaData(lua_State* L); 32 | static int GetSyncedMetaData(lua_State* L); 33 | static int HasStreamSyncedMetaData(lua_State* L); 34 | static int GetStreamSyncedMetaData(lua_State* L); 35 | 36 | #ifdef ALT_SERVER_API 37 | static int SetNetworkOwner(lua_State* L); 38 | 39 | static int SetSyncedMetaData(lua_State* L); 40 | static int DeleteSyncedMetaData(lua_State* L); 41 | static int SetStreamSyncedMetaData(lua_State* L); 42 | static int DeleteStreamSyncedMetaData(lua_State* L); 43 | static int SetVisible(lua_State* L); 44 | 45 | int IsFrozen(lua_State* L); 46 | int SetFrozen(lua_State* L); 47 | int HasCollision(lua_State* L); 48 | int SetCollision(lua_State* L); 49 | #else 50 | static int GetScriptGuid(lua_State* L); 51 | static int GetEntityByScriptGuid(lua_State* L); 52 | #endif 53 | }; 54 | } -------------------------------------------------------------------------------- /src/Defs/Entity/Player.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace lua::Class 6 | { 7 | #ifdef ALT_CLIENT_API 8 | 9 | class LocalPlayer 10 | { 11 | public: 12 | static const char* ClassName; 13 | static void Init(lua_State* L); 14 | 15 | private: 16 | static int GetLocalPlayer(lua_State* L); 17 | static int GetCurrentAmmo(lua_State* L); 18 | }; 19 | 20 | #endif 21 | 22 | class Player 23 | { 24 | public: 25 | static const char* ClassName; 26 | static void Init(lua_State* L); 27 | 28 | private: 29 | static int tostring(lua_State* L); 30 | static int ipairs(lua_State* L); 31 | 32 | static int GetName(lua_State* L); 33 | 34 | static int GetHealth(lua_State* L); 35 | static int GetMaxHealth(lua_State* L); 36 | 37 | static int GetCurrentWeaponComponents(lua_State* L); 38 | 39 | static int GetCurrentWeaponTintIndex(lua_State* L); 40 | 41 | static int GetCurrentWeapon(lua_State* L); 42 | 43 | static int IsDead(lua_State* L); 44 | 45 | static int IsJumping(lua_State* L); 46 | static int IsInRagdoll(lua_State* L); 47 | static int IsAiming(lua_State* L); 48 | static int IsShooting(lua_State* L); 49 | static int IsReloading(lua_State* L); 50 | 51 | static int GetArmour(lua_State* L); 52 | static int GetMaxArmour(lua_State* L); 53 | 54 | static int GetMoveSpeed(lua_State* L); 55 | 56 | /*static int GetWeapon(lua_State* L); 57 | static int GetAmmo(lua_State* L);*/ 58 | 59 | static int GetAimPos(lua_State* L); 60 | static int GetHeadRotation(lua_State* L); 61 | 62 | static int IsInVehicle(lua_State* L); 63 | static int GetVehicle(lua_State* L); 64 | static int GetSeat(lua_State* L); 65 | 66 | static int GetEntityAimingAt(lua_State* L); 67 | static int GetEntityAimOffset(lua_State* L); 68 | 69 | static int IsFlashlightActive(lua_State* L); 70 | 71 | static int IsSuperJumpEnabled(lua_State* L); 72 | static int IsCrouching(lua_State* L); 73 | static int IsStealthy(lua_State* L); 74 | 75 | static int GetModel(lua_State* L); 76 | 77 | #ifdef ALT_SERVER_API 78 | static int IsConnected(lua_State* L); 79 | static int GetPing(lua_State* L); 80 | static int GetIP(lua_State* L); 81 | static int GetSocialID(lua_State* L); 82 | static int GetHwidHash(lua_State* L); 83 | static int GetHwidExHash(lua_State* L); 84 | static int GetAuthToken(lua_State* L); 85 | 86 | static int Spawn(lua_State* L); 87 | static int Despawn(lua_State* L); 88 | static int SetModel(lua_State* L); 89 | static int SetArmour(lua_State* L); 90 | static int SetMaxArmour(lua_State* L); 91 | static int SetCurrentWeapon(lua_State* L); 92 | static int SetWeaponTintIndex(lua_State* L); 93 | static int AddWeaponComponent(lua_State* L); 94 | static int RemoveWeaponComponent(lua_State* L); 95 | static int ClearBloodDamage(lua_State* L); 96 | static int SetHealth(lua_State* L); 97 | static int SetMaxHealth(lua_State* L); 98 | static int GiveWeapon(lua_State* L); 99 | static int RemoveWeapon(lua_State* L); 100 | static int RemoveAllWeapons(lua_State* L); 101 | static int SetDateTime(lua_State* L); 102 | static int SetWeather(lua_State* L); 103 | static int Kick(lua_State* L); 104 | static int GetClothes(lua_State* L); 105 | static int SetClothes(lua_State* L); 106 | static int GetDlcClothes(lua_State* L); 107 | static int SetDlcClothes(lua_State* L); 108 | static int GetProp(lua_State* L); 109 | static int SetProp(lua_State* L); 110 | static int GetDlcProps(lua_State* L); 111 | static int SetDlcProps(lua_State* L); 112 | static int ClearProps(lua_State* L); 113 | static int IsEntityInStreamingRange(lua_State* L); 114 | static int SetInvincible(lua_State* L); 115 | static int GetInvincible(lua_State* L); 116 | static int SetIntoVehicle(lua_State* L); 117 | static int PlayAmbientSpeech(lua_State* L); 118 | static int SetHeadOverlay(lua_State* L); 119 | static int RemoveHeadOverlay(lua_State* L); 120 | static int SetHeadOverlayColor(lua_State* L); 121 | static int GetHeadOverlay(lua_State* L); 122 | static int SetFaceFeature(lua_State* L); 123 | static int GetFaceFeatureScale(lua_State* L); 124 | static int RemoveFaceFeature(lua_State* L); 125 | static int SetHeadBlendPaletteColor(lua_State* L); 126 | static int GetHeadBlendPaletteColor(lua_State* L); 127 | static int SetHeadBlendData(lua_State* L); 128 | static int GetHeadBlendData(lua_State* L); 129 | static int SetEyeColor(lua_State* L); 130 | static int GetEyeColor(lua_State* L); 131 | static int SetHairColor(lua_State* L); 132 | static int GetHairColor(lua_State* L); 133 | static int SetHairHighlightColor(lua_State* L); 134 | static int GetHairHighlightColor(lua_State* L); 135 | static int GetWeapons(lua_State* L); 136 | 137 | static int HasLocalMetaData(lua_State* L); 138 | static int SetLocalMetaData(lua_State* L); 139 | static int GetLocalMetaData(lua_State* L); 140 | static int DeleteLocalMetaData(lua_State* L); 141 | #else 142 | static int IsTalking(lua_State* L); 143 | static int GetMicLevel(lua_State* L); 144 | 145 | static int GetSpatialVolume(lua_State* L); 146 | static int SetSpatialVolume(lua_State* L); 147 | static int GetNonSpatialVolume(lua_State* L); 148 | static int SetNonSpatialVolume(lua_State* L); 149 | #endif 150 | }; 151 | } -------------------------------------------------------------------------------- /src/Defs/Entity/VoiceChannel.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifdef ALT_SERVER_API 4 | namespace lua::Class 5 | { 6 | const char* VoiceChannel::ClassName = "VoiceChannel"; 7 | void VoiceChannel::Init(lua_State* L) 8 | { 9 | DEBUG_INFO("VoiceChannel::Init"); 10 | 11 | lua_beginclass(L, ClassName, WorldObject::ClassName); 12 | { 13 | lua_classfunction(L, "new", Create); 14 | lua_classfunction(L, "isSpatial", IsSpatial); 15 | lua_classfunction(L, "getMaxDistance", GetMaxDistance); 16 | lua_classfunction(L, "hasPlayer", HasPlayer); 17 | lua_classfunction(L, "addPlayer", AddPlayer); 18 | lua_classfunction(L, "removePlayer", RemovePlayer); 19 | lua_classfunction(L, "isPlayerMuted", IsPlayerMuted); 20 | lua_classfunction(L, "mutePlayer", MutePlayer); 21 | lua_classfunction(L, "unmutePlayer", UnmutePlayer); 22 | 23 | lua_classvariable(L, "spatial", nullptr, IsSpatial); 24 | lua_classvariable(L, "maxDistance", nullptr, GetMaxDistance); 25 | } 26 | lua_endclass(L); 27 | 28 | DEBUG_INFO("VoiceChannel::Init ...done"); 29 | } 30 | 31 | int VoiceChannel::Create(lua_State* L) 32 | { 33 | bool spatial; 34 | float maxDistance; 35 | 36 | ArgumentReader argReader(L); 37 | argReader.ReadBool(spatial); 38 | argReader.ReadNumber(maxDistance); 39 | 40 | if (argReader.HasAnyError()) 41 | { 42 | argReader.GetErrorMessages(); 43 | return 0; 44 | } 45 | 46 | auto voiceChannel = Core->CreateVoiceChannel(spatial, maxDistance); 47 | if (voiceChannel) 48 | { 49 | lua_pushbaseobject(L, voiceChannel.Get()); 50 | 51 | auto resourceImpl = LuaScriptRuntime::Instance().GetResourceImplFromState(L); 52 | resourceImpl->AddEntity(voiceChannel.Get()); 53 | } 54 | else 55 | lua_pushnil(L); 56 | 57 | return 1; 58 | } 59 | 60 | int VoiceChannel::IsSpatial(lua_State* L) 61 | { 62 | alt::IVoiceChannel* voiceChannel; 63 | 64 | ArgumentReader argReader(L); 65 | argReader.ReadBaseObject(voiceChannel); 66 | 67 | if (argReader.HasAnyError()) 68 | { 69 | argReader.GetErrorMessages(); 70 | return 0; 71 | } 72 | 73 | lua_pushboolean(L, voiceChannel->IsSpatial()); 74 | 75 | return 1; 76 | } 77 | 78 | int VoiceChannel::GetMaxDistance(lua_State* L) 79 | { 80 | alt::IVoiceChannel* voiceChannel; 81 | 82 | ArgumentReader argReader(L); 83 | argReader.ReadBaseObject(voiceChannel); 84 | 85 | if (argReader.HasAnyError()) 86 | { 87 | argReader.GetErrorMessages(); 88 | return 0; 89 | } 90 | 91 | lua_pushnumber(L, voiceChannel->GetMaxDistance()); 92 | 93 | return 1; 94 | } 95 | 96 | int VoiceChannel::HasPlayer(lua_State* L) 97 | { 98 | alt::IVoiceChannel* voiceChannel; 99 | alt::IPlayer* player; 100 | 101 | ArgumentReader argReader(L); 102 | argReader.ReadBaseObject(voiceChannel); 103 | argReader.ReadBaseObject(player); 104 | 105 | if (argReader.HasAnyError()) 106 | { 107 | argReader.GetErrorMessages(); 108 | return 0; 109 | } 110 | 111 | lua_pushboolean(L, voiceChannel->HasPlayer(player)); 112 | 113 | return 1; 114 | } 115 | 116 | int VoiceChannel::AddPlayer(lua_State* L) 117 | { 118 | alt::IVoiceChannel* voiceChannel; 119 | alt::IPlayer* player; 120 | 121 | ArgumentReader argReader(L); 122 | argReader.ReadBaseObject(voiceChannel); 123 | argReader.ReadBaseObject(player); 124 | 125 | if (argReader.HasAnyError()) 126 | { 127 | argReader.GetErrorMessages(); 128 | return 0; 129 | } 130 | 131 | voiceChannel->AddPlayer(player); 132 | 133 | return 0; 134 | } 135 | 136 | int VoiceChannel::RemovePlayer(lua_State* L) 137 | { 138 | alt::IVoiceChannel* voiceChannel; 139 | alt::IPlayer* player; 140 | 141 | ArgumentReader argReader(L); 142 | argReader.ReadBaseObject(voiceChannel); 143 | argReader.ReadBaseObject(player); 144 | 145 | if (argReader.HasAnyError()) 146 | { 147 | argReader.GetErrorMessages(); 148 | return 0; 149 | } 150 | 151 | voiceChannel->RemovePlayer(player); 152 | 153 | return 0; 154 | } 155 | 156 | int VoiceChannel::IsPlayerMuted(lua_State* L) 157 | { 158 | alt::IVoiceChannel* voiceChannel; 159 | alt::IPlayer* player; 160 | 161 | ArgumentReader argReader(L); 162 | argReader.ReadBaseObject(voiceChannel); 163 | argReader.ReadBaseObject(player); 164 | 165 | if (argReader.HasAnyError()) 166 | { 167 | argReader.GetErrorMessages(); 168 | return 0; 169 | } 170 | 171 | lua_pushboolean(L, voiceChannel->IsPlayerMuted(player)); 172 | 173 | return 1; 174 | } 175 | 176 | int VoiceChannel::MutePlayer(lua_State* L) 177 | { 178 | alt::IVoiceChannel* voiceChannel; 179 | alt::IPlayer* player; 180 | 181 | ArgumentReader argReader(L); 182 | argReader.ReadBaseObject(voiceChannel); 183 | argReader.ReadBaseObject(player); 184 | 185 | if (argReader.HasAnyError()) 186 | { 187 | argReader.GetErrorMessages(); 188 | return 0; 189 | } 190 | 191 | voiceChannel->MutePlayer(player); 192 | 193 | return 0; 194 | } 195 | 196 | int VoiceChannel::UnmutePlayer(lua_State* L) 197 | { 198 | alt::IVoiceChannel* voiceChannel; 199 | alt::IPlayer* player; 200 | 201 | ArgumentReader argReader(L); 202 | argReader.ReadBaseObject(voiceChannel); 203 | argReader.ReadBaseObject(player); 204 | 205 | if (argReader.HasAnyError()) 206 | { 207 | argReader.GetErrorMessages(); 208 | return 0; 209 | } 210 | 211 | voiceChannel->UnmutePlayer(player); 212 | 213 | return 0; 214 | } 215 | } 216 | #endif -------------------------------------------------------------------------------- /src/Defs/Entity/VoiceChannel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #ifdef ALT_SERVER_API 6 | namespace lua::Class 7 | { 8 | class VoiceChannel 9 | { 10 | public: 11 | static const char* ClassName; 12 | static void Init(lua_State* L); 13 | 14 | private: 15 | static int Create(lua_State* L); 16 | 17 | static int IsSpatial(lua_State* L); 18 | static int GetMaxDistance(lua_State* L); 19 | 20 | static int HasPlayer(lua_State* L); 21 | static int AddPlayer(lua_State* L); 22 | static int RemovePlayer(lua_State* L); 23 | 24 | static int IsPlayerMuted(lua_State* L); 25 | static int MutePlayer(lua_State* L); 26 | static int UnmutePlayer(lua_State* L); 27 | }; 28 | } 29 | #endif -------------------------------------------------------------------------------- /src/Defs/Entity/WorldObject.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace lua::Class 4 | { 5 | const char* WorldObject::ClassName = "WorldObject"; 6 | void WorldObject::Init(lua_State* L) 7 | { 8 | DEBUG_INFO("WorldObject::Init"); 9 | 10 | lua_beginclass(L, ClassName, BaseObject::ClassName); 11 | { 12 | lua_classfunction(L, "setPosition", SetPosition); 13 | lua_classfunction(L, "getPosition", GetPosition); 14 | lua_classfunction(L, "setDimension", SetDimension); 15 | lua_classfunction(L, "getDimension", GetDimension); 16 | 17 | lua_classvariable(L, "pos", SetPosition, GetPosition); 18 | lua_classvariable(L, "position", SetPosition, GetPosition); 19 | lua_classvariable(L, "dimension", SetDimension, GetDimension); 20 | } 21 | lua_endclass(L); 22 | 23 | DEBUG_INFO("WorldObject::Init ...done"); 24 | } 25 | 26 | int WorldObject::SetPosition(lua_State* L) 27 | { 28 | alt::IWorldObject* worldObject; 29 | alt::Position position; 30 | 31 | ArgumentReader argReader(L); 32 | argReader.ReadBaseObject(worldObject); 33 | argReader.ReadVector(position); 34 | 35 | if (argReader.HasAnyError()) 36 | { 37 | argReader.GetErrorMessages(); 38 | return 0; 39 | } 40 | 41 | //Core->LogInfo("WorldObject::SetPosition: x = " + std::to_string(position.x)); 42 | //Core->LogInfo("WorldObject::SetPosition: y = " + std::to_string(position.y)); 43 | //Core->LogInfo("WorldObject::SetPosition: z = " + std::to_string(position.z)); 44 | 45 | worldObject->SetPosition(position); 46 | 47 | return 0; 48 | } 49 | 50 | int WorldObject::GetPosition(lua_State* L) 51 | { 52 | alt::IWorldObject* worldObject; 53 | 54 | //Core->LogInfo("WorldObject::GetPosition"); 55 | 56 | ArgumentReader argReader(L); 57 | argReader.ReadBaseObject(worldObject); 58 | 59 | if (argReader.HasAnyError()) 60 | { 61 | argReader.GetErrorMessages(); 62 | return 0; 63 | } 64 | 65 | //Core->LogInfo("WorldObject::GetPosition: " + std::to_string(worldObject->GetPosition().x)); 66 | 67 | lua_pushvector3(L, worldObject->GetPosition()); 68 | 69 | return 1; 70 | } 71 | 72 | int WorldObject::SetDimension(lua_State* L) 73 | { 74 | alt::IWorldObject* worldObject; 75 | int dimension; 76 | 77 | ArgumentReader argReader(L); 78 | argReader.ReadBaseObject(worldObject); 79 | argReader.ReadNumber(dimension); 80 | 81 | if (argReader.HasAnyError()) 82 | { 83 | argReader.GetErrorMessages(); 84 | return 0; 85 | } 86 | 87 | worldObject->SetDimension(dimension); 88 | 89 | return 0; 90 | } 91 | 92 | int WorldObject::GetDimension(lua_State* L) 93 | { 94 | alt::IWorldObject* worldObject; 95 | 96 | ArgumentReader argReader(L); 97 | argReader.ReadBaseObject(worldObject); 98 | 99 | if (argReader.HasAnyError()) 100 | { 101 | argReader.GetErrorMessages(); 102 | return 0; 103 | } 104 | 105 | lua_pushnumber(L, worldObject->GetDimension()); 106 | 107 | return 1; 108 | } 109 | } -------------------------------------------------------------------------------- /src/Defs/Entity/WorldObject.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace lua::Class 6 | { 7 | class WorldObject 8 | { 9 | public: 10 | static const char* ClassName; 11 | static void Init(lua_State* L); 12 | 13 | private: 14 | static int SetPosition(lua_State* L); 15 | static int GetPosition(lua_State* L); 16 | 17 | static int SetDimension(lua_State* L); 18 | static int GetDimension(lua_State* L); 19 | }; 20 | } -------------------------------------------------------------------------------- /src/Defs/Resource.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace lua::Class 6 | { 7 | class Resource 8 | { 9 | public: 10 | static const char* ClassName; 11 | static void Init(lua_State* L); 12 | 13 | private: 14 | static int tostring(lua_State* L); 15 | static int pairs(lua_State* L); 16 | static int ipairs(lua_State* L); 17 | 18 | static int ResourceIndex(lua_State* L); 19 | static int Call(lua_State* L); 20 | 21 | static int GetResourceByName(lua_State* L); 22 | static int IsStarted(lua_State* L); 23 | 24 | static int GetConfig(lua_State* L); 25 | 26 | static int GetType(lua_State* L); 27 | static int GetName(lua_State* L); 28 | static int GetPath(lua_State* L); 29 | static int GetMain(lua_State* L); 30 | static int GetExports(lua_State* L); 31 | static int GetDependencies(lua_State* L); 32 | static int GetDependants(lua_State* L); 33 | 34 | static int GetRequiredPermissions(lua_State* L); 35 | static int GetOptionalPermissions(lua_State* L); 36 | }; 37 | } -------------------------------------------------------------------------------- /src/Defs/Shared/MiscScripts.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drakeee/altv-lua-module/f3d18e7ef7f5c7ec089a8652ce02865720385960/src/Defs/Shared/MiscScripts.cpp -------------------------------------------------------------------------------- /src/Defs/Shared/MiscScripts.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace lua::Class 6 | { 7 | class MiscScripts 8 | { 9 | public: 10 | static void Init(lua_State* L); 11 | 12 | private: 13 | static void thread(lua_State* L); 14 | static void inspect(lua_State* L); 15 | }; 16 | } -------------------------------------------------------------------------------- /src/Defs/Shared/RGBA.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace lua::Class 4 | { 5 | const char* RGBA::ClassName = "RGBA"; 6 | void RGBA::Init(lua_State* L) 7 | { 8 | DEBUG_INFO("RGBA::Init"); 9 | 10 | lua_beginclass(L, ClassName); 11 | { 12 | lua_classfunction(L, "new", CreateRGBA); 13 | lua_classfunction(L, "setColor", SetColor); 14 | lua_classfunction(L, "getColor", GetColor); 15 | lua_classfunction(L, "setR", SetR); 16 | lua_classfunction(L, "getR", GetR); 17 | lua_classfunction(L, "setG", SetG); 18 | lua_classfunction(L, "getG", GetG); 19 | lua_classfunction(L, "setB", SetB); 20 | lua_classfunction(L, "getB", GetB); 21 | lua_classfunction(L, "setA", SetA); 22 | lua_classfunction(L, "getA", GetA); 23 | 24 | lua_classvariable(L, "color", "setColor", "getColor"); 25 | lua_classvariable(L, "r", "setR", "getR"); 26 | lua_classvariable(L, "g", "setG", "getG"); 27 | lua_classvariable(L, "b", "setB", "getB"); 28 | lua_classvariable(L, "a", "setA", "getA"); 29 | } 30 | lua_endclass(L); 31 | 32 | DEBUG_INFO("RGBA::Init ...done"); 33 | } 34 | 35 | int RGBA::SetColor(lua_State* L) 36 | { 37 | alt::RGBA* rgba; 38 | alt::RGBA* copy; 39 | 40 | ArgumentReader argReader(L); 41 | argReader.ReadUserData(rgba); 42 | argReader.ReadUserData(copy); 43 | 44 | if (argReader.HasAnyError()) 45 | { 46 | argReader.GetErrorMessages(); 47 | return 0; 48 | } 49 | 50 | rgba->r = copy->r; 51 | rgba->g = copy->g; 52 | rgba->b = copy->b; 53 | rgba->a = copy->a; 54 | 55 | return 0; 56 | } 57 | 58 | int RGBA::GetColor(lua_State* L) 59 | { 60 | alt::RGBA* rgba; 61 | 62 | ArgumentReader argReader(L); 63 | argReader.ReadUserData(rgba); 64 | 65 | if (argReader.HasAnyError()) 66 | { 67 | argReader.GetErrorMessages(); 68 | return 0; 69 | } 70 | 71 | lua_pushnumber(L, rgba->toInt()); 72 | 73 | return 1; 74 | } 75 | 76 | int RGBA::CreateRGBA(lua_State* L) 77 | { 78 | int r, g, b, a; 79 | 80 | ArgumentReader argReader(L); 81 | argReader.ReadNumber(r); 82 | argReader.ReadNumber(g); 83 | argReader.ReadNumber(b); 84 | argReader.ReadNumber(a); 85 | 86 | if (argReader.HasAnyError()) 87 | { 88 | argReader.GetErrorMessages(); 89 | return 0; 90 | } 91 | 92 | lua_pushrgba(L, alt::RGBA(r, g, b, a)); 93 | 94 | return 1; 95 | } 96 | 97 | int RGBA::SetR(lua_State* L) 98 | { 99 | alt::RGBA* rgba; 100 | int r; 101 | 102 | ArgumentReader argReader(L); 103 | argReader.ReadUserData(rgba); 104 | argReader.ReadNumber(r); 105 | 106 | if (argReader.HasAnyError()) 107 | { 108 | argReader.GetErrorMessages(); 109 | return 0; 110 | } 111 | 112 | rgba->r = r; 113 | 114 | return 0; 115 | } 116 | 117 | int RGBA::GetR(lua_State* L) 118 | { 119 | alt::RGBA* rgba; 120 | 121 | ArgumentReader argReader(L); 122 | argReader.ReadUserData(rgba); 123 | 124 | if (argReader.HasAnyError()) 125 | { 126 | argReader.GetErrorMessages(); 127 | return 0; 128 | } 129 | 130 | lua_pushnumber(L, rgba->r); 131 | 132 | return 1; 133 | } 134 | 135 | int RGBA::SetG(lua_State* L) 136 | { 137 | alt::RGBA* rgba; 138 | int g; 139 | 140 | ArgumentReader argReader(L); 141 | argReader.ReadUserData(rgba); 142 | argReader.ReadNumber(g); 143 | 144 | if (argReader.HasAnyError()) 145 | { 146 | argReader.GetErrorMessages(); 147 | return 0; 148 | } 149 | 150 | rgba->g = g; 151 | 152 | return 0; 153 | } 154 | 155 | int RGBA::GetG(lua_State* L) 156 | { 157 | alt::RGBA* rgba; 158 | 159 | ArgumentReader argReader(L); 160 | argReader.ReadUserData(rgba); 161 | 162 | if (argReader.HasAnyError()) 163 | { 164 | argReader.GetErrorMessages(); 165 | return 0; 166 | } 167 | 168 | lua_pushnumber(L, rgba->g); 169 | 170 | return 1; 171 | } 172 | 173 | int RGBA::SetB(lua_State* L) 174 | { 175 | alt::RGBA* rgba; 176 | int b; 177 | 178 | ArgumentReader argReader(L); 179 | argReader.ReadUserData(rgba); 180 | argReader.ReadNumber(b); 181 | 182 | if (argReader.HasAnyError()) 183 | { 184 | argReader.GetErrorMessages(); 185 | return 0; 186 | } 187 | 188 | rgba->b = b; 189 | 190 | return 0; 191 | } 192 | 193 | int RGBA::GetB(lua_State* L) 194 | { 195 | alt::RGBA* rgba; 196 | 197 | ArgumentReader argReader(L); 198 | argReader.ReadUserData(rgba); 199 | 200 | if (argReader.HasAnyError()) 201 | { 202 | argReader.GetErrorMessages(); 203 | return 0; 204 | } 205 | 206 | lua_pushnumber(L, rgba->b); 207 | 208 | return 1; 209 | } 210 | 211 | int RGBA::SetA(lua_State* L) 212 | { 213 | alt::RGBA* rgba; 214 | int a; 215 | 216 | ArgumentReader argReader(L); 217 | argReader.ReadUserData(rgba); 218 | argReader.ReadNumber(a); 219 | 220 | if (argReader.HasAnyError()) 221 | { 222 | argReader.GetErrorMessages(); 223 | return 0; 224 | } 225 | 226 | rgba->a = a; 227 | 228 | return 0; 229 | } 230 | 231 | int RGBA::GetA(lua_State* L) 232 | { 233 | alt::RGBA* rgba; 234 | 235 | ArgumentReader argReader(L); 236 | argReader.ReadUserData(rgba); 237 | 238 | if (argReader.HasAnyError()) 239 | { 240 | argReader.GetErrorMessages(); 241 | return 0; 242 | } 243 | 244 | lua_pushnumber(L, rgba->a); 245 | 246 | return 1; 247 | } 248 | } -------------------------------------------------------------------------------- /src/Defs/Shared/RGBA.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace lua::Class 6 | { 7 | class RGBA 8 | { 9 | public: 10 | static const char* ClassName; 11 | static void Init(lua_State* L); 12 | 13 | private: 14 | static int CreateRGBA(lua_State* L); 15 | 16 | static int SetColor(lua_State* L); 17 | static int GetColor(lua_State* L); 18 | static int SetR(lua_State* L); 19 | static int GetR(lua_State* L); 20 | static int SetG(lua_State* L); 21 | static int GetG(lua_State* L); 22 | static int SetB(lua_State* L); 23 | static int GetB(lua_State* L); 24 | static int SetA(lua_State* L); 25 | static int GetA(lua_State* L); 26 | }; 27 | } -------------------------------------------------------------------------------- /src/Defs/Shared/Vector2.cpp: -------------------------------------------------------------------------------- 1 | #include "Main.h" 2 | 3 | namespace lua::Class 4 | { 5 | const char* Vector2::ClassName = "Vector2"; 6 | void Vector2::Init(lua_State* L) 7 | { 8 | DEBUG_INFO("Vector2::Init"); 9 | 10 | lua_beginclass(L, ClassName); 11 | { 12 | lua_classmeta(L, "__gc", destroy); 13 | lua_classmeta(L, "__tostring", tostring); 14 | lua_classmeta(L, "__add", add); 15 | 16 | lua_classfunction(L, "new", create); 17 | lua_classfunction(L, "setX", SetX); 18 | lua_classfunction(L, "setY", SetY); 19 | lua_classfunction(L, "getX", GetX); 20 | lua_classfunction(L, "getY", GetY); 21 | 22 | lua_classvariable(L, "x", "setX", "getX"); 23 | lua_classvariable(L, "y", "setY", "getY"); 24 | } 25 | lua_endclass(L); 26 | 27 | DEBUG_INFO("Vector2::Init ...done"); 28 | } 29 | 30 | int Vector2::create(lua_State* L) 31 | { 32 | Vector2fp vector(0.0, 0.0); 33 | 34 | ArgumentReader argReader(L); 35 | if (argReader.IsCurrentType(LUA_TTABLE)) 36 | { 37 | //Syntax: Vector3({x = x, y = y, z = z}) 38 | lua_pushstring(L, "x"); 39 | lua_rawget(L, -2); 40 | 41 | if (lua_isnumber(L, -1)) 42 | { 43 | vector[0] = static_cast(lua_tonumber(L, -1)); 44 | lua_pop(L, 1); 45 | } 46 | else { 47 | lua_pop(L, 1); 48 | lua_rawgeti(L, -1, 1); 49 | 50 | if (lua_isnumber(L, -1)) 51 | vector[0] = static_cast(lua_tonumber(L, -1)); 52 | 53 | lua_pop(L, 1); 54 | } 55 | 56 | 57 | lua_pushstring(L, "y"); 58 | lua_rawget(L, -2); 59 | 60 | if (lua_isnumber(L, -1)) 61 | { 62 | vector[1] = static_cast(lua_tonumber(L, -1)); 63 | lua_pop(L, 1); 64 | } 65 | else { 66 | lua_pop(L, 1); 67 | lua_rawgeti(L, -1, 2); 68 | 69 | if (lua_isnumber(L, -1)) 70 | vector[1] = static_cast(lua_tonumber(L, -1)); 71 | 72 | lua_pop(L, 1); 73 | } 74 | 75 | lua_pop(L, 1); 76 | } 77 | else if (argReader.IsCurrentType(LUA_TNUMBER)) 78 | { 79 | argReader.ReadVector(vector); 80 | } 81 | 82 | #ifdef _DEBUG 83 | //Core->LogInfo("Vector3: x = "+ std::to_string(vector.x) +", y = "+ std::to_string(vector.y) +", z = "+ std::to_string(vector.z) +""); 84 | #endif 85 | 86 | Vector2fp* tempVector = new Vector2fp(vector); 87 | 88 | #ifdef _DEBUG 89 | /*printf("Create vector: %d\n", tempVector);*/ 90 | #endif 91 | 92 | // in this case we don't want to store any reference in the Lua registry 93 | // TODO (?): maybe store reference because we might need it (?) 94 | 95 | lua_pushvector2(L, tempVector); 96 | 97 | return 1; 98 | } 99 | 100 | int Vector2::destroy(lua_State* L) 101 | { 102 | Vector2fp* vector = nullptr; 103 | 104 | //lua_stacktrace(L, "destroy"); 105 | 106 | ArgumentReader argReader(L); 107 | argReader.ReadUserData(vector); 108 | 109 | if (!argReader.HasAnyError()) 110 | { 111 | delete vector; 112 | 113 | #ifdef _DEBUG 114 | Core->LogInfo("Vector garbage collected!"); 115 | #endif 116 | 117 | lua_pushboolean(L, true); 118 | return 1; 119 | } 120 | 121 | argReader.GetErrorMessages(); 122 | 123 | #ifdef _DEBUG 124 | Core->LogInfo("Vector failed to destroyed"); 125 | #endif 126 | 127 | lua_pushboolean(L, false); 128 | return 1; 129 | } 130 | 131 | int Vector2::tostring(lua_State* L) 132 | { 133 | Vector2fp* vector = nullptr; 134 | //Vector3 vector; 135 | 136 | ArgumentReader argReader(L); 137 | argReader.ReadUserData(vector); 138 | //argReader.ReadVector3D(vector); 139 | 140 | if (argReader.HasAnyError()) 141 | { 142 | argReader.GetErrorMessages(); 143 | return 0; 144 | } 145 | 146 | char buffer[128]; 147 | sprintf_s(buffer, "Vector2(%.3f, %.3f)", (*vector)[0], (*vector)[1]); 148 | 149 | lua_pushstring(L, buffer); 150 | 151 | //lua_stacktrace(L, "tostring"); 152 | 153 | return 1; 154 | } 155 | 156 | int Vector2::add(lua_State* L) 157 | { 158 | //lua_stacktrace(L, "Vector2::add"); 159 | 160 | Vector2fp* leftVector; 161 | Vector2fp* rightVector; 162 | 163 | ArgumentReader argReader(L); 164 | argReader.ReadUserData(leftVector); 165 | argReader.ReadUserData(rightVector); 166 | 167 | if (argReader.HasAnyError()) 168 | { 169 | argReader.GetErrorMessages(); 170 | 171 | lua_pushnil(L); 172 | 173 | return 1; 174 | } 175 | 176 | Vector2fp* temp = new Vector2fp( 177 | (*leftVector)[0] + (*rightVector)[0], 178 | (*leftVector)[1] + (*rightVector)[1] 179 | ); 180 | 181 | //lua_userdata(L, "Vector3", temp, false); 182 | 183 | /*Core->LogInfo("LeftVector: " + std::to_string(leftVector->x)); 184 | Core->LogInfo("RightVector: " + std::to_string(rightVector->x));*/ 185 | 186 | return 1; 187 | } 188 | 189 | int Vector2::SetX(lua_State* L) 190 | { 191 | Vector2fp* vector; 192 | float x; 193 | 194 | ArgumentReader argReader(L); 195 | argReader.ReadUserData(vector); 196 | argReader.ReadNumber(x); 197 | 198 | if (argReader.HasAnyError()) 199 | { 200 | argReader.GetErrorMessages(); 201 | return 0; 202 | } 203 | 204 | (*vector)[0] = x; 205 | 206 | return 0; 207 | } 208 | 209 | int Vector2::SetY(lua_State* L) 210 | { 211 | Vector2fp* vector; 212 | float y; 213 | 214 | ArgumentReader argReader(L); 215 | argReader.ReadUserData(vector); 216 | argReader.ReadNumber(y); 217 | 218 | if (argReader.HasAnyError()) 219 | { 220 | argReader.GetErrorMessages(); 221 | return 0; 222 | } 223 | 224 | (*vector)[1] = y; 225 | 226 | return 0; 227 | } 228 | 229 | int Vector2::GetX(lua_State* L) 230 | { 231 | Vector2fp* vector; 232 | 233 | ArgumentReader argReader(L); 234 | argReader.ReadUserData(vector); 235 | 236 | if (argReader.HasAnyError()) 237 | { 238 | argReader.GetErrorMessages(); 239 | return 0; 240 | } 241 | 242 | lua_pushnumber(L, (*vector)[0]); 243 | 244 | return 1; 245 | } 246 | 247 | int Vector2::GetY(lua_State* L) 248 | { 249 | Vector2fp* vector; 250 | 251 | ArgumentReader argReader(L); 252 | argReader.ReadUserData(vector); 253 | 254 | if (argReader.HasAnyError()) 255 | { 256 | argReader.GetErrorMessages(); 257 | return 0; 258 | } 259 | 260 | lua_pushnumber(L, (*vector)[1]); 261 | 262 | return 1; 263 | } 264 | } -------------------------------------------------------------------------------- /src/Defs/Shared/Vector2.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace lua::Class 6 | { 7 | class Vector2 8 | { 9 | public: 10 | static const char* ClassName; 11 | static void Init(lua_State* L); 12 | 13 | private: 14 | static int create(lua_State* L); 15 | static int destroy(lua_State* L); 16 | static int tostring(lua_State* L); 17 | static int add(lua_State* L); 18 | 19 | static int SetX(lua_State* L); 20 | static int SetY(lua_State* L); 21 | static int GetX(lua_State* L); 22 | static int GetY(lua_State* L); 23 | }; 24 | } -------------------------------------------------------------------------------- /src/Defs/Shared/Vector3.cpp: -------------------------------------------------------------------------------- 1 | #include "Main.h" 2 | 3 | namespace lua::Class 4 | { 5 | const char* Vector3::ClassName = "Vector3"; 6 | void Vector3::Init(lua_State* L) 7 | { 8 | DEBUG_INFO("Vector3::Init"); 9 | 10 | lua_beginclass(L, ClassName); 11 | { 12 | lua_classmeta(L, "__gc", destroy); 13 | lua_classmeta(L, "__tostring", tostring); 14 | lua_classmeta(L, "__add", add); 15 | 16 | lua_classfunction(L, "new", create); 17 | lua_classfunction(L, "setX", SetX); 18 | lua_classfunction(L, "setY", SetY); 19 | lua_classfunction(L, "setZ", SetZ); 20 | lua_classfunction(L, "getX", GetX); 21 | lua_classfunction(L, "getY", GetY); 22 | lua_classfunction(L, "getZ", GetZ); 23 | 24 | lua_classvariable(L, "x", "setX", "getX"); 25 | lua_classvariable(L, "y", "setY", "getY"); 26 | lua_classvariable(L, "z", "setZ", "getZ"); 27 | } 28 | lua_endclass(L); 29 | 30 | DEBUG_INFO("Vector3::Init ...done"); 31 | } 32 | 33 | int Vector3::create(lua_State* L) 34 | { 35 | Vector3fp vector(0.0, 0.0, 0.0); 36 | 37 | ArgumentReader argReader(L); 38 | if (argReader.IsCurrentType(LUA_TTABLE)) 39 | { 40 | //Syntax: Vector3({x = x, y = y, z = z}) 41 | lua_pushstring(L, "x"); 42 | lua_rawget(L, -2); 43 | 44 | if (lua_isnumber(L, -1)) 45 | { 46 | vector[0] = static_cast(lua_tonumber(L, -1)); 47 | lua_pop(L, 1); 48 | } 49 | else { 50 | lua_pop(L, 1); 51 | lua_rawgeti(L, -1, 1); 52 | 53 | if (lua_isnumber(L, -1)) 54 | vector[0] = static_cast(lua_tonumber(L, -1)); 55 | 56 | lua_pop(L, 1); 57 | } 58 | 59 | 60 | lua_pushstring(L, "y"); 61 | lua_rawget(L, -2); 62 | 63 | if (lua_isnumber(L, -1)) 64 | { 65 | vector[1] = static_cast(lua_tonumber(L, -1)); 66 | lua_pop(L, 1); 67 | } 68 | else { 69 | lua_pop(L, 1); 70 | lua_rawgeti(L, -1, 2); 71 | 72 | if (lua_isnumber(L, -1)) 73 | vector[1] = static_cast(lua_tonumber(L, -1)); 74 | 75 | lua_pop(L, 1); 76 | } 77 | 78 | 79 | lua_pushstring(L, "z"); 80 | lua_rawget(L, -2); 81 | 82 | if (lua_isnumber(L, -1)) 83 | { 84 | vector[2] = static_cast(lua_tonumber(L, -1)); 85 | lua_pop(L, 1); 86 | } 87 | else { 88 | lua_pop(L, 1); 89 | lua_rawgeti(L, -1, 3); 90 | 91 | if (lua_isnumber(L, -1)) 92 | vector[2] = static_cast(lua_tonumber(L, -1)); 93 | 94 | lua_pop(L, 1); 95 | } 96 | 97 | lua_pop(L, 1); 98 | } 99 | else if (argReader.IsCurrentType(LUA_TNUMBER)) 100 | { 101 | argReader.ReadVector(vector); 102 | } 103 | 104 | #ifdef _DEBUG 105 | //Core->LogInfo("Vector3: x = "+ std::to_string(vector.x) +", y = "+ std::to_string(vector.y) +", z = "+ std::to_string(vector.z) +""); 106 | #endif 107 | 108 | Vector3fp* tempVector = new Vector3fp(vector); 109 | 110 | #ifdef _DEBUG 111 | /*printf("Create vector: %d\n", tempVector);*/ 112 | #endif 113 | 114 | // in this case we don't want to store any reference in the Lua registry 115 | // TODO (?): maybe store reference because we might need it (?) 116 | 117 | lua_pushuserdata(L, "Vector3", tempVector, false); 118 | 119 | return 1; 120 | } 121 | 122 | int Vector3::destroy(lua_State* L) 123 | { 124 | Vector3fp* vector = nullptr; 125 | 126 | //lua_stacktrace(L, "destroy"); 127 | 128 | ArgumentReader argReader(L); 129 | argReader.ReadUserData(vector); 130 | 131 | if (!argReader.HasAnyError()) 132 | { 133 | delete vector; 134 | 135 | #ifdef _DEBUG 136 | Core->LogInfo("Vector garbage collected!"); 137 | #endif 138 | 139 | lua_pushboolean(L, true); 140 | return 1; 141 | } 142 | 143 | argReader.GetErrorMessages(); 144 | 145 | #ifdef _DEBUG 146 | Core->LogInfo("Vector failed to destroyed"); 147 | #endif 148 | 149 | lua_pushboolean(L, false); 150 | return 1; 151 | } 152 | 153 | int Vector3::tostring(lua_State* L) 154 | { 155 | Vector3fp* vector = nullptr; 156 | //Vector3 vector; 157 | 158 | ArgumentReader argReader(L); 159 | argReader.ReadUserData(vector); 160 | //argReader.ReadVector3D(vector); 161 | 162 | if (argReader.HasAnyError()) 163 | { 164 | argReader.GetErrorMessages(); 165 | return 0; 166 | } 167 | 168 | char buffer[128]; 169 | sprintf_s(buffer, "Vector3(%.3f, %.3f, %.3f)", (*vector)[0], (*vector)[1], (*vector)[2]); 170 | 171 | lua_pushstring(L, buffer); 172 | 173 | //lua_stacktrace(L, "tostring"); 174 | 175 | return 1; 176 | } 177 | 178 | int Vector3::add(lua_State* L) 179 | { 180 | //lua_stacktrace(L, "Vector3::add"); 181 | 182 | Vector3fp* leftVector; 183 | Vector3fp* rightVector; 184 | 185 | ArgumentReader argReader(L); 186 | argReader.ReadUserData(leftVector); 187 | argReader.ReadUserData(rightVector); 188 | 189 | if (argReader.HasAnyError()) 190 | { 191 | argReader.GetErrorMessages(); 192 | 193 | lua_pushnil(L); 194 | 195 | return 1; 196 | } 197 | 198 | Vector3fp* temp = new Vector3fp( 199 | (*leftVector)[0] + (*rightVector)[0], 200 | (*leftVector)[1] + (*rightVector)[1], 201 | (*leftVector)[2] + (*rightVector)[2] 202 | ); 203 | 204 | //lua_userdata(L, "Vector3", temp, false); 205 | 206 | /*Core->LogInfo("LeftVector: " + std::to_string(leftVector->x)); 207 | Core->LogInfo("RightVector: " + std::to_string(rightVector->x));*/ 208 | 209 | return 1; 210 | } 211 | 212 | int Vector3::SetX(lua_State* L) 213 | { 214 | Vector3fp* vector; 215 | float x; 216 | 217 | ArgumentReader argReader(L); 218 | argReader.ReadUserData(vector); 219 | argReader.ReadNumber(x); 220 | 221 | if (argReader.HasAnyError()) 222 | { 223 | argReader.GetErrorMessages(); 224 | return 0; 225 | } 226 | 227 | (*vector)[0] = x; 228 | 229 | return 0; 230 | } 231 | 232 | int Vector3::SetY(lua_State* L) 233 | { 234 | Vector3fp* vector; 235 | float y; 236 | 237 | ArgumentReader argReader(L); 238 | argReader.ReadUserData(vector); 239 | argReader.ReadNumber(y); 240 | 241 | if (argReader.HasAnyError()) 242 | { 243 | argReader.GetErrorMessages(); 244 | return 0; 245 | } 246 | 247 | (*vector)[1] = y; 248 | 249 | return 0; 250 | } 251 | 252 | int Vector3::SetZ(lua_State* L) 253 | { 254 | Vector3fp* vector; 255 | float z; 256 | 257 | ArgumentReader argReader(L); 258 | argReader.ReadUserData(vector); 259 | argReader.ReadNumber(z); 260 | 261 | if (argReader.HasAnyError()) 262 | { 263 | argReader.GetErrorMessages(); 264 | return 0; 265 | } 266 | 267 | (*vector)[2] = z; 268 | 269 | return 0; 270 | } 271 | 272 | int Vector3::GetX(lua_State* L) 273 | { 274 | Vector3fp* vector; 275 | 276 | ArgumentReader argReader(L); 277 | argReader.ReadUserData(vector); 278 | 279 | if (argReader.HasAnyError()) 280 | { 281 | argReader.GetErrorMessages(); 282 | return 0; 283 | } 284 | 285 | lua_pushnumber(L, (*vector)[0]); 286 | 287 | return 1; 288 | } 289 | 290 | int Vector3::GetY(lua_State* L) 291 | { 292 | Vector3fp* vector; 293 | 294 | ArgumentReader argReader(L); 295 | argReader.ReadUserData(vector); 296 | 297 | if (argReader.HasAnyError()) 298 | { 299 | argReader.GetErrorMessages(); 300 | return 0; 301 | } 302 | 303 | lua_pushnumber(L, (*vector)[1]); 304 | 305 | return 1; 306 | } 307 | 308 | int Vector3::GetZ(lua_State* L) 309 | { 310 | Vector3fp* vector; 311 | 312 | ArgumentReader argReader(L); 313 | argReader.ReadUserData(vector); 314 | 315 | if (argReader.HasAnyError()) 316 | { 317 | argReader.GetErrorMessages(); 318 | return 0; 319 | } 320 | 321 | lua_pushnumber(L, (*vector)[2]); 322 | 323 | return 1; 324 | } 325 | } -------------------------------------------------------------------------------- /src/Defs/Shared/Vector3.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace lua::Class 6 | { 7 | class Vector3 8 | { 9 | public: 10 | static const char* ClassName; 11 | static void Init(lua_State* L); 12 | 13 | private: 14 | static int create(lua_State* L); 15 | static int destroy(lua_State* L); 16 | static int tostring(lua_State* L); 17 | static int add(lua_State* L); 18 | 19 | static int SetX(lua_State* L); 20 | static int SetY(lua_State* L); 21 | static int SetZ(lua_State* L); 22 | static int GetX(lua_State* L); 23 | static int GetY(lua_State* L); 24 | static int GetZ(lua_State* L); 25 | }; 26 | } -------------------------------------------------------------------------------- /src/Defs/Voice.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifdef ALT_CLIENT_API 4 | namespace lua::Class 5 | { 6 | const char* Voice::ClassName = "Voice"; 7 | void Voice::Init(lua_State* L) 8 | { 9 | DEBUG_INFO("Voice::Init"); 10 | 11 | lua_globalfunction(L, "setVoiceInputMuted", SetVoiceInputMuted); 12 | lua_globalfunction(L, "isVoiceInputMuted", IsVoiceInputMuted); 13 | lua_globalfunction(L, "isVoiceActivationEnabled", IsVoiceActivationEnabled); 14 | lua_globalfunction(L, "toggleVoiceControls", ToggleVoiceControls); 15 | 16 | lua_beginclass(L, Voice::ClassName); 17 | { 18 | lua_classfunction(L, "toggleControls", ToggleVoiceControls); 19 | 20 | lua_classvariable(L, "muteInput", SetVoiceInputMuted, IsVoiceInputMuted); 21 | lua_classvariable(L, "activityInputEnabled", nullptr, IsVoiceActivationEnabled); 22 | //lua_classvariable(L, "activationKey", nullptr, GetVoiceActivationKey); 23 | } 24 | lua_endclass(L); 25 | 26 | DEBUG_INFO("Voice::Init ...done"); 27 | } 28 | 29 | int Voice::SetVoiceInputMuted(lua_State* L) 30 | { 31 | bool state; 32 | 33 | ArgumentReader argReader(L); 34 | argReader.ReadBool(state); 35 | 36 | if (argReader.HasAnyError()) 37 | { 38 | argReader.GetErrorMessages(); 39 | return 0; 40 | } 41 | 42 | Core->SetVoiceInputMuted(state); 43 | 44 | return 0; 45 | } 46 | 47 | int Voice::IsVoiceInputMuted(lua_State* L) 48 | { 49 | lua_pushboolean(L, Core->IsVoiceInputMuted()); 50 | 51 | return 1; 52 | } 53 | 54 | int Voice::IsVoiceActivationEnabled(lua_State* L) 55 | { 56 | lua_pushboolean(L, Core->IsVoiceActivationEnabled()); 57 | 58 | return 1; 59 | } 60 | 61 | //int Voice::GetVoiceActivationKey(lua_State* L) 62 | //{ 63 | // lua_pushboolean(L, Core->GetVoiceActivationKey()); 64 | // 65 | // return 1; 66 | //} 67 | 68 | int Voice::ToggleVoiceControls(lua_State* L) 69 | { 70 | bool state; 71 | 72 | ArgumentReader argReader(L); 73 | argReader.ReadBool(state); 74 | 75 | if (argReader.HasAnyError()) 76 | { 77 | argReader.GetErrorMessages(); 78 | return 0; 79 | } 80 | 81 | Core->ToggleVoiceControls(state); 82 | 83 | return 0; 84 | } 85 | } 86 | #endif -------------------------------------------------------------------------------- /src/Defs/Voice.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace lua::Class 6 | { 7 | class Voice 8 | { 9 | public: 10 | static const char* ClassName; 11 | static void Init(lua_State* L); 12 | private: 13 | static int SetVoiceInputMuted(lua_State* L); 14 | static int IsVoiceInputMuted(lua_State* L); 15 | static int IsVoiceActivationEnabled(lua_State* L); 16 | static int ToggleVoiceControls(lua_State* L); 17 | //static int GetVoiceActivationKey(lua_State* L); 18 | }; 19 | } -------------------------------------------------------------------------------- /src/EventManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #define REGISTER_LOCAL_EVENT(eventType,eventName,...) \ 6 | EventManager::Handler eventName(eventType,#eventName,__VA_ARGS__) 7 | 8 | class LuaResourceImpl; 9 | class EventManager 10 | { 11 | public: 12 | typedef std::function FunctionCallback; 13 | typedef std::function (LuaResourceImpl*, const alt::CEvent*)> CallbackGetter; 14 | 15 | class Handler 16 | { 17 | public: 18 | Handler(alt::CEvent::Type eventType, const std::string& eventName, FunctionCallback callback, CallbackGetter getter = nullptr); 19 | Handler(alt::CEvent::Type eventType, const std::string& eventName, alt::IBaseObject::Type baseObjectType, FunctionCallback callback, CallbackGetter getter = nullptr); 20 | void Invoke(void); 21 | 22 | private: 23 | EventManager* eventManager; 24 | 25 | alt::CEvent::Type eventType; 26 | std::string eventName; 27 | int baseObjectType = -1; 28 | 29 | FunctionCallback callback; 30 | CallbackGetter getter; 31 | }; 32 | 33 | struct Event 34 | { 35 | alt::CEvent::Type eventType; 36 | std::string eventName{ "" }; 37 | 38 | int baseObjectType = -1; 39 | 40 | FunctionCallback PushFunctionArguments = nullptr; 41 | CallbackGetter GetFunctionReferences = nullptr; 42 | 43 | bool IsBaseObjectEvent(void) { return this->baseObjectType != -1; } 44 | bool IsResourceEvent(void) { return !this->eventName.empty(); } 45 | }; 46 | 47 | alt::CEvent::Type GetEventTypeFromName(const std::string& eventName); 48 | std::string GetEventNameFromType(alt::CEvent::Type eventType); 49 | alt::CEvent::Type GetEventTypeFromBaseObject(alt::IBaseObject* baseObject); 50 | 51 | Event* GetEventByType(alt::CEvent::Type eventType); 52 | Event* GetEventByName(const std::string& eventName); 53 | 54 | inline void RegisterHandler(Handler* handler) { this->handlers.push_back(handler); } 55 | inline std::vector& GetAllHandlers(void) { return this->handlers; } 56 | 57 | void RegisterEvent(alt::CEvent::Type eventType, const std::string& eventName, FunctionCallback callback, CallbackGetter getter = nullptr); 58 | void RegisterBaseObjectEvent(alt::CEvent::Type eventType, int baseObjectType, FunctionCallback callback, CallbackGetter getter = nullptr); 59 | 60 | void Emit(const std::string& eventName, alt::MValueArgs& args); 61 | 62 | static EventManager& Instance() 63 | { 64 | static EventManager _Instance; 65 | return _Instance; 66 | } 67 | 68 | private: 69 | EventManager() { }; 70 | ~EventManager() { }; 71 | 72 | typedef std::map EventMap; 73 | EventMap eventDatas; 74 | 75 | std::vector handlers; 76 | 77 | void RegisterBaseObject(alt::CEvent::Type eventType, int baseObjectType); 78 | }; 79 | 80 | class ResourceEventManager 81 | { 82 | public: 83 | /*struct FunctionRef 84 | { 85 | int reference; 86 | bool isLocal = true; 87 | };*/ 88 | 89 | ResourceEventManager(LuaResourceImpl* resourceImpl); 90 | 91 | //bool SubscribeEvent(const std::string& eventName, int functionReference); 92 | bool SubscribeEvent(alt::IBaseObject* baseObject, const std::string& eventName, int functionReference); 93 | bool SubscribeLocalEvent(std::string& eventName, int functionReference); 94 | bool SubscribeRemoteEvent(std::string& eventName, int functionReference); 95 | 96 | bool UnsubscribeLocalEvent(std::string& eventName, int functionReference); 97 | bool UnsubscribeRemoteEvent(std::string& eventName, int functionReference); 98 | 99 | bool UnsubscribeEvent(const std::string& eventName, int functionReference); 100 | bool UnsubscribeEvent(alt::IBaseObject* baseObject, const std::string& eventName, int functionReference); 101 | 102 | std::vector GetFunctionReferences(alt::CEvent::Type eventType); 103 | std::vector GetFunctionReferences(alt::CEvent::Type eventType, std::string& eventName); 104 | std::vector GetFunctionReferences(alt::IBaseObject* baseObject, std::string& eventName); 105 | 106 | std::vector GetLocalFunctionReferences(std::string& eventName); 107 | std::vector GetRemoteFunctionReferences(std::string& eventName); 108 | 109 | void Emit(const std::string& eventName, alt::MValueArgs& args); 110 | 111 | bool ProcessEvents(const alt::CEvent* ev); 112 | 113 | private: 114 | EventManager* manager; 115 | LuaResourceImpl* resourceImpl; 116 | 117 | typedef std::vector FunctionReferences; 118 | typedef std::map EventsMap; 119 | 120 | typedef std::map ResourceEvents; 121 | ResourceEvents resourceEvents; 122 | 123 | typedef std::map> BaseObjectEvents; 124 | BaseObjectEvents baseObjectEvents; 125 | }; -------------------------------------------------------------------------------- /src/Events/Client/EntityEvents.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifdef ALT_CLIENT_API 4 | 5 | #include 6 | #include 7 | 8 | REGISTER_LOCAL_EVENT( 9 | alt::CEvent::Type::GAME_ENTITY_CREATE, 10 | gameEntityCreate, 11 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 12 | { 13 | const alt::CGameEntityCreateEvent* event = static_cast(ev); 14 | lua_State* L = resourceImpl->GetLuaState(); 15 | 16 | lua_pushbaseobject(L, event->GetTarget()); 17 | 18 | return 1; 19 | } 20 | ); 21 | 22 | REGISTER_LOCAL_EVENT( 23 | alt::CEvent::Type::GAME_ENTITY_DESTROY, 24 | gameEntityDestroy, 25 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 26 | { 27 | const alt::CGameEntityDestroyEvent* event = static_cast(ev); 28 | lua_State* L = resourceImpl->GetLuaState(); 29 | 30 | lua_pushbaseobject(L, event->GetTarget()); 31 | 32 | return 1; 33 | } 34 | ); 35 | 36 | REGISTER_LOCAL_EVENT( 37 | alt::CEvent::Type::WEB_VIEW_EVENT, 38 | WEB_VIEW, 39 | alt::IBaseObject::Type::WEBVIEW, 40 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 41 | { 42 | const alt::CWebViewEvent* event = static_cast(ev); 43 | lua_State* L = resourceImpl->GetLuaState(); 44 | 45 | for (auto arg : event->GetArgs()) 46 | { 47 | lua_pushmvalue(L, arg); 48 | } 49 | 50 | return static_cast(event->GetArgs().GetSize()); 51 | }, 52 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> std::vector 53 | { 54 | const alt::CWebViewEvent* event = static_cast(ev); 55 | ResourceEventManager* resourceEventManager = resourceImpl->GetResourceEventManager(); 56 | 57 | return resourceEventManager->GetFunctionReferences(event->GetTarget().Get(), const_cast(event->GetName())); 58 | } 59 | ); 60 | 61 | REGISTER_LOCAL_EVENT( 62 | alt::CEvent::Type::WEB_SOCKET_CLIENT_EVENT, 63 | WEB_SOCKET_CLIENT, 64 | alt::IBaseObject::Type::WEBSOCKET_CLIENT, 65 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 66 | { 67 | const alt::CWebSocketClientEvent* event = static_cast(ev); 68 | lua_State* L = resourceImpl->GetLuaState(); 69 | 70 | for (auto arg : event->GetArgs()) 71 | { 72 | lua_pushmvalue(L, arg); 73 | } 74 | 75 | return static_cast(event->GetArgs().GetSize()); 76 | }, 77 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> std::vector 78 | { 79 | const alt::CWebViewEvent* event = static_cast(ev); 80 | ResourceEventManager* resourceEventManager = resourceImpl->GetResourceEventManager(); 81 | 82 | return resourceEventManager->GetFunctionReferences(event->GetTarget().Get(), const_cast(event->GetName())); 83 | } 84 | ); 85 | 86 | REGISTER_LOCAL_EVENT( 87 | alt::CEvent::Type::AUDIO_EVENT, 88 | AUDIO_EVENT, 89 | alt::IBaseObject::Type::AUDIO, 90 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 91 | { 92 | const alt::CWebSocketClientEvent* event = static_cast(ev); 93 | lua_State* L = resourceImpl->GetLuaState(); 94 | 95 | for (auto arg : event->GetArgs()) 96 | { 97 | lua_pushmvalue(L, arg); 98 | } 99 | 100 | return static_cast(event->GetArgs().GetSize()); 101 | }, 102 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> std::vector 103 | { 104 | const alt::CWebViewEvent* event = static_cast(ev); 105 | ResourceEventManager* resourceEventManager = resourceImpl->GetResourceEventManager(); 106 | 107 | return resourceEventManager->GetFunctionReferences(event->GetTarget().Get(), const_cast(event->GetName())); 108 | } 109 | ); 110 | 111 | REGISTER_LOCAL_EVENT( 112 | alt::CEvent::Type::RMLUI_EVENT, 113 | RMLUI, 114 | alt::IBaseObject::Type::RML_ELEMENT, 115 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 116 | { 117 | const alt::CRmlEvent* event = static_cast(ev); 118 | lua_State* L = resourceImpl->GetLuaState(); 119 | 120 | //for (auto arg : event->GetArgs()) 121 | //{ 122 | lua_pushmvalue(L, event->GetArgs()); 123 | //} 124 | 125 | //return static_cast(event->GetArgs().GetSize()); 126 | 127 | return 1; 128 | }, 129 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> std::vector 130 | { 131 | const alt::CRmlEvent* event = static_cast(ev); 132 | ResourceEventManager* resourceEventManager = resourceImpl->GetResourceEventManager(); 133 | 134 | return resourceEventManager->GetFunctionReferences(event->GetElement().Get(), event->GetName()); 135 | } 136 | ); 137 | 138 | #endif -------------------------------------------------------------------------------- /src/Events/Client/MiscEvents.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifdef ALT_CLIENT_API 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | REGISTER_LOCAL_EVENT( 10 | alt::CEvent::Type::KEYBOARD_EVENT, 11 | keyboard, 12 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 13 | { 14 | const alt::CKeyboardEvent* event = static_cast(ev); 15 | lua_State* L = resourceImpl->GetLuaState(); 16 | 17 | lua_pushnumber(L, event->GetKeyCode()); 18 | 19 | return 1; 20 | }, 21 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) 22 | { 23 | const alt::CKeyboardEvent* event = static_cast(ev); 24 | ResourceEventManager* resourceEventManager = resourceImpl->GetResourceEventManager(); 25 | 26 | std::string eventName{ "keyup" }; 27 | if (event->GetKeyState() == alt::CKeyboardEvent::KeyState::DOWN) 28 | eventName.assign("keydown"); 29 | 30 | return resourceEventManager->GetLocalFunctionReferences(eventName); 31 | } 32 | ); 33 | 34 | REGISTER_LOCAL_EVENT( 35 | alt::CEvent::Type::CONNECTION_COMPLETE, 36 | connectionComplete, 37 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int { return 0; } 38 | ); 39 | 40 | REGISTER_LOCAL_EVENT( 41 | alt::CEvent::Type::DISCONNECT_EVENT, 42 | disconnect, 43 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int { return 0; } 44 | ); 45 | 46 | REGISTER_LOCAL_EVENT( 47 | alt::CEvent::Type::TASK_CHANGE, 48 | taskChange, 49 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 50 | { 51 | const alt::CTaskChangeEvent* event = static_cast(ev); 52 | lua_State* L = resourceImpl->GetLuaState(); 53 | 54 | lua_pushnumber(L, event->GetOldTask()); 55 | lua_pushnumber(L, event->GetNewTask()); 56 | 57 | return 2; 58 | } 59 | ); 60 | 61 | REGISTER_LOCAL_EVENT( 62 | alt::CEvent::Type::SPAWNED, 63 | spawned, 64 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int { return 0; } 65 | ); 66 | 67 | REGISTER_LOCAL_EVENT( 68 | alt::CEvent::Type::WINDOW_FOCUS_CHANGE, 69 | windowFocusChange, 70 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 71 | { 72 | const alt::CWindowFocusChangeEvent* event = static_cast(ev); 73 | lua_State* L = resourceImpl->GetLuaState(); 74 | 75 | lua_pushboolean(L, event->GetState()); 76 | 77 | return 1; 78 | } 79 | ); 80 | 81 | REGISTER_LOCAL_EVENT( 82 | alt::CEvent::Type::WINDOW_RESOLUTION_CHANGE, 83 | windowResolutionChange, 84 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 85 | { 86 | const alt::CWindowResolutionChangeEvent* event = static_cast(ev); 87 | lua_State* L = resourceImpl->GetLuaState(); 88 | 89 | lua_pushvector2(L, event->GetOldResolution()); 90 | lua_pushvector2(L, event->GetNewResolution()); 91 | 92 | return 2; 93 | } 94 | ); 95 | 96 | #endif -------------------------------------------------------------------------------- /src/Events/Server/MiscEvents.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifdef ALT_SERVER_API 4 | 5 | REGISTER_LOCAL_EVENT( 6 | alt::CEvent::Type::CREATE_BASE_OBJECT_EVENT, 7 | createBaseObject, 8 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 9 | { 10 | const alt::CCreateBaseObjectEvent* event = static_cast(ev); 11 | lua_State* L = resourceImpl->GetLuaState(); 12 | 13 | lua_pushbaseobject(L, event->GetObject()); 14 | 15 | return 1; 16 | } 17 | ); 18 | 19 | REGISTER_LOCAL_EVENT( 20 | alt::CEvent::Type::REMOVE_BASE_OBJECT_EVENT, 21 | removeBaseObject, 22 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 23 | { 24 | const alt::CRemoveBaseObjectEvent* event = static_cast(ev); 25 | lua_State* L = resourceImpl->GetLuaState(); 26 | 27 | lua_pushbaseobject(L, event->GetObject()); 28 | 29 | return 1; 30 | } 31 | ); 32 | 33 | REGISTER_LOCAL_EVENT( 34 | alt::CEvent::Type::FIRE_EVENT, 35 | startFire, 36 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 37 | { 38 | const alt::CFireEvent* event = static_cast(ev); 39 | lua_State* L = resourceImpl->GetLuaState(); 40 | 41 | const alt::Array& fires = event->GetFires(); 42 | 43 | lua_pushbaseobject(L, event->GetSource().Get()); 44 | lua_newtable(L); 45 | for (int i = 0; i < fires.GetSize(); ++i) 46 | { 47 | auto fire = fires[i]; 48 | 49 | lua_pushnumber(L, i + 1); 50 | lua_newtable(L); 51 | 52 | lua_setfield(L, -1, "position", fire.position); 53 | lua_setfield(L, -1, "weapon", fire.weaponHash); 54 | 55 | lua_rawset(L, -3); 56 | } 57 | 58 | return 2; 59 | } 60 | ); 61 | 62 | REGISTER_LOCAL_EVENT( 63 | alt::CEvent::Type::EXPLOSION_EVENT, 64 | explosion, 65 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 66 | { 67 | const alt::CExplosionEvent* event = static_cast(ev); 68 | lua_State* L = resourceImpl->GetLuaState(); 69 | 70 | lua_pushbaseobject(L, event->GetSource().Get()); 71 | lua_pushnumber(L, static_cast(event->GetExplosionType())); 72 | lua_pushvector3(L, event->GetPosition()); 73 | lua_pushnumber(L, event->GetExplosionFX()); 74 | 75 | return 4; 76 | } 77 | ); 78 | 79 | REGISTER_LOCAL_EVENT( 80 | alt::CEvent::Type::START_PROJECTILE_EVENT, 81 | startProjectile, 82 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 83 | { 84 | const alt::CStartProjectileEvent* event = static_cast(ev); 85 | lua_State* L = resourceImpl->GetLuaState(); 86 | 87 | lua_pushbaseobject(L, event->GetSource().Get()); 88 | lua_pushvector3(L, event->GetStartPosition()); 89 | lua_pushvector3(L, event->GetDirection()); 90 | lua_pushnumber(L, event->GetAmmoHash()); 91 | lua_pushnumber(L, event->GetWeaponHash()); 92 | 93 | return 5; 94 | } 95 | ); 96 | 97 | REGISTER_LOCAL_EVENT( 98 | alt::CEvent::Type::WEAPON_DAMAGE_EVENT, 99 | weaponDamage, 100 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 101 | { 102 | const alt::CWeaponDamageEvent* event = static_cast(ev); 103 | lua_State* L = resourceImpl->GetLuaState(); 104 | 105 | lua_pushbaseobject(L, event->GetSource().Get()); 106 | lua_pushbaseobject(L, event->GetTarget().Get()); 107 | lua_pushnumber(L, event->GetWeaponHash()); 108 | lua_pushnumber(L, event->GetDamageValue()); 109 | lua_pushvector3(L, event->GetShotOffset()); 110 | lua_pushnumber(L, static_cast(event->GetBodyPart())); 111 | 112 | return 6; 113 | } 114 | ); 115 | 116 | REGISTER_LOCAL_EVENT( 117 | alt::CEvent::Type::COLSHAPE_EVENT, 118 | COLSHAPE_EVENT, 119 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 120 | { 121 | const alt::CColShapeEvent* event = static_cast(ev); 122 | lua_State* L = resourceImpl->GetLuaState(); 123 | 124 | lua_pushbaseobject(L, event->GetTarget().Get()); 125 | lua_pushbaseobject(L, event->GetEntity().Get()); 126 | lua_pushboolean(L, event->GetState()); 127 | 128 | return 2; 129 | }, 130 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> std::vector 131 | { 132 | const alt::CColShapeEvent* event = static_cast(ev); 133 | ResourceEventManager* resourceEventManager = resourceImpl->GetResourceEventManager(); 134 | 135 | std::string eventName = event->GetState() ? "entityEnterColshape" : "entityLeaveColshape"; 136 | return resourceEventManager->GetLocalFunctionReferences(eventName); 137 | } 138 | ); 139 | 140 | REGISTER_LOCAL_EVENT( 141 | alt::CEvent::Type::NETOWNER_CHANGE, 142 | netOwnerChange, 143 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 144 | { 145 | const alt::CNetOwnerChangeEvent* event = static_cast(ev); 146 | lua_State* L = resourceImpl->GetLuaState(); 147 | 148 | lua_pushbaseobject(L, event->GetTarget().Get()); 149 | lua_pushbaseobject(L, event->GetNewOwner().Get()); 150 | lua_pushbaseobject(L, event->GetOldOwner().Get()); 151 | 152 | return 3; 153 | } 154 | ); 155 | 156 | REGISTER_LOCAL_EVENT( 157 | alt::CEvent::Type::REMOVE_ENTITY_EVENT, 158 | removeEntity, 159 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 160 | { 161 | const alt::CRemoveEntityEvent* event = static_cast(ev); 162 | lua_State* L = resourceImpl->GetLuaState(); 163 | 164 | lua_pushbaseobject(L, event->GetEntity().Get()); 165 | 166 | return 1; 167 | } 168 | ); 169 | 170 | REGISTER_LOCAL_EVENT( 171 | alt::CEvent::Type::SERVER_STARTED, 172 | serverStarted, 173 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 174 | { 175 | return 0; 176 | } 177 | ); 178 | 179 | #endif -------------------------------------------------------------------------------- /src/Events/Server/PlayerEvents.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifdef ALT_SERVER_API 4 | 5 | REGISTER_LOCAL_EVENT( 6 | alt::CEvent::Type::PLAYER_BEFORE_CONNECT, 7 | beforePlayerConnect, 8 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 9 | { 10 | const alt::CPlayerBeforeConnectEvent* event = static_cast(ev); 11 | lua_State* L = resourceImpl->GetLuaState(); 12 | 13 | const alt::Ref connectionInfo = event->GetConnectionInfo(); 14 | lua_newtable(L); 15 | { 16 | lua_setfield(L, -1, "name", connectionInfo->GetName()); 17 | lua_setfield(L, -1, "socialID", std::to_string(connectionInfo->GetSocialId())); 18 | lua_setfield(L, -1, "hwidHash", std::to_string(connectionInfo->GetHwIdHash())); 19 | lua_setfield(L, -1, "hwidExHash", std::to_string(connectionInfo->GetHwIdExHash())); 20 | lua_setfield(L, -1, "authToken", connectionInfo->GetAuthToken()); 21 | lua_setfield(L, -1, "isDebug", connectionInfo->GetIsDebug()); 22 | lua_setfield(L, -1, "branch", connectionInfo->GetBranch()); 23 | lua_setfield(L, -1, "build", connectionInfo->GetBuild()); 24 | lua_setfield(L, -1, "cdnUrl", connectionInfo->GetCdnUrl()); 25 | lua_setfield(L, -1, "passwordHash", connectionInfo->GetPasswordHash()); 26 | } 27 | 28 | lua_pushstring(L, event->GetReason()); 29 | 30 | return 2; 31 | } 32 | ); 33 | 34 | REGISTER_LOCAL_EVENT( 35 | alt::CEvent::Type::PLAYER_CONNECT, 36 | playerConnect, 37 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 38 | { 39 | const alt::CPlayerConnectEvent* event = static_cast(ev); 40 | lua_State* L = resourceImpl->GetLuaState(); 41 | 42 | lua_pushbaseobject(L, event->GetTarget().Get()); 43 | 44 | return 1; 45 | } 46 | ); 47 | 48 | REGISTER_LOCAL_EVENT( 49 | alt::CEvent::Type::PLAYER_DISCONNECT, 50 | playerDisconnect, 51 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 52 | { 53 | const alt::CPlayerDisconnectEvent* event = static_cast(ev); 54 | lua_State* L = resourceImpl->GetLuaState(); 55 | 56 | lua_pushbaseobject(L, event->GetTarget().Get()); 57 | lua_pushstring(L, event->GetReason()); 58 | 59 | return 2; 60 | } 61 | ); 62 | 63 | REGISTER_LOCAL_EVENT( 64 | alt::CEvent::Type::PLAYER_DAMAGE, 65 | playerDamage, 66 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 67 | { 68 | const alt::CPlayerDamageEvent* event = static_cast(ev); 69 | lua_State* L = resourceImpl->GetLuaState(); 70 | 71 | lua_pushbaseobject(L, event->GetTarget().Get()); 72 | 73 | if (event->GetAttacker()) 74 | lua_pushbaseobject(L, event->GetAttacker().Get()); 75 | else 76 | lua_pushnil(L); 77 | 78 | lua_pushnumber(L, event->GetWeapon()); 79 | lua_pushnumber(L, event->GetHealthDamage()); 80 | lua_pushnumber(L, event->GetArmourDamage()); 81 | 82 | return 5; 83 | } 84 | ); 85 | 86 | REGISTER_LOCAL_EVENT( 87 | alt::CEvent::Type::PLAYER_DEATH, 88 | playerDeath, 89 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 90 | { 91 | const alt::CPlayerDeathEvent* event = static_cast(ev); 92 | lua_State* L = resourceImpl->GetLuaState(); 93 | 94 | lua_pushbaseobject(L, event->GetTarget().Get()); 95 | 96 | if (event->GetKiller()) 97 | lua_pushbaseobject(L, event->GetKiller().Get()); 98 | else 99 | lua_pushnil(L); 100 | 101 | lua_pushnumber(L, event->GetWeapon()); 102 | 103 | return 3; 104 | } 105 | ); 106 | 107 | REGISTER_LOCAL_EVENT( 108 | alt::CEvent::Type::PLAYER_ENTER_VEHICLE, 109 | playerEnteredVehicle, 110 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 111 | { 112 | const alt::CPlayerEnterVehicleEvent* event = static_cast(ev); 113 | lua_State* L = resourceImpl->GetLuaState(); 114 | 115 | lua_pushbaseobject(L, event->GetPlayer().Get()); 116 | lua_pushbaseobject(L, event->GetTarget().Get()); 117 | lua_pushnumber(L, event->GetSeat()); 118 | 119 | return 3; 120 | } 121 | ); 122 | 123 | REGISTER_LOCAL_EVENT( 124 | alt::CEvent::Type::PLAYER_ENTERING_VEHICLE, 125 | playerEnteringVehicle, 126 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 127 | { 128 | const alt::CPlayerEnteringVehicleEvent* event = static_cast(ev); 129 | lua_State* L = resourceImpl->GetLuaState(); 130 | 131 | lua_pushbaseobject(L, event->GetPlayer().Get()); 132 | lua_pushbaseobject(L, event->GetTarget().Get()); 133 | lua_pushnumber(L, event->GetSeat()); 134 | 135 | return 3; 136 | } 137 | ); 138 | 139 | REGISTER_LOCAL_EVENT( 140 | alt::CEvent::Type::PLAYER_LEAVE_VEHICLE, 141 | playerLeftVehicle, 142 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 143 | { 144 | const alt::CPlayerLeaveVehicleEvent* event = static_cast(ev); 145 | lua_State* L = resourceImpl->GetLuaState(); 146 | 147 | lua_pushbaseobject(L, event->GetPlayer().Get()); 148 | lua_pushbaseobject(L, event->GetTarget().Get()); 149 | lua_pushnumber(L, event->GetSeat()); 150 | 151 | return 3; 152 | } 153 | ); 154 | 155 | REGISTER_LOCAL_EVENT( 156 | alt::CEvent::Type::PLAYER_CHANGE_VEHICLE_SEAT, 157 | playerChangedVehicleSeat, 158 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 159 | { 160 | const alt::CPlayerChangeVehicleSeatEvent* event = static_cast(ev); 161 | lua_State* L = resourceImpl->GetLuaState(); 162 | 163 | lua_pushbaseobject(L, event->GetPlayer().Get()); 164 | lua_pushbaseobject(L, event->GetTarget().Get()); 165 | lua_pushnumber(L, event->GetNewSeat()); 166 | lua_pushnumber(L, event->GetOldSeat()); 167 | 168 | return 4; 169 | } 170 | ); 171 | 172 | REGISTER_LOCAL_EVENT( 173 | alt::CEvent::Type::PLAYER_WEAPON_CHANGE, 174 | playerWeaponChange, 175 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 176 | { 177 | const alt::CPlayerWeaponChangeEvent* event = static_cast(ev); 178 | lua_State* L = resourceImpl->GetLuaState(); 179 | 180 | lua_pushbaseobject(L, event->GetTarget().Get()); 181 | lua_pushnumber(L, event->GetOldWeapon()); 182 | lua_pushnumber(L, event->GetNewWeapon()); 183 | 184 | return 3; 185 | } 186 | ); 187 | 188 | #endif -------------------------------------------------------------------------------- /src/Events/Server/VehicleEvents.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifdef ALT_SERVER_API 4 | 5 | REGISTER_LOCAL_EVENT( 6 | alt::CEvent::Type::VEHICLE_DESTROY, 7 | vehicleDestroy, 8 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 9 | { 10 | const alt::CVehicleDestroyEvent* event = static_cast(ev); 11 | lua_State* L = resourceImpl->GetLuaState(); 12 | 13 | lua_pushbaseobject(L, event->GetTarget().Get()); 14 | 15 | return 1; 16 | } 17 | ); 18 | 19 | REGISTER_LOCAL_EVENT( 20 | alt::CEvent::Type::VEHICLE_DAMAGE, 21 | vehicleDamage, 22 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 23 | { 24 | const alt::CVehicleDamageEvent* event = static_cast(ev); 25 | lua_State* L = resourceImpl->GetLuaState(); 26 | 27 | lua_pushbaseobject(L, event->GetTarget()); 28 | lua_pushbaseobject(L, event->GetDamager()); 29 | lua_pushnumber(L, event->GetBodyHealthDamage()); 30 | lua_pushnumber(L, event->GetBodyAdditionalHealthDamage()); 31 | lua_pushnumber(L, event->GetEngineHealthDamage()); 32 | lua_pushnumber(L, event->GetPetrolTankHealthDamage()); 33 | lua_pushnumber(L, event->GetDamagedWith()); 34 | 35 | return 7; 36 | } 37 | ); 38 | 39 | REGISTER_LOCAL_EVENT( 40 | alt::CEvent::Type::VEHICLE_ATTACH, 41 | vehicleAttach, 42 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 43 | { 44 | const alt::CVehicleAttachEvent* event = static_cast(ev); 45 | lua_State* L = resourceImpl->GetLuaState(); 46 | 47 | lua_pushbaseobject(L, event->GetTarget().Get()); 48 | lua_pushbaseobject(L, event->GetAttached().Get()); 49 | 50 | return 2; 51 | } 52 | ); 53 | 54 | REGISTER_LOCAL_EVENT( 55 | alt::CEvent::Type::VEHICLE_DETACH, 56 | vehicleDetach, 57 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 58 | { 59 | const alt::CVehicleDetachEvent* event = static_cast(ev); 60 | lua_State* L = resourceImpl->GetLuaState(); 61 | 62 | lua_pushbaseobject(L, event->GetTarget().Get()); 63 | lua_pushbaseobject(L, event->GetDetached().Get()); 64 | 65 | return 2; 66 | } 67 | ); 68 | 69 | #endif -------------------------------------------------------------------------------- /src/Events/Shared/MetaEvents.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | REGISTER_LOCAL_EVENT( 5 | alt::CEvent::Type::SYNCED_META_CHANGE, 6 | syncedMetaChange, 7 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 8 | { 9 | const alt::CSyncedMetaDataChangeEvent* event = static_cast(ev); 10 | lua_State* L = resourceImpl->GetLuaState(); 11 | 12 | lua_pushbaseobject(L, event->GetTarget().Get()); 13 | lua_pushstring(L, event->GetKey()); 14 | lua_pushmvalue(L, event->GetVal()); 15 | lua_pushmvalue(L, event->GetOldVal()); 16 | 17 | return 4; 18 | } 19 | ); 20 | 21 | REGISTER_LOCAL_EVENT( 22 | alt::CEvent::Type::STREAM_SYNCED_META_CHANGE, 23 | streamSyncedMetaChange, 24 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 25 | { 26 | const alt::CStreamSyncedMetaDataChangeEvent* event = static_cast(ev); 27 | lua_State* L = resourceImpl->GetLuaState(); 28 | 29 | lua_pushbaseobject(L, event->GetTarget().Get()); 30 | lua_pushstring(L, event->GetKey()); 31 | lua_pushmvalue(L, event->GetVal()); 32 | lua_pushmvalue(L, event->GetOldVal()); 33 | 34 | return 4; 35 | } 36 | ); 37 | 38 | REGISTER_LOCAL_EVENT( 39 | alt::CEvent::Type::GLOBAL_META_CHANGE, 40 | globalMetaChange, 41 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 42 | { 43 | const alt::CGlobalMetaDataChangeEvent* event = static_cast(ev); 44 | lua_State* L = resourceImpl->GetLuaState(); 45 | 46 | lua_pushstring(L, event->GetKey()); 47 | lua_pushmvalue(L, event->GetVal()); 48 | lua_pushmvalue(L, event->GetOldVal()); 49 | 50 | return 3; 51 | } 52 | ); 53 | 54 | REGISTER_LOCAL_EVENT( 55 | alt::CEvent::Type::GLOBAL_SYNCED_META_CHANGE, 56 | globalSyncedMetaChange, 57 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 58 | { 59 | const alt::CGlobalSyncedMetaDataChangeEvent* event = static_cast(ev); 60 | lua_State* L = resourceImpl->GetLuaState(); 61 | 62 | lua_pushstring(L, event->GetKey()); 63 | lua_pushmvalue(L, event->GetVal()); 64 | lua_pushmvalue(L, event->GetOldVal()); 65 | 66 | return 3; 67 | } 68 | ); 69 | 70 | REGISTER_LOCAL_EVENT( 71 | alt::CEvent::Type::LOCAL_SYNCED_META_CHANGE, 72 | localMetaChange, 73 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 74 | { 75 | const alt::CLocalMetaDataChangeEvent* event = static_cast(ev); 76 | lua_State* L = resourceImpl->GetLuaState(); 77 | 78 | if(!isClient) 79 | lua_pushbaseobject(L, event->GetTarget().Get()); 80 | 81 | lua_pushstring(L, event->GetKey()); 82 | lua_pushmvalue(L, event->GetVal()); 83 | lua_pushmvalue(L, event->GetOldVal()); 84 | 85 | int returnSize = isClient ? 3 : 4; 86 | return returnSize; 87 | } 88 | ); -------------------------------------------------------------------------------- /src/Events/Shared/MiscEvents.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | REGISTER_LOCAL_EVENT( 4 | alt::CEvent::Type::CONSOLE_COMMAND_EVENT, 5 | consoleCommand, 6 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* e) -> int 7 | { 8 | auto event = static_cast(e); 9 | lua_State* L = resourceImpl->GetLuaState(); 10 | 11 | lua_pushstring(L, event->GetName().c_str()); 12 | lua_newtable(L); 13 | 14 | int index = 1; 15 | for (auto& arg : event->GetArgs()) 16 | { 17 | lua_pushnumber(L, index); 18 | lua_pushstring(L, arg.c_str()); 19 | lua_rawset(L, -3); 20 | 21 | index++; 22 | } 23 | 24 | return 2; 25 | } 26 | ); 27 | 28 | REGISTER_LOCAL_EVENT( 29 | alt::CEvent::Type::SERVER_SCRIPT_EVENT, 30 | SERVER_SCRIPT_EVENT, 31 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 32 | { 33 | const alt::CServerScriptEvent* event = static_cast(ev); 34 | lua_State* L = resourceImpl->GetLuaState(); 35 | 36 | for (auto arg : event->GetArgs()) 37 | { 38 | lua_pushmvalue(L, arg); 39 | } 40 | 41 | return static_cast(event->GetArgs().GetSize()); 42 | }, 43 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> std::vector 44 | { 45 | const alt::CServerScriptEvent* event = static_cast(ev); 46 | ResourceEventManager* resourceEventManager = resourceImpl->GetResourceEventManager(); 47 | 48 | 49 | if(isClient) 50 | return resourceEventManager->GetRemoteFunctionReferences(const_cast(event->GetName())); 51 | else 52 | return resourceEventManager->GetLocalFunctionReferences(const_cast(event->GetName())); 53 | } 54 | ); 55 | 56 | #ifdef ALT_SERVER_API 57 | REGISTER_LOCAL_EVENT( 58 | alt::CEvent::Type::CLIENT_SCRIPT_EVENT, 59 | CLIENT_SCRIPT_EVENT, 60 | [](LuaResourceImpl* resource, const alt::CEvent* ev) -> int 61 | { 62 | const alt::CClientScriptEvent* event = static_cast(ev); 63 | lua_State* L = resource->GetLuaState(); 64 | 65 | lua_pushbaseobject(L, event->GetTarget().Get()); 66 | 67 | for (auto arg : event->GetArgs()) 68 | { 69 | lua_pushmvalue(L, arg); 70 | } 71 | return static_cast(event->GetArgs().GetSize()) + 1; 72 | }, 73 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> std::vector 74 | { 75 | const alt::CClientScriptEvent* event = static_cast(ev); 76 | return resourceImpl->GetResourceEventManager()->GetRemoteFunctionReferences(const_cast(event->GetName())); 77 | } 78 | ); 79 | #else 80 | REGISTER_LOCAL_EVENT( 81 | alt::CEvent::Type::CLIENT_SCRIPT_EVENT, 82 | CLIENT_SCRIPT_EVENT, 83 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 84 | { 85 | const alt::CClientScriptEvent* event = static_cast(ev); 86 | lua_State* L = resourceImpl->GetLuaState(); 87 | 88 | for (auto arg : event->GetArgs()) 89 | { 90 | lua_pushmvalue(L, arg); 91 | } 92 | 93 | return static_cast(event->GetArgs().GetSize()); 94 | }, 95 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> std::vector 96 | { 97 | const alt::CClientScriptEvent* event = static_cast(ev); 98 | return resourceImpl->GetResourceEventManager()->GetLocalFunctionReferences(const_cast(event->GetName())); 99 | } 100 | ); 101 | #endif -------------------------------------------------------------------------------- /src/Events/Shared/ResourceEvents.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | REGISTER_LOCAL_EVENT( 4 | alt::CEvent::Type::RESOURCE_START, 5 | anyResourceStart, 6 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 7 | { 8 | const alt::CResourceStartEvent* event = static_cast(ev); 9 | lua_State* L = resourceImpl->GetLuaState(); 10 | 11 | lua_pushresource(L, event->GetResource()); 12 | 13 | return 1; 14 | } 15 | ); 16 | 17 | REGISTER_LOCAL_EVENT( 18 | alt::CEvent::Type::RESOURCE_STOP, 19 | anyResourceStop, 20 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 21 | { 22 | const alt::CResourceStopEvent* event = static_cast(ev); 23 | lua_State* L = resourceImpl->GetLuaState(); 24 | 25 | lua_pushresource(L, event->GetResource()); 26 | 27 | return 1; 28 | } 29 | ); 30 | 31 | REGISTER_LOCAL_EVENT( 32 | alt::CEvent::Type::RESOURCE_ERROR, 33 | anyResourceError, 34 | [](LuaResourceImpl* resourceImpl, const alt::CEvent* ev) -> int 35 | { 36 | const alt::CResourceErrorEvent* event = static_cast(ev); 37 | lua_State* L = resourceImpl->GetLuaState(); 38 | 39 | lua_pushresource(L, event->GetResource()); 40 | 41 | return 1; 42 | } 43 | ); -------------------------------------------------------------------------------- /src/Helpers/LuaHelpers.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #ifdef __linux__ 6 | #include 7 | #endif 8 | 9 | #define L_ASSERT(a,b) \ 10 | assert((!(a)?(Core->LogError(b),true):true)&&a) 11 | 12 | #define UPVALUE_METADATA 1 13 | #define UPVALUE_SET 2 14 | #define UPVALUE_GET 3 15 | #define UPVALUE_CLASS 4 16 | #define UPVALUE_DATA 5 17 | 18 | /*#define lua_globalfunction(a,b,c) \ 19 | lua_register(a,b,c)*/ 20 | 21 | //#define lua_endstaticclass(a) \ 22 | // lua_endclass(L,true) 23 | extern const char* lua_meta_script; 24 | void lua_globalfunction(lua_State* L, const char* functionName, lua_CFunction func); 25 | 26 | int lua_setpath(lua_State* L, const char* path); 27 | 28 | void lua_mergetable(lua_State* L, int fromTable, int toTable); 29 | void lua_removedata(lua_State* L, alt::IBaseObject* baseObject); 30 | void lua_disablelib(lua_State* L, const char* libName); 31 | void lua_disablefunction(lua_State* L, const char* functionName); 32 | 33 | void lua_initclass(lua_State* L); 34 | void lua_beginclass(lua_State* L, const char* className, const char* baseClass = nullptr); 35 | void lua_endclass(lua_State* L); 36 | void lua_openclass(lua_State* L, const char* className); 37 | void lua_closeclass(lua_State* L); 38 | void lua_getclass(lua_State* L, const char* className); 39 | void lua_getclassmt(lua_State* L, const char* className); 40 | void lua_classfunction(lua_State* L, const char* functionName, const char* globalFuncName); 41 | void lua_classfunction(lua_State* L, const char* functionName, lua_CFunction function); 42 | void lua_classnative(lua_State* L, const char* functionName, lua_CFunction function, void* native); 43 | void lua_classmeta(lua_State* L, const char* metaName, lua_CFunction metaFunction, bool useClosure = false); //if useClosure set to true we store metatable in the upvalue 44 | void lua_classvariable(lua_State* L, const char* variableName, const char* setFunction, const char* getFunction); 45 | void lua_classvariable(lua_State* L, const char* variableName, lua_CFunction setFunction, lua_CFunction getFunction); 46 | 47 | void lua_pushuserdata(lua_State* L, const char* className, void* pObject, bool refUserData = true); 48 | void lua_pushbaseobject(lua_State* L, alt::IBaseObject* baseObject, bool refUserData = true); 49 | void lua_pushbaseobject(lua_State* L, alt::Ref baseObject, bool refUserData = true); 50 | void lua_pushconfig(lua_State* L, alt::config::Node::Dict* nodeDict, bool refUserData = true); 51 | void lua_pushstring(lua_State* L, const std::string& str); 52 | //void lua_pushstring(lua_State* L, alt::String& str); 53 | //void lua_pushstring(lua_State* L, alt::StringView& str); 54 | 55 | template::value, T>::type> 56 | void lua_setfield(lua_State* L, int index, const char* k, T value) 57 | { 58 | lua_pushnumber(L, value); 59 | lua_setfield(L, index - 1, k); 60 | } 61 | 62 | void lua_setfield(lua_State* L, int index, const char* k, const char* value); 63 | void lua_setfield(lua_State* L, int index, const char* k, const std::string& value); 64 | void lua_setfield(lua_State* L, int index, const char* k, bool value); 65 | void lua_setfield(lua_State* L, int index, const char* k, const Vector3fp& vector3); 66 | 67 | void* lua_checkclass(lua_State* L, int idx, const char* classname); 68 | #define lua_isclass(state,idx,classname) (lua_checkclass(state,idx,classname)!=nullptr) 69 | 70 | #ifdef ALT_CLIENT_API 71 | void lua_pushwebview(lua_State* L, alt::IWebView* webView, bool refUserData = true); 72 | 73 | void lua_pushmapdata(lua_State* L, alt::IMapData* mapData, bool refUserData = false); 74 | void lua_pushmapdata(lua_State* L, alt::Ref mapData, bool refUserData = false); 75 | 76 | void lua_pushhandlingdata(lua_State* L, alt::Ref handlingData, bool refUserData = false); 77 | void lua_pushhandlingdata(lua_State* L, alt::IHandlingData* handlingData, bool refUserData = false); 78 | #endif 79 | //template> 80 | //void lua_pushvector3(lua_State* L, const alt::Vector& vector, bool refUserData = false) 81 | //{ 82 | // alt::Vector* vec = new alt::Vector(vector); 83 | // lua_pushuserdata(L, Vector3::ClassName, vec, refUserData); 84 | //} 85 | void lua_pushvector2(lua_State* L, Vector2fp* vector, bool refUserData = false); 86 | void lua_pushvector2(lua_State* L, const Vector2fp& vector, bool refUserData = false); 87 | void lua_pushvector3(lua_State* L, Vector3fp* vector, bool refUserData = false); 88 | void lua_pushvector3(lua_State* L, const Vector3fp& vector, bool refUserData = false); 89 | //void lua_pushvehicle(lua_State* L, alt::IVehicle* vehicle, bool refUserData = true); 90 | void lua_pushrgba(lua_State* L, const alt::RGBA &color, bool refUserData = false); 91 | void lua_pushmvalue(lua_State* L, const alt::MValueConst &mValue); 92 | void lua_pushnode(lua_State* L, alt::config::Node& node); 93 | void lua_pushmvalueargs(lua_State* L, alt::MValueArgs& args); 94 | void lua_pushresource(lua_State* L, alt::IResource* resource, bool refUserData = true); 95 | void lua_pushstringarray(lua_State* L, const alt::Array& array); 96 | int lua_functionref(lua_State* L, int idx); 97 | 98 | int lua_isinteger(lua_State* L, int idx); 99 | void lua_todict(lua_State* L, int idx); 100 | alt::MValue lua_tomvalue(lua_State* L, int indx); 101 | alt::IBaseObject* lua_tobaseobject(lua_State* L, int idx); 102 | //void lua_toentity(lua_State* L, alt::IEntity* entity); 103 | 104 | void lua_stacktrace_ex(lua_State* L, const char* stackName = "Unknown"); 105 | void lua_stacktrace(lua_State* L, const char* stackName = "Unknown"); 106 | void lua_dumptable(lua_State* L, int idx, int level = 0); 107 | void lua_getdebuginfo(lua_State* L, lua_Debug& debugInfo); 108 | 109 | const char* luaL_tolstring(lua_State* L, int idx, size_t* len); -------------------------------------------------------------------------------- /src/Helpers/MetaFunction.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Main.h" 4 | 5 | class CEntity; 6 | 7 | class CLuaFunctionDefs 8 | { 9 | public: 10 | //static const char* GetEntityType(CEntity *entity); 11 | static int Index(lua_State *L); 12 | static int StaticIndex(lua_State* L); 13 | static int NewIndex(lua_State *L); 14 | static int Call(lua_State* L); 15 | static int FunctionCallback(lua_State* L); 16 | static int GarbageCollect(lua_State* L); 17 | static int DisabledFunction(lua_State* L); 18 | }; -------------------------------------------------------------------------------- /src/LuaResourceImpl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class LuaScriptRuntime; 6 | class LuaResourceImpl : public alt::IResource::Impl 7 | { 8 | public: 9 | struct LuaTimer 10 | { 11 | uint32_t functionIndex; 12 | uint32_t interval; 13 | bool repeat; 14 | int64_t lastTime; 15 | }; 16 | 17 | class LuaFunction : public alt::IMValueFunction::Impl 18 | { 19 | public: 20 | LuaFunction(LuaResourceImpl* resource, int functionRef) : 21 | resource(resource), 22 | functionRef(functionRef) 23 | { 24 | 25 | } 26 | ~LuaFunction() {} 27 | 28 | alt::MValue Call(alt::MValueArgs args) const override; 29 | 30 | private: 31 | LuaResourceImpl* resource; 32 | int functionRef; 33 | }; 34 | 35 | typedef std::map> EventsReferences; 36 | 37 | LuaResourceImpl(LuaScriptRuntime* runtime, alt::IResource* resource); 38 | ~LuaResourceImpl(); 39 | 40 | #ifdef ALT_SERVER_API 41 | bool MakeClient(alt::IResource::CreationInfo* info, alt::Array files) override; 42 | #endif 43 | 44 | bool Start() override; 45 | bool Stop() override; 46 | 47 | bool OnEvent(const alt::CEvent* ev) override; 48 | void OnTick() override; 49 | 50 | void OnCreateBaseObject(alt::Ref object) override; 51 | void OnRemoveBaseObject(alt::Ref object) override; 52 | 53 | lua_State* GetLuaState(void) { return this->resourceState; } 54 | #ifdef ALT_CLIENT_API 55 | 56 | inline bool IsScriptExists(std::string path) 57 | { 58 | auto pkg = resource->GetPackage(); 59 | return pkg->FileExists(path); 60 | } 61 | 62 | inline std::string GetScript(std::string path) 63 | { 64 | auto pkg = resource->GetPackage(); 65 | if (!pkg->FileExists(path)) 66 | { 67 | Core->LogError(" Client main \"" + path + "\" is not found"); 68 | return std::string{ "" }; 69 | } 70 | 71 | auto file = pkg->OpenFile(path); 72 | std::string script; 73 | script.resize(pkg->GetFileSize(file)); 74 | 75 | pkg->ReadFile(file, script.data(), script.size()); 76 | pkg->CloseFile(file); 77 | 78 | return script; 79 | } 80 | #endif 81 | inline ResourceEventManager* GetResourceEventManager() { return this->resourceEventManager; } 82 | void TriggerResourceLocalEvent(std::string eventName, alt::MValueArgs args); 83 | void IncludePath(const char* path); 84 | inline bool AddFunctionRef(const void* ptr, int functionRef) 85 | { 86 | if (this->IsFunctionRefExists(ptr)) 87 | return false; 88 | 89 | this->functionReferences[ptr] = functionRef; 90 | return true; 91 | } 92 | inline bool RemoveFunctionRef(const void* ptr) 93 | { 94 | if (!this->IsFunctionRefExists(ptr)) 95 | return false; 96 | 97 | luaL_unref(this->resourceState, LUA_REGISTRYINDEX, this->GetFunctionRef(ptr)); 98 | 99 | this->functionReferences.erase(ptr); 100 | return true; 101 | } 102 | inline bool IsFunctionRefExists(const void* ptr) 103 | { 104 | return this->functionReferences.find(ptr) != this->functionReferences.end(); 105 | } 106 | inline int GetFunctionRef(const void* ptr) 107 | { 108 | if (!this->IsFunctionRefExists(ptr)) 109 | return LUA_NOREF; 110 | 111 | return this->functionReferences[ptr]; 112 | } 113 | inline const void* GetFunctionRefByID(int functionRef) 114 | { 115 | for (auto it = this->functionReferences.begin(); it != this->functionReferences.end(); ++it) 116 | if (it->second == functionRef) 117 | return it->first; 118 | 119 | return nullptr; 120 | } 121 | 122 | inline void AddExport(std::string exportName, LuaFunction* func) 123 | { 124 | this->exportFunction->Set(exportName, Core->CreateMValueFunction(func)); 125 | } 126 | inline bool IsExportExists(std::string exportName) 127 | { 128 | return this->exportFunction->Get(exportName)->GetType() != alt::IMValue::Type::NONE; 129 | } 130 | inline alt::IResource* GetResource(void) 131 | { 132 | return this->resource; 133 | } 134 | inline std::string& GetWorkingPath(void) 135 | { 136 | return this->workingPath; 137 | } 138 | inline std::map& GetLoadedFiles(void) 139 | { 140 | return this->loadedFiles; 141 | } 142 | #ifdef ALT_SERVER_API 143 | inline alt::config::Node::Dict& GetResourceConfig(void) 144 | { 145 | return this->resourceConfigDict; 146 | } 147 | #endif 148 | inline bool AddEntity(alt::IBaseObject* baseObject) 149 | { 150 | auto entityFound = std::find(this->entities.begin(), this->entities.end(), baseObject) != this->entities.end(); 151 | if (entityFound) 152 | return false; 153 | 154 | this->entities.push_back(baseObject); 155 | return true; 156 | } 157 | 158 | inline bool RemoveEntity(alt::IBaseObject* baseObject) 159 | { 160 | auto it = std::find(this->entities.begin(), this->entities.end(), baseObject); 161 | if (it == this->entities.end()) 162 | return false; 163 | 164 | this->entities.erase(it); 165 | return true; 166 | } 167 | 168 | uint32_t CreateTimer(uint32_t functionIndex, uint32_t interval, bool repeat); 169 | inline bool DestroyTimer(uint32_t timerIndex) 170 | { 171 | return (this->timerReferences.erase(timerIndex) > 0); 172 | } 173 | 174 | private: 175 | lua_State* resourceState = nullptr; 176 | LuaScriptRuntime* runtime; 177 | ResourceEventManager* resourceEventManager; 178 | 179 | #ifdef ALT_SERVER_API 180 | alt::config::Node::Dict resourceConfigDict; 181 | #endif 182 | alt::IResource* resource; 183 | std::string workingPath; 184 | 185 | uint32_t timerIndex = -1; 186 | std::map timerReferences; 187 | 188 | std::map functionReferences; 189 | alt::MValueDict exportFunction; 190 | std::map loadedFiles; 191 | std::list entities; 192 | }; -------------------------------------------------------------------------------- /src/LuaScriptRuntime.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | //#include 5 | #include 6 | #include 7 | 8 | LuaScriptRuntime::LuaScriptRuntime() 9 | { 10 | this->eventManager = &EventManager::Instance(); 11 | 12 | //Register all events 13 | for(EventManager::Handler* handler : this->eventManager->GetAllHandlers()) 14 | { 15 | handler->Invoke(); 16 | } 17 | 18 | #ifndef NDEBUG 19 | Core->LogInfo("LuaScriptRuntime::LuaScriptRuntime"); 20 | #endif 21 | 22 | #ifdef ALT_SERVER_API 23 | VehicleModels::Instance(); //instance class once for further usage 24 | #endif 25 | 26 | #ifdef ALT_SERVER_API 27 | std::string serverConfigPath{ Core->GetRootDirectory() + p_s + "server.cfg" }; 28 | this->serverConfigDict = this->ParseConfig(serverConfigPath); 29 | 30 | //Core->SubscribeEvent(alt::CEvent::Type::RESOURCE_START, LuaScriptRuntime::OnResourceStart, this); 31 | //Core->SubscribeEvent(alt::CEvent::Type::RESOURCE_STOP, LuaScriptRuntime::OnResourceStop, this); 32 | #endif 33 | 34 | this->moduleStartedTime = this->GetTime(); 35 | } 36 | 37 | #ifdef ALT_SERVER_API 38 | bool LuaScriptRuntime::OnResourceStart(const alt::CEvent* e, void* userData) 39 | { 40 | LuaScriptRuntime *runtime = (LuaScriptRuntime*)userData; 41 | auto event = (alt::CResourceStartEvent*)e; 42 | 43 | if (event->GetResource()->GetType() == "lua") 44 | return true; 45 | 46 | std::string resourceConfigPath{ event->GetResource()->GetPath() + p_s + "resource.cfg" }; 47 | auto resourceNode = runtime->ParseConfig(resourceConfigPath); 48 | 49 | runtime->resourceNodeDictMap[event->GetResource()] = resourceNode; 50 | return true; 51 | } 52 | 53 | bool LuaScriptRuntime::OnResourceStop(const alt::CEvent* e, void* userData) 54 | { 55 | LuaScriptRuntime* runtime = (LuaScriptRuntime*)userData; 56 | auto event = (alt::CResourceStartEvent*)e; 57 | 58 | runtime->resourceNodeDictMap.erase(event->GetResource()); 59 | 60 | return true; 61 | } 62 | #endif 63 | 64 | alt::IResource::Impl* LuaScriptRuntime::CreateImpl(alt::IResource* resource) 65 | { 66 | 67 | DEBUG_INFO("Before::LuaScriptRuntime::CreateImpl"); 68 | 69 | LuaResourceImpl* resourceImpl = new LuaResourceImpl{ this, resource }; 70 | 71 | DEBUG_INFO("After::LuaScriptRuntime::CreateImpl: " + std::to_string(reinterpret_cast(resourceImpl)) + " - " + std::to_string(reinterpret_cast(resourceImpl->GetLuaState()))); 72 | 73 | return resourceImpl; 74 | } 75 | 76 | void LuaScriptRuntime::DestroyImpl(alt::IResource::Impl* impl) 77 | { 78 | LuaResourceImpl* resourceImpl = dynamic_cast(impl); 79 | 80 | if (resourceImpl != nullptr) 81 | { 82 | this->resources.erase(resourceImpl->GetLuaState()); 83 | } 84 | 85 | #ifndef NDEBUG 86 | Core->LogInfo("LuaScriptRuntime::DestroyImpl: " + std::to_string(reinterpret_cast(impl)) + " - " + std::to_string(reinterpret_cast(resourceImpl->GetLuaState()))); 87 | #endif 88 | 89 | delete impl; 90 | 91 | } 92 | 93 | alt::config::Node::Dict LuaScriptRuntime::ParseConfig(std::string path) 94 | { 95 | std::ifstream file(path); 96 | std::string str; 97 | std::string file_contents; 98 | 99 | while (std::getline(file, str)) 100 | { 101 | file_contents += str; 102 | file_contents.push_back('\n'); 103 | } 104 | 105 | alt::config::Parser parser(file_contents.c_str(), file_contents.size()); 106 | auto node = parser.Parse(); 107 | 108 | if (!node.IsDict()) 109 | { 110 | Core->LogError("Unable to parse config file: " + path); 111 | return {}; 112 | } 113 | 114 | return node.ToDict(); 115 | } 116 | 117 | LuaResourceImpl* LuaScriptRuntime::GetResourceImplFromState(lua_State* L) 118 | { 119 | auto it = this->resources.find(L); 120 | if (it != this->resources.end()) 121 | return it->second; 122 | 123 | return nullptr; 124 | } 125 | 126 | void LuaScriptRuntime::AddResource(lua_State* L, LuaResourceImpl* resource) 127 | { 128 | this->resources.insert({ L, resource }); 129 | } 130 | 131 | const std::string LuaScriptRuntime::GetBaseObjectType(alt::IBaseObject* baseObject) 132 | { 133 | return this->entityTypes.at(static_cast(baseObject->GetType())); 134 | } 135 | 136 | const std::string LuaScriptRuntime::GetBaseObjectType(alt::IBaseObject::Type baseType) 137 | { 138 | return this->entityTypes.at(static_cast(baseType)); 139 | } -------------------------------------------------------------------------------- /src/LuaScriptRuntime.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Main.h" 4 | #include 5 | 6 | #ifndef NDEBUG 7 | #define DEBUG_HELPER(x) (std::string("[Lua] ") + x) 8 | #define DEBUG_INFO(x) Core->LogInfo(DEBUG_HELPER(x)) 9 | #define DEBUG_WARNING(x) Core->LogWarning(DEBUG_HELPER(x)) 10 | #else 11 | #define DEBUG_INFO(x) 12 | #define DEBUG_WARNING(x) 13 | #endif 14 | 15 | class LuaResourceImpl; 16 | class LuaScriptRuntime : public alt::IScriptRuntime 17 | { 18 | 19 | public: 20 | typedef std::function FunctionCallback; 21 | typedef std::function*(LuaResourceImpl*, const alt::CEvent*)> CallbackGetter; 22 | typedef std::map EventsCallbacks; 23 | typedef std::map EventsGetter; 24 | 25 | #ifdef ALT_SERVER_API 26 | std::map resourceNodeDictMap; 27 | #endif 28 | 29 | alt::IResource::Impl* CreateImpl(alt::IResource* resource) override; 30 | void DestroyImpl(alt::IResource::Impl* impl) override; 31 | 32 | alt::config::Node::Dict ParseConfig(std::string path); 33 | LuaResourceImpl* GetResourceImplFromState(lua_State* L); 34 | void AddResource(lua_State* L, LuaResourceImpl* resource); 35 | const std::string GetBaseObjectType(alt::IBaseObject *baseObject); 36 | const std::string GetBaseObjectType(alt::IBaseObject::Type baseType); 37 | 38 | inline const semver::version& GetVersion(void) 39 | { 40 | return this->version; 41 | } 42 | inline EventManager* GetEventManager(void) 43 | { 44 | return this->eventManager; 45 | } 46 | #ifdef ALT_SERVER_API 47 | inline alt::config::Node::Dict &GetServerConfig(void) 48 | { 49 | return this->serverConfigDict; 50 | } 51 | inline alt::config::Node::Dict& GetResourceConfig(alt::IResource* resource) 52 | { 53 | return this->resourceNodeDictMap[resource]; 54 | } 55 | #endif 56 | 57 | //Source: https://github.com/altmp/v8-helpers/blob/f4e4c2cacff229df022e68af99756b6f6ef1f6eb/V8ResourceImpl.h#L229 58 | inline static int64_t GetTime() 59 | { 60 | return std::chrono::duration_cast( 61 | std::chrono::steady_clock::now().time_since_epoch()) 62 | .count(); 63 | } 64 | 65 | inline int64_t GetModuleTime() 66 | { 67 | return (this->GetTime() - this->moduleStartedTime); 68 | } 69 | 70 | static LuaScriptRuntime& Instance() 71 | { 72 | static LuaScriptRuntime _Instance; 73 | return _Instance; 74 | } 75 | 76 | private: 77 | LuaScriptRuntime(); 78 | ~LuaScriptRuntime() { }; 79 | 80 | char* _ALT_SDK_VERSION = (char*)ALT_SDK_VERSION; //disable annoying warnings in Linux build 81 | const semver::version version{ 1, 3, 0, _ALT_SDK_VERSION, semver::branch::dev }; 82 | 83 | #ifdef ALT_SERVER_API 84 | alt::config::Node::Dict serverConfigDict; 85 | 86 | static bool OnResourceStart(const alt::CEvent* e, void* userData); 87 | static bool OnResourceStop(const alt::CEvent* e, void* userData); 88 | #endif 89 | std::map resources; 90 | EventsCallbacks eventsCallbacks; 91 | EventsGetter eventsGetter; 92 | 93 | EventManager* eventManager; 94 | 95 | int64_t moduleStartedTime; 96 | 97 | const std::vector entityTypes{ 98 | "Player", 99 | "Vehicle", 100 | "Blip", 101 | "WebView", 102 | "VoiceChannel", 103 | "ColShape", 104 | "Checkpoint", 105 | "WebSocketClient", 106 | "HTTPClient", 107 | "Audio", 108 | "RmlElement", 109 | "RmlDocument", 110 | "LocalPlayer" 111 | }; 112 | }; -------------------------------------------------------------------------------- /src/Main.cpp: -------------------------------------------------------------------------------- 1 | #include "Main.h" 2 | #include 3 | #include 4 | 5 | alt::ICore* Core; 6 | 7 | #ifdef ALT_SERVER_API 8 | bool isClient = false; 9 | bool isServer = true; 10 | #else 11 | bool isClient = true; 12 | bool isServer = false; 13 | #endif 14 | 15 | #ifdef ALT_SERVER_API 16 | 17 | EXPORT bool altMain(alt::ICore* _core) 18 | { 19 | alt::ICore::SetInstance(_core); 20 | Core = _core; 21 | 22 | auto& runtime = LuaScriptRuntime::Instance(); 23 | 24 | _core->LogInfo(std::string() + "Lua server module. Version: v" + std::string(runtime.GetVersion().to_string())); 25 | _core->RegisterScriptRuntime("lua", &runtime); 26 | 27 | return true; 28 | } 29 | #else 30 | EXPORT alt::IScriptRuntime *CreateScriptRuntime(alt::ICore *_core) 31 | { 32 | alt::ICore::SetInstance(_core); 33 | Core = _core; 34 | 35 | auto runtime = &LuaScriptRuntime::Instance(); 36 | 37 | _core->LogInfo(std::string("Lua client module. Version: v" + std::string(runtime->GetVersion().to_string()))); 38 | 39 | return runtime; 40 | } 41 | 42 | EXPORT const char* GetType() 43 | { 44 | return "lua"; 45 | } 46 | #endif 47 | 48 | EXPORT const char* GetSDKHash() 49 | { 50 | return ALT_SDK_VERSION; 51 | } -------------------------------------------------------------------------------- /src/Main.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define MODULE_VERSION "0.1.0" 4 | #define ADDITIONAL_MODULE_FOLDER "modules" 5 | 6 | // #ifndef ALT_SERVER_API 7 | // #define ALT_SERVER_API 8 | // #endif 9 | 10 | #ifdef _WIN32 11 | static const char* preferred_separator = "\\"; 12 | #else 13 | static const char* preferred_separator = "/"; 14 | 15 | #define sprintf_s sprintf 16 | #endif 17 | 18 | //Include basic stuff 19 | #include 20 | //#include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | //Semantic versioning 31 | #include 32 | 33 | //Include AltV SDK 34 | #include 35 | #include 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | //Include Lua 46 | #include 47 | 48 | extern alt::ICore* Core; 49 | 50 | extern bool isClient; 51 | extern bool isServer; 52 | 53 | const std::string p_s(preferred_separator); 54 | 55 | typedef alt::Vector3f Vector3fp; 56 | typedef alt::Vector2f Vector2fp; 57 | 58 | #include "VehicleModels.hpp" 59 | 60 | #include "Helpers/LuaHelpers.h" 61 | #include "Helpers/ArgumentReader.h" 62 | #include "EventManager.h" 63 | #include "LuaScriptRuntime.h" 64 | #include "LuaResourceImpl.h" 65 | #include "Helpers/MetaFunction.h" 66 | 67 | #include 68 | #include 69 | #include 70 | #include 71 | #include 72 | #include 73 | #include 74 | #include 75 | #include 76 | #include 77 | #include 78 | #include 79 | #include 80 | #include 81 | #include 82 | #include 83 | #include 84 | #include 85 | #include 86 | #include 87 | #include 88 | #include 89 | #include 90 | #include 91 | #include 92 | 93 | #include -------------------------------------------------------------------------------- /src/semver.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace semver { 8 | enum branch { 9 | dev = 0, 10 | rc, 11 | release 12 | }; 13 | 14 | inline std::ostream& operator<<(std::ostream& os, const branch& branchType) 15 | { 16 | switch (branchType) 17 | { 18 | case branch::dev: 19 | os << "dev"; 20 | break; 21 | case branch::rc: 22 | os << "rc"; 23 | break; 24 | case branch::release: 25 | os << "release"; 26 | break; 27 | } 28 | 29 | return os; 30 | } 31 | 32 | struct version { 33 | uint8_t major; 34 | uint8_t minor; 35 | uint8_t patch; 36 | char* sdkVersion; 37 | branch releaseType = branch::dev; 38 | 39 | constexpr version(std::uint8_t major, 40 | std::uint8_t minor, 41 | std::uint8_t patch, 42 | char* sdkVersion, 43 | branch releaseType = branch::dev) noexcept 44 | : major{ major }, 45 | minor{ minor }, 46 | patch{ patch }, 47 | sdkVersion{ sdkVersion }, 48 | releaseType{ releaseType } 49 | { 50 | 51 | } 52 | 53 | std::string to_string(void) const { 54 | std::ostringstream stringStream; 55 | stringStream << std::to_string(major) << "." << std::to_string(minor) << "." << std::to_string(patch) << "." << sdkVersion << "-" << releaseType; 56 | return stringStream.str(); 57 | } 58 | }; 59 | } -------------------------------------------------------------------------------- /vendors/luajit/bin/linux64/lua51.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drakeee/altv-lua-module/f3d18e7ef7f5c7ec089a8652ce02865720385960/vendors/luajit/bin/linux64/lua51.so -------------------------------------------------------------------------------- /vendors/luajit/bin/linux64/luajit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drakeee/altv-lua-module/f3d18e7ef7f5c7ec089a8652ce02865720385960/vendors/luajit/bin/linux64/luajit -------------------------------------------------------------------------------- /vendors/luajit/bin/win64/lua51.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drakeee/altv-lua-module/f3d18e7ef7f5c7ec089a8652ce02865720385960/vendors/luajit/bin/win64/lua51.dll -------------------------------------------------------------------------------- /vendors/luajit/bin/win64/luajit.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drakeee/altv-lua-module/f3d18e7ef7f5c7ec089a8652ce02865720385960/vendors/luajit/bin/win64/luajit.exe -------------------------------------------------------------------------------- /vendors/luajit/include/lauxlib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lauxlib.h,v 1.88.1.1 2007/12/27 13:02:25 roberto Exp $ 3 | ** Auxiliary functions for building Lua libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lauxlib_h 9 | #define lauxlib_h 10 | 11 | 12 | #include 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | 18 | /* extra error code for `luaL_load' */ 19 | #define LUA_ERRFILE (LUA_ERRERR+1) 20 | 21 | typedef struct luaL_Reg { 22 | const char *name; 23 | lua_CFunction func; 24 | } luaL_Reg; 25 | 26 | LUALIB_API void (luaL_openlib) (lua_State *L, const char *libname, 27 | const luaL_Reg *l, int nup); 28 | LUALIB_API void (luaL_register) (lua_State *L, const char *libname, 29 | const luaL_Reg *l); 30 | LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e); 31 | LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e); 32 | LUALIB_API int (luaL_typerror) (lua_State *L, int narg, const char *tname); 33 | LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg); 34 | LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg, 35 | size_t *l); 36 | LUALIB_API const char *(luaL_optlstring) (lua_State *L, int numArg, 37 | const char *def, size_t *l); 38 | LUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int numArg); 39 | LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int nArg, lua_Number def); 40 | 41 | LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg); 42 | LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg, 43 | lua_Integer def); 44 | 45 | LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg); 46 | LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t); 47 | LUALIB_API void (luaL_checkany) (lua_State *L, int narg); 48 | 49 | LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname); 50 | LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname); 51 | 52 | LUALIB_API void (luaL_where) (lua_State *L, int lvl); 53 | LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...); 54 | 55 | LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def, 56 | const char *const lst[]); 57 | 58 | /* pre-defined references */ 59 | #define LUA_NOREF (-2) 60 | #define LUA_REFNIL (-1) 61 | 62 | LUALIB_API int (luaL_ref) (lua_State *L, int t); 63 | LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref); 64 | 65 | LUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename); 66 | LUALIB_API int (luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz, 67 | const char *name); 68 | LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s); 69 | 70 | LUALIB_API lua_State *(luaL_newstate) (void); 71 | 72 | 73 | LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p, 74 | const char *r); 75 | 76 | LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx, 77 | const char *fname, int szhint); 78 | 79 | /* From Lua 5.2. */ 80 | LUALIB_API int luaL_fileresult(lua_State *L, int stat, const char *fname); 81 | LUALIB_API int luaL_execresult(lua_State *L, int stat); 82 | LUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename, 83 | const char *mode); 84 | LUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz, 85 | const char *name, const char *mode); 86 | LUALIB_API void luaL_traceback (lua_State *L, lua_State *L1, const char *msg, 87 | int level); 88 | LUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup); 89 | LUALIB_API void (luaL_pushmodule) (lua_State *L, const char *modname, 90 | int sizehint); 91 | LUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname); 92 | LUALIB_API void (luaL_setmetatable) (lua_State *L, const char *tname); 93 | 94 | 95 | /* 96 | ** =============================================================== 97 | ** some useful macros 98 | ** =============================================================== 99 | */ 100 | 101 | #define luaL_argcheck(L, cond,numarg,extramsg) \ 102 | ((void)((cond) || luaL_argerror(L, (numarg), (extramsg)))) 103 | #define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL)) 104 | #define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL)) 105 | #define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n))) 106 | #define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d))) 107 | #define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n))) 108 | #define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d))) 109 | 110 | #define luaL_typename(L,i) lua_typename(L, lua_type(L,(i))) 111 | 112 | #define luaL_dofile(L, fn) \ 113 | (luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0)) 114 | 115 | #define luaL_dostring(L, s) \ 116 | (luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0)) 117 | 118 | #define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n))) 119 | 120 | #define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n))) 121 | 122 | /* From Lua 5.2. */ 123 | #define luaL_newlibtable(L, l) \ 124 | lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1) 125 | #define luaL_newlib(L, l) (luaL_newlibtable(L, l), luaL_setfuncs(L, l, 0)) 126 | 127 | /* 128 | ** {====================================================== 129 | ** Generic Buffer manipulation 130 | ** ======================================================= 131 | */ 132 | 133 | 134 | 135 | typedef struct luaL_Buffer { 136 | char *p; /* current position in buffer */ 137 | int lvl; /* number of strings in the stack (level) */ 138 | lua_State *L; 139 | char buffer[LUAL_BUFFERSIZE]; 140 | } luaL_Buffer; 141 | 142 | #define luaL_addchar(B,c) \ 143 | ((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \ 144 | (*(B)->p++ = (char)(c))) 145 | 146 | /* compatibility only */ 147 | #define luaL_putchar(B,c) luaL_addchar(B,c) 148 | 149 | #define luaL_addsize(B,n) ((B)->p += (n)) 150 | 151 | LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B); 152 | LUALIB_API char *(luaL_prepbuffer) (luaL_Buffer *B); 153 | LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l); 154 | LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s); 155 | LUALIB_API void (luaL_addvalue) (luaL_Buffer *B); 156 | LUALIB_API void (luaL_pushresult) (luaL_Buffer *B); 157 | 158 | 159 | /* }====================================================== */ 160 | 161 | #endif 162 | -------------------------------------------------------------------------------- /vendors/luajit/include/lua.hpp: -------------------------------------------------------------------------------- 1 | // C++ wrapper for LuaJIT header files. 2 | 3 | extern "C" { 4 | #include "lua.h" 5 | #include "lauxlib.h" 6 | #include "lualib.h" 7 | #include "luajit.h" 8 | } 9 | 10 | -------------------------------------------------------------------------------- /vendors/luajit/include/luaconf.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Configuration header. 3 | ** Copyright (C) 2005-2020 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #ifndef luaconf_h 7 | #define luaconf_h 8 | 9 | #ifndef WINVER 10 | #define WINVER 0x0501 11 | #endif 12 | #include 13 | #include 14 | 15 | /* Default path for loading Lua and C modules with require(). */ 16 | #if defined(_WIN32) 17 | /* 18 | ** In Windows, any exclamation mark ('!') in the path is replaced by the 19 | ** path of the directory of the executable file of the current process. 20 | */ 21 | #define LUA_LDIR "!\\lua\\" 22 | #define LUA_CDIR "!\\" 23 | #define LUA_PATH_DEFAULT \ 24 | ".\\?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" 25 | #define LUA_CPATH_DEFAULT \ 26 | ".\\?.dll;" LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll" 27 | #else 28 | /* 29 | ** Note to distribution maintainers: do NOT patch the following lines! 30 | ** Please read ../doc/install.html#distro and pass PREFIX=/usr instead. 31 | */ 32 | #ifndef LUA_MULTILIB 33 | #define LUA_MULTILIB "lib" 34 | #endif 35 | #ifndef LUA_LMULTILIB 36 | #define LUA_LMULTILIB "lib" 37 | #endif 38 | #define LUA_LROOT "/usr/local" 39 | #define LUA_LUADIR "/lua/5.1/" 40 | #define LUA_LJDIR "/luajit-2.1.0-beta3/" 41 | 42 | #ifdef LUA_ROOT 43 | #define LUA_JROOT LUA_ROOT 44 | #define LUA_RLDIR LUA_ROOT "/share" LUA_LUADIR 45 | #define LUA_RCDIR LUA_ROOT "/" LUA_MULTILIB LUA_LUADIR 46 | #define LUA_RLPATH ";" LUA_RLDIR "?.lua;" LUA_RLDIR "?/init.lua" 47 | #define LUA_RCPATH ";" LUA_RCDIR "?.so" 48 | #else 49 | #define LUA_JROOT LUA_LROOT 50 | #define LUA_RLPATH 51 | #define LUA_RCPATH 52 | #endif 53 | 54 | #define LUA_JPATH ";" LUA_JROOT "/share" LUA_LJDIR "?.lua" 55 | #define LUA_LLDIR LUA_LROOT "/share" LUA_LUADIR 56 | #define LUA_LCDIR LUA_LROOT "/" LUA_LMULTILIB LUA_LUADIR 57 | #define LUA_LLPATH ";" LUA_LLDIR "?.lua;" LUA_LLDIR "?/init.lua" 58 | #define LUA_LCPATH1 ";" LUA_LCDIR "?.so" 59 | #define LUA_LCPATH2 ";" LUA_LCDIR "loadall.so" 60 | 61 | #define LUA_PATH_DEFAULT "./?.lua" LUA_JPATH LUA_LLPATH LUA_RLPATH 62 | #define LUA_CPATH_DEFAULT "./?.so" LUA_LCPATH1 LUA_RCPATH LUA_LCPATH2 63 | #endif 64 | 65 | /* Environment variable names for path overrides and initialization code. */ 66 | #define LUA_PATH "LUA_PATH" 67 | #define LUA_CPATH "LUA_CPATH" 68 | #define LUA_INIT "LUA_INIT" 69 | 70 | /* Special file system characters. */ 71 | #if defined(_WIN32) 72 | #define LUA_DIRSEP "\\" 73 | #else 74 | #define LUA_DIRSEP "/" 75 | #endif 76 | #define LUA_PATHSEP ";" 77 | #define LUA_PATH_MARK "?" 78 | #define LUA_EXECDIR "!" 79 | #define LUA_IGMARK "-" 80 | #define LUA_PATH_CONFIG \ 81 | LUA_DIRSEP "\n" LUA_PATHSEP "\n" LUA_PATH_MARK "\n" \ 82 | LUA_EXECDIR "\n" LUA_IGMARK "\n" 83 | 84 | /* Quoting in error messages. */ 85 | #define LUA_QL(x) "'" x "'" 86 | #define LUA_QS LUA_QL("%s") 87 | 88 | /* Various tunables. */ 89 | #define LUAI_MAXSTACK 65500 /* Max. # of stack slots for a thread (<64K). */ 90 | #define LUAI_MAXCSTACK 8000 /* Max. # of stack slots for a C func (<10K). */ 91 | #define LUAI_GCPAUSE 200 /* Pause GC until memory is at 200%. */ 92 | #define LUAI_GCMUL 200 /* Run GC at 200% of allocation speed. */ 93 | #define LUA_MAXCAPTURES 32 /* Max. pattern captures. */ 94 | 95 | /* Configuration for the frontend (the luajit executable). */ 96 | #if defined(luajit_c) 97 | #define LUA_PROGNAME "luajit" /* Fallback frontend name. */ 98 | #define LUA_PROMPT "> " /* Interactive prompt. */ 99 | #define LUA_PROMPT2 ">> " /* Continuation prompt. */ 100 | #define LUA_MAXINPUT 512 /* Max. input line length. */ 101 | #endif 102 | 103 | /* Note: changing the following defines breaks the Lua 5.1 ABI. */ 104 | #define LUA_INTEGER ptrdiff_t 105 | #define LUA_IDSIZE 60 /* Size of lua_Debug.short_src. */ 106 | /* 107 | ** Size of lauxlib and io.* on-stack buffers. Weird workaround to avoid using 108 | ** unreasonable amounts of stack space, but still retain ABI compatibility. 109 | ** Blame Lua for depending on BUFSIZ in the ABI, blame **** for wrecking it. 110 | */ 111 | #define LUAL_BUFFERSIZE (BUFSIZ > 16384 ? 8192 : BUFSIZ) 112 | 113 | /* The following defines are here only for compatibility with luaconf.h 114 | ** from the standard Lua distribution. They must not be changed for LuaJIT. 115 | */ 116 | #define LUA_NUMBER_DOUBLE 117 | #define LUA_NUMBER double 118 | #define LUAI_UACNUMBER double 119 | #define LUA_NUMBER_SCAN "%lf" 120 | #define LUA_NUMBER_FMT "%.14g" 121 | #define lua_number2str(s, n) sprintf((s), LUA_NUMBER_FMT, (n)) 122 | #define LUAI_MAXNUMBER2STR 32 123 | #define LUA_INTFRMLEN "l" 124 | #define LUA_INTFRM_T long 125 | 126 | /* Linkage of public API functions. */ 127 | #if defined(LUA_BUILD_AS_DLL) 128 | #if defined(LUA_CORE) || defined(LUA_LIB) 129 | #define LUA_API __declspec(dllexport) 130 | #else 131 | #define LUA_API __declspec(dllimport) 132 | #endif 133 | #else 134 | #define LUA_API extern 135 | #endif 136 | 137 | #define LUALIB_API LUA_API 138 | 139 | /* Compatibility support for assertions. */ 140 | #if defined(LUA_USE_ASSERT) || defined(LUA_USE_APICHECK) 141 | #include 142 | #endif 143 | #ifdef LUA_USE_ASSERT 144 | #define lua_assert(x) assert(x) 145 | #endif 146 | #ifdef LUA_USE_APICHECK 147 | #define luai_apicheck(L, o) { (void)L; assert(o); } 148 | #else 149 | #define luai_apicheck(L, o) { (void)L; } 150 | #endif 151 | 152 | #endif 153 | -------------------------------------------------------------------------------- /vendors/luajit/include/luajit.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** LuaJIT -- a Just-In-Time Compiler for Lua. http://luajit.org/ 3 | ** 4 | ** Copyright (C) 2005-2020 Mike Pall. All rights reserved. 5 | ** 6 | ** Permission is hereby granted, free of charge, to any person obtaining 7 | ** a copy of this software and associated documentation files (the 8 | ** "Software"), to deal in the Software without restriction, including 9 | ** without limitation the rights to use, copy, modify, merge, publish, 10 | ** distribute, sublicense, and/or sell copies of the Software, and to 11 | ** permit persons to whom the Software is furnished to do so, subject to 12 | ** the following conditions: 13 | ** 14 | ** The above copyright notice and this permission notice shall be 15 | ** included in all copies or substantial portions of the Software. 16 | ** 17 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | ** 25 | ** [ MIT license: http://www.opensource.org/licenses/mit-license.php ] 26 | */ 27 | 28 | #ifndef _LUAJIT_H 29 | #define _LUAJIT_H 30 | 31 | #include "lua.h" 32 | 33 | #define LUAJIT_VERSION "LuaJIT 2.1.0-beta3" 34 | #define LUAJIT_VERSION_NUM 20100 /* Version 2.1.0 = 02.01.00. */ 35 | #define LUAJIT_VERSION_SYM luaJIT_version_2_1_0_beta3 36 | #define LUAJIT_COPYRIGHT "Copyright (C) 2005-2020 Mike Pall" 37 | #define LUAJIT_URL "http://luajit.org/" 38 | 39 | /* Modes for luaJIT_setmode. */ 40 | #define LUAJIT_MODE_MASK 0x00ff 41 | 42 | enum { 43 | LUAJIT_MODE_ENGINE, /* Set mode for whole JIT engine. */ 44 | LUAJIT_MODE_DEBUG, /* Set debug mode (idx = level). */ 45 | 46 | LUAJIT_MODE_FUNC, /* Change mode for a function. */ 47 | LUAJIT_MODE_ALLFUNC, /* Recurse into subroutine protos. */ 48 | LUAJIT_MODE_ALLSUBFUNC, /* Change only the subroutines. */ 49 | 50 | LUAJIT_MODE_TRACE, /* Flush a compiled trace. */ 51 | 52 | LUAJIT_MODE_WRAPCFUNC = 0x10, /* Set wrapper mode for C function calls. */ 53 | 54 | LUAJIT_MODE_MAX 55 | }; 56 | 57 | /* Flags or'ed in to the mode. */ 58 | #define LUAJIT_MODE_OFF 0x0000 /* Turn feature off. */ 59 | #define LUAJIT_MODE_ON 0x0100 /* Turn feature on. */ 60 | #define LUAJIT_MODE_FLUSH 0x0200 /* Flush JIT-compiled code. */ 61 | 62 | /* LuaJIT public C API. */ 63 | 64 | /* Control the JIT engine. */ 65 | LUA_API int luaJIT_setmode(lua_State *L, int idx, int mode); 66 | 67 | /* Low-overhead profiling API. */ 68 | typedef void (*luaJIT_profile_callback)(void *data, lua_State *L, 69 | int samples, int vmstate); 70 | LUA_API void luaJIT_profile_start(lua_State *L, const char *mode, 71 | luaJIT_profile_callback cb, void *data); 72 | LUA_API void luaJIT_profile_stop(lua_State *L); 73 | LUA_API const char *luaJIT_profile_dumpstack(lua_State *L, const char *fmt, 74 | int depth, size_t *len); 75 | 76 | /* Enforce (dynamic) linker error for version mismatches. Call from main. */ 77 | LUA_API void LUAJIT_VERSION_SYM(void); 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /vendors/luajit/include/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Standard library header. 3 | ** Copyright (C) 2005-2020 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #ifndef _LUALIB_H 7 | #define _LUALIB_H 8 | 9 | #include "lua.h" 10 | 11 | #define LUA_FILEHANDLE "FILE*" 12 | 13 | #define LUA_COLIBNAME "coroutine" 14 | #define LUA_MATHLIBNAME "math" 15 | #define LUA_STRLIBNAME "string" 16 | #define LUA_TABLIBNAME "table" 17 | #define LUA_IOLIBNAME "io" 18 | #define LUA_OSLIBNAME "os" 19 | #define LUA_LOADLIBNAME "package" 20 | #define LUA_DBLIBNAME "debug" 21 | #define LUA_BITLIBNAME "bit" 22 | #define LUA_JITLIBNAME "jit" 23 | #define LUA_FFILIBNAME "ffi" 24 | 25 | LUALIB_API int luaopen_base(lua_State *L); 26 | LUALIB_API int luaopen_math(lua_State *L); 27 | LUALIB_API int luaopen_string(lua_State *L); 28 | LUALIB_API int luaopen_table(lua_State *L); 29 | LUALIB_API int luaopen_io(lua_State *L); 30 | LUALIB_API int luaopen_os(lua_State *L); 31 | LUALIB_API int luaopen_package(lua_State *L); 32 | LUALIB_API int luaopen_debug(lua_State *L); 33 | LUALIB_API int luaopen_bit(lua_State *L); 34 | LUALIB_API int luaopen_jit(lua_State *L); 35 | LUALIB_API int luaopen_ffi(lua_State *L); 36 | 37 | LUALIB_API void luaL_openlibs(lua_State *L); 38 | 39 | #ifndef lua_assert 40 | #define lua_assert(x) ((void)0) 41 | #endif 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /vendors/luajit/lib/linux64/libluajit.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drakeee/altv-lua-module/f3d18e7ef7f5c7ec089a8652ce02865720385960/vendors/luajit/lib/linux64/libluajit.a -------------------------------------------------------------------------------- /vendors/luajit/lib/linux64/libluajit.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drakeee/altv-lua-module/f3d18e7ef7f5c7ec089a8652ce02865720385960/vendors/luajit/lib/linux64/libluajit.so -------------------------------------------------------------------------------- /vendors/luajit/lib/win64/lua51.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drakeee/altv-lua-module/f3d18e7ef7f5c7ec089a8652ce02865720385960/vendors/luajit/lib/win64/lua51.lib -------------------------------------------------------------------------------- /vendors/luajit/lib/win64/luajit.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drakeee/altv-lua-module/f3d18e7ef7f5c7ec089a8652ce02865720385960/vendors/luajit/lib/win64/luajit.lib --------------------------------------------------------------------------------