Advertisement
Nuppiz

asdeözljkilagjakof

Jun 12th, 2022 (edited)
1,172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.25 KB | None | 0 0
  1. void saveLevelState(char* levelname)
  2. {
  3.     FILE* save_file;
  4.     char savefilepath[50] = "SAVES/CURRENT/";
  5.     int i;
  6.     long object_offset = (long)Game.Objects;
  7.  
  8.     strcat(levelname, ".SAV");
  9.     strcat(savefilepath, levelname);
  10.     save_file = fopen(savefilepath, "wb");
  11.     if (!save_file)
  12.     {
  13.         perror("fopen");
  14.         delay(60000);
  15.     }
  16.     fwrite(&Game, sizeof(GameData_t), 1, save_file);
  17.     fwrite(Game.Objects, sizeof(Object_t), Game.object_capacity, save_file);
  18.     for (i = 0; i < Game.id_capacity; i++)
  19.     {
  20.         Game.ObjectsById[i] -= object_offset;
  21.     }
  22.     fwrite(Game.ObjectsById, sizeof(void*), Game.object_count, save_file);
  23.     for (i = 0; i < Game.id_capacity; i++)
  24.     {
  25.         Game.ObjectsById[i] += object_offset;
  26.     }
  27.     fwrite(Entities, sizeof(Entity_t), MAX_ENTITIES, save_file);
  28.     fclose(save_file);
  29. }
  30.  
  31. void loadLevelState(char* savename)
  32. {
  33.     FILE* save_file;
  34.     char savefilepath[50] = "SAVES/CURRENT/";
  35.     int i;
  36.     size_t object_offset;
  37.  
  38.     strcat(savefilepath, savename);
  39.     save_file = fopen(savefilepath, "rb");
  40.     if (!save_file)
  41.     {
  42.         perror("fopen");
  43.         delay(60000);
  44.     }
  45.     ASSERT(Game.Objects != NULL);
  46.     fseek(save_file, 0x30, SEEK_SET);
  47.     fread(&Game.object_count, 2, 1, save_file);
  48.     fseek(save_file, 0x32, SEEK_SET);
  49.     fread(&Game.object_capacity, 2, 1, save_file);
  50.     fseek(save_file, 0x34, SEEK_SET);
  51.     fread(&Game.id_capacity, 2, 1, save_file);
  52.  
  53.     initGameData(Game.object_count, Game.id_capacity);
  54.     object_offset = (size_t)Game.Objects;
  55.    
  56.     fseek(save_file, 0x36, SEEK_SET);
  57.     fread(&Game.player_id, 2, 1, save_file);
  58.     fseek(save_file, 0x38, SEEK_SET);
  59.     fread(Game.Objects, sizeof(Object_t), Game.object_capacity, save_file);
  60.     fread(Game.ObjectsById, sizeof(void*), Game.id_capacity, save_file);
  61.     for (i = 0; i < Game.id_capacity; i++)
  62.     {
  63.         Game.ObjectsById[i] += object_offset;
  64.     }
  65.     fread(Entities, sizeof(Entity_t), MAX_ENTITIES, save_file);
  66.     fclose(save_file);
  67.     for (i = 0; i < Game.object_count; i++)
  68.     {
  69.         Game.Objects[i].texture_id = loadTexture("SPRITES/DUDE1.7UP"); // replace with proper sprite system
  70.     }
  71.     corpse_sprite_id = loadTexture("SPRITES/CORPSE.7UP");
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement