Valhalla Legends Archive

Programming => Battle.net Bot Development => Topic started by: WiLD on June 16, 2006, 07:13 AM

Title: Code from .txt ?
Post by: WiLD on June 16, 2006, 07:13 AM
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

insertdword ...
insertdword ...
insertdword ...
sendpacket  ...
bsend "done"


and i can just 'insert' that wherever.
Title: Re: Code from .txt ?
Post by: rabbit on June 16, 2006, 07:53 AM
Yes.
Title: Re: Code from .txt ?
Post by: warz on June 16, 2006, 07:59 AM
I think the CallByName function is as close as you will get to dynamically calling functions during run-time.
Title: Re: Code from .txt ?
Post by: Yegg on June 16, 2006, 09:40 AM
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?
Title: Re: Code from .txt ?
Post by: warz on June 16, 2006, 09:58 AM
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'.
Title: Re: Code from .txt ?
Post by: vuther.de on June 16, 2006, 11:24 AM
Wouldn't be a bad idea.
Title: Re: Code from .txt ?
Post by: MyndFyre on June 16, 2006, 11:36 AM
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.
Title: Re: Code from .txt ?
Post by: WiLD on June 16, 2006, 01:27 PM
Quote from: Yegg on June 16, 2006, 09:40 AM
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?

Correct.


Quote from: warz on June 16, 2006, 09:58 AM
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'.

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.
Title: Re: Code from .txt ?
Post by: Spilled on June 16, 2006, 07:28 PM
very interesting. This is something I have never tried and I'll look into this. :)
Title: Re: Code from .txt ?
Post by: warz on June 16, 2006, 08:51 PM
Quote from: WiLD on June 16, 2006, 01:27 PM
Quote from: Yegg on June 16, 2006, 09:40 AM
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?

Correct.


Quote from: warz on June 16, 2006, 09:58 AM
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'.

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.

Make way for bugs. :-p
Title: Re: Code from .txt ?
Post by: vuther.de on June 16, 2006, 11:23 PM
Quote from: warz on June 16, 2006, 08:51 PM
Quote from: WiLD on June 16, 2006, 01:27 PM
Quote from: Yegg on June 16, 2006, 09:40 AM
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?

Correct.


Quote from: warz on June 16, 2006, 09:58 AM
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'.

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.

Make way for bugs. :-p

Especially for inexperienced people that attempt to do a code, and it mess their bot up and them not know how to fix it.
Title: Re: Code from .txt ?
Post by: topaz on June 17, 2006, 01:04 AM
Quote from: inner.de on June 16, 2006, 11:23 PM
Quote from: warz on June 16, 2006, 08:51 PM
Quote from: WiLD on June 16, 2006, 01:27 PM
Quote from: Yegg on June 16, 2006, 09:40 AM
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?

Correct.


Quote from: warz on June 16, 2006, 09:58 AM
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'.

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.

Make way for bugs. :-p

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

Oh, man...
Title: Re: Code from .txt ?
Post by: Warrior on June 17, 2006, 07:33 AM
Quote from: inner.de on June 16, 2006, 11:23 PM
Quote from: warz on June 16, 2006, 08:51 PM
Quote from: WiLD on June 16, 2006, 01:27 PM
Quote from: Yegg on June 16, 2006, 09:40 AM
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?

Correct.


Quote from: warz on June 16, 2006, 09:58 AM
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'.

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.

Make way for bugs. :-p

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

Haha
Title: Re: Code from .txt ?
Post by: Newby on June 17, 2006, 01:14 PM
I think you're better off releasing the source.
Title: Re: Code from .txt ?
Post by: WiLD on June 18, 2006, 11:13 AM
Quote from: Newby on June 17, 2006, 01:14 PM
I think you're better off releasing the source.

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) (http://www.pscode.com/vb/scripts/ShowZip.asp?lngWId=1&lngCodeId=36716&strZipAccessCode=tp%2FS367166177) which proves to be interesting but im having a little problem.
In the sample project im getting "Application or object defined error" on

Set MyScript = New clsSadScript

Anyone able to figure out why?  :-X


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

Thanks  ;)
Title: Re: Code from .txt ?
Post by: rabbit on June 20, 2006, 07:57 AM
Probably because that class isn't in the project.

Try
http://www.liquid-server.org/sources/EmptyChat2/
Title: Re: Code from .txt ?
Post by: ShadowDancer on June 28, 2006, 03:00 AM
Yes it is easy, i comonly create dinamyc instructions parsers for my programs, ei:


  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;


but the problem is that i cannt help you a little more bcoz I program in delphi, not vb =(
Title: Re: Code from .txt ?
Post by: rabbit on June 28, 2006, 01:28 PM
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?
Title: Re: Code from .txt ?
Post by: ShadowDancer on July 03, 2006, 01:01 PM
Quote from: rabbit on June 28, 2006, 01:28 PM
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?

a) right :P

b) not at all...


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;


have the same structure and does that he wants to do...
Title: Re: Code from .txt ?
Post by: l)ragon on July 04, 2006, 01:05 AM
If you were useing a .Net language you could use CodeDom.