package com.skysidestudio.skyside3gbyEditor;


import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.MenuItem;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Spinner;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.Toast;

import android.os.Build;
import android.os.StrictMode;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import android.text.InputFilter;


public class Modify_MainActivity extends Activity
{

	public class RCHEAD
	{
		public int ResLen;			/* 资源串总长度 */
		public int ResId;			/* 资源串id */
		public int ItmCnt;			/* 资源项个数 */
		public int ItmLen;			/* 资源项长度(0表示资源项不等长，后面会有资源项索引序列) */
		public int ResKey;			/* 资源串加密钥匙(加密算法统一使用+ResKey) */
		public int Reserved;		/* 保留 */
	};				/* 资源串头定义 */

	public class RIDX
	{

		public int offset;			/* 资源项相对资源起始地址的偏移地址 */
		public int rlen;			/* 资源项的数据长度 */
	}

	public class PictureHead
	{
		public int wid;		/*图片宽*/
		public int hig;		/*图片高*/
		public int count;		/*图片数*/
		public int mask;		/*高4为bpp；(mask & 0x01)为1时为透明图；(mask & 0x02)为0时为横向图，为1时为纵向图*/
	};


	public class HERO
	{
		public byte Id;				/*编号*/
		public byte Belong;			/*归属*/
		public byte Level;			/*等级*/
		public byte Force;			/*武力*/
		public byte IQ;				/*智力*/
		public byte Devotion;			/*忠诚*/
		public byte Character;			/*性格*/
		public byte Experience;			/*经验*/
		public byte Thew;			/*体力*/
		public byte ArmsType;			/*兵种*/
		public short Arms;			/*兵力*/
		public byte[] Equip = new byte[2];			/*装备*/
		public byte Age;				/*年龄*/

		public String name;

		//63
		public byte BornYear;	 //出生年
		public byte SearchId;
		public byte AppearCityId;   //出生城池
	};

	public class CITY
	{
		public byte Id;
		public byte Belong;			/*归属*/
		public byte SatrapId;			/*太守编号*/
		public short FarmingLimit;		/*农业上限*/
		public short Farming;			/*农业开发度*/
		public short CommerceLimit;		/*商业上限*/
		public short Commerce;			/*商业开发度*/
		public byte PeopleDevotion;		/*民忠*/
		public byte AvoidCalamity;		/*防灾*/
		public int PopulationLimit;		/*人口上限*/
		public int Population;			/*人口*/
		public short Money;			/*金钱*/
		public short Food;			/*粮食*/
		public short MothballArms;		/*后备兵力*/
		public byte PersonQueue;			/*人才队列*/
		public byte Persons;			/*人才数*/
		public byte ToolQueue;			/*道具队列*/
		public byte Tools;			/*道具数*/

		public String name;
	};

	public class GOOD
	{
		public byte idx;			/* 道具序号 */
		public byte useflag;		/* 使用标志：是被使用还是被装备*/
		//public byte[] name = new byte[10];		/* 道具名字 */
		//public byte[] inf = new byte[50];		/* 道具说明 */
		public byte at;			/* 对武力的加层 */
		public byte iq;			/* 对智力的加层 */
		public byte move;			/* 对移动力的加层 */
		public byte arm;			/* 对兵种的改变 */

		public String name;

		//67
		public byte AppearYear;
		public byte SearchId;
		public byte AppearCityId;
	};

	byte[] rlbByte = new byte[1048576 + 1];//1M
	byte[][] resByte = new byte[116][1048576];//1M
	int[] resAddress = new int[116];//0-4000h
	int tmpBmpbyteLen = 0;
	RCHEAD[] reshead = new RCHEAD[116];



	HERO[][] hero = new HERO[4][200];
	CITY[][] city = new CITY[4][38];
	GOOD[][] good = new GOOD[4][33];
	String[][] heroname = new String[4][200];
	String[] cityname = new String[38];
	String[] goodname = new String[33];

	byte[] savByte = new byte[3245 + 2708 + 1];
	int savByteLen = 3245 + 2708;
	HERO[] savhero = new HERO[200];
	CITY[] savcity = new CITY[38];
	GOOD[] savgood = new GOOD[33];
	String[] savheroname = new String[200];
	String[] savcityname = new String[38];
	String[] savgoodname = new String[33];
	int savPeriod = 0;
	String g_filename = "";
	String g_filename1 = "";

	byte[][] g_HeroQueue = new byte[4][200];
	byte[][] g_GoodsQueue = new byte[4][33];

	//int[] respicAddress = new int[300];//用于图片在res中相对的起始位置
	int resmax = 0;
	int resselected = 0;
	int respicmax = 0;
	int respicselected = 0;
	boolean saved = false;
	int rlbByteLen = 0;
	//bool edited = false;
	boolean isRlb = true;
	int g_idHero = 0;
	int g_idGood = 0;
	int g_idCity = 0;
	int g_idSavHero = 0;
	int g_idSavCity = 0;
	boolean notSavedHero = false;
	boolean notSavedGood = false;
	boolean notSavedCity = false;
	//bool intialed = false
	boolean noRlb = true;

	boolean isLib = false;
	boolean isSsv = false;

	boolean cannotSave = false;

	Spinner cbxHeroPeriod ;//= (Spinner) findViewById(R.id.cbxHeroPeriod);
	Spinner cbxHeroId;// = (Spinner) findViewById(R.id.cbxHeroId);
	EditText tbxHeroName;// = (EditText) findViewById(R.id.tbxHeroName);
	Spinner cbxHeroBelong;// = (Spinner) findViewById(R.id.cbxHeroBelong);
	EditText tbxHeroDegree;// = (EditText) findViewById(R.id.tbxHeroDegree);
	EditText tbxHeroForce;// = (EditText) findViewById(R.id.tbxHeroForce);
	EditText tbxHeroIQ;// = (EditText) findViewById(R.id.tbxHeroIQ);
	EditText tbxHeroDevotion;// = (EditText) findViewById(R.id.tbxHeroDevotion);
	Spinner cbxHeroCharacter;// = (Spinner) findViewById(R.id.cbxHeroCharacter);
	Spinner cbxHeroArmsType;// = (Spinner) findViewById(R.id.cbxHeroArmsType);
	EditText tbxHeroAge;// = (EditText) findViewById(R.id.tbxHeroAge);
	Spinner cbxHeroEquip1;
	Spinner cbxHeroEquip2;
	EditText tbxHeroBornYear;
	Spinner cbxHeroSearchId;// = (Spinner) findViewById(R.id.cbxHeroSearchId);
	Spinner cbxHeroAppearCityId;// = (Spinner) findViewById(R.id.cbxHeroAppearCityId);
	Button btnSaveHero;// = (Button) findViewById(R.id.btnSaveHero);

	Spinner cbxCityPeriod;// = (Spinner) findViewById(R.id.cbxCityPeriod);
	Spinner cbxCityId;// = (Spinner) findViewById(R.id.cbxCityId);
	EditText tbxCityName;// = (EditText) findViewById(R.id.tbxCityName);
	Spinner cbxCityBelong;// = (Spinner) findViewById(R.id.cbxCityBelong);
	EditText tbxCityPeopleDevotion;// = (EditText) findViewById(R.id.tbxCityPeopleDevotion);
	EditText tbxCityFarmingLimit;// = (EditText) findViewById(R.id.tbxCityFarmingLimit);
	EditText tbxCityFarming;// = (EditText) findViewById(R.id.tbxCityFarming);
	EditText tbxCityCommerceLimit;// = (EditText) findViewById(R.id.tbxCityCommerceLimit);
	EditText tbxCityCommerce;// = (EditText) findViewById(R.id.tbxCityCommerce);
	EditText tbxCityPopulationLimit;// = (EditText) findViewById(R.id.tbxCityPopulationLimit);
	EditText tbxCityPopulation;// = (EditText) findViewById(R.id.tbxCityPopulation);
	EditText tbxCityAvoidCalamity;// = (EditText) findViewById(R.id.tbxCityAvoidCalamity);
	EditText tbxCityMoney;// = (EditText) findViewById(R.id.tbxCityMoney);
	EditText tbxCityFood ;//= (EditText) findViewById(R.id.tbxCityFood);
	EditText tbxCityMothballArms ;//= (EditText) findViewById(R.id.tbxCityMothballArms);
	Button btnSaveCity;// = (Button) findViewById(R.id.btnSaveCity);

	Spinner cbxGoodPeriod;// = (Spinner) findViewById(R.id.cbxGoodPeriod);
	Spinner cbxGoodId;// = (Spinner) findViewById(R.id.cbxGoodId);
	EditText tbxGoodName;// = (EditText) findViewById(R.id.tbxGoodName);
	Spinner cbxGoodUseFlag;// = (Spinner) findViewById(R.id.cbxGoodUseFlag);
	EditText tbxGoodAt;// = (EditText) findViewById(R.id.tbxGoodAt);
	EditText tbxGoodIQ;// = (EditText) findViewById(R.id.tbxGoodIQ);
	EditText tbxGoodMove;// = (EditText) findViewById(R.id.tbxGoodMove);
	Spinner cbxGoodArm;// = (Spinner) findViewById(R.id.cbxGoodArm);
	EditText tbxGoodAppearYear;
	Spinner cbxGoodSearchId;// = (Spinner) findViewById(R.id.cbxGoodSearchId);
	Spinner cbxGoodAppearCityId;// = (Spinner) findViewById(R.id.cbxGoodAppearCityId);
	Button btnSaveGood;// = (Button) findViewById(R.id.btnSaveGood);

	Button btnSaveLib;// = (Button) findViewById(R.id.btnSaveLib);
	Button btnDelLib;
	Button btnBackUpLib;
	Button btnRestoreLib;
	Button btnBackUpSav ;
	Button btnRestoreSav ;
	//
	Spinner cbxSaveHeroId;// = (Spinner) findViewById(R.id.cbxSaveHeroId);
	EditText tbxSaveHeroName;// = (EditText) findViewById(R.id.tbxSaveHeroName);
	Spinner cbxSaveHeroBelong;// = (Spinner) findViewById(R.id.cbxSaveHeroBelong);
	EditText tbxSaveHeroDegree;// = (EditText) findViewById(R.id.tbxSaveHeroDegree);
	EditText tbxSaveHeroForce;// = (EditText) findViewById(R.id.tbxSaveHeroForce);
	EditText tbxSaveHeroIQ;// = (EditText) findViewById(R.id.tbxSaveHeroIQ);
	EditText tbxSaveHeroDevotion;// = (EditText) findViewById(R.id.tbxSaveHeroDevotion);
	Spinner cbxSaveHeroCharacter;// = (Spinner) findViewById(R.id.cbxSaveHeroCharacter);
	Spinner cbxSaveHeroArmsType;// = (Spinner) findViewById(R.id.cbxSaveHeroArmsType);
	EditText tbxSaveHeroAge;// = (EditText) findViewById(R.id.tbxSaveHeroAge);

	Button btnSaveSaveHero;// = (Button) findViewById(R.id.btnSaveSaveHero);

	Spinner cbxSaveCityId;// = (Spinner) findViewById(R.id.cbxSaveCityId);
	EditText tbxSaveCityName;// = (EditText) findViewById(R.id.tbxSaveCityName);
	Spinner cbxSaveCityBelong;// = (Spinner) findViewById(R.id.cbxSaveCityBelong);
	EditText tbxSaveCityPeopleDevotion;// = (EditText) findViewById(R.id.tbxSaveCityPeopleDevotion);
	EditText tbxSaveCityFarmingLimit;// = (EditText) findViewById(R.id.tbxSaveCityFarmingLimit);
	EditText tbxSaveCityFarming;// = (EditText) findViewById(R.id.tbxSaveCityFarming);
	EditText tbxSaveCityCommerceLimit;// = (EditText) findViewById(R.id.tbxSaveCityCommerceLimit);
	EditText tbxSaveCityCommerce;// = (EditText) findViewById(R.id.tbxSaveCityCommerce);
	EditText tbxSaveCityPopulationLimit;// = (EditText) findViewById(R.id.tbxSaveCityPopulationLimit);
	EditText tbxSaveCityPopulation;// = (EditText) findViewById(R.id.tbxSaveCityPopulation);
	EditText tbxSaveCityAvoidCalamity;// = (EditText) findViewById(R.id.tbxSaveCityAvoidCalamity);
	EditText tbxSaveCityMoney;// = (EditText) findViewById(R.id.tbxSaveCityMoney);
	EditText tbxSaveCityFood;// = (EditText) findViewById(R.id.tbxSaveCityFood);
	EditText tbxSaveCityMothballArms;// = (EditText) findViewById(R.id.tbxSaveCityMothballArms);

	Button btnSaveSaveCity;// = (Button) findViewById(R.id.btnSaveSaveCity);

	Button btnSaveSave;//= (Button) findViewById(R.id.btnSaveSave);

	Spinner cbxSaveId;

	String[] lcbxHeroPeriod  = new String[] {"董卓弄权","曹操崛起","赤壁之战","三国鼎立"};
	String[] lcbxHeroId   = new String[200];
	String[] lcbxHeroBelong   = new String[200+1];
	String[] lcbxHeroCharacter   = new String[] {"忠义","大志","贪财","怕死","鲁莽"};
	String[] lcbxHeroArmsType   = new String[]{"骑兵","步兵","弓兵","水兵","极兵","玄兵"};
	String[] lcbxHeroAppearCityId   = new String[38+1];
	String[] lcbxHeroSearchId   = new String[200+1];
	String[] lcbxHeroEquip1   = new String[33+1];
	String[] lcbxHeroEquip2   = new String[33+1];
	String[] lcbxCityPeriod   = new String[] {"董卓弄权","曹操崛起","赤壁之战","三国鼎立"};
	String[] lcbxCityId   = new String[38];
	String[] lcbxCityBelong   = new String[200+1];
	String[] lcbxGoodPeriod   = new String[] {"董卓弄权","曹操崛起","赤壁之战","三国鼎立"};
	String[] lcbxGoodId    = new String[33];
	String[] lcbxGoodUseFlag    =new String[] {"装备","使用"};
	String[] lcbxGoodArm    = new String[]{"骑兵","步兵","弓兵","水兵","极兵","玄兵"};
	String[] lcbxGoodAppearCityId    = new String[38+1];
	String[] lcbxGoodSearchId    = new String[200+1];


	String[] lcbxSaveHeroId   = new String[200];
	String[] lcbxSaveHeroBelong   = new String[200+1];
	String[] lcbxSaveHeroCharacter   = new String[] {"忠义","大志","贪财","怕死","鲁莽"};
	String[] lcbxSaveHeroArmsType   = new String[]{"骑兵","步兵","弓兵","水兵","极兵","玄兵"};
	String[] lcbxSaveCityId   = new String[38];
	String[] lcbxSaveCityBelong   = new String[200+1];

	String[] lcbxSaveId   = new String[] {"存档一","存档二","存档三"};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.modifier);

		try
		{
			if(Build.VERSION.SDK_INT >= 9)
			{
				StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
						.detectDiskReads()
						.detectDiskWrites()
						.detectNetwork()   // or .detectAll() for all detectable problems
						.penaltyLog()
						.build());
				StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
						.detectLeakedSqlLiteObjects()
						.detectLeakedClosableObjects()
						.penaltyLog()
						.penaltyDeath()
						.build());
			}
		}
		catch(Exception e)
		{

		}

		//Button button1 = (Button) findViewById(R.id.button1);
		for(int i = 0 ; i< 116; i ++)
		{
			reshead[i] = new RCHEAD();
		}
		for(int i = 0 ; i< 4; i ++)
		{
			for(int j = 0 ; j< 200; j ++)
			{
				hero[i][j] = new HERO();
			}
		}
		for(int i = 0 ; i< 4; i ++)
		{
			for(int j = 0 ; j< 38; j ++)
			{
				city[i][j] = new CITY();
			}
		}
		for(int i = 0 ; i< 4; i ++)
		{
			for(int j = 0 ; j< 33; j ++)
			{
				good[i][j] = new GOOD();
			}
		}

		for(int i = 0 ; i< 200; i++)
		{
				savhero[i] = new HERO();
		}
		for(int i = 0 ; i< 38; i ++)
		{
			savcity[i] = new CITY();
		}
		for(int i = 0 ; i< 33; i ++)
		{
			savgood[i] = new GOOD();
		}



		cbxHeroPeriod = (Spinner) findViewById(R.id.cbxHeroPeriod);
		cbxHeroId = (Spinner) findViewById(R.id.cbxHeroId);
		tbxHeroName = (EditText) findViewById(R.id.tbxHeroName);
		cbxHeroBelong = (Spinner) findViewById(R.id.cbxHeroBelong);
		tbxHeroDegree = (EditText) findViewById(R.id.tbxHeroDegree);
		tbxHeroForce = (EditText) findViewById(R.id.tbxHeroForce);
		tbxHeroIQ = (EditText) findViewById(R.id.tbxHeroIQ);
		tbxHeroDevotion = (EditText) findViewById(R.id.tbxHeroDevotion);
		cbxHeroCharacter = (Spinner) findViewById(R.id.cbxHeroCharacter);
		cbxHeroArmsType = (Spinner) findViewById(R.id.cbxHeroArmsType);
		tbxHeroAge = (EditText) findViewById(R.id.tbxHeroAge);
		cbxHeroEquip1 = (Spinner)findViewById(R.id.cbxHeroEquip1);
		cbxHeroEquip2 = (Spinner)findViewById(R.id.cbxHeroEquip2);
		tbxHeroBornYear = (EditText)findViewById(R.id.tbxHeroBornYear);
		cbxHeroSearchId = (Spinner) findViewById(R.id.cbxHeroSearchId);
		cbxHeroAppearCityId = (Spinner) findViewById(R.id.cbxHeroAppearCityId);
		btnSaveHero = (Button) findViewById(R.id.btnSaveHero);

		cbxCityPeriod = (Spinner) findViewById(R.id.cbxCityPeriod);
		cbxCityId = (Spinner) findViewById(R.id.cbxCityId);
		tbxCityName = (EditText) findViewById(R.id.tbxCityName);
		cbxCityBelong = (Spinner) findViewById(R.id.cbxCityBelong);
		tbxCityPeopleDevotion = (EditText) findViewById(R.id.tbxCityPeopleDevotion);
		tbxCityFarmingLimit = (EditText) findViewById(R.id.tbxCityFarmingLimit);
		tbxCityFarming = (EditText) findViewById(R.id.tbxCityFarming);
		tbxCityCommerceLimit = (EditText) findViewById(R.id.tbxCityCommerceLimit);
		tbxCityCommerce = (EditText) findViewById(R.id.tbxCityCommerce);
		tbxCityPopulationLimit = (EditText) findViewById(R.id.tbxCityPopulationLimit);
		tbxCityPopulation = (EditText) findViewById(R.id.tbxCityPopulation);
		tbxCityAvoidCalamity = (EditText) findViewById(R.id.tbxCityAvoidCalamity);
		tbxCityMoney = (EditText) findViewById(R.id.tbxCityMoney);
		tbxCityFood = (EditText) findViewById(R.id.tbxCityFood);
		tbxCityMothballArms = (EditText) findViewById(R.id.tbxCityMothballArms);
		btnSaveCity = (Button) findViewById(R.id.btnSaveCity);

		cbxGoodPeriod = (Spinner) findViewById(R.id.cbxGoodPeriod);
		cbxGoodId = (Spinner) findViewById(R.id.cbxGoodId);
		tbxGoodName = (EditText) findViewById(R.id.tbxGoodName);
		cbxGoodUseFlag = (Spinner) findViewById(R.id.cbxGoodUseFlag);
		tbxGoodAt = (EditText) findViewById(R.id.tbxGoodAt);
		tbxGoodIQ = (EditText) findViewById(R.id.tbxGoodIQ);
		tbxGoodMove = (EditText) findViewById(R.id.tbxGoodMove);
		cbxGoodArm = (Spinner) findViewById(R.id.cbxGoodArm);
		tbxGoodAppearYear = (EditText)findViewById(R.id.tbxGoodAppearYear);
		cbxGoodSearchId = (Spinner) findViewById(R.id.cbxGoodSearchId);
		cbxGoodAppearCityId = (Spinner) findViewById(R.id.cbxGoodAppearCityId);
		btnSaveGood = (Button) findViewById(R.id.btnSaveGood);

		btnSaveLib = (Button) findViewById(R.id.btnSaveLib);
		cbxSaveId = (Spinner) findViewById(R.id.cbxSaveId);
		btnDelLib = (Button) findViewById(R.id.btnDelLib);
		btnBackUpLib = (Button) findViewById(R.id.btnBackUpLib);
		btnRestoreLib = (Button) findViewById(R.id.btnRestoreLib);
		btnBackUpSav = (Button) findViewById(R.id.btnBackUpSav);
		btnRestoreSav = (Button) findViewById(R.id.btnRestoreSav);

		//
		cbxSaveHeroId = (Spinner) findViewById(R.id.cbxSaveHeroId);
		tbxSaveHeroName = (EditText) findViewById(R.id.tbxSaveHeroName);
		cbxSaveHeroBelong = (Spinner) findViewById(R.id.cbxSaveHeroBelong);
		tbxSaveHeroDegree = (EditText) findViewById(R.id.tbxSaveHeroDegree);
		tbxSaveHeroForce = (EditText) findViewById(R.id.tbxSaveHeroForce);
		tbxSaveHeroIQ = (EditText) findViewById(R.id.tbxSaveHeroIQ);
		tbxSaveHeroDevotion = (EditText) findViewById(R.id.tbxSaveHeroDevotion);
		cbxSaveHeroCharacter = (Spinner) findViewById(R.id.cbxSaveHeroCharacter);
		cbxSaveHeroArmsType = (Spinner) findViewById(R.id.cbxSaveHeroArmsType);
		tbxSaveHeroAge = (EditText) findViewById(R.id.tbxSaveHeroAge);

		btnSaveSaveHero = (Button) findViewById(R.id.btnSaveSaveHero);

		cbxSaveCityId = (Spinner) findViewById(R.id.cbxSaveCityId);
		tbxSaveCityName = (EditText) findViewById(R.id.tbxSaveCityName);
		cbxSaveCityBelong = (Spinner) findViewById(R.id.cbxSaveCityBelong);
		tbxSaveCityPeopleDevotion = (EditText) findViewById(R.id.tbxSaveCityPeopleDevotion);
		tbxSaveCityFarmingLimit = (EditText) findViewById(R.id.tbxSaveCityFarmingLimit);
		tbxSaveCityFarming = (EditText) findViewById(R.id.tbxSaveCityFarming);
		tbxSaveCityCommerceLimit = (EditText) findViewById(R.id.tbxSaveCityCommerceLimit);
		tbxSaveCityCommerce = (EditText) findViewById(R.id.tbxSaveCityCommerce);
		tbxSaveCityPopulationLimit = (EditText) findViewById(R.id.tbxSaveCityPopulationLimit);
		tbxSaveCityPopulation = (EditText) findViewById(R.id.tbxSaveCityPopulation);
		tbxSaveCityAvoidCalamity = (EditText) findViewById(R.id.tbxSaveCityAvoidCalamity);
		tbxSaveCityMoney = (EditText) findViewById(R.id.tbxSaveCityMoney);
		tbxSaveCityFood = (EditText) findViewById(R.id.tbxSaveCityFood);
		tbxSaveCityMothballArms = (EditText) findViewById(R.id.tbxSaveCityMothballArms);

		btnSaveSaveCity = (Button) findViewById(R.id.btnSaveSaveCity);

		btnSaveSave= (Button) findViewById(R.id.btnSaveSave);

		tbxHeroDegree.setFilters(new InputFilter[]{ new InputFilterMinMax("0", "20")});
		tbxHeroForce.setFilters(new InputFilter[]{ new InputFilterMinMax("0", "255")});
		tbxHeroIQ.setFilters(new InputFilter[]{ new InputFilterMinMax("0", "255")});
		tbxHeroDevotion.setFilters(new InputFilter[]{ new InputFilterMinMax("0", "100")});
		tbxHeroAge.setFilters(new InputFilter[]{ new InputFilterMinMax("0", "255")});
		tbxHeroBornYear.setFilters(new InputFilter[]{ new InputFilterMinMax("0", "1000")});

		tbxCityPeopleDevotion.setFilters(new InputFilter[]{ new InputFilterMinMax("0", "100")});
		tbxCityFarmingLimit.setFilters(new InputFilter[]{ new InputFilterMinMax("0", "65535")});
		tbxCityFarming.setFilters(new InputFilter[]{ new InputFilterMinMax("0", "65535")});
		tbxCityCommerceLimit.setFilters(new InputFilter[]{ new InputFilterMinMax("0", "65535")});
		tbxCityCommerce.setFilters(new InputFilter[]{ new InputFilterMinMax("0", "65535")});
		tbxCityPopulationLimit.setFilters(new InputFilter[]{ new InputFilterMinMax("0", "21000000")});
		tbxCityPopulation.setFilters(new InputFilter[]{ new InputFilterMinMax("0", "21000000")});
		tbxCityAvoidCalamity.setFilters(new InputFilter[]{ new InputFilterMinMax("0", "100")});
		tbxCityMoney.setFilters(new InputFilter[]{ new InputFilterMinMax("0", "65535")});
		tbxCityFood.setFilters(new InputFilter[]{ new InputFilterMinMax("0", "65535")});
		tbxCityMothballArms.setFilters(new InputFilter[]{ new InputFilterMinMax("0", "65535")});

		tbxGoodAt.setFilters(new InputFilter[]{ new InputFilterMinMax("0", "100")});
		tbxGoodIQ.setFilters(new InputFilter[]{ new InputFilterMinMax("0", "100")});
		tbxGoodMove.setFilters(new InputFilter[]{ new InputFilterMinMax("0", "100")});
		tbxGoodAppearYear.setFilters(new InputFilter[]{ new InputFilterMinMax("0", "255")});

		tbxSaveHeroDegree.setFilters(new InputFilter[]{ new InputFilterMinMax("0", "20")});
		tbxSaveHeroForce.setFilters(new InputFilter[]{ new InputFilterMinMax("0", "255")});
		tbxSaveHeroIQ.setFilters(new InputFilter[]{ new InputFilterMinMax("0", "255")});
		tbxSaveHeroDevotion .setFilters(new InputFilter[]{ new InputFilterMinMax("0", "100")});
		tbxSaveHeroAge.setFilters(new InputFilter[]{ new InputFilterMinMax("0", "255")});

		tbxSaveCityPeopleDevotion.setFilters(new InputFilter[]{ new InputFilterMinMax("0", "100")});
		tbxSaveCityFarmingLimit.setFilters(new InputFilter[]{ new InputFilterMinMax("0", "65535")});
		tbxSaveCityFarming.setFilters(new InputFilter[]{ new InputFilterMinMax("0", "65535")});
		tbxSaveCityCommerceLimit.setFilters(new InputFilter[]{ new InputFilterMinMax("0", "65535")});
		tbxSaveCityCommerce.setFilters(new InputFilter[]{ new InputFilterMinMax("0", "65535")});
		tbxSaveCityPopulationLimit.setFilters(new InputFilter[]{ new InputFilterMinMax("0", "21000000")});
		tbxSaveCityPopulation .setFilters(new InputFilter[]{ new InputFilterMinMax("0", "21000000")});
		tbxSaveCityAvoidCalamity.setFilters(new InputFilter[]{ new InputFilterMinMax("0", "100")});
		tbxSaveCityMoney.setFilters(new InputFilter[]{ new InputFilterMinMax("0", "65535")});
		tbxSaveCityFood.setFilters(new InputFilter[]{ new InputFilterMinMax("0", "65535")});
		tbxSaveCityMothballArms.setFilters(new InputFilter[]{ new InputFilterMinMax("0", "65535")});


        for (int i = 0; i < 116; i++)
		{
			reshead[i] = new RCHEAD();
			reshead[i].ItmCnt = 0;
			reshead[i].ItmLen = 0;
			reshead[i].Reserved = 0;
			reshead[i].ResId = 0;
			reshead[i].ResKey = 0;
			reshead[i].ResLen = 0;
		}

		OpenLib();

		SetHeroInfo();
		SetGoodInfo();
		SetCityInfo();

		OpenSsv(0);

		SetSavInfo();


		//绑定适配器和值
		ArrayAdapter<String> aacbxHeroPeriod = new ArrayAdapter<String>(Modify_MainActivity.this, android.R.layout.simple_spinner_item, lcbxHeroPeriod );
		ArrayAdapter<String> aacbxHeroId  = new ArrayAdapter<String>(Modify_MainActivity.this, android.R.layout.simple_spinner_item, lcbxHeroId );
		ArrayAdapter<String> aacbxHeroBelong  = new ArrayAdapter<String>(Modify_MainActivity.this, android.R.layout.simple_spinner_item, lcbxHeroBelong );
		ArrayAdapter<String> aacbxHeroCharacter  = new ArrayAdapter<String>(Modify_MainActivity.this, android.R.layout.simple_spinner_item, lcbxHeroCharacter );
		ArrayAdapter<String> aacbxHeroArmsType  = new ArrayAdapter<String>(Modify_MainActivity.this, android.R.layout.simple_spinner_item, lcbxHeroArmsType );
		ArrayAdapter<String> aacbxHeroAppearCityId  = new ArrayAdapter<String>(Modify_MainActivity.this, android.R.layout.simple_spinner_item, lcbxHeroAppearCityId );
		ArrayAdapter<String> aacbxHeroSearchId  = new ArrayAdapter<String>(Modify_MainActivity.this, android.R.layout.simple_spinner_item, lcbxHeroSearchId );
		ArrayAdapter<String> aacbxHeroEquip1  = new ArrayAdapter<String>(Modify_MainActivity.this, android.R.layout.simple_spinner_item, lcbxHeroEquip1);
		ArrayAdapter<String> aacbxHeroEquip2  = new ArrayAdapter<String>(Modify_MainActivity.this, android.R.layout.simple_spinner_item, lcbxHeroEquip2);
		ArrayAdapter<String> aacbxCityPeriod  = new ArrayAdapter<String>(Modify_MainActivity.this, android.R.layout.simple_spinner_item, lcbxCityPeriod );
		ArrayAdapter<String> aacbxCityId  = new ArrayAdapter<String>(Modify_MainActivity.this, android.R.layout.simple_spinner_item, lcbxCityId );
		ArrayAdapter<String> aacbxCityBelong  = new ArrayAdapter<String>(Modify_MainActivity.this, android.R.layout.simple_spinner_item, lcbxCityBelong );
		ArrayAdapter<String> aacbxGoodPeriod  = new ArrayAdapter<String>(Modify_MainActivity.this, android.R.layout.simple_spinner_item, lcbxGoodPeriod );
		ArrayAdapter<String> aacbxGoodId  = new ArrayAdapter<String>(Modify_MainActivity.this, android.R.layout.simple_spinner_item, lcbxGoodId );
		ArrayAdapter<String> aacbxGoodUseFlag  = new ArrayAdapter<String>(Modify_MainActivity.this, android.R.layout.simple_spinner_item, lcbxGoodUseFlag );
		ArrayAdapter<String> aacbxGoodArm  = new ArrayAdapter<String>(Modify_MainActivity.this, android.R.layout.simple_spinner_item, lcbxGoodArm );
		ArrayAdapter<String> aacbxGoodAppearCityId  = new ArrayAdapter<String>(Modify_MainActivity.this, android.R.layout.simple_spinner_item, lcbxGoodAppearCityId );
		ArrayAdapter<String> aacbxGoodSearchId   = new ArrayAdapter<String>(Modify_MainActivity.this, android.R.layout.simple_spinner_item, lcbxGoodSearchId );

		ArrayAdapter<String> aacbxSaveHeroId  = new ArrayAdapter<String>(Modify_MainActivity.this, android.R.layout.simple_spinner_item, lcbxSaveHeroId );
		ArrayAdapter<String> aacbxSaveHeroBelong  = new ArrayAdapter<String>(Modify_MainActivity.this, android.R.layout.simple_spinner_item, lcbxSaveHeroBelong );
		ArrayAdapter<String> aacbxSaveHeroCharacter  = new ArrayAdapter<String>(Modify_MainActivity.this, android.R.layout.simple_spinner_item, lcbxSaveHeroCharacter );
		ArrayAdapter<String> aacbxSaveHeroArmsType  = new ArrayAdapter<String>(Modify_MainActivity.this, android.R.layout.simple_spinner_item, lcbxSaveHeroArmsType );
		ArrayAdapter<String> aacbxSaveCityId  = new ArrayAdapter<String>(Modify_MainActivity.this, android.R.layout.simple_spinner_item, lcbxSaveCityId );
		ArrayAdapter<String> aacbxSaveCityBelong  = new ArrayAdapter<String>(Modify_MainActivity.this, android.R.layout.simple_spinner_item, lcbxSaveCityBelong );

		ArrayAdapter<String> aacbxSaveId   = new ArrayAdapter<String>(Modify_MainActivity.this, android.R.layout.simple_spinner_item,lcbxSaveId );

        cbxHeroPeriod.setOnItemSelectedListener(clcbxHeroPeriod);
		cbxHeroId.setOnItemSelectedListener(clcbxHeroId);
		cbxHeroBelong.setOnItemSelectedListener(clcbxHeroBelong);
		cbxHeroCharacter.setOnItemSelectedListener(clcbxHeroCharacter);
		cbxHeroArmsType.setOnItemSelectedListener(clcbxHeroArmsType);
		cbxHeroAppearCityId.setOnItemSelectedListener(clcbxHeroAppearCityId);
		cbxHeroSearchId.setOnItemSelectedListener(clcbxHeroSearchId);
		cbxHeroEquip1.setOnItemSelectedListener(clcbxHeroEquip1);
		cbxHeroEquip2.setOnItemSelectedListener(clcbxHeroEquip2);
        cbxCityPeriod .setOnItemSelectedListener(clcbxCityPeriod);
		cbxCityId .setOnItemSelectedListener(clcbxCityId);
		cbxCityBelong .setOnItemSelectedListener(clcbxCityBelong);
		cbxGoodPeriod .setOnItemSelectedListener(clcbxGoodPeriod);
		cbxGoodId .setOnItemSelectedListener(clcbxGoodId);
		cbxGoodUseFlag .setOnItemSelectedListener(clcbxGoodUseFlag);
		cbxGoodArm .setOnItemSelectedListener(clcbxGoodArm);
		cbxGoodAppearCityId .setOnItemSelectedListener(clcbxGoodAppearCityId);
		cbxGoodSearchId .setOnItemSelectedListener(clcbxGoodSearchId);
		cbxSaveHeroId.setOnItemSelectedListener(clcbxSaveHeroId);
		cbxSaveHeroBelong.setOnItemSelectedListener(clcbxSaveHeroBelong);
		cbxSaveHeroCharacter.setOnItemSelectedListener(clcbxSaveHeroCharacter);
		cbxSaveHeroArmsType.setOnItemSelectedListener(clcbxSaveHeroArmsType);
		cbxSaveCityId.setOnItemSelectedListener(clcbxSaveCityId);
		cbxSaveCityBelong.setOnItemSelectedListener(clcbxSaveCityBelong);

		cbxSaveId.setOnItemSelectedListener(clcbxSaveId);//20190323

		cbxHeroPeriod.setAdapter(aacbxHeroPeriod);
		cbxHeroId .setAdapter(aacbxHeroId);
		cbxHeroBelong .setAdapter(aacbxHeroBelong);
		cbxHeroCharacter .setAdapter(aacbxHeroCharacter);
		cbxHeroArmsType .setAdapter(aacbxHeroArmsType);
		cbxHeroAppearCityId .setAdapter(aacbxHeroAppearCityId);
		cbxHeroSearchId .setAdapter(aacbxHeroSearchId);
		cbxHeroEquip1.setAdapter(aacbxHeroEquip1);
		cbxHeroEquip2.setAdapter(aacbxHeroEquip2);
		cbxCityPeriod .setAdapter(aacbxCityPeriod);
		cbxCityId .setAdapter(aacbxCityId);
		cbxCityBelong .setAdapter(aacbxCityBelong);
		cbxGoodPeriod .setAdapter(aacbxGoodPeriod);
		cbxGoodId .setAdapter(aacbxGoodId);
		cbxGoodUseFlag .setAdapter(aacbxGoodUseFlag);
		cbxGoodArm .setAdapter(aacbxGoodArm);
		cbxGoodAppearCityId .setAdapter(aacbxGoodAppearCityId);
		cbxGoodSearchId  .setAdapter(aacbxGoodSearchId );

		btnSaveHero.setOnClickListener(clbtnSaveHero);
		btnSaveCity.setOnClickListener(clbtnSaveCity);
		btnSaveGood.setOnClickListener(clbtnSaveGood);
		btnSaveLib.setOnClickListener(clbtnSaveLib);
		btnDelLib.setOnClickListener(clbtnDelLib);
		btnBackUpLib.setOnClickListener(clbtnBackUpLib);
		btnRestoreLib.setOnClickListener(clbtnRestoreLib);
		btnBackUpSav.setOnClickListener(clbtnBackUpSav);
		btnRestoreSav.setOnClickListener(clbtnRestoreSav);

		cbxSaveHeroId .setAdapter(aacbxSaveHeroId);
		cbxSaveHeroBelong .setAdapter(aacbxSaveHeroBelong);
		cbxSaveHeroCharacter .setAdapter(aacbxSaveHeroCharacter);
		cbxSaveHeroArmsType .setAdapter(aacbxSaveHeroArmsType);
		cbxSaveCityId .setAdapter(aacbxSaveCityId);
		cbxSaveCityBelong .setAdapter(aacbxSaveCityBelong);

		cbxSaveId.setAdapter(aacbxSaveId);

		btnSaveSaveHero.setOnClickListener(clbtnSaveSaveHero);
		btnSaveSaveCity.setOnClickListener(clbtnSaveSaveCity);
		btnSaveSave.setOnClickListener(clbtnSaveSave);


		Modify_MainActivity.this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		/*TabHost tabHost=(TabHost)findViewById(R.id.tabHost);
		tabHost.setup();

		TabSpec spec0=tabHost.newTabSpec("LIB库");
		spec0.setContent(R.id.tab1);
		spec0.setIndicator("LIB库");

		TabSpec spec1=tabHost.newTabSpec("存档");
		spec1.setIndicator("存档");
		spec1.setContent(R.id.tab2);

		tabHost.addTab(spec0);
		tabHost.addTab(spec1);*/

		/////////////////////
		TabHost tabHost1=(TabHost)findViewById(R.id.tabHost);
		tabHost1.setup();

		TabSpec spec00=tabHost1.newTabSpec("LIB>>>");
		spec00.setContent(R.id.tab10);
		spec00.setIndicator("LIB>>>");

		TabSpec spec10=tabHost1.newTabSpec("武将");
		spec10.setContent(R.id.tab12);
		spec10.setIndicator("武将");

		TabSpec spec11=tabHost1.newTabSpec("城池");
		spec11.setIndicator("城池");
		spec11.setContent(R.id.tab13);

		TabSpec spec12=tabHost1.newTabSpec("道具");
		spec12.setIndicator("道具");
		spec12.setContent(R.id.tab14);

		tabHost1.addTab(spec00);
		tabHost1.addTab(spec10);
		tabHost1.addTab(spec11);
		tabHost1.addTab(spec12);

		/////////////////////
		TabHost tabHost2=(TabHost)findViewById(R.id.tabHost);
		tabHost2.setup();

		TabSpec spec20=tabHost2.newTabSpec("存档>>>");
		spec20.setContent(R.id.tab20);
		spec20.setIndicator("存档>>>");

		TabSpec spec22=tabHost2.newTabSpec("存档武将");
		spec22.setContent(R.id.tab22);
		spec22.setIndicator("存档武将");

		TabSpec spec23=tabHost2.newTabSpec("存档城池");
		spec23.setIndicator("存档城池");
		spec23.setContent(R.id.tab23);

		tabHost2.addTab(spec20);
		tabHost2.addTab(spec22);
		tabHost2.addTab(spec23);


		InitPanel(0);

        UpdateManager manager = new UpdateManager(Modify_MainActivity.this);
        // 检查软件更新
        manager.checkUpdateStart();



	}

	private void OpenLib()
	{
		isLib = true;
		isSsv = false;
		String filename = Public.SDPATH +"dat.lib";
		//File fileOpen = new File(fName);
		MyOpen(filename);
		isRlb = false;
		noRlb = false;
		//tabControl1.Enabled = true;
		comboBox1_SelectedIndexChanged();
	}

	private void comboBox1_SelectedIndexChanged()
	{
		if (noRlb == true)
		{
			return;
		}

		SetHeroInfo();
		notSavedHero = true;
	}

	private void SetHeroInfo()
	{
		int period = cbxHeroPeriod.getSelectedItemPosition();
		//cbxHeroId.Items.Clear();
		if(period < 0)period = 0;
		//lcbxHeroBelong = new String[200+1];
		//lcbxHeroSearchId = new String[200+1];
		//lcbxHeroAppearCityId = new String[38+1];

		lcbxHeroSearchId[0] = "无";
		lcbxHeroBelong[0] = "无";
		lcbxHeroAppearCityId[0] = "无";
		lcbxHeroEquip1[0] = "无";
		lcbxHeroEquip2[0] = "无";
		lcbxHeroId[0] = 0+"";

		for (int i = 0; i < 200; i++)
		{
			//cbxHeroId.Items.Add(i+1 +"");
			if(i<199)lcbxHeroId[i+1] = (i+1)+"";
			lcbxHeroBelong[i+1] = heroname[period][i];
			lcbxHeroSearchId[i+1] = heroname[period][i];

		}

		for (int i = 0; i < 38; i++)
		{
			lcbxHeroAppearCityId[i+1] = cityname[i];
		}

		for (int i = 0; i < 33; i++)
		{
			lcbxHeroEquip1[i+1] = goodname[i];
			lcbxHeroEquip2[i+1] = goodname[i];
		}

		ArrayAdapter<String> aacbxHeroBelong  = new ArrayAdapter<String>(Modify_MainActivity.this, android.R.layout.simple_spinner_item, lcbxHeroBelong );
		cbxHeroBelong.setAdapter(aacbxHeroBelong);
		aacbxHeroBelong.notifyDataSetChanged();

		ArrayAdapter<String> aacbxHeroSearchId  = new ArrayAdapter<String>(Modify_MainActivity.this, android.R.layout.simple_spinner_item, lcbxHeroSearchId );
		cbxHeroSearchId.setAdapter(aacbxHeroSearchId);
		aacbxHeroSearchId.notifyDataSetChanged();

		ArrayAdapter<String> aacbxHeroEquip1  = new ArrayAdapter<String>(Modify_MainActivity.this, android.R.layout.simple_spinner_item, lcbxHeroEquip1 );
		cbxHeroEquip1.setAdapter(aacbxHeroEquip1);
		aacbxHeroEquip1.notifyDataSetChanged();

		ArrayAdapter<String> aacbxHeroEquip2  = new ArrayAdapter<String>(Modify_MainActivity.this, android.R.layout.simple_spinner_item, lcbxHeroEquip2 );
		cbxHeroEquip2.setAdapter(aacbxHeroEquip2);
		aacbxHeroEquip2.notifyDataSetChanged();
	}

	private void MyOpen(String filename)
	{
		try
		{

			FileInputStream fin =new FileInputStream(filename);
			DataInputStream data_in = new DataInputStream(fin);
			rlbByteLen = fin.available();
			data_in.read(rlbByte,0,rlbByteLen);
			fin.close();
		}
		catch(Exception e){}

		//listBox1.Items.Clear();
		InitRlb();

	}

	private void InitRlb()
	{
		//head
		for (int i = 0; i < 116; i++)
		{
			byte[] tb = new byte[4];
			tb[0] = rlbByte[i * 4];
			tb[1] = rlbByte[i * 4 + 1];
			tb[2] = rlbByte[i * 4 + 2];
			tb[3] = rlbByte[i * 4 + 3];
			resAddress[i] = Byte2Int(tb, 0);
		}
		//资源
		for (int j = 0; j < 116; j++)
		{
			int adr = resAddress[j];
			if (adr < 0)
			{
				//listBox1.Items.Add(reshead[j].ResId + "-NONE");
				continue;
			}
			byte[] b1 = new byte[4];
			b1[0] = rlbByte[adr];
			b1[1] = rlbByte[adr + 1];
			b1[2] = rlbByte[adr + 2];
			b1[3] = rlbByte[adr + 3];
			reshead[j].ResLen = Byte2Int(b1, 0);
			adr += 4;
			byte[] b2 = new byte[4];
			b2[0] = rlbByte[adr];
			b2[1] = rlbByte[adr + 1];
			b2[2] = 0;
			b2[3] = 0;
			reshead[j].ResId = Byte2Int(b2, 0);
			adr += 2;
			byte[] b3 = new byte[4];
			b3[0] = rlbByte[adr];
			b3[1] = rlbByte[adr + 1];
			b3[2] = 0;
			b3[3] = 0;
			reshead[j].ItmCnt = Byte2Int(b3, 0);
			adr += 2;
			byte[] b4 = new byte[4];
			b4[0] = rlbByte[adr];
			b4[1] = rlbByte[adr + 1];
			b4[2] = 0;
			b4[3] = 0;
			reshead[j].ItmLen = Byte2Int(b4, 0);
			adr += 2;
			byte[] b5 = new byte[4];
			b5[0] = rlbByte[adr];
			b5[1] = rlbByte[adr + 1];
			b5[2] = 0;
			b5[3] = 0;
			reshead[j].ResKey = Byte2Int(b5, 0);
			adr += 2;
			for (int k = adr; k < reshead[j].ResLen + adr; k++)
			{
				resByte[j][k - adr] = rlbByte[k];
			}



			//listBox1.Items.Add(reshead[j].ResId +"");



		}


		int[] canUseResId = { 61, 62, 70, 71, 72, 57, 58, 66, 73, 63, 67 };

		InitHero(60);
		InitHeroName(61);
		InitHeroName(69);
		InitHeroName(70);
		InitHeroName(71);
		InitHeroCon(62);
		InitCity(56);
		InitCityName(57);
		InitGood(65);
		InitGoodName(72);
		InitGoodCon(66);
		InitHeroAtWhere(64);
		InitGoodAtWhere(67);


	}

	public int Byte2Int(byte[]bytes,int i)
	{
		return (bytes[3]&0xff)<<24
				| (bytes[2]&0xff)<<16
				| (bytes[1]&0xff)<<8
				| (bytes[0]&0xff);
	}

	public short Byte2Int16(byte[]bytes,int i)
	{
		return (short)((bytes[1]&0xff)<<8
				| (bytes[0]&0xff));
	}

	public byte[] Int2Byte(int num)
	{
		byte[]bytes=new byte[4];
		bytes[3]=(byte) ((num>>24)&0xff);
		bytes[2]=(byte) ((num>>16)&0xff);
		bytes[1]=(byte) ((num>>8)&0xff);
		bytes[0]=(byte) (num&0xff);
		return bytes;
	}


	private void InitGoodName(int resselected)
	{
		//reshead[resselected].
		int idx = 0;
		//HERO [] hero= new HERO[200];

		int st = 0;
		for (int i = 0; i < 33; i++)
		{
			byte[] byteArray = new byte[10];
			byte reskey = (byte)0xc3;
			byteArray[0] = (byte)(resByte[resselected][idx + st] - reskey);
			if(byteArray[0] != 0)
			byteArray[1] = (byte)(resByte[resselected][idx + st + 1] - reskey);
			if(byteArray[1] != 0)
			byteArray[2] = (byte)(resByte[resselected][idx + st + 2] - reskey);
			if(byteArray[2] != 0)
			byteArray[3] = (byte)(resByte[resselected][idx + st + 3] - reskey);
			if(byteArray[3] != 0)
			byteArray[4] = (byte)(resByte[resselected][idx + st + 4] - reskey);
			if(byteArray[4] != 0)
			byteArray[5] = (byte)(resByte[resselected][idx + st + 5] - reskey);
			if(byteArray[5] != 0)
			byteArray[6] = (byte)(resByte[resselected][idx + st + 6] - reskey);
			if(byteArray[6] != 0)
			byteArray[7] = (byte)(resByte[resselected][idx + st + 7] - reskey);
			if(byteArray[7] != 0)
			byteArray[8] = (byte)(resByte[resselected][idx + st + 8] - reskey);
			if(byteArray[8] != 0)
			byteArray[9] = (byte)(resByte[resselected][idx + st + 9] - reskey);

			try {
				goodname[i] = Public.filterCode(new String(byteArray, "gb2312"));
			}
			catch (Exception e){}
			//hero[j, i].Name = resByte[resselected, idx];

			st += 10;

		}

	}

	private void InitCityName(int resselected)
	{
		//reshead[resselected].
		int idx = 0;
		//HERO [] hero= new HERO[200];

		int st = 0;
		for (int i = 0; i < 38; i++)
		{
			byte[] byteArray = new byte[10];
			byte reskey = (byte)0xc0;
			byteArray[0] = (byte)(resByte[resselected][idx + st] - reskey);
			if(byteArray[0] != 0)
			byteArray[1] = (byte)(resByte[resselected][idx + st + 1] - reskey);
			if(byteArray[1] != 0)
			byteArray[2] = (byte)(resByte[resselected][idx + st + 2] - reskey);
			if(byteArray[2] != 0)
			byteArray[3] = (byte)(resByte[resselected][idx + st + 3] - reskey);
			if(byteArray[3] != 0)
			byteArray[4] = (byte)(resByte[resselected][idx + st + 4] - reskey);
			if(byteArray[4] != 0)
			byteArray[5] = (byte)(resByte[resselected][idx + st + 5] - reskey);
			if(byteArray[5] != 0)
			byteArray[6] = (byte)(resByte[resselected][idx + st + 6] - reskey);
			if(byteArray[6] != 0)
			byteArray[7] = (byte)(resByte[resselected][idx + st + 7] - reskey);
			if(byteArray[7] != 0)
			byteArray[8] = (byte)(resByte[resselected][idx + st + 8] - reskey);
			if(byteArray[8] != 0)
			byteArray[9] = (byte)(resByte[resselected][idx + st + 9] - reskey);

			try {
				cityname[i] = Public.filterCode(new String(byteArray, "gb2312"));
			}
			catch (Exception e){}
			//hero[j, i].Name = resByte[resselected, idx];

			st += 10;

		}

	}

	private void InitHeroName(int resselected)
	{
		//reshead[resselected].
		int idx = 0;
		//HERO [] hero= new HERO[200];

		int st = 0;
		for (int i = 0; i < 200; i++)
		{
			byte[] byteArray = new byte[8];
			byte reskey = (byte)0xc3;
			byteArray[0] = (byte)(resByte[resselected][idx + st] - reskey);
			if(byteArray[0] != 0)
			byteArray[1] = (byte)(resByte[resselected][idx + st + 1]- reskey);
			if(byteArray[1] != 0)
			byteArray[2] = (byte)(resByte[resselected][idx + st + 2]- reskey);
			if(byteArray[2] != 0)
			byteArray[3] = (byte)(resByte[resselected][idx + st + 3]- reskey);
			if(byteArray[3] != 0)
			byteArray[4] = (byte)(resByte[resselected][idx + st + 4]- reskey);
			if(byteArray[4] != 0)
			byteArray[5] = (byte)(resByte[resselected][idx + st + 5]- reskey);
			if(byteArray[5] != 0)
			byteArray[6] = (byte)(resByte[resselected][idx + st + 6]- reskey);
			if(byteArray[6] != 0)
			byteArray[7] = (byte)(resByte[resselected][idx + st + 7] - reskey);

			try
			{
				if ((resselected + 1) == 62) {
					heroname[0][i] = Public.filterCode(new String(byteArray, "gb2312"));
				} else if ((resselected + 1) == 70) {
					heroname[1][i] = Public.filterCode(new String(byteArray, "gb2312"));
				} else if ((resselected + 1) == 71) {
					heroname[2][i] = Public.filterCode(new String(byteArray, "gb2312"));
				} else if ((resselected + 1) == 72) {
					heroname[3][i] = Public.filterCode(new String(byteArray, "gb2312"));
				}
			}
			catch(Exception e){}

			//hero[j, i].Name = resByte[resselected, idx];

			st += 8;

		}
	}

	private void InitGood(int resselected)
	{
		//reshead[resselected].
		int idx = 0;
		//HERO [] hero= new HERO[200];
		//for (int j = 0; j < 4; j++)
		{
			idx = 0;
			for (int i = 0; i < 33; i++)
			{
				good[0][i] = new GOOD();
				good[0][i].idx = resByte[resselected][idx];
				good[0][i].useflag = resByte[resselected][idx + 1];

				//public byte[] name = new byte[10];		/* 道具名字 */


				//public byte[] inf = new byte[50];		/* 道具说明 */

				good[0][i].at = resByte[resselected][idx + 62];
				good[0][i].iq = resByte[resselected][idx + 63];
				good[0][i].move = resByte[resselected][idx + 64];
				good[0][i].arm = resByte[resselected][idx + 65];


				idx += 66;

			}
		}
	}

	private void InitGoodCon(int resselected)
	{
		//reshead[resselected].
		int idx = 0;
		//HERO [] hero= new HERO[200];
		for (int j = 0; j < 4; j++)
		{
			for (int i = 0; i < 33; i++)
			{
				good[j][i].AppearYear = resByte[resselected][idx + 0];
				good[j][i].SearchId = resByte[resselected][idx + 1];
				good[j][i].AppearCityId = resByte[resselected][idx + 2];

				idx += 3;

			}
		}
	}

	private void InitCity(int resselected)
	{
		//reshead[resselected].
		int idx = 0;
		//HERO [] hero= new HERO[200];
		for (int j = 0; j < 4; j++)
		{
			for (int i = 0; i < 38; i++)
			{
				city[j][i] = new CITY();
				city[j][i].Id = resByte[resselected][idx];
				city[j][i].Belong = resByte[resselected][ idx + 1];
				city[j][i].SatrapId = resByte[resselected][idx + 2];

				byte[] b1 = new byte[2];
				b1[0] = resByte[resselected][idx + 3];
				b1[1] = resByte[resselected][idx + 4];
				city[j][i].FarmingLimit = Byte2Int16(b1, 0);

				byte[] b2 = new byte[2];
				b2[0] = resByte[resselected][idx + 5];
				b2[1] = resByte[resselected][idx + 6];
				city[j][i].Farming = Byte2Int16(b2, 0);

				byte[] b3 = new byte[2];
				b3[0] = resByte[resselected][idx + 7];
				b3[1] = resByte[resselected][idx + 8];
				city[j][i].CommerceLimit = Byte2Int16(b3, 0);

				byte[] b4 = new byte[2];
				b4[0] = resByte[resselected][idx + 9];
				b4[1] = resByte[resselected][idx + 10];
				city[j][i].Commerce = Byte2Int16(b4, 0);

				city[j][i].PeopleDevotion = resByte[resselected][idx + 11];
				city[j][i].AvoidCalamity = resByte[resselected][ idx + 12];

				byte[] b5 = new byte[4];
				b5[0] = resByte[resselected][idx + 13];
				b5[1] = resByte[resselected][idx + 14];
				b5[2] = resByte[resselected][idx + 15];
				b5[3] = resByte[resselected][idx + 16];
				city[j][i].PopulationLimit = Byte2Int(b5, 0);

				byte[] b6 = new byte[4];
				b6[0] = resByte[resselected][idx + 17];
				b6[1] = resByte[resselected][idx + 18];
				b6[2] = resByte[resselected][idx + 19];
				b6[3] = resByte[resselected][idx + 20];
				city[j][i].Population = Byte2Int(b6, 0);

				byte[] b7 = new byte[2];
				b7[0] = resByte[resselected][idx + 21];
				b7[1] = resByte[resselected][idx + 22];
				city[j][ i].Money = Byte2Int16(b7, 0);

				byte[] b8 = new byte[2];
				b8[0] = resByte[resselected][idx + 23];
				b8[1] = resByte[resselected][idx + 24];
				city[j][i].Food = Byte2Int16(b8, 0);

				byte[] b9 = new byte[2];
				b9[0] = resByte[resselected][idx + 25];
				b9[1] = resByte[resselected][idx + 26];
				city[j][i].MothballArms = Byte2Int16(b9, 0);

				city[j][i].PersonQueue = resByte[resselected][idx + 27];
				city[j][i].Persons = resByte[resselected][idx + 28];
				city[j][i].ToolQueue = resByte[resselected][idx + 29];
				city[j][i].Tools = resByte[resselected][idx + 30];


				idx += 31;

			}
			idx += 2;
		}
	}

	private void InitHero(int resselected)
	{

		//reshead[resselected].
		int idx = 0;
		//HERO [] hero= new HERO[200];
		for (int j = 0; j < 4; j++)
		{

			for (int i = 0; i < 200; i++)
			{
				hero[j][i] = new HERO();
				hero[j][i].Id = resByte[resselected][idx];
				hero[j][i].Belong = resByte[resselected][idx + 1];
				hero[j][i].Level = resByte[resselected][idx + 2];
				hero[j][i].Force = resByte[resselected][idx + 3];
				hero[j][i].IQ = resByte[resselected][idx + 4];
				hero[j][i].Devotion = resByte[resselected][idx + 5];
				hero[j][i].Character = resByte[resselected][idx + 6];
				hero[j][i].Experience = resByte[resselected][idx + 7];
				hero[j][i].Thew = resByte[resselected][idx + 8];
				hero[j][i].ArmsType = resByte[resselected][idx + 9];

				byte[] b1 = new byte[2];
				b1[0] = resByte[resselected][idx + 10];
				b1[1] = resByte[resselected][idx + 11];
				hero[j][i].Arms = Byte2Int16(b1, 0);

				hero[j][i].Equip[0] = resByte[resselected][idx + 12];
				hero[j][i].Equip[1] = resByte[resselected][idx + 13];
				hero[j][i].Age = resByte[resselected][idx + 14];

				idx += 15;

			}
		}
	}

	private void InitHeroCon(int resselected)
	{

		//reshead[resselected].
		int idx = 0;
		//HERO [] hero= new HERO[200];
		for (int j = 0; j < 4; j++)
		{

			for (int i = 0; i < 200; i++)
			{
				hero[j][i].BornYear = resByte[resselected][idx + 0];
				hero[j][i].SearchId = resByte[resselected][idx + 1];
				hero[j][i].AppearCityId = resByte[resselected][idx + 2];

				idx += 3;

			}
		}
	}

	private void InitGoodAtWhere(int resselected)
	{
		int idx = 0;

		for (int jj = 0; jj < 4; jj++)
		{
			for (idx = 0; idx < 33; idx++)
			{
				g_GoodsQueue[jj][idx] = resByte[resselected ][jj*33 + idx];

			}
		}


		for (int jj = 0; jj < 4; jj++)
		{
			idx = 0;
			for (int ii = 0; ii < 38; ii++)//城池
			{
				int i, j;

				j = city[jj][ii].ToolQueue&0xff;

				for (i = 0; i < getUnsignedByte(city[jj][ ii].Tools); i++,j++)
				{
					int tmp = (int)g_GoodsQueue[jj][j]&0xff;
					good[jj][ tmp].AppearCityId = (byte)(ii+1);

				}

			}
		}
	}

	private void InitHeroAtWhere(int resselected)
	{
		int idx = 0;

		for (int jj = 0; jj < 4; jj++)
		{
			for (idx = 0; idx < 200; idx++)
			{
				g_HeroQueue[jj][ idx] = resByte[resselected][ jj * 200 + idx];

			}
		}


		for (int jj = 0; jj < 4; jj++)
		{
			idx = 0;
			for (int ii = 0; ii < 38; ii++)//城池
			{
				int i, j;

				j = (int)city[jj][ ii].PersonQueue&0xff;

				for (i = 0; i < getUnsignedByte(city[jj][ii].Persons); i++, j++)
				{
					int tmp = (int)g_HeroQueue[jj][j]&0xff;
					hero[jj][tmp].AppearCityId = (byte)(ii+1);

				}

			}
		}
	}

	private void InitPanel(int type)
	{
		if (type == 0)
		{

			if(lcbxHeroPeriod.length >0)cbxHeroPeriod.setSelection(0);
			cbxHeroId.setSelection(0);
			//SetHeroInfo();
			g_idHero = 0;
		}
		if (type == 1)
		{
			if (lcbxCityPeriod.length >0) cbxCityPeriod.setSelection(0);
			cbxCityId.setSelection(0);
			//SetCityInfo();
			g_idCity = 0;
		}
		if (type == 2)
		{
			if (lcbxGoodPeriod.length > 0) cbxGoodPeriod.setSelection(0);
			cbxGoodId.setSelection(0);
			//SetGoodInfo();
			g_idGood = 0;
		}
	}

	private void SaveCityData()
	{
		int pid = cbxCityPeriod.getSelectedItemPosition();
		int hid = g_idCity;
		cityname[hid] = tbxCityName.getText().toString();
		city[pid][hid].Belong = (byte)(cbxCityBelong.getSelectedItemPosition());
		city[pid][hid].PeopleDevotion = (byte)Integer.parseInt(tbxCityPeopleDevotion.getText().toString());
		city[pid][hid].FarmingLimit = (short)Integer.parseInt(tbxCityFarmingLimit.getText().toString());
		city[pid][hid].Farming =(short)Integer.parseInt(tbxCityFarming.getText().toString());
		city[pid][hid].CommerceLimit = (short)Integer.parseInt(tbxCityCommerceLimit.getText().toString());
		city[pid][hid].Commerce = (short)Integer.parseInt(tbxCityCommerce.getText().toString());
		city[pid][hid].PopulationLimit = (int)Integer.parseInt(tbxCityPopulationLimit.getText().toString());
		city[pid][hid].Population = (int)Integer.parseInt(tbxCityPopulation.getText().toString());
		city[pid][hid].AvoidCalamity = (byte)Integer.parseInt(tbxCityAvoidCalamity.getText().toString());
		city[pid][hid].Money = (short)Integer.parseInt(tbxCityMoney.getText().toString());
		city[pid][hid].Food = (short)Integer.parseInt(tbxCityFood.getText().toString());
		city[pid][hid].MothballArms = (short)Integer.parseInt(tbxCityMothballArms.getText().toString());
	}

	private void SetCityData()
	{
		int pid = cbxCityPeriod.getSelectedItemPosition();
		int hid = (int)cbxCityId.getSelectedItemPosition() ;
		//cbxHeroBelong.Text = heroname[pid, hero[pid, hid].Belong - 1];
		cbxCityBelong.setSelection((int)city[pid][hid].Belong&0xff );
		tbxCityPeopleDevotion.setText((int)(city[pid][hid].PeopleDevotion&0xff)+"");
		tbxCityFarmingLimit.setText((int)(city[pid][hid].FarmingLimit&0xffff)+"");
		tbxCityFarming.setText((int)(city[pid][hid].Farming&0xffff) +"");
		tbxCityCommerceLimit.setText((int)(city[pid][hid].CommerceLimit&0xffff)+"");
		tbxCityCommerce.setText((int)(city[pid][hid].Commerce&0xffff) +"");
		tbxCityPopulationLimit.setText((int)(city[pid][hid].PopulationLimit)+"" );
		tbxCityPopulation.setText((int)(city[pid][hid].Population) +"");
		tbxCityAvoidCalamity.setText((int)(city[pid][hid].AvoidCalamity&0xff)+"" );
		tbxCityMoney.setText((int)(city[pid][hid].Money&0xffff) +"");
		tbxCityFood.setText((int)(city[pid][hid].Food&0xffff) +"");
		tbxCityMothballArms.setText((int)(city[pid][hid].MothballArms&0xffff) +"");

	}

	private void SaveSavCityData()
	{
		int hid = g_idSavCity;
		savcityname[hid] = tbxSaveCityName.getText().toString();
		savcity[hid].Belong = (byte)(cbxSaveCityBelong.getSelectedItemPosition());
		savcity[hid].PeopleDevotion = (byte)Integer.parseInt(tbxSaveCityPeopleDevotion.getText().toString());
		savcity[hid].FarmingLimit = (short)Integer.parseInt(tbxSaveCityFarmingLimit.getText().toString());
		savcity[hid].Farming = (short)Integer.parseInt(tbxSaveCityFarming.getText().toString());
		savcity[hid].CommerceLimit = (short)Integer.parseInt(tbxSaveCityCommerceLimit.getText().toString());
		savcity[hid].Commerce = (short)Integer.parseInt(tbxSaveCityCommerce.getText().toString());
		savcity[hid].PopulationLimit = Integer.parseInt(tbxSaveCityPopulationLimit.getText().toString());
		savcity[hid].Population = Integer.parseInt(tbxSaveCityPopulation.getText().toString());
		savcity[hid].AvoidCalamity = (byte)Integer.parseInt(tbxSaveCityAvoidCalamity.getText().toString());
		savcity[hid].Money = (short)Integer.parseInt(tbxSaveCityMoney.getText().toString());
		savcity[hid].Food = (short)Integer.parseInt(tbxSaveCityFood.getText().toString());
		savcity[hid].MothballArms = (short)Integer.parseInt(tbxSaveCityMothballArms.getText().toString());
	}

	private void SetSavCityData()
	{
		int hid = (int)cbxSaveCityId.getSelectedItemPosition();// SelectedIndex;
		//cbxHeroBelong.Text = heroname[pid, hero[pid, hid].Belong - 1];
		cbxSaveCityBelong.setSelection((int)savcity[hid].Belong&0xff);
		tbxSaveCityPeopleDevotion.setText((int)(savcity[hid].PeopleDevotion&0xff)+"");
		tbxSaveCityFarmingLimit.setText((int)(savcity[hid].FarmingLimit&0xffff)+"");
		tbxSaveCityFarming.setText((int)(savcity[hid].Farming&0xffff)+"");
		tbxSaveCityCommerceLimit.setText((int)(savcity[hid].CommerceLimit&0xffff)+"");
		tbxSaveCityCommerce.setText((int)(savcity[hid].Commerce&0xffff)+"");
		tbxSaveCityPopulationLimit.setText((int)(savcity[hid].PopulationLimit)+"");
		tbxSaveCityPopulation.setText((int)(savcity[hid].Population)+"");
		tbxSaveCityAvoidCalamity.setText((int)(savcity[hid].AvoidCalamity&0xff)+"");
		tbxSaveCityMoney.setText((int)(savcity[hid].Money&0xffff)+"");
		tbxSaveCityFood.setText((int)(savcity[hid].Food&0xffff)+"");
		tbxSaveCityMothballArms.setText((int)(savcity[hid].MothballArms&0xffff)+"");

	}

	private void SetGoodInfo()
	{
		int period = cbxGoodPeriod.getSelectedItemPosition();
		//cbxGoodId.Items.Clear();
		if(period < 0)period = 0;
		//lcbxGoodAppearCityId = new String[38+1];
		//lcbxGoodSearchId = new String[200+1];
		//lcbxGoodId[0] = 0+"";

		lcbxGoodAppearCityId[0] ="无";
		lcbxGoodSearchId[0] ="无";
		lcbxGoodId[0] = 0+"";

		for (int i = 0; i < 33; i++)
		{
			if(i<32)lcbxGoodId[i+1] = (i+1)+"";
		}

		for (int i = 0; i < 38; i++)
		{
			lcbxGoodAppearCityId[i+1] = cityname[i];
		}

		for (int i = 0; i < 200; i++)
		{
			lcbxGoodSearchId[i+1] = heroname[period][i];
		}

		ArrayAdapter<String> aacbxGoodSearchId  = new ArrayAdapter<String>(Modify_MainActivity.this, android.R.layout.simple_spinner_item, lcbxGoodSearchId);
		cbxGoodSearchId.setAdapter(aacbxGoodSearchId);
		aacbxGoodSearchId.notifyDataSetChanged();

	}


	private void SaveGoodData()
	{
		int pid = cbxGoodPeriod.getSelectedItemPosition();
		int hid = g_idGood;
		goodname[hid] = tbxGoodName.getText().toString();
		good[0][hid].useflag = (byte)(cbxGoodUseFlag.getSelectedItemPosition());
		good[0][hid].at = (byte)Integer.parseInt(tbxGoodAt.getText().toString());
		good[0][hid].iq = (byte)Integer.parseInt(tbxGoodIQ.getText().toString());
		good[0][hid].move = (byte)Integer.parseInt(tbxGoodMove.getText().toString());
		good[0][hid].arm = (byte)cbxGoodArm.getSelectedItemPosition();

		good[pid][hid].AppearYear = (byte)Integer.parseInt(tbxGoodAppearYear.getText().toString());
		good[pid][hid].SearchId = (byte)(cbxGoodSearchId.getSelectedItemPosition());
		good[pid][hid].AppearCityId = (byte)(cbxGoodAppearCityId.getSelectedItemPosition());



	}

	private void SetGoodData()
	{
		int pid = cbxGoodPeriod.getSelectedItemPosition();
		int hid = (int)cbxGoodId.getSelectedItemPosition();// SelectedIndex;
		//cbxHeroBelong.Text = heroname[pid, hero[pid, hid].Belong - 1];
		cbxGoodUseFlag.setSelection((int)good[0][hid].useflag&0xff);
		tbxGoodAt.setText((int)(good[0][hid].at&0xff)+"");
		tbxGoodIQ.setText((int)(good[0][hid].iq&0xff)+"" );
		tbxGoodMove.setText((int)(good[0][hid].move&0xff) +"");
		cbxGoodArm.setSelection ((int)good[0][hid].arm&0xff);
		tbxGoodAppearYear.setText((int)(good[pid][hid].AppearYear&0xff)+"");
		cbxGoodSearchId.setSelection((int)good[pid][hid].SearchId&0xff) ;
		cbxGoodAppearCityId.setSelection((int)good[pid][hid].AppearCityId&0xff );

	}

	private void UpdateCityName(int resselected)
	{
		int idx = 0;

		byte reskey = (byte)0xc0;

		for (int i = 0; i < 38; i++)
		{
		    try
		    {
			byte[] b0 = cityname[i].getBytes("GB2312");

			int len = b0.length > 10 ? 10 : b0.length;
			for (int k = 0; k < 10; k++)
			{
				resByte[resselected][idx + k] = reskey;
				if (k < len)
				{
					resByte[resselected][idx + k] = (byte) (b0[k] + reskey);
				}
			}

			idx += 10;
			}
			catch(Exception e){}

		}

	}

	private void UpdateCity(int resselected)
	{

		int idx = 0;

		for (int j = 0; j < 4; j++)
		{
			for (int i = 0; i < 38; i++)
			{
				resByte[resselected][idx] = city[j][i].Id;
				resByte[resselected][idx + 1] = city[j][i].Belong;
				resByte[resselected][idx + 2] = city[j][i].SatrapId;

				resByte[resselected][idx + 3] = (byte)((city[j][i].FarmingLimit ) & 0xFF);
				resByte[resselected][idx + 4] = (byte)((city[j][i].FarmingLimit >> 8) & 0xFF);

				resByte[resselected][idx + 5] = (byte)((city[j][i].Farming ) & 0xFF);
				resByte[resselected][idx + 6] = (byte)((city[j][i].Farming >> 8) & 0xFF);

				resByte[resselected][idx + 7] = (byte)((city[j][i].CommerceLimit) & 0xFF);
				resByte[resselected][idx + 8] = (byte)((city[j][i].CommerceLimit >> 8) & 0xFF);


				resByte[resselected][idx + 9] = (byte)((city[j][i].Commerce) & 0xFF);
				resByte[resselected][idx + 10] = (byte)((city[j][i].Commerce >> 8) & 0xFF);


				resByte[resselected][idx + 11] = city[j][i].PeopleDevotion;
				resByte[resselected][idx + 12] = city[j][i].AvoidCalamity;

				resByte[resselected][idx + 13] = (byte)((city[j][i].PopulationLimit) & 0xFF);
				resByte[resselected][idx + 14] = (byte)((city[j][i].PopulationLimit >> 8) & 0xFF);
				resByte[resselected][idx + 15] = (byte)((city[j][i].PopulationLimit >> 16) & 0xFF);
				resByte[resselected][idx + 16] = (byte)((city[j][i].PopulationLimit >> 24) & 0xFF);


				resByte[resselected][idx + 17] = (byte)((city[j][i].Population ) & 0xFF);
				resByte[resselected][idx + 18] = (byte)((city[j][i].Population >> 8) & 0xFF);
				resByte[resselected][idx + 19] = (byte)((city[j][i].Population >> 16) & 0xFF);
				resByte[resselected][idx + 20] = (byte)((city[j][i].Population >> 24) & 0xFF);

				resByte[resselected][idx + 21] = (byte)((city[j][i].Money) & 0xFF);
				resByte[resselected][idx + 22] = (byte)((city[j][i].Money >> 8) & 0xFF);

				resByte[resselected][idx + 23] = (byte)((city[j][i].Food) & 0xFF);
				resByte[resselected][idx + 24] = (byte)((city[j][i].Food >> 8) & 0xFF);

				resByte[resselected][idx + 25] = (byte)((city[j][i].MothballArms) & 0xFF);
				resByte[resselected][idx + 26] = (byte)((city[j][i].MothballArms >> 8) & 0xFF);

				//resByte[resselected][idx + 27] = city[j][i].PersonQueue;
				//resByte[resselected][idx + 28] = city[j][i].Persons;
				//resByte[resselected][idx + 29] = city[j][i].ToolQueue;
				//resByte[resselected][idx + 30] = city[j][i].Tools;


				idx += 31;

			}
			idx += 2;
		}
	}

	private void UpdateCityHeroInfo(int resselected)
	{

		int idx = 0;

		for (int j = 0; j < 4; j++)
		{
			for (int i = 0; i < 38; i++)
			{

				resByte[resselected][idx + 27] = city[j][i].PersonQueue;
				resByte[resselected][idx + 28] = city[j][i].Persons;



				idx += 31;

			}
			idx += 2;
		}
	}

	private void UpdateCityGoodInfo(int resselected)
	{

		int idx = 0;

		for (int j = 0; j < 4; j++)
		{
			for (int i = 0; i < 38; i++)
			{

				resByte[resselected][idx + 29] = city[j][i].ToolQueue;
				resByte[resselected][idx + 30] = city[j][i].Tools;


				idx += 31;

			}
			idx += 2;
		}
	}

	private void SaveHeroData()
	{
		int pid = cbxHeroPeriod.getSelectedItemPosition();
		int hid = g_idHero;
		heroname[pid][hid] = tbxHeroName.getText().toString();
		//cbxHeroBelong.Text = heroname[pid, hero[pid, hid].Belong - 1];
		hero[pid][hid].Belong = (byte)(cbxHeroBelong.getSelectedItemPosition() ) ;
		hero[pid][hid].Level = (byte)Integer.parseInt(tbxHeroDegree.getText().toString());
		hero[pid][hid].Force = (byte)Integer.parseInt(tbxHeroForce.getText().toString());
		hero[pid][hid].IQ = (byte)Integer.parseInt(tbxHeroIQ.getText().toString());
		hero[pid][hid].Devotion = (byte)Integer.parseInt(tbxHeroDevotion.getText().toString());
		hero[pid][hid].Character = (byte)(cbxHeroCharacter.getSelectedItemPosition() ) ;
		hero[pid][hid].ArmsType = (byte)(cbxHeroArmsType.getSelectedItemPosition()  ) ;
		hero[pid][hid].Age = (byte)Integer.parseInt(tbxHeroAge.getText().toString());
		hero[pid][hid].Equip[0] = (byte)(cbxHeroEquip1.getSelectedItemPosition());
		hero[pid][hid].Equip[1] = (byte)(cbxHeroEquip2.getSelectedItemPosition());

		hero[pid][hid].BornYear = (byte)Integer.parseInt(tbxHeroBornYear.getText().toString());
		hero[pid][hid].SearchId = (byte)(cbxHeroSearchId.getSelectedItemPosition());
		hero[pid][hid].AppearCityId = (byte)(cbxHeroAppearCityId.getSelectedItemPosition());
	}


	private void UpdateHero(int resselected)
	{


		int idx = 0;

		for (int j = 0; j < 4; j++)
		{

			for (int i = 0; i < 200; i++)
			{
				resByte[resselected][idx] = hero[j][i].Id;
				resByte[resselected][idx + 1] = hero[j][i].Belong;
				resByte[resselected][idx + 2] = hero[j][i].Level;
				resByte[resselected][idx + 3] = hero[j][i].Force;
				resByte[resselected][idx + 4] = hero[j][i].IQ;
				resByte[resselected][idx + 5] = hero[j][i].Devotion;
				resByte[resselected][idx + 6] = hero[j][i].Character;
				resByte[resselected][idx + 7] = hero[j][i].Experience;
				resByte[resselected][idx + 8] = hero[j][i].Thew;
				resByte[resselected][idx + 9] = hero[j][i].ArmsType;

				resByte[resselected][idx + 10] = (byte)((hero[j][i].Arms ) & 0xFF);
				resByte[resselected][idx + 11] = (byte)((hero[j][i].Arms >> 8) & 0xFF);

				resByte[resselected][idx + 12] = hero[j][i].Equip[0];
				resByte[resselected][idx + 13] = hero[j][i].Equip[1];
				resByte[resselected][idx + 14] = hero[j][i].Age;

				idx += 15;

			}
		}
	}

	private void UpdateHeroCon(int resselected)
	{


		int idx = 0;

		for (int j = 0; j < 4; j++)
		{

			for (int i = 0; i < 200; i++)
			{
				resByte[resselected][idx + 0] = hero[j][i].BornYear;
				resByte[resselected][idx + 1] = hero[j][i].SearchId;
				resByte[resselected][idx + 2] = hero[j][i].AppearCityId;

				idx += 3;

			}
		}
	}

	private void UpdateHeroAtWhere(int resselected)
	{
		int idx = 0;

		for (int ji = 0; ji < 4; ji++)
		{
			for (int jk = 0; jk < 200; jk++)
			{
				g_HeroQueue[ji][jk] = 0;
			}
		}


		for (int jj = 0; jj < 4; jj++)
		{
			idx = 0;
			for (int ii = 0; ii < 38; ii++)//城池
			{
				city[jj][ii].Persons = 0;
				city[jj][ii].PersonQueue = (byte)idx;
				for (int kk = 0; kk < 200; kk++)//武将
				{
					if (hero[jj][kk].AppearCityId == (ii + 1))
					{
						city[jj][ii].Persons++;
						g_HeroQueue[jj][idx] = (byte)kk;
						idx++;
					}

				}
			}
		}

		UpdateCityHeroInfo(56);

		for (int yu = 0; yu < 4; yu++)
		{
			for (idx = 0; idx < 200; idx++)
			{
				resByte[resselected][yu*200+idx] = g_HeroQueue[yu][idx];

			}
		}
	}

	private void UpdateHeroName(int resselected)
	{
		int idx = 0;
		int ridx = 0;

		if (resselected == 61) ridx = 0;
		if (resselected == 69) ridx = 1;
		if (resselected == 70) ridx = 2;
		if (resselected == 71) ridx = 3;

		byte reskey = (byte)0xc3;

		for (int i = 0; i < 200; i++)
		{
		    try
		    {
			byte[] b0 =heroname[ridx][i].getBytes("GB2312");

			int len = b0.length>8?8:b0.length;
			for (int k = 0; k < 8; k++)
			{
				resByte[resselected][idx + k] = reskey;
				if (k < len)
				{
					resByte[resselected][idx + k] = (byte) (b0[k] + reskey);
				}
			}

			idx += 8;
            }
			catch(Exception e){}
		}

	}




	private void UpdateGoodAtWhere(int resselected)
	{
		int idx = 0;

		for (int ji = 0; ji < 4; ji++)
		{
			for (int jk = 0; jk < 33; jk++)
			{
				g_GoodsQueue[ji][jk] = 0;
			}
		}


		for (int jj = 0; jj < 4; jj++)
		{
			idx = 0;
			for (int ii = 0; ii < 38; ii++)//城池
			{
				city[jj][ii].Tools = 0;
				city[jj][ii].ToolQueue = (byte)idx;

				for (int kk = 0; kk < 33; kk++)//道具
				{
					if (good[jj][ kk].AppearCityId == (ii + 1))
					{
						city[jj][ ii].Tools++;
						g_GoodsQueue[jj][idx] = (byte)kk;
						idx++;
					}


				}

			}
		}

		UpdateCityGoodInfo(56);

		for (int yu = 0; yu < 4; yu++)
		{
			for (idx = 0; idx < 33; idx++)
			{
				resByte[resselected][yu*33 + idx] = g_GoodsQueue[yu][idx];

			}
		}

	}

	private void UpdateGood(int resselected)
	{
		//reshead[resselected].
		int idx = 0;
		//HERO [] hero= new HERO[200];

		for (int i = 0; i < 33; i++)
		{
			resByte[resselected][ idx] = good[0][i].idx;
			resByte[resselected][ idx + 1] = good[0][i].useflag;

			//public byte[] name = new byte[10];		/* 道具名字 */


			//public byte[] inf = new byte[50];		/* 道具说明 */

			resByte[resselected][ idx + 62] = good[0][i].at;
			resByte[resselected][ idx + 63] = good[0][i].iq;
			resByte[resselected][ idx + 64] = good[0][i].move;
			resByte[resselected][ idx + 65] = good[0][i].arm;


			idx += 66;

		}
	}

	private void UpdateGoodCon(int resselected)
	{
		//reshead[resselected].
		int idx = 0;
		//HERO [] hero= new HERO[200];
		for (int j = 0; j < 4; j++)
		{
			for (int i = 0; i < 33; i++)
			{
				resByte[resselected][idx + 0] = good[j][i].AppearYear;
				resByte[resselected][idx + 1] = good[j][i].SearchId;
				resByte[resselected][idx + 2] = good[j][i].AppearCityId;

				idx += 3;

			}
		}
	}

	private void UpdateGoodName(int resselected)
	{
		int idx = 0;


		byte reskey = (byte)0xc3;

		for (int i = 0; i < 33; i++)
		{
		    try
		    {
			byte[] b0 = goodname[i].getBytes("GB2312");

			int len = b0.length > 10 ? 10 : b0.length;
			for (int k = 0; k < 10; k++)
			{
				resByte[resselected][idx + k] = reskey;
				if (k < len)
				{
					resByte[resselected][idx + k] = (byte) (b0[k] + reskey);
				}
			}

			idx += 10;
            }
			catch(Exception e){}
		}

	}

	private void UpdateCitySav()
	{

		int idx = 0;
		int startPos = 3245 + 1530;


		for (int i = 0; i < 38; i++)
		{
			savByte[startPos] = savcity[i].Id;
			savByte[startPos + 1] = savcity[i].Belong;
			savByte[startPos + 2] = savcity[i].SatrapId;

			savByte[startPos + 3] = (byte)((savcity[i].FarmingLimit) & 0xFF);
			savByte[startPos + 4] = (byte)((savcity[i].FarmingLimit >> 8) & 0xFF);

			savByte[startPos + 5] = (byte)((savcity[i].Farming) & 0xFF);
			savByte[startPos + 6] = (byte)((savcity[i].Farming >> 8) & 0xFF);

			savByte[startPos + 7] = (byte)((savcity[i].CommerceLimit) & 0xFF);
			savByte[startPos + 8] = (byte)((savcity[i].CommerceLimit >> 8) & 0xFF);


			savByte[startPos + 9] = (byte)((savcity[i].Commerce) & 0xFF);
			savByte[startPos + 10] = (byte)((savcity[i].Commerce >> 8) & 0xFF);


			savByte[startPos + 11] = savcity[i].PeopleDevotion;
			savByte[startPos + 12] = savcity[i].AvoidCalamity;

			savByte[startPos + 13] = (byte)((savcity[i].PopulationLimit) & 0xFF);
			savByte[startPos + 14] = (byte)((savcity[i].PopulationLimit >> 8) & 0xFF);
			savByte[startPos + 15] = (byte)((savcity[i].PopulationLimit >> 16) & 0xFF);
			savByte[startPos + 16] = (byte)((savcity[i].PopulationLimit >> 24) & 0xFF);


			savByte[startPos + 17] = (byte)((savcity[i].Population) & 0xFF);
			savByte[startPos + 18] = (byte)((savcity[i].Population >> 8) & 0xFF);
			savByte[startPos + 19] = (byte)((savcity[i].Population >> 16) & 0xFF);
			savByte[startPos + 20] = (byte)((savcity[i].Population >> 24) & 0xFF);

			savByte[startPos + 21] = (byte)((savcity[i].Money) & 0xFF);
			savByte[startPos + 22] = (byte)((savcity[i].Money >> 8) & 0xFF);

			savByte[startPos + 23] = (byte)((savcity[i].Food) & 0xFF);
			savByte[startPos + 24] = (byte)((savcity[i].Food >> 8) & 0xFF);

			savByte[startPos + 25] = (byte)((savcity[i].MothballArms) & 0xFF);
			savByte[startPos + 26] = (byte)((savcity[i].MothballArms >> 8) & 0xFF);

			savByte[startPos + 27] = savcity[i].PersonQueue;
			savByte[startPos + 28] = savcity[i].Persons;
			savByte[startPos + 29] = savcity[i].ToolQueue;
			savByte[startPos + 30] = savcity[i].Tools;


			startPos += 31;

		}

	}

	private void UpdateHeroSav()
	{


		int idx = 0;

		int startPos = 12;

		for (int i = 0; i < 200; i++)
		{
			savByte[startPos] = savhero[i].Id;
			savByte[startPos + 1] = savhero[i].Belong;
			savByte[startPos + 2] = savhero[i].Level;
			savByte[startPos + 3] = savhero[i].Force;
			savByte[startPos + 4] = savhero[i].IQ;
			savByte[startPos + 5] = savhero[i].Devotion;
			savByte[startPos + 6] = savhero[i].Character;
			savByte[startPos + 7] = savhero[i].Experience;
			savByte[startPos + 8] = savhero[i].Thew;
			savByte[startPos + 9] = savhero[i].ArmsType;

			savByte[startPos + 10] = (byte)((savhero[i].Arms) & 0xFF);
			savByte[startPos + 11] = (byte)((savhero[i].Arms >> 8) & 0xFF);

			savByte[startPos + 12] = savhero[i].Equip[0];
			savByte[startPos + 13] = savhero[i].Equip[1];
			savByte[startPos + 14] = savhero[i].Age;

			startPos += 15;

		}

	}


	private void OpenSsv(int idx)
	{
		isLib = false;
		isSsv = true;
		String filename = Public.SDPATH ;
		String filename1 = Public.SDPATH ;
		//filename = Public.SDPATH +"dat.lib";
		if (idx == 0)
		{
			filename += "sango0.sav";
			filename1 += "sango1.sav";
		}
		else if (idx == 1)
		{
			filename += "sango2.sav";
			filename1 += "sango3.sav";
		}
		else if (idx == 2)
		{
			filename += "sango4.sav";
			filename1 += "sango5.sav";
		}
		g_filename = filename;
		g_filename1 = filename1;
		MyOpenSav(filename, filename1);
		isRlb = false;
		noRlb = false;

	}

	private void MyOpenSav(String filename, String filename1)
	{

		try
		{

			FileInputStream fin =new FileInputStream(filename);
			DataInputStream data_in = new DataInputStream(fin);
			savByteLen = fin.available();
			data_in.read(savByte,0,savByteLen);
			fin.close();

			FileInputStream fin1 =new FileInputStream(filename1);
			DataInputStream data_in1 = new DataInputStream(fin1);
			int t_savByteLen = fin1.available();
			for (int i = savByteLen; i < savByteLen + t_savByteLen; i++)
			{
				savByte[i] = data_in1.readByte();//read(savByte[i],i,1);
			}

			savByteLen += t_savByteLen;
			fin1.close();

		}
		catch(Exception e){}

		savPeriod = savByte[0] - 1;
		if(savPeriod<0)savPeriod = 0;//20190305

		int startPos = 12;

		for (int i = 0; i < 200; i++)
		{
			savhero[i] = new HERO();
			savhero[i].Id = savByte[startPos];
			savhero[i].Belong = savByte[startPos + 1];
			savhero[i].Level = savByte[startPos + 2];
			savhero[i].Force = savByte[startPos + 3];
			savhero[i].IQ = savByte[startPos + 4];
			savhero[i].Devotion = savByte[startPos + 5];
			savhero[i].Character = savByte[startPos + 6];
			savhero[i].Experience = savByte[startPos + 7];
			savhero[i].Thew = savByte[startPos + 8];
			savhero[i].ArmsType = savByte[startPos + 9];

			byte[] b1 = new byte[2];
			b1[0] = savByte[startPos + 10];
			b1[1] = savByte[startPos + 11];
			savhero[i].Arms = Byte2Int16(b1, 0);

			savhero[i].Equip[0] = savByte[startPos + 12];
			savhero[i].Equip[1] = savByte[startPos + 13];
			savhero[i].Age = savByte[startPos + 14];

			startPos += 15;
		}

		startPos = 3245 + 1530;

		for (int i = 0; i < 38; i++)
		{
			savcity[i] = new CITY();
			savcity[i].Id = savByte[startPos];
			savcity[i].Belong = savByte[startPos + 1];
			savcity[i].SatrapId = savByte[startPos + 2];

			byte[] b1 = new byte[2];
			b1[0] = savByte[startPos + 3];
			b1[1] = savByte[startPos + 4];
			savcity[i].FarmingLimit = Byte2Int16(b1, 0);

			byte[] b2 = new byte[2];
			b2[0] = savByte[startPos + 5];
			b2[1] = savByte[startPos + 6];
			savcity[i].Farming = Byte2Int16(b2, 0);

			byte[] b3 = new byte[2];
			b3[0] = savByte[startPos + 7];
			b3[1] = savByte[startPos + 8];
			savcity[i].CommerceLimit = Byte2Int16(b3, 0);

			byte[] b4 = new byte[2];
			b4[0] = savByte[startPos + 9];
			b4[1] = savByte[startPos + 10];
			savcity[i].Commerce = Byte2Int16(b4, 0);

			savcity[i].PeopleDevotion = savByte[startPos + 11];
			savcity[i].AvoidCalamity = savByte[startPos + 12];

			byte[] b5 = new byte[4];
			b5[0] = savByte[startPos + 13];
			b5[1] = savByte[startPos + 14];
			b5[2] = savByte[startPos + 15];
			b5[3] = savByte[startPos + 16];
			savcity[i].PopulationLimit = Byte2Int(b5, 0);

			byte[] b6 = new byte[4];
			b6[0] = savByte[startPos + 17];
			b6[1] = savByte[startPos + 18];
			b6[2] = savByte[startPos + 19];
			b6[3] = savByte[startPos + 20];
			savcity[i].Population = Byte2Int(b6, 0);

			byte[] b7 = new byte[2];
			b7[0] = savByte[startPos + 21];
			b7[1] = savByte[startPos + 22];
			savcity[i].Money = Byte2Int16(b7, 0);

			byte[] b8 = new byte[2];
			b8[0] = savByte[startPos + 23];
			b8[1] = savByte[startPos + 24];
			savcity[i].Food = Byte2Int16(b8, 0);

			byte[] b9 = new byte[2];
			b9[0] = savByte[startPos + 25];
			b9[1] = savByte[startPos + 26];
			savcity[i].MothballArms = Byte2Int16(b9, 0);

			savcity[i].PersonQueue = savByte[startPos + 27];
			savcity[i].Persons = savByte[startPos + 28];
			savcity[i].ToolQueue = savByte[startPos + 29];
			savcity[i].Tools = savByte[startPos + 30];


			startPos += 31;

		}

            /*gam_fwrite((U8 *)&g_PIdx,1,1,fp);
	gam_fwrite((U8 *)&g_PlayerKing,1,1,fp);
	gam_fwrite((U8 *)&g_YearDate,2,1,fp);
	gam_fwrite((U8 *)&g_LookEnemy,1,1,fp);
	gam_fwrite((U8 *)&g_LookMovie,1,1,fp);
	gam_fwrite((U8 *)&g_MoveSpeed,1,1,fp);
	gam_fwrite((U8 *)&g_MonthDate,1,1,fp);
	gam_fwrite((U8 *)&g_CityPos,sizeof(CitySetType),1,fp);//4
	gam_fwrite((U8 *)g_Persons,sizeof(PersonType),PERSON_MAX,fp);//15*200
	gam_fwrite((U8 *)g_PersonsQueue,1,PERSON_MAX,fp);//200
	gam_fwrite((U8 *)g_GoodsQueue,1,GOODS_MAX,fp);*///33

            /*gam_fwrite((U8 *)FIGHTERS_IDX,1,FIGHT_ORDER_MAX,fp);//30
	gam_fwrite((U8 *)FIGHTERS,10,FIGHT_ORDER_MAX,fp);//30*10
	gam_fwrite((U8 *)ORDERQUEUE,sizeof(OrderType),ORDER_MAX,fp);//12*100
	gam_fwrite((U8 *)g_Cities,sizeof(CityType),CITY_MAX,fp);*///31*38
		//InitRlb();

	}

	private void MySaveSav(String FileName, String FileName1)
	{

		//int savByteLen = 3245 + 2708;
		int startPos = 0;

		try
		{


			FileOutputStream fout =new FileOutputStream(FileName);
			DataOutputStream data_out = new DataOutputStream(fout);
			//rlbByteLen = fout.available();
			for (int i = 0; i < 3245; i++)
			{
				data_out.write(savByte[i]);
			}
			fout.close();

			startPos = 3245;

			FileOutputStream fout1 =new FileOutputStream(FileName1);
			DataOutputStream data_out1 = new DataOutputStream(fout1);
			//rlbByteLen = fout.available();
			for (int i = startPos; i < startPos + 2708; i++)
			{
				data_out.write(savByte[i]);
			}
			fout1.close();



		}
		catch(Exception e){}

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		super.onCreateOptionsMenu(menu);
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

    


	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
			case R.id.menu_settings:
				//设置
				menu_set();
				return true;
			case R.id.menu_whatsnew:
				//更新记录
				menu_new();
				return true;

			case R.id.menu_update :
				//反馈
				menu_update();
				return true;
			case R.id.menu_about:
				//关于
				menu_abt();
				return true;
		}
		return false; //should never happen
	}

	private void menu_update() {
		// TODO Auto-generated method stub
		//UpdateManager manager = new UpdateManager(MainActivity.this);
		// 检查软件更新
		//manager.checkUpdate();
	}




	private void menu_set()
	{
		new AlertDialog.Builder(Modify_MainActivity.this)
				.setTitle("帮助信息")
				.setMessage("使用前请备份存档。如果修改错误，请删除sd卡中对应文件后（sdcard/skyside3gby3/dat.lib）继续使用.\r\n ")
				.setPositiveButton("确定", null)
				.show();

	}

	private void menu_new()
	{
		new AlertDialog.Builder(Modify_MainActivity.this)
			.setTitle("更新记录")
			.setMessage(Public.getWhatsNewText())
			.setPositiveButton("确定", null)
			.show();

	}

	private void menu_abt()
	{

		new AlertDialog.Builder(Modify_MainActivity.this)
				.setTitle("版权信息")
				.setMessage("开发:天际边工作室  \r\n http://www.skysidestudio.com \r\n 版本信息： \r\n ver3.1.0 \r\n 官方下载网址：\r\n http://3gby.skysidestudio.com")
				.setPositiveButton("确定", null)
				.show();
	}

	private Spinner.OnItemSelectedListener clcbxHeroPeriod = new Spinner.OnItemSelectedListener()
	{
		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1,
								   int arg2, long arg3)
		{
			// TODO Auto-generated method stub

			if (noRlb == true)
			{
				return;
			}

			notSavedHero = true;

			cannotSave = true;
			cbxHeroId.setSelection(0);
			SetHeroInfo();
			SetHeroData();
			int pos = (int)cbxHeroId.getSelectedItemPosition();
			tbxHeroName.setText(heroname[cbxHeroPeriod.getSelectedItemPosition()][pos]);
			g_idHero = 0;

			cannotSave = false;

		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub

		}
	};

	private Spinner.OnItemSelectedListener clcbxHeroId = new Spinner.OnItemSelectedListener()
	{
		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1,
								   int arg2, long arg3)
		{
			// TODO Auto-generated method stub
			if (!tbxHeroName.getText().toString().equals("")&& (!cannotSave)) SaveHeroData();

			int pos = (int)cbxHeroId.getSelectedItemPosition();

			tbxHeroName.setText(heroname[cbxHeroPeriod.getSelectedItemPosition()][pos]);

			SetHeroData();
			g_idHero = pos;//.SelectedIndex;
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub

		}
	};

	private void SetHeroData()
	{
		int pid = cbxHeroPeriod.getSelectedItemPosition();
		int hid = (int)cbxHeroId.getSelectedItemPosition();//.SelectedIndex;
		//cbxHeroBelong.Text = heroname[pid, hero[pid, hid].Belong - 1];
		cbxHeroBelong.setSelection((int)hero[pid][hid].Belong&0xff);
		tbxHeroDegree.setText((int)(hero[pid][hid].Level&0xff)+"");
		tbxHeroForce.setText((int)(hero[pid][hid].Force&0xff)+"");
		tbxHeroIQ.setText((int)(hero[pid][hid].IQ&0xff)+"");
		tbxHeroDevotion.setText((int)(hero[pid][hid].Devotion&0xff)+"");
		cbxHeroCharacter.setSelection((int)hero[pid][hid].Character&0xff);
		cbxHeroArmsType.setSelection((int)hero[pid][hid].ArmsType&0xff);
		tbxHeroAge.setText((int)(hero[pid][hid].Age&0xff)+"");
		cbxHeroEquip1.setSelection((int)hero[pid][hid].Equip[0]&0xff);
		cbxHeroEquip2.setSelection((int)hero[pid][hid].Equip[1]&0xff);
		tbxHeroBornYear.setText((int)(hero[pid][hid].BornYear&0xff)+"");
		cbxHeroSearchId.setSelection((int)hero[pid][hid].SearchId&0xff);
		cbxHeroAppearCityId.setSelection((int)hero[pid][hid].AppearCityId&0xff);
	}

	private Spinner.OnItemSelectedListener clcbxHeroBelong = new Spinner.OnItemSelectedListener()
	{
		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1,
								   int arg2, long arg3) {
			// TODO Auto-generated method stub

		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub

		}
	};

	private Spinner.OnItemSelectedListener clcbxHeroCharacter = new Spinner.OnItemSelectedListener()
	{
		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1,
								   int arg2, long arg3) {
			// TODO Auto-generated method stub

		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub

		}
	};

	private Spinner.OnItemSelectedListener clcbxHeroArmsType = new Spinner.OnItemSelectedListener()
	{
		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1,
								   int arg2, long arg3) {
			// TODO Auto-generated method stub

		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub

		}
	};

	private Spinner.OnItemSelectedListener clcbxHeroAppearCityId = new Spinner.OnItemSelectedListener()
	{
		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1,
								   int arg2, long arg3) {
			// TODO Auto-generated method stub

		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub

		}
	};

	private Spinner.OnItemSelectedListener clcbxHeroSearchId = new Spinner.OnItemSelectedListener()
	{
		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1,
								   int arg2, long arg3) {
			// TODO Auto-generated method stub

		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub

		}
	};

	private Spinner.OnItemSelectedListener clcbxHeroEquip1  = new Spinner.OnItemSelectedListener()
	{
		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1,
								   int arg2, long arg3) {
			// TODO Auto-generated method stub

		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub

		}
	};

	private Spinner.OnItemSelectedListener clcbxHeroEquip2  = new Spinner.OnItemSelectedListener()
	{
		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1,
								   int arg2, long arg3) {
			// TODO Auto-generated method stub

		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub

		}
	};



	private void SetCityInfo()
	{
		int period = cbxCityPeriod.getSelectedItemPosition();
		if(period < 0)period = 0;
		//lcbxCityBelong = new String[200+1];

		lcbxCityBelong[0] ="无";
		lcbxCityId[0] = 0+"";

		for (int i = 0; i < 38; i++)
		{
			if(i<37)lcbxCityId[i+1] = (i+1)+"";
		}

		for (int i = 0; i < 200; i++)
		{
			lcbxCityBelong[i+1] = heroname[period][i];
		}

		ArrayAdapter<String> aacbxCityBelong  = new ArrayAdapter<String>(Modify_MainActivity.this, android.R.layout.simple_spinner_item, lcbxCityBelong );
		cbxCityBelong.setAdapter(aacbxCityBelong);
		aacbxCityBelong.notifyDataSetChanged();

	}

	private void SaveSavHeroData()
	{
		int hid = g_idSavHero;
		savheroname[hid] = tbxSaveHeroName.getText().toString();
		//cbxHeroBelong.Text = heroname[pid, hero[pid, hid].Belong - 1];
		savhero[hid].Belong = (byte)(cbxSaveHeroBelong.getSelectedItemPosition() + 0);
		savhero[hid].Level = (byte)Integer.parseInt(tbxSaveHeroDegree.getText().toString());
		savhero[hid].Force = (byte)Integer.parseInt(tbxSaveHeroForce.getText().toString());
		savhero[hid].IQ = (byte)Integer.parseInt(tbxSaveHeroIQ.getText().toString());
		savhero[hid].Devotion = (byte)Integer.parseInt(tbxSaveHeroDevotion.getText().toString());
		savhero[hid].Character = (byte)(cbxSaveHeroCharacter.getSelectedItemPosition());
		savhero[hid].ArmsType = (byte)(cbxSaveHeroArmsType.getSelectedItemPosition());
		savhero[hid].Age = (byte)Integer.parseInt(tbxSaveHeroAge.getText().toString());
		//savhero[hid].AppearCityId = (byte)(cbxSaveHeroAppearCityId.SelectedIndex + 1);
		//savhero[hid].SearchId = (byte)(cbxSaveHeroSearchId.SelectedIndex + 1);
	}

	private void SetSavHeroData()
	{

		int hid = (int)cbxSaveHeroId.getSelectedItemPosition();
		//cbxHeroBelong.Text = heroname[pid, hero[pid, hid].Belong - 1];
		cbxSaveHeroBelong.setSelection((int)savhero[hid].Belong&0xff);
		tbxSaveHeroDegree.setText((int)(savhero[hid].Level&0xff)+"");
		tbxSaveHeroForce.setText((int)(savhero[hid].Force&0xff)+"");
		tbxSaveHeroIQ.setText((int)(savhero[hid].IQ&0xff)+"");
		tbxSaveHeroDevotion.setText((int)(savhero[hid].Devotion&0xff)+"");
		cbxSaveHeroCharacter.setSelection((int)savhero[hid].Character&0xff);
		cbxSaveHeroArmsType.setSelection((int)savhero[hid].ArmsType&0xff);
		tbxSaveHeroAge.setText((int)(savhero[hid].Age&0xff)+"");


	}


	private Spinner.OnItemSelectedListener clcbxCityPeriod = new Spinner.OnItemSelectedListener()
	{
		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1,
								   int arg2, long arg3)
		{
			// TODO Auto-generated method stub
			if (noRlb == true)
			{
				return;
			}
			cannotSave = true;

			cbxHeroId.setSelection(0);
			SetCityInfo();
			SetCityData();
			int pos = (int)cbxCityId.getSelectedItemPosition();
			tbxCityName.setText(cityname[pos]);
			g_idCity = 0;

			cannotSave = false;

		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub

		}
	};

	private Spinner.OnItemSelectedListener clcbxCityId = new Spinner.OnItemSelectedListener()
	{
		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1,
								   int arg2, long arg3)
		{
			// TODO Auto-generated method stub
			if (!tbxCityName.getText().toString().equals("")&& (!cannotSave)) SaveCityData();

			int pos = (int)cbxCityId.getSelectedItemPosition();
			tbxCityName.setText(cityname[pos]);
			SetCityData();
			g_idCity = pos;
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub

		}
	};

	private Spinner.OnItemSelectedListener clcbxCityBelong = new Spinner.OnItemSelectedListener()
	{
		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1,
								   int arg2, long arg3) {
			// TODO Auto-generated method stub

		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub

		}
	};

	private Spinner.OnItemSelectedListener clcbxGoodPeriod = new Spinner.OnItemSelectedListener()
	{
		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1,
								   int arg2, long arg3)
		{
			// TODO Auto-generated method stub
			if (noRlb == true)
			{
				return;
			}
			cannotSave = true;

			cbxGoodId.setSelection(0);
			SetGoodInfo();
			SetGoodData();
			int pos = (int)cbxGoodId.getSelectedItemPosition();
			tbxGoodName.setText(goodname[pos]);

			g_idGood = 0;

			cannotSave = false;

		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub

		}
	};

	private Spinner.OnItemSelectedListener clcbxGoodId = new Spinner.OnItemSelectedListener()
	{
		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1,
								   int arg2, long arg3)
		{
			// TODO Auto-generated method stub
			if (!tbxGoodName.getText().toString().equals("")&& (!cannotSave)) SaveGoodData();

			int pos = (int)cbxGoodId.getSelectedItemPosition();

			tbxGoodName.setText(goodname[pos ]);

			SetGoodData();
			g_idGood = pos;// SelectedIndex;
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub

		}
	};

	private Spinner.OnItemSelectedListener clcbxGoodUseFlag = new Spinner.OnItemSelectedListener()
	{
		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1,
								   int arg2, long arg3) {
			// TODO Auto-generated method stub

		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub

		}
	};

	private Spinner.OnItemSelectedListener clcbxGoodArm = new Spinner.OnItemSelectedListener()
	{
		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1,
								   int arg2, long arg3) {
			// TODO Auto-generated method stub

		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub

		}
	};

	private Spinner.OnItemSelectedListener clcbxGoodAppearCityId = new Spinner.OnItemSelectedListener()
	{
		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1,
								   int arg2, long arg3) {
			// TODO Auto-generated method stub

		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub

		}
	};

	private Spinner.OnItemSelectedListener clcbxGoodSearchId = new Spinner.OnItemSelectedListener()
	{
		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1,
								   int arg2, long arg3) {
			// TODO Auto-generated method stub

		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub

		}
	};

	private Spinner.OnItemSelectedListener clcbxSaveHeroId = new Spinner.OnItemSelectedListener()
	{
		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1,
								   int arg2, long arg3) {
			// TODO Auto-generated method stub
			if (!tbxSaveHeroName.getText().toString().equals("")&& (!cannotSave)) SaveSavHeroData();

			int pos = (int)cbxSaveHeroId.getSelectedItemPosition();

			tbxSaveHeroName.setText(heroname[savPeriod][pos]);

			//SetCityInfo();
			SetSavHeroData();
			g_idSavHero = pos;//.SelectedIndex;
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub

		}
	};

	private Spinner.OnItemSelectedListener clcbxSaveHeroBelong = new Spinner.OnItemSelectedListener()
	{
		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1,
								   int arg2, long arg3) {
			// TODO Auto-generated method stub

		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub

		}
	};

	private Spinner.OnItemSelectedListener clcbxSaveHeroCharacter = new Spinner.OnItemSelectedListener()
	{
		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1,
								   int arg2, long arg3) {
			// TODO Auto-generated method stub

		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub

		}
	};

	private Spinner.OnItemSelectedListener clcbxSaveHeroArmsType = new Spinner.OnItemSelectedListener()
	{
		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1,
								   int arg2, long arg3) {
			// TODO Auto-generated method stub

		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub

		}
	};

	private Spinner.OnItemSelectedListener clcbxSaveCityId = new Spinner.OnItemSelectedListener()
	{
		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1,
								   int arg2, long arg3) {
			// TODO Auto-generated method stub
			if (!tbxSaveCityName.getText().toString().equals("")&& (!cannotSave)) SaveSavCityData();

			int pos = (int)cbxSaveCityId.getSelectedItemPosition();
			tbxSaveCityName.setText(cityname[pos]);
			SetSavCityData();
			g_idSavCity = pos;
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub

		}
	};

	private Spinner.OnItemSelectedListener clcbxSaveCityBelong = new Spinner.OnItemSelectedListener()
	{
		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1,
								   int arg2, long arg3) {
			// TODO Auto-generated method stub

		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub

		}
	};

	private void SetSavInfo()
	{
		int pos = (int)cbxSaveId.getSelectedItemPosition();
		OpenSsv(pos);

		//lcbxSaveHeroBelong = new String[200+1];
		//lcbxSaveCityBelong = new String[200+1];

		lcbxSaveHeroId[0] = "0";
		lcbxSaveCityId[0] = "0";
		lcbxSaveHeroBelong[0] = "无";
		lcbxSaveCityBelong[0] = "无";


		for (int i = 0; i < 200; i++)
		{
			//cbxHeroId.Items.Add(i+1 +"");
			if(i<199)lcbxSaveHeroId[i+1] = (i+1)+"";
			lcbxSaveHeroBelong[i+1] = heroname[savPeriod][i];
			lcbxSaveCityBelong[i+1] = heroname[savPeriod][i];

		}

		for (int i = 0; i < 38; i++)
		{
			if(i<37)lcbxSaveCityId[i+1] = (i+1)+"";
			//lcbxSaveHeroAppearCityId[i+1] = cityname[i];
		}

		ArrayAdapter<String> aacbxSaveHeroBelong  = new ArrayAdapter<String>(Modify_MainActivity.this, android.R.layout.simple_spinner_item, lcbxSaveHeroBelong );
		cbxSaveHeroBelong.setAdapter(aacbxSaveHeroBelong);
		aacbxSaveHeroBelong.notifyDataSetChanged();

		ArrayAdapter<String> aacbxSaveCityBelong  = new ArrayAdapter<String>(Modify_MainActivity.this, android.R.layout.simple_spinner_item, lcbxSaveCityBelong );
		cbxSaveCityBelong.setAdapter(aacbxSaveCityBelong);
		aacbxSaveCityBelong.notifyDataSetChanged();

	}

	private Spinner.OnItemSelectedListener clcbxSaveId = new Spinner.OnItemSelectedListener()
	{
		@Override
		public void onItemSelected(AdapterView<?> arg0, View arg1,
								   int arg2, long arg3) {
			// TODO Auto-generated method stub

			SetSavInfo();



			//cannotSave = true;

			//cbxSaveHeroId.Value = 0;
			//cbxSaveCityId.Value = 0;

			//cbxSaveHeroId_ValueChanged(sender, e);
			//cbxSaveCityId_ValueChanged(sender, e);

			//cannotSave = false;
		}
		@Override
		public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub

		}
	};


	private Button.OnClickListener clbtnSaveHero = new Button.OnClickListener()
	{
		@Override
		public void onClick(View arg0)
		{
			notSavedHero = false;
			if (!tbxHeroName.getText().toString().equals("")&& (!cannotSave)) SaveHeroData();
			UpdateHero(60);
			UpdateHeroCon(62);
			int period = cbxHeroPeriod.getSelectedItemPosition();
			if (period == 0) UpdateHeroName(61);
			if (period == 1) UpdateHeroName(69);
			if (period == 2) UpdateHeroName(70);
			if (period == 3) UpdateHeroName(71);
			UpdateHeroAtWhere(64);
			Toast.makeText(Modify_MainActivity.this,"保存成功", Toast.LENGTH_SHORT).show();
		}


	};

	private Button.OnClickListener clbtnSaveCity = new Button.OnClickListener()
{
	@Override
	public void onClick(View arg0)
	{
		if (!tbxCityName.getText().toString().equals("")&& (!cannotSave)) SaveCityData();
		UpdateCity(56);
		UpdateCityName(57);
		Toast.makeText(Modify_MainActivity.this,"保存成功", Toast.LENGTH_SHORT).show();
	}


};

	private Button.OnClickListener clbtnSaveGood = new Button.OnClickListener()
	{
		@Override
		public void onClick(View arg0)
		{
			if (!tbxGoodName.getText().toString().equals("")&& (!cannotSave)) SaveGoodData();
			UpdateGood(65);
			UpdateGoodCon(66);
			UpdateGoodName(72);
			UpdateGoodAtWhere(67);
			Toast.makeText(Modify_MainActivity.this,"保存成功", Toast.LENGTH_SHORT).show();
		}


	};

	private Button.OnClickListener clbtnSaveLib  = new Button.OnClickListener()
	{
		@Override
		public void onClick(View arg0)
		{
			//MessageBox.Show("请确认已经保存了各时期的数据", "提示");
			String FileName = Public.SDPATH +"dat.lib";
			MySave(FileName);
			Toast.makeText(Modify_MainActivity.this,"保存成功", Toast.LENGTH_SHORT).show();
		}


	};

	private Button.OnClickListener clbtnBackUpLib  = new Button.OnClickListener()
	{
		@Override
		public void onClick(View arg0)
		{
			//MessageBox.Show("请确认已经保存了各时期的数据", "提示");
			String FileName = Public.SDPATH +"dat.lib";
			String FileNameBk = Public.SDPATH +"dat_back.lib";

			File file = new File(FileNameBk);
			// 如果文件路径所对应的文件存在，并且是一个文件，则直接删除
			if (file.exists() && file.isFile())
			{
				file.delete();
			}
			File file1 = new File(FileName);
			if (file1.exists() && file1.isFile())
			{
				Public.copyFile(FileName,FileNameBk);
			}
			Toast.makeText(Modify_MainActivity.this,"备份成功", Toast.LENGTH_SHORT).show();
		}


	};

	private Button.OnClickListener clbtnRestoreLib  = new Button.OnClickListener()
	{
		@Override
		public void onClick(View arg0)
		{
			//MessageBox.Show("请确认已经保存了各时期的数据", "提示");
			String FileName = Public.SDPATH +"dat.lib";
			String FileNameBk = Public.SDPATH +"dat_back.lib";

			File file = new File(FileName);
			// 如果文件路径所对应的文件存在，并且是一个文件，则直接删除
			if (file.exists() && file.isFile())
			{
				file.delete();
			}
			File file1 = new File(FileNameBk);
			if (file1.exists() && file1.isFile())
			{
				Public.copyFile(FileNameBk,FileName);
			}
			Toast.makeText(Modify_MainActivity.this,"还原成功", Toast.LENGTH_SHORT).show();

		}


	};

	private Button.OnClickListener clbtnBackUpSav   = new Button.OnClickListener()
	{
		@Override
		public void onClick(View arg0)
		{
			//MessageBox.Show("请确认已经保存了各时期的数据", "提示");

			String FileName = Public.SDPATH +"sango0.sav";
			String FileNameBk = Public.SDPATH +"sango0_back.sav";

			File file = new File(FileNameBk);
			// 如果文件路径所对应的文件存在，并且是一个文件，则直接删除
			if (file.exists() && file.isFile())
			{
				file.delete();
			}
			File file1 = new File(FileName);
			if (file1.exists() && file1.isFile())
			{
				Public.copyFile(FileName,FileNameBk);
			}
			FileName = Public.SDPATH +"sango1.sav";
			FileNameBk = Public.SDPATH +"sango1_back.sav";

			file = new File(FileNameBk);
			// 如果文件路径所对应的文件存在，并且是一个文件，则直接删除
			if (file.exists() && file.isFile())
			{
				file.delete();
			}
			file1 = new File(FileName);
			if (file1.exists() && file1.isFile())
			{
				Public.copyFile(FileName,FileNameBk);
			}

			FileName = Public.SDPATH +"sango2.sav";
			FileNameBk = Public.SDPATH +"sango2_back.sav";

			file = new File(FileNameBk);
			// 如果文件路径所对应的文件存在，并且是一个文件，则直接删除
			if (file.exists() && file.isFile())
			{
				file.delete();
			}
			file1 = new File(FileName);
			if (file1.exists() && file1.isFile())
			{
				Public.copyFile(FileName,FileNameBk);
			}

			FileName = Public.SDPATH +"sango3.sav";
			FileNameBk = Public.SDPATH +"sango3_back.sav";

			file = new File(FileNameBk);
			// 如果文件路径所对应的文件存在，并且是一个文件，则直接删除
			if (file.exists() && file.isFile())
			{
				file.delete();
			}
			file1 = new File(FileName);
			if (file1.exists() && file1.isFile())
			{
				Public.copyFile(FileName,FileNameBk);
			}

			FileName = Public.SDPATH +"sango4.sav";
			FileNameBk = Public.SDPATH +"sango4_back.sav";

			file = new File(FileNameBk);
			// 如果文件路径所对应的文件存在，并且是一个文件，则直接删除
			if (file.exists() && file.isFile())
			{
				file.delete();
			}
			file1 = new File(FileName);
			if (file1.exists() && file1.isFile())
			{
				Public.copyFile(FileName,FileNameBk);
			}

			FileName = Public.SDPATH +"sango5.sav";
			FileNameBk = Public.SDPATH +"sango5_back.sav";

			file = new File(FileNameBk);
			// 如果文件路径所对应的文件存在，并且是一个文件，则直接删除
			if (file.exists() && file.isFile())
			{
				file.delete();
			}
			file1 = new File(FileName);
			if (file1.exists() && file1.isFile())
			{
				Public.copyFile(FileName,FileNameBk);
			}

			Toast.makeText(Modify_MainActivity.this,"备份成功", Toast.LENGTH_SHORT).show();
		}


	};

	private Button.OnClickListener clbtnRestoreSav   = new Button.OnClickListener()
	{
		@Override
		public void onClick(View arg0)
		{
			//MessageBox.Show("请确认已经保存了各时期的数据", "提示");
			String FileName = Public.SDPATH +"sango0.sav";
			String FileNameBk = Public.SDPATH +"sango0_back.sav";

			File file = new File(FileName);
			// 如果文件路径所对应的文件存在，并且是一个文件，则直接删除
			if (file.exists() && file.isFile())
			{
				file.delete();
			}
			File file1 = new File(FileNameBk);
			if (file1.exists() && file1.isFile())
			{
				Public.copyFile(FileNameBk,FileName);
			}

			FileName = Public.SDPATH +"sango1.sav";
			FileNameBk = Public.SDPATH +"sango1_back.sav";

			file = new File(FileName);
			// 如果文件路径所对应的文件存在，并且是一个文件，则直接删除
			if (file.exists() && file.isFile())
			{
				file.delete();
			}
			file1 = new File(FileNameBk);
			if (file1.exists() && file1.isFile())
			{
				Public.copyFile(FileNameBk,FileName);
			}

			FileName = Public.SDPATH +"sango2.sav";
			FileNameBk = Public.SDPATH +"sango2_back.sav";

			file = new File(FileName);
			// 如果文件路径所对应的文件存在，并且是一个文件，则直接删除
			if (file.exists() && file.isFile())
			{
				file.delete();
			}
			file1 = new File(FileNameBk);
			if (file1.exists() && file1.isFile())
			{
				Public.copyFile(FileNameBk,FileName);
			}

			FileName = Public.SDPATH +"sango3.sav";
			FileNameBk = Public.SDPATH +"sango3_back.sav";

			file = new File(FileName);
			// 如果文件路径所对应的文件存在，并且是一个文件，则直接删除
			if (file.exists() && file.isFile())
			{
				file.delete();
			}
			file1 = new File(FileNameBk);
			if (file1.exists() && file1.isFile())
			{
				Public.copyFile(FileNameBk,FileName);
			}

			FileName = Public.SDPATH +"sango4.sav";
			FileNameBk = Public.SDPATH +"sango4_back.sav";

			file = new File(FileName);
			// 如果文件路径所对应的文件存在，并且是一个文件，则直接删除
			if (file.exists() && file.isFile())
			{
				file.delete();
			}
			file1 = new File(FileNameBk);
			if (file1.exists() && file1.isFile())
			{
				Public.copyFile(FileNameBk,FileName);
			}

			FileName = Public.SDPATH +"sango5.sav";
			FileNameBk = Public.SDPATH +"sango5_back.sav";

			file = new File(FileName);
			// 如果文件路径所对应的文件存在，并且是一个文件，则直接删除
			if (file.exists() && file.isFile())
			{
				file.delete();
			}
			file1 = new File(FileNameBk);
			if (file1.exists() && file1.isFile())
			{
				Public.copyFile(FileNameBk,FileName);
			}

			Toast.makeText(Modify_MainActivity.this,"还原成功", Toast.LENGTH_SHORT).show();

		}


	};

	private Button.OnClickListener clbtnDelLib  = new Button.OnClickListener()
{
	@Override
	public void onClick(View arg0)
	{
		//MessageBox.Show("请确认已经保存了各时期的数据", "提示");
		String FileName = Public.SDPATH +"dat.lib";

		File file = new File(FileName);
		// 如果文件路径所对应的文件存在，并且是一个文件，则直接删除
		if (file.exists() && file.isFile())
		{
			file.delete();
		}
		Toast.makeText(Modify_MainActivity.this,"删除成功，请重新打开《天际边三国霸业》游戏程序后回到本程序修改数据", Toast.LENGTH_SHORT).show();
	}


};

	private Button.OnClickListener clbtnSaveSaveHero = new Button.OnClickListener()
	{
		@Override
		public void onClick(View arg0)
		{
			if (!tbxSaveHeroName.getText().toString().equals("")&& (!cannotSave)) SaveSavHeroData();
			UpdateHeroSav();
			Toast.makeText(Modify_MainActivity.this,"保存成功", Toast.LENGTH_SHORT).show();
		}


	};

	private Button.OnClickListener clbtnSaveSaveCity = new Button.OnClickListener()
	{
		@Override
		public void onClick(View arg0)
		{
			if (!tbxSaveCityName.getText().toString().equals("")&& (!cannotSave)) SaveSavCityData();
			UpdateCitySav();
			Toast.makeText(Modify_MainActivity.this,"保存成功", Toast.LENGTH_SHORT).show();
		}


	};


	private Button.OnClickListener clbtnSaveSave  = new Button.OnClickListener()
	{
		@Override
		public void onClick(View arg0)
		{

		    MySaveSav(g_filename, g_filename1);
			Toast.makeText(Modify_MainActivity.this,"保存成功", Toast.LENGTH_SHORT).show();
		}


	};

	private void MySave(String FileName)
	{
		for (int k1 = 0; k1 < 16384; k1++)
		{
			rlbByte[k1] = 0;
		}


		int pos = 16384;//4000h开始
		//resByte->rlbByte
		for (int j = 0; j < 116; j++)
		{
			//pos = resAddress[j];
			resAddress[j] = pos;
			byte[] b0 = Int2Byte(resAddress[j]);
			for (int q = 0; q < b0.length; q++)
			{
				if (q >= 4) break;
				rlbByte[j * 4 + q] = b0[q];
			}

			byte[] b1 = Int2Byte(reshead[j].ResLen);
			for (int q = 0; q < b1.length; q++)
			{
				if (q >= 4) break;
				rlbByte[pos + q] = b1[q];
			}
			pos += 4;
			byte[] b2 = Int2Byte(reshead[j].ResId);
			for (int q = 0; q < b2.length; q++)
			{
				if (q >= 2) break;
				rlbByte[pos + q] = b2[q];
			}
			pos += 2;
			byte[] b3 = Int2Byte(reshead[j].ItmCnt);
			for (int q = 0; q < b3.length; q++)
			{
				if (q >= 2) break;
				rlbByte[pos + q] = b3[q];
			}
			pos += 2;
			byte[] b4 = Int2Byte(reshead[j].ItmLen);
			for (int q = 0; q < b4.length; q++)
			{
				if (q >= 2) break;
				rlbByte[pos + q] = b4[q];
			}
			pos += 2;
			byte[] b5 = Int2Byte(reshead[j].ResKey);
			for (int q = 0; q < b5.length; q++)
			{
				if (q >= 2) break;
				rlbByte[pos + q] = b5[q];
			}

			pos += 2;

			for (int k = 0; k < reshead[j].ResLen; k++)
			{
				rlbByte[pos + k] = resByte[j][k];
			}
			pos += reshead[j].ResLen;
		}

		rlbByteLen = pos;


		try
		{


			FileOutputStream fout =new FileOutputStream(FileName);
			DataOutputStream data_out = new DataOutputStream(fout);
			//rlbByteLen = fout.available();
			for (int i = 0; i < rlbByteLen; i++)
			{
				data_out.write(rlbByte[i]);
			}
			fout.close();

		}
		catch(Exception e){}


	}

	public static int getUnsignedByte (byte data)
	{
		return data&0x0FF;
	}

	public static int getUnsignedShort (short data)
	{
		return data&0x0FFFF;
	}

	public static long getUnsignedInt (int data)
	{
		return data&0x0FFFFFFFF;
	}




}
