Advertisement
SemlerPDX

Load Variables from File / List to VoiceAttack Profile

Mar 12th, 2020
724
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 9.21 KB | None | 0 0
  1. ' Save File System Inline-Function for VoiceAttack -  Load Any/All Variables from File/List to Profile
  2. '  by SemlerPDX Mar2020
  3. '  VETERANS-GAMING.COM
  4. ' --Loads Variables from Text List Format into VA Variables of Appropriate Data Type (INT/DEC/TXT/BOOL)--
  5.  
  6. '  **note:  format for ALL variable names saved to file must start with same 4 character prefix i.e. AVCS_MyVar1, AVCS_MyVar2**
  7. ' ((below is example from VA command action list prior to calling this inline:))
  8. '---------------------------------------------------------------------------------------------
  9. '// Set variable to text contents of save file or text variable (list) depending on parameter(s) used
  10. 'Begin Boolean Compare : [AVCS_SFS_LOAD_list] Equals False
  11. '    Set text [~save_file] to [{TXT:AVCS_SFS_SaveFilePath}] (Trim)
  12. 'Else
  13. '    Set text [~save_file] to [AVCS_SFS_LOAD_contents] (Trim)
  14. 'End Condition
  15. '//
  16. 'Begin Text Compare : [~save_file] Does Not Contain '{NEWLINE}'
  17. '    Set text [~save_file] to [~save_file] (Replace '{SPACE}{TXTSUBSTR:~save_file:0:4}' with '(/n){TXTSUBSTR:~save_file:0:4}')
  18. 'End Condition
  19. '---------------------------------------------------------------------------------------------
  20.  
  21.  
  22. Imports Microsoft.VisualBasic
  23. Imports System
  24. Imports System.Collections
  25. Imports System.Collections.Generic
  26. Imports System.Data
  27. Imports System.Drawing
  28. Imports System.Diagnostics
  29. Imports System.Windows.Forms
  30. Imports System.Linq
  31. Imports System.Xml.Linq
  32. Imports System.Threading.Tasks
  33.  
  34. Public Class VAInline
  35.     dim clearVariable as boolean
  36.     dim saveVariable as boolean
  37.     dim variableIndex as integer
  38.     dim countD as integer
  39.     dim countC as integer
  40.     dim contents() as string
  41.     dim entry() as string
  42.    
  43.     Public Sub Main()
  44.        
  45.         if VA.GetText("~save_file") IsNot nothing
  46.            
  47.             'Check and Set Clear/Save Parameter Variables
  48.             if VA.GetBoolean("AVCS_SFS_LOAD_clear") IsNot nothing
  49.                 clearVariable = VA.GetBoolean("AVCS_SFS_LOAD_clear")
  50.             end if
  51.             if VA.GetBoolean("AVCS_SFS_LOAD_save") IsNot nothing
  52.                 saveVariable = VA.GetBoolean("AVCS_SFS_LOAD_save")
  53.             end if
  54.            
  55.             'Split contents of save file into single lines separated by the newline or (/n)
  56.             if VA.GetText("~save_file").Contains(vbNewLine)
  57.                 contents = VA.GetText("~save_file").Split(new string() {Environment.NewLine},StringSplitOptions.None)
  58.             else
  59.                 contents = VA.GetText("~save_file").Split(new string() {"(/n)"},StringSplitOptions.None)
  60.             end if
  61.            
  62.             'In each line, isolate Var Name/Val via '=' and Eval entry value for data type
  63.             for each line as string in contents
  64.                
  65.                 entry = line.Split("=")
  66.                
  67.                 if(entry(1).Contains ("."))
  68.                     countD = entry(1).Split(".").Length -1
  69.                 else
  70.                     countD = 0
  71.                 end if
  72.                 if(entry(1).Contains (","))
  73.                     countC = entry(1).Split(",").Length -1
  74.                 else
  75.                     countC = 0
  76.                 end if
  77.                
  78.                 'Use Comma and Decimal Count to check data type for casting as Int or Dec
  79.                 if((IsNumeric(entry(1))) and (((countD = 1) and (countC = 0)) or ((countD = 0) and (countC = 1)) or ((countD = 0) and (countC = 0))))
  80.                
  81.                     if(entry(1).Contains (".") or entry(1).Contains (","))
  82.                    
  83.                         ' Attempt to Handle International Decimal Separator
  84.                         if(entry(1).Contains (","))
  85.                             entry(1) = Replace(entry(1), ",", ".")
  86.                         end if
  87.                        
  88.                         ' Entry is a DECIMAL Type
  89.                         if((clearVariable) and (saveVariable))
  90.                             ' Prepare Decimal Var for SaveToProfile command, clearing from Profile completely
  91.                             variableIndex = variableIndex + 1
  92.                             VA.SetText("~~varType" + variableIndex.ToString(), "DEC")
  93.                             VA.SetText("~~varName" + variableIndex.ToString(), entry(0))
  94.                         elseif(saveVariable)
  95.                             ' Prepare Decimal Var for SaveToProfile command
  96.                             variableIndex = variableIndex + 1
  97.                             VA.SetText("~~varType" + variableIndex.ToString(), "DEC")
  98.                             VA.SetText("~~varName" + variableIndex.ToString(), entry(0))
  99.                             VA.SetText("~~varValue" + variableIndex.ToString(), entry(1))
  100.                         elseif(clearVariable)
  101.                             ' Clear Decimal Var directly from Profile
  102.                             VA.SetDecimal(entry(0), nothing)
  103.                         else
  104.                             ' Load Decimal Var directly to Profile
  105.                             VA.SetDecimal(entry(0), entry(1))
  106.                         end if
  107.                        
  108.                     else
  109.                    
  110.                         ' Entry is an INTEGER Type
  111.                         if((clearVariable) and (saveVariable))
  112.                             ' Prepare Integer Var for SaveToProfile command, clearing from Profile completely
  113.                             variableIndex = variableIndex + 1
  114.                             VA.SetText("~~varType" + variableIndex.ToString(), "INT")
  115.                             VA.SetText("~~varName" + variableIndex.ToString(), entry(0))
  116.                         elseif(saveVariable)
  117.                             ' Prepare Integer Var for SaveToProfile command
  118.                             variableIndex = variableIndex + 1
  119.                             VA.SetText("~~varType" + variableIndex.ToString(), "INT")
  120.                             VA.SetText("~~varName" + variableIndex.ToString(), entry(0))
  121.                             VA.SetText("~~varValue" + variableIndex.ToString(), entry(1))
  122.                         elseif(clearVariable)
  123.                             ' Clear Integer Var directly from Profile
  124.                             VA.SetInt(entry(0), nothing)
  125.                         else
  126.                             ' Load Integer Var directly to Profile
  127.                             VA.SetInt(entry(0), entry(1))
  128.                         end if
  129.                        
  130.                     end if
  131.                
  132.                 'if entry(1) is NOT Numeric--------------------------  
  133.                 elseif((LCase (entry(1)) = "true") or (LCase (entry(1)) = "false"))
  134.                
  135.                     ' Entry is a BOOLEAN Type
  136.                     if((clearVariable) and (saveVariable))
  137.                         ' Prepare Boolean Var for SaveToProfile command, clearing from Profile completely
  138.                         variableIndex = variableIndex + 1
  139.                         VA.SetText("~~varType" + variableIndex.ToString(), "BOOL")
  140.                         VA.SetText("~~varName" + variableIndex.ToString(), entry(0))
  141.                     elseif(saveVariable)
  142.                         ' Prepare Boolean Var for SaveToProfile command
  143.                         variableIndex = variableIndex + 1
  144.                         VA.SetText("~~varType" + variableIndex.ToString(), "BOOL")
  145.                         VA.SetText("~~varName" + variableIndex.ToString(), entry(0))
  146.                         VA.SetText("~~varValue" + variableIndex.ToString(), entry(1))
  147.                     elseif(clearVariable)
  148.                         ' Clear Boolean Var directly from Profile
  149.                         VA.SetBoolean(entry(0), nothing)
  150.                     else
  151.                         ' Load Boolean Var directly to Profile
  152.                         VA.SetBoolean(entry(0), entry(1))
  153.                     end if
  154.                    
  155.                 else
  156.                
  157.                     ' Entry is a TEXT Type
  158.                     if((clearVariable) and (saveVariable))
  159.                         ' Prepare Text Var for SaveToProfile command, clearing from Profile completely
  160.                         variableIndex = variableIndex + 1
  161.                         VA.SetText("~~varType" + variableIndex.ToString(), "TXT")
  162.                         VA.SetText("~~varName" + variableIndex.ToString(), entry(0))
  163.                     elseif(saveVariable)
  164.                         ' Prepare Text Var for SaveToProfile command
  165.                         variableIndex = variableIndex + 1
  166.                         VA.SetText("~~varType" + variableIndex.ToString(), "TXT")
  167.                         VA.SetText("~~varName" + variableIndex.ToString(), entry(0))
  168.                         VA.SetText("~~varValue" + variableIndex.ToString(), entry(1))
  169.                     elseif(clearVariable)
  170.                         ' Clear Text Var directly from Profile
  171.                         VA.SetText(entry(0), nothing)
  172.                     else
  173.                         ' Load Text Var directly to Profile
  174.                         VA.SetText(entry(0), entry(1))
  175.                     end if
  176.                    
  177.                 end if
  178.             next 'loop around to the next entry value
  179.            
  180.             if(variableIndex > 0)
  181.                 ' Set Max Count of Vars prepared for SaveToProfile command func, execute as sub-command, wait for completion
  182.                 VA.SetInt("~~varIndex", variableIndex.ToString())
  183.                 vaProxy.Command.Execute ("f_sfs_to_profile", true, true)
  184.             end if
  185.        
  186.         end if
  187.    
  188.     End Sub
  189. End Class
  190.  
  191. ' -- end of inline function --
  192.  
  193.  
  194. ' ((below is example from VA command action list for the 'f_sfs_to_profile' command executed at end of inline:))
  195. '---------------------------------------------------------------------------------------------
  196. '
  197. 'Start Loop : Repeat From 1 to [~~varIndex]
  198.     'Set text [~type] to '{TXT:~~varType{INT:~i}}'
  199.     'Begin Text Compare : [~type] Equals 'BOOL'
  200.         'Begin Boolean Compare : [AVCS_SFS_LOAD_clear] Equals True
  201.             'Set Boolean [{TXT:~~varName{INT:~i}}] to [Not Set] (save value to profile)
  202.         'Else
  203.             'Convert text [~~varValue{INT:~i}] to true/false (boolean) [{TXT:~~varName{INT:~i}}]
  204.             'Set Boolean [{TXT:~~varName{INT:~i}}] to [{TXT:~~varName{INT:~i}}] (save value to profile)
  205.         'End Condition
  206.     'Else If Text Compare : [~type] Equals 'TXT'
  207.         'Begin Boolean Compare : [AVCS_SFS_LOAD_clear] Equals True
  208.             'Set text [{TXT:~~varName{INT:~i}}] to [Not Set] (save value to profile)
  209.         'Else
  210.             'Set text [{TXT:~~varName{INT:~i}}] to '{TXT:~~varValue{INT:~i}}' (save value to profile)
  211.         'End Condition
  212.     'Else If Text Compare : [~type] Equals 'DEC'
  213.         'Begin Boolean Compare : [AVCS_SFS_LOAD_clear] Equals True
  214.             'Set decimal [{TXT:~~varName{INT:~i}}] value to [Not Set] (save value to profile)
  215.         'Else
  216.             'Set decimal [{TXT:~~varName{INT:~i}}] value to the converted value of {TXT:~~varValue{INT:~i}} (save value to profile)
  217.         'End Condition
  218.     'Else If Text Compare : [~type] Equals 'INT'
  219.         'Begin Boolean Compare : [AVCS_SFS_LOAD_clear] Equals True
  220.             'Set integer [{TXT:~~varName{INT:~i}}] value to [Not Set] (save value to profile)
  221.         'Else
  222.             'Set integer [{TXT:~~varName{INT:~i}}] value to the converted value of {TXT:~~varValue{INT:~i}} (save value to profile)
  223.         'End Condition
  224.     'End Condition
  225. 'End Loop
  226. '//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement