utils.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #ifndef _UTILS_H_
  4. #define _UTILS_H_
  5. #include "../common/cbasetypes.h"
  6. #include <stdio.h> // FILE*
  7. // generate a hex dump of the first 'length' bytes of 'buffer'
  8. void WriteDump(FILE* fp, const void* buffer, size_t length);
  9. void ShowDump(const void* buffer, size_t length);
  10. void findfile(const char *p, const char *pat, void (func)(const char*));
  11. bool exists(const char* filename);
  12. //Caps values to min/max
  13. #define cap_value(a, min, max) ((a >= max) ? max : (a <= min) ? min : a)
  14. /// calculates the value of A / B, in percent (rounded down)
  15. unsigned int get_percentage(const unsigned int A, const unsigned int B);
  16. //////////////////////////////////////////////////////////////////////////
  17. // byte word dword access [Shinomori]
  18. //////////////////////////////////////////////////////////////////////////
  19. extern uint8 GetByte(uint32 val, int idx);
  20. extern uint16 GetWord(uint32 val, int idx);
  21. extern uint16 MakeWord(uint8 byte0, uint8 byte1);
  22. extern uint32 MakeDWord(uint16 word0, uint16 word1);
  23. int date2version(int date);
  24. #endif /* _UTILS_H_ */