Clone of PhatAC @ https://github.com/floaterxk/PhatAC

Util.h 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #pragma once
  2. ///////////////////////////////////////
  3. //
  4. //UTIL.H - PhatAC - 02/28/2004
  5. //
  6. //A collection of random helper functions.
  7. //
  8. ///////////////////////////////////////
  9. #include <math.h>
  10. #include "BinaryWriter.h"
  11. #include "BinaryReader.h"
  12. class CClient;
  13. struct BlockData;
  14. bool LoadDataFromFile(const char *filepath, BYTE **data, DWORD *length);
  15. extern void MsgBox(const char* format, ...);
  16. extern void MsgBox(UINT iType, const char* format, ...);
  17. extern void MsgBoxError(DWORD dwError, const char* event);
  18. extern void UpdateFramesHUD(UINT64 frames);
  19. extern void UpdateClientsHUD(CClient **clients, WORD slotrange);
  20. #define cs(x) csprintf(x)
  21. extern char* csprintf(const char* format, ...); //static buffer
  22. extern char* timestamp(); //static buffer
  23. extern void strtrim(char *szText); //specified buffer
  24. extern BOOL strmask(const char* szTest, const char* szMask);
  25. extern long fsize(FILE* fp); //returns a FILE* size
  26. unsigned long ResolveIPFromHost(const char *host);
  27. unsigned long GetLocalIP();
  28. std::string GetLocalIPString();
  29. extern std::string DebugBytesToString(void *data, unsigned int len);
  30. extern void _OutputConsole(const char* format, ...);
  31. #define _DebugMe() LOG(Temp, Normal, "Debug me: %s %u\n", __FUNCTION__, __LINE__);
  32. extern BOOL SaveConfigKey(const char* Key, DWORD value);
  33. extern BOOL SaveConfigKey(const char* Key, const char* value);
  34. extern BOOL ReadConfigKey(const char* Key, DWORD* value);
  35. extern BOOL ReadConfigKey(const char* Key, char* value, DWORD size);
  36. extern bool FileExists(const char *filePath);
  37. extern float NorthSouth(char *szCoord);
  38. extern float EastWest(char *szCoord);
  39. extern loc_t GetLocation(double NS, double EW);
  40. extern BOOL IsWaterBlock(BlockData*);
  41. extern BOOL IsWaterBlock(DWORD dwCell);
  42. extern BOOL HasObjectBlock(BlockData*);
  43. extern BOOL HasObjectBlock(DWORD dwCell);
  44. extern float CalcSurfaceZ(DWORD dwCell, float xOffset, float yOffset);
  45. extern float CalcSurfaceZ2(DWORD dwCell, float xOffset, float yOffset);
  46. // Because the land system sucks.
  47. #define BLOCK_WORD(x) ((WORD)((x & 0xFFFF0000) >> 16))
  48. #define BLOCK_X(x) ((BYTE)((x >> 8) & 0xFF))
  49. #define BLOCK_Y(x) ((BYTE)((x >> 0) & 0xFF))
  50. #define CELL_WORD(x) ((WORD)((x & 0xFFFF)-1))
  51. #define CELL_X(x) ((BYTE)((x >> 3) & 7))
  52. #define CELL_Y(x) ((BYTE)((x >> 0) & 7))
  53. // Used for mapping out the above data to offsets from (0, 0).
  54. #define BASE_OFFSET(X, x) (((DWORD)X << 3) | x)
  55. #define BLOCK_OFFSET(x) ((WORD)((DWORD)x >> 3))
  56. // Potential view cell-range.
  57. #define PVC_RANGE 16
  58. // Land boundaries.
  59. const DWORD dwMinimumCellX = 0x0;
  60. const DWORD dwMinimumCellY = 0x0;
  61. const DWORD dwMaximumCellX = (0x800 - 1);
  62. const DWORD dwMaximumCellY = (0x800 - 1);