Advertisement
Pr0nogo

Untitled

Aug 29th, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.37 KB | None | 0 0
  1. /// This is where the magic happens; program your plug-in's core behavior here.
  2.  
  3. #include "game_hooks.h"
  4. #include <graphics/graphics.h>
  5. #include <SCBW/api.h>
  6. #include <SCBW/ExtendSightLimit.h>
  7. #include "psi_field.h"
  8. #include <cstdio>
  9.  
  10.  
  11. namespace hooks {
  12.  
  13. const u32 Func_GetAllUnitsInBounds = 0x0042FF80;
  14. CUnit** getAllUnitsInBounds(Box16* coords) {
  15. static CUnit** units_in_bounds;
  16. __asm {
  17. PUSHAD
  18. MOV EAX, coords
  19. CALL Func_GetAllUnitsInBounds
  20. MOV units_in_bounds, EAX
  21. POPAD
  22. }
  23.  
  24. return units_in_bounds;
  25. };
  26.  
  27. u32 alexeiproperties;
  28. bool detector_upgrade_unresearched = false;
  29.  
  30. u8 oldArmorType;
  31. u8 oldArmorAmount;
  32. const u32 Func_ReplaceUnitWithType = 0x0049FED0;
  33. void replaceUnitWithType(CUnit* unit, u16 newUnitId) {
  34.  
  35. u32 newUnitId_ = newUnitId;
  36.  
  37. __asm {
  38. PUSHAD
  39. PUSH newUnitId_
  40. MOV EAX, unit
  41. CALL Func_ReplaceUnitWithType
  42. POPAD
  43. }
  44.  
  45. };
  46.  
  47. ;
  48.  
  49.  
  50. void resetTaunt(CUnit* unit) {
  51. CExtendedUnitLayout* extendedStatus = unit->getExtendedUnitStatus();
  52. if(extendedStatus) {
  53. extendedStatus->tauntTimer = 0;
  54. extendedStatus->tauntTarget = NULL;
  55. unit->pAI = extendedStatus->oldAIBehavior;
  56. extendedStatus->oldAIBehavior = NULL;
  57. unit->prepareForNextOrder_Wrap();
  58. }
  59. }
  60.  
  61. void doTauntEffect(CUnit* unit) {
  62. static u32* const unknown_value_6BEE64 = (u32*) 0x006BEE64;
  63. static u32* const unknown_array_size_6BEE6C = (u32*) 0x006BEE6C; //array with 1st elem being size of array
  64.  
  65. static u16* const maxBoxRightValue = (u16*) 0x00628450;
  66. static u16* const maxBoxBottomValue = (u16*) 0x006284B4;
  67.  
  68. Box16 area_of_effect;
  69.  
  70. CUnit** unitsInAreaOfEffect;
  71. CUnit* current_unit;
  72. int x = unit->getX();
  73. int y = unit->getY();
  74.  
  75.  
  76. area_of_effect.left = (u16)x - weapons_dat::MaxRange[WeaponId::GaussRifle2_Unused];
  77. area_of_effect.right = (u16)x + weapons_dat::MaxRange[WeaponId::GaussRifle2_Unused];
  78. area_of_effect.top = (u16)y - weapons_dat::MaxRange[WeaponId::GaussRifle2_Unused];
  79. area_of_effect.bottom = (u16)y + weapons_dat::MaxRange[WeaponId::GaussRifle2_Unused];
  80.  
  81.  
  82. if(area_of_effect.left < 0)
  83. area_of_effect.left = 0;
  84. else
  85. if(area_of_effect.right > *maxBoxRightValue)
  86. area_of_effect.right = *maxBoxRightValue;
  87.  
  88. if(area_of_effect.top < 0)
  89. area_of_effect.top = 0;
  90. else
  91. if(area_of_effect.bottom > *maxBoxBottomValue)
  92. area_of_effect.bottom = *maxBoxBottomValue;
  93.  
  94. unitsInAreaOfEffect = getAllUnitsInBounds(&area_of_effect);
  95. current_unit = *unitsInAreaOfEffect;
  96. while(current_unit != NULL) {
  97. if(current_unit->isTargetEnemy(unit) && current_unit != unit) {
  98. bool shouldBeTaunted = true;
  99. if(!(current_unit->isTargetEnemy(unit)))
  100. shouldBeTaunted = false;
  101.  
  102. if(shouldBeTaunted) {
  103. CExtendedUnitLayout* extendedStatus = current_unit->getExtendedUnitStatus();
  104. if(extendedStatus) {
  105. extendedStatus->tauntTimer = 48;
  106. extendedStatus->tauntTarget = unit;
  107. extendedStatus->oldAIBehavior = current_unit->pAI;
  108. current_unit->pAI = NULL;
  109. }
  110. }
  111.  
  112. //current_unit->order(OrderId::Die, current_unit->getX(), current_unit->getY(), current_unit, current_unit->id, true);
  113. }
  114.  
  115. unitsInAreaOfEffect++; //go on next unit of the list (or null)
  116. current_unit = *unitsInAreaOfEffect;
  117. }
  118.  
  119. //code probably related to the use of getAllUnitsInBounds
  120. *unknown_value_6BEE64 = unknown_array_size_6BEE6C[unknown_array_size_6BEE6C[0]];
  121. unknown_array_size_6BEE6C[0] = unknown_array_size_6BEE6C[0] - 1;
  122.  
  123. }
  124.  
  125. bool resetExtendedStatus = false;
  126.  
  127.  
  128. /// This hook is called every frame; most of your plugin's logic goes here.
  129. bool nextFrame() {
  130.  
  131. if (!scbw::isGamePaused()) { //If the game is not paused
  132.  
  133. scbw::setInGameLoopState(true); //Needed for scbw::random() to work
  134. graphics::resetAllGraphics();
  135. hooks::updatePsiFieldProviders();
  136.  
  137. //This block is executed once every game.
  138. if (*elapsedTimeFrames == 0) {
  139. //Write your code here
  140. oldArmorType = units_dat::ArmorUpgrade[UnitId::fenix_zealot];
  141. oldArmorAmount = units_dat::ArmorAmount[UnitId::fenix_zealot];
  142. alexeiproperties = units_dat::BaseProperty[UnitId::Hero_AlexeiStukov]; /// Stores default flags for Alexei Stukov, used to revert data back between maps/saves
  143. bool detector_upgrade_unresearched = true; /// Boolean variable: set to false when researched; set to true otherwise
  144. }
  145.  
  146. //Loop through all visible units in the game.
  147. for (CUnit *unit = *firstVisibleUnit; unit; unit = unit->link.next) {
  148. //Write your code here
  149.  
  150. if( !(unit->getExtendedUnitStatus()) /*&& !unit->doNotCreateExtendedStatus*/) {
  151. CExtendedUnitLayout* extended = (CExtendedUnitLayout*)calloc(1, sizeof(CExtendedUnitLayout));
  152. unit->storeExtendedUnitStatus(extended);
  153. }
  154.  
  155.  
  156. if(unit->id == UnitId::fenix_zealot && unit->mainOrderId == OrderId::CarrierStop) {
  157. if(unit->energy < techdata_dat::EnergyCost[TechId::UnusedTech43] * 256) {
  158. scbw::showErrorMessageWithSfx(unit->playerId, 864, 158);
  159. }
  160. else {
  161. doTauntEffect(unit);
  162. unit->energy = unit->energy - (techdata_dat::EnergyCost[TechId::UnusedTech43] * 256);
  163. }
  164. }
  165.  
  166.  
  167. CExtendedUnitLayout* extendedStatus = unit->getExtendedUnitStatus();
  168. if(extendedStatus) {
  169.  
  170. if(unit->id == UnitId::fenix_zealot && unit->mainOrderId == OrderId::ReaverStop) {
  171. if(unit->energy < techdata_dat::EnergyCost[TechId::UnusedTech42] * 256) {
  172. scbw::showErrorMessageWithSfx(unit->playerId, 864, 158);
  173. }
  174. else {
  175. if(units_dat::ArmorUpgrade[UnitId::fenix_zealot] == oldArmorType) {
  176. int armorAmount = scbw::getUpgradeLevel(unit->playerId, extendedStatus->oldArmorType) + extendedStatus->oldArmorAmount + 5;
  177. unit->energy = unit->energy - (techdata_dat::EnergyCost[TechId::UnusedTech42] * 256);
  178. units_dat::ArmorUpgrade[UnitId::fenix_zealot] = UpgradeId::UnusedUpgrade57;
  179. units_dat::ArmorAmount[UnitId::fenix_zealot] = armorAmount;
  180. s32 shields = unit->shields;
  181. u16 energy = unit->energy;
  182. replaceUnitWithType(unit, unit->id);
  183. unit->shields = shields;
  184. unit->energy = energy;
  185. }
  186. extendedStatus->armorBuffTimer += techdata_dat::TimeCost[TechId::UnusedTech42];
  187.  
  188. }
  189. }
  190.  
  191. if(unit->id == UnitId::fenix_zealot && units_dat::ArmorUpgrade[UnitId::fenix_zealot] != oldArmorType && extendedStatus->armorBuffTimer == 0) {
  192. units_dat::ArmorUpgrade[UnitId::fenix_zealot] = oldArmorType;
  193. units_dat::ArmorAmount[UnitId::fenix_zealot] = oldArmorAmount;
  194. s32 shields = unit->shields;
  195. replaceUnitWithType(unit, unit->id);
  196. unit->shields = shields;
  197. }
  198.  
  199. if( (!(extendedStatus->tauntTarget) || extendedStatus->tauntTarget->hitPoints <= 0 || extendedStatus->tauntTarget->mainOrderId == OrderId::Die) && extendedStatus->tauntTimer > 0) {
  200. //resetTaunt(unit);
  201. scbw::printText("YOU SHOULD NOT BE SEEING THIS.");
  202. }
  203.  
  204. if(extendedStatus->tauntTimer == 0 && extendedStatus->tauntTarget) {
  205. //resetTaunt(unit);
  206. scbw::printText("YOU SHOULD NOT BE SEEING THIS EITHER.");
  207. }
  208.  
  209. if(extendedStatus->tauntTimer > 0) {
  210. if(unit->mainOrderId != OrderId::AttackUnit || unit->orderTarget.unit != extendedStatus->tauntTarget) {
  211. unit->orderTo(OrderId::AttackUnit, extendedStatus->tauntTarget);
  212. }
  213. }
  214.  
  215. /// Alekei Stukov detector upgrade
  216. if(unit->id == UnitId::Hero_AlexeiStukov && /// Unit ID 100
  217. scbw::getUpgradeLevel(unit->playerId, 57) && /// Upgrade ID 57
  218. detector_upgrade_unresearched) /// Reference to boolean (makes it local? what does this do?)
  219. {
  220. units_dat::BaseProperty[UnitId::Hero_AlexeiStukov] |= UnitProperty::Detector; /// Applies Detector flag to all future Alexei Stukov units
  221. detector_upgrade_unresearched = false; /// Sets boolean to false
  222. replaceUnitWithType(unit, unit->id); /// Replaces all existing Alexei Stukov units with new instances, to make the upgrade take into effect
  223. scbw::printText("STUKOV DETECTION ON"); /// Debug text
  224. }
  225. }
  226.  
  227. }
  228.  
  229. scbw::setInGameLoopState(false);
  230.  
  231. }
  232.  
  233. return true;
  234.  
  235. }
  236.  
  237. bool gameOn() {
  238. resetExtendedStatus = true;
  239. return true;
  240. }
  241.  
  242. bool gameEnd() {
  243. units_dat::ArmorUpgrade[UnitId::fenix_zealot] = oldArmorType;
  244. units_dat::ArmorAmount[UnitId::fenix_zealot] = oldArmorAmount;
  245. units_dat::BaseProperty[UnitId::Hero_AlexeiStukov] = alexeiproperties;
  246. scbw::setGameLoadState(true);
  247. return true;
  248. }
  249.  
  250. } //hooks
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement