Jump to content

Using Weidu to Create Exit & Entrance Points


CoM_Solaufein

Recommended Posts

I'm to paste some rather lengthy code at the bottom of my question here. If I was to use this code for a template for another mod, what information would I change in this and where would I get the information (WRITE_SHORT, WRITE_LONG) to do so?

 

I bolded what I guess would change if I was to use this on another mod with a different area.

 

// AR0400 gets new travel region and new entrance for CM7000
COPY_EXISTING ~AR0400.ARE~ ~override~
READ_LONG  0x54  "actors_offset"
READ_SHORT 0x58  "actors_num"
READ_SHORT 0x5a  "infotrig_num"
READ_LONG  0x5c  "infotrig_offset"
READ_LONG  0x60  "spawns_offset"
READ_LONG  0x64  "spawns_num"
READ_LONG  0x68  "entrances_offset"
READ_LONG  0x6c  "entrances_num"
READ_LONG  0x70  "cont_offset"
READ_SHORT 0x74  "cont_num"
READ_SHORT 0x76  "items_num"
READ_LONG  0x78  "items_offset"
READ_LONG  0x7c  "vert_offset"
READ_SHORT 0x80  "vert_num"
READ_SHORT 0x82  "amb_num"
READ_LONG  0x84  "amb_offset"
READ_LONG  0x88  "vars_offset"
READ_LONG  0x8c  "vars_num"
READ_LONG  0xa0  "expbmp_offset"
READ_LONG  0xa4  "doors_num"
READ_LONG  0xa8  "doors_offset"
READ_LONG  0xac  "anim_num"
READ_LONG  0xb0  "anim_offset"
READ_LONG  0xb4  "tiled_num"
READ_LONG  0xb8  "tiled_offset"
READ_LONG  0xbc  "songs_offset"
READ_LONG  0xc0  "rest_spawns_offset"
READ_LONG  0xc4  "automap_offset"
READ_LONG  0xc8  "automap_num"

//adding new trigger ************************************************
  SET offset = ("%infotrig_offset%"+0xc4*"%infotrig_num%")
  [b]INSERT_BYTES offset 0xc4
  WRITE_ASCII offset ~Tran7000~
  WRITE_SHORT (offset+0x20) 2			//travel trigger
  WRITE_SHORT (offset+0x22) 1526		 //bounding box
  WRITE_SHORT (offset+0x24) 794		  //bounding box
  WRITE_SHORT (offset+0x26) 1746		 //bounding box
  WRITE_SHORT (offset+0x28) 866		  //bounding box
  WRITE_SHORT (offset+0x2a) 4			//vertices number
  WRITE_LONG  (offset+0x2c) "%vert_num%" //first vertex index
  WRITE_LONG  (offset+0x34) 30		   //cursor
  WRITE_ASCII (offset+0x38) ~CM7000~	 //destination area
  WRITE_ASCII (offset+0x40) ~EXIT0400~   //destination area's entrance name
  WRITE_LONG  (offset+0x60) 0x00000004   //flags - party required
  WRITE_SHORT (offset+0x70) 1636		 //Trap location X
  WRITE_SHORT (offset+0x72) 830		  //Trap location Y[/b]
  SET "infotrig_num"="%infotrig_num%"+1
  WRITE_SHORT 0x5a  "%infotrig_num%"

  SET "info_ext"=0xc4
  PATCH_IF ("%actors_offset%">="%infotrig_offset%") BEGIN
 "actors_offset"="%actors_offset%"+"%info_ext%"
 WRITE_LONG  0x54 "%actors_offset%"
  END
  PATCH_IF ("%spawns_offset%">="%infotrig_offset%") BEGIN
 "spawns_offset"="%spawns_offset%"+"%info_ext%"
 WRITE_LONG  0x60  "%spawns_offset%"
  END
  PATCH_IF ("%entrances_offset%">="%infotrig_offset%") BEGIN
 "entrances_offset"="%entrances_offset%"+"%info_ext%"
 WRITE_LONG  0x68  "%entrances_offset%"
  END
  PATCH_IF ("%cont_offset%">="%infotrig_offset%") BEGIN
 "cont_offset"="%cont_offset%"+"%info_ext%"
 WRITE_LONG  0x70  "%cont_offset%"
  END
  PATCH_IF ("%items_offset%">="%infotrig_offset%") BEGIN
 "items_offset"="%items_offset%"+"%info_ext%"
 WRITE_LONG  0x78  "%items_offset%"
  END
  PATCH_IF ("%vert_offset%">="%infotrig_offset%") BEGIN
 "vert_offset"="%vert_offset%"+"%info_ext%"
 WRITE_LONG  0x7c  "%vert_offset%"
  END
  PATCH_IF ("%amb_offset%">="%infotrig_offset%") BEGIN
 "amb_offset"="%amb_offset%"+"%info_ext%"
 WRITE_LONG  0x84  "%amb_offset%"
  END
  PATCH_IF ("%vars_offset%">="%infotrig_offset%") BEGIN
 "vars_offset"="%vars_offset%"+"%info_ext%"
 WRITE_LONG  0x88  "%vars_offset%"
  END
  PATCH_IF ("%expbmp_offset%">="%infotrig_offset%") BEGIN
 "expbmp_offset"="%expbmp_offset%"+"%info_ext%"
 WRITE_LONG  0xa0  "%expbmp_offset%"
  END
  PATCH_IF ("%doors_offset%">="%infotrig_offset%") BEGIN
 "doors_offset"="%doors_offset%"+"%info_ext%"
 WRITE_LONG  0xa8  "%doors_offset%"
  END
  PATCH_IF ("%anim_offset%">="%infotrig_offset%") BEGIN
 "anim_offset"="%anim_offset%"+"%info_ext%"
 WRITE_LONG  0xb0  "%anim_offset%"
  END
  PATCH_IF ("%tiled_offset%">="%infotrig_offset%") BEGIN
 "tiled_offset"="%tiled_offset%"+"%info_ext%"
 WRITE_LONG  0xb8  "%tiled_offset%"
  END
  PATCH_IF ("%songs_offset%">="%infotrig_offset%") BEGIN
 "songs_offset"="%songs_offset%"+"%info_ext%"
 WRITE_LONG  0xbc  "%songs_offset%"
  END
  PATCH_IF ("%rest_spawns_offset%">="%infotrig_offset%") BEGIN
 "rest_spawns_offset"="%rest_spawns_offset%"+"%info_ext%"
 WRITE_LONG  0xc0  "%rest_spawns_offset%"
  END
  PATCH_IF ("%automap_offset%">="%infotrig_offset%") BEGIN
 "automap_offset"="%automap_offset%"+"%info_ext%"
 WRITE_LONG  0xc4  "%automap_offset%"
  END

 //adding 4 new vertices for triggers
  SET offset = ("%vert_offset%"+0x04*"%vert_num%")
  [b]INSERT_BYTES offset (0x04*4)
  WRITE_SHORT  offset	  1526
  WRITE_SHORT  (offset+2)  808
  WRITE_SHORT  (offset+4)  1741
  WRITE_SHORT  (offset+6)  793
  WRITE_SHORT  (offset+8)  1746
  WRITE_SHORT  (offset+10) 855
  WRITE_SHORT  (offset+12) 1534
  WRITE_SHORT  (offset+14) 866[/b]
  SET "vert_num"="%vert_num%"+4
  WRITE_SHORT 0x80  "%vert_num%"

  SET "info_ext"=0x04*4
  PATCH_IF ("%actors_offset%">="%vert_offset%") BEGIN
 "actors_offset"="%actors_offset%"+"%info_ext%"
 WRITE_LONG  0x54 "%actors_offset%"
  END
  PATCH_IF ("%spawns_offset%">="%vert_offset%") BEGIN
 "spawns_offset"="%spawns_offset%"+"%info_ext%"
 WRITE_LONG  0x60  "%spawns_offset%"
  END
  PATCH_IF ("%entrances_offset%">="%vert_offset%") BEGIN
 "entrances_offset"="%entrances_offset%"+"%info_ext%"
 WRITE_LONG  0x68  "%entrances_offset%"
  END
  PATCH_IF ("%cont_offset%">="%vert_offset%") BEGIN
 "cont_offset"="%cont_offset%"+"%info_ext%"
 WRITE_LONG  0x70  "%cont_offset%"
  END
  PATCH_IF ("%items_offset%">="%vert_offset%") BEGIN
 "items_offset"="%items_offset%"+"%info_ext%"
 WRITE_LONG  0x78  "%items_offset%"
  END
  PATCH_IF ("%infotrig_offset%">="%vert_offset%") BEGIN
 "infotrig_offset"="%infotrig_offset%"+"%info_ext%"
 WRITE_LONG  0x5c  "%infotrig_offset%"
  END
  PATCH_IF ("%amb_offset%">="%vert_offset%") BEGIN
 "amb_offset"="%amb_offset%"+"%info_ext%"
 WRITE_LONG  0x84  "%amb_offset%"
  END
  PATCH_IF ("%vars_offset%">="%vert_offset%") BEGIN
 "vars_offset"="%vars_offset%"+"%info_ext%"
 WRITE_LONG  0x88  "%vars_offset%"
  END
  PATCH_IF ("%expbmp_offset%">="%vert_offset%") BEGIN
 "expbmp_offset"="%expbmp_offset%"+"%info_ext%"
 WRITE_LONG  0xa0  "%expbmp_offset%"
  END
  PATCH_IF ("%doors_offset%">="%vert_offset%") BEGIN
 "doors_offset"="%doors_offset%"+"%info_ext%"
 WRITE_LONG  0xa8  "%doors_offset%"
  END
  PATCH_IF ("%anim_offset%">="%vert_offset%") BEGIN
 "anim_offset"="%anim_offset%"+"%info_ext%"
 WRITE_LONG  0xb0  "%anim_offset%"
  END
  PATCH_IF ("%tiled_offset%">="%vert_offset%") BEGIN
 "tiled_offset"="%tiled_offset%"+"%info_ext%"
 WRITE_LONG  0xb8  "%tiled_offset%"
  END
  PATCH_IF ("%songs_offset%">="%vert_offset%") BEGIN
 "songs_offset"="%songs_offset%"+"%info_ext%"
 WRITE_LONG  0xbc  "%songs_offset%"
  END
  PATCH_IF ("%rest_spawns_offset%">="%vert_offset%") BEGIN
 "rest_spawns_offset"="%rest_spawns_offset%"+"%info_ext%"
 WRITE_LONG  0xc0  "%rest_spawns_offset%"
  END
  PATCH_IF ("%automap_offset%">="%vert_offset%") BEGIN
 "automap_offset"="%automap_offset%"+"%info_ext%"
 WRITE_LONG  0xc4  "%automap_offset%"
  END

//adding 1 new entrance
SET offset = ("%entrances_offset%"+0x68*"%entrances_num%")
[b]INSERT_BYTES offset 0x68
WRITE_ASCII  offset	  ~Exit7000~
WRITE_SHORT  (offset+0x20)  1626	 //X
WRITE_SHORT  (offset+0x22)  759	  //Y
WRITE_LONG   (offset+0x24)  "9"	  // facing[/b]
SET "entrances_num"="%entrances_num%"+1
WRITE_LONG 0x6c  "%entrances_num%"

SET "info_ext"=0x68
PATCH_IF ("%actors_offset%">="%entrances_offset%") BEGIN
  "actors_offset"="%actors_offset%"+"%info_ext%"
  WRITE_LONG  0x54 "%actors_offset%"
END
PATCH_IF ("%spawns_offset%">="%entrances_offset%") BEGIN
  "spawns_offset"="%spawns_offset%"+"%info_ext%"
  WRITE_LONG  0x60  "%spawns_offset%"
END
PATCH_IF ("%vert_offset%">="%entrances_offset%") BEGIN
  "vert_offset"="%vert_offset%"+"%info_ext%"
  WRITE_LONG  0x7c  "%vert_offset%"
END
PATCH_IF ("%cont_offset%">="%entrances_offset%") BEGIN
  "cont_offset"="%cont_offset%"+"%info_ext%"
  WRITE_LONG  0x70  "%cont_offset%"
END
PATCH_IF ("%items_offset%">="%entrances_offset%") BEGIN
  "items_offset"="%items_offset%"+"%info_ext%"
  WRITE_LONG  0x78  "%items_offset%"
END
PATCH_IF ("%infotrig_offset%">="%entrances_offset%") BEGIN
  "infotrig_offset"="%infotrig_offset%"+"%info_ext%"
  WRITE_LONG  0x5c  "%infotrig_offset%"
END
PATCH_IF ("%amb_offset%">="%entrances_offset%") BEGIN
  "amb_offset"="%amb_offset%"+"%info_ext%"
  WRITE_LONG  0x84  "%amb_offset%"
END
PATCH_IF ("%vars_offset%">="%entrances_offset%") BEGIN
  "vars_offset"="%vars_offset%"+"%info_ext%"
  WRITE_LONG  0x88  "%vars_offset%"
END
PATCH_IF ("%expbmp_offset%">="%entrances_offset%") BEGIN
  "expbmp_offset"="%expbmp_offset%"+"%info_ext%"
  WRITE_LONG  0xa0  "%expbmp_offset%"
END
PATCH_IF ("%doors_offset%">="%entrances_offset%") BEGIN
  "doors_offset"="%doors_offset%"+"%info_ext%"
  WRITE_LONG  0xa8  "%doors_offset%"
END
PATCH_IF ("%anim_offset%">="%entrances_offset%") BEGIN
  "anim_offset"="%anim_offset%"+"%info_ext%"
  WRITE_LONG  0xb0  "%anim_offset%"
END
PATCH_IF ("%tiled_offset%">="%entrances_offset%") BEGIN
  "tiled_offset"="%tiled_offset%"+"%info_ext%"
  WRITE_LONG  0xb8  "%tiled_offset%"
END
PATCH_IF ("%songs_offset%">="%entrances_offset%") BEGIN
  "songs_offset"="%songs_offset%"+"%info_ext%"
  WRITE_LONG  0xbc  "%songs_offset%"
END
PATCH_IF ("%rest_spawns_offset%">="%entrances_offset%") BEGIN
  "rest_spawns_offset"="%rest_spawns_offset%"+"%info_ext%"
  WRITE_LONG  0xc0  "%rest_spawns_offset%"
END
PATCH_IF ("%automap_offset%">="%entrances_offset%") BEGIN
  "automap_offset"="%automap_offset%"+"%info_ext%"
  WRITE_LONG  0xc4  "%automap_offset%"
END

BUT_ONLY_IF_IT_CHANGES  //********************************************************  ~AR0400.are~

Link to comment
I bolded what I guess would change if I was to use this on another mod with a different area.
Maybe my vision isn't so good these days, or the bolded text didn't transfer. I believe Red Carnelian may have code dealing with the same issue in his Stone of Askavar update (hosted on your own site :rant:).
Link to comment

If all you are doing is adding entrances and exits, then you don't need all of that. This is what I have used successfully to add entrances and exits to many different areas:-

 

//**************************************************
//Modify existing areas to accept new entrances and exits
//**************************************************
//Ceinwen's house

COPY_EXISTING ~ar0400.are~ ~override~
// We start by reading offsets and numbers
READ_SHORT 0x5a "trig_num"
READ_LONG  0x5c "trig_off"
READ_LONG  0x60 "spawn_off"
READ_LONG  0x68 "ent_off"
READ_SHORT 0x6c "ent_num"
READ_LONG  0x70 "cont_off"
READ_LONG  0x78 "item_off"
READ_LONG  0x7c "vert_off"
READ_SHORT 0x80 "vert_num"
READ_LONG  0x84 "amb_off"
READ_LONG  0x88 "var_off"
READ_LONG  0xa0 "bmp_off"
READ_LONG  0xa8 "door_off"
READ_LONG  0xb0 "anim_off"
READ_LONG  0xb8 "tiled_off"
READ_LONG  0xbc "song_off"
READ_LONG  0xc0 "rest_off"
READ_LONG  0xc4 "note_off"
// Add 4 vertices
INSERT_BYTES  ("%vert_off%" + ("%vert_num%" * 0x4)	  ) 0x10
  WRITE_SHORT ("%vert_off%" + ("%vert_num%" * 0x4)	  ) 2844
  WRITE_SHORT ("%vert_off%" + ("%vert_num%" * 0x4) + 0x2) 2963
  WRITE_SHORT ("%vert_off%" + ("%vert_num%" * 0x4) + 0x4) 2776
  WRITE_SHORT ("%vert_off%" + ("%vert_num%" * 0x4) + 0x6) 2998
  WRITE_SHORT ("%vert_off%" + ("%vert_num%" * 0x4) + 0x8) 2776
  WRITE_SHORT ("%vert_off%" + ("%vert_num%" * 0x4) + 0xa) 3050
  WRITE_SHORT ("%vert_off%" + ("%vert_num%" * 0x4) + 0xc) 2843
  WRITE_SHORT ("%vert_off%" + ("%vert_num%" * 0x4) + 0xe) 3021
