infernal wrapper

Supplies some wrapper functions for public use

  1. // ==UserScript==
  2. // @name infernal wrapper
  3. // @description Supplies some wrapper functions for public use
  4. // @namespace infernal_wrapper
  5. // @include https://prodgame*.alliances.commandandconquer.com/*/index.aspx*
  6. // @version 0.390737.5
  7. // @author infernal_me, KRS_L, krisan
  8. // ==/UserScript==
  9. (function () {
  10. var CCTAWrapper_main = function () {
  11. try {
  12. _log = function () {
  13. if (typeof console != 'undefined') console.log(arguments);
  14. else if (window.opera) opera.postError(arguments);
  15. else GM_log(arguments);
  16. }
  17.  
  18. function createCCTAWrapper() {
  19. console.log('CCTAWrapper loaded');
  20. _log('wrapper loading' + PerforceChangelist);
  21. System = $I;
  22. SharedLib = $I;
  23. var strFunction;
  24. // SharedLib.Combat.CbtSimulation.prototype.DoStep
  25. for (var x in $I) {
  26. for (var key in $I[x].prototype) {
  27. if ($I[x].prototype.hasOwnProperty(key) && typeof($I[x].prototype[key]) === 'function') { // reduced iterations from 20K to 12K
  28. strFunction = $I[x].prototype[key].toString();
  29. if (strFunction.indexOf("().l;var b;for (var d = 0 ; d < c.length ; d++){b = c[d];if((b.") > -1) {
  30. $I[x].prototype.DoStep = $I[x].prototype[key];
  31. console.log("SharedLib.Combat.CbtSimulation.prototype.DoStep = $I." + x + ".prototype." + key);
  32. break;
  33. }
  34. }
  35. }
  36. }
  37.  
  38. // ClientLib.Data.CityRepair.prototype.CanRepair
  39. for (var key in ClientLib.Data.CityRepair.prototype) {
  40. if (typeof ClientLib.Data.CityRepair.prototype[key] === 'function') {
  41. strFunction = ClientLib.Data.CityRepair.prototype[key].toString();
  42. if (strFunction.indexOf("DefenseSetup") > -1 && strFunction.indexOf("DamagedEntity") > -1) { // order important to reduce iterations
  43. ClientLib.Data.CityRepair.prototype.CanRepair = ClientLib.Data.CityRepair.prototype[key];
  44. console.log("ClientLib.Data.CityRepair.prototype.CanRepair = ClientLib.Data.CityRepair.prototype." + key);
  45. break;
  46. }
  47. }
  48. }
  49.  
  50. // ClientLib.Data.CityRepair.prototype.UpdateCachedFullRepairAllCost
  51. for (var key in ClientLib.Data.CityRepair.prototype) {
  52. if (typeof ClientLib.Data.CityRepair.prototype[key] === 'function') {
  53. strFunction = ClientLib.Data.CityRepair.prototype[key].toString();
  54. if (strFunction.indexOf("Type==7") > -1 && strFunction.indexOf("var a=0;if") > -1) { // order important to reduce iterations
  55. ClientLib.Data.CityRepair.prototype.UpdateCachedFullRepairAllCost = ClientLib.Data.CityRepair.prototype[key];
  56. console.log("ClientLib.Data.CityRepair.prototype.UpdateCachedFullRepairAllCost = ClientLib.Data.CityRepair.prototype." + key);
  57. break;
  58. }
  59. }
  60. }
  61.  
  62. // ClientLib.Data.CityUnits.prototype.get_OffenseUnits
  63. strFunction = ClientLib.Data.CityUnits.prototype.HasUnitMdbId.toString();
  64. var searchString = "for (var b in {d:this.";
  65. var startPos = strFunction.indexOf(searchString) + searchString.length;
  66. var fn_name = strFunction.slice(startPos, startPos + 6);
  67. strFunction = "var $createHelper;return this." + fn_name + ";";
  68. var fn = Function('', strFunction);
  69. ClientLib.Data.CityUnits.prototype.get_OffenseUnits = fn;
  70. console.log("ClientLib.Data.CityUnits.prototype.get_OffenseUnits = function(){var $createHelper;return this." + fn_name + ";}");
  71.  
  72. // ClientLib.Data.CityUnits.prototype.get_DefenseUnits
  73. strFunction = ClientLib.Data.CityUnits.prototype.HasUnitMdbId.toString();
  74. searchString = "for (var c in {d:this.";
  75. startPos = strFunction.indexOf(searchString) + searchString.length;
  76. fn_name = strFunction.slice(startPos, startPos + 6);
  77. strFunction = "var $createHelper;return this." + fn_name + ";";
  78. fn = Function('', strFunction);
  79. ClientLib.Data.CityUnits.prototype.get_DefenseUnits = fn;
  80. console.log("ClientLib.Data.CityUnits.prototype.get_DefenseUnits = function(){var $createHelper;return this." + fn_name + ";}");
  81.  
  82. // ClientLib.Vis.Battleground.Battleground.prototype.get_Simulation
  83. strFunction = ClientLib.Vis.Battleground.Battleground.prototype.StartBattle.toString();
  84. searchString = "=0;for(var a=0; (a<9); a++){this.";
  85. startPos = strFunction.indexOf(searchString) + searchString.length;
  86. fn_name = strFunction.slice(startPos, startPos + 6);
  87. strFunction = "return this." + fn_name + ";";
  88. fn = Function('', strFunction);
  89. ClientLib.Vis.Battleground.Battleground.prototype.get_Simulation = fn;
  90. console.log("ClientLib.Vis.Battleground.Battleground.prototype.get_Simulation = function(){return this." + fn_name + ";}");
  91.  
  92. // GetNerfBoostModifier
  93. if (typeof ClientLib.Vis.Battleground.Battleground.prototype.GetNerfAndBoostModifier == 'undefined') ClientLib.Vis.Battleground.Battleground.prototype.GetNerfAndBoostModifier = ClientLib.Base.Util.GetNerfAndBoostModifier;
  94.  
  95. _log('wrapper loaded');
  96. }
  97. } catch (e) {
  98. console.log("createCCTAWrapper: ", e);
  99. }
  100.  
  101. function CCTAWrapper_checkIfLoaded() {
  102. try {
  103. if (typeof qx !== 'undefined') {
  104. createCCTAWrapper();
  105. } else {
  106. window.setTimeout(CCTAWrapper_checkIfLoaded, 1000);
  107. }
  108. } catch (e) {
  109. CCTAWrapper_IsInstalled = false;
  110. console.log("CCTAWrapper_checkIfLoaded: ", e);
  111. }
  112. }
  113.  
  114. if (/commandandconquer\.com/i.test(document.domain)) {
  115. window.setTimeout(CCTAWrapper_checkIfLoaded, 1000);
  116. }
  117. }
  118.  
  119. try {
  120. var CCTAWrapper = document.createElement("script");
  121. CCTAWrapper.innerHTML = "var CCTAWrapper_IsInstalled = true; (" + CCTAWrapper_main.toString() + ")();";
  122. CCTAWrapper.type = "text/javascript";
  123. if (/commandandconquer\.com/i.test(document.domain)) {
  124. document.getElementsByTagName("head")[0].appendChild(CCTAWrapper);
  125. }
  126. } catch (e) {
  127. console.log("CCTAWrapper: init error: ", e);
  128. }
  129. })();