diff --git a/methodmapize.py b/methodmapize.py index 2a768bc..8247269 100644 --- a/methodmapize.py +++ b/methodmapize.py @@ -1,336 +1,468 @@ #!/usr/bin/python # Methodmapizer for SourcePawn 1.7+ # Replaces all native calls with their equivalent methodmap call. -# By Peace-Maker -# Version 1.0 +# By Peace-Maker, JoinedSenses +# Version 1.2 + + +# 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) -# Run through all passed files + +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) + pattern = r'Handle[ \t]+' + var + r'\b' + replace = dataType + ' ' + var + code = re.sub(pattern, replace, code) + + return code + + +# 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 + + 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: - code = f.read() + with open(sys.argv[i], 'r', encoding = 'utf-8') as f: 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) - - # GroupId - code = re.sub(r"AddAdmGroupCmdOverride\s*\(\s*([^\,]+)\s*,\s*", r"\1.AddCommandOverride(", code) - code = re.sub(r"SetAdmGroupImmuneFrom\s*\(\s*([^\,]+)\s*,\s*", r"\1.AddGroupImmunity(", code) - code = re.sub(r"GetAdmGroupCmdOverride\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetCommandOverride(", code) - code = re.sub(r"GetAdmGroupAddFlags\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetFlags(", code) - code = re.sub(r"GetAdmGroupImmunity\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetGroupImmunity(", code) - code = re.sub(r"GetAdmGroupAddFlag\s*\(\s*([^\,]+)\s*,\s*", r"\1.HasFlag(", code) - code = re.sub(r"SetAdmGroupAddFlag\s*\(\s*([^\,]+)\s*,\s*", r"\1.SetFlag(", code) - code = re.sub(r"GetAdmGroupImmuneCount\s*\(\s*([^\)]+)\s*\)", r"\1\.GroupImmunitiesCount", code) - code = re.sub(r"GetAdmGroupImmunityLevel\s*\(\s*([^\)]+)\s*\)", r"\1\.ImmunityLevel", code) - code = re.sub(r"SetAdmGroupImmunityLevel\s*\(\s*([^\,]+)\s*,\s*([^\)]+)\s*\)", r"\1.ImmunityLevel = \2", code) - - # ArrayList - code = re.sub(r"ClearArray\s*\(\s*([^\)]+)\s*\)", r"\1.Clear()", code) - code = re.sub(r"CloneArray\s*\(\s*([^\)]+)\s*\)", r"\1.Clone()", code) - code = re.sub(r"CreateArray\s*\(\s*([^\)]*)\s*\)", r"new ArrayList(\1)", code) - code = re.sub(r"FindStringInArray\s*\(\s*([^\,]+)\s*,\s*", r"\1.FindString(", code) - code = re.sub(r"FindValueInArray\s*\(\s*([^\,]+)\s*,\s*", r"\1.FindValue(", code) - code = re.sub(r"GetArrayArray\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetArray(", code) - code = re.sub(r"GetArrayCell\s*\(\s*([^\,]+)\s*,\s*", r"\1.Get(", code) - code = re.sub(r"GetArraySize\s*\(\s*([^\)]+)\s*\)", r"\1\.Length", code) - code = re.sub(r"GetArrayString\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetString(", code) - code = re.sub(r"PushArrayArray\s*\(\s*([^\,]+)\s*,\s*", r"\1.PushArray(", code) - code = re.sub(r"PushArrayCell\s*\(\s*([^\,]+)\s*,\s*", r"\1.Push(", code) - code = re.sub(r"PushArrayString\s*\(\s*([^\,]+)\s*,\s*", r"\1.PushString(", code) - code = re.sub(r"RemoveFromArray\s*\(\s*([^\,]+)\s*,\s*", r"\1.Erase(", code) - code = re.sub(r"ResizeArray\s*\(\s*([^\,]+)\s*,\s*", r"\1.Resize(", code) - code = re.sub(r"SetArrayArray\s*\(\s*([^\,]+)\s*,\s*", r"\1.SetArray(", code) - code = re.sub(r"SetArrayCell\s*\(\s*([^\,]+)\s*,\s*", r"\1.Set(", code) - code = re.sub(r"SetArrayString\s*\(\s*([^\,]+)\s*,\s*", r"\1.SetString(", code) - code = re.sub(r"ShiftArrayUp\s*\(\s*([^\,]+)\s*,\s*", r"\1.ShiftUp(", code) - code = re.sub(r"SwapArrayItems\s*\(\s*([^\,]+)\s*,\s*", r"\1.SwapAt(", code) - - # ArrayStack - code = re.sub(r"CreateStack\s*\(\s*([^\)]*)\s*\)", r"new ArrayStack(\1)", code) - code = re.sub(r"IsStackEmpty\s*\(\s*([^\)]+)\s*\)", r"\1.Empty", code) - code = re.sub(r"PopStackArray\s*\(\s*([^\,]+)\s*,\s*", r"\1.PopArray(", code) - code = re.sub(r"PopStackCell\s*\(\s*([^\,]+)\s*,\s*", r"\1.Pop(", code) - code = re.sub(r"PopStackString\s*\(\s*([^\,]+)\s*,\s*", r"\1.PopString(", code) - code = re.sub(r"PushStackArray\s*\(\s*([^\,]+)\s*,\s*", r"\1.PushArray(", code) - code = re.sub(r"PushStackCell\s*\(\s*([^\,]+)\s*,\s*", r"\1.Push(", code) - code = re.sub(r"PushStackString\s*\(\s*([^\,]+)\s*,\s*", r"\1.PushString(", code) - - # StringMap - code = re.sub(r"CreateTrie\s*\(\s*\)", r"new StringMap()", code) - code = re.sub(r"GetTrieSize\s*\(\s*([^\)]+)\s*\)", r"\1.Size", code) - code = re.sub(r"ClearTrie\s*\(\s*([^\)]+)\s*\)", r"\1.Clear()", code) - code = re.sub(r"GetTrieString\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetString(", code) - code = re.sub(r"SetTrieString\s*\(\s*([^\,]+)\s*,\s*", r"\1.SetString(", code) - code = re.sub(r"GetTrieValue\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetValue(", code) - code = re.sub(r"SetTrieValue\s*\(\s*([^\,]+)\s*,\s*", r"\1.SetValue(", code) - code = re.sub(r"GetTrieArray\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetArray(", code) - code = re.sub(r"SetTrieArray\s*\(\s*([^\,]+)\s*,\s*", r"\1.SetArray(", code) - code = re.sub(r"RemoveFromTrie\s*\(\s*([^\,]+)\s*,\s*", r"\1.Remove(", code) - - # StringMapSnapshot - code = re.sub(r"CreateTrieSnapshot\s*\(\s*([^\)]+)\s*\)", r"\1.Snapshot()", code) - code = re.sub(r"TrieSnapshotKeyBufferSize\s*\(\s*([^\,]+)\s*,\s*", r"\1.KeyBufferSize(", code) - code = re.sub(r"GetTrieSnapshotKey\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetKey(", code) - code = re.sub(r"TrieSnapshotLength\s*\(\s*([^\)]+)\s*\)", r"\1.Length", code) - - # TODO - # BfRead - # BfWrite - - # ConVar - code = re.sub(r"GetConVarBool\s*\(\s*([^\)]+)\s*\)", r"\1.BoolValue", code) - code = re.sub(r"GetConVarBounds\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetBounds(", code) - code = re.sub(r"GetConVarDefault\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetDefault(", code) - code = re.sub(r"GetConVarFlags\s*\(\s*([^\)]+)\s*\)", r"\1.Flags", code) - code = re.sub(r"GetConVarFloat\s*\(\s*([^\)]+)\s*\)", r"\1.FloatValue", code) - code = re.sub(r"GetConVarInt\s*\(\s*([^\)]+)\s*\)", r"\1.IntValue", code) - code = re.sub(r"GetConVarName\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetName(", code) - code = re.sub(r"GetConVarString\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetString(", code) - code = re.sub(r"HookConVarChange\s*\(\s*([^\,]+)\s*,\s*", r"\1.AddChangeHook(", code) - code = re.sub(r"ResetConVar\s*\(\s*([^\,]+)\s*,\s*", r"\1.RestoreDefault(", code) - code = re.sub(r"SendConVarValue\s*\(\s*([^\,]+)\s*,\s*", r"\1.ReplicateToClient(", code) - - # Only use the method if the original call has more than 2 parameters. - code = re.sub(r"SetConVarBool\s*\(\s*([^\,]+)\s*,\s*([^\,]+)\s*,", r"\1.SetBool(\2,", code) - code = re.sub(r"SetConVarBool\s*\(\s*([^\,]+)\s*,\s*([^\)]+)\s*\)", r"\1.BoolValue = \2", code) - - code = re.sub(r"SetConVarBounds\s*\(\s*([^\,]+)\s*,\s*", r"\1.SetBounds(", code) - code = re.sub(r"SetConVarFlags\s*\(\s*([^\,]+)\s*,\s*([^\)]+)\s*\)", r"\1.Flags = \2", code) - - code = re.sub(r"SetConVarFloat\s*\(\s*([^\,]+)\s*,\s*([^\,]+)\s*,", r"\1.SetFloat(\2,", code) - code = re.sub(r"SetConVarFloat\s*\(\s*([^\,]+)\s*,\s*([^\)]+)\s*\)", r"\1.FloatValue = \2", code) - code = re.sub(r"SetConVarInt\s*\(\s*([^\,]+)\s*,\s*([^\,]+)\s*,", r"\1.SetInt(\2,", code) - code = re.sub(r"SetConVarInt\s*\(\s*([^\,]+)\s*,\s*([^\)]+)\s*\)", r"\1.IntValue = \2", code) - code = re.sub(r"SetConVarString\s*\(\s*([^\,]+)\s*,\s*", r"\1.SetString(", code) - code = re.sub(r"UnhookConVarChange\s*\(\s*([^\,]+)\s*,\s*", r"\1.RemoveChangeHook(", code) - - # DataPack - code = re.sub(r"CreateDataPack\s*\(\s*\)", r"new DataPack()", code) - code = re.sub(r"WritePackCell\s*\(\s*([^\,]+)\s*,\s*", r"\1.WriteCell(", code) - code = re.sub(r"WritePackFloat\s*\(\s*([^\,]+)\s*,\s*", r"\1.WriteFloat(", code) - code = re.sub(r"WritePackString\s*\(\s*([^\,]+)\s*,\s*", r"\1.WriteString(", code) - code = re.sub(r"WritePackFunction\s*\(\s*([^\,]+)\s*,\s*", r"\1.WriteFunction(", code) - code = re.sub(r"ReadPackCell\s*\(\s*([^\)]+)\s*\)", r"\1.ReadCell()", code) - code = re.sub(r"ReadPackFloat\s*\(\s*([^\)]+)\s*\)", r"\1.ReadFloat()", code) - code = re.sub(r"ReadPackString\s*\(\s*([^\,]+)\s*,\s*", r"\1.ReadString(", code) - code = re.sub(r"ReadPackFunction\s*\(\s*([^\)]+)\s*\)", r"\1.ReadFunction()", code) - code = re.sub(r"ResetPack\s*\(\s*([^\,\)]+)\s*,?\s*([^\)]*)\s*\)", r"\1.Reset(\2)", code) - code = re.sub(r"GetPackPosition\s*\(\s*([^\)]+)\s*\)", r"\1.Position", code) - code = re.sub(r"SetPackPosition\s*\(\s*([^\,]+)\s*,\s*([^\)]+)\s*\)", r"\1.Position = \2", code) - code = re.sub(r"IsStackEmptyckReadable\s*\(\s*([^\,]+)\s*,\s*", r"\1.IsReadable(", code) - - # DBDriver - code = re.sub(r"SQL_GetDriver\s*\(", r"DBDriver.Find(", code) - code = re.sub(r"SQL_GetDriverProduct\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetProduct(", code) - code = re.sub(r"SQL_GetDriverIdent\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetIdentifier(", code) - - # DBResultSet - code = re.sub(r"SQL_FetchMoreResults\s*\(\s*([^\)]+)\s*\)", r"\1.FetchMoreResults()", code) - code = re.sub(r"SQL_HasResultSet\s*\(\s*([^\)]+)\s*\)", r"\1.HasResults", code) - code = re.sub(r"SQL_GetRowCount\s*\(\s*([^\)]+)\s*\)", r"\1.RowCount", code) - code = re.sub(r"SQL_GetFieldCount\s*\(\s*([^\)]+)\s*\)", r"\1.FieldCount", code) - code = re.sub(r"SQL_GetAffectedRows\s*\(\s*([^\)]+)\s*\)", r"\1.AffectedRows", code) - code = re.sub(r"SQL_GetInsertId\s*\(\s*([^\)]+)\s*\)", r"\1.InsertId", code) - code = re.sub(r"SQL_FieldNumToName\s*\(\s*([^\,]+)\s*,\s*", r"\1.FieldNumToName(", code) - code = re.sub(r"SQL_FieldNameToNum\s*\(\s*([^\,]+)\s*,\s*", r"\1.FieldNameToNum(", code) - code = re.sub(r"SQL_FetchRow\s*\(\s*([^\)]+)\s*\)", r"\1.FetchRow()", code) - code = re.sub(r"SQL_MoreRows\s*\(\s*([^\)]+)\s*\)", r"\1.MoreRows", code) - code = re.sub(r"SQL_Rewind\s*\(\s*([^\)]+)\s*\)", r"\1.Rewind()", code) - code = re.sub(r"SQL_FetchString\s*\(\s*([^\,]+)\s*,\s*", r"\1.FetchString(", code) - code = re.sub(r"SQL_FetchFloats*\(\s*([^\,]+)\s*,\s*", r"\1.FetchFloat(", code) - code = re.sub(r"SQL_FetchInt*\(\s*([^\,]+)\s*,\s*", r"\1.FetchInt(", code) - code = re.sub(r"SQL_IsFieldNull*\(\s*([^\,]+)\s*,\s*", r"\1.IsFieldNull(", code) - code = re.sub(r"SQL_FetchSize*\(\s*([^\,]+)\s*,\s*", r"\1.FetchSize(", code) - - # Transaction - code = re.sub(r"SQL_CreateTransaction\s*\(\s*\)", r"new Transaction()", code) - code = re.sub(r"SQL_AddQuery\s*\(\s*([^\,]+)\s*,\s*", r"\1.AddQuery(", code) - - # DBStatement - code = re.sub(r"SQL_BindParamInt\s*\(\s*([^\,]+)\s*,\s*", r"\1.BindInt(", code) - code = re.sub(r"SQL_BindParamFloat\s*\(\s*([^\,]+)\s*,\s*", r"\1.BindFloat(", code) - code = re.sub(r"SQL_BindParamString\s*\(\s*([^\,]+)\s*,\s*", r"\1.BindString(", code) - - # Database - code = re.sub(r"SQL_TConnect\s*\(", r"Database.Connect(", code) - # Only replace if the optional ident argument isn't used. - code = re.sub(r"SQL_ReadDriver\s*\(\s*([^\)\,]+)\s*\)", r"\1.Driver", code) - code = re.sub(r"SQL_SetCharset\s*\(\s*([^\,]+)\s*,\s*", r"\1.SetCharset(", code) - code = re.sub(r"SQL_EscapeString\s*\(\s*([^\,]+)\s*,\s*", r"\1.Escape(", code) - code = re.sub(r"SQL_FormatQuery\s*\(\s*([^\,]+)\s*,\s*", r"\1.Format(", code) - code = re.sub(r"SQL_IsSameConnection\s*\(\s*([^\,]+)\s*,\s*", r"\1.IsSameConnection(", code) - code = re.sub(r"SQL_TQuery\s*\(\s*([^\,]+)\s*,\s*", r"\1.Query(", code) - code = re.sub(r"SQL_ExecuteTransaction\s*\(\s*([^\,]+)\s*,\s*", r"\1.Execute(", code) - - # Event - code = re.sub(r"FireEvent\s*\(\s*([^\,\)]+)\s*,?\s*([^\)]*)\s*\)", r"\1.Fire(\2)", code) - code = re.sub(r"CancelCreatedEvent\s*\(\s*([^\)]+)\s*\)", r"\1.Cancel()", code) - code = re.sub(r"GetEventBool\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetBool(", code) - code = re.sub(r"SetEventBool\s*\(\s*([^\,]+)\s*,\s*", r"\1.SetBool(", code) - code = re.sub(r"GetEventInt\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetInt(", code) - code = re.sub(r"SetEventInt\s*\(\s*([^\,]+)\s*,\s*", r"\1.SetInt(", code) - code = re.sub(r"GetEventFloat\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetFloat(", code) - code = re.sub(r"SetEventFloat\s*\(\s*([^\,]+)\s*,\s*", r"\1.SetFloat(", code) - code = re.sub(r"GetEventString\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetString(", code) - code = re.sub(r"SetEventString\s*\(\s*([^\,]+)\s*,\s*", r"\1.SetString(", code) - code = re.sub(r"GetEventName\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetName(", code) - code = re.sub(r"SetEventBroadcast\s*\(\s*([^\,]+)\s*,\s*([^\)]+)\s*\)", r"\1.BroadcastDisabled = \2", code) - - # DirectoryListing - code = re.sub(r"ReadDirEntry\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetNext(", code) - - # File - code = re.sub(r"IsEndOfFile\s*\(\s*([^\)]+)\s*\)", r"\1.EndOfFile()", code) - code = re.sub(r"ReadFile\s*\(\s*([^\,]+)\s*,\s*", r"\1.Read(", code) - code = re.sub(r"ReadFileLine\s*\(\s*([^\,]+)\s*,\s*", r"\1.ReadLine(", code) - code = re.sub(r"ReadFileString\s*\(\s*([^\,]+)\s*,\s*", r"\1.ReadString(", code) - code = re.sub(r"FileSeek\s*\(\s*([^\,]+)\s*,\s*", r"\1.Seek(", code) - code = re.sub(r"WriteFile\s*\(\s*([^\,]+)\s*,\s*", r"\1.Write(", code) - code = re.sub(r"WriteFileLine\s*\(\s*([^\,]+)\s*,\s*", r"\1.WriteLine(", code) - code = re.sub(r"WriteStringLine\s*\(\s*([^\,]+)\s*,\s*", r"\1.WriteString(", code) - code = re.sub(r"FilePosition\s*\(\s*([^\)]+)\s*\)", r"\1.Position", code) - # TODO: ReadFileCell & ReadIntX - - # Handles - code = re.sub(r"CloseHandle\s*\(\s*([^\)]+)\s*\)", r"delete \1", code) - - # KeyValues - code = re.sub(r"CreateKeyValues\s*\(\s*([^\)]+)\s*\)", r"new KeyValues(\1)", code) - code = re.sub(r"KvSetString\s*\(\s*([^\,]+)\s*,\s*", r"\1.SetString(", code) - code = re.sub(r"KvSetNum\s*\(\s*([^\,]+)\s*,\s*", r"\1.SetNum(", code) - code = re.sub(r"KvSetUInt64\s*\(\s*([^\,]+)\s*,\s*", r"\1.SetUInt64(", code) - code = re.sub(r"KvSetFloat\s*\(\s*([^\,]+)\s*,\s*", r"\1.SetFloat(", code) - code = re.sub(r"KvSetColor\s*\(\s*([^\,]+)\s*,\s*", r"\1.SetColor(", code) - code = re.sub(r"KvSetVector\s*\(\s*([^\,]+)\s*,\s*", r"\1.SetVector(", code) - code = re.sub(r"KvGetString\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetString(", code) - code = re.sub(r"KvGetNum\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetNum(", code) - code = re.sub(r"KvGetFloat\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetFloat(", code) - code = re.sub(r"KvGetColor\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetColor(", code) - code = re.sub(r"KvGetUInt64\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetUInt64(", code) - code = re.sub(r"KvGetVector\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetVector(", code) - code = re.sub(r"KvJumpToKey\s*\(\s*([^\,]+)\s*,\s*", r"\1.JumpToKey(", code) - code = re.sub(r"KvJumpToKeySymbol\s*\(\s*([^\,]+)\s*,\s*", r"\1.JumpToKeySymbol(", code) - code = re.sub(r"KvGotoFirstSubKey\s*\(\s*([^\,\)]+)\s*,?\s*([^\)]*)\s*\)", r"\1.GotoFirstSubKey(\2)", code) - code = re.sub(r"KvGotoNextKey\s*\(\s*([^\,\)]+)\s*,?\s*([^\)]*)\s*\)", r"\1.GotoNextKey(\2)", code) - code = re.sub(r"KvSavePosition\s*\(\s*([^\)]+)\s*\)", r"\1.SavePosition()", code) - code = re.sub(r"KvDeleteKey\s*\(\s*([^\,]+)\s*,\s*", r"\1.DeleteKey(", code) - code = re.sub(r"KvDeleteThis\s*\(\s*([^\)]+)\s*\)", r"\1.DeleteThis()", code) - code = re.sub(r"KvGoBack\s*\(\s*([^\)]+)\s*\)", r"\1.GoBack()", code) - code = re.sub(r"KvRewind\s*\(\s*([^\)]+)\s*\)", r"\1.Rewind()", code) - code = re.sub(r"KvGetSectionName\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetSectionName(", code) - code = re.sub(r"KvSetSectionName\s*\(\s*([^\,]+)\s*,\s*", r"\1.SetSectionName(", code) - code = re.sub(r"KvGetDataType\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetDataType(", code) - code = re.sub(r"KeyValuesToFile\s*\(\s*([^\,]+)\s*,\s*", r"\1.ExportToFile(", code) - code = re.sub(r"FileToKeyValues\s*\(\s*([^\,]+)\s*,\s*", r"\1.ImportFromFile(", code) - code = re.sub(r"StringToKeyValues\s*\(\s*([^\,]+)\s*,\s*", r"\1.ImportFromString(", code) - code = re.sub(r"KvSetEscapeSequences\s*\(\s*([^\,]+)\s*,\s*", r"\1.SetEscapeSequences(", code) - code = re.sub(r"KvNodesInStack\s*\(\s*([^\)]+)\s*\)", r"\1.NodesInStack()", code) - code = re.sub(r"KvCopySubkeys\s*\(\s*([^\,]+)\s*,\s*", r"\1.Import(", code) - code = re.sub(r"KvFindKeyById\s*\(\s*([^\,]+)\s*,\s*", r"\1.FindKeyById(", code) - code = re.sub(r"KvGetNameSymbol\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetNameSymbol(", code) - code = re.sub(r"KvGetSectionSymbol\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetSectionSymbol(", code) - - # Menu - code = re.sub(r"CreateMenu\s*\(\s*([^\)]+)\s*\)", r"new Menu(\1)", code) - code = re.sub(r"DisplayMenu\s*\(\s*([^\,]+)\s*,\s*", r"\1.Display(", code) - code = re.sub(r"DisplayMenuAtItem\s*\(\s*([^\,]+)\s*,\s*", r"\1.DisplayAt(", code) - code = re.sub(r"AddMenuItem\s*\(\s*([^\,]+)\s*,\s*", r"\1.AddItem(", code) - code = re.sub(r"InsertMenuItem\s*\(\s*([^\,]+)\s*,\s*", r"\1.InsertItem(", code) - code = re.sub(r"RemoveMenuItem\s*\(\s*([^\,]+)\s*,\s*", r"\1.RemoveItem(", code) - code = re.sub(r"RemoveAllMenuItems\s*\(\s*([^\)]+)\s*\)", r"\1.RemoveAllItems()", code) - code = re.sub(r"GetMenuItem\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetItem(", code) - code = re.sub(r"GetMenuSelectionPosition\s*\(\s*([^\)]+)\s*\)", r"\1.Selection", code) - code = re.sub(r"GetMenuItemCount\s*\(\s*([^\)]+)\s*\)", r"\1.ItemCount", code) - code = re.sub(r"SetMenuPagination\s*\(\s*([^\,]+)\s*,\s*([^\)]+)\s*\)", r"\1.Pagination = \2", code) - code = re.sub(r"GetMenuPagination\s*\(\s*([^\)]+)\s*\)", r"\1.Pagination", code) - code = re.sub(r"GetMenuStyle\s*\(\s*([^\)]+)\s*\)", r"\1.Style", code) - code = re.sub(r"SetMenuTitle\s*\(\s*([^\,]+)\s*,\s*", r"\1.SetTitle(", code) - code = re.sub(r"GetMenuTitle\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetTitle(", code) - code = re.sub(r"CreatePanelFromMenu\s*\(\s*([^\)]+)\s*\)", r"\1.ToPanel()", code) - code = re.sub(r"GetMenuExitButton\s*\(\s*([^\)]+)\s*\)", r"\1.ExitButton", code) - code = re.sub(r"SetMenuExitButton\s*\(\s*([^\,]+)\s*,\s*([^\)]+)\s*\)", r"\1.ExitButton = \2", code) - code = re.sub(r"GetMenuExitBackButton\s*\(\s*([^\)]+)\s*\)", r"\1.ExitBackButton", code) - code = re.sub(r"SetMenuExitBackButton\s*\(\s*([^\,]+)\s*,\s*([^\)]+)\s*\)", r"\1.ExitBackButton = \2", code) - code = re.sub(r"SetMenuNoVoteButton\s*\(\s*([^\,]+)\s*,\s*([^\)]+)\s*\)", r"\1.NoVoteButton = \2", code) - code = re.sub(r"CancelMenu\s*\(\s*([^\)]+)\s*\)", r"\1.Cancel()", code) - code = re.sub(r"GetMenuOptionFlags\s*\(\s*([^\)]+)\s*\)", r"\1.OptionFlags", code) - code = re.sub(r"SetMenuOptionFlags\s*\(\s*([^\,]+)\s*,\s*([^\)]+)\s*\)", r"\1.OptionFlags = \2", code) - code = re.sub(r"VoteMenu\s*\(\s*([^\,]+)\s*,\s*", r"\1.DisplayVote(", code) - code = re.sub(r"VoteMenuToAll\s*\(\s*([^\,]+)\s*,\s*", r"\1.DisplayVoteToAll(", code) - code = re.sub(r"SetVoteResultCallback\s*\(\s*([^\,]+)\s*,\s*([^\)]+)\s*\)", r"\1.VoteResultCallback = \2", code) - - # Panel - code = re.sub(r"CreatePanel\s*\(\s*([^\)]*)\s*\)", r"new Panel(\1)", code) - code = re.sub(r"GetPanelStyle\s*\(\s*([^\)]+)\s*\)", r"\1.Style", code) - code = re.sub(r"SetPanelTitle\s*\(\s*([^\,]+)\s*,\s*", r"\1.SetTitle(", code) - code = re.sub(r"DrawPanelItem\s*\(\s*([^\,]+)\s*,\s*", r"\1.DrawItem(", code) - code = re.sub(r"DrawPanelText\s*\(\s*([^\,]+)\s*,\s*", r"\1.DrawText(", code) - code = re.sub(r"CanPanelDrawFlags\s*\(\s*([^\,]+)\s*,\s*", r"\1.CanDrawFlags(", code) - code = re.sub(r"SetPanelKeys\s*\(\s*([^\,]+)\s*,\s*", r"\1.SetKeys(", code) - code = re.sub(r"SendPanelToClient\s*\(\s*([^\,]+)\s*,\s*", r"\1.Send(", code) - code = re.sub(r"GetPanelTextRemaining\s*\(\s*([^\)]+)\s*\)", r"\1.TextRemaining", code) - code = re.sub(r"GetPanelCurrentKey\s*\(\s*([^\)]+)\s*\)", r"\1.CurrentKey", code) - code = re.sub(r"SetPanelCurrentKey\s*\(\s*([^\,]+)\s*,\s*([^\)]+)\s*\)", r"\1.CurrentKey = \2", code) - - # TODO: Protobuf - - # Regex - code = re.sub(r"CompileRegex\s*\(\s*([^\)]*)\s*\)", r"new Regex(\1)", code) - code = re.sub(r"MatchRegex\s*\(\s*([^\,]+)\s*,\s*", r"\1.Match(", code) - code = re.sub(r"GetRegexSubString\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetSubString(", code) - - # SMCParser - code = re.sub(r"SMC_CreateParser\s*\(\s*\)", r"new SMCParser()", code) - code = re.sub(r"SMC_ParseFile\s*\(\s*([^\,]+)\s*,\s*", r"\1.ParseFile(", code) - code = re.sub(r"SMC_SetParseStart\s*\(\s*([^\,]+)\s*,\s*([^\)]+)\s*\)", r"\1.OnStart = \2", code) - code = re.sub(r"SMC_SetParseEnd\s*\(\s*([^\,]+)\s*,\s*([^\)]+)\s*\)", r"\1.OnEnd = \2", code) - # TODO: Split up into 3 seperate lines? - #code = re.sub(r"SMC_SetReaders\s*\(\s*([^\,]+)\s*,\s*([^\)]+)\s*\)", r"\1.OnEnterSection = \2", code) - #code = re.sub(r"SetPanelCurrentKey\s*\(\s*([^\,]+)\s*,\s*([^\)]+)\s*\)", r"\1.OnLeaveSection = \2", code) - #code = re.sub(r"SetPanelCurrentKey\s*\(\s*([^\,]+)\s*,\s*([^\)]+)\s*\)", r"\1.OnKeyValue = \2", code) - code = re.sub(r"SMC_SetRawLine\s*\(\s*([^\,]+)\s*,\s*([^\)]+)\s*\)", r"\1.OnRawLine = \2", code) - code = re.sub(r"SMC_GetErrorString\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetErrorString(", code) - - # TopMenu - code = re.sub(r"CreateTopMenu\s*\(\s*([^\)]*)\s*\)", r"new TopMenu(\1)", code) - code = re.sub(r"LoadTopMenuConfig\s*\(\s*([^\,]+)\s*,\s*", r"\1.LoadConfig(", code) - code = re.sub(r"AddToTopMenu\s*\(\s*([^\,]+)\s*,\s*([^\,]+)\s*,\s*TopMenuObject_Category", r"\1.AddCategory(\2, ", code) - code = re.sub(r"AddToTopMenu\s*\(\s*([^\,]+)\s*,\s*([^\,]+)\s*,\s*TopMenuObject_Item", r"\1.AddItem(\2, ", code) - code = re.sub(r"GetTopMenuInfoString\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetInfoString(", code) - code = re.sub(r"GetTopMenuObjName\s*\(\s*([^\,]+)\s*,\s*", r"\1.GetObjName(", code) - code = re.sub(r"RemoveFromTopMenu\s*\(\s*([^\,]+)\s*,\s*", r"\1.Remove(", code) - code = re.sub(r"DisplayTopMenu\s*\(\s*([^\,]+)\s*,\s*", r"\1.Display(", code) - code = re.sub(r"DisplayTopMenuCategory\s*\(\s*([^\,]+)\s*,\s*", r"\1.DisplayCategory(", code) - code = re.sub(r"FindTopMenuCategory\s*\(\s*([^\,]+)\s*,\s*", r"\1.FindCategory(", code) - code = re.sub(r"SetTopMenuTitleCaching\s*\(\s*([^\,]+)\s*,\s*([^\)]+)\s*\)", r"\1.CacheTitles = \2", code) - - # _: int retagging - #code = re.sub(r"_:([a-zA-Z0-9_]+(\[[a-zA-Z0-9_]+\])*)", r"view_as(\1)", code) - - with open(sys.argv[i] + '.m', 'w', encoding='utf-8') as f: + code = f.read() + + # -- Handle: -> Handle + code = re.sub(r'(\bnew[ \t]+)?Handle:', 'Handle ', code) + + + # -- Update handles from non 'new' functions + for methodmap, func in METHODMAPS_NO_NEW(): + code = updateHandle(methodmap, func, code) + + + # -- Main Replacements + for search, replace in REPLACEMEMTS(): + code = re.sub(search, replace, code) + + + # -- Remove deprecated FCVAR_PLUGIN + code = re.sub(r'(?:\|FCVAR_PLUGIN|FCVAR_PLUGIN\|)', r'', code) + code = re.sub('FCVAR_PLUGIN', '0', 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) + + + # -- 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) + + # -- 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) + + + index = sys.argv[i].rfind('.') + file = sys.argv[i][:index] + '.m' + sys.argv[i][index:] + + with open(file, 'w', encoding = 'utf-8') as f: f.write(code)