Exemplo n.º 1
0
    def get_free_mat_inst_consts(self, reload_only: bool = False) -> None:

        # We need any MeshComponent to create new MatInstConsts, I just use this cuz it's always loaded

        if not reload_only:
            # create and assign the new MatInstConsts
            for obj in self.need_mat_inst_const:
                mat = MESH.CreateAndSetMaterialInstanceConstant(0)
                unrealsdk.KeepAlive(mat)

                if obj.Class in (
                        unrealsdk.FindClass("ClassModDefinition"),
                        unrealsdk.FindClass("CrossDLCClassModDefinition"),
                        unrealsdk.FindClass("ArtifactDefinition")):
                    obj.OverrideMaterial = mat
                else:
                    obj.Material = mat

        for file in self.files:
            with open(file, "r") as TemplateFile:
                for line in TemplateFile:
                    if not line.split() or line.split()[0].lower() != "set":
                        continue
                    else:
                        try:
                            Materials.exec_skins(line, self.is_game_bl2)
                        except Exception as e:
                            logging.logger.error(e)
                            logging.logger.error(f"Error in: {line}")
Exemplo n.º 2
0
def bpd_helper(new_bpd: unrealsdk.UObject) -> None:
    counter = 0
    for Sequence in new_bpd.BehaviorSequences:
        for Data in Sequence.BehaviorData2:
            if Data.Behavior:
                new_behavior = unrealsdk.ConstructObject(Class=Data.Behavior.Class, Outer=new_bpd,
                                                         Name=f"{Data.Behavior.Name}_{counter}",
                                                         Template=Data.Behavior)
                unrealsdk.KeepAlive(new_behavior)
                new_behavior.ObjectFlags.B |= 4
                Data.Behavior = new_behavior
                counter += 1
                if Data.Behavior.Class == unrealsdk.FindClass("Behavior_AttributeEffect"):
                    behavior_attribute_effect_helper(new_behavior)
                elif Data.Behavior.Class == unrealsdk.FindClass("Behavior_ActivateSkill"):
                    behavior_activate_skill_helper(new_behavior)
Exemplo n.º 3
0
    def change_weapon(self):
        pawn_inv_manager = get_player_controller().GetPawnInventoryManager()
        if not self.old_gun:
            pass
        else:
            pawn_inv_manager.InventoryUnreadied(
                pawn_inv_manager.GetWeaponInSlot(1), False)

        willow_weapon = get_current_worldinfo().Spawn(
            unrealsdk.FindClass('WillowWeapon'))
        pawn_inv_manager.ChangedWeapon()

        definition_data = self.get_random_def_data_mayhem(
        ) if self.b_mayhem else self.get_random_def_data()

        willow_weapon.InitializeFromDefinitionData(definition_data,
                                                   pawn_inv_manager.Instigator,
                                                   True)
        willow_weapon.AdjustWeaponForBeingInBackpack()
        pawn_inv_manager.GiveStoredAmmoBeforeGoingToBackpack(
            definition_data[0].AmmoResource,
            definition_data[0].StartingAmmoCount)
        pawn_inv_manager.AddInventoryToBackpack(willow_weapon)
        pawn_inv_manager.ReadyBackpackInventory(willow_weapon, 1)
        self.old_gun = willow_weapon
Exemplo n.º 4
0
    def bank_on_close(self, caller: unrealsdk.UObject) -> bool:
        if caller.MaxSlots == 4:
            read_f = open(self.STASH_PATH, "r")
            save_json = json.load(read_f)
        elif caller.MaxSlots == 3:  # the grinder in TPS
            return True
        else:
            read_f = open(self.LOAD_PATH, "r")
            save_json = json.load(read_f)
        read_f.close()
        wweapon_class = unrealsdk.FindClass("WillowWeapon")

        bank = {"Weapons": list(), "Items": list()}
        for chest_data in caller.TheChest:
            if not chest_data.Inventory:
                break

            mark: int = chest_data.Inventory.Mark
            if chest_data.Inventory.Class == wweapon_class:
                bank["Weapons"].append(get_weapon_from_data(chest_data.Inventory.DefinitionData, mark=mark))
            else:
                bank["Items"].append(get_item_from_data(chest_data.Inventory.DefinitionData, mark=mark))
            chest_data.Inventory.Destroy()
            chest_data.Inventory = None

        bl2tools.get_player_controller().OnChestClosing(caller)
        caller.ChestIsOpen = False

        with open(self.LOAD_PATH if caller.MaxSlots != 4 else self.STASH_PATH, "w") as f:
            if caller.MaxSlots == 4:
                json.dump(bank, f, indent=4)
            else:
                save_json["Bank"] = bank
                json.dump(save_json, f, indent=4)
        return False
