Advertisement
cloverleafswag3

Threading.h

Jul 1st, 2015
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.66 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include "stdafx.h"
  4.  
  5. enum scrThreadState : unsigned int {
  6.     scrThreadStateIdle,
  7.     scrThreadStateRunning,
  8.     scrThreadStateKilled,
  9.     scrThreadState3, // dont know but it wont execute if this is the case (scrThread::Run)
  10. };
  11.  
  12. struct scrThreadContext {
  13.     unsigned int ThreadID; // 0x04
  14.     unsigned int ProgramID; // 0x08 (*.xsc + 0x38)
  15.     scrThreadState ThreadState; // 0x0C
  16.     char _0x10[0x0C];
  17.     unsigned int TimerA; // 0x1C
  18.     unsigned int TimerB; // 0x20
  19.     float WaitTime; // 0x24
  20.     char _0x28[0x1C];
  21.     unsigned int AllocatedStackSize; // 0x40
  22.     char _0x44[0x0C];
  23. }; // size 0x50
  24.  
  25. class scrThread {
  26. public:
  27.     virtual void scrThread_ctr() {};
  28.     virtual void Reset(int ProgramID, void *Args, int ArgCount) = 0;
  29.     virtual scrThreadState Run(int OpsToExecute) = 0;
  30.     virtual scrThreadState Tick(int OpsToExecute) = 0;
  31.     virtual void Kill() = 0;
  32.  
  33.     scrThreadContext Context; // 0x04
  34.     void *Stack; // 0x54
  35.     char _0x58[0x0C];
  36.     char *KillMessage; // 0x64
  37. }; // size 0x68
  38.  
  39. class GtaThread : public scrThread {
  40. public:
  41.     char ThreadName[24]; // 0x68
  42.     char _0x80[0x0C];
  43.     int NumberOfEvents; // 0x8C - not sure
  44.     char _0x90[0x47];
  45.     // char MissionFlag; // 0xD0
  46.     char CanBePaused; // 0xD7
  47.     char CanRemoveBlipsCreatedByAnyScript; // 0xD8
  48. }; // size unknown
  49.  
  50. class ScriptHookThread : public GtaThread {
  51. protected:
  52.     void Reset(int ProgramID, void *Args, int ArgCount);
  53.     scrThreadState Run(int OpsToExecute);
  54.     scrThreadState Tick(int OpsToExecute);
  55.     void Kill();
  56. private:
  57.     WORD ThreadIndex;
  58.     PVOID StartAddress;
  59. public:
  60.     BOOL ScriptInitializedCalled;
  61.     ScriptHookThread(PVOID lpStartAddress, PBOOL Result);
  62.     ~ScriptHookThread();
  63. };
  64.  
  65. // GtaThread scrThread
  66. // TickThreads() -> GtaThread::Tick() -> scrThread::Tick() -> scrThread::Run()
  67.  
  68. // 0x83B435C4 opsToExecute
  69. // 0x83DCD1E8 currentScriptName
  70. // 0x83DCD600 globals
  71.  
  72. /*
  73.  
  74. bool TickThreads(unsigned int opsToExecute)
  75. {
  76.     if(opsToExecute == 0) {
  77.         opsToExecute = 1000000;
  78.     }
  79.  
  80.     bool r = false;
  81.  
  82.     // just enumerates the thread pool then executes the GtaThread::Tick for each thread.
  83.  
  84.     for(int i = 0; i < ThreadPool->Count; i++) {
  85.         GtaThread *Thread = ThreadPool->Threads[i];
  86.         if(Thread->Context.ThreadID != NULL) {
  87.             Thread::Tick();
  88.         }
  89.     }
  90.  
  91.     return r;
  92. }
  93.  
  94. If we look at the native TIMERA
  95.  
  96. lwz       r11, 0(r13)   # Load Word and Zero
  97. li        r10, 0x134    # Load Immediate
  98. lwz       r9, 0(r3)     # Load Word and Zero
  99. lwzx      r8, r10, r11  # Load Word and Zero Indexed
  100. lwz       r7, 0x1C(r8)  # Load Word and Zero
  101. stw       r7, 0(r9)     # Store Word
  102. blr
  103.  
  104. makes sense now
  105. in scrThread::Run the r13 is packed with the GtaThread parameter
  106.  
  107. TlsValue(0); // ??
  108.  
  109. tls_index_0 + 0x134 = GtaThread
  110.  
  111. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement