Skip to content

Commit

Permalink
Fixin' item on item interactions and adding a variable to disable xtea
Browse files Browse the repository at this point in the history
  • Loading branch information
Katilith committed Nov 26, 2021
1 parent 3788683 commit 5d48d09
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 21 deletions.
1 change: 1 addition & 0 deletions config/server-config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"loginServerPort": 43591,
"rsaMod": "119568088839203297999728368933573315070738693395974011872885408638642676871679245723887367232256427712869170521351089799352546294030059890127723509653145359924771433131004387212857375068629466435244653901851504845054452735390701003613803443469723435116497545687393297329052988014281948392136928774011011998343",
"rsaExp": "12747337179295870166838611986189126026507945904720545965726999254744592875817063488911622974072289858092633084100280214658532446654378876853112046049506789703022033047774294965255097838909779899992870910011426403494610880634275141204442441976355383839981584149269550057129306515912021704593400378690444280161",
"encryptionEnabled": true,
"playerSavePath": "./data/saves",

"showWelcome": true,
Expand Down
3 changes: 2 additions & 1 deletion data/config/widgets.json5
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,6 @@
christmas: 23,
killcount: 24
},
whatWouldYouLikeToSpin: 459
whatWouldYouLikeToSpin: 459,
tanningHidesInterface: 324
}
18 changes: 13 additions & 5 deletions src/engine/action/pipe/item-on-item.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,19 @@ const itemOnItemActionPipe = (player: Player, usedItem: Item, usedSlot: number,
}

// Find all item on item action plugins that match this action
let matchingHooks = getActionHooks<ItemOnItemActionHook>('item_on_item').filter(plugin =>
questHookFilter(player, plugin) &&
(plugin.items.findIndex(i => i.item1 === usedItem.itemId && i.item2 === usedWithItem.itemId) !== -1 ||
plugin.items.findIndex(i => i.item2 === usedItem.itemId && i.item1 === usedWithItem.itemId) !== -1 ||
plugin.items.findIndex(i => i.item1 === usedItem.itemId && !i.item2 || i.item1 === usedWithItem.itemId && !i.item2 ) !== -1));
let matchingHooks = getActionHooks<ItemOnItemActionHook>('item_on_item', plugin => {
if(questHookFilter(player, plugin)) {
const used = usedItem.itemId;
const usedWith = usedWithItem.itemId;

return (plugin.items.some(({ item1, item2 }) => {
const items = [ item1, item2 ];
return items.includes(used) && items.includes(usedWith);
}));
}

return false;
});

const questActions = matchingHooks.filter(plugin => plugin.questRequirement !== undefined);

Expand Down
3 changes: 2 additions & 1 deletion src/engine/net/inbound-packets/item-on-item.packet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const itemOnItemPacket = (player: Player, packet: PacketData) => {
return;
}

player.actionPipeline.call('item_on_item', player, usedItem, usedSlot, usedWidgetId, usedWithItem, usedWithSlot, usedWithWidgetId);
player.actionPipeline.call('item_on_item',
player, usedItem, usedSlot, usedWidgetId, usedWithItem, usedWithSlot, usedWithWidgetId);
} else {
logger.warn(`Unhandled item on item case using widgets ${usedWidgetId}:${usedContainerId} => ${usedWithWidgetId}:${usedWithContainerId}`);
}
Expand Down
30 changes: 16 additions & 14 deletions src/engine/net/outbound-packet-handler.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { Player, SidebarTab } from '../world/actor/player/player';
import { Socket } from 'net';
import { Packet, PacketType } from '@engine/net/packet';
import { ItemContainer } from '@engine/world/items/item-container';
import { Item } from '@engine/world/items/item';
import { Position } from '@engine/world/position';
import { Chunk, ChunkUpdateItem } from '@engine/world/map/chunk';
import { WorldItem } from '@engine/world/items/world-item';
import { ByteBuffer } from '@runejs/core/buffer';
import { Npc } from '@engine/world/actor/npc';
import { stringToLong } from '@engine/util/strings';
import { LandscapeObject } from '@runejs/filestore';
import { xteaRegions } from '@engine/config/config-handler';
import { ConstructedChunk, ConstructedRegion } from '@engine/world/map/region';
import { ByteBuffer } from '@runejs/core/buffer';

