Ejemplo n.º 1
0
        public ReformPasteEventPacket(int planetId, List <ReformData> reformPreviews, Color[] colors, int playerId)
        {
            AuthorId = playerId;
            PlanetId = planetId;

            using (IWriterProvider writer = NebulaModAPI.GetBinaryWriter())
            {
                writer.BinaryWriter.Write(reformPreviews.Count);
                foreach (ReformData data in reformPreviews)
                {
                    writer.BinaryWriter.Write(data.latitude);
                    writer.BinaryWriter.Write(data.longitude);
                    writer.BinaryWriter.Write(data.type);
                    writer.BinaryWriter.Write(data.color);
                }

                writer.BinaryWriter.Write(colors != null);
                if (colors != null)
                {
                    for (int i = 0; i < 16; i++)
                    {
                        writer.BinaryWriter.Write(colors[i].r);
                        writer.BinaryWriter.Write(colors[i].g);
                        writer.BinaryWriter.Write(colors[i].b);
                        writer.BinaryWriter.Write(colors[i].a);
                    }
                }

                ReformData = writer.CloseAndGetBytes();
            }
        }
Ejemplo n.º 2
0
        public void GetData(out List <ReformData> reforms, out Color[] colors)
        {
            reforms = new List <ReformData>();
            colors  = null;

            using (IReaderProvider reader = NebulaModAPI.GetBinaryReader(ReformData))
            {
                int count = reader.BinaryReader.ReadInt32();
                for (int i = 0; i < count; i++)
                {
                    ReformData data = new ReformData
                    {
                        latitude  = reader.BinaryReader.ReadSingle(),
                        longitude = reader.BinaryReader.ReadSingle(),
                        type      = reader.BinaryReader.ReadInt32(),
                        color     = reader.BinaryReader.ReadInt32()
                    };
                    reforms.Add(data);
                }

                if (reader.BinaryReader.ReadBoolean())
                {
                    colors = new Color[16];
                    for (int i = 0; i < 16; i++)
                    {
                        colors[i] = new Color(
                            reader.BinaryReader.ReadSingle(),
                            reader.BinaryReader.ReadSingle(),
                            reader.BinaryReader.ReadSingle(),
                            reader.BinaryReader.ReadSingle());
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public List <ItemPackageL> GetData()
        {
            List <ItemPackageL> items = new List <ItemPackageL>(dataCount);

            using IReaderProvider reader = NebulaModAPI.GetBinaryReader(data);

            for (int i = 0; i < dataCount; i++)
            {
                int itemId = reader.BinaryReader.ReadInt32();
                int count  = reader.BinaryReader.ReadInt32();
                int inc    = reader.BinaryReader.ReadInt32();
                items.Add(new ItemPackageL(itemId, count, inc));
            }

            return(items);
        }
Ejemplo n.º 4
0
        public ReturnItemsPacket(Dictionary <int, int> counts, Dictionary <int, int> incCounts)
        {
            using IWriterProvider writer = NebulaModAPI.GetBinaryWriter();
            dataCount = counts.Count(pair => pair.Value > 0);

            foreach (var pair in counts)
            {
                if (pair.Value > 0)
                {
                    writer.BinaryWriter.Write(pair.Key);
                    writer.BinaryWriter.Write(pair.Value);
                    writer.BinaryWriter.Write(incCounts[pair.Key]);
                }
            }

            data = writer.CloseAndGetBytes();
        }
Ejemplo n.º 5
0
        private void Awake()
        {
            logger = Logger;

            #region Config

            cameraToggleEnabled   = Config.Bind("Interface", "cameraToggle", true, "Allows toggling camera between 3rd person and god view\nAll values are applied on restart");
            addPasteButtonEnabled = Config.Bind("Interface", "addBluprintPasteButton", true, "If enabled new button will be added to Blueprint Browser. Pressing it will paste curretly selected blueprint\nAll values are applied on restart");

            recipeChangeEnabled        = Config.Bind("Interface", "recipeChange", true, "Add recipe change panel to blueprint inspectors\nAll values are applied on restart");
            logisticCargoChangeEnabled = Config.Bind("Interface", "changeLogisticCargo", true, "Allows changing cargo requested/provided by logistic stations");
            changeTierEnabled          = Config.Bind("Interface", "changeTier", true, "Allows using change tier functionality\nAll values are applied on restart");
            beltHintsChangeEnable      = Config.Bind("Interface", "beltHintChange", true, "Add belt hint change panel to blueprint inspectors\nAll values are applied on restart");
            keepBlueprintDesc          = Config.Bind("Interface", "keepBlueprintDescription", true, "When pasting blueprint string into existing blueprint you can hold shift to keep description and icons");
            keepBrowserPath            = Config.Bind("Interface", "keepBroserPath", true, "Preserve last open Blueprint Browser directory. Also when creating new blueprints, they will be saved in the last open directory");



            forcePasteEnabled  = Config.Bind("Features", "forcePaste", true, "Allows using key to force blueprint placement\nAll values are applied on restart");
            axisLockEnabled    = Config.Bind("Features", "axisLock", true, "Allows using Latitude/Longtitude axis locks\nAll values are applied on restart");
            gridControlFeature = Config.Bind("Features", "gridControl", true, "Allows changing grid size and its offset\nAll values are applied on restart");
            blueprintMirroring = Config.Bind("Features", "blueprintMirroring", true, "Allows mirroring Blueprints\nAll values are applied on restart");
            dragRemove         = Config.Bind("Features", "dragRemove", true, "Allows using drag remove function\nAll values are applied on restart");
            pasteLocked        = Config.Bind("Features", "PasteLockedRecipes", true, "Allow pasting assemblers with recipes which have not been unlocked yet. Assemblers with recipes that are not unlocked will not work.");
            moveWithDragNDrop  = Config.Bind("Features", "moveBPWithDragNDrop", true, "Allow moving blueprints using drag and drop");
            factoryUndo        = Config.Bind("Features", "factoryUndo", true, "Enable Factory Undo feature. Allows to undo/redo most building actions. Will force dragRemove to true");


            blueprintFoundations = Config.Bind("Features", "blueprintFoundations", true, "Allow blueprinting foundations along with buildings.\nAll values are applied on restart");

            resetFunctionsOnMenuExit = Config.Bind("Misc", "resetOnExit", true, "If enabled when you exit build mode, some functions (Axis/Grid lock, Mirror) will reset their state");
            canBlueprintOnGasGiants  = Config.Bind("Misc", "bpOnGasGiants", true, "Allow using Blueprints on Gas Giants\nAll values are applied on restart");

            useFastDismantle = Config.Bind("Misc", "useFastDismantle", true, "When using drag remove tool or factory undo, an improved algorithm of removing entities will be used. It is about 20x faster, but might have some imperfections. If you encounter issues you can switch back to vanilla code.");
            excludeStations  = Config.Bind("Misc", "excludeStations", true, "When using drag remove tool, logistic stations (and miners Mk.II) will not get removed. This is a safeguard against errors which occur most of the time when you try to mass dismantle logistic stations.");

            undoMaxHistory = Config.Bind("Misc", "undoMaxHistory", 50, "Defines undo history size. When history reaches it's capacity, old entries will get removed. When using Nebula host controls the used value");


            Config.MigrateConfig <bool>("General", "Interface", new [] { "cameraToggle", "recipeChange", "changeLogisticCargo", "changeTier" });
            Config.MigrateConfig <bool>("General", "Features", new [] { "forcePaste", "axisLock", "gridControl", "gridControl", "blueprintFoundations" });
            Config.MigrateConfig <bool>("General", "Misc", new [] { "bpOnGasGiants" });

            if (factoryUndo.Value)
            {
                dragRemove.Value = true;
            }

            #endregion

            Config.Save();

            if (BepInEx.Bootstrap.Chainloader.PluginInfos.ContainsKey(FREE_FOUNDATIONS_GUID))
            {
                freeFoundationsIsInstalled = true;
            }
            if (BepInEx.Bootstrap.Chainloader.PluginInfos.ContainsKey(FREE_FOUNDATIONS_GUID_2))
            {
                freeFoundationsIsInstalled = true;
            }

            string pluginfolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            resource = new ResourceData(MODNAME, "blueprinttweaks", pluginfolder);
            resource.LoadAssetBundle("blueprinttweaks");
            ProtoRegistry.AddResource(resource);

            Harmony harmony = new Harmony(MODGUID);

            #region Strings

            ProtoRegistry.RegisterString("KEYToggleBPGodModeDesc", "Toggle Blueprint God Mode", "切换上帝模式浏览蓝图");
            ProtoRegistry.RegisterString("RecipesLabel", "Recipes", "配方");
            ProtoRegistry.RegisterString("ChangeTipText", "Left-click to change recipe", "左键点击更改配方");

            ProtoRegistry.RegisterString("ChangeTipTitle", "Change Recipe", "更改配方");
            ProtoRegistry.RegisterString("ChangeTipDesc",
                                         "Left-click to change recipe. When you click, picker menu will open, where a new recipe can be selected. All machines that used the old recipe will now use selected recipe. This change will take effect after saving.",
                                         "左键点击更改配方。点击将打开选择菜单,可在其中选择新配方。所有使用旧配方的机器将更新到选定的新配方。此更改将在保存后生效。");
            ProtoRegistry.RegisterString("KEYForceBPPlace", "Force Blueprint placement", "强制蓝图放置");

            ProtoRegistry.RegisterString("KEYLockLongAxis", "Lock Longitude axis", "经度锁定");
            ProtoRegistry.RegisterString("KEYLockLatAxis", "Lock Latitude axis", "纬度锁定");
            ProtoRegistry.RegisterString("KEYSetLocalOffset", "Set grid snapping offset", "设定网格捕捉偏移");

            ProtoRegistry.RegisterString("GridSizeLabel", "Blueprint Size", "蓝图尺寸");
            ProtoRegistry.RegisterString("GridLongSize", "Width", "宽度");
            ProtoRegistry.RegisterString("GridLatSize", "Height", "高度");

            ProtoRegistry.RegisterString("CantPasteThisInGasGiantWarn",
                                         "This Blueprint can't be pasted on a Gas Giant.",
                                         "此蓝图无法放置在气态/冰巨星上。");

            ProtoRegistry.RegisterString("FoundationsLabel", "Foundations", "地基");
            ProtoRegistry.RegisterString("foundationsBPCountLabel", "recorded", "块地基");
            ProtoRegistry.RegisterString("foundationBPEnabledLabel", "Blueprint foundations", "蓝图包含地基");

            ProtoRegistry.RegisterString("TransportLabel", "Logistics", "物流");
            ProtoRegistry.RegisterString("ChangeTipText2", "Left-click to change requested item", "左键点击更改物流清单物品");
            ProtoRegistry.RegisterString("ChangeTip2Title", "Change requested items", "更改物流清单物品");
            ProtoRegistry.RegisterString("ChangeTip2Desc",
                                         "Left-click to change requested item. When you click, picker menu will open, where a new item can be selected. Logistic station that used the old item will now use selected item. This change will take effect after saving.",
                                         "左键点击更改物流清单物品。点击将打开选择菜单,可在其中选择新的物流清单物品。使用旧物流清单物品的物流塔将更新到选定的新物流清单物品。此更改将在保存后生效。");


            ProtoRegistry.RegisterString("copyColorsLabel", "Copy Custom foundation colors", "附带自定义调色板");
            ProtoRegistry.RegisterString("copyColorsTip", "Copy Custom foundation colors", "附带自定义调色板");
            ProtoRegistry.RegisterString("copyColorsTipDesc",
                                         "When enabled, Custom foundation colors will be saved with Blueprint Data. When such Blueprint will be pasted, current planet's Custom colors will be replaced with colors stored in the Blueprint",
                                         "启用后,地基的自定义调色板将与蓝图数据一同保存。粘贴此类蓝图时,当前行星的地基自定义调色板将被蓝图中的调色板替代。");

            ProtoRegistry.RegisterString("hasColorsLabel", "Contains Color data", "含有颜色数据");

            ProtoRegistry.RegisterString("foundationsBlueprintTip", "Blueprint Foundations", "蓝图包含地基");
            ProtoRegistry.RegisterString("foundationsBlueprintTipDesc",
                                         "When enabled, all Foundations (Including their colors and types) in your selection will be saved to the Blueprint. If there are buildings that lack support, but blueprint has foundations under them they will successfully be pasted",
                                         "启用后,您选中的所有地基(包括它们的颜色和类型)都将保存到蓝图中。另外只要蓝图中的建筑下方包含地基,即便施工场地缺乏地基支撑,蓝图也能成功粘贴");

            ProtoRegistry.RegisterString("KEYMirrorLongAxis", "Mirror Blueprint in Longitude axis", "经向镜像");
            ProtoRegistry.RegisterString("KEYMirrorLatAxis", "Mirror Blueprint in Latitude axis", "纬向镜像");


            ProtoRegistry.RegisterString("BeltHintsLabel", "Belt Hints", "腰带提示");
            ProtoRegistry.RegisterString("HintsChangeTipText", "Left-click to change belt hints", "左键单击更改腰带提示");

            ProtoRegistry.RegisterString("ChangeHintsTipTitle", "You can change belt hints", "您可以更改腰带提示");
            ProtoRegistry.RegisterString("ChangeHintsTipDesc",
                                         "Left-click to change hints on belts. When you click, picker menu will open, where a new icon can be selected. All belts that used the old icon will now use selected icon. This change will take effect after saving.",
                                         "左键点击更改腰带提示。点击将打开选择菜单,可在其中选择新腰带提示。所有使用旧腰带提示的输送带将更新到选定的新腰带提示。此更改将在保存后生效。");

            ProtoRegistry.RegisterString("recipeLockedWarn", "Recipe is locked", "食谱已锁定");

            ProtoRegistry.RegisterString("BPBrowserPasteButtonTipTitle", "Paste Blueprint [Double click]", "粘贴蓝图[双击]");
            ProtoRegistry.RegisterString("BPBrowserPasteButtonTipDesc", "Start pasting current selected blueprint", "开始张贴当前选定的蓝图");

            ProtoRegistry.RegisterString("MoveBlueprintTip", "Move to", "移动到");

            ProtoRegistry.RegisterString("FileAlreadyExistsTitle", "Can't move blueprint!", "动不了蓝图!");
            ProtoRegistry.RegisterString("FileAlreadyExistsDesc",
                                         "Blueprint with same name already exists in target location! Please rename your blueprint and try again.",
                                         "同名蓝图已存在于目标位置! 请重命名蓝图并重试。");

            ProtoRegistry.RegisterString("KEYFactoryUndo", "Undo", "撤消");
            ProtoRegistry.RegisterString("KEYFactoryRedo", "Redo", "重做");

            ProtoRegistry.RegisterString("KEYDSPTrashButton", "Select Trash", "选择垃圾");

            ProtoRegistry.RegisterString("NotEnoughFoundationsMessage",
                                         "You need {0} more foundations to place this Blueprint!",
                                         "你需要 {0} 更多的基础来放置这个蓝图!");

            ProtoRegistry.RegisterString("FoundCountMessage",
                                         "Will consume {0} foundations",
                                         "会消耗 {0} 基础");


            ProtoRegistry.RegisterString("UndoSuccessText", "Undone successfully!", "撤消成功!");
            ProtoRegistry.RegisterString("UndoFailureText", "Failed to undo!", "未能撤消!");
            ProtoRegistry.RegisterString("RedoSuccessText", "Redone successfully!", "重做成功!");
            ProtoRegistry.RegisterString("RedoFailureText", "Failed to redo!", "重做失败!");

            ProtoRegistry.RegisterString("UndoClearedMessage", "Undo history cleared!", "撤消历史清除!");

            ProtoRegistry.RegisterString("UndoHistoryEmptyMessage", "Undo history is empty!", "撤消历史是空的!");
            ProtoRegistry.RegisterString("RedoHistoryEmptyMessage", "Redo history is empty!", "重做历史是空的!");

            #endregion

            if (factoryUndo.Value)
            {
                UndoManager.Init();
            }
            UIBlueprintInspectorPatch.Init();
            BlueprintUtilsPatch2.Init();
            RegisterKeyBinds();

            NebulaModAPI.RegisterPackets(Assembly.GetExecutingAssembly());

            #region Patches

            if (factoryUndo.Value)
            {
                harmony.PatchAll(FACTORY_UNDO);
            }

            if (keepBrowserPath.Value)
            {
                harmony.PatchAll(typeof(UIBlueprintBrowser_Patch));
            }

            if (moveWithDragNDrop.Value)
            {
                harmony.PatchAll(typeof(BuildTool_Copy_Patch));
                harmony.PatchAll(typeof(DragToMoveBlueprints.UIBlueprintBrowser_Patch));
            }

            if (keepBlueprintDesc.Value)
            {
                harmony.PatchAll(typeof(KeepBPName.UIBlueprintInspectorPatch));
            }

            if (pasteLocked.Value)
            {
                harmony.PatchAll(PASTE_LOCKED);
            }

            if (addPasteButtonEnabled.Value)
            {
                harmony.PatchAll(typeof(UIBlueprintBrowserPatch));
            }

            if (blueprintMirroring.Value)
            {
                harmony.PatchAll(typeof(BlueprintUtilsPatch2));
            }

            if (dragRemove.Value)
            {
                harmony.PatchAll(DRAG_REMOVE);
            }

            if (blueprintFoundations.Value)
            {
                harmony.PatchAll(BLUEPRINT_FOUNDATIONS);
            }

            if (changeTierEnabled.Value)
            {
                harmony.PatchAll(typeof(UIBlueprintComponentItemPatch));
            }

            if (canBlueprintOnGasGiants.Value)
            {
                harmony.PatchAll(typeof(PlayerControllerPatch));
                harmony.PatchAll(typeof(BuildTool_BlueprintPastePatch));
            }

            if (axisLockEnabled.Value || gridControlFeature.Value)
            {
                harmony.PatchAll(typeof(GridSnappingPatches));
            }
            if (cameraToggleEnabled.Value)
            {
                harmony.PatchAll(typeof(CameraFixPatch));
            }
            if (recipeChangeEnabled.Value || gridControlFeature.Value)
            {
                harmony.PatchAll(typeof(UIBlueprintInspectorPatch));
            }
            if (forcePasteEnabled.Value)
            {
                harmony.PatchAll(typeof(BlueprintPastePatch));
            }

            #endregion

            logger.LogInfo("Blueprint tweaks mod is initialized!");
        }