Changeset 107 for binary-improvements/NamePatcher/NamePatcher.cs
- Timestamp:
- Jul 26, 2014, 4:41:11 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.