Beispiel #1
0
 public bool TryParse(GameCache cache, List <string> args, out IBlamType result, out string error)
 {
     result = null;
     if (args.Count != 4)
     {
         error = $"{args.Count} arguments supplied; should be 4";
         return(false);
     }
     else if (!short.TryParse(args[0], out short top))
     {
         error = $"Unable to parse \"{args[0]}\" (top) as `short`.";
         return(false);
     }
     else if (!short.TryParse(args[1], out short left))
     {
         error = $"Unable to parse \"{args[1]}\" (left) as `short`.";
         return(false);
     }
     else if (!short.TryParse(args[2], out short bottom))
     {
         error = $"Unable to parse \"{args[2]}\" (bottom) as `short`.";
         return(false);
     }
     else if (!short.TryParse(args[3], out short right))
     {
         error = $"Unable to parse \"{args[3]}\" (right) as `short`.";
         return(false);
     }
     else
     {
         result = new Rectangle2d(top, left, bottom, right);
         error  = null;
         return(true);
     }
 }
Beispiel #2
0
        public CacheForm(DirectoryInfo cacheDirectory)
        {
            InitializeComponent();

            if (cacheDirectory.GetFiles("*.dat").Length == 0) // gen3
            {
                var smf = new SelectMapForm(cacheDirectory);

                if (smf.ShowDialog() != DialogResult.OK)
                {
                    Close();
                }

                Text  = smf.SelectedFile.FullName;
                Cache = GameCache.Open(smf.SelectedFile);
            }

            else // HO
            {
                Text  = cacheDirectory.FullName + "\\tags.dat";
                Cache = GameCache.Open(new FileInfo(Text));
            }

            var docFile = new FileInfo(Path.Combine(Application.StartupPath, "BlamCore.xml"));

            if (Documentation.ChildNodes.Count == 0 && docFile.Exists)
            {
                Documentation.Load(docFile.FullName);
            }
        }
Beispiel #3
0
        public override object Execute(List <string> args)
        {
            if (args.Count != 1)
            {
                return(false);
            }

            var path = args[0];
            var file = new FileInfo(path);

            /*
             * MapFile map;
             *
             * using(var stream = new FileStream(path, FileMode.Open))
             * using(var reader = new EndianReader(stream))
             * {
             *  map = new MapFile(reader);
             * }
             */

            GameCache cache;

            cache = new GameCache(file);



            return(true);
        }
Beispiel #4
0
 public bool TryParse(GameCache cache, List <string> args, out IBlamType result, out string error)
 {
     result = null;
     if (args.Count != 2)
     {
         error = $"{args.Count} arguments supplied; should be 2";
         return(false);
     }
     else if (!float.TryParse(args[0], out float x))
     {
         error = $"Unable to parse \"{args[0]}\" (x) as `float`.";
         return(false);
     }
     else if (!float.TryParse(args[1], out float y))
     {
         error = $"Unable to parse \"{args[1]}\" (y) as `float`.";
         return(false);
     }
     else
     {
         result = new RealPoint2d(x, y);
         error  = null;
         return(true);
     }
 }
Beispiel #5
0
        public static Tag Parse(GameCache cache, string name)
        {
            if (name == "****" || name == "null")
            {
                return(Null);
            }

            if (name.Length < 4)
            {
                if (name.Length == 3)
                {
                    name = $"{name} ";
                }
                else if (name.Length == 2)
                {
                    name = $"{name}  ";
                }
            }

            if (TagDefinition.TryFind(name, out var type))
            {
                var attribute = TagStructure.GetTagStructureAttribute(type);
                return(new Tag(attribute.Tag));
            }

            foreach (var pair in TagGroup.Instances)
            {
                if (name == cache.StringTable.GetString(pair.Value.Name))
                {
                    return(pair.Value.Tag);
                }
            }

            return(Null);
        }
Beispiel #6
0
 public bool TryParse(GameCache cache, List <string> args, out IBlamType result, out string error)
 {
     result = null;
     if (args.Count != 3)
     {
         error = $"{args.Count} arguments supplied; should be 3";
         return(false);
     }
     else if (!float.TryParse(args[0], out float i))
     {
         error = $"Unable to parse \"{args[0]}\" (i) as `float`.";
         return(false);
     }
     else if (!float.TryParse(args[1], out float j))
     {
         error = $"Unable to parse \"{args[1]}\" (j) as `float`.";
         return(false);
     }
     else if (!float.TryParse(args[2], out float d))
     {
         error = $"Unable to parse \"{args[2]}\" (d) as `float`.";
         return(false);
     }
     else
     {
         result = new RealPlane2d(i, j, d);
         error  = null;
         return(true);
     }
 }
        public static CommandContext Create(CommandContextStack contextStack, GameCache cache)
        {
            var context = new CommandContext(contextStack.Context, "tags");

            Populate(contextStack, context, cache);
            return(context);
        }
Beispiel #8
0
 /// <summary>
 /// Rollback all info about storage back to cache state.
 /// </summary>
 /// <param name="cache"></param>
 public void RollbackGame(GameCache cache)
 {
     UpdateResourceNum(
         cache.descriptor.GetPlayerInfo(Unit.TypeEnum.Bread, Unit.OwnerEnum.Black),
         cache.descriptor.GetPlayerInfo(Unit.TypeEnum.Bread, Unit.OwnerEnum.White));
     SwitchTurn(cache.descriptor.Turn, cache.turnNum);
 }
 public static void Populate(CommandContext context, GameCache info, CachedTag tag, RenderMethod renderMethod)
 {
     context.AddCommand(new ListArgumentsCommand(info, tag, renderMethod));
     context.AddCommand(new SetArgumentCommand(info, tag, renderMethod));
     context.AddCommand(new ListBitmapsCommand(info, tag, renderMethod));
     context.AddCommand(new SpecifyBitmapsCommand(info, tag, renderMethod));
 }
Beispiel #10
0
 public bool TryParse(GameCache cache, List <string> args, out IBlamType result, out string error)
 {
     result = null;
     if (args.Count != 4)
     {
         error = $"{args.Count} arguments supplied; should be 4";
         return(false);
     }
     else if (!float.TryParse(args[0], out float i))
     {
         error = $"Unable to parse \"{args[0]}\" (i) as `float`.";
         return(false);
     }
     else if (!float.TryParse(args[1], out float j))
     {
         error = $"Unable to parse \"{args[1]}\" (j) as `float`.";
         return(false);
     }
     else if (!float.TryParse(args[2], out float k))
     {
         error = $"Unable to parse \"{args[2]}\" (k) as `float`.";
         return(false);
     }
     else if (!float.TryParse(args[3], out float w))
     {
         error = $"Unable to parse \"{args[3]}\" (w) as `float`.";
         return(false);
     }
     else
     {
         result = new RealQuaternion(i, j, k, w);
         error  = null;
         return(true);
     }
 }
Beispiel #11
0
        public GeometryToObjectConverter(
            GameCacheHaloOnlineBase destCache, Stream destStream, GameCache sourceCache,
            Stream sourceStream, Scenario scenario, int structureBspIndex)
        {
            DestCache         = destCache;
            DestStream        = destStream;
            SourceCache       = sourceCache;
            SourceStream      = sourceStream;
            StructureBspIndex = structureBspIndex;
            PortTag           = new PortTagCommand(destCache, sourceCache);
            PortTag.SetFlags(PortTagCommand.PortingFlags.Default);

            Scenario          = scenario;
            StructureBspIndex = structureBspIndex;
            StructureBsp      = SourceCache.Deserialize <ScenarioStructureBsp>(SourceStream, Scenario.StructureBsps[structureBspIndex].StructureBsp);
            sLdT = SourceCache.Deserialize <ScenarioLightmap>(SourceStream, Scenario.Lightmap);

            if (SourceCache.Version >= CacheVersion.Halo3ODST)
            {
                Lbsp = SourceCache.Deserialize <ScenarioLightmapBspData>(SourceStream, sLdT.LightmapDataReferences[StructureBspIndex]);
            }
            else
            {
                Lbsp = sLdT.Lightmaps[StructureBspIndex];
            }

            var resourceDefinition = SourceCache.ResourceCache.GetRenderGeometryApiResourceDefinition(Lbsp.Geometry.Resource);

            Lbsp.Geometry.SetResourceBuffers(resourceDefinition);

            StructureBspResources = SourceCache.ResourceCache.GetStructureBspTagResources(StructureBsp.CollisionBspResource);
        }
