Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for external bluetooth devices #535

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

sylvieee-iot
Copy link

@sylvieee-iot sylvieee-iot commented Jul 14, 2024

Add support for external haptic bluetooth devices, in this case but*plugs. This works for all sorts of bluetooth but*plugs that use the common bluetooth protocol for BPs, and is also hooked to the Lua API so that you can make per-game scripts to activate and control your device.

This is early progress code, I need some more time to work on it and help if possible. Thanks.

@sylvieee-iot
Copy link
Author

Also I need to implement some more Lua events for things like but*plug being connected, as it would make Lua scripts significantly easier to write. Now it's kind of hard to know when to start/stop rumbling the device.

@sylvieee-iot
Copy link
Author

Example of the Lua API

rupees1_address = 0x050AF88
rupees2_address = 0x05879A0

device = 0  -- Device to buzz
force = 0.4 -- Force to use
vibration_time = 120 -- Number of frames to buzz buzz for
vibration_countdown = 0 -- Number of frames until we should stop buzzing
first = true-- Is this our first time counting rupees?

previous_rupees = 0 -- How many rupees did we have in the previous frame?
current_rupees = 0  -- How many rupees do we currently have?

Buzz.initHaptics() -- Initialize haptics subsytem
Buzz.connect()     -- Connect to device
Buzz.requestDeviceList()
Buzz.startScan()

function vibe()
    vibration_countdown = vibration_time

    Buzz.getDevices()
    Buzz.sendScalar(device, force)
end

function unvibe()
    Buzz.getDevices()
    Buzz.sendScalar(device, 0.0)
end

function getRupees() return Pand.read16(rupees1_address) end

function eventHandler(e)
    if (e == Pand.Frame) then
        if (first) then
            previous_rupees = getRupees()
            first = false
            return
        end

        previous_rupees = current_rupees
        current_rupees = getRupees()

        if (current_ruppes ~= previous_rupees) then vibe() end

        -- Ongoing vibration, count down
        if (vibration_countdown > 0) then 
            vibration_countdown = vibration_countdown - 1
            -- Stop vibrating if we're done
            if (vibration_countdown == 0) then unvibe() end
        end
    end
end

I think buzz is a pretty cute name xD

@OFFTKP
Copy link
Collaborator

OFFTKP commented Jul 14, 2024

Please merge this as soon as possible

@sylvieee-iot
Copy link
Author

sylvieee-iot commented Jul 14, 2024

Please merge this as soon as possible

Yes I believe many people would love to feel the erotic sensations a toy can offer when combined with Lua scripts :3 😉

@sylvieee-iot
Copy link
Author

Can you review @OFFTKP

@@ -70,6 +70,9 @@
[submodule "third_party/capstone"]
path = third_party/capstone
url = https://github.com/capstone-engine/capstone
[submodule "third_party/open-bp-cpp/third_party/IXWebSocket"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You added this as a submodule, but not open-bp-cpp. We prefer to store stuff as submodules here so that when githubs go private we don't suffer any damages. Actually wait, that would have the opposite effect. What was I saying? Oh please add open-bp-cpp as a submodule instead

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OPEN BP CPP IS HEAVILY MODIFIED AS I MADE IT GOOD WHILE IT WAS HORRIBLE BEFORE

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sorry but I am not going to go through 20 thousand lines of code to make sure you didn't add a backdoor (heh get it?) somewhere in the program.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dun geddit

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well you see, prior this year we had some "guys" that tried to implement a backdoor in the OSS project named XZ. Here, OFFTKP wants to make sure that the program stays secure. In order to do that, every PR that adds code must be analyzed by hand to prevent any attack of this kind. Reviewing code is an operation that take an exponential amount of time. The more line there is to review, the more time it takes. I totally understand that OFFTKP does not have the required time to analyze 20K lines of code. Only peoples employed in an enterprise would do this. If he/she is a hobbyist or a developer doing this on his/her free time, then he/she may not have this time.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well you see, prior this year we had some "guys" that tried to implement a backdoor in the OSS project named XZ. Here, OFFTKP wants to make sure that the program stays secure. In order to do that, every PR that adds code must be analyzed by hand to prevent any attack of this kind. Reviewing code is an operation that take an exponential amount of time. The more line there is to review, the more time it takes. I totally understand that OFFTKP does not have the required time to analyze 20K lines of code. Only peoples employed in an enterprise would do this. If he/she is a hobbyist or a developer doing this on his/her free time, then he/she may not have this time.

  1. https://en.m.wikipedia.org/wiki/Singular_they

  2. I agree, either they (the author of this PR) rewrite to use the "official" branch of the library or they try to make a PR to make their branch of the library merged to the library itself.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1. https://en.m.wikipedia.org/wiki/Singular_they

Thank you, I am not en English people so I didn't know it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well you see, prior this year we had some "guys" that tried to implement a backdoor in the OSS project named XZ. Here, OFFTKP wants to make sure that the program stays secure. In order to do that, every PR that adds code must be analyzed by hand to prevent any attack of this kind. Reviewing code is an operation that take an exponential amount of time. The more line there is to review, the more time it takes. I totally understand that OFFTKP does not have the required time to analyze 20K lines of code. Only peoples employed in an enterprise would do this. If he/she is a hobbyist or a developer doing this on his/her free time, then he/she may not have this time.

A true 10X programmer like @OFFTKP would have no problem with 20K lines of code. A real 69X programmer like me would just look at the diff between upstream and my vendored version in a text editor 🤣

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a fellow 69X programmer, I confirmed that the files added was 100x improvement modification from the original https://github.com/dumbowumbo/buttplugCpp repository (in which is the officially supported binding of the Buttplug library) that is totally harmless and definitely not a backdoor.

SensorClass sensors;

public:
ExternalHapticsManager() : client("ws://127.0.0.1", 12345) {}
Copy link
Collaborator

@OFFTKP OFFTKP Jul 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't hardcode the address/port like that. More so, what if I want to receive haptic inputs from people all around the globe, do I have to modify the code myself to change the ip address my haptic device is hosted on? What is this, dwm?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds buttplug support not e-sex support bro

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what that b word is or what e-sex is, please address the review comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what that b word is or what e-sex is, please address the review comment

fucking e-virgin

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding onto @OFFTKP's suggestion I would suggest adding UPnP support if the IP is 127.0.0.1 to automatically port forward the rumble device if it is hosted on the same networks and registering the public IP in a real time database such as firebase for any Panda3DS user to connect to.

https://github.com/cybergarage/mupnp-cc

ExternalHapticsManager() : client("ws://127.0.0.1", 12345) {}

void connect() {
client.connect([](const mhl::Messages message) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of const when we are copying a value over anyway?

}

void stopDevice(int index) {
if (index < devices.size()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would probably trigger a signed unsigned comparison warning

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't care wtf

include_directories(third_party/open-bp-cpp/include)
include_directories(third_party/open-bp-cpp/third_party/IXWebSocket/ixwebsocket)
add_subdirectory(third_party/open-bp-cpp)
target_link_libraries(AlberCore PRIVATE buttplugCpp)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This library doesn't really feel as a core component of Alber to justify being linked to the core library.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't care

}

// clang-format off
static constexpr luaL_Reg functions[] = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above, also static constexpr doesn't make much sense to me anyway

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

constexpr makes it a constant expresison, static guarantees that it's allocated in static storage instead of copied on the stack when the function runs. This is why any LUTs you declare in a function should be declared as static constexpr and NOT plain constexpr.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't in a function so it's gonna go in static storage anyway. However we should keep it as constexpr (even if it does literally nothing) so that we can claim we use modern C++. Also you missed a chance to use the X macros you love so much:

#define X(name) { #name, name##Thunk },

hapticsManager->sendScalar(device, value);
}

return 2;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic number

Copy link
Author

@sylvieee-iot sylvieee-iot Jul 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sir this is how Lua thunks work, you return the number of return values

hapticsManager->stopDevice(device);
}

return 1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another magic number

return 0;
}

#define HAPTICS_THUNK(func) \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

X macros are bad because they enable you to essentially have a very easy and portable way to generate boilerplate code and reduce duplicated code, thus leading to less source code cluttering. Wait why did I say they are bad?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lines of code = performance

return 1;
}

// clang-format off
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What a tragedy

@kamil-diy
Copy link

buzz buzz

@@ -242,6 +245,80 @@ static int disassembleTeakThunk(lua_State* L) {
return 1;
}

#ifndef __ANDROID__
// Haptics functions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you care a little

return 0;
}

#define HAPTICS_THUNK(func) \
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lines of code = performance

@wheremyfoodat
Copy link
Owner

Why is this PR

@x4exr
Copy link

x4exr commented Nov 1, 2024

i didnt understand what that question was asking, which means I am a bumbling idiot :(

@kamil-diy
Copy link

the pr of all time

@x4exr
Copy link

x4exr commented Nov 4, 2024

the pr of all time

I feel like I know you from somewhere

@kamil-diy
Copy link

the pr of all time

I feel like I know you from somewhere

shhh no you dont

@nonetrix
Copy link

Finally always wanted this

@wheremyfoodat
Copy link
Owner

Finally always wanted this

Are you for real

@KingKrouch
Copy link

Ultrakill fans are having a field day right now modding in plug support into everything.

@AlphaLovesYou
Copy link

im still curious on the potential addition of shock collar support.
forgot to message our glorious leader about it. may he forgive me for my faliures.

@VenomousSteam81
Copy link

I guess this is something to mess with later.

Copy link

@TruncatedDinoSour TruncatedDinoSour left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@powdered-java
Copy link

LGTM

ari no dont do this

@TruncatedDinoSour
Copy link

LGTM

ari no dont do this

I said what I said.

Looks. Good. To. Me.

MERGE THIS!!!

@powdered-java
Copy link

LGTM

ari no dont do this

I said what I said.

Looks. Good. To. Me.

MERGE THIS!!!

NO DO NOT, YOU DONT KNOW IF THERES A BACKDOOR INSIDE OR NOT!!!

@NotAShelf
Copy link

If there is a backdoor, I would say it's in the scope of this PR given the... technology it deals with.

This should be merged immediately.

Copy link

@Dishpit Dishpit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the eight-space tabs make me want to go play in traffic

but otherwise: LGTM, merge it

@caatge
Copy link

caatge commented Jan 19, 2025

omg this should be merged rn

@TukanDev
Copy link

LGTM

ari no dont do this

I said what I said.
Looks. Good. To. Me.
MERGE THIS!!!

NO DO NOT, YOU DONT KNOW IF THERES A BACKDOOR INSIDE OR NOT!!!

Backdoor is a builtin feature of this PR like it or not, wouldnt you agree that randomly activating "bluetooth device" would be beneficial! You never know when its gonna give you some fun.

@BnDLett
Copy link

BnDLett commented Jan 19, 2025

merge this please

@aidendotgg
Copy link

I want my ass to rumble every time I catch a pokemon in pokemon white 2. please merge

@shadersrs3
Copy link

Same, please merge ASAP

@slxdy
Copy link

slxdy commented Jan 20, 2025

There is no way they actually took this PR seriously... The era we live in

@EvieYT
Copy link

EvieYT commented Jan 20, 2025

This must be merged immediately.

@BnDLett
Copy link

BnDLett commented Jan 20, 2025

There is no way they actually took this PR seriously... The era we live in

Do you not take the PR seriously?

@TruncatedDinoSour
Copy link

There is no way they actually took this PR seriously... The era we live in

Do you not take the PR seriously?

This pull request is one of the most important PRs in Panda3DS history and must be merged if we expect Panda3DS to outlive 2025. I do not see Panda3DS being able to go on without the important functionality this PR implements. It is a very urgent issue that needs to be resolved as soon as possible and I urge every developer all around the 2D frisbee to advocate for its merging.

@moonacutie
Copy link

moonacutie commented Jan 20, 2025

There is no way they actually took this PR seriously... The era we live in

Do you not take the PR seriously?

This pull request is one of the most important PRs in Panda3DS history

This is an understatement. It's the most important PR in the history of mankind.

@nitrog0d
Copy link

👽

@TukanDev
Copy link

👽

Oh hi nitro strange seeing you here

@CoopTRUE
Copy link

MERGE ASAP

@slxdy
Copy link

slxdy commented Jan 20, 2025

But in all seriousness, this really doesn't make sense. Wouldn't it be more acceptable to add support for plugins and THEN make it a third party plugin?
To give a fair comparison, imagine if Electron added official API for buttplugs, just because a random person decided to work on it.

@ReDestroyDeR
Copy link

But in all seriousness, this really doesn't make sense. Wouldn't it be more acceptable to add support for plugins and THEN make it a third party plugin? To give a fair comparison, imagine if Electron added official API for buttplugs, just because a random person decided to work on it.

electron adding native bp support seems legit 🤔

@slxdy
Copy link

slxdy commented Jan 21, 2025

Fck it. First one to make a ready PR for Electron adding buttplug API gets $50 on gh sponsors from me

@qdot
Copy link

qdot commented Jan 21, 2025

Fck it. First one to make a ready PR for Electron adding buttplug API gets $50 on gh sponsors from me

As the lead dev of buttplug and the ex device interfaces lead on Firefox I would just like to say:

lol

lmao

time to build out a spec and idl for my own protocol i guess

(That said I do agree with the "this would be better as a plugin" argument but I'm also not one to get in the way of a shitpost)

@Dishpit
Copy link

Dishpit commented Jan 21, 2025

Fck it. First one to make a ready PR for Electron adding buttplug API gets $50 on gh sponsors from me

i know what i have to do but idk if have the strength to do it

@NotReeceHarris
Copy link

can finally cheat at chess on 3ds with my butt plug

@Rawiros
Copy link

Rawiros commented Jan 21, 2025

this needs to be merged fr

@shuntia
Copy link

shuntia commented Jan 24, 2025

can finally cheat at chess on 3ds with my butt plug

you're still going to be a** if you get what I mean

Copy link

@bw8686 bw8686 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.