Exemplo n.º 5
0
def obj_is_in_class(obj, inClass):
    """
    Compares the given Objects class with the given class.
    :param obj: UObject
    :param inClass: String, the Class to compare with
    :return: Bool, whether or not it's in the Class.
    """
    return bool(obj.Class == unrealsdk.FindClass(inClass))
Exemplo n.º 6
0
def obj_is_in_class(uobject: unrealsdk.UObject, uclass: str):
    """
    Compares the given Objects class with the given class.
    :param uobject: UObject
    :param uclass: String, the Class to compare with
    :return: Bool, whether it's in the Class.
    """
    return bool(uobject.Class == unrealsdk.FindClass(uclass))
Exemplo n.º 7
0
        def HandleVerificationReceived(caller: unrealsdk.UObject, function: unrealsdk.UFunction, params: unrealsdk.FStruct) -> bool:
            PC = unrealsdk.GetEngine().GamePlayers[0].Actor
            for i in range(self.DUMMY_AMOUNT):
                obj = unrealsdk.ConstructObject(unrealsdk.FindClass("SparkServiceConfiguration"))
                PC.ServerRCon(f"set {PC.PathName(obj)} ServiceName Dummy_{i}")

            unrealsdk.RemoveHook("GearboxFramework.SparkInitializationProcess.HandleVerificationReceived", "FixHotfixes")
            return True
Exemplo n.º 8
0
def behavior_attribute_effect_helper(new_obj: unrealsdk.UObject) -> None:
    if new_obj.AttributeEffect:
        new_effect = unrealsdk.ConstructObject(Class=new_obj.AttributeEffect.Class, Outer=new_obj,
                                               Name=f"{new_obj.AttributeEffect.Name}_1",
                                               Template=new_obj.AttributeEffect)
        unrealsdk.KeepAlive(new_effect)
        new_effect.ObjectFlags.B |= 4
        new_obj.AttributeEffect = new_effect
        if new_effect == unrealsdk.FindClass("SkillDefinition"):
            bpd_copy_helper(new_effect)
            skill_constraints_helper(new_effect)
Exemplo n.º 9
0
    def end_scene(self) -> None:
        if not IMGUI_SHOW:
            return

        pyd_imgui.begin("Inventory Editor")

        _, self.u_class_index = pyd_imgui.combo("Add Class",
                                                self.u_class_index,
                                                self.u_classes)
        if _:
            self.edit_obj = None

        # noinspection PyArgumentList
        if pyd_imgui.button("Add New"):
            pc: unrealsdk.UObject = bl2tools.get_player_controller()
            new_uclass: str = self.u_classes[self.u_class_index]
            if new_uclass == "WillowWeapon":
                pc.GetPawnInventoryManager().ClientAddWeaponToBackpack((), 1,
                                                                       False)
            else:
                new_item: unrealsdk.UObject = pc.Spawn(
                    unrealsdk.FindClass(new_uclass))
                new_item.Quantity = 1
                pc.GetPawnInventoryManager().AddInventoryToBackpack(new_item)

            inventory.update_inventory()

        pyd_imgui.separator()

        pyd_imgui.text(f"Backpack")
        _, self.backpack_index = pyd_imgui.list_box_stretch(
            "##backpack", self.backpack_index,
            inventory.player_inventory_readable)
        if _:
            self.b_update_helper = True
        pyd_imgui.end()

        if not inventory.player_inventory:
            return
        try:
            self.edit_obj = inventory.player_inventory[self.backpack_index]
        except IndexError:
            # in case the user removed too many objects from his inventory we might run into this exception
            # so let's just reset his backpack index to -1
            self.backpack_index = len(inventory.player_inventory) - 1
            self.edit_obj = inventory.player_inventory[self.backpack_index]
            self.b_update_helper = True

        if not self.edit_obj:
            return

        self.edit_helper()