import { serverConfig } from '@server/game';
import { Packet, PacketType } from '@engine/net';
import { xteaRegions } from '@engine/config';
import { activeWorld } from '@engine/world';
import { stringToLong } from '@engine/util';
import { ChunkUpdateItem, Position } from '@engine/world';
import { Player, SidebarTab, Npc } from '@engine/world/actor';
import { ItemContainer, Item, WorldItem } from '@engine/world/items';
import { Chunk, ConstructedChunk, ConstructedRegion } from '@engine/world/map';



Expand Down Expand Up @@ -643,12 +641,14 @@ export class OutboundPacketHandler {

packet.closeBitBuffer();

const encryptionEnabled = serverConfig.encryptionEnabled === undefined ? true : serverConfig.encryptionEnabled;

// Put the xtea keys for the two construction room template maps
// Map coords: 29,79 && 30,79
for(let mapX = 29; mapX <= 30; mapX++) {
const xteaRegion = xteaRegions[`l${mapX}_79`];
for(let seeds = 0; seeds < 4; seeds++) {
packet.put(/*xteaRegion?.key[seeds] || */0, 'int');
packet.put(encryptionEnabled ? (xteaRegion?.key[seeds] ?? 0) : 0, 'int');
}
}

Expand All @@ -668,11 +668,13 @@ export class OutboundPacketHandler {
const startY = Math.floor(this.player.position.chunkY / 8);
const endY = Math.floor((this.player.position.chunkY + 12) / 8);

const encryptionEnabled = serverConfig.encryptionEnabled === undefined ? true : serverConfig.encryptionEnabled;

for(let mapX = startX; mapX <= endX; mapX++) {
for(let mapY = startY; mapY <= endY; mapY++) {
const xteaRegion = xteaRegions[`l${mapX}_${mapY}`];
for(let seeds = 0; seeds < 4; seeds++) {
packet.put(/*xteaRegion?.key[seeds] || */0, 'int');
packet.put(encryptionEnabled ? (xteaRegion?.key[seeds] ?? 0) : 0, 'int');
}
}
}
Expand Down
34 changes: 34 additions & 0 deletions src/plugins/skills/crafting/leather-armour-interface.plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { ItemOnItemAction, ItemOnItemActionHook, TaskExecutor } from '@engine/action';
import { Player } from '@engine/world/actor';
import { widgets } from '@engine/config';


const openLeatherArmourCraftingInterface = (task: TaskExecutor<ItemOnItemAction>) => {
console.log(`[TASK] Executing func`);
const { player, actionData } = task.getDetails();

player.sendMessage('Opening interface');

player.interfaceState.openWidget(widgets.tanningHidesInterface, {
slot: 'screen'
});

loadLeatherArmourCraftingInterface(player);
};

const loadLeatherArmourCraftingInterface = (player: Player) => {
// player.sendMessage('Opening interface')
};

export default {
pluginId: 'rs:leather-armour-interface',
hooks: [
{
type: 'item_on_item',
items: [{ item1: 1733, item2: 1741 }, { item1: 1733, item2: 1743 }],
task: {
activate: openLeatherArmourCraftingInterface,
}
} as ItemOnItemActionHook,
]
};
1 change: 1 addition & 0 deletions src/server/game/game-server-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export interface GameServerConfig {
rsaExp: string;
host: string;
port: number;
encryptionEnabled: boolean;
loginServerHost: string;
loginServerPort: number;
updateServerHost: string;
Expand Down

0 comments on commit 5d48d09

Please sign in to comment.