Mod Tool/Scripting: Difference between revisions

m
using Image: consistently to make it easier to find all image refs on a page
m (correction on hierarchy)
m (using Image: consistently to make it easier to find all image refs on a page)
 
(13 intermediate revisions by 3 users not shown)
Line 14: Line 14:


'''Links'''
'''Links'''
* [http://softimage.wiki.softimage.com/index.php?title=Scripting_Tips_and_Tricks_%28XSISDK%29 xsi wiki page about scripting]
* [http://web.archive.org/web/20160803061035/http://softimage.wiki.softimage.com/index.php?title=Scripting_Tips_and_Tricks_%28XSISDK%29 xsi wiki page about scripting]
* '''[http://softimage.wiki.softimage.com/sdkdocs/scriptsdb/scriptsdb/scrdb_vbscript.htm many vbscript examples]'''
* '''[http://web.archive.org/web/20170616035120/http://softimage.wiki.softimage.com/sdkdocs/scriptsdb/scriptsdb/scrdb_vbscript.htm many vbscript examples]'''
* '''[http://ss64.com/vb/ vbs commands]'''
* '''[https://ss64.com/vb/ vbs commands]'''
* [http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/filesfolders/files/ objFSO/objWSHShell: Scripts to manage Files] (replace "Wscript.Echo" with "logmessage")
* [https://web.archive.org/web/20070510173452/https://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/filesfolders/files/ objFSO/objWSHShell: Scripts to manage Files] (replace "Wscript.Echo" with "logmessage")
* [http://activexperts.com/activmonitor/windowsmanagement/adminscripts/other/textfiles/ objFSO/objWSHShell: Scripts to manage Text Files]
* [https://web.archive.org/web/20150504221146/http://activexperts.com/activmonitor/windowsmanagement/adminscripts/other/textfiles/ objFSO/objWSHShell: Scripts to manage Text Files]
* [http://www.kxcad.net/Softimage_XSI/Softimage_XSI_Documentation/script_basics_IncludingExternalScripts.htm using external scripts]
* [http://web.archive.org/web/20080905102848/http://www.kxcad.net/softimage_xsi/Softimage_XSI_Documentation/script_basics_IncludingExternalScripts.htm using external scripts]
* [http://download.autodesk.com/global/docs/softimage2013/en_us/sdkguide/index.html?url=si_om/XSIUIToolkit.html,topicNumber=si_om_XSIUIToolkit_html progress bar and open file dialog<!-- (hm, InitialDirectory code for quick save idea ?)-->]
* [https://download.autodesk.com/global/docs/softimage2013/en_us/sdkguide/index.html?url=si_om/XSIUIToolkit.html,topicNumber=si_om_XSIUIToolkit_html progress bar and open file dialog<!-- (hm, InitialDirectory code for quick save idea ?)-->]
<!--* [http://download.autodesk.com/global/docs/softimage2013/en_us/sdkguide/index.html?url=files/cus_ppg_FileBrowserWidget.htm,topicNumber=d30e11980,hash=WS34BA39B437A993419C80CAB58E3BEFA1-0059 text box]-->
<!--* [http://download.autodesk.com/global/docs/softimage2013/en_us/sdkguide/index.html?url=files/cus_ppg_FileBrowserWidget.htm,topicNumber=d30e11980,hash=WS34BA39B437A993419C80CAB58E3BEFA1-0059 text box]-->


Line 83: Line 83:
  logmessage GetGlobal ("MyGloVar")
  logmessage GetGlobal ("MyGloVar")


Further information are found over [http://download.autodesk.com/global/docs/softimage2014/en_us/sdkguide/si_cmds/SetGlobal.html HERE.]
Further information are found over [https://download.autodesk.com/global/docs/softimage2014/en_us/sdkguide/si_cmds/SetGlobal.html HERE.]




Line 100: Line 100:
  logmessage XSIUtils.Environment("MyVar")
  logmessage XSIUtils.Environment("MyVar")


As the information is a string you need to convert it back to what it was meant originally e.g. with cBool and cInt. For more conversion see [http://www.w3schools.com/vbscript/vbscript_ref_functions.asp HERE]
As the information is a string you need to convert it back to what it was meant originally e.g. with cBool and cInt. For more conversion see [http://web.archive.org/web/20150707131602/http://www.w3schools.com/vbscript/vbscript_ref_functions.asp HERE]




Line 375: Line 375:




===dealing with different decimal marks===
===Dealing with different decimal marks===
Decimal sign is either period or comma.
Decimal sign is either period or comma.


Line 570: Line 570:
'''Via winmgmts'''
'''Via winmgmts'''
   
   
  ' slightly modified code from [http://blogs.technet.com/b/heyscriptingguy/archive/2006/12/08/how-can-i-start-a-process-and-then-wait-for-the-process-to-end-before-terminating-the-script.aspx that site]
  ' slightly modified code from [https://devblogs.microsoft.com/scripting/how-can-i-start-a-process-and-then-wait-for-the-process-to-end-before-terminating-the-script/ that site]
  ' ''logmessage "onisplit finished."'' will be executed after the conversion finished, there should be also an delay of 3 seconds to support very slow computers  
  ' ''logmessage "onisplit finished."'' will be executed after the conversion finished, there should be also an delay of 3 seconds to support very slow computers  
  ' if you are going to use this method consider to extent the code to check if input file and output directory exist
  ' if you are going to use this method consider to extent the code to check if input file and output directory exist
Line 812: Line 812:




==Modify file==
====AKEV AGQG====
===Binary===
read_AGQG_binary
[[Image:Before_and_after_binary_patching_with_vbs.png|thumb|400px|Before and after patching.]]
Change FilePath and in case of binary patching use function "StringToByteArray".
sub read_AGQG_binary
 
OniInputFile =  "C:\Oni\AE\GameDataFolder\L3\AKEVlab.oni"
  FilePath =  "C:\path_to\AKEVEnvWarehouse.oni"
' ##############################################
   
   
  ' ### create stream objects
Set OniInputFileStream = CreateObject("ADODB.Stream")
  Set InputStream = CreateObject("ADODB.Stream")
OniInputFileStream.Type = 1
  InputStream.Type = 1
OniInputFileStream.Open
  InputStream.Open
OniInputFileStream.LoadFromFile OniInputFile
  Set OutputStream = CreateObject("ADODB.Stream")
  OutputStream.Type = 1
data_table_offset = "&H20"
  OutputStream.Open
AGQG_table_offset = "&H94"
   
AGQG_table_size  = "&H9C"
  ' ### load input stream from file
  InputStream.LoadFromFile FilePath
   
ByteNum = 4
  ' ### copy first 16 signs of input stream to output stream
OniInputFileStream.Position = clng(data_table_offset)
  OutputStream.Write InputStream.Read(16)
BArr0 = OniInputFileStream.Read(ByteNum)
   
  ' ### apply patch
ByteNum = 4
  ' # ASCII patching
OniInputFileStream.Position = clng(AGQG_table_offset)
  patch_data = "ABCD"
BArr1 = OniInputFileStream.Read(ByteNum)
  patch_data_length = len(patch_data)
  '  patch_data_length = 4
ByteNum = 4
  InputStream.Position = InputStream.Position + patch_data_length
OniInputFileStream.Position = clng(AGQG_table_size)
  OutputStream.Write CreateObject("System.Text.ASCIIEncoding").GetBytes_4(patch_data)
BArr2 = OniInputFileStream.Read(ByteNum)
newhex = ""
data_table_offset_hex = SimpleBinaryToString(BArr0)
for i = ubound(data_table_offset_hex) - 1 to 0 step -1
h = hex(Asc(data_table_offset_hex(i)))
if len(h) = 1 then
h = "0" & h
end if
newhex = newhex & h
next
logmessage newhex
logmessage "data table offset: " & cLng("&H" & newhex)
data_table_offset_int = cLng("&H" & newhex)
newhex = ""
AGQG_offset_hex = SimpleBinaryToString(BArr1)
for i = ubound(AGQG_offset_hex) - 1 to 0 step -1
h = hex(Asc(AGQG_offset_hex(i)))
if len(h) = 1 then
h = "0" & h
end if
newhex = newhex & h
next
logmessage newhex
logmessage "AGQG table offset: " & cLng("&H" & newhex)
AGQG_offset_int = cLng("&H" & newhex)
newhex = ""
AGQG_size_hex = SimpleBinaryToString(BArr2)
for i = ubound(AGQG_size_hex) - 1 to 0 step -1
h = hex(Asc(AGQG_size_hex(i)))
if len(h) = 1 then
h = "0" & h
end if
newhex = newhex & h
next
logmessage newhex
logmessage "AGQG table size: " & cLng("&H" & newhex)
AGQG_size_int = cLng("&H" & newhex)
  logmessage "------------------------------"
  AGQG_start = data_table_offset_int + AGQG_offset_int - 8
  AGQG_end  = data_table_offset_int + AGQG_offset_int + AGQG_size_int - 8
  logmessage "AGQG_start: " & AGQG_start
 
' AGQG array size
  ByteNum = 4
OniInputFileStream.Position = AGQG_start + 28
BArr3 = OniInputFileStream.Read(ByteNum)
TContent = SimpleBinaryToString(BArr3)
  logmessage "------------------------------"
newhex = 0
for i = ubound(TContent) to 0 step -1
h = hex(Asc(TContent(i)))
if len(h) = 1 then
h = "0" & h
end if
newhex = newhex & h
next
AGQG_array_size = clng("&H" & newhex)
logmessage "AGQG array size: " & clng("&H" & newhex)
' reduce number by header space
ByteNum = AGQG_size_int - 31
' skip bytes used by header
OniInputFileStream.Position = AGQG_start + 32
BArr4 = OniInputFileStream.Read(ByteNum)
TContent2 = SimpleBinaryToString(BArr4)
c = -1
loop_count = 1
h = ""
newhex = ""
color = 0
logmessage "----------"
logmessage "element: 1"
for i = 0 to ubound(TContent2) - 1
c = c + 1
if c = 56 then
c = 0
loop_count = loop_count + 1
logmessage "----------"
logmessage "element: " & loop_count
end if
h = hex(Asc(TContent2(i)))
if len(h) = 1 then
h = "0" & h
end if
newhex = newhex & h
if i mod 56 = 32 then
color = 1
end if
if i mod 56 = 48 then
color = 0
end if
if i mod 56 = 52 then
objid = 1
end if
if i mod 56 = 0 then
objid = 0
end if
if len(newhex) = 8 then
if color = 1 then
logmessage newhex & " (color: " & clng(("&H" & left(newhex, 2))) _
& " " & clng("&H" & mid(newhex, 3, 2)) _
& " " & clng("&H" & mid(newhex, 5, 2)) _
& " " & clng("&H" & mid(newhex, 7, 2)) & ")"
elseif objid = 1 then
if newhex = "FFFFFFFF" then
logmessage newhex & " (object id: -1)"
else
logmessage newhex
end if
else
logmessage newhex
end if
newhex = ""
end if
next
end sub
Function SimpleBinaryToString(Binary)
ReDim tmpArr(LenB(Binary) - 1)
For I = 1 To LenB(Binary)
S = Chr(AscB(MidB(Binary, I, 1)))
tmpArr(I - 1) = S
'logmessage "hex = " & hex(AscB(S))
Next
SimpleBinaryToString = tmpArr
End Function
 
 
==Modify file==
===Binary===
[[Image:Before_and_after_binary_patching_with_vbs.png|thumb|400px|Before and after patching.]]
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
  ' # binary patching
  'OutputStream.Write StringToByteArray("41424344")
  'OutputStream.Write StringToByteArray("41424344")
Line 885: Line 1,052:
===Byte array -> string===
===Byte array -> string===
  Function ByteArrayToString(Binary)
  Function ByteArrayToString(Binary)
   'Antonin Foller, http://www.motobit.com
   'Antonin Foller, https://www.motobit.com/
   'Optimized version of a simple BinaryToString algorithm.
   'Optimized version of a simple BinaryToString algorithm.
    
    
Line 1,276: Line 1,443:


====Bounding box values====
====Bounding box values====
  ' this could be useful to create a bounding box for [[OBD_talk:OFGA#XML|OFGA files]]
  ' this could be useful to create a bounding box for [[XML:OFGA|OFGA files]]
   
   
  ' let's get the bounding box of a simple cylinder
  ' let's get the bounding box of a simple cylinder
Line 1,569: Line 1,736:
==Softimage ICE==
==Softimage ICE==
===Show a simple value in the viewport===
===Show a simple value in the viewport===
[[Image:XSI_ModTool_ICE_workaround_displaying_a_flag.png|thumb|400px]]
  CreatePrim "Cube", "MeshSurface"
  CreatePrim "Cube", "MeshSurface"
   
   
2,112

edits