Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1. void Padding()
  2. {
  3. local int64 padding = FTell() % 16;
  4. if (padding != 0)
  5. FSkip(16 - padding);
  6. };
  7.  
  8. struct FileHeader
  9. {
  10. int entryCount;
  11. int stringSectionOffset;
  12. int stringSectionSize;
  13. int stringCount;
  14. };
  15.  
  16. FileHeader h1;
  17.  
  18. local uint64 entriesOffset = FTell();
  19. FSeek(h1.stringSectionOffset+h1.stringSectionSize);
  20. Padding();
  21.  
  22. struct TagsHeader
  23. {
  24. int sectionSize;
  25. int count;
  26. int offset;
  27. int size;
  28. };
  29.  
  30. local int tagsDataOffset = FTell();
  31. TagsHeader tagsHeader;
  32. tagsDataOffset += tagsHeader.offset;
  33.  
  34. struct TagInfo
  35. {
  36. int tagId;
  37. int nameOffset;
  38.  
  39. local int pos = FTell();
  40. FSeek(tagsDataOffset);
  41.  
  42. string columnName;
  43. tagsDataOffset += Strlen(columnName)+1;
  44. FSeek(pos);
  45.  
  46. };
  47.  
  48. string TagInfo_Name(TagInfo &v)
  49. {
  50. string result;
  51. SPrintf( result, "TAG [%X8] %s", v.tagId, v.columnName );
  52. return result;
  53. }
  54.  
  55. TagInfo columnRefs[tagsHeader.count]<optimize=false,name=TagInfo_Name>;
  56. Padding();
  57. char columnNames[tagsHeader.size];
  58.  
  59. FSeek(entriesOffset);
  60.  
  61. local int gCurrentTag;
  62. local int gCurrentTagIndex;
  63. local string gCurrentTagName;
  64.  
  65. string GetTagName(int tagId)
  66. {
  67. if (gCurrentTag != tagId)
  68. {
  69. local int i;
  70. for (i = gCurrentTagIndex; i < tagsHeader.count; i++)
  71. {
  72. if (columnRefs[i].tagId == tagId)
  73. {
  74. gCurrentTag = tagId;
  75. gCurrentTagName = columnRefs[i].columnName;
  76. gCurrentTagIndex = i;
  77. return gCurrentTagName;
  78. }
  79. }
  80.  
  81. for (i = 0; i < gCurrentTagIndex; i++)
  82. {
  83. if (columnRefs[i].tagId == tagId)
  84. {
  85. gCurrentTag = tagId;
  86. gCurrentTagName = columnRefs[i].columnName;
  87. gCurrentTagIndex = i;
  88. return gCurrentTagName;
  89. }
  90. }
  91.  
  92. Exit(6);
  93. }
  94. return gCurrentTagName;
  95. }
  96.  
  97. struct Entry
  98. {
  99. int tagId;
  100. ubyte fieldCount;
  101.  
  102. if (fieldCount > 0)
  103. {
  104. local int maskSize = (fieldCount+3)/4;
  105. local int paddingSize = 3-maskSize % 4;
  106. ubyte fieldTypes[maskSize];
  107.  
  108. if (paddingSize > 0)
  109. ubyte padding[paddingSize];
  110.  
  111. uint64 fields[fieldCount];
  112. }
  113. else
  114. {
  115. ubyte padding[3];
  116. }
  117. };
  118.  
  119. ubyte GetFieldType(Entry &v, int fieldIndex)
  120. {
  121. local ubyte b = v.fieldTypes[fieldIndex/4];
  122. return (b >> (fieldIndex%4)) & 3;
  123. }
  124.  
  125. string Entry_Name(Entry &v)
  126. {
  127. string result;
  128.  
  129. if (v.fieldCount == 0)
  130. {
  131. SPrintf( result, "[%s] NULL", GetTagName(v.tagId));
  132. return result;
  133. }
  134.  
  135. if (v.fieldCount == 1)
  136. {
  137. ubyte type = GetFieldType(v, 0);
  138. if (type == 0)
  139. {
  140. result = ReadLine(h1.stringSectionOffset + v.fields[0]);
  141. SPrintf( result, "[%s] STR: %s", GetTagName(v.tagId), result );
  142. }
  143. else if (type == 1)
  144. {
  145. SPrintf( result, "[%s] INT: %d", GetTagName(v.tagId), v.fields[0] );
  146. }
  147. else if (type == 2)
  148. {
  149. SPrintf( result, "[%s] FLT: %f", GetTagName(v.tagId), v.fields[0] );
  150. }
  151. else
  152. {
  153. SPrintf( result, "[%s] LNG: %d", GetTagName(v.tagId), v.fields[0] );
  154. }
  155. return result;
  156. }
  157. else
  158. {
  159. SPrintf( result, "[%s] %d: (", GetTagName(v.tagId), v.fieldCount );
  160.  
  161. string tmp;
  162. int i = 0;
  163. ubyte type;
  164. for (i = 0; i < v.fieldCount; i++)
  165. {
  166. if (i > 0)
  167. result += ", ";
  168.  
  169. type = GetFieldType(v, i);
  170. if (type == 0)
  171. {
  172. tmp = ReadLine(h1.stringSectionOffset + v.fields[i]);
  173. result += tmp;
  174. }
  175. else if (type == 1)
  176. {
  177. SPrintf( tmp, "%d", v.fields[i] );
  178. result += tmp;
  179. }
  180. else if (type == 2)
  181. {
  182. SPrintf( tmp, "%f", v.fields[i] );
  183. result += tmp;
  184. }
  185. else
  186. {
  187. SPrintf( tmp, "%d", v.fields[i] );
  188. result += tmp;
  189. }
  190. }
  191. result += ")";
  192. return result;
  193. }
  194.  
  195. SPrintf( result, "[%s] %d", GetTagName(v.tagId), v.fieldCount );
  196. return result;
  197. }
  198.  
  199. Entry lines1[h1.entryCount]<optimize=false,name=Entry_Name>;
  200. Padding();
  201.  
  202. if (h1.stringSectionSize > 0)
  203. {
  204. FSeek(h1.stringSectionOffset);
  205. char content[h1.stringSectionSize];
  206. Padding();
  207. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement