automuteus / amonguscapture

Capture of the local Among Us executable state
MIT License
321 stars 92 forks source link

How to connect to capture application to get data? #91

Closed ryantheleach closed 3 years ago

ryantheleach commented 4 years ago

If I want to use this from a different application, (namely, a custom discord overlay for streaming) How can I hook into amonguscapture?

CarbonNeuron commented 4 years ago

You can "officially" hook into AmongUsCapture by creating a socketio server and just having capture connect to it in the manual connection page. You can do this in a plethora of languages. You can easily hook into the events in the capture program if you implement your own interface for the AmongUsCapture library. I show a basic example of implementing your own barebones interface in the console interface in the root of the repository. You would be looking to subscribe to the events in GameMemReader. You can get the current GameMemReader by doing GameMemReader.getInstance(); because GameMemReader is a singleton.

CarbonNeuron commented 4 years ago

Also if you are using OBS. There is a nice easy way to use websockets to control it. However you will need either a custom implementation, or a fork.

ryantheleach commented 4 years ago

Gotcha, Thanks I should be able to get something working with that.

sasuke37 commented 4 years ago

Hi guys,

I work to update my discord bot with among us.

Can i use it with node js / socketIO ? if yes, how?

Thanks

CarbonNeuron commented 4 years ago

You can use it with socket up but I'm kinda confused on what you're asking

sasuke37 commented 4 years ago

You sais "You can "officially" hook into AmongUsCapture by creating a socketio server", but i try somethings and i receive nothing on my socketIO server.

Is there a server (socket io) to connect my client or an api (web service) to request state of the game or the code of the game?

