Jump to content

New door at the area


tipun

Recommended Posts

New door at the area. I replaced the ship on the Waukeen Promenade with a ship from IWD2. Made it like a door. Everything works fine in the game. But Near Infinity now shows an error when trying to open a wed file.
Although I even manually checked all the offsets. Maybe you missed something?
Or maybe you can tell me somewhere I can find functions for editing wed files.

 

The code I used to edit the wed files:

Spoiler
DEFINE_PATCH_FUNCTION FC_GET_XY_COORDINATE
	INT_VAR num = 0
	RET     x1 y1
BEGIN
	y1 = ( num >> 16 )
	x1 = num - ( y1 << 16 )
END

DEFINE_PATCH_FUNCTION ZZ_ADD_WED_DOOR
	INT_VAR
		is_door = 1
		//tile_0, tile_1 etc. (lookup tiles)
		poly_opened_cnt = 0
		poly_closed_cnt = 0
		//	1, flags_2 etc. ( Count = poly_opened_cnt + poly_closed_cnt )
		//vertex_cnt_1, vertex_cnt_2 etc. ( Count = poly_opened_cnt + poly_closed_cnt )
		//vertex_1, vertex_2 etc.
		LastTile = 0
		Count = 0
		overlay_idx = 0
	STR_VAR
		name = ""
	RET
BEGIN
	PATCH_IF ( is_door > 1 ) OR ( is_door < 0 ) BEGIN SET is_door = 1 END
	LPM ZZ_READ_WED_OFFSETS
	LPM ZZ_CREATE_DOOR_Z
	LPM ZZ_CREATE_DOOR
END

DEFINE_PATCH_FUNCTION ZZ_GET_POLY_MINMAX_COORDS
	STR_VAR
		str = ""
	RET
		minX maxX minY maxY
BEGIN
	SET minX = 10000 SET maxX = 0 SET minY = 10000 SET maxY = 0
	SET lng = STRING_LENGTH ~%str%~
	FOR ( j = 0 ; j < lng ; j = j + 4 ) BEGIN
		INNER_PATCH_SAVE str ~%str%~ BEGIN
			READ_SHORT 0x00 + j mnXi
			READ_SHORT 0x02 + j mnYi
		END
		PATCH_IF ( mnXi <= minX ) BEGIN SET minX = mnXi END
		PATCH_IF ( mnXi >= maxX ) BEGIN SET maxX = mnXi END
		PATCH_IF ( mnYi <= minY ) BEGIN SET minY = mnYi END
		PATCH_IF ( mnYi >= maxY ) BEGIN SET maxY = mnYi END
	END
END

DEFINE_PATCH_MACRO ZZ_READ_WED_OFFSETS BEGIN
	READ_LONG 0x08 overlay_num
	READ_LONG 0x0c doors_num
	READ_LONG 0x10 overlay_off
	READ_LONG 0x14 sec_header_off
	READ_LONG 0x18 doors_off
	READ_LONG 0x1c door_tmap_lkup_off
	READ_LONG sec_header_off + 0x0c wall_group_off
	READ_LONG sec_header_off + 0x00 wall_poly_num
	READ_LONG sec_header_off + 0x04 wall_poly_off
	READ_LONG doors_off + 0x12 door_poly_off
	READ_LONG overlay_off + 0x10 tilemap_offset
	READ_LONG overlay_off + 0x14 tilemap_lookup_offset
	SET door_poly_num = 0
	SET vertex_door_num = 0
	SET tmap_lkp = 0
	FOR ( i = 0 ; i < doors_num ; ++i ) BEGIN
		READ_SHORT doors_off + i * 0x1a + 0x0e door_poly_open
		READ_SHORT doors_off + i * 0x1a + 0x10 door_poly_closed
		SET door_poly_all = door_poly_open + door_poly_closed
		SET door_poly_num = door_poly_num + door_poly_open + door_poly_closed
		SET ddr_off = doors_off + i * 0x1a
		READ_LONG ddr_off + 0x12 offs
		FOR ( j = 0 ; j < door_poly_all ; ++j ) BEGIN
			READ_LONG offs + j * 0x12 + 0x04 vtx
			SET vertex_door_num = vertex_door_num + vtx
		END
		READ_SHORT doors_off + i * 0x1a + 0x0a tml
		READ_SHORT doors_off + i * 0x1a + 0x0c tmz
		SET tmap_lkp = tml + tmz
	END
	READ_LONG sec_header_off + 0x10 wall_poly_lkup_off
	READ_LONG sec_header_off + 0x08 vertex_wall_off
	READ_LONG door_poly_off + 0x00 vertex_wall_num
	SET vertex_door_off = vertex_wall_off + vertex_wall_num * 0x04
END

DEFINE_PATCH_MACRO ZZ_CREATE_DOOR BEGIN
	SET length_first = 0x1a
	SET len = STRING_LENGTH ~%door_tmap_lkup%~
	SET length_second = length_first + len
	SET len = STRING_LENGTH ~%polygons%~
	SET length_third = length_second + len
	SET length_vertex = STRING_LENGTH ~%vert%~
	//vertex
	SET offset = ~%SOURCE_SIZE%~
	INSERT_BYTES offset length_vertex
	WRITE_EVALUATED_ASCII offset ~%vert%~ ( length_vertex )
	WRITE_LONG sec_header_off + 0x08 vertex_wall_off + length_third
	//wall_poly_lkup
	WRITE_LONG sec_header_off + 0x10 wall_poly_lkup_off + length_third
	//door polygons
	SET offset = wall_poly_lkup_off
	SET len = STRING_LENGTH ~%polygons%~
	INSERT_BYTES offset len
	WRITE_EVALUATED_ASCII offset ~%polygons%~ ( len )
	SET poly_offs = offset + length_second
	//Walls
	WRITE_LONG sec_header_off + 0x04 wall_poly_off + length_second
	//Wall groups
	WRITE_LONG sec_header_off + 0x0c wall_group_off + length_second
	//Tilemap lookup
	FOR ( i = 0 ; i < overlay_num ; ++i ) BEGIN
		READ_LONG overlay_off + i * 0x18 + 0x14 tmap_lookup
		WRITE_LONG overlay_off + i * 0x18 + 0x14 tmap_lookup + length_second
	END
	//door_tilemap_lookup
	SET door_tilemap_lookup = tilemap_lookup_offset
	SET len = STRING_LENGTH ~%door_tmap_lkup%~
	INSERT_BYTES door_tilemap_lookup len
	WRITE_EVALUATED_ASCII door_tilemap_lookup ~%door_tmap_lkup%~ ( len )
	WRITE_LONG 0x1c door_tmap_lkup_off + length_first
	//Overlay tilemap
	FOR ( i = 0 ; i < overlay_num ; ++i ) BEGIN
		READ_LONG overlay_off + i * 0x18 + 0x10 tmap_offset
		WRITE_LONG overlay_off + i * 0x18 + 0x10 tmap_offset + length_first
	END
	//door
	SET door_off = tilemap_offset
	INSERT_BYTES door_off length_first
	WRITE_EVALUATED_ASCII door_off ~%new_door%~ ( length_first )
	WRITE_LONG door_off + 0x12 poly_offs
	WRITE_LONG door_off + 0x16 poly_offs + poly_opened_cnt * 0x12
	WRITE_LONG 0x0c doors_num + 1
END

