预览模式: 普通 | 列表

解析游戏资源文件(附代码)

只因为我们太火

昆仑08年就开始在google用天书奇谈,现在又用龙之刃....真Q

仙域接昆仑的班,用天书奇谈<br/>

查看更多...

分类:Flash Game | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 33

诡异的cacheAsBitmap

public class ScaleImg extends Bitmap{

          public function ScaleImg(bimapData:BitmapData=null,
                        pixelSnapping:String="auto",
                        smoothing:Boolean=false){

                  this.cacheAsBitmap = true;
                  super(bimapData,pixelSnapping,smoothing);

         }

}

测试:

addChild(new ScaleImg());

如果是10.0.32.18之前的Flash Player 直接就crash了,但把this.cacheAsBitmap = true;放在super之后执行,就不会crash。
如果是10.0.32.18之后的版本的放在super前后都可以执行。

不知何故?

为了找到player crash的这个原因纠结了我好久!!!!

备注:
10.0.12.36  flash10a.ocx   2008.11
10.0.22.87  flash10b.ocx   2009.2
10.0.32.18  flash10c.ocx   2009.7
10.0.42.34  flash10d.ocx   2009.12
10.0.45.2    flash10e.ocx   2010.2
10.1            flash10f.ocx 

 

 


找到一个有用信息:
The following issues have been fixed in Flash Player 10.0.22.87:
.........
Setting bitmap width/height before super() crashes player. (FP-760/2216975)
.........

 

 

分类:ActionScript | 固定链接 | 评论: 1 | 引用: 0 | 查看次数: 45

Amf数据分析

前段时间分析了一个网页游戏,美术风格类似梦幻西游,是外包的。分析代码得知,客户端资源做了一些特殊处理,是用通过netconnection发过来的decode的swf来解资源,本地是无缓存,存在内存中,自己如果用模拟的客户端去连服务器, 接受的是只是一个zip压缩的png文件,wpe抓包如下:

看来做了域限制!用原客户端连服务器发的才是真实的decode的swf,一时找不到很好的内存读取工具,.只得用wpe抓包去分析amf3数据了,数据封包图如下:

现RTMP协议,amf0~3数据格式已开源,不难看出找个核心的数据包:

数据包协议头12字节
03表示12字节头,channelid=3,这个是Invoke通道,NetConnection.Call() 是用的找个通道,调用的方法在下面。
00 00 00表示时间戳 Timmer=0
00 31 D9表示数据大小 AMFSize=12761
14表示数据包类型 AMFType=Invoke 方法调用
00 00 00 00 表示StreamID = 0 音视频流的ID
AMF数据
02表示String
0008表示String长度8
6F 6E 42 57 44 6F 6E 65  是String的值onBWDone
00表示Double
40 00 00 00 00 00 00 00 表示double的
05表示 null
0a表示 ARRAY
00 00 05 87 数组长度1415
之后的就是数组里的数据,就是decode的swf数据文件.但这个只是amf序列化字节,还要转化,下面以如何得到arr[0]的值为例分析:
00 表示Double
40 5e 00 00 00 00 00 00 是表示在网络中的字节循序的(符号位在低存储)8字节的IEEE-754双精度浮点数,
那么读的时候就到过来,00 00 00 00 00 00 5e 40。java转换代码如下:
public static void main(String[] args) {
  byte[] b = new byte[8];
  b[0] = 0x00;
  b[1] = 0x00;
  b[2] = 0x00;
  b[3] = 0x00;
  b[4] = 0x00;
  b[5] = 0x00;
  b[6] = 0x5e;
  b[7] = 0x40;
  System.out.println(byteToDouble(b));
 }
//bye转double
public static double byteToDouble(byte[] b){
     long l;
     l=b[0];
     l&=0xff;
     l|=((long)b[1]<<8);
     l&=0xffff;
     l|=((long)b[2]<<16);
     l&=0xffffff;
     l|=((long)b[3]<<24);
     l&=0xffffffff;
     l|=((long)b[4]<<32);
     l&=0xffffffffffl;
     l|=((long)b[5]<<40);
     l&=0xffffffffffffl;
     l|=((long)b[6]<<48);
     l|=((long)b[7]<<56);
     return Double.longBitsToDouble(l);
   }

//当然用这个方法也可以验证一下数据
public static byte[] doubleToByte(double d){
     byte[] b=new byte[8];
     long l=Double.doubleToLongBits(d);
     for(int i=0;i<b.length;i++){
       b[i]=new Long(l).byteValue();
       l=l>>8;
     }
     return b;
  }

如此读1415个double数,得到一个byte[]转为bytearray,uncompress之,得到可以解文件的swf .
注意后续的字节,分了很多个包,用wpe封包后,凑一个完整的包,再读!
 

资料
Amf数据格式
RTMP协议

分类:Flash Game | 固定链接 | 评论: 5 | 引用: 0 | 查看次数: 264

天书多语言版本

简体中文版:http://t.mop.com
英文版:http://neverland.hithere.com/
港/澳/台/新/马版:https://member.runup.com.hk/

更多版本敬请期待.......

分类:Flash Game | 固定链接 | 评论: 1 | 引用: 0 | 查看次数: 211

Flex Builder 3使用air 1.5记录

在Flex Builder3下使用建air项目使用flash builder下的sdk 4,
F11报错
VerifyError: Error #1053: Illegal override of scaleZ in mx.core.UIComponent. at flash.display::MovieClip/nextFrame() .....
解决方法:
1.将项目根目录下的xxx-app.xml的第二行xmlns="http://ns.adobe.com/air/application/1.0" 改为 xmlns="http://ns.adobe.com/air/application/1.5"
2.将.actionScriptProperties中的htmlPlayerVersion="9.0.28"改为htmlPlayerVersion="10.0.0",并设置为只读

分类:life | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 169

pv3d和box2d

以前研究魔术笔的游戏,今日心血来潮仿制了一个pv3d和box2d的小程序,按下鼠标左键右拖动绘制盒子,按下左拖动绘制球,还比较有意思。完整源码下载  

box2d: http://box2dflash.sourceforge.net/

papervision3d: http://www.papervision3d.org

 文件较大,耐心等待... 

代码如下:

