8,484
edits
Paradox-01 (talk | contribs)  (not a fan of VbsEdit (especially since testing the code is delayed to force annoyance onto the user to buy the god damn license) but it can compile scripts to a program)  | 
				Paradox-01 (talk | contribs)   (String <=> ByteArray)  | 
				||
| Line 311: | Line 311: | ||
  	'qW = ... * -1  |   	'qW = ... * -1  | ||
  'set qRotation = XSIMath.CreateQuaternion (qW, qX, qY, qZ)  |   'set qRotation = XSIMath.CreateQuaternion (qW, qX, qY, qZ)  | ||
===Conversions===  | |||
====String -> byte array====  | |||
 function StringToByteArray(ThisString)  | |||
 	for i = 1 To Len(ThisString) Step 2  | |||
 		str = str & Chr("&h" & Mid(hexString, i, 2))  | |||
 	next  | |||
 	Set stream = CreateObject("ADODB.Stream")  | |||
 	With stream  | |||
 		.Open  | |||
 		.CharSet = "Windows-1252"  | |||
 		.Type = 2  | |||
 			' ### 2 = text  | |||
 		.WriteText HexString  | |||
 		.Position = 0  | |||
 		.Type = 1  | |||
 			' ### 1 = binary  | |||
 		StringToByteArray = .Read  | |||
 		.Close  | |||
 	End With  | |||
 end function  | |||
 ' ### usage  | |||
 ByteArray = StringToByteArray(ThisString)  | |||
====Byte array -> string====  | |||
 Function ByteArrayToString(Binary)  | |||
   'Antonin Foller, http://www.motobit.com  | |||
   'Optimized version of a simple BinaryToString algorithm.  | |||
   Dim cl1, cl2, cl3, pl1, pl2, pl3  | |||
   Dim L  | |||
   cl1 = 1  | |||
   cl2 = 1  | |||
   cl3 = 1  | |||
   L = LenB(Binary)  | |||
   Do While cl1<=L  | |||
     pl3 = pl3 & Chr(AscB(MidB(Binary,cl1,1)))  | |||
     cl1 = cl1 + 1  | |||
     cl3 = cl3 + 1  | |||
     If cl3>300 Then  | |||
       pl2 = pl2 & pl3  | |||
       pl3 = ""  | |||
       cl3 = 1  | |||
       cl2 = cl2 + 1  | |||
       If cl2>200 Then  | |||
         pl1 = pl1 & pl2  | |||
         pl2 = ""  | |||
         cl2 = 1  | |||
       End If  | |||
     End If  | |||
   Loop  | |||
   BinaryToString = pl1 & pl2 & pl3  | |||
 End Function  | |||
 ' ### usage  | |||
 MyString = ByteArrayToString(ByteArray)  | |||
[[Category:Windows-only modding tools]]  | [[Category:Windows-only modding tools]]  | ||
edits