├── Libraries ├── LuaInterface.dll ├── Mono.Cecil.dll ├── System.Data.SQLite.DLL ├── System.Data.SQLite.Linq.DLL ├── lua51.dll ├── tMod_v3.Database.SqlServerCe.dll └── tMod_v3.Database.dll ├── README ├── tMod v2.sln ├── tMod v2.suo └── tMod v2 ├── Configuration.cs ├── Database.cs ├── Edit.cs ├── Events ├── .svn │ ├── entries │ └── text-base │ │ ├── AvatarPacketReceivedEventArgs.cs.svn-base │ │ ├── CancelableEventArgs.cs.svn-base │ │ ├── ChangeTilePacketReceivedEventArgs.cs.svn-base │ │ ├── CommandReceivedEventArgs.cs.svn-base │ │ ├── ConfigLoadedEventArgs.cs.svn-base │ │ ├── DisconnectPacketReceivedEventArgs.cs.svn-base │ │ ├── DoorChangedEventArgs.cs.svn-base │ │ ├── PacketReceivedEventArgs.cs.svn-base │ │ ├── SetLiquidEventArgs.cs.svn-base │ │ ├── SetLiquidPacketReceivedEventArgs.cs.svn-base │ │ ├── TileChangedEventArgs.cs.svn-base │ │ └── UpdateKeyboardEventArgs.cs.svn-base ├── AvatarPacketReceivedEventArgs.cs ├── CancelableEventArgs.cs ├── ChangeTilePacketReceivedEventArgs.cs ├── CommandReceivedEventArgs.cs ├── ConfigLoadedEventArgs.cs ├── DisconnectPacketReceivedEventArgs.cs ├── DoorChangedEventArgs.cs ├── PacketReceivedEventArgs.cs ├── SetLiquidEventArgs.cs ├── SetLiquidPacketReceivedEventArgs.cs ├── TileChangedEventArgs.cs └── UpdateKeyboardEventArgs.cs ├── General.cs ├── Groups.cs ├── Lua ├── LuaInterface.dll ├── lua51.dll └── lua511.dll ├── LuaAddons ├── LuaAddon.cs └── LuaHandler.cs ├── PacketTypes.cs ├── Plugins ├── Plugin.cs └── PluginManager.cs ├── Program.cs ├── Properties ├── AssemblyInfo.cs ├── Settings.Designer.cs └── Settings.settings ├── PropertiesFile.cs ├── Rgb.cs ├── ServerCommandHandler.cs ├── Session.cs ├── StringExtension.cs ├── Terraria ├── ItemMod.cs ├── MainMod.Reflection.cs ├── MainMod.cs ├── MessageBufferMod.cs ├── NPCMod.cs ├── NetMessageMod.cs ├── NetplayMod.cs ├── Program.cs ├── ProjectileMod.cs └── WorldGenMod.cs ├── app.config ├── bin ├── Release │ ├── Config.xml │ ├── Configure.bat │ ├── Database.s3db │ ├── Groups.xml │ ├── LuaInterface.dll │ ├── Mono.Cecil.dll │ ├── System.Data.SQLite.dll │ ├── TerrariaServer.exe │ ├── lua │ │ └── core │ │ │ └── hook.lua │ ├── lua51.dll │ ├── tMod v3.exe.config │ ├── tMod v3.pdb │ ├── tMod v3.vshost.exe │ ├── tMod v3.vshost.exe.config │ ├── tMod v3.vshost.exe.manifest │ └── tMod v3.zip └── x86 │ └── tMod Config │ ├── tMod v3.exe.config │ ├── tMod v3.vshost.exe │ └── tMod v3.vshost.exe.config ├── obj └── x86 │ ├── Debug │ ├── DesignTimeResolveAssemblyReferences.cache │ ├── DesignTimeResolveAssemblyReferencesInput.cache │ ├── GenerateResource.read.1.tlog │ ├── GenerateResource.write.1.tlog │ ├── ResolveAssemblyReference.cache │ ├── TempPE │ │ └── Resources.Files.DatabaseDataSet.Designer.cs.dll │ ├── tMod v2.csproj.FileListAbsolute.txt │ ├── tMod v2.exe │ ├── tMod v2.g.resources │ ├── tMod v2.pdb │ ├── tMod v3.csproj.FileListAbsolute.txt │ ├── tMod v3.exe │ ├── tMod v3.g.resources │ ├── tMod v3.pdb │ ├── tMod_v2.Resources.Default.resources │ └── tMod_v3.Resources.Default.resources │ ├── Release │ ├── DesignTimeResolveAssemblyReferences.cache │ ├── DesignTimeResolveAssemblyReferencesInput.cache │ ├── ResolveAssemblyReference.cache │ ├── TempPE │ │ └── Resources.Files.DatabaseDataSet.Designer.cs.dll │ ├── tMod v2.csproj.FileListAbsolute.txt │ ├── tMod v3.csproj.FileListAbsolute.txt │ ├── tMod v3.exe │ └── tMod v3.pdb │ └── tMod Config │ ├── DesignTimeResolveAssemblyReferencesInput.cache │ └── tMod v3.csproj.FileListAbsolute.txt ├── tMod v2.csproj ├── tMod v2.csproj.user ├── tMod v3.csproj ├── tMod v3.csproj.user └── tMod.cs /Libraries/LuaInterface.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/Libraries/LuaInterface.dll -------------------------------------------------------------------------------- /Libraries/Mono.Cecil.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/Libraries/Mono.Cecil.dll -------------------------------------------------------------------------------- /Libraries/System.Data.SQLite.DLL: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/Libraries/System.Data.SQLite.DLL -------------------------------------------------------------------------------- /Libraries/System.Data.SQLite.Linq.DLL: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/Libraries/System.Data.SQLite.Linq.DLL -------------------------------------------------------------------------------- /Libraries/lua51.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/Libraries/lua51.dll -------------------------------------------------------------------------------- /Libraries/tMod_v3.Database.SqlServerCe.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/Libraries/tMod_v3.Database.SqlServerCe.dll -------------------------------------------------------------------------------- /Libraries/tMod_v3.Database.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/Libraries/tMod_v3.Database.dll -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | tMod v3, contrary to what the directories say. 2 | 3 | Please, don't rip this off and claim it as your own! I'm releasing this code so you can contribute to the mod, not so you can steal it. That's all you have permission to use it for. However, you're welcome to read it and learn from it as long as you don't copy and paste it. 4 | 5 | Sorry if some of it's a mess, I didn't clean it. A lot of it is from tMod v2. The directories say tMod v2 because it was tMod v2 until the merge... Meh, it's complicated. Not really but... whatever! 6 | 7 | Changelog: 8 | 9 | 003: 10 | Various bugfixes 11 | Autoupdate feature 12 | 13 | ======= 14 | 002: 15 | Fixed some... stuff... 16 | 17 | ======= 18 | 001: 19 | Initial Commit -------------------------------------------------------------------------------- /tMod v2.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual C# Express 2010 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "tMod v3", "tMod v2\tMod v3.csproj", "{8535C7E2-C7C7-4363-B186-9D2FE5CD99E0}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|x86 = Debug|x86 9 | Release|x86 = Release|x86 10 | tMod Config|x86 = tMod Config|x86 11 | EndGlobalSection 12 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 13 | {8535C7E2-C7C7-4363-B186-9D2FE5CD99E0}.Debug|x86.ActiveCfg = Debug|x86 14 | {8535C7E2-C7C7-4363-B186-9D2FE5CD99E0}.Debug|x86.Build.0 = Debug|x86 15 | {8535C7E2-C7C7-4363-B186-9D2FE5CD99E0}.Release|x86.ActiveCfg = Release|x86 16 | {8535C7E2-C7C7-4363-B186-9D2FE5CD99E0}.Release|x86.Build.0 = Release|x86 17 | {8535C7E2-C7C7-4363-B186-9D2FE5CD99E0}.tMod Config|x86.ActiveCfg = tMod Config|x86 18 | {8535C7E2-C7C7-4363-B186-9D2FE5CD99E0}.tMod Config|x86.Build.0 = tMod Config|x86 19 | EndGlobalSection 20 | GlobalSection(SolutionProperties) = preSolution 21 | HideSolutionNode = FALSE 22 | EndGlobalSection 23 | EndGlobal 24 | -------------------------------------------------------------------------------- /tMod v2.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/tMod v2.suo -------------------------------------------------------------------------------- /tMod v2/Configuration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Collections.Specialized; 6 | 7 | namespace tMod_v3 8 | { 9 | [Serializable] 10 | public class Configuration 11 | { 12 | public bool AsyncMod = true; 13 | public string BindAddress = "0.0.0.0"; 14 | public int BindPort = 7777; 15 | public int PlayerSlots = 100; 16 | public bool CheckForUpdates = true; 17 | public string WorldPath = "world1.wld"; 18 | public string Database = @"%CD%\tMod\Database.sdf"; 19 | public string ServerPassword = ""; 20 | public string MOTD = "Welcome to a tMod powered server!"; 21 | public bool RequireAlphaNumericName = true; 22 | public bool RequireHardcoreCharacter = false; 23 | public bool EnableRollbackTrimming = true; 24 | public bool AutomaticallyTrimRollbacks = false; 25 | public int MaximumRollbackEntries = 10000000; 26 | public bool AllowMassDestruction = false; 27 | public bool KickMassDestruction = false; 28 | public bool BanMassDestruction = false; 29 | public int MassDestructionSensitivity = 20; 30 | public bool AllowMassConstruction = false; 31 | public bool KickMassConstruction = false; 32 | public bool BanMassConstruction = false; 33 | public int MassConstructionSensitivity = 5; 34 | public bool UseBuiltInAntiSpam = true; 35 | public bool AllowExplosives = false; 36 | public bool KickExplosives = true; 37 | public bool AllowConstruction = true; 38 | public bool AllowDestruction = true; 39 | public bool AllowLava = true; 40 | public bool AllowWater = true; 41 | public bool AllowSpikes = true; 42 | public bool AllowSpawnNpcs = false; 43 | public bool AllowChest = true; 44 | public bool AllowSignEditing = true; 45 | public bool AllowPlayerItemDropping = true; 46 | public bool KickHealthHack = true; 47 | public bool KickManaHack = true; 48 | public bool KickItemStackHack = true; 49 | public bool KickDamageHack = true; 50 | public bool KickSpawnNpc = true; 51 | public bool KickInvalidTileEdits = true; 52 | public bool KickLiquidHack = true; 53 | public bool KickSendTileSquareHack = true; 54 | //public bool KickTeleportHack = false; 55 | //public bool KickSpeedHack = false; 56 | //public bool KickNoClipHack = false; 57 | //public bool KickMiscHack = false; 58 | //public bool KickAvatarHack = false; 59 | //public bool KickRangeHack = false; 60 | //public bool DisallowTModClientCheating = false; 61 | public bool BlockRegistration = false; 62 | public bool RequireRegistration = false; 63 | public bool RequireRegistrationForChat = false; 64 | public bool RequireRegistrationForDoors = false; 65 | //public bool RequireNewCharacterAlways = false; 66 | public bool Peaceful = false; 67 | //public bool InfiniteInvasion = false; 68 | public bool AdvertEnabled = true; 69 | //public int ServerTime = -1; 70 | //public bool FreezeTime = false; 71 | public int MaximumSpawns = 4; 72 | public int SpawnRate = 700; 73 | public string PluginDirectory = @"tMod\Plugins"; 74 | public string PluginDataDirectory = @"tMod\Plugins\Data"; 75 | public StringCollection Plugins = new StringCollection(); 76 | public StringCollection Ops = new StringCollection(); 77 | public StringCollection Mods = new StringCollection(); 78 | public StringCollection AlternativePasswords = new StringCollection(); 79 | public bool ShowKickNotifications = true; 80 | public bool ShowBanNotifications = true; 81 | public bool AllowRegistrationPasswordForServerPassword = false; 82 | public dynamic RequireNewCharacterIfNotRegistered = false; 83 | public dynamic RequireNewCharacterAlways = false; 84 | public bool ShowNPCNotifications = true; 85 | public int SpawnProtectionRadius = 0; 86 | public bool KickAvatarRenameHack = true; 87 | public bool KickImpersonatingName = true; 88 | public bool KickInvalidName = true; 89 | public bool KickSpikeHack = true; 90 | public string OpMePassword = "Disabled"; 91 | public bool ForceChatColors = true; 92 | public bool ColorOpChat = true; 93 | public bool ColorModChat = true; 94 | public Rgb OpColor = new Rgb(175, 75, 0xff); 95 | public Rgb ModColor = new Rgb(25, 175, 0); 96 | public Rgb MemberColor = new Rgb(0xff); 97 | public Rgb GuestColor = new Rgb(0xbb); 98 | public bool AllowAbove150Damage = false; 99 | public bool ShowOpMeNotifications = true; 100 | public bool BlockSendTileSquare = true; 101 | public bool BlockRangeHack = true; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /tMod v2/Database.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Data.SQLite; 6 | using System.IO; 7 | using System.Reflection; 8 | using System.Threading; 9 | using System.Security.Cryptography; 10 | using Terraria; 11 | 12 | namespace tMod_v3 13 | { 14 | public static class Database 15 | { 16 | private static SQLiteConnection Sql; 17 | private static Thread TrimThread; 18 | private static volatile bool PerformTrim = false; 19 | private static SHA512 Hash = SHA512.Create(); 20 | 21 | public static void Initialize() 22 | { 23 | Connect(); 24 | Update(); 25 | if (MainMod.Config.EnableRollbackTrimming) 26 | { 27 | StartTrim(); 28 | } 29 | } 30 | 31 | private static void Execute(string query, params SQLiteParameter[] param) 32 | { 33 | using (SQLiteCommand cmd = Sql.CreateCommand()) 34 | { 35 | cmd.CommandText = query; 36 | cmd.Parameters.AddRange(param); 37 | cmd.ExecuteNonQuery(); 38 | } 39 | } 40 | 41 | private static T ExecuteScalar(string query, params SQLiteParameter[] param) 42 | { 43 | using (SQLiteCommand cmd = Sql.CreateCommand()) 44 | { 45 | cmd.CommandText = query; 46 | cmd.Parameters.AddRange(param); 47 | return (T)cmd.ExecuteScalar(); 48 | } 49 | } 50 | 51 | private static SQLiteDataReader ExecuteResultSet(string query, params SQLiteParameter[] param) 52 | { 53 | using (SQLiteCommand cmd = Sql.CreateCommand()) 54 | { 55 | cmd.CommandText = query; 56 | cmd.Parameters.AddRange(param); 57 | return cmd.ExecuteReader(); 58 | } 59 | } 60 | 61 | private static void StartTrim() 62 | { 63 | TrimThread = new Thread(TrimLoop); 64 | TrimThread.IsBackground = true; 65 | TrimThread.Start(); 66 | } 67 | 68 | private static void TrimLoop() 69 | { 70 | while (true) 71 | { 72 | if (PerformTrim || MainMod.Config.AutomaticallyTrimRollbacks) 73 | { 74 | Trim(); 75 | } 76 | Thread.Sleep(1000); 77 | } 78 | } 79 | 80 | public static string Password(string pwd) 81 | { 82 | return BitConverter.ToString(Hash.ComputeHash(ASCIIEncoding.ASCII.GetBytes(pwd))).Replace("-", ""); 83 | } 84 | 85 | private static void CreateTable(string table, params string[] fields) 86 | { 87 | try 88 | { 89 | using (SQLiteCommand cmd = Sql.CreateCommand()) 90 | { 91 | cmd.CommandText = "CREATE TABLE " + table + " (" + string.Join(", ", fields) + ")"; 92 | cmd.ExecuteNonQuery(); 93 | } 94 | } 95 | catch 96 | { 97 | Console.WriteLine("Table {0} already exists.", table); 98 | } 99 | } 100 | 101 | private static void RequireTable(string table, params string[] fields) 102 | { 103 | Console.WriteLine("Verifying that table exists: {0}", table); 104 | CreateTable(table, fields); 105 | } 106 | 107 | private static void Update() 108 | { 109 | RequireTable("Users", 110 | "UserId INTEGER PRIMARY KEY", 111 | "Username nvarchar(1000) UNIQUE NOT NULL", 112 | "Password nvarchar(1024) NOT NULL", 113 | "LastIp nvarchar(15) NULL", 114 | "GroupName nvchar(1024) NULL"); 115 | RequireTable("Warps", 116 | "WarpId INTEGER PRIMARY KEY", 117 | "WarpName nvarchar(1000) UNIQUE NOT NULL", 118 | "WarpX int NOT NULL", 119 | "WarpY int NULL"); 120 | RequireTable("Sessions", 121 | "SessionId INTEGER PRIMARY KEY", 122 | "Username nvarchar(1000) NOT NULL", 123 | "IpAddress nvarchar(15) NULL"); 124 | RequireTable("TileEdits", 125 | "EditId INTEGER PRIMARY KEY", 126 | "SessionID int NOT NULL", 127 | "X int NOT NULL", 128 | "Y int NOT NULL", 129 | "Action tinyint NOT NULL", 130 | "Type tinyint NOT NULL"); 131 | Console.WriteLine("Checking Users table contains GroupName column..."); 132 | try 133 | { 134 | using (SQLiteCommand cmd = Sql.CreateCommand()) 135 | { 136 | cmd.CommandText = "SELECT GroupName FROM Users WHERE 1=1"; 137 | cmd.ExecuteScalar(); 138 | } 139 | } 140 | catch 141 | { 142 | Console.WriteLine("GroupName table doesn't exist... adding..."); 143 | using (SQLiteCommand cmd = Sql.CreateCommand()) 144 | { 145 | cmd.CommandText = "ALTER TABLE Users ADD GroupName nvarchar(1024) NULL"; 146 | cmd.ExecuteNonQuery(); 147 | } 148 | Thread.Sleep(5000); 149 | } 150 | } 151 | 152 | private static void Connect() 153 | { 154 | Sql = new SQLiteConnection("Data Source = Database.s3db"); 155 | Sql.Open(); 156 | } 157 | 158 | public static void Disconnect() 159 | { 160 | Sql.Close(); 161 | } 162 | 163 | public static bool WarpExists(string warp) 164 | { 165 | using (SQLiteCommand cmd = Sql.CreateCommand()) 166 | { 167 | cmd.CommandText = "SELECT WarpId FROM Warps WHERE WarpName=@Warp"; 168 | cmd.Parameters.Add(new SQLiteParameter("@Warp", warp)); 169 | if (cmd.ExecuteScalar() == null) return false; 170 | } 171 | return true; 172 | } 173 | 174 | public static int[] GetWarp(string warp) 175 | { 176 | using (SQLiteCommand cmd = Sql.CreateCommand()) 177 | { 178 | cmd.CommandText = "SELECT * FROM Warps WHERE WarpName=@Warp"; 179 | cmd.Parameters.Add(new SQLiteParameter("@Warp", warp)); 180 | using (SQLiteDataReader results = cmd.ExecuteReader()) 181 | { 182 | if (results.Read()) 183 | { 184 | int[] XandY = { (int)results["WarpX"], (int)results["WarpY"] }; 185 | return XandY; 186 | } 187 | } 188 | } 189 | throw new Exception("Error with warp SQL"); 190 | } 191 | 192 | public static void SetWarp(string warp, int x, int y) 193 | { 194 | using (SQLiteCommand cmd = Sql.CreateCommand()) 195 | { 196 | cmd.CommandText = "INSERT OR REPLACE INTO Warps (WarpId, WarpName, WarpX, WarpY) VALUES (NULL, @WarpName, @WarpX, @WarpY)"; 197 | cmd.Parameters.Add(new SQLiteParameter("WarpName", warp)); 198 | cmd.Parameters.Add(new SQLiteParameter("WarpX", x)); 199 | cmd.Parameters.Add(new SQLiteParameter("WarpY", y)); 200 | cmd.ExecuteNonQuery(); 201 | } 202 | } 203 | 204 | public static bool IsUserRegistered(string username) 205 | { 206 | using (SQLiteCommand cmd = Sql.CreateCommand()) 207 | { 208 | cmd.CommandText = "SELECT UserId FROM Users WHERE Username=@Username"; 209 | cmd.Parameters.Add(new SQLiteParameter("@Username", username)); 210 | if (cmd.ExecuteScalar() == null) return false; 211 | } 212 | return true; 213 | } 214 | 215 | public static void ChangeUserPassword(string username, string hash) 216 | { 217 | using (SQLiteCommand cmd = Sql.CreateCommand()) 218 | { 219 | cmd.CommandText = "UPDATE Users SET Password=@Password WHERE Username=@Username"; 220 | cmd.Parameters.Add(new SQLiteParameter("Username", username)); 221 | cmd.Parameters.Add(new SQLiteParameter("Password", hash)); 222 | cmd.ExecuteNonQuery(); 223 | } 224 | } 225 | 226 | public static void InsertRegistration(int userid, string hash) 227 | { 228 | using (SQLiteCommand cmd = Sql.CreateCommand()) 229 | { 230 | cmd.CommandText = "INSERT OR REPLACE INTO Users (UserId, Username, Password, LastIp) VALUES (NULL, @Username, @Password, @LastIp)"; 231 | cmd.Parameters.Add(new SQLiteParameter("Username", MainMod.Player[userid].name)); 232 | cmd.Parameters.Add(new SQLiteParameter("Password", hash)); 233 | cmd.Parameters.Add(new SQLiteParameter("LastIp", Session.Sessions[userid].IpAddress)); 234 | cmd.Parameters.Add(new SQLiteParameter("Group", Session.Sessions[userid].Group.GroupName)); 235 | cmd.ExecuteNonQuery(); 236 | } 237 | } 238 | 239 | public static void DeleteRegistration(string username) 240 | { 241 | using (SQLiteCommand cmd = Sql.CreateCommand()) 242 | { 243 | cmd.CommandText = "DELETE FROM Users WHERE Username=@Username"; 244 | cmd.Parameters.Add(new SQLiteParameter("Username", username)); 245 | cmd.ExecuteNonQuery(); 246 | } 247 | } 248 | 249 | public static string GetUserGroup(string username) 250 | { 251 | // this prick admined himself on a load of servers under this name due to me forgetting an if statement somewhere. 252 | // It wasn't a complete vulnerability since servers just left the opme password as "Disabled." >_> 253 | // Might seem harsh, it isn't. 254 | if (username.ToLower() == "maxmememax" || username.ToLower() == "smd") 255 | { 256 | return "Default"; 257 | } 258 | using (SQLiteCommand cmd = Sql.CreateCommand()) 259 | { 260 | cmd.CommandText = "SELECT GroupName FROM Users WHERE Username=@Username"; 261 | cmd.Parameters.Add(new SQLiteParameter("@Username", username)); 262 | using (SQLiteDataReader results = cmd.ExecuteReader()) 263 | { 264 | if (results.Read()) 265 | { 266 | if (results["GroupName"] == null) 267 | return "Default"; 268 | try // quickfix 269 | { 270 | string Group = (string)results["GroupName"]; 271 | if (Group != null) return Group; 272 | } 273 | catch 274 | { 275 | return "Default"; 276 | } 277 | } 278 | } 279 | } 280 | return "Default"; 281 | } 282 | 283 | public static void SetUserGroup(string username, string group) 284 | { 285 | using (SQLiteCommand cmd = Sql.CreateCommand()) 286 | { 287 | cmd.CommandText = "UPDATE Users SET GroupName=@Group WHERE Username=@Username"; 288 | cmd.Parameters.Add(new SQLiteParameter("Username", username)); 289 | cmd.Parameters.Add(new SQLiteParameter("Group", group)); 290 | cmd.ExecuteNonQuery(); 291 | } 292 | } 293 | 294 | public static int CheckLogin(string username, string hash) 295 | { 296 | using (SQLiteCommand cmd = Sql.CreateCommand()) 297 | { 298 | cmd.CommandText = "SELECT * FROM Users WHERE Username=@Username"; 299 | cmd.Parameters.Add(new SQLiteParameter("@Username", username)); 300 | using (SQLiteDataReader results = cmd.ExecuteReader()) 301 | { 302 | if (results.Read()) 303 | { 304 | string dbPass = (string)results["Password"]; 305 | if (dbPass == hash) 306 | { 307 | Console.WriteLine(results["UserId"].GetType()); 308 | return (int)(long)results["UserId"]; 309 | } 310 | } 311 | } 312 | } 313 | return -1; 314 | } 315 | 316 | public static int InsertSession(string username, string ip) 317 | { 318 | using (SQLiteCommand cmd = Sql.CreateCommand()) 319 | { 320 | cmd.CommandText = "INSERT OR REPLACE INTO Sessions (SessionId, Username, IpAddress) VALUES (NULL, @Username, @IpAddress)"; 321 | cmd.Parameters.Add(new SQLiteParameter("Username", username)); 322 | cmd.Parameters.Add(new SQLiteParameter("IpAddress", ip)); 323 | cmd.ExecuteNonQuery(); 324 | } 325 | using (SQLiteCommand cmd = Sql.CreateCommand()) 326 | { 327 | cmd.CommandText = "SELECT last_insert_rowid()"; 328 | return (int)(long)cmd.ExecuteScalar(); 329 | } 330 | } 331 | 332 | public static void InsertEdit(int session, byte action, byte type, int x, int y) 333 | { 334 | if (MainMod.Config.AsyncMode) ThreadPool.QueueUserWorkItem(delegate { InsertEditAsync(session, action, type, x, y); }); 335 | else InsertEditAsync(session, action, type, x, y); 336 | } 337 | 338 | private static object insertEdit = new object(); 339 | 340 | public static void InsertEditAsync(int session, byte action, byte type, int x, int y) 341 | { 342 | lock (insertEdit) 343 | using (SQLiteCommand cmd = Sql.CreateCommand()) 344 | { 345 | cmd.CommandText = "INSERT OR REPLACE INTO TileEdits (EditId, SessionId, Action, Type, X, Y) VALUES (NULL, @SessionId, @Action, @Type, @X, @Y)"; 346 | cmd.Parameters.Add(new SQLiteParameter("@SessionId", session)); 347 | cmd.Parameters.Add(new SQLiteParameter("@Action", action)); 348 | cmd.Parameters.Add(new SQLiteParameter("@Type", type)); 349 | cmd.Parameters.Add(new SQLiteParameter("@X", x)); 350 | cmd.Parameters.Add(new SQLiteParameter("@Y", y)); 351 | cmd.ExecuteNonQuery(); 352 | } 353 | } 354 | 355 | public static void Trim() 356 | { 357 | Execute("DELETE FROM TileEdits WHERE EditId NOT IN (SELECT TOP(@Maximum) EditId FROM TileEdits)", new SQLiteParameter("Maximum", MainMod.Config.MaximumRollbackEntries)); 358 | } 359 | 360 | private static object rollback = new object(); 361 | 362 | public static void Rollback(int caller, string username) 363 | { 364 | if (MainMod.Config.AsyncMode) ThreadPool.QueueUserWorkItem(delegate { RollbackAsync(caller, username); }); 365 | else RollbackAsync(caller, username); 366 | } 367 | 368 | public static void RollbackAsync(int caller, string username) 369 | { 370 | NetMessageMod.BroadcastMessage("Starting player rollback, server may lag for a moment."); 371 | List edits = new List(); 372 | using (SQLiteCommand cmd = Sql.CreateCommand()) 373 | { 374 | cmd.CommandText = "SELECT * FROM TileEdits WHERE SessionId IN (SELECT SessionId FROM Sessions WHERE Username=@Username) ORDER BY EditId DESC"; 375 | cmd.Parameters.Add(new SQLiteParameter("Username", username)); 376 | using (SQLiteDataReader results = cmd.ExecuteReader()) 377 | while (results.Read()) 378 | edits.Add(new Edit 379 | { 380 | SessionId = (int)results["SessionId"], 381 | X = (int)results["X"], 382 | Y = (int)results["Y"], 383 | Action = (byte)results["Action"], 384 | Type = (byte)results["Type"] 385 | }); 386 | } 387 | int retval = edits.Count; 388 | foreach (Edit e in edits) e.Rollback(); 389 | using (SQLiteCommand cmd = Sql.CreateCommand()) 390 | { 391 | cmd.CommandText = "DELETE FROM TileEdits WHERE SessionId IN (SELECT SessionId FROM Sessions WHERE Username=@Username)"; 392 | cmd.Parameters.Add(new SQLiteParameter("Username", username)); 393 | cmd.ExecuteNonQuery(); 394 | } 395 | NetMessageMod.BroadcastMessage("Player rollback finished."); 396 | Session.Sessions[caller].SendText(retval < 1 ? "Could not find any edits." : "Rolled back edit" + retval + (retval == 1 ? "." : "s.")); 397 | } 398 | 399 | public static int Rollback(int session) 400 | { 401 | NetMessageMod.BroadcastMessage("Starting player rollback, server may lag for a moment."); 402 | List edits = new List(); 403 | 404 | using (SQLiteCommand cmd = Sql.CreateCommand()) 405 | { 406 | cmd.CommandText = "SELECT * FROM TileEdits WHERE SessionId=@SessionId ORDER BY EditId DESC"; 407 | cmd.Parameters.Add(new SQLiteParameter("SessionId", session)); 408 | using (SQLiteDataReader results = cmd.ExecuteReader()) 409 | { 410 | while (results.Read()) 411 | { 412 | edits.Add(new Edit 413 | { 414 | SessionId = (int)results["SessionId"], 415 | X = (int)results["X"], 416 | Y = (int)results["Y"], 417 | Action = (byte)results["Action"], 418 | Type = (byte)results["Type"] 419 | }); 420 | } 421 | } 422 | } 423 | 424 | int retval = edits.Count; 425 | 426 | foreach (Edit e in edits) 427 | { 428 | e.Rollback(); 429 | } 430 | 431 | using (SQLiteCommand cmd = Sql.CreateCommand()) 432 | { 433 | cmd.CommandText = "DELETE FROM TileEdits WHERE SessionId=@SessionId"; 434 | cmd.Parameters.Add(new SQLiteParameter("SessionId", session)); 435 | cmd.ExecuteNonQuery(); 436 | } 437 | 438 | NetMessageMod.BroadcastMessage("Player rollback finished."); 439 | 440 | return retval; 441 | } 442 | 443 | public static void Check(int x, int y, Session session) 444 | { 445 | bool edits = false; 446 | using (SQLiteDataReader results = ExecuteResultSet( 447 | "SELECT * FROM TileEdits AS e, Sessions AS s WHERE e.SessionId=s.SessionId AND e.X=@X AND e.Y=@Y ORDER BY e.EditId DESC LIMIT 5", 448 | new SQLiteParameter("X", x), 449 | new SQLiteParameter("Y", y))) 450 | { 451 | while (results.Read()) 452 | { 453 | if (!edits) 454 | { 455 | session.SendText("Shown with most recent edit on top:"); 456 | edits = true; 457 | } 458 | string name = (string)results["Username"]; ; 459 | string block = string.Format("0x{0:x}", (byte)results["Type"]); 460 | string action; 461 | switch ((byte)results["Action"]) 462 | { 463 | case 0: 464 | case 2: 465 | case 4: 466 | action = " broke "; 467 | break; 468 | 469 | case 1: 470 | case 3: 471 | action = " placed "; 472 | break; 473 | 474 | default: 475 | action = " performed an invalid action on "; 476 | break; 477 | } 478 | session.SendText(name + action + block); 479 | } 480 | } 481 | if (!edits) 482 | { 483 | session.SendText("No recent edits have been made to that block."); 484 | } 485 | } 486 | 487 | public static void TrimAsync() 488 | { 489 | PerformTrim = true; 490 | } 491 | 492 | public static void Truncate() 493 | { 494 | Execute("DELETE FROM TileEdits"); 495 | } 496 | } 497 | } -------------------------------------------------------------------------------- /tMod v2/Edit.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Terraria; 6 | 7 | namespace tMod_v3 8 | { 9 | public class Edit 10 | { 11 | public int SessionId { get; set; } 12 | public int X { get; set; } 13 | public int Y { get; set; } 14 | public byte Action { get; set; } 15 | public byte Type { get; set; } 16 | 17 | public void Rollback() 18 | { 19 | switch (Action) 20 | { 21 | case 0: 22 | case 4: 23 | if (Type == 2) 24 | WorldGenMod.PlaceTile(X, Y, 0, true, true, -1); 25 | else 26 | WorldGenMod.PlaceTile(X, Y, Type, true, true, -1); 27 | MainMod.Tile[X, Y].type = Type; 28 | break; 29 | 30 | case 1: 31 | WorldGenMod.KillTile(X, Y, false, false, true); 32 | break; 33 | 34 | case 2: 35 | WorldGenMod.PlaceWall(X, Y, Type, true); 36 | MainMod.Tile[X, Y].wall = Type; 37 | break; 38 | 39 | case 3: 40 | WorldGenMod.KillWall(X, Y, false); 41 | break; 42 | 43 | default: 44 | return; 45 | } 46 | NetMessageMod.SendTileSquare(-1, X, Y, 3); 47 | } 48 | 49 | public static byte ReverseAction(byte action) 50 | { 51 | switch (action) 52 | { 53 | case 0: 54 | case 4: 55 | return 1; 56 | 57 | case 1: 58 | return 0; 59 | 60 | case 2: 61 | return 3; 62 | 63 | case 3: 64 | return 2; 65 | 66 | default: 67 | return action; 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /tMod v2/Events/.svn/entries: -------------------------------------------------------------------------------- 1 | 10 2 | 3 | dir 4 | 129 5 | svn://earth2me.net/tinamoh/trunk/TerrariaMod/tModCore/Events 6 | svn://earth2me.net/tinamoh 7 | 8 | 9 | 10 | 2011-06-24T03:01:40.943651Z 11 | 127 12 | paul 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 4b143a62-4bc5-4f19-8115-71b4998f2e8e 28 | 29 | AvatarPacketReceivedEventArgs.cs 30 | file 31 | 32 | 33 | 34 | 35 | 2011-06-25T23:43:27.421875Z 36 | 5afcd8cc170277acbb29a6cce596f12e 37 | 2011-06-23T04:21:15.332782Z 38 | 119 39 | paul 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 575 62 | 63 | DoorChangedEventArgs.cs 64 | file 65 | 66 | 67 | 68 | 69 | 2011-06-25T23:43:27.421875Z 70 | 2c8206234af587fa89b026251e50ad6f 71 | 2011-06-24T03:01:40.943651Z 72 | 127 73 | paul 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 602 96 | 97 | ConfigLoadedEventArgs.cs 98 | file 99 | 100 | 101 | 102 | 103 | 2011-06-25T23:43:27.437500Z 104 | 3d4f7ae69a00d23a2fb8e2c5ecdeeed4 105 | 2011-06-23T04:21:15.332782Z 106 | 119 107 | paul 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 394 130 | 131 | PacketReceivedEventArgs.cs 132 | file 133 | 134 | 135 | 136 | 137 | 2011-06-25T23:43:27.437500Z 138 | 15b5e9c808f5e486763f401e2caa813a 139 | 2011-06-23T04:21:15.332782Z 140 | 119 141 | paul 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 1079 164 | 165 | ChangeTilePacketReceivedEventArgs.cs 166 | file 167 | 168 | 169 | 170 | 171 | 2011-06-25T23:43:27.437500Z 172 | b8494e4b8113901410b794d2b6857a9b 173 | 2011-06-23T04:21:15.332782Z 174 | 119 175 | paul 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 1072 198 | 199 | SetLiquidPacketReceivedEventArgs.cs 200 | file 201 | 202 | 203 | 204 | 205 | 2011-06-25T23:43:27.437500Z 206 | 91117bb2bbcbda50860ab12170832166 207 | 2011-06-23T04:21:15.332782Z 208 | 119 209 | paul 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 961 232 | 233 | SetLiquidEventArgs.cs 234 | file 235 | 236 | 237 | 238 | 239 | 2011-06-25T23:43:27.437500Z 240 | 59157837189ef6e1c5bc392b295a7681 241 | 2011-06-24T03:01:40.943651Z 242 | 127 243 | paul 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 664 266 | 267 | UpdateKeyboardEventArgs.cs 268 | file 269 | 270 | 271 | 272 | 273 | 2011-06-25T23:43:27.437500Z 274 | 2a90fa7b7b755a09a15528d065354107 275 | 2011-06-23T04:21:15.332782Z 276 | 119 277 | paul 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 610 300 | 301 | CommandReceivedEventArgs.cs 302 | file 303 | 304 | 305 | 306 | 307 | 2011-06-25T23:43:27.453125Z 308 | 96d7c696390d1a243859b9c283cfa82f 309 | 2011-06-23T04:21:15.332782Z 310 | 119 311 | paul 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 494 334 | 335 | TileChangedEventArgs.cs 336 | file 337 | 338 | 339 | 340 | 341 | 2011-06-25T23:43:27.453125Z 342 | 70a00a2af896368f2a18f65bee721563 343 | 2011-06-24T03:01:40.943651Z 344 | 127 345 | paul 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 668 368 | 369 | DisconnectPacketReceivedEventArgs.cs 370 | file 371 | 372 | 373 | 374 | 375 | 2011-06-25T23:43:27.453125Z 376 | 4570cc7b254ef028e803ff66f0199051 377 | 2011-06-23T04:21:15.332782Z 378 | 119 379 | paul 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 587 402 | 403 | CancelableEventArgs.cs 404 | file 405 | 406 | 407 | 408 | 409 | 2011-06-25T23:43:27.453125Z 410 | 12d0193b9884d70bea7b6169d0d079c5 411 | 2011-06-23T04:21:15.332782Z 412 | 119 413 | paul 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 381 436 | 437 | -------------------------------------------------------------------------------- /tMod v2/Events/.svn/text-base/AvatarPacketReceivedEventArgs.cs.svn-base: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Terraria.Events 7 | { 8 | public delegate void AvatarPacketReceivedEventHandler(object sender, AvatarPacketReceivedEventArgs e); 9 | 10 | public class AvatarPacketReceivedEventArgs : PacketReceivedEventArgs 11 | { 12 | public string PlayerName { get; private set; } 13 | 14 | internal AvatarPacketReceivedEventArgs(PacketReceivedEventArgs e) 15 | : base(e) 16 | { 17 | int index = Start + 28; 18 | PlayerName = Encoding.ASCII.GetString(ReadBuffer, index, (Length - index) + Start); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tMod v2/Events/.svn/text-base/CancelableEventArgs.cs.svn-base: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Terraria.Events 7 | { 8 | public delegate void CancelableEventHandler(object sender, CancelableEventArgs e); 9 | 10 | public class CancelableEventArgs : EventArgs 11 | { 12 | public bool Canceled { get; private set; } 13 | 14 | public virtual void Cancel() 15 | { 16 | Canceled = true; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tMod v2/Events/.svn/text-base/ChangeTilePacketReceivedEventArgs.cs.svn-base: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Terraria.Events 7 | { 8 | public delegate void ChangeTilePacketReceivedEventHandler(object sender, ChangeTilePacketReceivedEventArgs e); 9 | 10 | public class ChangeTilePacketReceivedEventArgs : PacketReceivedEventArgs 11 | { 12 | public byte Action { get; private set; } 13 | public int X { get; private set; } 14 | public int Y { get; private set; } 15 | public byte Type { get; private set; } 16 | 17 | internal ChangeTilePacketReceivedEventArgs(PacketReceivedEventArgs e) 18 | : base(e) 19 | { 20 | int index = Start + 1; 21 | Action = ReadBuffer[index]; 22 | index++; 23 | X = BitConverter.ToInt32(ReadBuffer, index); 24 | index += 4; 25 | Y = BitConverter.ToInt32(ReadBuffer, index); 26 | index += 4; 27 | Type = ReadBuffer[index]; 28 | } 29 | 30 | public override void Cancel() 31 | { 32 | NetMessageMod.SendData(0x11, Player, 0xff, "", Edit.ReverseAction(Action), X, Y, Action == 1 || Action == 3 ? Type : (Action == 2 ? MainMod.Tile[X, Y].wall : MainMod.Tile[X, Y].type)); 33 | base.Cancel(); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tMod v2/Events/.svn/text-base/CommandReceivedEventArgs.cs.svn-base: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Terraria.Events 7 | { 8 | public delegate void CommandReceivedEventHandler(object sender, CommandReceivedEventArgs e); 9 | 10 | public class CommandReceivedEventArgs : CancelableEventArgs 11 | { 12 | public int Player { get; private set; } 13 | public string Text { get; private set; } 14 | 15 | internal CommandReceivedEventArgs(int player, string text) 16 | { 17 | Player = player; 18 | Text = text; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tMod v2/Events/.svn/text-base/ConfigLoadedEventArgs.cs.svn-base: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Terraria.Events 7 | { 8 | public delegate void ConfigLoadedEventHandler(object sender, ConfigLoadedEventArgs e); 9 | 10 | public class ConfigLoadedEventArgs : EventArgs 11 | { 12 | public string File { get; private set; } 13 | 14 | public ConfigLoadedEventArgs(string file) 15 | { 16 | File = file; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tMod v2/Events/.svn/text-base/DisconnectPacketReceivedEventArgs.cs.svn-base: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Terraria.Events 7 | { 8 | public delegate void DisconnectPacketReceivedEventHandler(object sender, DisconnectPacketReceivedEventArgs e); 9 | 10 | public class DisconnectPacketReceivedEventArgs : PacketReceivedEventArgs 11 | { 12 | public string Reason { get; private set; } 13 | 14 | internal DisconnectPacketReceivedEventArgs(PacketReceivedEventArgs e) 15 | : base(e) 16 | { 17 | int index = Start + 1; 18 | Reason = ASCIIEncoding.ASCII.GetString(ReadBuffer, index, (Length - index) + Start); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tMod v2/Events/.svn/text-base/DoorChangedEventArgs.cs.svn-base: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Terraria.Events 7 | { 8 | public delegate void DoorChangedEventHandler(object sender, DoorChangedEventArgs e); 9 | 10 | public class DoorChangedEventArgs : CancelableEventArgs 11 | { 12 | public byte PlayerId { get; private set; } 13 | public bool Action { get; private set; } 14 | public int X { get; private set; } 15 | public int Y { get; private set; } 16 | 17 | public DoorChangedEventArgs(byte playerId, bool action, int x, int y) 18 | { 19 | PlayerId = playerId; 20 | Action = action; 21 | X = x; 22 | Y = y; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /tMod v2/Events/.svn/text-base/PacketReceivedEventArgs.cs.svn-base: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Terraria.Events 7 | { 8 | public delegate void PacketReceivedEventHandler(object sender, PacketReceivedEventArgs e); 9 | 10 | public class PacketReceivedEventArgs : CancelableEventArgs 11 | { 12 | public PacketTypes PacketType { get; private set; } 13 | public int Start { get; private set; } 14 | public int Length { get; private set; } 15 | public byte[] ReadBuffer { get; private set; } 16 | public byte Player { get; private set; } 17 | internal dynamic Instance { get; private set; } 18 | 19 | internal PacketReceivedEventArgs(PacketReceivedEventArgs e) 20 | { 21 | Instance = e.Instance; 22 | PacketType = e.PacketType; 23 | Start = e.Start; 24 | Length = e.Length; 25 | ReadBuffer = e.ReadBuffer; 26 | Player = e.Player; 27 | } 28 | 29 | internal PacketReceivedEventArgs(dynamic inst, int start, int length) 30 | { 31 | Instance = inst; 32 | PacketType = (PacketTypes)inst.readBuffer[start]; 33 | Start = start; 34 | Length = length; 35 | ReadBuffer = inst.readBuffer; 36 | Player = (byte)(int)inst.whoAmI; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tMod v2/Events/.svn/text-base/SetLiquidEventArgs.cs.svn-base: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Terraria.Events 7 | { 8 | public delegate void SetLiquidEventHandler(object sender, SetLiquidEventArgs e); 9 | 10 | public class SetLiquidEventArgs : CancelableEventArgs 11 | { 12 | public byte PlayerId { get; private set; } 13 | public int X { get; private set; } 14 | public int Y { get; private set; } 15 | public byte Liquid { get; private set; } 16 | public bool Lava { get; private set; } 17 | 18 | public SetLiquidEventArgs(byte playerId, int x, int y, byte liquid, bool lava) 19 | { 20 | PlayerId = playerId; 21 | X = x; 22 | Y = y; 23 | Liquid = liquid; 24 | Lava = lava; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tMod v2/Events/.svn/text-base/SetLiquidPacketReceivedEventArgs.cs.svn-base: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Terraria.Events 7 | { 8 | public delegate void SetLiquidPacketReceivedEventHandler(object sender, SetLiquidPacketReceivedEventArgs e); 9 | 10 | public class SetLiquidPacketReceivedEventArgs : PacketReceivedEventArgs 11 | { 12 | public int X { get; private set; } 13 | public int Y { get; private set; } 14 | public byte LiquidAmount { get; private set; } 15 | public bool Lava { get; private set; } 16 | 17 | internal SetLiquidPacketReceivedEventArgs(PacketReceivedEventArgs e) 18 | : base(e) 19 | { 20 | int index = 1 + Start; 21 | X = BitConverter.ToInt32(ReadBuffer, index); 22 | index += 4; 23 | Y = BitConverter.ToInt32(ReadBuffer, index); 24 | index += 4; 25 | LiquidAmount = ReadBuffer[index]; 26 | index++; 27 | Lava = ReadBuffer[index] == 1; 28 | } 29 | 30 | public override void Cancel() 31 | { 32 | NetMessageMod.SendData(0x30, Player, -1, "", X, Y, 0f, 0f); 33 | base.Cancel(); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tMod v2/Events/.svn/text-base/TileChangedEventArgs.cs.svn-base: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Terraria.Events 7 | { 8 | public delegate void TileChangedEventHandler(object sender, TileChangedEventArgs e); 9 | 10 | public class TileChangedEventArgs : CancelableEventArgs 11 | { 12 | public byte PlayerId { get; private set; } 13 | public byte Action { get; private set; } 14 | public int X { get; private set; } 15 | public int Y { get; private set; } 16 | public byte Type { get; private set; } 17 | 18 | public TileChangedEventArgs(byte player, byte action, int x, int y, byte type) 19 | { 20 | PlayerId = player; 21 | Action = action; 22 | X = x; 23 | Y = y; 24 | Type = type; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tMod v2/Events/.svn/text-base/UpdateKeyboardEventArgs.cs.svn-base: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.Xna.Framework.Input; 6 | 7 | namespace Terraria.Events 8 | { 9 | public delegate void UpdateKeyboardEventHandler(object sender, UpdateKeyboardEventArgs e); 10 | 11 | public class UpdateKeyboardEventArgs : EventArgs 12 | { 13 | public KeyboardState CurrentState { get; private set; } 14 | public KeyboardState PreviousState { get; private set; } 15 | 16 | public UpdateKeyboardEventArgs(KeyboardState currentState, KeyboardState previousState) 17 | { 18 | CurrentState = currentState; 19 | PreviousState = previousState; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tMod v2/Events/AvatarPacketReceivedEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace tMod_v3.Events 7 | { 8 | public delegate void AvatarPacketReceivedEventHandler(object sender, AvatarPacketReceivedEventArgs e); 9 | 10 | public class AvatarPacketReceivedEventArgs : PacketReceivedEventArgs 11 | { 12 | public string PlayerName { get; private set; } 13 | 14 | internal AvatarPacketReceivedEventArgs(PacketReceivedEventArgs e) 15 | : base(e) 16 | { 17 | int index = Start + 28; 18 | PlayerName = Encoding.ASCII.GetString(ReadBuffer, index, (Length - index) + Start); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tMod v2/Events/CancelableEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace tMod_v3.Events 7 | { 8 | public delegate void CancelableEventHandler(object sender, CancelableEventArgs e); 9 | 10 | public class CancelableEventArgs : EventArgs 11 | { 12 | public bool Canceled { get; private set; } 13 | 14 | public virtual void Cancel() 15 | { 16 | Canceled = true; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tMod v2/Events/ChangeTilePacketReceivedEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Terraria; 6 | using tMod_v3; 7 | 8 | namespace tMod_v3.Events 9 | { 10 | public delegate void ChangeTilePacketReceivedEventHandler(object sender, ChangeTilePacketReceivedEventArgs e); 11 | 12 | public class ChangeTilePacketReceivedEventArgs : PacketReceivedEventArgs 13 | { 14 | public byte Action { get; private set; } 15 | public int X { get; private set; } 16 | public int Y { get; private set; } 17 | public byte Type { get; private set; } 18 | 19 | internal ChangeTilePacketReceivedEventArgs(PacketReceivedEventArgs e) 20 | : base(e) 21 | { 22 | int index = Start + 1; 23 | Action = ReadBuffer[index]; 24 | index++; 25 | X = BitConverter.ToInt32(ReadBuffer, index); 26 | index += 4; 27 | Y = BitConverter.ToInt32(ReadBuffer, index); 28 | index += 4; 29 | Type = ReadBuffer[index]; 30 | } 31 | 32 | public override void Cancel() 33 | { 34 | NetMessageMod.SendData(0x11, Player, 0xff, "", Edit.ReverseAction(Action), X, Y, Action == 1 || Action == 3 ? Type : (Action == 2 ? MainMod.Tile[X, Y].wall : MainMod.Tile[X, Y].type)); 35 | base.Cancel(); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tMod v2/Events/CommandReceivedEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace tMod_v3.Events 7 | { 8 | public delegate void CommandReceivedEventHandler(object sender, CommandReceivedEventArgs e); 9 | 10 | public class CommandReceivedEventArgs : CancelableEventArgs 11 | { 12 | public int Player { get; private set; } 13 | public string Text { get; private set; } 14 | 15 | internal CommandReceivedEventArgs(int player, string text) 16 | { 17 | Player = player; 18 | Text = text; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tMod v2/Events/ConfigLoadedEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace tMod_v3.Events 7 | { 8 | public delegate void ConfigLoadedEventHandler(object sender, ConfigLoadedEventArgs e); 9 | 10 | public class ConfigLoadedEventArgs : EventArgs 11 | { 12 | public string File { get; private set; } 13 | 14 | public ConfigLoadedEventArgs(string file) 15 | { 16 | File = file; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tMod v2/Events/DisconnectPacketReceivedEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace tMod_v3.Events 7 | { 8 | public delegate void DisconnectPacketReceivedEventHandler(object sender, DisconnectPacketReceivedEventArgs e); 9 | 10 | public class DisconnectPacketReceivedEventArgs : PacketReceivedEventArgs 11 | { 12 | public string Reason { get; private set; } 13 | 14 | internal DisconnectPacketReceivedEventArgs(PacketReceivedEventArgs e) 15 | : base(e) 16 | { 17 | int index = Start + 1; 18 | Reason = ASCIIEncoding.ASCII.GetString(ReadBuffer, index, (Length - index) + Start); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tMod v2/Events/DoorChangedEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace tMod_v3.Events 7 | { 8 | public delegate void DoorChangedEventHandler(object sender, DoorChangedEventArgs e); 9 | 10 | public class DoorChangedEventArgs : CancelableEventArgs 11 | { 12 | public byte PlayerId { get; private set; } 13 | public bool Action { get; private set; } 14 | public int X { get; private set; } 15 | public int Y { get; private set; } 16 | 17 | public DoorChangedEventArgs(byte playerId, bool action, int x, int y) 18 | { 19 | PlayerId = playerId; 20 | Action = action; 21 | X = x; 22 | Y = y; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /tMod v2/Events/PacketReceivedEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace tMod_v3.Events 7 | { 8 | public delegate void PacketReceivedEventHandler(object sender, PacketReceivedEventArgs e); 9 | 10 | public class PacketReceivedEventArgs : CancelableEventArgs 11 | { 12 | public PacketTypes PacketType { get; private set; } 13 | public int Start { get; private set; } 14 | public int Length { get; private set; } 15 | public byte[] ReadBuffer { get; private set; } 16 | public byte Player { get; private set; } 17 | internal dynamic Instance { get; private set; } 18 | 19 | internal PacketReceivedEventArgs(PacketReceivedEventArgs e) 20 | { 21 | Instance = e.Instance; 22 | PacketType = e.PacketType; 23 | Start = e.Start; 24 | Length = e.Length; 25 | ReadBuffer = e.ReadBuffer; 26 | Player = e.Player; 27 | } 28 | 29 | internal PacketReceivedEventArgs(dynamic inst, int start, int length) 30 | { 31 | Instance = inst; 32 | PacketType = (PacketTypes)inst.readBuffer[start]; 33 | Start = start; 34 | Length = length; 35 | ReadBuffer = inst.readBuffer; 36 | Player = (byte)(int)inst.whoAmI; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tMod v2/Events/SetLiquidEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace tMod_v3.Events 7 | { 8 | public delegate void SetLiquidEventHandler(object sender, SetLiquidEventArgs e); 9 | 10 | public class SetLiquidEventArgs : CancelableEventArgs 11 | { 12 | public byte PlayerId { get; private set; } 13 | public int X { get; private set; } 14 | public int Y { get; private set; } 15 | public byte Liquid { get; private set; } 16 | public bool Lava { get; private set; } 17 | 18 | public SetLiquidEventArgs(byte playerId, int x, int y, byte liquid, bool lava) 19 | { 20 | PlayerId = playerId; 21 | X = x; 22 | Y = y; 23 | Liquid = liquid; 24 | Lava = lava; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tMod v2/Events/SetLiquidPacketReceivedEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Terraria; 6 | 7 | namespace tMod_v3.Events 8 | { 9 | public delegate void SetLiquidPacketReceivedEventHandler(object sender, SetLiquidPacketReceivedEventArgs e); 10 | 11 | public class SetLiquidPacketReceivedEventArgs : PacketReceivedEventArgs 12 | { 13 | public int X { get; private set; } 14 | public int Y { get; private set; } 15 | public byte LiquidAmount { get; private set; } 16 | public bool Lava { get; private set; } 17 | 18 | internal SetLiquidPacketReceivedEventArgs(PacketReceivedEventArgs e) 19 | : base(e) 20 | { 21 | int index = 1 + Start; 22 | X = BitConverter.ToInt32(ReadBuffer, index); 23 | index += 4; 24 | Y = BitConverter.ToInt32(ReadBuffer, index); 25 | index += 4; 26 | LiquidAmount = ReadBuffer[index]; 27 | index++; 28 | Lava = ReadBuffer[index] == 1; 29 | } 30 | 31 | public override void Cancel() 32 | { 33 | NetMessageMod.SendData(0x30, Player, -1, "", X, Y, 0f, 0f); 34 | base.Cancel(); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /tMod v2/Events/TileChangedEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace tMod_v3.Events 7 | { 8 | public delegate void TileChangedEventHandler(object sender, TileChangedEventArgs e); 9 | 10 | public class TileChangedEventArgs : CancelableEventArgs 11 | { 12 | public byte PlayerId { get; private set; } 13 | public byte Action { get; private set; } 14 | public int X { get; private set; } 15 | public int Y { get; private set; } 16 | public byte Type { get; private set; } 17 | 18 | public TileChangedEventArgs(byte player, byte action, int x, int y, byte type) 19 | { 20 | PlayerId = player; 21 | Action = action; 22 | X = x; 23 | Y = y; 24 | Type = type; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tMod v2/Events/UpdateKeyboardEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.Xna.Framework.Input; 6 | 7 | namespace tMod_v3.Events 8 | { 9 | public delegate void UpdateKeyboardEventHandler(object sender, UpdateKeyboardEventArgs e); 10 | 11 | public class UpdateKeyboardEventArgs : EventArgs 12 | { 13 | public KeyboardState CurrentState { get; private set; } 14 | public KeyboardState PreviousState { get; private set; } 15 | 16 | public UpdateKeyboardEventArgs(KeyboardState currentState, KeyboardState previousState) 17 | { 18 | CurrentState = currentState; 19 | PreviousState = previousState; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tMod v2/General.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Reflection; 6 | 7 | namespace tMod_v3 8 | { 9 | public class General 10 | { 11 | public dynamic[] Player 12 | { 13 | get 14 | { 15 | return (dynamic[])tMod.main.GetField("player").GetValue(null); 16 | } 17 | set 18 | { 19 | tMod.main.GetField("player").SetValue(null, value); 20 | } 21 | } 22 | 23 | public dynamic[,] Tile 24 | { 25 | get 26 | { 27 | return (object[,])tMod.main.GetField("tile").GetValue(null); 28 | } 29 | set 30 | { 31 | tMod.main.GetField("tile").SetValue(null, value); 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tMod v2/Groups.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Terraria; 4 | using System.Text; 5 | using System.Collections.Specialized; 6 | 7 | namespace tMod_v3 8 | { 9 | [Serializable] 10 | public class Groups 11 | { 12 | public Group Ops = new Group(); 13 | public Group Mods = new Group(); 14 | public Group Default = new Group(); 15 | public Group Member = new Group(); 16 | public List CustomGroups = new List(); 17 | 18 | public Group GetGroup(string name) 19 | { 20 | name = name.ToLower(); 21 | if (name.Equals("ops")) return Ops; 22 | else if (name.Equals("mods")) return Mods; 23 | else if (name.Equals("default")) return Default; 24 | else if (name.Equals("member")) return Member; 25 | foreach (Group group in CustomGroups) 26 | if (group.GroupName.ToLower().Equals(name)) return group; 27 | return Default; 28 | } 29 | } 30 | 31 | [Serializable] 32 | public class Group 33 | { 34 | public string GroupName = "Default"; 35 | public StringCollection GroupPermissions = new StringCollection(); 36 | public string ChatPrefix = ""; 37 | public Rgb ChatColor = new Rgb(255, 255, 255); 38 | public string DerivesFrom = "Default"; 39 | public bool CanBuild = true; 40 | 41 | public bool HasPermission(string cmd) { return GroupPermissions.Contains(cmd) || GroupPermissions.Contains("*") || this != MainMod.Groups.Default && MainMod.Groups.GetGroup(DerivesFrom).HasPermission(cmd); } 42 | } 43 | } -------------------------------------------------------------------------------- /tMod v2/Lua/LuaInterface.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/tMod v2/Lua/LuaInterface.dll -------------------------------------------------------------------------------- /tMod v2/Lua/lua51.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/tMod v2/Lua/lua51.dll -------------------------------------------------------------------------------- /tMod v2/Lua/lua511.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/tMod v2/Lua/lua511.dll -------------------------------------------------------------------------------- /tMod v2/LuaAddons/LuaAddon.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.IO; 6 | using System.Xml.Serialization; 7 | using tMod_v3.Events; 8 | 9 | namespace tMod_v3 10 | { 11 | public class LuaAddon 12 | { 13 | public static List addons = new List(); 14 | public string AddonDir; 15 | 16 | public LuaAddon(string AddonDir) 17 | { 18 | this.AddonDir = AddonDir; 19 | addons.Add(this); 20 | } 21 | 22 | public void Run() 23 | { 24 | LuaHandler.Include("shared.lua"); 25 | } 26 | 27 | public static void CallEvent(object sender, PacketReceivedEventArgs args) 28 | { 29 | try 30 | { 31 | LuaHandler.lua.GetFunction("hook.Call").Call(new object[] { args.PacketType.ToString(), args }); 32 | } 33 | catch (Exception e) 34 | { 35 | Console.WriteLine("[Lua Error] {0}", e.Message); 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tMod v2/LuaAddons/LuaHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading; 6 | using System.Reflection; 7 | using System.IO; 8 | using LuaInterface; 9 | using Terraria; 10 | 11 | namespace tMod_v3 12 | { 13 | public class LuaHandler 14 | { 15 | public static Lua lua; 16 | public static LuaAddon ActiveAddon; 17 | public static LuaHandler instance; 18 | 19 | public static void LuaInit(bool reload = false) 20 | { 21 | instance = new LuaHandler(); 22 | lua = new Lua(); 23 | if(!reload) MessageBufferMod.LuaInit(); 24 | RegisterFunctions(); 25 | RunCoreLua(); 26 | if (MainMod.IsServer) 27 | { 28 | lua["SERVER"] = true; 29 | lua["CLIENT"] = false; 30 | } 31 | else 32 | { 33 | lua["SERVER"] = false; 34 | lua["CLIENT"] = true; 35 | } 36 | SandboxLua(); 37 | LoadAddons(); 38 | } 39 | 40 | public static void LoadAddons() 41 | { 42 | if (!Directory.Exists(@"lua\addons")) 43 | { 44 | Directory.CreateDirectory(@"lua\addons"); 45 | } 46 | foreach (string dir in Directory.GetDirectories(@"lua\addons")) 47 | { 48 | if (File.Exists(dir + "\\shared.lua")) 49 | { 50 | ActiveAddon = new LuaAddon(dir + "\\"); 51 | ActiveAddon.Run(); 52 | } 53 | else 54 | { 55 | Console.WriteLine("[Lua] Warning: No shared.lua found in {0}", dir); 56 | } 57 | } 58 | ActiveAddon = null; 59 | } 60 | 61 | public static void SandboxLua() 62 | { 63 | lua["luanet"] = null; 64 | lua["os"] = null; 65 | lua["require"] = null; 66 | lua["dofile"] = null; 67 | } 68 | 69 | public static void RegisterFunctions() 70 | { 71 | lua.RegisterFunction("AddCSLuaFile", instance, instance.GetType().GetMethod("AddCSLuaFile")); 72 | lua.RegisterFunction("include", instance, instance.GetType().GetMethod("Include")); 73 | lua.RegisterFunction("print", instance, instance.GetType().GetMethod("LuaPrint")); 74 | lua.RegisterFunction("GetPlayer", instance, instance.GetType().GetMethod("GetPlayer")); 75 | lua.RegisterFunction("tostring", instance, instance.GetType().GetMethod("toString")); 76 | lua.RegisterFunction("GetSession", instance, instance.GetType().GetMethod("GetSession")); 77 | } 78 | 79 | public static void ReloadLua() 80 | { 81 | Console.WriteLine("[LuaHandler] Reloading Lua..."); 82 | lua = null; 83 | LuaAddon.addons = new List(); 84 | LuaInit(true); 85 | } 86 | 87 | public static void RunCoreLua() 88 | { 89 | lua.DoString("luanet.load_assembly 'System';"); 90 | lua.DoString("luanet.load_assembly '" + System.AppDomain.CurrentDomain.FriendlyName + "';"); 91 | lua.DoString("Math = luanet.import_type('System.Math');"); 92 | lua.DoString("Session = luanet.import_type('Terraria.Session');"); 93 | lua.DoString("NetMessageMod = luanet.import_type('Terraria.NetMessageMod');"); 94 | lua.DoString("MainMod = luanet.import_type('Terraria.MainMod');"); 95 | lua.DoString("NPCMod = luanet.import_type('Terraria.NPCMod');"); 96 | lua.DoString("MessageBufferMod = luanet.import_type('Terraria.MessageBufferMod');"); 97 | lua.DoString("NetplayMod = luanet.import_type('Terraria.NetplayMod');"); 98 | lua.DoString("WorldGenMod = luanet.import_type('Terraria.WorldGenMod');"); 99 | lua.DoString("Database = luanet.import_type('tMod_v3.Database');"); 100 | lua["General"] = new General(); 101 | lua.DoFile(@"lua\core\hook.lua"); 102 | } 103 | 104 | public Session GetSession(int Player) 105 | { 106 | return Session.Sessions[Player]; 107 | } 108 | 109 | public Session GetPlayer(string Player) 110 | { 111 | try 112 | { 113 | return Session.Sessions[MainMod.GetPlayer(Player)]; 114 | } 115 | catch (Exception e) 116 | { 117 | Console.WriteLine("[WARNING] Problem fetching player!"); 118 | } 119 | return null; 120 | } 121 | 122 | public static void LuaPrint(string toprint) // Workaround since print wasn't working :s 123 | { 124 | Console.WriteLine(toprint); 125 | } 126 | 127 | public string toString(object obj) 128 | { 129 | return obj.ToString(); 130 | } 131 | 132 | public static void Include(string file) 133 | { 134 | try 135 | { 136 | if (ActiveAddon == null) 137 | { 138 | Console.WriteLine("[Lua] Warning: Tried including file after initial run, don't!"); 139 | } 140 | else 141 | { 142 | lua.DoFile(ActiveAddon.AddonDir + file); 143 | } 144 | } 145 | catch (Exception e) 146 | { 147 | Console.WriteLine("[Lua Error] {0}", e.Message); 148 | } 149 | } 150 | 151 | public void AddCSLuaFile(string luaFile) 152 | { 153 | Console.WriteLine("[LUA WARNING] What are you doing? There's no client mod yet to send these files to!"); 154 | } 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /tMod v2/PacketTypes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace tMod_v3 7 | { 8 | public enum PacketTypes : byte 9 | { 10 | Version = 1, 11 | Disconnect = 2, 12 | Connected = 3, 13 | Avatar = 4, 14 | InventorySlot = 5, 15 | Ready = 6, 16 | WorldParams = 7, 17 | RequestChunk = 8, 18 | Status = 9, 19 | SendRow = 0xa, 20 | CalculateFrame = 0xb, 21 | SpawnPlayer = 0xc, 22 | UpdatePlayer = 0xd, 23 | IsPlayerActive = 0xe, 24 | RequestPlayerSync = 0xf, 25 | PlayerLife = 0x10, 26 | ChangeTile = 0x11, 27 | UpdateTime = 0x12, 28 | UpdateDoor = 0x13, 29 | UpdateTiles = 0x14, 30 | DropItem = 0x15, 31 | ItemOwner = 0x16, 32 | NpcData = 0x17, 33 | PlayerHitNpc = 0x18, 34 | ChatMessage = 0x19, 35 | PlayerStrike = 0x1a, 36 | Projectile = 0x1b, 37 | StrikeNpc = 0x1c, 38 | DisposeProjectile = 0x1d, 39 | SetPvp = 0x1e, 40 | RequestChest = 0x1f, 41 | ChestItem = 0x20, 42 | OpenChest = 0x21, 43 | KillTile = 0x22, 44 | HealEffect = 0x23, 45 | SetZone = 0x24, 46 | RequestPassword = 0x25, 47 | SendPassword = 0x26, 48 | RemoveItemOwner = 0x27, 49 | TalkToNpc = 0x28, 50 | PlayerAnimation = 0x29, 51 | PlayerMana = 0x2a, 52 | ManaEffect = 0x2b, 53 | PlayerDeath = 0x2c, 54 | ChangeTeams = 0x2d, 55 | RequestSign = 0x2e, 56 | Sign = 0x2f, 57 | SetLiquid = 0x30, 58 | SpawnSelf = 0x31, 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /tMod v2/Plugins/Plugin.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace tMod_v3 7 | { 8 | public abstract class Plugin 9 | { 10 | public abstract string Name { get; } 11 | public abstract string Author { get; } 12 | public abstract Version Version { get; } 13 | 14 | public event EventHandler Loaded; 15 | public event EventHandler Unloaded; 16 | public event EventHandler Reloaded; 17 | 18 | protected internal virtual void OnLoaded(object sender, EventArgs e) 19 | { 20 | if (Loaded != null) 21 | { 22 | Loaded.Invoke(sender, e); 23 | } 24 | } 25 | 26 | protected internal void OnUnloaded(object sender, EventArgs e) 27 | { 28 | if (Unloaded != null) 29 | { 30 | Unloaded.Invoke(sender, e); 31 | } 32 | } 33 | 34 | public void Reload() 35 | { 36 | OnReloaded(this, new EventArgs()); 37 | } 38 | 39 | protected virtual void OnReloaded(object sender, EventArgs e) 40 | { 41 | if (Reloaded != null) 42 | { 43 | Reloaded.Invoke(sender, e); 44 | } 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /tMod v2/Plugins/PluginManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Reflection; 6 | using System.IO; 7 | using System.Threading; 8 | using tMod_v3.Events; 9 | using Terraria; 10 | 11 | namespace tMod_v3 12 | { 13 | public static class PluginManager 14 | { 15 | private static Configuration Config; 16 | private static List Plugins = new List(); 17 | 18 | public static void LoadPlugins(Configuration config) 19 | { 20 | Config = config; 21 | if (!Directory.Exists(config.PluginDirectory)) 22 | { 23 | Directory.CreateDirectory(config.PluginDirectory); 24 | } 25 | if (!Directory.Exists(config.PluginDataDirectory)) 26 | { 27 | Directory.CreateDirectory(config.PluginDataDirectory); 28 | } 29 | foreach (string p in config.Plugins) 30 | { 31 | try 32 | { 33 | LoadPlugin(p); 34 | } 35 | catch (Exception ex) 36 | { 37 | Console.WriteLine("[PluginManager] Problem loading plugin: {0}", p); 38 | Console.WriteLine("[PluginManager] Dumped error in PluginManagerException.txt"); 39 | Console.WriteLine("[PluginManager] Make sure you marked it as safe! Instructions at http://tmod.biz/forum/"); 40 | using (StreamWriter writer = new StreamWriter("PluginManagerException.txt", true)) 41 | { 42 | writer.WriteLine(DateTime.Now); 43 | writer.WriteLine(ex); 44 | writer.WriteLine(""); 45 | } 46 | } 47 | } 48 | } 49 | 50 | public static Plugin[] GetPlugins() 51 | { 52 | return Plugins.ToArray(); 53 | } 54 | 55 | public static Plugin GetPlugin(string pluginName) 56 | { 57 | foreach (Plugin plugin in Plugins) 58 | { 59 | if (plugin.Name.Equals(pluginName)) 60 | { 61 | return plugin; 62 | } 63 | } 64 | return null; // so I don't have to add an extra loop to see if it's loaded. 65 | } 66 | 67 | public static void LoadPlugin(string pluginName) 68 | { 69 | byte[] assembly = File.ReadAllBytes(Config.PluginDirectory + @"\" + pluginName + (pluginName.EndsWith(".dll") ? "" : ".dll")); 70 | Assembly asm = Assembly.Load(assembly); 71 | foreach (Type t in asm.GetTypes()) 72 | { 73 | if (t.BaseType == typeof(Plugin) && t.GetConstructor(new Type[0]) != null) 74 | { 75 | Thread tr = new Thread(LoadPlugin); 76 | tr.Start(t.GetConstructor(new Type[0]).Invoke(new object[0])); 77 | } 78 | } 79 | } 80 | 81 | public static bool PluginExists(string pluginName) 82 | { 83 | return File.Exists(Config.PluginDirectory + @"\" + pluginName + (pluginName.EndsWith(".dll") ? "" : ".dll")); 84 | } 85 | 86 | public static void LoadPlugin(object pl) 87 | { 88 | Plugin plugin = (Plugin)pl; 89 | Plugins.Add(plugin); 90 | plugin.OnLoaded(null, new EventArgs()); 91 | Console.WriteLine("Loaded plugin: " + plugin.Name + " v" + plugin.Version + " by " + plugin.Author, true); 92 | } 93 | 94 | public static void UnloadPlugin(Plugin plugin) 95 | { 96 | Plugins.Remove(plugin); 97 | 98 | plugin.OnUnloaded(null, new EventArgs()); 99 | Console.WriteLine("Unloaded plugin: " + plugin.Name + " v" + plugin.Version + " by " + plugin.Author, true); 100 | } 101 | 102 | public static void Reload() 103 | { 104 | foreach (Plugin p in Plugins) 105 | { 106 | p.Reload(); 107 | } 108 | } 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /tMod v2/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using System.IO; 6 | using System.Net; 7 | using System.Text; 8 | using System.Threading; 9 | using System.Reflection; 10 | using Terraria; 11 | 12 | namespace tMod_v3 13 | { 14 | class Program 15 | { 16 | static void Main(string[] args) 17 | { 18 | if (args.Count() > 0 && args[0] == "-config") 19 | { 20 | Console.WriteLine("tMod is starting in configuration mode..."); 21 | MainMod.LoadConfig(true); 22 | FieldInfo[] fields = MainMod.Config.GetType().GetFields(BindingFlags.Instance |BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); 23 | foreach (FieldInfo PI in fields) 24 | { 25 | try 26 | { 27 | // if one person complains about this I'll be so pissed. 28 | // It was being weird, no other method was working, sue me. 29 | if (PI.FieldType.Equals(typeof(String)) || PI.FieldType.Equals(typeof(Int32)) || PI.FieldType.Equals(typeof(Boolean)) || 30 | PI.Name == "Ops") 31 | { 32 | if (PI.FieldType.Equals(typeof(String))) 33 | { 34 | Console.Write("{0} (enter for {1}): ", PI.Name, PI.GetValue(MainMod.Config)); 35 | string read = Console.ReadLine(); 36 | if(read != "") PI.SetValue(MainMod.Config, read); 37 | } 38 | else if (PI.FieldType.Equals(typeof(Int32))) 39 | { 40 | Console.Write("{0} (enter for {1}): ", PI.Name, PI.GetValue(MainMod.Config)); 41 | string read = Console.ReadLine(); 42 | if (read != "") PI.SetValue(MainMod.Config, int.Parse(read)); 43 | } 44 | else if (PI.FieldType.Equals(typeof(Boolean))) 45 | { 46 | Console.Write("{0} (enter for {1} - put true or false): ", PI.Name, PI.GetValue(MainMod.Config)); 47 | string read = Console.ReadLine(); 48 | if (read != "") PI.SetValue(MainMod.Config, bool.Parse(read)); 49 | } 50 | else if (PI.Name == "Ops") 51 | { 52 | Console.WriteLine("This step will add you as an admin to your server!"); 53 | Console.Write("Please enter your IP address here (or press enter to skip): "); 54 | string IP = Console.ReadLine(); 55 | if (IP != "" && !MainMod.Config.Ops.Contains(IP)) 56 | { 57 | MainMod.Config.Ops.Add(IP); 58 | } 59 | } 60 | } 61 | } 62 | catch 63 | { 64 | Console.WriteLine("Problem with input, default set."); 65 | } 66 | } 67 | Console.WriteLine("Done!"); 68 | MainMod.SaveConfig(); 69 | } 70 | else if (args.Count() > 1) 71 | { 72 | MainMod.LoadConfig(true); 73 | for (int i = 0; i < args.Count(); i++) 74 | { 75 | // Not the best way by far, but sue me, I did this at 2am (1:53:03am to be exact ;D) 76 | try 77 | { 78 | FieldInfo field = MainMod.Config.GetType().GetField(args[i].Replace("-", "")); 79 | if (field != null) 80 | { 81 | i++; 82 | if (args.Count() > i) 83 | { 84 | if (field.FieldType.Equals(typeof(String))) 85 | { 86 | field.SetValue(MainMod.Config, args[i]); 87 | } 88 | else if (field.FieldType.Equals(typeof(Boolean))) 89 | { 90 | field.SetValue(MainMod.Config, bool.Parse(args[i])); 91 | } 92 | else if (field.FieldType.Equals(typeof(Int32))) 93 | { 94 | field.SetValue(MainMod.Config, int.Parse(args[i])); 95 | } 96 | } 97 | } 98 | } 99 | catch { } 100 | } 101 | MainMod.SaveConfig(); 102 | } 103 | if (!File.Exists("TerrariaServer.exe")) 104 | { 105 | Console.WriteLine("TerrariaServer.exe not found. Please copy it from your Terraria installation directory."); 106 | Console.ReadLine(); 107 | } 108 | Console.WriteLine("tMod v{0}", MainMod.tModVersion); 109 | if (File.Exists(@"tMod\Database.sdf")) 110 | { 111 | Console.WriteLine("WARNING!!!"); 112 | Console.WriteLine("tMod no longer supports SqlServerCe databases."); 113 | Console.WriteLine("We have detected that you still have yours."); 114 | Console.WriteLine(); 115 | Console.WriteLine("If you want to use your old database (contains rollback information, users, etc) please follow the guide here: "); 116 | Console.WriteLine("http://www.tmod.biz/database.html"); 117 | Console.WriteLine(); 118 | Console.WriteLine("Program will continue in ten seconds..."); 119 | Console.WriteLine(); 120 | Console.Beep(1000, 100); 121 | Console.Beep(1000, 100); 122 | Thread.Sleep(10000); 123 | } 124 | if (System.AppDomain.CurrentDomain.FriendlyName == "update_temp.exe") 125 | { 126 | Console.WriteLine("Update mode detected, transferring..."); 127 | Thread.Sleep(3000); // Just in case the old executable hasn't quit yet 128 | if (File.Exists("tMod v3.exe")) File.Delete("tMod v3.exe"); 129 | if (File.Exists("update_mm.exe")) File.Delete("update_mm.exe"); 130 | File.Copy(System.AppDomain.CurrentDomain.FriendlyName, "tMod v3.exe"); 131 | Process.Start("tMod v3.exe"); 132 | Environment.Exit(0); 133 | } 134 | else if (File.Exists("update_temp.exe")) 135 | { 136 | Console.WriteLine("Please wait, removing update_temp.exe"); 137 | Thread.Sleep(3000); 138 | File.Delete("update_temp.exe"); 139 | } 140 | Console.WriteLine("Please wait, scanning for Terraria.exe!"); 141 | tMod tmod = new tMod(); 142 | tmod.inject(); 143 | } 144 | 145 | private static void DownloadFile(string downloadFrom, string saveTo) 146 | { 147 | using (WebClient client = new WebClient()) 148 | { 149 | client.Proxy = new WebProxy(); 150 | client.DownloadFile(downloadFrom, saveTo); 151 | } 152 | } 153 | 154 | private static string GetText(string from) 155 | { 156 | Uri site = new Uri(from); 157 | WebRequest wReq = WebRequest.Create(site); 158 | wReq.Proxy = new WebProxy(); 159 | using (WebResponse wResp = wReq.GetResponse()) 160 | { 161 | Stream respStream = wResp.GetResponseStream(); 162 | StreamReader reader = new StreamReader(respStream, Encoding.ASCII); 163 | return reader.ReadToEnd(); 164 | } 165 | } 166 | } 167 | } -------------------------------------------------------------------------------- /tMod v2/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("tMod v3")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("tMod v3")] 13 | [assembly: AssemblyCopyright("Copyright © 2011")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("43d88c76-a0cf-40f3-bda8-84f84f83eb8a")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /tMod v2/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.1 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace tMod_v3.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | 26 | [global::System.Configuration.ApplicationScopedSettingAttribute()] 27 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 28 | [global::System.Configuration.SpecialSettingAttribute(global::System.Configuration.SpecialSetting.ConnectionString)] 29 | [global::System.Configuration.DefaultSettingValueAttribute("Data Source=|DataDirectory|\\Resources\\Files\\Database.sdf")] 30 | public string DatabaseConnectionString { 31 | get { 32 | return ((string)(this["DatabaseConnectionString"])); 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tMod v2/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | <?xml version="1.0" encoding="utf-16"?> 7 | <SerializableConnectionString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 8 | <ConnectionString>Data Source=|DataDirectory|\Resources\Files\Database.sdf</ConnectionString> 9 | <ProviderName>Microsoft.SqlServerCe.Client.3.5</ProviderName> 10 | </SerializableConnectionString> 11 | Data Source=|DataDirectory|\Resources\Files\Database.sdf 12 | 13 | 14 | -------------------------------------------------------------------------------- /tMod v2/PropertiesFile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Collections; 6 | using System.IO; 7 | 8 | namespace tMod_v3 9 | { 10 | public class PropertiesFile : Dictionary 11 | { 12 | string name; 13 | List properties = new List(); 14 | public PropertiesFile(string name) 15 | { 16 | this.name = name; 17 | } 18 | 19 | public void registerProperty(string propertyName, string defaultValue = "false") 20 | { 21 | properties.Add(propertyName + Environment.NewLine + defaultValue); 22 | } 23 | 24 | public int getInteger(string propertyName) 25 | { 26 | int ret = 0; 27 | if (!int.TryParse(this[propertyName], out ret)) 28 | { 29 | ret = -1; 30 | } 31 | return ret; 32 | } 33 | 34 | public bool getBoolean(string propertyName) 35 | { 36 | bool ret = false; 37 | if (!bool.TryParse(this[propertyName], out ret)) 38 | { 39 | ret = false; 40 | } 41 | return ret; 42 | } 43 | 44 | public double getDouble(string propertyName) 45 | { 46 | double ret = 0; 47 | if (!double.TryParse(this[propertyName], out ret)) 48 | { 49 | ret = -1; 50 | } 51 | return ret; 52 | } 53 | 54 | public void loadProperties() 55 | { 56 | if (!File.Exists(name + ".properties")) 57 | { 58 | File.Create(name + ".properties"); 59 | } 60 | foreach (string row in File.ReadAllLines(name + ".properties")) 61 | { 62 | if (row.IndexOf('=') > -1 && row.Substring(0, 1) != "#") 63 | { 64 | string[] split = row.Split('='); 65 | split[1] = split[1].Split('#')[0]; 66 | if (split[0] != "" && split[1] != "") 67 | { 68 | this.Add(split[0], split[1]); 69 | } 70 | else if (split[0] != "") 71 | { 72 | this.Add(split[0], ""); 73 | } 74 | } 75 | } 76 | if (!File.Exists(name + ".properties")) 77 | { 78 | File.Create(name + ".properties").Close(); 79 | Console.WriteLine("Generated {0}", name + ".properties"); 80 | } 81 | StreamWriter writer = File.AppendText(name + ".properties"); 82 | foreach (string str in properties) 83 | { 84 | string[] split = str.Split(Environment.NewLine.ToCharArray()); 85 | if (!this.ContainsKey(split[0])) 86 | { 87 | Console.WriteLine("Property: " + split[0] + " missing in file " + name + ".properties! Default set!"); 88 | this.Add(split[0], split[1]); 89 | writer.WriteLine(split[0] + "=" + split[1]); 90 | } 91 | } 92 | writer.Close(); 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /tMod v2/Rgb.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace tMod_v3 7 | { 8 | [Serializable] 9 | public class Rgb 10 | { 11 | public byte R; 12 | public byte G; 13 | public byte B; 14 | 15 | public Rgb() 16 | { 17 | } 18 | 19 | public Rgb(byte r, byte g, byte b) 20 | { 21 | R = r; 22 | G = g; 23 | B = b; 24 | } 25 | 26 | public Rgb(byte all) 27 | { 28 | R = G = B = all; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tMod v2/Session.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Terraria; 6 | using Microsoft.Xna.Framework; 7 | 8 | namespace tMod_v3 9 | { 10 | public class Session 11 | { 12 | public static Session[] Sessions = new Session[0xff]; 13 | 14 | public int Id { get; private set; } 15 | public int Index { get; private set; } 16 | public int DbId { get; private set; } 17 | public string Username { get; private set; } 18 | public string IpAddress { get; private set; } 19 | public bool IsLoggedIn { get; private set; } 20 | public bool IsCheckingBlock { get; set; } 21 | public bool IsTeleporting { get; set; } 22 | public bool IsUsingTMod { get; set; } 23 | public bool IsAllowedToRegister { get; set; } 24 | public bool IsMuted { get; set; } 25 | public bool Stupidized { get; set; } 26 | public bool Butterfingers { get; set; } 27 | public Group Group { get; set; } 28 | public int OldSpawnX { get; set; } 29 | public int OldSpawnY { get; set; } 30 | public int TeleSpawnX { get; set; } 31 | public int TeleSpawnY { get; set; } 32 | public int SpawnX { get { return MainMod.Player[Index].SpawnX; } } 33 | public int SpawnY { get { return MainMod.Player[Index].SpawnY; } } 34 | 35 | public Session(int index, string ip) 36 | { 37 | Index = index; 38 | IpAddress = ip; 39 | Group = MainMod.Groups.Member; 40 | } 41 | 42 | public Session(int index, string username, string ip, int id) 43 | { 44 | Index = index; 45 | Username = username; 46 | IpAddress = ip; 47 | Id = id; 48 | } 49 | 50 | internal void Initialize(string username) 51 | { 52 | Id = Database.InsertSession(Username = username, IpAddress); 53 | } 54 | 55 | public void SendText(string text) 56 | { 57 | SendText(175, 75, 255, text); 58 | } 59 | 60 | public void SendError(string text) 61 | { 62 | SendText(255, 0, 0, text); 63 | } 64 | 65 | public void SendHelp(string text) 66 | { 67 | SendText(255, 240, 20, text); 68 | } 69 | 70 | public void SendText(byte r, byte g, byte b, string text, int from = 0xff) 71 | { 72 | NetMessageMod.SendData(0x19, Index, -1, text, from, r, g, b); 73 | } 74 | 75 | public void MakeEdit(Edit edit) 76 | { 77 | Database.InsertEdit(Id, edit.Action, edit.Type, edit.X, edit.Y); 78 | } 79 | 80 | public void Rollback() 81 | { 82 | Database.Rollback(Id); 83 | } 84 | 85 | public void Register(string hash) 86 | { 87 | if (MainMod.Config.BlockRegistration && !IsAllowedToRegister) 88 | { 89 | SendError("You are not allowed to register at this time."); 90 | return; 91 | } 92 | if (!Database.IsUserRegistered(Username)) 93 | { 94 | if (hash == "") 95 | { 96 | SendError("Registration failed. Blank password?"); 97 | return; 98 | } 99 | MainMod.Log(Username + " has registered under the IP " + IpAddress); 100 | Database.InsertRegistration(Index, hash); 101 | SendText(0, 255, 0, "Registered, login with /login "); 102 | } 103 | else 104 | { 105 | SendError("This name is already registered."); 106 | SendError("Please rejoin with a different character name."); 107 | } 108 | } 109 | 110 | public void Login(string hash) 111 | { 112 | if (Database.IsUserRegistered(Username)) 113 | { 114 | int id = Database.CheckLogin(Username, hash); 115 | if (id == -1) 116 | { 117 | SendError("Incorrect password!"); 118 | return; 119 | } 120 | IsLoggedIn = true; 121 | DbId = id; 122 | MainMod.Log(Username + " has logged in under the IP " + IpAddress); 123 | Group = MainMod.Groups.GetGroup(Database.GetUserGroup(Username)); 124 | SendText(0, 255, 0, "Logged in successfully!"); 125 | } 126 | else 127 | { 128 | SendError("This name is not registered."); 129 | } 130 | } 131 | 132 | public void ChangePassword(string hash) 133 | { 134 | if (Database.IsUserRegistered(Username) && this.IsLoggedIn) 135 | { 136 | if (hash == "") 137 | { 138 | SendError("Change password failed. Blank password?"); 139 | return; 140 | } 141 | Database.ChangeUserPassword(Username, hash); 142 | SendText(0, 255, 0, "Password changed."); 143 | } 144 | else 145 | { 146 | SendError("You must be registered and logged in to use this command."); 147 | } 148 | } 149 | 150 | public void SendLoginMessage() 151 | { 152 | if (Database.IsUserRegistered(Username)) 153 | { 154 | SendText("You are not logged in!"); 155 | SendText("Log in with /login {password}"); 156 | } 157 | else if (MainMod.Config.RequireRegistration) 158 | { 159 | SendText("You are not registered!"); 160 | if (MainMod.Config.BlockRegistration) 161 | { 162 | SendText("You must have op/mod approval to register"); 163 | } 164 | else 165 | { 166 | SendText("Register with /register {password}"); 167 | } 168 | } 169 | if (MainMod.Config.AdvertEnabled) SendText("Server is powered by tMod ~ tMod.biz"); 170 | } 171 | 172 | public void SetGroup(string group) 173 | { 174 | Console.WriteLine("[NOTICE] Setting {0} to group {1}", Username, group); 175 | Group = MainMod.Groups.GetGroup(group); 176 | Database.SetUserGroup(Username, Group.GroupName); 177 | } 178 | 179 | public void Teleport(int tx, int ty) 180 | { 181 | if (IsUsingTMod) 182 | { 183 | byte[] writeBuffer = new byte[13]; 184 | Buffer.BlockCopy(BitConverter.GetBytes(9), 0, writeBuffer, 0, 4); 185 | writeBuffer[4] = 0xfe; 186 | Buffer.BlockCopy(BitConverter.GetBytes(tx), 0, writeBuffer, 5, 4); 187 | Buffer.BlockCopy(BitConverter.GetBytes(ty), 0, writeBuffer, 9, 4); 188 | NetMessageMod.FlushBuffer(writeBuffer, Index); 189 | } 190 | else 191 | { 192 | if (tx < 0 || ty < 0 || tx >= MainMod.MaxTilesX || ty >= MainMod.MaxTilesY) 193 | { 194 | Console.WriteLine("Attempt to teleport player {0} to invalid location: {1}, {2}.", Username ?? IpAddress, tx, ty); 195 | return; 196 | } 197 | bool changeSpawn = false; 198 | int ox = MainMod.SpawnTileX; 199 | int oy = MainMod.SpawnTileY; 200 | if (SpawnX >= 0 && SpawnY >= 0) 201 | { 202 | changeSpawn = true; 203 | ox = SpawnX; 204 | oy = SpawnY; 205 | } 206 | else if (OldSpawnX >= 0 && OldSpawnY >= 0) 207 | { 208 | changeSpawn = true; 209 | ox = OldSpawnX; 210 | oy = OldSpawnY; 211 | } 212 | int sx = tx / 200; 213 | int sy = ty / 150; 214 | int fromX = Math.Max(0, sx - 1); 215 | int fromY = Math.Max(0, sy - 1); 216 | int toX = Math.Min(sx + 1, MainMod.MaxTilesX / 200 - 1); 217 | int toY = Math.Min(sy + 1, MainMod.MaxTilesY / 150 - 1); 218 | int sections = 0; 219 | for (int x = fromX; x <= toX; x++) 220 | for (int y = fromY; y <= toY; y++) 221 | if (!NetplayMod.ServerSock[Index].tileSection[x, y]) sections += 1; 222 | if (sections > 0) 223 | { 224 | NetMessageMod.SendData(9, Index, -1, "Prepairing to teleport...", sections * 150); 225 | for (int x = fromX; x <= toX; x++) 226 | for (int y = fromY; y <= toY; y++) 227 | if (!NetplayMod.ServerSock[Index].tileSection[x, y]) 228 | NetMessageMod.SendSection(Index, x, y); 229 | NetMessageMod.SendData(11, Index, -1, "", fromX, fromY, toX, toY); 230 | } 231 | for (int proj = 0; proj < MainMod.Projectile.Length; ++proj) 232 | if (MainMod.Projectile[proj].active && MainMod.Projectile[proj].owner == Index && (MainMod.Projectile[proj].type == 13 || MainMod.Projectile[proj].type == 32)) 233 | { 234 | MainMod.Projectile[proj].active = false; 235 | MainMod.Projectile[proj].type = 0; 236 | NetMessageMod.SendData(27, -1, -1, "", proj); 237 | } 238 | int left = 0; 239 | int right = -1; 240 | if (changeSpawn && oy > 1) 241 | { 242 | left = Math.Max(0, ox - 4); 243 | right = Math.Min(ox + 4, MainMod.MaxTilesX); 244 | while (left < MainMod.MaxTilesX && MainMod.Tile[left, oy - 1].type != 79) 245 | left += 1; 246 | while (right > 0 && MainMod.Tile[right, oy - 1].type != 79) 247 | right -= 1; 248 | for (int x = left; x <= right; x++) 249 | { 250 | MainMod.Tile[x, oy - 1].active = false; 251 | NetMessageMod.SendTileSquare(Index, x, oy - 1, 1); 252 | MainMod.Tile[x, oy - 2].active = false; 253 | NetMessageMod.SendTileSquare(Index, x, oy - 2, 1); 254 | } 255 | } 256 | int tX = MainMod.SpawnTileX, tY = MainMod.SpawnTileY; 257 | MainMod.SpawnTileX = tx; MainMod.SpawnTileY = ty; 258 | NetMessageMod.SendData(7, Index); 259 | MainMod.SpawnTileX = tX; MainMod.SpawnTileY = tY; 260 | TeleSpawnX = tx; 261 | TeleSpawnY = ty; 262 | NetMessageMod.SendData(12, Index, -1, "", Index); 263 | int fx = Math.Max(0, Math.Min(MainMod.MaxTilesX - 8, tx - 4)); 264 | int fy = Math.Max(0, Math.Min(MainMod.MaxTilesY - 8, ty - 4)); 265 | NetMessageMod.SendTileSquare(Index, fx, fy, 7); 266 | if (changeSpawn && oy > 1) 267 | { 268 | NetMessageMod.SendTileSquare(Index, ox, oy, 1); 269 | if (right - left >= 0 && oy >= 2) 270 | NetMessageMod.SendTileSquare(Index, left, oy - 2, right - left + 1); 271 | } 272 | NetMessageMod.SendData(7, Index); 273 | } 274 | } 275 | } 276 | } -------------------------------------------------------------------------------- /tMod v2/StringExtension.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace tMod_v3 7 | { 8 | public static class StringExtension 9 | { 10 | private static readonly string[] Lower = new string[] { "of", "the", "a", "an", "in" }; 11 | public static string ToProper(this string p) 12 | { 13 | string[] words = p.ToLower().Split(' '); 14 | for (int i = 0; i < words.Length; i++) 15 | { 16 | if (i > 0 && Lower.Contains(words[i])) 17 | { 18 | continue; 19 | } 20 | if (words[i].Length > 1) 21 | { 22 | words[i] = words[i].Remove(1).ToUpper() + words[i].Substring(1); 23 | } 24 | else if (words[i].Length > 0) 25 | { 26 | words[i] = words[i].ToUpper(); 27 | } 28 | } 29 | return string.Join(" ", words); 30 | } 31 | static char[] whitelist = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890|\\¬!\"£$%^&*()_+{}:@~<>?,./;'#[]-= `".ToCharArray(); 32 | public static bool IsClean(this string p) 33 | { 34 | foreach (char c in p.ToUpper().ToCharArray()) 35 | { 36 | if (!whitelist.Contains(c)) 37 | { 38 | return false; 39 | } 40 | } 41 | return true; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tMod v2/Terraria/ItemMod.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace Terraria 7 | { 8 | public class ItemMod 9 | { 10 | public static Type Item; 11 | 12 | public static int NewItem(int X, int Y, int Width, int Height, int Type, int Stack = 1, bool noBroadcast = false) 13 | { 14 | return (int)Item.GetMethod("NewItem").Invoke(null, new object[] { X, Y, Width, Height, Type, Stack, noBroadcast }); 15 | } 16 | 17 | public static bool SetDefaultsMod(string name, dynamic item) 18 | { 19 | foreach (dynamic ci in XeedMod.GetItems().ToArray()) 20 | if (ci.name.Equals(name)) 21 | try 22 | { 23 | item.SetDefaults(ci.GetID(), true); 24 | ci.ApplyTo(item); 25 | return true; 26 | } 27 | catch (Exception ex) { Console.WriteLine(ex); } 28 | return false; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tMod v2/Terraria/MainMod.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Xml.Serialization; 6 | using System.IO; 7 | using System.Diagnostics; 8 | using System.Net; 9 | using Microsoft.Xna.Framework; 10 | using System.Threading; 11 | using tMod_v3; 12 | using tMod_v3.Events; 13 | 14 | namespace Terraria 15 | { 16 | public static partial class MainMod 17 | { 18 | public static string tModVersion = "3.2"; 19 | public static bool IsServer = true; 20 | public static dynamic main; 21 | public static Configuration Config; 22 | public static Groups Groups; 23 | private static string ConfigFile = "Config.xml"; 24 | public static event EventHandler Update; 25 | public static event ConfigLoadedEventHandler ConfigLoaded; 26 | 27 | public static void UpdateMod() 28 | { 29 | if (Update != null) 30 | { 31 | Update.Invoke(null, new EventArgs()); 32 | } 33 | } 34 | 35 | static bool generating; 36 | public static void DedServ() 37 | { 38 | Console.Title = "tMod v" + tModVersion; 39 | if(Config.CheckForUpdates) CheckForUpdates(); 40 | MainMod.LoadWorlds(); 41 | if (!File.Exists(Config.WorldPath)) 42 | { 43 | // god damned Terraria, I'll fix this next release. 44 | Console.WriteLine("Generating new world."); 45 | generating = true; 46 | ThreadPool.QueueUserWorkItem(delegate { CheckText(); }); 47 | MainMod.WorldPathName = Config.WorldPath; 48 | //Console.Write("Specify world width (MIN 8400, MAX 2147483647 but it's veeeeery slow!): "); 49 | //string str = Console.ReadLine(); 50 | //int width = 8400; 51 | //if (int.TryParse(str, out width) && width >= 8400) 52 | //{ 53 | // MainMod.MaxTilesX = width; 54 | // if (width > short.MaxValue) Console.WriteLine("It's gonna take sooome time... Well, you have been warned!"); 55 | //} 56 | //else 57 | //{ 58 | // Console.WriteLine("An error occured. World width set to 8400."); 59 | MainMod.MaxTilesX = 8400; 60 | //} 61 | MainMod.MaxTilesY = 2400; 62 | MainMod.Tile = (dynamic)tMod.main.Assembly.GetType("Terraria.Tile").MakeArrayType(2).GetConstructor(new Type[] { typeof(int), typeof(int) }).Invoke(new object[] { MainMod.MaxTilesX, MainMod.MaxTilesY }); 63 | tMod.main.GetField("bottomWorld").SetValue(null, MainMod.MaxTilesY * 0x10); 64 | tMod.main.GetField("rightWorld").SetValue(null, MainMod.MaxTilesX * 0x10); 65 | tMod.main.GetField("maxSectionsX").SetValue(null, MainMod.MaxTilesX / 200); 66 | tMod.main.GetField("maxSectionsY").SetValue(null, MainMod.MaxTilesY / 150); 67 | MainMod.DedServer = true; 68 | MainMod.ShowSplash = false; 69 | MainMod.Initialize(); 70 | MainMod.MenuState = 10; 71 | WorldGenMod.SaveLock = false; 72 | MainMod.SkipMenu = false; 73 | WorldGenMod.CreateNewWorld(); 74 | while (MainMod.MenuState == 10) { Thread.Sleep(200); } // workaround 75 | generating = false; 76 | Process.Start("tMod v3.exe"); 77 | Environment.Exit(0); 78 | } 79 | MainMod.WorldPathName = Config.WorldPath; 80 | main.DedServ(); 81 | } 82 | 83 | public static void CheckText() 84 | { 85 | string oldText = ""; 86 | while (generating) 87 | { 88 | if (MainMod.StatusText != oldText) 89 | { 90 | oldText = MainMod.StatusText; 91 | Console.WriteLine(oldText); 92 | } 93 | Thread.Sleep(100); 94 | } 95 | } 96 | 97 | public static void StartDedInputMod() 98 | { 99 | Console.Clear(); 100 | Console.Title = "tMod v" + tModVersion; 101 | Console.WriteLine("tMod v{0}", tModVersion); 102 | Console.WriteLine("http://tmod.biz/"); 103 | Console.WriteLine("If you paid for this, get your money back, it's FREE!"); 104 | Console.WriteLine(); 105 | Console.WriteLine("Loading .NET Plugins..."); 106 | Console.WriteLine(); 107 | PluginManager.LoadPlugins(MainMod.Config); 108 | Console.WriteLine(); 109 | Console.WriteLine("Loading Lua Plugins..."); 110 | Console.WriteLine(); 111 | LuaHandler.LuaInit(); 112 | Console.WriteLine(); 113 | Console.WriteLine("Done! tMod has started!"); 114 | if (MainMod.Config.AsyncMode) Console.WriteLine("Running in Async mode!"); 115 | } 116 | 117 | public static void CheckForUpdates() 118 | { 119 | #if !DEBUG 120 | Console.WriteLine("Checking for updates..."); 121 | Console.WriteLine("You can disable this in the configuration file! Set CheckForUpdates to false!"); 122 | try 123 | { 124 | string version = GetText("http://tmod.biz/current_version.txt"); 125 | if (version != tModVersion) 126 | { 127 | Console.WriteLine("tMod is outdated! Downloading update..."); 128 | string[] files = GetText("http://tmod.biz/update/update_files.txt").Split(Environment.NewLine.ToCharArray()); 129 | foreach (string file in files) 130 | { 131 | if(file != "") 132 | { 133 | Console.WriteLine("[AutoUpdate] Downloading: {0}", file); 134 | DownloadFile("http://tmod.biz/update/" + file, file); 135 | } 136 | } 137 | Console.WriteLine("[AutoUpdate] Downloading updated executable..."); 138 | DownloadFile("http://tmod.biz/update/update_temp.exe", "update_temp.exe"); 139 | Process.Start("update_temp.exe"); 140 | Environment.Exit(0); 141 | } 142 | } 143 | catch (Exception e) 144 | { 145 | Console.WriteLine("Failed to check for/download updates! {0}", e.Message); 146 | } 147 | #endif 148 | } 149 | 150 | private static string GetText(string from) 151 | { 152 | Uri site = new Uri(from); 153 | WebRequest wReq = WebRequest.Create(site); 154 | wReq.Proxy = new WebProxy(); 155 | using (WebResponse wResp = wReq.GetResponse()) 156 | { 157 | Stream respStream = wResp.GetResponseStream(); 158 | StreamReader reader = new StreamReader(respStream, Encoding.ASCII); 159 | return reader.ReadToEnd(); 160 | } 161 | } 162 | 163 | private static void DownloadFile(string downloadFrom, string saveTo) 164 | { 165 | using (WebClient client = new WebClient()) 166 | { 167 | client.Proxy = new WebProxy(); 168 | client.DownloadFile(downloadFrom, saveTo); 169 | } 170 | } 171 | 172 | public static void Notice(string notice) 173 | { 174 | Console.WriteLine("[NOTICE] {0}", notice); 175 | } 176 | 177 | public static void Log(string notice) 178 | { 179 | Console.WriteLine("[LOG] {0}", notice); 180 | } 181 | 182 | public static void Notice(string notice, bool urgent) 183 | { 184 | Console.WriteLine("[NOTICE] {0}", notice); 185 | } 186 | 187 | public static bool IsOp(int player) 188 | { 189 | return Config.Ops.Contains(Session.Sessions[player].Username) && Session.Sessions[player].IsLoggedIn || Config.Ops.Contains(Session.Sessions[player].IpAddress); 190 | } 191 | 192 | public static bool IsMod(int player) 193 | { 194 | return Config.Mods.Contains(Session.Sessions[player].Username) && Session.Sessions[player].IsLoggedIn || Config.Mods.Contains(Session.Sessions[player].IpAddress); 195 | } 196 | 197 | public static bool HasPermission(int player, string command) 198 | { 199 | return (Session.Sessions[player].IsLoggedIn && Session.Sessions[player].Group.HasPermission(command)) || MainMod.Groups.Default.HasPermission(command); 200 | } 201 | 202 | public static void SaveConfig() 203 | { 204 | XmlSerializer xml = new XmlSerializer(typeof(Configuration)); 205 | FileStream fs = File.Create(ConfigFile); 206 | xml.Serialize(fs, Config); 207 | fs.Flush(); 208 | fs.Close(); 209 | xml = new XmlSerializer(typeof(Groups)); 210 | fs = File.Create("Groups.xml"); 211 | xml.Serialize(fs, Groups); 212 | fs.Flush(); 213 | fs.Close(); 214 | } 215 | 216 | public static bool ServerModCommand(byte player, string text) 217 | { 218 | return ServerCommandHandler.ServerModCommand(player, text); 219 | } 220 | 221 | public static void LoadConfig(bool ConfigMode = false) 222 | { 223 | #if !DEBUG 224 | if (File.Exists(ConfigFile)) 225 | { 226 | XmlSerializer xml = new XmlSerializer(typeof(Configuration)); 227 | FileStream fs = File.OpenRead(ConfigFile); 228 | Config = (Configuration)xml.Deserialize(fs); 229 | fs.Close(); 230 | } 231 | else 232 | { 233 | #endif 234 | Config = new Configuration(); 235 | #if !DEBUG 236 | } 237 | #endif 238 | if (!File.Exists("Groups.xml")) 239 | { 240 | Groups = new Groups(); 241 | Config.Ops.Add("127.0.0.1"); 242 | Groups.Default.GroupPermissions.AddRange(new string[] 243 | { 244 | "/playing", 245 | "/about", 246 | "/list", 247 | "/who", 248 | "/p", 249 | "/party", 250 | "/me", 251 | "/help", 252 | "/motd", 253 | "/login", 254 | "/id", 255 | "/identify", 256 | "/register", 257 | "/spawn", 258 | "/getpos", 259 | "/mypos", 260 | }); 261 | Groups.Member.GroupPermissions.AddRange(new string[] 262 | { 263 | "/opme", 264 | "/changepw", 265 | "/changepassword", 266 | "/changelogin", 267 | }); 268 | Groups.Mods.GroupPermissions.AddRange(new string[] 269 | { 270 | "/mute", 271 | "/unmute", 272 | "/slience", 273 | "/ban", 274 | "/unban", 275 | "/pandon", 276 | "/kick", 277 | "/d", 278 | "/drop", 279 | "/i", 280 | "/item", 281 | "/give", 282 | "/npc", 283 | "/summon", 284 | "/mob", 285 | "/say", 286 | "/broadcast", 287 | "/b", 288 | "/moderate", 289 | "/allowbuild", 290 | "/allowbreak", 291 | "/allowbomb", 292 | "/allowwater", 293 | "/allowlava", 294 | "/allowspike", 295 | "/butcher", 296 | "/butcherall", 297 | "/kill", 298 | "/heal", 299 | "/hearts", 300 | "/giveheart", 301 | "/peace", 302 | "/peaceful", 303 | "/pvp", 304 | "/allowregister", 305 | "/day", 306 | "/night", 307 | "/dusk", 308 | "/noon", 309 | "/midnight", 310 | "/whois", 311 | "/ip", 312 | "/rollback", 313 | "/rban", 314 | "/check", 315 | }); 316 | Groups.Ops.GroupPermissions.Add("*"); 317 | Group Donator = new Group(); 318 | Donator.GroupName = "Donator"; 319 | Groups.CustomGroups.Add(Donator); 320 | } 321 | else 322 | { 323 | Console.WriteLine("Deserializing Groups.xml..."); 324 | try 325 | { 326 | XmlSerializer xml = new XmlSerializer(typeof(Groups)); 327 | FileStream fs = File.OpenRead("Groups.xml"); 328 | Groups = (Groups)xml.Deserialize(fs); 329 | 330 | fs.Close(); 331 | } 332 | catch (Exception ex) 333 | { 334 | Console.WriteLine("[Groups] Problem deserializing Groups.xml, check it's valid."); 335 | Console.WriteLine(ex.Message); 336 | } 337 | } 338 | if (!ConfigMode) 339 | { 340 | MainMod.motd = Config.MOTD; 341 | NetplayMod.ServerListenIP = IPAddress.Parse(Config.BindAddress); 342 | NetplayMod.ServerPort = Config.BindPort; 343 | NetplayMod.password = Config.ServerPassword; 344 | NPCMod.DefaultSpawnRate = NPCMod.SpawnRate = Config.SpawnRate; 345 | NPCMod.DefaultMaxSpawns = NPCMod.MaxSpawns = Config.MaximumSpawns; 346 | } 347 | if(!Groups.Default.GroupPermissions.Contains("/about")) 348 | { 349 | Console.WriteLine("/about HAS to be enabled, sorry."); 350 | Groups.Default.GroupPermissions.Add("/about"); 351 | } 352 | 353 | if(!ConfigMode) LoadOldOps(); 354 | SaveConfig(); 355 | 356 | if (ConfigLoaded != null) 357 | { 358 | ConfigLoaded.Invoke(null, new ConfigLoadedEventArgs(ConfigFile)); 359 | } 360 | } 361 | 362 | private static void LoadOldOps() 363 | { 364 | if (File.Exists(SavePath + @"\ops.txt")) 365 | { 366 | Config.Ops.Clear(); 367 | foreach (string o in File.ReadAllLines(SavePath + @"\ops.txt")) 368 | { 369 | Config.Ops.Add(o); 370 | Config.Mods.Remove(o); 371 | } 372 | File.Delete(SavePath + @"\ops.txt"); 373 | } 374 | } 375 | 376 | public static void SetTime(bool dayTime, int time) 377 | { 378 | MainMod.DayTime = dayTime; 379 | MainMod.Time = time; 380 | NetMessageMod.SendData((int)PacketTypes.UpdateTime, -1, -1, "", 0, 0, MainMod.SunModY, MainMod.MoonModY); 381 | NetMessageMod.SyncPlayers(); 382 | } 383 | 384 | public static int GetPlayer(string player) 385 | { 386 | player = player.ToLower(); 387 | for (int i = 0; i < MainMod.Player.Length; i++) 388 | { 389 | if (MainMod.Player[i].name.ToLower() == player || player == "-" && string.IsNullOrWhiteSpace(MainMod.Player[i].name)) 390 | { 391 | return i; 392 | } 393 | } 394 | for (int i = 0; i < MainMod.Player.Length; i++) 395 | { 396 | if (MainMod.Player[i].name.ToLower().Contains(player)) 397 | { 398 | return i; 399 | } 400 | } 401 | return -1; 402 | } 403 | } 404 | } -------------------------------------------------------------------------------- /tMod v2/Terraria/NPCMod.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.Xna.Framework.Input; 6 | using System.Reflection; 7 | using tMod_v3; 8 | 9 | namespace Terraria 10 | { 11 | public class NPCMod 12 | { 13 | public static Type NPC; 14 | 15 | public static int MaxSpawns 16 | { 17 | get 18 | { 19 | return (int)NPC.GetField("maxSpawns", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null); 20 | } 21 | set 22 | { 23 | NPC.GetField("maxSpawns", BindingFlags.NonPublic | BindingFlags.Static).SetValue(null, value); 24 | } 25 | } 26 | 27 | public static int DefaultMaxSpawns 28 | { 29 | get 30 | { 31 | return (int)NPC.GetField("defaultMaxSpawns", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null); 32 | } 33 | set 34 | { 35 | NPC.GetField("defaultMaxSpawns", BindingFlags.NonPublic | BindingFlags.Static).SetValue(null, value); 36 | } 37 | } 38 | 39 | public static int SpawnRate 40 | { 41 | get 42 | { 43 | return (int)NPC.GetField("spawnRate", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null); 44 | } 45 | set 46 | { 47 | NPC.GetField("spawnRate", BindingFlags.NonPublic | BindingFlags.Static).SetValue(null, value); 48 | } 49 | } 50 | 51 | public static int DefaultSpawnRate 52 | { 53 | get 54 | { 55 | return (int)NPC.GetField("defaultSpawnRate", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null); 56 | } 57 | set 58 | { 59 | NPC.GetField("defaultSpawnRate", BindingFlags.NonPublic | BindingFlags.Static).SetValue(null, value); 60 | } 61 | } 62 | 63 | public static int NewNPC(int x, int y, int type, int start = 0) 64 | { 65 | return (int)NPC.GetMethod("NewNPC").Invoke(null, new object[] { x, y, type, start }); 66 | } 67 | 68 | public static void SpawnOnPlayer(int player, int id) 69 | { 70 | NPC.GetMethod("SpawnOnPlayer").Invoke(null, new object[] { player, id }); 71 | } 72 | 73 | public static bool SetDefaultsMod(dynamic mob, dynamic name) 74 | { 75 | if (XeedMod.cmobs != null) 76 | lock (XeedMod.cmobs) 77 | foreach (dynamic cm in XeedMod.cmobs) 78 | if (cm.name.Equals(name)) 79 | try 80 | { 81 | mob.SetDefaults(cm.GetID(), -1f); 82 | cm.ApplyTo(mob); 83 | return true; 84 | } 85 | catch (Exception ex) { Console.WriteLine(ex); } 86 | return false; 87 | } 88 | 89 | public static void NPCLootMod(dynamic npc) 90 | { 91 | if (XeedMod.cmobs != null) 92 | lock (XeedMod.cmobs) 93 | foreach (dynamic cm in XeedMod.cmobs) 94 | { 95 | if (cm.name.Equals(npc.name)) 96 | { 97 | foreach (KeyValuePair item in cm.drops) 98 | { 99 | int index = (int)ItemMod.Item.GetMethod("NewItem").Invoke(null, new object[] { (int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, 0, item.Value, true }); 100 | MainMod.Item[index].SetDefaults(item.Key); 101 | MainMod.Item[index].stack = item.Value; 102 | NetMessageMod.SendData(0x15, -1, -1, "", index); 103 | } 104 | return; 105 | } 106 | } 107 | } 108 | 109 | public static void SpawnNpc(string p) 110 | { 111 | if (MainMod.NetMode == 1) 112 | { 113 | NetMessageMod.SendData(0x19, MainMod.MyPlayer, -1, "/npc " + p, MainMod.MyPlayer, 255f, 255f, 255f); 114 | } 115 | else 116 | { 117 | dynamic npc = NPCMod.NPC.GetConstructor(new Type[0]).Invoke(new object[0]); 118 | npc.SetDefaults(p.ToProper()); 119 | if (npc.type < 1) 120 | { 121 | MainMod.NewText("NPC does not exist.", 255, 0, 0); 122 | return; 123 | } 124 | 125 | MouseState mouseState = Mouse.GetState(); 126 | int x = (int)(mouseState.X + MainMod.ScreenPosition.X); 127 | int y = (int)(mouseState.Y + MainMod.ScreenPosition.Y); 128 | int index = NPCMod.NewNPC(x, y, npc.type, 0); 129 | MainMod.Npc[index].target = MainMod.MyPlayer; 130 | 131 | if (index == 1000) 132 | { 133 | MainMod.NewText("There are too many NPCs!", 255, 0, 0); 134 | return; 135 | } 136 | 137 | MainMod.NewText("Spawned " + MainMod.Npc[index].name + ".", 175, 75, 255); 138 | } 139 | } 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /tMod v2/Terraria/NetMessageMod.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.IO; 6 | using tMod_v3; 7 | using System.ComponentModel; 8 | using System.Reflection; 9 | 10 | namespace Terraria 11 | { 12 | public class NetMessageMod 13 | { 14 | public static Type NetMessage; 15 | 16 | private static BackgroundWorker bgw = new BackgroundWorker(); 17 | private static List queue = new List(); 18 | 19 | static NetMessageMod() { bgw.DoWork += new DoWorkEventHandler(bgw_DoWork); bgw.WorkerSupportsCancellation = true; bgw.RunWorkerAsync(); } 20 | 21 | private static void bgw_DoWork(object sender, DoWorkEventArgs e) 22 | { 23 | while (!bgw.CancellationPending) 24 | { 25 | if (queue.Count > 0) 26 | { 27 | try 28 | { 29 | MethodBase meth = (MethodBase)queue[0][0]; 30 | meth.Invoke(null, (object[])queue[0][1]); 31 | } 32 | catch (Exception ex) { Console.WriteLine(DateTime.Now + " ASYNC"); Console.WriteLine(ex); } 33 | queue.RemoveAt(0); 34 | } 35 | else System.Threading.Thread.Sleep(5); 36 | } 37 | } 38 | 39 | static dynamic[] Buffer 40 | { 41 | get 42 | { 43 | return (dynamic[])NetMessage.GetField("buffer").GetValue(null); 44 | } 45 | set 46 | { 47 | NetMessage.GetField("buffer").SetValue(null, value); 48 | } 49 | } 50 | 51 | public static void FireAsync(System.Reflection.MethodBase method, object[] args) 52 | { 53 | queue.Add(new object[] { method, args }); 54 | } 55 | 56 | public static void SendData(int msgType, int remoteClient = -1, int ignoreClient = -1, string d = "", int e = 0, float f = 0f, float g = 0f, float h = 0f, int i = 0) 57 | { 58 | if (MainMod.Config.AsyncMode) FireAsync(NetMessage.GetMethod("SendData"), new object[] { msgType, remoteClient, ignoreClient, d, e, f, g, h, i }); 59 | else NetMessage.GetMethod("SendData").Invoke(null, new object[] { msgType, remoteClient, ignoreClient, d, e, f, g, h, i }); 60 | } 61 | 62 | public static void SendSection(int whoAmi, int sectionX, int sectionY) 63 | { 64 | if (MainMod.Config.AsyncMode) FireAsync(NetMessage.GetMethod("SendSection"), new object[] { whoAmi, sectionX, sectionY }); 65 | else NetMessage.GetMethod("SendSection").Invoke(null, new object[] { whoAmi, sectionX, sectionY }); 66 | } 67 | 68 | public static void SendTileSquare(int plr, int x, int y, int size) 69 | { 70 | if (MainMod.Config.AsyncMode) FireAsync(NetMessage.GetMethod("SendTileSquare"), new object[] { plr, x, y, size }); 71 | else try 72 | { 73 | NetMessage.GetMethod("SendTileSquare").Invoke(null, new object[] { plr, x, y, size }); 74 | } 75 | catch 76 | { 77 | Console.WriteLine("Failed to SendTileSquare. Too large?"); 78 | } 79 | } 80 | 81 | public static void SyncPlayers() 82 | { 83 | if (MainMod.Config.AsyncMode) FireAsync(NetMessage.GetMethod("syncPlayers"), new object[0]); 84 | else NetMessage.GetMethod("syncPlayers").Invoke(null, new object[0]); 85 | } 86 | 87 | public static void BroadcastMessage(string text) 88 | { 89 | BroadcastMessage(175, 75, 255, text); 90 | } 91 | 92 | public static void BroadcastMessage(byte r, byte g, byte b, string text, int from = 0xff) 93 | { 94 | MainMod.Notice(text); 95 | NetMessageMod.SendData(0x19, -1, -1, text, from, r, g, b); 96 | } 97 | 98 | public static void FlushBuffer(byte[] writeBuffer, int remoteClient = -1, int ignoreClient = -1) 99 | { 100 | if (MainMod.NetMode == 1) 101 | { 102 | if (NetplayMod.ClientSock.tcpClient.Connected) 103 | { 104 | try 105 | { 106 | NetplayMod.ClientSock.networkStream.BeginWrite(writeBuffer, 0, writeBuffer.Length, new Callback().ClientWriteCallback, NetplayMod.ClientSock.networkStream); 107 | } 108 | catch (Exception ex) 109 | { 110 | Console.WriteLine(ex); 111 | } 112 | } 113 | } 114 | else if (remoteClient < 0) 115 | { 116 | for (int i = 0; i < 0x100; i++) 117 | { 118 | if (((i != ignoreClient) && (NetMessageMod.Buffer[i].broadcast || ((NetplayMod.ServerSock[i].state >= 3) && (writeBuffer[4] == 10)))) && NetplayMod.ServerSock[i].tcpClient.Connected) 119 | { 120 | try 121 | { 122 | NetplayMod.ServerSock[i].networkStream.BeginWrite(writeBuffer, 0, writeBuffer.Length, new Callback(i).ServerWriteCallback, NetplayMod.ServerSock[i].networkStream); 123 | } 124 | catch (Exception exception) 125 | { 126 | Console.WriteLine("A net message exception occured"); 127 | using (StreamWriter writer = new StreamWriter("NetMessageException.txt", true)) 128 | { 129 | writer.WriteLine(DateTime.Now); 130 | writer.WriteLine(exception); 131 | writer.WriteLine(""); 132 | } 133 | } 134 | } 135 | } 136 | } 137 | else if (NetplayMod.ServerSock[remoteClient].tcpClient.Connected) 138 | { 139 | try 140 | { 141 | NetplayMod.ServerSock[remoteClient].networkStream.BeginWrite(writeBuffer, 0, writeBuffer.Length, new Callback(remoteClient).ServerWriteCallback, NetplayMod.ServerSock[remoteClient].networkStream); 142 | } 143 | catch (Exception exception) 144 | { 145 | MainMod.Log("A net message exception occured"); 146 | using (StreamWriter writer = new StreamWriter("NetMessageException.txt", true)) 147 | { 148 | writer.WriteLine(DateTime.Now); 149 | writer.WriteLine(exception); 150 | writer.WriteLine(""); 151 | } 152 | } 153 | } 154 | else 155 | { 156 | //Console.WriteLine("Client {0} is already disconnected", remoteClient); 157 | } 158 | } 159 | 160 | public static void GreetPlayerMod(int id) 161 | { 162 | Session.Sessions[id].SendLoginMessage(); 163 | } 164 | 165 | private class Callback 166 | { 167 | private int Index; 168 | 169 | public AsyncCallback ClientWriteCallback { get; private set; } 170 | public AsyncCallback ServerWriteCallback { get; private set; } 171 | 172 | public Callback(int index) 173 | : this() 174 | { 175 | Index = index; 176 | } 177 | 178 | public Callback() 179 | { 180 | ClientWriteCallback = new AsyncCallback(ClientWriteCallbackProc); 181 | ServerWriteCallback = new AsyncCallback(ServerWriteCallbackProc); 182 | } 183 | 184 | public void ClientWriteCallbackProc(IAsyncResult ar) 185 | { 186 | NetplayMod.ClientSock.ClientWriteCallBack(ar); 187 | } 188 | 189 | public void ServerWriteCallbackProc(IAsyncResult ar) 190 | { 191 | NetplayMod.ServerSock[Index].ServerWriteCallBack(ar); 192 | } 193 | } 194 | } 195 | } -------------------------------------------------------------------------------- /tMod v2/Terraria/NetplayMod.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Net; 6 | using System.IO; 7 | using System.Net.Sockets; 8 | 9 | namespace Terraria 10 | { 11 | public class NetplayMod 12 | { 13 | public static Type Netplay; 14 | 15 | public static dynamic[] ServerSock 16 | { 17 | get 18 | { 19 | return (dynamic[])Netplay.GetField("serverSock").GetValue(null); 20 | } 21 | set 22 | { 23 | Netplay.GetField("serverSock").SetValue(null, value); 24 | } 25 | } 26 | 27 | public static dynamic ClientSock 28 | { 29 | get 30 | { 31 | return (dynamic)Netplay.GetField("clientSock").GetValue(null); 32 | } 33 | set 34 | { 35 | Netplay.GetField("clientSock").SetValue(null, value); 36 | } 37 | } 38 | 39 | public static IPAddress ServerListenIP 40 | { 41 | get 42 | { 43 | return (IPAddress)Netplay.GetField("serverListenIP").GetValue(null); 44 | } 45 | set 46 | { 47 | Netplay.GetField("serverListenIP").SetValue(null, value); 48 | } 49 | } 50 | 51 | public static bool disconnect 52 | { 53 | get 54 | { 55 | return (bool)Netplay.GetField("disconnect").GetValue(null); 56 | } 57 | set 58 | { 59 | Netplay.GetField("disconnect").SetValue(null, value); 60 | } 61 | } 62 | 63 | public static string password 64 | { 65 | get 66 | { 67 | return (string)Netplay.GetField("password").GetValue(null); 68 | } 69 | set 70 | { 71 | Netplay.GetField("password").SetValue(null, value); 72 | } 73 | } 74 | 75 | public static int ServerPort 76 | { 77 | get 78 | { 79 | return (int)Netplay.GetField("serverPort").GetValue(null); 80 | } 81 | set 82 | { 83 | Netplay.GetField("serverPort").SetValue(null, value); 84 | } 85 | } 86 | 87 | public static void KickPlayer(byte player, string reason = "Kicked") 88 | { 89 | NetMessageMod.SendData(0x2, player, -1, reason, 0, 0f, 0f, 0f); 90 | MainMod.Notice(MainMod.Player[player].name + " was kicked: " + reason, MainMod.Config.ShowKickNotifications); 91 | } 92 | 93 | public static void AddBanIP(string ip) 94 | { 95 | string banFile = (string)Netplay.GetField("banFile").GetValue(null); 96 | using (StreamWriter writer = new StreamWriter(banFile, true)) 97 | { 98 | writer.WriteLine("//IP Ban"); 99 | writer.WriteLine(ip); 100 | } 101 | MainMod.Notice(ip + " was banned", MainMod.Config.ShowBanNotifications); 102 | } 103 | 104 | public static void RemBan(string ip) 105 | { 106 | string tempFile = Path.GetTempFileName(); 107 | string banFile = (string)Netplay.GetField("banFile").GetValue(null); 108 | 109 | using (var sr = new StreamReader(banFile)) 110 | { 111 | using (var sw = new StreamWriter(tempFile)) 112 | { 113 | string line; 114 | 115 | while ((line = sr.ReadLine()) != null) 116 | { 117 | if (line != ip) 118 | sw.WriteLine(line); 119 | } 120 | } 121 | } 122 | 123 | File.Delete(banFile); 124 | File.Move(tempFile, banFile); 125 | 126 | MainMod.Notice(ip + " was unbanned", MainMod.Config.ShowBanNotifications); 127 | } 128 | 129 | public static int GetSectionY(int n) 130 | { 131 | return (int)Netplay.GetMethod("GetSectionY").Invoke(null, new object[] { n }); 132 | } 133 | 134 | public static int GetSectionX(int n) 135 | { 136 | return (int)Netplay.GetMethod("GetSectionX").Invoke(null, new object[] { n }); 137 | } 138 | 139 | public static void AddBan(int target) 140 | { 141 | Netplay.GetMethod("AddBan").Invoke(null, new object[] { target }); 142 | MainMod.Notice(MainMod.Player[target].name + " was banned", MainMod.Config.ShowBanNotifications); 143 | } 144 | 145 | public static bool CheckBan(string ip) 146 | { 147 | return (bool)Netplay.GetMethod("CheckBan").Invoke(null, new object[] { ip }); 148 | } 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /tMod v2/Terraria/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.Xna.Framework; 6 | using tMod_v3; 7 | 8 | namespace Terraria 9 | { 10 | public class Program 11 | { 12 | public static void tMod(string[] args) 13 | { 14 | Console.Clear(); 15 | Console.WriteLine("------------------------------------------------"); 16 | Console.WriteLine("tMod successfully injected!"); 17 | Console.WriteLine(); 18 | Console.WriteLine("Starting server..."); 19 | dynamic main = tMod_v3.tMod.main.GetConstructor(new Type[0]).Invoke(new object[0]); 20 | MainMod.main = main; 21 | MainMod.LoadConfig(); 22 | Database.Initialize(); 23 | MainMod.DedServ(); 24 | Database.Disconnect(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tMod v2/Terraria/ProjectileMod.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace tMod_v3.Terraria 7 | { 8 | public class ProjectileMod 9 | { 10 | public static bool NewProjectileMod(float X, float Y, float SpeedX, float SpeedY, int Type, int Damage, float KnockBack, int Owner = 255) 11 | { 12 | Console.WriteLine("New projectile mod: {0}", Type); 13 | return true; 14 | } 15 | 16 | public static bool SetDefaultsMod(dynamic proj, dynamic type) 17 | { 18 | if (XeedMod.cprojs != null) 19 | lock (XeedMod.cprojs) 20 | foreach (dynamic cm in XeedMod.cprojs) 21 | if (cm.type == type) 22 | try 23 | { 24 | proj.SetDefaults(cm.GetID()); 25 | cm.ApplyTo(proj); 26 | return true; 27 | } 28 | catch (Exception ex) { Console.WriteLine(ex); } 29 | return false; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tMod v2/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /tMod v2/bin/Release/Config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 0.0.0.0 4 | 7778 5 | 100 6 | true 7 | world1.wld 8 | %CD%\tMod\Database.sdf 9 | 10 | Welcome to a tMod powered server! 11 | false 12 | false 13 | true 14 | false 15 | 10000000 16 | false 17 | false 18 | false 19 | 20 20 | false 21 | false 22 | false 23 | 5 24 | true 25 | false 26 | true 27 | true 28 | true 29 | true 30 | true 31 | true 32 | false 33 | true 34 | true 35 | true 36 | true 37 | true 38 | true 39 | true 40 | true 41 | true 42 | true 43 | true 44 | false 45 | false 46 | false 47 | false 48 | false 49 | true 50 | 4 51 | 1000 52 | tMod\Plugins 53 | tMod\Plugins\Data 54 | 55 | 56 | 127.0.0.1 57 | 94.171.244.143 58 | 59 | 60 | 61 | true 62 | true 63 | false 64 | false 65 | false 66 | true 67 | 0 68 | true 69 | true 70 | true 71 | true 72 | Disabled 73 | true 74 | true 75 | true 76 | 77 | 175 78 | 75 79 | 255 80 | 81 | 82 | 25 83 | 175 84 | 0 85 | 86 | 87 | 255 88 | 255 89 | 255 90 | 91 | 92 | 187 93 | 187 94 | 187 95 | 96 | false 97 | true 98 | true 99 | true 100 | -------------------------------------------------------------------------------- /tMod v2/bin/Release/Configure.bat: -------------------------------------------------------------------------------- 1 | "tMod v3.exe" -config -------------------------------------------------------------------------------- /tMod v2/bin/Release/Database.s3db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/tMod v2/bin/Release/Database.s3db -------------------------------------------------------------------------------- /tMod v2/bin/Release/Groups.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Default 5 | 6 | * 7 | 8 | 9 | 10 | 255 11 | 255 12 | 255 13 | 14 | Default 15 | false 16 | 17 | 18 | Default 19 | 20 | /mute 21 | /unmute 22 | /slience 23 | /ban 24 | /unban 25 | /pandon 26 | /kick 27 | /d 28 | /drop 29 | /i 30 | /item 31 | /give 32 | /npc 33 | /summon 34 | /mob 35 | /say 36 | /broadcast 37 | /b 38 | /moderate 39 | /allowbuild 40 | /allowbreak 41 | /allowbomb 42 | /allowwater 43 | /allowlava 44 | /allowspike 45 | /butcher 46 | /butcherall 47 | /kill 48 | /heal 49 | /hearts 50 | /giveheart 51 | /peace 52 | /peaceful 53 | /pvp 54 | /allowregister 55 | /day 56 | /night 57 | /dusk 58 | /noon 59 | /midnight 60 | /whois 61 | /ip 62 | /rollback 63 | /rban 64 | /check 65 | 66 | 67 | 68 | 255 69 | 255 70 | 255 71 | 72 | Default 73 | false 74 | 75 | 76 | Default 77 | 78 | /playing 79 | /about 80 | /list 81 | /who 82 | /p 83 | /party 84 | /me 85 | /help 86 | /motd 87 | /login 88 | /id 89 | /identify 90 | /register 91 | /spawn 92 | /getpos 93 | /mypos 94 | 95 | 96 | 97 | 255 98 | 255 99 | 255 100 | 101 | Default 102 | false 103 | 104 | 105 | Default 106 | 107 | /opme 108 | /changepw 109 | /changepassword 110 | /changelogin 111 | 112 | 113 | 114 | 255 115 | 255 116 | 255 117 | 118 | Default 119 | false 120 | 121 | 122 | 123 | Mod 124 | 125 | * 126 | 127 | Mod 128 | 129 | 255 130 | 80 131 | 0 132 | 133 | Default 134 | false 135 | 136 | 137 | Donator 138 | 139 | /heal 140 | 141 | Donator 142 | 143 | 255 144 | 80 145 | 0 146 | 147 | Default 148 | false 149 | 150 | 151 | -------------------------------------------------------------------------------- /tMod v2/bin/Release/LuaInterface.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/tMod v2/bin/Release/LuaInterface.dll -------------------------------------------------------------------------------- /tMod v2/bin/Release/Mono.Cecil.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/tMod v2/bin/Release/Mono.Cecil.dll -------------------------------------------------------------------------------- /tMod v2/bin/Release/System.Data.SQLite.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/tMod v2/bin/Release/System.Data.SQLite.dll -------------------------------------------------------------------------------- /tMod v2/bin/Release/TerrariaServer.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/tMod v2/bin/Release/TerrariaServer.exe -------------------------------------------------------------------------------- /tMod v2/bin/Release/lua/core/hook.lua: -------------------------------------------------------------------------------- 1 | local print = print 2 | local table = table 3 | local pairs = pairs 4 | local pcall = pcall 5 | local ErrorNoHalt = ErrorNoHalt 6 | 7 | module("hook") 8 | hooks = {} 9 | 10 | function Call(HookName, ...) 11 | local Hook = hooks[HookName] 12 | if not Hook then 13 | return 14 | end 15 | 16 | for HookUnique, HookFunction in pairs(Hook) do 17 | local call, error = pcall(HookFunction, ...) 18 | if not call then 19 | print("[Lua] Error with hook " .. HookUnique) 20 | print("[Lua] " .. error) 21 | Remove(HookName, HookUnique) 22 | end 23 | end 24 | end 25 | 26 | function Add(HookName, HookUnique, HookFunction) 27 | hooks[HookName] = hooks[HookName] or {} 28 | hooks[HookName][HookUnique] = HookFunction 29 | end 30 | 31 | function Remove(HookName, HookUnique) 32 | if not hooks[HookName] then 33 | return 34 | end 35 | hooks[HookName][HookUnique] = nil 36 | end 37 | 38 | -------------------------------------------------------------------------------- /tMod v2/bin/Release/lua51.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/tMod v2/bin/Release/lua51.dll -------------------------------------------------------------------------------- /tMod v2/bin/Release/tMod v3.exe.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /tMod v2/bin/Release/tMod v3.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/tMod v2/bin/Release/tMod v3.pdb -------------------------------------------------------------------------------- /tMod v2/bin/Release/tMod v3.vshost.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/tMod v2/bin/Release/tMod v3.vshost.exe -------------------------------------------------------------------------------- /tMod v2/bin/Release/tMod v3.vshost.exe.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /tMod v2/bin/Release/tMod v3.vshost.exe.manifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /tMod v2/bin/Release/tMod v3.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/tMod v2/bin/Release/tMod v3.zip -------------------------------------------------------------------------------- /tMod v2/bin/x86/tMod Config/tMod v3.exe.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /tMod v2/bin/x86/tMod Config/tMod v3.vshost.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/tMod v2/bin/x86/tMod Config/tMod v3.vshost.exe -------------------------------------------------------------------------------- /tMod v2/bin/x86/tMod Config/tMod v3.vshost.exe.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /tMod v2/obj/x86/Debug/DesignTimeResolveAssemblyReferences.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/tMod v2/obj/x86/Debug/DesignTimeResolveAssemblyReferences.cache -------------------------------------------------------------------------------- /tMod v2/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/tMod v2/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache -------------------------------------------------------------------------------- /tMod v2/obj/x86/Debug/GenerateResource.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/tMod v2/obj/x86/Debug/GenerateResource.read.1.tlog -------------------------------------------------------------------------------- /tMod v2/obj/x86/Debug/GenerateResource.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/tMod v2/obj/x86/Debug/GenerateResource.write.1.tlog -------------------------------------------------------------------------------- /tMod v2/obj/x86/Debug/ResolveAssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/tMod v2/obj/x86/Debug/ResolveAssemblyReference.cache -------------------------------------------------------------------------------- /tMod v2/obj/x86/Debug/TempPE/Resources.Files.DatabaseDataSet.Designer.cs.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/tMod v2/obj/x86/Debug/TempPE/Resources.Files.DatabaseDataSet.Designer.cs.dll -------------------------------------------------------------------------------- /tMod v2/obj/x86/Debug/tMod v2.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | c:\documents and settings\administrator\my documents\visual studio 2010\Projects\tMod v2\tMod v2\obj\x86\Debug\ResolveAssemblyReference.cache 2 | c:\documents and settings\administrator\my documents\visual studio 2010\Projects\tMod v2\tMod v2\bin\Debug\tMod v2.exe 3 | c:\documents and settings\administrator\my documents\visual studio 2010\Projects\tMod v2\tMod v2\bin\Debug\tMod v2.pdb 4 | c:\documents and settings\administrator\my documents\visual studio 2010\Projects\tMod v2\tMod v2\bin\Debug\Mono.Cecil.dll 5 | c:\documents and settings\administrator\my documents\visual studio 2010\Projects\tMod v2\tMod v2\obj\x86\Debug\tMod v2.exe 6 | c:\documents and settings\administrator\my documents\visual studio 2010\Projects\tMod v2\tMod v2\obj\x86\Debug\tMod v2.pdb 7 | C:\Documents and Settings\Administrator\My Documents\Visual Studio 2010\Projects\tMod v2\tMod v2\bin\Debug\LuaInterface.dll 8 | C:\Documents and Settings\Administrator\My Documents\Visual Studio 2010\Projects\tMod v2\tMod v2\bin\Debug\lua51.dll 9 | C:\Documents and Settings\Administrator\My Documents\Visual Studio 2010\Projects\tMod v2\tMod v2\obj\x86\Debug\tMod_v2.Resources.Default.resources 10 | C:\Documents and Settings\Administrator\My Documents\Visual Studio 2010\Projects\tMod v2\tMod v2\obj\x86\Debug\GenerateResource.read.1.tlog 11 | C:\Documents and Settings\Administrator\My Documents\Visual Studio 2010\Projects\tMod v2\tMod v2\obj\x86\Debug\GenerateResource.write.1.tlog 12 | C:\Documents and Settings\Administrator\My Documents\Visual Studio 2010\Projects\tMod v2\tMod v2\bin\Debug\tMod v2.exe.config 13 | C:\Documents and Settings\Administrator\My Documents\Visual Studio 2010\Projects\tMod v2\tMod v2\obj\x86\Debug\tMod v2.g.resources 14 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\bin\Debug\tMod v2.exe.config 15 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\obj\x86\Debug\tMod v2.exe 16 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\obj\x86\Debug\tMod v2.pdb 17 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\bin\Debug\tMod v2.exe 18 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\bin\Debug\tMod v2.pdb 19 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\bin\Debug\LuaInterface.dll 20 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\bin\Debug\lua51.dll 21 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\obj\x86\Debug\ResolveAssemblyReference.cache 22 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\obj\x86\Debug\tMod v2.g.resources 23 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\obj\x86\Debug\tMod_v2.Resources.Default.resources 24 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\obj\x86\Debug\GenerateResource.read.1.tlog 25 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\obj\x86\Debug\GenerateResource.write.1.tlog 26 | C:\Documents and Settings\Administrator\My Documents\tMod v3\tMod v2\bin\Debug\tMod v2.exe.config 27 | C:\Documents and Settings\Administrator\My Documents\tMod v3\tMod v2\obj\x86\Debug\tMod v2.exe 28 | C:\Documents and Settings\Administrator\My Documents\tMod v3\tMod v2\obj\x86\Debug\tMod v2.pdb 29 | -------------------------------------------------------------------------------- /tMod v2/obj/x86/Debug/tMod v2.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/tMod v2/obj/x86/Debug/tMod v2.exe -------------------------------------------------------------------------------- /tMod v2/obj/x86/Debug/tMod v2.g.resources: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/tMod v2/obj/x86/Debug/tMod v2.g.resources -------------------------------------------------------------------------------- /tMod v2/obj/x86/Debug/tMod v2.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/tMod v2/obj/x86/Debug/tMod v2.pdb -------------------------------------------------------------------------------- /tMod v2/obj/x86/Debug/tMod v3.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\bin\Debug\tMod v3.exe.config 2 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\bin\Debug\tMod v3.exe 3 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\bin\Debug\tMod v3.pdb 4 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\bin\Debug\LuaInterface.dll 5 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\bin\Debug\Mono.Cecil.dll 6 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\bin\Debug\lua51.dll 7 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\obj\x86\Debug\ResolveAssemblyReference.cache 8 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\obj\x86\Debug\tMod v3.g.resources 9 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\obj\x86\Debug\tMod_v3.Resources.Default.resources 10 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\obj\x86\Debug\GenerateResource.read.1.tlog 11 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\obj\x86\Debug\GenerateResource.write.1.tlog 12 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\obj\x86\Debug\tMod v3.exe 13 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\obj\x86\Debug\tMod v3.pdb 14 | C:\Documents and Settings\Administrator\My Documents\tMod v3\tMod v2\bin\Debug\tMod v3.exe.config 15 | C:\Documents and Settings\Administrator\My Documents\tMod v3\tMod v2\obj\x86\Debug\tMod v3.exe 16 | C:\Documents and Settings\Administrator\My Documents\tMod v3\tMod v2\obj\x86\Debug\tMod v3.pdb 17 | C:\Documents and Settings\Administrator\My Documents\tMod v3\tMod v2\bin\Debug\tMod v3.exe 18 | C:\Documents and Settings\Administrator\My Documents\tMod v3\tMod v2\bin\Debug\tMod v3.pdb 19 | C:\Documents and Settings\Administrator\My Documents\tMod v3\tMod v2\bin\Debug\LuaInterface.dll 20 | C:\Documents and Settings\Administrator\My Documents\tMod v3\tMod v2\bin\Debug\Mono.Cecil.dll 21 | C:\Documents and Settings\Administrator\My Documents\tMod v3\tMod v2\bin\Debug\System.Data.SQLite.dll 22 | C:\Documents and Settings\Administrator\My Documents\tMod v3\tMod v2\bin\Debug\lua51.dll 23 | C:\Documents and Settings\Administrator\My Documents\tMod v3\tMod v2\obj\x86\Debug\ResolveAssemblyReference.cache 24 | -------------------------------------------------------------------------------- /tMod v2/obj/x86/Debug/tMod v3.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/tMod v2/obj/x86/Debug/tMod v3.exe -------------------------------------------------------------------------------- /tMod v2/obj/x86/Debug/tMod v3.g.resources: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/tMod v2/obj/x86/Debug/tMod v3.g.resources -------------------------------------------------------------------------------- /tMod v2/obj/x86/Debug/tMod v3.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/tMod v2/obj/x86/Debug/tMod v3.pdb -------------------------------------------------------------------------------- /tMod v2/obj/x86/Debug/tMod_v2.Resources.Default.resources: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/tMod v2/obj/x86/Debug/tMod_v2.Resources.Default.resources -------------------------------------------------------------------------------- /tMod v2/obj/x86/Debug/tMod_v3.Resources.Default.resources: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/tMod v2/obj/x86/Debug/tMod_v3.Resources.Default.resources -------------------------------------------------------------------------------- /tMod v2/obj/x86/Release/DesignTimeResolveAssemblyReferences.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/tMod v2/obj/x86/Release/DesignTimeResolveAssemblyReferences.cache -------------------------------------------------------------------------------- /tMod v2/obj/x86/Release/DesignTimeResolveAssemblyReferencesInput.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/tMod v2/obj/x86/Release/DesignTimeResolveAssemblyReferencesInput.cache -------------------------------------------------------------------------------- /tMod v2/obj/x86/Release/ResolveAssemblyReference.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/tMod v2/obj/x86/Release/ResolveAssemblyReference.cache -------------------------------------------------------------------------------- /tMod v2/obj/x86/Release/TempPE/Resources.Files.DatabaseDataSet.Designer.cs.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/tMod v2/obj/x86/Release/TempPE/Resources.Files.DatabaseDataSet.Designer.cs.dll -------------------------------------------------------------------------------- /tMod v2/obj/x86/Release/tMod v2.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\bin\Release\tMod v2.exe.config 2 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\obj\x86\Release\ResolveAssemblyReference.cache 3 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\obj\x86\Release\tMod v2.g.resources 4 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\obj\x86\Release\tMod_v2.Resources.Default.resources 5 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\obj\x86\Release\GenerateResource.read.1.tlog 6 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\obj\x86\Release\GenerateResource.write.1.tlog 7 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\bin\Release\tMod v2.exe 8 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\bin\Release\tMod v2.pdb 9 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\bin\Release\LuaInterface.dll 10 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\bin\Release\Mono.Cecil.dll 11 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\bin\Release\lua51.dll 12 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\obj\x86\Release\tMod v2.exe 13 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\obj\x86\Release\tMod v2.pdb 14 | -------------------------------------------------------------------------------- /tMod v2/obj/x86/Release/tMod v3.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\bin\Release\LuaInterface.dll 2 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\bin\Release\Mono.Cecil.dll 3 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\bin\Release\lua51.dll 4 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\obj\x86\Release\ResolveAssemblyReference.cache 5 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\obj\x86\Release\GenerateResource.read.1.tlog 6 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\obj\x86\Release\GenerateResource.write.1.tlog 7 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\bin\Release\tMod v3.exe.config 8 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\bin\Release\tMod v3.exe 9 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\bin\Release\tMod v3.pdb 10 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\obj\x86\Release\tMod v3.g.resources 11 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\obj\x86\Release\tMod_v3.Resources.Default.resources 12 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\obj\x86\Release\tMod v3.exe 13 | C:\Documents and Settings\Administrator\My Documents\tMod v2\tMod v2\obj\x86\Release\tMod v3.pdb 14 | C:\Documents and Settings\Administrator\My Documents\tMod v3\tMod v2\bin\Release\tMod v3.exe.config 15 | C:\Documents and Settings\Administrator\My Documents\tMod v3\tMod v2\obj\x86\Release\tMod v3.exe 16 | C:\Documents and Settings\Administrator\My Documents\tMod v3\tMod v2\obj\x86\Release\tMod v3.pdb 17 | C:\Documents and Settings\Administrator\My Documents\tMod v3\tMod v2\bin\Release\tMod v3.exe 18 | C:\Documents and Settings\Administrator\My Documents\tMod v3\tMod v2\bin\Release\tMod v3.pdb 19 | C:\Documents and Settings\Administrator\My Documents\tMod v3\tMod v2\bin\Release\LuaInterface.dll 20 | C:\Documents and Settings\Administrator\My Documents\tMod v3\tMod v2\bin\Release\Mono.Cecil.dll 21 | C:\Documents and Settings\Administrator\My Documents\tMod v3\tMod v2\bin\Release\lua51.dll 22 | C:\Documents and Settings\Administrator\My Documents\tMod v3\tMod v2\bin\Release\System.Data.SQLite.dll 23 | C:\Documents and Settings\Administrator\My Documents\tMod v3\tMod v2\obj\x86\Release\ResolveAssemblyReference.cache 24 | -------------------------------------------------------------------------------- /tMod v2/obj/x86/Release/tMod v3.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/tMod v2/obj/x86/Release/tMod v3.exe -------------------------------------------------------------------------------- /tMod v2/obj/x86/Release/tMod v3.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/tMod v2/obj/x86/Release/tMod v3.pdb -------------------------------------------------------------------------------- /tMod v2/obj/x86/tMod Config/DesignTimeResolveAssemblyReferencesInput.cache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jexius/tMod/e13ebfcd303ce39f8f82c803130d40bd46f22601/tMod v2/obj/x86/tMod Config/DesignTimeResolveAssemblyReferencesInput.cache -------------------------------------------------------------------------------- /tMod v2/obj/x86/tMod Config/tMod v3.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | C:\Documents and Settings\Administrator\My Documents\tMod v3\tMod v2\bin\x86\tMod Config\tMod v3.exe.config 2 | -------------------------------------------------------------------------------- /tMod v2/tMod v2.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | x86 6 | 8.0.30703 7 | 2.0 8 | {8535C7E2-C7C7-4363-B186-9D2FE5CD99E0} 9 | Exe 10 | Properties 11 | tMod_v2 12 | tMod v2 13 | v4.0 14 | Client 15 | 512 16 | publish\ 17 | true 18 | Disk 19 | false 20 | Foreground 21 | 7 22 | Days 23 | false 24 | false 25 | true 26 | 0 27 | 1.0.0.%2a 28 | false 29 | false 30 | true 31 | 32 | 33 | x86 34 | true 35 | full 36 | false 37 | bin\Debug\ 38 | DEBUG;TRACE 39 | prompt 40 | 4 41 | 42 | 43 | x86 44 | pdbonly 45 | true 46 | bin\Release\ 47 | TRACE 48 | prompt 49 | 4 50 | 51 | 52 | 53 | False 54 | Lua\LuaInterface.dll 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | ..\..\..\..\..\..\All Users\Documents\My Pictures\Sample Pictures\tinamoh\trunk\Libraries\Mono.Cecil.dll 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | True 105 | True 106 | Settings.settings 107 | 108 | 109 | 110 | 111 | True 112 | True 113 | DatabaseDataSet.xsd 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | Always 138 | 139 | 140 | 141 | 142 | 143 | SettingsSingleFileGenerator 144 | Settings.Designer.cs 145 | 146 | 147 | DatabaseDataSet.xsd 148 | 149 | 150 | MSDataSetGenerator 151 | DatabaseDataSet.Designer.cs 152 | Designer 153 | 154 | 155 | DatabaseDataSet.xsd 156 | 157 | 158 | 159 | 160 | False 161 | Microsoft .NET Framework 4 Client Profile %28x86 and x64%29 162 | true 163 | 164 | 165 | False 166 | .NET Framework 3.5 SP1 Client Profile 167 | false 168 | 169 | 170 | False 171 | .NET Framework 3.5 SP1 172 | false 173 | 174 | 175 | False 176 | SQL Server Compact 3.5 SP2 177 | true 178 | 179 | 180 | False 181 | Windows Installer 3.1 182 | true 183 | 184 | 185 | 186 | 193 | -------------------------------------------------------------------------------- /tMod v2/tMod v2.csproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | en-US 11 | false 12 | 13 | -------------------------------------------------------------------------------- /tMod v2/tMod v3.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | x86 6 | 8.0.30703 7 | 2.0 8 | {8535C7E2-C7C7-4363-B186-9D2FE5CD99E0} 9 | Exe 10 | Properties 11 | tMod_v3 12 | tMod v3 13 | v4.0 14 | Client 15 | 512 16 | publish\ 17 | true 18 | Disk 19 | false 20 | Foreground 21 | 7 22 | Days 23 | false 24 | false 25 | true 26 | 0 27 | 1.0.0.%2a 28 | false 29 | false 30 | true 31 | 32 | 33 | x86 34 | true 35 | full 36 | false 37 | bin\Debug\ 38 | DEBUG;TRACE 39 | prompt 40 | 4 41 | 42 | 43 | x86 44 | pdbonly 45 | true 46 | bin\Release\ 47 | TRACE 48 | prompt 49 | 4 50 | 51 | 52 | bin\x86\tMod Config\ 53 | TRACE 54 | true 55 | pdbonly 56 | x86 57 | prompt 58 | false 59 | false 60 | 61 | 62 | 63 | False 64 | Lua\LuaInterface.dll 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | ..\Libraries\Mono.Cecil.dll 78 | 79 | 80 | 81 | 82 | False 83 | ..\..\tMod v2\Libraries\System.Data.SQLite.dll 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | True 123 | True 124 | Settings.settings 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | SettingsSingleFileGenerator 148 | Settings.Designer.cs 149 | 150 | 151 | 152 | 153 | False 154 | Microsoft .NET Framework 4 Client Profile %28x86 and x64%29 155 | true 156 | 157 | 158 | False 159 | .NET Framework 3.5 SP1 Client Profile 160 | false 161 | 162 | 163 | False 164 | .NET Framework 3.5 SP1 165 | false 166 | 167 | 168 | False 169 | SQL Server Compact 3.5 SP2 170 | true 171 | 172 | 173 | False 174 | Windows Installer 3.1 175 | true 176 | 177 | 178 | 179 | 186 | -------------------------------------------------------------------------------- /tMod v2/tMod v3.csproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | en-US 11 | false 12 | 13 | -------------------------------------------------------------------------------- /tMod v2/tMod.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Mono.Cecil; 6 | using Mono.Cecil.Cil; 7 | using System.Reflection; 8 | using System.IO; 9 | using System.Diagnostics; 10 | using LuaInterface; 11 | using System.Threading; 12 | using Terraria; 13 | 14 | namespace tMod_v3 15 | { 16 | public class tMod 17 | { 18 | public static Type worldGen; 19 | public static Type main; 20 | AssemblyDefinition terrariaAsm; 21 | ModuleDefinition module; 22 | ModuleDefinition tMod2; 23 | MemoryStream stream = new MemoryStream(); 24 | 25 | public void writeLine(string write) 26 | { 27 | Console.WriteLine(write); 28 | } 29 | 30 | public void inject() 31 | { 32 | Load(); 33 | 34 | module.Types.Remove(module.Types["Terraria.ProgramServer"]); 35 | module.Inject(tMod2.Types["Terraria.Program"]); 36 | terrariaAsm.EntryPoint = getMethod(module.Types["Terraria.Program"], "tMod"); 37 | 38 | modifyMain(); 39 | ModifyMessageBuffer(); 40 | ModifyNetMessage(); 41 | ModifyNetplay(); 42 | 43 | Write(); 44 | 45 | Assembly asm = System.Reflection.Assembly.Load(stream.GetBuffer()); 46 | worldGen = asm.GetType("Terraria.WorldGen"); 47 | main = asm.GetType("Terraria.Main"); 48 | 49 | ItemMod.Item = asm.GetType("Terraria.Item"); 50 | MainMod.main = asm.GetType("Terraria.Main"); 51 | MessageBufferMod.messageBuffer = asm.GetType("Terraria.messageBuffer"); 52 | NetMessageMod.NetMessage = asm.GetType("Terraria.NetMessage"); 53 | NetplayMod.Netplay = asm.GetType("Terraria.Netplay"); 54 | NPCMod.NPC = asm.GetType("Terraria.NPC"); 55 | WorldGenMod.WorldGen = asm.GetType("Terraria.WorldGen"); 56 | 57 | try 58 | { 59 | asm.EntryPoint.Invoke(null, new object[] { new string[0] }); 60 | } 61 | catch (Exception e) 62 | { 63 | Console.WriteLine(e.ToString()); 64 | Console.WriteLine("Program crashed..."); 65 | } 66 | 67 | Console.ReadKey(); 68 | } 69 | 70 | private void Write() 71 | { 72 | AssemblyFactory.SaveAssembly(terrariaAsm, stream); 73 | } 74 | 75 | private void Load() 76 | { 77 | Console.WriteLine("Loading original Terraria assembly"); 78 | tMod2 = AssemblyFactory.GetAssembly(System.Reflection.Assembly.GetExecutingAssembly().Location).MainModule; 79 | while (true) 80 | { 81 | try 82 | { 83 | string Path = Environment.CurrentDirectory + @"\"; 84 | terrariaAsm = AssemblyFactory.GetAssembly(Path + "TerrariaServer.exe"); 85 | module = terrariaAsm.MainModule; 86 | break; 87 | } 88 | catch 89 | { 90 | Console.WriteLine("TerrariaServer.exe couldn't be found in the same directory as tModServer.exe"); 91 | Console.WriteLine("Please move tMod v3.exe into the same directory as the TerrariaServer.exe"); 92 | Console.ReadKey(); 93 | } 94 | } 95 | } 96 | 97 | public void ModifyNetplay() 98 | { 99 | ExceptionHandler exh = new ExceptionHandler(ExceptionHandlerType.Catch); 100 | TypeReference exception = module.Import(typeof(Exception)); 101 | VariableDefinition ex = new VariableDefinition(exception); 102 | MethodDefinition listenForClients = getMethod(module.Types["Terraria.Netplay"], "ListenForClients"); 103 | CilWorker cil = listenForClients.Body.CilWorker; 104 | Instruction instr = listenForClients.Body.Instructions[listenForClients.Body.Instructions.Count - 1]; 105 | listenForClients.Body.Variables.Add(ex); 106 | exh.TryStart = listenForClients.Body.Instructions[0]; 107 | exh.CatchType = exception; 108 | cil.InsertAfter(instr, instr = exh.TryEnd = exh.HandlerStart = cil.Create(OpCodes.Stloc, ex)); 109 | cil.InsertAfter(instr, instr = cil.Create(OpCodes.Ldloc, ex)); 110 | cil.InsertAfter(instr, instr = cil.Create(OpCodes.Call, module.Import(typeof(Console).GetMethod("WriteLine", new Type[] { typeof(object) })))); 111 | cil.InsertAfter(instr, instr = exh.HandlerEnd = cil.Create(OpCodes.Ret)); 112 | listenForClients.Body.ExceptionHandlers.Add(exh); 113 | } 114 | 115 | public void modifyMain() 116 | { 117 | Console.WriteLine("Modifying Terraria.Main"); 118 | TypeDefinition type = module.Types["Terraria.Main"]; 119 | MethodDefinition update = getMethod(type, "Update"); 120 | MethodReference updateMod = module.Import(typeof(MainMod).GetMethod("UpdateMod")); 121 | MethodDefinition startDedInput = getMethod(type, "startDedInput"); 122 | MethodReference startDedInputMod = module.Import(typeof(MainMod).GetMethod("StartDedInputMod")); 123 | 124 | CilWorker cil; 125 | 126 | // Call UpdateMod 127 | cil = update.Body.CilWorker; 128 | cil.InsertBefore(update.Body.Instructions[0], cil.Create(OpCodes.Call, updateMod)); 129 | 130 | // Call StartDedInputMod 131 | cil = startDedInput.Body.CilWorker; 132 | cil.InsertBefore(startDedInput.Body.Instructions[startDedInput.Body.Instructions.Count - 1], cil.Create(OpCodes.Call, startDedInputMod)); 133 | } 134 | 135 | private void ModifyNetMessage() 136 | { 137 | Console.WriteLine("Modifying Terraria.NetMessage"); 138 | TypeDefinition type = module.Types["Terraria.NetMessage"]; 139 | MethodDefinition greetPlayer = getMethod(type, "greetPlayer"); 140 | MethodReference greetPlayerMod = module.Import(typeof(NetMessageMod).GetMethod("GreetPlayerMod")); 141 | MethodDefinition SendData = getMethod(type, "SendData"); 142 | MethodReference SendDataTrick = module.Import(typeof(NetMessageMod).GetMethod("SendDataTrick")); 143 | 144 | CilWorker cil = greetPlayer.Body.CilWorker; 145 | Instruction instr = greetPlayer.Body.Instructions[greetPlayer.Body.Instructions.Count - 1]; 146 | 147 | cil.InsertBefore(instr, cil.Create(OpCodes.Ldarg_0)); 148 | cil.InsertBefore(instr, cil.Create(OpCodes.Call, greetPlayerMod)); 149 | 150 | /*cil = SendData.Body.CilWorker; 151 | List ins = new List(); 152 | foreach (Instruction str in SendData.Body.Instructions) 153 | { 154 | if (str.Operand != null && str.Operand.ToString().Contains("BeginWrite")) 155 | { 156 | ins.Add(str); 157 | } 158 | } 159 | foreach (Instruction str in ins) 160 | { 161 | cil.Replace(str, cil.Create(OpCodes.Callvirt, SendDataTrick)); 162 | }*/ 163 | } 164 | 165 | private void ModifyMessageBuffer() 166 | { 167 | Console.WriteLine("Modifying Terraria.messageBuffer"); 168 | TypeDefinition type = module.Types["Terraria.messageBuffer"]; 169 | MethodDefinition getData = getMethod(type, "GetData"); 170 | MethodReference getDataMod = module.Import(typeof(MessageBufferMod).GetMethod("GetDataMod")); 171 | 172 | CilWorker cil = getData.Body.CilWorker; 173 | Instruction instr = getData.Body.Instructions[0]; 174 | cil.InsertBefore(instr, cil.Create(OpCodes.Ldarg_0)); 175 | cil.InsertBefore(instr, cil.Create(OpCodes.Ldarg_1)); 176 | cil.InsertBefore(instr, cil.Create(OpCodes.Ldarg_2)); 177 | cil.InsertBefore(instr, cil.Create(OpCodes.Call, getDataMod)); 178 | cil.InsertBefore(instr, cil.Create(OpCodes.Brfalse, getData.Body.Instructions[getData.Body.Instructions.Count - 1])); 179 | } 180 | 181 | private static dynamic getMethod(dynamic type, dynamic name, int param = -1) 182 | { 183 | for (int i = 0; i < type.Methods.Count; i++) 184 | { 185 | if (type.Methods[i].Name == name) 186 | { 187 | if (param >= 0 && type.Methods[i].Parameters.Count == param) 188 | return type.Methods[i]; 189 | else return type.Methods[i]; 190 | } 191 | } 192 | throw new Exception("Method " + name + " does not exist."); 193 | } 194 | } 195 | 196 | public static class XeedMod 197 | { 198 | private static dynamic ItemFile { get { return MainMod.Config.PluginDataDirectory + "\\ItemData.txt"; } } 199 | 200 | public static dynamic GetObj(dynamic list, dynamic name) 201 | { 202 | foreach (dynamic obj in list) if (String.Equals(obj.name, name)) return obj; 203 | return null; 204 | } 205 | 206 | static XeedMod() 207 | { 208 | MainMod.LoadConfig(); 209 | items = new List(); 210 | if (File.Exists(ItemFile)) 211 | { 212 | CustomItem ci = null; 213 | foreach (string line in File.ReadAllLines(ItemFile)) 214 | if (line.StartsWith("[") && line.EndsWith("]")) 215 | { 216 | if (ci != null) items.Add(ci); 217 | ci = new CustomItem(line.Remove(line.Length - 1, 1).Remove(0, 1)); 218 | } 219 | else 220 | { 221 | string[] data = line.Split(new char[] { '=' }, 2); 222 | if (data[0].Equals("baseId")) ci.iId = int.Parse(data[1]); 223 | else if (data[0].Equals("name")) ci.name = data[1]; 224 | else if (data[0].Equals("scope-effect")) ci.scope = bool.Parse(data[1]); 225 | else if (data[0].Equals("texture-name") && !String.IsNullOrWhiteSpace(data[1])) 226 | ci.ctex = ImageToByte2(System.Drawing.Image.FromFile(MainMod.Config.PluginDataDirectory + @"\Textures\" + data[1])); 227 | else if (!data[0].StartsWith("#")) ci.AddField(data[0].Split(':'), data[1]); 228 | } 229 | if (ci != null) items.Add(ci); 230 | } 231 | } 232 | 233 | private static dynamic ImageToByte2(dynamic img) 234 | { 235 | dynamic byteArray = new byte[0]; 236 | using (dynamic stream = new MemoryStream()) 237 | { 238 | img.Save(stream, System.Drawing.Imaging.ImageFormat.Png); 239 | stream.Close(); 240 | byteArray = stream.ToArray(); 241 | } 242 | return byteArray; 243 | } 244 | 245 | internal static dynamic cmobs { get { return CPlugin == null ? null : CPlugin.mobs; } } 246 | 247 | internal static dynamic cprojs { get { return CPlugin == null ? null : CPlugin.projs; } } 248 | 249 | internal static dynamic GetItems() 250 | { 251 | if (CPlugin != null) return CPlugin.items; 252 | else return items; 253 | } 254 | 255 | internal static dynamic items; 256 | 257 | internal static dynamic CPlugin { get { return PluginManager.GetPlugin("CustomPlug"); } } 258 | 259 | internal static dynamic GetItemName(dynamic itemId) 260 | { 261 | dynamic obj2 = ItemMod.Item.GetConstructor(new Type[0]).Invoke(new object[0]); 262 | obj2.SetDefaults(itemId, true); 263 | return obj2.name; 264 | } 265 | } 266 | } 267 | --------------------------------------------------------------------------------