lugia19

NG+ upscaler + wordwrapper

Feb 10th, 2020
678
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 51.29 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", "gnome_st33r",
  19. "008", "009a_05", "015_01", "015_01",
  20. "015_02", "015_02",
  21. "015_03", "015_03",
  22. "015_04", "015_04",
  23. "017_01", "017_01",
  24. "017_02", "017_02",
  25. "017_03", "017_03",
  26. "017_04", "017_04",
  27. "017_05", "017_05", "blackwind",
  28. "elm_poison", "logo", "poseidoness", "poseidoness2", "window1f"}.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. Dim friname As String = fri.Name.Substring(0, fri.Name.Length - 4)
  180. If friname = "minccubus_hd1.jpg" Then
  181. Continue For
  182. End If
  183. Console.WriteLine("File " & count & " out of " & fiArr.Length)
  184. If fri.Extension <> ".bmp" And fri.Extension <> ".png" And fri.Extension <> ".jpg" And fri.Extension <> ".jpeg" Then
  185. Continue For
  186. End If
  187. If listoflines.Contains(friname & ",1") Then 'was in progress, grab the copy
  188. Dim tempfriname As String = fri.FullName
  189. File.Delete(tempfriname)
  190. File.Copy(tempfriname & "_temp", tempfriname)
  191. fri = New FileInfo(tempfriname)
  192. Console.WriteLine("File " & friname & " was interrupted, restarting")
  193. ElseIf listoflines.Contains(friname & ",0") Then 'already upscaled
  194. Console.WriteLine("Already upscaled.")
  195. If fri.Extension <> ".png" Then
  196. fri.Delete()
  197. End If
  198. Continue For
  199. Else 'It never started upscaling
  200. If subfolder.Name = "effect" Or subfolder.Name = "system" Or subfolder.Name = "chara" Then
  201. If ListOfMerges.Contains(friname) And ShouldMerge = True Then
  202. Dim tempfriname = fri.FullName
  203. SplitAndMerge(fri)
  204. fri = New FileInfo(fri.FullName.Substring(0, fri.FullName.Length - 4) & ".png")
  205. End If
  206. End If
  207. listoflines.Add(friname & ",1")
  208. Dim sw As StreamWriter = File.AppendText(subfolder.FullName & "\filelist.txt")
  209. sw.WriteLine(friname & ",1")
  210. sw.Close()
  211. File.Copy(fri.FullName, fri.FullName & "_temp")
  212. End If
  213. 'Upscale.
  214. Console.WriteLine("Upscaling file " & friname)
  215. Upscale(fri)
  216. listoflines.Item(listoflines.Count() - 1) = listoflines.Item(listoflines.Count() - 1).Replace(",1", ",0")
  217.  
  218. File.Delete(subfolder.FullName & "\filelist.txt")
  219. File.WriteAllLines(subfolder.FullName & "\filelist.txt", listoflines.ToArray)
  220. If File.Exists(fri.FullName & "_temp") Then
  221. File.Delete(fri.FullName & "_temp")
  222. End If
  223. Next
  224. Next
  225.  
  226. Dim CurrentFile As Integer = 0
  227. count = 0
  228.  
  229. If Not (Directory.Exists(NGDir & "\txtbackups")) Then
  230. Directory.CreateDirectory(NGDir & "\txtbackups")
  231. Else 'Means it already started running at some point. Starts over.
  232. Do While File.Exists(NGDir & "\txtbackups\" & CurrentFile & ".txt")
  233. File.Delete(NGDir & "\" & CurrentFile & ".txt")
  234. File.Copy(NGDir & "\txtbackups\" & CurrentFile & ".txt", NGDir & "\" & CurrentFile & ".txt")
  235. CurrentFile = CurrentFile + 1
  236. Loop
  237. CurrentFile = 0
  238. End If
  239.  
  240. Console.WriteLine("Done with the upscaling.")
  241. Console.WriteLine("Starting txt file edits.")
  242.  
  243. Do While File.Exists(NGDir & "\" & CurrentFile & ".txt")
  244. Console.WriteLine("File " & CurrentFile & ".txt")
  245. If Not (File.Exists(NGDir & "\txtbackups\" & CurrentFile & ".txt")) Then
  246. File.Move(NGDir & "\" & CurrentFile & ".txt", NGDir & "\txtbackups\" & CurrentFile & ".txt")
  247. Else
  248. File.Delete(NGDir & "\" & CurrentFile & ".txt")
  249. End If
  250.  
  251. Dim reader As StreamReader = New StreamReader(NGDir & "\txtbackups\" & CurrentFile & ".txt")
  252. Dim writer As StreamWriter = New StreamWriter(NGDir & "\" & CurrentFile & ".txt")
  253. Dim a As String
  254. Do
  255. a = reader.ReadLine
  256. If a = ";$V50000G6750S800,600L10000 ;?????800*600????????%1500~" Then 'Special case for the resolution setting
  257. writer.WriteLine(";$V10000G1500S1440,1080L10000 ;TCY800*600AO[o%1500`")
  258. Continue Do
  259. End If
  260. If a Is Nothing Then
  261. Exit Do
  262. End If
  263. If a.Contains(".bmp") Then
  264. a = a.Replace(".bmp", ".png")
  265. End If
  266. If a.Contains(".jpg") Then
  267. a = a.Replace(".jpg", ".png")
  268. End If
  269. If a.Contains(".jpeg") Then
  270. a = a.Replace(".jpeg", ".png")
  271. End If
  272.  
  273. If a.Contains("lsp ") Then
  274. Dim bodge As Boolean = False
  275. If a.IndexOf("lsp") > 0 Then
  276. Console.WriteLine(a)
  277. Console.WriteLine(GetChar(a, a.IndexOf("lsp")))
  278. If GetChar(a, a.IndexOf("lsp")) = ";" Or GetChar(a, a.IndexOf("lsp")) = ">" Then
  279. Console.WriteLine("it's a comment/whatever the fuck the one with > is.")
  280. bodge = True
  281. End If
  282. End If
  283. If bodge = False Then
  284. Dim i As Integer = a.IndexOf("lsp")
  285. i = a.IndexOf("""", i)
  286. Console.WriteLine(a.Substring(i + 1, 3))
  287.  
  288.  
  289. If a.Substring(i + 1, 3) = ":s/" Then
  290.  
  291. Dim i3 As Integer = a.IndexOf(":s/") + 3
  292. Dim i2 As Integer = a.IndexOf(",", i3)
  293.  
  294. i2 = a.IndexOf(",", i2 + 1)
  295. Dim currenttextsize As String = a.Substring(i3, i2 - i3)
  296. Console.WriteLine(currenttextsize)
  297.  
  298. Dim size1, size2 As Integer
  299. Console.WriteLine(currenttextsize.Substring(0, currenttextsize.Length - currenttextsize.IndexOf(",") - 1))
  300. Console.WriteLine(currenttextsize.Substring(currenttextsize.IndexOf(",") + 1))
  301.  
  302. size1 = currenttextsize.Substring(0, currenttextsize.Length - currenttextsize.IndexOf(",") - 1)
  303. size2 = currenttextsize.Substring(currenttextsize.IndexOf(",") + 1)
  304. If ScaleFactor = "1.8" Then
  305. a = a.Replace(":s/" & size1 & "," & size2, ":s/" & size1 + 10 & "," & size2 + 10)
  306. Else
  307. a = a.Replace(":s/" & size1 & "," & size2, ":s/" & size1 + 7 & "," & size2 + 7)
  308. End If
  309. 'Text sizes should now be fixed.
  310. Console.WriteLine(a)
  311.  
  312. End If
  313.  
  314.  
  315. i = a.IndexOf("""", i + 1) + 1 'i is now after the " close
  316. If i = 0 Then
  317. i = a.IndexOf(",", i) + 1
  318. End If
  319. i = a.IndexOf(",", i) + 1
  320. a = a.Insert(i, "(")
  321. a = a.Insert(a.IndexOf(",", i), ")" & scalefraction)
  322. Dim i4 As Integer = a.IndexOf(",", i) + 1 'i4 should be just after the ,
  323. a = a.Insert(i4, "(")
  324. Console.WriteLine((GetChar(a, i4)))
  325.  
  326. Console.WriteLine(a.IndexOf(":", i4))
  327. Console.WriteLine(a.IndexOf(";", i4))
  328. If a.IndexOf(":", i4) <> -1 Then
  329. i4 = a.IndexOf(":", i4)
  330. a = a.Insert(i4, ")" & scalefraction)
  331. ElseIf a.IndexOf(";", i4) <> -1 Then
  332. i4 = a.IndexOf(";", i4)
  333. Do While Not (Char.IsNumber(GetChar(a, i4)))
  334. Console.WriteLine(GetChar(a, i4))
  335. i4 = i4 - 1
  336. Loop
  337.  
  338.  
  339. If GetChar(a, i4 + 1) = "," Then
  340. Console.WriteLine(a)
  341. Console.WriteLine(GetChar(a, i4 + 3))
  342. 'Console.ReadLine()
  343. If GetChar(a, i4 + 3) = "%" Then
  344. i4 = i4 + 3
  345. Dim r As Regex = New Regex("[^a-zA-Z0-9()%+]", RegexOptions.IgnoreCase)
  346. Dim m As Match
  347. m = r.Match(GetChar(a, i4))
  348. Do Until m.Success
  349. i4 = i4 + 1
  350. m = r.Match(GetChar(a, i4))
  351. Loop
  352. a = a.Insert(i4 - 1, ")" & scalefraction)
  353. Console.WriteLine(a)
  354. 'Console.ReadLine()
  355. End If
  356.  
  357. Else
  358. Dim i5 As Integer = i4
  359. Do While Char.IsNumber(GetChar(a, i5))
  360. i5 = i5 - 1
  361. Loop
  362. If GetChar(a, i5) = "+" Then
  363. a = a.Insert(i4, ")" & scalefraction)
  364. Else
  365. a = a.Insert(i4, ")" & scalefraction)
  366. End If
  367. Console.WriteLine(a)
  368. 'Console.ReadLine()
  369. End If
  370.  
  371. Console.WriteLine(a)
  372. Else
  373. a = a & ")" & scalefraction
  374. End If
  375.  
  376. Console.WriteLine(a)
  377.  
  378. If a.Contains("**") Or a.Contains(",*") Or a.Contains(":*") Then
  379. Console.ReadLine()
  380. End If
  381. 'Positions should now be multiplied correctly.
  382.  
  383. End If
  384.  
  385. End If
  386.  
  387. If a.Contains("strsp") Then
  388. Console.WriteLine(a)
  389. Dim i As Integer = a.IndexOf("strsp")
  390. i = a.IndexOf(",", i) + 1
  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. a = a.Insert(i, "(")
  397. i = a.IndexOf(",", i)
  398. a = a.Insert(i, ")" & scalefraction)
  399. i = a.IndexOf(",", i) + 1
  400. i = a.IndexOf(",", i) + 1
  401. i = a.IndexOf(",", i) + 1
  402. i = a.IndexOf(",", i)
  403. If ScaleFactor = "1.8" Then
  404. a = a.Insert(i, "+12")
  405. Else
  406. a = a.Insert(i, "+5")
  407. End If
  408. i = a.IndexOf(",", i) + 1
  409. i = a.IndexOf(",", i)
  410. If ScaleFactor = "1.8" Then
  411. a = a.Insert(i, "+12")
  412. Else
  413. a = a.Insert(i, "+5")
  414. End If
  415. i = a.IndexOf(",", i) + 1
  416. i = a.IndexOf(",", i) + 1
  417. i = a.IndexOf(",", i)
  418. If ScaleFactor = "1.8" Then
  419. a = a.Insert(i, "+18")
  420. Else
  421. a = a.Insert(i, "+12")
  422. End If
  423. Console.WriteLine(a)
  424. End If
  425.  
  426. If a.Contains("getscreenshot") Then
  427. Console.WriteLine(a)
  428. Dim i As Integer = a.IndexOf("getscreenshot")
  429. i = a.IndexOf(",", i)
  430. a = a.Insert(i, scalefraction)
  431. i = a.IndexOf(",", i) + 1
  432. Console.WriteLine(GetChar(a, i))
  433. i = i + 1
  434. Dim bodge As Boolean = False
  435. Do While Char.IsNumber(GetChar(a, i))
  436. Console.WriteLine(GetChar(a, i))
  437. i = i + 1
  438. If i = a.Length Then
  439. a = a & scalefraction
  440. bodge = True
  441. End If
  442. Loop
  443. If Not (bodge) Then
  444. a = a.Insert(i - 1, scalefraction)
  445. End If
  446.  
  447.  
  448. Console.WriteLine(a)
  449. End If
  450.  
  451. If a.Contains("mov $savetime," & """" & ":s/") Or a.Contains("mov $savenum," & """" & ":s/") Then
  452. Console.WriteLine(a)
  453. Dim i As Integer = a.IndexOf("""")
  454. i = a.IndexOf(",", i)
  455. If ScaleFactor = "1.8" Then
  456. a = a.Insert(i, "+10")
  457. Else
  458. a = a.Insert(i, "+7")
  459. End If
  460. i = a.IndexOf(",", i) + 1
  461. i = a.IndexOf(",", i)
  462. If ScaleFactor = "1.8" Then
  463. a = a.Insert(i, "+10")
  464. Else
  465. a = a.Insert(i, "+7")
  466. End If
  467. Console.WriteLine(a)
  468. End If
  469.  
  470. If a.Contains("btn ") Then
  471. Console.WriteLine(a)
  472. Dim r As Regex = New Regex("[^a-zA-Z0-9]btn ", RegexOptions.IgnoreCase)
  473. Dim m As Match
  474. m = r.Match(a)
  475. If m.Success Then
  476. Dim i As Integer = a.IndexOf("btn ")
  477. i = a.IndexOf(",", i) + 1
  478. i = a.IndexOf(",", i)
  479. a = a.Insert(i, scalefraction)
  480. i = a.IndexOf(",", i) + 1
  481. i = a.IndexOf(",", i)
  482. a = a.Insert(i, scalefraction)
  483. i = a.IndexOf(",", i) + 1
  484. i = a.IndexOf(",", i)
  485. a = a.Insert(i, scalefraction)
  486. i = a.IndexOf(",", i) + 1
  487. i = a.IndexOf(",", i)
  488. a = a.Insert(i, scalefraction)
  489. Console.WriteLine(a)
  490. End If
  491. End If
  492.  
  493. If a.Contains("setwindow3") Then
  494. Dim i As Integer = a.IndexOf(",")
  495. a = a.Insert(a.IndexOf(","), scalefraction)
  496. i = a.IndexOf(",", i) + 1
  497. i = a.IndexOf(",", i)
  498. a = a.Insert(i, scalefraction)
  499. i = a.IndexOf(",", i) + 1
  500. i = a.IndexOf(",", i) + 1
  501. i = a.IndexOf(",", i) + 1
  502. i = a.IndexOf(",", i)
  503. If ScaleFactor = "1.8" Then
  504. a = a.Insert(i, "+10")
  505. Else
  506. a = a.Insert(i, "+4")
  507. End If
  508. i = a.IndexOf(",", i) + 1
  509. i = a.IndexOf(",", i)
  510. If ScaleFactor = "1.8" Then
  511. a = a.Insert(i, "+10")
  512. Else
  513. a = a.Insert(i, "+4")
  514. End If
  515. i = a.IndexOf("#")
  516. i = a.IndexOf(",", i) + 1
  517. i = a.IndexOf(",", i)
  518. a = a.Insert(i, scalefraction)
  519. i = a.IndexOf(",", i) + 1
  520. i = a.IndexOf(",", i)
  521. a = a.Insert(i, scalefraction)
  522. i = a.IndexOf(",", i) + 1
  523. i = a.IndexOf(",", i)
  524. a = a.Insert(i, scalefraction)
  525. i = a.IndexOf(":", i) - 1
  526. a = a.Insert(i, scalefraction)
  527.  
  528. Console.WriteLine(a)
  529.  
  530. End If
  531.  
  532. If a.Contains("bar ") Then
  533. Dim i As Integer = a.IndexOf("bar ") + 4
  534. Console.WriteLine(a)
  535. Console.WriteLine(GetChar(a, i + 1))
  536.  
  537. If Char.IsNumber(GetChar(a, i + 1)) Then
  538. i = a.IndexOf(",", i) + 1
  539. i = a.IndexOf(",", i) + 1
  540. i = a.IndexOf(",", i)
  541. a = a.Insert(i, scalefraction)
  542. i = a.IndexOf(",", i + 1) + 1
  543. i = a.IndexOf(",", i)
  544. a = a.Insert(i, scalefraction)
  545. i = a.IndexOf(",", i + 1) + 1
  546. i = a.IndexOf(",", i)
  547. a = a.Insert(i, scalefraction)
  548. i = a.IndexOf(",", i + 1) + 1
  549. i = a.IndexOf(",", i)
  550. a = a.Insert(i, scalefraction)
  551. Console.WriteLine(a)
  552.  
  553. End If
  554. End If
  555.  
  556. If a.Contains("mov %monster_x") Then
  557. Dim i As Integer = a.IndexOf(",")
  558. Dim indexchar As String
  559. Console.WriteLine(GetChar(a, i))
  560. If GetChar(a, i) <> "x" Then 'This handles the cases where it's %monster_xb etc.
  561. indexchar = GetChar(a, i)
  562. Else
  563. indexchar = ""
  564. End If
  565. If a.Contains(":") Then 'if there is a command following this one
  566. i = a.IndexOf(":")
  567. a = a.Insert(i, ":mul %monster_x" & indexchar & "," & ScaleFactor)
  568. Else
  569. a = a & ":mul %monster_x" & indexchar & "," & ScaleFactor
  570. End If
  571. Console.WriteLine(a)
  572.  
  573. End If
  574.  
  575. If a.Contains("mov %monster_y") Then
  576. Dim i As Integer = a.IndexOf(",")
  577. Dim indexchar As String
  578. Console.WriteLine(GetChar(a, i))
  579. If GetChar(a, i) <> "y" Then 'This handles the cases where it's %monster_xb etc.
  580. indexchar = GetChar(a, i)
  581. Else
  582. indexchar = ""
  583. End If
  584. If a.Contains(":") Then 'if there is a command following this one
  585. i = a.IndexOf(":")
  586. a = a.Insert(i, ":mul %monster_y" & indexchar & "," & ScaleFactor)
  587. Else
  588. a = a & ":mul %monster_y" & indexchar & "," & ScaleFactor
  589. End If
  590. Console.WriteLine(a)
  591.  
  592. End If
  593.  
  594.  
  595. writer.WriteLine(a)
  596. Loop Until a Is Nothing
  597. reader.Close()
  598. writer.Close()
  599.  
  600.  
  601. #Region "Wordwrap code"
  602. Dim sensitivity As Integer = 78
  603. Dim path(1) As String
  604. path(0) = NGDir & "\" & CurrentFile & ".txt"
  605. a = ""
  606. Dim first, second As String
  607. reader = My.Computer.FileSystem.OpenTextFileReader(path(0), Encoding.Default)
  608. writer = My.Computer.FileSystem.OpenTextFileWriter(path(0).Replace(".txt", "_edited_1.txt"), False, Encoding.Default)
  609. Dim total As Integer = File.ReadAllLines(path(0)).Length
  610. Dim current As Integer = 0
  611. Dim EOL As Char
  612. Dim modifiedlines As New List(Of Integer)
  613. Dim testrun As Boolean = False
  614. Do
  615. first = ""
  616. Second = ""
  617. current = current + 1
  618. a = reader.ReadLine
  619. If a <> "" Then
  620. If a(0) = ">" Then
  621. Try
  622. If a.Contains("@") Then
  623. EOL = "@"
  624. ElseIf a.Contains("\") Then
  625. EOL = "\"
  626. Else
  627. Console.WriteLine(a)
  628. EOL = ""
  629. 'Console.ReadLine()
  630. End If
  631.  
  632. If EOL <> vbNullChar Then
  633. If a.IndexOf(">", a.IndexOf(EOL)) <> -1 Then
  634. Dim tlength As Integer
  635. Console.WriteLine(a)
  636. If (a.IndexOf("@")) = -1 Then
  637. Console.WriteLine("what the fuck")
  638. tlength = a.Length
  639. Else
  640. tlength = a.Substring(0, a.IndexOf("@") - 1).Length
  641. Console.WriteLine(a.Substring(0, a.IndexOf("@") - 1))
  642. End If
  643.  
  644.  
  645. Dim i As Integer = a.IndexOf("@")
  646. If i <> -1 Then
  647. Do While a.IndexOf(">", i) <> -1
  648. If a.IndexOf("@", i + 1) <> -1 Then
  649. Console.WriteLine(a.IndexOf("@", i + 1))
  650. Console.WriteLine(a.IndexOf(">", i))
  651.  
  652. If a.IndexOf(">", i) >= a.IndexOf("@", i + 1) Then
  653. tlength = a.Length
  654. Exit Do
  655. End If
  656.  
  657. tlength = tlength + a.Substring(a.IndexOf(">", i), a.IndexOf("@", i + 1) - a.IndexOf(">", i) - 1).Length
  658. Console.WriteLine(a.Substring(a.IndexOf(">", i), a.IndexOf("@", i + 1) - a.IndexOf(">", i) - 1))
  659. ElseIf a.IndexOf("\", i) <> -1 Then
  660. tlength = tlength + a.Substring(a.IndexOf(">", i), a.IndexOf("\", i) - a.IndexOf(">", i) - 1).Length
  661. Console.WriteLine(a.Substring(a.IndexOf(">", i), a.IndexOf("\", i) - a.IndexOf(">", i) - 1))
  662. Else
  663. tlength = tlength + a.Substring(a.IndexOf(">", i)).Length
  664. Console.WriteLine(a.Substring(a.IndexOf(">", i)))
  665. End If
  666.  
  667.  
  668. i = a.IndexOf("@", i + 1)
  669. If i = -1 Then
  670. i = a.IndexOf("\", i + 1)
  671. If i = -1 Then
  672. Exit Do
  673. End If
  674.  
  675. End If
  676. Loop
  677. End If
  678.  
  679. If tlength > sensitivity Then
  680. Console.WriteLine(a(a.LastIndexOf(" ", sensitivity) + 1))
  681. Try
  682. If a(a.LastIndexOf(" ", sensitivity) + 1) = "@" Then
  683. first = a.Substring(0, a.LastIndexOf(" ", a.LastIndexOf(" ", sensitivity) - 1))
  684. second = a.Substring(a.LastIndexOf(" ", a.LastIndexOf(" ", sensitivity) - 1), a.Length - a.LastIndexOf(" ", a.LastIndexOf(" ", sensitivity) - 1))
  685. Else
  686. first = a.Substring(0, a.LastIndexOf(" ", sensitivity))
  687. second = a.Substring(a.LastIndexOf(" ", sensitivity), a.Length - a.LastIndexOf(" ", sensitivity))
  688. End If
  689. Catch ex As Exception
  690. first = a.Substring(0, a.LastIndexOf(" ", sensitivity))
  691. second = a.Substring(a.LastIndexOf(" ", sensitivity), a.Length - a.LastIndexOf(" ", sensitivity))
  692. End Try
  693.  
  694. first = first.Trim()
  695. second = second.Trim()
  696. If second(0) <> ">" Then
  697. second = ">" & second
  698. End If
  699. If first(first.Length - 1) <> "@" Then
  700. first = first & " _@"
  701. End If
  702. If testrun Then
  703. Console.WriteLine(a)
  704. Console.WriteLine(tlength)
  705. Console.WriteLine(first)
  706. Console.WriteLine(second)
  707. Console.ReadLine()
  708. Else
  709. 'FIX IT
  710. writer.WriteLine(first)
  711. If second <> "@" Then
  712. If second(0) = ">" Then second = second.Substring(1)
  713. writer.WriteLine(">" & second)
  714. End If
  715. End If
  716. Else
  717. writer.WriteLine(a)
  718. End If
  719.  
  720. Else
  721. If a.Substring(0, a.LastIndexOf(EOL) - 1).Length > sensitivity Then
  722. Try
  723. Try
  724. If a(a.LastIndexOf(" ", sensitivity) + 1) = "@" Then
  725. first = a.Substring(0, a.LastIndexOf(" ", a.LastIndexOf(" ", sensitivity) - 1))
  726. second = a.Substring(a.LastIndexOf(" ", a.LastIndexOf(" ", sensitivity) - 1), a.Length - a.LastIndexOf(" ", a.LastIndexOf(" ", sensitivity) - 1))
  727. Else
  728. first = a.Substring(0, a.LastIndexOf(" ", sensitivity))
  729. second = a.Substring(a.LastIndexOf(" ", sensitivity), a.Length - a.LastIndexOf(" ", sensitivity))
  730. End If
  731. Catch ex As Exception
  732. first = a.Substring(0, a.LastIndexOf(" ", sensitivity))
  733. second = a.Substring(a.LastIndexOf(" ", sensitivity), a.Length - a.LastIndexOf(" ", sensitivity))
  734. End Try
  735. first = first.Trim()
  736. second = second.Trim()
  737. If testrun Then
  738. Console.WriteLine(first & " _@")
  739. Console.WriteLine(">" & second)
  740. Console.ReadLine()
  741. Else
  742. 'FIX IT
  743.  
  744. writer.WriteLine(first & " _@")
  745. If second <> "@" Then
  746. If second(0) = ">" Then second = second.Substring(1)
  747. writer.WriteLine(">" & second)
  748. End If
  749. End If
  750.  
  751. Catch ex As Exception
  752. Console.WriteLine(a)
  753. Console.WriteLine("This is that stupid exception where the line is too long but doesn't contain any spaces. Up to you how to modify it, the line will remain as is.")
  754. Console.WriteLine("This is on line " & current)
  755. Console.ReadLine()
  756. writer.WriteLine(a)
  757. End Try
  758. Else
  759. writer.WriteLine(a)
  760. End If
  761. End If
  762.  
  763. Else
  764. If a.Length > sensitivity Then
  765. Try
  766. If a(a.LastIndexOf(" ", sensitivity) + 1) = "@" Then
  767. first = a.Substring(0, a.LastIndexOf(" ", a.LastIndexOf(" ", sensitivity) - 1))
  768. second = a.Substring(a.LastIndexOf(" ", a.LastIndexOf(" ", sensitivity) - 1), a.Length - a.LastIndexOf(" ", a.LastIndexOf(" ", sensitivity) - 1))
  769. Else
  770. first = a.Substring(0, a.LastIndexOf(" ", sensitivity))
  771. second = a.Substring(a.LastIndexOf(" ", sensitivity), a.Length - a.LastIndexOf(" ", sensitivity))
  772. End If
  773. Catch ex As Exception
  774. first = a.Substring(0, a.LastIndexOf(" ", sensitivity))
  775. second = a.Substring(a.LastIndexOf(" ", sensitivity), a.Length - a.LastIndexOf(" ", sensitivity))
  776. End Try
  777.  
  778. first = first.Trim()
  779. second = second.Trim()
  780.  
  781. If testrun Then
  782. Console.WriteLine(first & " _@")
  783. Console.WriteLine(">" & second)
  784. Console.ReadLine()
  785. Else
  786. writer.WriteLine(first & " _@")
  787. writer.WriteLine(">" & second)
  788. End If
  789. Else
  790. writer.WriteLine(a)
  791. End If
  792. End If
  793. Catch ex As Exception
  794. Console.WriteLine(ex)
  795. Console.WriteLine("SAFETY MEASURE - IF ERROR THEN DON'T WORDWRAP AT ALL")
  796. writer.WriteLine(a)
  797. End Try
  798.  
  799. Else
  800. writer.WriteLine(a)
  801. End If
  802. Else
  803. writer.WriteLine(a)
  804. End If
  805. Console.WriteLine(current & " out of " & total)
  806. Loop Until a Is Nothing
  807. 'Console.ReadLine()
  808.  
  809. reader.Close()
  810. writer.Close()
  811.  
  812. reader = My.Computer.FileSystem.OpenTextFileReader(path(0).Replace(".txt", "_edited_1.txt"), Encoding.Default)
  813.  
  814. current = 0
  815.  
  816. Do
  817. current = current + 1
  818. a = reader.ReadLine
  819. If a <> "" Then
  820. If a.Contains("_@") Then
  821. modifiedlines.Add(current + 1)
  822. Console.WriteLine("Line " & current + 1 & "added to list")
  823. End If
  824. End If
  825. Loop Until a Is Nothing
  826. 'Console.ReadLine()
  827. reader.Close()
  828.  
  829.  
  830. reader = My.Computer.FileSystem.OpenTextFileReader(path(0).Replace(".txt", "_edited_1.txt"), Encoding.Default)
  831. writer = My.Computer.FileSystem.OpenTextFileWriter(path(0).Replace(".txt", "_edited_2.txt"), False, Encoding.Default)
  832. current = 0
  833.  
  834. total = File.ReadAllLines(path(0).Replace(".txt", "_edited_1.txt")).Length
  835.  
  836. Do
  837. current = current + 1
  838. a = reader.ReadLine
  839. If a <> "" Then
  840.  
  841. Dim regex As New Regex("skip -\d\d")
  842. Dim regex2 As New Regex("skip \d\d")
  843. Dim offset As Integer
  844.  
  845. 'POSITIVE CASE
  846. If regex2.Match(a).Success Then
  847. offset = regex2.Match(a).Value.Replace("skip ", "")
  848. For Each item As Integer In modifiedlines
  849. If item > current And item - current <= offset Then
  850. Console.WriteLine(offset)
  851. Console.WriteLine("current: " & current)
  852. Console.WriteLine("item: " & item)
  853. Console.WriteLine(a)
  854. Console.WriteLine("Skip edited. Is now " & offset + 1 & ", it was " & offset)
  855. Console.WriteLine("This is on line " & current)
  856. a = a.Replace(regex2.Match(a).Value, regex2.Match(a).Value.Replace(offset, offset + 1))
  857. Console.WriteLine(a)
  858. offset = offset + 1
  859. 'Console.ReadLine()
  860. End If
  861. Next
  862.  
  863. Else
  864. regex2 = New Regex("skip \d")
  865. If regex2.Match(a).Success Then
  866. offset = regex2.Match(a).Value.Replace("skip ", "")
  867. For Each item As Integer In modifiedlines
  868. If item > current And item - current <= offset Then
  869. Console.WriteLine(a)
  870. Console.WriteLine("Skip edited. Is now " & offset + 1 & ", it was " & offset)
  871. Console.WriteLine("This is on line " & current)
  872. a = a.Replace(regex2.Match(a).Value, regex2.Match(a).Value.Replace(offset, offset + 1))
  873. Console.WriteLine(a)
  874. offset = offset + 1
  875. 'Console.ReadLine()
  876. End If
  877. Next
  878. Else
  879.  
  880. End If
  881. End If
  882.  
  883.  
  884. 'NEGATIVE CASE
  885. If regex.Match(a).Success Then
  886. offset = regex.Match(a).Value.Replace("skip ", "")
  887. For Each item As Integer In modifiedlines
  888. If item < current And item - current >= offset Then
  889. Console.WriteLine(a)
  890. Console.WriteLine("Skip edited. Is now " & offset - 1 & ", it was " & offset)
  891. Console.WriteLine("This is on line " & current)
  892. Console.WriteLine(regex.Match(a).Value)
  893. Console.WriteLine(regex.Match(a).Value.Replace(offset, offset - 1))
  894.  
  895. a = a.Replace(regex.Match(a).Value, regex.Match(a).Value.Replace(offset, offset - 1))
  896. Console.WriteLine(a)
  897. offset = offset - 1
  898. 'Console.ReadLine()
  899. End If
  900. Next
  901. Else
  902. regex = New Regex("skip -\d")
  903. If regex.Match(a).Success Then
  904. offset = regex.Match(a).Value.Replace("skip ", "")
  905. For Each item As Integer In modifiedlines
  906. If item < current And item - current >= offset Then
  907. Console.WriteLine(a)
  908. Console.WriteLine("Skip edited. Is now " & offset - 1 & ", it was " & offset)
  909. Console.WriteLine("This is on line " & current)
  910. a = a.Replace(regex.Match(a).Value, regex.Match(a).Value.Replace(offset, offset - 1))
  911. Console.WriteLine(a)
  912. offset = offset - 1
  913. 'Console.ReadLine()
  914. End If
  915. Next
  916. Else
  917.  
  918. End If
  919. End If
  920. writer.WriteLine(a)
  921. Else
  922. writer.WriteLine(a)
  923. End If
  924. Console.WriteLine(current & " out of " & total)
  925. Loop Until a Is Nothing
  926. writer.Close()
  927. reader.Close()
  928. File.Delete(path(0))
  929. File.Delete(path(0).Replace(".txt", "_edited_1.txt"))
  930. File.Move(path(0).Replace(".txt", "_edited_2.txt"), path(0))
  931. 'Console.ReadLine()
  932. #End Region
  933.  
  934.  
  935. Console.WriteLine("Loop end.")
  936.  
  937. CurrentFile = CurrentFile + 1
  938. Loop
  939.  
  940.  
  941.  
  942.  
  943.  
  944.  
  945.  
  946.  
  947. Logs.Close()
  948. End Sub
  949.  
  950. Sub MakeJunction(Link As String, Target As String)
  951. If Not (Directory.Exists(Target)) Then
  952. RunCommandH("""C:\Windows\System32\cmd.exe""", " /c mklink /J " & """" & Target & """" & " """ & Link & """")
  953. End If
  954.  
  955. End Sub
  956.  
  957.  
  958.  
  959.  
  960. Function RunCommandH(Command As String, Arguments As String) As String
  961. 'Console.WriteLine(Command)
  962. Logs.WriteLine(Command & Arguments)
  963. 'Console.ReadLine()
  964. Dim oProcess As New Process()
  965. Dim oStartInfo As New ProcessStartInfo(Command, Arguments)
  966. oStartInfo.UseShellExecute = False
  967. oStartInfo.RedirectStandardOutput = True
  968. oProcess.StartInfo = oStartInfo
  969. Try
  970. oProcess.Start()
  971. Catch ex As Exception
  972. File.WriteAllText(ParentDir & "crashreport.txt", ex.ToString)
  973. Console.WriteLine(ParentDir)
  974. Console.WriteLine(ex.ToString)
  975. Console.WriteLine("Something went wrong.")
  976. 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.")
  977. Console.ReadLine()
  978. End Try
  979.  
  980.  
  981.  
  982. Dim sOutput As String
  983. Using oStreamReader As System.IO.StreamReader = oProcess.StandardOutput
  984. sOutput = oStreamReader.ReadToEnd()
  985. End Using
  986. If Not Arguments.Contains("verbose") Or Arguments.Contains("[1x1") Then
  987. Logs.Writeline(sOutput)
  988. 'Console.WriteLine(sOutput)
  989. End If
  990.  
  991.  
  992. oProcess.WaitForExit()
  993. Return sOutput
  994. oProcess.WaitForExit()
  995.  
  996. oProcess.Dispose()
  997.  
  998. End Function
  999.  
  1000. Sub Upscale(fri As FileInfo)
  1001.  
  1002. 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""")
  1003. If fri.Extension <> ".png" Then
  1004. fri.Delete()
  1005. End If
  1006. End Sub
  1007.  
  1008.  
  1009.  
  1010.  
  1011. Function MaskCheck(fri As FileInfo) As Boolean
  1012.  
  1013. If fri.Extension <> ".bmp" Then
  1014. Return False
  1015. End If
  1016.  
  1017. If fri.FullName.Contains("black.bmp") Or fri.FullName.Contains("Marco1") Then
  1018. Return True
  1019. End If
  1020. Dim bmp As New Bitmap(fri.FullName)
  1021. Dim FileNameOnly As String = fri.FullName.Substring(0, fri.FullName.Length - 4)
  1022. Dim Corner1, Corner2, Corner3, Corner4 As Boolean
  1023.  
  1024. 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
  1025. Corner1 = True
  1026. Else
  1027. Corner1 = False
  1028. End If
  1029.  
  1030. 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
  1031. Corner2 = True
  1032. Else
  1033. Corner2 = False
  1034. End If
  1035.  
  1036. 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
  1037. Corner3 = True
  1038. Else
  1039. Corner3 = False
  1040. End If
  1041.  
  1042. 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
  1043. Corner4 = True
  1044. Else
  1045. Corner4 = False
  1046. End If
  1047.  
  1048. bmp.Dispose()
  1049. If Corner1 Or Corner2 Or Corner3 Or Corner4 Then
  1050. Return True
  1051. Else
  1052. Return False
  1053. End If
  1054.  
  1055. End Function
  1056.  
  1057. Sub SplitAndMerge(fri As FileInfo)
  1058. Dim filenameonly As String = fri.FullName.Substring(0, fri.FullName.Length - 4)
  1059. RunCommandH("""" & RemasterDir & "\mod\ImageMagick\magick.exe""", "convert -crop 50%x100% """ & fri.FullName & """ """ & filenameonly & "_%d.png""")
  1060. 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""")
  1061.  
  1062. File.Delete(filenameonly & "_1.png")
  1063. File.Delete(filenameonly & "_0.png")
  1064. If fri.Extension <> ".png" Then
  1065. File.Delete(fri.FullName)
  1066. End If
  1067. End Sub
  1068.  
  1069. Function Getcolor(File As String, Color As String, X As Double, Y As Double) As Int32
  1070. Select Case Color
  1071. Case "Red"
  1072. Color = "r"
  1073. Case "Green"
  1074. Color = "g"
  1075. Case "Blue"
  1076. Color = "b"
  1077. End Select
  1078. Return Convert.ToInt32(RunCommandH("""" & RemasterDir & "\mod\ImageMagick\magick.exe""", "convert """ & File & """[1x1+" & X & "+" & Y & "] -format ""%[fx: floor(255 * u." & Color & ")]"" info:"))
  1079. End Function
  1080.  
  1081. End Module
Add Comment
Please, Sign In to add comment