Mod Tool/Scripting: Difference between revisions

modify file via binary stream while patch data can be ASCII or byte array
mNo edit summary
(modify file via binary stream while patch data can be ASCII or byte array)
Line 41: Line 41:


===read file===
===read file===
====as binary====
====binary====
  scan_AKEV_file_table
  scan_AKEV_file_table
   
   
Line 135: Line 135:
  ' [...]
  ' [...]
  ' INFO : TXMPWH_DCTRBND
  ' INFO : TXMPWH_DCTRBND
===modify file===
====binary====
Change FilePath and in case of binary patching use function "StringToByteArray".
FilePath =  "C:\path_to\AKEVEnvWarehouse.oni"
' ### create stream objects
Set InputStream = CreateObject("ADODB.Stream")
InputStream.Type = 1
InputStream.Open
Set OutputStream = CreateObject("ADODB.Stream")
OutputStream.Type = 1
OutputStream.Open
' ### load input stream from file
InputStream.LoadFromFile FilePath
' ### copy first 16 signs of input stream to output stream
OutputStream.Write InputStream.Read(16)
' ### apply patch
' # ASCII patching
patch_data = "ABCD"
patch_data_length = len(patch_data)
'  patch_data_length = 4
InputStream.Position = InputStream.Position + patch_data_length
OutputStream.Write CreateObject("System.Text.ASCIIEncoding").GetBytes_4(patch_data)
' # binary patching
'OutputStream.Write StringToByteArray("41424344")
' ### re-add data that was cut off
OutputStream.Write InputStream.Read
   
' ### unloader
InputStream.Close
Set InputStream = Nothing
' ### modes: 2 = overwrite; 1 = dontoverwrite
' test: save to new file
' FilePath2 = "C:\path_to\AKEVEnvWarehouseB.oni"
OutputStream.SaveToFile FilePath, 2
OutputStream.Close
Set OutputStream = Nothing




8,452

edits