It was used to make games portable and point the folders in wich games save ini files and save files etc, to the game folder

So all it does it drops 2 .reg files one that changes those paths and one that restores original paths

It is my first code so be gentle its far from good

Thx to developers for purebasic its such elegant and human friendly language, yet so powerful and gives possibilities to go
low level

Code: Select all
; StringtoHex procedure was found on forums so credits go to creator :)
; It was a bit modified as you can see :)
;--------------------------------------------------------------------------
;procedure to make string into hex with 00 in between and "," char between each hex value
Procedure.s StringToHex(str$)
For x = 1 To Len(str$)
hexchar$ = Hex(Asc(Mid(str$, x, 1)))
If Len(hexchar$) = 1
hexchar$ = "0" + hexchar$
EndIf
StringToHex$ + hexchar$ + "," + "00" + ","
Next x
ProcedureReturn StringToHex$
EndProcedure
;procedure to make valid .reg files to move those folders to current dir
Procedure.s WriteToReg_change(str$, filename$, reg_key1$, reg_key2$, reg_key3$, reg_key4$)
CreateFile(1,filename$)
WriteStringN(1,"Windows Registry Editor Version 5.00 ",0)
WriteStringN(1,reg_key1$ + str$,0)
WriteStringN(1,reg_key2$ + str$,0)
WriteStringN(1,reg_key3$ + str$,0)
WriteString(1,reg_key4$ + str$,0)
CloseFile(1)
EndProcedure
Procedure.s WriteToReg_restore(str1$, str2$, str3$, str4$, filename$, reg_key1$, reg_key2$, reg_key3$, reg_key4$)
CreateFile(1,filename$)
WriteStringN(1,"Windows Registry Editor Version 5.00 ",0)
WriteStringN(1,reg_key1$ + str1$,0)
WriteStringN(1,reg_key2$ + str2$,0)
WriteStringN(1,reg_key3$ + str3$,0)
WriteString(1,reg_key4$ + str4$,0)
CloseFile(1)
EndProcedure
;getting current dir string...
current_dir$ = GetCurrentDirectory()
;adding padding zeroes to make valid registry format
hex_current_dir$ = StringToHex(current_dir$) + "00,00 "
;hex_restore$ = ""
;concentating strings for valid reg file (pain in the ASSS) ;)
reg_key1$ = "[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders]" + Chr(13) + Chr (10) + Chr(34) + "Personal" + Chr(34) + "=hex(2):"
reg_key2$ = "[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders]" + Chr(13) + Chr(10) + Chr(34) + "AppData" + Chr(34) + "=hex(2):"
reg_key3$ = "[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders]" + Chr(13) + Chr(10) + Chr(34) + "Local" + " AppData" + Chr(34) + "=hex(2):"
reg_key4$ = "[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders]" + Chr(13) + Chr(10) + Chr(34) + "Common" + " AppData" + Chr(34) + "=hex(2):"
str1$ = "25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,4c,00,45,00,25,00,5c,00,4d,00,79,00,20,00,44,00,6f,00,63,00,75,00,6d,00,65,00,6e,00,74,00,73,00,00,00"
str2$ = "25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,4c,00,45,00,25,00,5c,00,41,00,70,00,70,00,6c,00,69,00,63,00,61,00,74,00,69,00,6f,00,6e,00,20,00,44,00,61,00,74,00,61,00,00,00"
str3$ = "25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,4c,00,45,00,25,00,5c,00,4c,00,6f,00,63,00,61,00,6c,00,20,00,53,00,65,00,74,00,74,00,69,00,6e,00,67,00,73,00,5c,00,41,00,70,00,70,00,6c,00,69,00,63,00,61,00,74,00,69,00,6f,00,6e,00,20,00,44,00,61,00,74,00,61,00,00,00"
str4$ = "25,00,41,00,4c,00,4c,00,55,00,53,00,45,00,52,00,53,00,50,00,52,00,4f,00,46,00,49,00,4c,00,45,00,25,00,5c,00,41,00,70,00,70,00,6c,00,69,00,63,00,61,00,74,00,69,00,6f,00,6e,00,20,00,44,00,61,00,74,00,61,00,00,00"
;writing reg files
WriteToReg_change(hex_current_dir$,"mydoc_here.reg", reg_key1$, reg_key2$, reg_key3$, reg_key4$)
WriteToReg_restore(str1$, str2$, str3$, str4$ ,"mydoc_restore.reg",reg_key1$,reg_key2$,reg_key3$,reg_key4$)
;output msgbox with string and hex values for debug
;MessageRequester(current_dir$, hex_current_dir$, #PB_MessageRequester_Ok)