Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "Threading.h"
- DataPool<GtaThread> *GtaThreads = (DataPool<GtaThread> *)0x83DDD518;
- ScriptHookThread::ScriptHookThread(PVOID StartAddress, PBOOL Result) {
- if(GtaThreads->Data != NULL) {
- this->StartAddress = StartAddress;
- this->ThreadIndex = GtaThreads->Count;
- this->Context.ThreadID = 1;
- GtaThreads->Data[GtaThreads->Count] = this;
- GtaThreads->Count++;
- *Result = TRUE;
- return;
- }
- *Result = FALSE;
- }
- ScriptHookThread::~ScriptHookThread() {
- this->Kill();
- }
- void ScriptHookThread::Reset(int ProgramID, void *Args, int ArgCount) {
- // this is not close to done
- if(ProgramID != NULL) {
- this->Context.ProgramID = ProgramID;
- }
- /*this->Context.0x10 = NULL;
- if(this->Context.ProgramID == NULL) {
- this->KillMessage = "Reset: Invalid program id";
- }*/
- /*if(ArgCount != NULL && this->Context.0x14 << 2 != ArgCount) {
- // doesnt just work like that but what ever
- CHAR Buffer[256];
- sprintf(Buffer, "Reset: Arg size mismatch, calling code has %u but script expects %u", this->Context.0x14 << 2, ArgCount);
- this->KillMessage = Buffer;
- }*/
- /*this->Context.ThreadState = scrThreadStateIdle;
- if(this->Context.AllocatedStackSize >= this->Context.0x18) {
- // doesnt just work like that but what ever
- CHAR Buffer[256];
- 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
- this->KillMessage = Buffer;
- }*/
- this->Context.TimerA = NULL;
- this->Context.TimerB = NULL;
- //this->Context.0x44 = NULL;
- /*if(this->ThreadName[0] != NULL) {
- this->0xB0 = JOAT(this->ThreadName);
- } else {
- this->0xB0 = NULL;
- }*/
- }
- scrThreadState ScriptHookThread::Run(int OpsToExecute) {
- if(this->Context.ThreadState != scrThreadStateKilled || this->Context.ThreadState != scrThreadState3) {
- register int a = (int)GtaThreads->Data[0]; // someday i will have my own stuff
- __asm
- {
- lwz r30, 0(r13)
- li r29, 0x134
- li r28, 0x138
- stwx a, r30, r29
- li r11, 1
- stbx r11, r30, r28
- }
- ((void(*)())this->StartAddress)();
- return scrThreadStateRunning;
- }
- return this->Context.ThreadState;
- }
- scrThreadState ScriptHookThread::Tick(int OpsToExecute) {
- this->Context.TimerA += 66;
- this->Context.TimerB += 66;
- return Run(OpsToExecute);
- }
- void ScriptHookThread::Kill() {
- this->Context.ThreadState = scrThreadStateKilled;
- this->KillMessage = "via scrThread::Kill on myself";
- // someday ill reverse the rest, we really only need to set ThreadID to null
- this->Context.ThreadID = NULL;
- this->Context.AllocatedStackSize = NULL;
- this->Stack = NULL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement