Raised This Month: $404 Target: $400
 101% 

TOGs SourcePawn Syntax Converter [MS Excel Based for now]


Post New Thread Reply   
 
Thread Tools Display Modes
ReFlexPoison
☠☠☠
Join Date: Jul 2011
Location: United States
Old 07-19-2017 , 13:01   Re: TOGs SourcePawn Syntax Converter [MS Excel Based for now]
Reply With Quote #41

I remember requesting this when the new syntax was brand new! Great work!
Only thing that needs fixing as I can see is whenever view_as<?> needs to be placed, it just puts the variable type then a space as if it's creating a new variable.
__________________
ReFlexPoison is offline
ThatOneGuy
Veteran Member
Join Date: Jul 2012
Location: Oregon, USA
Old 07-19-2017 , 21:05   Re: TOGs SourcePawn Syntax Converter [MS Excel Based for now]
Reply With Quote #42

Quote:
Originally Posted by ReFlexPoison View Post
I remember requesting this when the new syntax was brand new! Great work!
Only thing that needs fixing as I can see is whenever view_as<?> needs to be placed, it just puts the variable type then a space as if it's creating a new variable.
Correct. I couldnt think of a way to capture the view_as stuff that didnt create false positives or trigger as a false positive for another part of the code....I may look into it again when I have more time.
__________________
ThatOneGuy is offline
envynz
AlliedModders Donor
Join Date: Nov 2014
Location: NZ
Old 07-20-2017 , 19:45   Re: TOGs SourcePawn Syntax Converter [MS Excel Based for now]
Reply With Quote #43

Works quite well. Just had to edit a line and it works fine!, may come up with tag mismatches but those are easy to fix.
envynz is offline
T1MOXA
Member
Join Date: Aug 2016
Old 07-22-2017 , 15:00   Re: TOGs SourcePawn Syntax Converter [MS Excel Based for now]
Reply With Quote #44

Lots of errors after formatting: https://forums.alliedmods.net/showthread.php?t=285493
T1MOXA is offline
ThatOneGuy
Veteran Member
Join Date: Jul 2012
Location: Oregon, USA
Old 07-22-2017 , 17:00   Re: TOGs SourcePawn Syntax Converter [MS Excel Based for now]
Reply With Quote #45

Quote:
Originally Posted by T1MOXA View Post
The tool sometimes wont handle 100% of the processing. The point is that it usually gets you MOST of the way, if not all of the way there. See OP for notes of what it doesnt handle currently.

For this plugin, they declare new variables across multiple lines in a single statement. The line breaks in the middle of the statement are throwing the tool off. The less typical the formatting style of the coder, the more likely it might not be processed 100% correct.

I also noticed that the "Break apart lines where variables of multiple types are declared." part I thought was done doesn't appear to work on this plugin, so for now I've edited the OP description of things that need to be done to reflect this.

The tool also didn't detect the native GivePlayerItem (from SDKTools) as an int, and thus put the function type as "void". I noticed my include is in new syntax, so I'm not sure if it is processing new-syntax includes correctly, and will have to make edits for that one of these days.

I've attached my edited .sp's of the plugin and a compiled version in new syntax for your convenience.
Attached Files
File Type: sp Get Plugin or Get Source (sm_advanced_admin newsyntax.sp - 93 views - 48.4 KB)
File Type: sp Get Plugin or Get Source (sm_advanced_admin.sp - 94 views - 48.4 KB)
__________________

Last edited by Headline; 07-24-2017 at 12:03.
ThatOneGuy is offline
Silvers
AlliedModders Donor
Join Date: Aug 2010
Location: SpaceX
Old 04-23-2018 , 09:23   Re: TOGs SourcePawn Syntax Converter [MS Excel Based for now]
Reply With Quote #46

Hello, thanks for this project. Hopefully we can make it even better.

I have written a PHP script to take the sourcepawn from TOGs "newsyntax.sp" and process into new methodmaps. For example (pseudo test code, not real world):

Spoiler

Can anyone with knowledge of the new methodmaps and ideally PHP also, help me finish anything I've missed? There are probably still some issues to work. I've converted all my scripts (69 plugins/73k lines/2.2m chars) with TOGs VBA project and my script to use the new syntax and methodmaps, which took maybe about 5 hours due to compiler warnings from VBA not handling the data types correctly and some time refining the PHP script.

I'll post the PHP script in future when it's cleaned up.
__________________

Last edited by Silvers; 04-23-2018 at 19:08.
Silvers is offline
hmmmmm
Senior Member
Join Date: Mar 2017
Location: ...
Old 04-23-2018 , 20:58   Re: TOGs SourcePawn Syntax Converter [MS Excel Based for now]
Reply With Quote #47

Peace-Maker has a similar python script that converts functions to their method map equivalents.
https://github.com/peace-maker/sm-methodmapize
hmmmmm is offline
ThatOneGuy
Veteran Member
Join Date: Jul 2012
Location: Oregon, USA
Old 04-23-2018 , 21:51   Re: TOGs SourcePawn Syntax Converter [MS Excel Based for now]
Reply With Quote #48

Quote:
Originally Posted by Silvers View Post
Hello, thanks for this project. Hopefully we can make it even better.

...

I'll post the PHP script in future when it's cleaned up.
Quote:
Originally Posted by hmmmmm View Post
Peace-Maker has a similar python script that converts functions to their method map equivalents.
https://github.com/peace-maker/sm-methodmapize
Nice. I'm glad someone is taking the time to convert this to PHP or another more-enterprise solution. I look forward to seeing what you end up with, as I think for the next few years it will be very helpful. Eventually, the tools will fade away as new plugins are more and more written in new syntax. For now, I'm glad it can help some and I think a PHP version would be even more helpful, since MS Excel isnt needed and it can be web based.
__________________
ThatOneGuy is offline
Silvers
AlliedModders Donor
Join Date: Aug 2010
Location: SpaceX
Old 04-26-2018 , 17:07   Re: TOGs SourcePawn Syntax Converter [MS Excel Based for now]
Reply With Quote #49

Well after seeing that Python script I'm embarrassed to post mine, but then again I tried the python converter on some of my sourcepawn scripts and it broke them deleting parts etc. So mine actually works nearer 99% even though it's not optimized and you could say terrible. I put 73k .sp lines through it with few problems.

1. Use TOGs VBA script to upgrade old scripts to the new syntax.
2. Run my PHP script and paste TOGs converted code into the textbox to convert it into using the new methodmaps.

Edit: added "Vars" button, see code for comments.

PHP Code:
<html><body text="white">
<?php
/*
 *    Name    :    [SM] Sourcepawn to Methodmaps Converter
 *    Author    :    SilverShot
 *    Descrp    :    1. Use TOGs VBA script to uppgrade old scripts to the new syntax. 2. Run this script and paste the code into the box to convert the code to use the new methodmaps.
 *    Link    :    https://www.sourcemod.net/plugins.php?author=Silvers&search=1&sortby=title&order=0 // https://forums.alliedmods.net/showthread.php?t=290805
 */
$g_Methods = array
(
    array(
"AddAngle","PbAddAngle"),
    array(
"AddBool","PbAddBool"),
    array(
"AddChangeHook","HookConVarChange"),
    array(
"AddColor","PbAddColor"),
    array(
"AddCommandOverride","AddAdmGroupCmdOverride"),
    array(
"AddFloat","PbAddFloat"),
    array(
"AddGroupImmunity","SetAdmGroupImmuneFrom"),
    array(
"AddInt","PbAddInt"),
    array(
"AddItem","AddMenuItem"),
    array(
"AddItem","AddToTopMenu"),
    array(
"AddMessage","PbAddMessage"),
    array(
"AddQuery","SQL_AddQuery"),
    array(
"AddString","PbAddString"),
    array(
"AddVector","PbAddVector"),
    array(
"AddVector2D","PbAddVector2D"),
    array(
"AffectedRows","SQL_GetAffectedRows"),
    array(
"ArrayList","CreateArray"),
    array(
"ArrayStack","CreateStack"),
    array(
"BindFloat","SQL_BindParamFloat"),
    array(
"BindIdentity","BindAdminIdentity"),
    array(
"BindInt","SQL_BindParamInt"),
    array(
"BindString","SQL_BindParamString"),
    array(
"BlockSize","GetArrayBlockSize"),
    array(
"BlockSize","GetStackBlockSize"),
    array(
"BoolValue","GetConVarBool"),
    array(
"BoolValue.set","SetConVarBool"),
    array(
"BroadcastDisabled","SetEventBroadcast"),
    array(
"BytesLeft","BfGetNumBytesLeft"),
    array(
"Cancel","CancelCreatedEvent"),
    array(
"Cancel","CancelMenu"),
    array(
"CanDrawFlags","CanPanelDrawFlags"),
    array(
"CanTarget","CanAdminTarget"),
    array(
"Clear","ClearArray"),
    array(
"Clear","ClearTrie"),
    array(
"Clone","CloneArray"),
    array(
"Connect","Database_Connect"),
    array(
"CurrentKey","GetPanelCurrentKey"),
    array(
"CurrentKey.set","SetPanelCurrentKey"),
    array(
"DataPack","CreateDataPack"),
    array(
"DBStatement.BindFloat","SQL_BindParamFloat"),
    array(
"DBStatement.BindInt","SQL_BindParamInt"),
    array(
"DBStatement.BindString","SQL_BindParamString"),
    array(
"DeleteKey","KvDeleteKey"),
    array(
"DeleteThis","KvDeleteThis"),
    array(
"Display","DisplayMenu"),
    array(
"Display","DisplayTopMenu"),
    array(
"DisplayAt","DisplayMenuAtItem"),
    array(
"DisplayCategory","DisplayTopMenuCategory"),
    array(
"DisplayVote","VoteMenu"),
    array(
"DisplayVoteToAll","VoteMenuToAll"),
    array(
"DrawItem","DrawPanelItem"),
    array(
"DrawText","DrawPanelText"),
    array(
"Driver","SQL_ReadDriver"),
    array(
"Empty","IsStackEmpty"),
    array(
"EndOfFile","IsEndOfFile"),
    array(
"Erase","RemoveFromArray"),
    array(
"Escape","SQL_EscapeString"),
    array(
"Execute","SQL_ExecuteTransaction"),
    array(
"ExitBackButton","GetMenuExitBackButton"),
    array(
"ExitBackButton.set","SetMenuExitBackButton"),
    array(
"ExitButton","GetMenuExitButton"),
    array(
"ExitButton.set","SetMenuExitButton"),
    array(
"ExportLength","KeyValuesExportLength"),
    array(
"ExportToFile","KeyValuesToFile"),
    array(
"ExportToString","KeyValuesToString"),
    array(
"FetchFloat","SQL_FetchFloat"),
    array(
"FetchInt","SQL_FetchInt"),
    array(
"FetchMoreResults","SQL_FetchMoreResults"),
    array(
"FetchRow","SQL_FetchRow"),
    array(
"FetchSize","SQL_FetchSize"),
    array(
"FetchString","SQL_FetchString"),
    array(
"FieldCount","SQL_GetFieldCount"),
    array(
"FieldNameToNum","SQL_FieldNameToNum"),
    array(
"FieldNumToName","SQL_FieldNumToName"),
    array(
"Find","SQL_GetDriver"),
    array(
"FindCategory","FindTopMenuCategory"),
    array(
"FindKeyById","KvFindKeyById"),
    array(
"FindString","FindStringInArray"),
    array(
"FindValue","FindValueInArray"),
    array(
"Fire","FireEvent"),
    array(
"FireToClient","FireEventToClient"),
    array(
"Flags","GetConVarFlags"),
    array(
"Flags.set","SetConVarFlags"),
    array(
"FloatValue","GetConVarFloat"),
    array(
"FloatValue.set","SetConVarFloat"),
    array(
"Format","SQL_FormatQuery"),
    array(
"Get","GetArrayCell"),
    array(
"GetArray","GetArrayArray"),
    array(
"GetArray","GetTrieArray"),
    array(
"GetBool","GetEventBool"),
    array(
"GetBounds","GetConVarBounds"),
    array(
"GetColor","KvGetColor"),
    array(
"GetCommandOverride","GetAdmGroupCmdOverride"),
    array(
"GetDataType","KvGetDataType"),
    array(
"GetDefault","GetConVarDefault"),
    array(
"GetErrorString","SMC_GetErrorString"),
    array(
"GetFlags","GetAdmGroupAddFlags"),
    array(
"GetFlags","GetAdminFlags"),
    array(
"GetFloat","GetEventFloat"),
    array(
"GetFloat","KvGetFloat"),
    array(
"GetGroup","GetAdminGroup"),
    array(
"GetGroupImmunity","GetAdmGroupImmunity"),
    array(
"GetIdentifier","SQL_GetDriverIdent"),
    array(
"GetInfoString","GetTopMenuInfoString"),
    array(
"GetInt","GetEventInt"),
    array(
"GetItem","GetMenuItem"),
    array(
"GetKey","GetTrieSnapshotKey"),
    array(
"GetName","GetConVarName"),
    array(
"GetName","GetEventName"),
    array(
"GetNameSymbol","KvGetNameSymbol"),
    array(
"GetNext","ReadDirEntry"),
    array(
"GetNum","KvGetNum"),
    array(
"GetObjName","GetTopMenuObjName"),
    array(
"GetPassword","GetAdminPassword"),
    array(
"GetProduct","SQL_GetDriverProduct"),
    array(
"GetRepeatedFieldCount","PbGetRepeatedFieldCount"),
    array(
"GetSectionName","KvGetSectionName"),
    array(
"GetSectionSymbol","KvGetSectionSymbol"),
    array(
"GetString","GetArrayString"),
    array(
"GetString","GetConVarString"),
    array(
"GetString","GetEventString"),
    array(
"GetString","GetTrieString"),
    array(
"GetString","KvGetString"),
    array(
"GetSubString","GetRegexSubString"),
    array(
"GetTitle","GetMenuTitle"),
    array(
"GetUInt64","KvGetUInt64"),
    array(
"GetUsername","GetAdminUsername"),
    array(
"GetValue","GetTrieValue"),
    array(
"GetVector","KvGetVector"),
    array(
"GoBack","KvGoBack"),
    array(
"GotoFirstSubKey","KvGotoFirstSubKey"),
    array(
"GotoNextKey","KvGotoNextKey"),
    array(
"GroupCount","GetAdminGroupCount"),
    array(
"GroupImmunitiesCount","GetAdmGroupImmuneCount"),
    array(
"HasField","PbHasField"),
    array(
"HasFlag","GetAdmGroupAddFlag"),
    array(
"HasFlag","GetAdminFlag"),
    array(
"HasResults","SQL_HasResultSet"),
    array(
"ImmunityLevel","GetAdmGroupImmunityLevel"),
    array(
"ImmunityLevel","GetAdminImmunityLevel"),
    array(
"ImmunityLevel.set","SetAdmGroupImmunityLevel"),
    array(
"ImmunityLevel.set","SetAdminImmunityLevel"),
    array(
"Import","KvCopySubkeys"),
    array(
"ImportFromFile","FileToKeyValues"),
    array(
"ImportFromString","StringToKeyValues"),
    array(
"InheritGroup","AdminInheritGroup"),
    array(
"InsertId","SQL_GetInsertId"),
    array(
"InsertItem","InsertMenuItem"),
    array(
"IntValue","GetConVarInt"),
    array(
"IntValue.set","SetConVarInt"),
    array(
"IsFieldNull","SQL_IsFieldNull"),
    array(
"IsReadable","IsPackReadable"),
    array(
"IsReadable","IsStackEmptyckReadable"),
    array(
"IsSameConnection","SQL_IsSameConnection"),
    array(
"ItemCount","GetMenuItemCount"),
    array(
"JumpToKey","KvJumpToKey"),
    array(
"JumpToKeySymbol","KvJumpToKeySymbol"),
    array(
"KeyBufferSize","TrieSnapshotKeyBufferSize"),
    array(
"KeyValues","CreateKeyValues"),
    array(
"Length","GetArraySize"),
    array(
"Length","TrieSnapshotLength"),
    array(
"LoadConfig","LoadTopMenuConfig"),
    array(
"Match","MatchRegex"),
    array(
"Menu","CreateMenu"),
    array(
"MoreRows","SQL_MoreRows"),
    array(
"NodesInStack","KvNodesInStack"),
    array(
"NoVoteButton.set","SetMenuNoVoteButton"),
    array(
"OnEnd.set","SMC_SetParseEnd"),
    array(
"OnEnterSection","SMCParser_OnEnterSection_set"),
    array(
"OnKeyValue","SMCParser_OnKeyValue_set"),
    array(
"OnLeaveSection","SMCParser_OnLeaveSection_set"),
    array(
"OnRawLine","SMC_SetRawLine"),
    array(
"OnStart.set","SMC_SetParseStart"),
    array(
"OptionFlags","GetMenuOptionFlags"),
    array(
"OptionFlags.set","SetMenuOptionFlags"),
    array(
"Pagination","GetMenuPagination"),
    array(
"Pagination.set","SetMenuPagination"),
    array(
"Panel","CreatePanel"),
    array(
"ParseFile","SMC_ParseFile"),
    array(
"Pop","PopStackCell"),
    array(
"PopArray","PopStackArray"),
    array(
"PopString","PopStackString"),
    array(
"Position","FilePosition"),
    array(
"Position","GetPackPosition"),
    array(
"Position.set","SetPackPosition"),
    array(
"Push","PushArrayCell"),
    array(
"Push","PushStackCell"),
    array(
"PushArray","PushArrayArray"),
    array(
"PushArray","PushStackArray"),
    array(
"PushString","PushArrayString"),
    array(
"PushString","PushStackString"),
    array(
"Query","SQL_TQuery"),
    array(
"Read","ReadFile"),
    array(
"ReadAngle","BfReadAngle"),
    array(
"ReadAngle","PbReadAngle"),
    array(
"ReadAngles","BfReadAngles"),
    array(
"ReadBool","BfReadBool"),
    array(
"ReadBool","PbReadBool"),
    array(
"ReadByte","BfReadByte"),
    array(
"ReadCell","ReadPackCell"),
    array(
"ReadChar","BfReadChar"),
    array(
"ReadColor","PbReadColor"),
    array(
"ReadCoord","BfReadCoord"),
    array(
"ReadEntity","BfReadEntity"),
    array(
"ReadFloat","BfReadFloat"),
    array(
"ReadFloat","PbReadFloat"),
    array(
"ReadFloat","ReadPackFloat"),
    array(
"ReadFunction","ReadPackFunction"),
    array(
"ReadInt","PbReadInt"),
    array(
"ReadInt16","File_ReadTyped<int16_t>"),
    array(
"ReadInt32","File_ReadTyped<int32_t>"),
    array(
"ReadInt8","File_ReadTyped<int8_t>"),
    array(
"ReadLine","ReadFileLine"),
    array(
"ReadMessage","PbReadMessage"),
    array(
"ReadNum","BfReadNum"),
    array(
"ReadRepeatedMessage","PbReadRepeatedMessage"),
    array(
"ReadShort","BfReadShort"),
    array(
"ReadString","BfReadString"),
    array(
"ReadString","PbReadString"),
    array(
"ReadString","ReadFileString"),
    array(
"ReadString","ReadPackString"),
    array(
"ReadUint16","File_ReadTyped<uint16_t>"),
    array(
"ReadUint8","File_ReadTyped<uint8_t>"),
    array(
"ReadVecCoord","BfReadVecCoord"),
    array(
"ReadVecNormal","BfReadVecNormal"),
    array(
"ReadVector","PbReadVector"),
    array(
"ReadVector2D","PbReadVector2D"),
    array(
"ReadWord","BfReadWord"),
    array(
"Remove","RemoveFromTopMenu"),
    array(
"Remove","RemoveFromTrie"),
    array(
"RemoveAllItems","RemoveAllMenuItems"),
    array(
"RemoveChangeHook","UnhookConVarChange"),
    array(
"RemoveItem","RemoveMenuItem"),
    array(
"RemoveRepeatedFieldValue","PbRemoveRepeatedFieldValue"),
    array(
"ReplicateToClient","SendConVarValue"),
    array(
"Reset","ResetPack"),
    array(
"Resize","ResizeArray"),
    array(
"RestoreDefault","ResetConVar"),
    array(
"Rewind","KvRewind"),
    array(
"Rewind","SQL_Rewind"),
    array(
"RowCount","SQL_GetRowCount"),
    array(
"SavePosition","KvSavePosition"),
    array(
"Seek","FileSeek"),
    array(
"Selection","GetMenuSelectionPosition"),
    array(
"Send","SendPanelToClient"),
    array(
"Set","SetArrayCell"),
    array(
"SetAngle","PbSetAngle"),
    array(
"SetArray","SetArrayArray"),
    array(
"SetArray","SetTrieArray"),
    array(
"SetBool","PbSetBool"),
    array(
"SetBool","SetConVarBool"),
    array(
"SetBool","SetEventBool"),
    array(
"SetBounds","SetConVarBounds"),
    array(
"SetCharset","SQL_SetCharset"),
    array(
"SetColor","KvSetColor"),
    array(
"SetColor","PbSetColor"),
    array(
"SetEscapeSequences","KvSetEscapeSequences"),
    array(
"SetFlag","SetAdmGroupAddFlag"),
    array(
"SetFlag","SetAdminFlag"),
    array(
"SetFloat","KvSetFloat"),
    array(
"SetFloat","PbSetFloat"),
    array(
"SetFloat","SetConVarFloat"),
    array(
"SetFloat","SetEventFloat"),
    array(
"SetInt","PbSetInt"),
    array(
"SetInt","SetConVarInt"),
    array(
"SetInt","SetEventInt"),
    array(
"SetKeys","SetPanelKeys"),
    array(
"SetNum","KvSetNum"),
    array(
"SetPassword","SetAdminPassword"),
    array(
"SetSectionName","KvSetSectionName"),
    array(
"SetString","KvSetString"),
    array(
"SetString","PbSetString"),
    array(
"SetString","SetArrayString"),
    array(
"SetString","SetConVarString"),
    array(
"SetString","SetEventString"),
    array(
"SetString","SetTrieString"),
    array(
"SetTitle","SetMenuTitle"),
    array(
"SetTitle","SetPanelTitle"),
    array(
"SetUInt64","KvSetUInt64"),
    array(
"SetValue","SetTrieValue"),
    array(
"SetVector","KvSetVector"),
    array(
"SetVector","PbSetVector"),
    array(
"SetVector2D","PbSetVector2D"),
    array(
"ShiftUp","ShiftArrayUp"),
    array(
"Size","GetTrieSize"),
    array(
"SMCParser","SMC_CreateParser"),
    array(
"Snapshot","CreateTrieSnapshot"),
    array(
"StringMap","CreateTrie"),
    array(
"StringMapSnapshotKey","GetTrieSnapshotKey"),
    array(
"Style","GetMenuStyle"),
    array(
"Style","GetPanelStyle"),
    array(
"SwapAt","SwapArrayItems"),
    array(
"TextRemaining","GetPanelTextRemaining"),
    array(
"ToPanel","CreatePanelFromMenu"),
    array(
"Transaction","SQL_CreateTransaction"),
    array(
"VoteResultCallback.set","SetVoteResultCallback"),
    array(
"Write","WriteFile"),
    array(
"WriteAngle","BfWriteAngle"),
    array(
"WriteAngles","BfWriteAngles"),
    array(
"WriteBool","BfWriteBool"),
    array(
"WriteByte","BfWriteByte"),
    array(
"WriteCell","WritePackCell"),
    array(
"WriteChar","BfWriteChar"),
    array(
"WriteCoord","BfWriteCoord"),
    array(
"WriteEntity","BfWriteEntity"),
    array(
"WriteFloat","BfWriteFloat"),
    array(
"WriteFloat","WritePackFloat"),
    array(
"WriteFunction","WritePackFunction"),
    array(
"WriteInt16","File_WriteTyped<int16_t>"),
    array(
"WriteInt32","File_WriteTyped<int32_t>"),
    array(
"WriteInt8","File_WriteTyped<int8_t>"),
    array(
"WriteLine","WriteFileLine"),
    array(
"WriteNum","BfWriteNum"),
    array(
"WriteShort","BfWriteShort"),
    array(
"WriteString","BfWriteString"),
    array(
"WriteString","WriteFileString"),
    array(
"WriteString","WritePackString"),
    array(
"WriteString","WriteStringLine"),
    array(
"WriteVecCoord","BfWriteVecCoord"),
    array(
"WriteVecNormal","BfWriteVecNormal"),
    array(
"WriteWord","BfWriteWord")
);

