Hi
Here is a little code to hide string in your code or to get txt$ from an agk code.
The full code (with functions) :
// Project: txt2chr
// Created: 2023-07-25, by blendman
// improved 7 novembre 2023
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "txt2chr or txt2agk" )
global g_width = 1024
global G_height = 768
global usetab =1
global usereturn = 0
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
SetImmersiveMode(1)
// gadgets
#Constant C_sp_btnusechr =1
#Constant C_sp_btnOK =2
#Constant C_sp_btnAGK2txt =3
#CONSTANT KEY_CONTROL_ GetRawKeyState(17)
#CONSTANT KEY_V 86
y = 10
x = 10
w = 100
h = 35
Addbuton(C_sp_btnusechr, x, y, w, h, "Use []") : inc x, 110
Addbuton(C_sp_btnOK, x, y, w, h, "OK") : inc x, 110
Addbuton(C_sp_btnAGK2txt, x, y, w, h, "agk2txt") : inc x, 110
// Editbox
y = 60
n=1
CreateEditBox(1)
SetEditBoxPosition(1, 10, y)
SetEditBoxSize(1, g_width*0.5-20, G_height-10-y)
SetEditBoxTextSize(n, 30)
SetEditBoxMultiLine(n, 30)
n= 2
CreateEditBox(n)
SetEditBoxPosition(n, g_width*0.5+5, y)
SetEditBoxSize(n, g_width*0.5-20, G_height-10-y)
SetEditBoxTextSize(n, 30)
SetEditBoxMultiLine(n, 30)
do
if KEY_CONTROL_
if GetRawKeypressed(KEY_V)
txt$ = GetClipboardText()
SetEditBoxText(1, txt$)
endif
endif
if GetRawKeypressed(27)
txt$ = GetEditBoxText(2)
SetClipboardText(txt$)
end
endif
mx = getpointerx()
my = getpointery()
If GetPointerPressed()
buton = GetSpriteHit(mx, my)
setspritecolor(buton, 50, 50, 50, 255)
if buton = C_sp_btnusechr
endif
endif
If GetPointerreleased()
bb = GetSpriteHit(mx, my)
setspritecolor(buton,150,150, 150, 255)
if bb<> 0
else
if buton = C_sp_btnusechr
setspritecolor(C_sp_btnusechr,150,150, 150, 150+105* usetab)
endif
endif
if bb =buton
select bb
case C_sp_btnAGK2txt
useagk = 1- useagk
if useagk = 1
GetAGKCodeFromTxt()
endif
setspritecolor(buton,150,150, 150, 150 +105 * useagk)
endcase
case C_sp_btnok
if useagk = 1
GetAGKCodeFromTxt()
else
GetChrFromTxt()
endif
setspritecolor(buton,150,150, 150, 255)
endcase
case C_sp_btnusechr
usetab = 1-usetab
if useagk = 1
GetAGKCodeFromTxt()
else
GetChrFromTxt()
endif
setspritecolor(buton,150,150, 150, 150+105* usetab)
endcase
endselect
endif
endif
if GetEditBoxHasFocus(1)
if useagk = 1
GetAGKCodeFromTxt()
else
GetChrFromTxt()
endif
endif
if GetEditBoxHasFocus(2)
txt$ = GetEditBoxText(2)
SetClipboardText(txt$)
endif
//~ Print( ScreenFPS() )
Sync()
loop
Function Input(textin$,length)
SetCursorBlinkTime(0.5)
SetTextInputMaxChars(length)
StartTextInput(textin$)
do
sync()
state=GetTextInputState()
c=GetLastChar()
if GetTextInputCompleted()
if GetTextInputCancelled()
text$=textin$
exit
else
text$=GetTextInput()
exit
endif
endif
loop
StopTextInput()
sync()
endfunction text$
Function GetAGKCodeFromTxt()
tx$ = GeteditboxText(1)
result$ = ""
nb = CountStringTokens(tx$, Chr(10))
txt$=""
For i=0 To nb
txt1$= GetStringToken(tx$, Chr(10), i+1)
txt1$ = ReplaceString(txt1$, Chr(10), "",-1)
txt1$ = ReplaceString(txt1$, Chr(13), "", -1)
txt1$ = ReplaceString(txt1$, Chr(34), "+chr(34)+", -1)
// a = Asc(Mid(tx$,i,1))
// Debug a
txt$ = txt$+" txt$ = txt$+"+Chr(34)+txt1$+Chr(34)+"+Chr(10)"+Chr(10)
Next
result$ = txt$
SetEditboxText(2, result$)
Endfunction
Function GetChrFromTxt()
tx$ = GeteditboxText(1)
result$ = ""
info$ = ""
Foldstart
nb = Len(tx$)
For i=1 To nb
a = Asc(Mid(tx$,i,1))
b=0
info$ = info$ + str(a) +Chr(10) // "mid("++"i,1)"
If usereturn = 1 And (a = 13 Or a =10) // ; return
result$ = Left(result$,Len(result$)-1) +Chr(10)
Else
If usetab = 0
If i < nb
result$ = result$ +"Chr("+Str(a)+")+"
Else
result$ = result$ +"Chr("+Str(a)+")"
EndIf
Else
If i < nb
result$ = result$ +"Chr["+Str(a)+"]+"
Else
result$ = result$ +"Chr["+Str(a)+"]"
EndIf
EndIf
EndIf
info2$ = info2$ + Chr(a) // "mid("++"i,1)"
Next
Foldend
SetEditboxText(2, result$)
endFunction
Function Addbuton(n, x, y, w, h, txt$)
CreateSprite(n, 0)
SetSpritePosition(n, x, y)
SetSpriteSize(n, w, h)
SetSpriteColor(n, 150, 150, 150, 255)
SetSpriteTransparency(n, 1)
createtext(n, txt$)
SetTextPosition(n, getspritex(n)+50, y)
SetTextSize(n, h-5)
SetTextAlignment(n, 1)
endfunction
Function ExportToAGK(filename$)
OpenToWrite(1, filename$)
//copy here the strings get with AGk2txt
txt$ = ""
Writeline(1, txt$)
CloseFile(1)
endfunction
How to use this code ?
1) txt to chr :
How to use it ?
For exemple, if in your code, you have string that you want to hide in the bytecode :
you can use this tool to get chr() or chr[] (if you use a global dim chr[]) to hide your code.
After convert it ith this tool, you will get :
Name$ = Chr[82]+Chr[111]+Chr[98]+Chr[101]+Chr[114]+Chr[116]
or
Name$ = Chr(82)+Chr(111)+Chr(98)+Chr(101)+Chr(114)+Chr(116)
I use that to get the code to hide my string in the bycode of my games/appl
.
2) how to use Agk2txt :
If you want to create an appli or game which will export some agk code, you could have to write all the exported code by hand.
With agk2txt, if you have this code to export :
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
SetImmersiveMode(1)
You can use the buton agk2txt and you will get :
txt$ = txt$+"SetWindowSize( 1024, 768, 0 )"+Chr(10)
txt$ = txt$+"SetWindowAllowResize( 1 ) // allow the user to resize the window"+Chr(10)
txt$ = txt$+""+Chr(10)
txt$ = txt$+"// set display properties"+Chr(10)
txt$ = txt$+"SetVirtualResolution( 1024, 768 ) // doesn't have to match the window"+Chr(10)
txt$ = txt$+"SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices"+Chr(10)
txt$ = txt$+"SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery"+Chr(10)
txt$ = txt$+"SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders"+Chr(10)
txt$ = txt$+"UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts"+Chr(10)
txt$ = txt$+"SetImmersiveMode(1)"+Chr(10)
txt$ = txt$+""+Chr(10)
And how to use it in you code ?
simply :
Function exportToAGK(filename$)
opentowrite(1, filename$)
txt$ = txt$+"SetWindowSize( 1024, 768, 0 )"+Chr(10)
txt$ = txt$+"SetWindowAllowResize( 1 ) // allow the user to resize the window"+Chr(10)
txt$ = txt$+""+Chr(10)
txt$ = txt$+"// set display properties"+Chr(10)
txt$ = txt$+"SetVirtualResolution( 1024, 768 ) // doesn't have to match the window"+Chr(10)
txt$ = txt$+"SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices"+Chr(10)
txt$ = txt$+"SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery"+Chr(10)
txt$ = txt$+"SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders"+Chr(10)
txt$ = txt$+"UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts"+Chr(10)
txt$ = txt$+"SetImmersiveMode(1)"+Chr(10)
txt$ = txt$+""+Chr(10)
Writeline(1, txt$)
closefile(1)
endfunction
I use that to get the code to export for agk, from my app
I hope this can be usefull
cheers
AGK2 tier1 - http://www.dracaena-studio.com