lugia19

NG+ upscaler

Feb 9th, 2020
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 32.43 KB | None | 0 0
  1. Imports System.IO
  2. Imports System.Text.RegularExpressions
  3. Imports System.Text
  4. Imports System.Threading
  5. Imports System.Drawing
  6.  
  7. Module Module1
  8. Dim Logs As StreamWriter = My.Computer.FileSystem.OpenTextFileWriter(Environment.CurrentDirectory & "\NGUpscaler-log.txt", True, System.Text.Encoding.UTF8)
  9. Dim NGDir As String
  10. Dim RemasterDir As String
  11. Dim ParentDir As String = Environment.CurrentDirectory
  12. Dim SharedDir As String = ParentDir & "\SharedFiles"
  13. Dim scalefraction As String
  14. Dim ScaleFactor As Double
  15. Dim mode As String
  16. Dim choice As String
  17. Dim ShouldMerge As Boolean
  18. Dim ListOfMerges As List(Of String) = {"tamamo_st21.bmp", "gnome_st33r.png",
  19. "008.bmp", "009a_05.bmp", "015_01.bmp", "015_01.jpg",
  20. "015_02.bmp", "015_02.jpg",
  21. "015_03.bmp", "015_03.jpg",
  22. "015_04.bmp", "015_04.jpg",
  23. "017_01.bmp", "017_01.jpg",
  24. "017_02.bmp", "017_02.jpg",
  25. "017_03.bmp", "017_03.jpg",
  26. "017_04.bmp", "017_04.jpg",
  27. "017_05.bmp", "017_05.jpg", "blackwind.bmp",
  28. "elm_poison.bmp", "logo.bmp", "poseidoness.bmp", "poseidoness2.bmp", "window1f.bmp"}.ToList
  29.  
  30.  
  31. Sub Main()
  32. Logs.AutoFlush = True
  33. Logs.WriteLine(vbCrLf & vbCrLf & vbCrLf & vbCrLf & vbCrLf & vbCrLf & DateTime.Now.ToShortDateString & " - " & Now.TimeOfDay.ToString & vbCrLf & vbCrLf & vbCrLf & vbCrLf & vbCrLf & vbCrLf)
  34.  
  35.  
  36. Console.WriteLine("To use this installer the following folder structure is required:")
  37. Console.WriteLine(">Parent directory")
  38. Console.WriteLine(" >Directory where the NG+ zip was extracted")
  39. Console.WriteLine(" >Directory where the Remaster is installed")
  40. Console.WriteLine("This file must be placed inside the parent directory.")
  41. Console.WriteLine("Press Enter to continue.")
  42. Console.ReadLine()
  43. Console.Clear()
  44. Do
  45. Console.WriteLine("Please input the folder name of where NG+ was extracted:")
  46. NGDir = Console.ReadLine()
  47. NGDir = ParentDir & "\" & NGDir
  48. If Not (Directory.Exists(NGDir)) Then
  49. Console.WriteLine("That folder does not exist. Try again.")
  50. ElseIf Not (File.Exists(NGDir & "\mon_que_ng+.exe")) Then
  51.  
  52. Console.WriteLine("The folder does not contain NG+.")
  53. End If
  54.  
  55. Loop While Not Directory.Exists(NGDir) Or Not File.Exists(NGDir & "\mon_que_ng+.exe")
  56. Console.Clear()
  57. Do
  58. Console.WriteLine("Please input the folder name of where the Remaster was installed:")
  59. RemasterDir = Console.ReadLine()
  60. RemasterDir = ParentDir & "\" & RemasterDir
  61. If Not (Directory.Exists(RemasterDir)) Then
  62. Console.WriteLine("That folder does not exist. Try again.")
  63. ElseIf Not (File.Exists(RemasterDir & "\Monster Girl Quest Remastered.exe")) Then
  64. Console.WriteLine("The folder does not contain the remaster.")
  65. End If
  66.  
  67. Loop While Not Directory.Exists(RemasterDir) Or Not File.Exists(RemasterDir & "\Monster Girl Quest Remastered.exe")
  68.  
  69. Do
  70. Console.WriteLine("Use GPU acceleration? (Note: Requires an Nvidia GPU and CUDA, run cuda.exe to install it if you haven't already, it's in the mod folder of the remaster)")
  71. Console.WriteLine("1) Yes")
  72. Console.WriteLine("2) No")
  73. choice = Console.ReadLine()
  74. If choice = "1" Then
  75. mode = "gpu"
  76. Console.Clear()
  77. Exit Do
  78. ElseIf choice = "2" Then
  79. mode = "cpu"
  80. Console.Clear()
  81. Exit Do
  82. End If
  83. Console.Clear()
  84. Loop
  85.  
  86. Do
  87. Console.WriteLine("Please enter the number corresponding to your resolution then press Enter to confirm.")
  88. Console.WriteLine("1) 1080p")
  89. Console.WriteLine("2) 720p")
  90. choice = Console.ReadLine()
  91. If choice = "1" Then
  92. ScaleFactor = 1.8
  93. scalefraction = "*18/10"
  94. Console.Clear()
  95. Exit Do
  96. ElseIf choice = "2" Then
  97. ScaleFactor = 1.5
  98. scalefraction = "*15/10"
  99. Console.Clear()
  100. Exit Do
  101. End If
  102. Console.Clear()
  103. Loop
  104.  
  105. If Not (File.Exists(RemasterDir & "\mod\SideStoryUpscaler.exe")) Then
  106. Console.WriteLine("THIS PROGRAM REQUIRES THAT YOU HAVE THE SIDESTORYUPSCALER INSTALLED.")
  107. Console.WriteLine("PLEASE DOWNLOAD IT FROM THE UPDATES LINK IN THE PASTEBIN AND INSTALL IT IN THE CORRECT LOCATION.")
  108. Return
  109. End If
  110.  
  111.  
  112.  
  113. If Not (Directory.Exists(SharedDir)) Then
  114. Directory.CreateDirectory(SharedDir)
  115. Directory.Move(RemasterDir & "\bg", SharedDir & "\bg")
  116. Directory.Move(RemasterDir & "\chara", SharedDir & "\chara")
  117. Directory.Move(RemasterDir & "\effect", SharedDir & "\effect")
  118. Directory.Move(RemasterDir & "\ency", SharedDir & "\ency")
  119. Directory.Move(RemasterDir & "\se", SharedDir & "\se")
  120. Directory.Move(RemasterDir & "\system", SharedDir & "\system")
  121. End If
  122. 'We have established where NG+ and the remaster are installed. Let's start moving the folders.
  123. 'Now we have all the dirs moved. Junctions time.
  124. MakeJunction(SharedDir & "\bg", RemasterDir & "\bg")
  125. MakeJunction(SharedDir & "\chara", RemasterDir & "\chara")
  126. MakeJunction(SharedDir & "\effect", RemasterDir & "\effect")
  127. MakeJunction(SharedDir & "\ency", RemasterDir & "\ency")
  128. MakeJunction(SharedDir & "\se", RemasterDir & "\se")
  129. MakeJunction(SharedDir & "\system", RemasterDir & "\system")
  130.  
  131. MakeJunction(SharedDir & "\bg", NGDir & "\bg")
  132. MakeJunction(SharedDir & "\chara", NGDir & "\chara")
  133. MakeJunction(SharedDir & "\effect", NGDir & "\effect")
  134. MakeJunction(SharedDir & "\ency", NGDir & "\ency")
  135. MakeJunction(SharedDir & "\se", NGDir & "\se")
  136. MakeJunction(SharedDir & "\system", NGDir & "\system")
  137.  
  138.  
  139. 'Now the remaster is back where it was, only with junctions. Time to copy the miscellaneous files.
  140. File.Copy(RemasterDir & "\arc.nsa", NGDir & "\arc.nsa", True)
  141. File.Copy(RemasterDir & "\arc1.nsa", NGDir & "\arc1.nsa", True)
  142. File.Copy(RemasterDir & "\arc2.nsa", NGDir & "\arc2.nsa", True)
  143. File.Copy(RemasterDir & "\NSFont.dll", NGDir & "\NSFont.dll", True)
  144. File.Copy(RemasterDir & "\nslua.dll", NGDir & "\nslua.dll", True)
  145. File.Copy(RemasterDir & "\nsogg2.dll", NGDir & "\nsogg2.dll", True)
  146. File.Copy(RemasterDir & "\nspng.dll", NGDir & "\nspng.dll", True)
  147. File.Copy(RemasterDir & "\SDL.dll", NGDir & "\SDL.dll", True)
  148.  
  149. Directory.CreateDirectory(NGDir & "\save")
  150.  
  151. 'Time to upscale.
  152.  
  153. If File.Exists(NGDir & "\2Q\effect\015_01.bmp") Then
  154. Dim frtemp As FileInfo = New FileInfo(NGDir & "\2Q\effect\015_01.bmp")
  155. ShouldMerge = MaskCheck(frtemp)
  156. End If
  157.  
  158. Dim di As New DirectoryInfo(NGDir & "\2Q")
  159. Dim count As Integer = 0
  160. For Each subfolder As DirectoryInfo In di.GetDirectories("*", SearchOption.AllDirectories)
  161. If subfolder.Name = "bgm" Or subfolder.Name = "se" Then
  162. Continue For
  163. End If
  164. count = 0
  165. Dim fiArr As FileInfo() = subfolder.GetFiles()
  166. Dim listoflines As List(Of String)
  167.  
  168. If Not (File.Exists(subfolder.FullName & "\filelist.txt")) Then
  169. Dim sw2 As StreamWriter = New StreamWriter(subfolder.FullName & "\filelist.txt")
  170. sw2.Write("")
  171. sw2.Flush()
  172. sw2.Close()
  173. End If
  174.  
  175. listoflines = File.ReadAllLines(subfolder.FullName & "\filelist.txt").ToList
  176.  
  177. For Each fri In fiArr
  178. count = count + 1
  179. If subfolder.Name = "effect" Or subfolder.Name = "system" Or subfolder.Name = "chara" Then
  180. If ListOfMerges.Contains(fri.Name) And ShouldMerge = True Then
  181. Dim tempfriname = fri.FullName
  182. SplitAndMerge(fri)
  183. fri = New FileInfo(fri.FullName.Substring(0, fri.FullName.Length - 4) & ".png")
  184. End If
  185. End If
  186. If fri.Name = "minccubus_hd1.jpg.png" Or fri.Name = "minccubus_hd1.jpg" Then
  187. Continue For
  188. End If
  189. Console.WriteLine("File " & count & " out of " & fiArr.Length)
  190. If fri.Extension <> ".bmp" And fri.Extension <> ".png" And fri.Extension <> ".jpg" And fri.Extension <> ".jpeg" Then
  191. Continue For
  192. End If
  193. If listoflines.Contains(fri.Name & ",1") Then 'was in progress, grab the copy
  194. Dim tempfriname As String = fri.FullName
  195. File.Delete(tempfriname)
  196. File.Copy(tempfriname & "_temp", tempfriname)
  197. fri = New FileInfo(tempfriname)
  198. Console.WriteLine("File " & fri.Name & " was interrupted, restarting")
  199. ElseIf listoflines.Contains(fri.Name & ",0") Then 'already upscaled
  200. Console.WriteLine("Already upscaled.")
  201. Continue For
  202. Else 'It never started upscaling
  203. listoflines.Add(fri.Name & ",1")
  204. Dim sw As StreamWriter = File.AppendText(subfolder.FullName & "\filelist.txt")
  205. sw.WriteLine(fri.Name & ",1")
  206. sw.Close()
  207. File.Copy(fri.FullName, fri.FullName & "_temp")
  208. End If
  209. 'Upscale.
  210. Console.WriteLine("Upscaling file " & fri.Name)
  211. Upscale(fri)
  212. listoflines.Item(listoflines.Count() - 1) = listoflines.Item(listoflines.Count() - 1).Replace(",1", ",0").Replace(".jpg", ".png").Replace(".bmp", ".png").Replace(".jpeg", ".png")
  213.  
  214. File.Delete(subfolder.FullName & "\filelist.txt")
  215. File.WriteAllLines(subfolder.FullName & "\filelist.txt", listoflines.ToArray)
  216. If File.Exists(fri.FullName & "_temp") Then
  217. File.Delete(fri.FullName & "_temp")
  218. End If
  219. Next
  220. Next
  221.  
  222. Dim CurrentFile As Integer = 0
  223. count = 0
  224.  
  225. If Not (Directory.Exists(NGDir & "\txtbackups")) Then
  226. Directory.CreateDirectory(NGDir & "\txtbackups")
  227. Else 'Means it already started running at some point. Starts over.
  228. Do While File.Exists(NGDir & "\txtbackups\" & CurrentFile & ".txt")
  229. File.Delete(NGDir & "\" & CurrentFile & ".txt")
  230. File.Copy(NGDir & "\txtbackups\" & CurrentFile & ".txt", NGDir & "\" & CurrentFile & ".txt")
  231. CurrentFile = CurrentFile + 1
  232. Loop
  233. CurrentFile = 0
  234. End If
  235.  
  236. Console.WriteLine("Done with the upscaling.")
  237. Console.WriteLine("Starting txt file edits.")
  238.  
  239. Do While File.Exists(NGDir & "\" & CurrentFile & ".txt")
  240. Console.WriteLine("File " & CurrentFile & ".txt")
  241. If Not (File.Exists(NGDir & "\txtbackups\" & CurrentFile & ".txt")) Then
  242. File.Move(NGDir & "\" & CurrentFile & ".txt", NGDir & "\txtbackups\" & CurrentFile & ".txt")
  243. Else
  244. File.Delete(NGDir & "\" & CurrentFile & ".txt")
  245. End If
  246.  
  247. Dim reader As StreamReader = New StreamReader(NGDir & "\txtbackups\" & CurrentFile & ".txt")
  248. Dim writer As StreamWriter = New StreamWriter(NGDir & "\" & CurrentFile & ".txt")
  249. Dim a As String
  250. Do
  251. a = reader.ReadLine
  252. If a = ";$V50000G6750S800,600L10000 ;?????800*600????????%1500~" Then 'Special case for the resolution setting
  253. writer.WriteLine(";$V10000G1500S1440,1080L10000 ;TCY800*600AO[o%1500`")
  254. Continue Do
  255. End If
  256. If a Is Nothing Then
  257. Exit Do
  258. End If
  259. If a.Contains(".bmp") Then
  260. a = a.Replace(".bmp", ".png")
  261. End If
  262. If a.Contains(".jpg") Then
  263. a = a.Replace(".jpg", ".png")
  264. End If
  265. If a.Contains(".jpeg") Then
  266. a = a.Replace(".jpeg", ".png")
  267. End If
  268.  
  269. If a.Contains("lsp ") Then
  270. Dim bodge As Boolean = False
  271. If a.IndexOf("lsp") > 0 Then
  272. Console.WriteLine(a)
  273. Console.WriteLine(GetChar(a, a.IndexOf("lsp")))
  274. If GetChar(a, a.IndexOf("lsp")) = ";" Or GetChar(a, a.IndexOf("lsp")) = ">" Then
  275. Console.WriteLine("it's a comment/whatever the fuck the one with > is.")
  276. bodge = True
  277. End If
  278. End If
  279. If bodge = False Then
  280. Dim i As Integer = a.IndexOf("lsp")
  281. i = a.IndexOf("""", i)
  282. Console.WriteLine(a.Substring(i + 1, 3))
  283.  
  284.  
  285. If a.Substring(i + 1, 3) = ":s/" Then
  286.  
  287. Dim i3 As Integer = a.IndexOf(":s/") + 3
  288. Dim i2 As Integer = a.IndexOf(",", i3)
  289.  
  290. i2 = a.IndexOf(",", i2 + 1)
  291. Dim currenttextsize As String = a.Substring(i3, i2 - i3)
  292. Console.WriteLine(currenttextsize)
  293.  
  294. Dim size1, size2 As Integer
  295. Console.WriteLine(currenttextsize.Substring(0, currenttextsize.Length - currenttextsize.IndexOf(",") - 1))
  296. Console.WriteLine(currenttextsize.Substring(currenttextsize.IndexOf(",") + 1))
  297.  
  298. size1 = currenttextsize.Substring(0, currenttextsize.Length - currenttextsize.IndexOf(",") - 1)
  299. size2 = currenttextsize.Substring(currenttextsize.IndexOf(",") + 1)
  300. If ScaleFactor = "1.8" Then
  301. a = a.Replace(":s/" & size1 & "," & size2, ":s/" & size1 + 10 & "," & size2 + 10)
  302. Else
  303. a = a.Replace(":s/" & size1 & "," & size2, ":s/" & size1 + 7 & "," & size2 + 7)
  304. End If
  305. 'Text sizes should now be fixed.
  306. Console.WriteLine(a)
  307.  
  308. End If
  309.  
  310.  
  311. i = a.IndexOf("""", i + 1) + 1 'i is now after the " close
  312. If i = 0 Then
  313. i = a.IndexOf(",", i) + 1
  314. End If
  315. i = a.IndexOf(",", i) + 1
  316. a = a.Insert(i, "(")
  317. a = a.Insert(a.IndexOf(",", i), ")" & scalefraction)
  318. Dim i4 As Integer = a.IndexOf(",", i) + 1 'i4 should be just after the ,
  319. a = a.Insert(i4, "(")
  320. Console.WriteLine((GetChar(a, i4)))
  321.  
  322. Console.WriteLine(a.IndexOf(":", i4))
  323. Console.WriteLine(a.IndexOf(";", i4))
  324. If a.IndexOf(":", i4) <> -1 Then
  325. i4 = a.IndexOf(":", i4)
  326. a = a.Insert(i4, ")" & scalefraction)
  327. ElseIf a.IndexOf(";", i4) <> -1 Then
  328. i4 = a.IndexOf(";", i4)
  329. Do While Not (Char.IsNumber(GetChar(a, i4)))
  330. Console.WriteLine(GetChar(a, i4))
  331. i4 = i4 - 1
  332. Loop
  333.  
  334.  
  335. If GetChar(a, i4 + 1) = "," Then
  336. Console.WriteLine(a)
  337. Console.WriteLine(GetChar(a, i4 + 3))
  338. 'Console.ReadLine()
  339. If GetChar(a, i4 + 3) = "%" Then
  340. i4 = i4 + 3
  341. Dim r As Regex = New Regex("[^a-zA-Z0-9()%+]", RegexOptions.IgnoreCase)
  342. Dim m As Match
  343. m = r.Match(GetChar(a, i4))
  344. Do Until m.Success
  345. i4 = i4 + 1
  346. m = r.Match(GetChar(a, i4))
  347. Loop
  348. a = a.Insert(i4 - 1, ")" & scalefraction)
  349. Console.WriteLine(a)
  350. 'Console.ReadLine()
  351. End If
  352.  
  353. Else
  354. Dim i5 As Integer = i4
  355. Do While Char.IsNumber(GetChar(a, i5))
  356. i5 = i5 - 1
  357. Loop
  358. If GetChar(a, i5) = "+" Then
  359. a = a.Insert(i4, ")" & scalefraction)
  360. Else
  361. a = a.Insert(i4, ")" & scalefraction)
  362. End If
  363. Console.WriteLine(a)
  364. 'Console.ReadLine()
  365. End If
  366.  
  367. Console.WriteLine(a)
  368. Else
  369. a = a & ")" & scalefraction
  370. End If
  371.  
  372. Console.WriteLine(a)
  373.  
  374. If a.Contains("**") Or a.Contains(",*") Or a.Contains(":*") Then
  375. Console.ReadLine()
  376. End If
  377. 'Positions should now be multiplied correctly.
  378.  
  379. End If
  380.  
  381. End If
  382.  
  383. If a.Contains("strsp") Then
  384. Console.WriteLine(a)
  385. Dim i As Integer = a.IndexOf("strsp")
  386. i = a.IndexOf(",", i) + 1
  387. i = a.IndexOf(",", i) + 1
  388. a = a.Insert(i, "(")
  389. i = a.IndexOf(",", i)
  390. a = a.Insert(i, ")" & scalefraction)
  391. i = a.IndexOf(",", i) + 1
  392. a = a.Insert(i, "(")
  393. i = a.IndexOf(",", i)
  394. a = a.Insert(i, ")" & scalefraction)
  395. i = a.IndexOf(",", i) + 1
  396. i = a.IndexOf(",", i) + 1
  397. i = a.IndexOf(",", i) + 1
  398. i = a.IndexOf(",", i)
  399. If ScaleFactor = "1.8" Then
  400. a = a.Insert(i, "+12")
  401. Else
  402. a = a.Insert(i, "+5")
  403. End If
  404. i = a.IndexOf(",", i) + 1
  405. i = a.IndexOf(",", i)
  406. If ScaleFactor = "1.8" Then
  407. a = a.Insert(i, "+12")
  408. Else
  409. a = a.Insert(i, "+5")
  410. End If
  411. i = a.IndexOf(",", i) + 1
  412. i = a.IndexOf(",", i) + 1
  413. i = a.IndexOf(",", i)
  414. If ScaleFactor = "1.8" Then
  415. a = a.Insert(i, "+18")
  416. Else
  417. a = a.Insert(i, "+12")
  418. End If
  419. Console.WriteLine(a)
  420. End If
  421.  
  422. If a.Contains("getscreenshot") Then
  423. Console.WriteLine(a)
  424. Dim i As Integer = a.IndexOf("getscreenshot")
  425. i = a.IndexOf(",", i)
  426. a = a.Insert(i, scalefraction)
  427. i = a.IndexOf(",", i) + 1
  428. Console.WriteLine(GetChar(a, i))
  429. i = i + 1
  430. Dim bodge As Boolean = False
  431. Do While Char.IsNumber(GetChar(a, i))
  432. Console.WriteLine(GetChar(a, i))
  433. i = i + 1
  434. If i = a.Length Then
  435. a = a & scalefraction
  436. bodge = True
  437. End If
  438. Loop
  439. If Not (bodge) Then
  440. a = a.Insert(i - 1, scalefraction)
  441. End If
  442.  
  443.  
  444. Console.WriteLine(a)
  445. End If
  446.  
  447. If a.Contains("mov $savetime," & """" & ":s/") Or a.Contains("mov $savenum," & """" & ":s/") Then
  448. Console.WriteLine(a)
  449. Dim i As Integer = a.IndexOf("""")
  450. i = a.IndexOf(",", i)
  451. If ScaleFactor = "1.8" Then
  452. a = a.Insert(i, "+10")
  453. Else
  454. a = a.Insert(i, "+7")
  455. End If
  456. i = a.IndexOf(",", i) + 1
  457. i = a.IndexOf(",", i)
  458. If ScaleFactor = "1.8" Then
  459. a = a.Insert(i, "+10")
  460. Else
  461. a = a.Insert(i, "+7")
  462. End If
  463. Console.WriteLine(a)
  464. End If
  465.  
  466. If a.Contains("btn ") Then
  467. Console.WriteLine(a)
  468. Dim r As Regex = New Regex("[^a-zA-Z0-9]btn ", RegexOptions.IgnoreCase)
  469. Dim m As Match
  470. m = r.Match(a)
  471. If m.Success Then
  472. Dim i As Integer = a.IndexOf("btn ")
  473. i = a.IndexOf(",", i) + 1
  474. i = a.IndexOf(",", i)
  475. a = a.Insert(i, scalefraction)
  476. i = a.IndexOf(",", i) + 1
  477. i = a.IndexOf(",", i)
  478. a = a.Insert(i, scalefraction)
  479. i = a.IndexOf(",", i) + 1
  480. i = a.IndexOf(",", i)
  481. a = a.Insert(i, scalefraction)
  482. i = a.IndexOf(",", i) + 1
  483. i = a.IndexOf(",", i)
  484. a = a.Insert(i, scalefraction)
  485. Console.WriteLine(a)
  486. End If
  487. End If
  488.  
  489. If a.Contains("setwindow3") Then
  490. Dim i As Integer = a.IndexOf(",")
  491. a = a.Insert(a.IndexOf(","), scalefraction)
  492. i = a.IndexOf(",", i) + 1
  493. i = a.IndexOf(",", i)
  494. a = a.Insert(i, scalefraction)
  495. i = a.IndexOf(",", i) + 1
  496. i = a.IndexOf(",", i) + 1
  497. i = a.IndexOf(",", i) + 1
  498. i = a.IndexOf(",", i)
  499. If ScaleFactor = "1.8" Then
  500. a = a.Insert(i, "+10")
  501. Else
  502. a = a.Insert(i, "+4")
  503. End If
  504. i = a.IndexOf(",", i) + 1
  505. i = a.IndexOf(",", i)
  506. If ScaleFactor = "1.8" Then
  507. a = a.Insert(i, "+10")
  508. Else
  509. a = a.Insert(i, "+4")
  510. End If
  511. i = a.IndexOf("#")
  512. i = a.IndexOf(",", i) + 1
  513. i = a.IndexOf(",", i)
  514. a = a.Insert(i, scalefraction)
  515. i = a.IndexOf(",", i) + 1
  516. i = a.IndexOf(",", i)
  517. a = a.Insert(i, scalefraction)
  518. i = a.IndexOf(",", i) + 1
  519. i = a.IndexOf(",", i)
  520. a = a.Insert(i, scalefraction)
  521. i = a.IndexOf(":", i) - 1
  522. a = a.Insert(i, scalefraction)
  523.  
  524. Console.WriteLine(a)
  525.  
  526. End If
  527.  
  528. If a.Contains("bar ") Then
  529. Dim i As Integer = a.IndexOf("bar ") + 4
  530. Console.WriteLine(a)
  531. Console.WriteLine(GetChar(a, i + 1))
  532.  
  533. If Char.IsNumber(GetChar(a, i + 1)) Then
  534. i = a.IndexOf(",", i) + 1
  535. i = a.IndexOf(",", i) + 1
  536. i = a.IndexOf(",", i)
  537. a = a.Insert(i, scalefraction)
  538. i = a.IndexOf(",", i + 1) + 1
  539. i = a.IndexOf(",", i)
  540. a = a.Insert(i, scalefraction)
  541. i = a.IndexOf(",", i + 1) + 1
  542. i = a.IndexOf(",", i)
  543. a = a.Insert(i, scalefraction)
  544. i = a.IndexOf(",", i + 1) + 1
  545. i = a.IndexOf(",", i)
  546. a = a.Insert(i, scalefraction)
  547. Console.WriteLine(a)
  548.  
  549. End If
  550. End If
  551.  
  552. If a.Contains("mov %monster_x") Then
  553. Dim i As Integer = a.IndexOf(",")
  554. Dim indexchar As String
  555. Console.WriteLine(GetChar(a, i))
  556. If GetChar(a, i) <> "x" Then 'This handles the cases where it's %monster_xb etc.
  557. indexchar = GetChar(a, i)
  558. Else
  559. indexchar = ""
  560. End If
  561. If a.Contains(":") Then 'if there is a command following this one
  562. i = a.IndexOf(":")
  563. a = a.Insert(i, ":mul %monster_x" & indexchar & "," & ScaleFactor)
  564. Else
  565. a = a & ":mul %monster_x" & indexchar & "," & ScaleFactor
  566. End If
  567. Console.WriteLine(a)
  568.  
  569. End If
  570.  
  571. If a.Contains("mov %monster_y") Then
  572. Dim i As Integer = a.IndexOf(",")
  573. Dim indexchar As String
  574. Console.WriteLine(GetChar(a, i))
  575. If GetChar(a, i) <> "y" Then 'This handles the cases where it's %monster_xb etc.
  576. indexchar = GetChar(a, i)
  577. Else
  578. indexchar = ""
  579. End If
  580. If a.Contains(":") Then 'if there is a command following this one
  581. i = a.IndexOf(":")
  582. a = a.Insert(i, ":mul %monster_y" & indexchar & "," & ScaleFactor)
  583. Else
  584. a = a & ":mul %monster_y" & indexchar & "," & ScaleFactor
  585. End If
  586. Console.WriteLine(a)
  587.  
  588. End If
  589.  
  590.  
  591. writer.WriteLine(a)
  592. Loop Until a Is Nothing
  593. reader.Close()
  594. writer.Close()
  595.  
  596.  
  597.  
  598.  
  599. Console.WriteLine("Loop end.")
  600.  
  601. CurrentFile = CurrentFile + 1
  602. Loop
  603.  
  604.  
  605.  
  606.  
  607.  
  608. Logs.Close()
  609. End Sub
  610.  
  611. Sub MakeJunction(Link As String, Target As String)
  612. If Not (Directory.Exists(Target)) Then
  613. RunCommandH("""C:\Windows\System32\cmd.exe""", " /c mklink /J " & """" & Target & """" & " """ & Link & """")
  614. End If
  615.  
  616. End Sub
  617.  
  618.  
  619.  
  620.  
  621. Function RunCommandH(Command As String, Arguments As String) As String
  622. 'Console.WriteLine(Command)
  623. Logs.WriteLine(Command & Arguments)
  624. 'Console.ReadLine()
  625. Dim oProcess As New Process()
  626. Dim oStartInfo As New ProcessStartInfo(Command, Arguments)
  627. oStartInfo.UseShellExecute = False
  628. oStartInfo.RedirectStandardOutput = True
  629. oProcess.StartInfo = oStartInfo
  630. Try
  631. oProcess.Start()
  632. Catch ex As Exception
  633. File.WriteAllText(ParentDir & "crashreport.txt", ex.ToString)
  634. Console.WriteLine(ParentDir)
  635. Console.WriteLine(ex.ToString)
  636. Console.WriteLine("Something went wrong.")
  637. Console.WriteLine("Please message me on discord (you can find me on the NG+ server, check ecstasywastaken.blogspot.com for the link) and send me the crashreport.txt and NGupscaler-log.txt files.")
  638. Console.ReadLine()
  639. End Try
  640.  
  641.  
  642.  
  643. Dim sOutput As String
  644. Using oStreamReader As System.IO.StreamReader = oProcess.StandardOutput
  645. sOutput = oStreamReader.ReadToEnd()
  646. End Using
  647. If Not Arguments.Contains("verbose") Or Arguments.Contains("[1x1") Then
  648. Logs.Writeline(sOutput)
  649. 'Console.WriteLine(sOutput)
  650. End If
  651.  
  652.  
  653. oProcess.WaitForExit()
  654. Return sOutput
  655. oProcess.WaitForExit()
  656.  
  657. oProcess.Dispose()
  658.  
  659. End Function
  660.  
  661. Sub Upscale(fri As FileInfo)
  662.  
  663. RunCommandH("""" & RemasterDir & "\mod\waifu2x\waifu2x-caffe-cui.exe""", "-p " & mode & " -s " & ScaleFactor & " --Model_dir """ & RemasterDir & "\mod\waifu2x\models\anime_style_art_rgb"" -i """ & fri.FullName & """ -o """ & fri.FullName.Substring(0, fri.FullName.Length - 4) & ".png""")
  664. If fri.Extension <> ".png" Then
  665. fri.Delete()
  666. End If
  667. End Sub
  668.  
  669.  
  670.  
  671.  
  672. Function MaskCheck(fri As FileInfo) As Boolean
  673.  
  674. If fri.Extension <> ".bmp" Then
  675. Return False
  676. End If
  677.  
  678. If fri.FullName.Contains("black.bmp") Or fri.FullName.Contains("Marco1") Then
  679. Return True
  680. End If
  681. Dim bmp As New Bitmap(fri.FullName)
  682. Dim FileNameOnly As String = fri.FullName.Substring(0, fri.FullName.Length - 4)
  683. Dim Corner1, Corner2, Corner3, Corner4 As Boolean
  684.  
  685. If Getcolor(fri.FullName, "Red", 0, 0) = 0 And Getcolor(fri.FullName, "Green", 0, 0) = 255 And Getcolor(fri.FullName, "Blue", 0, 0) = 0 Then
  686. Corner1 = True
  687. Else
  688. Corner1 = False
  689. End If
  690.  
  691. If Getcolor(fri.FullName, "Red", 0, bmp.Height - 1) = 0 And Getcolor(fri.FullName, "Green", 0, bmp.Height - 1) = 255 And Getcolor(fri.FullName, "Blue", 0, bmp.Height - 1) = 0 Then
  692. Corner2 = True
  693. Else
  694. Corner2 = False
  695. End If
  696.  
  697. If Getcolor(fri.FullName, "Red", bmp.Width / 2 - 1, 0) = 0 And Getcolor(fri.FullName, "Green", bmp.Width / 2 - 1, 0) = 255 And Getcolor(fri.FullName, "Blue", bmp.Width / 2 - 1, 0) = 0 Then
  698. Corner3 = True
  699. Else
  700. Corner3 = False
  701. End If
  702.  
  703. If Getcolor(fri.FullName, "Red", bmp.Width / 2 - 1, bmp.Height - 1) = 0 And Getcolor(fri.FullName, "Green", bmp.Width / 2 - 1, bmp.Height - 1) = 255 And Getcolor(fri.FullName, "Blue", bmp.Width / 2 - 1, bmp.Height - 1) = 0 Then
  704. Corner4 = True
  705. Else
  706. Corner4 = False
  707. End If
  708.  
  709. bmp.Dispose()
  710. If Corner1 Or Corner2 Or Corner3 Or Corner4 Then
  711. Return True
  712. Else
  713. Return False
  714. End If
  715.  
  716. End Function
  717.  
  718. Sub SplitAndMerge(fri As FileInfo)
  719. Dim filenameonly As String = fri.FullName.Substring(0, fri.FullName.Length - 4)
  720. RunCommandH("""" & RemasterDir & "\mod\ImageMagick\magick.exe""", "convert -crop 50%x100% """ & fri.FullName & """ """ & filenameonly & "_%d.png""")
  721. RunCommandH("""" & RemasterDir & "\mod\ImageMagick\magick.exe""", "convert """ & filenameonly & "_0.png"" ( """ & filenameonly & "_1.png"" -colorspace gray -alpha off -negate ) -compose copy-opacity -composite """ & fri.FullName.Substring(0, fri.FullName.Length - 4) & ".png""")
  722.  
  723. File.Delete(filenameonly & "_1.png")
  724. File.Delete(filenameonly & "_0.png")
  725. If fri.Extension <> ".png" Then
  726. File.Delete(fri.FullName)
  727. End If
  728. End Sub
  729.  
  730. Function Getcolor(File As String, Color As String, X As Double, Y As Double) As Int32
  731. Select Case Color
  732. Case "Red"
  733. Color = "r"
  734. Case "Green"
  735. Color = "g"
  736. Case "Blue"
  737. Color = "b"
  738. End Select
  739. Return Convert.ToInt32(RunCommandH("""" & RemasterDir & "\mod\ImageMagick\magick.exe""", "convert """ & File & """[1x1+" & X & "+" & Y & "] -format ""%[fx: floor(255 * u." & Color & ")]"" info:"))
  740. End Function
  741.  
  742. End Module
Add Comment
Please, Sign In to add comment