Valhalla Legends Forums Archive | Battle.net Bot Development | Code from .txt ?

AuthorMessageTime
WiLD
Just a stupid question but is it possible to pull code from a txt file and execute it as if it were hardcoded? ..or anything similar?


Im guessing i could always use vbscript and call the function but i want to try and steer away from that.

Eg; code.txt
[code]
insertdword ...
insertdword ...
insertdword ...
sendpacket  ...
bsend "done"
[/code]

and i can just 'insert' that wherever.
June 16, 2006, 12:13 PM
rabbit
Yes.
June 16, 2006, 12:53 PM
warz
I think the CallByName function is as close as you will get to dynamically calling functions during run-time.
June 16, 2006, 12:59 PM
Yegg
Most languages should be able to do this. This is one thing I love about LISP, such a task would be solved with little to no effort. I remember Python having an eval() function that may perform the same or similar task.

To make sure I understand you correctly, if you had "1 + 1" copied down somewhere in a text document, would you want to evaluate the "code" from that document to get the result of 2?
June 16, 2006, 2:40 PM
warz
Looks to me like he's wanting to be able to place his packet structures in text files so he can add support for new packets 'on the fly'.
June 16, 2006, 2:58 PM
inner.
Wouldn't be a bad idea.
June 16, 2006, 4:24 PM
Myndfyr
Why do you want to steer away from VBScript?  The Windows Script Host provides access to VBScript, JScript, and any other ActiveX-supported scripting language developed for Windows, including ActivePerl and ActivePython, among others.

It seems like one of the easiest and most flexible ways to do this.  Otherwise you'd need to pretty much implement your own parser, or use someone else's scripting engine.
June 16, 2006, 4:36 PM
WiLD
[quote author=Yegg link=topic=15187.msg154510#msg154510 date=1150468843]
Most languages should be able to do this. This is one thing I love about LISP, such a task would be solved with little to no effort. I remember Python having an eval() function that may perform the same or similar task.

To make sure I understand you correctly, if you had "1 + 1" copied down somewhere in a text document, would you want to evaluate the "code" from that document to get the result of 2?
[/quote]

Correct.


[quote author=warz link=topic=15187.msg154513#msg154513 date=1150469934]
Looks to me like he's wanting to be able to place his packet structures in text files so he can add support for new packets 'on the fly'.
[/quote]

I was thinking about doing this, if i decided to i would proberly stick with vbscript since it would be easier.
At the moment i only want users to be able to 'inject' their own code that will be executed at an event.
June 16, 2006, 6:27 PM
Spilled[DW]
very interesting. This is something I have never tried and I'll look into this. :)
June 17, 2006, 12:28 AM
warz
[quote author=WiLD link=topic=15187.msg154529#msg154529 date=1150482478]
[quote author=Yegg link=topic=15187.msg154510#msg154510 date=1150468843]
Most languages should be able to do this. This is one thing I love about LISP, such a task would be solved with little to no effort. I remember Python having an eval() function that may perform the same or similar task.

To make sure I understand you correctly, if you had "1 + 1" copied down somewhere in a text document, would you want to evaluate the "code" from that document to get the result of 2?
[/quote]

Correct.


[quote author=warz link=topic=15187.msg154513#msg154513 date=1150469934]
Looks to me like he's wanting to be able to place his packet structures in text files so he can add support for new packets 'on the fly'.
[/quote]

I was thinking about doing this, if i decided to i would proberly stick with vbscript since it would be easier.
At the moment i only want users to be able to 'inject' their own code that will be executed at an event.
[/quote]

Make way for bugs. :-p
June 17, 2006, 1:51 AM
inner.
[quote author=warz link=topic=15187.msg154557#msg154557 date=1150509092]
[quote author=WiLD link=topic=15187.msg154529#msg154529 date=1150482478]
[quote author=Yegg link=topic=15187.msg154510#msg154510 date=1150468843]
Most languages should be able to do this. This is one thing I love about LISP, such a task would be solved with little to no effort. I remember Python having an eval() function that may perform the same or similar task.

To make sure I understand you correctly, if you had "1 + 1" copied down somewhere in a text document, would you want to evaluate the "code" from that document to get the result of 2?
[/quote]

Correct.


[quote author=warz link=topic=15187.msg154513#msg154513 date=1150469934]
Looks to me like he's wanting to be able to place his packet structures in text files so he can add support for new packets 'on the fly'.
[/quote]

I was thinking about doing this, if i decided to i would proberly stick with vbscript since it would be easier.
At the moment i only want users to be able to 'inject' their own code that will be executed at an event.
[/quote]

Make way for bugs. :-p
[/quote]

Especially for inexperienced people that attempt to do a code, and it mess their bot up and them not know how to fix it.
June 17, 2006, 4:23 AM
Topaz
[quote author=inner.de link=topic=15187.msg154564#msg154564 date=1150518217]
[quote author=warz link=topic=15187.msg154557#msg154557 date=1150509092]
[quote author=WiLD link=topic=15187.msg154529#msg154529 date=1150482478]
[quote author=Yegg link=topic=15187.msg154510#msg154510 date=1150468843]
Most languages should be able to do this. This is one thing I love about LISP, such a task would be solved with little to no effort. I remember Python having an eval() function that may perform the same or similar task.

To make sure I understand you correctly, if you had "1 + 1" copied down somewhere in a text document, would you want to evaluate the "code" from that document to get the result of 2?
[/quote]

Correct.


[quote author=warz link=topic=15187.msg154513#msg154513 date=1150469934]
Looks to me like he's wanting to be able to place his packet structures in text files so he can add support for new packets 'on the fly'.
[/quote]

I was thinking about doing this, if i decided to i would proberly stick with vbscript since it would be easier.
At the moment i only want users to be able to 'inject' their own code that will be executed at an event.
[/quote]

Make way for bugs. :-p
[/quote]

Especially for inexperienced people that attempt to do a code, and it mess their bot up and them not know how to fix it.
[/quote]

Oh, man...
June 17, 2006, 6:04 AM
Quarantine
[quote author=inner.de link=topic=15187.msg154564#msg154564 date=1150518217]
[quote author=warz link=topic=15187.msg154557#msg154557 date=1150509092]
[quote author=WiLD link=topic=15187.msg154529#msg154529 date=1150482478]
[quote author=Yegg link=topic=15187.msg154510#msg154510 date=1150468843]
Most languages should be able to do this. This is one thing I love about LISP, such a task would be solved with little to no effort. I remember Python having an eval() function that may perform the same or similar task.

To make sure I understand you correctly, if you had "1 + 1" copied down somewhere in a text document, would you want to evaluate the "code" from that document to get the result of 2?
[/quote]

Correct.


[quote author=warz link=topic=15187.msg154513#msg154513 date=1150469934]
Looks to me like he's wanting to be able to place his packet structures in text files so he can add support for new packets 'on the fly'.
[/quote]

I was thinking about doing this, if i decided to i would proberly stick with vbscript since it would be easier.
At the moment i only want users to be able to 'inject' their own code that will be executed at an event.
[/quote]

Make way for bugs. :-p
[/quote]

Especially for inexperienced people that attempt to do a code, and it mess their bot up and them not know how to fix it.
[/quote]

Haha
June 17, 2006, 12:33 PM
Newby
I think you're better off releasing the source.
June 17, 2006, 6:14 PM
WiLD
[quote author=Newby link=topic=15187.msg154578#msg154578 date=1150568053]
I think you're better off releasing the source.
[/quote]

I plan to at a later stage, as with all my projects i normally release source around v2 (If it get sthat far).

Anyways i have been looking around and i ended up looking on pscode.com, after awhile i found this (click here) which proves to be interesting but im having a little problem.
In the sample project im getting "Application or object defined error" on
[code]
Set MyScript = New clsSadScript
[/code]
Anyone able to figure out why?  :-X


P.S. Remember to register and make a reference to the dll.

Thanks  ;)
June 18, 2006, 4:13 PM
rabbit
Probably because that class isn't in the project.

Try
http://www.liquid-server.org/sources/EmptyChat2/
June 20, 2006, 12:57 PM
ShadowDancer
Yes it is easy, i comonly create dinamyc instructions parsers for my programs, ei:

[code]
  if zstring(strstack[0],1) = 'walk' then
  begin
  li:=nil;
  if zstring(strstack[0],3) = 'comp_player' then
    li:=listview3.FindCaption(0,zstring(strstack[0],4),false,true,false);
  if zstring(strstack[0],3) = 'object' then
    li:=listview5.FindCaption(0,zstring(strstack[0],4),false,true,false);

  if li <> nil then
  begin
    bots[i].goingto.X:=strtoint('$'+li.SubItems.strings[2]);
    bots[i].goingto.Y:=strtoint('$'+li.SubItems.strings[3]);
  end
  else
    dec_ig_actionsstack(i,1);
  end;
  if zstring(strstack[0],1) = 'use_comp_player' then
  begin
    dwordstack[0]:=strtoint('$'+zstring(strstack[0],2));
    bytestack[0]:=strtoint('$'+zstring(strstack[0],3));
    d2g_sendpacket_0x38(bots[i].connections[2],0,dwordstack[0],bytestack[0]); // warriv go to east
  end;
  if zstring(strstack[0],1) = 'interact' then
  begin
  if zstring(strstack[0],3) = 'object' then
  begin
    dwordstack[0]:=strtoint('$'+zstring(strstack[0],4));
    d2g_sendpacket_0x13(bots[i].connections[2],2,dwordstack[0]);
    dec_ig_actionsstack(i,1);
  end;
  if zstring(strstack[0],3) = 'comp_player' then
  begin
    dwordstack[0]:=strtoint('$'+zstring(strstack[0],4));
    d2g_sendpacket_0x59(bots[i].connections[2],1,dwordstack[0],0,0);
    d2g_sendpacket_0x13(bots[i].connections[2],1,dwordstack[0]);
    d2g_sendpacket_0x2F(bots[i].connections[2],1,dwordstack[0]);
  end;
  if zstring(strstack[0],2) = 'end' then
  begin
    dwordstack[0]:=strtoint('$'+zstring(strstack[0],3));
    d2g_sendpacket_0x30(bots[i].connections[2],1,dwordstack[0]);
  end;
  end;
[/code]

but the problem is that i cannt help you a little more bcoz I program in delphi, not vb =(
June 28, 2006, 8:00 AM
rabbit
A) Learn grammar please.
B) If you're not going to help at all, why post?  And why post a large block of code that has nothing to do with the thread?
June 28, 2006, 6:28 PM
ShadowDancer
[quote author=rabbit link=topic=15187.msg155045#msg155045 date=1151519281]
A) Learn grammar please.
B) If you're not going to help at all, why post?  And why post a large block of code that has nothing to do with the thread?
[/quote]

a) right :P

b) not at all...

[code]
var
       buf:array[0..1000] of byte; 
       strstack:array[0..10] of string;
       bufpos:longword;

procedure parseline();
begin
if (zstring(strstack[0],1) = 'openpacket') then
begin
  fillchar(buf, sizeof(buf), #0);
  bufpos:=0;
end;
if (zstring(strstack[0],1) = 'insertdword') then
begin
  writedword(buf, strtoint('$'+zstring(strstack[0],2)),bufpos);
end;
if (zstring(strstack[0],1) = 'insertword') then
begin
  writeword(buf, strtoint('$'+zstring(strstack[0],2)),bufpos);
end;
if (zstring(strstack[0],1) = 'insertbyte') then
begin
  writebyte(buf, strtoint('$'+zstring(strstack[0],2)),bufpos);
end;
if (zstring(strstack[0],1) = 'sendpacket') then
  socket.sendbuf(buf, bufpos,true);
if (zstring(strstack[0],1) = 'bsend') then // i dont undestand exactly what he mean with this
begin
  strstack[1]:=strstack[0]; delete(strstack[1],1,pos(' ',strstack[1])); //remove "bsend "
  socket.sendstr(strstack[1], true);
end;
end;
[/code]

have the same structure and does that he wants to do...
July 3, 2006, 6:01 PM
dRAgoN
If you were useing a .Net language you could use CodeDom.
July 4, 2006, 6:05 AM

Search