global_func.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. // global_var.h - [2020-04-13 11:57:47]
  2. #ifndef _GLOBAL_FUNC_H_
  3. #define _GLOBAL_FUNC_H_
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <stdint.h>
  7. #include <math.h>
  8. #include <iostream>
  9. #include <sstream>
  10. #include <string>
  11. #include <vector>
  12. #include <map>
  13. #include <wchar.h>
  14. #include "CFTTMemPool_Resizing.h"
  15. #include "common_type.h"
  16. using namespace std;
  17. extern int lang_47AEA8;
  18. extern bool g_bNeonAvailable;
  19. struct TSprintfParam {
  20. int field_0;
  21. int field_4;
  22. int field_8;
  23. int field_c;
  24. int field_10;
  25. int field_14;
  26. int field_18;
  27. int field_1c;
  28. int field_20;
  29. int field_24;
  30. int field_28;
  31. int field_2c;
  32. int field_30;
  33. int field_34;
  34. int field_38;
  35. int field_3c;
  36. int field_40;
  37. int field_44;
  38. int field_48;
  39. int field_4c;
  40. };
  41. //-------------------------------------------------------------------------------------------------
  42. //自定义了一个组 arm 指令集的宏,用于生成特定arm指令
  43. #define UXTB_00(X) ((uint)X & 0xFF)
  44. #define UXTB_08(X) (((uint)X >> 8) & 0xFF)
  45. #define UXTB_16(X) (((uint)X >> 16) & 0xFF)
  46. #define UXTB_24(X) (((uint)X >> 24) & 0xFF)
  47. #define UXTB16_00(X) ((uint)X & 0xFF00FF)
  48. #define UXTB16_08(X) (((uint)X >> 8) & 0xFF00FF)
  49. #define UXTB16_16(X) (((uint)X >> 16) & 0xFF00FF)
  50. #define UXTB16_24(X) (((uint)X >> 24) & 0xFF00FF)
  51. #define UBFX(Rn, lsb, width) ((Rn >> lsb) & (0xFFFFFFFF >> (32 - width)))
  52. // must uint
  53. #define BFC(Rn, lsb, width) (((Rn >> ((lsb + width) >= 32 ? 31 : (lsb + width))) << ((lsb + width) >= 32 ? 31 : (lsb + width))) | ((Rn << (32 - lsb)) >> (32 - lsb)))
  54. uint bfi(uint rd, uint rn, uint lsb, uint width);
  55. //-------------------------------------------------------------------------------------------------
  56. #define UXTH_00(X) (X & 0xFFFF)
  57. //-------------------------------------------------------------------------------------------------
  58. template <typename T>
  59. uchar GetByte(T s, int pos) {
  60. uchar cret;
  61. uchar* p = reinterpret_cast<uchar*>(&s);
  62. p += pos;
  63. cret = *p;
  64. return cret;
  65. }
  66. //#define BYTE1(x) GetByte<uint>(x, 0)
  67. //#define BYTE2(x) GetByte<uint>(x, 1)
  68. //#define BYTE3(x) GetByte<uint>(x, 2)
  69. //#define BYTE4(x) GetByte<uint>(x, 3)
  70. //#define BYTE5(x) GetByte<uint64>(x, 4)
  71. //#define BYTE6(x) GetByte<uint64>(x, 5)
  72. //#define BYTE7(x) GetByte<uint64>(x, 6)
  73. //#define BYTE8(x) GetByte<uint64>(x, 7)
  74. #define BYTEn(x, n) (*((uchar*)&(x) + n))
  75. #define BYTE0(x) BYTEn(x, 0)
  76. #define BYTE1(x) BYTEn(x, 1)
  77. #define BYTE2(x) BYTEn(x, 2)
  78. #define BYTE3(x) BYTEn(x, 3)
  79. #define BYTE4(x) BYTEn(x, 4)
  80. #define BYTE5(x) BYTEn(x, 5)
  81. #define BYTE6(x) BYTEn(x, 6)
  82. #define BYTE7(x) BYTEn(x, 7)
  83. #define BYTE8(x) BYTEn(x, 8)
  84. #define BYTE9(x) BYTEn(x, 9)
  85. #define BYTE10(x) BYTEn(x, 10)
  86. #define BYTE11(x) BYTEn(x, 11)
  87. #define BYTE12(x) BYTEn(x, 12)
  88. #define BYTE13(x) BYTEn(x, 13)
  89. #define BYTE14(x) BYTEn(x, 14)
  90. #define BYTE15(x) BYTEn(x, 15)
  91. #define __PAIR64__(high, low) (((uint64)(high) << 32) | (uint32)(low))
  92. float int64_to_float_2A42A0(int64);
  93. //-------------------------------------------------------------------------------------------------
  94. // 00265868
  95. uint32 FTTHash(char const* pdata);
  96. // 002659F0
  97. uint32 FTTHash(void const* pdata, int len);
  98. //-------------------------------------------------------------------------------------------------
  99. int32_t int64_2_int32(int64_t d);
  100. int64_t int32_2_int64(int32_t d);
  101. //-------------------------------------------------------------------------------------------------
  102. // 002635AC
  103. void FTTEncode(int* result, int len, uint a3);
  104. // 002635C4
  105. void FTTDecode(void* pdata, int dlen, uint dkey);
  106. //-------------------------------------------------------------------------------------------------
  107. std::string hexstring(uchar* p, int dlen);
  108. std::string hexstring_line(const uint8_t* buffer, size_t size);
  109. //-------------------------------------------------------------------------------------------------
  110. struct TPoint {
  111. int dx_0;
  112. int dy_4;
  113. TPoint(){
  114. // dx_0 = 0;
  115. // dy_4 = 0;
  116. };
  117. void copy(TPoint p){
  118. dx_0=p.dx_0;
  119. dy_4=p.dy_4;
  120. }
  121. TPoint(int i0, int i1) {
  122. dx_0 = i0;
  123. dy_4 = i1;
  124. };
  125. TPoint(TPoint* point) {
  126. if ((void*)point != (void*)this) {
  127. this->dx_0 = point->dx_0;
  128. this->dy_4 = point->dy_4;
  129. }
  130. };
  131. TPoint* operator=(const TPoint* point) {
  132. if ((void*)this != (void*)point) {
  133. this->dx_0 = point->dx_0;
  134. this->dy_4 = point->dy_4;
  135. }
  136. return this;
  137. };
  138. // TPoint& operator=(const TPoint& other) {
  139. // if (this != &other) {
  140. // this->dx_0 = other.dx_0;
  141. // this->dy_4 = other.dy_4;
  142. // }
  143. // return *this;
  144. // };
  145. bool operator!=(const TPoint& other) {
  146. if ((this->dx_0 == other.dx_0) && (this->dy_4 == other.dy_4))
  147. return true;
  148. else
  149. return false;
  150. };
  151. bool operator==(const TPoint& other) {
  152. if ((this->dx_0 == other.dx_0) && (this->dy_4 == other.dy_4))
  153. return true;
  154. else
  155. return false;
  156. };
  157. };
  158. extern TPoint g_vZero;
  159. //-------------------------------------------------------------------------------------------------
  160. // 001F5630
  161. float atof_1F5630(const char* a1);
  162. //-------------------------------------------------------------------------------------------------
  163. TPoint StrToPos(const char* pTxt);
  164. //-------------------------------------------------------------------------------------------------
  165. struct TPointF {
  166. float fx_0;
  167. float fy_4;
  168. TPointF() {
  169. }
  170. TPointF(float fX, float fY) {
  171. fx_0 = fX;
  172. fy_4 = fY;
  173. }
  174. TPointF& operator=(const TPointF& other) {
  175. this->fx_0 = other.fx_0;
  176. this->fy_4 = other.fy_4;
  177. return *this;
  178. };
  179. };
  180. TPointF StrToPosF(char const* p_c_r1_arg); // 001F5A68
  181. //-------------------------------------------------------------------------------------------------
  182. struct TPointF3D {
  183. float fx_0;
  184. float fy_4;
  185. float fz_8;
  186. TPointF3D& operator=(const TPointF3D& other) {
  187. this->fx_0 = other.fx_0;
  188. this->fy_4 = other.fy_4;
  189. this->fz_8 = other.fz_8;
  190. return *this;
  191. }
  192. };
  193. TPointF3D StrToPosF3D(const char* pTxt);
  194. //-------------------------------------------------------------------------------------------------
  195. struct TPoint3D {
  196. TPoint point_0;
  197. int dz_8;
  198. TPoint3D(){
  199. // point_0.dx_0 = 0;
  200. // point_0.dy_4 = 0;
  201. // dz_8 = 0;
  202. };
  203. TPoint3D(int i0, int i1, int i2) {
  204. point_0.dx_0 = i0;
  205. point_0.dy_4 = i1;
  206. dz_8 = i2;
  207. };
  208. TPoint3D(TPoint& point) {
  209. point_0 = point;
  210. };
  211. TPoint3D(TPoint3D* point) {
  212. *this = *point;
  213. };
  214. TPoint3D& operator=(const TPoint3D& other) {
  215. point_0.dx_0 = other.point_0.dx_0;
  216. point_0.dy_4 = other.point_0.dy_4;
  217. dz_8 = other.dz_8;
  218. // memcpy(this, &other, sizeof(TPoint3D));
  219. return *this;
  220. };
  221. TPoint3D* operator+=(const TPoint3D& other) {
  222. point_0.dx_0 += other.point_0.dx_0;
  223. point_0.dy_4 += other.point_0.dy_4;
  224. this->dz_8 += other.dz_8;
  225. return this;
  226. };
  227. TPoint3D* operator-(const TPoint3D& other) {
  228. point_0.dx_0 -= other.point_0.dx_0;
  229. point_0.dy_4 -= other.point_0.dy_4;
  230. this->dz_8 -= other.dz_8;
  231. return this;
  232. };
  233. TPoint3D* operator+(const TPoint3D& other) {
  234. point_0.dx_0 += other.point_0.dx_0;
  235. point_0.dy_4 += other.point_0.dy_4;
  236. this->dz_8 += other.dz_8;
  237. return this;
  238. };
  239. TPoint3D operator*(float f2) {
  240. int iX = point_0.dx_0 * f2;
  241. int iY = point_0.dy_4 * f2;
  242. int iZ = dz_8 * f2;
  243. TPoint3D tp;
  244. tp.point_0.dx_0 = iX;
  245. tp.point_0.dy_4 = iY;
  246. tp.dz_8 = iZ;
  247. return tp;
  248. }
  249. };
  250. TPoint3D StrToPos3D(const char* pTxt);
  251. extern TPointF3D g_vZeroF3;
  252. //-------------------------------------------------------------------------------------------------
  253. struct TPoint4D {
  254. int dx_0;
  255. int dy_4;
  256. int dz_8;
  257. int di_C;
  258. TPoint4D& operator=(const TPoint4D& other) {
  259. this->dx_0 = other.dx_0;
  260. this->dy_4 = other.dy_4;
  261. this->dz_8 = other.dz_8;
  262. this->di_C = other.di_C;
  263. return *this;
  264. };
  265. };
  266. //-------------------------------------------------------------------------------------------------
  267. // 001F5CA8
  268. void StrToPos4D(char const* p_c_r0, int* p_d_r1);
  269. //-------------------------------------------------------------------------------------------------
  270. uint StrHexToInt(const char* pTxt);
  271. //-------------------------------------------------------------------------------------------------
  272. // uint StrToEaser(char const* p_c_r0); //0014BAC8
  273. //返回值不确定,int or uint
  274. // uint StrToCol(char const* p_c_r0_arg); //001F5DD0
  275. extern const TPoint3D g_vZero3;
  276. bool PASS_FW_SPIN(int val1);
  277. bool FTTLicence_IsData();
  278. extern uint32 algn_47BC88[2];
  279. extern uint32 dword_47BC90;
  280. extern uint32 dword_47BBB0[54];
  281. int sync_log(int prio, const char* tag, const char* fmt, ...);
  282. int sync_log_file(int prio, const char* tag, const char* fmt, ...);
  283. // 001BCD30
  284. float Log2(float f_r0);
  285. bool NIS_Active();
  286. string hash_buf(uint8_t* const pBuf, int dlen);
  287. #endif //_GLOBAL_FUNC_H_