GithubHelp home page GithubHelp logo

arcdps_bindings's Introduction

Arcdps Plugin Bindings Latest Version

This provides arcdps plugin bindings featuring safe, zero-cost abstractions.

Easily integrate into arcdps with just a few lines of code.

Features

Current features include:

  • Versioning plugins via Cargo.toml
  • A simple interface for all callbacks
  • Optional opt out of safe abstractions to directly access the arcdps C interface
  • Imgui interfacing via imgui-rs
  • Logging to arcdps via the log crate
  • unofficial extras bindings

Still in development:

  • Exposing settings from arcdps

Still exploring technical boundaries:

  • Arcdps-like snapping of imgui windows

How to use

A small example showcasing 2 of the many functions provided. If init returns an error, arcdps won't consider the plugin as loaded and will display the error. No other function, except for unofficial-extras functions, will be called afterwards.

use std::error::Error;

use arcdps::UserInfoIter;

arcdps::arcdps_export! {
    name: "example addon",
    sig: 123, // change this to a random number
    unofficial_extras_squad_update: crate::squad_update,
    init: crate::init,
}

fn squad_update(users: UserInfoIter) {
    for user in users.into_iter() {
        println!("{:?}", user);
    }
}

fn init(swapchain: Option<NonNull<c_void>>) -> Result<(), Box<dyn Error>> {
    match swapchain {
        Some(swapchain) => {
            println!("init: initialized with swapchain: {:?}", swapchain);
            Ok(())
        }
        None => Err("init: swapchain is None".into()),
    }
}

arcdps_bindings's People

Contributors

belst avatar greaka avatar krappa322 avatar lunahria avatar mirclus avatar zerthox avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

arcdps_bindings's Issues

remove chrono dependency

when i run cargo audit, i get this error

Crate:     time
Version:   0.1.45
Title:     Potential segfault in the time crate
Date:      2020-11-18
ID:        RUSTSEC-2020-0071
URL:       https://rustsec.org/advisories/RUSTSEC-2020-0071
Severity:  6.2 (medium)
Solution:  Upgrade to >=0.2.23
Dependency tree:
time 0.1.45
└── chrono 0.4.26
    └── arcdps 0.9.0
        └── jokolink 0.1.0
error: 1 vulnerability found!

chrono won't fix it chronotope/chrono#602 (comment)
and instead recommends people to wait for 0.5 release which has been going on since April chronotope/chrono#970 . Just like the Alliances :D

So, we have three options:

  1. wait for chrono 0.5 which might take a while
  2. directly use time crate, if possible.
  3. feature gate the uses of chrono. AFAIK it is only used for combat messages. and they can be enabled by an optional feature

Backport table sorting API

Can't create an issue in the imgui-rs fork so creating it here.

Backport table_sort_specs_mut and all the structs etc that's needed to go along with that. I have gotten this to work: (although in the fork you can of course make table_sort_specs_mut a member function in imgui::ui instead of sending it as first argument). It should be 100% the same as upstream, except for the aforementioned function which I converted into a free function,

use arcdps::imgui::{self, ImStr, Ui};
use std::marker::PhantomData;

// START COPIED FROM LATEST IMGUI-RS - https://github.com/imgui-rs/imgui-rs/blob/main/imgui/src/tables.rs#L737

/// A wrapper around table sort specs.
///
/// To use this simply, use [conditional_sort] and provide a closure --
/// if you should sort your data, then the closure will be ran and imgui
/// will be informed that your data is sorted.
///
/// For manual control (such as if sorting can fail), use [should_sort] to
/// check if you should sort your data, sort your data using [specs] for information
/// on how to sort it, and then [set_sorted] to indicate that the data is sorted.
///
/// [conditional_sort]: Self::conditional_sort
/// [should_sort]: Self::should_sort
/// [specs]: Self::specs
/// [set_sorted]: Self::set_sorted
pub struct TableSortSpecsMut<'ui>(*mut imgui::sys::ImGuiTableSortSpecs, PhantomData<Ui<'ui>>);

