AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   TOGs SourcePawn Syntax Converter [MS Excel Based for now] (https://forums.alliedmods.net/showthread.php?t=290805)

ReFlexPoison 07-19-2017 13:01

Re: TOGs SourcePawn Syntax Converter [MS Excel Based for now]
 
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.

ThatOneGuy 07-19-2017 21:05

Re: TOGs SourcePawn Syntax Converter [MS Excel Based for now]
 
Quote:

Originally Posted by ReFlexPoison (Post 2536393)
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.

cigzag 07-20-2017 19:45

Re: TOGs SourcePawn Syntax Converter [MS Excel Based for now]
 
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.

T1MOXA 07-22-2017 15:00

Re: TOGs SourcePawn Syntax Converter [MS Excel Based for now]
 
Lots of errors after formatting: https://forums.alliedmods.net/showthread.php?t=285493

ThatOneGuy 07-22-2017 17:00

Re: TOGs SourcePawn Syntax Converter [MS Excel Based for now]
 
2 Attachment(s)
Quote:

Originally Posted by T1MOXA (Post 2536988)

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.

Silvers 04-23-2018 09:23

Re: TOGs SourcePawn Syntax Converter [MS Excel Based for now]
 
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.

hmmmmm 04-23-2018 20:58

Re: TOGs SourcePawn Syntax Converter [MS Excel Based for now]
 
Peace-Maker has a similar python script that converts functions to their method map equivalents.
https://github.com/peace-maker/sm-methodmapize

ThatOneGuy 04-23-2018 21:51

Re: TOGs SourcePawn Syntax Converter [MS Excel Based for now]
 
Quote:

Originally Posted by Silvers (Post 2589016)
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 (Post 2589103)
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.

Silvers 04-26-2018 17:07

Re: TOGs SourcePawn Syntax Converter [MS Excel Based for now]
 
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>


Dragokas 04-26-2018 17:17

Re: TOGs SourcePawn Syntax Converter [MS Excel Based for now]
 
Thanks a much, Silvers!

Peace-Maker 05-04-2018 13:14

Re: TOGs SourcePawn Syntax Converter [MS Excel Based for now]
 
Quote:

Originally Posted by Silvers (Post 2589592)
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.

I haven't had any issues with that script yet. What exact code was deleted?

Silvers 05-04-2018 17:20

Re: TOGs SourcePawn Syntax Converter [MS Excel Based for now]
 
Quote:

Originally Posted by Peace-Maker (Post 2590713)
I haven't had any issues with that script yet. What exact code was deleted?

I think this or something similar with menus:
PHP Code:

AddToTopMenu(g_hAdminMenu"sm_forcemode_menu"TopMenuObject_ItemHandle_Categoryplayer_commands"sm_forcemode_menu"ADMFLAG_GENERIC); 

It deleted TopMenuObject_Item or some equiv.

Peace-Maker 05-05-2018 15:40

Re: TOGs SourcePawn Syntax Converter [MS Excel Based for now]
 
Quote:

Originally Posted by Silvers (Post 2590731)
I think this or something similar with menus:
PHP Code:

AddToTopMenu(g_hAdminMenu"sm_forcemode_menu"TopMenuObject_ItemHandle_Categoryplayer_commands"sm_forcemode_menu"ADMFLAG_GENERIC); 

It deleted TopMenuObject_Item or some equiv.

That's correct though, since there are seperate AddCategory and AddItem functions on the methodmap.

Dragokas 05-22-2018 07:53

Re: TOGs SourcePawn Syntax Converter [MS Excel Based for now]
 
1 Attachment(s)
Maybe, it will make life easier for somebody.

===========================================
Batch sm plugins converter to new syntax.
===========================================

Benefits: all-in-one. Simple right click => got new .sp/.smx

Copyrights:

MethodMaps converter by Peace-Maker.
New-syntax converter by ThatOneGuy (port to VB6 by SilverShot and Dragokas).
Batch Script by Dragokas.

------------------------------------------

Installation:

- Install Python: https://www.python.org/downloads/
- Download and unpack SourcePawn compiler for Windows (v.1.8+): https://www.sourcemod.net/downloads.php?branch=dev
- Unpack this archive.
- Edit sp_file_handler.reg to point to your compiler path.
- Apply sp_file_handler.reg by double-click.
- Edit Convert_Syntax.cmd to point "include" in correct folder path of your compiler.
- Make shortcut to file "Convert_Syntax.cmd"
- Press Win + R, enter "Shell:Sendto" and place shortcut in opened window.

Usage:

- Press right mouse click on your old-syntax .sp file => choose "Convert_Syntax".
- Wait for coverting to new syntax (stage 1).
- spcomp.exe will try to compile. If errors appear, you should manually fix them (file "plugin.sp").
- Press any key (enter).
- Wait for coverting to new methodmaps (stage 2).
- spcomp.exe will try to compile. If errors appear, you should manually fix them (file "plugin_mm.sp"):
> Usually it's wrong var. types like:
>> Handle cvar = INVALID_HANDLE; => should be: ConVar cvar;
>> Handle hMenu => should be: Menu hMenu
>> Handle hEvent => should be: Event hEvent e.t.c.

At the end, you will receive:
- plugin.sp.bak (your original file). It will not be overwritten in any situation.
- plugin.sp (after stage 1 - new syntax only)
- plugin_mm.sp (after stage 2 - new syntax + new methodmaps)
- .smx files for each stage.

rogeraabbccdd 08-07-2018 21:45

Re: TOGs SourcePawn Syntax Converter [MS Excel Based for now]
 
Quote:

Originally Posted by Dragokas (Post 2593268)
Maybe, it will make life easier for somebody...

Hello, can you add Typedefs convert in your script?
Old funcenum is deprecated in SM 1.10

Dragokas 08-08-2018 11:12

Re: TOGs SourcePawn Syntax Converter [MS Excel Based for now]
 
Hi, rogeraabbccdd!

My script consist of:
Quote:

Originally Posted by Dragokas
Copyrights:

MethodMaps converter by Peace-Maker.
New-syntax converter by ThatOneGuy (port to VB6 by SilverShot and Dragokas).

You have to ask them.

--
P.S. You have a misprint in your signature.

disawar1 09-12-2018 13:11

Re: TOGs SourcePawn Syntax Converter [MS Excel Based for now]
 
Hi there. Here the bug report.

Before
PHP Code:

Float:vOrg[3] = {0.00.00.0}
static 
count 

After
PHP Code:

// Invalid syntax
float vOrg[3] = {0.0int 0.0int 0.0}
static 
count 

Valid syntax
PHP Code:

float vOrg[3] = {0.00.00.0}
static 
int count 


eyal282 01-25-2020 17:58

Re: TOGs SourcePawn Syntax Converter [MS Excel Based for now]
 
Quote:

Originally Posted by Dragokas (Post 2593268)
Maybe, it will make life easier for somebody.

===========================================
Batch sm plugins converter to new syntax.
===========================================

Benefits: all-in-one. Simple right click => got new .sp/.smx

Copyrights:

MethodMaps converter by Peace-Maker.
New-syntax converter by ThatOneGuy (port to VB6 by SilverShot and Dragokas).
Batch Script by Dragokas.

------------------------------------------

Installation:

- Install Python: https://www.python.org/downloads/
- Download and unpack SourcePawn compiler for Windows (v.1.8+): https://www.sourcemod.net/downloads.php?branch=dev
- Unpack this archive.
- Edit sp_file_handler.reg to point to your compiler path.
- Apply sp_file_handler.reg by double-click.
- Edit Convert_Syntax.cmd to point "include" in correct folder path of your compiler.
- Make shortcut to file "Convert_Syntax.cmd"
- Press Win + R, enter "Shell:Sendto" and place shortcut in opened window.

Usage:

- Press right mouse click on your old-syntax .sp file => choose "Convert_Syntax".
- Wait for coverting to new syntax (stage 1).
- spcomp.exe will try to compile. If errors appear, you should manually fix them (file "plugin.sp").
- Press any key (enter).
- Wait for coverting to new methodmaps (stage 2).
- spcomp.exe will try to compile. If errors appear, you should manually fix them (file "plugin_mm.sp"):
> Usually it's wrong var. types like:
>> Handle cvar = INVALID_HANDLE; => should be: ConVar cvar;
>> Handle hMenu => should be: Menu hMenu
>> Handle hEvent => should be: Event hEvent e.t.c.

At the end, you will receive:
- plugin.sp.bak (your original file). It will not be overwritten in any situation.
- plugin.sp (after stage 1 - new syntax only)
- plugin_mm.sp (after stage 2 - new syntax + new methodmaps)
- .smx files for each stage.

native SQLiteVIPAPI_AddFeature(char FeatureName[64], Handle VIPLevelList, Handle NameList, &bool AlreadyExisted=false);

This is generated by your converter, should be bool &. Also should be native int SQLiteVIPAPI_Add...

Dragokas 01-25-2020 18:44

Re: TOGs SourcePawn Syntax Converter [MS Excel Based for now]
 
Quote:

Originally Posted by eyal282 (Post 2681624)
native SQLiteVIPAPI_AddFeature(char FeatureName[64], Handle VIPLevelList, Handle NameList, &bool AlreadyExisted=false);

This is generated by your converter, should be bool &. Also should be native int SQLiteVIPAPI_Add...

You quoted my post, but parser is not mine.
We just made external interface.
Maybe at some point I'll take a look on engine. Not now.
Thanks for report.

ThatOneGuy 01-25-2020 23:40

Re: TOGs SourcePawn Syntax Converter [MS Excel Based for now]
 
Quote:

Originally Posted by eyal282 (Post 2681624)
native SQLiteVIPAPI_AddFeature(char FeatureName[64], Handle VIPLevelList, Handle NameList, &bool AlreadyExisted=false);

This is generated by your converter, should be bool &. Also should be native int SQLiteVIPAPI_Add...

Quote:

Originally Posted by ThatOneGuy (Post 2472251)
Also, it isnt perfect (and probably never will be) ... the point is that the tool gets you most of the way there, taking a lot of the work out of it (if not all).

As noted, the point is that it does most of the work for you, leaving only a few edits to fix rather processing hundreds or thousands of lines, line by line. Hope it helps. At this point I am leaving it as is. I believe others are providing additional support/ports.

Merc1less 01-16-2021 07:15

Re: TOGs SourcePawn Syntax Converter [MS Excel Based for now]
 
Keep getting an error while converting in Sub "OverrideFunctionType" when it comes to "a_sSplit(UBound(a_sSplit) - 1)", cause there are not items in "a_sSplit".

So I changed this part to:
"UBoundSize = UBound(a_sSplit)
If UBoundSize > 0 Then
sExistingType = a_sSplit(UBoundSize - 1)".

Hope, that is okay and works like mentioned.

eyal282 05-15-2023 06:14

Re: TOGs SourcePawn Syntax Converter [MS Excel Based for now]
 
GetArrayString(Handle ActionBar[client], pos, actionpos, sizeof(actionpos));

I'm not entirely sure what would cause this, when used on

https://github.com/iammyka/left-4-de...ing/rum_rpg.sp

Seems out of place.


All times are GMT -4. The time now is 22:04.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.