rj
2013-02-06 21:41:39
Figuring no, but just wondering.
2013-02-06 21:41:39
2013-02-06 21:51:27
2013-02-06 22:55:22
2013-02-07 00:26:38
2013-02-07 05:29:33
2013-02-07 06:29:23
From: Ollybest
Currently not no, and in all honestly i really don't see the point in multithreading in runescape really… sure proggys would be nice but you really don't need exact timing of every function.
2013-02-07 19:29:05
2013-02-09 12:03:39
From: DannyRS
It's useless for actual tasks, but for anti-ban and creating human like behaviours, it would be awesome, for example monitoring colors while moving the mouse about or whatever, just isn't very possible in procedural
{$loadlib Threading.dll}
var
ThreadIDs: TIntegerArray;
Procedure FunctionToPass();
begin
writeln("TEST");
end;
begin
SetLength(ThreadIDs, 1); //Amount of threads we want to spawn..
ThreadIDs[0] := ThreadFunction(@FunctionToPass); //This is how you pass function address in lape right?
StopThreadFunction(ThreadIDs[0]);
end.
#ifndef EXPORT_HPP_INCLUDED
#define EXPORT_HPP_INCLUDED
#include <windows.h>
#include <iostream>
#ifdef SIMBA_EXPORTS
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT __declspec(dllimport)
#endif
#ifdef __cplusplus
#define SIMBA_EXTERN extern "C"
#define SIMBA_EXPORT extern "C" DLL_EXPORT
#endif
#define NumberOfExports 2
extern HINSTANCE hInstance;
extern char* Exports[];
SIMBA_EXPORT int GetPluginABIVersion();
SIMBA_EXPORT int GetFunctionCount();
SIMBA_EXPORT int GetFunctionInfo(int Index, void*& Address, char*& Definition);
#endif // EXPORT_HPP_INCLUDED
#ifndef THREADING_HPP_INCLUDED
#define THREADING_HPP_INCLUDED
#include <iostream>
#include <fstream>
#include <thread>
#include <atomic>
#include <system_error>
#include <map>
class Threading
{
private:
std::map<std::uint32_t, std::thread> ThreadPool;
std::map<std::uint32_t, std::atomic<bool>> ThreadIDs;
public:
Threading() {};
template<class Function, class... Args>
std::uint32_t StartThread(Function&& FunctionToPass, Args&&... args);
std::uint32_t StartThread(std::function<void()>& FunctionToPass);
void StopThread(std::uint32_t ThreadID);
};
template<class Function, class... Args>
std::uint32_t Threading::StartThread(Function&& FunctionToPass, Args&&... args)
{
ThreadPool.insert(std::pair<std::uint32_t, std::thread>(ThreadPool.size() + 1, std::thread(FunctionToPass, args...)));
return ThreadPool.size();
}
#endif // THREADING_HPP_INCLUDED
#include "Threading.hpp"
std::uint32_t Threading::StartThread(std::function<void()>& FunctionToPass)
{
ThreadPool.insert(std::pair<std::uint32_t, std::thread>(ThreadPool.size() + 1, std::thread(FunctionToPass)));
return ThreadPool.size();
}
void Threading::StopThread(std::uint32_t ThreadID)
{
try
{
std::map<std::uint32_t, std::atomic<bool>>::iterator TID = this->ThreadIDs.find(ThreadID);
if (TID != this->ThreadIDs.end() && TID->second)
{
std::map<std::uint32_t, std::thread>::iterator it = this->ThreadPool.find(ThreadID);
if (it != this->ThreadPool.end())
{
it->second.detach();
ThreadPool.erase(it);
}
}
else
{
std::map<std::uint32_t, std::thread>::iterator it = this->ThreadPool.find(ThreadID);
if (it != this->ThreadPool.end())
{
it->second.join();
ThreadPool.erase(it);
}
}
}
catch (...){}
}
#include "Export.hpp"
#include "Threading.hpp"
HINSTANCE hInstance = NULL;
Threading ThreadPool;
char* Exports[] = {
(char*)"ThreadFunction", (char*)"Function ThreadFunction(FunctionToPass: Pointer): Integer",
(char*)"StopThreadFunction", (char*)"Procedure StopThreadFunction(ThreadID: Integer);"
};
SIMBA_EXPORT int GetPluginABIVersion()
{
return 2;
}
SIMBA_EXPORT int GetFunctionCount()
{
return NumberOfExports;
}
SIMBA_EXPORT int GetFunctionInfo(int Index, void*& Address, char*& Definition)
{
if (Index < NumberOfExports)
{
Address = (void*)GetProcAddress(hInstance, Exports[Index * 2]);
#ifdef _MSC_VER
#pragma warning(disable: 4996)
strcpy(Definition, Exports[Index * 2 + 1]);
//strcpy_s(Definition, Exports[Index * 2 + 1]);
#else
strcpy(Definition, Exports[Index * 2 + 1]);
#endif
return Index;
}
return -1;
}
SIMBA_EXPORT std::uint32_t ThreadFunction(std::function<void()> &FunctionToPass) //Can just make this take parameter: void (*FunctionToPass)() still works. Even just an address works.
{
return ThreadPool.StartThread(FunctionToPass);
}
SIMBA_EXPORT void StopThreadFunction(std::uint32_t ThreadID)
{
ThreadPool.StopThread(ThreadID);
}
SIMBA_EXPORT BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
{
hInstance = hinstDLL;
std::cout<<"Threading Loaded.."<<std::endl;
return true;
}
break;
case DLL_PROCESS_DETACH:
{
return true;
}
break;
}
return TRUE; // succesful
}
#include <iostream>
#include <windows.h>
#include <functional>
using namespace std;
//typedef void (*Func_Ptr)(void);
//typedef void (*CallFunc)(Func_Ptr);
typedef std::uint32_t (*StartFunc)(std::function<void()>&);
typedef void (*StopFunc)(std::uint32_t);
void LOL(int X, int Y)
{
std::cout<<"Testing DLL Function: X="<<X<<" Y="<<Y<<std::endl;
}
int main()
{
HMODULE L = LoadLibrary("C:/Users/Brandon/Desktop/Thread/bin/Release/Thread.dll");
StartFunc ThreadFunction = (StartFunc)GetProcAddress(L, "ThreadFunction");
StopFunc StopThreadFunction = (StopFunc)(GetProcAddress(L, "StopThreadFunction"));
std::function<void()> FunctionToPass = std::bind(LOL, 1, 2); //Binding some arguments to our Thread Function.. Can bind any amount of arguments.. Can also use funcptr instead of std::function/std::bind.
std::uint32_t ID = ThreadFunction(FunctionToPass);
std::cout<<"\nThread ID: "<< ID <<std::endl;
StopThreadFunction(ID);
FreeLibrary(L);
return 0;
}
2013-02-09 12:12:40
From: Brandon
That brings the question.. Does Lape have function pointers? I thought it does :S
Just a theory though.. I don't see why it shouldn't work.
2013-02-09 12:19:56
From: DannyRS
It's useless for actual tasks, but for anti-ban and creating human like behaviours, it would be awesome, for example monitoring colors while moving the mouse about or whatever, just isn't very possible in procedural
2013-02-09 12:24:26
From: Richard
A really good use would be for dynamic mouse splines. Although it would be possible without multithreading.
Another example: being able to read chat text whilst waiting for an inventory of items to be finished.
It general, it just makes scripts more versatile.
2013-02-09 13:48:11
2013-02-09 13:54:00
2013-02-09 17:51:19
From: rjj95
Looks like all this talk about muilti threading is getting people excited.
2013-02-10 08:02:44
From: Echo_
It's been talked about for years, there's even a tutorial for emulating concurrency using TTimer:
http://villavu.com/forum/showthread.php?t=51578
2013-02-10 22:58:15
From: Richard
Wasn't that awfully glitchey though? And only worked in SCAR?
2013-02-11 04:20:43
From: Richard
Wasn't that awfully glitchey though? And only worked in SCAR?