Advertisement
cloverleafswag3

Threading.cpp

Jul 1st, 2015
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.65 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "Threading.h"
  3.  
  4. DataPool<GtaThread> *GtaThreads = (DataPool<GtaThread> *)0x83DDD518;
  5.  
  6. ScriptHookThread::ScriptHookThread(PVOID StartAddress, PBOOL Result) {
  7.     if(GtaThreads->Data != NULL) {
  8.         this->StartAddress = StartAddress;
  9.         this->ThreadIndex = GtaThreads->Count;
  10.         this->Context.ThreadID = 1;
  11.         GtaThreads->Data[GtaThreads->Count] = this;
  12.         GtaThreads->Count++;
  13.         *Result = TRUE;
  14.         return;
  15.     }
  16.     *Result = FALSE;
  17. }
  18.  
  19. ScriptHookThread::~ScriptHookThread() {
  20.     this->Kill();
  21. }
  22.  
  23. void ScriptHookThread::Reset(int ProgramID, void *Args, int ArgCount) {
  24.     // this is not close to done
  25.  
  26.     if(ProgramID != NULL) {
  27.         this->Context.ProgramID = ProgramID;
  28.     }
  29.  
  30.     /*this->Context.0x10 = NULL;
  31.     if(this->Context.ProgramID == NULL) {
  32.         this->KillMessage = "Reset: Invalid program id";
  33.     }*/
  34.  
  35.     /*if(ArgCount != NULL && this->Context.0x14 << 2 != ArgCount) {
  36.         // doesnt just work like that but what ever
  37.         CHAR Buffer[256];
  38.         sprintf(Buffer, "Reset: Arg size mismatch, calling code has %u but script expects %u", this->Context.0x14 << 2, ArgCount);
  39.         this->KillMessage = Buffer;
  40.     }*/
  41.  
  42.     /*this->Context.ThreadState = scrThreadStateIdle;
  43.     if(this->Context.AllocatedStackSize >= this->Context.0x18) {
  44.         // doesnt just work like that but what ever
  45.         CHAR Buffer[256];
  46.         sprintf(Buffer, "Reset: Too many static variables for program %s\n", this->Context.AllocatedStackSize); // i think this is a mistake on the R* developers side lol
  47.         this->KillMessage = Buffer;
  48.     }*/
  49.  
  50.  
  51.     this->Context.TimerA = NULL;
  52.     this->Context.TimerB = NULL;
  53.     //this->Context.0x44 = NULL;
  54.  
  55.     /*if(this->ThreadName[0] != NULL) {
  56.         this->0xB0 = JOAT(this->ThreadName);
  57.     } else {
  58.         this->0xB0 = NULL;
  59.     }*/
  60. }
  61.  
  62. scrThreadState ScriptHookThread::Run(int OpsToExecute) {
  63.     if(this->Context.ThreadState != scrThreadStateKilled || this->Context.ThreadState != scrThreadState3) {
  64.         register int a = (int)GtaThreads->Data[0]; // someday i will have my own stuff
  65.         __asm
  66.         {
  67.             lwz r30, 0(r13)
  68.             li r29, 0x134
  69.             li r28, 0x138
  70.             stwx a, r30, r29
  71.             li r11, 1
  72.             stbx r11, r30, r28
  73.         }
  74.         ((void(*)())this->StartAddress)();
  75.         return scrThreadStateRunning;
  76.     }
  77.     return this->Context.ThreadState;
  78. }
  79.  
  80. scrThreadState ScriptHookThread::Tick(int OpsToExecute) {
  81.     this->Context.TimerA += 66;
  82.     this->Context.TimerB += 66;
  83.     return Run(OpsToExecute);
  84. }
  85.  
  86. void ScriptHookThread::Kill() {
  87.     this->Context.ThreadState = scrThreadStateKilled;
  88.     this->KillMessage = "via scrThread::Kill on myself";
  89.    
  90.     // someday ill reverse the rest, we really only need to set ThreadID to null
  91.  
  92.     this->Context.ThreadID = NULL;
  93.     this->Context.AllocatedStackSize = NULL;
  94.     this->Stack = NULL;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement