diff --git a/.vs/GBAPokemonGameEditor/v14/.suo b/.vs/GBAPokemonGameEditor/v14/.suo
index ea434c3..a182e4b 100644
Binary files a/.vs/GBAPokemonGameEditor/v14/.suo and b/.vs/GBAPokemonGameEditor/v14/.suo differ
diff --git a/GBAPokemonGameEditor/AttackExpander.vb b/GBAPokemonGameEditor/AttackExpander.vb
index 4d7683a..2f308a5 100644
--- a/GBAPokemonGameEditor/AttackExpander.vb
+++ b/GBAPokemonGameEditor/AttackExpander.vb
@@ -1,4 +1,6 @@
-Imports System.IO
+Option Strict Off
+Option Explicit On
+Imports System.IO
Public Class AttackExpander
Private Sub AttackExpander_Load(sender As Object, e As EventArgs) Handles MyBase.Load
diff --git a/GBAPokemonGameEditor/bin/Debug/GBAPokemonGameEditor.application b/GBAPokemonGameEditor/bin/Debug/GBAPokemonGameEditor.application
index 8ec7bda..c8aa511 100644
--- a/GBAPokemonGameEditor/bin/Debug/GBAPokemonGameEditor.application
+++ b/GBAPokemonGameEditor/bin/Debug/GBAPokemonGameEditor.application
@@ -16,7 +16,7 @@
- XyOEDKFMxBvklN+6056G84y6/uo=
+ xCGc77xuhTzFkmBux90dKBsoxzs=
diff --git a/GBAPokemonGameEditor/bin/Debug/GBAPokemonGameEditor.exe b/GBAPokemonGameEditor/bin/Debug/GBAPokemonGameEditor.exe
index a328411..8d4a612 100644
Binary files a/GBAPokemonGameEditor/bin/Debug/GBAPokemonGameEditor.exe and b/GBAPokemonGameEditor/bin/Debug/GBAPokemonGameEditor.exe differ
diff --git a/GBAPokemonGameEditor/bin/Debug/GBAPokemonGameEditor.exe.manifest b/GBAPokemonGameEditor/bin/Debug/GBAPokemonGameEditor.exe.manifest
index fc25b2d..6997776 100644
--- a/GBAPokemonGameEditor/bin/Debug/GBAPokemonGameEditor.exe.manifest
+++ b/GBAPokemonGameEditor/bin/Debug/GBAPokemonGameEditor.exe.manifest
@@ -50,7 +50,7 @@
- PAf6FxgFYUAixqkl7QKqzILPITA=
+ zfIfQA394oVQVjkALdzRdn72vio=
diff --git a/GBAPokemonGameEditor/bin/Debug/GBAPokemonGameEditor.pdb b/GBAPokemonGameEditor/bin/Debug/GBAPokemonGameEditor.pdb
index 444a77a..0aab3e3 100644
Binary files a/GBAPokemonGameEditor/bin/Debug/GBAPokemonGameEditor.pdb and b/GBAPokemonGameEditor/bin/Debug/GBAPokemonGameEditor.pdb differ
diff --git a/GBAPokemonGameEditor/bin/Debug/GBAPokemonGameEditor.vshost.application b/GBAPokemonGameEditor/bin/Debug/GBAPokemonGameEditor.vshost.application
index 8ec7bda..c8aa511 100644
--- a/GBAPokemonGameEditor/bin/Debug/GBAPokemonGameEditor.vshost.application
+++ b/GBAPokemonGameEditor/bin/Debug/GBAPokemonGameEditor.vshost.application
@@ -16,7 +16,7 @@
- XyOEDKFMxBvklN+6056G84y6/uo=
+ xCGc77xuhTzFkmBux90dKBsoxzs=
diff --git a/GBAPokemonGameEditor/bin/Debug/GBAPokemonGameEditor.vshost.exe.manifest b/GBAPokemonGameEditor/bin/Debug/GBAPokemonGameEditor.vshost.exe.manifest
index fc25b2d..6997776 100644
--- a/GBAPokemonGameEditor/bin/Debug/GBAPokemonGameEditor.vshost.exe.manifest
+++ b/GBAPokemonGameEditor/bin/Debug/GBAPokemonGameEditor.vshost.exe.manifest
@@ -50,7 +50,7 @@
- PAf6FxgFYUAixqkl7QKqzILPITA=
+ zfIfQA394oVQVjkALdzRdn72vio=
diff --git a/GBAPokemonGameEditor/bin/Debug/app.publish/GBAPokemonGameEditor.exe b/GBAPokemonGameEditor/bin/Debug/app.publish/GBAPokemonGameEditor.exe
index a328411..8d4a612 100644
Binary files a/GBAPokemonGameEditor/bin/Debug/app.publish/GBAPokemonGameEditor.exe and b/GBAPokemonGameEditor/bin/Debug/app.publish/GBAPokemonGameEditor.exe differ
diff --git a/GBAPokemonGameEditor/mMain.vb b/GBAPokemonGameEditor/mMain.vb
index 74ac140..01adb55 100644
--- a/GBAPokemonGameEditor/mMain.vb
+++ b/GBAPokemonGameEditor/mMain.vb
@@ -82,7 +82,7 @@ Module mMain
End Function
- Public Function MakeFreeSpaceString(NeededLength As Integer)
+ Public Function MakeFreeSpaceString(NeededLength As Integer, Optional NeedByteString As String = "FF")
Dim PrivLoopVar As Integer
Dim OutBuffThing As String = ""
@@ -91,7 +91,7 @@ Module mMain
While (PrivLoopVar < NeededLength)
- OutBuffThing = OutBuffThing & "FF"
+ OutBuffThing = OutBuffThing & NeedByteString
PrivLoopVar = PrivLoopVar + 1
End While
diff --git a/GBAPokemonGameEditor/modSearchFreeSpace.vb b/GBAPokemonGameEditor/modSearchFreeSpace.vb
index b17d929..30bde2b 100644
--- a/GBAPokemonGameEditor/modSearchFreeSpace.vb
+++ b/GBAPokemonGameEditor/modSearchFreeSpace.vb
@@ -1,150 +1,155 @@
-Option Explicit On
+Option Strict Off
+Option Explicit On
Imports VB = Microsoft.VisualBasic
+Imports System.IO
Module modSearchFreeSpace
- '06/22/2013 - This code has been ported to VB.Net by Gamer2020
+ ' '06/22/2013 - This code has been ported to VB.Net by Gamer2020
+ ' '12/29/2015 - It doesn't seem to be working. Code commented out and adding Jambo51's function.
- ' Copyright © 2009 HackMew
- ' ------------------------------
- ' Feel free to create derivate works from it, as long as you clearly give me credits of my code and
- ' make available the source code of derivative programs or programs where you used parts of my code.
- ' Redistribution is allowed at the same conditions.
+ ' ' Copyright © 2009 HackMew
+ ' ' ------------------------------
+ ' ' Feel free to create derivate works from it, as long as you clearly give me credits of my code and
+ ' ' make available the source code of derivative programs or programs where you used parts of my code.
+ ' ' Redistribution is allowed at the same conditions.
- 'Private Const sMyName As String = "modSearchFreeSpace"
+ ' 'Private Const sMyName As String = "modSearchFreeSpace"
- 'This function wasn't working so I made my own.
- 'Private Declare Sub RtlFillMemory Lib "kernel32" (ByVal pDest As Byte, ByVal nLen As Long, ByVal Fill As Byte)
+ ' 'This function wasn't working so I made my own.
+ ' 'Private Declare Sub RtlFillMemory Lib "kernel32" (ByVal pDest As Byte, ByVal nLen As Long, ByVal Fill As Byte)
- Public Function SearchFreeSpace(ByVal FileName As String, ByVal FreeSpaceByte As Byte, ByVal NeededBytes As Long, Optional ByVal StartOffset As Long = 0&, Optional ByVal ChunkSize As Long = 65536, Optional ByVal Accuracy As Byte = 0) As Long
- 'Const sThis As String = "SearchFreeSpace"
- Dim iFileNum As Long
- Dim lFileLen As Long
- Dim lOffset As Long
- Dim lIncrement As Long
- Dim bBuffer() As Byte
- Dim bSearch() As Byte
- Dim i As Long
- Dim loopy As Integer
+ ' Public Function SearchFreeSpace(ByVal FileName As String, ByVal FreeSpaceByte As Byte, ByVal NeededBytes As Long, Optional ByVal StartOffset As Long = 0&, Optional ByVal ChunkSize As Long = 65536, Optional ByVal Accuracy As Byte = 0) As Long
+ ' 'Const sThis As String = "SearchFreeSpace"
+ ' Dim iFileNum As Long
+ ' Dim lFileLen As Long
+ ' Dim lOffset As Long
+ ' Dim lIncrement As Long
+ ' Dim bBuffer() As Byte
+ ' Dim bSearch() As Byte
+ ' Dim i As Long
+ ' Dim loopy As Integer
- On Error GoTo LocalHandler
+ ' On Error GoTo LocalHandler
- ' Check if NeededBytes and ChunkSize
- ' are higher than zero
- If (NeededBytes + ChunkSize) Then
+ ' ' Check if NeededBytes and ChunkSize
+ ' ' are higher than zero
+ ' If (NeededBytes + ChunkSize) Then
- ' Set the increment
- lIncrement = ChunkSize \ (CLng(Accuracy) + 1&)
+ ' ' Set the increment
+ ' lIncrement = ChunkSize \ (CLng(Accuracy) + 1&)
- ' Allocate the buffer and the search pattern
- ReDim bBuffer(ChunkSize - 1&)
- ReDim bSearch(NeededBytes - 1&)
+ ' ' Allocate the buffer and the search pattern
+ ' ReDim bBuffer(ChunkSize - 1&)
+ ' ReDim bSearch(NeededBytes - 1&)
- ' Fill the search pattern with the
- ' FreeSpaceByte when it's not 0
- 'This function wasn't working so I made my own.
+ ' ' Fill the search pattern with the
+ ' ' FreeSpaceByte when it's not 0
+ ' 'This function wasn't working so I made my own.
- 'If FreeSpaceByte Then
- 'RtlFillMemory(bSearch(0), NeededBytes, FreeSpaceByte)
- 'End If
+ ' 'If FreeSpaceByte Then
+ ' 'RtlFillMemory(bSearch(0), NeededBytes, FreeSpaceByte)
+ ' 'End If
- loopy = 0
+ ' loopy = 0
- 'just a simple loop to fill the buffer.
- While loopy < NeededBytes
+ ' 'just a simple loop to fill the buffer.
+ ' While loopy < NeededBytes
- bSearch(loopy) = bSearch(loopy) & FreeSpaceByte
+ ' bSearch(loopy) = bSearch(loopy) & FreeSpaceByte
- loopy = loopy + 1
+ ' loopy = loopy + 1
- End While
+ ' End While
- ' Get the next free number
- iFileNum = FreeFile()
+ ' ' Get the next free number
+ ' iFileNum = FreeFile()
- ' Open the file
- 'Open FileName For Binary As iFileNum
- FileOpen(iFileNum, FileName, OpenMode.Binary)
- ' Get the file length
- lFileLen = LOF(iFileNum)
+ ' ' Open the file
+ ' 'Open FileName For Binary As iFileNum
+ ' FileOpen(iFileNum, FileName, OpenMode.Binary)
+ ' ' Get the file length
+ ' lFileLen = LOF(iFileNum)
- ' Ensure the file is not empty
- If lFileLen Then
+ ' ' Ensure the file is not empty
+ ' If lFileLen Then
- ' Check if the StartOffset is valid
- If (lFileLen - StartOffset) Then
+ ' ' Check if the StartOffset is valid
+ ' If (lFileLen - StartOffset) Then
- ' Loop through the file
- For i = 0& To (lFileLen - StartOffset) \ ChunkSize
+ ' ' Loop through the file
+ ' For i = 0& To (lFileLen - StartOffset) \ ChunkSize
- ' Get a file chunk at the current offset
- 'Get #iFileNum, StartOffset + 1&, bBuffer
- FileGet(iFileNum, bBuffer, StartOffset + 1&)
+ ' ' Get a file chunk at the current offset
+ ' 'Get #iFileNum, StartOffset + 1&, bBuffer
+ ' FileGet(iFileNum, bBuffer, StartOffset + 1&)
- ' Search the needed space
- 'lOffset = InStrB(bBuffer, bSearch)
- lOffset = InStr(bBuffer(0), bSearch(0))
+ ' ' Search the needed space
+ ' 'lOffset = InStrB(bBuffer, bSearch)
+ ' lOffset = InStr(bBuffer(0), bSearch(0))
- ' Was there enough space?
- If lOffset Then
+ ' ' Was there enough space?
+ ' If lOffset Then
- ' Yeah, stop searching
- lOffset = lOffset + StartOffset - 1&
- Exit For
+ ' ' Yeah, stop searching
+ ' lOffset = lOffset + StartOffset - 1&
+ ' Exit For
- End If
+ ' End If
- ' Increment the offset
- StartOffset = StartOffset + lIncrement
+ ' ' Increment the offset
+ ' StartOffset = StartOffset + lIncrement
- Next i
+ ' Next i
- End If
+ ' End If
- End If
+ ' End If
- FileClose(iFileNum)
+ ' FileClose(iFileNum)
- ' Make sure the offset isn't past the EOF
- If lOffset < lFileLen Then
- SearchFreeSpace = lOffset
- End If
+ ' ' Make sure the offset isn't past the EOF
+ ' If lOffset < lFileLen Then
+ ' SearchFreeSpace = lOffset
+ ' End If
- End If
- Exit Function
+ ' End If
+ ' Exit Function
-LocalHandler:
+ 'LocalHandler:
- 'insert error handler here
+ ' 'insert error handler here
- 'Select Case GlobalHandler(sThis, sMyName)
- ' Case vbRetry
- ' Resume
- ' Case vbAbort
- ' Quit()
- ' Case Else
- ' Resume Next
- ' End Select
+ ' 'Select Case GlobalHandler(sThis, sMyName)
+ ' ' Case vbRetry
+ ' ' Resume
+ ' ' Case vbAbort
+ ' ' Quit()
+ ' ' Case Else
+ ' ' Resume Next
+ ' ' End Select
- End Function
+ ' End Function
Public Function SearchFreeSpaceFourAligned(ByVal FileName As String, ByVal FreeSpaceByte As Byte, ByVal NeededBytes As Long, Optional ByVal StartOffset As Long = 0) As Long
Dim SearchIncrement As String
Dim CurSearchOffset As String
- CurSearchOffset = Hex(SearchFreeSpace(FileName, FreeSpaceByte, NeededBytes, StartOffset, 100))
+ CurSearchOffset = Hex(FindFreeSpace(FileName, FreeSpaceByte, NeededBytes, StartOffset))
SearchIncrement = 1
While (((CurSearchOffset(CurSearchOffset.Length - 1)) <> "0") AndAlso ((CurSearchOffset(CurSearchOffset.Length - 1)) <> "4") AndAlso ((CurSearchOffset(CurSearchOffset.Length - 1)) <> "8") AndAlso ((CurSearchOffset(CurSearchOffset.Length - 1)) <> "C"))
- CurSearchOffset = Hex(SearchFreeSpace(FileName, FreeSpaceByte, NeededBytes, (StartOffset) + SearchIncrement))
+ MsgBox(CInt("&H" & CurSearchOffset) + CInt(SearchIncrement))
+
+ CurSearchOffset = Hex(FindFreeSpace(FileName, FreeSpaceByte, NeededBytes, CInt("&H" & CurSearchOffset) + CInt(SearchIncrement)))
SearchIncrement = SearchIncrement + 1
@@ -154,4 +159,32 @@ LocalHandler:
End Function
+ Private Function FindFreeSpace(selectedROMPath As String, freeSpaceByte As Byte, dataSize As Integer, startLocation As Integer) As Integer
+
+ Dim rom As Byte() = File.ReadAllBytes(selectedROMPath)
+
+ Dim spaceFound As Boolean = False
+ While Not spaceFound
+ For i As Integer = 0 To dataSize
+ If startLocation + dataSize <= rom.Length Then
+ If rom(startLocation + i) <> freeSpaceByte Then
+ Exit For
+ ElseIf i = dataSize Then
+ spaceFound = True
+ Exit For
+ End If
+ Else
+ spaceFound = True
+ 'MessageBox.Show("No free space could be found in the alloted area. Try widening the search parameters.")
+ startLocation = 8388608
+ Exit For
+ End If
+ Next
+ If Not spaceFound Then
+ startLocation += 1
+ End If
+ End While
+ Return startLocation
+ End Function
+
End Module
diff --git a/GBAPokemonGameEditor/obj/x86/Debug/GBAPokemonGameEditor.application b/GBAPokemonGameEditor/obj/x86/Debug/GBAPokemonGameEditor.application
index 8ec7bda..c8aa511 100644
--- a/GBAPokemonGameEditor/obj/x86/Debug/GBAPokemonGameEditor.application
+++ b/GBAPokemonGameEditor/obj/x86/Debug/GBAPokemonGameEditor.application
@@ -16,7 +16,7 @@
- XyOEDKFMxBvklN+6056G84y6/uo=
+ xCGc77xuhTzFkmBux90dKBsoxzs=
diff --git a/GBAPokemonGameEditor/obj/x86/Debug/GBAPokemonGameEditor.exe b/GBAPokemonGameEditor/obj/x86/Debug/GBAPokemonGameEditor.exe
index a328411..8d4a612 100644
Binary files a/GBAPokemonGameEditor/obj/x86/Debug/GBAPokemonGameEditor.exe and b/GBAPokemonGameEditor/obj/x86/Debug/GBAPokemonGameEditor.exe differ
diff --git a/GBAPokemonGameEditor/obj/x86/Debug/GBAPokemonGameEditor.exe.manifest b/GBAPokemonGameEditor/obj/x86/Debug/GBAPokemonGameEditor.exe.manifest
index fc25b2d..6997776 100644
--- a/GBAPokemonGameEditor/obj/x86/Debug/GBAPokemonGameEditor.exe.manifest
+++ b/GBAPokemonGameEditor/obj/x86/Debug/GBAPokemonGameEditor.exe.manifest
@@ -50,7 +50,7 @@
- PAf6FxgFYUAixqkl7QKqzILPITA=
+ zfIfQA394oVQVjkALdzRdn72vio=
diff --git a/GBAPokemonGameEditor/obj/x86/Debug/GBAPokemonGameEditor.pdb b/GBAPokemonGameEditor/obj/x86/Debug/GBAPokemonGameEditor.pdb
index 444a77a..0aab3e3 100644
Binary files a/GBAPokemonGameEditor/obj/x86/Debug/GBAPokemonGameEditor.pdb and b/GBAPokemonGameEditor/obj/x86/Debug/GBAPokemonGameEditor.pdb differ