View previous topic :: View next topic |
Author |
Message |
Game Hacking Dojo Expert Cheater Reputation: 1
Joined: 17 Sep 2023 Posts: 110
|
Posted: Sun May 05, 2024 8:59 am Post subject: Fixing Lua String Compare |
|
|
Could you help me with this I've been wasting hours on this particular problem:
Code: | fileExtension = (".cdc")
processName = process:gsub('%.exe$','') -- = Sifu-Win64-Shipping
-- file name: Sifu-Win64-Shipping - Dissect Code.cdc
if string.lower(file):find(string.lower(processName)) and string.lower(file):find(fileExtension) then |
I also have tried:
Code: | if file:lower():find(processName:lower()) and file:lower():find(fileExtension:lower()) then |
the code doesn't pass the go through the if statement although the file is found. The only way it passes is when I comment out Code: | string.lower(file):find(string.lower(processName)) |
I added the string.lower for better results and it wasn't there when the problem started. Using this code for other cases it worked but not sure why this one didn't. It is driving me nuts. I made sure they were the same characters
Any Idea?
File Name: Sifu-Win64-Shipping - Dissect Code.cdc
File Name Char 1: S (ASCII 83)
File Name Char 2: i (ASCII 105)
File Name Char 3: f (ASCII 102)
File Name Char 4: u (ASCII 117)
File Name Char 5: - (ASCII 45)
File Name Char 6: W (ASCII 87)
File Name Char 7: i (ASCII 105)
File Name Char 8: n (ASCII 110)
File Name Char 9: 6 (ASCII 54)
File Name Char 10: 4 (ASCII 52)
File Name Char 11: - (ASCII 45)
File Name Char 12: S (ASCII 83)
File Name Char 13: h (ASCII 104)
File Name Char 14: i (ASCII 105)
File Name Char 15: p (ASCII 112)
File Name Char 16: p (ASCII 112)
File Name Char 17: i (ASCII 105)
File Name Char 18: n (ASCII 110)
File Name Char 19: g (ASCII 103)
File Name Char 20: (ASCII 32)
File Name Char 21: - (ASCII 45)
File Name Char 22: (ASCII 32)
File Name Char 23: D (ASCII 68)
File Name Char 24: i (ASCII 105)
File Name Char 25: s (ASCII 115)
File Name Char 26: s (ASCII 115)
File Name Char 27: e (ASCII 101)
File Name Char 28: c (ASCII 99)
File Name Char 29: t (ASCII 116)
File Name Char 30: (ASCII 32)
File Name Char 31: C (ASCII 67)
File Name Char 32: o (ASCII 111)
File Name Char 33: d (ASCII 100)
File Name Char 34: e (ASCII 101)
File Name Char 35: . (ASCII 46)
File Name Char 36: c (ASCII 99)
File Name Char 37: d (ASCII 100)
File Name Char 38: c (ASCII 99)
Process Name Char 1: S (ASCII 83)
Process Name Char 2: i (ASCII 105)
Process Name Char 3: f (ASCII 102)
Process Name Char 4: u (ASCII 117)
Process Name Char 5: - (ASCII 45)
Process Name Char 6: W (ASCII 87)
Process Name Char 7: i (ASCII 105)
Process Name Char 8: n (ASCII 110)
Process Name Char 9: 6 (ASCII 54)
Process Name Char 10: 4 (ASCII 52)
Process Name Char 11: - (ASCII 45)
Process Name Char 12: S (ASCII 83)
Process Name Char 13: h (ASCII 104)
Process Name Char 14: i (ASCII 105)
Process Name Char 15: p (ASCII 112)
Process Name Char 16: p (ASCII 112)
Process Name Char 17: i (ASCII 105)
Process Name Char 18: n (ASCII 110)
Process Name Char 19: g (ASCII 103)
|
|
Back to top |
|
|
AylinCE Grandmaster Cheater Supreme Reputation: 33
Joined: 16 Feb 2017 Posts: 1329
|
Posted: Sun May 05, 2024 12:20 pm Post subject: |
|
|
Since you added it to the comparison, this is the file name.
But this code seems to contain a suffix, not a name.
Code: | fileExtension = (".cdc") |
This comparison seems to test the two files against each other, rather than against each other.
Code: | if file:lower():find(processName:lower()) and file:lower():find(fileExtension:lower()) then |
If you manage to get the correct file name (We have solved this issue in your previous questions.)
Try this:
Code: | fileExtension = string.gsub(fileName, string.lower(" - Dissect Code.cdc"), "")
processName = process:gsub('.exe','')
if string.lower(fileExtension)==string.lower(processName) then
print("The filenames match.") -- true
else
print("Filenames are not the same!") -- false
end |
You asked a similar issue here and got the solution.
The same test exists in this code:
https://forum.cheatengine.org/viewtopic.php?p=5789413#5789413
_________________
|
|
Back to top |
|
|
Game Hacking Dojo Expert Cheater Reputation: 1
Joined: 17 Sep 2023 Posts: 110
|
Posted: Sun May 05, 2024 1:19 pm Post subject: |
|
|
My plan was, to check if the file found contains the name of the process and the declared ending. I think this code would accomplish a different methodology.
Quote: | Code: | fileExtension = string.gsub(fileName, string.lower(" - Dissect Code.cdc"), "")
processName = process:gsub('.exe','')
if string.lower(fileExtension)==string.lower(processName) then
print("The filenames match.") -- true
else
print("Filenames are not the same!") -- false
end |
|
So, my question is, how do I check if a string contains a certain word or a set of characters?
And as far as I know :find() is exactly what I am looking for to accomplish my goal.
Yeah, sure, it belongs to the same initial script however I modified it, adding functionality. And thank you again for the script.
|
|
Back to top |
|
|
AylinCE Grandmaster Cheater Supreme Reputation: 33
Joined: 16 Feb 2017 Posts: 1329
|
Posted: Sun May 05, 2024 3:21 pm Post subject: |
|
|
-- 1)
Code: | prcs1 = "Sifu-Win64-Shipping.exe" -- process
processName = prcs1:gsub('.exe','')
print("processName: "..processName)
file = "Sifu-Win64-Shipping - Dissect Code.cdc"
fileName = string.gsub(string.lower(file), string.lower(" %- Dissect Code.cdc"), "")
print("fileName: "..fileName)
if string.lower(fileName)==string.lower(processName) then
print("The filenames match.") -- true
else
print("Filenames are not the same!") -- false
end |
or
-- 2)
Code: | prcs1 = "Sifu-Win64-Shipping.exe" -- process
processName = prcs1:gsub('.exe','')
print("processName: "..processName)
fileName = "Sifu-Win64-Shipping - Dissect Code.cdc"
----------------------------------------------------
res1 = string.lower(processName):gsub("%-","_")
res2 = string.lower(fileName):gsub("%-","_")
print(string.find(res2,res1))
print(res1)
print(res2)
if string.find(res2,res1) then
print("The filenames match.") -- true
else
print("Filenames are not the same!") -- false
end |
There must be such "-" characters that confuse "find()".
It was necessary to replace the "-" character before comparing.
Code: | string.lower(processName):gsub("%-","_") |
test:
Code: | fileName = "Sifu-Win64-Shipping - Dissect Code.cdc"
print(string.find(fileName,"Sifu")) -- > 1 4
fileName = "Sifu-Win64-Shipping - Dissect Code.cdc"
print(string.find(fileName,"Sifu-Win64")) -- > no result!
fileName = ("Sifu-Win64-Shipping - Dissect Code.cdc"):gsub("%-","_")
print(string.find(fileName,"Sifu_Win64")) -- > 1 10 |
_________________
|
|
Back to top |
|
|
Game Hacking Dojo Expert Cheater Reputation: 1
Joined: 17 Sep 2023 Posts: 110
|
Posted: Sun May 05, 2024 3:35 pm Post subject: |
|
|
Okay thank you I'll try that.
I suppose that is also the case for string.find() as well since it did not work either.
|
|
Back to top |
|
|
ParkourPenguin I post too much Reputation: 143
Joined: 06 Jul 2014 Posts: 4370
|
Posted: Sun May 05, 2024 3:53 pm Post subject: |
|
|
AylinCE wrote: | There must be such "-" characters that confuse "find()". |
Lua 5.3 Reference Manual:
Quote: | x: (where x is not one of the magic characters ^$()%.[]*+-?) represents the character x itself.
...
%x: (where x is any non-alphanumeric character) represents the character x. This is the standard way to escape the magic characters. | "-" is a magic character. Use "%-" to escape it.
https://www.lua.org/manual/5.3/manual.html#6.4.1
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
|
Game Hacking Dojo Expert Cheater Reputation: 1
Joined: 17 Sep 2023 Posts: 110
|
Posted: Sun May 05, 2024 4:05 pm Post subject: |
|
|
Then I have to find if the name contains hyphens I substitute them with %- and do my search. Then restore the hyphens back.
I'd love to do this method since it's more accurate so I don't forcefully change hyphens into underscores and back since it might not return the name to its original in some cases
Edit:
Could you show me the way to do so?
|
|
Back to top |
|
|
ParkourPenguin I post too much Reputation: 143
Joined: 06 Jul 2014 Posts: 4370
|
Posted: Sun May 05, 2024 4:13 pm Post subject: |
|
|
There's a fourth parameter to string.find
Code: | ('abc!$^*()- def'):find('!$^*()-',1,true)
-- returns 4 10 (this is correct) |
I'd strongly recommend you read the manual if you want to know what the code you're writing does
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
|
Game Hacking Dojo Expert Cheater Reputation: 1
Joined: 17 Sep 2023 Posts: 110
|
Posted: Sun May 05, 2024 4:39 pm Post subject: |
|
|
Thank you very much guys for the help and yes that worked. I understand your point. But believe it or not, I spent a big chunk of today trying to know what was happening. I want to learn I love learning and sorry to bother you.
I checked the documentation for this one but I now figured out that something else went wrong when I made it right. So I was close but didn't work this time.
Thanks a lot
|
|
Back to top |
|
|
AylinCE Grandmaster Cheater Supreme Reputation: 33
Joined: 16 Feb 2017 Posts: 1329
|
Posted: Sun May 05, 2024 4:42 pm Post subject: |
|
|
ParkourPenguin wrote: | "-" is a magic character. Use "%-" to escape it. |
This is not in an assigned name, but in a name that exists and is read.
Well;
print(process) -- reads the selected process.
or
print(filename) -- returns filenames.
So we just access the "%-" character with "gsub" and convert it to "_".
Once the change is complete, "find()" results in trouble-free reading and finding.
Game Hacking Dojo wrote: |
I'd love to do this method since it's more accurate so I don't forcefully change hyphens into underscores and back since it might not return the name to its original in some cases
|
If you want to use the original name, don't transform it again, go back to the beginning and the original names are still there, use them again.
Code: | processName = process:gsub('.exe','')
file = "Sifu-Win64-Shipping - Dissect Code.cdc"
-- processName and file .. |
_________________
|
|
Back to top |
|
|
Game Hacking Dojo Expert Cheater Reputation: 1
Joined: 17 Sep 2023 Posts: 110
|
Posted: Sun May 05, 2024 5:04 pm Post subject: |
|
|
I used:
Code: | if string.find(string.lower(file), string.lower(processName), 1, true) and string.find(string.lower(file),(string.lower(fileExtension).. "$")) |
the parameter "true" stands for literal search or plain search it will regard all special characters as plain text. So, that worked actually.
|
|
Back to top |
|
|
Y.A.K.E Advanced Cheater Reputation: 0
Joined: 15 Jul 2019 Posts: 54
|
Posted: Wed May 08, 2024 3:44 am Post subject: |
|
|
file = "Sifu-Win64-Shipping - Dissect Code.cdc"
file = "Sifu%-Win64%-Shipping %- Dissect Code.cdc"
|
|
Back to top |
|
|
Game Hacking Dojo Expert Cheater Reputation: 1
Joined: 17 Sep 2023 Posts: 110
|
Posted: Wed May 08, 2024 4:05 am Post subject: |
|
|
Yes, thank you, that could've solved it if it's done manually but my script involves zero manual entries.
|
|
Back to top |
|
|
AylinCE Grandmaster Cheater Supreme Reputation: 33
Joined: 16 Feb 2017 Posts: 1329
|
Posted: Wed May 08, 2024 5:04 am Post subject: |
|
|
Y.A.K.E wrote: | file = "Sifu-Win64-Shipping - Dissect Code.cdc"
file = "Sifu%-Win64%-Shipping %- Dissect Code.cdc" |
Code: | file = "Sifu-Win64-Shipping - Dissect Code.cdc" |
We only showed this file name for testing purposes.
But actually the filename is in a folder and we had to read and interpret it.
Instead of the full name, we have its representation (local, string) "file".
@Y.A.K.E use:
Code: | local path = [[D:\mydirectory\mysubdirectory\Game Hacks]] -- your ct path
for _,p in ipairs(getFileList(path, '*.ct', true)) do
--print(p)
file = extractFileName(p) -- < -- "file" = representation of filenames in all content, owner!
--print(file)
res = string.lower(file):gsub("%-","_")
print(res)
end |
"String.find" pauses on escape characters and produces no results.
But I believe you've found enough code now that you don't need it.
_________________
|
|
Back to top |
|
|
Game Hacking Dojo Expert Cheater Reputation: 1
Joined: 17 Sep 2023 Posts: 110
|
Posted: Wed May 08, 2024 5:28 am Post subject: |
|
|
Thank you guys for the help. I have made a handful of scripts because of your help I just posted one at (Lua extensions)
My questions could've been related but I was making different scripts like:
- Auto load table on attachment
- Auto load dissect code (if available)
- Get byte signature pattern
- Automated export referenced strings/functions
- Export symbols
- And some more
And of course, I learnt a lot of Lua and CE API.
Thanks again.
|
|
Back to top |
|
|
|