Description
This is a mod for Terraria (both tModloader and latest version). This adds in a WebSocket server that will send out messages at some events.
Setup - tModloader
Simple download the mod from Github and put it in the mods folder
win: C:/Users/%USERNAME%/Documents/My Games/Terraria/ModLoader/Mods
linux(Untested!): ~/. local/share/Terraria/ModLoader/Mods
Setup - Vanilla
- Download TerrariaInjector.exe.
- Download 0Harmony.dll and save the one from the
net35
folder. - Put both files into Terraria’s install folder (eg.
C:\Program Files (x86)\Steam\steamapps\common\Terraria
) - Run TerrariaInjector.exe once, it should make a
Mods
folder. - Download TerraSocket(for vanilla) here and put it into the
Mods
folder. - Download Newtonsoft.Json(the dll from
Json{version}.zip\bin\net40
) and websocket-sharp - add
Newtonsoft.Json.dll
andwebsocket-sharp.dll
intoTerraria\Mods\Libs
(create it, if it doesn’t exist).
Note regarding vanilla version, TerrariaInjector doesn’t modify Terraria.exe, so whenever you want to play with the websocket, run TerrariaInjector.exe
.
Connecting
The connection process is the same from both tModloader and vanilla version.
- start the game (either
tModloader.exe
orTerrariaInjcetor.exe
) and Streamer.bot. - Once the main menu has loaded, go to
Servers/Clients
→Websocket Clients
in Streamer.bot and add a client. The name doesn’t matter, but Endpoint is important by default it isws://127.0.0.1:7394/
(This can be changed). - Enjoy the game!
Configuring the endpoint/address
In the game’s install folder, there will be created a file called wsipconfig.json
that holds a string and a unsigned short(0-65535).
By default the file looks like this {"Host":"127.0.0.1","Port":7394}
, this will host the server at ws://127.0.0.1:7394/
. This file is read at startup/load, so change it before launching the game.
Usage
Simple open the game and connect. The websocket client(Streamer.Bot) will automatically get send messages. Remember to setup the actions for Connected
, Disconnected
and Message
(Import codes below).
Message needs be set to MessageHandler
When a message is received from TerraSocket, the action with same name as the event will get called, eg. if PlayerKilled
is sent then the action (under TerraSocketEvents) with the same name gets called.
Send commands to Terraria
TerraSocket supports 3 commands, that can be sent from Streamer.bot.
- KillPayer
- HealPlayer
- GiveItem
To send a command, you need to send a json string to the websocket server.
Important! Username
needs to populated(doesn’t need to be a username, just needs to be a string) and Command
needs to be one of the 3 commands. HealPlayer
needs to have HealAmount
populated as an int. The same with GiveItem
and ItemID
.
Kill player example:
using System;
public class CPHInline
{
public bool Execute()
{
string user = args["userName"].ToString();
string json = $"{{\"UserName\":\"{user}\",\"Command\":\"KillPlayer\"}}";
CPH.WebsocketSend(json,0);
return true;
}
}
Heal player example:
using System;
public class CPHInline
{
public bool Execute()
{
string user = args["userName"].ToString();
string json = $"{{\"UserName\":\"{user}\",\"Command\":\"HealPlayer\", \"HealAmount\":10}}";
CPH.WebsocketSend(json,0);
return true;
}
}
Give item example:
using System;
public class CPHInline
{
public bool Execute()
{
string user = args["userName"].ToString();
string json = $"{{\"UserName\":\"{user}\",\"Command\":\"GiveItem\", \"ItemID\":1}}";
CPH.WebsocketSend(json,0);
return true;
}
}
Events
Some events have different names or only exists in one of the versions.
tModloader
- PlayerKilled
- PlayerHit
- NPCKilled
- NPCHit
- OnEnterWorld
- OnRespawn
- PlayerConnect
- PlayerDisconnect
- PartyEvent
- SandstormEvent
- DD2Event
- PumpkinMoonEvent
- SnowMoonEvent
- BloodMoonEvent
- BossSpawn
- CultistRitualStarted
- MeteorLanded
- LunarApocalypseStarted
- SlimeRainEvent
- AnglerQuestReset
Vanilla
- AchievementCompleted
- PlayerHurt
- PlayerKilled
- NPCHit
- NPCKill
- BossSpawn
- CultistRitualStarted
- MeteorLanded
- LunarApocalypseStarted
- SlimeRainEvent
- AnglerQuestReset
- PetPat
- PartyEvent
- SandstormEvent
- DD2Event
- PumpkinMoonEvent
- SnowMoonEvent
- BloodMoonEvent
Json file from TerraSocket
Whenever an event is triggered in Terraria, TerraSocket will send out an json string/file to all connected clients.
This is a example json file, that will never be able to be sent, but it has all the values the json can have.
{
"webSocketServerVersion": { //This just tells you the version of TerraSocket, not that useful.
"majorVersion": 0,
"minorVersion": 0,
"patchVersion": 0
},
"event": "SomeEvent", //This is the Event, Example: "PlayerKilled".
"status": "Succes", //This isn't used for now, might use it later. Don't mind it.
"extraInfo": { //If an event is isn't events like "SandStormEvent" it will have extra/more info.
"player": "MyPlayer", //This will always be your player.
"eventinfo": "Some extra info like acheivement Name or pet name", //This is only used for acheivements and pat pet, tells you the names of each.
"playerDamage": { //This will only be sent when your player takes damage.
"playerName": "MyPlayer", //This will for now always be you player.
"pvp": false, // if true then the damage was from pvp, if not then it is other sources.
"quiet": false, // if the damage event/method was sent to the terraria server, eg. was the damage taken client or server sided. Not that useful.
"damage": 10.0, //The amount of damage taken.
"hitDirection": 0, // Binary way of telling which direction you took damage. -1 for left, 0 for up, down and center and 1 for right.
"crit": false, //false means that the damage wasn't a critical hit and so on.
"sourceType": "NPC", //This has four different types: NPC, PLAYER, PROJECTILE and NOTENTITY. NOTENTITY means that it is all other sources like fall damage. tModloader has MELEE too.
"sourceName": "Some Npc Name" //Holds the name of the npc/player/projectile of the type. Is null if it is NOTENTITY.
},
"npcDamage": { //This will only be sent when a npc takes damage from you/your player.
"npcName": "Some NPC name", //Holds the npc's name
"sourceType": "MELEE", //Can be either MELEE or PROJECTILE.
"sourceName": "Item name", //holds the name of the item or projectile.
"sourcePlayer": "MyPlayer", //your playername.
"npcLifePreHit": 100, //how much the npc had before it was hit.
"damageDealt": 20 //how much damage you dealt.
},
"npcKilled": { //This will only be sent when a npc was killed by you/from your player.
"npcName": "Another NPC name", //Holds the npc's name.
"sourceWithPrefix": "Godly item name", //Holds the item's full name, so prefixes included.
"sourceType": "MELEE", //This is only populated on tModloader version, because of how the event is triggered.
"sourceName": "Item name", //This is the item name.
"sourcePlayer": "MyPlayer", //This is your player name.
"npcLifePreHit": 200, //This is the Npc health before it was killed.
"damageDealt": 500, //This is how much damage it took, from your attack.
"overflowDamage": 300 //This is how much damage you dealt over the npc health.
},
"playerKilled": { //This will only be sent when your player is killed.
"playerName": "MyPlayer", //The player name of the killed player.
"sourceType": "NPC", //What killed your player, can be either NPC, PLAYER, PROJECTILE or NOTENTITY. tModloader has MELEE too.
"sourceName": "Yet Another Npc Name", //The name of the sourceType, will be null for NOTENTITY.
"playerLifePreHit": 20, //life before the killing blow.
"damageDealt": 30, //How much damage dealt to the player.
"overflowDamage": 10, //How much damage it was dealt over the player health.
"PVP": false //Will be true, if its pvp/sourceType is PLAYER.
},
"bossSpawn": { //This will only be sent when a boss is spawned.
"name": "Some Boss Name", //The name of the boss.
"lifepoints": 1000 //How much health the boss has.
}
}
}
Import codes
This will import two groups, TerraSocket
and TerraSocketEvents
, and 3 commands under the TerraSocket (Remember to enable them).
TlM0RR+LCAAAAAAABADtXVlz4ki2fp+I+Q916/W2OnLTNhHzYFaLsuRhFdKtechNIJCAYTGGif7v9whsF8Z4XHa5Z6hxVwS2UaZSJ8/2fSeVUv3zz3/69OnzjZ4v0unk818+kV92ByY81/Dtc0fP57w9lWO9/Lxv4XIJPRfQ+H/F90+f/rn/BU2pKk7BTpI4jHCD2wIbzKbSEFwpI3FN05QJQRYm+7F2J/1jpVe7S1GUmBJjbViIKINhIfYjJJJRblumKbB1cJ6ecJHp4orL+UofHL+V2Urp2nyaX6aL5XS+gS4JzxYHfe5ndyGHqb7RuZ4sy9N8luklDPit22A+Xc2OtFC9gc6Lg048W/PNorWaPL3MnE/UNL/YKexpq5xO5Go+h+Geth0o+e/HR+uFVMdNcpplfLbQ6qB13/jbL6fNRLCUtquVYTkWNRjCiSGQaRtaWtQWnILd2LmYaTLI9Ly50otlSy/uPfG/30SMKU5d5RiSJMxgjFmG4yTSMN0EbMcdRi3nTExUyqZT5U+nk53yP4qBbAzBoh2wDeIm/EhswwGTGaYlFRWcmJyoczHQdLFoz/h68lFsgxzKkKWFYTIiDebayuAmloarLaESi5m2bZ+JbcqrbAl9WulyxbP2ks8/EAxxC7mIysQAiiAMRm2wkGlzQ5hECEwVwuhcQqhSIR8quyFbWFbCpCEpcDjGpAkRJIVBOME2SgCc7HMxzdVqwucXs6nk2Qbm+MFiiApiEQo8gXFhGcwyIYZs4hhKMUZs26WOoGdiKF8vFnygL0GdQOleMNC/0TT3xw6U+0jub6LsDiu9kPN0dnfJ49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acuytZMoRV69TwA/c4Pjx4uPX96gmK/zr5OTlRcRliUwtQxIGFB+EYQMIS1scCokNR2OXPHqW1wMIfyekz+8w/V7V16EIO26lBjSKvby2ZIarouI4QhFE5uaFjrc13gegXs90y+tUp9p2E5B8h8IW7AGM8FMRAK/Z6bWhstMoCpMO6ZwLWJZ1k8atqcVc/egCIfqE3HHcDmCabuSQd6iyEiQa7vUdblrvnrr7U8RssWvfc993P2L/+TlleEoMlB7Ohk8H2yHsfRUHDnN86JQOCXQ/tb7UWigE0qZ6XmeLpdadRd6fqyWh8aTSttPOmEKYYmBb1BWPFJVbHcjQhvIdrmQQAkVPZ2DjuacTnZJ6ElyyvebYNChsXbzLi7+P4P0RqePHwPam9l7y+NNcjrN1HQ9ufg2xCNP/AwW43d56kCgdDCZznVpuvyWOh7PYVb8T0KLZblo1PNTSe6+AT05qbDLsyeuvjUW1vnnbwdj8kWxi2uRLk/tbvo8yKaCZ+W7CT++8n7UUy0vZPkB5PLl3X4P9Bzk/ftck2NNuANJStgJFJTC4gZ3ZfEKeG0RllDMOf39XHOoeTY73jt36Jyv3MH/h3P+VzknQ3aiqG0ZEkFFzZApDYG1bViKI2raVpLg39E5x2n2gnO+bsvqH875/s65g/o//+m3/websUmRjm4AAA==
Support
If you find any issues or need help, either ping me in Streamer.bit Extensions’ Discord or send me a private message ConfuzzedCat#5793
(note: I may only answer related message.)