$gCoded "
// This part is for the 'Vars' button.. remove this comment and the scripts below, outputs the same types onto a single with 1 declare instead of what you see. Easily breaks with unexpected or unsupported formatting, works good enough for what I needed:
ConVar g_hCvarMPGameMode; ConVar g_hCvarModes; ConVar g_hCvarModesOff; ConVar g_hCvarModesTog; ConVar g_hCvarAllow;
bool g_bCvarAllow; bool g_bLeft4Dead2; bool g_bLoaded;
int g_iCvarGlow; int g_iCvarGlowCol; int g_iCvarRandom;
Menu g_hMenuAng; Menu g_hMenuPos; int g_iPlayerSpawn; int g_iRoundStart;
int g_iSpawnCount; int g_iSpawns[MAX_SPAWNS][2];


// This is for the converter, you can press the convert button and see what it does.
SetEventInt(hEvent, \"userid\", GetAdminFlag(client));\nint blah = GetConVarInt(hTest);\n
  AddMenuItem(menu, \"\", \"X + 5.0\");
  AddMenuItem(menu, \"\", \"Y + 5.0\");
  AddMenuItem(menu, \"\", \"Z + 5.0\");
  SetMenuTitle(menu, \"Set Angle\");
  SetMenuExitButton(menu, false);
  SetMenuExitButton(menu, true);
  DisplayMenu(menu, client, MENU_TIME_FOREVER);

    Handle hCfg = OpenFile(sPath, \"w\");
    WriteFileLine(hCfg, \"\");
    if(hCfg==INVALID_HANDLE) CloseHandle(hCfg); // Test

  // Load config
  Handle hFile = CreateKeyValues(\"flares\");
  if( !FileToKeyValues(hFile, sPath) )

  public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast)
  {
  public int AngMenuHandler(Handle menu, MenuAction action, int client, int index)
  {

  BfWriteByte(UserMsgShake, 0);
  BfWriteFloat(UserMsgShake, 1.0);
  BfWriteFloat(UserMsgShake, 0.5);
  BfWriteFloat(UserMsgShake, 0.5);
"
;

if( isset(
$_POST['conv']) )
{
    
$gCoded $_POST['txtBox'];
    
$lines explode("\n"$gCoded);
    
$size sizeof($g_Methods);
    
$gCoded "";

    
// 1. LOOP THROUGH POSTED CODE.
    
foreach($lines as $line)
    {
        
// 1b. REPLACE SPECIFIC THINGS WHERE 'new' HAS TO BE USED
        // Replace specific variables and types:
        
if( preg_match("/\bOpenDirectory\b/"$line) )
        {
            
$line preg_replace("/\bHandle\b/""DirectoryListing"$line);
        }
        if( 
preg_match("/\bCreateMenu|MenuAction\b/"$line) )
        {
            
$line preg_replace("/\bHandle\b/""Menu"$line);
        }
        else if( 
preg_match("/\b(CreateKeyValues|KeyValues)\b/"$line) )
        {
            
$line preg_replace("/\bHandle\b/""KeyValues"$line);
        }
        else if( 
preg_match("/\bOpenFile\b/"$line) )
        {
            
$line preg_replace("/\bHandle\b/""File"$line);
        }
        else if( 
preg_match("/\bSMC_CreateParser\b/"$line) )
        {
            
$line preg_replace("/\bHandle\b/""SMCParser"$line);
        }
        else if( 
preg_match("/\bCreatePanel\b/"$line) )
        {
            
$line preg_replace("/\bHandle\b/""Panel"$line);
        }
        else if( 
preg_match("/\bSQL_CreateTransaction\b/"$line) )
        {
            
$line preg_replace("/\bHandle\b/""Transaction"$line);
        }
        else if( 
preg_match("/\bCreateDataPack\b/"$line) )
        {
            
$line preg_replace("/\bHandle\b/""DataPack"$line);
        }
        else if( 
preg_match("/\bCreateStack\b/"$line) )
        {
            
$line preg_replace("/\bHandle\b/""ArrayStack"$line);
        }
        else if( 
preg_match("/\bCreateTrie\b/"$line) )
        {
            
$line preg_replace("/\bHandle\b/""StringMap"$line);
        }
        else if( 
preg_match("/\bCreateArray\b/"$line) )
        {
            
$line preg_replace("/\bHandle\b/""ArrayList"$line);
        }
        else if( 
preg_match("/\bCreateTopMenu\b/"$line) )
        {
            
$line preg_replace("/\bHandle\b/""TopMenu"$line);
        }
        else if( 
preg_match("/\bCompileRegex\b/"$line) )
        {
            
$line preg_replace("/\bHandle\b/""Regex"$line);
        }
        
// else if( preg_match("/\bCreateEvent\b/", $line) )
        // {
            // $line = str_replace("Handle", "Event", $line);
        // }
        // $line = str_replace("CreateEvent", "new Event", $line);
        
$line str_replace("CompileRegex""new Regex"$line);
        
$line str_replace("CreateTopMenu""new TopMenu"$line);
        
$line str_replace("CreateArray""new ArrayList"$line);
        
$line str_replace("CreateTrie""new StringMap"$line);
        
$line str_replace("CreateStack""new ArrayStack"$line);
        
$line str_replace("CreateDataPack""new DataPack"$line);
        
$line str_replace("SQL_CreateTransaction""new Transaction"$line);
        
$line str_replace("SMC_CreateParser""new SMCParser"$line);
        
$line str_replace("CreateKeyValues""new KeyValues"$line);
        
$line str_replace("CreatePanel""new Panel"$line);
        
$line str_replace("CreateMenu""new Menu"$line);
        
$line str_replace("Handle event""Event event"$line);
        
$line str_replace("Handle menu""Menu menu"$line);

        
// Fix handlers
        
$line str_replace("(Handle convar, const char oldValue[], const newValue[])""(Handle convar, const char[] oldValue, const char[] newValue)"$line);
        
$line str_replace("const char output[], caller, activator, float delay""const char[] output, int caller, int activator, float delay"$line);
        
$line str_replace("&float damage,""float &damage,"$line);
        
$line str_replace("public OnConfigsExecuted""public void OnConfigsExecuted"$line);

        
// Custom changes for my scripts:
        
$line str_replace("public ConVarChanged_""public void ConVarChanged_"$line);

        
// BUG FIXME ::    ERROR CONVERTING - missing var inside () // int menupos = GetMenuSelectionPosition();


        // CloseHandle -> delete
        
if( preg_match("/\bCloseHandle\b/"$line) )
        {
            
$pos strpos($line"CloseHandle");
            
$posB1 strpos($line"("$pos);
            
$posB2 strpos($line")"$pos);
            
$line substr($line0$pos)
            . 
"delete "
            
substr($line$posB1 1$posB2 $posB1 1)
            . 
substr($line$posB2 1)
            ;
        }


        
// INVALID_HANDLE -> null
        
$line str_replace("INVALID_HANDLE""null"$line);



        
// FIX float <view_as> UGLY BULLSHIT
        // float {        Float: {
        // view_as<float>({})
        // Doesn't yet handle single line with multiple floats{}
        /*
        if( preg_match("/\bfloat\b(.*)(\{)/", $line) )
        {
            if( preg_match("/\bview_as\b/", $line) )
            {
                // Duhh
            } else {
                $line = str_replace("float", "view_as<float>(", $line);
                $line = str_replace("}", "})", $line);
            }
        }
        // */

        // 2. LOOP THROUGH AVAILABLE METHODS TO CONVERT
        
for( $i 0$i $size$i++ )
        {
            
// 3. CHECK LINE CONTAINS OLD METHOD TO CONVERT
            
$meth $g_Methods[$i][1];
            
$newM $g_Methods[$i][0];
            
$addB "(";
            
$pos preg_match("/\b$meth\b/"$line);
            if( 
$pos )
            {
                
$pos strpos($line$meth);
                
$posEnd $pos strlen($meth);
                
$posBracket strpos($line"("$posEnd);
                
$endBracket strpos($line")"$posEnd);
                
$endComma strpos($line","$pos);
                
$tog 0;
                if( 
$endComma !== false && $endComma $endBracket )
                {
                    
$endBracket $endComma;
                    
$tog 1;
                }

                
// 3b. SPECIFIC CASE FOR .set
                
if( strpos($newM".set") )
                {
                    
$addB " = ";
                    
$newM str_replace(".set"""$newM);
                    
$tog += 1;

                    
$endB strpos($line")"$posEnd);
                    
$newS trim(
                        
substr($line$endBracket $tog, - 3)
                        . 
substr($line$endB 1)
                    );
                } else {
                    
$newS trim(substr($line$endBracket $tog));
                }

                
$line2 ""
                
substr($line0$pos)
                . 
substr($line$posBracket 1$endBracket $posBracket 1)
                . 
"."
                
$newM
                
$addB
                
$newS
                
"";
                
$line $line2;
            }
        }

        
$line str_replace("Value();""Value;"$line); // Fix for *Value(); bug
        
$line str_replace(".Flags();"".Flags;"$line); // Fix for *Flags(); bug
        
$gCoded .= $line "\n";
    }
} else if( isset(
$_POST['vars']) ) {

    
$array_Vars = array("Address","char","Handle","ConVar","float","int","bool","Regex","TopMenu","ArrayList","StringMap","ArrayStack","DataPack","Transaction","SMCParser","KeyValues","Panel","Menu","Event");
    
$regex_Str "/\b(" implode('|'$array_Vars) . ")\b ([A-Za-z0-9_\+\[\]]+);/";

    
$matches = array();
    
$gCoded $_POST['txtBox'];
    
$gCoded str_replace("  "" "$gCoded);
    
$gCoded str_replace("    "" "$gCoded);
    
preg_match_all($regex_Str$gCoded$matches);

    
$last "";
    
$gCoded "";

    
sort($matches[0]);
    foreach(
$matches[0] as $match)
    {
        
$pos strpos($match" ");
        
$sub substr($match0$pos);
        if( 
$last != $sub )
        {
            
$last $sub;

            
$gCoded substr($gCoded0, -1);
            
$gCoded .= ";\r\n" $sub " " substr($match$pos 1, -1) . ",";
        } else {
            
$gCoded .= substr($match$pos, -1) . ",";
        }
    }
    
$gCoded substr($gCoded1);
    
$gCoded substr($gCoded0, -1);
    
$gCoded .= ";";
}

?>
<br><form action="sm_conv.php" method="post">
<textarea name="txtBox" cols="100" rows="30"><?php echo $gCoded?></textarea>
<br>
<input type="submit" name="conv" value="Convert">
<input type="submit" name="vars" value="Vars">
</form>
</body>
</html>
__________________

Last edited by Silvers; 04-29-2018 at 14:33.
Silvers is offline
Dragokas
Senior Member
Join Date: Nov 2017
Location: Ukraine
Old 04-26-2018 , 17:17   Re: TOGs SourcePawn Syntax Converter [MS Excel Based for now]
Reply With Quote #50

Thanks a much, Silvers!
__________________
Expert of CMD/VBS/VB6. Malware analyst.
Dragokas is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:35.


Powered by vBulletin®
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Theme made by Freecode