Advertisement
AnthonyCagliano

Untitled

Nov 15th, 2022
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. bool ship_load_data(const uint8_t* data, size_t len){
  2.  
  3. // (uint8_t)*data is the maximum module count
  4. // (uint8_t*)data+1 is the ptr to the start of module data
  5. // len - 1 is the length of the module data
  6. // (len - 1) / sizeof(shipmodule_t) is the number of modules
  7.  
  8. uint8_t module_count = (len - 1) / sizeof(shipmodule_t);
  9. uint8_t *modules = malloc(len-1);
  10. if(!modules) return false;
  11.  
  12. gamestate.ship.ship_module_max = *data++;
  13. gamestate.ship.ship_module_count = module_count;
  14. gamestate.ship.modules = modules;
  15.  
  16. memcpy(modules, data, len-1);
  17.  
  18. return true;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement