Advertisement
Guest User

Untitled

a guest
Nov 17th, 2020
669
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.03 KB | None | 0 0
  1. #include <windows.h>
  2. #include <string>
  3. #include <assert.h>
  4. #include <process.h>
  5. #include <ctime>
  6.  
  7. #include "SAMPFUNCS_API.h"
  8. #include "game_api\game_api.h"
  9.  
  10. SAMPFUNCS *SF = new SAMPFUNCS();
  11. stFontInfo* pFont;
  12.  
  13. unsigned int simplex_seed = 0xCAA938DB;
  14.  
  15. long long int nrandom(long long int max)
  16. {
  17.     int min = 0;
  18.     unsigned int INITIAL_SEED = 0xCAA938DB;
  19.     long long int IL_RMULT = (1103515245);
  20.     if (min > max)
  21.         min ^= max, max ^= min, min ^= max;
  22.  
  23.     if (simplex_seed == INITIAL_SEED)
  24.     {
  25.         simplex_seed = time(0);
  26.     }
  27.  
  28.     long long int lo, hi, ll, lh, hh, hl;
  29.     long long int result;
  30.  
  31.     lo = simplex_seed & 0xffff;
  32.     hi = simplex_seed >> 16;
  33.     ll = lo * (IL_RMULT & 0xffff);
  34.     lh = lo * (IL_RMULT >> 16);
  35.     hl = hi * (IL_RMULT & 0xffff);
  36.     hh = hi * (IL_RMULT >> 16);
  37.  
  38.     result = ((ll + 12345) >> 16) + lh + hl + (hh << 16);
  39.     result &= ~(-2147483647);
  40.  
  41.     if (max != 0)
  42.         result %= (max - min);
  43.  
  44.     return result + min;
  45. }
  46.  
  47. void srandom(unsigned int seed)
  48. {
  49.     simplex_seed = seed;
  50. }
  51.  
  52. int core_random(long long int max, int min = 0)
  53. {
  54.     int result = nrandom(max);
  55.  
  56.     simplex_seed = simplex_seed * 1103515245 + 12345;
  57.  
  58.     return result;
  59. }
  60.  
  61. void CALLBACK cmd_rnd(std::string param)
  62. {
  63.     char buf[128];
  64.  
  65.     sprintf(buf, "script random: %d", core_random(10) + 2);
  66.  
  67.     SF->getSAMP()->getChat()->AddChatMessage(-1, buf);
  68. };
  69.  
  70. void CALLBACK mainloop()
  71. {
  72.     static bool init = false;
  73.     if (!init)
  74.     {
  75.         if (GAME == nullptr)
  76.             return;
  77.         if (GAME->GetSystemState() != eSystemState::GS_PLAYING_GAME)
  78.             return;
  79.         if (!SF->getSAMP()->IsInitialized())
  80.             return;
  81.         SF->getSAMP()->getChat()->AddChatMessage( D3DCOLOR_XRGB( 0, 0xAA, 0 ), "mac test" );
  82.  
  83.         SF->getSAMP()->registerChatCommand("random1", cmd_rnd);
  84.  
  85.         init = true;
  86.     }
  87. }
  88.  
  89. BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReasonForCall, LPVOID lpReserved)
  90. {
  91.     switch (dwReasonForCall)
  92.     {
  93.         case DLL_PROCESS_ATTACH:
  94.             SF->initPlugin(mainloop, hModule);
  95.             break;
  96.         case DLL_THREAD_ATTACH:
  97.         case DLL_THREAD_DETACH:
  98.         case DLL_PROCESS_DETACH:
  99.             break;
  100.     }
  101.     return TRUE;
  102. }
  103.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement