• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# cs 1.6 calc

krot Feb 24th, 2020 (edited) 2,650 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. --Cheat Engine скрипт для решение примеров AMXX Calculator, MindGames 2.0 и тд..
2. --https://pastebin.com/u/krot
3. ----------- calc
4. function characterPresent(stringParam, character)
5.     --[[
6.         This function returns true if and only if character is in stringParam.
7.     ]]--
8.     --Loop through stringParam:
9.     for i=1, #stringParam do
10.         --If the current character is character, return true.
11.         if stringParam:sub(i, i) == character then return true end
12.     end
13.     --If we go through the whole string without returning true, we get to this point.
14.     --This means we've checked every character and haven't found character, so we return false.
15.     return false
16. end
17.
18. function getNumber(stringParam)
19.     --[[
20.         This function parses a number from the beginning of stringParam and also returns the rest of the string.
21.         For example, if stringParam is "23s", this function returns 23, "s".
22.         If there is no number at the beginning of stringParam (e.g., stringParam is "Hi"), then the function returns nil, stringParam.
23.     ]]--
24.     --These are all of the characters we would expect in a number.
25.     local validCharacters = "0123456789.-"
26.     --This is true if and only if we have found a digit.
27.     local foundDigit = false
28.     --This is the index of the character in stringParam we are currently looking at.
29.     local i = 1
30.     --This is the character in stringParams we are currently looking at.
31.     local currentCharacter = stringParam:sub(i, i)
32.     --We want to examine stringParam while the current character is a valid character:
33.     while characterPresent(validCharacters, currentCharacter) do
34.         --In the first character, get rid of the - from validCharacters because we do not want a negative sign after the number has already begun. Negative signs must always be the first character in a number.
35.         if i == 1 then validCharacters = "0123456789." end
36.         --If currentCharacter is a decimal point, then make get rid of the . and - from validCharacters because we only want one decimal point and a negative sign can not come after a decimal point.
37.         if currentCharacter == "." then validCharacters = "0123456789" end
38.         --If currentCharacter is a digit, then make foundDigit true:
39.         if characterPresent("0123456789", currentCharacter) then foundDigit = true end
40.         --Finally, increment i to go to the next character.
41.         i = i+1
42.         --If i has gone past the length of stringParam, then there are no more characters and the loop should be exited.
43.         if i > #stringParam then break end
44.         --Otherwise, update currentCharacter.
45.         currentCharacter = stringParam:sub(i, i)
46.     end
47.     --If we have not found a digit, then we have not found a number, so go back to the beginning of the string to signify that stringParam does not have a number at the beginning.
49.     --Parse the number from the beginningof the string up till i.
50.     local number = tonumber(stringParam:sub(1, i-1))
51.     --Finally, return the number and the rest of the string.
52.     return number, stringParam:sub(i, #stringParam)
53. end
54.
55. function parseExpression(expression, expectEndParentheses)
56.     --[[
57.         This function parses expression and returns the mathematical value of expression along with the rest of expression that was not parsed.
58.         If expectEndParentheses is not specified, it defaults to false.
59.         If expectEndParentheses is false, then the whole expression is parsed. If the expression is valid, what is returned is the value of the expression along with the empty string.
60.         If expectEndParentheses is true, then the expression is parsed up until the first end parentheses without a matching beginning parentheses. If the expression is valid, what is returned is the value of the expression along with the rest of expression after the end parentheses.
61.         In both cases, if the expression is invalid, the. what is returned is nil along with an error message.
62.         For example:
63.         parseExpression("2+3") -> 5, ""
64.         parseExpression("Hi") -> nil, "Invalid input where number or '(' was expected"
65.         parseExpression("2+3)+5", true) -> 5, "+5"
66.     ]]--
67.     --This is true if and only if we are expecting an expression next instead of an operator.
68.     local expectingExpression = true
69.     --This is true if and only if the last expression examined was surrounded by parentheses.
70.     local lastExpressionWasParenthetical = false
71.     --These are all the operators in our parser.
72.     local operators = "+-/*^"
73.     --This is a list of all of the parts in our expression.
74.     local parts = {}
75.     --This is true if and only if we have found an unmatched end parentheses.
76.     local foundEndParentheses = false
77.     --If expectEndParentheses is not specified, make it default to false.
78.     expectEndParentheses = expectEndParentheses or false
79.     --We want to parse the expression until we have broken it up into all of its parts and there is nothing left to parse:
80.     while expression ~= "" do
81.         --Check if there is a number at the beginning of expression.
82.         local nextNumber, expressionAfterNumber = getNumber(expression)
83.         --This is the next character:
84.         local nextCharacter = expression:sub(1, 1)
85.         --This is the next piece of the expression, used in error messages:
86.         local nextPiece = expression:sub(1, 5)
87.         --Add " [end]" if expression has 5 characters or less to signify that this piece is the end of the expression
88.         if #expression <= 5 then nextPiece = nextPiece.." [end]" end
89.         --If we expect an expression:
90.         if expectingExpression then
91.             --If there is a beginning parentheses next, parse the expression inside the parentheses:
92.             if nextCharacter == "(" then
93.                 --Parse the next expression by taking the beginning parentheses off and outting the rest of the expression into parseExpression. Also, make expectEndParentheses true so that the expression will only be parsed up to the next end parentheses that is not matched without this beginning parentheses.
94.                 local nestedExpressionValue, expressionAfterParentheses = parseExpression(expression:sub(2, #expression), true)
95.                 --If the value returned is nil, then parsing this expression must have caused an error, so return the error message.
96.                 if nestedExpressionValue == nil then return nestedExpressionValue, expressionAfterParentheses end
97.                 --Otherwise, insert the value into parts.
98.                 table.insert(parts, nestedExpressionValue)
99.                 --Also, update expression by going on to what's after the parentheses.
100.                 expression = expressionAfterParentheses
101.                 --Make lastExpressionWasParenthetical true.
102.                 lastExpressionWasParenthetical = true
103.             --Otherwise, if there is no parentheses, parse the next number:
104.             else
105.                 --If the next number is nil, then return an error message.
106.                 if nextNumber == nil then return nil, "Expected number or '(', but found '"..nextPiece.."'" end
107.                 --Otherwise, insert the number into parts.
108.                 table.insert(parts, nextNumber)
109.                 --Also, update expression by going on to what's after the number.
110.                 expression = expressionAfterNumber
111.                 --Make lastExpressionWasParenthetical false.
112.                 lastExpressionWasParenthetical = false
113.             end
114.         --The following cases deal with the case that we expect an operator instead of an expression.
115.         --If the next character is an operator:
116.         elseif characterPresent(operators, nextCharacter) then
117.             --Insert the operator into parts.
118.             table.insert(parts, nextCharacter)
119.             --Also, update expression by taking out the operator.
120.             expression = expression:sub(2, #expression)
121.         --If the next character is a beginning parentheses or the preceding character was an end parentheses and there is a valid number after it, insert a multiplication sign.
122.         elseif nextCharacter == "(" or (lastExpressionWasParenthetical and nextNumber ~= nil) then table.insert(parts, "*")
123.         --If the next character is an end parentheses:
124.         elseif nextCharacter == ")" then
125.             --If we expect an end parentheses:
126.             if expectEndParentheses then
127.                 --Take the parentheses out of the expression.
128.                 expression = expression:sub(2, #expression)
129.                 --Set foundEndParentheses to true and exit the while loop.
130.                 foundEndParentheses = true
131.                 break
132.             --Otherwise, if we were not expecting an end parentheses, then return an error message.
133.             else return nil, "')' present without matching '(' at '"..nextPiece.."'" end
134.         --If none of the above cases apply, then the expression must be invalid, so return an error message.
135.         else return nil, "Expected expression, but found '"..nextPiece.."'" end
136.         --If we are expecting an expression, switch to expecting an operator and vice versa.
137.         expectingExpression = not expectingExpression
138.     end
139.     --If, at the end, we are left expecting an expression or have not found an end parentheses despite being told we would, then the expression ended before it was supposed to, so return an error message.
140.     if expectEndParentheses and not foundEndParentheses then return nil, "Expression unexpectedly ended ('(' present without matching ')')" end
141.     if expectingExpression then return nil, "Expression unexpectedly ended" end
142.     --Otherwise, the expression has been parsed successfully, so now we must evaulate it.
143.     --Loop through parts backwards and evaluate the exponentiation operations:
144.     --Notice that we loop through exponentiation since exponentiation is right-associative (2^3^4=2^81, not 8^4) and that we do not use a for loop since the value of #parts is going to change.
145.     local i = #parts
146.     while i >= 1 do
147.         --If the current part is an exponentiation operator, evaluate the operation, put the result in the slot of the former number, and remove the operator along with the latter number.
148.         if parts[i] == "^" then
149.             parts[i-1] = parts[i-1]^parts[i+1]
150.             table.remove(parts, i+1)
151.             table.remove(parts, i)
152.         end
153.         --Decrement i.
154.         --Notice that we decrement i regardless of if we have just encountered an exponentiation operator. This is because since we are going backwards, the operator we are on after removing the exponentiation operator must have been ahead of the exponentiation operator in the expression and thus could not have been an exponentiation operator.
155.         --To understand this better, examine the expression "2^3*4^5". How would this while loop deal with that expression by making sure that all of the exponentiation operations are evaluated?
156.         i = i-1
157.     end
158.     --Loop through parts forwards and evaluate the multiplication and division operators.
159.     --Notice that we loop forward since division is left-associative (1/2/4=0.5/4, not 1/0.5).
160.     i = 1
161.     while i <= #parts do
162.         --If the current part is a multiplication operator, evaluate the operation, put the result in the slot of the former number, and remove the operator along with the latter number.
163.         if parts[i] == "*" then
164.             parts[i-1] = parts[i-1]*parts[i+1]
165.             table.remove(parts, i+1)
166.             table.remove(parts, i)
167.         --If the current part is an division operator, evaluate the operation, put the result in the slot of the former number, and remove the operator along with the latter number.
168.         elseif parts[i] == "/" then
169.             parts[i-1] = parts[i-1]/parts[i+1]
170.             table.remove(parts, i+1)
171.             table.remove(parts, i)
172.         --Increment if the current part is not an operator.
173.         --Notice that we make this incrementation conditional. This is because since we are going backwards, incrementing after we have just processed an operator could make us skip a multiplication or division operator by hopping over it.
174.         --To understand this better, examine the expression "1/2/3". How does making this incrementation conditional prevent us from skipping over a division operator?
175.         else i = i+1 end
176.     end
177.     --Loop through parts forwards and evaluate the addition and subtraction operators.
178.     --Notice that we loop forward since subtraction is left-associative (1-2-3=-1-3, not 1-(-1)).
179.     i = 1
180.     while i <= #parts do
181.         --If the current part is an exponentiation operator, evaluate the operation, put the result in the slot of the former number, and remove the operator along with the latter number.
182.         if parts[i] == "+" then
183.             parts[i-1] = parts[i-1]+parts[i+1]
184.             table.remove(parts, i+1)
185.             table.remove(parts, i)
186.         --If the current part is an exponentiation operator, evaluate the operation, put the result in the slot of the former number, and remove the operator along with the latter number.
187.         elseif parts[i] == "-" then
188.             parts[i-1] = parts[i-1]-parts[i+1]
189.             table.remove(parts, i+1)
190.             table.remove(parts, i)
191.         --Just like with multiplication and division, increment i if the current part is not an operator.
192.         else i = i+1 end
193.     end
194.     --Finally, return the answer (which is in the first element of parts) along with the rest of the expression to be parsed.
195.     return parts[1], expression
196. end
197. --------------------------------------------end calc
198. function strpos (str, f)
199.     if str ~= nil and f ~= nil then
200.         return (string.find(str, f))
201.     else
202.         return nil
203.     end
204. end
205. ----------------------form
206.         MyForm = createForm()
207.         label1 = createLabel(MyForm)
208.         label2 = createLabel(MyForm)
209.
210.         FontHeight = getProperty(label2 , "Font")
211.         setProperty(FontHeight , "Style", "[fsBold]")
212.         setProperty(FontHeight , "Color", "0x000000FF")
213.         setProperty(FontHeight , "Height", "36")
214.
215.
216.
217.         FontHeight = getProperty(label1 , "Font")
218.         setProperty(FontHeight , "Height", "23")
219.
220.
221.         control_setCaption(MyForm, "krot")
222.
223.         control_setCaption(label1, "https://pastebin.com/u/krot") --  "Example text from the read process memory"
224.         control_setCaption(label2, "000000000") -- "Here is what CheatEngine thinks of memory ..."
225.
226.         control_setPosition(label1, 10, 5)
227.         control_setPosition(label2, 10, 40)
228. ----------------------bp
229. -- https://github.com/VSES/SourceEngine2007/blob/master/se2007/engine/tmessage.h
231.
232. --output:close()
234.
235. --output = io.open("C:/logbp.txt", "a+")
236.
237.
238. local pri="";
239. ff =findTableFile('nf.wav')
242. local lof = strpos(value," = \\?")
243.
244. if lof  ~= nil   then
245. if pri  ~= value   then
246. pri=value
247.
248. v=value:gsub("sin%(90°%)","1")
249. v=v:gsub("([^0-9-+*/\\(\\)])","")
250.
251. control_setCaption(label1, value)
252.
253. local result, errorMessage = parseExpression(v)
254.     --If the expression is invalid, then print the error message.
255.     if result == nil then
256.      control_setCaption(label2, errorMessage)
257.     --Otherwise, print the result.
258.     else
259.             -- print(result)
260.             control_setCaption(label2, result)
261.             PlaySound(ff)
262.      end
263.
264.
265. --output:write(value)
266. --output:write("\n")
267.  end
268.     end
269.
270.   debug_continueFromBreakpoint(co_run)
271.   return 0
272. end)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Top