Pr0nogo

Untitled

Jan 13th, 2021
488
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //for simple extenders (i.e. same byte length)
  2. #![allow(non_snake_case)]
  3. #![allow(dead_code)]
  4. use samase;
  5. use config::{UnitsDatEntry};
  6. use failure::{Context,Error};
  7. use parking_lot::{Mutex, RwLock};
  8. use globals::{self,Globals};
  9. use bw;
  10. use windows;
  11. use winapi::um::processthreadsapi::{GetCurrentProcess, TerminateProcess};
  12.  
  13. lazy_static! {
  14.    static ref FAKE_UNIT_EXTENDER: RwLock<UnitExtender> = RwLock::new(Default::default());
  15.    static ref FLINGY_EXTENDER: RwLock<FlingyExtender> = RwLock::new(Default::default());
  16.    static ref SPRITE_EXTENDER: RwLock<SpriteExtender> = RwLock::new(Default::default());
  17.    static ref IMAGE_EXTENDER: RwLock<ImageExtender> = RwLock::new(Default::default());
  18.    static ref SFX_EXTENDER: RwLock<SFXExtender> = RwLock::new(Default::default());
  19.    static ref CCMU_EXTENDER: RwLock<CcmuExtender> = RwLock::new(Default::default());
  20. }
  21.  
  22. pub unsafe fn init_flingy_ext(exe: &mut whack::ModulePatcher){
  23.     FLINGY_EXTENDER.write().extend_data_conventional(exe);
  24. }
  25.  
  26. pub unsafe fn init_sprite_ext(exe: &mut whack::ModulePatcher){
  27.     SPRITE_EXTENDER.write().extend_data_conventional(exe);
  28. }
  29. pub unsafe fn init_image_ext_new(exe: &mut whack::ModulePatcher){
  30.     IMAGE_EXTENDER.write().init_code(exe);
  31. }
  32. pub unsafe fn init_unit_ext(exe: &mut whack::ModulePatcher){
  33.     FAKE_UNIT_EXTENDER.write().extend_data_conventional(exe);
  34. }
  35. pub unsafe fn init_new_sprite_ext(exe: &mut whack::ModulePatcher){
  36.     SPRITE_EXTENDER.write().extend_data_from_dat_file(exe);
  37. }
  38. pub unsafe fn flingy_identifier(string: &str)->Option<FlingyValues>{
  39.     let mut r = FLINGY_EXTENDER.write();
  40.     let identifier = r.identifier(string);
  41.     identifier
  42. }
  43. pub unsafe fn sprite_identifier(string: &str)->Option<SpriteValues>{
  44.     let mut r = SPRITE_EXTENDER.write();
  45.     let identifier = r.identifier(string);
  46.     identifier
  47. }
  48. pub unsafe fn image_identifier(string: &str)->Option<ImageValues>{
  49.     let mut r = IMAGE_EXTENDER.write();
  50.     let identifier = r.identifier(string);
  51.     identifier
  52. }
  53.  
  54. pub unsafe fn fakeid_flingy_ptr()->u32 {
  55.     let mut w = FAKE_UNIT_EXTENDER.write();
  56.     if w.flingy_ext.len()==0 {
  57.         return 0;
  58.     }
  59.     let array = &mut w.flingy_ext[0] as *mut u32 as u32;
  60.     array
  61. }
  62.  
  63. pub unsafe fn set_image_entries(exe: &mut whack::ModulePatcher){
  64.     IMAGE_EXTENDER.write().extend_data_conventional(exe);
  65. }
  66.  
  67. pub unsafe fn flingy_ext_debug(){
  68. //  FLINGY_EXTENDER.write().extender_debug();
  69. }
  70.  
  71. pub unsafe fn get_flingy_data(entry: u32, index: usize)->u32{
  72.     let r = FLINGY_EXTENDER.read();
  73.     let result = match entry {
  74.         0=>r.top_speed[index].into(),
  75.         1=>r.acceleration[index].into(),
  76.         2=>r.turn_radius[index].into(),
  77.         3=>r.movement_type[index].into(),
  78.         4=>r.sprite_id[index].into(),
  79.         5=>r.halt_distance[index].into(),
  80.         6=>r.iscript_mask[index].into(),
  81.         _=>0,
  82.     };
  83.     result
  84. }
  85. pub unsafe fn get_unit_data(entry: u32, index: usize)->u32{
  86.     let r = FAKE_UNIT_EXTENDER.read();
  87.     let result = match entry {
  88.         0=>r.flingy_ext[index].into(),
  89.         29=>r.snd_ready[index].into(),
  90.         30=>r.snd_wht_start[index].into(),
  91.         31=>r.snd_wht_end[index].into(),
  92.         32=>r.snd_pss_start[index].into(),
  93.         33=>r.snd_pss_end[index].into(),
  94.         34=>r.snd_yes_start[index].into(),
  95.         35=>r.snd_yes_end[index].into(),
  96.         _=>0,
  97.     };
  98.     result
  99. }
  100. pub unsafe fn set_flingy_data(entry: u32, index: usize, value: u32){
  101.     let mut r = FLINGY_EXTENDER.write();
  102.     match entry {
  103.         0=>r.top_speed[index] = value,
  104.         1=>r.acceleration[index] = value as u16,
  105.         2=>r.turn_radius[index] = value as u8,
  106.         3=>r.movement_type[index] = value as u8,
  107.         4=>r.sprite_id[index] = value as u16,
  108.         5=>r.halt_distance[index] = value,
  109.         6=>r.iscript_mask[index] = value as u8,
  110.         _=>{},
  111.     }  
  112. }
  113. pub unsafe fn set_flingy_data_e(entry: FlingyValues, index: usize, value: u32){
  114.     let mut r = FLINGY_EXTENDER.write();
  115.     match entry {
  116.         FlingyValues::TopSpeed=>r.top_speed[index] = value,
  117.         FlingyValues::Acceleration=>r.acceleration[index] = value as u16,
  118.         FlingyValues::TurnRadius=>r.turn_radius[index] = value as u8,
  119.         FlingyValues::MovementType=>r.movement_type[index] = value as u8,
  120.         FlingyValues::SpriteId=>r.sprite_id[index] = value as u16,
  121.         FlingyValues::HaltDistance=>r.halt_distance[index] = value,
  122.         FlingyValues::IscriptMask=>r.iscript_mask[index] = value as u8,
  123.         _=>{},
  124.     }  
  125. }
  126. pub unsafe fn set_unit_data_e(entry: UnitsDatEntry, index: usize, value: u32){
  127.     let mut r = FAKE_UNIT_EXTENDER.write();
  128.     match entry {
  129.         UnitsDatEntry::Flingy=>r.flingy_ext[index] = value as u32,
  130.         UnitsDatEntry::SndReady=>r.snd_ready[index] = value as u16,
  131.         UnitsDatEntry::SndYesFirst=>r.snd_yes_start[index] = value as u16,
  132.         UnitsDatEntry::SndYesLast=>r.snd_yes_end[index] = value as u16,
  133.         UnitsDatEntry::SndWhatFirst=>r.snd_wht_start[index] = value as u16,
  134.         UnitsDatEntry::SndWhatLast=>r.snd_wht_end[index] = value as u16,
  135.         UnitsDatEntry::SndPissedFirst=>r.snd_pss_start[index] = value as u16,
  136.         UnitsDatEntry::SndPissedLast=>r.snd_pss_end[index] = value as u16,
  137.         _=>{},
  138.     }  
  139. }
  140.  
  141. pub unsafe fn set_sprite_data_e(entry: SpriteValues, index: usize, value: u32){
  142.     let mut r = SPRITE_EXTENDER.write();
  143.     match entry {
  144.         SpriteValues::IncludeInVision=>r.include_in_vision[index]=value as u8,
  145.         SpriteValues::StartAsVisible=>r.start_as_visible[index]=value as u8,
  146.         SpriteValues::ImageId=>r.image_id[index]=value as u16,
  147.         SpriteValues::SelectionCircle=>r.selection_circle[index]=value as u8,
  148.         SpriteValues::ImagePos=>r.imagepos[index]=value as u8,
  149.         SpriteValues::HpBar=>r.hp_bar[index]=value as u8,
  150.         _=>{},
  151.     }  
  152. }
  153. pub unsafe fn set_image_data_e(entry: ImageValues, index: usize, value: u32){
  154.     let mut r = IMAGE_EXTENDER.write();
  155.     match entry {
  156.         ImageValues::GrpId => r.grp_id[index]=value as u32,
  157.         ImageValues::GraphicTurns => r.graphic_turns[index]=value as u8,
  158.         ImageValues::Clickable => r.clickable[index]=value as u8,
  159.         ImageValues::UseFullIscript => r.use_full_iscript[index]=value as u8,
  160.         ImageValues::DrawIfCloaked => r.draw_if_cloaked[index]=value as u8,
  161.         ImageValues::DrawFunc => r.draw_func[index]=value as u8,
  162.         ImageValues::DrawRemap => r.draw_remap[index]=value as u8,
  163.         ImageValues::IscriptId => r.iscript_id[index]=value as u32,
  164.         ImageValues::OverlayShield => r.overlay_shield[index]=value as u32,
  165.         ImageValues::OverlayAttack => r.overlay_attack[index]=value as u32,
  166.         ImageValues::OverlayDamage => r.overlay_damage[index]=value as u32,
  167.         ImageValues::OverlaySpecial => r.overlay_special[index]=value as u32,
  168.         ImageValues::OverlayLanding => r.overlay_landing[index]=value as u32,
  169.         ImageValues::OverlayLiftoff => r.overlay_liftoff[index]=value as u32,
  170.         _=>(),
  171.     }
  172. }
  173.  
  174. pub unsafe fn set_sprite_data(entry: u32, index: usize, value: u32) {
  175.     let mut r = SPRITE_EXTENDER.write();
  176.     match entry {
  177.         0=>r.include_in_vision[index]=value as u8,
  178.         1=>r.start_as_visible[index]=value as u8,
  179.         2=>r.image_id[index]=value as u16,
  180.         3=>r.selection_circle[index]=value as u8,
  181.         4=>r.imagepos[index]=value as u8,
  182.         5=>r.hp_bar[index]=value as u8,
  183.         _=>(), 
  184.     }
  185. }
  186. pub unsafe fn get_sprite_data(entry: u32, index: usize)->u32 {
  187.     let r = SPRITE_EXTENDER.read();
  188.     match entry {
  189.         4|5|6=>{
  190.             if index < 105 {
  191.                 return 0;
  192.             }
  193.         },
  194.         _=>{},
  195.     }
  196.     let result = match entry {
  197.         0=>r.include_in_vision[index].into(),
  198.         1=>r.start_as_visible[index].into(),
  199.         2=>r.image_id[index].into(),
  200.         3=>r.selection_circle[index-105].into(),
  201.         4=>r.imagepos[index-105].into(),
  202.         5=>r.hp_bar[index-105].into(),
  203.         _=>0,
  204.     };
  205.     result
  206. }
  207.  
  208. pub unsafe fn get_image_data(entry: u32, index: usize)->u32{
  209.     let r = IMAGE_EXTENDER.read();
  210.     let length = r.length as usize;
  211.     let result = match entry {
  212.         0 => r.grp_id[index].into(),
  213.         1 => r.graphic_turns[index].into(),
  214.         2 => r.clickable[index].into(),
  215.         3 => r.use_full_iscript[index].into(),
  216.         4 => r.draw_if_cloaked[index].into(),
  217.         5 => r.draw_func[index].into(),
  218.         6 => r.draw_remap[index].into(),
  219.         7 => r.iscript_id[index].into(),
  220.         8 => r.overlay_shield[index].into(),
  221.         9 => r.overlay_attack[index].into(),
  222.         10 => r.overlay_damage[index].into(),
  223.         11 => r.overlay_special[index].into(),
  224.         12 => r.overlay_landing[index].into(),
  225.         13 => r.overlay_liftoff[index].into(),
  226.         14 => r.overlays[index+length*5].into(),
  227.         15 => r.overlays[index].into(), //attack overlays
  228.         16 => r.overlays[index+length].into(), //damage overlays
  229.         17 => r.overlays[index+length*2].into(), //special overlays
  230.         18 => r.overlays[index+length*3].into(), //landing overlays
  231.         19 => r.overlays[index+length*4].into(), //liftoff overlays
  232.         20 => r.image_grp_ptr[index].into(),
  233.         21 => r.building_overlay_state_max[index].into(),
  234.         _=>0,
  235.     };
  236.     result
  237. }
  238.  
  239.  
  240. pub trait DataExtender {
  241.     type Id: Copy;
  242.     type SizeLimit;
  243.     unsafe fn uplink<T>(exe: &mut whack::ModulePatcher, new_array: *mut T, address_list: Vec<usize>){
  244.         //debug!("Uplink list...");
  245.         for a in address_list {
  246.             //debug!("address: {:x}, val {:p}",a,new_array);   
  247.             exe.replace_val(a, new_array as u32);
  248.         }  
  249.     }
  250.     unsafe fn uplink_length_dattable(exe: &mut whack::ModulePatcher, length: u32, size_address: Vec<usize>){
  251.         //debug!("Uplink length list...");
  252.         for i in size_address {
  253.             //debug!("address: 0x{:x} {}",i,length);
  254.             exe.replace_val(i, length);
  255.         }
  256.        
  257.     }  
  258.     unsafe fn init_code(&mut self, exe: &mut whack::ModulePatcher){}
  259.     fn get(&mut self, index: usize, identifier: Self::Id)->u32;
  260.     fn identifier(&mut self, line: &str)->Option<Self::Id>;
  261.     fn push_val<T: num_traits::cast::ToPrimitive>(&mut self, identifier: Self::Id, value: T);
  262.     fn set<T: num_traits::cast::ToPrimitive>(&mut self, index: usize, identifier: Self::Id, value: T);
  263.     unsafe fn parse_entry_value(&mut self, text: String, identifier: Self::Id)->u32;
  264.     unsafe fn parse(&mut self, filename: &str)->Result<(),String>{
  265.         //debug!("Parse stuff");
  266.         let (data, len) = match samase::read_file(filename) {
  267.             Some(s) => s,
  268.             None => { return Err(format!("Unable to read file {}",filename)); },
  269.         };
  270.         let slice = std::slice::from_raw_parts(data, len);
  271.         for line in slice.split(|&x| x == b'\n')
  272.         {
  273.             let line = String::from_utf8_lossy(line);
  274.             let line = line.trim();
  275.             if line.starts_with("#") || line.starts_with(";") || line.is_empty() {
  276.                 continue;
  277.             }
  278.             let command_list: Vec<&str> = line.split(':').collect();
  279.             if command_list.len()==2 {
  280.                 let name = command_list[0];
  281.                 //debug!("Split line: {} {}",command_list[0],command_list[1]);
  282.                
  283.                 if let Some(id) = self.identifier(&name.to_lowercase()){
  284.                     let value: u32 = self.parse_entry_value(command_list[1].to_string(),id);
  285.                     self.push_val::<u32>(id,value);
  286.                 }
  287.             }
  288.         }
  289.         Ok(()) 
  290.     }
  291.     unsafe fn parse_set(&mut self, filename: &str, default_max_limit: u32, struct_entries: u32)->Result<(),String>{
  292.         let (data, len) = match samase::read_file(filename) {
  293.             Some(s) => s,
  294.             None => { return Err(format!("Unable to read file {}",filename)); },
  295.         };
  296.         let slice = std::slice::from_raw_parts(data, len);
  297.         let mut entry_count = 0;
  298.         let mut current_entry = default_max_limit;
  299.         for line in slice.split(|&x| x == b'\n')
  300.         {
  301.             let line = String::from_utf8_lossy(line);
  302.             let line = line.trim();
  303.             if line.starts_with("#") || line.starts_with(";") || line.is_empty() {
  304.                 continue;
  305.             }
  306.             let command_list: Vec<&str> = line.split(':').collect();
  307.             if command_list.len()==2 {
  308.                 let name = command_list[0];
  309.                 if let Some(id) = self.identifier(&name.to_lowercase()){
  310.                     let value: u32 = self.parse_entry_value(command_list[1].to_string(),id);
  311.                     self.set::<u32>(current_entry as usize,id,value);
  312.                 }
  313.             }
  314.             entry_count+=1;
  315.             if entry_count==struct_entries {
  316.                 entry_count=0;
  317.                 current_entry += 1;
  318.             }
  319.         }
  320.         Ok(()) 
  321.     }
  322.     unsafe fn get_file_entry_count(&mut self, filename: &str, struct_entries: u32)->Option<u32>{
  323.         debug!("Parse stuff [2]");
  324.         let (data, len) = match samase::read_file(filename) {
  325.             Some(s) => s,
  326.             None => { return None; },
  327.         };
  328.         let mut count = 0;
  329.         let slice = std::slice::from_raw_parts(data, len);
  330.         for line in slice.split(|&x| x == b'\n')
  331.         {
  332.             let line = String::from_utf8_lossy(line);
  333.             let line = line.trim();
  334.             if line.starts_with("#") || line.starts_with(";") || line.is_empty() {
  335.                 continue;
  336.             }
  337.             let command_list: Vec<&str> = line.split(':').collect();
  338.             if command_list.len()==2 {
  339.                 let name = command_list[0];
  340.                 if let Some(id) = self.identifier(&name.to_lowercase()){
  341.                     count+=1;
  342.                 }
  343.             }
  344.         }
  345.         count /= struct_entries;
  346.         Some(count)
  347.     }  
  348.  
  349.     fn get_address_list(identifier: Self::Id)->Vec<usize>;
  350.     fn get_size_list()->Vec<usize>;
  351.     unsafe fn extend_data_conventional(&mut self, exe: &mut whack::ModulePatcher);
  352.     fn clear(&mut self);
  353.     unsafe fn init_raw<T: num_traits::cast::ToPrimitive>(&mut self, new_size: T, repatch_array: bool);
  354.     unsafe fn extra_code(&mut self, exe: &mut whack::ModulePatcher);
  355.    
  356.  
  357.     unsafe fn copy_array_from<T: num_traits::cast::FromPrimitive+Clone+Copy>(old_offset: *mut T, new_vec: &mut Vec<T>, length: usize){
  358.         new_vec.resize(length, T::from_u32(0).unwrap());
  359.         for i in 0..length {
  360.             new_vec[i as usize] = *old_offset.offset(i as isize);
  361.         }
  362.     }
  363.     unsafe fn copy_array_from_changesize<T: num_traits::cast::FromPrimitive+Clone+Copy>(old_offset: *mut T, new_vec: &mut Vec<T>,
  364.             old_length: usize, new_length: usize){
  365. //      new_vec.resize(new_length, T::from_u32(0).unwrap());//no longer required because of new default
  366.         for i in 0..old_length {
  367.             new_vec[i as usize] = *old_offset.offset(i as isize);
  368.         }//for stupid arrays like sounds in units.dat
  369.     }
  370.    
  371. }
  372. //attack extender in current version is not used in w/ actual data extender, only functions/type declarations
  373. #[derive(Default, Serialize, Deserialize)]
  374. pub struct AttackExtender {
  375.     pub unit_ids: Vec<u16>,
  376. }
  377. //used to get bytes from pointer for wrappers
  378.  
  379. #[allow(dead_code)]
  380. fn split_bytes(val: u32)->[u8;4]{
  381.     let result: [u8;4] = [
  382.         (val & 0xff) as u8,
  383.         ((val & 0xff00)>>8) as u8,
  384.         ((val & 0xff0000)>>16) as u8,
  385.         ((val & 0xff000000)>>24) as u8];
  386.     result
  387. }
  388.  
  389.  
  390.  
  391. #[derive(Copy,Clone)]
  392. pub enum SpriteValues {
  393.     IncludeInVision,
  394.     StartAsVisible,
  395.     ImageId,
  396.     SelectionCircle,
  397.     ImagePos,
  398.     HpBar,
  399. }
  400.  
  401. //
  402. #[derive(Default, Serialize, Deserialize)]
  403. pub struct SpriteExtender {
  404.     pub include_in_vision: Vec<u8>,//vision sync
  405.     pub start_as_visible: Vec<u8>,
  406.     pub image_id: Vec<u16>,
  407.     pub selection_circle: Vec<u8>,
  408.     pub imagepos: Vec<u8>,
  409.     pub hp_bar: Vec<u8>,
  410.    
  411.     //not used or present in data files, but set in data tables
  412.     pub unknown: Vec<u8>,
  413. }
  414.  
  415. impl SpriteExtender {
  416.    
  417.     unsafe fn extend_data_from_dat_file(&mut self, exe: &mut whack::ModulePatcher){
  418.         let (data, len) = match samase::read_file("arr\\sprites.dat"){
  419.             Some(s) => s,
  420.             None => { return; },
  421.         };
  422.         debug!("Length is {}",len);
  423.         //selcircle, imagepos and hpbar are not set for 0-129 entries
  424.         //equation formula for calculation of number of entries is following:
  425.         // x*4 + (x-130)*3 = n, where n is length of file in bytes
  426.         let count = (len + 390) / 7;
  427.         self.include_in_vision.resize(count,0);
  428.         self.start_as_visible.resize(count,0);
  429.         self.image_id.resize(count,0);
  430.         self.selection_circle.resize(count-130,0);
  431.         self.imagepos.resize(count-130,0);
  432.         self.hp_bar.resize(count-130,0);       
  433.         self.unknown.resize(count,0);
  434.         exe.replace_val(0x00513FC0, count);
  435.         exe.replace_val(0x00513FCC, count-130);
  436.         exe.replace_val(0x00513FD8, count);
  437.         exe.replace_val(0x00513FE4, count);
  438.         exe.replace_val(0x00513FF0, count-130);
  439.         exe.replace_val(0x00513FFC, count-130);
  440.       exe.replace_val(0x00463A8B, &mut self.image_id[0] as *mut u16);
  441.       exe.replace_val(0x004683D9, &mut self.image_id[0] as *mut u16);
  442.       exe.replace_val(0x0048D769, &mut self.image_id[0] as *mut u16);
  443.       exe.replace_val(0x0048DAA3, &mut self.image_id[0] as *mut u16);
  444.       exe.replace_val(0x00499081, &mut self.image_id[0] as *mut u16);
  445.       exe.replace_val(0x004D7A5C, &mut self.image_id[0] as *mut u16);
  446.       exe.replace_val(0x004D7ABF, &mut self.image_id[0] as *mut u16);
  447.       exe.replace_val(0x004E4CC9, &mut self.image_id[0] as *mut u16);
  448.       exe.replace_val(0x004E4FDF, &mut self.image_id[0] as *mut u16);
  449.       exe.replace_val(0x004E501C, &mut self.image_id[0] as *mut u16);
  450.       exe.replace_val(0x004E6644, &mut self.image_id[0] as *mut u16);
  451.       exe.replace_val(0x00513FB8, &mut self.image_id[0] as *mut u16);
  452.   exe.replace_val(0x0047A873, ((&mut self.hp_bar[0] as *mut u8 as *mut u32 as u32)-130) as *mut u8);
  453.   exe.replace_val(0x0047A90F, ((&mut self.hp_bar[0] as *mut u8 as *mut u32 as u32)-130) as *mut u8);
  454.   exe.replace_val(0x0047AA6E, ((&mut self.hp_bar[0] as *mut u8 as *mut u32 as u32)-130) as *mut u8);
  455.   exe.replace_val(0x004D6045, ((&mut self.hp_bar[0] as *mut u8 as *mut u32 as u32)-130) as *mut u8);
  456.   exe.replace_val(0x00513FC4, &mut self.hp_bar[0] as *mut u8);
  457.   exe.replace_val(0x00513FD0, &mut self.unknown[0] as *mut u8);
  458.   exe.replace_val(0x0049906D, &mut self.start_as_visible[0] as *mut u8);
  459.   exe.replace_val(0x00513FDC, &mut self.start_as_visible[0] as *mut u8);
  460.   exe.replace_val(0x004D6021, ((&mut self.selection_circle[0] as *mut u8 as *mut u32 as u32)-130) as *mut u8);
  461.   exe.replace_val(0x004D681E, ((&mut self.selection_circle[0] as *mut u8 as *mut u32 as u32)-130) as *mut u8);
  462.   exe.replace_val(0x00513FE8, &mut self.selection_circle[0] as *mut u8);
  463.   exe.replace_val(0x004D6034, ((&mut self.imagepos[0] as *mut u8 as *mut u32 as u32)-130) as *mut u8);
  464.   exe.replace_val(0x004D6842, ((&mut self.imagepos[0] as *mut u8 as *mut u32 as u32)-130) as *mut u8);
  465.   exe.replace_val(0x00513FF4, &mut self.imagepos[0] as *mut u8);
  466.   exe.replace_val(0x0042D517, &mut self.include_in_vision[0] as *mut u8);
  467.   exe.replace_val(0x00497159, &mut self.include_in_vision[0] as *mut u8);
  468.   exe.replace_val(0x00497180, &mut self.include_in_vision[0] as *mut u8);
  469.   exe.replace_val(0x004971A7, &mut self.include_in_vision[0] as *mut u8);
  470.   exe.replace_val(0x004971CE, &mut self.include_in_vision[0] as *mut u8);
  471.   exe.replace_val(0x004971F5, &mut self.include_in_vision[0] as *mut u8);
  472.   exe.replace_val(0x0049721C, &mut self.include_in_vision[0] as *mut u8);
  473.   exe.replace_val(0x00497C66, &mut self.include_in_vision[0] as *mut u8);
  474.     }
  475. }
  476.  
  477. impl DataExtender for SpriteExtender {
  478.     type Id = SpriteValues;
  479.     type SizeLimit = u32;
  480.     unsafe fn extra_code(&mut self, exe: &mut whack::ModulePatcher){}
  481.     fn clear(&mut self){
  482.         self.include_in_vision.clear();
  483.         self.start_as_visible.clear();
  484.         self.image_id.clear();
  485.         self.selection_circle.clear();
  486.         self.imagepos.clear();
  487.         self.hp_bar.clear();
  488.     }
  489.  
  490.     unsafe fn init_code(&mut self, exe: &mut whack::ModulePatcher){}
  491.     unsafe fn init_raw<T: num_traits::cast::ToPrimitive>(&mut self, new_size: T, repatch_array: bool){}
  492.     fn get(&mut self, index: usize, identifier: Self::Id)->u32{
  493.         let result = match identifier {
  494.             SpriteValues::IncludeInVision => self.include_in_vision[index] as u32,
  495.             SpriteValues::StartAsVisible => self.start_as_visible[index] as u32,
  496.             SpriteValues::ImageId => self.image_id[index] as u32,
  497.             SpriteValues::SelectionCircle => self.selection_circle[index] as u32,
  498.             SpriteValues::ImagePos => self.imagepos[index] as u32,
  499.             SpriteValues::HpBar => self.hp_bar[index] as u32,
  500.         };
  501.         result 
  502.     }  
  503.     fn identifier(&mut self, line: &str)->Option<Self::Id>{
  504.         let result = match line.trim().as_ref(){
  505.             "include_in_vision"=>SpriteValues::IncludeInVision,
  506.             "start_as_visible"=>SpriteValues::StartAsVisible,
  507.             "image_id"=>SpriteValues::ImageId,
  508.             "selection_circle"=>SpriteValues::SelectionCircle,
  509.             "image_pos"=>SpriteValues::ImagePos,
  510.             "hp_bar"=>SpriteValues::HpBar,
  511.             _=>{
  512.                 return None;
  513.             },
  514.         };
  515.         Some(result)
  516.     }
  517.     fn push_val<T: num_traits::cast::ToPrimitive>(&mut self, identifier: Self::Id, value: T){
  518.         match identifier {
  519.             SpriteValues::IncludeInVision=>self.include_in_vision.push(T::to_u8(&value).unwrap()),
  520.             SpriteValues::StartAsVisible=>self.start_as_visible.push(T::to_u8(&value).unwrap()),
  521.             SpriteValues::ImageId=>self.image_id.push(T::to_u16(&value).unwrap()),
  522.             SpriteValues::SelectionCircle=>self.selection_circle.push(T::to_u8(&value).unwrap()),
  523.             SpriteValues::ImagePos=>self.imagepos.push(T::to_u8(&value).unwrap()),
  524.             SpriteValues::HpBar=>self.hp_bar.push(T::to_u8(&value).unwrap()),
  525.         }
  526.     }
  527.     fn set<T: num_traits::cast::ToPrimitive>(&mut self, index: usize, identifier: Self::Id, value: T){
  528.         match identifier {
  529.             SpriteValues::IncludeInVision=>self.include_in_vision[index] = T::to_u8(&value).unwrap(),
  530.             SpriteValues::StartAsVisible=>self.start_as_visible[index] = T::to_u8(&value).unwrap(),
  531.             SpriteValues::ImageId=>self.image_id[index] = T::to_u16(&value).unwrap(),
  532.             SpriteValues::SelectionCircle=>self.selection_circle[index] = T::to_u8(&value).unwrap(),
  533.             SpriteValues::ImagePos=>self.imagepos[index] = T::to_u8(&value).unwrap(),
  534.             SpriteValues::HpBar=>self.hp_bar[index] = T::to_u8(&value).unwrap(),   
  535.         }
  536.     }
  537.     unsafe fn parse_entry_value(&mut self, text: String, identifier: Self::Id)->u32{//placeholder for the future
  538.         text.trim().parse().unwrap()
  539.     }
  540.     fn get_address_list(identifier: Self::Id)->Vec<usize>{
  541.         let list = match identifier {
  542.  
  543.            
  544.             SpriteValues::IncludeInVision=>vec![0x0042D515+2,0x00497157+2,0x0049717E+2,
  545.                                                 0x004971A5+2,0x004971CC+2,
  546.                                                 0x004971F3+2,0x0049721A+2,0x00497C64+2],//+
  547.             SpriteValues::StartAsVisible=>vec![0x0049906B+2],//+   
  548.            
  549.             SpriteValues::ImageId=>vec![0x00463A87+4,0x004683D5+4,0x0048D765+4,0x0048DA9F+4,
  550.             0x0049907D+4,0x004D7A58+4,
  551.                                     0x004D7ABB+4,0x004E4CC5+4,0x004E4FDB+4,0x004E5018+4,
  552.                                     0x004E6640+4],
  553.             SpriteValues::SelectionCircle=>vec![0x004D601E+3,0x004D681A+4],
  554.             SpriteValues::ImagePos=>vec![0x004D6032+2,0x004D6840+2],
  555.             SpriteValues::HpBar=>vec![0x0047A871+2,0x0047A90D+2,0x0047AA6B+3,0x004D6043+2],
  556.             _=>vec![],
  557.  
  558.         };
  559.         list           
  560.     }
  561.     unsafe fn extend_data_conventional(&mut self, exe: &mut whack::ModulePatcher){
  562.         self.clear();
  563.         //sync
  564.         debug!("Init sprite stuff");
  565.         let sprite_list_start = 130;
  566.         Self::copy_array_from::<u8>(&mut bw::sprites_dat_vision[0] as *mut u8, &mut self.include_in_vision, 0x205);
  567.         Self::copy_array_from::<u8>(&mut bw::sprites_dat_as_visible[0] as *mut u8, &mut self.start_as_visible, 0x205);
  568.         Self::copy_array_from::<u16>(&mut bw::sprites_dat_image_id[0] as *mut u16, &mut self.image_id, 0x205);
  569.         Self::copy_array_from::<u8>(&mut bw::sprites_dat_selection_circle_off[0] as *mut u8,
  570.                                     &mut self.selection_circle, 0x205 - sprite_list_start);
  571.         Self::copy_array_from::<u8>(&mut bw::sprites_dat_selection_imagepos_off[0] as *mut u8,
  572.                                     &mut self.imagepos, 0x205 - sprite_list_start);
  573.         Self::copy_array_from::<u8>(&mut bw::sprites_dat_healthbar_off[0] as *mut u8,
  574.                                     &mut self.hp_bar, 0x205 - sprite_list_start);
  575.         debug!("Copy arrays");
  576.         let _ = match self.parse("samase\\sprites_ext.txt"){
  577.             Ok(())=>{
  578.                 //everything's okay
  579.             },
  580.             Err(e)=>{
  581.                 windows::message_box("Aise panic", &e);
  582.                 TerminateProcess(GetCurrentProcess(), 0x4230daef);
  583.             },
  584.         };
  585.         debug!("S: {} {} {} {} {} {}",self.include_in_vision.len(),self.start_as_visible.len(),self.image_id.len(),
  586.             self.selection_circle.len(), self.imagepos.len(), self.hp_bar.len());
  587.         let length = self.image_id.len();
  588.         Self::uplink::<u8>(exe, &mut self.include_in_vision[0] as *mut u8, Self::get_address_list(SpriteValues::IncludeInVision));
  589.         Self::uplink::<u8>(exe, &mut self.start_as_visible[0] as *mut u8, Self::get_address_list(SpriteValues::StartAsVisible));
  590.         Self::uplink::<u16>(exe, &mut self.image_id[0] as *mut u16, Self::get_address_list(SpriteValues::ImageId));
  591.        
  592.         Self::uplink::<u8>(exe,
  593.         ((&mut self.selection_circle[0] as *mut u8 as *mut u32 as u32)-130) as *mut u8,
  594.                 Self::get_address_list(SpriteValues::SelectionCircle));
  595.         Self::uplink::<u8>(exe,
  596.         ((&mut self.imagepos[0] as *mut u8 as *mut u32 as u32)-130) as *mut u8,
  597.                 Self::get_address_list(SpriteValues::ImagePos));//selection circle offset
  598.         Self::uplink::<u8>(exe,
  599.         ((&mut self.hp_bar[0] as *mut u8 as *mut u32 as u32)-130) as *mut u8,
  600.                 Self::get_address_list(SpriteValues::HpBar));
  601.         Self::uplink_length_dattable(exe, length.clone() as u32, Self::get_size_list());
  602.         self.extra_code(exe);
  603.         debug!("End sprite stuff");
  604.     }  
  605.     fn get_size_list()->Vec<usize>{
  606.         return vec![
  607.        
  608.        
  609.         ];
  610.     }
  611. }
  612.  
  613. //
  614. //
  615. //
  616. //
  617. #[derive(Default, Serialize, Deserialize)]
  618. pub struct SFXExtender {
  619.     pub length: u32,
  620.    
  621.     pub volume: Vec<u8>,
  622.     pub flags: Vec<u8>,
  623.     pub race: Vec<u16>,
  624.     pub stype: Vec<u8>,
  625.     pub soundfile: Vec<u32>,
  626.     //ptr-related
  627.     //suffering starts
  628.     pub ptr: Vec<u32>,//x16
  629. //  pub sound_data: Vec<SoundData>,//x16
  630. }      
  631. /*006D1270 = SoundData sound_data[?]x16
  632. SoundData: (0x10)
  633. 0x0     dword wav_data_size
  634. 0x4     dword 0 - tick? (x4 + GetTickCount ~~ frame?) (0 - (GetTickCount() - 0x51))
  635. 0x8     dword duration_msecs (006D1278)
  636. 0xc     IDirectSoundBuffer *buffer
  637. */
  638.  
  639.  
  640. #[derive(Copy,Clone)]
  641. pub enum SFXValues {
  642.     Volume,
  643.     Flags,
  644.     Race,
  645.     Type,
  646.     Soundfile,
  647.    
  648.     SoundDataPtr,
  649. }
  650. /*
  651.     pub volume: Vec<u8>,
  652.     pub flags: Vec<u8>,
  653.     pub race: Vec<u16>,
  654.     pub stype: Vec<u8>,
  655.     pub soundfile: Vec<u32>,
  656.     //ptr-related
  657.     //suffering starts
  658.     pub ptr: Vec<u32>,//x16
  659. //  pub sound_data: Vec<SoundData>,
  660.  
  661.  
  662. */
  663.  
  664. impl DataExtender for SFXExtender {
  665.     type Id = SFXValues;
  666.     type SizeLimit = u32;
  667.     unsafe fn extra_code(&mut self, exe: &mut whack::ModulePatcher){
  668.         //
  669.    
  670.         //
  671.    
  672.         //
  673.     }
  674.     fn clear(&mut self){
  675.         self.volume.clear();
  676.         self.flags.clear();
  677.         self.race.clear();
  678.         self.stype.clear();
  679.         self.soundfile.clear();
  680.     }
  681.     unsafe fn init_code(&mut self, exe: &mut whack::ModulePatcher){
  682.         if let Some(count) = self.get_file_entry_count("samase\\sfx_ext.txt",5){//14 is number of data default entries
  683.             self.length = 1144+count;
  684.             let sum = self.length as usize;
  685.             self.volume.resize(sum,0);
  686.             self.flags.resize(sum,0);
  687.             self.race.resize(sum,0);
  688.             self.stype.resize(sum,0);
  689.             self.soundfile.resize(sum,0);
  690.             self.ptr.resize(sum*4,0);
  691.             self.extra_code(exe);
  692.             Self::uplink_length_dattable(exe, sum as u32, Self::get_size_list());
  693.             Self::uplink::<u8>(exe, &mut self.volume[0] as *mut u8, Self::get_address_list(SFXValues::Volume));
  694.             Self::uplink::<u8>(exe, &mut self.flags[0] as *mut u8, Self::get_address_list(SFXValues::Flags));
  695.             Self::uplink::<u16>(exe, &mut self.race[0] as *mut u16, Self::get_address_list(SFXValues::Race));
  696.             Self::uplink::<u8>(exe, &mut self.stype[0] as *mut u8, Self::get_address_list(SFXValues::Type));
  697.             Self::uplink::<u32>(exe, &mut self.soundfile[0] as *mut u32, Self::get_address_list(SFXValues::Soundfile));
  698.             //
  699.         }
  700.     }
  701.     unsafe fn extend_data_conventional(&mut self, exe: &mut whack::ModulePatcher){}
  702.     unsafe fn init_raw<T: num_traits::cast::ToPrimitive>(&mut self, new_size: T, repatch_array: bool){}
  703.     fn get(&mut self, index: usize, identifier: Self::Id)->u32{
  704.         let result = match identifier {
  705.             SFXValues::Volume => self.volume[index] as u32,
  706.             SFXValues::Flags => self.flags[index] as u32,
  707.             SFXValues::Race => self.race[index] as u32,
  708.             SFXValues::Type => self.stype[index] as u32,
  709.             SFXValues::Soundfile => self.soundfile[index] as u32,
  710.             SFXValues::SoundDataPtr => self.ptr[index] as u32,
  711.         };
  712.         result 
  713.     }  
  714.     fn identifier(&mut self, line: &str)->Option<Self::Id>{
  715.         let result = match line.trim().as_ref(){
  716.             "volume"=>SFXValues::Volume,
  717.             "flags"=>SFXValues::Flags,
  718.             "race"=>SFXValues::Race,
  719.             "type"=>SFXValues::Type,
  720.             "soundfile"=>SFXValues::Soundfile,
  721.             _=>{
  722.                 return None;
  723.             },
  724.         };
  725.         Some(result)
  726.     }
  727.     fn push_val<T: num_traits::cast::ToPrimitive>(&mut self, identifier: Self::Id, value: T){
  728.         match identifier {
  729.             SFXValues::Volume=>self.volume.push(T::to_u8(&value).unwrap()),
  730.             SFXValues::Flags=>self.flags.push(T::to_u8(&value).unwrap()),
  731.             SFXValues::Race=>self.race.push(T::to_u16(&value).unwrap()),
  732.             SFXValues::Type=>self.stype.push(T::to_u8(&value).unwrap()),
  733.             SFXValues::Soundfile=>self.soundfile.push(T::to_u32(&value).unwrap()),
  734.             _=>{},
  735.         }
  736.     }
  737.     fn set<T: num_traits::cast::ToPrimitive>(&mut self, index: usize, identifier: Self::Id, value: T){
  738.         let length=self.length as usize;
  739.         match identifier {
  740.             SFXValues::Volume=>self.volume[index] = T::to_u8(&value).unwrap(),
  741.             SFXValues::Flags=>self.flags[index] = T::to_u8(&value).unwrap(),
  742.             SFXValues::Race=>self.race[index] = T::to_u16(&value).unwrap(),
  743.             SFXValues::Type=>self.stype[index] = T::to_u8(&value).unwrap(),
  744.             SFXValues::Soundfile=>self.soundfile[index] = T::to_u32(&value).unwrap(),
  745.             _=>{},
  746.         }
  747.     }
  748.     unsafe fn parse_entry_value(&mut self, text: String, identifier: Self::Id)->u32{//placeholder for the future
  749.         text.trim().parse().unwrap()
  750.     }
  751.     fn get_address_list(identifier: Self::Id)->Vec<usize>{
  752.         let list = match identifier {
  753.             SFXValues::Volume=>vec![],
  754.             SFXValues::Flags=>vec![],
  755.             SFXValues::Race=>vec![],
  756.             SFXValues::Type=>vec![],
  757.             SFXValues::Soundfile=>vec![],          
  758.             _=>vec![],
  759.  
  760.         };
  761.         list   
  762.     }
  763.     fn get_size_list()->Vec<usize>{
  764.         return vec![];
  765.     }
  766. }
  767. //
  768. //
  769. //
  770.  
  771. #[derive(Copy,Clone)]
  772. pub enum ImageValues {
  773.     GrpId,
  774.     IscriptId,
  775.     GraphicTurns,
  776.     DrawIfCloaked,
  777.     Clickable,
  778.     UseFullIscript,
  779.     DrawFunc,
  780.     DrawRemap,
  781.     OverlayAttack,
  782.     OverlayDamage,
  783.     OverlaySpecial,
  784.     OverlayLanding,
  785.     OverlayLiftoff,
  786.     OverlayShield,
  787.    
  788.     BuildingOverlayStateMax,
  789.     OverlayShieldPtr,
  790.     OverlayAttackPtr,
  791.     OverlayDamagePtr,
  792.     OverlaySpecialPtr,
  793.     OverlayLandingPtr,
  794.     OverlayLiftoffPtr,
  795.     ImageGrpPtr,
  796. }
  797.  
  798. #[derive(Default)]
  799. pub struct ImageExtender {
  800.     pub length: u32,
  801.    
  802.     pub grp_id: Vec<u32>,
  803.     pub iscript_id: Vec<u32>,
  804.     pub graphic_turns: Vec<u8>,
  805.     pub draw_if_cloaked: Vec<u8>,
  806.     pub clickable: Vec<u8>,
  807.     pub use_full_iscript: Vec<u8>,
  808.     pub draw_func: Vec<u8>,
  809.     pub draw_remap: Vec<u8>,
  810.    
  811.     pub overlay_shield: Vec<u32>,
  812.    
  813.     pub overlay_attack: Vec<u32>,
  814.     pub overlay_damage: Vec<u32>,
  815.     pub overlay_special: Vec<u32>,
  816.     pub overlay_landing: Vec<u32>,
  817.     pub overlay_liftoff: Vec<u32>,
  818.     //extra
  819.     pub building_overlay_state_max: Vec<u8>,
  820.     //ptrs
  821. /*  pub overlay_attack_ptr: Vec<u32>,
  822.     pub overlay_damage_ptr: Vec<u32>,
  823.     pub overlay_special_ptr: Vec<u32>,
  824.     pub overlay_landing_ptr: Vec<u32>,
  825.     pub overlay_liftoff_ptr: Vec<u32>,*/
  826.     pub overlays: Vec<u32>,//why we have to suffer
  827. //  pub overlay_shield_ptr: Vec<u32>,
  828.     pub image_grp_ptr: Vec<u32>,
  829. }
  830.  
  831. impl ImageExtender {
  832.     pub fn new()->ImageExtender {
  833.         ImageExtender {
  834.             length: 0,
  835.             grp_id: Vec::new(),
  836.             graphic_turns: Vec::new(),
  837.             draw_if_cloaked: Vec::new(),
  838.             clickable: Vec::new(),
  839.             use_full_iscript: Vec::new(),
  840.             draw_func: Vec::new(),
  841.             draw_remap: Vec::new(),
  842.             iscript_id: Vec::new(),
  843.             overlay_attack: Vec::new(),
  844.             overlay_damage: Vec::new(),
  845.             overlay_special: Vec::new(),
  846.             overlay_landing: Vec::new(),
  847.             overlay_liftoff: Vec::new(),
  848.             overlay_shield: Vec::new(),
  849.             building_overlay_state_max: Vec::new(),
  850.             overlays: Vec::new(),
  851.             /*overlay_shield_ptr: Vec::new(),
  852.             overlay_attack_ptr: Vec::new(),
  853.             overlay_damage_ptr: Vec::new(),
  854.             overlay_special_ptr: Vec::new(),
  855.             overlay_landing_ptr: Vec::new(),
  856.             overlay_liftoff_ptr: Vec::new(),*/
  857.             image_grp_ptr: Vec::new(),
  858.         }
  859.     }
  860. }
  861.  
  862.  
  863.  
  864.    
  865.  
  866. impl DataExtender for ImageExtender {
  867.     type Id = ImageValues;
  868.     type SizeLimit = u32;
  869.     fn clear(&mut self){
  870.         self.grp_id.clear();
  871.         self.iscript_id.clear();
  872.         self.graphic_turns.clear();
  873.         self.draw_if_cloaked.clear();
  874.         self.clickable.clear();
  875.         self.use_full_iscript.clear();
  876.         self.draw_func.clear();
  877.         self.draw_remap.clear();
  878.         self.overlay_attack.clear();
  879.         self.overlay_damage.clear();
  880.         self.overlay_special.clear();
  881.         self.overlay_landing.clear();
  882.         self.overlay_liftoff.clear();
  883.         self.overlay_shield.clear();
  884. //     
  885.         self.overlays.clear();
  886. /*      self.overlay_attack_ptr.clear();
  887.         self.overlay_damage_ptr.clear();
  888.         self.overlay_special_ptr.clear();
  889.         self.overlay_landing_ptr.clear();
  890.         self.overlay_liftoff_ptr.clear();
  891.         self.overlay_shield_ptr.clear();*/
  892.         self.image_grp_ptr.clear();
  893.         self.building_overlay_state_max.clear();
  894.     }
  895.     unsafe fn init_raw<T: num_traits::cast::ToPrimitive>(&mut self, new_size: T, repatch_array: bool){}
  896.     unsafe fn init_code(&mut self, exe: &mut whack::ModulePatcher){
  897.         if let Some(count) = self.get_file_entry_count("samase\\images_ext.txt",14){//14 is number of data default entries
  898.             self.length = 999+count;
  899.             let sum = self.length as usize;
  900.             debug!("Sum is: {}",sum);
  901.             self.grp_id.resize(sum,0);
  902.             self.iscript_id.resize(sum,0);
  903.             self.graphic_turns.resize(sum,0);
  904.             self.draw_if_cloaked.resize(sum,0);
  905.             self.clickable.resize(sum,0);
  906.             self.use_full_iscript.resize(sum,0);
  907.             self.draw_func.resize(sum,0);
  908.             self.draw_remap.resize(sum,0);
  909.             self.overlay_attack.resize(sum,0);
  910.             self.overlay_damage.resize(sum,0);
  911.             self.overlay_special.resize(sum,0);
  912.             self.overlay_landing.resize(sum,0);
  913.             self.overlay_liftoff.resize(sum,0);
  914.             self.overlay_shield.resize(sum,0);
  915.            
  916.            
  917.             self.overlays.resize(sum*6,0);
  918.            
  919.             /*
  920.             self.overlay_attack_ptr.resize(sum,0);
  921.             self.overlay_damage_ptr.resize(sum,0);
  922.             self.overlay_special_ptr.resize(sum,0);
  923.             self.overlay_landing_ptr.resize(sum,0);
  924.             self.overlay_liftoff_ptr.resize(sum,0);
  925.            
  926.             self.overlay_shield_ptr.resize(sum,0);
  927.             */
  928.            
  929.             self.image_grp_ptr.resize(sum,0);
  930.             self.building_overlay_state_max.resize(sum,0);
  931.            
  932.            
  933.             /*
  934.             //extra uplinks/memory patches
  935.             debug!("Resize done");*/
  936.             self.extra_code(exe);
  937.            
  938.             debug!("Extra code done, uplink image length table, length is {}",self.length);
  939.             Self::uplink_length_dattable(exe, sum as u32, Self::get_size_list());
  940.  
  941.             debug!("Dattable done");
  942.            
  943.            
  944.             Self::uplink::<u32>(exe, &mut self.grp_id[0] as *mut u32, Self::get_address_list(ImageValues::GrpId));     
  945.             Self::uplink::<u8>(exe, &mut self.graphic_turns[0] as *mut u8, Self::get_address_list(ImageValues::GraphicTurns));         
  946.             Self::uplink::<u8>(exe, &mut self.draw_if_cloaked[0] as *mut u8, Self::get_address_list(ImageValues::DrawIfCloaked));
  947.             Self::uplink::<u8>(exe, &mut self.clickable[0] as *mut u8, Self::get_address_list(ImageValues::Clickable));
  948.             Self::uplink::<u8>(exe, &mut self.use_full_iscript[0] as *mut u8, Self::get_address_list(ImageValues::UseFullIscript));
  949.             Self::uplink::<u8>(exe, &mut self.draw_func[0] as *mut u8, Self::get_address_list(ImageValues::DrawFunc));
  950.             Self::uplink::<u8>(exe, &mut self.draw_remap[0] as *mut u8, Self::get_address_list(ImageValues::DrawRemap));   
  951.             Self::uplink::<u32>(exe, &mut self.iscript_id[0] as *mut u32, Self::get_address_list(ImageValues::IscriptId));
  952.             Self::uplink::<u32>(exe, &mut self.overlay_attack[0] as *mut u32, Self::get_address_list(ImageValues::OverlayAttack));
  953.             Self::uplink::<u32>(exe, &mut self.overlay_damage[0] as *mut u32, Self::get_address_list(ImageValues::OverlayDamage));
  954.             Self::uplink::<u32>(exe, &mut self.overlay_special[0] as *mut u32, Self::get_address_list(ImageValues::OverlaySpecial));
  955.             Self::uplink::<u32>(exe, &mut self.overlay_landing[0] as *mut u32, Self::get_address_list(ImageValues::OverlayLanding));
  956.             Self::uplink::<u32>(exe, &mut self.overlay_liftoff[0] as *mut u32, Self::get_address_list(ImageValues::OverlayLiftoff));
  957.             Self::uplink::<u32>(exe, &mut self.overlay_shield[0] as *mut u32, Self::get_address_list(ImageValues::OverlayShield));
  958.             /*
  959.             Self::uplink::<u32>(exe, &mut self.overlay_attack_ptr[0] as *mut u32, Self::get_address_list(ImageValues::OverlayAttackPtr));
  960.             Self::uplink::<u32>(exe, &mut self.overlay_damage_ptr[0] as *mut u32, Self::get_address_list(ImageValues::OverlayDamagePtr));
  961.             Self::uplink::<u32>(exe, &mut self.overlay_special_ptr[0] as *mut u32, Self::get_address_list(ImageValues::OverlaySpecialPtr));
  962.             Self::uplink::<u32>(exe, &mut self.overlay_landing_ptr[0] as *mut u32, Self::get_address_list(ImageValues::OverlayLandingPtr));
  963.             Self::uplink::<u32>(exe, &mut self.overlay_liftoff_ptr[0] as *mut u32, Self::get_address_list(ImageValues::OverlayLiftoffPtr));
  964.             Self::uplink::<u32>(exe, &mut self.overlay_shield_ptr[0] as *mut u32, Self::get_address_list(ImageValues::OverlayShieldPtr));
  965.  
  966.             */
  967.             Self::uplink::<u32>(exe, &mut self.overlays[0] as *mut u32, Self::get_address_list(ImageValues::OverlayAttackPtr));
  968.             Self::uplink::<u32>(exe, &mut self.overlays[sum] as *mut u32, Self::get_address_list(ImageValues::OverlayDamagePtr));
  969.             Self::uplink::<u32>(exe, &mut self.overlays[sum*2] as *mut u32, Self::get_address_list(ImageValues::OverlaySpecialPtr));
  970.             Self::uplink::<u32>(exe, &mut self.overlays[sum*3] as *mut u32, Self::get_address_list(ImageValues::OverlayLandingPtr));
  971.             Self::uplink::<u32>(exe, &mut self.overlays[sum*4] as *mut u32, Self::get_address_list(ImageValues::OverlayLiftoffPtr));
  972.             Self::uplink::<u32>(exe, &mut self.overlays[sum*5] as *mut u32, Self::get_address_list(ImageValues::OverlayShieldPtr));
  973.             //
  974.             Self::uplink::<u32>(exe, &mut self.image_grp_ptr[0] as *mut u32, Self::get_address_list(ImageValues::ImageGrpPtr));        
  975.             Self::uplink::<u8>(exe, &mut self.building_overlay_state_max[0] as *mut u8, Self::get_address_list(ImageValues::BuildingOverlayStateMax));         
  976.        
  977.             debug!("All uplinks done");
  978.            
  979.         }
  980.     }
  981.     fn get(&mut self, index: usize, identifier: Self::Id)->u32{
  982.         let length = self.length as usize;
  983.         let result = match identifier {
  984.             ImageValues::GrpId => self.grp_id[index] as u32,
  985.             ImageValues::IscriptId => self.iscript_id[index] as u32,
  986.             ImageValues::GraphicTurns => self.graphic_turns[index] as u32,
  987.             ImageValues::DrawIfCloaked => self.draw_if_cloaked[index] as u32,
  988.             ImageValues::Clickable => self.clickable[index] as u32,
  989.             ImageValues::UseFullIscript => self.use_full_iscript[index] as u32,
  990.             ImageValues::DrawFunc => self.draw_func[index] as u32,
  991.             ImageValues::DrawRemap => self.draw_remap[index] as u32,
  992.             ImageValues::OverlayAttack => self.overlay_attack[index] as u32,
  993.             ImageValues::OverlayDamage => self.overlay_damage[index] as u32,
  994.             ImageValues::OverlaySpecial => self.overlay_special[index] as u32,
  995.             ImageValues::OverlayLanding => self.overlay_landing[index] as u32,
  996.             ImageValues::OverlayLiftoff => self.overlay_liftoff[index] as u32,
  997.             ImageValues::OverlayShield => self.overlay_shield[index] as u32,
  998. /*          ImageValues::OverlayAttackPtr => self.overlay_attack_ptr[index] as u32,
  999.             ImageValues::OverlayDamagePtr => self.overlay_damage_ptr[index] as u32,
  1000.             ImageValues::OverlaySpecialPtr => self.overlay_special_ptr[index] as u32,
  1001.             ImageValues::OverlayLandingPtr => self.overlay_landing_ptr[index] as u32,
  1002.             ImageValues::OverlayLiftoffPtr => self.overlay_liftoff_ptr[index] as u32,*/
  1003.             ImageValues::OverlayAttackPtr => self.overlays[index] as u32,
  1004.             ImageValues::OverlayDamagePtr => self.overlays[index+length] as u32,
  1005.             ImageValues::OverlaySpecialPtr => self.overlays[index+length*2] as u32,
  1006.             ImageValues::OverlayLandingPtr => self.overlays[index+length*3] as u32,
  1007.             ImageValues::OverlayLiftoffPtr => self.overlays[index+length*4] as u32,
  1008.             ImageValues::OverlayShieldPtr => self.overlays[index+length*5] as u32,
  1009. //          ImageValues::OverlayShieldPtr => self.overlay_shield_ptr[index] as u32,
  1010.             ImageValues::ImageGrpPtr => self.image_grp_ptr[index] as u32,  
  1011.             ImageValues::BuildingOverlayStateMax => self.building_overlay_state_max[index] as u32, 
  1012.            
  1013.         };
  1014.         result 
  1015.     }  
  1016.     fn identifier(&mut self, line: &str)->Option<Self::Id>{
  1017.         let result = match line.trim().as_ref(){
  1018.             "grp_id"=>ImageValues::GrpId,
  1019.             "iscript_id"=>ImageValues::IscriptId,
  1020.             "graphic_turns"=>ImageValues::GraphicTurns,
  1021.             "draw_if_cloaked"=>ImageValues::DrawIfCloaked,
  1022.             "clickable"=>ImageValues::Clickable,
  1023.             "use_full_iscript"=>ImageValues::UseFullIscript,
  1024.             "draw_func"=>ImageValues::DrawFunc,
  1025.             "draw_remap"=>ImageValues::DrawRemap,
  1026.             "overlay_attack"=>ImageValues::OverlayAttack,
  1027.             "overlay_damage"=>ImageValues::OverlayDamage,
  1028.             "overlay_special"=>ImageValues::OverlaySpecial,
  1029.             "overlay_landing"=>ImageValues::OverlayLanding,
  1030.             "overlay_liftoff"=>ImageValues::OverlayLiftoff,
  1031.             "overlay_shield"=>ImageValues::OverlayShield,
  1032.             _=>{
  1033.                 return None;
  1034.             },
  1035.         };
  1036.         Some(result)
  1037.     }
  1038.     fn push_val<T: num_traits::cast::ToPrimitive>(&mut self, identifier: Self::Id, value: T){
  1039.         match identifier {
  1040.             ImageValues::GrpId=>self.grp_id.push(T::to_u32(&value).unwrap()),
  1041.             ImageValues::GraphicTurns=>self.graphic_turns.push(T::to_u8(&value).unwrap()),
  1042.             ImageValues::DrawIfCloaked=>self.draw_if_cloaked.push(T::to_u8(&value).unwrap()),
  1043.             ImageValues::Clickable=>self.clickable.push(T::to_u8(&value).unwrap()),
  1044.             ImageValues::UseFullIscript=>self.use_full_iscript.push(T::to_u8(&value).unwrap()),
  1045.             ImageValues::DrawFunc=>self.draw_func.push(T::to_u8(&value).unwrap()),
  1046.             ImageValues::DrawRemap=>self.draw_remap.push(T::to_u8(&value).unwrap()),
  1047.             ImageValues::IscriptId=>self.iscript_id.push(T::to_u32(&value).unwrap()),
  1048.             ImageValues::OverlayAttack=>self.overlay_attack.push(T::to_u32(&value).unwrap()),
  1049.             ImageValues::OverlayDamage=>self.overlay_damage.push(T::to_u32(&value).unwrap()),
  1050.             ImageValues::OverlaySpecial=>self.overlay_special.push(T::to_u32(&value).unwrap()),
  1051.             ImageValues::OverlayLanding=>self.overlay_landing.push(T::to_u32(&value).unwrap()),
  1052.             ImageValues::OverlayLiftoff=>self.overlay_liftoff.push(T::to_u32(&value).unwrap()),
  1053.             ImageValues::OverlayShield=>self.overlay_shield.push(T::to_u32(&value).unwrap()),
  1054.  
  1055. /*          ImageValues::OverlayAttackPtr=>self.overlay_attack_ptr.push(T::to_u32(&value).unwrap()),   
  1056.             ImageValues::OverlayDamagePtr=>self.overlay_damage_ptr.push(T::to_u32(&value).unwrap()),   
  1057.             ImageValues::OverlaySpecialPtr=>self.overlay_special_ptr.push(T::to_u32(&value).unwrap()), 
  1058.             ImageValues::OverlayLandingPtr=>self.overlay_landing_ptr.push(T::to_u32(&value).unwrap()), 
  1059.             ImageValues::OverlayLiftoffPtr=>self.overlay_liftoff_ptr.push(T::to_u32(&value).unwrap()), 
  1060.             ImageValues::OverlayShieldPtr=>self.overlay_shield_ptr.push(T::to_u32(&value).unwrap()),        */
  1061.             ImageValues::ImageGrpPtr=>self.image_grp_ptr.push(T::to_u32(&value).unwrap()),
  1062.             ImageValues::BuildingOverlayStateMax=>self.building_overlay_state_max.push(T::to_u8(&value).unwrap()),
  1063.             _=>{
  1064.                 debug!("Unable to push value");
  1065.             },
  1066.         }
  1067.     }
  1068.     fn set<T: num_traits::cast::ToPrimitive>(&mut self, index: usize, identifier: Self::Id, value: T){
  1069.         let length=self.length as usize;
  1070.         match identifier {
  1071.             ImageValues::GrpId=>self.grp_id[index] = T::to_u32(&value).unwrap(),
  1072.             ImageValues::GraphicTurns=>self.graphic_turns[index] = T::to_u8(&value).unwrap(),
  1073.             ImageValues::DrawIfCloaked=>self.draw_if_cloaked[index] = T::to_u8(&value).unwrap(),
  1074.             ImageValues::Clickable=>self.clickable[index] = T::to_u8(&value).unwrap(),
  1075.             ImageValues::UseFullIscript=>self.use_full_iscript[index] = T::to_u8(&value).unwrap(), 
  1076.             ImageValues::DrawFunc=>self.draw_func[index] = T::to_u8(&value).unwrap(),
  1077.             ImageValues::DrawRemap=>self.draw_remap[index] = T::to_u8(&value).unwrap(),
  1078.             ImageValues::IscriptId=>self.iscript_id[index] = T::to_u32(&value).unwrap(),
  1079.             ImageValues::OverlayAttack=>self.overlay_attack[index] = T::to_u32(&value).unwrap(),   
  1080.             ImageValues::OverlayDamage=>self.overlay_damage[index] = T::to_u32(&value).unwrap(),   
  1081.             ImageValues::OverlaySpecial=>self.overlay_special[index] = T::to_u32(&value).unwrap(), 
  1082.             ImageValues::OverlayLanding=>self.overlay_landing[index] = T::to_u32(&value).unwrap(), 
  1083.             ImageValues::OverlayLiftoff=>self.overlay_liftoff[index] = T::to_u32(&value).unwrap(), 
  1084.             ImageValues::OverlayShield=>self.overlay_shield[index] = T::to_u32(&value).unwrap(),   
  1085.            
  1086. /*          ImageValues::OverlayAttackPtr=>self.overlay_attack_ptr[index] = T::to_u32(&value).unwrap(),
  1087.             ImageValues::OverlayDamagePtr=>self.overlay_damage_ptr[index] = T::to_u32(&value).unwrap(),
  1088.             ImageValues::OverlaySpecialPtr=>self.overlay_special_ptr[index] = T::to_u32(&value).unwrap(),  
  1089.             ImageValues::OverlayLandingPtr=>self.overlay_landing_ptr[index] = T::to_u32(&value).unwrap(),  
  1090.             ImageValues::OverlayLiftoffPtr=>self.overlay_liftoff_ptr[index] = T::to_u32(&value).unwrap(),  
  1091.            
  1092.             ImageValues::OverlayShieldPtr=>self.overlay_shield_ptr[index] = T::to_u32(&value).unwrap(),     */
  1093.             ImageValues::OverlayAttackPtr=>self.overlays[index] = T::to_u32(&value).unwrap(),  
  1094.             ImageValues::OverlayDamagePtr=>self.overlays[index+length] = T::to_u32(&value).unwrap(),   
  1095.             ImageValues::OverlaySpecialPtr=>self.overlays[index+length*2] = T::to_u32(&value).unwrap(),
  1096.             ImageValues::OverlayLandingPtr=>self.overlays[index+length*3] = T::to_u32(&value).unwrap(),
  1097.             ImageValues::OverlayLiftoffPtr=>self.overlays[index+length*4] = T::to_u32(&value).unwrap(),        
  1098.             ImageValues::OverlayShieldPtr=>self.overlays[index+length*5] = T::to_u32(&value).unwrap(),     
  1099.            
  1100.             ImageValues::ImageGrpPtr=>self.image_grp_ptr[index] = T::to_u32(&value).unwrap(),
  1101.             ImageValues::BuildingOverlayStateMax=>self.building_overlay_state_max[index] = T::to_u8(&value).unwrap(),
  1102.            
  1103.         }
  1104.     }
  1105.     unsafe fn parse_entry_value(&mut self, text: String, identifier: Self::Id)->u32{//placeholder for the future
  1106.         text.trim().parse().unwrap()
  1107.     }
  1108.     fn get_address_list(identifier: Self::Id)->Vec<usize>{
  1109.         let list = match identifier {
  1110.             //0x005***** is data table info, only for image extender-type extenders initialized at game init
  1111.             ImageValues::GrpId=>vec![0x004D7262+1,/**/0x00514010],
  1112.             ImageValues::IscriptId=>vec![0x00498FFF+3, 0x004D6698+3, 0x004D671C+3, 0x004D67A8+3, 0x004D689C+3, 0x004D691E+3,
  1113.                                         0x004D853F+3,/**/0x00514064],
  1114.             ImageValues::GraphicTurns=>vec![0x004D5A67+2,/**/0x0051401C],
  1115.             ImageValues::DrawIfCloaked=>vec![0x004976E4+2, 0x00498184+2, 0x004D6EC7+2, 0x004D7A60+2, 0x004D7AC3+2,
  1116.                                             /**/0x00514040],
  1117.             ImageValues::Clickable=>vec![0x004D5A7C+2,/**/0x00514028],
  1118.             ImageValues::UseFullIscript=>vec![0x00498FDB+2, 0x004D6701+2,/**/0x00514034],
  1119.             ImageValues::DrawFunc=>vec![0x00498FCA+2, 0x004D5AD0+2, 0x004D5AE0+2, 0x004D66B8+2,/**/0x0051404C],
  1120.             //also known as RLE Func
  1121.            
  1122.             ImageValues::DrawRemap=>vec![0x004D5AE9+3,/**/0x00514058],    
  1123.             ImageValues::OverlayAttack=>vec![0x004D728A+1,/**/0x0051407C],
  1124.             ImageValues::OverlayDamage=>vec![0x00467384+3,0x004798EF+3,0x004993D1+3,0x00499591+3,0x004D72B7+1,
  1125.                                             /**/0x00514088],
  1126.             ImageValues::OverlaySpecial=>vec![0x004D72DA+1,/**/0x00514094],
  1127.             ImageValues::OverlayLanding=>vec![0x004997EA+3, 0x004D72FD+1,/**/0x005140A0],
  1128.             ImageValues::OverlayShield=>vec![0x004D7343+1,/**/0x00514070],
  1129.             ImageValues::OverlayLiftoff=>vec![0x0049982A+3, 0x004D7320+1,/**/0x005140AC],
  1130.             ImageValues::OverlayAttackPtr=>vec![0x00401E0F+3, 0x00477FFD+3, 0x00478071+3, 0x0049968F+3, 0x004D50F5+1,
  1131.                                                 0x004D5788+3, 0x004D728F+1],
  1132.             ImageValues::OverlayDamagePtr=>vec![0x0049941A+3, 0x004994C2+3, 0x00499603+3, 0x004D5C39+3, 0x004D72BC+1], 
  1133.             ImageValues::OverlaySpecialPtr=>vec![0x00498BE5+3, 0x0049F73E+3, 0x004D5A0A+3, 0x004D72DF+1],      
  1134.             ImageValues::OverlayLandingPtr=>vec![0x0049826A+3, 0x0049829A+3, 0x004D7302+1, 0x004D7325+1],
  1135.             ImageValues::OverlayLiftoffPtr=>vec![0x004D7325+1],
  1136.             ImageValues::OverlayShieldPtr=>vec![0x0049938E+3, 0x004D511D+1, 0x004D5748+3, 0x004E614F+3, 0x004D7348+1
  1137.                                                 ],                                         
  1138.             ImageValues::ImageGrpPtr=>vec![0x0048D76D+3,0x0048DAA7+3,0x004D50E1+1,0x004D5A57+3,0x004D6360+3,
  1139.                                         0x004D682F+3,0x004D701B+3,0x004D7267+1],                                           
  1140.             ImageValues::BuildingOverlayStateMax=>vec![0x00496ED7+2, 0x004994AA+3, 0x0049EF37+2, 0x004D5C33+2, 0x004D5C77+2,
  1141.                                                     0x004E60B5+3,0x004E669A+2],
  1142.             _=>vec![],
  1143.  
  1144.         };
  1145.         list           
  1146.     }
  1147.  
  1148.     unsafe fn extend_data_conventional(&mut self, exe: &mut whack::ModulePatcher){
  1149.         let _ = match self.parse_set("samase\\images_ext.txt",999,14){
  1150.             Ok(())=>{
  1151.                 //everything's okay
  1152.             },
  1153.             Err(e)=>{
  1154.                 windows::message_box("Aise panic", &e);
  1155.                 TerminateProcess(GetCurrentProcess(), 0x4230daef);
  1156.             },
  1157.         };
  1158.     }  
  1159.     unsafe fn extra_code(&mut self, exe: &mut whack::ModulePatcher){
  1160.         //extra uplinks
  1161.         let length = self.length as usize;
  1162.         exe.replace_val(0x00493367+2,(&mut self.image_grp_ptr[0] as *mut u32) as u32 + 0x920);//image 584 (psi field 1)
  1163.         exe.replace_val(0x004D5415+2,(&mut self.image_grp_ptr[0] as *mut u32) as u32 + 0x348);
  1164.         exe.replace_val(0x004D5636+3,(&mut self.image_grp_ptr[0] as *mut u32) as u32 - 0x4);
  1165.         exe.replace_val(0x004D6025+3,(&mut self.image_grp_ptr[0] as *mut u32) as u32 + 0x8c4);//image 561 (sel circle 22px)
  1166.         exe.replace_val(0x004D5110+2,(&mut self.overlays[length*4] as *mut u32) as u32 + 4*(self.grp_id.len() as u32));
  1167. //      exe.replace_val(0x004D5110+2,(&mut self.overlay_liftoff_ptr[0] as *mut u32) as u32 + 4*(self.grp_id.len() as u32));
  1168.  
  1169.         debug!("Replace val check: {}",self.grp_id.len());
  1170.         exe.replace_val(0x004D510A+2, self.grp_id.len()*4);
  1171.         exe.replace_val(0x004D7183+1, self.grp_id.len()*24+8);
  1172.         exe.replace_val(0x0047AE48+2, self.grp_id.len()-0x0F4);
  1173.         exe.replace_val(0x0047AF48+2, self.grp_id.len()-0x0F4);
  1174.         exe.replace_val(0x004D6356+1, self.grp_id.len()-0x0F4);
  1175.         let offset_n4_8 = -(self.grp_id.len() as i32)*4-8;
  1176.         let offset_n24_8 = -(self.grp_id.len() as i32)*24-8;
  1177.         exe.replace_val(0x004D724E+2, offset_n4_8 as usize);
  1178.         exe.replace_val(0x004D7255+2, offset_n24_8 as usize);
  1179.         exe.replace_val(0x004D7276+2, offset_n4_8 as usize);
  1180.         exe.replace_val(0x004D727D+2, offset_n24_8 as usize);  
  1181.         exe.replace_val(0x004D72A3+2, offset_n4_8 as usize);
  1182.         exe.replace_val(0x004D72AA+2, offset_n24_8 as usize);  
  1183.         exe.replace_val(0x004D72C6+2, offset_n4_8 as usize);
  1184.         exe.replace_val(0x004D72CD+2, offset_n24_8 as usize);  
  1185.         exe.replace_val(0x004D72E9+2, offset_n4_8 as usize);
  1186.         exe.replace_val(0x004D72F0+2, offset_n24_8 as usize);  
  1187.         exe.replace_val(0x004D730C+2, offset_n4_8 as usize);
  1188.         exe.replace_val(0x004D7313+2, offset_n24_8 as usize);
  1189.         exe.replace_val(0x004D732F+2, offset_n4_8 as usize);
  1190.         exe.replace_val(0x004D7336+2, offset_n24_8 as usize);
  1191.         exe.replace_val(0x004EA60D+2, self.grp_id.len() as u16);   
  1192.     }
  1193.     fn get_size_list()->Vec<usize>{
  1194.    
  1195.    
  1196.    
  1197.         return vec![0x00401DFA+2, 0x00499676+2, 0x004D50DC+1, 0x004D5100+1, 0x004D5118+1, 0x004D5773+2, 0x004D5C23+1,
  1198.                    0x004D72D4+1, 0x004D72F7+1, 0x004D731A+1, 0x004D725C+1, 0x004D7284+1, 0x004D72B1+1, 0x004D733D+1,
  1199.                    0x004F397D+1,
  1200.                    //only for images.dat, not required for new extender:
  1201. /*                 0x00514018, 0x00514024, 0x00514030, 0x0051403C, 0x00514048, 0x00514054, 0x00514060, 0x0051406C,
  1202.                    0x00514078, 0x00514084, 0x00514090, 0x0051409C, 0x005140A8, 0x005140B4*/];              
  1203.     }
  1204. }
  1205. //
  1206. //
  1207. //
  1208. #[derive(Copy,Clone)]
  1209. pub enum UnitValues {
  1210.     Flingy,
  1211.     SndWhtStart,
  1212.     SndWhtEnd,
  1213.     SndYesStart,
  1214.     SndYesEnd,
  1215.     SndPssStart,
  1216.     SndPssEnd,
  1217.     SndReady,
  1218. }
  1219.  
  1220.  
  1221. //#[derive(Default)]
  1222. pub struct UnitExtender {
  1223.     pub length: u32,
  1224.    
  1225.     pub flingy_ext: Vec<u32>,
  1226.     pub snd_wht_start: Vec<u16>,
  1227.     pub snd_wht_end: Vec<u16>,
  1228.     pub snd_yes_start: Vec<u16>,
  1229.     pub snd_yes_end: Vec<u16>,
  1230.     pub snd_pss_start: Vec<u16>,
  1231.     pub snd_pss_end: Vec<u16>,
  1232.     pub snd_ready: Vec<u16>,
  1233. }
  1234.  
  1235. impl Default for UnitExtender {
  1236.     fn default() -> UnitExtender {
  1237.         UnitExtender {
  1238.             length: 228,
  1239.             flingy_ext: vec![0;228],
  1240.             snd_wht_start: vec![0;228],
  1241.             snd_wht_end: vec![0;228],
  1242.             snd_yes_start: vec![0;228],
  1243.             snd_yes_end: vec![0;228],
  1244.             snd_pss_start: vec![0;228],
  1245.             snd_pss_end: vec![0;228],
  1246.             snd_ready: vec![0;228],//custom default is required for pointer to first member to exist    */         
  1247.         }
  1248.     }
  1249. }
  1250.  
  1251. impl UnitExtender {
  1252.     fn new()->UnitExtender {
  1253.         UnitExtender {
  1254.             length: 228,
  1255.             flingy_ext: Vec::new(),//required for ptr
  1256.             snd_wht_start: Vec::new(),
  1257.             snd_wht_end: Vec::new(),
  1258.             snd_yes_start: Vec::new(),
  1259.             snd_yes_end: Vec::new(),
  1260.             snd_pss_start: Vec::new(),
  1261.             snd_pss_end: Vec::new(),
  1262.             snd_ready: Vec::new(),
  1263.  
  1264.         }
  1265.     }
  1266. }
  1267. impl DataExtender for UnitExtender {
  1268.     type Id = UnitValues;
  1269.     type SizeLimit = u32;
  1270.     fn clear(&mut self){
  1271.         self.flingy_ext.clear();
  1272.         self.snd_wht_start.clear();
  1273.         self.snd_wht_end.clear();
  1274.         self.snd_yes_start.clear();
  1275.         self.snd_yes_end.clear();
  1276.         self.snd_pss_start.clear();
  1277.         self.snd_pss_end.clear();
  1278.         self.snd_ready.clear();
  1279.     }
  1280.    
  1281.     unsafe fn init_raw<T: num_traits::cast::ToPrimitive>(&mut self, new_size: T, repatch_array: bool){}
  1282.     unsafe fn init_code(&mut self, exe: &mut whack::ModulePatcher){ }
  1283.     fn get(&mut self, index: usize, identifier: Self::Id)->u32{
  1284.         let length = self.length as usize;
  1285.         let result = match identifier {
  1286.             UnitValues::Flingy => self.flingy_ext[index] as u32,   
  1287.             UnitValues::SndWhtStart => self.snd_wht_start[index] as u32,   
  1288.             UnitValues::SndWhtEnd => self.snd_wht_end[index] as u32,   
  1289.             UnitValues::SndYesStart => self.snd_yes_start[index] as u32,   
  1290.             UnitValues::SndYesEnd => self.snd_yes_end[index] as u32,   
  1291.             UnitValues::SndPssStart => self.snd_pss_start[index] as u32,   
  1292.             UnitValues::SndPssEnd => self.snd_pss_end[index] as u32,   
  1293.             UnitValues::SndReady => self.snd_ready[index] as u32,  
  1294.         };
  1295.         result
  1296.     }
  1297.     fn identifier(&mut self,line: &str)->Option<Self::Id>{
  1298.         None//not used for fake extender, as there's no units_dat.txt
  1299.     }
  1300.     fn push_val<T: num_traits::cast::ToPrimitive>(&mut self, identifier: Self::Id, value: T){
  1301.         //not used for fake extender, length is always 228
  1302.     }  
  1303.     fn set<T: num_traits::cast::ToPrimitive>(&mut self, index: usize, identifier: Self::Id, value: T){
  1304.         match identifier {
  1305.             UnitValues::Flingy => self.flingy_ext[index] = T::to_u32(&value).unwrap(), 
  1306.             UnitValues::SndWhtStart => self.snd_wht_start[index] = T::to_u16(&value).unwrap(), 
  1307.             UnitValues::SndWhtEnd => self.snd_wht_end[index] = T::to_u16(&value).unwrap(), 
  1308.             UnitValues::SndYesStart => self.snd_yes_start[index] = T::to_u16(&value).unwrap(), 
  1309.             UnitValues::SndYesEnd => self.snd_yes_end[index] = T::to_u16(&value).unwrap(), 
  1310.             UnitValues::SndPssStart => self.snd_pss_start[index] = T::to_u16(&value).unwrap(), 
  1311.             UnitValues::SndPssEnd => self.snd_pss_end[index] = T::to_u16(&value).unwrap(), 
  1312.             UnitValues::SndReady => self.snd_ready[index] = T::to_u16(&value).unwrap(),
  1313.         };
  1314.     }
  1315.     unsafe fn parse_entry_value(&mut self, text: String, identifier: Self::Id)->u32{//placeholder for the future
  1316.         text.trim().parse().unwrap()
  1317.     }
  1318.     fn get_address_list(identifier: Self::Id)->Vec<usize>{
  1319.         match identifier {
  1320.             UnitValues::Flingy => vec![],//patched in gptp, not used
  1321.            
  1322.             UnitValues::SndReady => vec![0x0048F478+4],    
  1323.             UnitValues::SndPssStart => vec![0x0048EA26+4], 
  1324.             UnitValues::SndPssEnd => vec![0x0048EA33+4],//also 0042FF21 but not related to sounds at all (?)
  1325.             UnitValues::SndWhtStart => vec![0x0047BE12+4, 0x0048EA4F+4],
  1326.             UnitValues::SndWhtEnd => vec![0x0047BF36+4,0x0048EA58+4],
  1327.             UnitValues::SndYesStart => vec![0x0048EAB5+4],
  1328.             UnitValues::SndYesEnd => vec![0x0048EAC4+4],
  1329.             _=>vec![],
  1330.         }
  1331.     }
  1332.     unsafe fn extend_data_conventional(&mut self, exe: &mut whack::ModulePatcher){
  1333.         //self.clear();
  1334.         let length = 228;
  1335. //      debug!("Extend data: units");
  1336. //      self.flingy_ext.resize(length, 0);
  1337. /*      for i in 0..length {
  1338.             self.flingy_ext[i] = bw::units_dat_flingy_old[i] as u32;
  1339.         }*/
  1340.         bw::gptp_flingyid_copy();
  1341.         Self::copy_array_from_changesize::<u16>(&mut bw::units_dat_snd_ready[0] as *mut u16, &mut self.snd_ready, 106, 228);
  1342.         Self::copy_array_from_changesize::<u16>(&mut bw::units_dat_snd_annoyed_begin[0] as *mut u16, &mut self.snd_pss_start, 106, 228);
  1343.         Self::copy_array_from_changesize::<u16>(&mut bw::units_dat_snd_annoyed_end[0] as *mut u16, &mut self.snd_pss_end, 106, 228);
  1344.         Self::copy_array_from_changesize::<u16>(&mut bw::units_dat_snd_what_begin[0] as *mut u16, &mut self.snd_wht_start, 228, 228);
  1345.         Self::copy_array_from_changesize::<u16>(&mut bw::units_dat_snd_what_end[0] as *mut u16, &mut self.snd_wht_end, 228, 228);
  1346.         Self::copy_array_from_changesize::<u16>(&mut bw::units_dat_snd_yes_begin[0] as *mut u16, &mut self.snd_yes_start, 106, 228);
  1347.         Self::copy_array_from_changesize::<u16>(&mut bw::units_dat_snd_yes_end[0] as *mut u16, &mut self.snd_yes_end, 106, 228);
  1348.         Self::uplink::<u16>(exe, &mut self.snd_ready[0] as *mut u16, Self::get_address_list(UnitValues::SndReady));
  1349.         Self::uplink::<u16>(exe, &mut self.snd_pss_start[0] as *mut u16, Self::get_address_list(UnitValues::SndPssStart));
  1350.         Self::uplink::<u16>(exe, &mut self.snd_pss_end[0] as *mut u16, Self::get_address_list(UnitValues::SndPssEnd));
  1351.         Self::uplink::<u16>(exe, &mut self.snd_wht_start[0] as *mut u16, Self::get_address_list(UnitValues::SndWhtStart));
  1352.         Self::uplink::<u16>(exe, &mut self.snd_wht_end[0] as *mut u16, Self::get_address_list(UnitValues::SndWhtEnd));
  1353.         Self::uplink::<u16>(exe, &mut self.snd_yes_start[0] as *mut u16, Self::get_address_list(UnitValues::SndYesStart));
  1354.         Self::uplink::<u16>(exe, &mut self.snd_yes_end[0] as *mut u16, Self::get_address_list(UnitValues::SndYesEnd));
  1355.         /*let bytes = split_bytes(&mut self.flingy_ext[0] as *mut u32 as u32);
  1356.         let eax_eax = [0x8b, 0x04, 0x85,bytes[0],bytes[1],bytes[2],bytes[3],0xc3];
  1357.         globals::simple_wrapper(exe,&eax_eax,0x00454317,2);
  1358.         let ecx_edi = [0x8b,0x0c,0xbd,bytes[0],bytes[1],bytes[2],bytes[3],0xc3];
  1359.         globals::simple_wrapper(exe,&ecx_edi,0x00463A71,2);
  1360.         let edx_ecx = [0x8b,0x14,0x8d,bytes[0],bytes[1],bytes[2],bytes[3],0xc3];
  1361.         //globals::simple_wrapper(exe,&edx_ecx,0x004683C6,2);
  1362.         let edx_eax = [0x8b, 0x14, 0x85,bytes[0],bytes[1],bytes[2],bytes[3],0xc3];
  1363.         //globals::simple_wrapper(exe,&edx_eax,0x0047B854,2);
  1364.         //globals::simple_wrapper(exe,&edx_eax,0x0047B8A4,2);
  1365.         //wrappers 3-5 if gptp speed hooks are enabled
  1366.         let ecx_eax = [0x8b, 0x0c, 0x85, bytes[0],bytes[1],bytes[2],bytes[3],0xc3];
  1367.         globals::simple_wrapper(exe,&ecx_eax,0x0047B8F4,2);
  1368.         globals::simple_wrapper(exe,&ecx_eax,0x0048D756,2);
  1369.         globals::simple_wrapper(exe,&ecx_eax,0x0048DA8A,2);
  1370.         globals::simple_wrapper(exe,&edx_eax,0x00497148,2);
  1371.         let eax_ebx = [0x8b, 0x04, 0x9d, bytes[0],bytes[1],bytes[2],bytes[3],0xc3];
  1372.         globals::simple_wrapper(exe,&eax_ebx,0x0049ED0B,2);
  1373.         let eax_edx = [0x8b, 0x04, 0x95, bytes[0],bytes[1],bytes[2],bytes[3],0xc3];
  1374.         globals::simple_wrapper(exe,&eax_edx,0x004E9A10,2);*/
  1375.        
  1376.         //Self::uplink::<u8>(exe, &mut self.flingy_ext[0] as *mut u16, Self::get_address_list(UnitValues::Flingy));
  1377.     }
  1378.     unsafe fn extra_code(&mut self, exe: &mut whack::ModulePatcher){}
  1379.     fn get_size_list()->Vec<usize>{
  1380.         vec![]
  1381.     }
  1382. }
  1383.  
  1384. //
  1385. //
  1386. //
  1387. #[derive(Copy,Clone)]
  1388. pub enum FlingyValues {
  1389.     TopSpeed,
  1390.     Acceleration,
  1391.     TurnRadius,
  1392.     MovementType,
  1393.     SpriteId,
  1394.     HaltDistance,
  1395.     IscriptMask,
  1396. }
  1397.  
  1398. #[derive(Default, Serialize, Deserialize)]
  1399. pub struct FlingyExtender {
  1400.     pub top_speed: Vec<u32>,
  1401.     pub acceleration: Vec<u16>,
  1402.     pub turn_radius: Vec<u8>,
  1403.     pub movement_type: Vec<u8>,
  1404.     pub sprite_id: Vec<u16>,
  1405.     pub halt_distance: Vec<u32>,
  1406.     pub iscript_mask: Vec<u8>,
  1407. }
  1408.  
  1409. impl FlingyExtender {
  1410.     pub fn new()->FlingyExtender {
  1411.         FlingyExtender {
  1412.             top_speed: Vec::new(),
  1413.             acceleration: Vec::new(),
  1414.             turn_radius: Vec::new(),
  1415.             movement_type: Vec::new(),
  1416.             sprite_id: Vec::new(),
  1417.             halt_distance: Vec::new(),
  1418.             iscript_mask: Vec::new(),
  1419.         }
  1420.     }
  1421. }
  1422.  
  1423. impl DataExtender for FlingyExtender {
  1424.     type Id = FlingyValues;
  1425.     type SizeLimit = u32;//old - u8
  1426.     unsafe fn extra_code(&mut self, exe: &mut whack::ModulePatcher){}
  1427.     unsafe fn init_raw<T: num_traits::cast::ToPrimitive>(&mut self, new_size: T, repatch_array: bool){}
  1428.     fn get(&mut self, index: usize, identifier: Self::Id)->u32{
  1429.         let result = match identifier {
  1430.             FlingyValues::TopSpeed => self.top_speed[index],
  1431.             FlingyValues::Acceleration => self.acceleration[index] as u32,
  1432.             FlingyValues::TurnRadius => self.turn_radius[index] as u32,
  1433.             FlingyValues::MovementType => self.movement_type[index] as u32,
  1434.             FlingyValues::SpriteId => self.sprite_id[index] as u32,
  1435.             FlingyValues::HaltDistance => self.halt_distance[index],
  1436.             FlingyValues::IscriptMask => self.iscript_mask[index] as u32,
  1437.         };
  1438.         result 
  1439.     }
  1440.     unsafe fn init_code(&mut self, exe: &mut whack::ModulePatcher){}
  1441.     unsafe fn parse_entry_value(&mut self, text: String, identifier: Self::Id)->u32{//placeholder for the future
  1442.         text.trim().parse().unwrap()
  1443.     }
  1444.     fn get_address_list(identifier: Self::Id)->Vec<usize>{
  1445.         let list = match identifier {
  1446.             FlingyValues::TopSpeed=>vec![0x00454334+3,0x0047B8FB+3,0x00494FA3+3,0x0049637E+3, /* 0x00515A44*/],
  1447.             FlingyValues::Acceleration=>vec![0x0047B8AB+4,0x00494FB0+4,0x00496388+4,/* 0x00515A50*/],
  1448.             FlingyValues::TurnRadius=>vec![0x0047B85B+3,0x00496397+2, /*0x00515A68*/],
  1449.             FlingyValues::MovementType=>vec![0x0045431E+2,0x004963A0+2, /*0x00515A80*/],
  1450.             FlingyValues::SpriteId=>vec![0x00463A78+4,0x004683CD+4,0x0048D75D+4,0x0048DA97+4,0x00496411+4,0x0049714F+4,0x00497176+4,
  1451.                             0x0049719D+4,0x004971C4+4,0x004971EB+4,0x00497212+4,0x004E9A17+4,/*0x00515A38*/],
  1452.             FlingyValues::HaltDistance=>vec![0x00494FBA+3, /*0x00515A5C*/],
  1453. //          FlingyValues::IscriptMask=>vec![0x00515A74],//not used in bw, memory ref only
  1454.             _=>vec![],
  1455.         };
  1456.         list           
  1457.     }
  1458.     fn get_size_list()->Vec<usize>{
  1459.         //flingy data header offset +0x8 (count)
  1460.         return vec![];
  1461. //      return vec![0x00515A38+8, 0x00515A44+8, 0x00515A50+8, 0x00515A5C+8, 0x00515A68+8, 0x00515A74+8, 0x00515A80+8];//unused
  1462.     }
  1463.     fn clear(&mut self){
  1464.         self.top_speed.clear();
  1465.         self.acceleration.clear();
  1466.         self.turn_radius.clear();
  1467.         self.movement_type.clear();
  1468.         self.sprite_id.clear();
  1469.         self.halt_distance.clear();
  1470.         self.iscript_mask.clear();
  1471.     }
  1472.     unsafe fn extend_data_conventional(&mut self, exe: &mut whack::ModulePatcher){
  1473.         self.clear();
  1474.         Self::copy_array_from::<u32>(&mut bw::flingy_dat_top_speed[0] as *mut u32, &mut self.top_speed, 0xd1);
  1475.         Self::copy_array_from::<u16>(&mut bw::flingy_dat_acceleration[0] as *mut u16, &mut self.acceleration, 0xd1);
  1476.         Self::copy_array_from::<u8>(&mut bw::flingy_dat_turn_radius[0] as *mut u8, &mut self.turn_radius, 0xd1);
  1477.         Self::copy_array_from::<u8>(&mut bw::flingy_dat_movement_type[0] as *mut u8, &mut self.movement_type, 0xd1);
  1478.         Self::copy_array_from::<u16>(&mut bw::flingy_dat_sprite_id[0] as *mut u16, &mut self.sprite_id, 0xd1);
  1479.         Self::copy_array_from::<u32>(&mut bw::flingy_dat_halt_distance[0] as *mut u32, &mut self.halt_distance, 0xd1);
  1480.         Self::copy_array_from::<u8>(&mut bw::flingy_dat_iscript_mask[0] as *mut u8, &mut self.iscript_mask, 0xd1); 
  1481.        
  1482.         let _ = match self.parse("samase\\flingy_ext.txt"){
  1483.             Ok(())=>{
  1484.                 //everything's okay
  1485.             },
  1486.             Err(e)=>{
  1487.                 windows::message_box("Aise panic", &e);
  1488.                 TerminateProcess(GetCurrentProcess(), 0x4230daef);
  1489.             },
  1490.         };
  1491.         debug!("F: {} {} {} {} {} {} {}",self.top_speed.len(),self.acceleration.len(),self.movement_type.len(),self.turn_radius.len(),
  1492.                                 self.sprite_id.len(), self.halt_distance.len(),self.iscript_mask.len());
  1493.         let length = self.top_speed.len();
  1494.         Self::uplink::<u32>(exe, &mut self.top_speed[0] as *mut u32, Self::get_address_list(FlingyValues::TopSpeed));
  1495.         Self::uplink::<u16>(exe, &mut self.acceleration[0] as *mut u16, Self::get_address_list(FlingyValues::Acceleration));
  1496.         Self::uplink::<u8>(exe, &mut self.turn_radius[0] as *mut u8, Self::get_address_list(FlingyValues::TurnRadius));
  1497.         Self::uplink::<u8>(exe, &mut self.movement_type[0] as *mut u8, Self::get_address_list(FlingyValues::MovementType));
  1498.         Self::uplink::<u16>(exe, &mut self.sprite_id[0] as *mut u16, Self::get_address_list(FlingyValues::SpriteId));
  1499.         Self::uplink::<u32>(exe, &mut self.halt_distance[0] as *mut u32, Self::get_address_list(FlingyValues::HaltDistance));
  1500.         Self::uplink::<u8>(exe, &mut self.iscript_mask[0] as *mut u8, Self::get_address_list(FlingyValues::IscriptMask));
  1501.         Self::uplink_length_dattable(exe, length.clone() as u32, Self::get_size_list());
  1502.         self.extra_code(exe);
  1503.     }  
  1504.     fn identifier(&mut self, line: &str)->Option<Self::Id>{
  1505.         let result = match line.trim().as_ref(){
  1506.             "top_speed"=>FlingyValues::TopSpeed,
  1507.             "acceleration"=>FlingyValues::Acceleration,
  1508.             "turn_radius"=>FlingyValues::TurnRadius,
  1509.             "movement_type"=>FlingyValues::MovementType,
  1510.             "sprite_id"=>FlingyValues::SpriteId,
  1511.             "halt_distance"=>FlingyValues::HaltDistance,
  1512.             "iscript_mask"=>FlingyValues::IscriptMask,
  1513.             _=>{
  1514.                 return None;
  1515.             },
  1516.         };
  1517.         Some(result)
  1518.     }
  1519.     fn set<T: num_traits::cast::ToPrimitive>(&mut self, index: usize, identifier: Self::Id, value: T){
  1520.         match identifier {
  1521.             FlingyValues::TopSpeed=>self.top_speed[index] = T::to_u32(&value).unwrap(),
  1522.             FlingyValues::Acceleration=>self.acceleration[index] = T::to_u16(&value).unwrap(),
  1523.             FlingyValues::TurnRadius=>self.turn_radius[index] = T::to_u8(&value).unwrap(),
  1524.             FlingyValues::MovementType=>self.movement_type[index] = T::to_u8(&value).unwrap(),
  1525.             FlingyValues::SpriteId=>self.sprite_id[index] = T::to_u16(&value).unwrap(),
  1526.             FlingyValues::HaltDistance=>self.halt_distance[index] = T::to_u32(&value).unwrap(),
  1527.             FlingyValues::IscriptMask=>self.iscript_mask[index] = T::to_u8(&value).unwrap(),       
  1528.             _=>{},
  1529.         }
  1530.     }
  1531.     fn push_val<T: num_traits::cast::ToPrimitive>(&mut self, identifier: Self::Id, value: T){
  1532.         match identifier {
  1533.             FlingyValues::TopSpeed=>self.top_speed.push(T::to_u32(&value).unwrap()),
  1534.             FlingyValues::Acceleration=>self.acceleration.push(T::to_u16(&value).unwrap()),
  1535.             FlingyValues::TurnRadius=>self.turn_radius.push(T::to_u8(&value).unwrap()),
  1536.             FlingyValues::MovementType=>self.movement_type.push(T::to_u8(&value).unwrap()),
  1537.             FlingyValues::SpriteId=>self.sprite_id.push(T::to_u16(&value).unwrap()),
  1538.             FlingyValues::HaltDistance=>self.halt_distance.push(T::to_u32(&value).unwrap()),
  1539.             FlingyValues::IscriptMask=>self.iscript_mask.push(T::to_u8(&value).unwrap()),      
  1540.             _=>{},
  1541.         }
  1542.     }
  1543. }
  1544.  
  1545. #[derive(Default, Serialize, Deserialize)]
  1546. pub struct CcmuExtender {
  1547.     pub bytes: Vec<u8>,
  1548.     //59cb58 - offset 0
  1549.     //59cca8 - offset 336
  1550.     //6283E8 - offset (1700*336)+336
  1551.     pub length: u32,
  1552. }
  1553.  
  1554. impl DataExtender for CcmuExtender {
  1555.     type Id = u8;
  1556.     type SizeLimit = u32;
  1557.     unsafe fn extra_code(&mut self, exe: &mut whack::ModulePatcher){}
  1558.     fn clear(&mut self){}
  1559.     unsafe fn init_code(&mut self, exe: &mut whack::ModulePatcher){}
  1560.     unsafe fn init_raw<T: num_traits::cast::ToPrimitive>(&mut self, new_size: T, repatch_array: bool){}
  1561.     fn get(&mut self, index: usize, identifier: Self::Id)->u32{0}//later add unit recovery but probably not required at all
  1562.     fn identifier(&mut self, line: &str)->Option<Self::Id>{None}
  1563.     fn push_val<T: num_traits::cast::ToPrimitive>(&mut self, identifier: Self::Id, value: T){}
  1564.     fn set<T: num_traits::cast::ToPrimitive>(&mut self, index: usize, identifier: Self::Id, value: T){}
  1565.     unsafe fn parse_entry_value(&mut self, text: String, identifier: Self::Id)->u32{0}
  1566.     fn get_address_list(identifier: Self::Id)->Vec<usize>{
  1567.         /*let list = {
  1568.             //last is start of dat array in memory to patch *data entry
  1569.             SpriteValues::IncludeInVision=>vec![0x0042D515+2,0x00497157+2,0x0049717E+2,0x004971A5+2,0x004971CC+2,
  1570.                                                 0x004971F3+2,0x0049721A+2,0x00497C64+2],//+
  1571.             SpriteValues::StartAsVisible=>vec![0x00665C48+2],//+           
  1572.             SpriteValues::ImageId=>vec![0x00463A87+4,0x004683D5+4,0x0048D765+4,0x0048DA9F+4,0x0049907D+4,0x004D7A58+4,
  1573.                                     0x004D7ABB+4,0x004E4CC5+4,0x004E4FDB+4,0x004E5018+4,0x004E6640+4],
  1574.             SpriteValues::SelectionCircle=>vec![0x004D601E+3,0x004D681A+4],
  1575.             SpriteValues::ImagePos=>vec![0x004D6032+2,0x004D6840+2],
  1576.             SpriteValues::HpBar=>vec![0x0047A871+2,0x0047A90D+2,0x0047AA6B+3,0x004D6043+2],
  1577.             _=>vec![],
  1578.        
  1579.         };
  1580.         list    */     
  1581.         vec![]
  1582.     }
  1583.     unsafe fn extend_data_conventional(&mut self, exe: &mut whack::ModulePatcher){
  1584.         //patch all entries
  1585.         //add gptp support (59cca8/59cb58 use)
  1586.         //add aise function to recover array offsets
  1587.     }  
  1588.     fn get_size_list()->Vec<usize>{
  1589.         return vec![];
  1590.     }
  1591. }
RAW Paste Data