Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.IO
- Imports System.Text.RegularExpressions
- Imports System.Text
- Imports System.Threading
- Imports System.Drawing
- Module Module1
- Dim Logs As StreamWriter = My.Computer.FileSystem.OpenTextFileWriter(Environment.CurrentDirectory & "\NGUpscaler-log.txt", True, System.Text.Encoding.UTF8)
- Dim NGDir As String
- Dim RemasterDir As String
- Dim ParentDir As String = Environment.CurrentDirectory
- Dim SharedDir As String = ParentDir & "\SharedFiles"
- Dim scalefraction As String
- Dim ScaleFactor As Double
- Dim mode As String
- Dim choice As String
- Dim ShouldMerge As Boolean
- Dim ListOfMerges As List(Of String) = {"tamamo_st21", "gnome_st33r",
- "008", "009a_05", "015_01", "015_01",
- "015_02", "015_02",
- "015_03", "015_03",
- "015_04", "015_04",
- "017_01", "017_01",
- "017_02", "017_02",
- "017_03", "017_03",
- "017_04", "017_04",
- "017_05", "017_05", "blackwind",
- "elm_poison", "logo", "poseidoness", "poseidoness2", "window1f"}.ToList
- Sub Main()
- Logs.AutoFlush = True
- Logs.WriteLine(vbCrLf & vbCrLf & vbCrLf & vbCrLf & vbCrLf & vbCrLf & DateTime.Now.ToShortDateString & " - " & Now.TimeOfDay.ToString & vbCrLf & vbCrLf & vbCrLf & vbCrLf & vbCrLf & vbCrLf)
- Console.WriteLine("To use this installer the following folder structure is required:")
- Console.WriteLine(">Parent directory")
- Console.WriteLine(" >Directory where the NG+ zip was extracted")
- Console.WriteLine(" >Directory where the Remaster is installed")
- Console.WriteLine("This file must be placed inside the parent directory.")
- Console.WriteLine("Press Enter to continue.")
- Console.ReadLine()
- Console.Clear()
- Do
- Console.WriteLine("Please input the folder name of where NG+ was extracted:")
- NGDir = Console.ReadLine()
- NGDir = ParentDir & "\" & NGDir
- If Not (Directory.Exists(NGDir)) Then
- Console.WriteLine("That folder does not exist. Try again.")
- ElseIf Not (File.Exists(NGDir & "\mon_que_ng+.exe")) Then
- Console.WriteLine("The folder does not contain NG+.")
- End If
- Loop While Not Directory.Exists(NGDir) Or Not File.Exists(NGDir & "\mon_que_ng+.exe")
- Console.Clear()
- Do
- Console.WriteLine("Please input the folder name of where the Remaster was installed:")
- RemasterDir = Console.ReadLine()
- RemasterDir = ParentDir & "\" & RemasterDir
- If Not (Directory.Exists(RemasterDir)) Then
- Console.WriteLine("That folder does not exist. Try again.")
- ElseIf Not (File.Exists(RemasterDir & "\Monster Girl Quest Remastered.exe")) Then
- Console.WriteLine("The folder does not contain the remaster.")
- End If
- Loop While Not Directory.Exists(RemasterDir) Or Not File.Exists(RemasterDir & "\Monster Girl Quest Remastered.exe")
- Do
- 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)")
- Console.WriteLine("1) Yes")
- Console.WriteLine("2) No")
- choice = Console.ReadLine()
- If choice = "1" Then
- mode = "gpu"
- Console.Clear()
- Exit Do
- ElseIf choice = "2" Then
- mode = "cpu"
- Console.Clear()
- Exit Do
- End If
- Console.Clear()
- Loop
- Do
- Console.WriteLine("Please enter the number corresponding to your resolution then press Enter to confirm.")
- Console.WriteLine("1) 1080p")
- Console.WriteLine("2) 720p")
- choice = Console.ReadLine()
- If choice = "1" Then
- ScaleFactor = 1.8
- scalefraction = "*18/10"
- Console.Clear()
- Exit Do
- ElseIf choice = "2" Then
- ScaleFactor = 1.5
- scalefraction = "*15/10"
- Console.Clear()
- Exit Do
- End If
- Console.Clear()
- Loop
- If Not (File.Exists(RemasterDir & "\mod\SideStoryUpscaler.exe")) Then
- Console.WriteLine("THIS PROGRAM REQUIRES THAT YOU HAVE THE SIDESTORYUPSCALER INSTALLED.")
- Console.WriteLine("PLEASE DOWNLOAD IT FROM THE UPDATES LINK IN THE PASTEBIN AND INSTALL IT IN THE CORRECT LOCATION.")
- Return
- End If
- If Not (Directory.Exists(SharedDir)) Then
- Directory.CreateDirectory(SharedDir)
- Directory.Move(RemasterDir & "\bg", SharedDir & "\bg")
- Directory.Move(RemasterDir & "\chara", SharedDir & "\chara")
- Directory.Move(RemasterDir & "\effect", SharedDir & "\effect")
- Directory.Move(RemasterDir & "\ency", SharedDir & "\ency")
- Directory.Move(RemasterDir & "\se", SharedDir & "\se")
- Directory.Move(RemasterDir & "\system", SharedDir & "\system")
- End If
- 'We have established where NG+ and the remaster are installed. Let's start moving the folders.
- 'Now we have all the dirs moved. Junctions time.
- MakeJunction(SharedDir & "\bg", RemasterDir & "\bg")
- MakeJunction(SharedDir & "\chara", RemasterDir & "\chara")
- MakeJunction(SharedDir & "\effect", RemasterDir & "\effect")
- MakeJunction(SharedDir & "\ency", RemasterDir & "\ency")
- MakeJunction(SharedDir & "\se", RemasterDir & "\se")
- MakeJunction(SharedDir & "\system", RemasterDir & "\system")
- MakeJunction(SharedDir & "\bg", NGDir & "\bg")
- MakeJunction(SharedDir & "\chara", NGDir & "\chara")
- MakeJunction(SharedDir & "\effect", NGDir & "\effect")
- MakeJunction(SharedDir & "\ency", NGDir & "\ency")
- MakeJunction(SharedDir & "\se", NGDir & "\se")
- MakeJunction(SharedDir & "\system", NGDir & "\system")
- 'Now the remaster is back where it was, only with junctions. Time to copy the miscellaneous files.
- File.Copy(RemasterDir & "\arc.nsa", NGDir & "\arc.nsa", True)
- File.Copy(RemasterDir & "\arc1.nsa", NGDir & "\arc1.nsa", True)
- File.Copy(RemasterDir & "\arc2.nsa", NGDir & "\arc2.nsa", True)
- File.Copy(RemasterDir & "\NSFont.dll", NGDir & "\NSFont.dll", True)
- File.Copy(RemasterDir & "\nslua.dll", NGDir & "\nslua.dll", True)
- File.Copy(RemasterDir & "\nsogg2.dll", NGDir & "\nsogg2.dll", True)
- File.Copy(RemasterDir & "\nspng.dll", NGDir & "\nspng.dll", True)
- File.Copy(RemasterDir & "\SDL.dll", NGDir & "\SDL.dll", True)
- Directory.CreateDirectory(NGDir & "\save")
- 'Time to upscale.
- If File.Exists(NGDir & "\2Q\effect\015_01.bmp") Then
- Dim frtemp As FileInfo = New FileInfo(NGDir & "\2Q\effect\015_01.bmp")
- ShouldMerge = MaskCheck(frtemp)
- End If
- Dim di As New DirectoryInfo(NGDir & "\2Q")
- Dim count As Integer = 0
- For Each subfolder As DirectoryInfo In di.GetDirectories("*", SearchOption.AllDirectories)
- If subfolder.Name = "bgm" Or subfolder.Name = "se" Then
- Continue For
- End If
- count = 0
- Dim fiArr As FileInfo() = subfolder.GetFiles()
- Dim listoflines As List(Of String)
- If Not (File.Exists(subfolder.FullName & "\filelist.txt")) Then
- Dim sw2 As StreamWriter = New StreamWriter(subfolder.FullName & "\filelist.txt")
- sw2.Write("")
- sw2.Flush()
- sw2.Close()
- End If
- listoflines = File.ReadAllLines(subfolder.FullName & "\filelist.txt").ToList
- For Each fri In fiArr
- count = count + 1
- Dim friname As String = fri.Name.Substring(0, fri.Name.Length - 4)
- If friname = "minccubus_hd1.jpg" Then
- Continue For
- End If
- Console.WriteLine("File " & count & " out of " & fiArr.Length)
- If fri.Extension <> ".bmp" And fri.Extension <> ".png" And fri.Extension <> ".jpg" And fri.Extension <> ".jpeg" Then
- Continue For
- End If
- If listoflines.Contains(friname & ",1") Then 'was in progress, grab the copy
- Dim tempfriname As String = fri.FullName
- File.Delete(tempfriname)
- File.Copy(tempfriname & "_temp", tempfriname)
- fri = New FileInfo(tempfriname)
- Console.WriteLine("File " & friname & " was interrupted, restarting")
- ElseIf listoflines.Contains(friname & ",0") Then 'already upscaled
- Console.WriteLine("Already upscaled.")
- If fri.Extension <> ".png" Then
- fri.Delete()
- End If
- Continue For
- Else 'It never started upscaling
- If subfolder.Name = "effect" Or subfolder.Name = "system" Or subfolder.Name = "chara" Then
- If ListOfMerges.Contains(friname) And ShouldMerge = True Then
- Dim tempfriname = fri.FullName
- SplitAndMerge(fri)
- fri = New FileInfo(fri.FullName.Substring(0, fri.FullName.Length - 4) & ".png")
- End If
- End If
- listoflines.Add(friname & ",1")
- Dim sw As StreamWriter = File.AppendText(subfolder.FullName & "\filelist.txt")
- sw.WriteLine(friname & ",1")
- sw.Close()
- File.Copy(fri.FullName, fri.FullName & "_temp")
- End If
- 'Upscale.
- Console.WriteLine("Upscaling file " & friname)
- Upscale(fri)
- listoflines.Item(listoflines.Count() - 1) = listoflines.Item(listoflines.Count() - 1).Replace(",1", ",0")
- File.Delete(subfolder.FullName & "\filelist.txt")
- File.WriteAllLines(subfolder.FullName & "\filelist.txt", listoflines.ToArray)
- If File.Exists(fri.FullName & "_temp") Then
- File.Delete(fri.FullName & "_temp")
- End If
- Next
- Next
- Dim CurrentFile As Integer = 0
- count = 0
- If Not (Directory.Exists(NGDir & "\txtbackups")) Then
- Directory.CreateDirectory(NGDir & "\txtbackups")
- Else 'Means it already started running at some point. Starts over.
- Do While File.Exists(NGDir & "\txtbackups\" & CurrentFile & ".txt")
- File.Delete(NGDir & "\" & CurrentFile & ".txt")
- File.Copy(NGDir & "\txtbackups\" & CurrentFile & ".txt", NGDir & "\" & CurrentFile & ".txt")
- CurrentFile = CurrentFile + 1
- Loop
- CurrentFile = 0
- End If
- Console.WriteLine("Done with the upscaling.")
- Console.WriteLine("Starting txt file edits.")
- Do While File.Exists(NGDir & "\" & CurrentFile & ".txt")
- Console.WriteLine("File " & CurrentFile & ".txt")
- If Not (File.Exists(NGDir & "\txtbackups\" & CurrentFile & ".txt")) Then
- File.Move(NGDir & "\" & CurrentFile & ".txt", NGDir & "\txtbackups\" & CurrentFile & ".txt")
- Else
- File.Delete(NGDir & "\" & CurrentFile & ".txt")
- End If
- Dim reader As StreamReader = New StreamReader(NGDir & "\txtbackups\" & CurrentFile & ".txt")
- Dim writer As StreamWriter = New StreamWriter(NGDir & "\" & CurrentFile & ".txt")
- Dim a As String
- Do
- a = reader.ReadLine
- If a = ";$V50000G6750S800,600L10000 ;?????800*600????????%1500~" Then 'Special case for the resolution setting
- writer.WriteLine(";$V10000G1500S1440,1080L10000 ;TCY800*600AO[o%1500`")
- Continue Do
- End If
- If a Is Nothing Then
- Exit Do
- End If
- If a.Contains(".bmp") Then
- a = a.Replace(".bmp", ".png")
- End If
- If a.Contains(".jpg") Then
- a = a.Replace(".jpg", ".png")
- End If
- If a.Contains(".jpeg") Then
- a = a.Replace(".jpeg", ".png")
- End If
- If a.Contains("lsp ") Then
- Dim bodge As Boolean = False
- If a.IndexOf("lsp") > 0 Then
- Console.WriteLine(a)
- Console.WriteLine(GetChar(a, a.IndexOf("lsp")))
- If GetChar(a, a.IndexOf("lsp")) = ";" Or GetChar(a, a.IndexOf("lsp")) = ">" Then
- Console.WriteLine("it's a comment/whatever the fuck the one with > is.")
- bodge = True
- End If
- End If
- If bodge = False Then
- Dim i As Integer = a.IndexOf("lsp")
- i = a.IndexOf("""", i)
- Console.WriteLine(a.Substring(i + 1, 3))
- If a.Substring(i + 1, 3) = ":s/" Then
- Dim i3 As Integer = a.IndexOf(":s/") + 3
- Dim i2 As Integer = a.IndexOf(",", i3)
- i2 = a.IndexOf(",", i2 + 1)
- Dim currenttextsize As String = a.Substring(i3, i2 - i3)
- Console.WriteLine(currenttextsize)
- Dim size1, size2 As Integer
- Console.WriteLine(currenttextsize.Substring(0, currenttextsize.Length - currenttextsize.IndexOf(",") - 1))
- Console.WriteLine(currenttextsize.Substring(currenttextsize.IndexOf(",") + 1))
- size1 = currenttextsize.Substring(0, currenttextsize.Length - currenttextsize.IndexOf(",") - 1)
- size2 = currenttextsize.Substring(currenttextsize.IndexOf(",") + 1)
- If ScaleFactor = "1.8" Then
- a = a.Replace(":s/" & size1 & "," & size2, ":s/" & size1 + 10 & "," & size2 + 10)
- Else
- a = a.Replace(":s/" & size1 & "," & size2, ":s/" & size1 + 7 & "," & size2 + 7)
- End If
- 'Text sizes should now be fixed.
- Console.WriteLine(a)
- End If
- i = a.IndexOf("""", i + 1) + 1 'i is now after the " close
- If i = 0 Then
- i = a.IndexOf(",", i) + 1
- End If
- i = a.IndexOf(",", i) + 1
- a = a.Insert(i, "(")
- a = a.Insert(a.IndexOf(",", i), ")" & scalefraction)
- Dim i4 As Integer = a.IndexOf(",", i) + 1 'i4 should be just after the ,
- a = a.Insert(i4, "(")
- Console.WriteLine((GetChar(a, i4)))
- Console.WriteLine(a.IndexOf(":", i4))
- Console.WriteLine(a.IndexOf(";", i4))
- If a.IndexOf(":", i4) <> -1 Then
- i4 = a.IndexOf(":", i4)
- a = a.Insert(i4, ")" & scalefraction)
- ElseIf a.IndexOf(";", i4) <> -1 Then
- i4 = a.IndexOf(";", i4)
- Do While Not (Char.IsNumber(GetChar(a, i4)))
- Console.WriteLine(GetChar(a, i4))
- i4 = i4 - 1
- Loop
- If GetChar(a, i4 + 1) = "," Then
- Console.WriteLine(a)
- Console.WriteLine(GetChar(a, i4 + 3))
- 'Console.ReadLine()
- If GetChar(a, i4 + 3) = "%" Then
- i4 = i4 + 3
- Dim r As Regex = New Regex("[^a-zA-Z0-9()%+]", RegexOptions.IgnoreCase)
- Dim m As Match
- m = r.Match(GetChar(a, i4))
- Do Until m.Success
- i4 = i4 + 1
- m = r.Match(GetChar(a, i4))
- Loop
- a = a.Insert(i4 - 1, ")" & scalefraction)
- Console.WriteLine(a)
- 'Console.ReadLine()
- End If
- Else
- Dim i5 As Integer = i4
- Do While Char.IsNumber(GetChar(a, i5))
- i5 = i5 - 1
- Loop
- If GetChar(a, i5) = "+" Then
- a = a.Insert(i4, ")" & scalefraction)
- Else
- a = a.Insert(i4, ")" & scalefraction)
- End If
- Console.WriteLine(a)
- 'Console.ReadLine()
- End If
- Console.WriteLine(a)
- Else
- a = a & ")" & scalefraction
- End If
- Console.WriteLine(a)
- If a.Contains("**") Or a.Contains(",*") Or a.Contains(":*") Then
- Console.ReadLine()
- End If
- 'Positions should now be multiplied correctly.
- End If
- End If
- If a.Contains("strsp") Then
- Console.WriteLine(a)
- Dim i As Integer = a.IndexOf("strsp")
- i = a.IndexOf(",", i) + 1
- i = a.IndexOf(",", i) + 1
- a = a.Insert(i, "(")
- i = a.IndexOf(",", i)
- a = a.Insert(i, ")" & scalefraction)
- i = a.IndexOf(",", i) + 1
- a = a.Insert(i, "(")
- i = a.IndexOf(",", i)
- a = a.Insert(i, ")" & scalefraction)
- i = a.IndexOf(",", i) + 1
- i = a.IndexOf(",", i) + 1
- i = a.IndexOf(",", i) + 1
- i = a.IndexOf(",", i)
- If ScaleFactor = "1.8" Then
- a = a.Insert(i, "+12")
- Else
- a = a.Insert(i, "+5")
- End If
- i = a.IndexOf(",", i) + 1
- i = a.IndexOf(",", i)
- If ScaleFactor = "1.8" Then
- a = a.Insert(i, "+12")
- Else
- a = a.Insert(i, "+5")
- End If
- i = a.IndexOf(",", i) + 1
- i = a.IndexOf(",", i) + 1
- i = a.IndexOf(",", i)
- If ScaleFactor = "1.8" Then
- a = a.Insert(i, "+18")
- Else
- a = a.Insert(i, "+12")
- End If
- Console.WriteLine(a)
- End If
- If a.Contains("getscreenshot") Then
- Console.WriteLine(a)
- Dim i As Integer = a.IndexOf("getscreenshot")
- i = a.IndexOf(",", i)
- a = a.Insert(i, scalefraction)
- i = a.IndexOf(",", i) + 1
- Console.WriteLine(GetChar(a, i))
- i = i + 1
- Dim bodge As Boolean = False
- Do While Char.IsNumber(GetChar(a, i))
- Console.WriteLine(GetChar(a, i))
- i = i + 1
- If i = a.Length Then
- a = a & scalefraction
- bodge = True
- End If
- Loop
- If Not (bodge) Then
- a = a.Insert(i - 1, scalefraction)
- End If
- Console.WriteLine(a)
- End If
- If a.Contains("mov $savetime," & """" & ":s/") Or a.Contains("mov $savenum," & """" & ":s/") Then
- Console.WriteLine(a)
- Dim i As Integer = a.IndexOf("""")
- i = a.IndexOf(",", i)
- If ScaleFactor = "1.8" Then
- a = a.Insert(i, "+10")
- Else
- a = a.Insert(i, "+7")
- End If
- i = a.IndexOf(",", i) + 1
- i = a.IndexOf(",", i)
- If ScaleFactor = "1.8" Then
- a = a.Insert(i, "+10")
- Else
- a = a.Insert(i, "+7")
- End If
- Console.WriteLine(a)
- End If
- If a.Contains("btn ") Then
- Console.WriteLine(a)
- Dim r As Regex = New Regex("[^a-zA-Z0-9]btn ", RegexOptions.IgnoreCase)
- Dim m As Match
- m = r.Match(a)
- If m.Success Then
- Dim i As Integer = a.IndexOf("btn ")
- i = a.IndexOf(",", i) + 1
- i = a.IndexOf(",", i)
- a = a.Insert(i, scalefraction)
- i = a.IndexOf(",", i) + 1
- i = a.IndexOf(",", i)
- a = a.Insert(i, scalefraction)
- i = a.IndexOf(",", i) + 1
- i = a.IndexOf(",", i)
- a = a.Insert(i, scalefraction)
- i = a.IndexOf(",", i) + 1
- i = a.IndexOf(",", i)
- a = a.Insert(i, scalefraction)
- Console.WriteLine(a)
- End If
- End If
- If a.Contains("setwindow3") Then
- Dim i As Integer = a.IndexOf(",")
- a = a.Insert(a.IndexOf(","), scalefraction)
- i = a.IndexOf(",", i) + 1
- i = a.IndexOf(",", i)
- a = a.Insert(i, scalefraction)
- i = a.IndexOf(",", i) + 1
- i = a.IndexOf(",", i) + 1
- i = a.IndexOf(",", i) + 1
- i = a.IndexOf(",", i)
- If ScaleFactor = "1.8" Then
- a = a.Insert(i, "+10")
- Else
- a = a.Insert(i, "+4")
- End If
- i = a.IndexOf(",", i) + 1
- i = a.IndexOf(",", i)
- If ScaleFactor = "1.8" Then
- a = a.Insert(i, "+10")
- Else
- a = a.Insert(i, "+4")
- End If
- i = a.IndexOf("#")
- i = a.IndexOf(",", i) + 1
- i = a.IndexOf(",", i)
- a = a.Insert(i, scalefraction)
- i = a.IndexOf(",", i) + 1
- i = a.IndexOf(",", i)
- a = a.Insert(i, scalefraction)
- i = a.IndexOf(",", i) + 1
- i = a.IndexOf(",", i)
- a = a.Insert(i, scalefraction)
- i = a.IndexOf(":", i) - 1
- a = a.Insert(i, scalefraction)
- Console.WriteLine(a)
- End If
- If a.Contains("bar ") Then
- Dim i As Integer = a.IndexOf("bar ") + 4
- Console.WriteLine(a)
- Console.WriteLine(GetChar(a, i + 1))
- If Char.IsNumber(GetChar(a, i + 1)) Then
- i = a.IndexOf(",", i) + 1
- i = a.IndexOf(",", i) + 1
- i = a.IndexOf(",", i)
- a = a.Insert(i, scalefraction)
- i = a.IndexOf(",", i + 1) + 1
- i = a.IndexOf(",", i)
- a = a.Insert(i, scalefraction)
- i = a.IndexOf(",", i + 1) + 1
- i = a.IndexOf(",", i)
- a = a.Insert(i, scalefraction)
- i = a.IndexOf(",", i + 1) + 1
- i = a.IndexOf(",", i)
- a = a.Insert(i, scalefraction)
- Console.WriteLine(a)
- End If
- End If
- If a.Contains("mov %monster_x") Then
- Dim i As Integer = a.IndexOf(",")
- Dim indexchar As String
- Console.WriteLine(GetChar(a, i))
- If GetChar(a, i) <> "x" Then 'This handles the cases where it's %monster_xb etc.
- indexchar = GetChar(a, i)
- Else
- indexchar = ""
- End If
- If a.Contains(":") Then 'if there is a command following this one
- i = a.IndexOf(":")
- a = a.Insert(i, ":mul %monster_x" & indexchar & "," & ScaleFactor)
- Else
- a = a & ":mul %monster_x" & indexchar & "," & ScaleFactor
- End If
- Console.WriteLine(a)
- End If
- If a.Contains("mov %monster_y") Then
- Dim i As Integer = a.IndexOf(",")
- Dim indexchar As String
- Console.WriteLine(GetChar(a, i))
- If GetChar(a, i) <> "y" Then 'This handles the cases where it's %monster_xb etc.
- indexchar = GetChar(a, i)
- Else
- indexchar = ""
- End If
- If a.Contains(":") Then 'if there is a command following this one
- i = a.IndexOf(":")
- a = a.Insert(i, ":mul %monster_y" & indexchar & "," & ScaleFactor)
- Else
- a = a & ":mul %monster_y" & indexchar & "," & ScaleFactor
- End If
- Console.WriteLine(a)
- End If
- writer.WriteLine(a)
- Loop Until a Is Nothing
- reader.Close()
- writer.Close()
- #Region "Wordwrap code"
- Dim sensitivity As Integer = 78
- Dim path(1) As String
- path(0) = NGDir & "\" & CurrentFile & ".txt"
- a = ""
- Dim first, second As String
- reader = My.Computer.FileSystem.OpenTextFileReader(path(0), Encoding.Default)
- writer = My.Computer.FileSystem.OpenTextFileWriter(path(0).Replace(".txt", "_edited_1.txt"), False, Encoding.Default)
- Dim total As Integer = File.ReadAllLines(path(0)).Length
- Dim current As Integer = 0
- Dim EOL As Char
- Dim modifiedlines As New List(Of Integer)
- Dim testrun As Boolean = False
- Do
- first = ""
- Second = ""
- current = current + 1
- a = reader.ReadLine
- If a <> "" Then
- If a(0) = ">" Then
- Try
- If a.Contains("@") Then
- EOL = "@"
- ElseIf a.Contains("\") Then
- EOL = "\"
- Else
- Console.WriteLine(a)
- EOL = ""
- 'Console.ReadLine()
- End If
- If EOL <> vbNullChar Then
- If a.IndexOf(">", a.IndexOf(EOL)) <> -1 Then
- Dim tlength As Integer
- Console.WriteLine(a)
- If (a.IndexOf("@")) = -1 Then
- Console.WriteLine("what the fuck")
- tlength = a.Length
- Else
- tlength = a.Substring(0, a.IndexOf("@") - 1).Length
- Console.WriteLine(a.Substring(0, a.IndexOf("@") - 1))
- End If
- Dim i As Integer = a.IndexOf("@")
- If i <> -1 Then
- Do While a.IndexOf(">", i) <> -1
- If a.IndexOf("@", i + 1) <> -1 Then
- Console.WriteLine(a.IndexOf("@", i + 1))
- Console.WriteLine(a.IndexOf(">", i))
- If a.IndexOf(">", i) >= a.IndexOf("@", i + 1) Then
- tlength = a.Length
- Exit Do
- End If
- tlength = tlength + a.Substring(a.IndexOf(">", i), a.IndexOf("@", i + 1) - a.IndexOf(">", i) - 1).Length
- Console.WriteLine(a.Substring(a.IndexOf(">", i), a.IndexOf("@", i + 1) - a.IndexOf(">", i) - 1))
- ElseIf a.IndexOf("\", i) <> -1 Then
- tlength = tlength + a.Substring(a.IndexOf(">", i), a.IndexOf("\", i) - a.IndexOf(">", i) - 1).Length
- Console.WriteLine(a.Substring(a.IndexOf(">", i), a.IndexOf("\", i) - a.IndexOf(">", i) - 1))
- Else
- tlength = tlength + a.Substring(a.IndexOf(">", i)).Length
- Console.WriteLine(a.Substring(a.IndexOf(">", i)))
- End If
- i = a.IndexOf("@", i + 1)
- If i = -1 Then
- i = a.IndexOf("\", i + 1)
- If i = -1 Then
- Exit Do
- End If
- End If
- Loop
- End If
- If tlength > sensitivity Then
- Console.WriteLine(a(a.LastIndexOf(" ", sensitivity) + 1))
- Try
- If a(a.LastIndexOf(" ", sensitivity) + 1) = "@" Then
- first = a.Substring(0, a.LastIndexOf(" ", a.LastIndexOf(" ", sensitivity) - 1))
- second = a.Substring(a.LastIndexOf(" ", a.LastIndexOf(" ", sensitivity) - 1), a.Length - a.LastIndexOf(" ", a.LastIndexOf(" ", sensitivity) - 1))
- Else
- first = a.Substring(0, a.LastIndexOf(" ", sensitivity))
- second = a.Substring(a.LastIndexOf(" ", sensitivity), a.Length - a.LastIndexOf(" ", sensitivity))
- End If
- Catch ex As Exception
- first = a.Substring(0, a.LastIndexOf(" ", sensitivity))
- second = a.Substring(a.LastIndexOf(" ", sensitivity), a.Length - a.LastIndexOf(" ", sensitivity))
- End Try
- first = first.Trim()
- second = second.Trim()
- If second(0) <> ">" Then
- second = ">" & second
- End If
- If first(first.Length - 1) <> "@" Then
- first = first & " _@"
- End If
- If testrun Then
- Console.WriteLine(a)
- Console.WriteLine(tlength)
- Console.WriteLine(first)
- Console.WriteLine(second)
- Console.ReadLine()
- Else
- 'FIX IT
- writer.WriteLine(first)
- If second <> "@" Then
- If second(0) = ">" Then second = second.Substring(1)
- writer.WriteLine(">" & second)
- End If
- End If
- Else
- writer.WriteLine(a)
- End If
- Else
- If a.Substring(0, a.LastIndexOf(EOL) - 1).Length > sensitivity Then
- Try
- Try
- If a(a.LastIndexOf(" ", sensitivity) + 1) = "@" Then
- first = a.Substring(0, a.LastIndexOf(" ", a.LastIndexOf(" ", sensitivity) - 1))
- second = a.Substring(a.LastIndexOf(" ", a.LastIndexOf(" ", sensitivity) - 1), a.Length - a.LastIndexOf(" ", a.LastIndexOf(" ", sensitivity) - 1))
- Else
- first = a.Substring(0, a.LastIndexOf(" ", sensitivity))
- second = a.Substring(a.LastIndexOf(" ", sensitivity), a.Length - a.LastIndexOf(" ", sensitivity))
- End If
- Catch ex As Exception
- first = a.Substring(0, a.LastIndexOf(" ", sensitivity))
- second = a.Substring(a.LastIndexOf(" ", sensitivity), a.Length - a.LastIndexOf(" ", sensitivity))
- End Try
- first = first.Trim()
- second = second.Trim()
- If testrun Then
- Console.WriteLine(first & " _@")
- Console.WriteLine(">" & second)
- Console.ReadLine()
- Else
- 'FIX IT
- writer.WriteLine(first & " _@")
- If second <> "@" Then
- If second(0) = ">" Then second = second.Substring(1)
- writer.WriteLine(">" & second)
- End If
- End If
- Catch ex As Exception
- Console.WriteLine(a)
- 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.")
- Console.WriteLine("This is on line " & current)
- Console.ReadLine()
- writer.WriteLine(a)
- End Try
- Else
- writer.WriteLine(a)
- End If
- End If
- Else
- If a.Length > sensitivity Then
- Try
- If a(a.LastIndexOf(" ", sensitivity) + 1) = "@" Then
- first = a.Substring(0, a.LastIndexOf(" ", a.LastIndexOf(" ", sensitivity) - 1))
- second = a.Substring(a.LastIndexOf(" ", a.LastIndexOf(" ", sensitivity) - 1), a.Length - a.LastIndexOf(" ", a.LastIndexOf(" ", sensitivity) - 1))
- Else
- first = a.Substring(0, a.LastIndexOf(" ", sensitivity))
- second = a.Substring(a.LastIndexOf(" ", sensitivity), a.Length - a.LastIndexOf(" ", sensitivity))
- End If
- Catch ex As Exception
- first = a.Substring(0, a.LastIndexOf(" ", sensitivity))
- second = a.Substring(a.LastIndexOf(" ", sensitivity), a.Length - a.LastIndexOf(" ", sensitivity))
- End Try
- first = first.Trim()
- second = second.Trim()
- If testrun Then
- Console.WriteLine(first & " _@")
- Console.WriteLine(">" & second)
- Console.ReadLine()
- Else
- writer.WriteLine(first & " _@")
- writer.WriteLine(">" & second)
- End If
- Else
- writer.WriteLine(a)
- End If
- End If
- Catch ex As Exception
- Console.WriteLine(ex)
- Console.WriteLine("SAFETY MEASURE - IF ERROR THEN DON'T WORDWRAP AT ALL")
- writer.WriteLine(a)
- End Try
- Else
- writer.WriteLine(a)
- End If
- Else
- writer.WriteLine(a)
- End If
- Console.WriteLine(current & " out of " & total)
- Loop Until a Is Nothing
- 'Console.ReadLine()
- reader.Close()
- writer.Close()
- reader = My.Computer.FileSystem.OpenTextFileReader(path(0).Replace(".txt", "_edited_1.txt"), Encoding.Default)
- current = 0
- Do
- current = current + 1
- a = reader.ReadLine
- If a <> "" Then
- If a.Contains("_@") Then
- modifiedlines.Add(current + 1)
- Console.WriteLine("Line " & current + 1 & "added to list")
- End If
- End If
- Loop Until a Is Nothing
- 'Console.ReadLine()
- reader.Close()
- reader = My.Computer.FileSystem.OpenTextFileReader(path(0).Replace(".txt", "_edited_1.txt"), Encoding.Default)
- writer = My.Computer.FileSystem.OpenTextFileWriter(path(0).Replace(".txt", "_edited_2.txt"), False, Encoding.Default)
- current = 0
- total = File.ReadAllLines(path(0).Replace(".txt", "_edited_1.txt")).Length
- Do
- current = current + 1
- a = reader.ReadLine
- If a <> "" Then
- Dim regex As New Regex("skip -\d\d")
- Dim regex2 As New Regex("skip \d\d")
- Dim offset As Integer
- 'POSITIVE CASE
- If regex2.Match(a).Success Then
- offset = regex2.Match(a).Value.Replace("skip ", "")
- For Each item As Integer In modifiedlines
- If item > current And item - current <= offset Then
- Console.WriteLine(offset)
- Console.WriteLine("current: " & current)
- Console.WriteLine("item: " & item)
- Console.WriteLine(a)
- Console.WriteLine("Skip edited. Is now " & offset + 1 & ", it was " & offset)
- Console.WriteLine("This is on line " & current)
- a = a.Replace(regex2.Match(a).Value, regex2.Match(a).Value.Replace(offset, offset + 1))
- Console.WriteLine(a)
- offset = offset + 1
- 'Console.ReadLine()
- End If
- Next
- Else
- regex2 = New Regex("skip \d")
- If regex2.Match(a).Success Then
- offset = regex2.Match(a).Value.Replace("skip ", "")
- For Each item As Integer In modifiedlines
- If item > current And item - current <= offset Then
- Console.WriteLine(a)
- Console.WriteLine("Skip edited. Is now " & offset + 1 & ", it was " & offset)
- Console.WriteLine("This is on line " & current)
- a = a.Replace(regex2.Match(a).Value, regex2.Match(a).Value.Replace(offset, offset + 1))
- Console.WriteLine(a)
- offset = offset + 1
- 'Console.ReadLine()
- End If
- Next
- Else
- End If
- End If
- 'NEGATIVE CASE
- If regex.Match(a).Success Then
- offset = regex.Match(a).Value.Replace("skip ", "")
- For Each item As Integer In modifiedlines
- If item < current And item - current >= offset Then
- Console.WriteLine(a)
- Console.WriteLine("Skip edited. Is now " & offset - 1 & ", it was " & offset)
- Console.WriteLine("This is on line " & current)
- Console.WriteLine(regex.Match(a).Value)
- Console.WriteLine(regex.Match(a).Value.Replace(offset, offset - 1))
- a = a.Replace(regex.Match(a).Value, regex.Match(a).Value.Replace(offset, offset - 1))
- Console.WriteLine(a)
- offset = offset - 1
- 'Console.ReadLine()
- End If
- Next
- Else
- regex = New Regex("skip -\d")
- If regex.Match(a).Success Then
- offset = regex.Match(a).Value.Replace("skip ", "")
- For Each item As Integer In modifiedlines
- If item < current And item - current >= offset Then
- Console.WriteLine(a)
- Console.WriteLine("Skip edited. Is now " & offset - 1 & ", it was " & offset)
- Console.WriteLine("This is on line " & current)
- a = a.Replace(regex.Match(a).Value, regex.Match(a).Value.Replace(offset, offset - 1))
- Console.WriteLine(a)
- offset = offset - 1
- 'Console.ReadLine()
- End If
- Next
- Else
- End If
- End If
- writer.WriteLine(a)
- Else
- writer.WriteLine(a)
- End If
- Console.WriteLine(current & " out of " & total)
- Loop Until a Is Nothing
- writer.Close()
- reader.Close()
- File.Delete(path(0))
- File.Delete(path(0).Replace(".txt", "_edited_1.txt"))
- File.Move(path(0).Replace(".txt", "_edited_2.txt"), path(0))
- 'Console.ReadLine()
- #End Region
- Console.WriteLine("Loop end.")
- CurrentFile = CurrentFile + 1
- Loop
- Logs.Close()
- End Sub
- Sub MakeJunction(Link As String, Target As String)
- If Not (Directory.Exists(Target)) Then
- RunCommandH("""C:\Windows\System32\cmd.exe""", " /c mklink /J " & """" & Target & """" & " """ & Link & """")
- End If
- End Sub
- Function RunCommandH(Command As String, Arguments As String) As String
- 'Console.WriteLine(Command)
- Logs.WriteLine(Command & Arguments)
- 'Console.ReadLine()
- Dim oProcess As New Process()
- Dim oStartInfo As New ProcessStartInfo(Command, Arguments)
- oStartInfo.UseShellExecute = False
- oStartInfo.RedirectStandardOutput = True
- oProcess.StartInfo = oStartInfo
- Try
- oProcess.Start()
- Catch ex As Exception
- File.WriteAllText(ParentDir & "crashreport.txt", ex.ToString)
- Console.WriteLine(ParentDir)
- Console.WriteLine(ex.ToString)
- Console.WriteLine("Something went wrong.")
- 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.")
- Console.ReadLine()
- End Try
- Dim sOutput As String
- Using oStreamReader As System.IO.StreamReader = oProcess.StandardOutput
- sOutput = oStreamReader.ReadToEnd()
- End Using
- If Not Arguments.Contains("verbose") Or Arguments.Contains("[1x1") Then
- Logs.Writeline(sOutput)
- 'Console.WriteLine(sOutput)
- End If
- oProcess.WaitForExit()
- Return sOutput
- oProcess.WaitForExit()
- oProcess.Dispose()
- End Function
- Sub Upscale(fri As FileInfo)
- 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""")
- If fri.Extension <> ".png" Then
- fri.Delete()
- End If
- End Sub
- Function MaskCheck(fri As FileInfo) As Boolean
- If fri.Extension <> ".bmp" Then
- Return False
- End If
- If fri.FullName.Contains("black.bmp") Or fri.FullName.Contains("Marco1") Then
- Return True
- End If
- Dim bmp As New Bitmap(fri.FullName)
- Dim FileNameOnly As String = fri.FullName.Substring(0, fri.FullName.Length - 4)
- Dim Corner1, Corner2, Corner3, Corner4 As Boolean
- 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
- Corner1 = True
- Else
- Corner1 = False
- End If
- 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
- Corner2 = True
- Else
- Corner2 = False
- End If
- 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
- Corner3 = True
- Else
- Corner3 = False
- End If
- 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
- Corner4 = True
- Else
- Corner4 = False
- End If
- bmp.Dispose()
- If Corner1 Or Corner2 Or Corner3 Or Corner4 Then
- Return True
- Else
- Return False
- End If
- End Function
- Sub SplitAndMerge(fri As FileInfo)
- Dim filenameonly As String = fri.FullName.Substring(0, fri.FullName.Length - 4)
- RunCommandH("""" & RemasterDir & "\mod\ImageMagick\magick.exe""", "convert -crop 50%x100% """ & fri.FullName & """ """ & filenameonly & "_%d.png""")
- 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""")
- File.Delete(filenameonly & "_1.png")
- File.Delete(filenameonly & "_0.png")
- If fri.Extension <> ".png" Then
- File.Delete(fri.FullName)
- End If
- End Sub
- Function Getcolor(File As String, Color As String, X As Double, Y As Double) As Int32
- Select Case Color
- Case "Red"
- Color = "r"
- Case "Green"
- Color = "g"
- Case "Blue"
- Color = "b"
- End Select
- Return Convert.ToInt32(RunCommandH("""" & RemasterDir & "\mod\ImageMagick\magick.exe""", "convert """ & File & """[1x1+" & X & "+" & Y & "] -format ""%[fx: floor(255 * u." & Color & ")]"" info:"))
- End Function
- End Module
Add Comment
Please, Sign In to add comment