Changeset 75
- Timestamp:
- Jul 16, 2014, 7:36:46 PM (10 years ago)
- Location:
- binary-improvements
- Files:
-
- 5 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/7dtd-server-fixes.csproj
r74 r75 8 8 <ProjectGuid>{81DA7F87-1A66-4920-AADA-6EAF1971F8D0}</ProjectGuid> 9 9 <OutputType>Library</OutputType> 10 <RootNamespace>dtdserverfixes</RootNamespace>11 10 <AssemblyName>7dtd-server-fixes</AssemblyName> 12 11 </PropertyGroup> … … 38 37 <Compile Include="src\AllocsNetTelnetServer.cs" /> 39 38 <Compile Include="src\AssemblyInfo.cs" /> 39 <Compile Include="src\AllocsTelnetConnection.cs" /> 40 <Compile Include="src\TelnetCommands\GetTime.cs" /> 41 <Compile Include="src\AllocsRequestToSpawnPlayer.cs" /> 42 <Compile Include="src\TelnetCommands\ListPlayersExtended.cs" /> 40 43 </ItemGroup> 41 44 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> 42 45 <ItemGroup> 43 46 <Folder Include="src\" /> 47 <Folder Include="src\TelnetCommands\" /> 44 48 </ItemGroup> 45 49 </Project> -
binary-improvements/7dtd-server-fixes/7dtd-server-fixes.userprefs
r74 r75 1 1 <Properties> 2 2 <MonoDevelop.Ide.Workspace ActiveConfiguration="Release" /> 3 <MonoDevelop.Ide.Workbench ActiveDocument="src/Allocs NetTelnetServer.cs">3 <MonoDevelop.Ide.Workbench ActiveDocument="src/AllocsTelnetCommand.cs"> 4 4 <Files> 5 5 <File FileName="src/AssemblyInfo.cs" Line="1" Column="1" /> 6 <File FileName="src/AllocsNetTelnetServer.cs" Line="37" Column="5" /> 6 <File FileName="src/AllocsNetTelnetServer.cs" Line="40" Column="101" /> 7 <File FileName="src/AllocsTelnetConnection.cs" Line="16" Column="34" /> 8 <File FileName="src/AllocsTelnetCommand.cs" Line="3" Column="4" /> 7 9 </Files> 8 10 </MonoDevelop.Ide.Workbench> -
binary-improvements/7dtd-server-fixes/src/AllocsNetTelnetServer.cs
r74 r75 9 9 public class AllocsNetTelnetServer 10 10 { 11 private class Connection 12 { 13 private bool authenticated = false; 14 private TcpClient client; 15 private NetworkStream stream; 16 private string lineBuffer = string.Empty; 17 private EndPoint endpoint; 18 19 public Connection (TcpClient client) 20 { 21 this.client = client; 22 this.stream = client.GetStream (); 23 this.endpoint = client.Client.RemoteEndPoint; 24 } 25 26 public EndPoint GetEndPoint () 27 { 28 return endpoint; 29 } 30 31 private void WriteByte (byte v) 32 { 33 if (!IsClosed () && stream.CanWrite) { 34 stream.WriteByte (v); 35 } 36 } 37 38 public void WriteLine (string s) 39 { 40 if (!IsClosed () && stream.CanWrite) { 41 for (int i = 0; i < s.Length; i++) { 42 WriteByte ((byte)s [i]); 43 } 44 WriteByte (10); 45 } 46 } 47 48 public void Close () 49 { 50 if (client != null) 51 client.Close (); 52 client = null; 53 } 54 55 public bool IsClosed () 56 { 57 if (client != null && !client.Connected) { 58 Log.Out ("Telnet connection interrupted: " + endpoint); 59 } 60 return (client == null) || (!client.Connected); 61 } 62 63 public bool IsAuthenticated () 64 { 65 return !authEnabled || authenticated; 66 } 67 68 public void SetAuthenticated () 69 { 70 authenticated = true; 71 } 72 73 public bool Read () 74 { 75 while (!IsClosed() && stream.CanRead && stream.DataAvailable) { 76 int b = stream.ReadByte (); 77 if (b == '\r' || b == '\n') { 78 if (lineBuffer.Length > 0) 79 return true; 80 } else { 81 lineBuffer += (char)b; 82 } 83 } 84 return false; 85 } 86 87 public string GetLine () 88 { 89 string res = lineBuffer; 90 lineBuffer = string.Empty; 91 return res; 92 } 93 } 94 95 private static cl004c console = null; 11 private static ConsoleSdtd console = null; 96 12 private static Thread telnetThread = null; 97 13 private static TcpListener listener = null; 98 14 private static bool closed = false; 99 15 private static bool authEnabled = false; 100 private static List< Connection> conns = new List<Connection> ();16 private static List<AllocsTelnetConnection> conns = new List<AllocsTelnetConnection> (); 101 17 102 18 public static void init (int port) 103 19 { 104 Log.Out ("[7dtd-server-fixes by Alloc] Version: " + Assembly.GetExecutingAssembly ().GetName().Version);20 Log.Out ("[7dtd-server-fixes by Alloc] Version: " + Assembly.GetExecutingAssembly ().GetName ().Version); 105 21 authEnabled = GamePrefs.GetString (EnumGamePrefs.TelnetPassword).Length != 0; 106 22 if (authEnabled) … … 121 37 Thread.Sleep (10); 122 38 if (listener.Pending ()) { 123 Connection c = new Connection (listener.AcceptTcpClient ());39 AllocsTelnetConnection c = new AllocsTelnetConnection (listener.AcceptTcpClient (), authEnabled); 124 40 conns.Add (c); 125 41 Log.Out ("Telnet connection from: " + c.GetEndPoint ()); … … 131 47 } 132 48 133 foreach ( Connection c in conns) {49 foreach (AllocsTelnetConnection c in conns) { 134 50 if (c.IsClosed ()) { 135 51 c.Close (); … … 157 73 break; 158 74 } 159 160 75 Log.Out ("Telnet executed \"" + line + "\" from: " + c.GetEndPoint ()); 161 76 console.md000f (line); … … 172 87 } 173 88 174 private static void LoginMessage ( Connection c)89 private static void LoginMessage (AllocsTelnetConnection c) 175 90 { 176 91 c.WriteLine ("*** Connected with 7DTD server."); … … 208 123 listener.Stop (); 209 124 } 210 foreach ( Connection c in conns) {125 foreach (AllocsTelnetConnection c in conns) { 211 126 c.Close (); 212 127 } … … 214 129 } 215 130 216 public static void SetConsole ( cl004cconsole)131 public static void SetConsole (ConsoleSdtd console) 217 132 { 133 Log.Out("Telnet SetConsole called"); 218 134 AllocsNetTelnetServer.console = console; 135 console.AddCommand(new GetTime(console)); 136 console.AddCommand(new ListPlayersExtended(console)); 219 137 } 220 138 221 139 private static void RemoveClosedConnections () 222 140 { 223 foreach ( Connection c in conns) {141 foreach (AllocsTelnetConnection c in conns) { 224 142 if (c.IsClosed ()) { 225 143 c.Close (); … … 234 152 } 235 153 RemoveClosedConnections (); 236 foreach ( Connection c in conns) {237 if (c.IsAuthenticated ())154 foreach (AllocsTelnetConnection c in conns) { 155 if (c.IsAuthenticated ()) 238 156 c.WriteLine (line); 239 157 } -
binary-improvements/assembly-patcher/Assembly-Patcher.userprefs
r74 r75 3 3 <MonoDevelop.Ide.Workbench ActiveDocument="Main.cs"> 4 4 <Files> 5 <File FileName="Main.cs" Line=" 19" Column="4" />5 <File FileName="Main.cs" Line="35" Column="161" /> 6 6 <File FileName="AssemblyInfo.cs" Line="7" Column="36" /> 7 7 </Files> -
binary-improvements/assembly-patcher/Main.cs
r73 r75 12 12 ModuleDefinition module = ModuleDefinition.ReadModule ("Assembly-CSharp.dll"); 13 13 telnetPatch (module); 14 connectLogPatch(module); 14 15 module.Write ("Assembly-CSharp.dll"); 15 16 Console.WriteLine ("Done"); 17 } 18 19 private static void connectLogPatch (ModuleDefinition module) 20 { 21 TypeDefinition type = module.GetType ("GameManager"); 22 23 if (isPatched (type)) { 24 return; 25 } 26 27 markTypePatched (module, type); 28 addHook (type, "RequestToSpawnPlayer", true, 5, typeof(AllocsRequestToSpawnPlayer).GetMethod ("RequestToSpawnPlayer")); 16 29 } 17 30 … … 25 38 26 39 markTypePatched (module, type); 27 patchMethod (type, ".ctor", 1, typeof(AllocsNetTelnetServer).GetMethod ("init"));28 patchMethod (type, "Disconnect", 0, typeof(AllocsNetTelnetServer).GetMethod ("Disconnect"));29 patchMethod (type, "SetConsole", 1, typeof(AllocsNetTelnetServer).GetMethod ("SetConsole"));30 patchMethod (type, "WriteToClient", 1, typeof(AllocsNetTelnetServer).GetMethod ("WriteToClient"));40 replaceMethod (type, ".ctor", 1, typeof(AllocsNetTelnetServer).GetMethod ("init")); 41 replaceMethod (type, "Disconnect", 0, typeof(AllocsNetTelnetServer).GetMethod ("Disconnect")); 42 replaceMethod (type, "SetConsole", 1, typeof(AllocsNetTelnetServer).GetMethod ("SetConsole")); 43 replaceMethod (type, "WriteToClient", 1, typeof(AllocsNetTelnetServer).GetMethod ("WriteToClient")); 31 44 } 32 45 … … 36 49 } 37 50 38 private static void patchMethod (TypeDefinition type, string methodName, int opCount, MethodBase targetMethod) 51 private static void addHook (TypeDefinition type, string methodName, bool addThisRef, int opCount, MethodBase targetMethod) 52 { 53 foreach (MethodDefinition method in type.Methods) { 54 if (method.Name.Equals (methodName)) { 55 Console.WriteLine ("Patching " + methodName); 56 var il = method.Body.GetILProcessor (); 57 var call = il.Create (OpCodes.Call, method.Module.Import (targetMethod)); 58 var i = 0; 59 if (addThisRef) 60 il.InsertBefore (method.Body.Instructions [i++], il.Create (OpCodes.Ldarg, 0)); 61 for (int op = 0; op < opCount; op++) { 62 il.InsertBefore (method.Body.Instructions [i++], il.Create (OpCodes.Ldarg, op + 1)); 63 } 64 il.InsertBefore (method.Body.Instructions [i++], call); 65 } 66 } 67 } 68 69 private static void replaceMethod (TypeDefinition type, string methodName, int opCount, MethodBase targetMethod) 39 70 { 40 71 foreach (MethodDefinition method in type.Methods) {
Note:
See TracChangeset
for help on using the changeset viewer.