Thread: OSRS Texture Support

Page 1 of 3 123 LastLast
Results 1 to 10 of 26
  1. #1 OSRS Texture Support 
    Registered Member
    Deku's Avatar
    Join Date
    May 2016
    Posts
    136
    Thanks given
    32
    Thanks received
    70
    Rep Power
    100
    Implemented this from a 130 deob, there's a small anti-leech. Good luck





    Code:
    package com;
    
    public class Model extends Renderable {
    
    	public static void nullLoader() {
    		header = null;
    		aBooleanArray1663 = null;
    		aBooleanArray1664 = null;
    		vertex_viewpoint_y = null;
    		anIntArray1667 = null;
    		texture_viewpoint_x = null;
    		texture_viewpoint_y = null;
    		texture_viewpoint_z = null;
    		anIntArray1671 = null;
    		anIntArrayArray1672 = null;
    		anIntArray1673 = null;
    		anIntArrayArray1674 = null;
    		anIntArray1675 = null;
    		anIntArray1676 = null;
    		anIntArray1677 = null;
    		SINE = null;
    		COSINE = null;
    		modelIntArray3 = null;
    		modelIntArray4 = null;
    	}
    	
    	public void decode_old(byte[] data, int modelId) {
    		boolean has_face_type = false;
    		boolean has_texture_type = false;
    		Buffer stream = new Buffer(data);
    		Buffer stream1 = new Buffer(data);
    		Buffer stream2 = new Buffer(data);
    		Buffer stream3 = new Buffer(data);
    		Buffer stream4 = new Buffer(data);
    		stream.currentPosition = data.length - 18;
    		vertices = stream.readUShort();
    		faces = stream.readUShort();
    		texture_faces = stream.readUnsignedByte();
    		int type_opcode = stream.readUnsignedByte();
    		int priority_opcode = stream.readUnsignedByte();
    		int alpha_opcode = stream.readUnsignedByte();
    		int tSkin_opcode = stream.readUnsignedByte();
    		int vSkin_opcode = stream.readUnsignedByte();
    		int i_254_ = stream.readUShort();
    		int i_255_ = stream.readUShort();
    		int i_256_ = stream.readUShort();
    		int i_257_ = stream.readUShort();
    		int i_258_ = 0;
    		
    		int i_259_ = i_258_;
    		i_258_ += vertices;
    		
    		int i_260_ = i_258_;
    		i_258_ += faces;
    		
    		int i_261_ = i_258_;
    		if (priority_opcode == 255)
    			i_258_ += faces;
    		
    		int i_262_ = i_258_;
    		if (tSkin_opcode == 1)
    			i_258_ += faces;
    		
    		int i_263_ = i_258_;
    		if (type_opcode == 1)
    			i_258_ += faces;
    		
    		int i_264_ = i_258_;
    		if (vSkin_opcode == 1)
    			i_258_ += vertices;
    		
    		int i_265_ = i_258_;
    		if (alpha_opcode == 1)
    			i_258_ += faces;
    		
    		int i_266_ = i_258_;
    		i_258_ += i_257_;
    		
    		int i_267_ = i_258_;
    		i_258_ += faces * 2;
    		
    		int i_268_ = i_258_;
    		i_258_ += texture_faces * 6;
    		
    		int i_269_ = i_258_;
    		i_258_ += i_254_;
    		
    		int i_270_ = i_258_;
    		i_258_ += i_255_;
    		
    		int i_271_ = i_258_;
    		i_258_ += i_256_;
    		
    		particle_vertices = new int[vertices];
    		vertexX = new int[vertices];
    		vertexY = new int[vertices];
    		vertexZ = new int[vertices];
    		edge_a = new int[faces];
    		edge_b = new int[faces];
    		edge_c = new int[faces];
    		if (texture_faces > 0) {
    			texture_type = new byte[texture_faces];
    			texture_edge_a = new short[texture_faces];
    			texture_edge_b = new short[texture_faces];
    			texture_edge_c = new short[texture_faces];
    		}
    		
    		if (vSkin_opcode == 1)
    			vSkin = new int[vertices];
    		
    		if (type_opcode == 1) {
    			render_type = new int[faces];
    			texture_coordinates = new byte[faces];
    			texture = new short[faces];
    		}
    		
    		if (priority_opcode == 255)
    			render_priorities = new byte[faces];
    		else
    			priority = (byte) priority_opcode;
    		
    		if (alpha_opcode == 1)
    			alpha = new int[faces];
    		
    		if (tSkin_opcode == 1)
    			tSkin = new int[faces];
    		
    		color = new short[faces];
    		stream.currentPosition = i_259_;
    		stream1.currentPosition = i_269_;
    		stream2.currentPosition = i_270_;
    		stream3.currentPosition = i_271_;
    		stream4.currentPosition = i_264_;
    		int start_x = 0;
    		int start_y = 0;
    		int start_z = 0;
    		for (int point = 0; point < vertices; point++) {
    			int flag = stream.readUnsignedByte();
    			int x = 0;
    			if ((flag & 0x1) != 0)
    				x = stream1.readSmart();
    			int y = 0;
    			if ((flag & 0x2) != 0)
    				y = stream2.readSmart();
    			int z = 0;
    			if ((flag & 0x4) != 0)
    				z = stream3.readSmart();
    			
    			vertexX[point] = start_x + x;
    			vertexY[point] = start_y + y;
    			vertexZ[point] = start_z + z;
    			start_x = vertexX[point];
    			start_y = vertexY[point];
    			start_z = vertexZ[point];
    			if (vSkin_opcode == 1)
    				vSkin[point] = stream4.readUnsignedByte();
    			
    		}
    		stream.currentPosition = i_267_;
    		stream1.currentPosition = i_263_;
    		stream2.currentPosition = i_261_;
    		stream3.currentPosition = i_265_;
    		stream4.currentPosition = i_262_;
    		for (int face = 0; face < faces; face++) {
    			color[face] = (short) stream.readUShort();
    			if (type_opcode == 1) {
    				int flag = stream1.readUnsignedByte();
    				if ((flag & 0x1) == 1) {
    					render_type[face] = 1;
    					has_face_type = true;
    				} else {
    					render_type[face] = 0;
    				}
    				
    				if ((flag & 0x2) != 0) {
    					texture_coordinates[face] = (byte) (flag >> 2);
    					texture[face] = color[face];
    					color[face] = 127;
    					if (texture[face] != -1)
    						has_texture_type = true;
    					
    					if(texture[face] == 53) //frozen whip 
    						texture[face] = 1;
    					else
    					if(texture[face] == 56) //lava dragon 
    						texture[face] = 41;
    					else
    					if(texture[face] > 51) 
    						texture[face] = 1;
    					
    				} else {
    					texture_coordinates[face] = -1;
    					texture[face] =  -1;
    				}
    			}
    			if (priority_opcode == 255)
    				render_priorities[face] = stream2.readSignedByte();
    			
    			if (alpha_opcode == 1) {
    				alpha[face] = stream3.readSignedByte();
    			}
    			if (tSkin_opcode == 1)
    				tSkin[face] = stream4.readUnsignedByte();
    				
    		}
    		stream.currentPosition = i_266_;
    		stream1.currentPosition = i_260_;
    		int coordinate_a = 0;
    		int coordinate_b = 0;
    		int coordinate_c = 0;
    		int offset = 0;
    		int coordinate;
    		for (int face = 0; face < faces; face++) {
    			int opcode = stream1.readUnsignedByte();
    			if (opcode == 1) {
    				coordinate_a = (stream.readSmart() + offset);
    				offset = coordinate_a;
    				coordinate_b = (stream.readSmart() + offset);
    				offset = coordinate_b;
    				coordinate_c = (stream.readSmart() + offset);
    				offset = coordinate_c;
    				edge_a[face] = coordinate_a;
    				edge_b[face] = coordinate_b;
    				edge_c[face] = coordinate_c;
    			}
    			if (opcode == 2) {
    				coordinate_b = coordinate_c;
    				coordinate_c = (stream.readSmart() + offset);
    				offset = coordinate_c;
    				edge_a[face] = coordinate_a;
    				edge_b[face] = coordinate_b;
    				edge_c[face] = coordinate_c;
    			}
    			if (opcode == 3) {
    				coordinate_a = coordinate_c;
    				coordinate_c = (stream.readSmart() + offset);
    				offset = coordinate_c;
    				edge_a[face] = coordinate_a;
    				edge_b[face] = coordinate_b;
    				edge_c[face] = coordinate_c;
    			}
    			if (opcode == 4) {
    				coordinate = coordinate_a;
    				coordinate_a = coordinate_b;
    				coordinate_b = coordinate;
    				coordinate_c = (stream.readSmart() + offset);
    				offset = coordinate_c;
    				edge_a[face] = coordinate_a;
    				edge_b[face] = coordinate_b;
    				edge_c[face] = coordinate_c;
    			}
    		}
    		stream.currentPosition = i_268_;
    		for (int face = 0; face < texture_faces; face++) {
    			texture_type[face] = 0;
    			texture_edge_a[face] = (short) stream.readUShort();
    			texture_edge_b[face] = (short) stream.readUShort();
    			texture_edge_c[face] = (short) stream.readUShort();
    		}
    		if (texture_coordinates != null) {
    			boolean textured = false;
    			for (int face = 0; face < faces; face++) {
    				coordinate = texture_coordinates[face] & 0xff;
    				if (coordinate != 255) {
    					if (((texture_edge_a[coordinate] & 0xffff) == edge_a[face]) && ((texture_edge_b[coordinate] & 0xffff)  == edge_b[face]) && ((texture_edge_c[coordinate] & 0xffff) == edge_c[face])) {
    						texture_coordinates[face] = -1;
    					} else {
    						textured = true;
    					}
    				}
    			}
    			if (!textured)
    				texture_coordinates = null;
    		}
    		if (!has_texture_type)
    			texture = null;
    			
    		if (!has_face_type)
    			render_type = null;
    	}
    
    	public void decode_new(byte data[], int modelId) {
    		Buffer nc1 = new Buffer(data);
    		Buffer nc2 = new Buffer(data);
    		Buffer nc3 = new Buffer(data);
    		Buffer nc4 = new Buffer(data);
    		Buffer nc5 = new Buffer(data);
    		Buffer nc6 = new Buffer(data);
    		Buffer nc7 = new Buffer(data);
    		nc1.currentPosition = data.length - 23;
    		vertices = nc1.readUShort();
    		faces = nc1.readUShort();
    		texture_faces = nc1.readUnsignedByte();
    		int flags = nc1.readUnsignedByte();
    		int priority_opcode = nc1.readUnsignedByte();
    		int alpha_opcode = nc1.readUnsignedByte();
    		int tSkin_opcode = nc1.readUnsignedByte();
    		int texture_opcode = nc1.readUnsignedByte();
    		int vSkin_opcode = nc1.readUnsignedByte();
    		int j3 = nc1.readUShort();
    		int k3 = nc1.readUShort();
    		int l3 = nc1.readUShort();
    		int i4 = nc1.readUShort();
    		int j4 = nc1.readUShort();
    		int texture_id = 0;
    		int texture_ = 0;
    		int texture__ = 0;
    		int face;
    		color = new short[faces];
    		if (texture_faces > 0) {
    			texture_type = new byte[texture_faces];
    			nc1.currentPosition = 0;
    			for (face = 0; face < texture_faces; face++) {
    				byte opcode = texture_type[face] = nc1.readSignedByte();
    				if (opcode == 0) {
    					texture_id++;
    				}
    				
    				if (opcode >= 1 && opcode <= 3) {
    					texture_++;
    					//output is 1
    				}
    				if (opcode == 2) {
    					texture__++;
    					//no output
    				}
    			}
    		}
    		int pos;
    		pos = texture_faces;// + vertices;
    		int vertexMod_offset = pos;
    		pos += vertices;
    		
    		int drawTypeBasePos = pos;
    		if (flags == 1)
    			pos += faces;
    		
    		int faceMeshLink_offset = pos;
    		pos += faces;
    		
    		int facePriorityBasePos = pos;
    		if (priority_opcode == 255)
    			pos += faces;
    		
    		int tSkinBasePos = pos;
    		if (tSkin_opcode == 1)
    			pos += faces;
    		
    		int vSkinBasePos = pos;
    		if (vSkin_opcode == 1)
    			pos += vertices;
    		
    		int alphaBasePos = pos;
    		if (alpha_opcode == 1)
    			pos += faces;
    		
    		int faceVPoint_offset = pos;
    		pos += i4;
    		
    		int textureIdBasePos = pos;
    		if (texture_opcode == 1)
    			pos += faces * 2;
    		
    		int textureBasePos = pos;
    		pos += j4;
    		
    		int color_offset = pos;
    		pos += faces * 2;
    		
    		int vertexX_offset = pos;
    		pos += j3;
    		
    		int vertexY_offset = pos;
    		pos += k3;
    		
    		int vertexZ_offset = pos;
    		pos += l3;
    		
    		int mainBuffer_offset = pos;
    		pos += texture_id * 6;
    		
    		int firstBuffer_offset = pos;
    		pos += texture_ * 6;
    		
    		int secondBuffer_offset = pos;
    		pos += texture_ * 6;
    		
    		int thirdBuffer_offset = pos;
    		pos += texture_ * 2;
    		
    		int fourthBuffer_offset = pos;
    		pos += texture_;
    		
    		int fifthBuffer_offset = pos;
    		pos += texture_ * 2 + texture__ * 2;
    		
    		particle_vertices = new int[vertices];
    		vertexX = new int[vertices];
    		vertexY = new int[vertices];
    		vertexZ = new int[vertices];
    		edge_a = new int[faces];
    		edge_b = new int[faces];
    		edge_c = new int[faces];
    		if (vSkin_opcode == 1)
    			vSkin = new int[vertices];
    		
    		if (flags == 1)
    			render_type = new int[faces];
    
    		if (priority_opcode == 255)
    			render_priorities = new byte[faces];
    		else 
    			priority = (byte) priority_opcode;
    		
    		if (alpha_opcode == 1)
    			alpha = new int[faces];
    		
    		if (tSkin_opcode == 1)
    			tSkin = new int[faces];
    		
    		if (texture_opcode == 1)
    			texture = new short[faces];
    		
    		if (texture_opcode == 1 && texture_faces > 0)
    			texture_coordinates = new byte[faces];
    		
    		if (texture_faces > 0) {
    			texture_edge_a = new short[texture_faces];
    			texture_edge_b = new short[texture_faces];
    			texture_edge_c = new short[texture_faces];
    		}
    		nc1.currentPosition = vertexMod_offset;
    		nc2.currentPosition = vertexX_offset;
    		nc3.currentPosition = vertexY_offset;
    		nc4.currentPosition = vertexZ_offset;
    		nc5.currentPosition = vSkinBasePos;
    		int start_x = 0;
    		int start_y = 0;
    		int start_z = 0;
    		for (int point = 0; point < vertices; point++) {
    			int flag = nc1.readUnsignedByte();
    			int x = 0;
    			if ((flag & 1) != 0) {
    				x = nc2.readSmart();
    			}
    			int y = 0;
    			if ((flag & 2) != 0) {
    				y = nc3.readSmart();
    				
    			}
    			int z = 0;
    			if ((flag & 4) != 0) {
    				z = nc4.readSmart();
    			}
    			vertexX[point] = start_x + x;
    			vertexY[point] = start_y + y;
    			vertexZ[point] = start_z + z;
    			start_x = vertexX[point];
    			start_y = vertexY[point];
    			start_z = vertexZ[point];
    			if (vSkin != null)
    				vSkin[point] = nc5.readUnsignedByte();
    			
    		}
    		nc1.currentPosition = color_offset;
    		nc2.currentPosition = drawTypeBasePos;
    		nc3.currentPosition = facePriorityBasePos;
    		nc4.currentPosition = alphaBasePos;
    		nc5.currentPosition = tSkinBasePos;
    		nc6.currentPosition = textureIdBasePos;
    		nc7.currentPosition = textureBasePos;
    		for (face = 0; face < faces; face++) {
    			color[face] = (short) nc1.readUShort();
    			if (flags == 1) {
    				render_type[face] = nc2.readSignedByte();
    			}
    			if (priority_opcode == 255) {
    				render_priorities[face] = nc3.readSignedByte();
    			}
    			if (alpha_opcode == 1) {
    				alpha[face] = nc4.readSignedByte();
    				if (alpha[face] < 0)
    					alpha[face] = (256 + alpha[face]);
    				
    			}
    			if (tSkin_opcode == 1)
    				tSkin[face] = nc5.readUnsignedByte();
    			
    			if (texture_opcode == 1) {
    				texture[face] = (short) (nc6.readUShort() - 1);
    				
    				if(texture[face] == 53) //frozen whip 
    					texture[face] = 1;
    				else
    				if(texture[face] == 56) //lava dragon 
    					texture[face] = 41;
    				else
    				if(texture[face] > 51) 
    					texture[face] = 1;
    			}
    			if (texture_coordinates != null && texture[face] != -1) {
    				texture_coordinates[face] = (byte) (nc7.readUnsignedByte() - 1);
    			}
    		}
    		nc1.currentPosition = faceVPoint_offset;
    		nc2.currentPosition = faceMeshLink_offset;
    		int coordinate_a = 0;
    		int coordinate_b = 0;
    		int coordinate_c = 0;
    		int last_coordinate = 0;
    		for (face = 0; face < faces; face++) {
    			int opcode = nc2.readUnsignedByte();
    			if (opcode == 1) {
    				coordinate_a = nc1.readSmart() + last_coordinate;
    				last_coordinate = coordinate_a;
    				coordinate_b = nc1.readSmart() + last_coordinate;
    				last_coordinate = coordinate_b;
    				coordinate_c = nc1.readSmart() + last_coordinate;
    				last_coordinate = coordinate_c;
    				edge_a[face] = coordinate_a;
    				edge_b[face] = coordinate_b;
    				edge_c[face] = coordinate_c;
    			}
    			if (opcode == 2) {
    				coordinate_b = coordinate_c;
    				coordinate_c = nc1.readSmart() + last_coordinate;
    				last_coordinate = coordinate_c;
    				edge_a[face] = coordinate_a;
    				edge_b[face] = coordinate_b;
    				edge_c[face] = coordinate_c;
    			}
    			if (opcode == 3) {
    				coordinate_a = coordinate_c;
    				coordinate_c = nc1.readSmart() + last_coordinate;
    				last_coordinate = coordinate_c;
    				edge_a[face] = coordinate_a;
    				edge_b[face] = coordinate_b;
    				edge_c[face] = coordinate_c;
    			}
    			if (opcode == 4) {
    				int l14 = coordinate_a;
    				coordinate_a = coordinate_b;
    				coordinate_b = l14;
    				coordinate_c = nc1.readSmart() + last_coordinate;
    				last_coordinate = coordinate_c;
    				edge_a[face] = coordinate_a;
    				edge_b[face] = coordinate_b;
    				edge_c[face] = coordinate_c;
    			}
    		}
    		nc1.currentPosition = mainBuffer_offset;
    		nc2.currentPosition = firstBuffer_offset;
    		nc3.currentPosition = secondBuffer_offset;
    		nc4.currentPosition = thirdBuffer_offset;
    		nc5.currentPosition = fourthBuffer_offset;
    		nc6.currentPosition = fifthBuffer_offset;
    		for (face = 0; face < texture_faces; face++) {
    			int opcode = texture_type[face] & 0xff;
    			if (opcode == 0) {
    				texture_edge_a[face] = (short) nc1.readUShort();
    				texture_edge_b[face] = (short) nc1.readUShort();
    				texture_edge_c[face] = (short) nc1.readUShort();
    			}
    			if (opcode == 1) {
    				texture_edge_a[face] = (short) nc2.readUShort();
    				texture_edge_b[face] = (short) nc2.readUShort();
    				texture_edge_c[face] = (short) nc2.readUShort();
    			}
    			if (opcode == 2) {
    				texture_edge_a[face] = (short) nc2.readUShort();
    				texture_edge_b[face] = (short) nc2.readUShort();
    				texture_edge_c[face] = (short) nc2.readUShort();
    			}
    			if (opcode == 3) {
    				texture_edge_a[face] = (short) nc2.readUShort();
    				texture_edge_b[face] = (short) nc2.readUShort();
    				texture_edge_c[face] = (short) nc2.readUShort();
    			}
    		}
    		nc1.currentPosition = pos;
    		face = nc1.readUnsignedByte();
    	}
    
    	public Model(int modelId) {
    		byte[] data = header[modelId].aByteArray368;
    		if (data[data.length - 1] == -1 && data[data.length - 2] == -1) {
    			decode_new(data, modelId);
    		} else {
    			decode_old(data, modelId);
    			//readOldModel(modelId);
    		}
    		int[][] attachments = ParticleAttachment.getAttachments(modelId);
    		if (attachments != null) {
    			for (int point = 0; point < attachments.length; point++) {
    				int[] attach = attachments[point];
    				if (attach[0] == -1) {
    					for (int z = 0; z < edge_a.length; z++)
    						particle_vertices[edge_a[z]] = attach[1] + 1;
    				} else if (attach[0] == -2) {
    					for (int z = 0; z < edge_b.length; z++)
    						particle_vertices[edge_b[z]] = attach[1] + 1;
    				} else if (attach[0] == -3) {
    					for (int z = 0; z < edge_c.length; z++)
    						particle_vertices[edge_c[z]] = attach[1] + 1;
    				} else if (attach[0] == -4) {
    					for (int z = 0; z < edge_a.length; z++)
    						particle_vertices[edge_a[z]] = attach[1] + 1;
    					for (int z = 0; z < edge_b.length; z++)
    						particle_vertices[edge_b[z]] = attach[1] + 1;
    					for (int z = 0; z < edge_c.length; z++)
    						particle_vertices[edge_c[z]] = attach[1] + 1;
    				} else {
    					particle_vertices[attach[0]] = attach[1] + 1;
    				}
    			}
    		}
    	}
    
    	/*private void readOldModel(int i) {
    		int j = -870;//dead?
    		aBoolean1618 = true;//dead
    		
    		fits_on_single_square = false;
    		anInt1620++;
    		
    		ModelHeader def = header[i];
    		vertices = def.anInt369;
    		faces = def.anInt370;
    		texture_faces = def.anInt371;
    		
    		particle_vertices = new int[vertices];
    		vertexX = new int[vertices];
    		vertexY = new int[vertices];
    		vertexZ = new int[vertices];
    		edge_a = new int[faces];
    		edge_b = new int[faces];
    		while (j >= 0)
    			aBoolean1618 = !aBoolean1618;//dead?
    		edge_c = new int[faces];
    		texture_edge_a = new short[texture_faces];
    		texture_edge_b = new short[texture_faces];
    		texture_edge_c = new short[texture_faces];
    		if (def.anInt376 >= 0)
    			vSkin = new int[vertices];
    		
    		if (def.anInt380 >= 0)
    			render_type = new int[faces];
    		
    		if (def.anInt381 >= 0)
    			render_priorities = new byte[faces];
    		else
    			priority = (byte) (-def.anInt381 - 1);
    		
    		if (def.anInt382 >= 0)
    			alpha = new int[faces];
    		
    		if (def.anInt383 >= 0)
    			tSkin = new int[faces];
    		
    		color = new short[faces];
    		Buffer stream = new Buffer(def.aByteArray368);
    		stream.currentPosition = def.anInt372;
    		Buffer stream_1 = new Buffer(def.aByteArray368);
    		stream_1.currentPosition = def.anInt373;
    		Buffer stream_2 = new Buffer(def.aByteArray368);
    		stream_2.currentPosition = def.anInt374;
    		Buffer stream_3 = new Buffer(def.aByteArray368);
    		stream_3.currentPosition = def.anInt375;
    		Buffer stream_4 = new Buffer(def.aByteArray368);
    		stream_4.currentPosition = def.anInt376;
    		int start_x = 0;
    		int start_y = 0;
    		int start_z = 0;
    		for (int point = 0; point < vertices; point++) {
    			int flag = stream.readUnsignedByte();
    			int x = 0;
    			if ((flag & 1) != 0)
    				x = stream_1.readSmart();
    			
    			int y = 0;
    			if ((flag & 2) != 0)
    				y = stream_2.readSmart();
    			
    			int z = 0;
    			if ((flag & 4) != 0)
    				z = stream_3.readSmart();
    			
    			vertexX[point] = start_x + x;
    			vertexY[point] = start_y + y;
    			vertexZ[point] = start_z + z;
    			start_x = vertexX[point];
    			start_y = vertexY[point];
    			start_z = vertexZ[point];
    			if (vSkin != null)
    				vSkin[point] = stream_4.readUnsignedByte();
    			
    		}
    		stream.currentPosition = def.anInt379;
    		stream_1.currentPosition = def.anInt380;
    		stream_2.currentPosition = def.anInt381;
    		stream_3.currentPosition = def.anInt382;
    		stream_4.currentPosition = def.anInt383;
    		for (int face = 0; face < faces; face++) {
    			color[face] = (short) stream.readUShort();
    			if (render_type != null)
    				render_type[face] = stream_1.readUnsignedByte();
    			
    			if (render_priorities != null)
    				render_priorities[face] = (byte) stream_2.readUnsignedByte();
    			
    			if (alpha != null) 
    				alpha[face] = stream_3.readUnsignedByte();
    			
    			if (tSkin != null)
    				tSkin[face] = stream_4.readUnsignedByte();
    			
    		}
    		stream.currentPosition = def.anInt377;
    		stream_1.currentPosition = def.anInt378;
    		int coordinate_a = 0;
    		int coordinate_b = 0;
    		int coordinate_c = 0;
    		int last_coordinate = 0;
    		for (int face = 0; face < faces; face++) {
    			int opcode = stream_1.readUnsignedByte();
    			if (opcode == 1) {
    				coordinate_a = stream.readSmart() + last_coordinate;
    				last_coordinate = coordinate_a;
    				coordinate_b = stream.readSmart() + last_coordinate;
    				last_coordinate = coordinate_b;
    				coordinate_c = stream.readSmart() + last_coordinate;
    				last_coordinate = coordinate_c;
    				edge_a[face] = coordinate_a;
    				edge_b[face] = coordinate_b;
    				edge_c[face] = coordinate_c;
    			}
    			if (opcode == 2) {
    				coordinate_b = coordinate_c;
    				coordinate_c = stream.readSmart() + last_coordinate;
    				last_coordinate = coordinate_c;
    				edge_a[face] = coordinate_a;
    				edge_b[face] = coordinate_b;
    				edge_c[face] = coordinate_c;
    			}
    			if (opcode == 3) {
    				coordinate_a = coordinate_c;
    				coordinate_c = stream.readSmart() + last_coordinate;
    				last_coordinate = coordinate_c;
    				edge_a[face] = coordinate_a;
    				edge_b[face] = coordinate_b;
    				edge_c[face] = coordinate_c;
    			}
    			if (opcode == 4) {
    				int l14 = coordinate_a;
    				coordinate_a = coordinate_b;
    				coordinate_b = l14;
    				coordinate_c = stream.readSmart() + last_coordinate;
    				last_coordinate = coordinate_c;
    				edge_a[face] = coordinate_a;
    				edge_b[face] = coordinate_b;
    				edge_c[face] = coordinate_c;
    			}
    		}
    		stream.currentPosition = def.anInt384;
    		for (int face = 0; face < texture_faces; face++) {
    			texture_edge_a[face] = (short) stream.readUShort();
    			texture_edge_b[face] = (short) stream.readUShort();
    			texture_edge_c[face] = (short) stream.readUShort();
    		}
    	}*/
    
    	public static void method460(byte abyte0[], int j) {
    		try {
    			if (abyte0 == null) {
    				ModelHeader class21 = header[j] = new ModelHeader();
    				class21.anInt369 = 0;
    				class21.anInt370 = 0;
    				class21.anInt371 = 0;
    				return;
    			}
    			Buffer stream = new Buffer(abyte0);
    			stream.currentPosition = abyte0.length - 18;
    			ModelHeader class21_1 = header[j] = new ModelHeader();
    			class21_1.aByteArray368 = abyte0;
    			class21_1.anInt369 = stream.readUShort();
    			class21_1.anInt370 = stream.readUShort();
    			class21_1.anInt371 = stream.readUnsignedByte();
    			int k = stream.readUnsignedByte();
    			int l = stream.readUnsignedByte();
    			int i1 = stream.readUnsignedByte();
    			int j1 = stream.readUnsignedByte();
    			int k1 = stream.readUnsignedByte();
    			int l1 = stream.readUShort();
    			int i2 = stream.readUShort();
    			int j2 = stream.readUShort();
    			int k2 = stream.readUShort();
    			int l2 = 0;
    			class21_1.anInt372 = l2;
    			l2 += class21_1.anInt369;
    			class21_1.anInt378 = l2;
    			l2 += class21_1.anInt370;
    			class21_1.anInt381 = l2;
    			if (l == 255)
    				l2 += class21_1.anInt370;
    			else
    				class21_1.anInt381 = -l - 1;
    			class21_1.anInt383 = l2;
    			if (j1 == 1)
    				l2 += class21_1.anInt370;
    			else
    				class21_1.anInt383 = -1;
    			class21_1.anInt380 = l2;
    			if (k == 1)
    				l2 += class21_1.anInt370;
    			else
    				class21_1.anInt380 = -1;
    			class21_1.anInt376 = l2;
    			if (k1 == 1)
    				l2 += class21_1.anInt369;
    			else
    				class21_1.anInt376 = -1;
    			class21_1.anInt382 = l2;
    			if (i1 == 1)
    				l2 += class21_1.anInt370;
    			else
    				class21_1.anInt382 = -1;
    			class21_1.anInt377 = l2;
    			l2 += k2;
    			class21_1.anInt379 = l2;
    			l2 += class21_1.anInt370 * 2;
    			class21_1.anInt384 = l2;
    			l2 += class21_1.anInt371 * 6;
    			class21_1.anInt373 = l2;
    			l2 += l1;
    			class21_1.anInt374 = l2;
    			l2 += i2;
    			class21_1.anInt375 = l2;
    			l2 += j2;
    		} catch (Exception _ex) {
    			_ex.printStackTrace();
    		}
    	}
    
    	public static void method459(int id, Provider onDemandFetcherParent) {
    		header = new ModelHeader[id];
    		resourceProvider = onDemandFetcherParent;
    	}
    
    	public static void method461(int file) {//clear
    		header[file] = null;
    	}
    
    	public static Model getModel(int file) {
    		if (header == null)
    			return null;
    		
    		ModelHeader class21 = header[file];
    		if (class21 == null) {
    			resourceProvider.provide(file);
    			return null;
    		} else {
    			return new Model(file);
    		}
    	}
    
    	public static boolean isCached(int file) {
    		if (header == null)
    			return false;
    
    		ModelHeader class21 = header[file];
    		if (class21 == null) {
    			resourceProvider.provide(file);
    			return false;
    		} else {
    			return true;
    		}
    	}
    
    	private Model(boolean flag) {
    		aBoolean1618 = true;//?
    		fits_on_single_square = false;
    		if (!flag)
    			aBoolean1618 = !aBoolean1618;
    	}
    
    	public Model(int length, Model model_segments[]) {
    		try {
    			aBoolean1618 = true;
    			fits_on_single_square = false;
    			anInt1620++;
    			boolean type_flag = false;
    			boolean priority_flag = false;
    			boolean alpha_flag = false;
    			boolean tSkin_flag = false;
    			boolean color_flag = false;
    			boolean texture_flag = false;
    			boolean coordinate_flag = false;
    			vertices = 0;
    			faces = 0;
    			texture_faces = 0;
    			priority = -1;
    			Model build;
    			for (int segment_index = 0; segment_index < length; segment_index++) {
    				build = model_segments[segment_index];
    				if (build != null) {
    					vertices += build.vertices;
    					faces += build.faces;
    					texture_faces += build.texture_faces;
    					type_flag |= build.render_type != null;
    					alpha_flag |= build.alpha != null;
    					if (build.render_priorities != null) {
    						priority_flag = true;
    					} else {
    						if (priority == -1)
    							priority = build.priority;
    						
    						if (priority != build.priority)
    							priority_flag = true;
    					}
    					tSkin_flag |= build.tSkin != null;
    					color_flag |= build.color != null;
    					texture_flag |= build.texture != null;
    					coordinate_flag |= build.texture_coordinates != null;
    				}
    			}
    			particle_vertices = new int[vertices];
    			vertexX = new int[vertices];
    			vertexY = new int[vertices];
    			vertexZ = new int[vertices];
    			vSkin = new int[vertices];
    			edge_a = new int[faces];
    			edge_b = new int[faces];
    			edge_c = new int[faces];
    			if(color_flag)
    				color = new short[faces];
    			
    			if (type_flag)
    				render_type = new int[faces];
    			
    			if (priority_flag)
    				render_priorities = new byte[faces];
    			
    			if (alpha_flag)
    				alpha = new int[faces];
    			
    			if (tSkin_flag)
    				tSkin = new int[faces];
    			
    			if(texture_flag)
    				texture = new short[faces];
    			
    			if (coordinate_flag)
    				texture_coordinates = new byte[faces];
    			
    			if(texture_faces > 0) {
    				texture_type = new byte[texture_faces];
    				texture_edge_a = new short[texture_faces];
    				texture_edge_b = new short[texture_faces];
    				texture_edge_c = new short[texture_faces];
    			}
    			vertices = 0;
    			faces = 0;
    			texture_faces = 0;
    			int texture_face = 0;
    			for (int segment_index = 0; segment_index < length; segment_index++) {
    				build = model_segments[segment_index];
    				if (build != null) {
    					for (int face = 0; face < build.faces; face++) {
    						/*if (type_flag) {
    							if (build.render_type == null) {
    								render_type[faces] = 0;
    							} else {
    								int type = build.render_type[face];
    								if ((type & 2) == 2)
    									type += texture_face << 2;
    								
    								render_type[faces] = type;
    							}
    						}*/
    						if(type_flag && build.render_type != null)
    							render_type[faces] = build.render_type[face];
    						
    						if (priority_flag)
    							if (build.render_priorities == null)
    								render_priorities[faces] = build.priority;
    							else
    								render_priorities[faces] = build.render_priorities[face];
    						
    						if (alpha_flag && build.alpha != null)
    							alpha[faces] = build.alpha[face];
    
    						if (tSkin_flag && build.tSkin != null)
    							tSkin[faces] = build.tSkin[face];
    						
    						if(texture_flag) {
    							if(build.texture != null) 
    								texture[faces] = build.texture[face];
    							else
    								texture[faces] = -1;
    						}
    						if(coordinate_flag) {
    							if(build.texture_coordinates != null && build.texture_coordinates[face] != -1) {
    								texture_coordinates[faces] = (byte) (build.texture_coordinates[face] + texture_face);
    							} else {
    								texture_coordinates[faces] = -1;
    							}
    						}
    						color[faces] = build.color[face];
    						edge_a[faces] = method465(build, build.edge_a[face]);
    						edge_b[faces] = method465(build, build.edge_b[face]);
    						edge_c[faces] = method465(build, build.edge_c[face]);
    						faces++;
    					}
    					for (int texture_edge = 0; texture_edge < build.texture_faces; texture_edge++) {
    						texture_edge_a[texture_faces] = (short) method465(build, build.texture_edge_a[texture_edge]);
    						texture_edge_b[texture_faces] = (short) method465(build, build.texture_edge_b[texture_edge]);
    						texture_edge_c[texture_faces] = (short) method465(build, build.texture_edge_c[texture_edge]);
    						texture_faces++;
    					}
    					texture_face += build.texture_faces;
    				}
    			}
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    
    	public Model(Model model_segments[]) {
    		int length = 2;
    		aBoolean1618 = true;
    		fits_on_single_square = false;
    		anInt1620++;
    		boolean type_flag = false;
    		boolean priority_flag = false;
    		boolean alpha_flag = false;
    		boolean color_flag = false;
    		boolean texture_flag = false;
    		boolean coordinate_flag = false;
    		vertices = 0;
    		faces = 0;
    		texture_faces = 0;
    		priority = -1;
    		Model build;
    		for (int segment_index = 0; segment_index < length; segment_index++) {
    			build = model_segments[segment_index];
    			if (build != null) {
    				vertices += build.vertices;
    				faces += build.faces;
    				texture_faces += build.texture_faces;
    				type_flag |= render_type != null;
    				if (build.render_priorities != null) {
    					priority_flag = true;
    				} else {
    					if (priority == -1)
    						priority = build.priority;
    					
    					if (priority != build.priority)
    						priority_flag = true;
    				}
    				alpha_flag |= build.alpha != null;
    				color_flag |= build.color != null;
    				texture_flag |= build.texture != null;
    				coordinate_flag |= build.texture_coordinates != null;
    			}
    		}
    		particle_vertices = new int[vertices];
    		vertexX = new int[vertices];
    		vertexY = new int[vertices];
    		vertexZ = new int[vertices];
    		edge_a = new int[faces];
    		edge_b = new int[faces];
    		edge_c = new int[faces];
    		hue_a = new int[faces];
    		hue_b = new int[faces];
    		hue_c = new int[faces];
    		
    		if (type_flag)
    			render_type = new int[faces];
    		
    		if (priority_flag)
    			render_priorities = new byte[faces];
    		
    		if (alpha_flag)
    			alpha = new int[faces];
    		
    		if (texture_flag)
    			texture = new short[faces];
    		
    		if (coordinate_flag)
    			texture_coordinates = new byte[faces];
    		
    		if(texture_faces > 0) {
    			texture_type = new byte[texture_faces];
    			texture_edge_a = new short[texture_faces];
    			texture_edge_b = new short[texture_faces];
    			texture_edge_c = new short[texture_faces];
    		}
    		
    		if (color_flag)
    			color = new short[faces];
    		
    		vertices = 0;
    		faces = 0;
    		texture_faces = 0;
    		int texture_face = 0;
    		for (int segment_index = 0; segment_index < length; segment_index++) {
    			build = model_segments[segment_index];
    			if (build != null) {
    				int vertex = vertices;
    				for (int face = 0; face < build.faces; face++) {
    					edge_a[faces] = build.edge_a[face] + vertex;
    					edge_b[faces] = build.edge_b[face] + vertex;
    					edge_c[faces] = build.edge_c[face] + vertex;
    					hue_a[faces] = build.hue_a[face];
    					hue_b[faces] = build.hue_b[face];
    					hue_c[faces] = build.hue_c[face];
    					/*if (type_flag)
    						if (build.render_type == null) {
    							render_type[faces] = 0;
    						} else {
    							int type = build.render_type[face];
    							if ((type & 2) == 2) //texture
    								type += texture_face << 2;
    							render_type[faces] = type;
    						}*/
    					
    					if(type_flag && build.render_type != null) {
    						render_type[faces] = build.render_type[face];
    					}
    					if (priority_flag)
    						if (build.render_priorities == null)
    							render_priorities[faces] = build.priority;
    						else
    							render_priorities[faces] = build.render_priorities[face];
    					
    					if (alpha_flag && build.alpha != null)
    						alpha[faces] = build.alpha[face];
    						
    					if (color_flag && build.color != null)
    						color[faces] = build.color[face];
    
    					if(texture_flag) {
    						if(build.texture != null) 
    							texture[faces] = build.texture[segment_index];
    						else 
    							texture[faces] = -1;
    						
    					}
    					if(coordinate_flag) {
    						if(build.texture_coordinates != null && build.texture_coordinates[segment_index] != -1) 
    							texture_coordinates[faces] = (byte) (build.texture_coordinates[segment_index] + texture_faces);
    						else 
    							texture_coordinates[faces] = -1;
    						
    					}
    					faces++;
    				}
    				for (int texture_edge = 0; texture_edge < build.texture_faces; texture_edge++) {
    					texture_edge_a[texture_faces] = (short) (build.texture_edge_a[texture_edge] + vertex);
    					texture_edge_b[texture_faces] = (short) (build.texture_edge_b[texture_edge] + vertex);
    					texture_edge_c[texture_faces] = (short) (build.texture_edge_c[texture_edge] + vertex);
    					texture_faces++;
    				}
    				for (int point = 0; point < build.vertices; point++) {
    					particle_vertices[vertices] = build.particle_vertices[point];
    					vertexX[vertices] = build.vertexX[point];
    					vertexY[vertices] = build.vertexY[point];
    					vertexZ[vertices] = build.vertexZ[point];
    					vertices++;
    				}
    				texture_face += build.texture_faces;
    			}
    		}
    		method466();
    	}
    	
    	public Model(boolean color_flag, boolean alpha_flag, boolean animated, Model model) {
    		this(color_flag, alpha_flag, animated, false, model);
    	}
    	
    	public Model(boolean color_flag, boolean alpha_flag, boolean animated, boolean texture_flag, Model model) {
    		aBoolean1618 = true;
    		fits_on_single_square = false;
    		anInt1620++;
    		vertices = model.vertices;
    		faces = model.faces;
    		texture_faces = model.texture_faces;
    		if (animated) {
    			particle_vertices = model.particle_vertices;
    			vertexX = model.vertexX;
    			vertexY = model.vertexY;
    			vertexZ = model.vertexZ;
    		} else {
    			particle_vertices = new int[vertices];
    			vertexX = new int[vertices];
    			vertexY = new int[vertices];
    			vertexZ = new int[vertices];
    			for (int point = 0; point < vertices; point++) {
    				particle_vertices[point] = model.particle_vertices[point];
    				vertexX[point] = model.vertexX[point];
    				vertexY[point] = model.vertexY[point];
    				vertexZ[point] = model.vertexZ[point];
    			}
    
    		}
    		if (color_flag) {
    			color = model.color;
    		} else {
    			color = new short[faces];
    			for (int face = 0; face < faces; face++)
    				color[face] = model.color[face];
    
    		}
    		if(!texture_flag && texture != null) {
    			texture = new short[faces];
    			for(int face = 0; face < faces; face++) {
    				texture[face] = model.texture[face];
    			}
    		} else {
    			texture = model.texture;
    		}
    		
    		if (alpha_flag) {
    			alpha = model.alpha;
    		} else {
    			alpha = new int[faces];
    			if (model.alpha == null) {
    				for (int l = 0; l < faces; l++)
    					alpha[l] = 0;
    
    			} else {
    				for (int i1 = 0; i1 < faces; i1++)
    					alpha[i1] = model.alpha[i1];
    
    			}
    		}
    		vSkin = model.vSkin;
    		tSkin = model.tSkin;
    		render_type = model.render_type;
    		edge_a = model.edge_a;
    		edge_b = model.edge_b;
    		edge_c = model.edge_c;
    		render_priorities = model.render_priorities;
    		texture_coordinates = model.texture_coordinates;
    		texture_type = model.texture_type;
    		priority = model.priority;
    		texture_edge_a = model.texture_edge_a;
    		texture_edge_b = model.texture_edge_b;
    		texture_edge_c = model.texture_edge_c;
    	}
    
    	public Model(boolean adjust_elevation, boolean gouraud_shading, Model model) {
    		aBoolean1618 = true;
    		fits_on_single_square = false;
    		anInt1620++;
    		vertices = model.vertices;
    		faces = model.faces;
    		texture_faces = model.texture_faces;
    		if (adjust_elevation) {
    			vertexY = new int[vertices];
    			for (int point = 0; point < vertices; point++)
    				vertexY[point] = model.vertexY[point];
    
    		} else {
    			vertexY = model.vertexY;
    		}
    		if (gouraud_shading) {
    			hue_a = new int[faces];
    			hue_b = new int[faces];
    			hue_c = new int[faces];
    			for (int face = 0; face < faces; face++) {
    				hue_a[face] = model.hue_a[face];
    				hue_b[face] = model.hue_b[face];
    				hue_c[face] = model.hue_c[face];
    			}
    
    			render_type = new int[faces];
    			if (model.render_type == null) {
    				for (int face = 0; face < faces; face++)
    					render_type[face] = 0;
    
    			} else {
    				for (int face = 0; face < faces; face++)
    					render_type[face] = model.render_type[face];
    
    			}
    			super.aClass33Array1425 = new Vertex[vertices];
    			for (int point = 0; point < vertices; point++) {
    				Vertex class33 = super.aClass33Array1425[point] = new Vertex();
    				Vertex class33_1 = model.aClass33Array1425[point];
    				class33.anInt602 = class33_1.anInt602;
    				class33.anInt603 = class33_1.anInt603;
    				class33.anInt604 = class33_1.anInt604;
    				class33.anInt605 = class33_1.anInt605;
    			}
    			gouraud_vertex = model.gouraud_vertex;
    			
    		} else {
    			hue_a = model.hue_a;
    			hue_b = model.hue_b;
    			hue_c = model.hue_c;
    			render_type = model.render_type;
    		}
    		particle_vertices = model.particle_vertices;
    		vertexX = model.vertexX;
    		vertexZ = model.vertexZ;
    		edge_a = model.edge_a;
    		edge_b = model.edge_b;
    		edge_c = model.edge_c;
    		render_priorities = model.render_priorities;
    		alpha = model.alpha;
    		texture_coordinates = model.texture_coordinates;
    		color = model.color;
    		texture = model.texture;
    		priority = model.priority;
    		texture_type = model.texture_type;
    		texture_edge_a = model.texture_edge_a;
    		texture_edge_b = model.texture_edge_b;
    		texture_edge_c = model.texture_edge_c;
    		super.modelHeight = model.modelHeight;
    		anInt1650 = model.anInt1650;
    		anInt1653 = model.anInt1653;
    		anInt1652 = model.anInt1652;
    		anInt1646 = model.anInt1646;
    		anInt1648 = model.anInt1648;
    		anInt1649 = model.anInt1649;
    		anInt1647 = model.anInt1647;
    	}
    
    	public void method464(Model model, boolean alpha_flag) {
    		vertices = model.vertices;
    		faces = model.faces;
    		texture_faces = model.texture_faces;
    		if (anIntArray1622.length < vertices) {
    			anIntArray1622 = new int[vertices + 10000];
    			anIntArray1623 = new int[vertices + 10000];
    			anIntArray1624 = new int[vertices + 10000];
    		}
    		particle_vertices = new int[vertices];
    		vertexX = anIntArray1622;
    		vertexY = anIntArray1623;
    		vertexZ = anIntArray1624;
    		for (int point = 0; point < vertices; point++) {
    			if (particle_vertices != null)
    				particle_vertices[point] = model.particle_vertices[point];
    			
    			vertexX[point] = model.vertexX[point];
    			vertexY[point] = model.vertexY[point];
    			vertexZ[point] = model.vertexZ[point];
    		}
    		if (alpha_flag) {
    			alpha = model.alpha;
    		} else {
    			if (anIntArray1625.length < faces)
    				anIntArray1625 = new int[faces + 100];
    			
    			alpha = anIntArray1625;
    			if (model.alpha == null) {
    				for (int face = 0; face < faces; face++)
    					alpha[face] = 0;
    
    			} else {
    				for (int face = 0; face < faces; face++)
    					alpha[face] = model.alpha[face];
    
    			}
    		}
    		render_type = model.render_type;
    		color = model.color;
    		render_priorities = model.render_priorities;
    		priority = model.priority;
    		face_skin = model.face_skin;
    		vertex_skin = model.vertex_skin;
    		edge_a = model.edge_a;
    		edge_b = model.edge_b;
    		edge_c = model.edge_c;
    		hue_a = model.hue_a;
    		hue_b = model.hue_b;
    		hue_c = model.hue_c;
    		texture_edge_a = model.texture_edge_a;
    		texture_edge_b = model.texture_edge_b;
    		texture_edge_c = model.texture_edge_c;
    		texture_coordinates = model.texture_coordinates;
    		texture_type = model.texture_type;
    		texture = model.texture;
    	}
    
    	private final int method465(Model model, int face) {
    		int vertex = -1;
    		int particle_point = model.particle_vertices[face];
    		int x = model.vertexX[face];
    		int y = model.vertexY[face];
    		int z = model.vertexZ[face];
    		for (int index = 0; index < vertices; index++) {
    			if (x != vertexX[index] || y != vertexY[index] || z != vertexZ[index])
    				continue;
    			vertex = index;
    			break;
    		}
    		if (vertex == -1) {
    			particle_vertices[vertices] = particle_point;
    			vertexX[vertices] = x;
    			vertexY[vertices] = y;
    			vertexZ[vertices] = z;
    			if (model.vSkin != null)
    				vSkin[vertices] = model.vSkin[face];
    			
    			vertex = vertices++;
    		}
    		return vertex;
    	}
    
    	public void method466() {
    		super.modelHeight = 0;
    		anInt1650 = 0;
    		anInt1651 = 0;
    		for (int index = 0; index < vertices; index++) {
    			int x = vertexX[index];
    			int y = vertexY[index];
    			int z = vertexZ[index];
    			if (-y > super.modelHeight)
    				super.modelHeight = -y;
    			
    			if (y > anInt1651)
    				anInt1651 = y;
    			
    			int i1 = x * x + z * z;
    			if (i1 > anInt1650)
    				anInt1650 = i1;
    		}
    		anInt1650 = (int) (Math.sqrt(anInt1650) + 0.98999999999999999D);
    		anInt1653 = (int) (Math.sqrt(anInt1650 * anInt1650 + super.modelHeight * super.modelHeight) + 0.98999999999999999D);
    		anInt1652 = anInt1653 + (int) (Math.sqrt(anInt1650 * anInt1650 + anInt1651 * anInt1651) + 0.98999999999999999D);
    	}
    
    	public void computeSphericalBounds() {
    		super.modelHeight = 0;
    		anInt1651 = 0;
    		for (int index = 0; index < vertices; index++) {
    			int j = vertexY[index];
    			if (-j > super.modelHeight)
    				super.modelHeight = -j;
    			
    			if (j > anInt1651)
    				anInt1651 = j;
    			
    		}
    		anInt1653 = (int) (Math.sqrt(anInt1650 * anInt1650 + super.modelHeight * super.modelHeight) + 0.98999999999999999D);
    		anInt1652 = anInt1653 + (int) (Math.sqrt(anInt1650 * anInt1650 + anInt1651 * anInt1651) + 0.98999999999999999D);
    	}
    
    	public void method468(int i) {
    		super.modelHeight = 0;
    		anInt1650 = 0;
    		anInt1651 = 0;
    		anInt1646 = 0xf423f;
    		anInt1647 = 0xfff0bdc1;
    		anInt1648 = 0xfffe7961;
    		anInt1649 = 0x1869f;
    		for (int j = 0; j < vertices; j++) {
    			int x = vertexX[j];
    			int y = vertexY[j];
    			int z = vertexZ[j];
    			if (x < anInt1646)
    				anInt1646 = x;
    			if (x > anInt1647)
    				anInt1647 = x;
    			if (z < anInt1649)
    				anInt1649 = z;
    			if (z > anInt1648)
    				anInt1648 = z;
    			if (-y > super.modelHeight)
    				super.modelHeight = -y;
    			if (y > anInt1651)
    				anInt1651 = y;
    			int j1 = x * x + z * z;
    			if (j1 > anInt1650)
    				anInt1650 = j1;
    		}
    		anInt1650 = (int) Math.sqrt(anInt1650);
    		anInt1653 = (int) Math.sqrt(anInt1650 * anInt1650 + super.modelHeight * super.modelHeight);
    		if (i != 21073) {
    			return;
    		} else {
    			anInt1652 = anInt1653 + (int) Math.sqrt(anInt1650 * anInt1650 + anInt1651 * anInt1651);
    			return;
    		}
    	}
    
    	public void skin() {
    		if (vSkin != null) {
    			int ai[] = new int[256];
    			int j = 0;
    			for (int l = 0; l < vertices; l++) {
    				int j1 = vSkin[l];
    				ai[j1]++;
    				if (j1 > j)
    					j = j1;
    			}
    			vertex_skin = new int[j + 1][];
    			for (int k1 = 0; k1 <= j; k1++) {
    				vertex_skin[k1] = new int[ai[k1]];
    				ai[k1] = 0;
    			}
    			for (int j2 = 0; j2 < vertices; j2++) {
    				int l2 = vSkin[j2];
    				vertex_skin[l2][ai[l2]++] = j2;
    			}
    			vSkin = null;
    		}
    		if (tSkin != null) {
    			int ai1[] = new int[256];
    			int k = 0;
    			for (int i1 = 0; i1 < faces; i1++) {
    				int l1 = tSkin[i1];
    				ai1[l1]++;
    				if (l1 > k)
    					k = l1;
    			}
    			face_skin = new int[k + 1][];
    			for (int i2 = 0; i2 <= k; i2++) {
    				face_skin[i2] = new int[ai1[i2]];
    				ai1[i2] = 0;
    			}
    			for (int k2 = 0; k2 < faces; k2++) {
    				int i3 = tSkin[k2];
    				face_skin[i3][ai1[i3]++] = k2;
    			}
    			tSkin = null;
    		}
    	}
    	
    	public void method470(int frame, int nextFrame, int end, int cycle) {
    		if (!Configuration.enableTweening) {
    			apply(frame);
    			return;
    		}
    		if (vertex_skin != null && frame != -1) {
    			Frame currentAnimation = Frame.method531(frame);
    			FrameBase list1 = currentAnimation.aClass18_637;
    			anInt1681 = 0;
    			anInt1682 = 0;
    			anInt1683 = 0;
    			Frame nextAnimation = null;
    			FrameBase list2 = null;
    			if (nextFrame != -1) {
    				nextAnimation = Frame.method531(nextFrame);
    				if (nextAnimation.aClass18_637 != list1)
    					nextAnimation = null;
    				list2 = nextAnimation.aClass18_637;
    			}
    			if (nextAnimation == null || list2 == null) {
    				for (int i_263_ = 0; i_263_ < currentAnimation.anInt638; i_263_++) {
    					int i_264_ = currentAnimation.anIntArray639[i_263_];
    					method472(list1.anIntArray342[i_264_], list1.anIntArrayArray343[i_264_],
    							currentAnimation.anIntArray640[i_263_],
    							currentAnimation.anIntArray641[i_263_],
    							currentAnimation.anIntArray642[i_263_]);
    				}
    			} else {
    				for (int i1 = 0; i1 < currentAnimation.anInt638; i1++) {
    					int n1 = currentAnimation.anIntArray639[i1];
    					int opcode = list1.anIntArray342[n1];
    					int[] skin = list1.anIntArrayArray343[n1];
    					int x = currentAnimation.anIntArray640[i1];
    					int y = currentAnimation.anIntArray641[i1];
    					int z = currentAnimation.anIntArray642[i1];
    					boolean found = false;
    					for (int i2 = 0; i2 < nextAnimation.anInt638; i2++) {
    						int n2 = nextAnimation.anIntArray639[i2];
    						if (list2.anIntArrayArray343[n2].equals(skin)) {
    							if (opcode != 2) {
    								x += (nextAnimation.anIntArray640[i2] - x) * cycle / end;
    								y += (nextAnimation.anIntArray641[i2] - y) * cycle / end;
    								z += (nextAnimation.anIntArray642[i2] - z) * cycle / end;
    							} else {
    								x &= 0x7ff;
    								y &= 0x7ff;
    								z &= 0x7ff;
    								int dx = nextAnimation.anIntArray640[i2] - x & 0x7ff;
    								int dy = nextAnimation.anIntArray641[i2] - y & 0x7ff;
    								int dz = nextAnimation.anIntArray642[i2] - z & 0x7ff;
    								if (dx >= 1024) {
    									dx -= 2048;
    								}
    								if (dy >= 1024) {
    									dy -= 2048;
    								}
    								if (dz >= 1024) {
    									dz -= 2048;
    								}
    								x = x + dx * cycle / end & 0x7ff;
    								y = y + dy * cycle / end & 0x7ff;
    								z = z + dz * cycle / end & 0x7ff;
    							}
    							found = true;
    							break;
    						}
    					}
    					if (!found) {
    						if (opcode != 3 && opcode != 2) {
    							x = x * (end - cycle) / end;
    							y = y * (end - cycle) / end;
    							z = z * (end - cycle) / end;
    						} else if (opcode == 3) {
    							x = (x * (end - cycle) + (cycle << 7)) / end;
    							y = (y * (end - cycle) + (cycle << 7)) / end;
    							z = (z * (end - cycle) + (cycle << 7)) / end;
    						} else {
    							x &= 0x7ff;
    							y &= 0x7ff;
    							z &= 0x7ff;
    							int dx = -x & 0x7ff;
    							int dy = -y & 0x7ff;
    							int dz = -z & 0x7ff;
    							if (dx >= 1024) {
    								dx -= 2048;
    							}
    							if (dy >= 1024) {
    								dy -= 2048;
    							}
    							if (dz >= 1024) {//128
    								dz -= 2048;//256
    							}
    							x = x + dx * cycle / end & 0x7ff;//0xff
    							y = y + dy * cycle / end & 0x7ff;
    							z = z + dz * cycle / end & 0x7ff;
    						}
    					}
    					method472(opcode, skin, x, y, z);
    				}
    			}
    		}
    	}
    
    	public void apply(int id) {
    		if (vertex_skin == null)
    			return;
    		if (id == -1)
    			return;
    		Frame frame = Frame.method531(id);
    		if (frame == null)
    			return;
    		FrameBase skin = frame.aClass18_637;
    		anInt1681 = 0;
    		anInt1682 = 0;
    		anInt1683 = 0;
    		for (int k = 0; k < frame.anInt638; k++) {
    			int l = frame.anIntArray639[k];
    			method472(skin.anIntArray342[l], skin.anIntArrayArray343[l], frame.anIntArray640[k], frame.anIntArray641[k], frame.anIntArray642[k]);
    		}
    
    	}
    
    	public void method471(int ai[], int j, int k) {
    		if (k == -1)
    			return;
    		if (ai == null || j == -1) {
    			apply(k);
    			return;
    		}
    		Frame class36 = Frame.method531(k);
    		if (class36 == null)
    			return;
    		Frame class36_1 = Frame.method531(j);
    		if (class36_1 == null) {
    			apply(k);
    			return;
    		}
    		FrameBase class18 = class36.aClass18_637;
    		anInt1681 = 0;
    		anInt1682 = 0;
    		anInt1683 = 0;
    		int l = 0;
    		int i1 = ai[l++];
    		for (int j1 = 0; j1 < class36.anInt638; j1++) {
    			int k1;
    			for (k1 = class36.anIntArray639[j1]; k1 > i1; i1 = ai[l++])
    				;
    			if (k1 != i1 || class18.anIntArray342[k1] == 0)
    				method472(class18.anIntArray342[k1],
    						class18.anIntArrayArray343[k1],
    						class36.anIntArray640[j1], class36.anIntArray641[j1],
    						class36.anIntArray642[j1]);
    		}
    		anInt1681 = 0;
    		anInt1682 = 0;
    		anInt1683 = 0;
    		l = 0;
    		i1 = ai[l++];
    		for (int l1 = 0; l1 < class36_1.anInt638; l1++) {
    			int i2;
    			for (i2 = class36_1.anIntArray639[l1]; i2 > i1; i1 = ai[l++])
    				;
    			if (i2 == i1 || class18.anIntArray342[i2] == 0)
    				method472(class18.anIntArray342[i2],
    						class18.anIntArrayArray343[i2],
    						class36_1.anIntArray640[l1],
    						class36_1.anIntArray641[l1],
    						class36_1.anIntArray642[l1]);
    		}
    	}
    
    	private void method472(int opcode, int skin[], int x, int y, int z) {
    		int length = skin.length;
    		if (opcode == 0) {
    			int j1 = 0;
    			anInt1681 = 0;
    			anInt1682 = 0;
    			anInt1683 = 0;
    			for (int index = 0; index < length; index++) {
    				int l3 = skin[index];
    				if (l3 < vertex_skin.length) {
    					int ai5[] = vertex_skin[l3];
    					for (int i5 = 0; i5 < ai5.length; i5++) {
    						int j6 = ai5[i5];
    						anInt1681 += vertexX[j6];
    						anInt1682 += vertexY[j6];
    						anInt1683 += vertexZ[j6];
    						j1++;
    					}
    
    				}
    			}
    
    			if (j1 > 0) {
    				anInt1681 = anInt1681 / j1 + x;
    				anInt1682 = anInt1682 / j1 + y;
    				anInt1683 = anInt1683 / j1 + z;
    				return;
    			} else {
    				anInt1681 = x;
    				anInt1682 = y;
    				anInt1683 = z;
    				return;
    			}
    		}
    		if (opcode == 1) {
    			for (int index = 0; index < length; index++) {
    				int l2 = skin[index];
    				if (l2 < vertex_skin.length) {
    					int ai1[] = vertex_skin[l2];
    					for (int i4 = 0; i4 < ai1.length; i4++) {
    						int j5 = ai1[i4];
    						vertexX[j5] += x;
    						vertexY[j5] += y;
    						vertexZ[j5] += z;
    					}
    
    				}
    			}
    
    			return;
    		}
    		if (opcode == 2) {//rotation
    			for (int index = 0; index < length; index++) {
    				int i3 = skin[index];
    				if (i3 < vertex_skin.length) {
    					int ai2[] = vertex_skin[i3];
    					for (int j4 = 0; j4 < ai2.length; j4++) {
    						int k5 = ai2[j4];
    						vertexX[k5] -= anInt1681;
    						vertexY[k5] -= anInt1682;
    						vertexZ[k5] -= anInt1683;
    						//int k6 = (x & 0xff) * 8;
    						//int l6 = (y & 0xff) * 8;
    						//int i7 = (z & 0xff) * 8;
    						if(z != 0) {//if (i7 != 0) {
    							int j7 = SINE[z];//i7
    							int i8 = COSINE[z];//i7
    							int l8 = vertexY[k5] * j7 + vertexX[k5] * i8 >> 16;
    							vertexY[k5] = vertexY[k5] * i8 - vertexX[k5] * j7 >> 16;
    							vertexX[k5] = l8;
    						}
    						if(x != 0) {//if (k6 != 0) {
    							int k7 = SINE[x];//k6
    							int j8 = COSINE[x];//k6
    							int i9 = vertexY[k5] * j8 - vertexZ[k5] * k7 >> 16;
    							vertexZ[k5] = vertexY[k5] * k7 + vertexZ[k5] * j8 >> 16;
    							vertexY[k5] = i9;
    						}
    						if(y != 0) {//if (l6 != 0) {
    							int l7 = SINE[y];//l6
    							int k8 = COSINE[y];//l6
    							int j9 = vertexZ[k5] * l7 + vertexX[k5] * k8 >> 16;
    							vertexZ[k5] = vertexZ[k5] * k8 - vertexX[k5] * l7 >> 16;
    							vertexX[k5] = j9;
    						}
    						vertexX[k5] += anInt1681;
    						vertexY[k5] += anInt1682;
    						vertexZ[k5] += anInt1683;
    					}
    
    				}
    			}
    			return;
    		}
    		if (opcode == 3) {
    			for (int index = 0; index < length; index++) {
    				int j3 = skin[index];
    				if (j3 < vertex_skin.length) {
    					int ai3[] = vertex_skin[j3];
    					for (int k4 = 0; k4 < ai3.length; k4++) {
    						int l5 = ai3[k4];
    						vertexX[l5] -= anInt1681;
    						vertexY[l5] -= anInt1682;
    						vertexZ[l5] -= anInt1683;
    						vertexX[l5] = (vertexX[l5] * x) / 128;
    						vertexY[l5] = (vertexY[l5] * y) / 128;
    						vertexZ[l5] = (vertexZ[l5] * z) / 128;
    						vertexX[l5] += anInt1681;
    						vertexY[l5] += anInt1682;
    						vertexZ[l5] += anInt1683;
    					}
    				}
    			}
    			return;
    		}
    		if (opcode == 5 && face_skin != null && alpha != null) {
    			for (int index = 0; index < length; index++) {
    				int k3 = skin[index];
    				if (k3 < face_skin.length) {
    					int ai4[] = face_skin[k3];
    					for (int l4 = 0; l4 < ai4.length; l4++) {
    						int i6 = ai4[l4];
    						alpha[i6] += x * 8;
    						if (alpha[i6] < 0)
    							alpha[i6] = 0;
    						if (alpha[i6] > 255)
    							alpha[i6] = (byte) 255;
    					}
    				}
    			}
    		}
    	}
    
    	public void method473() {
    		for (int point = 0; point < vertices; point++) {
    			int k = vertexX[point];
    			vertexX[point] = vertexZ[point];
    			vertexZ[point] = -k;
    		}
    	}
    
    	public void method474(int i) {
    		int k = SINE[i];
    		int l = COSINE[i];
    		for (int point = 0; point < vertices; point++) {
    			int j1 = vertexY[point] * l - vertexZ[point] * k >> 16;
    			vertexZ[point] = vertexY[point] * k + vertexZ[point] * l >> 16;
    			vertexY[point] = j1;
    		}
    	}
    
    	public void translate(int x, int y, int z) {
    		for (int point = 0; point < vertices; point++) {
    			vertexX[point] += x;
    			vertexY[point] += y;
    			vertexZ[point] += z;
    		}
    	}
    
    	public void recolor(int found, int replace) {
    		if(color != null)
    			for (int face = 0; face < faces; face++)
    				if (color[face] == (short) found)
    					color[face] = (short) replace;
    	}
    	
    	public void retexture(short found, short replace) {
    		if(texture != null)
    			for (int face = 0; face < faces; face++)
    				if (texture[face] == found)
    					texture[face] = replace;
    	}
    	
    	public void texture() {
    		/*
    		//refactored from a 130 deob, was called before lighting calculation occured
    		if(texture_faces > 0 && texture_coordinates != null) {
    			int[] texture_face = new int[texture_faces];
    			int face;
    			for(face = 0; face < faces; face++) {
    				if(texture_coordinates[face] != -1)
    					++texture_face[texture_coordinates[face] & 0xff];
    				
    			}
    			texture_faces = 0;
    			for(face = 0; face < texture_faces; face++) {
    				if(texture_face[face] > 0 && texture_type[face] == 0)
    					texture_faces++;
    				
    			}
    			texture_edge_a = new short[texture_faces];
    			texture_edge_b = new short[texture_faces];
    			texture_edge_c = new short[texture_faces];
    			face = 0;
    			int var7;
    			for(var7 = 0; var7 < texture_faces; ++var7) {
    				if(texture_face[var7] > 0 && texture_type[var7] == 0) {
    					texture_edge_a[face] = (short) (texture_edge_a[var7] & 0xffff);
    					texture_edge_b[face] = (short) (texture_edge_b[var7] & 0xffff);
    					texture_edge_c[face] = (short) (texture_edge_c[var7] & 0xffff);
    					texture_face[var7] = face++;
    				} else {
    					texture_face[var7] = -1;
    				}
    			}
    			
    			texture_coordinates = new byte[faces];
    			for(var7 = 0; var7 < this.faces; ++var7) {
    				if(texture_coordinates[var7] != -1) {
    					texture_coordinates[var7] = (byte)texture_face[texture_coordinates[var7] & 0xff];
    				} else {
    					texture_coordinates[var7] = -1;
    				}
    			}
    		}*/
    	}
    
    	public void method477() {
    		for (int index = 0; index < vertices; index++)
    			vertexZ[index] = -vertexZ[index];
    		
    		for (int face = 0; face < faces; face++) {
    			int l = edge_a[face];
    			edge_a[face] = edge_c[face];
    			edge_c[face] = l;
    		}
    	}
    
    	public void scale() {//fix 600+ model scaling
    		for (int index = 0; index < vertices; index++) {
    			vertexX[index] >>= 2;
    			vertexY[index] >>= 2;
    			vertexZ[index] >>= 2;
    		}
    	}
    	
    	public void scale(int i, int j, int l) {//478
    		for (int index = 0; index < vertices; index++) {
    			vertexX[index] = (vertexX[index] * i) / 128;
    			vertexY[index] = (vertexY[index] * l) / 128;
    			vertexZ[index] = (vertexZ[index] * j) / 128;
    		}
    
    	}
    	
    	public void light(int intensity, int mag, int x, int y, int z, boolean flat_shading) {
    		int pre_mag = (int) Math.sqrt(x * x + y * y + z * z);
    		int fall_off = mag * pre_mag >> 8;
    		hue_a = new int[faces];
    		hue_b = new int[faces];
    		hue_c = new int[faces];
    		if (super.aClass33Array1425 == null) {
    			super.aClass33Array1425 = new Vertex[vertices];
    			for (int index = 0; index < vertices; index++)
    				super.aClass33Array1425[index] = new Vertex();
    
    		}
    		for (int face = 0; face < faces; face++) {
    			int j2 = edge_a[face];
    			int l2 = edge_b[face];
    			int i3 = edge_c[face];
    			int j3 = vertexX[l2] - vertexX[j2];
    			int k3 = vertexY[l2] - vertexY[j2];
    			int l3 = vertexZ[l2] - vertexZ[j2];
    			int i4 = vertexX[i3] - vertexX[j2];
    			int j4 = vertexY[i3] - vertexY[j2];
    			int k4 = vertexZ[i3] - vertexZ[j2];
    			int l4 = k3 * k4 - j4 * l3;
    			int i5 = l3 * i4 - k4 * j3;
    			int j5;
    			for (j5 = j3 * j4 - i4 * k3; l4 > 8192 || i5 > 8192 || j5 > 8192 || l4 < -8192 || i5 < -8192 || j5 < -8192; j5 >>= 1) {
    				l4 >>= 1;
    				i5 >>= 1;
    			}
    			int k5 = (int) Math.sqrt(l4 * l4 + i5 * i5 + j5 * j5);
    			if (k5 <= 0)
    				k5 = 1;
    			
    			l4 = (l4 * 256) / k5;
    			i5 = (i5 * 256) / k5;
    			j5 = (j5 * 256) / k5;
    			
    			short texture_id;
    			int type;
    			if(render_type != null)
    				type = render_type[face];
    			else
    				type = 0;
    			
    			if(texture == null) {
    				texture_id = -1;
    			} else {
    				texture_id = texture[face];
    			}
    			
    			if (render_type == null || (render_type[face] & 1) == 0) {
    				Vertex class33_2 = super.aClass33Array1425[j2];
    				class33_2.anInt602 += l4;
    				class33_2.anInt603 += i5;
    				class33_2.anInt604 += j5;
    				class33_2.anInt605++;
    				class33_2 = super.aClass33Array1425[l2];
    				class33_2.anInt602 += l4;
    				class33_2.anInt603 += i5;
    				class33_2.anInt604 += j5;
    				class33_2.anInt605++;
    				class33_2 = super.aClass33Array1425[i3];
    				class33_2.anInt602 += l4;
    				class33_2.anInt603 += i5;
    				class33_2.anInt604 += j5;
    				class33_2.anInt605++;
    			} else {
    				if(texture_id != -1) {
    					type = 2;
    				}
    				int light = intensity + (x * l4 + y * i5 + z * j5) / (fall_off + fall_off / 2);
    				hue_a[face] = method481(color[face], light, type);
    			}
    		}
    		if (flat_shading) {
    			method480(intensity, fall_off, x, y, z);
    			method466();
    		} else {
    			gouraud_vertex = new Vertex[vertices];
    			for (int point = 0; point < vertices; point++) {
    				Vertex class33 = super.aClass33Array1425[point];
    				Vertex class33_1 = gouraud_vertex[point] = new Vertex();
    				class33_1.anInt602 = class33.anInt602;
    				class33_1.anInt603 = class33.anInt603;
    				class33_1.anInt604 = class33.anInt604;
    				class33_1.anInt605 = class33.anInt605;
    			}
    			method468(21073);
    		}
    		//?
    		/*if (flat_shading) {
    			method466();
    			return;
    		} else {
    			method468(21073);
    			return;
    		}*/
    	}
    	
    	public final void method480(int intensity, int fall_off, int x, int y, int z) {
    		for (int face = 0; face < faces; face++) {
    			int a = edge_a[face];
    			int b = edge_b[face];
    			int c = edge_c[face];
    			short texture_id;
    			if(texture == null)
    				texture_id = -1;
    			else
    				texture_id = texture[face];
    			
    			if (render_type == null) {
    				int type;
    				if(texture_id != -1) {
    					type = 2;
    				} else {
    					type = 1;
    				}
    				int hsl = color[face] & 0xffff;
    				Vertex vertex = super.aClass33Array1425[a];
    				int light = intensity + (x * vertex.anInt602 + y * vertex.anInt603 + z * vertex.anInt604) / (fall_off * vertex.anInt605);
    				hue_a[face] = method481(hsl, light, type);
    				vertex = super.aClass33Array1425[b];
    				light = intensity + (x * vertex.anInt602 + y * vertex.anInt603 + z * vertex.anInt604) / (fall_off * vertex.anInt605);
    				hue_b[face] = method481(hsl, light, type);
    				vertex = super.aClass33Array1425[c];
    				light = intensity + (x * vertex.anInt602 + y * vertex.anInt603 + z * vertex.anInt604) / (fall_off * vertex.anInt605);
    				hue_c[face] = method481(hsl, light, type);
    			} else if ((render_type[face] & 1) == 0) {
    				int type = render_type[face];
    				if(texture_id != -1) {
    					type = 2;
    				}
    				int hsl = color[face] & 0xffff;
    				Vertex vertex = super.aClass33Array1425[a];
    				int light = intensity + (x * vertex.anInt602 + y * vertex.anInt603 + z * vertex.anInt604) / (fall_off * vertex.anInt605);
    				hue_a[face] = method481(hsl, light, type);
    				vertex = super.aClass33Array1425[b];
    				light = intensity + (x * vertex.anInt602 + y * vertex.anInt603 + z * vertex.anInt604) / (fall_off * vertex.anInt605);
    				hue_b[face] = method481(hsl, light, type);
    				vertex = super.aClass33Array1425[c];
    				light = intensity + (x * vertex.anInt602 + y * vertex.anInt603 + z * vertex.anInt604) / (fall_off * vertex.anInt605);
    				hue_c[face] = method481(hsl, light, type);
    			}
    		}
    
    		super.aClass33Array1425 = null;
    		gouraud_vertex = null;
    		vSkin = null;
    		tSkin = null;
    		/*if (render_type != null) {
    			for (int face = 0; face < faces; face++)
    				if ((render_type[face] & 2) == 2)
    					return;
    		//texture check, to return before color null call?
    		}*/
    		color = null;
    	}
    
    	public static final int method481(int light) {
    		if(light >= 2) {
    			if(light > 126) {
    				light = 126;
    			}
    		} else {
    			light = 2;
    		}
    		return light;
    	}
    	
    	public static final int method481(int hsl, int light) {
    		light = light * (hsl & 127) >> 7;
    		if(light < 2) {
    			light = 2;
    		} else if(light > 126) {
    			light = 126;
    		}
    		return (hsl & 0xff80) + light;
    	}
       
    	public static final int method481(int hsl, int light, int type) {
    		if (hsl == 65535)
    			return 0;
    		
    		if ((type & 2) == 2) {//texture lighting
    			if (light < 0)
    				light = 0;
    			else if (light > 127)
    				light = 127;
    			
    			light = 127 - light;
    			return light;
    		}
    		
    		light = light * (hsl & 0x7f) >> 7;
    		if (light < 2)
    			light = 2;
    		else if (light > 126)
    			light = 126;
    		
    		return (hsl & 0xff80) + light;
    	}
    
    	public final void method482(int roll, int yaw, int pitch, int start_x, int start_y, int zoom) {
    		int depth = 0;
    		int center_x = Rasterizer.textureInt1;
    		int center_y = Rasterizer.textureInt2;
    		int depth_sin = SINE[depth];
    		int depth_cos = COSINE[depth];
    		int roll_sin = SINE[roll];
    		int roll_cos = COSINE[roll];
    		int yaw_sin = SINE[yaw];
    		int yaw_cos = COSINE[yaw];
    		int pitch_sin = SINE[pitch];
    		int pitch_cos = COSINE[pitch];
    		int position = start_y * pitch_sin + zoom * pitch_cos >> 16;
    		for (int index = 0; index < vertices; index++) {
    			int x = vertexX[index];
    			int y = vertexY[index];
    			int z = vertexZ[index];
    			if (yaw != 0) {
    				int k5 = y * yaw_sin + x * yaw_cos >> 16;
    				y = y * yaw_cos - x * yaw_sin >> 16;
    				x = k5;
    			}
    			if (depth != 0) {
    				int l5 = y * depth_cos - z * depth_sin >> 16;
    				z = y * depth_sin + z * depth_cos >> 16;
    				y = l5;
    			}
    			if (roll != 0) {
    				int i6 = z * roll_sin + x * roll_cos >> 16;
    				z = z * roll_cos - x * roll_sin >> 16;
    				x = i6;
    			}
    			x += start_x;
    			y += start_y;
    			z += zoom;
    			
    			int j6 = y * pitch_cos - z * pitch_sin >> 16;
    			z = y * pitch_sin + z * pitch_cos >> 16;
    			y = j6;
    			
    			anIntArray1667[index] = z - position;
    			vertex_viewpoint_z[index] = z;//was set to 0, changed to z?
    			vertex_viewpoint_x[index] = center_x + (x << 9) / z;
    			vertex_viewpoint_y[index] = center_y + (y << 9) / z;
    			if (texture_faces > 0) {
    				texture_viewpoint_x[index] = x;
    				texture_viewpoint_y[index] = y;
    				texture_viewpoint_z[index] = z;
    			}
    		}
    		try {
    			method483(false, false, 0);
    			return;
    		} catch (Exception _ex) {
    			return;
    		}
    	}
    
    	@Override
    	public final void method443(int orientation, int object_cosine_y, int object_sine_y, int object_sine_x, int object_cosine_x, int start_x, int start_y, int depth, int uid) {
    		offX = start_x + Client.instance.absoluteX;
    		offY = start_y + Client.instance.anchor;
    		offZ = depth + Client.instance.absoluteY;
    		model_orientation = orientation;
    		//calculating bounds?
    		int j2 = depth * object_cosine_x - start_x * object_sine_x >> 16;
    		int k2 = start_y * object_cosine_y + j2 * object_sine_y >> 16;
    		int l2 = anInt1650 * object_sine_y >> 16;
    		int i3 = k2 + l2;
    		if (i3 <= 50 || k2 >= 3500)
    			return;
    		
    		int j3 = depth * object_sine_x + start_x * object_cosine_x >> 16;
    		int k3 = j3 - anInt1650 << SceneGraph.viewDistance;
    		if (k3 / i3 >= Raster.centerY)
    			return;
    		
    		int l3 = j3 + anInt1650 << SceneGraph.viewDistance;
    		if (l3 / i3 <= -Raster.centerY)
    			return;
    		
    		int i4 = start_y * object_sine_y - j2 * object_cosine_y >> 16;
    		int j4 = anInt1650 * object_cosine_y >> 16;
    		int k4 = i4 + j4 << SceneGraph.viewDistance;
    		if (k4 / i3 <= -Raster.anInt1387)
    			return;
    		
    		int l4 = j4 + (super.modelHeight * object_sine_y >> 16);
    		int i5 = i4 - l4 << SceneGraph.viewDistance;
    		if (i5 / i3 >= Raster.anInt1387)
    			return;
    		
    		int j5 = l2 + (super.modelHeight * object_cosine_y >> 16);
    		boolean in_viewable_raster = false;//name this better, nothing to do with 'in' but more to do with the depth rendering of triangles
    		if (k2 - j5 <= 50)
    			in_viewable_raster = true;
    		
    		boolean large_object = false;
    		if (uid > 0 && objectExists) {
    			int k5 = k2 - l2;
    			if (k5 <= 50)
    				k5 = 50;
    			if (j3 > 0) {
    				k3 /= i3;
    				l3 /= k5;
    			} else {
    				l3 /= i3;
    				k3 /= k5;
    			}
    			if (i4 > 0) {
    				i5 /= i3;
    				k4 /= k5;
    			} else {
    				k4 /= i3;
    				i5 /= k5;
    			}
    			int i6 = anInt1685 - Rasterizer.textureInt1;
    			int k6 = anInt1686 - Rasterizer.textureInt2;
    			if (i6 > k3 && i6 < l3 && k6 > i5 && k6 < k4)
    				if (fits_on_single_square)
    					objectsInCurrentRegion[anInt1687++] = uid;
    				else
    					large_object = true;
    		}
    		int center_x = Rasterizer.textureInt1;
    		int center_y = Rasterizer.textureInt2;
    		int sine_x = 0;
    		int cosine_x = 0;
    		if (orientation != 0) {
    			sine_x = SINE[orientation];
    			cosine_x = COSINE[orientation];
    		}
    		for (int index = 0; index < vertices; index++) {
    			int raster_x = vertexX[index];
    			int raster_y = vertexY[index];
    			int raster_z = vertexZ[index];
    			if (orientation != 0) {
    				int j8 = raster_z * sine_x + raster_x * cosine_x >> 16;
    				raster_z = raster_z * cosine_x - raster_x * sine_x >> 16;
    				raster_x = j8;
    			}
    			raster_x += start_x;
    			raster_y += start_y;
    			raster_z += depth;
    			int position = raster_z * object_sine_x + raster_x * object_cosine_x >> 16;
    			raster_z = raster_z * object_cosine_x - raster_x * object_sine_x >> 16;
    			raster_x = position;
    			
    			position = raster_y * object_sine_y - raster_z * object_cosine_y >> 16;
    			raster_z = raster_y * object_cosine_y + raster_z * object_sine_y >> 16;
    			raster_y = position;
    			
    			anIntArray1667[index] = raster_z - k2;
    			vertex_viewpoint_z[index] = raster_z;
    			if (raster_z >= 50) {
    				vertex_viewpoint_x[index] = center_x + (raster_x << SceneGraph.viewDistance) / raster_z;
    				vertex_viewpoint_y[index] = center_y + (raster_y << SceneGraph.viewDistance) / raster_z;
    			} else {
    				vertex_viewpoint_x[index] = -5000;
    				in_viewable_raster = true;
    			}
    			if (in_viewable_raster || texture_faces > 0) {
    				texture_viewpoint_x[index] = raster_x;
    				texture_viewpoint_y[index] = raster_y;
    				texture_viewpoint_z[index] = raster_z;
    			}
    		}
    		try {
    			method483(in_viewable_raster, large_object, uid);
    			return;
    		} catch (Exception _ex) {
    			return;
    		}
    	}
    
    	private final void method483(boolean in_viewable_raster, boolean large_object, int uid) {
    		for (int j = 0; j < anInt1652; j++)
    			anIntArray1671[j] = 0;
    
    		for (int face = 0; face < faces; face++) {
    			if (render_type == null || render_type[face] != -1) {
    				int a = edge_a[face];
    				int b = edge_b[face];
    				int c = edge_c[face];
    				int x_a = vertex_viewpoint_x[a];
    				int x_b = vertex_viewpoint_x[b];
    				int x_c = vertex_viewpoint_x[c];
    				if (in_viewable_raster && (x_a == -5000 || x_b == -5000 || x_c == -5000)) {
    					aBooleanArray1664[face] = true;
    					int j5 = (anIntArray1667[a] + anIntArray1667[b] + anIntArray1667[c]) / 3 + anInt1653;
    					anIntArrayArray1672[j5][anIntArray1671[j5]++] = face;
    				} else {
    					if (large_object && method486(anInt1685, anInt1686, vertex_viewpoint_y[a], vertex_viewpoint_y[b], vertex_viewpoint_y[c], x_a, x_b, x_c)) {
    						objectsInCurrentRegion[anInt1687++] = uid;
    						large_object = false;
    					}
    					if ((x_a - x_b) * (vertex_viewpoint_y[c] - vertex_viewpoint_y[b]) - (vertex_viewpoint_y[a] - vertex_viewpoint_y[b]) * (x_c - x_b) > 0) {
    						aBooleanArray1664[face] = false;
    						if (x_a < 0 || x_b < 0 || x_c < 0 || x_a > Raster.centerX || x_b > Raster.centerX || x_c > Raster.centerX)
    							aBooleanArray1663[face] = true;
    						else
    							aBooleanArray1663[face] = false;
    						
    						int k5 = (anIntArray1667[a] + anIntArray1667[b] + anIntArray1667[c]) / 3 + anInt1653;
    						anIntArrayArray1672[k5][anIntArray1671[k5]++] = face;
    					}
    				}
    			}
    		}
    		if (render_priorities == null) {
    			for (int i1 = anInt1652 - 1; i1 >= 0; i1--) {
    				int l1 = anIntArray1671[i1];
    				if (l1 > 0) {
    					int ai[] = anIntArrayArray1672[i1];
    					for (int j3 = 0; j3 < l1; j3++)
    						method484(ai[j3]);
    
    				}
    			}
    			return;
    		}
    		for (int j1 = 0; j1 < 12; j1++) {
    			anIntArray1673[j1] = 0;
    			anIntArray1677[j1] = 0;
    		}
    		for (int i2 = anInt1652 - 1; i2 >= 0; i2--) {
    			int k2 = anIntArray1671[i2];
    			if (k2 > 0) {
    				int ai1[] = anIntArrayArray1672[i2];
    				for (int i4 = 0; i4 < k2; i4++) {
    					int l4 = ai1[i4];
    					byte l5 = render_priorities[l4];
    					int j6 = anIntArray1673[l5]++;
    					anIntArrayArray1674[l5][j6] = l4;
    					if (l5 < 10)
    						anIntArray1677[l5] += i2;
    					else if (l5 == 10)
    						anIntArray1675[j6] = i2;
    					else
    						anIntArray1676[j6] = i2;
    				}
    
    			}
    		}
    
    		int l2 = 0;
    		if (anIntArray1673[1] > 0 || anIntArray1673[2] > 0)
    			l2 = (anIntArray1677[1] + anIntArray1677[2]) / (anIntArray1673[1] + anIntArray1673[2]);
    		int k3 = 0;
    		if (anIntArray1673[3] > 0 || anIntArray1673[4] > 0)
    			k3 = (anIntArray1677[3] + anIntArray1677[4]) / (anIntArray1673[3] + anIntArray1673[4]);
    		int j4 = 0;
    		if (anIntArray1673[6] > 0 || anIntArray1673[8] > 0)
    			j4 = (anIntArray1677[6] + anIntArray1677[8]) / (anIntArray1673[6] + anIntArray1673[8]);
    		
    		int i6 = 0;
    		int k6 = anIntArray1673[10];
    		int ai2[] = anIntArrayArray1674[10];
    		int ai3[] = anIntArray1675;
    		if (i6 == k6) {
    			i6 = 0;
    			k6 = anIntArray1673[11];
    			ai2 = anIntArrayArray1674[11];
    			ai3 = anIntArray1676;
    		}
    		int i5;
    		if (i6 < k6)
    			i5 = ai3[i6];
    		else
    			i5 = -1000;
    		
    		for (int l6 = 0; l6 < 10; l6++) {
    			while (l6 == 0 && i5 > l2) {
    				method484(ai2[i6++]);
    				if (i6 == k6 && ai2 != anIntArrayArray1674[11]) {
    					i6 = 0;
    					k6 = anIntArray1673[11];
    					ai2 = anIntArrayArray1674[11];
    					ai3 = anIntArray1676;
    				}
    				if (i6 < k6)
    					i5 = ai3[i6];
    				else
    					i5 = -1000;
    			}
    			while (l6 == 3 && i5 > k3) {
    				method484(ai2[i6++]);
    				if (i6 == k6 && ai2 != anIntArrayArray1674[11]) {
    					i6 = 0;
    					k6 = anIntArray1673[11];
    					ai2 = anIntArrayArray1674[11];
    					ai3 = anIntArray1676;
    				}
    				if (i6 < k6)
    					i5 = ai3[i6];
    				else
    					i5 = -1000;
    			}
    			while (l6 == 5 && i5 > j4) {
    				method484(ai2[i6++]);
    				if (i6 == k6 && ai2 != anIntArrayArray1674[11]) {
    					i6 = 0;
    					k6 = anIntArray1673[11];
    					ai2 = anIntArrayArray1674[11];
    					ai3 = anIntArray1676;
    				}
    				if (i6 < k6)
    					i5 = ai3[i6];
    				else
    					i5 = -1000;
    			}
    			int i7 = anIntArray1673[l6];
    			int ai4[] = anIntArrayArray1674[l6];
    			for (int j7 = 0; j7 < i7; j7++)
    				method484(ai4[j7]);
    
    		}
    		while (i5 != -1000) {
    			method484(ai2[i6++]);
    			if (i6 == k6 && ai2 != anIntArrayArray1674[11]) {
    				i6 = 0;
    				ai2 = anIntArrayArray1674[11];
    				k6 = anIntArray1673[11];
    				ai3 = anIntArray1676;
    			}
    			if (i6 < k6)
    				i5 = ai3[i6];
    			else
    				i5 = -1000;
    		}
    		for (int m = 0; m < vertices; m++) {
    			int n = m;
    
    			int pid = particle_vertices[n] - 1;
    			if (pid < 0)
    				continue;
    			// n = 150;
    			ParticleDefinition def = ParticleDefinition.cache[pid];
    			int pX = vertexX[m];
    			int pY = vertexY[m];
    			int pZ = vertexZ[m];
    			int pZbuffer = vertex_viewpoint_z[m];
    			if (model_orientation != 0) {
    				int sine = Model.SINE[model_orientation];
    				int cosine = Model.COSINE[model_orientation];
    				int rotatedX = (pZ * sine + pX * cosine >> 16);
    				pZ = (pZ * cosine - pX * sine >> 16);
    				pX = rotatedX;
    			}
    			pX += offX;
    			//pY -= offY;
    			pZ += offZ;
    			/*if (pid == 2 || pid == 3) {
    				pY -= 11;
    			}*/
    			Vector basePos = new Vector(pX, -pY, pZ);
    			for (int p = 0; p < def.getSpawnRate(); p++) {
    				Particle particle = new Particle(def, basePos, pZbuffer, pid);
    				Client.instance.addParticle(particle);
    			}
    		}
    	}
    	
    	private final void method484(int face) {
    		if (aBooleanArray1664[face]) {
    			method485(face);
    			return;
    		}
    		int a = edge_a[face];
    		int b = edge_b[face];
    		int c = edge_c[face];
    		Rasterizer.aBoolean1462 = aBooleanArray1663[face];
    		if (alpha == null)
    			Rasterizer.anInt1465 = 0;
    		else
    			Rasterizer.anInt1465 = alpha[face] & 0xff;
    		
    		int type;
    		if (render_type == null)
    			type = 0;
    		else
    			type = render_type[face] & 3;
    		
    		if(texture != null && texture[face] != -1) {
    			int texture_a = a;
    			int texture_b = b;
    			int texture_c = c;
    			if(texture_coordinates != null && texture_coordinates[face] != -1) {
    				int coordinate = texture_coordinates[face] & 0xff;
    				texture_a = texture_edge_a[coordinate];
    				texture_b = texture_edge_b[coordinate];
    				texture_c = texture_edge_c[coordinate];
    			}
    			if(hue_c[face] == -1 || type == 3) {
    				//havent seen/found any texture that uses this?
    				Rasterizer.drawTexturedTriangle(
    					vertex_viewpoint_y[a], vertex_viewpoint_y[b], vertex_viewpoint_y[c], 
    					vertex_viewpoint_x[a], vertex_viewpoint_x[b], vertex_viewpoint_x[c], 
    					hue_a[face], hue_a[face], hue_a[face], 
    					texture_viewpoint_x[texture_a], texture_viewpoint_x[texture_b], texture_viewpoint_x[texture_c],
    					texture_viewpoint_y[texture_a], texture_viewpoint_y[texture_b], texture_viewpoint_y[texture_c], 
    					texture_viewpoint_z[texture_a], texture_viewpoint_z[texture_b], texture_viewpoint_z[texture_c],
    					texture[face], 
    					vertex_viewpoint_z[a], vertex_viewpoint_z[b], vertex_viewpoint_z[c]);
    			} else {
    				Rasterizer.drawTexturedTriangle(
    					vertex_viewpoint_y[a], vertex_viewpoint_y[b], vertex_viewpoint_y[c], 
    					vertex_viewpoint_x[a], vertex_viewpoint_x[b],vertex_viewpoint_x[c], 
    					hue_a[face], hue_b[face], hue_c[face], 
    					texture_viewpoint_x[texture_a], texture_viewpoint_x[texture_b], texture_viewpoint_x[texture_c],
    					texture_viewpoint_y[texture_a], texture_viewpoint_y[texture_b], texture_viewpoint_y[texture_c], 
    					texture_viewpoint_z[texture_a], texture_viewpoint_z[texture_b], texture_viewpoint_z[texture_c],
    					texture[face], 
    					vertex_viewpoint_z[a], vertex_viewpoint_z[b], vertex_viewpoint_z[c]);
    			} 
    		} else {
    			if (type == 0) {
    				Rasterizer.drawShadedTriangle(vertex_viewpoint_y[a], vertex_viewpoint_y[b],
    						vertex_viewpoint_y[c], vertex_viewpoint_x[a], vertex_viewpoint_x[b],
    						vertex_viewpoint_x[c], hue_a[face], hue_b[face],
    						hue_c[face], vertex_viewpoint_z[a], vertex_viewpoint_z[b], vertex_viewpoint_z[c]);
    				return;
    			}
    			if (type == 1) {
    				Rasterizer.drawFlatTriangle(
    					vertex_viewpoint_x[a], vertex_viewpoint_x[b], vertex_viewpoint_x[c], 
    					vertex_viewpoint_y[a], vertex_viewpoint_y[b], vertex_viewpoint_y[c], modelIntArray3[hue_a[face]], vertex_viewpoint_z[a], vertex_viewpoint_z[b], vertex_viewpoint_z[c]);
    				
    				
    				return;
    			}
    		}
    	}
    
    	private final void method485(int face) {
    		int center_x = Rasterizer.textureInt1;
    		int center_y = Rasterizer.textureInt2;
    		int l = 0;
    		int a = edge_a[face];
    		int b = edge_b[face];
    		int c = edge_c[face];
    		int l1 = texture_viewpoint_z[a];
    		int i2 = texture_viewpoint_z[b];
    		int j2 = texture_viewpoint_z[c];
    		if (l1 >= 50) {
    			anIntArray1678[l] = vertex_viewpoint_x[a];
    			anIntArray1679[l] = vertex_viewpoint_y[a];
    			anIntArray1680[l++] = hue_a[face];
    		} else {
    			int k2 = texture_viewpoint_x[a];
    			int k3 = texture_viewpoint_y[a];
    			int k4 = hue_a[face];
    			if (j2 >= 50) {
    				int k5 = (50 - l1) * modelIntArray4[j2 - l1];
    				anIntArray1678[l] = center_x + (k2 + ((texture_viewpoint_x[c] - k2) * k5 >> 16) << SceneGraph.viewDistance) / 50;
    				anIntArray1679[l] = center_y + (k3 + ((texture_viewpoint_y[c] - k3) * k5 >> 16) << SceneGraph.viewDistance) / 50;
    				anIntArray1680[l++] = k4 + ((hue_c[face] - k4) * k5 >> 16);
    			}
    			if (i2 >= 50) {
    				int l5 = (50 - l1) * modelIntArray4[i2 - l1];
    				anIntArray1678[l] = center_x + (k2 + ((texture_viewpoint_x[b] - k2) * l5 >> 16) << SceneGraph.viewDistance) / 50;
    				anIntArray1679[l] = center_y + (k3 + ((texture_viewpoint_y[b] - k3) * l5 >> 16) << SceneGraph.viewDistance) / 50;
    				anIntArray1680[l++] = k4 + ((hue_b[face] - k4) * l5 >> 16);
    			}
    		}
    		if (i2 >= 50) {
    			anIntArray1678[l] = vertex_viewpoint_x[b];
    			anIntArray1679[l] = vertex_viewpoint_y[b];
    			anIntArray1680[l++] = hue_b[face];
    		} else {
    			int l2 = texture_viewpoint_x[b];
    			int l3 = texture_viewpoint_y[b];
    			int l4 = hue_b[face];
    			if (l1 >= 50) {
    				int i6 = (50 - i2) * modelIntArray4[l1 - i2];
    				anIntArray1678[l] = center_x + (l2 + ((texture_viewpoint_x[a] - l2) * i6 >> 16) << SceneGraph.viewDistance) / 50;
    				anIntArray1679[l] = center_y + (l3 + ((texture_viewpoint_y[a] - l3) * i6 >> 16) << SceneGraph.viewDistance) / 50;
    				anIntArray1680[l++] = l4 + ((hue_a[face] - l4) * i6 >> 16);
    			}
    			if (j2 >= 50) {
    				int j6 = (50 - i2) * modelIntArray4[j2 - i2];
    				anIntArray1678[l] = center_x + (l2 + ((texture_viewpoint_x[c] - l2) * j6 >> 16) << SceneGraph.viewDistance) / 50;
    				anIntArray1679[l] = center_y + (l3 + ((texture_viewpoint_y[c] - l3) * j6 >> 16) << SceneGraph.viewDistance) / 50;
    				anIntArray1680[l++] = l4 + ((hue_c[face] - l4) * j6 >> 16);
    			}
    		}
    		if (j2 >= 50) {
    			anIntArray1678[l] = vertex_viewpoint_x[c];
    			anIntArray1679[l] = vertex_viewpoint_y[c];
    			anIntArray1680[l++] = hue_c[face];
    		} else {
    			int i3 = texture_viewpoint_x[c];
    			int i4 = texture_viewpoint_y[c];
    			int i5 = hue_c[face];
    			if (i2 >= 50) {
    				int k6 = (50 - j2) * modelIntArray4[i2 - j2];
    				anIntArray1678[l] = center_x + (i3 + ((texture_viewpoint_x[b] - i3) * k6 >> 16) << SceneGraph.viewDistance) / 50;
    				anIntArray1679[l] = center_y + (i4 + ((texture_viewpoint_y[b] - i4) * k6 >> 16) << SceneGraph.viewDistance) / 50;
    				anIntArray1680[l++] = i5 + ((hue_b[face] - i5) * k6 >> 16);
    			}
    			if (l1 >= 50) {
    				int l6 = (50 - j2) * modelIntArray4[l1 - j2];
    				anIntArray1678[l] = center_x + (i3 + ((texture_viewpoint_x[a] - i3) * l6 >> 16) << SceneGraph.viewDistance) / 50;
    				anIntArray1679[l] = center_y + (i4 + ((texture_viewpoint_y[a] - i4) * l6 >> 16) << SceneGraph.viewDistance) / 50;
    				anIntArray1680[l++] = i5 + ((hue_a[face] - i5) * l6 >> 16);
    			}
    		}
    		int y_a = anIntArray1678[0];
    		int y_b = anIntArray1678[1];
    		int y_c = anIntArray1678[2];
    		int x_a = anIntArray1679[0];
    		int x_b = anIntArray1679[1];
    		int x_c = anIntArray1679[2];
    		if ((y_a - y_b) * (x_c - x_b) - (x_a - x_b) * (y_c - y_b) > 0) {
    			Rasterizer.aBoolean1462 = false;
    			int texture_a = a;
    			int texture_b = b;
    			int texture_c = c;
    			if (l == 3) {
    				if (y_a < 0 || y_b < 0 || y_c < 0 || y_a > Raster.centerX || y_b > Raster.centerX || y_c > Raster.centerX)
    					Rasterizer.aBoolean1462 = true;
    				
    				int type;
    				if (render_type == null)
    					type = 0;
    				else
    					type = render_type[face] & 3;
    				
    				if(texture != null && texture[face] != -1) {
    					if(texture_coordinates != null && texture_coordinates[face] != -1) {
    						int coordinate = texture_coordinates[face] & 0xff;
    						texture_a = texture_edge_a[coordinate];
    						texture_b = texture_edge_b[coordinate];
    						texture_c = texture_edge_c[coordinate];
    					}
    					if(hue_c[face] == -1) {
    						Rasterizer.drawTexturedTriangle(
    							x_a, x_b, x_c, 
    							y_a, y_b, y_c,
    							hue_a[face], hue_a[face], hue_a[face], 
    							texture_viewpoint_x[texture_a], texture_viewpoint_x[texture_b], texture_viewpoint_x[texture_c],
    							texture_viewpoint_y[texture_a], texture_viewpoint_y[texture_b], texture_viewpoint_y[texture_c], 
    							texture_viewpoint_z[texture_a], texture_viewpoint_z[texture_b], texture_viewpoint_z[texture_c],
    							texture[face], 
    							vertex_viewpoint_z[a], vertex_viewpoint_z[b], vertex_viewpoint_z[c]);
    					} else {
    						Rasterizer.drawTexturedTriangle(
    							x_a, x_b, x_c, 
    							y_a, y_b, y_c,
    							anIntArray1680[0], anIntArray1680[1], anIntArray1680[2], 
    							texture_viewpoint_x[texture_a], texture_viewpoint_x[texture_b], texture_viewpoint_x[texture_c],
    							texture_viewpoint_y[texture_a], texture_viewpoint_y[texture_b], texture_viewpoint_y[texture_c], 
    							texture_viewpoint_z[texture_a], texture_viewpoint_z[texture_b], texture_viewpoint_z[texture_c], 
    							texture[face], 
    							vertex_viewpoint_z[a], vertex_viewpoint_z[b], vertex_viewpoint_z[c]);
    					}
    				} else {
    					if (type == 0)
    						Rasterizer.drawShadedTriangle(x_a, x_b, x_c, y_a, y_b, y_c, anIntArray1680[0], anIntArray1680[1], anIntArray1680[2], -1f, -1f, -1f);
    							
    					else if (type == 1)
    						Rasterizer.drawFlatTriangle(x_a, x_b, x_c, y_a, y_b, y_c, modelIntArray3[hue_a[face]], -1f, -1f, -1f);
    				}
    			}
    			if (l == 4) {
    				if (y_a < 0 || y_b < 0 || y_c < 0 || y_a > Raster.centerX || y_b > Raster.centerX || y_c > Raster.centerX || anIntArray1678[3] < 0 || anIntArray1678[3] > Raster.centerX)
    					Rasterizer.aBoolean1462 = true;
    				int type;
    				if (render_type == null)
    					type = 0;
    				else
    					type = render_type[face] & 3;
    				
    				if(texture != null && texture[face] != -1) {
    					if(texture_coordinates != null && texture_coordinates[face] != -1) {
    						int coordinate = texture_coordinates[face] & 0xff;
    						texture_a = texture_edge_a[coordinate];
    						texture_b = texture_edge_b[coordinate];
    						texture_c = texture_edge_c[coordinate];
    					}
    					if(hue_c[face] == -1) {
    						Rasterizer.drawTexturedTriangle(
    							x_a, x_b, x_c, 
    							y_a, y_b, y_c,
    							hue_a[face], hue_a[face], hue_a[face], 
    							texture_viewpoint_x[texture_a], texture_viewpoint_x[texture_b], texture_viewpoint_x[texture_c],
    							texture_viewpoint_y[texture_a], texture_viewpoint_y[texture_b], texture_viewpoint_y[texture_c], 
    							texture_viewpoint_z[texture_a], texture_viewpoint_z[texture_b], texture_viewpoint_z[texture_c],
    							texture[face], 
    							vertex_viewpoint_z[a], vertex_viewpoint_z[b], vertex_viewpoint_z[c]);
    						Rasterizer.drawTexturedTriangle(
    							x_a, x_c, anIntArray1679[3], 
    							y_a, y_c, anIntArray1678[3], 
    							hue_a[face], hue_a[face], hue_a[face],
    							texture_viewpoint_x[texture_a], texture_viewpoint_x[texture_b], texture_viewpoint_x[texture_c], 
    							texture_viewpoint_y[texture_a], texture_viewpoint_y[texture_b], texture_viewpoint_y[texture_c],
    							texture_viewpoint_z[texture_a], texture_viewpoint_z[texture_b], texture_viewpoint_z[texture_c], 
    							texture[face], 
    							vertex_viewpoint_z[a], vertex_viewpoint_z[b], vertex_viewpoint_z[c]);
    					} else {
    						Rasterizer.drawTexturedTriangle(
    							x_a, x_b, x_c, 
    							y_a, y_b, y_c,
    							anIntArray1680[0], anIntArray1680[1], anIntArray1680[2], 
    							texture_viewpoint_x[texture_a], texture_viewpoint_x[texture_b], texture_viewpoint_x[texture_c],
    							texture_viewpoint_y[texture_a], texture_viewpoint_y[texture_b], texture_viewpoint_y[texture_c],
    							texture_viewpoint_z[texture_a], texture_viewpoint_z[texture_b], texture_viewpoint_z[texture_c],
    							texture[face], 
    							vertex_viewpoint_z[a], vertex_viewpoint_z[b], vertex_viewpoint_z[c]);
    						Rasterizer.drawTexturedTriangle(
    							x_a, x_c, anIntArray1679[3],
    							y_a, y_c, anIntArray1678[3], 
    							anIntArray1680[0], anIntArray1680[2], anIntArray1680[3],
    							texture_viewpoint_x[texture_a], texture_viewpoint_x[texture_b], texture_viewpoint_x[texture_c], 
    							texture_viewpoint_y[texture_a], texture_viewpoint_y[texture_b], texture_viewpoint_y[texture_c],
    							texture_viewpoint_z[texture_a], texture_viewpoint_z[texture_b], texture_viewpoint_z[texture_c], 
    							texture[face], 
    							vertex_viewpoint_z[a], vertex_viewpoint_z[b], vertex_viewpoint_z[c]);
    						return;
    					}
    				} else {
    					if (type == 0) {
    						Rasterizer.drawShadedTriangle(x_a, x_b, x_c, y_a, y_b, y_c, anIntArray1680[0], anIntArray1680[1], anIntArray1680[2], -1f, -1f, -1f);
    						Rasterizer.drawShadedTriangle(x_a, x_c, anIntArray1679[3], y_a, y_c, anIntArray1678[3], anIntArray1680[0], anIntArray1680[2], anIntArray1680[3], vertex_viewpoint_z[a], vertex_viewpoint_z[b], vertex_viewpoint_z[c]);
    						return;
    					}
    					if (type == 1) {
    						int l8 = modelIntArray3[hue_a[face]];
    						Rasterizer.drawFlatTriangle(x_a, x_b, x_c, y_a, y_b, y_c, l8, -1f, -1f, -1f);
    						Rasterizer.drawFlatTriangle(x_a, x_c, anIntArray1679[3], y_a, y_c, anIntArray1678[3], l8, vertex_viewpoint_z[a], vertex_viewpoint_z[b], vertex_viewpoint_z[c]);
    						return;
    					}
    				}
    			}
    		}
    	}
    
    	private final boolean method486(int i, int j, int k, int l, int i1, int x_a, int x_b, int x_c) {
    		if (j < k && j < l && j < i1)
    			return false;
    		if (j > k && j > l && j > i1)
    			return false;
    		if (i < x_a && i < x_b && i < x_c)
    			return false;
    		return i <= x_a || i <= x_b || i <= x_c;
    	}
    
    	//*Added*//
    	public int offX = 0;
    	public int offY = 0;
    	public int offZ = 0;
    	public int model_orientation = 0;
    	public short[] texture;
    	public byte[] texture_coordinates;
    	public byte[] texture_type;
    	public int[] particle_vertices;
    	
    	//*Default*//
    	private boolean aBoolean1618;
    	public static int anInt1620;
    	public static Model EMPTY_MODEL = new Model(true);
    	private static int anIntArray1622[] = new int[2000];
    	private static int anIntArray1623[] = new int[2000];
    	private static int anIntArray1624[] = new int[2000];
    	private static int anIntArray1625[] = new int[2000];
    	public int vertices;
    	public int vertexX[];
    	public int vertexY[];
    	public int vertexZ[];
    	public int faces;
    	public int edge_a[];
    	public int edge_b[];
    	public int edge_c[];
    	public int hue_a[];
    	public int hue_b[];
    	public int hue_c[];
    	public int render_type[];
    	public byte render_priorities[];
    	public int alpha[];
    	public short color[];
    	public byte priority = 0;
    	public int texture_faces;
    	public short texture_edge_a[];
    	public short texture_edge_b[];
    	public short texture_edge_c[];
    	public int anInt1646;
    	public int anInt1647;
    	public int anInt1648;
    	public int anInt1649;
    	public int anInt1650;
    	public int anInt1651;
    	public int anInt1652;
    	public int anInt1653;
    	public int anInt1654;
    	public int vSkin[];//bones 
    	public int tSkin[];//muscle
    	public int vertex_skin[][];
    	public int face_skin[][];
    	public boolean fits_on_single_square;
    	public Vertex gouraud_vertex[];
    	static ModelHeader header[];
    	static Provider resourceProvider;
    	static boolean aBooleanArray1663[] = new boolean[4700];
    	static boolean aBooleanArray1664[] = new boolean[4700];
    	static int vertex_viewpoint_x[] = new int[4700];
    	static int vertex_viewpoint_y[] = new int[4700];
    	static int vertex_viewpoint_z[] = new int[4700];
    	static int anIntArray1667[] = new int[4700];
    	static int texture_viewpoint_x[] = new int[4700];
    	static int texture_viewpoint_y[] = new int[4700];
    	static int texture_viewpoint_z[] = new int[4700];
    	static int anIntArray1671[] = new int[1600];//1500
    	static int anIntArrayArray1672[][] = new int[1600][512];//1500
    	static int anIntArray1673[] = new int[12];
    	static int anIntArrayArray1674[][] = new int[12][2000];//1500
    	static int anIntArray1675[] = new int[2000];//1500
    	static int anIntArray1676[] = new int[2000];//1500
    	static int anIntArray1677[] = new int[12];
    	static int anIntArray1678[] = new int[10];
    	static int anIntArray1679[] = new int[10];
    	static int anIntArray1680[] = new int[10];
    	static int anInt1681;
    	static int anInt1682;
    	static int anInt1683;
    	public static boolean objectExists;
    	public static int anInt1685;
    	public static int anInt1686;
    	public static int anInt1687;
    	public static int objectsInCurrentRegion[] = new int[1000];
    	public static int SINE[];
    	public static int COSINE[];
    	static int modelIntArray3[];
    	static int modelIntArray4[];
    
    	static {
    		SINE = Rasterizer.anIntArray1470;
    		COSINE = Rasterizer.COSINE;
    		modelIntArray3 = Rasterizer.anIntArray1482;
    		modelIntArray4 = Rasterizer.anIntArray1469;
    	}
    	
    }
    Here are a few edits I made,

    In your drawTexturedTriangle, add this and make sure to close the {} at the very bottom
    Code:
    		int texture[] = getTexturePixels(k4);
    		if(texture == null) {
    			drawShadedTriangle(y_a, y_b, y_c, x_a, x_b, x_c, k1, l1, i2, z_a, z_b, z_c);
    		} else {
    In your ObjectDefinition class,
    Code:
    		objectDef.readValues(stream);
    		if(objectDef.type > 14500) {//fixes 'black' objects without ruining gouraud shadowing 
    			//I guessed this Id but it should be the last id of the 377 object list
    			if(objectDef.delayShading == true)
    				objectDef.delayShading = false;
    		}
    If your client also uses the rubbish lighting that Lost Valentino decided was good, replace it with the default values
    Code:
    model_3.light(ambientLighting + 64, 768 + lightDiffusion, -50, -10, -50, !delayShading);
    Code:
    else if (opcode == 22)
    	delayShading = true;


    Should be it, if ya get any errors you know what to do.

    Spoiler for Bugs:

    Shadows 'turn' with your camera, and on certain object types they look inverted. Pretty sure that's to do with the scan line but too lazy to fuck with it.

    Spoiler for hint:

    Code:
    vertex_viewpoint_y
    swap with
    Code:
    vertex_viewpoint_x
    in type == 1
    All content I release is NOT to be SOLD or offered as a SERVICE. Please respect my wishes, as my releases are free to use. Thank you.


    ~[Only registered and activated users can see links. ]
    Reply With Quote  
     


  2. #2  
    Registered Member

    Join Date
    Apr 2014
    Posts
    1,415
    Thanks given
    38
    Thanks received
    503
    Rep Power
    563
    Code:
    if ((flag & 0x2) != 0) {
    					texture_coordinates[face] = (byte) (flag >> 2);
    					texture[face] = color[face];
    					color[face] = 127;
    					if (texture[face] != -1)
    						has_texture_type = true;
    					
    					if(texture[face] == 53) //frozen whip 
    						texture[face] = 1;
    					else
    					if(texture[face] == 56) //lava dragon 
    						texture[face] = 41;
    					else
    					if(texture[face] > 51) 
    						texture[face] = 1;
    					
    				} else {
    					texture_coordinates[face] = -1;
    					texture[face] =  -1;
    				}
    Why not just pack the new textures images?

    Good work on this though.


    One day, I wish I could be on his level.
    Reply With Quote  
     

  3. #3  
    Registered Member
    Deku's Avatar
    Join Date
    May 2016
    Posts
    136
    Thanks given
    32
    Thanks received
    70
    Rep Power
    100
    Quote Originally Posted by Zion View Post
    Code:
    if ((flag & 0x2) != 0) {
    					texture_coordinates[face] = (byte) (flag >> 2);
    					texture[face] = color[face];
    					color[face] = 127;
    					if (texture[face] != -1)
    						has_texture_type = true;
    					
    					if(texture[face] == 53) //frozen whip 
    						texture[face] = 1;
    					else
    					if(texture[face] == 56) //lava dragon 
    						texture[face] = 41;
    					else
    					if(texture[face] > 51) 
    						texture[face] = 1;
    					
    				} else {
    					texture_coordinates[face] = -1;
    					texture[face] =  -1;
    				}
    Why not just pack the new textures images?

    Good work on this though.
    It's there for the snippet, if ya don't need it remove it.
    Personally texture 53 looks like aids, so I would recommend leaving that, but only in decode_new

    Also minor edit, this is a fix for npc/player - can't edit main post
    Spoiler for Fix texture coordinates for npcs / players:
    Code:
    	/*public Model(int length, Model model_segments[]) {
    		this(length, model_segments, false);
    	}*///uncomment AFTER adding the true flag to player / object calls
    	
    	public Model(int length, Model model_segments[], boolean check) {
    		try {
    			aBoolean1618 = true;
    			fits_on_single_square = false;
    			anInt1620++;
    			boolean type_flag = false;
    			boolean priority_flag = false;
    			boolean alpha_flag = false;
    			boolean tSkin_flag = false;
    			boolean color_flag = false;
    			boolean texture_flag = false;
    			boolean coordinate_flag = false;
    			vertices = 0;
    			faces = 0;
    			texture_faces = 0;
    			priority = -1;
    			Model build;
    			for (int segment_index = 0; segment_index < length; segment_index++) {
    				build = model_segments[segment_index];
    				if (build != null) {
    					vertices += build.vertices;
    					faces += build.faces;
    					texture_faces += build.texture_faces;
    					type_flag |= build.render_type != null;
    					alpha_flag |= build.alpha != null;
    					if (build.render_priorities != null) {
    						priority_flag = true;
    					} else {
    						if (priority == -1)
    							priority = build.priority;
    						
    						if (priority != build.priority)
    							priority_flag = true;
    					}
    					tSkin_flag |= build.tSkin != null;
    					color_flag |= build.color != null;
    					texture_flag |= build.texture != null;
    					coordinate_flag |= build.texture_coordinates != null;
    				}
    			}
    			particle_vertices = new int[vertices];
    			vertexX = new int[vertices];
    			vertexY = new int[vertices];
    			vertexZ = new int[vertices];
    			vSkin = new int[vertices];
    			edge_a = new int[faces];
    			edge_b = new int[faces];
    			edge_c = new int[faces];
    			if(color_flag)
    				color = new short[faces];
    			
    			if (type_flag)
    				render_type = new int[faces];
    			
    			if (priority_flag)
    				render_priorities = new byte[faces];
    			
    			if (alpha_flag)
    				alpha = new int[faces];
    			
    			if (tSkin_flag)
    				tSkin = new int[faces];
    			
    			if(texture_flag)
    				texture = new short[faces];
    			
    			if (coordinate_flag)
    				texture_coordinates = new byte[faces];
    			
    			if(texture_faces > 0) {
    				texture_type = new byte[texture_faces];
    				texture_edge_a = new short[texture_faces];
    				texture_edge_b = new short[texture_faces];
    				texture_edge_c = new short[texture_faces];
    			}
    			vertices = 0;
    			faces = 0;
    			texture_faces = 0;
    			for (int segment_index = 0; segment_index < length; segment_index++) {
    				build = model_segments[segment_index];
    				if (build != null) {
    					for (int face = 0; face < build.faces; face++) {
    						/*if (type_flag) {
    							if (build.render_type == null) {
    								render_type[faces] = 0;
    							} else {
    								int type = build.render_type[face];
    								if ((type & 2) == 2)
    									type += texture_face << 2;
    								
    								render_type[faces] = type;
    							}
    						}*/
    						if(type_flag && build.render_type != null)
    							render_type[faces] = build.render_type[face];
    						
    						if (priority_flag)
    							if (build.render_priorities == null)
    								render_priorities[faces] = build.priority;
    							else
    								render_priorities[faces] = build.render_priorities[face];
    						
    						if (alpha_flag && build.alpha != null)
    							alpha[faces] = build.alpha[face];
    
    						if (tSkin_flag && build.tSkin != null)
    							tSkin[faces] = build.tSkin[face];
    						
    						if(texture_flag) {
    							if(build.texture != null) 
    								texture[faces] = build.texture[face];
    							else
    								texture[faces] = -1;
    						}
    						if(coordinate_flag) {
    							if(build.texture_coordinates != null && build.texture_coordinates[face] != -1) {
    								texture_coordinates[faces] = (byte) (build.texture_coordinates[face] + texture_faces);
    							} else {
    								texture_coordinates[faces] = -1;
    							}
    						}
    						color[faces] = build.color[face];
    						edge_a[faces] = method465(build, build.edge_a[face]);
    						edge_b[faces] = method465(build, build.edge_b[face]);
    						edge_c[faces] = method465(build, build.edge_c[face]);
    						faces++;
    					}
    					for (int texture_edge = 0; texture_edge < build.texture_faces; texture_edge++) {
    						byte opcode = texture_type[texture_faces] = build.texture_type[texture_edge];
    						if(opcode == 0) {
    							texture_edge_a[texture_faces] = (short) method465(build, build.texture_edge_a[texture_edge]);
    							texture_edge_b[texture_faces] = (short) method465(build, build.texture_edge_b[texture_edge]);
    							texture_edge_c[texture_faces] = (short) method465(build, build.texture_edge_c[texture_edge]);
    							if(check)
    								texture_faces++;
    						}
    						if(opcode >= 1 && opcode <= 3) {
    							texture_edge_a[texture_faces] = build.texture_edge_a[texture_edge];
    							texture_edge_b[texture_faces] = build.texture_edge_b[texture_edge];
    							texture_edge_c[texture_faces] = build.texture_edge_c[texture_edge];
    						}
    						if(opcode == 2) {
    							
    						}
    					}
    					if(!check)
    						texture_faces++;
    				}
    			}
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    Add a 'true' to any player/object calls, for example,
    Code:
    model = new Model(k1, aModelArray741s, true);
    All content I release is NOT to be SOLD or offered as a SERVICE. Please respect my wishes, as my releases are free to use. Thank you.


    ~[Only registered and activated users can see links. ]
    Reply With Quote  
     

  4. #4  
    🎶🎶Why do good girls like bad guys🎶🎶

    i_pk_pjers_i's Avatar
    Join Date
    Feb 2015
    Posts
    1,158
    Thanks given
    3,912
    Thanks received
    433
    Rep Power
    1315
    Nice release, repped.
    [Only registered and activated users can see links. ]
    Vouches (11, many more available upon request): [Only registered and activated users can see links. ]

    LOL : [Only registered and activated users can see links. ]

    Made me smile : [Only registered and activated users can see links. ]

    I'm honored : [Only registered and activated users can see links. ]

    Quote Originally Posted by Idiot Bird View Post
    Quote Originally Posted by Velocity View Post
    lol np mate looks like the community brought ur rep down to ur IQ
    Not too sure about that, it's at 0 . It would have to go minus to even be remotely close to his IQ.
    Reply With Quote  
     

  5. #5  
    Registered Member
    Zivik's Avatar
    Join Date
    Oct 2007
    Age
    22
    Posts
    4,405
    Thanks given
    886
    Thanks received
    1,504
    Rep Power
    5000
    Thanks for the share.
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  6. #6  
    Registered Member TA TA's Avatar
    Join Date
    Apr 2016
    Posts
    357
    Thanks given
    65
    Thanks received
    15
    Rep Power
    0
    Thanks for the share will use for sure!
    Spoiler for Matt/Scandi is awesome LOL:
    Reply With Quote  
     

  7. #7  
    Registered Member

    Join Date
    Apr 2014
    Posts
    1,415
    Thanks given
    38
    Thanks received
    503
    Rep Power
    563
    Would you be upset if I released a full unrenamed version?


    One day, I wish I could be on his level.
    Reply With Quote  
     

  8. #8  
    Registered Member
    Deku's Avatar
    Join Date
    May 2016
    Posts
    136
    Thanks given
    32
    Thanks received
    70
    Rep Power
    100
    Quote Originally Posted by Zivik View Post
    Thanks for the share.
    Quote Originally Posted by TA TA View Post
    Thanks for the share will use for sure!
    Np

    Quote Originally Posted by Zion View Post
    Would you be upset if I released a full unrenamed version?
    Wouldn't bother me, as long I'm credited
    All content I release is NOT to be SOLD or offered as a SERVICE. Please respect my wishes, as my releases are free to use. Thank you.


    ~[Only registered and activated users can see links. ]
    Reply With Quote  
     

  9. #9  
    Registered Member

    Join Date
    Apr 2014
    Posts
    1,415
    Thanks given
    38
    Thanks received
    503
    Rep Power
    563
    Quote Originally Posted by Deku View Post
    Np



    Wouldn't bother me, as long I'm credited
    What is the anti leech?


    One day, I wish I could be on his level.
    Reply With Quote  
     

  10. #10  
    Registered Member
    Deku's Avatar
    Join Date
    May 2016
    Posts
    136
    Thanks given
    32
    Thanks received
    70
    Rep Power
    100
    Quote Originally Posted by Zion View Post
    What is the anti leech?
    Ruins the fun tho :-(
    Here's a hint, has to do with an x and y swap of viewport triangles
    All content I release is NOT to be SOLD or offered as a SERVICE. Please respect my wishes, as my releases are free to use. Thank you.


    ~[Only registered and activated users can see links. ]
    Reply With Quote  
     

Page 1 of 3 123 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 58
    Last Post: 06-10-2017, 07:21 AM
  2. osrs texture support
    By _Patrick_ in forum Buying
    Replies: 1
    Last Post: 10-14-2015, 11:30 PM
  3. Model Texturing Support 317 [Project]
    By OnCue in forum Projects
    Replies: 68
    Last Post: 02-14-2014, 06:54 AM
  4. 508 Model Header with 80% texture support
    By Mr Reece in forum Snippets
    Replies: 10
    Last Post: 12-16-2012, 01:57 PM
  5. [WIP] New(er) Header Texture Support
    By Mr Reece in forum Show-off
    Replies: 13
    Last Post: 11-30-2012, 09:45 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •