#NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=C:\Users\Puls3\Pictures\Icons\Ethereal\Blue.ico #AutoIt3Wrapper_Res_Fileversion=1.0.0.0 #AutoIt3Wrapper_Res_LegalCopyright=Ethereal #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include #include #include #include #include #include #include Opt("GUIOnEventMode", 1) Global $Version = "0.1" Global $DisplayVersion = $Version Global $Edition = "Consumer" Global $Dev = True If $Dev = True Then $Edition = "Developer" If $Dev = True Then $DisplayVersion = $Version & " Developer" Global $Compiled = "False" If @Compiled = 1 Then $Compiled = "True" Global $SavePath = @ScriptDir & "\Saves\Save.sav" Global $TempSavePath = @ScriptDir & "\Saves\TempSave.ini" Global $LogPath = @ScriptDir & "\Logs\" Global $SavePass = "TemporaryPassword" Global $Log Global $First Global $Name[3] Global $Level[3] Global $Exp[3] Global $ExpMax[3] Global $Dead[3] Global $Display[3] Global $Health[3] Global $HealthMax[3] Global $Attack[3] Global $Defense[3] LogData() AddLog("Ran.") Parameters() Defaults() Load() Form() Loop() Func Form() AddLog("Creating Form.") $Form = GUICreate("Arena v" & $Version, 831, 485, 503, 250) $Display[1] = GUICtrlCreateEdit("", 10, 10, 400, 270, BitOR($ES_CENTER,$ES_READONLY)) GUICtrlSetData(-1, StringFormat("Name Here\r\n\r\nHealth:\r\n( 50 / 100 )\r\n\r\nAttack:\r\n( d12 +1 )\r\n\r\nDefense:\r\n( d10 +1 )")) GUICtrlSetFont(-1, 14, 400, 0, "Segoe UI") $Display[2] = GUICtrlCreateEdit("", 420, 10, 400, 270, BitOR($ES_CENTER,$ES_READONLY)) GUICtrlSetData(-1, StringFormat("Name Here\r\n\r\nHealth:\r\n( 50 / 100 )\r\n\r\nAttack:\r\n( d12 +1 )\r\n\r\nDefense:\r\n( d10 +1 )")) GUICtrlSetFont(-1, 14, 400, 0, "Segoe UI") GUICtrlSetBkColor(-1, 0xFFFFFF) $ActionLogDisplay = GUICtrlCreateEdit("", 10, 290, 810, 140, BitOR($ES_CENTER,$ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN)) GUICtrlSetData(-1, "ActionLogDisplay, Not used yet!") GUICtrlSetFont(-1, 12, 400, 0, "Segoe UI") $ContinueButton = GUICtrlCreateButton("Continue", 10, 440, 810, 35) GUICtrlSetFont(-1, 14, 400, 0, "Segoe UI") GUISetState(@SW_SHOW) GUISetOnEvent($GUI_EVENT_CLOSE,"Close") GUICtrlSetOnEvent($ContinueButton,"Continue") AddLog("Form Created.") EndFunc Func Continue() Attack(1,2) Attack(2,1) EndFunc Func Attack($i,$u) AddLog("Combatnt " & $i & " is attacking.") Local $AttackAmount = Random(1,12,1) AddLog("Combatnt " & $i & " rolled d" & $AttackAmount & " +" & $Attack[$i]) $AttackAmount += $Attack[$i] AddLog("Combatnt " & $u & " is defending.") Local $DefenseAmount = Random(1,10,1) AddLog("Combatnt " & $u & " rolled d" & $DefenseAmount & " +" & $Defense[$u]) $DefenseAmount += $Defense[$u] If ($AttackAmount - $DefenseAmount) > 0 Then Local $TotalAmount = $AttackAmount - $DefenseAmount $Health[$u] -= $TotalAmount AddLog("Combatant " & $i & " attacked for " & $TotalAmount & " damage.") Else AddLog("Combatant " & $i & " missed.") EndIf AddLog("Combatnt " & $u & " finsihed defending.") AddLog("Combatnt " & $i & " finished attacking.") HealthCheck($u) SetDisplay($u) EndFunc Func HealthCheck($i) If $Health[$i] < 1 Then AddLog("Combatnt " & $i & " died.") EndIf EndFunc Func Refresh($i) $Health[$i] = $HealthMax[$i] EndFunc Func Reset($i) $Name[$i] = $Name[0] $Level[$i] = $Level[0] $Exp[$i] = $Exp[0] $ExpMax[$i] = $ExpMax[0] $Dead[$i] = $Dead[0] $Health[$i] = $Health[0] $HealthMax[$i] = $HealthMax[0] $Attack[$i] = $Attack[0] $Defense[$i] = $Defense[0] EndFunc Func SetDisplay($i) $Testing = False Local $Text = $Name[$i] If $Dead[$i] = 1 Then $Text = $Text & " (DEAD)" $Text = $Text & @CRLF & @CRLF $Text = $Text & "Level " & $Level[$i] & ":" & @CRLF $Text = $Text & "( " & $Exp[$i] & " / " & $ExpMax[$i] & " )" & @CRLF & @CRLF $Text = $Text & "Health:" & @CRLF $Text = $Text & "( " & $Health[$i] & " / " & $HealthMax[$i] & " )" & @CRLF & @CRLF $Text = $Text & "Attack:" & @CRLF $Text = $Text & "( d12 +" & $Attack[$i] & " )" & @CRLF & @CRLF $Text = $Text & "Defense:" & @CRLF $Text = $Text & "( d10 +" & $Defense[$i] & " )" If DevTest($Testing) Then MsgBox(0,"Display",$Text) GUICtrlSetData($Display[$i],$Text) EndFunc Func Loop() While 1 Sleep(1000) WEnd EndFunc #Region ;Save & Load Func Encrypt() AddLog("Encrypting.") If FileExists($SavePath) Then FileDelete($SavePath) _Crypt_EncryptFile($TempSavePath, $SavePath, $SavePass, $CALG_RC4) If Not $Dev = True Then FileDelete($TempSavePath) If @error = 0 Then AddLog("Encrypted.") Return 1 Else AddLog("Encryption error code: " & @error) AddLog("Encryption failed.") Return 0 EndIf EndFunc Func Decrypt() AddLog("Decrypting.") If FileExists($TempSavePath) Then FileDelete($TempSavePath) If FileExists($SavePath) Then _Crypt_DecryptFile($SavePath, $TempSavePath, $SavePass, $CALG_RC4) If @error = 0 Then AddLog("Decrypted.") Else AddLog("Decryption error code: " & @error) AddLog("Decryption failed.") EndIf EndFunc Func Save() AddLog("Initiating save.") If Not FileExists($TempSavePath) Then AddLog("Creating save file.") FileOpen($TempSavePath,10) Else Decrypt() EndIf AddLog("Saving.") ;Data IniWrite($TempSavePath, "Data", "Developer", $Dev) IniWrite($TempSavePath, "Data", "Compiled", $Compiled) IniWrite($TempSavePath, "Data", "Version", $Version) IniWrite($TempSavePath, "Data", "Edition", $Edition) IniWrite($TempSavePath, "Data", "User Name", @UserName) IniWrite($TempSavePath, "Data", "PC Name", @ComputerName) IniWrite($TempSavePath, "Data", "OS Version", @OSVersion) IniWrite($TempSavePath, "Data", "OS Language", @OSLang) IniWrite($TempSavePath, "Data", "OS Architecture", @OSArch) IniWrite($TempSavePath, "Data", "CPU Architecture", @CPUArch) IniWrite($TempSavePath, "Data", "AutoIt Version", @AutoItVersion) IniWrite($TempSavePath, "Data", "AutoIt Executable", @AutoItExe) IniWrite($TempSavePath, "Data", "Directory", @ScriptDir) IniWrite($TempSavePath, "Data", "Path", @ScriptFullPath) If $First = "True" Then IniWrite($TempSavePath, "Data", "First Save", @YEAR & "/" & @MON & "/" & @MDAY) IniWrite($TempSavePath, "Data", "Year", @YEAR) IniWrite($TempSavePath, "Data", "Month", @MON) IniWrite($TempSavePath, "Data", "Month Day", @MDAY) IniWrite($TempSavePath, "Data", "Hour", @HOUR) IniWrite($TempSavePath, "Data", "Minute", @MIN) ;Combatants SaveCombatant(1) SaveCombatant(2) If Encrypt() Then AddLog("Saved.") Else AddLog("Save canceled.") EndIf EndFunc Func SaveCombatant($i) IniWrite($TempSavePath, "Combatant" & $i, "Name", $Name[$i]) IniWrite($TempSavePath, "Combatant" & $i, "Level", $Level[$i]) IniWrite($TempSavePath, "Combatant" & $i, "Exp", $Name[$i]) IniWrite($TempSavePath, "Combatant" & $i, "ExpMax", $Name[$i]) IniWrite($TempSavePath, "Combatant" & $i, "Dead", $Dead[$i]) IniWrite($TempSavePath, "Combatant" & $i, "Health", $Health[$i]) IniWrite($TempSavePath, "Combatant" & $i, "HealthMax", $HealthMax[$i]) IniWrite($TempSavePath, "Combatant" & $i, "Attack", $Attack[$i]) IniWrite($TempSavePath, "Combatant" & $i, "Defense", $Defense[$i]) EndFunc Func Load() AddLog("Initiating load.") AddLog("Checking for save file.") If FileExists($SavePath) Then AddLog("Save file found.") Decrypt() AddLog("Loading.") ;Data Local $PreVersion = IniRead($TempSavePath, "Data", "Version", "ERROR") Local $PreEdition = IniRead($TempSavePath, "Data", "Edition", $Edition) $First = IniRead($TempSavePath, "Data", "First Save", "True") VersionCheck($PreVersion) EditionCheck($PreEdition) AddLog("Loaded.") Else AddLog("Save file not found.") AddLog("Load canceled.") $First = "True" EndIf LoadCombatant(1) LoadCombatant(2) EndFunc Func LoadCombatant($i) AddLog("Loading or creating Combatant " & $i & ".") $Name[$i] = IniRead($TempSavePath, "Combatant" & $i, "Name", $Name[0]) $Level[$i] = IniRead($TempSavePath, "Combatant" & $i, "Level", $Level[0]) $Exp[$i] = IniRead($TempSavePath, "Combatant" & $i, "Exp", $Exp[0]) $ExpMax[$i] = IniRead($TempSavePath, "Combatant" & $i, "ExpMax", $ExpMax[0]) $Dead[$i] = IniRead($TempSavePath, "Combatant" & $i, "Dead", $Dead[0]) $Health[$i] = IniRead($TempSavePath, "Combatant" & $i, "Health", $Health[0]) $HealthMax[$i] = IniRead($TempSavePath, "Combatant" & $i, "HealthMax", $HealthMax[0]) $Attack[$i] = IniRead($TempSavePath, "Combatant" & $i, "Attack", $Attack[0]) $Defense[$i] = IniRead($TempSavePath, "Combatant" & $i, "Defense", $Defense[0]) AddLog("Combatant " & $i & " loaded or created.") EndFunc Func Defaults() $Name[0] = "Combatant" $Level[0] = 1 $Exp[0] = 0 $ExpMax = 20 $Dead[0] = 0 $Health[0] = 20 $HealthMax[0] = 20 $Attack[0] = 1 $Defense[0] = 1 EndFunc #EndRegion #Region ;Logging Func AddLog($Text) Local $Testing = False $Log = $Log & "[" & _NowCalc() & "]: " & $Text & @CRLF ConsoleWrite($Text&@CRLF) If DevTest($Testing) Then MsgBox(0,"Display","[" & @YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & "]: " & $Text & @CRLF) EndFunc Func LogData() Local $Testing = False $Log = @CRLF & "[DATA]" & @CRLF & _ "Developer: " & $Dev & @CRLF & _ "Compiled: " & $Compiled & @CRLF & _ "Version: " & $Version & @CRLF & _ "Edition: " & $Edition & @CRLF & _ "Parameters: " & $CmdLine[0] & @CRLF & _ "User Name: " & @UserName & @CRLF & _ "PC Name: " & @ComputerName & @CRLF & _ "OS Version: " & @OSVersion & @CRLF & _ "OS Language: " & @OSLang & @CRLF & _ "OS Architecture: " & @OSArch & @CRLF & _ "CPU Architecture: " & @CPUArch & @CRLF & _ "AutoIt Version: " & @AutoItVersion & @CRLF & _ "AutoIt Executable: " & @AutoItExe & @CRLF & _ "Directory: " & @ScriptDir & @CRLF & _ "Path: " & @ScriptFullPath & @CRLF & _ "Year: " & @YEAR & @CRLF & _ "Month: " & @MON & @CRLF & _ "Month Day: " & @MDAY & @CRLF & _ "Hour: " & @HOUR & @CRLF & _ "Minute: " & @MIN & @CRLF & @CRLF If DevTest($Testing) Then MsgBox(0,"Display",$Log) EndFunc Func SaveLog() Local $Testing = False Local $LogName = @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & ".txt" AddLog("Saving log.") ;Local $TempLog = FileRead($LogPath) Local $File = FileOpen($LogPath & $LogName,10) FileWrite($File,$Log) FileClose($File) If DevTest($Testing) Then MsgBox(0,"Display",$LogPath) If DevTest($Testing) Then MsgBox(0,"Display",$LogPath & $LogName) If DevTest($Testing) Then MsgBox(0,"Display",$Log) $Log = "" EndFunc #EndRegion #Region ;Load Checks Func VersionCheck($PreVersion) $Testing = False AddLog("Checking Version.") If $PreVersion <> $Version Then If $PreVersion = "ERROR" Then AddLog("Failed to read save file version.") AddLog("Save file upgrade / downgrade will not work.") VersionFail($PreVersion) Else AddLog("Save file version does not match. (Version: " & $Version & ", Save Version: " & $PreVersion & ")") AddLog("Save file upgrade / downgrade may or may not work.") EndIf EndIf If DevTest($Testing) Then MsgBox(0,"Version Check", "Version: " & $Version & @CRLF & "Save Version: " & $PreVersion) AddLog("Version check passed.") EndFunc Func VersionFail($PreVersion) AddLog("Version check failed.") MsgBox(0,"Version Check Failed!", "Version: " & $Version & @CRLF & _ "Save Version: " & $PreVersion & @CRLF & _ "This save file cannot be read by this version.") ForceExit() EndFunc Func EditionCheck($PreEdition) $Testing = False AddLog("Checking Edition.") If $Edition = "Consumer" Then If $PreEdition <> "Consumer" Then EditionFail($PreEdition) EndIf EndIf If DevTest($Testing) Then MsgBox(0,"Edition Check", "Edition: " & $Edition & @CRLF & "Save Type: " & $PreEdition) AddLog("Edition check passed.") EndFunc Func EditionFail($PreEdition) AddLog("Edition check failed. (Edition: " & $Edition & ", Save Type: " & $PreEdition & ")") MsgBox(0,"Edition Check Failed!", "Edition: " & $Edition & @CRLF & _ "Save Type: " & $PreEdition & @CRLF & _ "This save file is not allowed to be opened by this edition.") ForceExit() EndFunc #EndRegion Func DevTest($Testing) If $Dev = True And $Testing = True Then Return True EndFunc Func Parameters() AddLog("Checking launch parameters.") $Testing = False If Not $CmdLine[0] = 0 Then $Testing = True AddLog("found " & $CmdLine[0] & " parameter(s).") If DevTest($Testing) Then MsgBox(64, "Passed Parameters", $CmdLine[0] & " parameters have been passed to this script!") For $i = 1 To $CmdLine[0] If DevTest($Testing) Then MsgBox(64, "Passed Parameters", "Parameter " & $i & ": " & $CmdLine[$i]) If $CmdLine[$i] = "-Puls3" Then Puls3Check() Next Else AddLog("No launch parameters.") EndIf EndFunc Func Puls3Check() AddLog("Checking if you are Puls3.") If @UserName = "Puls3" Then AddLog("You are Puls3.") $Puls3 = True Return True Else AddLog("You are not Puls3.") $Puls3 = False Return False EndIf EndFunc Func ForceExit() AddLog("Forcing exit.") SaveLog() Exit EndFunc Func Close() $Testing = False Save() AddLog("Closing.") AddLog("All Hail His Majesty Arch Puls3!") SaveLog() If DevTest($Testing) Then Sleep(5*1000) Exit EndFunc