Epic Online Services Godot (EOSG)

repository·main·Indexed 43 days ago

https://github.com/3ddelano/epic-online-services-godot

A GDExtension-based plugin for Godot 4.2+ that integrates Epic Online Services. It offers a High Level EOS system with simplified async methods and signals for common tasks, as well as a low-level GDExtension EOS interface for direct access to the EOS C SDK.

Tokens
14.6K
Snippets
30
Records
61
Agent score
56%

What's inside EOSG

  1. Choose between High Level EOS and GDExtension EOS

    main

    EOSG provides two distinct ways to interact with Epic Online Services depending on your needs and experience level:

    1. High Level EOS (Recommended): This is the preferred method for most developers. It provides a simplified API using easy-to-use methods and signals that abstract away the complexities of the EOS SDK. It is ideal for beginners or those wanting to implement core functionality quickly.

    2. GDExtension EOS: This provides low-level access to the underlying Epic Online Services SDK. It gives you full control via the EOS and IEOS classes but requires a deeper understanding of the SDK. This is not recommended for beginners.

  2. Understand the two EOSG systems: High Level vs GDExtension

    main

    EOSG provides two distinct ways to interact with Epic Online Services:

    1. High Level EOS (Recommended): Provides easy-to-use methods and signals designed for beginners. It uses specialized classes like HPlatform, HAuth, HAchievements, etc., to simplify common tasks.
    2. GDExtension EOS: Provides advanced, direct access to EOS features. This is not recommended for beginners and requires working with the EOS and IEOS classes.

    Use the High Level system for most game logic unless you require low-level control over the SDK.

  3. Install EOSG via Godot Asset Library

    main

    The recommended way to install the plugin is through the built-in Godot Asset Library:

    1. Open the Godot editor and navigate to the AssetLib tab.
    2. Search for EOSG.
    3. Select Epic Online Services Godot (EOSG) by 3ddelano.
    4. Click Download, then click Install once the download completes.
    5. Go to Project -> Project Settings -> Plugins and enable the Epic Online Services Godot 4.2+ (EOSG) plugin.
    6. Restart the Godot editor.
  4. Manual Android Export Setup

    main

    To export your project for Android, you can use the EOSG Android Exporter or follow these manual steps:

    1. Prerequisites

    2. Configure res://android/build/build.gradle

    Add dependencies:

    // Inside dependencies block
    implementation 'androidx.appcompat:appcompat:1.5.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.security:security-crypto:1.0.0'
    implementation 'androidx.browser:browser:1.4.0'
    implementation 'androidx.webkit:webkit:1.7.0'
    // Path to the AAR provided in addons/epic-online-services-godot/bin/android/
    implementation files('../../addons/epic-online-services-godot/bin/android/eossdk-StaticSTDC-release.aar')

    Add ClientId to defaultConfig:

    android {
        defaultConfig {
            // ... existing config
            missingDimensionStrategy 'products', 'template'
    
            // Required by EOS Android SDK
            String ClientId = "PUT YOUR EOS CLIENT ID HERE"
            resValue("string", "eos_login_protocol_scheme", "eos." + ClientId.toLowerCase())
        }
    }

    3. Configure res://android/build/config.gradle

    Update minSdk to 23:

    minSdk : 23

    4. Modify res://android/build/src/com/godot/game/GodotGame.java

    Update the Java entry point to initialize the EOS SDK:

    package com.godot.game;
    
    import com.epicgames.mobile.eossdk.EOSSDK; // added
    import org.godotengine.godot.GodotActivity;
    import android.os.Bundle;
    
    public class GodotApp extends GodotActivity {
        static {
            System.loadLibrary("EOSSDK"); // added
        }
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            EOSSDK.init(getActivity()); // added
            setTheme(R.style.GodotAppMainTheme);
            super.onCreate(savedInstanceState);
        }
    }

    5. Export Settings

    In Godot Project -> Export:

    • Enable Use Gradle Build.
    • Enable arm64-v8a in Architectures.
    • Enable ACCESS_NETWORK_STATE, ACCESS_WIFI_STATE, and INTERNET in Permissions.
    package com.godot.game;
    
    import com.epicgames.mobile.eossdk.EOSSDK;
    import org.godotengine.godot.GodotActivity;
    import android.os.Bundle;
    
    public class GodotApp extends GodotActivity {
        static {
            System.loadLibrary("EOSSDK");
        }
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            EOSSDK.init(getActivity());
            setTheme(R.style.GodotAppMainTheme);
            super.onCreate(savedInstanceState);
        }
    }
  5. Bootstrap Godot with EOS for Windows Account Portal

    main

    To use the Account Portal login option on Windows, you must bootstrap the Godot executable using the Epic Games Redistributable Installer. This involves creating an .ini file that points to your executable.

    Example .ini configuration for development:

    ApplicationPath=Godot_v4.2.0-stable_win64.exe
    WorkingDirectory=
    WaitForExit=0
    NoOperation=0

    Note: ApplicationPath should point to your Godot Editor executable during development, or your exported game executable for production.

  6. Initialize High Level EOS in GDScript

    main

    To use the High Level EOS system, you must first create an HCredentials object with your Epic Developer Portal details and call HPlatform.setup_eos_async(credentials).

    Key steps in a typical setup script:

    1. Set HLog.log_level for debugging.
    2. Populate HCredentials with product_name, product_version, product_id, sandbox_id, deployment_id, client_id, and client_secret.
    3. Await HPlatform.setup_eos_async(credentials).
    4. Connect to HPlatform.log_msg to capture SDK logs.
    5. Connect to HAuth.logged_in to handle authentication events.
    6. Use HAuth.login_devtool_async() for local development or HAuth.login_anonymous_async() for anonymous login.
    # In main script
    extends Node
    
    func _ready() -> void:
    	# Setup HEOS Logs
    	HLog.log_level = HLog.LogLevel.INFO
    
    	var credentials = HCredentials.new()
    	credentials.product_name = "PRODUCT_NAME_NAME"
    	credentials.product_version = "PRODUCT_VERSION_HERE"
    	credentials.product_id = "PRODUCT_ID_HERE"
    	credentials.sandbox_id = "SANDBOX_ID_HERE"
    	credentials.deployment_id = "DEPLOYMENT_ID_HERE"
    	credentials.client_id = "CLIENT_ID_HERE"
    	credentials.client_secret = "CLIENT_SECRET_HERE"
    	# credentials.encryption_key = "ENCRYPTION_KEY_HERE" # optional
    
    	var setup_success := await HPlatform.setup_eos_async(credentials)
    	if not setup_success:
    	    printerr("Failed to setup EOS. See logs for more details")
    	    return
    
    	# Setup Logs from EOS
    	HPlatform.log_msg.connect(_on_eos_log_msg)
    	var log_res := HPlatform.set_eos_log_level(EOS.Logging.LogCategory.AllCategories, EOS.Logging.LogLevel.Info)
    	if not EOS.is_success(log_res):
    		printerr("Failed to set logging level")
    		return
    
    	HAuth.logged_in.connect(_on_logged_in)
    
    	# During development use the devauth tool to login
    	HAuth.login_devtool_async("localhost:4545", "CREDENTIAL_NAME_HERE")
    
    	# Or login without any credentials
    	# await HAuth.login_anonymous_async()
    
    
    func _on_logged_in():
    	print("Logged in successfully: product_user_id=%s" % HAuth.product_user_id)
    
    	# Example: Get top records for a leaderboard
    	var records := await HLeaderboards.get_leaderboard_records_async("LEADERBOARD_ID_HERE")
    	print(records)
    
    
    func _on_eos_log_msg(msg: EOS.Logging.LogMessage) -> void:
    	print("SDK %s | %s" % [msg.category, msg.message])
  7. Install EOSG from GitHub

    main

    If you prefer manual installation or need specific platform builds:

    1. Download the latest release from the GitHub Releases page. You can download platform-specific zip files or the epic-online-services-godot-all package for all platforms.
    2. Extract the zip file.
    3. Copy the addons/epic-online-services-godot folder into your project's res://addons/ directory (create the addons folder if it does not exist).
    4. In the Godot editor, go to Project -> Project Settings -> Plugins and enable the Epic Online Services Godot 4.2+ (EOSG) plugin.
    5. Restart the Godot editor.
  8. Setup EOS for Android

    main

    Android initialization requires manual configuration of the Android build template and Gradle files.

    1. Gradle Dependencies

    In res://android/build/build.gradle, add the following to the dependencies section:

    // EOS SDK dependencies
    implementation 'androidx.appcompat:appcompat:1.5.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.security:security-crypto:1.0.0'
    implementation 'androidx.browser:browser:1.4.0'
    // Path to the .aar file in the plugin bin folder
    implementation files('../../addons/epic-online-services-godot/bin/android/eossdk-StaticSTDC-release.aar')

    2. Android Configuration

    In res://android/build/build.gradle, add the following inside the android.defaultConfig section:

    // This is needed by EOS Android SDK
    String ClientId = "PUT YOUR EOS CLIENT_ID HERE"
    resValue("string", "eos_login_protocol_scheme", "eos." + ClientId.toLowerCase())

    3. Minimum SDK Version

    In res://android/build/config.gradle, update minSdk to 23:

    minSdk : 23

    4. Java Initialization

    In res://android/build/src/com/godot/game/GodotGame.java, load the library and initialize the SDK:

    package com.godot.game;
    
    import com.epicgames.mobile.eossdk.EOSSDK;
    import org.godotengine.godot.GodotActivity;
    import android.os.Bundle;
    
    public class GodotApp extends GodotActivity {
        static {
            System.loadLibrary("EOSSDK");
        }
        
        @Override
        public void onCreate(Bundle savedInstanceState) {
            EOSSDK.init(getActivity());
            setTheme(R.style.GodotAppMainTheme);
            super.onCreate(savedInstanceState);
        }
    }

    5. Export Settings

    When creating the Android export profile in Godot:

    • Enable Use Gradle Build.
    • Enable arm64-v8a architecture.
    • Enable permissions: ACCESS_NETWORK_STATE, ACCESS_WIFI_STATE, and INTERNET.
  9. Initialize the EOS SDK and Platform in Godot

    main

    To use the plugin, you must first obtain credentials from the EOS Developer Portal (PRODUCT_ID, SANDBOX_ID, DEPLOYMENT_ID, CLIENT_ID, CLIENT_SECRET) and define your own project metadata (PRODUCT_NAME, PRODUCT_VERSION, and a 64-character ENCRYPTION_KEY).

    Initialization involves two main steps:

    1. Initialize the SDK: Uses EOS.Platform.InitializeOptions to set up the core SDK.
    2. Create the Platform: Uses EOS.Platform.CreateOptions to create the EOS platform instance.

    On Windows, you can enable the Social Overlay by setting create_opts.flags = EOS.Platform.PlatformFlags.WindowsEnableOverlayOpengl and configuring HAuth.auth_login_flags.

    extends Node
    
    func _ready() -> void:
    	# 1. Configure EOSG Logging
    	HLog.log_level = HLog.LogLevel.INFO
    
    	# 2. Setup SDK Initialization
    	var init_opts = EOS.Platform.InitializeOptions.new()
    	init_opts.product_name = "PRODUCT_NAME_HERE"
    	init_opts.product_version = "PRODUCT_VERSION_HERE"
    
    	# 3. Setup Platform Creation
    	var create_opts = EOS.Platform.CreateOptions.new()
    	create_opts.product_id = "PRODUCT_ID_HERE"
    	create_opts.sandbox_id = "SANDBOX_ID_HERE"
    	create_opts.deployment_id = "DEPLOYMENT_ID_HERE"
    	create_opts.client_id = "CLIENT_ID_HERE"
    	create_opts.client_secret = "CLIENT_SECRET_HERE"
    	create_opts.encryption_key = "ENCRYPTION_KEY_HERE"
    
    	# Windows Social Overlay
    	if OS.get_name() == "Windows":
    		HAuth.auth_login_flags = EOS.Auth.LoginFlags.None
    		create_opts.flags = EOS.Platform.PlatformFlags.WindowsEnableOverlayOpengl
    
    	# 4. Execute Initialization
    	var init_res := await HPlatform.initialize_async(init_opts)
    	if not EOS.is_success(init_res):
    		printerr("Failed to initialize EOS SDK: ", EOS.result_str(init_res))
    		return
    	
    	var create_success := await HPlatform.create_platform_async(create_opts)
    	if not create_success:
    		printerr("Failed to create EOS Platform")
    		return
    
    	# 5. Setup Logging and Signals
    	HPlatform.log_msg.connect(_on_eos_log_msg)
    	var log_res := HPlatform.set_eos_log_level(EOS.Logging.LogCategory.AllCategories, EOS.Logging.LogLevel.Info)
    	if not EOS.is_success(log_res):
    		printerr("Failed to set logging level")
    		return
    
    	HAuth.logged_in.connect(_on_logged_in)
    
    func _on_logged_in():
    	print("Logged in successfully: product_user_id=%s" % HAuth.product_user_id)
    
    func _on_eos_log_msg(msg: EOS.Logging.LogMessage) -> void:
    	print("SDK %s | %s" % [msg.category, msg.message])
  10. Build the EOSG GDExtension from source

    main

    To develop or build the plugin manually, you need the Godot Engine, the Epic Online Services C SDK, and SCons.

    1. Clone the repository and update submodules:
      git submodule update --init --recursive
    2. Place the EOS C SDK in the thirdparty/eos-sdk folder.
    3. Build for debug (with symbols):
      scons platform=<platform> target=template_debug dev_build=yes
    4. Build for release (optimized):
      scons platform=<platform> target=template_release

    Replace <platform> with your target (e.g., windows, linux, android, macos, ios).

    scons platform=windows target=template_debug dev_build=yes