Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Changelog

## Unreleased — original low-poly driving scene
## Unreleased — embedded versioned maps and driving scene

- Removed map file selection/forget controls. Standalone loads compressed game-matching app resources directly and ignores obsolete IndexedDB imports.
- Added automatic Steam library discovery, version-archive/content inventory compatibility checks, bounded gzip decoding and pack checksum validation. Incompatible packs are disabled after game/DLC changes.
- Local packaging embeds the qualified ATS 1.61.3.1 scene (about 24 MiB compressed). Public archives exclude local game-derived data; automatic extraction for other/new versions remains unimplemented.
- Bundled the MIT, checksum-pinned ETS2LA 1.61 provider with automatic installation for verified compatible game packs, existing DLL backups and installation/restart status. Live feed qualification remains separate from successful installation.
- Added embedded pack selection, tampering, version/DLC changes and clean-profile app reload/restart regressions.


- Replaced the triangle position marker with an original generic tractor and optional straight trailer proxy, following measured world pose.
- Added a smoothed 30 FPS chase camera, persistent overview switch and shortest-angle heading interpolation; hidden/paused views stop animation.
Expand Down
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,9 @@ The app reuses `haulsense.service` when present, otherwise starts its bundled na

### Maps and live signal/GPS provider

Use **Load road map** once. IndexedDB restores that map on the next launch/reload; **Forget map** removes the saved copy. The standalone also checks `${XDG_DATA_HOME:-~/.local/share}/haulsense/maps/ats.json` on its first launch. Game-derived map files are not shipped in public releases. See [export, limits and map setup](docs/WEB-NAVIGATOR.md).
The standalone selects an embedded, compressed map automatically. There is no map file picker and old IndexedDB imports are ignored. Local packaging (`npm run --prefix ats-dualsense/desktop package -- --local-maps`, also used by the source desktop installer) embeds `build/ats-scene.json` / `build/ets2-scene.json` with extracted `gameVersion` metadata. Steam libraries are discovered automatically. The installed version archive and game/DLC archive inventory must match the pack; game/content updates disable incompatible roads instead of silently using stale data. The verified local ATS pack is **1.61.3.1**, approximately **24 MiB compressed**. ETS2 has no locally qualified embedded pack yet.

For **ATS/ETS2 1.61 only**, install the separate, checksum-pinned ETS2LA provider, then restart the game:

```bash
GAME_VERSION=1.61 ATS_DIR='/path/to/American Truck Simulator' ./ats-dualsense/scripts/install-signal-provider.sh
```
The standalone also bundles the checksum-pinned MIT **1.61.x** ETS2LA provider and installs it automatically into a verified matching Windows game installation, backing up a different existing DLL. Its status distinguishes installation from a live connection. Restart the game after a new provider installation. Game-derived packs stay in the local application; the public source/archive excludes them. Automatic extraction for arbitrary fresh installations and future game versions is not implemented; those builds need matching map packs prepared during packaging. See [pack creation and compatibility](docs/WEB-NAVIGATOR.md).

Under Wine/Proton, the provider creates `/dev/shm/ETS2LASemaphore` and `/dev/shm/ETS2LARoute`. HaulSense reads them without writing controls or injecting into game memory. Do not use this pinned provider for another game version. [Provider ABI, compatibility and freshness](docs/SIGNAL-PROVIDER.md) explains the limitations and live qualification gap.

