Changeset 107 for binary-improvements
- Timestamp:
- Jul 26, 2014, 4:41:11 PM (10 years ago)
- Location:
- binary-improvements
- Files:
-
- 3 added
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/7dtd-server-fixes.csproj
r103 r107 55 55 <Compile Include="src\CommandExtensions.cs" /> 56 56 <Compile Include="src\CommonMappingFunctions.cs" /> 57 <Compile Include="src\ConsoleOutputSeparator.cs" /> 57 58 </ItemGroup> 58 59 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> -
binary-improvements/7dtd-server-fixes/7dtd-server-fixes.userprefs
r99 r107 1 1 <Properties> 2 2 <MonoDevelop.Ide.Workspace ActiveConfiguration="Release" /> 3 <MonoDevelop.Ide.Workbench ActiveDocument="src/ PlayerDataStuff.cs">3 <MonoDevelop.Ide.Workbench ActiveDocument="src/AdminToolsStuff.cs"> 4 4 <Files> 5 5 <File FileName="src/AssemblyInfo.cs" Line="20" Column="40" /> 6 <File FileName="src/AllocsNetTelnetServer.cs" Line="136" Column="1" /> 7 <File FileName="src/AllocsTelnetConnection.cs" Line="44" Column="42" /> 8 <File FileName="src/AllocsLogFunctions.cs" Line="27" Column="42" /> 9 <File FileName="src/AdminToolsStuff.cs" Line="30" Column="54" /> 10 <File FileName="src/PlayerDataStuff.cs" Line="30" Column="27" /> 11 <File FileName="src/CommandExtensions.cs" Line="12" Column="73" /> 6 <File FileName="src/AllocsNetTelnetServer.cs" Line="155" Column="65" /> 7 <File FileName="src/AllocsTelnetConnection.cs" Line="50" Column="3" /> 8 <File FileName="src/AllocsLogFunctions.cs" Line="27" Column="43" /> 9 <File FileName="src/AdminToolsStuff.cs" Line="33" Column="1" /> 10 <File FileName="src/PlayerDataStuff.cs" Line="59" Column="40" /> 11 <File FileName="src/TelnetCommands/SayToPlayer.cs" Line="23" Column="49" /> 12 <File FileName="src/CommonMappingFunctions.cs" Line="149" Column="1" /> 13 <File FileName="src/CommandExtensions.cs" Line="34" Column="28" /> 12 14 </Files> 13 15 </MonoDevelop.Ide.Workbench> -
binary-improvements/7dtd-server-fixes/src/AdminToolsStuff.cs
r103 r107 25 25 } 26 26 } 27 28 if (tmpInfo.PermissionLevel <= 0) { 29 List<ConsoleCommand> commands = console.commands; 30 foreach (ConsoleCommand c in commands) { 31 if (!allowed.Contains (c.Names () [0])) { 32 if (!hasPermissionLevel (admTools, c.Names () [0])) { 33 addAllowed (console, allowed, c.Names () [0]); 34 } 35 } 36 } 37 } 27 38 } catch (Exception e) { 28 39 Log.Out ("Error in GetAllowedCommandsList: " + e); … … 33 44 } 34 45 46 private static bool hasPermissionLevel (AdminTools admTools, string cmd) 47 { 48 List<AdminToolsCommandPermissions> perms = admTools.commandPermissions; 49 50 foreach (AdminToolsCommandPermissions atcp in perms) { 51 foreach (string ccName in getAlternativeNames(cmd)) { 52 if (atcp.Command.ToLower ().Equals (ccName)) { 53 return true; 54 } 55 } 56 } 57 return false; 58 } 59 35 60 private static void addAllowed (ConsoleSdtd console, List<string> list, string cmd) 36 61 { 37 ConsoleCommand cc = console.getCommand (cmd); 62 foreach (string ccName in getAlternativeNames(cmd)) { 63 if (!list.Contains (ccName)) { 64 list.Add (ccName); 65 } 66 } 67 } 68 69 private static string[] getAlternativeNames (string cmd) 70 { 71 ConsoleCommand cc = CommonMappingFunctions.GetGameManager ().m_GUIConsole.getCommand (cmd); 38 72 if (cc != null) { 39 foreach (string ccName in cc.Names()) { 40 if (!list.Contains (ccName)) { 41 list.Add (ccName); 42 } 43 } 73 return cc.Names (); 44 74 } else { 45 list.Add (cmd);75 return new string[0]; 46 76 } 47 77 } -
binary-improvements/7dtd-server-fixes/src/AllocsLogFunctions.cs
r103 r107 28 28 } 29 29 } 30 31 public static void ExecuteCmdFromClient (ConsoleSdtd console, NetworkPlayer _networkPlayer, string _playerID, string _command)32 {33 Log.Out ("Executed command \"" + _command + "\" from player \"" + _playerID + "\"");34 }35 30 } -
binary-improvements/7dtd-server-fixes/src/AllocsNetTelnetServer.cs
r103 r107 78 78 } 79 79 Log.Out ("Telnet executed \"" + line + "\" from: " + c.GetEndPoint ()); 80 console.md000f (line);80 ConsoleOutputSeparator.QueueTelnetCommand (line, c); 81 81 } 82 82 } … … 168 168 } 169 169 } 170 171 public static void WriteToClient (string line, AllocsTelnetConnection client) 172 { 173 if (line == null) { 174 return; 175 } 176 RemoveClosedConnections (); 177 foreach (AllocsTelnetConnection c in connections) { 178 if (c.IsAuthenticated () && (c == client)) 179 c.WriteLine (line); 180 } 181 } 170 182 } -
binary-improvements/7dtd-server-fixes/src/CommandExtensions.cs
r96 r107 1 1 using System; 2 using System.Collections.Generic; 2 3 3 4 public class CommandExtensions … … 5 6 public static void InitCommandExtensions (GameManager manager) 6 7 { 7 manager.m_GUIConsole.AddCommand(new GetGamePrefs(manager.m_GUIConsole)); 8 manager.m_GUIConsole.AddCommand(new GetTime(manager.m_GUIConsole)); 9 manager.m_GUIConsole.AddCommand(new ListPlayersExtended(manager.m_GUIConsole)); 10 manager.m_GUIConsole.AddCommand(new SayToPlayer(manager.m_GUIConsole)); 11 manager.m_GUIConsole.AddCommand(new SetTimeReal(manager.m_GUIConsole)); 12 manager.m_GUIConsole.AddCommand(new ShowInventory(manager.m_GUIConsole)); 8 try { 9 manager.m_GUIConsole.AddCommand (new GetGamePrefs (manager.m_GUIConsole)); 10 manager.m_GUIConsole.AddCommand (new GetTime (manager.m_GUIConsole)); 11 manager.m_GUIConsole.AddCommand (new ListPlayersExtended (manager.m_GUIConsole)); 12 manager.m_GUIConsole.AddCommand (new SayToPlayer (manager.m_GUIConsole)); 13 manager.m_GUIConsole.AddCommand (new SetTimeReal (manager.m_GUIConsole)); 14 manager.m_GUIConsole.AddCommand (new ShowInventory (manager.m_GUIConsole)); 15 } catch (Exception e) { 16 Log.Out ("Error registering custom commands: " + e); 17 } 18 /* 19 try { 20 List<ConsoleCommand> commands = manager.m_GUIConsole.commands; 21 foreach (ConsoleCommand c in commands) { 22 string name = string.Empty; 23 foreach (string cname in c.Names()) { 24 if (cname.Length > 0) { 25 if (name.Length > 0) 26 name += ", "; 27 name += cname; 28 } 29 } 30 name += " => " + c.Description(); 31 Log.Out (name); 32 } 33 } catch (Exception e) { 34 Log.Out ("Error listing commands: " + e); 35 } 36 */ 13 37 } 14 38 } -
binary-improvements/7dtd-server-fixes/src/TelnetCommands/GetGamePrefs.cs
r103 r107 65 65 } 66 66 foreach (string s in sortedList.Keys) { 67 m_Console. md000a(sortedList [s]);67 m_Console.SendResult (sortedList [s]); 68 68 } 69 69 } else { 70 70 if (prefAccessAllowed (enumGamePrefs)) 71 m_Console. md000a(string.Format ("{0} = {1}", enumGamePrefs, GamePrefs.GetObject (enumGamePrefs)));71 m_Console.SendResult (string.Format ("{0} = {1}", enumGamePrefs, GamePrefs.GetObject (enumGamePrefs))); 72 72 else 73 m_Console. md000a("Access to requested preference is forbidden");73 m_Console.SendResult ("Access to requested preference is forbidden"); 74 74 } 75 75 } catch (Exception e) { -
binary-improvements/7dtd-server-fixes/src/TelnetCommands/GetTime.cs
r103 r107 28 28 } 29 29 int min = (int)(time % 1000) * 60 / 1000; 30 m_Console. md000a(String.Format ("Day {0}, {1:00}:{2:00} ", day, hour, min));30 m_Console.SendResult (String.Format ("Day {0}, {1:00}:{2:00} ", day, hour, min)); 31 31 } catch (Exception e) { 32 32 Log.Out ("Error in GetTime.Run: " + e); -
binary-improvements/7dtd-server-fixes/src/TelnetCommands/ListPlayersExtended.cs
r103 r107 29 29 ip = ci.networkPlayer.ipAddress; 30 30 } 31 m_Console. md000a(string.Concat (new object[]31 m_Console.SendResult (string.Concat (new object[] 32 32 { 33 33 string.Empty, … … 63 63 ); 64 64 } 65 m_Console. md000a("Total of " + w.playerEntities.list.Count + " in the game");65 m_Console.SendResult ("Total of " + w.playerEntities.list.Count + " in the game"); 66 66 } catch (Exception e) { 67 67 Log.Out ("Error in ListPlayersExtended.Run: " + e); -
binary-improvements/7dtd-server-fixes/src/TelnetCommands/SayToPlayer.cs
r103 r107 23 23 new object[] { _message, -1, _sender + " (PM)", true }); 24 24 string receiverName = CommonMappingFunctions.GetPlayerName (_receiver); 25 m_Console. md000a("Message to player " + (receiverName != null ? "\"" + receiverName + "\"" : "unknownName") + " sent with sender \"" + _sender + "\"");25 m_Console.SendResult ("Message to player " + (receiverName != null ? "\"" + receiverName + "\"" : "unknownName") + " sent with sender \"" + _sender + "\""); 26 26 } 27 27 … … 29 29 { 30 30 if (_params.Length < 2) { 31 m_Console. md000a("Usage: sayplayer <playername|entityid> <message>");31 m_Console.SendResult ("Usage: sayplayer <playername|entityid> <message>"); 32 32 return; 33 33 } … … 42 42 SendMessage (ci, _sender, message); 43 43 } else { 44 m_Console. md000a("Playername or entity ID not found.");44 m_Console.SendResult ("Playername or entity ID not found."); 45 45 } 46 46 } -
binary-improvements/7dtd-server-fixes/src/TelnetCommands/SetTimeReal.cs
r103 r107 21 21 try { 22 22 if (_params.Length != 3) { 23 m_Console. md000a("Usage: settimereal <day> <hour> <min>");23 m_Console.SendResult ("Usage: settimereal <day> <hour> <min>"); 24 24 return; 25 25 } … … 27 27 int day, hour, min; 28 28 if (!int.TryParse (_params [0], out day)) { 29 m_Console. md000a("Could not parse day number \"" + _params [0] + "\"");29 m_Console.SendResult ("Could not parse day number \"" + _params [0] + "\""); 30 30 return; 31 31 } 32 32 if (day < 1) { 33 m_Console. md000a("Day must be >= 1");33 m_Console.SendResult ("Day must be >= 1"); 34 34 return; 35 35 } 36 36 if (!int.TryParse (_params [1], out hour)) { 37 m_Console. md000a("Could not parse hour \"" + _params [1] + "\"");37 m_Console.SendResult ("Could not parse hour \"" + _params [1] + "\""); 38 38 return; 39 39 } 40 40 if (hour > 23) { 41 m_Console. md000a("Hour must be <= 23");41 m_Console.SendResult ("Hour must be <= 23"); 42 42 return; 43 43 } 44 44 if (!int.TryParse (_params [2], out min)) { 45 m_Console. md000a("Could not parse minute \"" + _params [2] + "\"");45 m_Console.SendResult ("Could not parse minute \"" + _params [2] + "\""); 46 46 return; 47 47 } 48 48 if (min > 59) { 49 m_Console. md000a("Minute must be <= 59");49 m_Console.SendResult ("Minute must be <= 59"); 50 50 return; 51 51 } 52 52 if ((day < 1) || (hour < 8 && day < 1)) { 53 m_Console. md000a("Time may not be prior to day 1, 8:00");53 m_Console.SendResult ("Time may not be prior to day 1, 8:00"); 54 54 return; 55 55 } … … 57 57 ulong time = ((ulong)(day - 1) * 24000) + ((ulong)hour * 1000) + ((ulong)min * 1000 / 60) - 8000; 58 58 m_Console.gameManager.World.gameTime = time; 59 m_Console. md000a(String.Format ("Set time to Day {0}, {1:00}:{2:00} = {3}", day, hour, min, time));59 m_Console.SendResult (String.Format ("Set time to Day {0}, {1:00}:{2:00} = {3}", day, hour, min, time)); 60 60 } catch (Exception e) { 61 61 Log.Out ("Error in SetTimeReal.Run: " + e); -
binary-improvements/7dtd-server-fixes/src/TelnetCommands/ShowInventory.cs
r103 r107 25 25 try { 26 26 if (_params.Length < 1) { 27 m_Console. md000a("Usage: showinventory <playername|entityid>");27 m_Console.SendResult ("Usage: showinventory <playername|entityid>"); 28 28 return; 29 29 } … … 47 47 48 48 if (items == null) { 49 m_Console. md000a("Playername or entity id not found or no inventory saved (first saved after a player has been online for 30s).");49 m_Console.SendResult ("Playername or entity id not found or no inventory saved (first saved after a player has been online for 30s)."); 50 50 return; 51 51 } 52 52 53 m_Console. md000a("Belt of player:");53 m_Console.SendResult ("Belt of player:"); 54 54 foreach (KeyValuePair<string, int> kvp in items.belt) { 55 m_Console. md000a(string.Format (" {0:000} * {1}", kvp.Value, kvp.Key));55 m_Console.SendResult (string.Format (" {0:000} * {1}", kvp.Value, kvp.Key)); 56 56 } 57 m_Console. md000a(string.Empty);58 m_Console. md000a("Bagpack of player:");57 m_Console.SendResult (string.Empty); 58 m_Console.SendResult ("Bagpack of player:"); 59 59 foreach (KeyValuePair<string, int> kvp in items.bag) { 60 m_Console. md000a(string.Format (" {0:000} * {1}", kvp.Value, kvp.Key));60 m_Console.SendResult (string.Format (" {0:000} * {1}", kvp.Value, kvp.Key)); 61 61 } 62 m_Console. md000a(string.Empty);62 m_Console.SendResult (string.Empty); 63 63 } catch (Exception e) { 64 64 Log.Out ("Error in ShowInventory.Run: " + e); -
binary-improvements/NamePatcher/NamePatcher.cs
r104 r107 8 8 namespace NamePatcher 9 9 { 10 10 11 class NamePatcher 11 12 { … … 56 57 } 57 58 58 static void applyManualPatches (ModuleDefinition mainModule)59 {60 NameNormalizer.setName (mainModule.GetType ("ItemBlock").BaseType.Resolve (), "ItemBase");61 62 foreach (FieldDefinition fd in mainModule.GetType ("Authenticator").Fields) {63 TypeReference fdType = fd.FieldType;64 if (fdType.FullName.Contains ("Dictionary") && fdType.FullName.Contains ("System.String")) {65 Console.WriteLine ("Renaming and making public Authenticator field -> usersToIDs");66 fd.Attributes = fd.Attributes & (~Mono.Cecil.FieldAttributes.Private) | Mono.Cecil.FieldAttributes.Public;67 NameNormalizer.setName (fd, "usersToIDs");68 }69 }70 71 foreach (FieldDefinition fd in mainModule.GetType("PlayerDataFile").Fields) {72 TypeReference fdType = fd.FieldType;73 if (fd.Name.Equals ("inventory") && fdType.IsArray) {74 foreach (FieldDefinition fd2 in fdType.Resolve().Fields) {75 TypeReference fd2Type = fd2.FieldType;76 if (fd2Type.FullName.Equals ("System.Int32")) {77 Console.WriteLine ("Renaming inventory field field -> count");78 NameNormalizer.setName (fd2, "count");79 }80 if (fd2Type.FullName.Equals ("ItemValue")) {81 Console.WriteLine ("Renaming inventory field field -> itemValue");82 NameNormalizer.setName (fd2, "itemValue");83 }84 }85 Console.WriteLine ("Renaming inventory field class -> InventoryField");86 NameNormalizer.setName (fdType.Resolve (), "InventoryField");87 }88 }89 90 foreach (FieldDefinition fd in mainModule.GetType ("AdminTools").Fields) {91 TypeReference fdType = fd.FieldType;92 if (fdType.FullName.Contains ("List") && fdType.FullName.Contains ("AdminToolsCommandPermissions")) {93 Console.WriteLine ("Renaming and making public admin tools field -> commandPermissions");94 fd.Attributes = fd.Attributes & (~Mono.Cecil.FieldAttributes.Private) | Mono.Cecil.FieldAttributes.Public;95 NameNormalizer.setName (fd, "commandPermissions");96 }97 }98 99 foreach (FieldDefinition fd in mainModule.GetType ("World").Fields) {100 TypeReference fdType = fd.FieldType;101 if (fdType.FullName.Equals ("System.UInt64")) {102 Console.WriteLine ("Renaming world field -> gameTime");103 NameNormalizer.setName (fd, "gameTime");104 }105 }106 107 foreach (FieldDefinition fd in mainModule.GetType ("GameManager").Fields) {108 TypeReference fdType = fd.FieldType;109 if (fdType.FullName.Equals ("ConnectionManager")) {110 Console.WriteLine ("Renaming and making public GameMananger field -> connectionManager");111 fd.Attributes = fd.Attributes & (~Mono.Cecil.FieldAttributes.Private) | Mono.Cecil.FieldAttributes.Public;112 NameNormalizer.setName (fd, "connectionManager");113 }114 }115 116 foreach (FieldDefinition fd in mainModule.GetType ("ConnectionManager").Fields) {117 TypeReference fdType = fd.FieldType;118 if (fdType.FullName.Equals ("GameManager")) {119 Console.WriteLine ("Renaming and making public ConnectionManager field -> gameManager");120 fd.Attributes = fd.Attributes & (~Mono.Cecil.FieldAttributes.Private) | Mono.Cecil.FieldAttributes.Public;121 NameNormalizer.setName (fd, "gameManager");122 }123 if (fdType.FullName.Contains ("Dictionary") && fdType.FullName.Contains ("ClientInfo")) {124 Console.WriteLine ("Renaming and making public ConnectionManager field -> connectedClients");125 fd.Attributes = fd.Attributes & (~Mono.Cecil.FieldAttributes.Private) | Mono.Cecil.FieldAttributes.Public;126 NameNormalizer.setName (fd, "connectedClients");127 }128 if (fdType.FullName.Contains ("Dictionary") && fdType.FullName.Contains ("System.Int32,System.Int32")) {129 Console.WriteLine ("Renaming and making public ConnectionManager field -> mapClientToEntity");130 fd.Attributes = fd.Attributes & (~Mono.Cecil.FieldAttributes.Private) | Mono.Cecil.FieldAttributes.Public;131 NameNormalizer.setName (fd, "mapClientToEntity");132 }133 }134 135 string consoleTypeName = string.Empty;136 TypeDefinition typeTelnetServer = mainModule.GetType ("NetTelnetServer");137 foreach (FieldDefinition fd in typeTelnetServer.Fields) {138 if (NameNormalizer.makeValidName (fd.FieldType.Name) != null) {139 Console.WriteLine ("Renaming console class -> ConsoleSdtd");140 consoleTypeName = fd.FieldType.Name;141 NameNormalizer.setName (fd.FieldType.Resolve (), "ConsoleSdtd");142 NameNormalizer.setName (fd, "console");143 }144 }145 146 if (consoleTypeName.Length > 0) {147 TypeDefinition typeConsole = mainModule.GetType (consoleTypeName);148 string consoleCommandTypeName = string.Empty;149 foreach (MethodDefinition md in typeConsole.Methods) {150 if (!md.IsConstructor) {151 if (md.Parameters.Count == 3 && md.Parameters [0].ParameterType.Name.Equals ("NetworkPlayer")) {152 Console.WriteLine ("Renaming console method -> ExecuteCmdFromClient");153 NameNormalizer.setName (md, "ExecuteCmdFromClient");154 }155 }156 }157 foreach (FieldDefinition fd in typeConsole.Fields) {158 TypeReference fdType = fd.FieldType;159 if (fdType.FullName.Contains ("Generic.List")) {160 if (fdType.IsGenericInstance) {161 GenericInstanceType genType = (GenericInstanceType)fdType;162 TypeReference genRef = genType.GenericArguments [0];163 if (genRef.Name.Length < 2) {164 Console.WriteLine ("Renaming console command class -> ConsoleCommand");165 NameNormalizer.setName (genRef.Resolve (), "ConsoleCommand");166 NameNormalizer.setName (fd, "commands");167 consoleCommandTypeName = genRef.Name;168 }169 }170 }171 if (fdType.FullName.Equals ("GameManager")) {172 Console.WriteLine ("Renaming and making public console field -> gameManager");173 fd.Attributes = fd.Attributes & (~Mono.Cecil.FieldAttributes.Private) | Mono.Cecil.FieldAttributes.Public;174 NameNormalizer.setName (fd, "gameManager");175 }176 }177 178 if (consoleCommandTypeName.Length > 0) {179 foreach (MethodDefinition md in typeConsole.Methods) {180 if (!md.IsConstructor) {181 if (md.Parameters.Count == 1 && md.Parameters [0].ParameterType.Name.Equals (consoleCommandTypeName)) {182 Console.WriteLine ("Renaming console method -> AddCommand");183 NameNormalizer.setName (md, "AddCommand");184 }185 if (md.Parameters.Count == 1 && md.Parameters [0].ParameterType.FullName.Equals ("System.String") && md.ReturnType.FullName.Equals (consoleCommandTypeName)) {186 Console.WriteLine ("Renaming console method -> getCommand");187 NameNormalizer.setName (md, "getCommand");188 }189 }190 }191 192 TypeDefinition typeConsoleCommand = mainModule.GetType (consoleCommandTypeName);193 foreach (MethodDefinition md in typeConsoleCommand.Methods) {194 if (!md.IsConstructor) {195 if (md.Parameters.Count == 1 && md.Parameters [0].ParameterType.Name.Equals (consoleTypeName)) {196 Console.WriteLine ("Renaming console command method -> Help");197 NameNormalizer.setName (md, "Help");198 }199 if (md.Parameters.Count == 0 && md.ReturnType.Name.Equals ("Int32")) {200 Console.WriteLine ("Renaming console command method -> Timeout");201 NameNormalizer.setName (md, "Timeout");202 }203 if (md.Parameters.Count == 0 && md.ReturnType.Name.Equals ("String[]")) {204 Console.WriteLine ("Renaming console command method -> Names");205 NameNormalizer.setName (md, "Names");206 }207 if (md.Parameters.Count == 0 && md.ReturnType.Name.Equals ("String")) {208 Console.WriteLine ("Renaming console command method -> Description");209 NameNormalizer.setName (md, "Description");210 }211 if (md.Parameters.Count == 1 && md.Parameters [0].ParameterType.IsArray) {212 Console.WriteLine ("Renaming console command method -> Run");213 NameNormalizer.setName (md, "Run");214 }215 }216 }217 }218 }219 }220 221 59 static void Main (string[] args) 222 60 { 223 Console.WriteLine ("NamePatcher for 7dtd's Assembly-CSharp.dll [by DerPopo, modified by Alloc] for Dedi build 320404");61 Console.WriteLine ("NamePatcher for 7dtd's Assembly-CSharp.dll [by DerPopo, modified by Alloc]"); 224 62 if (!TryArgs (args)) { 225 63 DrawUsage (); … … 247 85 248 86 249 applyManualPatches (input.MainModule);87 ManualPatches.applyManualPatches (input.MainModule); 250 88 251 89 -
binary-improvements/NamePatcher/NamePatcher.csproj
r77 r107 44 44 <Compile Include="NamePatcher.cs" /> 45 45 <Compile Include="Properties\AssemblyInfo.cs" /> 46 <Compile Include="ManualPatches.cs" /> 46 47 </ItemGroup> 47 48 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> -
binary-improvements/NamePatcher/NamePatcher.userprefs
r104 r107 1 1 <Properties> 2 2 <MonoDevelop.Ide.Workspace ActiveConfiguration="Release|x86" /> 3 <MonoDevelop.Ide.Workbench ActiveDocument=" NamePatcher.cs">3 <MonoDevelop.Ide.Workbench ActiveDocument="ManualPatches.cs"> 4 4 <Files> 5 <File FileName="NamePatcher.cs" Line=" 64" Column="92" />5 <File FileName="NamePatcher.cs" Line="5" Column="1" /> 6 6 <File FileName="NameNormalizer.cs" Line="188" Column="1" /> 7 <File FileName="ManualPatches.cs" Line="120" Column="1" /> 7 8 </Files> 8 9 <Pads> … … 11 12 <Node name="NamePatcher" expanded="True"> 12 13 <Node name="Properties" expanded="True" /> 13 <Node name=" NamePatcher.cs" selected="True" />14 <Node name="ManualPatches.cs" selected="True" /> 14 15 </Node> 15 16 </State> -
binary-improvements/assembly-patcher/Main.cs
r96 r107 1 1 using System; 2 using System.Collections.Generic; 2 3 using System.Reflection; 3 4 using Mono.Cecil; … … 14 15 TypeDefinition type = module.GetType ("GameManager"); 15 16 if (isPatched (type)) { 16 Console.WriteLine ("Assembly already patched");17 Console.WriteLine ("Assembly already patched"); 17 18 return; 18 19 } 19 20 markTypePatched (module, type); 20 21 22 consoleOutputPatch (module); 21 23 telnetPatch (module); 22 24 connectLogPatch (module); 23 executionLogPatch (module);24 25 publicCommandPermissionsPatch (module); 25 26 playerDataPatch (module); 27 26 28 module.Write ("Assembly-CSharp.dll"); 27 29 Console.WriteLine ("Done"); 30 31 } 32 33 private static void consoleOutputPatch (ModuleDefinition module) 34 { 35 TypeDefinition type = module.GetType ("ConsoleSdtd"); 36 replaceMethod (type, "ExecuteCmdFromClient", true, 3, typeof(ConsoleOutputSeparator).GetMethod ("C_ExecuteCmdFromClient")); 37 addHook (type, "Run", true, 0, true, typeof(ConsoleOutputSeparator).GetMethod ("C_Run")); 38 replaceMethod (type, "SendResult", true, 1, typeof(ConsoleOutputSeparator).GetMethod ("C_SendResult")); 39 28 40 } 29 41 … … 31 43 { 32 44 TypeDefinition type = module.GetType ("GameManager"); 33 34 45 addHook (type, "SavePlayerData", true, 2, true, typeof(PlayerDataStuff).GetMethod ("GM_SavePlayerData")); 35 addHook (type, "Awake", true, 0, true, typeof(CommandExtensions).GetMethod ("InitCommandExtensions"));46 addHook (type, "Awake", true, 0, true, typeof(CommandExtensions).GetMethod ("InitCommandExtensions")); 36 47 } 37 48 … … 39 50 { 40 51 TypeDefinition type = module.GetType ("AdminTools"); 41 42 52 replaceMethod (type, "GetAllowedCommandsList", true, 1, typeof(AdminToolsStuff).GetMethod ("GetAllowedCommandsList")); 43 53 } … … 46 56 { 47 57 TypeDefinition type = module.GetType ("GameManager"); 48 49 58 addHook (type, "RequestToSpawnPlayer", true, 5, true, typeof(AllocsLogFunctions).GetMethod ("RequestToSpawnPlayer")); 50 }51 52 private static void executionLogPatch (ModuleDefinition module)53 {54 TypeDefinition type = module.GetType ("ConsoleSdtd");55 56 addHook (type, "ExecuteCmdFromClient", true, 3, false, typeof(AllocsLogFunctions).GetMethod ("ExecuteCmdFromClient"));57 59 } 58 60 … … 60 62 { 61 63 TypeDefinition type = module.GetType ("NetTelnetServer"); 62 63 64 replaceMethod (type, ".ctor", false, 1, typeof(AllocsNetTelnetServer).GetMethod ("init")); 64 65 replaceMethod (type, "Disconnect", false, 0, typeof(AllocsNetTelnetServer).GetMethod ("Disconnect")); … … 76 77 foreach (MethodDefinition method in type.Methods) { 77 78 if (method.Name.Equals (methodName)) { 78 Console.WriteLine ("Patching " + methodName);79 79 var il = method.Body.GetILProcessor (); 80 80 var call = il.Create (OpCodes.Call, method.Module.Import (targetMethod)); … … 98 98 il.InsertBefore (method.Body.Instructions [i++], call); 99 99 } 100 return; 100 101 } 101 102 } 103 Console.WriteLine ("ERROR: Did not find " + type.Name + "." + methodName + "()"); 102 104 } 103 105 … … 106 108 foreach (MethodDefinition method in type.Methods) { 107 109 if (method.Name.Equals (methodName)) { 108 Console.WriteLine ("Patching " + methodName);109 110 var il = method.Body.GetILProcessor (); 110 111 var call = il.Create (OpCodes.Call, method.Module.Import (targetMethod)); … … 117 118 il.InsertBefore (method.Body.Instructions [i++], call); 118 119 il.InsertBefore (method.Body.Instructions [i++], il.Create (OpCodes.Ret)); 120 return; 119 121 } 120 122 } 123 Console.WriteLine ("ERROR: Did not find " + type.Name + "." + methodName + "()"); 121 124 } 122 125 … … 125 128 foreach (FieldDefinition fd in type.Fields) { 126 129 if (fd.Name.Equals ("AllocsPatch")) { 127 Console.WriteLine ("\"" + type.Name + "\" is already patched, skipping");128 130 return true; 129 131 } 130 132 } 131 Console.WriteLine ("Patching \"" + type.Name + "\"");132 133 return false; 133 134 }
Note:
See TracChangeset
for help on using the changeset viewer.