|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
geesve Cheater Reputation: 0
Joined: 15 Feb 2017 Posts: 25
|
Posted: Sun Mar 04, 2018 11:10 pm Post subject: |
|
|
Yeah, thanks ParkourPenguin for your patience, now i see. it seems like common newbie issue with understanding how float points are working in LUA :)
Well, for now it looks like a real "dead end". I tried few things, but even when i tried code like this:
Code: | {$lua}
...
...
writeDouble("camx", readFloat(node + 0xF0) + (sinh * 0.001)) -- by "debugging" it, i can see that it write full proper value into table
...
...
{$asm}
...
...
cvtsd2ss xmm2,[camx] // should convert double to float, if i get it right
movss [rcx+30],xmm2 // copy converted value to in-game cameraX |
It works in the same way too. So looks like we can do calculations only (or most of them) in LUA and in such case we get free camera with stuttering, lags and so on because of how LUA works with floats. That lags are not very annoying, but only if purpose of free camera is not recording the video (photo, just flying around and so on...). Or, ASM, that should works fine. But i'm bit scared of how amount of the code might looks like if we decide to implement inertia and "slow start" :)
|
|
Back to top |
|
|
ParkourPenguin I post too much Reputation: 138
Joined: 06 Jul 2014 Posts: 4275
|
|
Back to top |
|
|
geesve Cheater Reputation: 0
Joined: 15 Feb 2017 Posts: 25
|
Posted: Wed Mar 07, 2018 10:14 am Post subject: |
|
|
Quote: | That's not Lua's fault |
Yes, sorry, i'm misunderstand that. This is how single-precision floats working wherever they are used: LUA, ASM, C++... Another good article with explanations of how in-game cameras working with floats.
And, actually, i got the idea that makes LUA camera moves without of "swings" when camera speed have very low values, like 0.001 and with properly rotations. And with using tips and tricks from that topic - we finally get the camera that moving smooth, without of lags and stuttering. Honestly, i though that we can't get that :)
The idea is that we do not really need to constantly read current camera XYZ values when we do calculations. Actually, we can read that values only once, when script activated. After that we can do calculations "locally" and write all three new values at once with function provided by panraven. That all reduce lags, increase calculations precision and so on. The only restriction in such case is if we want to move around some small object (like apple on the ground) and if camera XYZ values are something like 1234.567 - we still can notice very tiny stutter, but that is because of that "7 digits precision" and that's how in-game camera works too. If i try to slowly move in-game character to North with very small rotation to east or west, so sine value will be like "0.002", i can notice how X value updated not constantly and see that "micro-jumps" when camera X value changed from 1234.567 to 1234.568, for example.
So, yeah, it's working and working smooth. And can be used now not only for photo or just flying around but also for making in-game videos.
Oh, and function for writing all new camXYZ values at once makes possible to use sleep(5) instead of sleep(1) or sleep(0). But seems like particular value depend from game where it using.
The whole new code below. I tried to comment every step to make it clear if someone find that topic from google. Just explain some logic of camera movements here:
- When we press "Move Forward" hotkey and camera watching at NE - camera start increase it's speed slowly, until it reached maximum speed. When we release "Move Forward" key - camera keep moving to NE and slowly decreasing it's speed (inertia);
- While camera keep moving with that inertia, there is possible to rotate her around and camera will keep moving to NE (camera will not move in such case where it watching);
- If camera moving to it's right side, but we press "Moving Left" hotkey - it decreased "Right" speed faster;
- Camera does not moving up or down, until hotkey for moving up or down are pressed, so even if camera watching down to the ground and "Move Down" hotkey are not pressed - it keep moving in horizontal directions only. For making camera move exactly where it's watching, it required not so much changes.
There is still some scenarios that should be covered, but for that it's required just to play with it's logic, nothing more :)
Code: |
globalalloc(cheaton,4) // global variable for createThread on/off
cheaton:
dd 0
{$lua}
if syntaxcheck then return end
[ENABLE]
-------------------------------------
-- Speed and Multipliers variables --
-------------------------------------
local multFB = 0
local multRL = 0
local multUpDown = 0
local maxPosSpeed = 0.1 -- maximum speed for Forward and Right movement
local maxNegSpeed = -0.1 -- maximum speed for Back and Left movement
local SlowerMult = 0.0001 -- how soon max speed will achieved when hotkey pressed and how soon camera stop if hotkey released
local FasterMult = 0.0002 -- how fast speed change if movement goes vice versa (e.g. from right to left, while camera keeps going right)
-- local variables that will be used for camera movement direction, when it moves with inertia.
local sinhfb = 0
local coshfb = 0
local sinhrl = 0
local coshhrl = 0
local sinhupdown = 0
local coshhupdown = 0
-------------------------------------------------------------------------------------
-- Create "node" for base cameraXYZ addresses
local node = getAddress("[[[theHunterCotW_F.exe+01D94868]+158]+468]")
-- so after that, (node + 0xF0) is the same as "[[[theHunterCotW_F.exe+01D94868]+158]+468]+F0"
-------------------------------------------------------------------------------------
-- Save once current Camera XYZ values for further calculations
local calcX = readFloat(node + 0xF0) -- east/west
local calcY = readFloat(node + 0xF4) -- up/down
local calcZ = readFloat(node + 0xF8) -- north/south
-------------------------------------------------------------------------------------
-- Function for read and write group of values at once
-- for write
function packWrite(addr, fms, ...)
local packed = addr and string.pack(fms,...)
if packed then return writeBytes(addr,{packed:byte(1,-1)}) end
end
-- for read (not used here)
--[[function packRead(addr, fms)
local sz = addr and string.packsize(fms)
local bt = sz and readBytes(addr,sz,true)
if bt and #bt == sz then
return string.unpack(fms,byteTableToString(bt))
end
end]]
-- maded by panraven
-------------------------------------------------------------------------------------
createNativeThread(function(timer)
sleep(200) -- delay for giving script time to write for "cheaton" proper value
while readFloat("cheaton") == 0 do -- while "cheaton" value equal "0" this cheat work
sleep(5) -- like timer interval
if readBytes("theHunterCotW_F.exe+1D94390") == 0 then -- Check for Alt-Tab
-- read in-game sin/cos values
local sinh = readFloat("theHunterCotW_F.exe+1E6695C")
local cosh = readFloat("theHunterCotW_F.exe+1E66954")
-------------------------
-- Assign Hotkeys Here --
-------------------------
local MoveForward = isKeyPressed(VK_W) -- local variable for move forward hotkey
local MoveBack = isKeyPressed(VK_S) -- local variable for move back hotkey
local MoveLeft = isKeyPressed(VK_A) -- local variable for move left hotkey
local MoveRight = isKeyPressed(VK_D) -- local variable for move right hotkey
local MoveUp = isKeyPressed(VK_R) -- local variable for move up hotkey
local MoveDown = isKeyPressed(VK_F) -- local variable for move down hotkey
----------------------------
-- Movements calculations --
----------------------------
---- Forward
if MoveForward then -- start moving Forward
if multFB < maxPosSpeed then -- if max speed not achieved
multFB = multFB + SlowerMult -- slowly increasing to max speed
end
if multFB < 0 then -- if cam moving back but need forward
multFB = multFB + FasterMult -- faster speed increase
else
calcX = calcX + (sinh * multFB) -- store calculated new camX value
calcZ = calcZ - (cosh * multFB) -- store calculated new camZ value
sinhfb = sinh -- copy sinh value to the local sinh for using later when we release hotkey
coshfb = cosh -- copy cosh value to the local cosh for using later when we release hotkey
end
end
if not MoveForward and multFB > 0.0001 then -- check if keys released and camera moves forward
multFB = multFB - SlowerMult -- slowly stop moving forward
calcX = calcX + (sinhfb * multFB) -- store calculated new camX value
calcZ = calcZ - (coshfb * multFB) -- store calculated new camZ value
end
---- Back
if MoveBack then -- start moving Back
if multFB > maxNegSpeed then -- if max speed not achieved
multFB = multFB - SlowerMult -- slowly decreasing to max speed
end
if multFB > 0 then -- if cam moving forward but need back
multFB = multFB - FasterMult -- faster speed decrease
else
calcX = calcX + (sinh * multFB) -- store calculated new camX value
calcZ = calcZ - (cosh * multFB) -- store calculated new camZ value
sinhfb = sinh -- copy sinh value to the local sinh for using later when we release hotkey
coshfb = cosh -- copy cosh value to the local cosh for using later when we release hotkey
end
end
if not MoveBack and multFB < -0.0001 then -- check if keys released and camera moves back
multFB = multFB + SlowerMult -- slowly stop moving back
calcX = calcX + (sinhfb * multFB) -- store calculated new camX value
calcZ = calcZ - (coshfb * multFB) -- store calculated new camZ value
end
---- Right
if MoveRight then -- start moving Right
if multRL < maxPosSpeed then -- if max speed not achieved
multRL = multRL + SlowerMult -- slowly increasing to max speed
end
if multRL < 0 then -- if cam moving left but need right
multRL = multRL + FasterMult -- faster speed increase
else
calcX = calcX + (cosh * multRL) -- store calculated new camX value
calcZ = calcZ + (sinh * multRL) -- store calculated new camZ value
sinhrl = sinh -- copy sinh value to the local sinh for using later when we release hotkey
coshrl = cosh -- copy cosh value to the local cosh for using later when we release hotkey
end
end
if not MoveRight and multRL > 0.0001 then -- check if keys released and camera moves right
multRL = multRL - SlowerMult -- slowly stop moving right
calcX = calcX + (coshrl * multRL) -- store calculated new camX value
calcZ = calcZ + (sinhrl * multRL) -- store calculated new camZ value
end
---- Left
if MoveLeft then -- start moving Left
if multRL > maxNegSpeed then -- if max speed not achieved
multRL = multRL - SlowerMult -- slowly decreasing to max speed
end
if multRL > 0 then -- if cam moving right but need left
multRL = multRL - FasterMult -- faster speed decrease
else
calcX = calcX + (cosh * multRL) -- store calculated new camX value
calcZ = calcZ + (sinh * multRL) -- store calculated new camZ value
sinhrl = sinh -- copy sinh value to the local sinh for using later when we release hotkey
coshrl = cosh -- copy cosh value to the local cosh for using later when we release hotkey
end
end
if not MoveLeft and multRL < -0.0001 then -- check if keys released and camera moves Left
multRL = multRL + SlowerMult -- slowly stop moving left
calcX = calcX + (coshrl * multRL) -- store calculated new camX value
calcZ = calcZ + (sinhrl * multRL) -- store calculated new camZ value
end
---- Up
if MoveUp then -- start moving Up
if multUpDown < maxPosSpeed then -- if max speed not achieved
multUpDown = multUpDown + SlowerMult -- slowly increasing to max speed
end
if multUpDown < 0 then -- if cam moving down but need up
multUpDown = multUpDown + FasterMult -- faster speed increase
else
calcY = calcY + multUpDown -- store calculated new camY value
end
end
if not MoveUp and multUpDown > 0.0001 then -- check if keys released and camera moves up
multUpDown = multUpDown - SlowerMult -- slowly stop moving up
calcY = calcY + multUpDown -- store calculated new camY value
end
---- Down
if MoveDown then -- start moving Down
if multUpDown > maxNegSpeed then -- if max speed not achieved
multUpDown = multUpDown - SlowerMult -- slowly decreasing to max speed
end
if multUpDown > 0 then -- if cam moving up but need down
multUpDown = multUpDown - FasterMult -- faster speed decrease
else
calcY = calcY + multUpDown -- store calculated new camY value
end
end
if not MoveDown and multUpDown < -0.0001 then -- check if keys released and camera down
multUpDown = multUpDown + SlowerMult -- slowly stop moving down
calcY = calcY + multUpDown -- store calculated new camY value
end
-- write new Camera XYZ values all at once, with using function
packWrite(node + 0xF0, 'fff', calcX, calcY, calcZ)
end -- close alt-tab check
end -- close while
end) -- close timer function
[DISABLE]
{$asm}
cheaton:
dd 1 // give to "cheaton" any other value than "0" for stop thread from LUA
|
|
|
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
|
|