Expand Down
22 changes: 22 additions & 0 deletions ats-dualsense/desktop/embed-maps.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';
// Local game-derived packs stay in build/resources, outside source and public archives.
const fs=require('node:fs/promises'),path=require('node:path'),zlib=require('node:zlib');
const {libraries,identify,digest,regular,readResource}=require('./maps.cjs');
async function embed(target,home){
const root=path.resolve(__dirname,'../..'),packs=[];
for(const game of ['ats','ets2']){
const source=path.join(root,'build',game+'-scene.json');let map;try{map=JSON.parse(await regular(source));}catch(error){if(error.code==='ENOENT')continue;throw error;}
if(map.game!==game||map.version!==2||!/^\d+\.\d+\.\d+\.\d+$/.test(map.gameVersion||''))throw Error('Map must contain its extracted gameVersion: '+source);
let directory;for(const library of await libraries(home)){const candidate=path.join(library,'steamapps','common',game==='ats'?'American Truck Simulator':'Euro Truck Simulator 2');try{await identify(candidate);directory=candidate;break;}catch{}}
if(!directory)throw Error('Cannot verify the game installation for '+game);
// Check extracted version against the current game's log before binding archive identity.
const id=game==='ats'?'270880':'227300';const steamapps=path.dirname(path.dirname(directory));const log=path.join(steamapps,'compatdata',id,'pfx','drive_c','users','steamuser','Documents',path.basename(directory),'game.log.txt');
const versionResource=await readResource(path.join(directory,'version.scs'),1024*1024),logResource=await readResource(log,16*1024*1024);if(versionResource.stat.mtimeMs>logResource.stat.mtimeMs)throw Error('Run the updated game once before embedding its map');
const text=logResource.data.toString('utf8');const match=text.match(/Loaded pack set version (\d+\.\d+\.\d+\.\d+)/);if(match?.[1]!==map.gameVersion)throw Error('Extracted map does not match the installed game log');
const identity=await identify(directory),data=Buffer.from(JSON.stringify(map)),compressed=zlib.gzipSync(data,{level:9}),file=game+'-'+map.gameVersion+'.json.gz';
await fs.mkdir(path.join(target,'maps'),{recursive:true});await fs.writeFile(path.join(target,'maps',file),compressed);
packs.push({game,gameVersion:map.gameVersion,file,bytes:data.length,sha256:digest(compressed),...identity});
}
await fs.mkdir(path.join(target,'maps'),{recursive:true});await fs.writeFile(path.join(target,'maps','manifest.json'),JSON.stringify({format:1,packs},null,2));return packs;
}
module.exports={embed};
10 changes: 5 additions & 5 deletions ats-dualsense/desktop/main.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
const {app,BrowserWindow,Menu,protocol,session,dialog,net}=require('electron');
const {spawn}=require('node:child_process');
const fs=require('node:fs'),path=require('node:path'),{Readable}=require('node:stream');
const fs=require('node:fs'),path=require('node:path');
const {ORIGIN,allowedURL,allowedPath}=require('./policy.cjs');
const demo=process.argv.includes('--demo');
const service=demo?'http://127.0.0.1:39076':'http://127.0.0.1:39056';let window,ownedDaemon;
Expand All @@ -25,15 +25,15 @@ async function ensureService(){
}
async function start(){
await ensureService();
const maps=new (require('./maps.cjs').EmbeddedMaps)(app.isPackaged?process.resourcesPath:path.resolve(__dirname,'../../build/embedded-resources'),app.getPath('home'));await maps.init();
async function mapGame(){try{const state=await (await net.fetch(service+'/api/state',{signal:AbortSignal.timeout(1000)})).json();if(['ats','ets2'].includes(state.telemetry?.game))return state.telemetry.game;}catch{}return maps.manifest.packs[0]?.game||'ats';}
const ses=session.fromPartition('persist:haulsense');
ses.setPermissionRequestHandler((_contents,_permission,callback)=>callback(false));ses.setPermissionCheckHandler(()=>false);
ses.webRequest.onBeforeRequest((details,callback)=>callback({cancel:!allowedURL(details.url)}));
ses.protocol.handle('haulsense',async request=>{
const url=new URL(request.url);if(!allowedURL(request.url)||url.search||!allowedPath(url.pathname,request.method))return new Response('Not found',{status:404});
if(url.pathname==='/api/map'){
const dataHome=process.env.XDG_DATA_HOME||path.join(app.getPath('home'),'.local','share');
const map=path.join(dataHome,'haulsense','maps','ats.json');
try{const stat=await fs.promises.lstat(map);if(!stat.isFile()||stat.size>96*1024*1024)throw Error('Invalid map');return new Response(Readable.toWeb(fs.createReadStream(map)),{headers:{'Content-Type':'application/json','Cache-Control':'no-store'}});}catch{return new Response('No installed map',{status:404});}
if(url.pathname==='/api/map-status'||url.pathname==='/api/map'){
try{const game=await mapGame();if(url.pathname==='/api/map-status'){const {state,pack}=await maps.status(game);return Response.json({...state,id:pack?.sha256||null},{headers:{'Cache-Control':'no-store'}});}return new Response(await maps.read(game),{headers:{'Content-Type':'application/json','Cache-Control':'no-store'}});}catch{return new Response('Embedded map unavailable',{status:503});}
}
const headers={};if(request.method==='POST'){headers['X-HaulSense']='1';headers['Content-Type']='application/x-www-form-urlencoded';headers.Origin=service;}
try{return await net.fetch(service+url.pathname,{method:request.method,headers,body:request.method==='POST'?await request.text():undefined,signal:AbortSignal.timeout(3000)});}catch{return new Response('Local service unavailable',{status:503});}
Expand Down
45 changes: 45 additions & 0 deletions ats-dualsense/desktop/maps.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'use strict';
// Trusted application resources only. Renderer input never supplies filesystem paths.
const fs=require('node:fs/promises'),path=require('node:path'),crypto=require('node:crypto'),zlib=require('node:zlib');
const GAMES={ats:{id:'270880',directory:'American Truck Simulator'},ets2:{id:'227300',directory:'Euro Truck Simulator 2'}};
const MAX=96*1024*1024;
const digest=data=>crypto.createHash('sha256').update(data).digest('hex');
async function readResource(file,max=MAX){
const handle=await fs.open(file,fs.constants.O_RDONLY|fs.constants.O_NOFOLLOW);
try{const stat=await handle.stat();if(!stat.isFile()||stat.size>max)throw Error('Invalid application resource');const data=Buffer.alloc(stat.size);let offset=0;while(offset<data.length){const {bytesRead}=await handle.read(data,offset,data.length-offset,offset);if(!bytesRead)throw Error('Resource changed during read');offset+=bytesRead;}const after=await handle.stat();if(after.size!==stat.size||after.mtimeMs!==stat.mtimeMs)throw Error('Resource changed during read');return {data,stat};}finally{await handle.close();}
}
async function regular(file,max=MAX){return (await readResource(file,max)).data;}
async function libraries(home){
const roots=[path.join(home,'.steam','steam'),path.join(home,'.local','share','Steam'),path.join(home,'.var','app','com.valvesoftware.Steam','data','Steam')];const result=new Set();
for(const root of roots){try{const vdf=await fs.readFile(path.join(root,'steamapps','libraryfolders.vdf'),'utf8');result.add(root);for(const m of vdf.matchAll(/"path"\s+"([^"\r\n]+)"/g))if(path.isAbsolute(m[1]))result.add(m[1].replace(/\\\\/g,'\\'));}catch{}}
return [...result];
}
async function identify(directory){
const versionSha256=digest(await regular(path.join(directory,'version.scs'),1024*1024));
const archives=[];for(const name of (await fs.readdir(directory)).filter(n=>/^[a-z0-9_]+\.scs$/i.test(n)).sort()){const s=await fs.lstat(path.join(directory,name));if(!s.isFile())throw Error('Invalid game archive');archives.push([name,s.size]);}
return {versionSha256,archiveSignature:digest(JSON.stringify(archives))};
}
function compatible(pack,identity){return pack.versionSha256===identity.versionSha256&&pack.archiveSignature===identity.archiveSignature;}
class EmbeddedMaps{
constructor(resources,home){this.resources=resources;this.home=home;this.checked=new Map();}
async init(){try{this.manifest=JSON.parse(await regular(path.join(this.resources,'maps','manifest.json'),1024*1024));if(this.manifest.format!==1||!Array.isArray(this.manifest.packs))throw Error('Invalid map catalog');}catch{this.manifest={format:1,packs:[]};}this.roots=await libraries(this.home);}
async status(game='ats'){
if(!GAMES[game])game='ats';const packs=this.manifest.packs.filter(p=>p.game===game);let installation;
for(const root of this.roots){const directory=path.join(root,'steamapps','common',GAMES[game].directory);try{const identity=await identify(directory);installation={directory,identity};break;}catch{}}
const pack=installation&&packs.find(p=>compatible(p,installation.identity));
const state={game,ready:!!pack,version:pack?.gameVersion||null,reason:!installation?'game-not-installed':!packs.length?'map-not-bundled':!pack?'version-mismatch':'ready',provider:'waiting',message:!installation?'Steam game installation not found.':!packs.length?'This app has no embedded map for '+game.toUpperCase()+'.':!pack?'Game content changed. A matching app map pack is required; incompatible roads are disabled.':'Embedded '+game.toUpperCase()+' '+pack.gameVersion+' map · verified against installed game archives'};
if(pack&&pack.gameVersion.startsWith('1.61.')){try{state.provider=await this.provision(installation.directory);}catch{state.provider='install-failed';}}
if(pack&&!pack.gameVersion.startsWith('1.61.'))state.provider='unsupported-version';
return {state,pack};
}
async provision(directory){
const source=path.join(this.resources,'providers','ets2la_plugin.dll');const expected='0e1893719f84f28079857451b82a22a263401d98b8fc299cd561eb7695bfa88f';
const data=await regular(source,1024*1024);if(digest(data)!==expected)throw Error('Invalid provider checksum');
const plugins=path.join(directory,'bin','win_x64','plugins');await fs.mkdir(plugins,{recursive:true});if(!(await fs.lstat(plugins)).isDirectory())throw Error('Invalid plugins directory');const target=path.join(plugins,'ets2la_plugin.dll');
try{if(digest(await regular(target,1024*1024))===expected){const status=this.checked.get(directory)||'installed';this.checked.set(directory,status);return status;}await fs.copyFile(target,target+'.backup-'+Date.now(),fs.constants.COPYFILE_EXCL);}catch(error){if(error.code!=='ENOENT')throw error;}
const temporary=path.join(plugins,'.haulsense-provider-'+crypto.randomBytes(8).toString('hex'));try{await fs.writeFile(temporary,data,{mode:0o644,flag:'wx'});await fs.rename(temporary,target);}finally{await fs.unlink(temporary).catch(()=>{});}
this.checked.set(directory,'restart-required');return 'restart-required';
}
async read(game){const {state,pack}=await this.status(game);if(!state.ready)throw Error(state.message);if(!/^(ats|ets2)-[0-9.]+\.json\.gz$/.test(pack.file))throw Error('Invalid map pack filename');const bytes=await regular(path.join(this.resources,'maps',pack.file));if(digest(bytes)!==pack.sha256)throw Error('Map pack checksum mismatch');const data=zlib.gunzipSync(bytes,{maxOutputLength:MAX});if(data.length!==pack.bytes)throw Error('Map pack size mismatch');return data;}
}
module.exports={EmbeddedMaps,libraries,identify,compatible,digest,regular,readResource};
15 changes: 12 additions & 3 deletions ats-dualsense/desktop/package.cjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
'use strict';
const path=require('node:path'),fs=require('node:fs/promises');
const path=require('node:path'),fs=require('node:fs/promises'),os=require('node:os');
const localMaps=process.argv.includes('--local-maps');
(async()=>{
const provider=path.resolve(__dirname,'../../build/ets2la-provider/ets2la_plugin.dll');
const expected='0e1893719f84f28079857451b82a22a263401d98b8fc299cd561eb7695bfa88f';let providerBytes;
try{providerBytes=await require('./maps.cjs').regular(provider,1024*1024);}catch(error){if(error.code!=='ENOENT')throw error;await require('node:util').promisify(require('node:child_process').execFile)('bash',[path.resolve(__dirname,'../scripts/download-signal-provider.sh')],{timeout:100000});providerBytes=await require('./maps.cjs').regular(provider,1024*1024);}
if(providerBytes.length>1024*1024||require('./maps.cjs').digest(providerBytes)!==expected)throw Error('Provider checksum mismatch');
const {packager}=await import('@electron/packager');
const output=path.resolve(__dirname,'../../build/desktop');
const {flipFuses,FuseVersion,FuseV1Options}=await import('@electron/fuses');
const paths=await packager({dir:__dirname,out:output,name:'HaulSense',executableName:'haulsense-app',platform:'linux',arch:'x64',electronVersion:require('./package.json').devDependencies.electron,overwrite:true,asar:true,prune:true,ignore:[/^\/test(?:\/|$)/,/^\/package\.cjs$/,/^\/node_modules$/]});
for(const directory of paths){await flipFuses(path.join(directory,'haulsense-app'),{version:FuseVersion.V1,[FuseV1Options.RunAsNode]:false,[FuseV1Options.EnableNodeOptionsEnvironmentVariable]:false,[FuseV1Options.EnableNodeCliInspectArguments]:false,[FuseV1Options.OnlyLoadAppFromAsar]:true});const target=path.join(directory,'resources','daemon');await fs.mkdir(target,{recursive:true});await fs.copyFile(path.resolve(__dirname,'../../build/ats-dualsense/daemon/haulsense'),path.join(target,'haulsense'));await fs.chmod(path.join(target,'haulsense'),0o755);await fs.copyFile(path.resolve(__dirname,'../../LICENSE'),path.join(directory,'HAULSENSE-LICENSE'));}
const paths=await packager({dir:__dirname,out:output,name:'HaulSense',executableName:'haulsense-app',platform:'linux',arch:'x64',electronVersion:require('./package.json').devDependencies.electron,overwrite:true,asar:true,prune:true,ignore:[/^\/test(?:\/|$)/,/^\/(?:package|embed-maps)\.cjs$/,/^\/node_modules$/]});
for(const directory of paths){await flipFuses(path.join(directory,'haulsense-app'),{version:FuseVersion.V1,[FuseV1Options.RunAsNode]:false,[FuseV1Options.EnableNodeOptionsEnvironmentVariable]:false,[FuseV1Options.EnableNodeCliInspectArguments]:false,[FuseV1Options.OnlyLoadAppFromAsar]:true});const target=path.join(directory,'resources','daemon');await fs.mkdir(target,{recursive:true});await fs.copyFile(path.resolve(__dirname,'../../build/ats-dualsense/daemon/haulsense'),path.join(target,'haulsense'));await fs.chmod(path.join(target,'haulsense'),0o755);await fs.copyFile(path.resolve(__dirname,'../../LICENSE'),path.join(directory,'HAULSENSE-LICENSE'));
if(localMaps)await require('./embed-maps.cjs').embed(path.join(directory,'resources'),os.homedir());
const destination=path.join(directory,'resources','providers');await fs.mkdir(destination,{recursive:true});await fs.writeFile(path.join(destination,'ets2la_plugin.dll'),providerBytes);await fs.copyFile(path.resolve(__dirname,'../third_party/ets2la-provider/LICENSE'),path.join(destination,'LICENSE'));
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
}

console.log(paths.join('\n'));
})().catch(e=>{console.error(e.message);process.exitCode=1;});
2 changes: 1 addition & 1 deletion ats-dualsense/desktop/policy.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ const ORIGIN='haulsense://app';
function allowedURL(value){try{const u=new URL(value);return u.protocol==='haulsense:'&&u.hostname==='app'&&!u.username&&!u.password&&!u.port;}catch{return false;}}
function allowedPath(path,method='GET'){
if(method==='POST')return path==='/api/config';
return method==='GET'&&(['/','/hud','/navigation.js','/scene.js','/routing-worker.js','/dashboard.js','/hud.js','/persistence.js','/jobs.js','/api/state','/api/config','/api/route','/api/signals','/api/jobs','/api/map'].includes(path)||/^\/api\/jobs\/\d{1,24}$/.test(path));
return method==='GET'&&(['/','/hud','/navigation.js','/scene.js','/routing-worker.js','/dashboard.js','/hud.js','/persistence.js','/jobs.js','/api/state','/api/config','/api/route','/api/signals','/api/jobs','/api/map','/api/map-status'].includes(path)||/^\/api\/jobs\/\d{1,24}$/.test(path));
}
module.exports={ORIGIN,allowedURL,allowedPath};
Loading
Loading