Beispiel #12
0
        public bool TryParse(GameCache cache, List <string> args, out IBounds result, out string error)
        {
            result = null;
            error  = null;

            var argType  = GetType().GenericTypeArguments[0];
            var argCount = SetFieldCommand.RangeArgCount(argType);

            if (argCount * 2 != args.Count)
            {
                error = $"{args.Count} arguments supplied; should be {argCount * 2}";
                return(false);
            }

            var min = SetFieldCommand.ParseArgs(cache, argType, null, args.Take(argCount).ToList());
            var max = SetFieldCommand.ParseArgs(cache, argType, null, args.Skip(argCount).Take(argCount).ToList());

            if (min.Equals(false) || max.Equals(false))
            {
                error = $"Invalid value parsed.";
                return(false);
            }

            result = Activator.CreateInstance(this.GetType(), new object[] { min, max }) as IBounds;
            return(true);
        }
Beispiel #13
0
 public bool TryParse(GameCache cache, List <string> args, out IBlamType result, out string error)
 {
     result = null;
     if (args.Count != 4)
     {
         error = $"{args.Count} arguments supplied; should be 4";
         return(false);
     }
     else if (!float.TryParse(args[0], out float a))
     {
         error = $"Unable to parse \"{args[0]}\" (a) as `float`.";
         return(false);
     }
     else if (!float.TryParse(args[1], out float r))
     {
         error = $"Unable to parse \"{args[1]}\" (r) as `float`.";
         return(false);
     }
     else if (!float.TryParse(args[2], out float g))
     {
         error = $"Unable to parse \"{args[2]}\" (g) as `float`.";
         return(false);
     }
     else if (!float.TryParse(args[3], out float b))
     {
         error = $"Unable to parse \"{args[3]}\" (b) as `float`.";
         return(false);
     }
     else
     {
         result = new RealArgbColor(a, r, g, b);
         error  = null;
         return(true);
     }
 }
Beispiel #14
0
    /// <summary>
    /// Rollback the board to cached state.
    /// </summary>
    public void RollbackGame(GameCache cache)
    {
        ClearGame();
        boardUnit  = new Unit[BoardInfo.Row, BoardInfo.Col];
        boardBread = new Unit[BoardInfo.Row, BoardInfo.Col];
        boardState = new GridState[BoardInfo.Row, BoardInfo.Col];
        playerInfo = new Dictionary <Unit.TypeEnum, int>[2] {
            new Dictionary <Unit.TypeEnum, int>(), new Dictionary <Unit.TypeEnum, int>()
        };
        restBreadNum = 0;

        for (int i = 0; i < BoardInfo.Row; i++)
        {
            for (int j = 0; j < BoardInfo.Col; j++)
            {
                boardState[i, j] = cache.descriptor.GetGridState(i, j);
                if (boardState[i, j] == GridState.Bread)
                {
                    CreateUnit(new UnitInfo(new Position(i, j), Unit.TypeEnum.Bread));
                }
                var unitInfo = cache.descriptor.GetUnitInfo(i, j);
                if (unitInfo.type >= Unit.TypeEnum.Scout && unitInfo.type <= Unit.TypeEnum.Bomb)
                {
                    CreateUnit(unitInfo);
                }
            }
        }
        for (Unit.TypeEnum type = Unit.TypeEnum.Bread; type < Unit.TypeEnum.Void; type++)
        {
            playerInfo[(int)Unit.OwnerEnum.Black][type] = cache.descriptor.GetPlayerInfo(type, Unit.OwnerEnum.Black);
            playerInfo[(int)Unit.OwnerEnum.White][type] = cache.descriptor.GetPlayerInfo(type, Unit.OwnerEnum.White);
        }
        restBreadNum = cache.descriptor.RestResource;
        SwitchTurn(cache.descriptor.Turn);
    }
Beispiel #15
0
 public bool TryParse(GameCache cache, List <string> args, out IBlamType result, out string error)
 {
     result = null;
     if (args.Count != 2)
     {
         error = $"{args.Count} arguments supplied; should be 2";
         return(false);
     }
     else if (!float.TryParse(args[0], out float yaw))
     {
         error = $"Unable to parse \"{args[0]}\" (yaw) as `float`.";
         return(false);
     }
     else if (!float.TryParse(args[1], out float pitch))
     {
         error = $"Unable to parse \"{args[1]}\" (pitch) as `float`.";
         return(false);
     }
     else
     {
         result = new RealEulerAngles2d(
             Angle.FromDegrees(yaw),
             Angle.FromDegrees(pitch));
         error = null;
         return(true);
     }
 }
        protected override IList <UserRank> GetCacheList()
        {
            rankList.Clear();
            if (rankingData.RankList.Count == 0)
            {
                var gameCache = new ShareCacheStruct <GameCache>();
                var levelrank = gameCache.FindKey("LevelRanking");
                if (levelrank == null)
                {
                    levelrank       = new GameCache();
                    levelrank.Key   = "LevelRanking";
                    levelrank.Value = "";
                    gameCache.Add(levelrank);
                    gameCache.Update();
                }

                LevelRankingData data = null;
                data = JsonUtils.Deserialize <LevelRankingData>(levelrank.Value);
                if (data == null)
                {
                    data = new LevelRankingData();
                }
            }

            foreach (var v in rankingData.RankList)
            {
                UserRank rank = new UserRank(v);
                rankList.Add(rank);
            }

            return(rankList);
        }
Beispiel #17
0
        public PickerDialog(Instance emulator)
            : this()
        {
            Debug.Assert(emulator != null);

            _emulator = emulator;

            string cachePath = GameCache.DefaultPath;

            _cache = new GameCache();
            _cache.Load(cachePath);
            umdGameListing.SetCache(_cache);

            umdGameListing.Text         = "UMDs";
            msGameListing.Text          = "EBOOTs";
            msGameListing.RegionEnabled = false;

            SetEnabledState(true);

            //this.FindGames();

            //umdGameListing_SelectionChanged( umdGameListing, EventArgs.Empty );

            this.DialogResult = DialogResult.Cancel;
        }
Beispiel #18
0
        public RenderMaterial(Direct3D.Device device, GameCache cache, TagTool.Geometry.RenderMaterial material)
        {
            if (material.RenderMethod == null)
            {
                return;
            }

            using (var cacheStream = cache.OpenCacheRead())
            {
                var renderMethod = cache.Deserialize <RenderMethod>(cacheStream, material.RenderMethod);

                var template = cache.Deserialize <RenderMethodTemplate>(cacheStream, renderMethod.ShaderProperties[0].Template);

                Textures = new Dictionary <string, RenderTexture>();

                for (var shaderMapIndex = 0; shaderMapIndex < renderMethod.ShaderProperties[0].TextureConstants.Count; shaderMapIndex++)
                {
                    var shaderMapName = cache.StringTable.GetString(template.TextureParameterNames[shaderMapIndex].Name);

                    if (Textures.ContainsKey(shaderMapName))
                    {
                        continue;
                    }

                    var shaderMap           = renderMethod.ShaderProperties[0].TextureConstants[shaderMapIndex];
                    var shaderMapDefinition = cache.Deserialize <Bitmap>(cacheStream, shaderMap.Bitmap);

                    Textures[shaderMapName] = new RenderTexture(device, cache, shaderMapDefinition, shaderMap.BitmapIndex);
                }
            }
        }
Beispiel #19
0
 /// <summary>
 /// 悔棋点击事件
 /// </summary>
 public void OnUndoClick()
 {
     if (GameCache.maps.Count >= 3)
     {
         //回合状态回退
         if (GameController.playing == Playing.OnRed || GameController.playing == Playing.RedAdding)
         {
             GameController.playing = Playing.OnRed;
         }
         else
         {
             GameController.playing = Playing.OnBlack;
         }
         //棋谱回退 并移除回退前两步信息
         GameUtil.SetChessBoardByMaps(GameCache.maps.Count - 1 - 2);
         GameCache.maps.RemoveRange(GameCache.maps.Count - 2, 2);
         GameCache.attrMaps.RemoveRange(GameCache.attrMaps.Count - 2, 2);
         GameCache.UpdateChessData(); //更新映射关系,但不计入图谱
         UndoEvent();
     }
     else
     {
         //GameObject.Find("UndoButton").GetComponent<Button>().enabled = false;
     }
 }
Beispiel #20
0
 public SoundControl(GameCache cache, CachedTag tag, Sound sound) :
     this()
 {
     Cache     = cache;
     Instance  = tag;
     Sound     = sound;
     SoundFile = new FileInfo(Path.Combine(Application.StartupPath, "temp", $"{Instance.Index:X4}.mp3"));
 }
Beispiel #21
0
 /// <summary>
 /// 重置游戏数据
 /// </summary>
 public static void ResetGame()
 {
     IsBattle   = false;
     step       = 0;
     gameStatus = GameStatus.NotBegin;
     playing    = Playing.None;
     GameCache.ClearCache();
 }
Beispiel #22
0
 public void UpdateGameData()
 {
     GameCache.UpdateChessData();
     GameCache.SetMaps();
     GameCache.SetAttrMaps();
     UpdateGameDataCompleteEvent();
     step++;
 }
Beispiel #23
0
 public ArgbColorControl(GameCache cache, FieldInfo field) :
     this()
 {
     Cache       = cache;
     Field       = field;
     label1.Text = field.Name.ToSpaced().Replace("_", "");
     new ToolTip().SetToolTip(label1, $"{field.FieldType} {CacheForm.GetDocumentation(field)}");
 }
Beispiel #24
0
        public CharacterGenerator()
        {
            HumanoidMatcher       = new Regex(IoC.Get <CharacterConfig>().HumanoidMatcher);
            UniqueHumanoidMatcher = new Regex(IoC.Get <CharacterConfig>().UniqueHumanoidMatcher);
            Ignored = IoC.Get <CharacterConfig>().IgnoredCharacters.ToArray();

            _cache = new GameCache <List <CharacterModel> >("npcs");
        }
Beispiel #25
0
 public StructMultiControl(CacheForm form, GameCache cache, CachedTag tag, object definition) :
     this()
 {
     Form       = form;
     Cache      = cache;
     Instance   = tag;
     Definition = definition;
 }
