Greymeister.net

Mount & Blade Face Code Fun

I’ve been toying around with editing my Mount and Blade character’s looks for some time, and found that one of the more annoying aspects is that the code generated is not the same format as the one when you export your character.

So original looking

However, after looking at the different face code strings, I did see a method to the madness, and managed to create a crappy VBS file that makes it easy for me to go from the one in the editor screen to the one in the character file.

facecode.vbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
strInput = InputBox("Enter Full Face Code from CTRL-E on Character Screen","Facecode Converter")
firstCode = GetFirstPart( strInput )
lastCode = GetSecondPart( strInput )
' Thanks to http://nerds-central.blogspot.com/2007/01/using-vbscript-to-paste-text-into.html
' Open notepad 
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "notepad", 9

' Give Notepad time to load
WScript.Sleep 1000

WshShell.SendKeys "// Replace the bottom of your character text file with the following 2 lines: {ENTER}"
WshShell.SendKeys "face_key_1 = " & firstCode & " {ENTER}"
WshShell.SendKeys "face_key_2 = " & lastCode & " {ENTER}"

Function GetFirstPart( faceCode )
  ' Take the first part of the face code based on substrings
  first16 = Mid( faceCode, 3, 16 )
  first16AsDecimal = Hex_to_Dec( first16 )  
  GetFirstPart = MyHex( first16AsDecimal )
  WScript.Echo "First Code " & GetFirstPart   
End Function

Function GetSecondPart( faceCode )
  ' Take the first part of the face code based on substrings
  secondPart = Mid( faceCode, 19, 32 )
  GetSecondPart = Left( secondPart, 16 )
  WScript.Echo "Second Code " & GetSecondPart 
End Function

Function Hex_to_Dec(hex_value)
  Hex_to_Dec = CDbl("&h" & hex_value)
End Function

Function MyHex(ByVal Number)
' Thanks to http://blogs.msdn.com/b/ericlippert/archive/2004/08/30/222760.aspx for this
  Dim Sign
  Const HexChars = "0123456789ABCDEF"
  Sign = Sgn(Number)
  Number = Fix(Abs(CDbl(number)))
  If Number = 0 Then
    MyHex = "0"
    Exit Function
  End If
  While Number > 0
    MyHex = Mid(HexChars, 1 + (Number - 16 * Fix(Number / 16)), 1) & MyHex
    Number = Fix(Number/16)
  WEnd
  If Sign = -1 Then MyHex = "-" & MyHex
End Function

Ugly, as most VBScript is to me. Unfortunately, Mount and Blade only runs on Windows. I would love it if I could stop having to use my Windows machine to play on it, but that’s a sacrifice I’m willing to make for this awesome game.