Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.94 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Duldrum Deleter
  3. // @author PenguinSquared
  4. //
  5. // @include https://steamcommunity.com/saliengame
  6. // @include https://steamcommunity.com/saliengame/
  7. // @include https://steamcommunity.com/saliengame/play
  8. // @include https://steamcommunity.com/saliengame/play/
  9. //
  10. // @version 1.1.2
  11. //
  12. // @run-at document-start|document-end
  13. //
  14. // @grant unsafeWindow
  15. //
  16. // @unwrap
  17. // ==/UserScript==
  18.  
  19. (function() {
  20. if (typeof unsafeWindow !== "undefined")
  21. unsafeWindow.requestAnimationFrame = c => { setTimeout(c, 1000 / 60); };
  22.  
  23. // Game broke reload and try again
  24. GameLoadError = function() {
  25. clearInterval(intervalFunc);
  26. setTimeout(function() {
  27. if (typeof unsafeWindow !== "undefined")
  28. unsafeWindow.location.reload();
  29. else
  30. window.location.reload();
  31. }, 750);
  32. }
  33.  
  34.  
  35. var joiningZone = false;
  36. var joiningPlanet = false;
  37. var gameCheck = function(){
  38.  
  39. if (!gGame || !gGame.m_State) return;
  40.  
  41. if (gGame.m_State instanceof CBootState && gGame.m_State.button) {
  42. startGame();
  43. return;
  44. }
  45.  
  46. if (gGame.m_State instanceof CPlanetSelectionState && gGame.m_State.m_rgPlanets) {
  47. // Go to uncaptured zone with the highest difficulty
  48. var uncapturedPlanets = gGame.m_State.m_rgPlanets
  49. .filter(function(p){ return p.state && !p.state.captured })
  50. .sort(function(p1, p2){return p2.state.difficulty - p1.state.difficulty});
  51.  
  52. if (uncapturedPlanets.length == 0) {
  53. console.log("We rekt every planet!");
  54. return;
  55. }
  56.  
  57. joinPlanet(uncapturedPlanets[0].id);
  58. return;
  59. }
  60.  
  61. if (gGame.m_State.m_VictoryScreen || gGame.m_State.m_LevelUpScreen) {
  62. gGame.ChangeState( new CBattleSelectionState( gGame.m_State.m_PlanetData.id ) );
  63. console.log('round done');
  64. return;
  65. }
  66.  
  67. if (gGame.m_State.m_ScoreIncrements && gGame.m_State.m_ScoreIncrements != 0 && gGame.m_State.m_rtBattleStart && gGame.m_State.m_rtBattleEnd) {
  68. var ptPerSec = (gGame.m_State.m_rtBattleEnd - gGame.m_State.m_rtBattleStart) / 1000;
  69. gGame.m_State.m_Score = gGame.m_State.m_ScoreIncrements * ptPerSec;
  70. gGame.m_State.m_ScoreIncrements = 0;
  71. }
  72.  
  73. if (gGame.m_State.m_EnemyManager) {
  74. joiningZone = false;
  75. return;
  76. }
  77.  
  78. if (gGame.m_State.m_PlanetData && gGame.m_State.m_PlanetData.zones) {
  79. joiningPlanet = false;
  80. // Go to boss in uncaptured zone if there is one
  81. var bossZone = gGame.m_State.m_PlanetData.zones
  82. .find(function(z){ return !z.captured && z.boss });
  83.  
  84. if (bossZone && bossZone.zone_position) {
  85. console.log('Boss battle at zone:', bossZone.zone_position);
  86. joinZone(bossZone.zone_position);
  87. return;
  88. }
  89.  
  90. // Go to uncaptured zone with the highest difficulty
  91. var uncapturedZones = gGame.m_State.m_PlanetData.zones
  92. .filter(function(z){ return !z.captured })
  93. .sort(function(z1, z2){return z2.difficulty - z1.difficulty});
  94.  
  95. if (uncapturedZones.length == 0 && gGame.m_State.m_PlanetData) {
  96. console.log("Planet is completely captured.");
  97. leavePlanet(gGame.m_State.m_PlanetData.id);
  98. return;
  99. }
  100.  
  101. joinZone(uncapturedZones[0].zone_position);
  102. return;
  103. }
  104. };
  105.  
  106. var intervalFunc = setInterval(gameCheck, 100);
  107.  
  108. var joinZone = function(zoneId) {
  109. if (joiningZone) return;
  110. console.log('Joining zone:', zoneId);
  111.  
  112. joiningZone = true;
  113.  
  114. clearInterval(intervalFunc);
  115.  
  116. gServer.JoinZone(
  117. zoneId,
  118. function ( results ) {
  119. gGame.ChangeState( new CBattleState( gGame.m_State.m_PlanetData, zoneId ) );
  120. },
  121. GameLoadError
  122. );
  123.  
  124. setTimeout(function() {
  125. intervalFunc = setInterval(gameCheck, 100);
  126. }, 10000);
  127. };
  128.  
  129. var joinPlanet = function(planetId) {
  130. if (joiningPlanet) return;
  131. console.log('Joining planet:', planetId);
  132.  
  133. joiningPlanet = true;
  134.  
  135. clearInterval(intervalFunc);
  136.  
  137. gServer.JoinPlanet(
  138. planetId,
  139. function ( response ) {
  140. gGame.ChangeState( new CBattleSelectionState( planetId ) );
  141. },
  142. function ( response ) {
  143. ShowAlertDialog( 'Join Planet Error', 'Failed to join planet. Please reload your game or try again shortly.' );
  144. }
  145. );
  146.  
  147. setTimeout(function() {
  148. intervalFunc = setInterval(gameCheck, 100);
  149. }, 10000);
  150. };
  151.  
  152. var leavePlanet = function(planetDataId) {
  153.  
  154. if (joiningPlanet) return;
  155. console.log('Leaving planet:', planetDataId);
  156.  
  157. joiningPlanet = true;
  158.  
  159. clearInterval(intervalFunc);
  160.  
  161. gServer.LeaveGameInstance(
  162. planetDataId,
  163. function() {
  164. gGame.ChangeState( new CPlanetSelectionState() );
  165. }
  166. );
  167.  
  168. setTimeout(function() {
  169. intervalFunc = setInterval(gameCheck, 100);
  170. }, 10000);
  171. };
  172.  
  173. var startGame = function() {
  174. console.log('Pressing Play in 2 seconds');
  175.  
  176. clearInterval(intervalFunc);
  177.  
  178. // wait 2 seconds for game to load
  179. // can't be arsed doing this programatically tbh
  180. setTimeout(function() {
  181. gGame.m_State.button.click();
  182.  
  183. setTimeout(function() {
  184. intervalFunc = setInterval(gameCheck, 100);
  185. }, 5000);
  186. }, 2000);
  187. };
  188. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement