From fdcd6d8680182ecf96c23e4e74b1cdd182384368 Mon Sep 17 00:00:00 2001 From: JoinedSenses Date: Tue, 7 Aug 2018 17:45:21 -0400 Subject: [PATCH 01/25] Negative lookbehinds and new datatypes I have added a negative lookbehind to ensure that this script doesn't modify custom methods with similarly naming schemes. Example: sourceIRC has `IRC_GetAdminFlag`, which would be affected by this script. I have also added in datatype checks for these new methodmaps. Example: `code = re.sub(r"[\w]+ ([\w\d_]+) = CreateMenu", r"Menu \1 = new Menu", code)` This line will change this: `Handle menu = CreateMenu(whatever, whatever);` into: `Menu menu = new Menu(whatever, whatever);` --- methodmapize.py | 501 ++++++++++++++++++++++++------------------------ 1 file changed, 254 insertions(+), 247 deletions(-) diff --git a/methodmapize.py b/methodmapize.py index 2a768bc..7f192f4 100644 --- a/methodmapize.py +++ b/methodmapize.py @@ -24,310 +24,317 @@ print('Methodmapizing {}'.format(sys.argv[i])) - # AdminId - code = re.sub(r"BindAdminIdentity\s*\(\s*([^\,]+)\s*,\s*", r"\1.BindIdentity(", code) - code = re.sub(r"CanAdminTarget\s*\(\s*([^\,]+)\s*,\s*", r"\1.CanTarget(", code) - code = re.sub(r"GetAdminFlags\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetFlags(", code) - code = re.sub(r"GetAdminGroup\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetGroup(", code) - code = re.sub(r"GetAdminPassword\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetPassword(", code) - code = re.sub(r"GetAdminFlag\s*\(\s*([^\,]+)\s*,\s*", r"\1.HasFlag(", code) - code = re.sub(r"AdminInheritGroup\s*\(\s*([^\,]+)\s*,\s*", r"\1.InheritGroup(", code) - code = re.sub(r"SetAdminPassword\s*\(\s*([^\,]+)\s*,\s*", r"\1.SetPassword(", code) - code = re.sub(r"GetAdminGroupCount\s*\(\s*([^\)]+)\s*\)", r"\1\.GroupCount", code) - code = re.sub(r"GetAdminImmunityLevel\s*\(\s*([^\)]+)\s*\)", r"\1\.ImmunityLevel", code) - code = re.sub(r"SetAdminImmunityLevel\s*\(\s*([^\,]+)\s*,\s*([^\)]+)\s*\)", r"\1.ImmunityLevel = \2", code) + code = re.sub(r"(?(\1)", code) From dde758fbae6432d088923945e492c4f2c79e3ea5 Mon Sep 17 00:00:00 2001 From: JoinedSenses Date: Tue, 7 Aug 2018 17:56:08 -0400 Subject: [PATCH 02/25] Removed unnecessary regex --- methodmapize.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/methodmapize.py b/methodmapize.py index 7f192f4..a9c621f 100644 --- a/methodmapize.py +++ b/methodmapize.py @@ -23,7 +23,8 @@ code = f.read() print('Methodmapizing {}'.format(sys.argv[i])) - + + # AdminId code = re.sub(r"(? Date: Tue, 7 Aug 2018 20:36:11 -0400 Subject: [PATCH 03/25] Updated ArrayStack --- methodmapize.py | 1 + 1 file changed, 1 insertion(+) diff --git a/methodmapize.py b/methodmapize.py index a9c621f..ab030d7 100644 --- a/methodmapize.py +++ b/methodmapize.py @@ -72,6 +72,7 @@ code = re.sub(r"(? Date: Tue, 7 Aug 2018 20:48:18 -0400 Subject: [PATCH 04/25] Added method to detect and update data types --- methodmapize.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/methodmapize.py b/methodmapize.py index ab030d7..2bf1eaf 100644 --- a/methodmapize.py +++ b/methodmapize.py @@ -8,6 +8,16 @@ import re import os.path +def replaceDataType(dataType, code): + pattern = r"(\w+) = new ("+dataType+")" + for m in re.finditer(pattern, code): + var = m.group(1) + var2 = m.group(2) + pattern = r"\w+ " + var + replacement = var2+" "+var + code = re.sub(pattern, replacement, code) + return code + if len(sys.argv) < 2: print('Give at least one file to methodmapize: file1.sp file2.sp ...') sys.exit(1) @@ -340,6 +350,10 @@ # _: int retagging #code = re.sub(r"_:([a-zA-Z0-9_]+(\[[a-zA-Z0-9_]+\])*)", r"view_as(\1)", code) + + dataTypes = ["ArrayList", "ArrayStack", "StringMap", "DataPack", "Transaction", "KeyValues", "Menu", "Panel", "Regex", "SMCParser", "TopMenu"] + for dataType in dataTypes: + code = replaceDataType(dataType, code) with open(sys.argv[i] + '.m', 'w', encoding='utf-8') as f: f.write(code) From 56ae76b608e0c9ebb0e37823f44f59d4aac98db2 Mon Sep 17 00:00:00 2001 From: JoinedSenses Date: Wed, 8 Aug 2018 03:08:26 -0400 Subject: [PATCH 05/25] Fixed GetConVarInt to include FindConVar() --- methodmapize.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/methodmapize.py b/methodmapize.py index 2bf1eaf..f14c95a 100644 --- a/methodmapize.py +++ b/methodmapize.py @@ -120,7 +120,7 @@ def replaceDataType(dataType, code): code = re.sub(r"(? Date: Thu, 9 Aug 2018 19:36:39 -0400 Subject: [PATCH 06/25] Update methodmapize.py --- methodmapize.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/methodmapize.py b/methodmapize.py index f14c95a..1b958e6 100644 --- a/methodmapize.py +++ b/methodmapize.py @@ -13,7 +13,7 @@ def replaceDataType(dataType, code): for m in re.finditer(pattern, code): var = m.group(1) var2 = m.group(2) - pattern = r"\w+ " + var + pattern = r"Handle " + var replacement = var2+" "+var code = re.sub(pattern, replacement, code) return code From 1132b754b86eb4a257fff1ebcac456283a801122 Mon Sep 17 00:00:00 2001 From: JoinedSenses Date: Fri, 10 Aug 2018 23:00:42 -0400 Subject: [PATCH 07/25] Update methodmapize.py --- methodmapize.py | 526 ++++++++++++++++++++++++------------------------ 1 file changed, 263 insertions(+), 263 deletions(-) diff --git a/methodmapize.py b/methodmapize.py index 1b958e6..b5760d5 100644 --- a/methodmapize.py +++ b/methodmapize.py @@ -8,20 +8,20 @@ import re import os.path +if len(sys.argv) < 2: + print('Give at least one file to methodmapize: file1.sp file2.sp ...') + sys.exit(1) + def replaceDataType(dataType, code): - pattern = r"(\w+) = new ("+dataType+")" + pattern = r'(\w+) = new ("+dataType+")' for m in re.finditer(pattern, code): var = m.group(1) var2 = m.group(2) - pattern = r"Handle " + var - replacement = var2+" "+var + pattern = r'(static )*Handle ' + var+r'\b' + replacement = r'\1'+var2+" "+var code = re.sub(pattern, replacement, code) return code -if len(sys.argv) < 2: - print('Give at least one file to methodmapize: file1.sp file2.sp ...') - sys.exit(1) - # Run through all passed files for i in range(1, len(sys.argv)): if not os.path.isfile(sys.argv[i]): @@ -35,321 +35,321 @@ def replaceDataType(dataType, code): print('Methodmapizing {}'.format(sys.argv[i])) # AdminId - code = re.sub(r"(?(\1)", code) + code = re.sub(r'(?(\1)\2', code) dataTypes = ["ArrayList", "ArrayStack", "StringMap", "DataPack", "Transaction", "KeyValues", "Menu", "Panel", "Regex", "SMCParser", "TopMenu"] for dataType in dataTypes: From c220c7271f3c8c7722d611b3c904854264fef8b3 Mon Sep 17 00:00:00 2001 From: JoinedSenses Date: Fri, 10 Aug 2018 23:02:57 -0400 Subject: [PATCH 08/25] Update methodmapize.py --- methodmapize.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/methodmapize.py b/methodmapize.py index b5760d5..132695d 100644 --- a/methodmapize.py +++ b/methodmapize.py @@ -13,7 +13,7 @@ sys.exit(1) def replaceDataType(dataType, code): - pattern = r'(\w+) = new ("+dataType+")' + pattern = r'(\w+) = new ('+dataType+')' for m in re.finditer(pattern, code): var = m.group(1) var2 = m.group(2) From 3d35735c25f5ab06c3b383c663470e2b5e525a84 Mon Sep 17 00:00:00 2001 From: JoinedSenses Date: Sat, 11 Aug 2018 11:04:30 -0400 Subject: [PATCH 09/25] Update methodmapize.py --- methodmapize.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/methodmapize.py b/methodmapize.py index 132695d..2937e04 100644 --- a/methodmapize.py +++ b/methodmapize.py @@ -120,7 +120,7 @@ def replaceDataType(dataType, code): code = re.sub(r'(? Date: Sat, 11 Aug 2018 23:15:50 -0400 Subject: [PATCH 10/25] Fixed ArrayStack type check --- methodmapize.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/methodmapize.py b/methodmapize.py index 2937e04..b3a8edc 100644 --- a/methodmapize.py +++ b/methodmapize.py @@ -82,7 +82,7 @@ def replaceDataType(dataType, code): code = re.sub(r'(? Date: Wed, 15 Aug 2018 00:07:33 -0400 Subject: [PATCH 11/25] Added DirectoryListing Class --- methodmapize.py | 1 + 1 file changed, 1 insertion(+) diff --git a/methodmapize.py b/methodmapize.py index b3a8edc..10ede4a 100644 --- a/methodmapize.py +++ b/methodmapize.py @@ -215,6 +215,7 @@ def replaceDataType(dataType, code): code = re.sub(r'(? Date: Sun, 26 Aug 2018 02:13:57 -0400 Subject: [PATCH 12/25] Update methodmapize.py --- methodmapize.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/methodmapize.py b/methodmapize.py index 10ede4a..1de59cd 100644 --- a/methodmapize.py +++ b/methodmapize.py @@ -4,6 +4,11 @@ # By Peace-Maker # Version 1.0 + +# NOTE: DO NOT RELY ON THIS SCRIPT. IT IS EXPERIMENTAL AND +# STILL IN DEVELOPMENT. ALWAYS DIFFCHECK CHANGES + + import sys import re import os.path From f83e8460e5d9327864ffe59d3ca8cf299e9b7379 Mon Sep 17 00:00:00 2001 From: JoinedSenses Date: Mon, 24 Sep 2018 00:47:39 -0400 Subject: [PATCH 13/25] Update methodmapize.py --- methodmapize.py | 810 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 546 insertions(+), 264 deletions(-) diff --git a/methodmapize.py b/methodmapize.py index 1de59cd..10f42cc 100644 --- a/methodmapize.py +++ b/methodmapize.py @@ -1,8 +1,9 @@ #!/usr/bin/python # Methodmapizer for SourcePawn 1.7+ # Replaces all native calls with their equivalent methodmap call. -# By Peace-Maker -# Version 1.0 +# Replaces old syntax declarations with new syntax +# By Peace-Maker, JoinedSenses +# Version 1.1 # NOTE: DO NOT RELY ON THIS SCRIPT. IT IS EXPERIMENTAL AND @@ -17,16 +18,45 @@ print('Give at least one file to methodmapize: file1.sp file2.sp ...') sys.exit(1) +# Updates Handles to their new class def replaceDataType(dataType, code): - pattern = r'(\w+) = new ('+dataType+')' + pattern = r'(\w+)[ \t]*=[ \t]*new[ \t]+(' + dataType + ')' for m in re.finditer(pattern, code): var = m.group(1) var2 = m.group(2) - pattern = r'(static )*Handle ' + var+r'\b' + pattern = r'(static[ \t]+)*Handle[ \t]+' + var + r'\b' replacement = r'\1'+var2+" "+var code = re.sub(pattern, replacement, code) return code +# Loops regex until it fails to find a result +def reLoop(pattern, repl, code, flags=0): + m = re.search(pattern, code, flags) + while m: + code = re.sub(pattern, repl, code, 0, flags) + m = re.search(pattern, code, flags) + return code + +# Updates convar handles to ConVar class +def replConVar(code): + pattern = r'(\w+) *= *CreateConVar' + for m in re.finditer(pattern, code): + var = m.group(1) + pattern = r'Handle[ \t]+'+var+r'\b' + replacement = r'ConVar ' + var + code = re.sub(pattern, replacement, code) + return code + +# Updates file handles to File class +def replFileType(code): + pattern = r'(\w+)[ \t]*= *OpenFile' + for m in re.finditer(pattern, code): + var = m.group(1) + pattern = r'Handle[ \t]+'+var+r'\b' + replacement = r'File[ \t]+' + var + code = re.sub(pattern, replacement, code) + return code + # Run through all passed files for i in range(1, len(sys.argv)): if not os.path.isfile(sys.argv[i]): @@ -37,329 +67,581 @@ def replaceDataType(dataType, code): with open(sys.argv[i], 'r', encoding='utf-8') as f: code = f.read() + # Formatting stuff. OPTIONAL: DISABLE IF YOU LIKE UGLY THINGS + # ***************************************************************************** + print('\nFormatting {}'.format(sys.argv[i])) + + # This brings curly braces up to the line above it if it's alone on a line (reason: preference/readability) + # function(whatever) + # { + # --------------> + # function(whatever) { + code = re.sub(r'[ \t]*\n[ \t]*\{', r' {', code) + + # These remove spaces inside of brackets & parenthesis (reason: ugly) + # [ WHATEVER + 1 ] -> [WHATEVER + 1] + code = re.sub(r'[ \t]+\]', r']', code) + code = re.sub(r'\[[ \t]+', r'[', code) + code = re.sub(r'[ \t]+\)', r')', code) + code = re.sub(r'\([ \t]+', r'(', code) + code = re.sub(r'[ \t]+\n', r'\n', code) + + # Adds spaces between <>= and characters (reason: preference) + # i<=MaxClients + # --------------> + # i <= MaxClients + code = re.sub(r'(?<=[^<])(\b\w+)([=<>]+)[ \t]*(\w+\b)(?=[^>]+[ \t\(\[\;])(?=(?:[^"]*"[^"]*")*[^"]*$)', r'\1 \2 \3', code) + code = re.sub(r'(?<=[^<])(\b\w+)[ \t]*([=<>]+)(\w+\b)(?=[^>]+[ \t\(\[\;])(?=(?:[^"]*"[^"]*")*[^"]*$)', r'\1 \2 \3', code) + + # Adds a space between comma and character + code = re.sub(r',(\w)', r', \1', code) + + # This adds a space between if/else/while/for and left parenthesis (reason: preference) + # if(whatever) + # --------------> + # if (whatever) + code = re.sub(r'(if|else|while|for)\(', r'\1 (', code) + + # This splits up single line functions without curly braces (reason: ugly/readability) + # if (whatever) doThing; + # --------------> + # if (whatever) + # doThing; + code = re.sub(r'^(\t+)(\w.*?\))( |\t)*(\w)(?=(?:[^\"\n]*\"[^\"\n]*\")*[^\"\n]*$)', r'\1\2\n\1\t\4', code, 0, re.M) + code = re.sub(r'^(\t+)(else)([ \t]+)(?!if)(\w)', r'\1\2\n\1\t\4', code, 0, re.M) + + # This adds curly braces around unbraced single method functions (reason: preference) + # if (whatever) + # doThing; + # --------------> + # if (whatever) { + # doThing; + # } + code = re.sub(r'(^\t+)((?:\w.*?\)|else)[ \t]*)(\n\1\t.*?\;)', r'\1\2 {\3\n\1}', code, 0, re.M) + + # This moves else down a line if next to a right curly brace (reason: preference/readability) + # } else + # --------------> + # } + # else + code = re.sub(r'(\t+)\}[ \t]*(else)', r'\1}\n\1\2', code) + + # This adds curly braces around unbraced else functions (reason: preference) + # else + # whatever; + # --------------> + # else { + # whatever; + # } + code = re.sub(r'(\t+)(else[ \t]*)(\n\1\t.*?\;)', r'\1\2 {\3\n\1}', code) + + # These lines turn single line functions into multi-lined and also split multiple functions(reason: ugly) + # This also brings commands from the side of functions to the top (reason: ease of future regex searches) + # + # if (whatever) { do thing; } // Comment + # --------------> + # // Comment + # if (whatever) { + # do thing; + # } + # * * * * * * * * * * * * * + # doThing1(whatever); doThing2(whatever); + # --------------> + # doThing1(whatever); + # doThing2(whatever); + code = re.sub(r'(^\w.*?)[ \t]*(?(\1)\2', code) - + code = re.sub(r'(?(\1)\2', code) + + # type:whatever -> view_as(whatever) + code = reLoop(r'(=[ \t]*)(\w+):(.*?)(,|;)(?=(?:[^{]*{[^}]*})*[^}]*$)(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)(?=(?:[^\(]*\([^\)]*\))*[^\)]*$)', r'\1view_as<\2>(\3)\4', code, re.M) + + # update function type to void + code = re.sub(r'(\npublic )((?:OnMapTimeLeftChanged|TF2_OnConditionAdded|TF2_OnWaitingForPlayersEnd|TF2_OnWaitingForPlayersStart|TF2_OnConditionRemoved|OnEntityCreated|OnEntityDestroyed|OnMapVoteStarted|OnNominationRemoved|OnClientSayCommand_Post|BaseComm_OnClientGag|OnClientCookiesCached|BaseComm_OnClientMute|OnAdminMenuCreated|OnAdminMenuReady|OnRebuildAdminCache|OnClientAuthorized|OnClientPostAdminCheck|OnClientPostAdminFilter|OnClientPutInServer|OnClientSettingsChanged|OnClientDisconnect_Post|OnClientConnected|OnClientDisconnect|OnAllPluginsLoaded|OnAutoConfigsBuffered|OnClientFloodResult|OnConfigsExecuted|OnGameFrame|OnLibraryAdded|OnLibraryRemoved|OnMapEnd|OnMapStart|OnPluginEnd|OnPluginPauseChange|OnPluginStart|OnServerCfg)[ \t]*\()', r'\1void \2', code) + + # public native -> public int native + for m in re.finditer(r'\bCreateNative\(.*?,[ \t]*(.*?)[ \t]*\)', code): + native = m.group(1) + pattern = r'\npublic '+native+r'\(' + replace = r'\npublic int '+native+r'(' + code = re.sub(pattern, replace, code) + + # public convarChange -> public void convarChange + for m in re.finditer(r'\.AddChangeHook\([ \t]*(.*?)[ \t]*\)', code): + convarChange = m.group(1) + pattern = r'\npublic '+convarChange+r'\( *\w+' + replace = r'\npublic void '+convarChange+r'(ConVar' + code = re.sub(pattern, replace, code) + + # public eventHook -> public void eventHook + for m in re.finditer(r'\bHookEvent(?:Ex)*\(.*?,[ \t]*(.*?)[ \t]*(,|\))', code): + event = m.group(1) + pattern = r'\npublic '+event+r'\([ \t]*\w+' + replace = r'\npublic void '+event+r'(Event' + code = re.sub(pattern, replace, code) + pattern = r'Action(:| +)'+event+r'[ \t]*\(Handle(:| +)' + replace = r'Action '+event+r'(Event ' + code = re.sub(pattern, replace, code) + + # *************************************** + # socket(even though this directly SM, I've included it) + m = re.search(r'\bSocketCreate\([ \t]*.*?[ \t]*,[ \t]*(.*?)[ \t]*\)', code) + if m: + SocketErrorCB = m.group(1) + code = re.sub(r'(\npublic )'+r'([ \t]*\b'+SocketErrorCB+r'\b[ \t]*)', r'\1void \2', code) + + m = re.search(r'\bSocketListen\([ \t]*.*?[ \t]*,[ \t]*(.*?)[ \t]*\)', code) + if m: + SocketIncomingCB = m.group(1) + code = re.sub(r'(\npublic )'+r'([ \t]*\b'+SocketIncomingCB+r'\b[ \t]*)', r'\1void \2', code) + + m = re.search(r'\bSocketSetSendqueueEmptyCallback\([ \t]*.*?[ \t]*,[ \t]*(.*?)[ \t]*\)', code) + if m: + SocketSendqueueEmptyCB = m.group(1) + code = re.sub(r'(\npublic )'+r'([ \t]*\b'+SocketSendqueueEmptyCB+r'\b[ \t]*)', r'\1void \2', code) + + m = re.search(r'\bSocketConnect\([ \t]*.*?[ \t]*,[ \t]*(.*?)[ \t]*,[ \t]*(.*?)[ \t]*,[ \t]*(.*?)[ \t]*,', code) + if m: + SocketConnectCB = m.group(1) + SocketReceiveCB = m.group(2) + SocketDisconnectCB = m.group(3) + code = re.sub(r'(^public[ \t])'+r'([ \t]*\b'+SocketConnectCB+r'\b[ \t]*)', r'\1void \2', code, 0, re.M) + code = re.sub(r'(^public[ \t])'+r'([ \t]*\b'+SocketReceiveCB+r'\b[ \t]*)', r'\1void \2', code, 0, re.M) + code = re.sub(r'(^public[ \t])'+r'([ \t]*\b'+SocketDisconnectCB+r'\b[ \t]*)', r'\1void \2', code, 0, re.M) + # **************************************** + + # Remove deprecated FCVAR_PLUGIN + code = re.sub(r'(?:\|FCVAR_PLUGIN|FCVAR_PLUGIN\|)', r'', code) + code = re.sub(r'FCVAR_PLUGIN', r'0', code) + + # Update invalid_handle to null + code = re.sub(r'INVALID_HANDLE', r'null', code) + + code = re.sub(r'iClient', r'client', code) + + # Check to remove unrequired var type in BuildPath (idk, i saw a plugin do this, so i added it) + code = re.sub(r'(BuildPath\()[ \t]*PathType:*', r'\1', code) + + # String:whatever[] -> char[] whatever + code = re.sub(r'String:*(\w+)(\[\])', r'char\2 \1', code) + + # *********************************************************************************** + # ## Var Declarations ## + # decl String:whatever[1], Float:whatever, whatever; + # --------------> + # char whatever[1]; + # float whatever; + # int whatever; + code = reLoop(r'^([ \t]*)(decl[ \t]+.+), (\w+(?:\[[ \t]*\w+[ \t]*\])?[ \t]*)(?:,[ \t]*|=[ \t]*\-?(?:\d+|\w+)[ \t]*(?:\)|,[ \t]*)|;)(?=(?:[^{]*{[^}]*})*[^}]*$)(?=(?:[^"]*"[^"]*")*[^"]*$)(?=[^)]*$)', r'\1\2;\n\1int \3;\n\1', code, re.M) + code = re.sub(r'(decl\b +)(\w+(?:\[.+?\][ =]*\d*)*)(;|[ \t]*,[ \t]*)', r'\1 int \2\3', code) + code = reLoop(r'^([ \t]*)(decl\b[^(\n]+)(.*?\),|,[ \t]*)(.*?)(;|,[ \t]*)', r'\1\2;\n\1\4;', code, re.M) + code = re.sub(r'decl\b +', r'', code) + # + # Same thing, but for new String:whatever[1], Float:whatever, whatever; + code = reLoop(r'^([ \t]*)(new[ \t]+.+),[ \t]+(\w+(?:\[[ \t]*\w+[ \t]*\])?[ \t]*)(?:,|=[ \t]*\-?(?:\d+|\w+)[ \t]*(?:\)|,)|;)(?=(?:[^{]*{[^}]*})*[^}]*$)(?=(?:[^"]*"[^"]*")*[^"]*$)(?=[^)]*$)', r'\1\2;\n\1int \3;\n\1', code, re.M) + code = re.sub(r'(? char var + code = re.sub(r'(?:new[ \t]+)*String:', r'char ', code) + + # new dataType:whatever -> dataType whatever + code = re.sub(r'new[ \t]+(\w+):', r'\1 ', code) + + # Handle: -> Handle + code = re.sub(r'Handle:',r'Handle ', code) + + # Float -> float + code = re.sub(r'\bFloat\b(:|[ \t]+)', r'float ', code) + + # new var -> int var + code = re.sub(r'(\n\t*)new[ \t]+(\w+([ \t]*\=|\;))', r'\1int \2', code) + + # for (new = -> for (int = + code = re.sub(r'(for[ \t]*\()[ \t]*new', r'\1int', code) + + # dataType:whatever -> dataType whatever + code = re.sub(r'(^.*?\w):(\w.*\()', r'\1 \2', code, 0, re.M) + + # new var -> int var + code = re.sub(r'(? const int var + code = re.sub(r'(,*[ \t]*const) ([\w\d_]+\,)', r'\1 int \2', code) + + # dataType:whatever -> dataType whatever (NOTE TO SELF: reference this for finding things not inside of quotes!) + code = reLoop(r'(\([ \t]*|,[ \t]*)([a-zA-Z]+):(\w[^\"\n,]+(,|\)))', r'\1\2 \3', code) + code = re.sub(r'(^public[ \t]+\w+):(.*?\=)', r'\1 \2', code, 0, re.M) + + # removes colons from bool and any + code = re.sub (r'^(\t*bool):', r'\1 ', code, 0, re.M) + code = re.sub (r'(any):(\.)', r'\1 \2', code) + + # DataType vars + # Handle var -> ConVar var + code = replConVar(code) + # Handle var -> File var + code = replFileType(code) + dataTypes = ["ArrayList", "ArrayStack", "StringMap", "DataPack", "Transaction", "KeyValues", "Menu", "Panel", "Regex", "SMCParser", "TopMenu"] for dataType in dataTypes: code = replaceDataType(dataType, code) - with open(sys.argv[i] + '.m', 'w', encoding='utf-8') as f: + # Handle var -> ArrayList var + for m in re.finditer(r'(\w+)[ \t]*=[ \t]*GetNativeCell', code): + var = m.group(1) + pattern = r'Handle[ \t]+'+var+r'\b' + replace = r'ArrayList '+var + code = re.sub(pattern, replace, code) + + # Redundancy check on converting handles to ArrayList class + re.sub(r'Handle[ \t]+(\w+[ \t]*=[ \t]*GetNativeCell)', r'ArrayList \1', code) + + # public Menu_Handler -> public int Menu_Handler + for m in re.finditer(r'=[ \t]*new Menu\((.*?)(?:,|\))', code): + var = m.group(1) + pattern = r'^(public)[ \t]+'+var+r'[ \t]*\([ \t]*\w+[ \t]+' + replace = r'\1 int '+var+r'(Menu ' + code = re.sub(pattern, replace, code, 0, re.M) + + # This one finds int vars in function declaration and adds `int` in front it the var + code = reLoop(r'^(\w.+?\(.*)(?<=,|\()[ \t]*(&?[\w]+(?:\[\d+\])?[ \t]*(?:,|\)|=[ \t]*\-?(\d+|\w+)[ \t]*(?:\)|,)))(?=(?:[^{]*{[^}]*})*[^}]*$)(?=(?:[^"]*"[^"]*")*[^"]*$)', r'\1 int \2', code, re.M) + + # Redundancy check on removing colons from variables + code = re.sub(r'^(\t*\w+)\:', r'\1 ', code, 0, re.M) + + # Format again. Remove extra spaces. + code = re.sub(r'[ \t]*\n[ \t]*\{', r' {', code) + code = re.sub(r'[ \t]+\]', r']', code) + code = re.sub(r'\[[ \t]+', r'[', code) + code = re.sub(r'[ \t]+\)', r')', code) + code = re.sub(r'\([ \t]+', r'(', code) + code = re.sub(r'[ \t]+\n', r'\n', code) + + + with open(sys.argv[i], 'w', encoding='utf-8') as f: f.write(code) From ab77f6212d7fbccde3b35bdf5c501a527ea72f5c Mon Sep 17 00:00:00 2001 From: JoinedSenses Date: Mon, 24 Sep 2018 19:47:07 -0400 Subject: [PATCH 14/25] Update methodmapize.py --- methodmapize.py | 494 ++++++++++++++++++++++++------------------------ 1 file changed, 247 insertions(+), 247 deletions(-) diff --git a/methodmapize.py b/methodmapize.py index 10f42cc..f218962 100644 --- a/methodmapize.py +++ b/methodmapize.py @@ -3,7 +3,7 @@ # Replaces all native calls with their equivalent methodmap call. # Replaces old syntax declarations with new syntax # By Peace-Maker, JoinedSenses -# Version 1.1 +# Version 1.1Full # NOTE: DO NOT RELY ON THIS SCRIPT. IT IS EXPERIMENTAL AND @@ -162,307 +162,307 @@ def replFileType(code): print('Methodmapizing {}'.format(sys.argv[i])) # AdminId - code = re.sub(r'(?(\1)\2', code) + code = re.sub(r'\b_:(.*?)(,[ \t]*|[)]+|;)', r'view_as(\1)\2', code) # type:whatever -> view_as(whatever) code = reLoop(r'(=[ \t]*)(\w+):(.*?)(,|;)(?=(?:[^{]*{[^}]*})*[^}]*$)(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)(?=(?:[^\(]*\([^\)]*\))*[^\)]*$)', r'\1view_as<\2>(\3)\4', code, re.M) @@ -564,7 +564,7 @@ def replFileType(code): code = re.sub(r'^([ \t]*)new[ \t]+(\w+[ \t:]+\w)', r'\1\2', code, 0, re.M) # ************************************************************************************ - code = re.sub(r'(? char var code = re.sub(r'(?:new[ \t]+)*String:', r'char ', code) From c79f3794d451bde92ee12d36892e8dacf2218edf Mon Sep 17 00:00:00 2001 From: JoinedSenses Date: Mon, 24 Sep 2018 19:50:24 -0400 Subject: [PATCH 15/25] Update methodmapize.py --- methodmapize.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/methodmapize.py b/methodmapize.py index f218962..db3a443 100644 --- a/methodmapize.py +++ b/methodmapize.py @@ -504,7 +504,7 @@ def replFileType(code): code = re.sub(pattern, replace, code) # *************************************** - # socket(even though this directly SM, I've included it) + # socket(even though this isn't included in SM, I've added it) m = re.search(r'\bSocketCreate\([ \t]*.*?[ \t]*,[ \t]*(.*?)[ \t]*\)', code) if m: SocketErrorCB = m.group(1) From 6ee23ec024f16124d79636c803ce9cab3dc497cc Mon Sep 17 00:00:00 2001 From: JoinedSenses Date: Sat, 29 Sep 2018 11:35:40 -0400 Subject: [PATCH 16/25] Update methodmapize.py --- methodmapize.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/methodmapize.py b/methodmapize.py index db3a443..4a5d98e 100644 --- a/methodmapize.py +++ b/methodmapize.py @@ -2,6 +2,7 @@ # Methodmapizer for SourcePawn 1.7+ # Replaces all native calls with their equivalent methodmap call. # Replaces old syntax declarations with new syntax +# Formats code for readability # By Peace-Maker, JoinedSenses # Version 1.1Full @@ -235,9 +236,9 @@ def replFileType(code): code = re.sub(r'\bGetTrieSnapshotKey[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetKey(', code) code = re.sub(r'\bTrieSnapshotLength[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Length', code) - # TODO - # BfRead - # BfWrite + # BfRead/BfWrite + code = re.sub(r'\bBfRead(\w+)\((\w+)[, ]+', r'\2.Read\1(', code) + code = re.sub(r'\bBfWrite(\w+)\((\w+)[, ]+', r'\2.Write\1(', code) # ConVar code = re.sub(r'\bGetConVarBool[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.BoolValue', code) @@ -435,7 +436,8 @@ def replFileType(code): code = re.sub(r'\bGetPanelCurrentKey[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.CurrentKey', code) code = re.sub(r'\bSetPanelCurrentKey[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.CurrentKey = \2', code) - # TODO: Protobuf + # Protobuf + code = re.sub(r'\bPb((?:Add|Read|Set|Get|Remove)\w+)\((\w+)[, ]+', r'\2.\1(', code) # Regex code = re.sub(r'\bCompileRegex[ \t]*\([ \t]*([^\)]*)[ \t]*\)', r'new Regex(\1)', code) From 90e379f78824a3ec3e5c6eff17044724f4f38efa Mon Sep 17 00:00:00 2001 From: JoinedSenses Date: Wed, 24 Oct 2018 22:41:59 -0400 Subject: [PATCH 17/25] Update methodmapize.py --- methodmapize.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/methodmapize.py b/methodmapize.py index 4a5d98e..8b306a5 100644 --- a/methodmapize.py +++ b/methodmapize.py @@ -2,7 +2,6 @@ # Methodmapizer for SourcePawn 1.7+ # Replaces all native calls with their equivalent methodmap call. # Replaces old syntax declarations with new syntax -# Formats code for readability # By Peace-Maker, JoinedSenses # Version 1.1Full @@ -54,7 +53,7 @@ def replFileType(code): for m in re.finditer(pattern, code): var = m.group(1) pattern = r'Handle[ \t]+'+var+r'\b' - replacement = r'File[ \t]+' + var + replacement = r'File ' + var code = re.sub(pattern, replacement, code) return code @@ -237,8 +236,7 @@ def replFileType(code): code = re.sub(r'\bTrieSnapshotLength[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Length', code) # BfRead/BfWrite - code = re.sub(r'\bBfRead(\w+)\((\w+)[, ]+', r'\2.Read\1(', code) - code = re.sub(r'\bBfWrite(\w+)\((\w+)[, ]+', r'\2.Write\1(', code) + code = re.sub(r'\bBf((?:Read|Write)\w+)\((\w+)[, ]*', r'\2.\1(', code) # ConVar code = re.sub(r'\bGetConVarBool[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.BoolValue', code) @@ -437,7 +435,7 @@ def replFileType(code): code = re.sub(r'\bSetPanelCurrentKey[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.CurrentKey = \2', code) # Protobuf - code = re.sub(r'\bPb((?:Add|Read|Set|Get|Remove)\w+)\((\w+)[, ]+', r'\2.\1(', code) + code = re.sub(r'\bPb((?:Add|Read|Set|Get|Remove)\w+)\((\w+)[, ]*', r'\2.\1(', code) # Regex code = re.sub(r'\bCompileRegex[ \t]*\([ \t]*([^\)]*)[ \t]*\)', r'new Regex(\1)', code) @@ -539,7 +537,7 @@ def replFileType(code): # Update invalid_handle to null code = re.sub(r'INVALID_HANDLE', r'null', code) - code = re.sub(r'iClient', r'client', code) + code = re.sub(r'\biClient', r'client', code) # Check to remove unrequired var type in BuildPath (idk, i saw a plugin do this, so i added it) code = re.sub(r'(BuildPath\()[ \t]*PathType:*', r'\1', code) From aed02be1aa97865102de50b4fc04843cb6f120d0 Mon Sep 17 00:00:00 2001 From: JoinedSenses Date: Sun, 18 Nov 2018 01:40:27 -0500 Subject: [PATCH 18/25] Update methodmapize.py --- methodmapize.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/methodmapize.py b/methodmapize.py index 8b306a5..512f141 100644 --- a/methodmapize.py +++ b/methodmapize.py @@ -455,7 +455,7 @@ def replFileType(code): code = re.sub(r'\bCreateTopMenu[ \t]*\([ \t]*([^\)]*)[ \t]*\)', r'new TopMenu(\1)', code) code = re.sub(r'\bLoadTopMenuConfig[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.LoadConfig(', code) code = re.sub(r'\bAddToTopMenu[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\,]+)[ \t]*,[ \t]*TopMenuObject_Category', r'\1.AddCategory(\2, ', code) - code = re.sub(r'\bAddToTopMenu[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\,]+)[ \t]*,[ \t]*TopMenuObject_Item', r'\1.AddItem(\2, ', code) + code = re.sub(r'\bAddToTopMenu[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\,]+)[ \t]*,[ \t]*TopMenuObject_Item', r'\1.AddItem(\2', code) code = re.sub(r'\bGetTopMenuInfoString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetInfoString(', code) code = re.sub(r'\bGetTopMenuObjName[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetObjName(', code) code = re.sub(r'\bRemoveFromTopMenu[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Remove(', code) @@ -644,4 +644,4 @@ def replFileType(code): with open(sys.argv[i], 'w', encoding='utf-8') as f: - f.write(code) + f.write(code) \ No newline at end of file From aa27c5966bf07f0db60c084aa3687d2c49c211f7 Mon Sep 17 00:00:00 2001 From: JoinedSenses Date: Mon, 17 Dec 2018 23:13:38 -0500 Subject: [PATCH 19/25] Update methodmapize.py --- methodmapize.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/methodmapize.py b/methodmapize.py index 512f141..f0dc45e 100644 --- a/methodmapize.py +++ b/methodmapize.py @@ -471,7 +471,7 @@ def replFileType(code): print('Updating syntax on {}'.format(sys.argv[i])) # _: int retagging - code = re.sub(r'\b_:(.*?)(,[ \t]*|[)]+|;)', r'view_as(\1)\2', code) + code = re.sub(r'\b_:(.*?)((?:\]|,)[ \t]*|[)]+|;)', r'view_as(\1)\2', code) # type:whatever -> view_as(whatever) code = reLoop(r'(=[ \t]*)(\w+):(.*?)(,|;)(?=(?:[^{]*{[^}]*})*[^}]*$)(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)(?=(?:[^\(]*\([^\)]*\))*[^\)]*$)', r'\1view_as<\2>(\3)\4', code, re.M) @@ -543,7 +543,7 @@ def replFileType(code): code = re.sub(r'(BuildPath\()[ \t]*PathType:*', r'\1', code) # String:whatever[] -> char[] whatever - code = re.sub(r'String:*(\w+)(\[\])', r'char\2 \1', code) + code = re.sub(r'(? ConVar var + for m in re.finditer(r'([\w_]+)[ \t]*=[ \t]*FindConVar\(', code): + var = m.group(1) + pattern = r'Handle[ \t]'+var+r'\b' + replace = r'ConVar '+var + code = re.sub(pattern, replace, code) + + # Redundancy check on converting handles to ArrayList class re.sub(r'Handle[ \t]+(\w+[ \t]*=[ \t]*GetNativeCell)', r'ArrayList \1', code) @@ -644,4 +652,4 @@ def replFileType(code): with open(sys.argv[i], 'w', encoding='utf-8') as f: - f.write(code) \ No newline at end of file + f.write(code) From 595fa418bc15782bc9602ad600127a4157bbf1b2 Mon Sep 17 00:00:00 2001 From: JoinedSenses Date: Mon, 17 Dec 2018 23:15:52 -0500 Subject: [PATCH 20/25] Update methodmapize.py --- methodmapize.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/methodmapize.py b/methodmapize.py index f0dc45e..2e6c916 100644 --- a/methodmapize.py +++ b/methodmapize.py @@ -621,7 +621,7 @@ def replFileType(code): # Handle var -> ConVar var for m in re.finditer(r'([\w_]+)[ \t]*=[ \t]*FindConVar\(', code): var = m.group(1) - pattern = r'Handle[ \t]'+var+r'\b' + pattern = r'Handle[ \t]+'+var+r'\b' replace = r'ConVar '+var code = re.sub(pattern, replace, code) @@ -652,4 +652,4 @@ def replFileType(code): with open(sys.argv[i], 'w', encoding='utf-8') as f: - f.write(code) + f.write(code) \ No newline at end of file From 96498ebc37c4bf112da9d25f88261f4bb852f458 Mon Sep 17 00:00:00 2001 From: JoinedSenses Date: Mon, 17 Dec 2018 23:16:32 -0500 Subject: [PATCH 21/25] Updated version --- methodmapize.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/methodmapize.py b/methodmapize.py index 2e6c916..31679e6 100644 --- a/methodmapize.py +++ b/methodmapize.py @@ -3,7 +3,7 @@ # Replaces all native calls with their equivalent methodmap call. # Replaces old syntax declarations with new syntax # By Peace-Maker, JoinedSenses -# Version 1.1Full +# Version 1.2Full # NOTE: DO NOT RELY ON THIS SCRIPT. IT IS EXPERIMENTAL AND From 57e5fe94cda11ce6f0141c17a6be3a187501f3e3 Mon Sep 17 00:00:00 2001 From: JoinedSenses Date: Thu, 30 May 2019 23:04:17 -0400 Subject: [PATCH 22/25] Update methodmapize.py --- methodmapize.py | 61 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 49 insertions(+), 12 deletions(-) diff --git a/methodmapize.py b/methodmapize.py index 31679e6..e7d2780 100644 --- a/methodmapize.py +++ b/methodmapize.py @@ -149,13 +149,13 @@ def replFileType(code): # --------------> # doThing1(whatever); # doThing2(whatever); - code = re.sub(r'(^\w.*?)[ \t]*(?(\1)\2', code) - # type:whatever -> view_as(whatever) code = reLoop(r'(=[ \t]*)(\w+):(.*?)(,|;)(?=(?:[^{]*{[^}]*})*[^}]*$)(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)(?=(?:[^\(]*\([^\)]*\))*[^\)]*$)', r'\1view_as<\2>(\3)\4', code, re.M) @@ -560,10 +574,13 @@ def replFileType(code): # Same thing, but for new String:whatever[1], Float:whatever, whatever; code = reLoop(r'^([ \t]*)(new[ \t]+.+),[ \t]+(\w+(?:\[[ \t]*\w+[ \t]*\])?[ \t]*)(?:,|=[ \t]*\-?(?:\d+|\w+)[ \t]*(?:\)|,)|;)(?=(?:[^{]*{[^}]*})*[^}]*$)(?=(?:[^"]*"[^"]*")*[^"]*$)(?=[^)]*$)', r'\1\2;\n\1int \3;\n\1', code, re.M) code = re.sub(r'(?(\1)\2', code) + code = re.sub(r'\bGetClientAuthString\([ \t]*(.*?,)', r'GetClientAuthId(\1 AuthId_Steam2,', code) # new String:var -> char var @@ -607,7 +624,22 @@ def replFileType(code): # Handle var -> File var code = replFileType(code) - dataTypes = ["ArrayList", "ArrayStack", "StringMap", "DataPack", "Transaction", "KeyValues", "Menu", "Panel", "Regex", "SMCParser", "TopMenu"] + dataTypes = [ + "ArrayList" + , "ArrayStack" + , "Cookie" + , "DataPack" + , "GlobalForward" + , "KeyValues" + , "Menu" + , "Panel" + , "PrivateForward" + , "Regex" + , "SMCParser" + , "StringMap" + , "TopMenu" + , "Transaction" + ] for dataType in dataTypes: code = replaceDataType(dataType, code) @@ -625,6 +657,11 @@ def replFileType(code): replace = r'ConVar '+var code = re.sub(pattern, replace, code) + for m in re.finditer(r'([\w_]+)[ \t]*=[ \t]*OpenDirectory\(', code): + var = m.group(1) + pattern = r'Handle[ \t]+'+var+r'\b' + replace = r'DirectoryListing '+var + code = re.sub(pattern, replace, code) # Redundancy check on converting handles to ArrayList class re.sub(r'Handle[ \t]+(\w+[ \t]*=[ \t]*GetNativeCell)', r'ArrayList \1', code) From fd1c444ffac704a728af27fa34d60b7ee4087f39 Mon Sep 17 00:00:00 2001 From: Arron Vinyard Date: Tue, 31 Dec 2019 08:25:21 -0500 Subject: [PATCH 23/25] Update methodmapize.py --- methodmapize.py | 1074 +++++++++++++++++++---------------------------- 1 file changed, 435 insertions(+), 639 deletions(-) diff --git a/methodmapize.py b/methodmapize.py index e7d2780..304bd2d 100644 --- a/methodmapize.py +++ b/methodmapize.py @@ -1,692 +1,488 @@ #!/usr/bin/python # Methodmapizer for SourcePawn 1.7+ # Replaces all native calls with their equivalent methodmap call. -# Replaces old syntax declarations with new syntax # By Peace-Maker, JoinedSenses -# Version 1.2Full +# Version 1.2 -# NOTE: DO NOT RELY ON THIS SCRIPT. IT IS EXPERIMENTAL AND -# STILL IN DEVELOPMENT. ALWAYS DIFFCHECK CHANGES - +# NOTE: DO NOT BLINDLY RELY ON THIS SCRIPT. +# ALWAYS DIFFCHECK CHANGES import sys import re import os.path + if len(sys.argv) < 2: print('Give at least one file to methodmapize: file1.sp file2.sp ...') sys.exit(1) -# Updates Handles to their new class -def replaceDataType(dataType, code): - pattern = r'(\w+)[ \t]*=[ \t]*new[ \t]+(' + dataType + ')' - for m in re.finditer(pattern, code): + +REPLACEMEMTS = lambda : [ + # AdminId + (r'\bBindAdminIdentity[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.BindIdentity('), + (r'\bCanAdminTarget[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.CanTarget('), + (r'\bGetAdminFlags[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetFlags('), + (r'\bGetAdminGroup[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetGroup('), + (r'\bGetAdminPassword[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetPassword('), + (r'\bGetAdminFlag[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.HasFlag('), + (r'\bAdminInheritGroup[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.InheritGroup('), + (r'\bSetAdminPassword[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetPassword('), + (r'\bGetAdminGroupCount[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1\.GroupCount'), + (r'\bGetAdminImmunityLevel[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1\.ImmunityLevel'), + (r'\bSetAdminImmunityLevel[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.ImmunityLevel = \2'), + + #GroupId + (r'\bAddAdmGroupCmdOverride[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.AddCommandOverride('), + (r'\bSetAdmGroupImmuneFrom[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.AddGroupImmunity('), + (r'\bGetAdmGroupCmdOverride[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetCommandOverride('), + (r'\bGetAdmGroupAddFlags[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetFlags('), + (r'\bGetAdmGroupImmunity[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetGroupImmunity('), + (r'\bGetAdmGroupAddFlag[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.HasFlag('), + (r'\bSetAdmGroupAddFlag[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetFlag('), + (r'\bGetAdmGroupImmuneCount[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1\.GroupImmunitiesCount'), + (r'\bGetAdmGroupImmunityLevel[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1\.ImmunityLevel'), + (r'\bSetAdmGroupImmunityLevel[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.ImmunityLevel = \2'), + + # ArrayList + (r'\bClearArray[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Clear()'), + (r'\bCloneArray[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Clone()'), + (r'\bCreateArray[ \t]*\([ \t]*([^\)]*)[ \t]*\)', r'new ArrayList(\1)'), + (r'\bFindStringInArray[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.FindString('), + (r'\bFindValueInArray[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.FindValue('), + (r'\bGetArrayArray[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetArray('), + (r'\bGetArrayCell[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Get('), + (r'\bGetArraySize[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Length'), + (r'\bGetArrayString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetString('), + (r'\bPushArrayArray[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.PushArray('), + (r'\bPushArrayCell[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Push('), + (r'\bPushArrayString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.PushString('), + (r'\bRemoveFromArray[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Erase('), + (r'\bResizeArray[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Resize('), + (r'\bSetArrayArray[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetArray('), + (r'\bSetArrayCell[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Set('), + (r'\bSetArrayString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetString('), + (r'\bShiftArrayUp[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.ShiftUp('), + (r'\bSwapArrayItems[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SwapAt('), + + # ArrayStack + (r'\bCreateStack[ \t]*\([ \t]*([^\)]*)[ \t]*\)', r'new ArrayStack(\1)'), + (r'\bIsStackEmpty[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Empty'), + (r'\bPopStackArray[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.PopArray('), + (r'\bPopStackCell[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Pop('), + (r'\bPopStackString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.PopString('), + (r'\bPushStackArray[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.PushArray('), + (r'\bPushStackCell[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Push('), + (r'\bPushStackString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.PushString('), + + # StringMap + (r'\bCreateTrie[ \t]*\([ \t]*\)', r'new StringMap()'), + (r'\bGetTrieSize[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Size'), + (r'\bClearTrie[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Clear()'), + (r'\bGetTrieString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetString('), + (r'\bSetTrieString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetString('), + (r'\bGetTrieValue[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetValue('), + (r'\bSetTrieValue[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetValue('), + (r'\bGetTrieArray[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetArray('), + (r'\bSetTrieArray[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetArray('), + (r'\bRemoveFromTrie[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Remove('), + + # StringMapSnapshot + (r'\bCreateTrieSnapshot[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Snapshot()'), + (r'\bTrieSnapshotKeyBufferSize[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.KeyBufferSize('), + (r'\bGetTrieSnapshotKey[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetKey('), + (r'\bTrieSnapshotLength[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Length'), + + # BfRead/Write + (r'\bBf((?:Read|Write)\w+)\((\w+)[, ]*', r'\2.\1('), + + # ConVar + (r'\bGetConVarBool[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.BoolValue'), + (r'\bGetConVarBounds[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetBounds('), + (r'\bGetConVarDefault[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetDefault('), + (r'\bGetConVarFlags[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Flags'), + (r'\bGetConVarFloat[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.FloatValue'), + (r'\bGetConVarInt\((FindConVar\(.+?\)|.+?)\)', r'\1.IntValue'), + (r'\bGetConVarName[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetName('), + (r'\bGetConVarString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetString('), + (r'\bHookConVarChange[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.AddChangeHook('), + (r'\bResetConVar[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.RestoreDefault('), + (r'\bSendConVarValue[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.ReplicateToClient('), + (r'\bSetConVarBool[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\,]+)[ \t]*,', r'\1.SetBool(\2,'), + (r'\bSetConVarBool[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.BoolValue = \2'), + (r'\bSetConVarBounds[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetBounds('), + (r'\bSetConVarFlags[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.Flags = \2'), + (r'\bSetConVarFloat[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\,]+)[ \t]*,', r'\1.SetFloat(\2,'), + (r'\bSetConVarFloat[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.FloatValue = \2'), + (r'\bSetConVarInt[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\,]+)[ \t]*,', r'\1.SetInt(\2,'), + (r'\bSetConVarInt[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.IntValue = \2'), + (r'\bSetConVarString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetString('), + (r'\bUnhookConVarChange[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.RemoveChangeHook('), + + # Cookie + (r'\bRegClientCookie[ \t]*\([ \t]*', r'new Cookie('), + (r'\bFindClientCookie[ \t]*\(', r'Cookie.Find('), + (r'\bSetClientCookie[ \t]*\([ \t]*(.*?)[ \t]*,[ \t]*([^\,]+)[ \t]*', r'\2.Set(\1'), + (r'\bGetClientCookie[ \t]*\([ \t]*(.*?)[ \t]*,[ \t]*([^\,]+)[ \t]*', r'\2.Get(\1'), + (r'\bSetAuthIdCookie[ \t]*\([ \t]*(.*?)[ \t]*,[ \t]*([^\,]+)[ \t]*', r'\2.SetByAuthId(\1'), + (r'\bSetCookiePrefabMenu[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetPrefabMenu('), + (r'\bGetCookieAccess[ \t]*\([ \t]*(.*?)[ \t]*\)', r'\1.AccessLevel'), + + # DataPack + (r'\bCreateDataPack[ \t]*\([ \t]*\)', r'new DataPack()'), + (r'\bWritePackCell[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.WriteCell('), + (r'\bWritePackFloat[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.WriteFloat('), + (r'\bWritePackString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.WriteString('), + (r'\bWritePackFunction[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.WriteFunction('), + (r'\bReadPackCell[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.ReadCell()'), + (r'\bReadPackFloat[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.ReadFloat()'), + (r'\bReadPackString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.ReadString('), + (r'\bReadPackFunction[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.ReadFunction()'), + (r'\bResetPack[ \t]*\([ \t]*([^\,\)]+)[ \t]*,?[ \t]*([^\)]*)[ \t]*\)', r'\1.Reset(\2)'), + (r'\bGetPackPosition[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Position'), + (r'\bSetPackPosition[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.Position = \2'), + (r'\bIsStackEmptyckReadable[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.IsReadable('), + + # DBDriver + (r'\bSQL_GetDriver[ \t]*\(', r'DBDriver.Find('), + (r'\bSQL_GetDriverProduct[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetProduct('), + (r'\bSQL_GetDriverIdent[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetIdentifier('), + + # DBResultSet + (r'\bSQL_FetchMoreResults[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.FetchMoreResults()'), + (r'\bSQL_HasResultSet[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.HasResults'), + (r'\bSQL_GetRowCount[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.RowCount'), + (r'\bSQL_GetFieldCount[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.FieldCount'), + (r'\bSQL_GetAffectedRows[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.AffectedRows'), + (r'\bSQL_GetInsertId[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.InsertId'), + (r'\bSQL_FieldNumToName[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.FieldNumToName('), + (r'\bSQL_FieldNameToNum[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.FieldNameToNum('), + (r'\bSQL_FetchRow[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.FetchRow()'), + (r'\bSQL_MoreRows[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.MoreRows'), + (r'\bSQL_Rewind[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Rewind()'), + (r'\bSQL_FetchString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.FetchString('), + (r'\bSQL_FetchFloats*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.FetchFloat('), + (r'\bSQL_FetchInt*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.FetchInt('), + (r'\bSQL_IsFieldNull*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.IsFieldNull('), + (r'\bSQL_FetchSize*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.FetchSize('), + + # Transaction + (r'\bSQL_CreateTransaction[ \t]*\([ \t]*\)', r'new Transaction()'), + (r'\bSQL_AddQuery[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.AddQuery('), + + # Database + (r'\bSQL_TConnect[ \t]*\(', r'Database.Connect('), + (r'\bSQL_ReadDriver[ \t]*\([ \t]*([^\)\,]+)[ \t]*\)', r'\1.Driver'), + (r'\bSQL_SetCharset[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetCharset('), + (r'\bSQL_EscapeString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Escape('), + (r'\bSQL_FormatQuery[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Format('), + (r'\bSQL_IsSameConnection[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.IsSameConnection('), + (r'\bSQL_TQuery[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Query('), + (r'\bSQL_ExecuteTransaction[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Execute('), + + # DBStatement + (r'\bSQL_BindParamInt[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.BindInt('), + (r'\bSQL_BindParamFloat[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.BindFloat('), + (r'\bSQL_BindParamString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.BindString('), + + # DirectoryListing + (r'\b\w+[ \t]+(.*?)[ \t]*=[ \t]*(OpenDirectory)', r'DirectoryListing \1 = \2'), + (r'\bReadDirEntry[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetNext('), + + # Event + (r'\bFireEvent[ \t]*\([ \t]*([^\,\)]+)[ \t]*,?[ \t]*([^\)]*)[ \t]*\)', r'\1.Fire(\2)'), + (r'\bCancelCreatedEvent[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Cancel()'), + (r'\bGetEventBool[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetBool('), + (r'\bSetEventBool[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetBool('), + (r'\bGetEventInt[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetInt('), + (r'\bSetEventInt[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetInt('), + (r'\bGetEventFloat[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetFloat('), + (r'\bSetEventFloat[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetFloat('), + (r'\bGetEventString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetString('), + (r'\bSetEventString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetString('), + (r'\bGetEventName[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetName('), + (r'\bSetEventBroadcast[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.BroadcastDisabled = \2'), + + # File + (r'\bIsEndOfFile[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.EndOfFile()'), + (r'\bReadFile[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Read('), + (r'\bReadFileLine[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.ReadLine('), + (r'\bReadFileString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.ReadString('), + (r'\bFileSeek[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Seek('), + (r'\bWriteFile[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Write('), + (r'\bWriteFileLine[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.WriteLine('), + (r'\bWriteStringLine[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.WriteString('), + (r'\bFilePosition[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Position'), + # TODO: ReadFileCell, ReadIntX + + # Forward + (r'\bCreateGlobalForward[ \t]*\(', r'new GlobalForward('), + (r'\bGetForwardFunctionCount[ \t]*\([ \t]*(.*?)[ \t]*\)', r'\1.FunctionCount'), + + (r'\bCreateForward[ \t]*\(', r'new PrivateForward('), + (r'\bAddToForward[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.AddFunction('), + (r'\bRemoveFromForward[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.RemoveFunction('), + (r'\bRemoveAllFromForward[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.RemoveAllFunctions('), + + # GameData + (r'\bLoadGameConfigFile[ \t]*\(', r'new GameData'), + (r'\bGameConfGetOffset[ \t]*\([ \t]*([^\,]+),[ \t]*', r'\1.GetOffset('), + (r'\bGameConfGetKeyValue[ \t]*\([ \t]*([^\,]+),[ \t]*', r'\1.GetKeyValue('), + (r'\bGameConfGetAddress[ \t]*\([ \t]*([^\,]+),[ \t]*', r'\1.GetAddress('), + + # Handle + (r'\bCloseHandle[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'delete \1'), + + # KeyValue + (r'\bCreateKeyValues[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'new KeyValues(\1)'), + (r'\bKvSetString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetString('), + (r'\bKvSetNum[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetNum('), + (r'\bKvSetUInt64[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetUInt64('), + (r'\bKvSetFloat[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetFloat('), + (r'\bKvSetColor[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetColor('), + (r'\bKvSetVector[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetVector('), + (r'\bKvGetString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetString('), + (r'\bKvGetNum[ \t]*\([ \t]*(.*?)[ \t]*,[ \t]*', r'\1.GetNum('), + (r'\bKvGetFloat[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetFloat('), + (r'\bKvGetColor[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetColor('), + (r'\bKvGetUInt64[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetUInt64('), + (r'\bKvGetVector[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetVector('), + (r'\bKvJumpToKey[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.JumpToKey('), + (r'\bKvJumpToKeySymbol[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.JumpToKeySymbol('), + (r'\bKvGotoFirstSubKey[ \t]*\([ \t]*([^\,\)]+)[ \t]*,?[ \t]*([^\)]*)[ \t]*\)', r'\1.GotoFirstSubKey(\2)'), + (r'\bKvGotoNextKey[ \t]*\([ \t]*([^\,\)]+)[ \t]*,?[ \t]*([^\)]*)[ \t]*\)', r'\1.GotoNextKey(\2)'), + (r'\bKvSavePosition[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.SavePosition()'), + (r'\bKvDeleteKey[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.DeleteKey('), + (r'\bKvDeleteThis[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.DeleteThis()'), + (r'\bKvGoBack[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.GoBack()'), + (r'\bKvRewind[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Rewind()'), + (r'\bKvGetSectionName[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetSectionName('), + (r'\bKvSetSectionName[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetSectionName('), + (r'\bKvGetDataType[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetDataType('), + (r'\bKeyValuesToFile[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.ExportToFile('), + (r'\bFileToKeyValues[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.ImportFromFile('), + (r'\bStringToKeyValues[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.ImportFromString('), + (r'\bKvSetEscapeSequences[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetEscapeSequences('), + (r'\bKvNodesInStack[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.NodesInStack()'), + (r'\bKvCopySubkeys[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Import('), + (r'\bKvFindKeyById[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.FindKeyById('), + (r'\bKvGetNameSymbol[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetNameSymbol('), + (r'\bKvGetSectionSymbol[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetSectionSymbol('), + + # Menu + (r'\bCreateMenu[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'new Menu(\1)'), + (r'\bDisplayMenu[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Display('), + (r'\bDisplayMenuAtItem[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.DisplayAt('), + (r'\bAddMenuItem[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.AddItem('), + (r'\bInsertMenuItem[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.InsertItem('), + (r'\bRemoveMenuItem[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.RemoveItem('), + (r'\bRemoveAllMenuItems[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.RemoveAllItems()'), + (r'\bGetMenuItem[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetItem('), + (r'\bGetMenuSelectionPosition[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Selection'), + (r'\bGetMenuItemCount[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.ItemCount'), + (r'\bSetMenuPagination[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.Pagination = \2'), + (r'\bGetMenuPagination[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Pagination'), + (r'\bGetMenuStyle[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Style'), + (r'\bSetMenuTitle[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetTitle('), + (r'\bGetMenuTitle[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetTitle('), + (r'\bCreatePanelFromMenu[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.ToPanel()'), + (r'\bGetMenuExitButton[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.ExitButton'), + (r'\bSetMenuExitButton[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.ExitButton = \2'), + (r'\bGetMenuExitBackButton[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.ExitBackButton'), + (r'\bSetMenuExitBackButton[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.ExitBackButton = \2'), + (r'\bSetMenuNoVoteButton[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.NoVoteButton = \2'), + (r'\bCancelMenu[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Cancel()'), + (r'\bGetMenuOptionFlags[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.OptionFlags'), + (r'\bSetMenuOptionFlags[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.OptionFlags = \2'), + (r'\bVoteMenu[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.DisplayVote('), + (r'\bVoteMenuToAll[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.DisplayVoteToAll('), + (r'\bSetVoteResultCallback[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.VoteResultCallback = \2'), + + # Panel + (r'\bCreatePanel[ \t]*\([ \t]*([^\)]*)[ \t]*\)', r'new Panel(\1)'), + (r'\bGetPanelStyle[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Style'), + (r'\bSetPanelTitle[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetTitle('), + (r'\bDrawPanelItem[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.DrawItem('), + (r'\bDrawPanelText[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.DrawText('), + (r'\bCanPanelDrawFlags[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.CanDrawFlags('), + (r'\bSetPanelKeys[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetKeys('), + (r'\bSendPanelToClient[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Send('), + (r'\bGetPanelTextRemaining[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.TextRemaining'), + (r'\bGetPanelCurrentKey[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.CurrentKey'), + (r'\bSetPanelCurrentKey[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.CurrentKey = \2'), + + # Profiler + (r'\bCreateProfiler[ \t]*\([ \t]*\)', r'new Profiler()'), + (r'\bStartProfiling[ \t]*\([ \t]*(.*?)[ \t]*\)', r'\1.Start()'), + (r'\bStopProfiling[ \t]*\([ \t]*(.*?)[ \t]*\)', r'\1.Stop()'), + (r'\bGetProfilerTime[ \t]*\([ \t]*(.*?)[ \t]*\)', r'\1.Time'), + + # Protobuf + (r'\bPb((?:Add|Read|Set|Get|Remove)\w+)\((\w+)[, ]*', r'\2.\1('), + + # Regex + (r'\bCompileRegex[ \t]*\([ \t]*([^\)]*)[ \t]*\)', r'new Regex(\1)'), + (r'\bMatchRegex[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Match('), + (r'\bGetRegexSubString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetSubString('), + + # SMCParser + (r'\bSMC_CreateParser[ \t]*\([ \t]*\)', r'new SMCParser()'), + (r'\bSMC_ParseFile[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.ParseFile('), + (r'\bSMC_SetParseStart[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.OnStart = \2'), + (r'\bSMC_SetParseEnd[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.OnEnd = \2'), + (r'([ \t]+)SMC_SetReaders\((\w+),[ \t]*(\w+),[ \t]*(\w+),[ \t]*(\w+).*', r'\1\2.OnEnterSection = \3;\n\1\2.OnKeyValue = \4;\n\1\2.OnLeaveSection = \5;'), + (r'\bSMC_SetRawLine[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.OnRawLine = \2'), + # Can't update SMC_GetErrorString with regex + + # TopMenu + (r'\bCreateTopMenu[ \t]*\([ \t]*([^\)]*)[ \t]*\)', r'new TopMenu(\1)'), + (r'\bLoadTopMenuConfig[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.LoadConfig('), + (r'\bAddToTopMenu[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\,]+)[ \t]*,[ \t]*TopMenuObject_Category', r'\1.AddCategory(\2, '), + (r'\bAddToTopMenu[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\,]+)[ \t]*,[ \t]*TopMenuObject_Item', r'\1.AddItem(\2, '), + (r'\bGetTopMenuInfoString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetInfoString('), + (r'\bGetTopMenuObjName[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetObjName('), + (r'\bRemoveFromTopMenu[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Remove('), + (r'\bDisplayTopMenu[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Display('), + (r'\bDisplayTopMenuCategory[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.DisplayCategory('), + (r'\bFindTopMenuCategory[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.FindCategory('), + (r'\bSetTopMenuTitleCaching[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.CacheTitles = \2'), +] + + +METHODMAPS_NO_NEW = lambda : [ + ('ArrayList', 'CloneArray'), + ('ConVar', 'CreateConVar'), + ('ConVar', 'FindConVar'), + ('Cookie', 'FindClientCookie'), + ('DirectoryListing', 'OpenDirectory'), + ('Event', 'CreateEvent'), + ('File', 'OpenFile'), + ('Protobuf', 'PbAddMessage'), +] + + +METHODMAPS = lambda : [ + 'ArrayList', + 'ArrayStack', + 'Cookie', + 'DataPack', + 'GameData', + 'GlobalForward', + 'KeyValues', + 'Menu', + 'Panel', + 'PrivateForward', + 'Profiler', + 'Regex', + 'SMCParser', + 'StringMap', + 'TopMenu', + 'Transaction' +] + + +# Updates Handles to their methodmap +def updateHandle(dataType, func, code): + for m in re.finditer(r'(\w+)[ \t]*=[ \t]*' + func, code): var = m.group(1) - var2 = m.group(2) - pattern = r'(static[ \t]+)*Handle[ \t]+' + var + r'\b' - replacement = r'\1'+var2+" "+var - code = re.sub(pattern, replacement, code) - return code + pattern = r'Handle[ \t]+' + var + r'\b' + replace = dataType + ' ' + var + code = re.sub(pattern, replace, code) -# Loops regex until it fails to find a result -def reLoop(pattern, repl, code, flags=0): - m = re.search(pattern, code, flags) - while m: - code = re.sub(pattern, repl, code, 0, flags) - m = re.search(pattern, code, flags) return code -# Updates convar handles to ConVar class -def replConVar(code): - pattern = r'(\w+) *= *CreateConVar' - for m in re.finditer(pattern, code): - var = m.group(1) - pattern = r'Handle[ \t]+'+var+r'\b' - replacement = r'ConVar ' + var - code = re.sub(pattern, replacement, code) - return code -# Updates file handles to File class -def replFileType(code): - pattern = r'(\w+)[ \t]*= *OpenFile' - for m in re.finditer(pattern, code): - var = m.group(1) - pattern = r'Handle[ \t]+'+var+r'\b' - replacement = r'File ' + var +# Updates Handles to their methodmap (searches for `= new`) +def updateMethodmap(dataType, code): + for m in re.finditer(r'(\w+)[ \t]*=[ \t]*new[ \t]+(' + dataType + ')', code): + var1 = m.group(1) + var2 = m.group(2) + + pattern = r'(static[ \t]+)?Handle[ \t]+' + var1 + r'\b' + replacement = r'\1' + var2 + ' ' + var1 + code = re.sub(pattern, replacement, code) + return code -# Run through all passed files + for i in range(1, len(sys.argv)): if not os.path.isfile(sys.argv[i]): print('File not found: {}'.format(sys.argv[i])) continue code = '' - with open(sys.argv[i], 'r', encoding='utf-8') as f: + + with open(sys.argv[i], 'r', encoding = 'utf-8') as f: + print('Methodmapizing {}'.format(sys.argv[i])) + code = f.read() - # Formatting stuff. OPTIONAL: DISABLE IF YOU LIKE UGLY THINGS - # ***************************************************************************** - print('\nFormatting {}'.format(sys.argv[i])) - - # This brings curly braces up to the line above it if it's alone on a line (reason: preference/readability) - # function(whatever) - # { - # --------------> - # function(whatever) { - code = re.sub(r'[ \t]*\n[ \t]*\{', r' {', code) - - # These remove spaces inside of brackets & parenthesis (reason: ugly) - # [ WHATEVER + 1 ] -> [WHATEVER + 1] - code = re.sub(r'[ \t]+\]', r']', code) - code = re.sub(r'\[[ \t]+', r'[', code) - code = re.sub(r'[ \t]+\)', r')', code) - code = re.sub(r'\([ \t]+', r'(', code) - code = re.sub(r'[ \t]+\n', r'\n', code) - - # Adds spaces between <>= and characters (reason: preference) - # i<=MaxClients - # --------------> - # i <= MaxClients - code = re.sub(r'(?<=[^<])(\b\w+)([=<>]+)[ \t]*(\w+\b)(?=[^>]+[ \t\(\[\;])(?=(?:[^"]*"[^"]*")*[^"]*$)', r'\1 \2 \3', code) - code = re.sub(r'(?<=[^<])(\b\w+)[ \t]*([=<>]+)(\w+\b)(?=[^>]+[ \t\(\[\;])(?=(?:[^"]*"[^"]*")*[^"]*$)', r'\1 \2 \3', code) - - # Adds a space between comma and character - code = re.sub(r',(\w)', r', \1', code) - - # This adds a space between if/else/while/for and left parenthesis (reason: preference) - # if(whatever) - # --------------> - # if (whatever) - code = re.sub(r'(if|else|while|for)\(', r'\1 (', code) - - # This splits up single line functions without curly braces (reason: ugly/readability) - # if (whatever) doThing; - # --------------> - # if (whatever) - # doThing; - code = re.sub(r'^(\t+)(\w.*?\))( |\t)*(\w)(?=(?:[^\"\n]*\"[^\"\n]*\")*[^\"\n]*$)', r'\1\2\n\1\t\4', code, 0, re.M) - code = re.sub(r'^(\t+)(else)([ \t]+)(?!if)(\w)', r'\1\2\n\1\t\4', code, 0, re.M) - - # This adds curly braces around unbraced single method functions (reason: preference) - # if (whatever) - # doThing; - # --------------> - # if (whatever) { - # doThing; - # } - code = re.sub(r'(^\t+)((?:\w.*?\)|else)[ \t]*)(\n\1\t.*?\;)', r'\1\2 {\3\n\1}', code, 0, re.M) - - # This moves else down a line if next to a right curly brace (reason: preference/readability) - # } else - # --------------> - # } - # else - code = re.sub(r'(\t+)\}[ \t]*(else)', r'\1}\n\1\2', code) - - # This adds curly braces around unbraced else functions (reason: preference) - # else - # whatever; - # --------------> - # else { - # whatever; - # } - code = re.sub(r'(\t+)(else[ \t]*)(\n\1\t.*?\;)', r'\1\2 {\3\n\1}', code) - - # These lines turn single line functions into multi-lined and also split multiple functions(reason: ugly) - # This also brings commands from the side of functions to the top (reason: ease of future regex searches) - # - # if (whatever) { do thing; } // Comment - # --------------> - # // Comment - # if (whatever) { - # do thing; - # } - # * * * * * * * * * * * * * - # doThing1(whatever); doThing2(whatever); - # --------------> - # doThing1(whatever); - # doThing2(whatever); - code = re.sub(r'(^\w.*?)[ \t]*(? Handle + code = re.sub(r'(\bnew[ \t]+)?Handle:', 'Handle ', code) - print('Methodmapizing {}'.format(sys.argv[i])) - # AdminId - code = re.sub(r'\bBindAdminIdentity[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.BindIdentity(', code) - code = re.sub(r'\bCanAdminTarget[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.CanTarget(', code) - code = re.sub(r'\bGetAdminFlags[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetFlags(', code) - code = re.sub(r'\bGetAdminGroup[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetGroup(', code) - code = re.sub(r'\bGetAdminPassword[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetPassword(', code) - code = re.sub(r'\bGetAdminFlag[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.HasFlag(', code) - code = re.sub(r'\bAdminInheritGroup[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.InheritGroup(', code) - code = re.sub(r'\bSetAdminPassword[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetPassword(', code) - code = re.sub(r'\bGetAdminGroupCount[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1\.GroupCount', code) - code = re.sub(r'\bGetAdminImmunityLevel[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1\.ImmunityLevel', code) - code = re.sub(r'\bSetAdminImmunityLevel[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.ImmunityLevel = \2', code) - - # GroupId - code = re.sub(r'\bAddAdmGroupCmdOverride[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.AddCommandOverride(', code) - code = re.sub(r'\bSetAdmGroupImmuneFrom[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.AddGroupImmunity(', code) - code = re.sub(r'\bGetAdmGroupCmdOverride[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetCommandOverride(', code) - code = re.sub(r'\bGetAdmGroupAddFlags[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetFlags(', code) - code = re.sub(r'\bGetAdmGroupImmunity[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetGroupImmunity(', code) - code = re.sub(r'\bGetAdmGroupAddFlag[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.HasFlag(', code) - code = re.sub(r'\bSetAdmGroupAddFlag[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetFlag(', code) - code = re.sub(r'\bGetAdmGroupImmuneCount[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1\.GroupImmunitiesCount', code) - code = re.sub(r'\bGetAdmGroupImmunityLevel[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1\.ImmunityLevel', code) - code = re.sub(r'\bSetAdmGroupImmunityLevel[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.ImmunityLevel = \2', code) - - # ArrayList - code = re.sub(r'\bClearArray[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Clear()', code) - code = re.sub(r'\bCloneArray[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Clone()', code) - code = re.sub(r'\bCreateArray[ \t]*\([ \t]*([^\)]*)[ \t]*\)', r'new ArrayList(\1)', code) - code = re.sub(r'\bFindStringInArray[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.FindString(', code) - code = re.sub(r'\bFindValueInArray[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.FindValue(', code) - code = re.sub(r'\bGetArrayArray[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetArray(', code) - code = re.sub(r'\bGetArrayCell[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Get(', code) - code = re.sub(r'\bGetArraySize[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Length', code) - code = re.sub(r'\bGetArrayString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetString(', code) - code = re.sub(r'\bPushArrayArray[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.PushArray(', code) - code = re.sub(r'\bPushArrayCell[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Push(', code) - code = re.sub(r'\bPushArrayString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.PushString(', code) - code = re.sub(r'\bRemoveFromArray[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Erase(', code) - code = re.sub(r'\bResizeArray[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Resize(', code) - code = re.sub(r'\bSetArrayArray[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetArray(', code) - code = re.sub(r'\bSetArrayCell[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Set(', code) - code = re.sub(r'\bSetArrayString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetString(', code) - code = re.sub(r'\bShiftArrayUp[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.ShiftUp(', code) - code = re.sub(r'\bSwapArrayItems[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SwapAt(', code) - - # ArrayStack - code = re.sub(r'\bCreateStack[ \t]*\([ \t]*([^\)]*)[ \t]*\)', r'new ArrayStack(\1)', code) - code = re.sub(r'\bIsStackEmpty[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Empty', code) - code = re.sub(r'\bPopStackArray[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.PopArray(', code) - code = re.sub(r'\bPopStackCell[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Pop(', code) - code = re.sub(r'\bPopStackString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.PopString(', code) - code = re.sub(r'\bPushStackArray[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.PushArray(', code) - code = re.sub(r'\bPushStackCell[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Push(', code) - code = re.sub(r'\bPushStackString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.PushString(', code) - - # StringMap - code = re.sub(r'\bCreateTrie[ \t]*\([ \t]*\)', r'new StringMap()', code) - code = re.sub(r'\bGetTrieSize[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Size', code) - code = re.sub(r'\bClearTrie[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Clear()', code) - code = re.sub(r'\bGetTrieString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetString(', code) - code = re.sub(r'\bSetTrieString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetString(', code) - code = re.sub(r'\bGetTrieValue[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetValue(', code) - code = re.sub(r'\bSetTrieValue[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetValue(', code) - code = re.sub(r'\bGetTrieArray[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetArray(', code) - code = re.sub(r'\bSetTrieArray[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetArray(', code) - code = re.sub(r'\bRemoveFromTrie[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Remove(', code) - - # StringMapSnapshot - code = re.sub(r'\bCreateTrieSnapshot[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Snapshot()', code) - code = re.sub(r'\bTrieSnapshotKeyBufferSize[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.KeyBufferSize(', code) - code = re.sub(r'\bGetTrieSnapshotKey[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetKey(', code) - code = re.sub(r'\bTrieSnapshotLength[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Length', code) - - # BfRead/BfWrite - code = re.sub(r'\bBf((?:Read|Write)\w+)\((\w+)[, ]*', r'\2.\1(', code) - - # ConVar - code = re.sub(r'\bGetConVarBool[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.BoolValue', code) - code = re.sub(r'\bGetConVarBounds[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetBounds(', code) - code = re.sub(r'\bGetConVarDefault[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetDefault(', code) - code = re.sub(r'\bGetConVarFlags[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Flags', code) - code = re.sub(r'\bGetConVarFloat[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.FloatValue', code) - code = re.sub(r'\bGetConVarInt\((FindConVar\(.+?\)|.+?)\)', r'\1.IntValue', code) - code = re.sub(r'\bGetConVarName[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetName(', code) - code = re.sub(r'\bGetConVarString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetString(', code) - code = re.sub(r'\bHookConVarChange[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.AddChangeHook(', code) - code = re.sub(r'\bResetConVar[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.RestoreDefault(', code) - code = re.sub(r'\bSendConVarValue[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.ReplicateToClient(', code) - - # Only use the method if the original call has more than 2 parameters. - code = re.sub(r'\bSetConVarBool[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\,]+)[ \t]*,', r'\1.SetBool(\2,', code) - code = re.sub(r'\bSetConVarBool[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.BoolValue = \2', code) - - code = re.sub(r'\bSetConVarBounds[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetBounds(', code) - code = re.sub(r'\bSetConVarFlags[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.Flags = \2', code) - - code = re.sub(r'\bSetConVarFloat[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\,]+)[ \t]*,', r'\1.SetFloat(\2,', code) - code = re.sub(r'\bSetConVarFloat[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.FloatValue = \2', code) - code = re.sub(r'\bSetConVarInt[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\,]+)[ \t]*,', r'\1.SetInt(\2,', code) - code = re.sub(r'\bSetConVarInt[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.IntValue = \2', code) - code = re.sub(r'\bSetConVarString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetString(', code) - code = re.sub(r'\bUnhookConVarChange[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.RemoveChangeHook(', code) - - # Cookie - code = re.sub(r'\bRegClientCookie[ \t]*\([ \t]*\)', r'new Cookie(', code) - code = re.sub(r'\bFindClientCookie[ \t]*\(', r'Cookie.Find(', code) - code = re.sub(r'\bSetClientCookie[ \t]*\([ \t]*(.*?)[ \t]*,[ \t]*([^\,]+)[ \t]*', r'\2.Set(\1', code) - code = re.sub(r'\bGetClientCookie[ \t]*\([ \t]*(.*?)[ \t]*,[ \t]*([^\,]+)[ \t]*', r'\2.Get(\1', code) - code = re.sub(r'\bSetAuthIdCookie[ \t]*\([ \t]*(.*?)[ \t]*,[ \t]*([^\,]+)[ \t]*', r'\2.SetByAuthId(\1', code) - code = re.sub(r'\bSetCookiePrefabMenu[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetPrefabMenu(', code) - code = re.sub(r'\bGetCookieAccess[ \t]*\([ \t]*(.*?)[ \t]*\)', r'\1.AccessLevel', code) - - # DataPack - code = re.sub(r'\bCreateDataPack[ \t]*\([ \t]*\)', r'new DataPack()', code) - code = re.sub(r'\bWritePackCell[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.WriteCell(', code) - code = re.sub(r'\bWritePackFloat[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.WriteFloat(', code) - code = re.sub(r'\bWritePackString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.WriteString(', code) - code = re.sub(r'\bWritePackFunction[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.WriteFunction(', code) - code = re.sub(r'\bReadPackCell[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.ReadCell()', code) - code = re.sub(r'\bReadPackFloat[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.ReadFloat()', code) - code = re.sub(r'\bReadPackString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.ReadString(', code) - code = re.sub(r'\bReadPackFunction[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.ReadFunction()', code) - code = re.sub(r'\bResetPack[ \t]*\([ \t]*([^\,\)]+)[ \t]*,?[ \t]*([^\)]*)[ \t]*\)', r'\1.Reset(\2)', code) - code = re.sub(r'\bGetPackPosition[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Position', code) - code = re.sub(r'\bSetPackPosition[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.Position = \2', code) - code = re.sub(r'\bIsStackEmptyckReadable[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.IsReadable(', code) - - # DBDriver - code = re.sub(r'\bSQL_GetDriver[ \t]*\(', r'DBDriver.Find(', code) - code = re.sub(r'\bSQL_GetDriverProduct[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetProduct(', code) - code = re.sub(r'\bSQL_GetDriverIdent[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetIdentifier(', code) - - # DBResultSet - code = re.sub(r'\bSQL_FetchMoreResults[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.FetchMoreResults()', code) - code = re.sub(r'\bSQL_HasResultSet[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.HasResults', code) - code = re.sub(r'\bSQL_GetRowCount[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.RowCount', code) - code = re.sub(r'\bSQL_GetFieldCount[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.FieldCount', code) - code = re.sub(r'\bSQL_GetAffectedRows[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.AffectedRows', code) - code = re.sub(r'\bSQL_GetInsertId[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.InsertId', code) - code = re.sub(r'\bSQL_FieldNumToName[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.FieldNumToName(', code) - code = re.sub(r'\bSQL_FieldNameToNum[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.FieldNameToNum(', code) - code = re.sub(r'\bSQL_FetchRow[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.FetchRow()', code) - code = re.sub(r'\bSQL_MoreRows[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.MoreRows', code) - code = re.sub(r'\bSQL_Rewind[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Rewind()', code) - code = re.sub(r'\bSQL_FetchString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.FetchString(', code) - code = re.sub(r'\bSQL_FetchFloats*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.FetchFloat(', code) - code = re.sub(r'\bSQL_FetchInt*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.FetchInt(', code) - code = re.sub(r'\bSQL_IsFieldNull*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.IsFieldNull(', code) - code = re.sub(r'\bSQL_FetchSize*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.FetchSize(', code) - - # Transaction - code = re.sub(r'\bSQL_CreateTransaction[ \t]*\([ \t]*\)', r'new Transaction()', code) - code = re.sub(r'\bSQL_AddQuery[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.AddQuery(', code) - - # DBStatement - code = re.sub(r'\bSQL_BindParamInt[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.BindInt(', code) - code = re.sub(r'\bSQL_BindParamFloat[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.BindFloat(', code) - code = re.sub(r'\bSQL_BindParamString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.BindString(', code) - - # Database - code = re.sub(r'\bSQL_TConnect[ \t]*\(', r'Database.Connect(', code) - # Only replace if the optional ident argument isn't used. - code = re.sub(r'\bSQL_ReadDriver[ \t]*\([ \t]*([^\)\,]+)[ \t]*\)', r'\1.Driver', code) - code = re.sub(r'\bSQL_SetCharset[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetCharset(', code) - code = re.sub(r'\bSQL_EscapeString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Escape(', code) - code = re.sub(r'\bSQL_FormatQuery[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Format(', code) - code = re.sub(r'\bSQL_IsSameConnection[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.IsSameConnection(', code) - code = re.sub(r'\bSQL_TQuery[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Query(', code) - code = re.sub(r'\bSQL_ExecuteTransaction[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Execute(', code) - - # Event - code = re.sub(r'\bFireEvent[ \t]*\([ \t]*([^\,\)]+)[ \t]*,?[ \t]*([^\)]*)[ \t]*\)', r'\1.Fire(\2)', code) - code = re.sub(r'\bCancelCreatedEvent[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Cancel()', code) - code = re.sub(r'\bGetEventBool[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetBool(', code) - code = re.sub(r'\bSetEventBool[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetBool(', code) - code = re.sub(r'\bGetEventInt[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetInt(', code) - code = re.sub(r'\bSetEventInt[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetInt(', code) - code = re.sub(r'\bGetEventFloat[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetFloat(', code) - code = re.sub(r'\bSetEventFloat[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetFloat(', code) - code = re.sub(r'\bGetEventString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetString(', code) - code = re.sub(r'\bSetEventString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetString(', code) - code = re.sub(r'\bGetEventName[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetName(', code) - code = re.sub(r'\bSetEventBroadcast[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.BroadcastDisabled = \2', code) - - # DirectoryListing - code = re.sub(r'\bReadDirEntry[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetNext(', code) - - # File - code = re.sub(r'\bIsEndOfFile[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.EndOfFile()', code) - code = re.sub(r'\bReadFile[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Read(', code) - code = re.sub(r'\bReadFileLine[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.ReadLine(', code) - code = re.sub(r'\bReadFileString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.ReadString(', code) - code = re.sub(r'\bFileSeek[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Seek(', code) - code = re.sub(r'\bWriteFile[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Write(', code) - code = re.sub(r'\bWriteFileLine[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.WriteLine(', code) - code = re.sub(r'\bWriteStringLine[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.WriteString(', code) - code = re.sub(r'\bFilePosition[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Position', code) - # TODO: ReadFileCell & ReadIntX - - # Forwards - code = re.sub(r'\bCreateGlobalForward[ \t]*\(', r'new GlobalForward(', code) - code = re.sub(r'\bGetForwardFunctionCount[ \t]*\([ \t]*(.*?)[ \t]*\)', r'\1.FunctionCount', code) - - code = re.sub(r'\bCreateForward[ \t]*\(', r'new PrivateForward(', code) - code = re.sub(r'\bAddToForward[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.AddFunction(', code) - code = re.sub(r'\bRemoveFromForward[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.RemoveFunction(', code) - code = re.sub(r'\bRemoveAllFromForward[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.RemoveAllFunctions(', code) - - # Handles - code = re.sub(r'\bCloseHandle[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'delete \1', code) - - # KeyValues - code = re.sub(r'\bCreateKeyValues[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'new KeyValues(\1)', code) - code = re.sub(r'\bKvSetString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetString(', code) - code = re.sub(r'\bKvSetNum[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetNum(', code) - code = re.sub(r'\bKvSetUInt64[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetUInt64(', code) - code = re.sub(r'\bKvSetFloat[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetFloat(', code) - code = re.sub(r'\bKvSetColor[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetColor(', code) - code = re.sub(r'\bKvSetVector[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetVector(', code) - code = re.sub(r'\bKvGetString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetString(', code) - code = re.sub(r'\bKvGetNum[ \t]*\([ \t]*(.*?)[ \t]*,[ \t]*', r'\1.GetNum(', code) - code = re.sub(r'\bKvGetFloat[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetFloat(', code) - code = re.sub(r'\bKvGetColor[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetColor(', code) - code = re.sub(r'\bKvGetUInt64[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetUInt64(', code) - code = re.sub(r'\bKvGetVector[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetVector(', code) - code = re.sub(r'\bKvJumpToKey[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.JumpToKey(', code) - code = re.sub(r'\bKvJumpToKeySymbol[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.JumpToKeySymbol(', code) - code = re.sub(r'\bKvGotoFirstSubKey[ \t]*\([ \t]*([^\,\)]+)[ \t]*,?[ \t]*([^\)]*)[ \t]*\)', r'\1.GotoFirstSubKey(\2)', code) - code = re.sub(r'\bKvGotoNextKey[ \t]*\([ \t]*([^\,\)]+)[ \t]*,?[ \t]*([^\)]*)[ \t]*\)', r'\1.GotoNextKey(\2)', code) - code = re.sub(r'\bKvSavePosition[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.SavePosition()', code) - code = re.sub(r'\bKvDeleteKey[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.DeleteKey(', code) - code = re.sub(r'\bKvDeleteThis[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.DeleteThis()', code) - code = re.sub(r'\bKvGoBack[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.GoBack()', code) - code = re.sub(r'\bKvRewind[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Rewind()', code) - code = re.sub(r'\bKvGetSectionName[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetSectionName(', code) - code = re.sub(r'\bKvSetSectionName[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetSectionName(', code) - code = re.sub(r'\bKvGetDataType[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetDataType(', code) - code = re.sub(r'\bKeyValuesToFile[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.ExportToFile(', code) - code = re.sub(r'\bFileToKeyValues[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.ImportFromFile(', code) - code = re.sub(r'\bStringToKeyValues[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.ImportFromString(', code) - code = re.sub(r'\bKvSetEscapeSequences[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetEscapeSequences(', code) - code = re.sub(r'\bKvNodesInStack[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.NodesInStack()', code) - code = re.sub(r'\bKvCopySubkeys[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Import(', code) - code = re.sub(r'\bKvFindKeyById[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.FindKeyById(', code) - code = re.sub(r'\bKvGetNameSymbol[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetNameSymbol(', code) - code = re.sub(r'\bKvGetSectionSymbol[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetSectionSymbol(', code) - - # Menu - code = re.sub(r'\bCreateMenu[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'new Menu(\1)', code) - code = re.sub(r'\bDisplayMenu[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Display(', code) - code = re.sub(r'\bDisplayMenuAtItem[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.DisplayAt(', code) - code = re.sub(r'\bAddMenuItem[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.AddItem(', code) - code = re.sub(r'\bInsertMenuItem[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.InsertItem(', code) - code = re.sub(r'\bRemoveMenuItem[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.RemoveItem(', code) - code = re.sub(r'\bRemoveAllMenuItems[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.RemoveAllItems()', code) - code = re.sub(r'\bGetMenuItem[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetItem(', code) - code = re.sub(r'\bGetMenuSelectionPosition[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Selection', code) - code = re.sub(r'\bGetMenuItemCount[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.ItemCount', code) - code = re.sub(r'\bSetMenuPagination[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.Pagination = \2', code) - code = re.sub(r'\bGetMenuPagination[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Pagination', code) - code = re.sub(r'\bGetMenuStyle[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Style', code) - code = re.sub(r'\bSetMenuTitle[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetTitle(', code) - code = re.sub(r'\bGetMenuTitle[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetTitle(', code) - code = re.sub(r'\bCreatePanelFromMenu[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.ToPanel()', code) - code = re.sub(r'\bGetMenuExitButton[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.ExitButton', code) - code = re.sub(r'\bSetMenuExitButton[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.ExitButton = \2', code) - code = re.sub(r'\bGetMenuExitBackButton[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.ExitBackButton', code) - code = re.sub(r'\bSetMenuExitBackButton[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.ExitBackButton = \2', code) - code = re.sub(r'\bSetMenuNoVoteButton[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.NoVoteButton = \2', code) - code = re.sub(r'\bCancelMenu[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Cancel()', code) - code = re.sub(r'\bGetMenuOptionFlags[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.OptionFlags', code) - code = re.sub(r'\bSetMenuOptionFlags[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.OptionFlags = \2', code) - code = re.sub(r'\bVoteMenu[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.DisplayVote(', code) - code = re.sub(r'\bVoteMenuToAll[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.DisplayVoteToAll(', code) - code = re.sub(r'\bSetVoteResultCallback[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.VoteResultCallback = \2', code) - - # Panel - code = re.sub(r'\bCreatePanel[ \t]*\([ \t]*([^\)]*)[ \t]*\)', r'new Panel(\1)', code) - code = re.sub(r'\bGetPanelStyle[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.Style', code) - code = re.sub(r'\bSetPanelTitle[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetTitle(', code) - code = re.sub(r'\bDrawPanelItem[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.DrawItem(', code) - code = re.sub(r'\bDrawPanelText[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.DrawText(', code) - code = re.sub(r'\bCanPanelDrawFlags[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.CanDrawFlags(', code) - code = re.sub(r'\bSetPanelKeys[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.SetKeys(', code) - code = re.sub(r'\bSendPanelToClient[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Send(', code) - code = re.sub(r'\bGetPanelTextRemaining[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.TextRemaining', code) - code = re.sub(r'\bGetPanelCurrentKey[ \t]*\([ \t]*([^\)]+)[ \t]*\)', r'\1.CurrentKey', code) - code = re.sub(r'\bSetPanelCurrentKey[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.CurrentKey = \2', code) - - # Protobuf - code = re.sub(r'\bPb((?:Add|Read|Set|Get|Remove)\w+)\((\w+)[, ]*', r'\2.\1(', code) - - # Regex - code = re.sub(r'\bCompileRegex[ \t]*\([ \t]*([^\)]*)[ \t]*\)', r'new Regex(\1)', code) - code = re.sub(r'\bMatchRegex[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Match(', code) - code = re.sub(r'\bGetRegexSubString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetSubString(', code) - - # SMCParser - code = re.sub(r'\bSMC_CreateParser[ \t]*\([ \t]*\)', r'new SMCParser()', code) - code = re.sub(r'\bSMC_ParseFile[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.ParseFile(', code) - code = re.sub(r'\bSMC_SetParseStart[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.OnStart = \2', code) - code = re.sub(r'\bSMC_SetParseEnd[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.OnEnd = \2', code) - code = re.sub(r'([ \t]+)SMC_SetReaders\((\w+),[ \t]*(\w+),[ \t]*(\w+),[ \t]*(\w+).*', r'\1\2.OnEnterSection = \3;\n\1\2.OnKeyValue = \4;\n\1\2.OnLeaveSection = \5;', code) - code = re.sub(r'\bSMC_SetRawLine[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.OnRawLine = \2', code) - code = re.sub(r'\bSMC_GetErrorString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetErrorString(', code) - - # TopMenu - code = re.sub(r'\bCreateTopMenu[ \t]*\([ \t]*([^\)]*)[ \t]*\)', r'new TopMenu(\1)', code) - code = re.sub(r'\bLoadTopMenuConfig[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.LoadConfig(', code) - code = re.sub(r'\bAddToTopMenu[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\,]+)[ \t]*,[ \t]*TopMenuObject_Category', r'\1.AddCategory(\2, ', code) - code = re.sub(r'\bAddToTopMenu[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\,]+)[ \t]*,[ \t]*TopMenuObject_Item', r'\1.AddItem(\2', code) - code = re.sub(r'\bGetTopMenuInfoString[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetInfoString(', code) - code = re.sub(r'\bGetTopMenuObjName[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.GetObjName(', code) - code = re.sub(r'\bRemoveFromTopMenu[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Remove(', code) - code = re.sub(r'\bDisplayTopMenu[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.Display(', code) - code = re.sub(r'\bDisplayTopMenuCategory[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.DisplayCategory(', code) - code = re.sub(r'\bFindTopMenuCategory[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*', r'\1.FindCategory(', code) - code = re.sub(r'\bSetTopMenuTitleCaching[ \t]*\([ \t]*([^\,]+)[ \t]*,[ \t]*([^\)]+)[ \t]*\)', r'\1.CacheTitles = \2', code) - - - - # -------------------------------------------------------------------------------------------------------------------------------- - # GENERAL SYNTAX UPDATES - print('Updating syntax on {}'.format(sys.argv[i])) - - # type:whatever -> view_as(whatever) - code = reLoop(r'(=[ \t]*)(\w+):(.*?)(,|;)(?=(?:[^{]*{[^}]*})*[^}]*$)(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)(?=(?:[^\(]*\([^\)]*\))*[^\)]*$)', r'\1view_as<\2>(\3)\4', code, re.M) - - # update function type to void - code = re.sub(r'(\npublic )((?:OnMapTimeLeftChanged|TF2_OnConditionAdded|TF2_OnWaitingForPlayersEnd|TF2_OnWaitingForPlayersStart|TF2_OnConditionRemoved|OnEntityCreated|OnEntityDestroyed|OnMapVoteStarted|OnNominationRemoved|OnClientSayCommand_Post|BaseComm_OnClientGag|OnClientCookiesCached|BaseComm_OnClientMute|OnAdminMenuCreated|OnAdminMenuReady|OnRebuildAdminCache|OnClientAuthorized|OnClientPostAdminCheck|OnClientPostAdminFilter|OnClientPutInServer|OnClientSettingsChanged|OnClientDisconnect_Post|OnClientConnected|OnClientDisconnect|OnAllPluginsLoaded|OnAutoConfigsBuffered|OnClientFloodResult|OnConfigsExecuted|OnGameFrame|OnLibraryAdded|OnLibraryRemoved|OnMapEnd|OnMapStart|OnPluginEnd|OnPluginPauseChange|OnPluginStart|OnServerCfg)[ \t]*\()', r'\1void \2', code) - - # public native -> public int native - for m in re.finditer(r'\bCreateNative\(.*?,[ \t]*(.*?)[ \t]*\)', code): - native = m.group(1) - pattern = r'\npublic '+native+r'\(' - replace = r'\npublic int '+native+r'(' - code = re.sub(pattern, replace, code) + # -- Update handles from non 'new' functions + for methodmap, func in METHODMAPS_NO_NEW(): + code = updateHandle(methodmap, func, code) - # public convarChange -> public void convarChange - for m in re.finditer(r'\.AddChangeHook\([ \t]*(.*?)[ \t]*\)', code): - convarChange = m.group(1) - pattern = r'\npublic '+convarChange+r'\( *\w+' - replace = r'\npublic void '+convarChange+r'(ConVar' - code = re.sub(pattern, replace, code) - # public eventHook -> public void eventHook - for m in re.finditer(r'\bHookEvent(?:Ex)*\(.*?,[ \t]*(.*?)[ \t]*(,|\))', code): - event = m.group(1) - pattern = r'\npublic '+event+r'\([ \t]*\w+' - replace = r'\npublic void '+event+r'(Event' - code = re.sub(pattern, replace, code) - pattern = r'Action(:| +)'+event+r'[ \t]*\(Handle(:| +)' - replace = r'Action '+event+r'(Event ' - code = re.sub(pattern, replace, code) + # -- Main Replacements + for search, replace in REPLACEMEMTS(): + code = re.sub(search, replace, code) + - # *************************************** - # socket(even though this isn't included in SM, I've added it) + # -- Socket m = re.search(r'\bSocketCreate\([ \t]*.*?[ \t]*,[ \t]*(.*?)[ \t]*\)', code) - if m: - SocketErrorCB = m.group(1) - code = re.sub(r'(\npublic )'+r'([ \t]*\b'+SocketErrorCB+r'\b[ \t]*)', r'\1void \2', code) + if m: # SocketErrorCB + code = re.sub(r'(\npublic )([ \t]*\b' + m.group(1) + r'\b[ \t]*)', r'\1void \2', code) m = re.search(r'\bSocketListen\([ \t]*.*?[ \t]*,[ \t]*(.*?)[ \t]*\)', code) - if m: - SocketIncomingCB = m.group(1) - code = re.sub(r'(\npublic )'+r'([ \t]*\b'+SocketIncomingCB+r'\b[ \t]*)', r'\1void \2', code) + if m: # SocketIncomingCB + code = re.sub(r'(\npublic )([ \t]*\b' + m.group(1) + r'\b[ \t]*)', r'\1void \2', code) m = re.search(r'\bSocketSetSendqueueEmptyCallback\([ \t]*.*?[ \t]*,[ \t]*(.*?)[ \t]*\)', code) - if m: - SocketSendqueueEmptyCB = m.group(1) - code = re.sub(r'(\npublic )'+r'([ \t]*\b'+SocketSendqueueEmptyCB+r'\b[ \t]*)', r'\1void \2', code) + if m: # SocketSendqueueEmptyCB + code = re.sub(r'(\npublic )([ \t]*\b' + m.group(1) + r'\b[ \t]*)', r'\1void \2', code) m = re.search(r'\bSocketConnect\([ \t]*.*?[ \t]*,[ \t]*(.*?)[ \t]*,[ \t]*(.*?)[ \t]*,[ \t]*(.*?)[ \t]*,', code) - if m: - SocketConnectCB = m.group(1) - SocketReceiveCB = m.group(2) - SocketDisconnectCB = m.group(3) - code = re.sub(r'(^public[ \t])'+r'([ \t]*\b'+SocketConnectCB+r'\b[ \t]*)', r'\1void \2', code, 0, re.M) - code = re.sub(r'(^public[ \t])'+r'([ \t]*\b'+SocketReceiveCB+r'\b[ \t]*)', r'\1void \2', code, 0, re.M) - code = re.sub(r'(^public[ \t])'+r'([ \t]*\b'+SocketDisconnectCB+r'\b[ \t]*)', r'\1void \2', code, 0, re.M) - # **************************************** - - # Remove deprecated FCVAR_PLUGIN + if m: # Connect, Receive, Disconnect + for i in range(1, 3): + code = re.sub(r'(^public[ \t])' + r'([ \t]*\b' + m.group(i) + r'\b[ \t]*)', r'\1void \2', code, 0, re.M) + + + # -- Remove deprecated FCVAR_PLUGIN code = re.sub(r'(?:\|FCVAR_PLUGIN|FCVAR_PLUGIN\|)', r'', code) - code = re.sub(r'FCVAR_PLUGIN', r'0', code) - - # Update invalid_handle to null - code = re.sub(r'INVALID_HANDLE', r'null', code) - - code = re.sub(r'\biClient', r'client', code) - - # Check to remove unrequired var type in BuildPath (idk, i saw a plugin do this, so i added it) - code = re.sub(r'(BuildPath\()[ \t]*PathType:*', r'\1', code) - - # String:whatever[] -> char[] whatever - code = re.sub(r'(? - # char whatever[1]; - # float whatever; - # int whatever; - code = reLoop(r'^([ \t]*)(decl[ \t]+.+), (\w+(?:\[[ \t]*\w+[ \t]*\])?[ \t]*)(?:,[ \t]*|=[ \t]*\-?(?:\d+|\w+)[ \t]*(?:\)|,[ \t]*)|;)(?=(?:[^{]*{[^}]*})*[^}]*$)(?=(?:[^"]*"[^"]*")*[^"]*$)(?=[^)]*$)', r'\1\2;\n\1int \3;\n\1', code, re.M) - code = re.sub(r'(decl\b +)(\w+(?:\[.+?\][ =]*\d*)*)(;|[ \t]*,[ \t]*)', r'\1 int \2\3', code) - code = reLoop(r'^([ \t]*)(decl\b[^(\n]+)(.*?\),|,[ \t]*)(.*?)(;|,[ \t]*)', r'\1\2;\n\1\4;', code, re.M) - code = re.sub(r'decl\b +', r'', code) - # - # Same thing, but for new String:whatever[1], Float:whatever, whatever; - code = reLoop(r'^([ \t]*)(new[ \t]+.+),[ \t]+(\w+(?:\[[ \t]*\w+[ \t]*\])?[ \t]*)(?:,|=[ \t]*\-?(?:\d+|\w+)[ \t]*(?:\)|,)|;)(?=(?:[^{]*{[^}]*})*[^}]*$)(?=(?:[^"]*"[^"]*")*[^"]*$)(?=[^)]*$)', r'\1\2;\n\1int \3;\n\1', code, re.M) - code = re.sub(r'(?(\1)\2', code) - - code = re.sub(r'\bGetClientAuthString\([ \t]*(.*?,)', r'GetClientAuthId(\1 AuthId_Steam2,', code) - - # new String:var -> char var - code = re.sub(r'(?:new[ \t]+)*String:', r'char ', code) - - # new dataType:whatever -> dataType whatever - code = re.sub(r'new[ \t]+(\w+):', r'\1 ', code) - - # Handle: -> Handle - code = re.sub(r'Handle:',r'Handle ', code) - - # Float -> float - code = re.sub(r'\bFloat\b(:|[ \t]+)', r'float ', code) - - # new var -> int var - code = re.sub(r'(\n\t*)new[ \t]+(\w+([ \t]*\=|\;))', r'\1int \2', code) - - # for (new = -> for (int = - code = re.sub(r'(for[ \t]*\()[ \t]*new', r'\1int', code) - - # dataType:whatever -> dataType whatever - code = re.sub(r'(^.*?\w):(\w.*\()', r'\1 \2', code, 0, re.M) - - # new var -> int var - code = re.sub(r'(? const int var - code = re.sub(r'(,*[ \t]*const) ([\w\d_]+\,)', r'\1 int \2', code) - - # dataType:whatever -> dataType whatever (NOTE TO SELF: reference this for finding things not inside of quotes!) - code = reLoop(r'(\([ \t]*|,[ \t]*)([a-zA-Z]+):(\w[^\"\n,]+(,|\)))', r'\1\2 \3', code) - code = re.sub(r'(^public[ \t]+\w+):(.*?\=)', r'\1 \2', code, 0, re.M) - - # removes colons from bool and any - code = re.sub (r'^(\t*bool):', r'\1 ', code, 0, re.M) - code = re.sub (r'(any):(\.)', r'\1 \2', code) - - # DataType vars - # Handle var -> ConVar var - code = replConVar(code) - # Handle var -> File var - code = replFileType(code) - - dataTypes = [ - "ArrayList" - , "ArrayStack" - , "Cookie" - , "DataPack" - , "GlobalForward" - , "KeyValues" - , "Menu" - , "Panel" - , "PrivateForward" - , "Regex" - , "SMCParser" - , "StringMap" - , "TopMenu" - , "Transaction" - ] - for dataType in dataTypes: - code = replaceDataType(dataType, code) - - # Handle var -> ArrayList var - for m in re.finditer(r'(\w+)[ \t]*=[ \t]*GetNativeCell', code): - var = m.group(1) - pattern = r'Handle[ \t]+'+var+r'\b' - replace = r'ArrayList '+var - code = re.sub(pattern, replace, code) + code = re.sub('FCVAR_PLUGIN', '0', code) - # Handle var -> ConVar var - for m in re.finditer(r'([\w_]+)[ \t]*=[ \t]*FindConVar\(', code): - var = m.group(1) - pattern = r'Handle[ \t]+'+var+r'\b' - replace = r'ConVar '+var - code = re.sub(pattern, replace, code) - for m in re.finditer(r'([\w_]+)[ \t]*=[ \t]*OpenDirectory\(', code): - var = m.group(1) - pattern = r'Handle[ \t]+'+var+r'\b' - replace = r'DirectoryListing '+var - code = re.sub(pattern, replace, code) + # -- Update invalid_handle to null + code = re.sub('INVALID_HANDLE', 'null', code) + + + # -- Updates Handle to datatypes generated by `= new` functions + for methodmap in METHODMAPS(): + code = updateMethodmap(methodmap, code) - # Redundancy check on converting handles to ArrayList class - re.sub(r'Handle[ \t]+(\w+[ \t]*=[ \t]*GetNativeCell)', r'ArrayList \1', code) - # public Menu_Handler -> public int Menu_Handler - for m in re.finditer(r'=[ \t]*new Menu\((.*?)(?:,|\))', code): - var = m.group(1) - pattern = r'^(public)[ \t]+'+var+r'[ \t]*\([ \t]*\w+[ \t]+' - replace = r'\1 int '+var+r'(Menu ' - code = re.sub(pattern, replace, code, 0, re.M) - # This one finds int vars in function declaration and adds `int` in front it the var - code = reLoop(r'^(\w.+?\(.*)(?<=,|\()[ \t]*(&?[\w]+(?:\[\d+\])?[ \t]*(?:,|\)|=[ \t]*\-?(\d+|\w+)[ \t]*(?:\)|,)))(?=(?:[^{]*{[^}]*})*[^}]*$)(?=(?:[^"]*"[^"]*")*[^"]*$)', r'\1 int \2', code, re.M) + # -- ConVar change callback + for m in re.finditer(r'\.AddChangeHook\([ \t]*(.*?)[ \t]*\)', code): + cvar = m.group(1) + pattern = r'(\n[ \t]*public .*?' + cvar + r')\([ \t]*Handle' + replace = r'\1' + r'(ConVar' + code = re.sub(pattern, replace, code) - # Redundancy check on removing colons from variables - code = re.sub(r'^(\t*\w+)\:', r'\1 ', code, 0, re.M) + # -- Event callback + for m in re.finditer(r'\bHookEvent(?:Ex)*\(.*?,[ \t]*(.*?)[ \t]*(,|\))', code): + event = m.group(1) + pattern = r'(\n[ \t]*public .*?' + event + r')\([ \t]*Handle' + replace = r'\1' + r'(Event' + code = re.sub(pattern, replace, code) - # Format again. Remove extra spaces. - code = re.sub(r'[ \t]*\n[ \t]*\{', r' {', code) - code = re.sub(r'[ \t]+\]', r']', code) - code = re.sub(r'\[[ \t]+', r'[', code) - code = re.sub(r'[ \t]+\)', r')', code) - code = re.sub(r'\([ \t]+', r'(', code) - code = re.sub(r'[ \t]+\n', r'\n', code) + index = sys.argv[i].rfind('.') + file = sys.argv[i][:index] + '.m' + sys.argv[i][index:] - with open(sys.argv[i], 'w', encoding='utf-8') as f: - f.write(code) \ No newline at end of file + with open(file, 'w', encoding = 'utf-8') as f: + f.write(code) From 0e2807d20f8bc7c4142f87145aa56f5cbf3ded09 Mon Sep 17 00:00:00 2001 From: Arron Vinyard Date: Tue, 31 Dec 2019 08:49:24 -0500 Subject: [PATCH 24/25] Update methodmapize.py --- methodmapize.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/methodmapize.py b/methodmapize.py index 304bd2d..de17b35 100644 --- a/methodmapize.py +++ b/methodmapize.py @@ -448,7 +448,7 @@ def updateMethodmap(dataType, code): m = re.search(r'\bSocketConnect\([ \t]*.*?[ \t]*,[ \t]*(.*?)[ \t]*,[ \t]*(.*?)[ \t]*,[ \t]*(.*?)[ \t]*,', code) if m: # Connect, Receive, Disconnect for i in range(1, 3): - code = re.sub(r'(^public[ \t])' + r'([ \t]*\b' + m.group(i) + r'\b[ \t]*)', r'\1void \2', code, 0, re.M) + code = re.sub(r'(^public[ \t])[ \t]*\b' + m.group(i) + r'\b[ \t]*)', r'\1void \2', code, 0, re.M) # -- Remove deprecated FCVAR_PLUGIN From 7e732bfe6a44693da45bf4d53137e4b23f2f6ef8 Mon Sep 17 00:00:00 2001 From: Arron Vinyard Date: Tue, 31 Dec 2019 14:37:07 -0500 Subject: [PATCH 25/25] Remove socket callback support --- methodmapize.py | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/methodmapize.py b/methodmapize.py index de17b35..8247269 100644 --- a/methodmapize.py +++ b/methodmapize.py @@ -432,25 +432,6 @@ def updateMethodmap(dataType, code): code = re.sub(search, replace, code) - # -- Socket - m = re.search(r'\bSocketCreate\([ \t]*.*?[ \t]*,[ \t]*(.*?)[ \t]*\)', code) - if m: # SocketErrorCB - code = re.sub(r'(\npublic )([ \t]*\b' + m.group(1) + r'\b[ \t]*)', r'\1void \2', code) - - m = re.search(r'\bSocketListen\([ \t]*.*?[ \t]*,[ \t]*(.*?)[ \t]*\)', code) - if m: # SocketIncomingCB - code = re.sub(r'(\npublic )([ \t]*\b' + m.group(1) + r'\b[ \t]*)', r'\1void \2', code) - - m = re.search(r'\bSocketSetSendqueueEmptyCallback\([ \t]*.*?[ \t]*,[ \t]*(.*?)[ \t]*\)', code) - if m: # SocketSendqueueEmptyCB - code = re.sub(r'(\npublic )([ \t]*\b' + m.group(1) + r'\b[ \t]*)', r'\1void \2', code) - - m = re.search(r'\bSocketConnect\([ \t]*.*?[ \t]*,[ \t]*(.*?)[ \t]*,[ \t]*(.*?)[ \t]*,[ \t]*(.*?)[ \t]*,', code) - if m: # Connect, Receive, Disconnect - for i in range(1, 3): - code = re.sub(r'(^public[ \t])[ \t]*\b' + m.group(i) + r'\b[ \t]*)', r'\1void \2', code, 0, re.M) - - # -- Remove deprecated FCVAR_PLUGIN code = re.sub(r'(?:\|FCVAR_PLUGIN|FCVAR_PLUGIN\|)', r'', code) code = re.sub('FCVAR_PLUGIN', '0', code) @@ -465,7 +446,6 @@ def updateMethodmap(dataType, code): code = updateMethodmap(methodmap, code) - # -- ConVar change callback for m in re.finditer(r'\.AddChangeHook\([ \t]*(.*?)[ \t]*\)', code): cvar = m.group(1)