# HG changeset patch # User nemo # Date 1505154538 14400 # Node ID a675a94b5cc1e246137d810ba2674ac7f73f55bb # Parent 89423b1db3297b89ffe323078fbd0ad30ef6fcb7 Totally untested. Trying to ensure scripts loaded more or less match. diff -r 89423b1db329 -r a675a94b5cc1 hedgewars/uScript.pas --- a/hedgewars/uScript.pas Tue Sep 05 21:15:25 2017 +0200 +++ b/hedgewars/uScript.pas Mon Sep 11 14:28:58 2017 -0400 @@ -2995,12 +2995,40 @@ // custom script loader via physfs, passed to lua_load const BUFSIZE = 1024; +var inComment: boolean; +var lastChar: char; +// ⭒⭐⭒✨⭐⭒✨⭐☆✨⭐✨✧✨☆✨✧✨☆⭒✨☆⭐⭒☆✧✨⭒✨⭐✧⭒☆⭒✧☆✨✧⭐☆✨☆✧⭒✨✧⭒☆⭐☆✧ +function ScriptReader(L: Plua_State; f: PFSFile; sz: Psize_t) : PChar; Cdecl; +var mybuf: PChar; + i: LongInt; +begin + mybuf := physfsReader(L, f, sz); + if (mybuf <> nil) and (sz^ > 0) then + begin + for i:= 0 to sz^-1 do + begin + if (lastChar = '-') and (mybuf[i] = '-') then + inComment := true + // gonna add any non-magic whitespace and skip - just to make comment avoidance easier + else if not inComment and (byte(mybuf[i]) > $20) and (byte(mybuf[i]) < $7F) and (mybuf[i]<>'-') then + AddRandomness(byte(mybuf[i])); + lastChar := mybuf[i]; + if inComment and ((byte(mybuf[i]) = $0D) or (byte(mybuf[i]) = $0A)) then + inComment := false + end; + end; + ScriptReader:= mybuf +end; +// ⭒⭐⭒✨⭐⭒✨⭐☆✨⭐✨✧✨☆✨✧✨☆⭒✨☆⭐⭒☆✧✨⭒✨⭐✧⭒☆⭒✧☆✨✧⭐☆✨☆✧⭒✨✧⭒☆⭐☆✧ + procedure ScriptLoad(name : shortstring); var ret : LongInt; s : shortstring; f : PFSFile; buf : array[0..Pred(BUFSIZE)] of byte; begin +inComment:= false; +lastChar:= 'X'; s:= cPathz[ptData] + name; if not pfsExists(s) then begin @@ -3015,7 +3043,7 @@ hedgewarsMountPackage(Str2PChar(copy(s, 1, length(s)-4)+'.hwp')); physfsReaderSetBuffer(@buf); -ret:= lua_load(luaState, @physfsReader, f, Str2PChar(s)); +ret:= lua_load(luaState, @ScriptReader, f, Str2PChar(s)); pfsClose(f); if ret <> 0 then