Chaosforge Forum

  • April 16, 2024, 15:44
  • Welcome, Guest
Please login or register.



Login with username, password and session length

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - icelus

Pages: [1]
1
DiabloRL / Re: dialorl-svn build error
« on: June 02, 2012, 11:36 »
The problem I reported before was in fact a hang. It was quite an interesting one. Essentially when Tristram is created, the shops are reloaded. Each of them is looking for items to sell, and there's no limit on the number of times they'll try random generation to get acceptable items. All that makes an item acceptable is a positive price and having no spell on it, which should be no problem because almost all items have prices and most don't have spells. However, the way items are created is to use data from a master lua table. The Delphi code in charge of building an item is very forgiving about fields that might not be present, and simply fills in defaults, including a value of zero for price. The fields are all there in the master table, but the call TLuaTable.TryGetField doesn't set its result value in the case of success. That means that an arbitrary collection of properties on an object are not initialised, they just come from the defaults. So: every single item that the shop refiller tries to generate has a zero price, even though the lua datastructures are being initialised correctly. Loading Tristram therefore hangs.

The following patch fixes that bug and one other less interesting one. On my machine, running the sytem in debug mode segfaults. The culprit is ClearInterrupts which generates a range exception because the iterator is a Word instead of an Integer (I don't know why this should be, but it is reproducible). Now that except occurs in a constructor, and in fact in a naughty constructor which is doing work before its ancestors have been initialised. One of those ancestors has prev and next pointers to a linked list of like objects, and those prev and next pointers always point to something valid (in the case of the single item list, they both point to the object itself). When an attempt is made to Detach the uninitialised ancestor, it tries to shrink the list using its prev and next pointers, but they are null (because that naughty constructor TTextIODriver.Create is doing work before initialising it). The result is crash.

After applying this patch you should find you can walk around Tristram. This is how far forward I am. Hopefully I can sit down and play now!

Index: src/viotypes.pas
===================================================================
--- src/viotypes.pas    (revision 571)
+++ src/viotypes.pas    (working copy)
@@ -125,10 +125,10 @@
 { TIODriver }
 
 procedure TIODriver.ClearInterrupts;
-var iCount : Word;
+var iCount : Integer;
 begin
   FOnQuit := nil;
-  for iCount := 0 to High(FInterrupts) do FInterrupts[iCount] := nil;
+  for iCount := Low(FInterrupts) to High(FInterrupts) do FInterrupts[iCount] := nil;
 end;
 
 procedure TIODriver.RegisterInterrupt ( aCode : TIOKeyCode; aInterrupt : TIOInterrupt );
Index: src/vluatable.pas
===================================================================
--- src/vluatable.pas   (revision 571)
+++ src/vluatable.pas   (working copy)
@@ -892,6 +892,7 @@
 begin
   lua_getfield( FState, -1, PChar( aKey ) );
   if lua_isnil( FState, -1 ) then Exit( False );
+  Result := True;
 end;
 
 procedure TLuaTable.RunGetField ( const aKey : AnsiString; ReqType : Byte ) ;
@@ -904,6 +905,7 @@
 begin
   lua_getfield( FState, -1, PChar( aKey ) );
   if lua_type( FState, -1 ) <> ReqType then Exit( False );
+  Result := True;
 end;
 
 function TLuaTable.IsField ( const aKey : AnsiString; ReqType : Byte ) : Boolean;

2
DiabloRL / Re: dialorl-svn build error
« on: June 02, 2012, 08:11 »
Thanks for the help on building this. I wanted to try the latest version.

This is not so trivial at the moment to build on my system. In case anyone else runs into problems, a rough guide for debian/lenny amd64 is (assuming you followed COMPILING.linux and it didn't work):

cd src
make clean
FPCDIR=/usr/lib/fpc/2.6.0/ fpcmake
make  COMPILER_UNITDIR=../../fpcvalkyrie/libs/ FPCOPT="-k-lm"

This probably builds (it does for me). But before you celebrate, try

cd ../bin
./mpq

If this works, congratulations. If you get "no such file or directory", this is a weird interaction bug with fpc, the linker, and the dynamic linker and your mpq has a bad interpreter. For me at least, ./rl ran fine, and you can use that to find out what your interpreter should be:

readelf -l rl | grep interpreter

This will produce something like:

 [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]

Check your mpq interpreter is bad:

readelf -l mpq | grep interpreter

  [Requesting program interpreter: /lib/ld64.so.1]

Luckily this is fixable.

cd ../src
make clean
make FPCOPT="-k-lm -k--dynamic-linker=/lib64/ld-linux-x86-64.so.2" COMPILER_UNITDIR=../../fpcvalkyrie/libs/

Note the string after --dynamic-linker should be the "good" interpreter you got from /bin/rl (or if not there, any other working exe on your machine).

For me at least, mpq now runs, and rl can be started. However, in the "select name" box, pressing enter sends focus to the shell behind (seems to automatically background rl without redrawing the screen). Be very careful what you type while you're wondering when it's going to load (it isn't going to load).

This got me incrementally further forward anyway.

Best wishes.

3
DiabloRL / dialorl-svn build error
« on: June 01, 2012, 18:36 »
I think the file vlualibrary.pas in fpcvalkyrie is missing; in r387 a bunch of stuff was refactored to use it, and the log message indicates it's the main change.... but there's no file that I can see.

In r984 diablorl gives me errors in rlthing: rlthing.pas(26,42) Error: Unknown class field or method identifier "FPosition" (using the 2.6.0 fpc compiler - it refused to build with anything less).

Stepping back to r983 gives me errors in rlview (probably because I had to step to r386 of fpcvalkyrie to get a build).

First occurrence without that is r946; that has errors in rlui (more missing modules from the library).

First occurrence without those errors is 944. That needs vlualibrary (the same we started off missing).

First occurrence without that is r940. This has overloading errors in rllua/rlplayer (State.Push is an ambiguous overload). I backported the fixes from r984 into 940 and fixed these.

Unfortunately, there's an ifOnHit (undefined flag from TFlags) still outstanding. I wasn't able to work out how to fix this in the time available.

ALl of which is a long way of saying I think svn doesn't build at the moment. I did try though! I really wanted to play this.

4
DiabloRL / Re: Patch for Linux on svn875
« on: August 30, 2011, 16:59 »
Four crash bugs I found; I have a fix for two.

1) Barrels killing an NPC causes a segfault. Fix:


--- rlnpc.pas   2011-08-30 23:36:33.000000000 +0100
+++ rlnpc.fix   2011-08-30 23:34:58.000000000 +0100
@@ -502,7 +502,12 @@
     game.player.querry := nil;
   if Visible then UI.Msg(GetName(CTheName)+' dies.');
   PlaySound('d');
-  RunHook( Hook_OnDrop, [ Attacker ] );
+
+  if Attacker <> nil then
+    RunHook( Hook_OnDrop, [  Attacker ] )
+  else
+    RunHook( Hook_OnDrop, [ ] );
+
   if AI in AIMonster then
     UI.Msg('You gain '+IntToStr(getExpValue(Game.Player.Level))+' experience.');
   Game.Player.AddExp(getExpValue(Game.Player.Level));


2) Under certain circumstances, the lua calls through to drop item with invalid coordinates. Below fixes the crash, the lua still needs to be identified.


Index: rllevel.pas
===================================================================
--- rllevel.pas (revision 878)
+++ rllevel.pas (working copy)

@@ -715,6 +715,11 @@
   if State.StackSize < 2 then Exit(0);
   tid   := State.ToString(1);
   Coord := State.ToCoord(2);
+
+  if ((Coord.X < 1) or (Coord.X > MapSizeX) or
+      (Coord.Y < 1) or (Coord.Y > MapSizeY) ) then
+     Exit(luaL_error(L, PChar('Coordinates out of range')));
+   
   if tid = '' then
   begin
     FreeAndNil(Game.Lua.Level.Map[Coord.X, Coord.Y].NPC);


3) Valgrind backtrace identified this access of free'd memory. I'm not really sure where to start. I can take a look at it, but I could use a hint.



==5016== Invalid read of size 8
==5016==    at 0x52F3A8: VLUASTATE_TLUASTATE_$__PUSH$TLUAREFERENCEDOBJECT (vluastate.pas:403)
==5016==    by 0x4E32290: (within /usr/lib/liblua5.1.so.0.0.0)
==5016==    by 0x4E3C422: (within /usr/lib/liblua5.1.so.0.0.0)
==5016==    by 0x4E326FD: (within /usr/lib/liblua5.1.so.0.0.0)
==5016==    by 0x4E31E36: (within /usr/lib/liblua5.1.so.0.0.0)
==5016==    by 0x4E31EB4: (within /usr/lib/liblua5.1.so.0.0.0)
==5016==    by 0x4E2DF74: lua_pcall (in /usr/lib/liblua5.1.so.0.0.0)
==5016==    by 0x5297EA: LUA_LUA_CALLFUNCTION$PLUA_STATE$ANSISTRING$array_of_VARIANT$LONGINT$$VARIANT (lua.pas:611)
==5016==    by 0x4E7B92: VLUA_TLUATABLE_$__EXECUTE$ANSISTRING$array_of_VARIANT$$VARIANT (vlua.pas:830)
==5016==    by 0x4EFC7B: RLNPC_TNPC_$__ACTIVATECELL$TCOORD2D$$BOOLEAN (rlnpc.pas:367)
==5016==    by 0x493806: RLPLAYER_TPLAYER_$_ACTION_TRYMOVE$TDIRECTION (rlplayer.pas:1479)
==5016==    by 0x49299F: RLPLAYER_TPLAYER_$__ACTION (rlplayer.pas:1531)
==5016==  Address 0x7123660 is 128 bytes inside a block of size 256 free'd
==5016==    at 0x4C2130F: free (vg_replace_malloc.c:323)
==5016==    by 0x4534F4: CMEM_CFREEMEM$POINTER$$QWORD (in /home/ed/sources/diablorl-svn/bin/rl)
==5016==    by 0x489AD5: RLLEVEL_LUA_LEVEL_DROP_ITEM$PLUA_STATE$$LONGINT (rllevel.pas:727)
==5016==    by 0x4E32290: (within /usr/lib/liblua5.1.so.0.0.0)
==5016==    by 0x4E3C422: (within /usr/lib/liblua5.1.so.0.0.0)
==5016==    by 0x4E326FD: (within /usr/lib/liblua5.1.so.0.0.0)
==5016==    by 0x4E31E36: (within /usr/lib/liblua5.1.so.0.0.0)
==5016==    by 0x4E31EB4: (within /usr/lib/liblua5.1.so.0.0.0)
==5016==    by 0x4E2DF74: lua_pcall (in /usr/lib/liblua5.1.so.0.0.0)
==5016==    by 0x5297EA: LUA_LUA_CALLFUNCTION$PLUA_STATE$ANSISTRING$array_of_VARIANT$LONGINT$$VARIANT (lua.pas:611)
==5016==    by 0x4E7B92: VLUA_TLUATABLE_$__EXECUTE$ANSISTRING$array_of_VARIANT$$VARIANT (vlua.pas:830)
==5016==    by 0x4EFC7B: RLNPC_TNPC_$__ACTIVATECELL$TCOORD2D$$BOOLEAN (rlnpc.pas:367)
==5016==
==5016== Invalid read of size 4
==5016==    at 0x4ED660: RLGOBJ_TGAMEOBJECT_$__GETLUAINDEX$$LONGINT (rlgobj.pas:174)
==5016==    by 0x4E32290: (within /usr/lib/liblua5.1.so.0.0.0)
==5016==    by 0x4E3C422: (within /usr/lib/liblua5.1.so.0.0.0)
==5016==    by 0x4E326FD: (within /usr/lib/liblua5.1.so.0.0.0)
==5016==    by 0x4E31E36: (within /usr/lib/liblua5.1.so.0.0.0)
==5016==    by 0x4E31EB4: (within /usr/lib/liblua5.1.so.0.0.0)
==5016==    by 0x4E2DF74: lua_pcall (in /usr/lib/liblua5.1.so.0.0.0)
==5016==    by 0x5297EA: LUA_LUA_CALLFUNCTION$PLUA_STATE$ANSISTRING$array_of_VARIANT$LONGINT$$VARIANT (lua.pas:611)
==5016==    by 0x4E7B92: VLUA_TLUATABLE_$__EXECUTE$ANSISTRING$array_of_VARIANT$$VARIANT (vlua.pas:830)
==5016==    by 0x4EFC7B: RLNPC_TNPC_$__ACTIVATECELL$TCOORD2D$$BOOLEAN (rlnpc.pas:367)
==5016==    by 0x493806: RLPLAYER_TPLAYER_$_ACTION_TRYMOVE$TDIRECTION (rlplayer.pas:1479)
==5016==    by 0x49299F: RLPLAYER_TPLAYER_$__ACTION (rlplayer.pas:1531)
==5016==  Address 0x7123658 is 120 bytes inside a block of size 256 free'd
==5016==    at 0x4C2130F: free (vg_replace_malloc.c:323)
==5016==    by 0x4534F4: CMEM_CFREEMEM$POINTER$$QWORD (in /home/ed/sources/diablorl-svn/bin/rl)
==5016==    by 0x489AD5: RLLEVEL_LUA_LEVEL_DROP_ITEM$PLUA_STATE$$LONGINT (rllevel.pas:727)
==5016==    by 0x4E32290: (within /usr/lib/liblua5.1.so.0.0.0)
==5016==    by 0x4E3C422: (within /usr/lib/liblua5.1.so.0.0.0)
==5016==    by 0x4E326FD: (within /usr/lib/liblua5.1.so.0.0.0)
==5016==    by 0x4E31E36: (within /usr/lib/liblua5.1.so.0.0.0)
==5016==    by 0x4E31EB4: (within /usr/lib/liblua5.1.so.0.0.0)
==5016==    by 0x4E2DF74: lua_pcall (in /usr/lib/liblua5.1.so.0.0.0)
==5016==    by 0x5297EA: LUA_LUA_CALLFUNCTION$PLUA_STATE$ANSISTRING$array_of_VARIANT$LONGINT$$VARIANT (lua.pas:611)
==5016==    by 0x4E7B92: VLUA_TLUATABLE_$__EXECUTE$ANSISTRING$array_of_VARIANT$$VARIANT (vlua.pas:830)
==5016==    by 0x4EFC7B: RLNPC_TNPC_$__ACTIVATECELL$TCOORD2D$$BOOLEAN (rlnpc.pas:367)
==5016==


4) I really don't know what happened here. Things went BOOM in a bad way.


==5417== Invalid read of size 8
==5417==    at 0x445551: fpc_raiseexception (in /home/ed/sources/diablorl-svn/bin/rl)
==5417==    by 0x4E7C12: VLUA_TLUATABLE_$__EXECUTE$ANSISTRING$array_of_VARIANT$$VARIANT (vlua.pas:830)
==5417==    by 0x4EFCFB: RLNPC_TNPC_$__ACTIVATECELL$TCOORD2D$$BOOLEAN (rlnpc.pas:367)
==5417==    by 0x493886: RLPLAYER_TPLAYER_$_ACTION_TRYMOVE$TDIRECTION (rlplayer.pas:1479)
==5417==    by 0x492A1F: RLPLAYER_TPLAYER_$__ACTION (rlplayer.pas:1531)
==5417==    by 0x4F0582: RLNPC_TNPC_$__TIMEFLOW$LONGINT (rlnpc.pas:485)
==5417==    by 0x434E02: main (rl.pas:27)
==5417==  Address 0x7fefff638 is just below the stack ptr.  To suppress, use: --workaround-gcc296-bugs=yes
==5417==
==5417== Invalid read of size 8
==5417==    at 0x449D04: SYSTEM_LONGJMP$JMP_BUF$LONGINT (in /home/ed/sources/diablorl-svn/bin/rl)
==5417==    by 0x44555E: fpc_raiseexception (in /home/ed/sources/diablorl-svn/bin/rl)
==5417==    by 0x4E7C12: VLUA_TLUATABLE_$__EXECUTE$ANSISTRING$array_of_VARIANT$$VARIANT (vlua.pas:830)
==5417==    by 0x4EFCFB: RLNPC_TNPC_$__ACTIVATECELL$TCOORD2D$$BOOLEAN (rlnpc.pas:367)
==5417==    by 0x493886: RLPLAYER_TPLAYER_$_ACTION_TRYMOVE$TDIRECTION (rlplayer.pas:1479)
==5417==    by 0x492A1F: RLPLAYER_TPLAYER_$__ACTION (rlplayer.pas:1531)
==5417==    by 0x4F0582: RLNPC_TNPC_$__TIMEFLOW$LONGINT (rlnpc.pas:485)
==5417==    by 0x434E02: main (rl.pas:27)
==5417==  Address 0x7fefff5f8 is not stack'd, malloc'd or (recently) free'd
==5417==
==5417== Invalid read of size 8
==5417==    at 0x449D07: SYSTEM_LONGJMP$JMP_BUF$LONGINT (in /home/ed/sources/diablorl-svn/bin/rl)
==5417==    by 0x44555E: fpc_raiseexception (in /home/ed/sources/diablorl-svn/bin/rl)
==5417==    by 0x4E7C12: VLUA_TLUATABLE_$__EXECUTE$ANSISTRING$array_of_VARIANT$$VARIANT (vlua.pas:830)
==5417==    by 0x4EFCFB: RLNPC_TNPC_$__ACTIVATECELL$TCOORD2D$$BOOLEAN (rlnpc.pas:367)
==5417==    by 0x493886: RLPLAYER_TPLAYER_$_ACTION_TRYMOVE$TDIRECTION (rlplayer.pas:1479)
==5417==    by 0x492A1F: RLPLAYER_TPLAYER_$__ACTION (rlplayer.pas:1531)
==5417==    by 0x4F0582: RLNPC_TNPC_$__TIMEFLOW$LONGINT (rlnpc.pas:485)
==5417==    by 0x434E02: main (rl.pas:27)
==5417==  Address 0x7fefff600 is not stack'd, malloc'd or (recently) free'd
==5417==
==5417== Invalid read of size 8
==5417==    at 0x449D0B: SYSTEM_LONGJMP$JMP_BUF$LONGINT (in /home/ed/sources/diablorl-svn/bin/rl)
==5417==    by 0x7FEFFFAFF: ???
==5417==    by 0x44555E: fpc_raiseexception (in /home/ed/sources/diablorl-svn/bin/rl)
==5417==    by 0x0: ???
==5417==    by 0x0: ???
==5417==    by 0x7FEFFFAFF: ???
==5417==    by 0x4FC358: LUA_LUA_CALLFUNCTION$PLUA_STATE$ANSISTRING$array_of_VARIANT$LONGINT$$VARIANT (lua.pas:615)
==5417==    by 0x7FEFFFA0F: ???
==5417==    by 0x64540EF: ???
==5417==    by 0x6FBF237: ???
==5417==    by 0x167: ???
==5417==    by 0x64495E7: ???
==5417==  Address 0x7fefff608 is not stack'd, malloc'd or (recently) free'd
==5417==
==5417== Invalid read of size 8
==5417==    at 0x449D0F: SYSTEM_LONGJMP$JMP_BUF$LONGINT (in /home/ed/sources/diablorl-svn/bin/rl)
==5417==    by 0x7FEFFFAFF: ???
==5417==    by 0x44555E: fpc_raiseexception (in /home/ed/sources/diablorl-svn/bin/rl)
==5417==    by 0x0: ???
==5417==    by 0x0: ???
==5417==    by 0x7FEFFFAFF: ???
==5417==    by 0x4FC358: LUA_LUA_CALLFUNCTION$PLUA_STATE$ANSISTRING$array_of_VARIANT$LONGINT$$VARIANT (lua.pas:615)
==5417==    by 0x7FEFFFA0F: ???
==5417==    by 0x64540EF: ???
==5417==    by 0x6FBF237: ???
==5417==    by 0x167: ???
==5417==    by 0x64495E7: ???
==5417==  Address 0x7fefff610 is not stack'd, malloc'd or (recently) free'd
==5417==
==5417== Invalid read of size 8
==5417==    at 0x449D13: SYSTEM_LONGJMP$JMP_BUF$LONGINT (in /home/ed/sources/diablorl-svn/bin/rl)
==5417==    by 0x7FEFFFAFF: ???
==5417==    by 0x44555E: fpc_raiseexception (in /home/ed/sources/diablorl-svn/bin/rl)
==5417==    by 0x0: ???
==5417==    by 0x0: ???
==5417==    by 0x7FEFFFAFF: ???
==5417==    by 0x4FC358: LUA_LUA_CALLFUNCTION$PLUA_STATE$ANSISTRING$array_of_VARIANT$LONGINT$$VARIANT (lua.pas:615)
==5417==    by 0x7FEFFFA0F: ???
==5417==    by 0x64540EF: ???
==5417==    by 0x6FBF237: ???
==5417==    by 0x167: ???
==5417==    by 0x64495E7: ???
==5417==  Address 0x7fefff618 is not stack'd, malloc'd or (recently) free'd

==5417== Invalid read of size 8
==5417==    at 0x449D17: SYSTEM_LONGJMP$JMP_BUF$LONGINT (in /home/ed/sources/diablorl-svn/bin/rl)
==5417==    by 0x7FEFFFAFF: ???
==5417==    by 0x44555E: fpc_raiseexception (in /home/ed/sources/diablorl-svn/bin/rl)
==5417==    by 0x0: ???
==5417==    by 0x0: ???
==5417==    by 0x7FEFFFAFF: ???
==5417==    by 0x4FC358: LUA_LUA_CALLFUNCTION$PLUA_STATE$ANSISTRING$array_of_VARIANT$LONGINT$$VARIANT (lua.pas:615)
==5417==    by 0x7FEFFFA0F: ???
==5417==    by 0x64540EF: ???
==5417==    by 0x6FBF237: ???
==5417==    by 0x167: ???
==5417==    by 0x64495E7: ???
==5417==  Address 0x7fefff620 is just below the stack ptr.  To suppress, use: --workaround-gcc296-bugs=yes
==5417==
==5417== Invalid read of size 8
==5417==    at 0x449D27: SYSTEM_LONGJMP$JMP_BUF$LONGINT (in /home/ed/sources/diablorl-svn/bin/rl)
==5417==    by 0x7FEFFFAFF: ???
==5417==    by 0x44555E: fpc_raiseexception (in /home/ed/sources/diablorl-svn/bin/rl)
==5417==    by 0x0: ???
==5417==    by 0x0: ???
==5417==    by 0x7FEFFFAFF: ???
==5417==    by 0x4FC358: LUA_LUA_CALLFUNCTION$PLUA_STATE$ANSISTRING$array_of_VARIANT$LONGINT$$VARIANT (lua.pas:615)
==5417==    by 0x7FEFFFA0F: ???
==5417==    by 0x64540EF: ???
==5417==    by 0x6FBF237: ???
==5417==    by 0x167: ???
==5417==    by 0x64495E7: ???
==5417==  Address 0x7fefff630 is just below the stack ptr.  To suppress, use: --workaround-gcc296-bugs=yes
==5417==
==5417== Invalid read of size 8
==5417==    at 0x449D2B: SYSTEM_LONGJMP$JMP_BUF$LONGINT (in /home/ed/sources/diablorl-svn/bin/rl)
==5417==    by 0x7FEFFFAFF: ???
==5417==    by 0x44555E: fpc_raiseexception (in /home/ed/sources/diablorl-svn/bin/rl)
==5417==    by 0x0: ???
==5417==    by 0x0: ???
==5417==    by 0x7FEFFFAFF: ???
==5417==    by 0x4FC358: LUA_LUA_CALLFUNCTION$PLUA_STATE$ANSISTRING$array_of_VARIANT$LONGINT$$VARIANT (lua.pas:615)
==5417==    by 0x7FEFFFA0F: ???
==5417==    by 0x64540EF: ???
==5417==    by 0x6FBF237: ???
==5417==    by 0x167: ???
==5417==    by 0x64495E7: ???
==5417==  Address 0x7fefff628 is just below the stack ptr.  To suppress, use: --workaround-gcc296-bugs=yes


5
DiabloRL / Re: Patch for Linux on svn875
« on: August 29, 2011, 16:43 »
There are still a lot of bugs in SVN (as in it's completely unplayable). This is one crash bug in loading save game:

Index: rlplayer.pas
===================================================================
--- rlplayer.pas        (revision 876)
+++ rlplayer.pas        (working copy)
@@ -1877,7 +1877,7 @@
     end;
 
   ISt.Read(tsob, sizeof(tsob));
-  for Count := 1 to Game.Lua.Table['quests','__counter']  do
+  for Count := 1 to Game.Lua.Table['achievments','__counter']  do
     if Count in tsob then
     begin
       Game.Lua.IndexedTable['achievments', Count, 'active'] := true;



Even with this it won't work though. There is a deep problem in rllua.pas/TRLLua.RunHook when it comes to loading Grisworld's magical items. I can't work out how this should work. It's clear the current system can't work because after calling CallFunction with no args, the function is at the top of the stack and there are no arguments... except the lua references a first argument "self" and that bombs. You can add an extra parameter saying "resurrect the previous n arguments from the stack" and that gets you somewhere... But there's still the problem of what the object you're working with actually is, and how you get a handle to it. At the moment it's looking up stuff in the "items" table, and that seems to be prototypes. But how to get hold of instance isn't clear to me. Here's how far I got, in case this is useful.


Index: rllua.pas
===================================================================
--- rllua.pas   (revision 876)
+++ rllua.pas   (working copy)
@@ -210,7 +210,7 @@
   try
     with TLuaTable.Create( Self, TableName, Index ) do
     try
-      RunHook := State.CallFunction( Name, Args, -1 );
+      RunHook := State.CallFunction( Name, Args, -1, 1 );
     finally
       Free;
     end;

And the corresponding fpcvalkyrie changes:

Index: vluastate.pas
===================================================================
--- vluastate.pas       (revision 243)
+++ vluastate.pas       (working copy)
@@ -83,7 +83,7 @@
     procedure UnRegisterObject( Obj : TLuaReferencedObject );
     procedure RegisterNewSubObject( Ref : Integer; Obj : TObject; const Field, Prototype : AnsiString );
     function  RunHook( Obj : TLuaReferencedObject; HookName : AnsiString; const Params : array of const ) : Variant;
-    function  CallFunction( Name : AnsiString; const Params : array of const; idx : Integer = GLOBALSINDEX ) : Variant;
+    function  CallFunction(Name : AnsiString; const Params : array of const; idx : Integer = GLOBALSINDEX; extra_args: Integer = 0 ) : Variant;
     destructor Done;
     procedure RegisterSubTable( Ref : Integer; const Name : AnsiString );
     procedure SubTableToStream( Obj : TLuaReferencedObject; const Name : AnsiString; OSt : TStream );
@@ -522,8 +522,9 @@
 end;
 
 function TLuaState.CallFunction( Name : AnsiString;
-    const Params : array of const; idx : Integer = GLOBALSINDEX ) : Variant;
+   const Params : array of const; idx : Integer = GLOBALSINDEX; extra_args   : Integer = 0): Variant;
 var Index : Integer;
+var i : Integer ;
 begin
   Index := lua_absindex( FState, idx );
   lua_pushstring( FState, Name );
@@ -532,7 +533,11 @@
 
   Push( Params );
 
-  if lua_pcall( FState, High( Params ) + 1, 1, 0 ) <> 0 then PopRaise( 1, 'Lua error : '+lua_tostring( FState, -1) );
+  (* Raise the extra parameters from their previous (assumed) stack position *)
+  for i := 1 to extra_args do
+    lua_pushvalue(FState, -2 - extra_args + i);

+  if lua_pcall( FState, High( Params ) + 1 + extra_args, 1, 0 ) <> 0 then PopRaise( 1, 'Lua error : '+lua_tostring( FState, -1) );
   CallFunction := lua_tovariant( FState, -1 );
   lua_pop( FState, 1 );
 end;

6
DiabloRL / Patch for Linux on svn875
« on: August 27, 2011, 12:29 »
svn 875 is broken on linux, path delimiter woes in building the resource bundle.

Need:

Index: src/mpq.pas
===================================================================
--- src/mpq.pas   (revision 875)
+++ src/mpq.pas   (working copy)
@@ -17,10 +17,14 @@
     MPQFile.AddLuaFile('functions.lua',FILETYPE_LUA,[vdfCompressed]);
     MPQFile.AddLuaFile('const.inc',FILETYPE_LUA,[vdfCompressed]);
 
-    MPQFile.Add('lua','*.lua',@MPQFile.AddLuaFile,FILETYPE_LUA,[vdfCompressed]);
-    MPQFile.Add('lua\items','*.lua',@MPQFile.AddLuaFile,FILETYPE_LUA,[vdfCompressed],'items');
-    MPQFile.Add('lua\npc','*.lua',@MPQFile.AddLuaFile,FILETYPE_LUA,[vdfCompressed],'npc');
-    MPQFile.Add('lua\levels','*.lua',@MPQFile.AddLuaFile,FILETYPE_LUA,[vdfCompressed],'levels');
+    MPQFile.Add('lua','*.lua',
+                @MPQFile.AddLuaFile,FILETYPE_LUA,[vdfCompressed]);
+    MPQFile.Add('lua' + PathDelim + 'items','*.lua',
+                @MPQFile.AddLuaFile,FILETYPE_LUA,[vdfCompressed],'items');
+    MPQFile.Add('lua' + PathDelim + 'npc','*.lua',
+                @MPQFile.AddLuaFile,FILETYPE_LUA,[vdfCompressed],'npc');
+    MPQFile.Add('lua' + PathDelim + 'levels','*.lua',
+                @MPQFile.AddLuaFile,FILETYPE_LUA,[vdfCompressed],'levels');
   except
     on e : Exception do
       Writeln( e.Message );

Pages: [1]