Beispiel #26
0
        private void EndReceive(IAsyncResult res)
        {
            var state = res.AsyncState as SocketReceiveBundle;
            var ep    = new IPEndPoint(IPAddress.Any, Port);

            byte[] data = null;
            try {
                data = state.UdpClient.EndReceive(res, ref ep);
            } catch (ObjectDisposedException ex) {
                Log.Info($"{nameof(EndReceive)}: This is more or less expected", ex);
                return;
            }

            if (data.Length < 4)
            {
                Receive();
                return;
            }
            var length = data[0] | data[1] << 8 | data[2] << 16 | data[3] << 24;

            if (data.Length < length)
            {
                Receive();
                return;
            }

            data = data.Skip(4).ToArray();

            try {
                using (var ms = new MemoryStream(data)) {
                    ms.Position = 0;
                    var bf = new BinaryFormatter();
                    var hg = (HostedGame)bf.Deserialize(ms);

                    if (hg.Host == "0.0.0.0")
                    {
                        hg.HostAddress = $"{ep.Address}:{hg.Port}";
                    }

                    lock (GameCache) {
                        if (GameCache.Contains(hg.Id.ToString()))
                        {
                            GameCache.Remove(hg.Id.ToString());
                        }
                        GameCache.Add(hg.Id.ToString(), hg, DateTime.Now.AddSeconds(10));

                        if (_awaitingStart.TryGetValue(hg.Id, out var tcs))
                        {
                            tcs.SetResult(hg);
                        }
                    }
                }
            } catch (Exception ex) {
                Log.Error($"{nameof(EndReceive)}: Error reading data", ex);
            }

            Receive();
        }
Beispiel #27
0
 public RuntimeSerializationContext(GameCache cache, ProcessMemoryStream processStream, uint tagAddress, uint originalOffset, uint headerSize, uint originalSize)
 {
     Cache                = cache;
     ProcessStream        = processStream;
     StartAddress         = tagAddress;
     OriginalStructOffset = originalOffset;
     HeaderSize           = headerSize;
     OriginalSize         = originalSize;
 }
Beispiel #28
0
        public static CommandContext Create(CommandContext parent, GameCache cache, CachedTag tag, CollisionModel definition)
        {
            var groupName      = cache.StringTable.GetString(tag.Group.Name);
            var commandContext = new CommandContext(parent, string.Format("{0:X8}.{1}", tag.Index, groupName));

            Populate(commandContext, cache, tag, definition);

            return(commandContext);
        }
 public static void Populate(CommandContext context, GameCache cache, CachedTag tag, RenderModel renderModel)
 {
     context.AddCommand(new SpecifyShadersCommand(cache, tag, renderModel));
     context.AddCommand(new DumpRenderGeometryCommand(cache, renderModel.Geometry));
     context.AddCommand(new ReplaceRenderGeometryCommand(cache, tag, renderModel));
     context.AddCommand(new ExtractModelCommand(cache, renderModel));
     context.AddCommand(new ExtractBitmapsCommand(cache, renderModel));
     context.AddCommand(new ExtractBMFCommand(cache, renderModel));
 }
Beispiel #30
0
 public ShaderMatcherNew(GameCache baseCache, GameCache portingCache, Stream baseCacheStream, Stream portingCacheStream, bool useMS30 = false)
 {
     UseMs30            = useMS30;
     BaseCache          = baseCache;
     PortingCache       = portingCache;
     BaseCacheStream    = baseCacheStream;
     PortingCacheStream = portingCacheStream;
     Init();
 }
Beispiel #31
0
        public PickerDialog( Instance emulator )
            : this()
        {
            Debug.Assert( emulator != null );

            _emulator = emulator;

            string cachePath = GameCache.DefaultPath;
            _cache = new GameCache();
            _cache.Load( cachePath );
            umdGameListing.SetCache( _cache );

            umdGameListing.Text = "UMDs";
            msGameListing.Text = "EBOOTs";
            msGameListing.RegionEnabled = false;

            SetEnabledState( true );

            //this.FindGames();

            //umdGameListing_SelectionChanged( umdGameListing, EventArgs.Empty );

            this.DialogResult = DialogResult.Cancel;
        }
Beispiel #32
0
 public GameRoom(string gameId, GameCache roomCache = null, int emptyRoomLiveTime = 0)
     : base(gameId, roomCache, emptyRoomLiveTime)
 {
 }
 public void SetCache( GameCache cache )
 {
     _cache = cache;
 }