Jump to content
Sign in to follow this  
4cc

How to check a file for values?

Recommended Posts

4cc

Hi thar,

I have a file, to be more specific, a config file from Counter-Strike (any version), which I need to check for certain values.

For example, I have this file:

unbindall
bind "0" "slot10"
bind "a" "buy hegrenade"
bind "k" "+voicerecord"
bind "q" "buy awp; buy flashbang; buy defuser; buy hegrenade; buy smokegrenade; buy vesthelm; buy flashbang; buy vest"
cl_righthand "0"
alias +cjump "+jump; +duck"
cl_rumblescale "1.0"
cl_debugrumble "0"
cl_detail_avoid_recover_speed "0.25"
cl_logofile "materials/vgui/logos/spray.vtf"
exec autoexec.cfg

So, I have the following patterns:

command

command "+a"

command "-a"

command "a"

command "a b; c d; e f; g h"

command "a" "b"

command a

command a "b; c; d"

Now what I want to do is, to check for certain values. For example, if "cl_righthand" is "0" or "1".

What I did so far is to specify a "ruleset", e.g.:

$cvarHashMap = ObjCreate("Scripting.Dictionary")
$cvarHashMap.add('mat_specular=mat_bumpmap', '0/1')
$cvarHashMap.add('net_graph', '0/1')
$cvarHashMap.add('cl_pitchspeed', '225')
$cvarHashMap.add('cl_yawspeed', '210')
$cvarHashMap.add('r_proplightingfromdisk', '0/1')
$cvarHashMap.add('mat_dxlevel', '80/81/90/95/98')

With some regular expressions I try to get the values from various patterns:

;; BIND cmds
;$bindRegExp = StringRegExpReplace($cfgIncoming, '(\n|^)((?<=)bind)(\s|\t)("?\S+"?)(\s|\t)("?.+"?)', '`~bind~´$2 $4 $6' & @CRLF)
;$bindCmd_Array = StringRegExp($bindRegExp, '`~bind~´(.+)' & @CRLF, 3)

;; ALIAS cmds
;$aliasRegExp = StringRegExpReplace($cfgIncoming, '(\n|^)((?<=)alias)(\s|\t)("?\S+"?)(\s|\t)("?.+"?)', '`~alias~´$2 $4 $6' & @CRLF)
;$aliasCmd_Array = StringRegExp($aliasRegExp, '`~alias~´(.+)' & @CRLF, 3)

;; COMMENT cmds
;$commentRegExp = StringRegExpReplace($cfgIncoming, '(/{2})(.+)', '`~comment~´$1 $2')
;$commentCmd_Array = StringRegExp($commentRegExp, '`~comment~´(.+)', 3)

;; SINGLE cmds
;$singleRegExp = StringRegExpReplace($cfgIncoming, '(\n|^)(\w+)(\r|\n|$)', '`~single~´$2' & @CRLF)
;$singleCmd_Array = StringRegExp($singleRegExp, '`~single~´(.+)' & @CRLF, 3)

;; NORMAL cmds
;$normalRegExp = StringRegExpReplace($cfgIncoming, '[\n|^]([\w+]{5,}?)(\s|\t)+"(.+)?"([^*])', '`~normal~´$1 $3' & @CRLF)
;$normalCmd_Array = StringRegExp($normalRegExp, '`~normal~´(.+)' & @CRLF, 3)

;; TWO VALUES FOR ONE VAR cmds
;$twovalsRegExp = StringRegExpReplace($cfgIncoming, '[\n|^]([\w+]{5,}?)(\s|\t)+"(.+)?"(\s|\t)+"(.+)?"([^*])', '`~twovals~´$1 $3 $5' & @CRLF)
;$twovalsCmd_Array = StringRegExp($twovalsRegExp, '`~twovals~´(.+)' & @CRLF, 3)

As I'm not that experienced in programming, I now wonder:

1. Is that the right way to do what I want to do?

2. Is there a better way?

3. How would you do it?

It feels a bit wrong the way I'm trying to manage this and I appreciate any hints and/or suggestions on doing this.

- 4cc

Share this post


Link to post
Share on other sites
water

Welcome to AutoIt and the forum!

I'm not exactly sure what you want to do but make sure that you read the forum rules (link can be found in the lower right corner of each page). Especially the part about game automation.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
4cc

So, as I can't find any function to contact a moderator via private message:

It's not about automation for a game. I want to check if a config file has forbidden values in it.

Like this: http://4pl.4players.de/data/ac/config/9a/dc/publicdata-596661.txt

So users, of that league, can check if their opponents had forbidden config values in their config.

That's nothing related to cheating or whatever (it's against that), so I don't understand why you closed my thread.

- 4cc

Edited by 4cc

Share this post


Link to post
Share on other sites
water

You don't have enough posts to send a private message. IIRC the post limit is either 5 or 10.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Melba23

4cc,

as I can't find any function to contact a moderator via private message

No need for a PM (and you need a certain number of posts to have access to that function) - you can contact us via the "Report" button that is at the bottom right of each post. I have done it for you so there is no need to do it again. ;)

I will let the Mod who closed the thread decide whether to reopen it, but I have a couple of questions that might help resolve the matter:

- 1. How do you get these "config files"? Do you read them from the game server?

- 2. What do you do when you find a "config file" which is not correct? Do you take action in the game to deal with it?

Answers to those questions will help us decide what to do about your thread. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
4cc

I want to provide a GUI where users can input the URL to a match they made in the league, e.g. http://4pl.4players.de/index.php/de/gameview.session/4793/2/index.html

After they've input the URL, I try to get the config file which you can find by clicking on "4PL Insight!" and then on "public data":

Posted Image

The config file in this case would be:

http://4pl.4players.de/data/ac/config/36/15/publicdata.txt

Maybe I even let them input the direct URL to the publicdata.txt, not the match URL, we'll see :P

Whatever, I then read the config file like:

Func getLogFileFromUrl($logUrl, $tempDir)
Local $logFileRead

InetGet($logUrl, $tempDir, 1)
$logFile = FileRead($tempDir)

If @error Then
Return False
Else
Return $logFile

EndIf

FileDelete($tempDir)

EndFunc

And try to get the values with regular expressions. I then want to output (in a textbox within the GUI) which values are against the ruleset I specified (or which the league specified in their game rules), so one can check if their opponent had bad config values in the match. That's all. Sorry for not going into detail in the thread which is closed now.

Edited by 4cc

Share this post


Link to post
Share on other sites
Melba23

4cc,

You have not answered my questions. :naughty:

We understand everything you explained - all you have done is repeated the same information as in your previous posts. What we want to know is whether you have to interact with the game or the server to obtain these files before you try to check their content. In simple terms, to what does your InetGet connect? :huh:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
4cc

I answered it.

$logfileUrl = "http://4pl.4players.de/data/ac/config/36/15/publicdata.txt"
$logfileTmp = @TempDir & "\_4cc\temp_logfile.4cc"

$logfile = getLogFileFromUrl($logfileUrl, $logfileTmp)

It doesn't interact with the game. You just put in the URL to the log/config file (which isn't connected to the game itself) from the match and it checks for values.

The log/config file is created by the Anti-Cheat program "4PL Insight!". Isn't that clear enough?

Edited by 4cc

Share this post


Link to post
Share on other sites
Melba23

4cc,

Thanks for answering. It is now up to the Mod who closed the earlier thread to decide what to do - he is aware of this thread. :)

M23.


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
4cc

Thank you. I hope water opens it again, as I really need help on that one.

Share this post


Link to post
Share on other sites
Jos

Thank you. I hope water opens it again, as I really need help on that one.

think you are mixing up people here.

I locked it and have now unlocked it given this seems to be unrelated to game automation.

Jos


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
4cc

think you are mixing up people here.

I locked it and have now unlocked it given this seems to be unrelated to game automation.

Jos

Oh, thought water was it, as he first replied here. Thanks for opening it again!

I hope someone has an answer, or two. :-)

- 4cc

Share this post


Link to post
Share on other sites
Melba23

4cc,

Now we have determined that your thread is legal, let us see what we can do to help you. :)

Reading your requirements I believe that getting the downloaded config file into an array would be a sensible first step (_FileReadToArray). You search the array for the elements you wish to check (_ArraySearch) and then use StringRegExpReplace to extract the set value. It is easy to check this value against the valid values associated with that particular key(StringInStr) if we place the key/values into a 2D array as we use the same index to access both. Here is a short example using the example config file to which you linked above:

#include <Array.au3>
#include <File.au3>

; Get the file onto disk

; Now read it into an array
Local $aLines
_FileReadToArray("CS.cfg", $aLines)

_ArrayDisplay($aLines) ; Just for display purposes

; Create an array to hold the rule set - here we only have 2 rules
Local $aRuleSet[2][2] = [["net_graph", "0|1"], _
                         ["hud_draw",  "0|1"]] ; Note use of "|" to delimit valid values

; Now we look for each "rule key" within the file
For $iRule = 0 To UBound($aRuleSet) - 1
    ; Search for the rule key in the array
    $iIndex = _ArraySearch($aLines, $aRuleSet[$iRule][0], 0, 0, 0, 1) ; Use the partial search algorithm
    ; Check we found it
    If $iIndex <> -1 Then
        ; Extract the set value
        $sSetValue = StringRegExpReplace($aLines[$iIndex], '^.*"(.*)".*$', '$1')
        ; Compare the set value with the legal values in the rule set
        If StringInStr("|" & $aRuleSet[$iRule][1], "|" & $sSetValue) Then ; Add a leading "|" to the valid results and the set value to cater for multicharacter values
            $sValid = "Valid"
        Else
            $sValid = "Invalid"
        EndIf
        MsgBox(0, "Rule Check", "Rule: " & $aRuleSet[$iRule][0] & @CRLF & "set to: " & $sSetValue & @CRLF & @CRLF & "Result: " & $sValid)
    EndIf
Next

I hope the comments make it clear what is going on and that it is obvious how to expand the code to check all the rules you require. But do ask if you have any questions. :)

M23

  • Like 1

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
4cc

Thanks for your answer! However, it also finds commands like "net_graphproportionalfont" and "hud_draw_fixed_reticle", as it searches for "net_graph" and "hud_draw".

I looked at the _ArraySearch options and found "$iPartial", which I thought would help me out by settings it from 1 to 0, but it doesn't find anything then.

Am I doing it wrong?

- 4cc

//e: I am now working around this by adding a

& ' '
after, e.g., the "net_graph" string. Further experiments incoming.

//e²: Why does

$sSetValue = StringRegExpReplace($logfileArray[$iFound], '^([\w+]){5,}?(\s|\t)+"(.+)?"([^*])', '$3')
return, e.g., net_graph "0" instead of 0? Edited by 4cc

Share this post


Link to post
Share on other sites
Melba23

4cc,

Good spot about the multiple returns - adding a space should solve the problem as you have found for yourself. :)

What was wrong with the SRE I used? Your version looks very much more complicated. If you provide a decode of what it is supposed to do I will try and see why it does not do it, although I am far from expert in these beasts. ;)

M23

  • Like 1

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
4cc

The thing is, commands can look like this, for example:

net_graph

net_graph "0"

net_graph 0

bind "v" "net_graph 0; buy m4a1; [...]"

alias +whatever "net_graph 0; net_graph 3; [...]"

... or something completely different (maybe). I need/want to be very specific on what to search, which is why I had several regular expressions for each possible case.

Single: stuffcmds

Normal w ": net_graph "0"

Binds: bind "MOUSE1" "+attack1"

Aliases: alias +whatever "+jump"

Comments: // no problem :_P

The "s are optional in the config, so you can also write net_graph 0 or bind MOUSE1 +attack1, etc.

Your pattern matches several of the ones above (except the single commands and comments), but I want to target those separately, just to be prepared for the future and further features added some time.

I use this site to check my regular expressions btw: http://rubular.com/

Again, why doesn't the $3 in my previous post return the value 0? I'm confused :-c

Thanks for your time!

- 4cc

Edited by 4cc

Share this post


Link to post
Share on other sites
Melba23

4cc,

This extracts all instances of the test string from the samples you gave:

Global $aLines[6] = [5, _
                    'net_graph', _
                    'net_graph "0"', _
                    'net_graph 0', _
                    'bind "v" "net_graph 0; buy m4a1; [...]"', _
                    'alias +whatever "net_graph 0; net_graph 3; [...]"']

$sTest_String = "net_graph"

For $i = 1 To $aLines[0]
    ; Just for display
    ConsoleWrite(@CRLF & $aLines[$i] & @CRLF & "Found values: ")

    ; Extract an array of matching elements
    $aRet = StringRegExp(StringReplace($aLines[$i], '"', ''), "(?i)(?U)" & $sTest_String & "\s.*(\d)", 3)

    ; Just for display - show the array elements
    For $j = 0 To UBound($aRet) - 1
        ConsoleWrite($aRet[$j] & " ")
    Next
    ConsoleWrite(@CRLF)
Next

Now as I have no interest in gaming whatsoever, I am withdrawing from this thread. Good luck with the rest of your project. :)

M23

  • Like 1

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
4cc

Thank you very much for your help, I finally managed it now!

I'm not reading the file into an array, but a string. But you got me in the right direction. Works like a charm now. :-)

$sSetValue = StringRegExp($curFileContent, "[^a-zA-Z_-]" & $cvarList[$i][0] & ' "?([^";]+)"?;?', 1)
$sSetValue = _ArrayToString($sSetValue)

- 4cc

Posted Image

Edited by 4cc

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×