impl TableSortSpecsMut<'_> {
    /// Gets the specs for a given sort. In most scenarios, this will be a slice of 1 entry.
    pub fn specs(&self) -> Specs<'_> {
        let value =
            unsafe { std::slice::from_raw_parts((*self.0).Specs, (*self.0).SpecsCount as usize) };

        Specs(value)
    }

    // /// Returns true if the data should be sorted.
    // pub fn should_sort(&self) -> bool {
    //     unsafe { (*self.0).SpecsDirty }
    // }

    // /// Sets the internal flag that the data has been sorted.
    // pub fn set_sorted(&mut self) {
    //     unsafe {
    //         (*self.0).SpecsDirty = false;
    //     }
    // }

    // /// Provide a closure, which will receive the Specs for a sort.
    // ///
    // /// If you should sort the data, the closure will run, and ImGui will be
    // /// told that the data has been sorted.
    // ///
    // /// If you need manual control over sorting, consider using [should_sort], [specs],
    // /// and [set_sorted] youself.
    // ///
    // /// [should_sort]: Self::should_sort
    // /// [specs]: Self::specs
    // /// [set_sorted]: Self::set_sorted
    // pub fn conditional_sort(mut self, mut f: impl FnMut(Specs<'_>)) {
    //     let is_dirty = self.should_sort();

    //     if is_dirty {
    //         f(self.specs());
    //     }

    //     self.set_sorted();
    // }
}

/// A wrapper around a slice of [TableColumnSortSpecs].
///
/// This slice may be 0 if [TableFlags::SORT_TRISTATE] is true, may be > 1 is [TableFlags::SORT_MULTI] is true,
/// but is generally == 1.
///
/// Consume this struct as an iterator.
pub struct Specs<'a>(&'a [imgui::sys::ImGuiTableColumnSortSpecs]);

impl<'a> Specs<'a> {
    pub fn iter(self) -> impl Iterator<Item = TableColumnSortSpecs<'a>> {
        self.0.iter().map(|v| TableColumnSortSpecs(v))
    }
}

pub struct TableColumnSortSpecs<'a>(&'a imgui::sys::ImGuiTableColumnSortSpecs);
impl<'a> TableColumnSortSpecs<'a> {
    // /// User id of the column (if specified by a TableSetupColumn() call)
    // pub fn column_user_id(&self) -> imgui::sys::ImGuiID {
    //     self.0.ColumnUserID
    // }

    /// Index of the column
    pub fn column_idx(&self) -> usize {
        self.0.ColumnIndex as usize
    }

    // /// Index within parent [Specs] slice where this was found -- always stored in order starting
    // /// from 0, tables sorted on a single criteria will always have a 0 here.
    // ///
    // /// Generally, you don't need to access this, as it's the same as calling `specs.iter().enumerate()`.
    // pub fn sort_order(&self) -> usize {
    //     self.0.SortOrder as usize
    // }

    /// Gets the sort direction for the given column. This will nearly always be `Some` if you
    /// can access it.
    pub fn sort_direction(&self) -> Option<TableSortDirection> {
        match self.0.SortDirection() {
            0 => None,
            1 => Some(TableSortDirection::Ascending),
            2 => Some(TableSortDirection::Descending),
            _ => unimplemented!(),
        }
    }
}

#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
pub enum TableSortDirection {
    Ascending,
    Descending,
}

/// Gets the sorting data for a table. This will be `None` when not sorting.
///
/// See the examples folder for how to use the sorting API.
pub fn table_sort_specs_mut<'a>(_pUi: &'a Ui) -> Option<TableSortSpecsMut<'a>> {
    unsafe {
        let value = imgui::sys::igTableGetSortSpecs();
        if value.is_null() {
            None
        } else {
            Some(TableSortSpecsMut(value, PhantomData))
        }
    }
}

// END COPIED FROM LATEST IMGUI-RS

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.