CitizenFX / FiveM

repository·master·Indexed 26 days ago

https://github.com/citizenfx/fivem

Core code for Cfx.re projects, including FiveM (GTA V modification framework), RedM (Red Dead Redemption 2 modification framework), and FXServer. The repository includes the CitizenFX client architecture, server-side implementations, game-specific components for GTA5 and RDR2, and the Cfx.re Development Kit (FxDK). It also features a native codegen suite for transforming native function declarations into C#, TypeScript, JavaScript, and Lua bindings.

Tokens
138.1K
Snippets
913
Records
1.1K
Agent score
88%

What's inside citizenfx/fivem

  1. Overview of system-resources

    master

    The system-resources package contains build scripts for bundled system resources used in the FiveM/RedM ecosystem. It manages two types of resources:

    1. Source-code-based resources: Resources like Chat which are built directly from source.
    2. Artifact-based resources: Resources like Monitor (txAdmin) which use ready-built artifacts from an external source code repository.
  2. Overview of the CitizenFX Native Project structure

    master

    The CitizenFX Native Project is organized into several functional directories that house the core logic for the FiveM/RedM framework:

    • client/: Contains the client launcher logic and common code shared across various projects.
    • components/: The primary location for code organized within the 'component' system.
    • server/: Contains the server launcher logic.
    • shared/: Contains low-level shared code (distinct from client/shared/).
    • deplibs/: Legacy directory containing manually vendored include and library files.
    • tools/: Build tooling used for the native CitizenFX project.
    • vendor/: Contains Premake vendor definitions and non-submodule dependent source files or includes.
    • tests/: A legacy prototype of unit and integration tests (unused since 2014).
  3. Overview of CitizenFX Implementation Components

    master
    The components/ directory contains the core implementation modules for CitizenFX. These components are categorized into Common functionality, Server-side implementations, and game-specific modules for GTA5 and RDR2. Developers looking to extend the platform or understand the underlying architecture can explore these specific sub-modules.
  4. Understand the CitizenFX source code layout

    master

    The CitizenFX codebase is composed of multiple components. Use the following directory structure to navigate the repository:

    • code/: Contains the core native project code and serves as the root for the native build.
    • data/: Contains runtime data used by the projects.
    • ext/: Contains extra supporting projects, which are typically standalone or only depend on files/data within the ext/ directory.
    • vendor/: Contains submodules for project dependencies.
  5. Understand the CitizenFX Client Architecture

    master

    The client/ directory contains the shared CitizenFX framework code used for the client-side environment. The architecture is composed of several key components:

    • citicore: The CitizenFX Runtime. It is responsible for loading components and implementing the CitizenFX Object Model.
    • citigame: An auxiliary component that manages the client-side lifecycle after the initial bootstrapping process is complete.
    • clrcore: The CitizenFX.Core C# library.
    • clrref: Provides reference generation for the CitizenFX.Core library.
    • common: Contains shared source files included across all projects.
    • console: The FiveM.com console launcher.
    • diag: The CfxDiag utility for diagnostics.
    • launcher: The main client entry point and bootstrapper.
    • shared: Contains shared includes and source files used by the framework.
  6. Understand FxDK component communication channels

    master

    The FxDK (Cfx.re Development Kit) consists of several isolated components that communicate via different Inter-Process Communication (IPC) methods. Understanding these channels is essential for debugging or extending the communication between the core, backend, frontend, and game environments.

    Components

    • SDK_HOST: FxDK C++ core
    • SDK_BACKEND: FxDK TypeScript backend (resources/sdk-root/src/backend)
    • SDK_FRONTEND: FxDK TypeScript React frontend (resources/sdk-root/src)
    • SDK_FRONTEND_THEIA: Theia frontend
    • GAME_CLIENT: The game client
    • GAME_SERVER: The game server

    Communication Matrix

    SourceDestinationMethod
    SDK_HOSTSDK_BACKENDEvents
    SDK_BACKENDSDK_HOSTEvents
    SDK_HOSTGAME_CLIENTCustom IPC (launcherTalk)
    SDK_BACKENDSDK_FRONTENDWebSockets
    SDK_BACKENDGAME_SERVERCustom IPC channel
    GAME_SERVERGAME_CLIENTEvents
    SDK_FRONTENDSDK_FRONTEND_THEIAWindow messages
    SDK_FRONTEND*SDK_HOSTCustom V8 handlers (sending process messages)
    SDK_FRONTEND*GAME_CLIENTLimited communication via SharedHostData
    SDK_HOSTSDK_FRONTENDWindow messages
  7. Understand CitizenFX Runtime Data structure

    master
    The data/ directory contains essential runtime data that is copied to the project layout directory during the build process. This data is required for the application to function correctly at runtime. The directory is organized by target platform and runtime type:
  8. Initialize and build the FiveM environment

    master

    Execute these commands in a cmd.exe shell to clone the repository, initialize submodules, and generate the build solution for FiveM.

    Note: If using Python 3.12 or higher, you must install setuptools via pip.

    git clone https://github.com/citizenfx/fivem.git -c core.symlinks=true
    cd fivem
    git submodule update --jobs=16 --init
    
    :: if you're using Python 3.12 or higher make sure you install the setuptools package
    pip install setuptools
    
    :: downloads the right Chrome version for 64-bit projects
    fxd get-chrome
    
    :: build bindings of game natives.
    prebuild
    
    :: or -game server/-game rdr3
    fxd gen -game five
    fxd vs -game five
  9. Add an artifact-based system resource

    master

    Use the manager.js script to add a new artifact-based resource. Note that adding resources requires manual updates to the build.cmd and build.sh build scripts to include the necessary extra build steps.

    $ node manager.js add --name=%RESOURCE_NAME% --url=%RESOURCE_ARTIFACT_URL% --version=%RESOURCE_VERSION%