DEFINE_PATCH_MACRO ZZ_CREATE_DOOR_Z BEGIN
	//overlay
	SPRINT door_tmap_lkup ~~
	PATCH_IF ( VARIABLE_IS_SET $tile(0) ) BEGIN
		PATCH_IF ( overlay_idx >= overlay_num ) BEGIN SET overlay_idx = overlay_num - 1 END
		PATCH_IF ( overlay_idx < 0 ) BEGIN SET overlay_idx = 0 END
		SET door_tmap_lkup_size = 0
		FOR ( i = 0 ; i < 65536 ; ++i ) BEGIN
			PATCH_IF ( VARIABLE_IS_SET $tile(~%i%~) ) BEGIN
				SET cls_tile = LastTile + i
				SET cur_tile = $tile(~%i%~)
				READ_LONG overlay_off + overlay_idx * 0x18 + 0x10 tiled_object_offset
				WRITE_SHORT tiled_object_offset + cur_tile * 0x0a + 0x04 cls_tile
				INNER_PATCH_SAVE door_tmap_lkup ~%door_tmap_lkup%~ BEGIN
					INSERT_BYTES door_tmap_lkup_size 2
					WRITE_SHORT  door_tmap_lkup_size cur_tile
					SET door_tmap_lkup_size = door_tmap_lkup_size + 2
				END
			END ELSE BEGIN SET i = 65536 END
		END
	END
	//vertex
	SPRINT vert ~~
	SET vtxnum = 0
	PATCH_IF ( VARIABLE_IS_SET $vertex(0) ) BEGIN
		FOR ( i = 0 ; i < 65536 ; ++i ) BEGIN
			PATCH_IF ( VARIABLE_IS_SET $vertex(~%i%~) ) BEGIN
				INNER_PATCH_SAVE vert ~%vert%~ BEGIN
					INSERT_BYTES i * 0x04 0x04
					SET vvx = $vertex(~%i%~)
					WRITE_LONG   i * 0x04 vvx
					SET vtxnum = vtxnum + 1
				END
			END ELSE BEGIN SET i = 65536 END
		END
	END
	//polygon
	SPRINT polygons ~~
	SET vtx = vertex_wall_num + vertex_door_num
	SET vn = 0
	SET poly_num = 0
	PATCH_IF ( VARIABLE_IS_SET $vertex_cnt(0) ) BEGIN
		FOR ( i = 0 ; i < 65536 ; ++i ) BEGIN
			PATCH_IF ( VARIABLE_IS_SET $vertex_cnt(~%i%~) ) BEGIN
				SPRINT polygon ~~
				INNER_PATCH_SAVE polygon ~%polygon%~ BEGIN
					INSERT_BYTES 0x00 0x12
					WRITE_LONG 0x00 vtx
					SET nvtx = $vertex_cnt(~%i%~)
					WRITE_LONG 0x04 nvtx
					SET vtx = vtx + nvtx
					PATCH_IF ( VARIABLE_IS_SET $flags(~%i%~) ) BEGIN SET flg = $flags(~%i%~) END ELSE BEGIN SET flg = 0 END
					WRITE_BYTE 0x08 flg
					WRITE_BYTE 0x09 0xff
					SET zn = nvtx * 4
					INNER_PATCH_SAVE vert ~%vert%~ BEGIN
						READ_ASCII vn * 0x04 abs ( zn )
					END
					LPF ZZ_GET_POLY_MINMAX_COORDS STR_VAR str = EVAL ~%abs%~ RET minX maxX minY maxY END
					SET vn = vn + nvtx
					WRITE_SHORT 0x0a minX
					WRITE_SHORT 0x0c maxX
					WRITE_SHORT 0x0e minY
					WRITE_SHORT 0x10 maxY
				END
				SPRINT polygons ~%polygons%%polygon%~
				SET poly_num = poly_num + 1
			END ELSE BEGIN SET i = 65536 END
		END
	END
	//door
	SPRINT new_door ~~
	INNER_PATCH_SAVE new_door ~%new_door%~ BEGIN
		INSERT_BYTES 0x00 0x1a
		WRITE_EVALUATED_ASCII 0x00 ~%name%~ ( 8 )
		WRITE_SHORT 0x08 is_door
		WRITE_SHORT 0x0a tmap_lkp
		WRITE_SHORT 0x0c door_tmap_lkup_size / 2
		WRITE_SHORT 0x0e poly_opened_cnt
		WRITE_SHORT 0x10 poly_closed_cnt
	END
END

 

 

Image0001.jpg

Edited by tipun
Link to comment

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...