Jump to content

Diablo II Simple Name Changer


Recommended Posts

Here's a script to change your characters name in Diablo II.

Select a save file, pick a new name, and hit apply. It is indended for use in Diablo II LOD 1.10 and 1.11.

It was written becuase most other utilities that can do name changes are 'too' functional. They provide anaylisis and automatic fixing of the save file, but for certian cases this is not ideal (namely, when using a MOD that has non-stnadard save files). As a result, they fail to work on save files for mod'ed versions of Diablo II.

This script only looks at the file header and only write to the name section.

Also keep in mind there is no elaborate checking for errors, invalid files or other circumstancial use. Use at your own risk (backup your .d2s files) and don't try to do anything fancy.

Bug reports and the like are welcome.

Also, as a side note, I would like to recomend the following mod to any Diablo II fans-

http://arimyth.planetdiablo.gamespy.com/hell.htm

It's called Hell Unleashed. It's quite entertaining for a refreashing Diablo II experiance, and it is the inspiration for this script.

Opt("GuiOnEventMode",1)
GuiCreate("Diablo II - Simple Name Changer", 392, 323)
GUISetOnEvent(-3,"Close")
$txtFilePath = GuiCtrlCreateInput("", 90, 20, 200, 20)
GuiCtrlCreateLabel("Current Name:", 10, 60, 70, 20)
$txtCharName= GuiCtrlCreateInput("", 90, 60, 200, 20)
GUICtrlSetState(-1,128)
GuiCtrlCreateLabel("File:", 40, 20, 40, 20)
$btnBrowse = GuiCtrlCreateButton("Browse", 310, 20, 60, 20)
GUICtrlSetOnEvent(-1,"Browse")
$btnRefreash = GuiCtrlCreateButton("Refreash", 310, 60, 60, 20)
GUICtrlSetOnEvent(-1,"Refreash")
GuiCtrlCreateLabel("New Name", 10, 150, 60, 20)
$txtNewName = GuiCtrlCreateInput("", 90, 150, 200, 20)
$btnBrwose = GuiCtrlCreateButton("Apply", 310, 150, 60, 20)
GUICtrlSetOnEvent(-1,"Apply")
$btnClose = GuiCtrlCreateButton("Close", 300, 290, 90, 30)
GUICtrlSetOnEvent(-3,"Close")
$btnAbout = GuiCtrlCreateButton("About", 0, 290, 70, 30)
GUICtrlSetOnEvent(-1,"About")

Global $byteA

GuiSetState()
While 1
    Sleep(100)
WEnd

func About()
    MsgBox(0,"Simple Name Changer V1.0 by Evilertoaster","This is designed to rename a single player character for Daiblo II 1.10 and 1.11. It will not rename the .key or map files, so you have to do that manually if you want them")
EndFunc
func Apply()
    $newName=GUICtrlRead($txtNewName)
    if $newName="" or StringLen($newName)<2 or stringlen($newName)>16 Then
        MsgBox(0,"Error","Invalid Name")
        Return
    EndIf
    for $i=20 to 35
        $byteA[$i]=Binary("0x"&Hex(Asc(StringMid($newName,$i-19,1)),2))
    Next
    FixCheckSum()
    WriteFile()
    MsgBox(0,"Done","File Saved")
EndFunc
Func WriteFile()
    $Path=GUICtrlRead($txtFilePath)
    $Dir=StringMid($Path,1,StringInStr($Path,"\",0,-1))
    $newName=GUICtrlRead($txtNewName)
    $OutFile=FileOpen($Dir&$NewName&".d2s",18)
    for $i=0 to UBound($byteA)-1
        FileWrite($OutFile,$byteA[$i])
    Next
    FileClose($OutFile) 
EndFunc
func Close()
    Exit
EndFunc
func Browse()
    $Path=FileOpenDialog("Select Save File",@ScriptDir,"Diablo II Save Files(*.d2s)")
    if $Path="" then Return
    GUICtrlSetData($txtFilePath,$Path)
    Refreash()
EndFunc
Func Refreash()
    $file=GUICtrlRead($txtFilePath)
    if $file="" then Return
    $filehandle=FileOpen($file,4)
    $size=FileGetSize($file)
    dim $byteA[$size]
    for $i = 0 to $size-1
        $byteA[$i]=FileRead($filehandle,1)
    Next
    $name=""
    for $i=20 to 35
        $name&=chr(Dec(Hex(Binary($byteA[$i]))))
    Next
    GUICtrlSetData($txtCharName,$name)
EndFunc
func FixCheckSum()
    dim $checksum[4]
    $byteA[12]=0x00
    $byteA[13]=0x00
    $byteA[14]=0x00
    $byteA[15]=0x00
    $boolCarry=0
    for $i=0 to UBound($byteA)-1
        $temp=Dec(Hex(Binary($byteA[$i])))+$boolCarry
        $checksum[0]= $checksum[0]*2 +$temp
        $checksum[1]=$checksum[1]*2
        if $checksum[0] > 255 Then
            $checksum[1] = $checksum[1] + ($checksum[0] - Mod($checksum[0],256)) / 256
            $checksum[0] = Mod($checksum[0],256)
        EndIf
        $checksum[2]=$checksum[2]*2
        if $checksum[1] > 255 Then
            $checksum[2] = $checksum[2] + ($checksum[1] - Mod($checksum[1],256)) / 256
            $checksum[1] = Mod($checksum[1],256)
        EndIf
        $checksum[3]=$checksum[3]*2
        if $checksum[2] > 255 Then
            $checksum[3] = $checksum[3] + ($checksum[2] - Mod($checksum[2],256)) / 256
            $checksum[2] = Mod($checksum[2],256)
        EndIf
        If $checksum[3] > 255 Then
            $checksum[3] = Mod($checksum[3], 256)
        EndIf
        if BitAND($checksum[3],0x80)<>0 Then
            $boolCarry=1
        Else
            $boolCarry=0
        EndIf
    Next
    $byteA[12]="0x"&Hex($checksum[0],2)
    $byteA[13]="0x"&Hex($checksum[1],2)
    $byteA[14]="0x"&Hex($checksum[2],2)
    $byteA[15]="0x"&Hex($checksum[3],2)
EndFunc

I'll try and post a compiled version when I clean up some attachment space.

edit:Attached Compiled Version

Diablo_II_Simple_Name_Changer.exe

Edited by evilertoaster
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...