package
{
	import Box2D.Collision.Shapes.b2CircleDef;
	import Box2D.Collision.Shapes.b2PolygonDef;
	import Box2D.Collision.Shapes.b2Shape;
	import Box2D.Collision.b2AABB;
	import Box2D.Common.Math.b2Vec2;
	import Box2D.Dynamics.Joints.b2MouseJoint;
	import Box2D.Dynamics.Joints.b2MouseJointDef;
	import Box2D.Dynamics.b2Body;
	import Box2D.Dynamics.b2BodyDef;
	import Box2D.Dynamics.b2DebugDraw;
	import Box2D.Dynamics.b2World;
	
	import General.FpsCounter;
	import General.Input;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.utils.getTimer;
	
	import org.papervision3d.core.effects.view.ReflectionView;
	import org.papervision3d.lights.PointLight3D;
	import org.papervision3d.materials.shadematerials.GouraudMaterial;
	import org.papervision3d.materials.utils.MaterialsList;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.objects.primitives.Cube;
	import org.papervision3d.objects.primitives.Sphere;
	
	[SWF(width="600", height="600", backgroundColor="#000000", frameRate="40")] 
	public class DrawBox extends ReflectionView
	{
		public var w:int = 600,h:int = 600;//视野的宽和高
		public const scale:Number = 30;//缩放比率,box2d中1px = 30m
		protected var iterations:int = 10,timeStep:Number = 1/30;
		protected var world:b2World;
		protected var mouseXWorldPhys:Number,mouseYWorldPhys:Number;
		protected var isDrawing:Boolean = false,isMouseDown:Boolean = false;
        protected var clickX:Number,clickY:Number;//点击开始点
        protected var drawSprite:Sprite = new Sprite();
		
		
		protected var materialsList:MaterialsList;
        protected var light:PointLight3D = new PointLight3D(true);//灯光
        protected var gmaterials:GouraudMaterial ;
        
        static public var m_fpsCounter:FpsCounter = new FpsCounter();
		
		public function DrawBox()
		{  
			//Fps
			m_fpsCounter.x = 7;
			m_fpsCounter.y = 5;
			addChildAt(m_fpsCounter, 0);
			//绘制容器
			addChild(drawSprite);
			
			super(this.w,this.h,true,false,"CAMERA3D");
			  //以舞台正中间的为起点 
			surfaceHeight = -this.h + 110;
			light.x = 1000;light.y = 1000;light.z = -1000;
			this.camera.focus = 10;this.camera.zoom = 100;
			this.gmaterials = new GouraudMaterial(light,0xcc0000,0x111111,10);
			this.materialsList = new MaterialsList({all : gmaterials});
			
			
			//初始包围盒
			var b2aabb:b2AABB = new b2AABB();
            b2aabb.lowerBound.Set(0, 0);
            b2aabb.upperBound.Set(this.w / this.scale, this.h / this.scale);
            //重力
            var g:b2Vec2 = new b2Vec2(0, 10);
            //2d物理世界
            this.world = new b2World(b2aabb, g, true);
            //debug绘制
            //this.setupDebugDraw();
            //地面
            this.createFloor();
            
            for(var i:int = 0; i < 2;i++){
           		this.addCube(Math.random()*20,Math.random()*20,Math.random()*60,Math.random()*60);
            	this.addSphere(Math.random()*60,Math.random()*20,Math.random()*30);
            }
          
            //开始3d的渲染
            this.startRendering();
			//事件初始
			stage.addEventListener(Event.ENTER_FRAME, this.enterFrame);
            stage.addEventListener(MouseEvent.MOUSE_DOWN, this.onMouseDown);
            stage.addEventListener(MouseEvent.MOUSE_MOVE, this.onMouseMove);
            stage.addEventListener(MouseEvent.MOUSE_UP, this.onMouseUp);
		}
		
		//创建所有墙体
		private function createFloor() : void{
			//下
          	createBox(this.w / this.scale / 2, (this.h + 5) / this.scale ,this.w / this.scale / 2, 10 / this.scale);
            //左
            createBox(-5 / this.scale, this.h / this.scale / 2,10 / this.scale, this.h / this.scale / 2);
            //右
            createBox(this.w / this.scale, this.h / this.scale / 2,10 / this.scale, this.h / this.scale / 2);
        }
        //添加3d盒子 
        public function addCube(x:Number,y:Number,bw:Number,bh:Number):void{
        	var body:b2Body = createBox((x + bw / 2) / this.scale, (y + bh / 2) / this.scale ,bw / 2 / this.scale, bh / 2 / this.scale,false);
        	var cube:Cube = new Cube(this.materialsList, bw, (bw + bh) / 2, bh);
            scene.addChild(cube);
            body.m_userData = cube;
        }
        //添加3d球体 
        public function addSphere(x:Number,y:Number,radius:Number):void{
        	var body:b2Body = createCircle(x  / this.scale, y / this.scale , radius ,false);
        	var sphere:Sphere = new Sphere(this.gmaterials, radius);
            scene.addChild(sphere);
            body.m_userData = sphere;
        }
        
        //矩形
        private function createBox(x:Number,y:Number,hx:Number,hy:Number,isSleep:Boolean = true):b2Body{
        	var def:b2PolygonDef  = new b2PolygonDef();
        	if(isSleep == false){
        		def.density = 1;
            	def.friction = 0.7;
            	def.restitution = 0.7;
         	}
            var bodyDef:b2BodyDef  = new b2BodyDef();
            bodyDef.position.Set(x,y);
            def.SetAsBox(hx,hy);
            var body:b2Body = this.world.CreateBody(bodyDef);
            body.CreateShape(def);
            body.SetMassFromShapes();
            return body;
        }
        
        //球
        private function createCircle(x:Number,y:Number,radius:Number,isSleep:Boolean = true):b2Body{
        	var def:b2CircleDef  = new b2CircleDef();
        	if(isSleep == false){
        		def.density = 1;
            	def.friction = 0.7;
            	def.restitution = 0.7;
         	}
         	def.radius = radius / this.scale
            var bodyDef:b2BodyDef  = new b2BodyDef();
            bodyDef.position.Set(x,y);
            var body:b2Body = this.world.CreateBody(bodyDef);
            body.CreateShape(def);
            body.SetMassFromShapes();
            return body;
        }
        
      
        
		//debug绘制刚体等外观轮廓
		public function setupDebugDraw() : void {
            var dbg:Sprite = new Sprite();
            addChild(dbg);
            var dd:b2DebugDraw = new b2DebugDraw();
            dd.m_sprite = dbg;
            dd.m_drawScale = this.scale;
            dd.m_fillAlpha = 0.5;
            dd.m_lineThickness = 1;
            dd.m_drawFlags = b2DebugDraw.e_shapeBit | b2DebugDraw.e_jointBit | b2DebugDraw.e_centerOfMassBit;
            this.world.SetDebugDraw(dd);
        }
		
		//2d物理世界主循环
		public function enterFrame(evt:Event) : void{
			var physStart:uint = getTimer();
			this.updateMouseWorld();
			this.mouseDrag();
		 	this.world.Step(this.timeStep, this.iterations);
		 	 var d3d:DisplayObject3D;
		 	 for (var bb:b2Body = world.m_bodyList; bb; bb = bb.m_next){
                if (bb.m_userData is DisplayObject3D){   
                 	d3d = bb.m_userData as DisplayObject3D;
                 	d3d.x = bb.GetPosition().x * this.scale - this.w * 0.5;
                    d3d.y = (-bb.GetPosition().y) * this.scale + this.h * 0.5 + 50;
                    d3d.rotationZ = (-bb.GetAngle()) * (180 / Math.PI);
                }
    		}
    		this.singleRender();
    		m_fpsCounter.update();
    		m_fpsCounter.updatePhys(physStart);
		}
		
		public function updateMouseWorld() : void{
        	this.mouseXWorldPhys = mouseX / this.scale;
            this.mouseYWorldPhys = mouseY / this.scale;
        }
		
		//开始拖动
		public function onMouseDown(evt:MouseEvent) : void{
		 	this.clickX = mouseX;
            this.clickY = mouseY;
            this.isDrawing = true;
            this.isMouseDown = true;
		}
		//拖动绘制
		public function onMouseMove(evt:MouseEvent) : void{
		 	if (this.isDrawing){
                with(drawSprite){
	                graphics.clear();
	                graphics.beginFill(0xFF0000, 0.5);
	                if (this.clickX > mouseX){
	                    graphics.drawCircle(mouseX, mouseY, Math.min(40, Point.distance(new Point(this.clickX, this.clickY), new Point(mouseX, mouseY)) / 2));
	                }else{
	                    graphics.drawRect(clickX,clickY, Math.min(200, mouseX - this.clickX), Math.min(100, mouseY - this.clickY));
	                }
                }
                this.isMouseDown = false;
            }
		}
		//拖动结束
		public function onMouseUp(evt:MouseEvent) : void{
            if (this.isDrawing){
                if (this.clickX > mouseX){//向左画圆
                    this.addSphere(mouseX, mouseY,drawSprite.width/2);
                }else{//向右画方
                    this.addCube(clickX,clickY,drawSprite.width,drawSprite.height);
                }
                drawSprite.graphics.clear();
                this.isDrawing = false;
            }
            this.isMouseDown = false;
		}
		
		
		
		//拖动选中的3d对象
		public var m_mouseJoint:b2MouseJoint;
		public function mouseDrag():void{
			// mouse press
			if (isMouseDown && !m_mouseJoint){
				var body:b2Body = GetBodyAtMouse();
				if (body){
					this.isDrawing = false;
                    drawSprite.graphics.clear();
					var md:b2MouseJointDef = new b2MouseJointDef();
					md.body1 = world.GetGroundBody();
					md.body2 = body;
					md.target.Set(mouseXWorldPhys, mouseYWorldPhys);
					md.maxForce = 300.0 * body.GetMass();
					md.timeStep = timeStep;
					m_mouseJoint = world.CreateJoint(md) as b2MouseJoint;
					body.WakeUp();
				}
			}
			// mouse release
			if (!isMouseDown){
				if (m_mouseJoint){
					world.DestroyJoint(m_mouseJoint);
					m_mouseJoint = null;
				}
			}
			// mouse move
			if (m_mouseJoint){
				m_mouseJoint.SetTarget(new b2Vec2(mouseXWorldPhys, mouseYWorldPhys));
			}
		}
		
		
		
		//按d键删除选中的3d对象
		public function MouseDestroy():void{
			// mouse press
			if (!this.isMouseDown && Input.isKeyPressed(68/*D*/)){
				var body:b2Body = GetBodyAtMouse(true);
				if (body){
					world.DestroyBody(body);
					return;
				}
			}
		}
		
		//取当前鼠标下刚体
		private var mousePVec:b2Vec2 = new b2Vec2();
		public function GetBodyAtMouse(includeStatic:Boolean=false):b2Body{
			// Make a small box.
			mousePVec.Set(mouseXWorldPhys, mouseYWorldPhys);
			var aabb:b2AABB = new b2AABB();
			aabb.lowerBound.Set(mouseXWorldPhys - 0.001, mouseYWorldPhys - 0.001);
			aabb.upperBound.Set(mouseXWorldPhys + 0.001, mouseYWorldPhys + 0.001);
			
			// Query the world for overlapping shapes.
			var k_maxCount:int = 10;
			var shapes:Array = new Array();
			var count:int = world.Query(aabb, shapes, k_maxCount);
			var body:b2Body = null;
			for (var i:int = 0; i < count; ++i)
			{
				//if (shapes[i].GetBody().IsStatic() == false || includeStatic)
				{
					var tShape:b2Shape = shapes[i] as b2Shape;
					var inside:Boolean = tShape.TestPoint(tShape.GetBody().GetXForm(), mousePVec);
					if (inside){
						body = tShape.GetBody();
						break;
					}
				}
			}
			return body;
		}
		
		
	}
}

查看更多...

分类:ActionScript | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 996

adobe真的要放弃as3吗?

adobe真的要放弃as3吗?详文见:
www.ncannasse.fr/blog/adobe_drop_as3_for_haxe

分类:ActionScript | 固定链接 | 评论: 7 | 引用: 0 | 查看次数: 1169