SHARE
TWEET

extracthalotagdefs diffs by Smx

liquidspark Aug 12th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --- "/l/Program Files (x86)/Microsoft Games/Halo Custom Edition/progs/extracthalotagdefs.c" 2019-07-07 14:33:51.068656800 +0200
  2. +++ "/l/Program Files (x86)/Microsoft Games/Halo Custom Edition/progs/extracthalotagdefs_fix.c" 2019-07-27 12:01:20.691244400 +0200
  3. @@ -6,10 +6,11 @@
  4.  //  Copyright © 2018 haloserver. All rights reserved.
  5.  //
  6.  
  7. -#import <stdio.h>
  8. -#import <stdlib.h>
  9. -#import <string.h>
  10. -#import <stdbool.h>
  11. +#include <stdio.h>
  12. +#include <stdlib.h>
  13. +#include <string.h>
  14. +#include <stdbool.h>
  15. +#include <stdint.h>
  16.  
  17.  const uint8_t negone[] = { 0xFF, 0xFF, 0xFF, 0xFF };
  18.  const char* hex = "0123456789abcdef";
  19. @@ -195,17 +196,39 @@
  20.  
  21.  struct file_data store_file(const char *path)
  22.  {
  23. -   struct file_data result = { 0, calloc(1, sizeof(size_t)) };
  24. -   if (path == NULL) return result;
  25. -   FILE* file = fopen(path, "r");
  26. -   if (file == NULL) return result;
  27. -   if (fseek(file, 0, SEEK_END) != 0) { fclose(file); return result; }
  28. +   struct file_data result = {
  29. +       .length = 0,
  30. +       .bytes = calloc(1, sizeof(size_t))
  31. +   };
  32. +   if (path == NULL){
  33. +       return result;
  34. +   }
  35. +   FILE* file = fopen(path, "rb");
  36. +   if (file == NULL) {
  37. +       fprintf(stderr, "Failed to open file %s for reading\n", path);
  38. +       return result;
  39. +   }
  40. +   if (fseek(file, 0, SEEK_END) != 0) {
  41. +       fclose(file);
  42. +       return result;
  43. +   }
  44.     long filesize = ftell(file);
  45. -   if (filesize == -1 || filesize == 0) { fclose(file); return result; }
  46. +   if (filesize == -1 || filesize == 0) {
  47. +       fclose(file);
  48. +       return result;
  49. +   }
  50.     void *data = calloc(1, (size_t)filesize);
  51. -   if (data == NULL)  { fclose(file); return result; }
  52. +   if (data == NULL) {
  53. +       fclose(file);
  54. +       return result;
  55. +   }
  56.     rewind(file);
  57. -   if (fread(data, (size_t)filesize, 1, file) != 1) { free(data); fclose(file); return result; }
  58. +   if (fread(data, (size_t)filesize, 1, file) != 1) {
  59. +       fprintf(stderr, "Failed to read %lu bytes\n", filesize);
  60. +       free(data);
  61. +       fclose(file);
  62. +       return result;
  63. +   }
  64.     fclose(file);
  65.     result.length = (size_t)filesize;
  66.     result.bytes = data;
  67. @@ -214,10 +237,13 @@
  68.  // returns the number of equivalent bytes, unlike memcmp
  69.  size_t compare_bytes(const void* given1, const void* given2, size_t length)
  70.  {
  71. -   if (given1 == NULL || given2 == NULL || length <= 0) return 0;
  72. -   for (size_t i = 0; i < length; i++)
  73. -   {
  74. -       if (*(uint8_t*)(given1 + i) != *(uint8_t*)(given2 + i)) return i;
  75. +   if (given1 == NULL || given2 == NULL || length <= 0) {
  76. +       return 0;
  77. +   }
  78. +   for (size_t i = 0; i < length; i++) {
  79. +       if (*(uint8_t*)(given1 + i) != *(uint8_t*)(given2 + i)){
  80. +           return i;
  81. +       }
  82.     }
  83.     return length;
  84.  }
  85. @@ -242,7 +268,11 @@
  86.     if (s != NULL && *s != '\0')
  87.     {
  88.         char temp, *end = s + strlen(s);
  89. -       while ( --end > s ) { temp = *s; *s++ = *end; *end=temp; }
  90. +       while ( --end > s ) {
  91. +           temp = *s;
  92. +           *s++ = *end;
  93. +           *end=temp;
  94. +       }
  95.     }
  96.  }
  97.  
  98. @@ -251,14 +281,20 @@
  99.     if (data != NULL && data_length > 1)
  100.     {
  101.         uint8_t temp, *point1 = data, *point2 = data + data_length;
  102. -       while ( --point2 > point1 ) { temp = *point1; *(point1++) = *point2; *point2 = temp; }
  103. +       while ( --point2 > point1 ) {
  104. +           temp = *point1;
  105. +           *(point1++) = *point2;
  106. +           *point2 = temp;
  107. +       }
  108.     }
  109.  }
  110.  // convert static pointer address to HEK program binary offset
  111.  // this lets me interpret all pointers as file data offsets in the file data bytes array, or use pointer math with void* bytes
  112.  uint32_t p2o(const void* given)
  113.  {
  114. -   if (given == NULL) return 0;
  115. +   if (given == NULL){
  116. +       return 0;
  117. +   }
  118.     return *(uint32_t*)given - MEMREGION;
  119.  }
  120.  char* o2string(struct file_data file, uint32_t offset)
  121. @@ -645,7 +681,7 @@
  122.                 for (int i = 0; i < flags.info.count; i++)
  123.                 {
  124.                     indent(levels);
  125. -                   printf("%s\n",o2string(file, p2o(flags.info.names) + (i * sizeof(uint32_t))));
  126. +                   printf("%s\n", o2string(file, p2o(flags.info.names) + (i * sizeof(uint32_t))));
  127.                 }
  128.                
  129.                 levels -= 1;
  130. @@ -1561,15 +1597,21 @@
  131.  // the purpose of this program is to output in C the tag file definitions from within an HEK program.
  132.  int main(int argc, const char * argv[])
  133.  {
  134. -   @autoreleasepool
  135. -   {
  136. -       if (argc < 2) return 0;
  137. +   if (argc < 2){
  138. +       return 0;
  139. +   }
  140.         struct file_data file = store_file(argv[1]);
  141.         //NSFileManager *fm = [NSFileManager new];
  142.         //NSData *filedata = [fm contentsAtPath:[NSString stringWithCString:argv[1] encoding:NSUTF8StringEncoding]];
  143. -       if (file.bytes == NULL) return 1;
  144. +   if (file.bytes == NULL){
  145. +       fprintf(stderr, "Failed to read input file %s\n", argv[1]);
  146. +       return 1;
  147. +   }
  148.         // get all the tag definition file data offsets
  149. -       if (file.length < GUERILLA_DEFS_INDEX + (83 * sizeof(uint32_t))) return 1;
  150. +   if (file.length < GUERILLA_DEFS_INDEX + (83 * sizeof(uint32_t))){
  151. +       fprintf(stderr, "Input file too short (file.length = %lu)\n", file.length);
  152. +       return 1;
  153. +   }
  154.         uint32_t tag_def_offsets[83] = { 0 };
  155.         printf("extracthalotagdefs and its resulting file are by sparky (e-mail:galaxyverge+halo@pm.me discord:sparky#0343 chat:https://discord.gg/mcEzrrv)\ntetelestai\ntag definitions parsed from guerilla.exe\nmodify output to suit your source code syntax needs by modifying extracthalotagdefs\nall credit to Jesus Christ for anything that pleases His Majesty, King of Glory\nnote that these definitions do not fully equate to stored file data...\nrespect me and what I freely did for you by leaving this printf statement intact\n\n");
  156.         for (uint32_t i = 0; i < 83; i++)
  157. @@ -1590,7 +1632,5 @@
  158.             printf("\n");
  159.             release(tagdef);
  160.         }
  161. -      
  162. -   }
  163.      return 0;
  164.  }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top