// Now, we add a new entrance. Yippie!
INSERT_BYTES  ("%ent_off%" + ("%ent_num%" * 0x68)	   ) 0x68
  WRITE_ASCII ("%ent_off%" + ("%ent_num%" * 0x68)	   ) ~Exitys0310~   // Name of the new entrance
  WRITE_SHORT ("%ent_off%" + ("%ent_num%" * 0x68) + 0x20) 2889		  // Location: X
  WRITE_SHORT ("%ent_off%" + ("%ent_num%" * 0x68) + 0x22) 3038		  // Location: Y
  WRITE_SHORT ("%ent_off%" + ("%ent_num%" * 0x68) + 0x24) 12			// Directional facing
// First, we insert the new trigger by adding 196 bytes at a specific location in the file, then we patch it :)
INSERT_BYTES  ("%trig_off%" + ("%trig_num%" * 0xc4)	   ) 0xc4
  WRITE_ASCII ("%trig_off%" + ("%trig_num%" * 0xc4)	   ) ~Travys0310~   // Name of the new trigger
  WRITE_SHORT ("%trig_off%" + ("%trig_num%" * 0xc4) + 0x20) 0x02		 // Which trigger type? 2=travel
  WRITE_SHORT ("%trig_off%" + ("%trig_num%" * 0xc4) + 0x22) 2776		  // Bounding box = most westerly point...
  WRITE_SHORT ("%trig_off%" + ("%trig_num%" * 0xc4) + 0x24) 2963		  // Bounding box = most northerly point...
  WRITE_SHORT ("%trig_off%" + ("%trig_num%" * 0xc4) + 0x26) 2844		  // Bounding box = most easterly point...
  WRITE_SHORT ("%trig_off%" + ("%trig_num%" * 0xc4) + 0x28) 3050		  // Bounding box = most southerly point... (from the vertices list)
  WRITE_SHORT ("%trig_off%" + ("%trig_num%" * 0xc4) + 0x2a) 0x04		 // Number of vertices
  WRITE_LONG  ("%trig_off%" + ("%trig_num%" * 0xc4) + 0x2c) "%vert_num%" // First vertex index
  WRITE_LONG  ("%trig_off%" + ("%trig_num%" * 0xc4) + 0x34) 0x2a		 // Cursor index
  WRITE_ASCII ("%trig_off%" + ("%trig_num%" * 0xc4) + 0x38) ~ys0310~	 // Destination area
  WRITE_ASCII ("%trig_off%" + ("%trig_num%" * 0xc4) + 0x40) ~Exitar0400~   // Exit point in the destination area
  WRITE_LONG  ("%trig_off%" + ("%trig_num%" * 0xc4) + 0x60) 0x04		 // Flags
  SAY		 ("%trig_off%" + ("%trig_num%" * 0xc4) + 0x64) #-1		  // Trigger Text
// Code wrapup - need to adjust numbers of vertices and triggers and adjust offsets
WRITE_SHORT 0x80 ("%vert_num%" + 0x04) // Four new vertices
WRITE_SHORT 0x5a ("%trig_num%" + 0x01) // One new trigger
WRITE_SHORT 0x6c ("%ent_num%"  + 0x01) // One new entrance
// Remember that even if the offset-fields are listed in one certain order, the offsets aren't
SET "adj" = 0xc4
WRITE_LONG 0x60 ("%spawn_off%" + "%adj%")
WRITE_LONG 0x68 ("%ent_off%"   + "%adj%")
SET "adj" = (0xc4 + 0x68)
WRITE_LONG 0x70 ("%cont_off%"  + "%adj%")
WRITE_LONG 0x78 ("%item_off%"  + "%adj%")
WRITE_LONG 0x7c ("%vert_off%"  + "%adj%")
WRITE_LONG 0x84 ("%amb_off%"   + "%adj%")
WRITE_LONG 0x88 ("%var_off%"   + "%adj%")
WRITE_LONG 0xa8 ("%door_off%"  + "%adj%")
WRITE_LONG 0xb8 ("%tiled_off%" + "%adj%")
SET "adj" = (0xc4 + 0x68 + 0x10)
WRITE_LONG 0xa0 ("%bmp_off%"   + "%adj%")
WRITE_LONG 0xb0 ("%anim_off%"  + "%adj%")
WRITE_LONG 0xbc ("%song_off%"  + "%adj%")
WRITE_LONG 0xc0 ("%rest_off%"  + "%adj%")
WRITE_LONG  0xc4 ("%note_off%"  + "%adj%")
BUT_ONLY_IF_IT_CHANGES

 

This adds a simple four-point travel region and a single entrance.

 

-Y-

Link to comment

Those two blocks do the same three things :rant:

 

The second one has the disadvantage of assuming that the .are is structured in the usual order, which is not necessarily true.

 

The first doesn't, so it's a bit longer (though x = x + 1 should not be used as shorthand for SET x = x + 1 - it shouldn't lead to any ambiguity here, but it's still a bad habit :) )

Link to comment
The first doesn't, so it's a bit longer (though x = x + 1 should not be used as shorthand for SET x = x + 1 - it shouldn't lead to any ambiguity here, but it's still a bad habit :) )
What are you talking about? It's equivalent and should be considered the preferred usage IMO (actually, most preferable would be x += 0x1).

 

You only need SET in two instances (the first patch in a TP action and after evil patches like SAY and PATCH_PRINT). Don't use it anywhere else; you will be considered l33t.

Link to comment

Yes, but you need to use SET after "evil" patches, and you never need to not use it.

 

I'm a fan of += notation also, but it's only usable in patches, not actions.

 

Not going to recommend shortcuts without a list of where they're inapplicable, especially when people in general aren't even using NO_IF_EVAL_BUG and haven't read the process_patch vs process_patch2 tutorial because it doesn't exist :rant:

Link to comment

In Yovaneth's example, which I would use as a template for adding entrances and exits in my mod, where do you get the numbers for:

 

INSERT_BYTES ("%vert_off%" + ("%vert_num%" * 0x4) ) 0x10

WRITE_SHORT ("%vert_off%" + ("%vert_num%" * 0x4) ) 2844

WRITE_SHORT ("%vert_off%" + ("%vert_num%" * 0x4) + 0x2) 2963

WRITE_SHORT ("%vert_off%" + ("%vert_num%" * 0x4) + 0x4) 2776

WRITE_SHORT ("%vert_off%" + ("%vert_num%" * 0x4) + 0x6) 2998

WRITE_SHORT ("%vert_off%" + ("%vert_num%" * 0x4) + 0x8) 2776

WRITE_SHORT ("%vert_off%" + ("%vert_num%" * 0x4) + 0xa) 3050

WRITE_SHORT ("%vert_off%" + ("%vert_num%" * 0x4) + 0xc) 2843

WRITE_SHORT ("%vert_off%" + ("%vert_num%" * 0x4) + 0xe) 3021

 

entrance

WRITE_SHORT ("%ent_off%" + ("%ent_num%" * 0x68) + 0x20) 2889

WRITE_SHORT ("%ent_off%" + ("%ent_num%" * 0x68) + 0x22) 3038

WRITE_SHORT ("%ent_off%" + ("%ent_num%" * 0x68) + 0x24) 12

 

and so on. I would guess those numbers change when you make your own entrance and exit?

Link to comment

The line

 

WRITE_SHORT ("%ent_off%" + ("%ent_num%" * 0x68) + 0x24) 12

 

is the direction you want the party to face when they enter the area. In this case 12=East, where 0=South, 1=South-SouthWest, 2=SouthWest, 3=West-SouthWest etc.

 

-Y-

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...