Sorry for my english, i'm french :'(

CarbonNeuron commented 4 years ago

to request state of the game or the code of the game? No. Currently that is not supported. You would need to make a socket io server and connect the capture to it.

sasuke37 commented 4 years ago

ok ok,

is this planned in a future version? Or write server and code game in log (CaptureLog.txt)

or how you get all informations game (state and code) ?

CarbonNeuron commented 4 years ago

This is a planned feature. Just not very high priority.

sasuke37 commented 4 years ago

Ok, if to add code game in log. Its ok, to wait an API. And i use log to get state 😀

CarbonNeuron commented 4 years ago

I guess if you want to parse the log file, be my guest.

sasuke37 commented 4 years ago

Yes i parse log, if you add code game.

Can write color in logs when we change ?

Have to hot server ? If yes can you write this ?

CarbonNeuron commented 4 years ago

Uhh... I'm kind of confused by your questions. I cannot write colors in the log file because it is a text file and does not support color.

sasuke37 commented 4 years ago

Yeah i know :( But can you right color (hex, rgb or texte) in bracket like this : sasuke37 : changedColor (blue)

But its not important to my bot, its only aesthetic ;)

CarbonNeuron commented 3 years ago

As per branch APIserver we now have a beta api for interfacing with capture. This is over websockets. The docs look like this:

Beta websocket API //server hosted on ws://localhost:42069/api Stream containing events that are sent to the server. They are in the format:

{ EventID : EventName {state = 0, player = 1, lobby = 2, gameover = 3} //The type of event EventData: string //String of the event object }

Event obj:

lobby: //Sent on lobby join
    Props:
        LobbyCode: str
        Region: PlayRegion { NorthAmerica = 0, Asia = 1, Europe = 2}

player: //Sent for each player. And on player change.
    Props:
        Action: PlayerAction {Joined, Left, Died, ChangedColor, ForceUpdated, Disconnected, Exiled}
        Name: str
        IsDead: bool
        Disconnected: bool
        Color: PlayerColor {Red = 0, Blue = 1, Green = 2, Pink = 3, Orange = 4, Yellow = 5, Black = 6, White = 7, Purple = 8, Brown = 9, Cyan = 10, Lime = 11}

state: //Sent on phase change.
    Props:
        NewState: GameState {LOBBY, TASKS, DISCUSSION, MENU, UNKNOWN}

connectCode: //Sent on connect and each reconnect.
    str

botID: //Sent only if the capture has a discord bot linked to it. (Shhh. Beta)
    ulong
ryantheleach commented 3 years ago

One thing missing that I'd need for my stuff is the order of the players, as listed on the meeting screen.

CarbonNeuron commented 3 years ago

We don't have that data. But it is probably just alphabetical or something

ryantheleach commented 3 years ago

I really wish it were, but it's the order the players join the lobby, with all dead and disconnected at the time the button was hit listed in the same order, but after the alive players. if someone disconnects mid-meeting the order doesn't change, if someone is killed just before the meeting, they remain with the alive players but render as dead and can not vote, making it possible for a dead player to call a meeting due to race conditions. It's impossible to recreate accurately, without grabbing the array of players.

CarbonNeuron commented 3 years ago

Sounds overly complicated. What do you need it for?

sasuke37 commented 3 years ago

Thanks, I go try this with my bot :)

But where we download beta to try this 😢

ryantheleach commented 3 years ago

I want to create a on-stream overlay, that shows who is talking in discord, next to the characters who are talking, to better visualize meetings for newer stream viewers that do not yet know whose voices belong to which characters.

While it's currently possible to do this with the standard discord overlay, it's quite messy to have the names listed twice, not to mention management of peoples names matching their voice names.

CarbonNeuron commented 3 years ago

I'm sorry but short of writing your overlay for you, there's not much we can do. Capture doesn't have access to which user you link to in discord.

ryantheleach commented 3 years ago

I can come up with a solution for that. I was asked why I wanted the order of the meeting names.

saiashish90 commented 3 years ago

As per branch APIserver we now have a beta api for interfacing with capture. This is over websockets. The docs look like this:

Beta websocket API //server hosted on ws://localhost:42069/api Stream containing events that are sent to the server. They are in the format:

{ EventID : EventName {state = 0, player = 1, lobby = 2, gameover = 3} //The type of event EventData: string //String of the event object }

Event obj:

lobby: //Sent on lobby join
    Props:
        LobbyCode: str
        Region: PlayRegion { NorthAmerica = 0, Asia = 1, Europe = 2}

player: //Sent for each player. And on player change.
    Props:
        Action: PlayerAction {Joined, Left, Died, ChangedColor, ForceUpdated, Disconnected, Exiled}
        Name: str
        IsDead: bool
        Disconnected: bool
        Color: PlayerColor {Red = 0, Blue = 1, Green = 2, Pink = 3, Orange = 4, Yellow = 5, Black = 6, White = 7, Purple = 8, Brown = 9, Cyan = 10, Lime = 11}

state: //Sent on phase change.
    Props:
        NewState: GameState {LOBBY, TASKS, DISCUSSION, MENU, UNKNOWN}

connectCode: //Sent on connect and each reconnect.
    str

botID: //Sent only if the capture has a discord bot linked to it. (Shhh. Beta)
    ulong

when will you release the compiled exe file for this branch?

saiashish90 commented 3 years ago

You can "officially" hook into AmongUsCapture by creating a socketio server and just having capture connect to it in the manual connection page. You can do this in a plethora of languages. You can easily hook into the events in the capture program if you implement your own interface for the AmongUsCapture library. I show a basic example of implementing your own barebones interface in the console interface in the root of the repository. You would be looking to subscribe to the events in GameMemReader. You can get the current GameMemReader by doing GameMemReader.getInstance(); because GameMemReader is a singleton.

My python socket io program says that it has received a connection. but the amonguscapture says attempting to connect and then just throws an exception. Do I need to send something from my socketio server for the AUcapture application to get connected.

CarbonNeuron commented 3 years ago

You need to make sure you are using SocketIO and not websockets. There may need to be some code modification done to allow clients that are > v3 of socketIO.

sasuke37 commented 3 years ago

Thanks for update 👍

sasuke37 commented 3 years ago

I have some problem/update with it :

Can you send all game info when we connect to websocket ? You dont update "Disconnected" key, when player leave lobby.

CarbonNeuron commented 3 years ago

https://github.com/CarbonNeuron/AUCapture-Server-Example/ Here is an example of how to make your own socketio server for the capture client. (Along with the types)

CarbonNeuron commented 3 years ago

I have some problem/update with it :

Can you send all game info when we connect to websocket ? You dont update "Disconnected" key, when player leave lobby.

We should be sending a player update with a player action of 5(Disconnected). It shouldn't be too hard to make it rebroadcast data on connect.

saiashish90 commented 3 years ago

https://github.com/CarbonNeuron/AUCapture-Server-Example/ Here is an example of how to make your own socketio server for the capture client. (Along with the types)

Thank you so much for this. Was exactly what I needed, I was using discord.py, but discord.js is so much better for things like this so I switched. Also are you considering making this a REST API so we get all the information everytime an event occurs instead of event specific contextual data.

CarbonNeuron commented 3 years ago

No probably not

gifumaster commented 3 years ago

This api sent kill message before report? (tested in freeplay) I want to use this api for obs , but can also use for cheat.

CarbonNeuron commented 3 years ago

Yes because it is a direct translation of the packets sent to server.

p-ham commented 3 years ago

@CarbonNeuron I tried your example, but couldn't get it to output anything. I tried changing the port to 42069, because AUCapture uses that port, but it still didn't work. Could you give me a pointer? Not sure what I'm doing wrong.

CarbonNeuron commented 3 years ago

My example is not showing off the api, it is showing how to emulate a server like how the auto mute us bot is doing

CarbonNeuron commented 3 years ago

If you want to use the api server, turn it on in settings under general.

sasuke37 commented 3 years ago

Can you add, in websocket, an event when we complete or fail tasks ?

If you have player's coordonate, can you emit an event ? Please 😀

saiashish90 commented 3 years ago

@CarbonNeuron I tried your example, but couldn't get it to output anything. I tried changing the port to 42069, because AUCapture uses that port, but it still didn't work. Could you give me a pointer? Not sure what I'm doing wrong.

If you want to use the socket.io connection that @CarbonNeuron has shown in his example. I implemented it in my discord bot, you can look at that or raise an issue there and I can help you. The repo is called Matt.js. If you want to use the API sever then you will need to enable it in the settings and then use websockets to connect to it.

CarbonNeuron commented 3 years ago

Can you add, in websocket, an event when we complete or fail tasks ?

If you have player's coordonate, can you emit an event ? Please 😀

No. This could be used for cheating. I will be closing this issue and future questions should make a new issue