Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.63 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.File;
  3. import java.io.FileInputStream;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.util.List;
  7.  
  8. import javax.swing.JTextArea;
  9. import javax.swing.SwingWorker;
  10.  
  11. public class VmfEntityObf extends SwingWorker<List<String>, String>{
  12. public VmfEntityObf(JTextArea console, File vmf, List<String> targetnameExceptions) {
  13. this.console = console;
  14. this.vmf = vmf;
  15. this.targetnameExceptions = targetnameExceptions;
  16. }
  17.  
  18. @Override
  19. protected List<String> doInBackground() throws IOException {
  20. publish("\n");
  21. publish("--------------------VMF Entity Targetname Obfuscator--------------------" + "\n");
  22.  
  23. // Reading lines from file into List
  24. publish("Loading vmf... ");
  25.  
  26.  
  27. // hier passieren komische Sachen
  28.  
  29.  
  30. List<String> vmfList = null;
  31. BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(this.vmf)));
  32.  
  33. String line = br.readLine();
  34. while(line != null) { // for whatever fkn reason SwingWorker just stops here and doesn't do shit no more
  35. vmfList.add(line);
  36. line = br.readLine();
  37. }
  38. br.close();
  39. publish("DONE" + "\n");
  40.  
  41. // Setting up for progress calculations
  42. int totallines = vmfList.size();
  43. int progress = 0;
  44. int localprogress = 0;
  45.  
  46. // lets first skip all worldgeometry never containing any targetname information
  47. publish("Skipping WorldGeometry... ");
  48. for(int i = 0; vmfList.get(i).contains("entity"); i++) {
  49. totallines--; // removing worldgeometry-lines from the progress calculations
  50. }
  51. publish("DONE" + "\n");
  52.  
  53. // Wildcards need to be excluded from the renaming progress (future update might include wildcards)
  54. publish("\n");
  55. publish("Finding Wildcards: ");
  56. int start;
  57. int end;
  58. for(int i = totallines; i < vmfList.size(); i++) {
  59. line = vmfList.get(i);
  60. if(line.contains("*")){
  61. start = line.indexOf("\"", line.indexOf("\"", line.indexOf("\"")+1)+1)+1;
  62. end = line.indexOf("*");
  63. if(!(this.targetnameExceptions.contains(line.substring(start, end)))){
  64. this.targetnameExceptions.add(line.substring(start, end));
  65. }
  66. }
  67. // Local Progress Calculations
  68. if((double)progress / (double)totallines >= 0.025 * localprogress) {
  69. if(localprogress % 4 == 0) {
  70. publish(localprogress + "");
  71. } else {
  72. publish(".");
  73. }
  74. localprogress++;
  75. }
  76. // Overall Progress Calculations
  77. progress++;
  78. setProgress((int)(100 * (double)progress / (double)(3 * totallines)));
  79. }
  80. publish("10" + "\n");
  81. localprogress = 0;
  82.  
  83. // we run through the remaining lines and search for entities applicable for targetname change
  84. publish("\n");
  85. publish("Finding Targetnames: 0");
  86. List<String> applicableNames = null;
  87. boolean bol = false;
  88. String targetname;
  89.  
  90. for(int i = totallines; i < vmfList.size(); i++) {
  91. // search for lines with "targetname"
  92. if(line.contains("targetname") && !(line.contains("none") || line.contains(","))){
  93. targetname = line.substring(line.indexOf("\"", line.indexOf("\"", line.indexOf("\"")+1)+1)+1, line.length()-1);
  94. // check if found targetname was already added
  95. if(!(applicableNames.contains(targetname))){
  96. // check if found targetname matches any Exceptions
  97. for(int j = 0; i < this.targetnameExceptions.size(); j++){
  98. if(targetname.startsWith(this.targetnameExceptions.get(j))){
  99. bol = true;
  100. }
  101. }
  102. // if it doesnt match any Exceptions add it to toBeRenamed
  103. if (!bol){
  104. applicableNames.add(targetname);
  105. }
  106. // reset bol for next line
  107. bol = false;
  108. }
  109. }
  110. // Local Progress Calculations
  111. if((double)progress / (double)totallines >= 0.025 * localprogress) {
  112. if(localprogress % 4 == 0) {
  113. publish(localprogress + "");
  114. } else {
  115. publish(".");
  116. }
  117. localprogress++;
  118. }
  119. // Overall Progress Calculations
  120. progress++;
  121. setProgress((int)(100 * (double)progress / (double)(3 * totallines)));
  122. }
  123. publish("10" + "\n");
  124. localprogress = 0;
  125.  
  126. // now we replace found entities targetname keyvalue with an Integer
  127. publish("\n");
  128. publish("Renaming Targetnames: 0");
  129.  
  130. String entry;
  131. for(int i = totallines; i < vmfList.size(); i++) { // run though all lines of vmf beginning from the first entity entry
  132. line = vmfList.get(i);
  133. for(int j = 0; j < applicableNames.size(); j++){ // run though all found targetnames for each line
  134. entry = applicableNames.get(j);
  135. if(line.contains(" " + entry + ",") || // inside "connections"
  136. line.contains("\"" + entry + "\"")|| // "targetname" keyvalue
  137. line.contains("\"" + entry + ",") || //
  138. line.contains("\"" + entry + ",") || //
  139. line.contains("," + entry + ",")) {
  140. // replace the targetname with an Integer
  141. line = line.replace(entry,"" + j);
  142. // we have to do the same checks for lowerCase as Hammer ignores Case-sensitivity
  143. } else if(line.toLowerCase().contains(" " + entry.toLowerCase() + ",") ||
  144. line.toLowerCase().contains("\"" + entry.toLowerCase() + "\"")||
  145. line.toLowerCase().contains("\"" + entry.toLowerCase() + ",") ||
  146. line.toLowerCase().contains("\"" + entry.toLowerCase() + ",") ||
  147. line.toLowerCase().contains("," + entry.toLowerCase() + ",")
  148. ) {
  149. // replace the targetname with an Integer
  150. line = line.toLowerCase().replace(entry.toLowerCase(),"" + j);
  151. }
  152. // Local Progress Calculations
  153. if((double)progress / (double)totallines >= 0.025 * localprogress) { //problemo here
  154. if(localprogress % 4 == 0) {
  155. publish(localprogress + "");
  156. } else {
  157. publish(".");
  158. }
  159. localprogress++;
  160. }
  161. // Overall Progress Calculations
  162. progress++;
  163. setProgress((int)(100 * (double)progress / (double)(3 * totallines)));
  164. }
  165. vmfList.set(i, line);
  166. }
  167. publish("10" + "\n");
  168.  
  169. // all steps are done
  170. publish("\n");
  171. publish("------------------------------------------------------------------------" + "\n");
  172. publish("\n");
  173. return vmfList;
  174. }
  175.  
  176. @Override
  177. protected void process(List<String> chunks) {
  178. for(String line : chunks) {
  179. this.console.append(line + "\n");
  180. }
  181. }
  182.  
  183. @Override
  184. protected void done() {
  185. System.out.println("test");
  186. }
  187.  
  188. private JTextArea console;
  189. private File vmf;
  190. private List<String> targetnameExceptions;
  191. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement