void frmServer_Load(object sender, EventArgs e) { //читаем карты - просто смотрим все файлы в папке Directory.CreateDirectory("maps"); var files = Directory.GetFiles("maps"); foreach (var file in files) { try { Image im = Image.FromFile(file); mapInfo map = new mapInfo(); clsGame game = new clsGame(); MD5 md5 = MD5.Create(); var fstream = File.OpenRead(file); map.hashCode = md5.ComputeHash(fstream); map.width = (ushort)im.Width; map.height = (ushort)im.Height; map.name = Path.GetFileName(file); fstream.Close(); fstream.Dispose(); im.Dispose(); lstGames.Items.Add(map.name); game.Map = map; games.Add(map.name, game); }catch (Exception ex) { } } connectWaitThread = new Thread(connectWaitProcess); threads.Add(connectWaitThread); connectWaitThread.Start(); }
// Use this for initialization void Awake() { // gm.InitPlayer(100, 100, ""); // gm.InitOtherPlayer(50, 50, ""); socket.On("joinGame", (data) => { Debug.Log("recive : joinGame"); posInit p_params = new posInit(); p_params = JsonUtility.FromJson <posInit>(data.ToString()); UnityMainThreadDispatcher.Instance().Enqueue(InitTheMainThread(p_params)); }); socket.On("startGame", (data) => { Debug.Log("recive : startGame"); mapInfo p_params = new mapInfo(); p_params = JsonUtility.FromJson <mapInfo>(data.ToString()); UnityMainThreadDispatcher.Instance().Enqueue(ThisWillBeExecutedOnTheMainThread(p_params)); }); socket.On("idPlayer", (data) => { Debug.Log("recive : id"); string p_params; p_params = JsonUtility.FromJson <string>(data.ToString()); gm.setMyId(p_params); }); socket.On("updateGame", (data) => { Debug.Log("recive : updateGame"); mapInfo p_params = new mapInfo(); p_params = JsonUtility.FromJson <mapInfo>(data.ToString()); UnityMainThreadDispatcher.Instance().Enqueue(ThisWillBeExecutedOnTheMainThread(p_params)); }); }
private bool checkMapExist(mapInfo map) { Directory.CreateDirectory("maps"); string fpath = Path.Combine("maps", map.name); if (!File.Exists(fpath)) { return(false); } var fstream = File.OpenRead(fpath); var md5 = System.Security.Cryptography.MD5.Create(); var localHash = md5.ComputeHash(fstream); fstream.Dispose(); if (localHash.Length != map.hashCode.Length) { return(false); } for (int i = 0; i < localHash.Length; i++) { if (localHash[i] != map.hashCode[i]) { return(false); } } return(true); }
public IEnumerator ThisWillBeExecutedOnTheMainThread(mapInfo p_params) { // Debug.Log ("This is executed from the main thread"); Debug.Log(idPlayer); Debug.Log(p_params.p1); if (idPlayer == "1") { Debug.Log(p_params.p1); gm.updatePlayer(p_params.p1.x, p_params.p1.y, p_params.p1.direction); gm.updateOtherPlayer(p_params.p2.x, p_params.p2.y, p_params.p2.direction); } else if (idPlayer == "2") { gm.updatePlayer(p_params.p2.x, p_params.p2.y, p_params.p2.direction); gm.updateOtherPlayer(p_params.p1.x, p_params.p1.y, p_params.p1.direction); } gm.CiaoGuigui(); yield return(null); }
private void button1_Click(object sender, EventArgs e) { frmNewMap nm = new frmNewMap(); mapInfo map = nm.AddNewMap(); }
/// <summary> /// The load main menu data. /// </summary> /// <remarks></remarks> private void loadMainMenuData() { // Load MATG tag (globals\globals), should always be at location 0 Meta meta = Map.GetMetaFromTagIndex(0, map, false, false); br = new BinaryReader(meta.MS); int matgOffset = meta.offset; // Runtime level Data br.BaseStream.Position = 368; int RuntimeLevelCount = br.ReadInt32(); // Should always be 1 int RuntimeLevelOffset = br.ReadInt32() - map.SecondaryMagic - matgOffset; br.BaseStream.Position = RuntimeLevelOffset + 0; int CampaignIDCount = br.ReadInt32(); int CampaignIDOffset = br.ReadInt32() - map.SecondaryMagic - matgOffset; for (int i = 0; i < CampaignIDCount; i++) { br.BaseStream.Position = CampaignIDOffset + i * 264; campaignScenarios cs = new campaignScenarios(br, matgOffset); campScenarios.Add(cs); } // UI Level Data, Size 24 br.BaseStream.Position = 376; int UILevelCount = br.ReadInt32(); // Should always be 1 int UILevelOffset = br.ReadInt32() - map.SecondaryMagic - matgOffset; #region Campaign Levels, Size 2896 br.BaseStream.Position = UILevelOffset + 8; int CampaignLevelCount = br.ReadInt32(); int CampaignLevelOffset = br.ReadInt32() - map.SecondaryMagic - matgOffset; for (int i = 0; i < CampaignLevelCount; i++) { br.BaseStream.Position = CampaignLevelOffset + i * 2896; mapInfo cLevel = new mapInfo(br, matgOffset, campScenarios); cLevel.originalNumber = i; for (int j = 0; j <= i; j++) { if (j == i || cLevel.MapID == -1) { campaignLevels.Add(cLevel); break; } else if (cLevel.Sort_Order < campaignLevels[j].Sort_Order || cLevel.MapID == -1) { campaignLevels.Insert(j, cLevel); break; } } } #endregion #region Multiplayer Levels, Size 3172 br.BaseStream.Position = UILevelOffset + 16; int MPLevelCount = br.ReadInt32(); int MPLevelOffset = br.ReadInt32() - map.SecondaryMagic - matgOffset; for (int i = 0; i < MPLevelCount; i++) { br.BaseStream.Position = MPLevelOffset + i * 3172; mapInfo mLevel = new mapInfo(br, matgOffset); mLevel.originalNumber = i; for (int j = 0; j <= i; j++) { if (j == i || mLevel.MapID == -1) { MPLevels.Add(mLevel); break; } else if (mLevel.Sort_Order < MPLevels[j].Sort_Order || MPLevels[j].MapID == -1) { MPLevels.Insert(j, mLevel); break; } } } #endregion br.Close(); }
/// <summary> /// The lb map listing_ mouse up. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The e.</param> /// <remarks></remarks> private void lbMapListing_MouseUp(object sender, MouseEventArgs e) { currentDrag = null; }
/// <summary> /// The lb map listing_ mouse move. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The e.</param> /// <remarks></remarks> private void lbMapListing_MouseMove(object sender, MouseEventArgs e) { if (lbMapListing.SelectedIndex == -1) { return; } if (e.Button == MouseButtons.Left) { if (currentDrag == null) { lbMapListing_SelectedIndexChanged(sender, null); currentDrag = currentLevels[lbMapListing.SelectedIndex]; } itemInsert((ListBox)sender, ((ListBox)sender).SelectedItem, e.Location); } }
/// <summary> /// The add map. /// </summary> /// <param name="filename">The filename.</param> /// <remarks></remarks> private void addMap(string filename) { if (currentLevels[currentLevels.Count - 1].mapID != -1) { MessageBox.Show("There are already " + currentLevels.Count + " maps! No more can be added."); return; } Map tempmap = Map.LoadFromFile(filename); if (tempmap == null) { MessageBox.Show("Unable to load MAP: " + filename); } // Set default gametype numbers gametypes gameTypes = new gametypes(); // Load SCNR tag for (int i = 0; i < tempmap.IndexHeader.metaCount; i++) { if (tempmap.MetaInfo.TagType[i] == "scnr") { tempmap.SelectedMeta = Map.GetMetaFromTagIndex(1, tempmap, false, false); break; } } Meta m = tempmap.SelectedMeta; BinaryReader br = new BinaryReader(m.MS); // Netgame flags, size 32 br.BaseStream.Position = 280; int netgameFlagsCount = br.ReadInt32(); int netgameFlagsOffset = br.ReadInt32() - m.offset - m.magic; for (int i = 0; i < netgameFlagsCount; i++) { // offset 16 is netgame type (0-1=CTF, 2-3=Assault, 4=Odball, 6=Race, 9=Headhunter, 10=Territories, 11-18=KOTH) br.BaseStream.Position = netgameFlagsOffset + i * 32 + 16; int gameType = br.ReadInt16(); int teamNum = br.ReadInt16(); // We only need to check CTF & Assault. For all else, it will default to 8 teams max if (gameType == 0 || gameType == 1) { gameTypes.gameTypes[(int)gametypes.gameTypesNames.CTF].Teams[teamNum] = true; } else if (gameType == 2 || gameType == 3) { gameTypes.gameTypes[(int)gametypes.gameTypesNames.Assault].Teams[teamNum] = true; } } // Start new MapID at 90 for MP, 101 for Campaign int newID = currentLevels[0].campaignNumber == -1 ? 90 : 201; for (int i = 0; i < currentLevels.Count; i++) { if (currentLevels[i].MapID == newID) { // increase MapID by 10 for MP, 100 for Campaign and restart search newID = currentLevels[i].MapID + (currentLevels[0].campaignNumber == -1 ? 10 : 100); i = -1; } } mapInfo newMap = new mapInfo(tempmap.MapHeader.mapName.Trim('\0'), tempmap.MapHeader.scenarioPath, newID); gameTypes.Save(newMap); // Load Map Picture as raw data (for transfer) and Bitmap (for display) tempmap.OpenMap(MapTypes.Internal); m = MapForm.GetMapBitmapMeta(tempmap); ////////////////////////////////// // Backwash for example has no internal picture, so it errors. ////////////////////////////////// if (m != null) { newMap.screenShotRaw = m.raw.rawChunks[0]; ParsedBitmap pm = new ParsedBitmap(ref m, tempmap); newMap.screenShot = pm.FindChunkAndDecode(0, 0, 0, ref m, tempmap, 0, 0); } else { newMap.screenShotRaw = new RawDataChunk(); newMap.screenShotRaw.MS = new MemoryStream(); newMap.screenShotRaw.pointerMetaOffset = 104; } tempmap.CloseMap(); // Save the current Map Bitmap Offset listing in case a map has been added, then removed, so we don't keep // adding new un-needed Raw Listings newMap.screenShotOffset = currentLevels[lbMapListing.Items.Count].screenShotOffset; // Insert the new map & remove the current listing to make sure that we keep the same # of maps total for // when we rewrite currentLevels[this.lbMapListing.Items.Count] = newMap; this.lbMapListing.Items.Add(newMap.Name); }
/// <summary> /// The save. /// </summary> /// <param name="mi">The mi.</param> /// <remarks></remarks> public void Save(mapInfo mi) { mi.Max_Teams_None = this.gameTypes[(int)gameTypesNames.None].GetTotal(); mi.Max_Teams_CTF = this.gameTypes[(int)gameTypesNames.CTF].GetTotal(); mi.Max_Teams_Slayer = this.gameTypes[(int)gameTypesNames.Slayer].GetTotal(); mi.Max_Teams_Oddball = this.gameTypes[(int)gameTypesNames.Oddball].GetTotal(); mi.Max_Teams_KOTH = this.gameTypes[(int)gameTypesNames.KOTH].GetTotal(); mi.Max_Teams_Race = this.gameTypes[(int)gameTypesNames.Race].GetTotal(); mi.Max_Teams_Headhunter = this.gameTypes[(int)gameTypesNames.Headhunter].GetTotal(); mi.Max_Teams_Juggernaught = this.gameTypes[(int)gameTypesNames.Juggernaught].GetTotal(); mi.Max_Teams_Territories = this.gameTypes[(int)gameTypesNames.Territories].GetTotal(); mi.Max_Teams_Assault = this.gameTypes[(int)gameTypesNames.Assault].GetTotal(); }
/// <summary> /// The save mp data. /// </summary> /// <param name="meta">The meta.</param> /// <remarks></remarks> private void saveMPData(Meta meta) { Map thisMap = map; thisMap.SelectedMeta = meta; int matgOffset = thisMap.SelectedMeta.offset; br = new BinaryReader(thisMap.SelectedMeta.MS); bw = new BinaryWriter(thisMap.SelectedMeta.MS); // UI Level Data, Size 24 br.BaseStream.Position = 376; int UILevelCount = br.ReadInt32(); // Should always be 1 int UILevelOffset = br.ReadInt32() - thisMap.SecondaryMagic - matgOffset; br.BaseStream.Position = UILevelOffset + 16; bw.Write(MPLevels.Count); int MPLevelOffset = br.ReadInt32() - thisMap.SecondaryMagic - matgOffset; for (int i = 0; i < MPLevels.Count; i++) { // Puts listings back into original position // If original listing is gone, inserts a new listing in that spot // or if neither, nulls it out int nextUp = -1; for (int j = 0; j < MPLevels.Count; j++) { // If the level listing was originally at this spot and not empty, it takes precedence if (i == MPLevels[j].originalNumber && MPLevels[j].MapID != -1) { nextUp = j; break; } // If we added a map, place it in an opening else if (MPLevels[j].originalNumber == -1 && nextUp == -1) { nextUp = j; } } br.BaseStream.Position = MPLevelOffset + i * 3172; if (nextUp != -1) { MPLevels[nextUp].originalNumber = i; MPLevels[nextUp].Preview_Image_Tag = "mtib".ToCharArray(); int tagNum = thisMap.Functions.ForMeta.FindByNameAndTagType( "bitm", "ui\\code_global_bitmaps\\multiplayer" + i); MPLevels[nextUp].Preview_Image_Ident = thisMap.MetaInfo.Ident[tagNum]; MPLevels[nextUp].write(i, bw, matgOffset); } else { // Null out level listing mapInfo mi = new mapInfo(string.Empty, string.Empty, -1); mi.Preview_Image_Tag = "mtib".ToCharArray(); int tagNum = thisMap.Functions.ForMeta.FindByNameAndTagType("bitm", "ui\\code_global_bitmaps\\multiplayer" + i.ToString()); mi.Preview_Image_Ident = thisMap.MetaInfo.Ident[tagNum]; mi.write(i, bw, matgOffset); } } }