예제 #1
0
        private static int getuid(String s)
        {
            try
            {
                string uidPath = Path.Combine(s, "uid.dat");
                bool   exists  = File.Exists(uidPath);
                using (FileStream uidFile = File.Open(uidPath, FileMode.OpenOrCreate))
                {
                    if (!exists || uidFile.Length < 4L)
                    {
                        BinaryWriter dataoutputstream = new BinaryWriter(uidFile);
                        dataoutputstream.Write((int)(StaticRandomGenerator.Next() * 99999999D));
                        dataoutputstream.Close();
                    }
                }
            }
            catch (Exception _ex)
            {
                throw new InvalidOperationException($"Failed to generate and write uid. Reason: {_ex.Message}", _ex);
            }

            try
            {
                BinaryReader datainputstream = new BinaryReader(File.OpenRead(s + "uid.dat"), Encoding.Default, false);
                int          i = datainputstream.ReadInt32();
                datainputstream.Close();
                return(i + 1);
            }
            catch (Exception _ex)
            {
                throw new InvalidOperationException($"Failed to read uid.");
            }
        }
예제 #2
0
        public static void initialise()
        {
            noise = new int[32768];
            for (int noiseId = 0; noiseId < 32768; noiseId++)
            {
                if (StaticRandomGenerator.Next() > 0.5D)
                {
                    noise[noiseId] = 1;
                }
                else
                {
                    noise[noiseId] = -1;
                }
            }

            sine = new int[32768];
            for (int sineId = 0; sineId < 32768; sineId++)
            {
                sine[sineId] = (int)(Math.Sin(sineId / 5215.1903000000002D) * 16384D);
            }

            output = new int[0x35d54];
        }
예제 #3
0
        internal async Task LoadMediaContentAsync()
        {
            Archive          archiveMedia   = requestArchive(4, "2d graphics", "media", 0, 40);
            Default317Buffer metadataBuffer = new Default317Buffer(archiveMedia.decompressFile("index.dat"));

            inventoryBackgroundImage = new IndexedImage(archiveMedia, "invback", 0, metadataBuffer);
            chatBackgroundImage      = new IndexedImage(archiveMedia, "chatback", 0, metadataBuffer);
            minimapBackgroundImage   = new IndexedImage(archiveMedia, "mapback", 0, metadataBuffer);
            backBase1Image           = new IndexedImage(archiveMedia, "backbase1", 0, metadataBuffer);
            backBase2Image           = new IndexedImage(archiveMedia, "backbase2", 0, metadataBuffer);
            backHmid1Image           = new IndexedImage(archiveMedia, "backhmid1", 0, metadataBuffer);
            for (int icon = 0; icon < 13; icon++)
            {
                sideIconImage[icon] = new IndexedImage(archiveMedia, "sideicons", icon, metadataBuffer);
            }

            minimapCompassImage = new Sprite(archiveMedia, "compass", 0, metadataBuffer);
            minimapEdgeImage    = new Sprite(archiveMedia, "mapedge", 0, metadataBuffer);
            minimapEdgeImage.trim();

            await TaskDelayFactory.Create(1);

            try
            {
                for (int i = 0; i < 100; i++)
                {
                    mapSceneImage[i] = new IndexedImage(archiveMedia, "mapscene", i, metadataBuffer);
                }

                await TaskDelayFactory.Create(1);
            }
            catch (Exception _ex)
            {
                signlink.reporterror($"Unexpected Exception: {_ex.Message} \n\n Stack: {_ex.StackTrace}");
            }

            try
            {
                for (int i = 0; i < 100; i++)
                {
                    mapFunctionImage[i] = new Sprite(archiveMedia, "mapfunction", i, metadataBuffer);
                }

                await TaskDelayFactory.Create(1);
            }
            catch (Exception _ex)
            {
                signlink.reporterror($"Unexpected Exception: {_ex.Message} \n\n Stack: {_ex.StackTrace}");
            }

            try
            {
                for (int i = 0; i < 20; i++)
                {
                    hitMarkImage[i] = new Sprite(archiveMedia, "hitmarks", i, metadataBuffer);
                }

                await TaskDelayFactory.Create(1);
            }
            catch (Exception _ex)
            {
                signlink.reporterror($"Unexpected Exception: {_ex.Message} \n\n Stack: {_ex.StackTrace}");
            }

            try
            {
                for (int i = 0; i < 20; i++)
                {
                    headIcons[i] = new Sprite(archiveMedia, "headicons", i, metadataBuffer);
                }

                await TaskDelayFactory.Create(1);
            }
            catch (Exception _ex)
            {
                signlink.reporterror($"Unexpected Exception: {_ex.Message} \n\n Stack: {_ex.StackTrace}");
                throw;
            }

            mapFlag   = new Sprite(archiveMedia, "mapmarker", 0, metadataBuffer);
            mapMarker = new Sprite(archiveMedia, "mapmarker", 1, metadataBuffer);
            for (int i = 0; i < 8; i++)
            {
                crosses[i] = new Sprite(archiveMedia, "cross", i, metadataBuffer);
            }

            mapDotItem    = new Sprite(archiveMedia, "mapdots", 0, metadataBuffer);
            mapDotNPC     = new Sprite(archiveMedia, "mapdots", 1, metadataBuffer);
            mapDotPlayer  = new Sprite(archiveMedia, "mapdots", 2, metadataBuffer);
            mapDotFriend  = new Sprite(archiveMedia, "mapdots", 3, metadataBuffer);
            mapDotTeam    = new Sprite(archiveMedia, "mapdots", 4, metadataBuffer);
            scrollBarUp   = new IndexedImage(archiveMedia, "scrollbar", 0, metadataBuffer);
            scrollBarDown = new IndexedImage(archiveMedia, "scrollbar", 1, metadataBuffer);
            redStone1     = new IndexedImage(archiveMedia, "redstone1", 0, metadataBuffer);
            redStone2     = new IndexedImage(archiveMedia, "redstone2", 0, metadataBuffer);
            redStone3     = new IndexedImage(archiveMedia, "redstone3", 0, metadataBuffer);
            redStone1_2   = new IndexedImage(archiveMedia, "redstone1", 0, metadataBuffer);
            redStone1_2.flipHorizontally();
            redStone2_2 = new IndexedImage(archiveMedia, "redstone2", 0, metadataBuffer);
            redStone2_2.flipHorizontally();
            redStone1_3 = new IndexedImage(archiveMedia, "redstone1", 0, metadataBuffer);
            redStone1_3.flipVertically();
            redStone2_3 = new IndexedImage(archiveMedia, "redstone2", 0, metadataBuffer);
            redStone2_3.flipVertically();
            redStone3_2 = new IndexedImage(archiveMedia, "redstone3", 0, metadataBuffer);
            redStone3_2.flipVertically();
            redStone1_4 = new IndexedImage(archiveMedia, "redstone1", 0, metadataBuffer);
            redStone1_4.flipHorizontally();
            redStone1_4.flipVertically();
            redStone2_4 = new IndexedImage(archiveMedia, "redstone2", 0, metadataBuffer);
            redStone2_4.flipHorizontally();
            redStone2_4.flipVertically();
            for (int i = 0; i < 2; i++)
            {
                modIcons[i] = new IndexedImage(archiveMedia, "mod_icons", i, metadataBuffer);
            }

            await TaskDelayFactory.Create(1);

            Sprite sprite = new Sprite(archiveMedia, "backleft1", 0, metadataBuffer);

            backLeftIP1 = CreateNewImageProducer(sprite.width, sprite.height, nameof(backLeftIP1));
            sprite.drawInverse(0, 0);
            sprite      = new Sprite(archiveMedia, "backleft2", 0, metadataBuffer);
            backLeftIP2 = CreateNewImageProducer(sprite.width, sprite.height, nameof(backLeftIP2));
            sprite.drawInverse(0, 0);
            sprite       = new Sprite(archiveMedia, "backright1", 0, metadataBuffer);
            backRightIP1 = CreateNewImageProducer(sprite.width, sprite.height, nameof(backRightIP1));
            sprite.drawInverse(0, 0);
            sprite       = new Sprite(archiveMedia, "backright2", 0, metadataBuffer);
            backRightIP2 = CreateNewImageProducer(sprite.width, sprite.height, nameof(backRightIP2));
            sprite.drawInverse(0, 0);
            sprite     = new Sprite(archiveMedia, "backtop1", 0, metadataBuffer);
            backTopIP1 = CreateNewImageProducer(sprite.width, sprite.height, nameof(backTopIP1));
            sprite.drawInverse(0, 0);
            sprite      = new Sprite(archiveMedia, "backvmid1", 0, metadataBuffer);
            backVmidIP1 = CreateNewImageProducer(sprite.width, sprite.height, nameof(backVmidIP1));
            sprite.drawInverse(0, 0);
            sprite      = new Sprite(archiveMedia, "backvmid2", 0, metadataBuffer);
            backVmidIP2 = CreateNewImageProducer(sprite.width, sprite.height, nameof(backVmidIP2));
            sprite.drawInverse(0, 0);
            sprite      = new Sprite(archiveMedia, "backvmid3", 0, metadataBuffer);
            backVmidIP3 = CreateNewImageProducer(sprite.width, sprite.height, nameof(backVmidIP3));
            sprite.drawInverse(0, 0);
            sprite        = new Sprite(archiveMedia, "backhmid2", 0, metadataBuffer);
            backVmidIP2_2 = CreateNewImageProducer(sprite.width, sprite.height, nameof(backVmidIP2_2));
            sprite.drawInverse(0, 0);

            await TaskDelayFactory.Create(1);

            int randomRed    = (int)(StaticRandomGenerator.Next() * 21D) - 10;
            int randomGreen  = (int)(StaticRandomGenerator.Next() * 21D) - 10;
            int randomBlue   = (int)(StaticRandomGenerator.Next() * 21D) - 10;
            int randomColour = (int)(StaticRandomGenerator.Next() * 41D) - 20;

            for (int i = 0; i < 100; i++)
            {
                if (mapFunctionImage[i] != null)
                {
                    mapFunctionImage[i].adjustRGB(randomRed + randomColour, randomGreen + randomColour,
                                                  randomBlue + randomColour);
                }
                if (mapSceneImage[i] != null)
                {
                    mapSceneImage[i].mixPalette(randomRed + randomColour, randomGreen + randomColour,
                                                randomBlue + randomColour);
                }
            }
        }
예제 #4
0
        private void rgbToHls(int rgb)
        {
            double red   = (rgb >> 16 & 0xff) / 256D;
            double green = (rgb >> 8 & 0xff) / 256D;
            double blue  = (rgb & 0xff) / 256D;
            double minC  = red;

            if (green < minC)
            {
                minC = green;
            }
            if (blue < minC)
            {
                minC = blue;
            }
            double maxC = red;

            if (green > maxC)
            {
                maxC = green;
            }
            if (blue > maxC)
            {
                maxC = blue;
            }
            double h = 0.0D;
            double s = 0.0D;
            double l = (minC + maxC) / 2D;

            if (minC != maxC)
            {
                if (l < 0.5D)
                {
                    s = (maxC - minC) / (maxC + minC);
                }
                if (l >= 0.5D)
                {
                    s = (maxC - minC) / (2D - maxC - minC);
                }
                if (red == maxC)
                {
                    h = (green - blue) / (maxC - minC);
                }
                else if (green == maxC)
                {
                    h = 2D + (blue - red) / (maxC - minC);
                }
                else if (blue == maxC)
                {
                    h = 4D + (red - green) / (maxC - minC);
                }
            }

            h         /= 6D;
            hue2       = (int)(h * 256D);
            saturation = (int)(s * 256D);
            lightness  = (int)(l * 256D);
            if (saturation < 0)
            {
                saturation = 0;
            }
            else if (saturation > 255)
            {
                saturation = 255;
            }
            if (lightness < 0)
            {
                lightness = 0;
            }
            else if (lightness > 255)
            {
                lightness = 255;
            }
            if (l > 0.5D)
            {
                hueDivisor = (int)((1.0D - l) * s * 512D);
            }
            else
            {
                hueDivisor = (int)(l * s * 512D);
            }
            if (hueDivisor < 1)
            {
                hueDivisor = 1;
            }
            hue = (int)(h * hueDivisor);
            int randomHue = (hue2 + (int)(StaticRandomGenerator.Next(16))) - 8;

            if (randomHue < 0)
            {
                randomHue = 0;
            }
            else if (randomHue > 255)
            {
                randomHue = 255;
            }
            int randomSaturation = (saturation + (int)(StaticRandomGenerator.Next(48))) - 24;

            if (randomSaturation < 0)
            {
                randomSaturation = 0;
            }
            else if (randomSaturation > 255)
            {
                randomSaturation = 255;
            }
            int randomLightness = (lightness + (int)(StaticRandomGenerator.Next(48))) - 24;

            if (randomLightness < 0)
            {
                randomLightness = 0;
            }
            else if (randomLightness > 255)
            {
                randomLightness = 255;
            }
            hsl = packHSL(randomHue, randomSaturation, randomLightness);
        }