Advertisement
Pr0nogo

Untitled

Jul 3rd, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.13 KB | None | 0 0
  1. // 0049ECF0 = InitializeUnit(), arg 1 unit_id, arg 2 x, arg 3 player, eax Unit *unit, edx y | Called also when transformed -- Needs ASM pseudocode
  2. pub unsafe fn init_unit_hook(
  3. unitid: u32,
  4. arg_x: u32,
  5. player: u32,
  6. unit: *mut bw::Unit,
  7. arg_y: u32,
  8. orig: &dyn Fn(u32, u32, u32, *mut Unit u32,)->u32)->u32 {
  9. let unit = match Unit::from_ptr(unit) {
  10. Some(s) => s,
  11. None => {
  12. return orig(unitid, arg_x, player, unit, arg_y);
  13. },
  14. };
  15. let mut result: u32 = 0;
  16. let mut active_unit = bw::active_iscript_unit;
  17. let mut flingy = bw::units_dat_flingy[unitid];
  18.  
  19. if bw::init_flingy(flingy, arg_y as u16, arg_x, unit, player as u8, 0) == 0 {
  20. //blockA
  21. result = 0;
  22. return result;
  23. }
  24. (*unit.0).player = player;
  25. (*unit.0).order = 0xBC; // Fatal
  26. (*unit.0).order_state = 0;
  27. (*unit.0).order_signal = 0;
  28. (*unit.0).order_fow_unit = 0;
  29. (*unit.0).order_timer = 0;
  30. (*unit.0).target = 0;
  31. (*unit.0).order_target_pos = 0;
  32. let first_child = (*unit.0).unit_specific; // assumed to be first_inside_child
  33. (*first_child.0).hitpoints = 0;
  34. (*first_child.0).sprite = 0;
  35. (*unit.0).unit_id = unitid;
  36. let mut sprite = (*unit.0).sprite;
  37. (*unit.0).carried_powerup_flags = 0;
  38. (*unit.0).secondary_order_wait = 0;
  39. if sprite != null_mut() {
  40. //blockB
  41. bw::progress_sprite_frame(sprite);
  42. (*unit.0).last_attacking_player = 0;
  43. (*unit.0).shields = bw::units_dat_shields[unitid] << 8;
  44. if unitid != 0xAC { // Shield Battery
  45. //blockC
  46. (*unit.0).energy = (bw::get_max_energy(unit.0) + (active_unit & 3)) << 2; // active_unit might also be player_id, or have defaulted to arg_y
  47. }
  48. else {
  49. (*unit.0).energy = 6400;
  50. }
  51. //blockD
  52. (*unit.0).ai_spell_flags = 0;
  53. (*sprite.0).elevation_level = bw::units_dat_elevation_level[unitid];
  54. let mut datFlags = bw::units_dat_flags[unitid] >> 1;
  55. let mut unitFlags = (*unit.0).flags;
  56. datFlags ^= unitFlags;
  57. unitFlags ^= unitFlags & 2; // Landed building
  58. datFlags ^= unitFlags;
  59. unitFlags = datFlags & 4 ^= unitFlags; // Air
  60.  
  61. datFlags = bw::units_dat_flags[unitid] >> 0xC;
  62. datFlags ^= unitFlags;
  63. datFlags &= 0x10000; // Organic
  64. datFlags ^= unitFlags;
  65. unitFlags = datFlags;
  66.  
  67. datFlags = bw::units_dat_flags[unitid] >> 0xA;
  68. datFlags ^= unitFlags;
  69. datFlags &= 0x20000; // Requires creep?
  70. datFlags ^= unitFlags;
  71. unitFlags = datFlags;
  72. unitFlags >> 2;
  73. unitFlags << 14;
  74. !unitFlags;
  75. unitFlags ^= datFlags;
  76. unitFlags &= 0x100000; // Burrowable
  77. unitFlags ^= datFlags;
  78.  
  79.  
  80. (*unit.0).flags = unitFlags;
  81. let mut pathFlags = (*unit.0).pathing_flags;
  82. let mut eax: u8 = 0;
  83. if bw::units_dat_elevation_level[unitid] < 0xC {
  84. eax = 1;
  85. }
  86. else {
  87. eax = 0;
  88. }
  89. eax ^= pathFlags;
  90. pathFlags = 1;
  91. eax ^= pathFlags;
  92. (*unit.0).pathing_flags = eax;
  93. if unitid < 0xC2 { // Zerg Beacon
  94. //blockE
  95. if unitid != 0xCC { // Floor Hatch
  96. //blockG
  97. if (bw::units_dat_flags[unitid] & 1) == 0 { // Building
  98. (*unit.0).tech = 0x2C;
  99. (*unit.0).upgrade = 0x3D;
  100. }
  101. }
  102. //blockF
  103. (*unit.0).flags |= 0x200000; // No collision
  104. }
  105. if unitid <= 0xC7 { // Protoss Flag Beacon
  106. //blockF
  107. (*unit.0).flags |= 0x200000; // No collision
  108. //blockG
  109. if (bw::units_dat_flags[unitid] & 1) == 0 { // Building
  110. (*unit.0).tech = 0x2C;
  111. (*unit.0).upgrade = 0x3D;
  112. }
  113. }
  114. //blockH
  115. eax = 0;
  116. (*unit.0).path = 0;
  117. (*unit.0).movement_state = 0;
  118. (*unit.0).move_target_update_timer = 0;
  119. let mut imageid = (*sprite.0).image.image_id;
  120. let mut buildTime = bw::units_dat_build_time[unit];
  121. if (bw::units_dat_flags[unitid] & 0x20000000) == 1 { // Invincible
  122. //blockI
  123. if (bw::units_dat_flags[unitid] & 0x20000000) == 0 { // Invincible
  124. //blockK
  125. (*unit.0).building_overlay_state = bw::building_overlay_state_max[sprite];
  126. (*unit.0).remaining_build_time = buildTime;
  127. if buildTime == 0 {
  128. (*unit.0).remaining_build_time = 1;
  129. }
  130. //blockL
  131. bw::set_build_hp_gain(unit.0);
  132. bw::set_build_shield_gain(unit.0);
  133. bw::set_upgrade_speed(unit.0);
  134. bw::update_speed(unit.0);
  135. result = 1;
  136. return result;
  137. }
  138. eax = (*unit.0).flags;
  139. eax &= 0xFBFF_FFFF
  140. }
  141. else {
  142. eax |= 4000000; // Invincible
  143. }
  144. //blockJ
  145. (*unit.0).flags = eax;
  146. //blockK
  147. (*unit.0).building_overlay_state = bw::building_overlay_state_max[sprite];
  148. (*unit.0).remaining_build_time = buildTime;
  149. if buildTime == 0 {
  150. (*unit.0).remaining_build_time = 1;
  151. }
  152. //blockL
  153. bw::set_build_hp_gain(unit.0);
  154. bw::set_build_shield_gain(unit.0);
  155. bw::set_upgrade_speed(unit.0);
  156. bw::update_speed(unit.0);
  157. result = 1;
  158. return result;
  159. }
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement