Code Monkey home page Code Monkey logo

ps2-rich-presence's Introduction

PS2 Rich Presence

An open source project providing Rich Presence for PlanetSide 2.

License GitHub Release Date

OverviewFeaturesLimitationsLicenseInstallationContributing

Overview

The PlanetSide 2 Rich Presence Client is a project enabling you to display the current status of your PS2 character on Discord.

Rich Presence Comparison

This application runs independently of the main PlanetSide 2 executable and does not affect your in-game experience. Instead, it listens to the game's event stream and infers the current status of your character based on kills and experience gain.

Note: This is a third-party tool and not affiliated with Rogue Planet Games or the PlanetSide 2 development team in any way.

Work In Progress

This utility is still in its early stages of development. Many features are missing (see below) and bugs are next to certain.

If you find some, please do not hesitate to report them.

Noteworthy omissions

These are planned features that are in development but not yet available in the current version:

  • No start-on-login support
  • No minimizing to tray
  • No automatic tracking of characters on login or failover when they log off

Features

  • Display your character's status on Discord
  • Detection of current continent, class, and vehicle
  • Lightweight and low bandwidth usage
  • Automatic tracking upon login (soon)

Limitations

This application is not tied to the game executable or your player account. Its only way to detect your character's status is to listen to the game's event stream, and it is limited to the events and activities it can detect.

This means that there are things that it cannot detect, such as:

  • Whether the player is currently in a squad or platoon (at least with any accuracy)
  • Where on the map they are
  • Any situation where you are not gaining any experience for an extended period of time

Additionally, we intentionally do not support display of character or outfit names for privacy reasons as there is no way to ensure that the tracked character belongs to the player who is running the application.

License

The PS2 Rich Presence Client is licensed under the GNU General Public License v3.0.

We do not recommend basing your own work on this project, but feel free to use it as a reference for your own projects or reach out to the developers if you have any questions.

Game Artwork and Icons

Most artworks used in this application are based on assets available through the Daybreak Game Company Census API, which were then modified (e.g., upscaled, traced, or cropped) for our requirements. See the Assets README for details on where these assets came from and how exactly they were altered.

Use of our modifications is permitted without restriction. Note that your use still has to comply with the Census API Policy and the Daybreak Game Company Terms of Service.

Screenshots

Some assets, such as the continent artworks, are derived from in-game screenshots taken by project contributors. You can find the full-size screenshots here.

You are free to use and modify these screenshots for your own projects given compliance with the PlanetSide 2 Terms of Service.

Installation

You can find an installer package for the latest version in the project Releases.

Building from Source

The following is a non-exhaustive guide to building this project from source.

  1. This project uses CMake to generate its build system. At least version 3.25 is required.

  2. Dependencies are provided by vcpkg. See the vcpkg docs for downloading and bootstrapping an installation.

  3. Clone this repository using Git:

    git clone https://github.com/leonhard-s/ps2-rich-presence

    Set your current working directory to the root of the cloned project:

    cd ps2-rich-presence
  4. The CMake presets for this project expect the environment variable VCPKG_INSTALLATION_ROOT to be set to your vcpkg installation. Alternatively, you can create a custom preset inheriting from vcpkg and override the CMAKE_TOOLCHAIN_FILE cache variable to point to your installation's CMake toolchain script.

  5. Run CMake to configure the project:

    cmake -S . -B ./build/ --preset "vcpkg-x64-windows"

    Note: During initial configuration, the CMake toolchain will fetch and install the dependencies. Note that this includes building Qt, which may take some time on first configuration.

  6. Build the project:

    cmake --build ./build/ --target install

    The --target install suffix will automatically install the application into the dist/<preset> subdirectory, including any required dependencies.

Contributing

If you encounter any issues using the app or would like to suggest a new feature or change, feel free to get in touch via the repository issues.

Please also consider lack of clarity or undocumented features when creating issues.
Using this application should be straightforward for anyone familiar with the game, and any improvement to make the app clearer and more intuitive to use is worth discussing.

ps2-rich-presence's People

Contributors

dependabot[bot] avatar leonhard-s avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ps2-rich-presence's Issues

Fix spurious errors in class reporting

When dying to an enemy, the tracker occasionally reports an incorrect infantry class.

I am not certain yet whether it confuses the killing player with the victim. The error does not appear to occur when piloting a vehicle, but this is more likely down to the game no longer letting players die in vehicles (instead, they exit the vehicle first and then die as their current infantry class).

Investigation ongoing.

Create custom screenshots for zone icons

We're currently using existing Screenshots by other players or artwork extracted from PS2 news articles or loading screens.
These assets are therefore inconsistent and most importantly their use is not covered by the terms of service.

Over the next few days, I will go on photo safari in-game and create high resolution solution 4K ultra screenshots to use in new assets, which can then also be hosted in the repository.

Create Discord API application

A Discord application has been created and I have had lovely time playing with assets.

The assets used in the screenshot below are either available through the game's file endpoint or are based on freely available screenshots from the game's "Media" section. The latter may be replaced with our own screenshots to avoid legal questions; the API assets are covered by its terms.

Screenshot 2021-12-22 123538

Replace fallback data with TLRU API cache

The ps2data library was written back when the API was very out-of-date. Now that it is maintained again, it would be nice to leverage it again, with new weapons, continents, and alerts being added.

The existing fallback values may remain, but an optional TLRU cache would be used to query the latest data from Census/Sanctuary on launch.

Support minimizing to tray

Small utilities like this one don't deserve to sit in the task bar, so they should hide away in the system tray drawer until someone wants to close them.

Particularly once auto-tracking of characters and autorun on login are implemented, there is little reason to open the application itself beyond adding or removing characters.

'GainExperience' subscription payload regularly defaults to nonsensical values

An irregular error in the EssClient::subscribe() method causes deferred subscriptions (i.e. ones performed prior to the ESS client establishing the WebSocket connection) to fail.

This is linked to the definition order; the first subscription always succeeds, while any later subscriptions get more and more mangled in the process.

TypeError: unsupported operand type(s) for |: 'EnumMeta' and 'EnumMeta'

Hi,

I just tried using the app but I get the following exception and traceback:

WARNING: CPU random generator seem to be failing, disabling hardware random number generation
WARNING: RDRND generated: 0xffffffff 0xffffffff 0xffffffff 0xffffffff
Traceback (most recent call last):
  File "C:\Python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\user\GitHub\ps2-rich-presence\ps2rpc\__main__.py", line 10, in <module>
    from ._app import Application
  File "C:\Users\user\GitHub\ps2-rich-presence\ps2rpc\_app.py", line 8, in <module>
    from ._rpc import RPCHandler
  File "C:\Users\user\GitHub\ps2-rich-presence\ps2rpc\_rpc.py", line 15, in <module>
    from .presence import PresencePayload
  File "C:\Users\user\GitHub\ps2-rich-presence\ps2rpc\presence\__init__.py", line 8, in <module>
    from ._factory import PresenceFactory
  File "C:\Users\user\GitHub\ps2-rich-presence\ps2rpc\presence\_factory.py", line 8, in <module>
    from ..game import GameState, Ps2Class
  File "C:\Users\user\GitHub\ps2-rich-presence\ps2rpc\game\__init__.py", line 10, in <module>
    from ._gamestate import GameState, GameStateFactory
  File "C:\Users\user\GitHub\ps2-rich-presence\ps2rpc\game\_gamestate.py", line 14, in <module>
    class GameState:
  File "C:\Users\user\GitHub\ps2-rich-presence\ps2rpc\game\_gamestate.py", line 21, in GameState
    profile: Ps2Class | Ps2Vehicle
TypeError: unsupported operand type(s) for |: 'EnumMeta' and 'EnumMeta'

Installation/Usage steps:

  1. git clone [email protected]:leonhard-s/ps2-rich-presence.git; cd ps2-rich-presence
  2. python -m venv .
  3. .\Scripts\Activate.ps1
  4. pip install -r .\requirements.txt
  5. python -m ps2rpc

Support alert tracking

The Discord RPC payload supports startTimestamp and endTimestamp fields that can be used to create timers.

The countdown timers would be a nice touch for ongoing alerts.

However, for this to be dependable, we would require a REST endpoint to detect ongoing alerts upon login or when switching zones.

Postponing this issue for the time being; something to look into once the ps2 map API is up and running.

Remember active char on char manager cancel

Upon leaving the character manager, the GUI currently defaults to the first character in the list.

It would be more convenient to switch to the last added character, since they were likely added for a reason.

Get Auraxium to run in PyQt6 (qasync)

Auraxium requires asyncio-like event loops to function. However, Qt (and thus PyQt6) have their own event loop system, which makes them incompatible.

The qasync package aims to provide a Qt-based event loop that is compatible with the interface required for Python coroutines.

First step is to see if this works, or if we have to create a separate thread for asyncio and start signalling back and forth between Qt and Python.

Expand CI integration

The build, test, and release process need to be moved to CI before tackling any of the other features.

This includes:

Automated builds

  • Windows builds using MSVC
  • Windows builds using Clang
  • Linux builds

Quality

  • CppCheck
  • MSVC C++ Code Analyis

Testing

  • Unit tests for Arx
  • Integration tests (using Qt for clients)
  • Synchronization tests for PS2Data

Deployment

  • Automated build & installer creation

Investigate pypresence incompatibility

Brief

The project currently has to monkey-patch certain utilities in the pypresence module to function.

While effective, this is not a great idea and should be rectified.

Details

The application being Qt-based means that it does not support Python-level asynchronous code out of the box. The qasync package fixes this by providing a Qt-compatible implementation of the PEP 3156 event loop interface.

However, on Windows, pypresence performs an isinstance() check on the running event loop as part of its initialisation and will replace it with the default asyncio.ProactorEventLoop if the test fails. This of course is not compatible with Qt and causes the event loop to fail.

Currently, we work around this by monkey-patching this utility function with a version that ignores this check on the "win32" platform:

def _get_event_loop(force_fresh: bool = False) -> asyncio.AbstractEventLoop:
"""Monkey-patched version of pypresence.utils.get_event_loop.
pypresence insists that the win32 event loop must of a particular
subclass, which is not compatible with the QEventLoop helper
requried for Qt support.
"""
if sys.platform == 'win32':
loop = get_qasync_event_loop()
if not loop.is_closed():
return loop
return _get_event_loop_old(force_fresh)
pypresence_utils.get_event_loop = _get_event_loop

Potential Solutions

  • Reach out to the pypresence devs and look into the reason for the isinstance check in this package.

  • If it is not necessary, we can fork/PR the library to get rid of it.

  • If it is indeed required to avoid certain issues, we should investigate adding our own safeguards against whatever it was doing and ideally still fork/PR it instead of monkey-patching internal helpers.

Use custom service ID in WebSocket

The WebSocket connection currently uses s:example regardless of the GitHub repo secret.

This is fine as DBG won't throttle ESS clients anyway, but it should be rectified to correctly identify our client to the service.

Design GUI

Needed information:

  • Tracked characters list
    • Adding/Removing characters
  • Option for automatically tracking chars
  • Debug information (optional / advanced, logs?)
    • Streaming latency
    • API latency
    • Messages per second
  • Connect / Disconnect
  • Reconnect / Restart (optional)
  • Rich presence controls (optional)
    • Show character name
    • Show server
    • Show current class
    • Show current continent
    • Show timer
  • Help link (Repo Wiki)
  • Report A Bug (Repo issues)
  • Repository (Repo)
  • About (License information)

Duplicate character check bypassed on name resolution

If the first copy of a character is added with incorrect spelling, a second copy can be added later. On resolution, both will get corrected to the actual spelling, resulting in duplicate entries.

Since the character manager internally maps characters via their ID, this does not cause any issues in the config and duplicates are removed on next start-up.

The same check-on-resolution would also ensure that a player cannot queue up the same character lookup multiple times (different spellings, direct ID, etc.).

Support display of session stats

In addition of a nondescript "Vanu Sovereignty - Cobalt" status, we could also track the performance of the character. Namely, we could show the current KDR, KHR, KPM, streak, etc. as part of the presence window.

Need to chat up some infantry mains about which stats they care about. Accuracy is likely impossible to calculate reliably from live data (go look at Recursion if you have doubts), so session IvI might be out of the question, too.

thx Sneak for the suggestion

Finalise Presence Model

The Discord Presence drafts were fun but inconsistent. It is time to produce a more uniform style matching the intentions of the corresponding fields as per the RPC documentation.

Notes

  • A "join squad" or "In a squad (X of 12)" button cannot be implemented as this functionality is not available in the API.
  • While displaying the current character name or outfit tag is not a violation of any terms of service, it does open avenues of abuse. We will therefore never display character names or outfit tags.
  • Game state fields ("Idle", "Playing Solo", "Playing in a Squad", etc.) should be settable by the user to communicate that they are open for other players joining them via Discord (i.e. DM and manual invite)

Add character tracking component

The app will have two event listeners, one always-on tracker to detect characters logging in or out, and a second one for tracking the active character.

The former should be an independent component to minimise the risk of the WebSocket subscription going bad.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.