llee_____

Bat file

Sep 28th, 2024
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.91 KB | None | 0 0
  1. <# : batch portion
  2. @echo off & setlocal
  3.  
  4. set PATH=%SystemRoot%\System32;%SystemRoot%;%SystemRoot%\System32\WindowsPowerShell\v1.0;%PATH%
  5.  
  6. pushd "%~dp0"
  7.  
  8. set "p1=%~f0"
  9. set p=%p1:^=%
  10. set p=%p:@=%
  11. set p=%p:&=%
  12. if not "%p1%"=="%p%" goto :badpath
  13.  
  14. if not "%~nx0"=="setup.bat" goto :badname
  15.  
  16. echo marco | findstr /C:"polo" >nul
  17. if %ERRORLEVEL% EQU 0 goto :wineskip
  18. echo marco | findstr /V /C:"polo" >nul
  19. if %ERRORLEVEL% NEQ 0 goto :wineskip
  20. echo. >nul || goto :wineskip
  21.  
  22. echo "%~dp0" | findstr /V /C:"%TEMP%" >nul
  23. if %ERRORLEVEL% NEQ 0 goto :temp
  24.  
  25. set "script_path=%~f0"
  26. set "arg1=%1"
  27.  
  28. echo "Starting the script... %~f0"
  29. powershell -noprofile "$_PSCommandPath = [Environment]::GetEnvironmentVariable('script_path', 'Process'); iex ((Get-Content -LiteralPath $_PSCommandPath) | out-string)"
  30. if %ERRORLEVEL% EQU 0 goto :EOF
  31.  
  32. if %ERRORLEVEL% LSS 0 exit /B %ERRORLEVEL%
  33.  
  34. pause
  35. goto :EOF
  36.  
  37. :wineskip
  38. echo It looks like you're trying to run this script through Wine - that won't work. If you're on Linux - use setup_linux.sh instead!
  39. pause
  40. goto :EOF
  41.  
  42. :temp
  43. echo It looks like you're trying to run this script from inside the archive. Make sure you extract the file first.
  44. pause
  45. goto :EOF
  46.  
  47. :badname
  48. echo Don't rename this script, leave it as "setup.bat"!
  49. pause
  50. goto :EOF
  51.  
  52. :badpath
  53. echo %~dp0
  54. echo You put the Unlocker in a path that will break the setup script. Move it somewhere else, for example "C:\unlocker" or "D:\unlocker". The problematic characters are: @^&^^
  55. pause
  56. goto :EOF
  57. : end batch / begin powershell #>
  58.  
  59. function Get-Env {
  60. param (
  61. [string]$name
  62. )
  63.  
  64. Return [Environment]::GetEnvironmentVariable($name, 'Process')
  65. }
  66.  
  67. $arg1 = Get-Env 'arg1'
  68.  
  69. $ErrorActionPreference = 'stop'
  70. Set-Location -LiteralPath (Split-Path -parent $_PSCommandPath)
  71. $FileMissingMessage = ' missing, you didn''t extract all files'
  72. $GameConfigPrefix = 'g_'
  73. $GameConfigSuffix = '.ini'
  74. Clear-Host
  75.  
  76. function Fail {
  77. param (
  78. [string]$message
  79. )
  80.  
  81. Write-Host `n'Fatal error:' -NoNewline -BackgroundColor red -ForegroundColor white
  82. Warn (' ' + $message)
  83. Write-Host 'Script path:' $_PSCommandPath
  84. Write-Host
  85. Exit 1
  86. }
  87.  
  88. function Warn {
  89. param (
  90. [string]$message
  91. )
  92.  
  93. Write-Host $message -ForegroundColor red
  94. }
  95.  
  96. function Success {
  97. param (
  98. [string]$message
  99. )
  100.  
  101. Write-Host $message -ForegroundColor green
  102. }
  103.  
  104. function Special {
  105. param (
  106. [string]$yellow,
  107. [string]$suffix
  108. )
  109.  
  110. Write-Host $yellow -NoNewline -ForegroundColor yellow
  111. Write-Host $suffix
  112. }
  113.  
  114. function Special2 {
  115. param (
  116. [string]$red,
  117. [string]$suffix
  118. )
  119.  
  120. Write-Host $red -NoNewline -ForegroundColor red
  121. Write-Host $suffix
  122. }
  123.  
  124. function Force-Stop-Clients {
  125. If ($client -Eq 'origin') {
  126. $wildcard = 'Origin*'
  127. }
  128. Else {
  129. $wildcard = 'EA*'
  130. }
  131. Stop-Process -Force -Name $wildcard
  132. Wait-Process -Name $wildcard -Timeout 10
  133. }
  134.  
  135. function Delete-Folder-Recursively {
  136. param (
  137. [string]$directory
  138. )
  139.  
  140. If (Test-Path -LiteralPath $directory) {
  141. Get-ChildItem -LiteralPath $directory -Force -Recurse | Remove-Item -Force
  142. Remove-Item -LiteralPath $directory -Force
  143. }
  144. }
  145.  
  146. function Delete-Folder-If-Empty {
  147. param (
  148. [string]$directory
  149. )
  150.  
  151. If ((Test-Path -LiteralPath $directory) -And ((Get-ChildItem -LiteralPath $directory).Count -Eq 0)) {
  152. Remove-Item -LiteralPath $directory -Force
  153. }
  154. }
  155.  
  156. function Get-Client-Path-From-Registry {
  157. param (
  158. [string]$RegistryPath
  159. )
  160.  
  161. $path = (Get-ItemProperty -Path ('Registry::HKEY_LOCAL_MACHINE\SOFTWARE\' + $RegistryPath) -Name ClientPath).ClientPath
  162. Return (Resolve-Path -LiteralPath (Join-Path $path '..'))
  163. }
  164.  
  165. function Is-Admin {
  166. Return ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
  167. }
  168.  
  169. function Is-Special-Admin {
  170. Return ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).Identity.User -like 'S-1-5-21-*-500'
  171. }
  172.  
  173. function Delete-If-Exists {
  174. param (
  175. [string]$path
  176. )
  177.  
  178. If (Test-Path -LiteralPath $path) {
  179. Remove-Item -LiteralPath $path -Force
  180. }
  181. }
  182.  
  183. function Remove-Old-Unlocker {
  184. Delete-If-Exists (Join-Path $client_path 'version_o.dll')
  185. Delete-If-Exists (Join-Path $client_path 'winhttp.dll')
  186. Delete-If-Exists (Join-Path $client_path 'winhttp_o.dll')
  187. Get-ChildItem -LiteralPath $client_path -Force | Where-Object {($_.Name.EndsWith('.ini') -And $_.Name.StartsWith('w_'))} | Remove-Item -Force
  188. }
  189.  
  190. function Common-Setup-Real {
  191. param (
  192. [string]$action
  193. )
  194.  
  195. If (-Not (Is-Admin)) {
  196. Special 'Requesting administrator rights...'
  197. # with "-Wait" it throws an error on Win 7
  198. $process = Start-Process -FilePath setup.bat -Verb RunAs -WorkingDirectory . -ArgumentList $action -PassThru
  199. If (!($process.Id)) {
  200. Fail 'Failed to get administrator rights.'
  201. }
  202. while (!($process.HasExited)) {
  203. Start-Sleep -Milliseconds 200
  204. }
  205. # you have to do it like that without "-Wait"...
  206. Return $process.GetType().GetField('exitCode', 'NonPublic, Instance').GetValue($process)
  207. }
  208.  
  209. Try {
  210. Force-Stop-Clients
  211. Start-Sleep -Seconds 1
  212. Remove-Old-Unlocker
  213. If ($action -Eq 'install') {
  214. If ($client -Eq 'ea_desktop') {
  215. $stageddir2 = Join-Path $stageddir '*'
  216. $ErrorActionPreference = 'silentlycontinue'
  217. & schtasks /Create /F /RL HIGHEST /SC ONCE /ST 00:00 /SD 01/01/2000 /TN copy_dlc_unlocker /TR "xcopy.exe /Y '$dstdll' '$stageddir2'" 2>&1 | Out-Null
  218. If ($LASTEXITCODE -Ne 0) {
  219. & schtasks /Create /F /RL HIGHEST /SC ONCE /ST 00:00 /SD 2000/01/01 /TN copy_dlc_unlocker /TR "xcopy.exe /Y '$dstdll' '$stageddir2'" 2>&1 | Out-Null
  220. }
  221. $ErrorActionPreference = 'stop'
  222. Try {
  223. Add-Content "$env:ProgramData\EA Desktop\machine.ini" "machine.bgsstandaloneenabled=0" -Force -Encoding utf8
  224. }
  225. Catch {}
  226. }
  227. Copy-Item $srcdll -Destination $dstdll -Force
  228. If (Test-Path -LiteralPath $stageddir) {
  229. Copy-Item $srcdll -Destination $dstdll2 -Force
  230. }
  231.  
  232. Return 0
  233. }
  234. ElseIf ($action -Eq 'uninstall') {
  235. Delete-If-Exists $dstdll
  236. Delete-If-Exists $dstdll2
  237. $ErrorActionPreference = 'silentlycontinue'
  238. & schtasks /Delete /TN copy_dlc_unlocker /F 2>&1 | Out-Null
  239. $ErrorActionPreference = 'stop'
  240. Return 0
  241. }
  242. Else {
  243. Return -1
  244. }
  245. }
  246. Catch {
  247. $ErrorActionPreference = 'stop'
  248. Write-Host $_
  249. $tmp = Read-Host -Prompt "Press enter to exit"
  250. Return -1
  251. }
  252. }
  253.  
  254. function Common-Setup {
  255. param (
  256. [string]$action
  257. )
  258.  
  259. $result = Common-Setup-Real $action
  260. If ($result -Ne 0) {
  261. Fail ('An error occured. Could not ' + $action + ' the Unlocker.')
  262. }
  263. }
  264.  
  265. function Create-Config-Directory {
  266. Try {
  267. New-Item -Path $appdatadir -ItemType 'Directory' -Force | Out-Null
  268. }
  269. Catch {
  270. Fail 'Could not create the configs folder.'
  271. }
  272. Success 'Configs folder created!'
  273. }
  274.  
  275. function Install-Unlocker {
  276. Write-Host 'Installing...'
  277.  
  278. If (-Not (Test-Path $srcdll)) {
  279. Fail ($srcdll + $FileMissingMessage + ' or your anti-virus deleted it.')
  280. }
  281. If (-Not (Test-Path $srcconfig)) {
  282. Fail ($srcconfig + $FileMissingMessage + '.')
  283. }
  284.  
  285. Create-Config-Directory
  286. Try {
  287. Copy-Item $srcconfig -Destination $dstconfig -Force
  288. Success 'Main config copied!'
  289. }
  290. Catch {
  291. Fail 'Could not copy the main config.'
  292. }
  293.  
  294. Common-Setup 'install'
  295. Success 'DLC Unlocker installed!'
  296. }
  297.  
  298. function Uninstall-Unlocker {
  299. Write-Host 'Uninstalling...'
  300.  
  301. Try {
  302. Delete-Folder-Recursively $appdatadir
  303. Delete-Folder-If-Empty (Join-Path $appdatadir '..')
  304. Success 'Configs folder deleted!'
  305. }
  306. Catch {
  307. Warn 'Could not delete the configs folder.'
  308. }
  309.  
  310. Common-Setup 'uninstall'
  311. Success 'DLC Unlocker uninstalled!'
  312.  
  313. Try {
  314. Delete-Folder-Recursively $localappdatadir
  315. Delete-Folder-If-Empty (Join-Path $localappdatadir '..')
  316. Success 'Logs folder deleted!'
  317. }
  318. Catch {
  319. Warn 'Could not delete the logs folder.'
  320. }
  321. }
  322.  
  323. function Open-Configs-Folder {
  324. If (Test-Path -LiteralPath $appdatadir) {
  325. Invoke-Item -LiteralPath $appdatadir
  326. Success 'Configs folder opened!'
  327. }
  328. Else {
  329. Warn 'Configs folder not found. Install the Unlocker first.'
  330. }
  331. }
  332.  
  333. function Open-Logs-Folder {
  334. If (Test-Path -LiteralPath $localappdatadir) {
  335. Invoke-Item -LiteralPath $localappdatadir
  336. Success 'Logs folder opened!'
  337. }
  338. Else {
  339. Warn 'Logs folder not found. Install the Unlocker and run EA Desktop/Origin first.'
  340. }
  341. }
  342.  
  343. function Add-Game-Config {
  344. Try {
  345. [string[]] $configs = Get-ChildItem -Path '.' | Where-Object {($_.Name.EndsWith($GameConfigSuffix) -And $_.Name.StartsWith($GameConfigPrefix))} | %{ $_.Name.Substring(2, ($_.Name.Length-6)) }
  346. }
  347. Catch {
  348. $configs = @()
  349. }
  350.  
  351. If ($configs.Length -Eq 0) {
  352. Fail ('Game configs' + $FileMissingMessage + '.')
  353. }
  354. Else {
  355. While ($True) {
  356. Special 'Game configs' ':'
  357. For ($i = 0; $i -Lt $configs.Length; $i++) {
  358. Special ($i + 1) ('. ' + $configs[$i])
  359. }
  360. Special2 'b' '. Go back'
  361.  
  362. $choice = Read-Host -Prompt `n'Choose option number and press enter'
  363. Clear-Host
  364.  
  365. If ($choice -Eq 'b') {
  366. Write-Host 'No game config selected.'
  367. Return
  368. }
  369. Try {
  370. $game = $configs.Get(([int] $choice) - 1)
  371. Break
  372. }
  373. Catch {}
  374. Warn 'Bad option!'
  375. Write-Host
  376. }
  377. }
  378.  
  379. Create-Config-Directory
  380. Special $game ' config selected.'
  381. Try {
  382. Copy-Item ($GameConfigPrefix + $game + $GameConfigSuffix) -Destination $appdatadir -Force
  383. Success 'Game config copied!'
  384. }
  385. Catch {
  386. Fail 'Could not copy the game config.'
  387. }
  388.  
  389. Try {
  390. Delete-If-Exists (Join-Path $localappdatadir ($game + '.etag'))
  391. }
  392. Catch {}
  393. }
  394.  
  395. function Print-Game-Configs {
  396. Write-Host 'Game configs installed: ' -NoNewline
  397.  
  398. Try {
  399. [string[]] $configs = Get-ChildItem -LiteralPath $appdatadir | Where-Object {($_.Name.EndsWith($GameConfigSuffix) -And $_.Name.StartsWith($GameConfigPrefix))} | %{ $_.Name.Substring(2, ($_.Name.Length-6)) }
  400. }
  401. Catch {
  402. $configs = @()
  403. }
  404.  
  405. If ($configs.Length -Eq 0) {
  406. Write-Host 'none' -ForegroundColor yellow
  407. }
  408. Else {
  409. For ($i = 0; $i -Lt $configs.Length; $i++) {
  410. If ($i -Ne 0) {
  411. Write-Host ', ' -NoNewline
  412. }
  413. Write-Host ($configs[$i]) -NoNewline -ForegroundColor cyan
  414. }
  415. Write-Host
  416. }
  417. }
  418.  
  419. function Check-Task {
  420. $old_preference = $ErrorActionPreference
  421. $ErrorActionPreference = 'continue'
  422. & schtasks /Query /TN copy_dlc_unlocker 2>&1>$null
  423. $ErrorActionPreference = $old_preference
  424. If ($LASTEXITCODE -Eq 0) {
  425. Return $True
  426. }
  427. Return $False
  428. }
  429.  
  430. $client = 'ea_desktop'
  431. $client_name = 'EA Desktop'
  432. Try {
  433. $client_path = Get-Client-Path-From-Registry 'Electronic Arts\EA Desktop'
  434. }
  435. Catch {
  436. $client = 'origin'
  437. $client_name = 'Origin'
  438. Try {
  439. $client_path = Get-Client-Path-From-Registry 'WOW6432Node\Origin'
  440. }
  441. Catch {
  442. Try {
  443. $client_path = Get-Client-Path-From-Registry 'Origin'
  444. }
  445. Catch {
  446. Fail 'EA Desktop/Origin not found, reinstall one of them.'
  447. }
  448. }
  449. }
  450.  
  451. $srcdll = Join-Path $client 'version.dll'
  452. $dstdll = Join-Path $client_path 'version.dll'
  453. $stageddir = Join-Path (Join-Path -Resolve $client_path '..') 'StagedEADesktop\EA Desktop'
  454. $dstdll2 = Join-Path $stageddir 'version.dll'
  455.  
  456. $commondir = 'anadius\EA DLC Unlocker v2'
  457. $appdatadir = Join-Path (Get-Env 'AppData') $commondir
  458. $localappdatadir = Join-Path (Get-Env 'LocalAppData') $commondir
  459.  
  460. $srcconfig = 'config.ini'
  461. $dstconfig = Join-Path $appdatadir 'config.ini'
  462.  
  463. If (($arg1 -Eq 'install') -Or ($arg1 -Eq 'uninstall')) {
  464. Exit (Common-Setup-Real $arg1)
  465. }
  466.  
  467. If (Is-Admin) {
  468. If (Is-Special-Admin) {
  469. Warn "DON'T run this script as administrator. It's not necessary.`nThis script will ask for administrator rights when needed.`nIf you run this script by double clicking and still see this error - you use a special Administrator account.`nIf you get any problems - that's probably the reason why. Don't report it."
  470. }
  471. Else {
  472. Fail "DON'T run this script as administrator. It's not necessary.`nThis script will ask for administrator rights when needed.`nIf you run this script by double clicking and still see this error - you probably have UAC disabled. So enable it."
  473. }
  474. }
  475.  
  476. $checkTask = $True
  477. While ($True) {
  478. If ($checkTask) {
  479. If ($client -Eq 'ea_desktop') {
  480. $task = Check-Task
  481. }
  482. Else {
  483. $task = $True
  484. }
  485. $checkTask = $False
  486. }
  487. Special $client_name ' detected'
  488. Write-Host 'DLC Unlocker ' -NoNewline
  489. If ((Test-Path -LiteralPath $dstdll) -and (Test-Path -LiteralPath $dstconfig)) {
  490. Write-Host 'installed' -NoNewline -ForegroundColor green
  491. If ($task) {
  492. Write-Host ''
  493. }
  494. Else {
  495. Write-Host ' (but copy task missing - you will have to reinstall DLC Unloker every time EA app updates)'
  496. }
  497. Print-Game-Configs
  498. }
  499. Else {
  500. Write-Host 'not installed' -ForegroundColor red
  501. }
  502. Special '1' '. Install EA DLC Unlocker'
  503. Special '2' '. Add/Update game config'
  504. Special '3' '. Open folder with installed configs'
  505. Special '4' '. Open folder with log file'
  506. Special '5' '. Uninstall EA DLC Unlocker'
  507. Special2 'q' '. Quit'
  508.  
  509. $choice = Read-Host -Prompt `n'Choose option number and press enter'
  510. Clear-Host
  511.  
  512. If ($choice -Eq '1') { Install-Unlocker; $checkTask = $True }
  513. ElseIf ($choice -Eq '2') { Add-Game-Config }
  514. ElseIf ($choice -Eq '3') { Open-Configs-Folder }
  515. ElseIf ($choice -Eq '4') { Open-Logs-Folder }
  516. ElseIf ($choice -Eq '5') { Uninstall-Unlocker; $checkTask = $True }
  517. ElseIf ($choice -Eq 'q') { Exit 0 }
  518. Else { Warn 'Bad option!' }
  519. Write-Host
  520. }
  521.  
Add Comment
Please, Sign In to add comment