Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: marcincichocki/breach-protocol-autosolver
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.0.0-beta.0
Choose a base ref
...
head repository: marcincichocki/breach-protocol-autosolver
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.0.0-beta.1
Choose a head ref
  • 11 commits
  • 19 files changed
  • 1 contributor

Commits on Aug 24, 2021

  1. Copy the full SHA
    f5c016e View commit details
  2. build: update standard-version

    fixes #168
    marcincichocki authored Aug 24, 2021
    Copy the full SHA
    1a37899 View commit details

Commits on Aug 25, 2021

  1. Copy the full SHA
    497601b View commit details
  2. Copy the full SHA
    0927d44 View commit details

Commits on Aug 26, 2021

  1. Copy the full SHA
    a32c7a6 View commit details
  2. Copy the full SHA
    909e7ac View commit details
  3. Copy the full SHA
    cce0da1 View commit details
  4. Copy the full SHA
    d437366 View commit details
  5. Copy the full SHA
    b20f91a View commit details
  6. Copy the full SHA
    d455198 View commit details
  7. Copy the full SHA
    38075a1 View commit details
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,25 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [2.0.0-beta.1](https://github.com/marcincichocki/breach-protocol-autosolver/compare/v2.0.0-beta.0...v2.0.0-beta.1) (2021-08-26)


### Features

* **client-electron:** add ability to play sound on breach start ([909e7ac](https://github.com/marcincichocki/breach-protocol-autosolver/commit/909e7ac17334e9e4579ea5ca776ef0d54ed6f0cf)), closes [#172](https://github.com/marcincichocki/breach-protocol-autosolver/issues/172) [#164](https://github.com/marcincichocki/breach-protocol-autosolver/issues/164)
* **client-electron:** add error handler to worker ([cce0da1](https://github.com/marcincichocki/breach-protocol-autosolver/commit/cce0da18217fbf1a0ddd097d51daa7ff98b91111))


### Bug Fixes

* **client-electron:** catch unhandled promises ([d455198](https://github.com/marcincichocki/breach-protocol-autosolver/commit/d455198393ad423b5e27d4418cc2ec74c64a9912))
* **client-electron:** preserve metadata in action ([497601b](https://github.com/marcincichocki/breach-protocol-autosolver/commit/497601ba1516e3ea4bd8671663747257cea4d332))
* **client-electron:** resolve race condition ([0927d44](https://github.com/marcincichocki/breach-protocol-autosolver/commit/0927d4416b71fba01f9cbdfaf967ed350c5d11c8))
* **core:** catch unhandled errors during ocr ([a32c7a6](https://github.com/marcincichocki/breach-protocol-autosolver/commit/a32c7a6c488fa8f02b4f69dfd88b208c08a79b30)), closes [#166](https://github.com/marcincichocki/breach-protocol-autosolver/issues/166)
* **core:** handle custom resolutions ([d437366](https://github.com/marcincichocki/breach-protocol-autosolver/commit/d4373665915fbfb37a2d6f1c75e0ccd5089231ec))
* **core:** load traindeddata with new strategy ([f5c016e](https://github.com/marcincichocki/breach-protocol-autosolver/commit/f5c016ea652dea3aefdf2875cf7a34338c0cfda4)), closes [#162](https://github.com/marcincichocki/breach-protocol-autosolver/issues/162)
* **linux:** send correct keystroke ([b20f91a](https://github.com/marcincichocki/breach-protocol-autosolver/commit/b20f91a2a0904e48165e6859aa945f1aaf71c2a1))

## [2.0.0-beta.0](https://github.com/marcincichocki/breach-protocol-autosolver/compare/v1.8.0...v2.0.0-beta.0) (2021-08-22)


18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "breach-protocol-autosolver",
"version": "2.0.0-beta.0",
"version": "2.0.0-beta.1",
"description": "Automatically solve breach protocol minigame in Cyberpunk 2077",
"main": "dist/main.js",
"private": true,
@@ -84,7 +84,7 @@
"jest": "^26.6.3",
"license-webpack-plugin": "^2.3.19",
"patch-package": "^6.4.7",
"standard-version": "^9.3.0",
"standard-version": "^9.3.1",
"style-loader": "^2.0.0",
"ts-jest": "^26.4.4",
"ts-loader": "^9.1.1",
2 changes: 1 addition & 1 deletion src/common/node/robot.ts
Original file line number Diff line number Diff line change
@@ -143,7 +143,7 @@ export class NirCmdRobot extends BreachProtocolRobot {
export class AhkRobot extends BreachProtocolRobot {
protected readonly keys = {
[BreachProtocolRobotKeys.Escape]: 'Escape',
[BreachProtocolRobotKeys.Enter]: 'Enter',
[BreachProtocolRobotKeys.Enter]: 'Return',
[BreachProtocolRobotKeys.Up]: 'Up',
[BreachProtocolRobotKeys.Down]: 'Down',
[BreachProtocolRobotKeys.Left]: 'Left',
Binary file added src/core/bp-registry/custom/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions src/core/bp-registry/registry.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
{
"custom": [
{
"fileName": "1.png",
"daemons": [
["55", "1C", "1C"],
["1C", "1C"],
["1C", "E9", "1C", "E9"]
],
"grid": [
"E9", "1C", "55", "1C", "55",
"1C", "1C", "55", "E9", "55",
"1C", "1C", "55", "E9", "1C",
"BD", "1C", "1C", "1C", "55",
"1C", "55", "1C", "55", "BD"
],
"bufferSize": 7
}
],
"1024x768": [
{
"fileName": "1.png",
25 changes: 18 additions & 7 deletions src/core/ocr/base.ts
Original file line number Diff line number Diff line change
@@ -128,12 +128,12 @@ export abstract class BreachProtocolFragment<
const { width, height, left, top } = this.container.getCroppedBoundingBox();

return {
left: left + Math.round(p1.x * width),
top: top + Math.round(p1.y * height),
left: Math.round(p1.x * width + left),
top: Math.round(p1.y * height + top),
width: Math.round((p2.x - p1.x) * width),
height: Math.round((p2.y - p1.y) * height),
outerWidth: width + 2 * left,
outerHeight: height + 2 * top,
outerWidth: Math.round(2 * left + width),
outerHeight: Math.round(2 * top + height),
innerWidth: width,
innerHeight: height,
} as BreachProtocolFragmentBoundingBox;
@@ -264,13 +264,21 @@ export abstract class BreachProtocolOCRFragment<
return w;
}

static async initScheduler(
options: Partial<Tesseract.WorkerOptions> = { cachePath: './resources' }
) {
/**
* Initialize tesseract.js scheduler.
*
* @param langPath Path to folder where BreachProtocol.traineddata can be found. Relative to process.cwd() or absolute.
*/
static async initScheduler(langPath: string) {
if (BreachProtocolOCRFragment.scheduler) {
throw new Error('Scheduler is alredy initialized.');
}

const options: Partial<Tesseract.WorkerOptions> = {
cacheMethod: 'none',
gzip: false,
langPath,
};
const w1 = await BreachProtocolOCRFragment.initWorker(options);
const w2 = await BreachProtocolOCRFragment.initWorker(options);

@@ -282,6 +290,9 @@ export abstract class BreachProtocolOCRFragment<
BreachProtocolOCRFragment.scheduler = scheduler;
}

/**
* Terminate tesseract.js scheduler.
*/
static terminateScheduler() {
if (!BreachProtocolOCRFragment.scheduler) {
throw new Error('Scheduler is not initialized.');
16 changes: 14 additions & 2 deletions src/core/ocr/buffer-size-trim.ts
Original file line number Diff line number Diff line change
@@ -5,18 +5,30 @@ import { BreachProtocolBufferSizeFragmentResult } from './buffer-size';
export class BreachProtocolBufferSizeTrimFragment<
TImage
> extends BreachProtocolBufferSizeBase<TImage> {
override readonly fragment = this.container.processBufferSizeFragment(this.boundingBox);
override readonly fragment = this.container.processBufferSizeFragment(
this.boundingBox
);

// Ensure compatibility with current api.
async recognize(
threshold?: number
): Promise<BreachProtocolBufferSizeFragmentResult> {
const { buffer, width } = await this.container.trim(this.fragment);
const { buffer, width } = await this.trimFragment();
const bufferSize = await this.getBufferSizeFromPixels(width);

return this.getFragmentResult(null, bufferSize, buffer, null);
}

private async trimFragment() {
try {
return await this.container.trim(this.fragment);
} catch (e) {
const buffer = await this.container.toBuffer(this.fragment);

return { buffer, width: 0 };
}
}

private async getBufferSizeFromPixels(width: number) {
const { innerWidth } = this.boundingBox;

2 changes: 1 addition & 1 deletion src/core/ocr/buffer-size.ts
Original file line number Diff line number Diff line change
@@ -82,7 +82,7 @@ export class BreachProtocolBufferSizeFragment<
// Second control group has some white pixels, threshold is too low.
start = m + 1;
}
} while (i++ < Math.log2(base) + 1);
} while (++i < Math.log2(base));

// No threshold found.
return base;
10 changes: 9 additions & 1 deletion src/core/ocr/ocr.test.ts
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ interface RegistryEntry {
}

type Resolution =
| 'custom'
| '1024x768'
| '1920x1080'
| '2560x1440'
@@ -177,13 +178,20 @@ describe('raw data validation', () => {

describe('ocr', () => {
beforeAll(async () => {
await BreachProtocolOCRFragment.initScheduler();
await BreachProtocolOCRFragment.initScheduler('./resources');
}, 30000);

afterAll(async () => {
await BreachProtocolOCRFragment.terminateScheduler();
});

it.each(getRegistryFor('custom'))(
'should correctly ocr custom resolution/%s',
async (f: string, entry: RegistryEntry) => {
await compareOcrToJson(entry, 'custom');
}
);

it.each(getRegistryFor('1024x768'))(
'should correctly ocr 1024x768/%s',
async (f: string, entry: RegistryEntry) => {
1 change: 1 addition & 0 deletions src/electron/common/common.ts
Original file line number Diff line number Diff line change
@@ -49,6 +49,7 @@ export interface AppSettings extends RobotSettings {
preserveSourceOnSuccess: boolean;
soundEnabled: boolean;
errorSoundPath: string;
startSoundPath: string;
checkForUpdates: boolean;
autoUpdate: boolean;
minimizeToTray: boolean;
5 changes: 5 additions & 0 deletions src/electron/common/options.ts
Original file line number Diff line number Diff line change
@@ -74,6 +74,11 @@ const options: BreachProtocolOption[] = [
? 'C:/Windows/Media/Windows Foreground.wav'
: '',
},
{
id: 'startSoundPath',
description: 'Sound played at the start of the job.',
defaultValue: '',
},
{
id: 'thresholdBufferSize',
description: 'Fixed threshold value for buffer size fragment.',
5 changes: 3 additions & 2 deletions src/electron/main/store/store.ts
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ import {
Request,
Response,
State,
WorkerStatus,
} from '@/electron/common';
import { app, ipcMain as ipc, IpcMainEvent, WebContents } from 'electron';
import ElectronStore from 'electron-store';
@@ -141,7 +142,7 @@ export class Store {
history: this.history.get('data'),
displays: [],
settings: { ...this.settings.store, screenshotDir },
status: null,
status: WorkerStatus.Bootstrap,
updateStatus: null,
stats: this.stats.store,
};
@@ -164,7 +165,7 @@ export class Store {
}

private notify(action: Action) {
const stateAction = { payload: this.state, type: action.type };
const stateAction = { ...action, payload: this.state };

this.worker.send('state', stateAction);
this.renderer.send('state', stateAction);
27 changes: 23 additions & 4 deletions src/electron/renderer/components/File.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { basename } from 'path';
import { ChangeEvent, useState } from 'react';
import { MdClose } from 'react-icons/md';
import styled from 'styled-components';
import { useField } from './Form';

@@ -49,15 +51,22 @@ const FileLabel = styled.label`
cursor: pointer;
`;

const ClearButton = styled.button`
height: 50px;
width: 50px;
border: 2px solid var(--primary);
color: var(--primary);
background: #942f2f;
cursor: pointer;
`;

interface FileProps {
accept?: string;
}

export const File = ({ accept }: FileProps) => {
const { setValue, value, name } = useField<string>();
const [displayName, setDisplayName] = useState<string>(
value.slice(value.lastIndexOf('/') + 1)
);
const [displayName, setDisplayName] = useState<string>(basename(value));

function onChange(e: ChangeEvent<HTMLInputElement>) {
const file = e.target.files[0];
@@ -68,10 +77,20 @@ export const File = ({ accept }: FileProps) => {
setValue(file.path);
}

function onClear() {
setDisplayName(null);
setValue('');
}

return (
<FileWrapper>
{value ? (
<FilePath>{displayName}</FilePath>
<>
<ClearButton onClick={onClear}>
<MdClose size="24px" />
</ClearButton>
<FilePath>{displayName}</FilePath>
</>
) : (
<FilePathEmpty>No file selected</FilePathEmpty>
)}
14 changes: 11 additions & 3 deletions src/electron/renderer/pages/Settings.tsx
Original file line number Diff line number Diff line change
@@ -182,10 +182,14 @@ const AutoSolverSettings = ({ status }: { status: WorkerStatus }) => {
}
}

function changeAhkBinPath() {
function changeAhkBinPath(path: string) {
if (values.engine === 'ahk') {
// NOTE: same as above.
updateWorkerStatus(WorkerStatus.Ready);
if (path) {
// NOTE: same as above.
updateWorkerStatus(WorkerStatus.Ready);
} else {
updateWorkerStatus(WorkerStatus.Disabled);
}
}
}

@@ -234,6 +238,10 @@ const AutoSolverSettings = ({ status }: { status: WorkerStatus }) => {
<Label>Error sound path</Label>
<File accept=".mp3,.wav" />
</Field>
<Field name="startSoundPath">
<Label>Start sound</Label>
<File accept=".mp3,.wav" />
</Field>
<Field name="delay">
<Label>Delay</Label>
<RangeSlider />
Loading