Exemplo n.º 10
0
def on_any_impact_helper(new_obj: unrealsdk.UObject) -> None:
    if new_obj.OnAnyImpact:
        new_on_any_impact = []
        counter = 0
        for behavior in new_obj.OnAnyImpact:
            new_behavior = unrealsdk.ConstructObject(Class=behavior.Class, Outer=new_obj,
                                                     Name=f"{behavior.Name}_{counter}",
                                                     Template=behavior)
            counter += 1
            unrealsdk.KeepAlive(new_behavior)
            new_behavior.ObjectFlags.B |= 4
            new_on_any_impact.append(new_behavior)
            if behavior.Class == unrealsdk.FindClass("Behavior_AttributeEffect"):
                behavior_attribute_effect_helper(new_behavior)
        new_obj.OnAnyImpact = new_on_any_impact
Exemplo n.º 11
0
def _create_data_provider(name: str) -> unrealsdk.UObject:
    """
    Helper function that creates a new data provider and adds it to the stack.

    Args:
        name: The menu name to give the new data provider.
    Returns:
        The data provider.
    """
    provider = unrealsdk.ConstructObject(Class=unrealsdk.FindClass(
        "WillowScrollingListDataProviderOptionsBase"))
    # See issue #45
    unrealsdk.GetEngine().GamePlayers[0].Actor.ServerRCon(
        f"set {provider.PathName(provider)} MenuDisplayName {name}")
    _modded_data_provider_stack.append(provider)
    return provider
Exemplo n.º 12
0
    def exec_skins(command: str, is_bl2: bool) -> None:
        """

        :type is_bl2: bool
        :type command: str
        """
        pc = bl2tools.get_player_controller()

        pattern_simple_param_name = re.compile("ParameterName=\"(.*?)\"")
        pattern_simple_float = re.compile("-?\d+\.\d+")
        pattern_simple_obj = re.compile("ParameterValue=(.*?),")
        pattern_simple_rgba = re.compile(
            "ParameterValue=\(R=(-?\d+\.\d+),G=(-?\d+\.\d+),B=(-?\d+\.\d+),A=(-?\d+\.\d+)\)"
        )
        obj = unrealsdk.FindObject("Object", command.split()[1])

        if obj is None:
            # When we don't find our object, simply skip to the next line
            return

        # this is used in case we dynamically created a MatInstConst for a constructed MaterialPart, so we need to get
        # its MatInstConst from the known MatPart Object inside the '.Material' file.
        if obj.Class in (unrealsdk.FindClass("ClassModDefinition"),
                         unrealsdk.FindClass("CrossDLCClassModDefinition"),
                         unrealsdk.FindClass("ArtifactDefinition")):
            new_mat = obj.OverrideMaterial
        else:
            new_mat = obj.Material

        # this happens if we are not using the .material file and want to edit the MatInstConst object directly
        if new_mat is None:
            new_mat = obj

        if is_bl2:
            set_cmd = "set "
            set_cmd += bl2tools.get_obj_path_name(new_mat) + " "
            set_cmd += command.split()[2] + " " + command.split()[3]
            pc.ConsoleCommand(set_cmd, 1)

        # The following code will only run if the game is TPS
        else:
            attr = command.split()[2].lower()
            values = command.split()[3].strip()
            if attr == "parent":
                new_mat.SetParent(unrealsdk.FindObject("Object", values))
            elif attr == "scalarparametervalues":
                for param, val in zip(
                        re.finditer(pattern_simple_param_name, values),
                        re.finditer(pattern_simple_float, values)):
                    value = float(val.group())
                    new_mat.SetScalarParameterValue(param.group(1), value)
                    logging.logger.verbose(
                        f"{bl2tools.get_obj_path_name(new_mat)}.SetScalarParameterValue({param.group(1)}, {value})"
                    )

            elif attr == "textureparametervalues":
                for param, val in zip(
                        re.finditer(pattern_simple_param_name, values),
                        re.finditer(pattern_simple_obj, values)):
                    value = unrealsdk.FindObject("Object", val.group(1))
                    new_mat.SetTextureParameterValue(param.group(1), value)
                    logging.logger.verbose(
                        f"{bl2tools.get_obj_path_name(new_mat)}.SetTextureParameterValue({param.group(1)}, {value})"
                    )
            elif attr == "vectorparametervalues":
                for param, val in zip(
                        re.finditer(pattern_simple_param_name, values),
                        re.finditer(pattern_simple_rgba, values)):
                    new_mat.SetVectorParameterValue(
                        param.group(1), tuple(float(x) for x in val.groups()))
                    logging.logger.verbose(
                        f"{bl2tools.get_obj_path_name(new_mat)}.SetVectorParameterValue({param.group(1)}, "
                        f"{tuple(float(x) for x in val.groups())})")