|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
DaSpamer Grandmaster Cheater Supreme Reputation: 52
Joined: 13 Sep 2011 Posts: 1578
|
Posted: Mon Jul 28, 2014 9:14 am Post subject: Reusing a thread? |
|
|
Hey dark byte,
Is there any method to use a thread?
After running a test:
3.5 seconds update, each update made in a thread (new thread in our case).
After about 20 hours of running it, I'm starting to get this error
Code: | Error:Thread creation error: Not enough storage is available to process this command. |
_________________
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 457
Joined: 09 May 2003 Posts: 25262 Location: The netherlands
|
Posted: Tue Jul 29, 2014 3:17 am Post subject: |
|
|
No idea, if you free the thread properly (and all the objects you create inside it) it shouldn't cause a problem.
What you could do is create a thread that handles a message loop constantly until it receives a message that it should kill itself
e.g:
Code: |
pipename="something"
commandhandler={}
commandhandler[0]=function(state) print("Command 0 is being handled") end
commandhandler[1]=function(state) print("This is command 1") end
commandhandler[2]=function(state) print("Executing command 2 which got as extra parameter "..state.pipe.readDword()) end
commandhandler[3]=function(state) print("This is command 3, which is to tell the thread to go kill itself") state.running=false end
function handler(t)
local pipe=connectToPipe(pipename)
local state={}
state.running=true;
state.thread=t
state.pipe=pipe
while (pipe.Connected and state.running) do
print("Thread: Waiting for command");
local command=pipe.readByte()
if (command==nil) then
print("Thread: readByte failed\n")
break;
end
print(string.format("Thread: Received command %d", command))
if (commandhandler[command]~=nil) then
commandhandler[command](state)
else
print("Thread: Unknown command received. Aborting");
break
end
end
print("Thread: Thread exiting")
pipe.destroy()
end
com=createPipe(pipename)
createNativeThread(handler)
com.acceptConnection()
com.writeByte(0)
com.writeByte(1)
com.writeByte(2) com.writeDword(1234567)
com.writeByte(3)
|
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
|
DaSpamer Grandmaster Cheater Supreme Reputation: 52
Joined: 13 Sep 2011 Posts: 1578
|
Posted: Thu Aug 14, 2014 10:58 pm Post subject: |
|
|
A script that usages the pipe class and color gradient, colorful GUI .
Code: | function rgb2hex(tab)
if (tab and (type(tab) == 'table')) then
if (type(tab) == 'table' and #tab == 3) then
local red,green,blue = string.format('%x', tab[1]) , string.format('%x', tab[2]) , string.format('%x', tab[3])
return '0x' .. (#red < 2 and '0' or '') .. red .. (#green < 2 and '0' or '') .. green .. (#blue < 2 and '0' or '') .. blue
end
end
end
function hex2rgb(tab)
if (tab and (type(tab) == 'string')) then
if (#tab == 6 and tonumber('0x' .. tab)) then
local rgb = {};
for i=1,6,2 do
rgb[#rgb+1] = tonumber('0x' .. tab:sub(i,i+1))
end
return rgb
end
end
end
UDF1 = createForm();
function transistToRgb()
local function RandomBGRHex()
local b,g,r = string.format('%x', math.floor(math.random() * 255)),string.format('%x', math.floor(math.random() * 255)),string.format('%x', math.floor(math.random() * 255))
if (#b == 1) then
b = '0' .. b
end
if (#g == 1) then
g = '0' .. g
end
if (#r == 1) then
r = '0' .. r
end
return b..g..r
end
local start_color = RandomBGRHex()
local end_color = RandomBGRHex()
local fps = 60;
local timer_update = 16;
timer_object = createTimer(nil,true);
timer_object.Interval = timer_update;
local function getNextColor(current_color, next_color)
if ( (not current_color) or (not next_color)) then
return
end
if (type(current_color) == 'string' and #current_color == 6) then
current_color = hex2rgb(current_color)
elseif (not (type(current_color == 'table' and #current_color == 3))) then
return
end
if (type(next_color) == 'string' and #next_color == 6) then
next_color = hex2rgb(next_color)
elseif (not (type(next_color == 'table' and #next_color == 3))) then
return
end
return {math.abs(current_color[1] - next_color[1]), math.abs(current_color[2] - next_color[2]), math.abs(current_color[3] - next_color[3])};
end
local function calculateIncrement(distance)
if (not distance) then
return
end
if (type(distance) == 'string' and distance) then
distance = hex2rgb(distance)
elseif (not (type(distance == 'table' and #distance == 3))) then
return
end
local data = {math.abs(math.floor(distance[1] / fps)), math.abs(math.floor(distance[2] / fps)), math.abs(math.floor(distance[3] / fps))}
for i = 1,3 do
data[i] = (data[i] == 0 and 1 or nil) or data[i]
end
return data;
end
local distance_color = getNextColor(start_color, end_color)
local increment = calculateIncrement(distance_color);
local current_clr_table = hex2rgb(start_color)
local max_clr_table = hex2rgb(end_color)
local com
commandhandler={}
commandhandler[0] = function(state)
if (current_clr_table[1] > max_clr_table[1]) then
current_clr_table[1] = current_clr_table[1] - increment[1]
if (current_clr_table[1] <= max_clr_table[1]) then
increment[1] = 0
end
else
current_clr_table[1] = current_clr_table[1] + increment[1]
if (current_clr_table[1] >= max_clr_table[1]) then
increment[1] = 0
end
end
if (current_clr_table[2] > max_clr_table[2]) then
current_clr_table[2] = current_clr_table[2] - increment[2]
if (current_clr_table[2] <= max_clr_table[2]) then
increment[2] = 0
end
else
current_clr_table[2] = current_clr_table[2] + increment[2]
if (current_clr_table[2] >= max_clr_table[2]) then
increment[2] = 0
end
end
if (current_clr_table[3] > max_clr_table[3]) then
current_clr_table[3] = current_clr_table[3] - increment[3]
if (current_clr_table[3] <= max_clr_table[3]) then
increment[3] = 0
end
else
current_clr_table[3] = current_clr_table[3] + increment[3]
if (current_clr_table[3] >= max_clr_table[3]) then
increment[3] = 0
end
end
if (state.thread) then
thread_synchronize(state.thread, function () UDF1.Color = tonumber(rgb2hex(current_clr_table)); end)
end
if (increment[3] == 0 and increment[2] == 0 and increment[1] == 0) then
start_color = end_color
end_color = RandomBGRHex()
distance_color = getNextColor(start_color, end_color)
increment = calculateIncrement(distance_color);
current_clr_table = hex2rgb(start_color)
max_clr_table = hex2rgb(end_color)
-- timer_object.Enabled = false;
-- com.writeByte(1);
end
end
commandhandler[1] = function(state) state.running = false end
local pipename = UDF1.Caption
function handler(t)
local pipe = connectToPipe(pipename)
local state={}
state.running=true;
state.thread=t
state.pipe=pipe
while (pipe.Connected and state.running) do
local command = pipe.readByte()
if (command==nil) then
break;
end
if (commandhandler[command]~=nil) then
commandhandler[command](state)
else
break
end
end
pipe.destroy()
end
com = createPipe(pipename)
createNativeThread(handler)
com.acceptConnection()
timer_object.onTimer = function ()
com.writeByte(0);
end
stop = function () com.writeByte(1); end;
print('Execute Stop(); to stop');
end
transistToRgb() |
_________________
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|