Compare commits

..
2 Commits
Author SHA1 Message Date
Alug 8963e17b83 check if __THROW is defined
Windows does not have it at all, so we gotta check this otherwise compile may fail
2025-08-03 14:40:09 +01:00
Alug feda0bae80 update md5 lib
no real changes, mostly just cleanup and some memory alignment fixes
2025-08-03 00:38:52 +02:00
23 changed files with 471 additions and 786 deletions

No files matched your search

-5
View File
@@ -1,5 +0,0 @@
[submodule "libs/bluajit"]
path = libs/bluajit
url = https://github.com/Indev450/bluajit
[submodule "libs/bluajit/"]
branch = bluajit-install
Submodule libs/bluajit deleted from 14f5b60567.
+1 -23
View File
@@ -64,10 +64,6 @@
# DEBUGMODE=1 - Enable various debugging capabilities.
# Also disables optimizations.
#
# Potentially Unsafe
# ------------------
# HAVE_BLUAJIT=1 - Enable compiling with BluaJIT instead of blua, can have potential bugs
#
# Development flags:
#
# VALGRIND=1 - Enable Valgrind memory debugging support.
@@ -188,14 +184,8 @@ sources+=\
$(call List,Sourcefile)\
$(call List,core/Sourcefile)
ifndef HAVE_BLUAJIT
lualib:=
sources+=\
$(call List,blua/Sourcefile)
else
opts+=-DLUAJIT_INTONLY
lualib:=../libs/bluajit/src/libbluajit.a
endif
depends:=$(basename $(filter %.c %.cpp %.s,$(sources)))
objects:=$(basename $(filter %.c %.cpp %.s %.nas,$(sources)))
@@ -367,15 +357,10 @@ ifdef UPX
endif
# original executable with debugging symbols
$(dbg) : $(objects) $(lualib) | $$(@D)/
$(dbg) : $(objects) | $$(@D)/
$(call Echo,Linking $(@F)...)
$(.)$(LD) -o $@ $^ $(libs)
ifdef HAVE_BLUAJIT
$(lualib) ::
@$(MAKE) -C ../libs/bluajit $(MAKECMDGOALS) CC="$(CC)" CCOPT="$(opts)" LDFLAGS="$(LDFLAGS)"
endif
# disassembly of executable
$(dbg).txt : $(dbg)
$(call Echo,Dumping debugging info...)
@@ -438,13 +423,6 @@ clean :
distclean :
$(call _rm,../bin ../objs ../dep ../make comptime.h)
ifdef HAVE_BLUAJIT
$(call _rm,$(objdir)/buildvm* $(objdir)/minilua* $(objdir)/lj_vm*)
cleanjit:
$(call _rm,$(objdir)/buildvm* $(objdir)/minilua* $(objdir)/lj_vm* $(ALL_HDRGEN) $(LJVMCORE_O) $(ALL_GEN))
endif
info:
ifdef WINDOWSHELL
@REM
+1 -2
View File
@@ -6,8 +6,7 @@ passthru_opts+=\
NOHW NOMD5 NOPOSTPROCESSING\
MOBJCONSISTANCY PACKETDROP ZDEBUG\
HAVE_MINIUPNPC\
HAVE_DISCORDRPC DEVELOP\
HAVE_BLUAJIT
HAVE_DISCORDRPC DEVELOP
# build with debugging information
ifdef DEBUGMODE
-5
View File
@@ -26,11 +26,6 @@ ifeq (${DEDICATED},1)
EXENAME?=lsrb2kartd
endif
ifdef HAVE_BLUAJIT
libs+=-L../libs/bluajit/src/ -l:libbluajit.a
opts+=-I../libs/bluajit/src/
endif
# In common usage.
ifdef LINUX
libs+=-lrt
-5
View File
@@ -69,11 +69,6 @@ LIBOPENMPT_opts:=-I$(lib)/inc
LIBOPENMPT_libs:=-L$(lib)/lib/$(x86) -lopenmpt
$(eval $(call _set,LIBOPENMPT))
lib:=../libs/bluajit
BLUAJIT_opts:=-I$(lib)/src
BLUAJIT_libs:=-L$(lib)/lib/$(x86) -lbluajit
$(eval $(call _set,BLUAJIT))
lib:=../libs/SDL2_mixer/$(mingw)
ifdef SDL
+70 -5
View File
@@ -17,14 +17,27 @@
#include "lauxlib.h"
#include "lualib.h"
#include "../i_system.h"
#include "../doomdef.h"
#include "../d_main.h"
#include "../m_misc.h"
#define IO_INPUT 1
#define IO_OUTPUT 2
#define FILELIMIT 1024*1024 // Size limit for reading/writing files
static const char *const fnames[] = {"input", "output"};
static const char *whitelist[] = { // Allow scripters to write files of these types to SRB2's folder
".txt",
".sav2",
".cfg",
".png",
".bmp"
};
static int pushresult (lua_State *L, int i, const char *filename) {
@@ -146,12 +159,59 @@ static int io_tostring (lua_State *L) {
return 1;
}
static int StartsWith(const char *a, const char *b) // this is wolfs being lazy yet again
{
if(strncmp(a, b, strlen(b)) == 0) return 1;
return 0;
}
static int io_open (lua_State *L) {
const char *filename = luaL_checkstring(L, 1);
const char *mode = luaL_optstring(L, 2, "r");
FILE **pf = newfile(L);
*pf = fopen(filename, mode);
return (*pf == NULL) ? pushresult(L, 0, filename) : 1;
FILE **pf;
const char *filename = luaL_checkstring(L, 1);
int pass = 0;
size_t i;
int length = strlen(filename);
char *splitter, *forward, *backward;
char *destFilename;
const char *mode = luaL_optstring(L, 2, "r");
for (i = 0; i < (sizeof (whitelist) / sizeof(const char *)); i++)
{
if (!stricmp(&filename[length - strlen(whitelist[i])], whitelist[i]))
{
pass = 1;
break;
}
}
if (l_unlikely(strstr(filename, "..") || strchr(filename, ':') || StartsWith(filename, "\\")
|| StartsWith(filename, "/") || !pass))
{
luaL_error(L,"access denied to %s", filename);
return pushresult(L,0,filename);
}
destFilename = va("%s"PATHSEP"luafiles"PATHSEP"%s", srb2home, filename);
// Make directories as needed
splitter = destFilename;
forward = strchr(splitter, '/');
backward = strchr(splitter, '\\');
while ((splitter = (forward && backward) ? min(forward, backward) : (forward ?: backward)))
{
*splitter = 0;
I_mkdir(destFilename, 0755);
*splitter = '/';
splitter++;
forward = strchr(splitter, '/');
backward = strchr(splitter, '\\');
}
pf = newfile(L);
*pf = fopen(destFilename, mode);
return (*pf == NULL) ? pushresult(L, 0, filename) : 1;
}
@@ -394,6 +454,11 @@ static int g_write (lua_State *L, FILE *f, int arg) {
else {
size_t l;
const char *s = luaL_checklstring(L, arg, &l);
if (l_unlikely(ftell(f) + l > FILELIMIT))
{
luaL_error(L,"write limit bypassed in file. Changes have been discarded.");
break;
}
status = status && (fwrite(s, sizeof(char), l, f) == l);
}
}
-4
View File
@@ -777,10 +777,6 @@ void D_RegisterServerCommands(void)
CV_RegisterVar(&cv_netdemosyncquality);
CV_RegisterVar(&cv_maxdemosize);
CV_RegisterVar(&cv_demochangemap);
#ifdef HAVE_BLUAJIT
CV_RegisterVar(&cv_luajit);
#endif
}
// =========================================================================
+36 -72
View File
@@ -1138,33 +1138,6 @@ static boolean K_UseColorSpeedo(int speedostyle)
}
}
enum
{
GAUGE_DEFAULT = 1,
GAUGE_SMALL,
GAUGE_BIGNUM,
GAUGE_NUMONLY,
GAUGE_EXTRA,
};
static SINT8 K_GetDriftgaugeStyle(void)
{
if (driftgaugegfx)
{
if (cv_driftgaugestyle.value == 1)
return GAUGE_DEFAULT;
else if (cv_driftgaugestyle.value == 2)
return GAUGE_SMALL;
else if (cv_driftgaugestyle.value == 3)
return GAUGE_BIGNUM;
else if (cv_driftgaugestyle.value == 5 && xtra_speedo3)
return GAUGE_EXTRA;
}
// Fallback
return GAUGE_NUMONLY; // (cv_driftgaugestyle.value == 4)
}
static boolean K_IsHighResolution(void)
{
return (vid.width >= 640 && vid.height >= 400);
@@ -1726,7 +1699,7 @@ static void K_drawKartItem(void)
switch (stplyr->kartstuff[k_itemblinkmode])
{
case 2:
localcolor = K_RainbowColor();
localcolor = (UINT8)(1 + (leveltime % (MAXSKINCOLORS-1)));
break;
case 1:
localcolor = SKINCOLOR_RED;
@@ -3176,7 +3149,7 @@ static void K_drawDriftGauge(void)
fixed_t basex, basey;
const int dup = vid.dupx;
int i;
UINT8 *colormap = NULL;
UINT8 *cmap;
static const UINT8 driftcolors[3][4] = {
{0, 0, 10, 16}, // no drift
@@ -3222,21 +3195,23 @@ skipcrap:
const INT32 driftcharge = min(driftval*4, stplyr->kartstuff[k_driftcharge]);
const INT32 driftlevel = min(driftcharge / driftval, 2);
const INT32 drifttrans = ((cv_driftgaugetrans.value) ? V_LocalTransFlag() : 0);
const SINT8 gaugestyle = K_GetDriftgaugeStyle();
basex = pos.x>>FRACBITS;
basey = pos.y>>FRACBITS;
switch (gaugestyle)
switch (cv_driftgaugestyle.value)
{
case GAUGE_DEFAULT:
case GAUGE_SMALL:
case GAUGE_EXTRA:
case GAUGE_BIGNUM:
case 1:
case 2:
case 3:
case 5:
{
patch_t *driftpatch = NULL;
if (!driftgaugegfx)
break;
if (gaugestyle == GAUGE_DEFAULT || gaugestyle == GAUGE_BIGNUM || gaugestyle == GAUGE_EXTRA)
const boolean usescaledpatch = (cv_driftgaugestyle.value == 5 && xtra_speedo3);
if (cv_driftgaugestyle.value == 1 || cv_driftgaugestyle.value == 3 || usescaledpatch)
{
barx = basex - dup*23;
BAR_WIDTH = dup*47;
@@ -3249,44 +3224,40 @@ skipcrap:
bary = basey - dup*2;
if (gaugestyle == GAUGE_EXTRA) // i hate hud code i hate hud code i hate hud code i hate hud code i hate hud code.....
if (usescaledpatch) // i hate hud code i hate hud code i hate hud code i hate hud code i hate hud code.....
{
if (K_UseColorSpeedo(SPEEDO_EXTRA3)) // We reuse the extra speedometer patch hence this check
if (K_UseColorSpeedo(SPEEDO_EXTRA3)) // Colourized hud
{
colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE);
driftpatch = skp_smallstickerclr3;
UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE);
V_DrawStretchyFixedPatch((basex - dup*30)<<FRACBITS, ((basey<<FRACBITS) - FixedMul(dup<<FRACBITS, 21*FRACUNIT/10)), XTRA3PSCALE, XTRA3VSCALE, V_NOSCALESTART|V_OFFSET|drifttrans, skp_smallstickerclr3, colormap, 0);
}
else
driftpatch = skp_smallsticker3;
V_DrawStretchyFixedPatch((basex - dup*30)<<FRACBITS, ((basey<<FRACBITS) - FixedMul(dup<<FRACBITS, 21*FRACUNIT/10)), XTRA3PSCALE, XTRA3VSCALE, V_NOSCALESTART|V_OFFSET|drifttrans, driftpatch, colormap, 0);
V_DrawStretchyFixedPatch((basex - dup*30)<<FRACBITS, ((basey<<FRACBITS) - FixedMul(dup<<FRACBITS, 21*FRACUNIT/10)), XTRA3PSCALE, XTRA3VSCALE, V_NOSCALESTART|V_OFFSET|drifttrans, skp_smallsticker3, NULL, 0);
}
else
{
if (K_UseColorHud()) // Colourized hud
{
colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE);
driftpatch = (gaugestyle == GAUGE_SMALL ? driftgaugesmallcolor : driftgaugecolor);
UINT8 *colormap = R_GetTranslationColormap(TC_DEFAULT, K_GetHudColor(), GTC_CACHE);
V_DrawMappedPatch(cv_driftgaugestyle.value == 2 ? basex + dup*11 : basex, basey, V_NOSCALESTART|V_OFFSET|drifttrans, cv_driftgaugestyle.value == 2 ? driftgaugesmallcolor : driftgaugecolor, colormap);
}
else
driftpatch = (gaugestyle == GAUGE_SMALL ? driftgaugesmall : driftgauge);
V_DrawMappedPatch(gaugestyle == GAUGE_SMALL ? basex + dup*11 : basex, basey, V_NOSCALESTART|V_OFFSET|drifttrans, driftpatch, colormap);
V_DrawMappedPatch(cv_driftgaugestyle.value == 2 ? basex + dup*11 : basex, basey, V_NOSCALESTART|V_OFFSET|drifttrans, cv_driftgaugestyle.value == 2 ? driftgaugesmall : driftgauge, NULL);
}
if (driftcharge >= driftval*4) // rainbow sparks
{
colormap = R_GetTranslationColormap(TC_RAINBOW, K_RainbowColor(), GTC_CACHE);
cmap = R_GetTranslationColormap(TC_RAINBOW, 1 + leveltime % (MAXSKINCOLORS-1),GTC_CACHE);
for (i = 0; i < 4; i++)
V_DrawFill(barx, bary+dup*1+dup*i, BAR_WIDTH, dup, (driftrainbow[min((leveltime % 18) + 1, 17)] + i*2) | V_NOSCALESTART|drifttrans);
V_DrawFill(barx, bary+dup*1+dup*i, BAR_WIDTH, dup, (driftrainbow[min((leveltime % 18) + 1, 18 - 1)] + i*2) | V_NOSCALESTART|drifttrans);
}
else // none/blue/red
{
const INT32 limit = (driftval * (driftcharge >= driftval*2 ? 2 : 1));
const INT32 width = ((driftcharge - (driftcharge >= driftval ? limit : 0)) * BAR_WIDTH) / limit;
colormap = R_GetTranslationColormap(TC_RAINBOW, driftskins[driftlevel], GTC_CACHE);
cmap = R_GetTranslationColormap(TC_RAINBOW, driftskins[driftlevel],GTC_CACHE);
for (i = 0; i < 4; i++)
{
@@ -3298,20 +3269,20 @@ skipcrap:
}
// right, also draw a cool number
if (gaugestyle == GAUGE_BIGNUM)
V_DrawPaddedTallColorNum(basex + (dup*32), basey, V_NOSCALESTART|V_OFFSET|drifttrans, driftcharge*100 / driftval, 3, colormap);
if (cv_driftgaugestyle.value == 3)
V_DrawPaddedTallColorNum(basex + (dup*32), basey, V_NOSCALESTART|V_OFFSET|drifttrans, driftcharge*100 / driftval, 3, cmap);
else
V_DrawPingNum((gaugestyle == GAUGE_SMALL ? basex + (dup*22) : basex + (dup*32)), basey, V_NOSCALESTART|V_OFFSET|drifttrans, driftcharge*100 / driftval, colormap);
V_DrawPingNum(cv_driftgaugestyle.value == 2 ? basex + (dup*22) : basex + (dup*32), basey, V_NOSCALESTART|V_OFFSET|drifttrans, driftcharge*100 / driftval, cmap);
}
break;
case GAUGE_NUMONLY:
case 4:
{
if (driftcharge >= driftval*4)
colormap = R_GetTranslationColormap(TC_RAINBOW, K_RainbowColor(), GTC_CACHE);
cmap = R_GetTranslationColormap(TC_RAINBOW, 1 + leveltime % (MAXSKINCOLORS-1),GTC_CACHE);
else
colormap = R_GetTranslationColormap(TC_RAINBOW, driftskins[driftlevel], GTC_CACHE);
cmap = R_GetTranslationColormap(TC_RAINBOW, driftskins[driftlevel],GTC_CACHE);
V_DrawPaddedTallColorNum(basex + (dup*16), basey, V_NOSCALESTART|V_OFFSET|drifttrans, driftcharge*100 / driftval, 3, colormap);
V_DrawPaddedTallColorNum(basex + (dup*16), basey, V_NOSCALESTART|V_OFFSET|drifttrans, driftcharge*100 / driftval, 3, cmap);
}
break;
default:
@@ -3372,7 +3343,6 @@ static void K_drawKartWanted(void)
{
basex = WANT_X;
basey = WANT_Y;
if (splitscreen == 2)
{
basey += 16; // slight adjust for 3P
@@ -4122,23 +4092,17 @@ static void K_drawKartFirstPerson(void)
x -= xoffs;
else
x += xoffs;
if (!splitscreen)
y += yoffs;
}
const INT32 driftcharge = stplyr->kartstuff[k_driftcharge];
// drift sparks!
if ((leveltime & 1) && driftcharge)
{
if (driftcharge >= dsthree)
colmap = R_GetTranslationColormap(TC_RAINBOW, K_RainbowColor(), GTC_CACHE);
else if (driftcharge >= dstwo)
colmap = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_KETCHUP, GTC_CACHE);
else if (driftcharge >= dsone)
colmap = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_SAPPHIRE, GTC_CACHE);
}
if ((leveltime & 1) && (stplyr->kartstuff[k_driftcharge] >= dsthree))
colmap = R_GetTranslationColormap(TC_RAINBOW, (UINT8)(1 + (leveltime % (MAXSKINCOLORS-1))), GTC_CACHE);
else if ((leveltime & 1) && (stplyr->kartstuff[k_driftcharge] >= dstwo))
colmap = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_KETCHUP, GTC_CACHE);
else if ((leveltime & 1) && (stplyr->kartstuff[k_driftcharge] >= dsone))
colmap = R_GetTranslationColormap(TC_RAINBOW, SKINCOLOR_SAPPHIRE, GTC_CACHE);
else
#endif
// invincibility/grow/shrink!
+2 -21
View File
@@ -484,15 +484,6 @@ UINT8 colortranslations[MAXTRANSLATIONS][16] = {
{120, 120, 96, 96, 97, 98, 98, 99, 81, 81, 69, 71, 73, 75, 77, 79}, // SKINCOLOR_CSUPER5
};
//
// Gives you a color to use for rainbow effects (like invincibility).
// Return: Skincolor value.
//
UINT8 K_RainbowColor(void)
{
return (UINT8)(1 + (leveltime % (MAXSKINCOLORS-1)));
}
// Define for getting accurate color brightness readings according to how the human eye sees them.
// https://en.wikipedia.org/wiki/Relative_luminance
// 0.2126 to red
@@ -654,46 +645,36 @@ UINT8 K_GetKartColorByName(const char *name)
return 0;
}
//
// returns the players skinnumber
// accounts for localskins
//
INT32 K_GetSkinNum(player_t *player)
{
return player->localskin ? (player->localskin - 1) : player->skin;
}
//
// returns the mobj skinnumber
// accounts for localskins
//
INT32 K_GetMobjSkinNum(const skin_t *skin, boolean local)
{
return skin - K_GetSkinArray(local);
}
//
// returns the players skinnumber
// accounts for localskins
//
skin_t *K_GetMobjSkin(const mobj_t *mobj)
{
return mobj->localskin ? mobj->localskin : mobj->skin;
}
//
// returns the skin array to use
// accounts for localskins
//
skin_t *K_GetSkinArray(boolean local)
{
return local ? localskins : skins;
}
//
// returns the players skin
// accounts for localskins
//
skin_t *K_GetPlayerSkin(player_t *player)
{
return &K_GetSkinArray(player->skinlocal)[K_GetSkinNum(player)];
@@ -3103,7 +3084,7 @@ static UINT16 K_DriftSparkColor(player_t *player, INT32 charge)
if (charge >= K_GetKartDriftSparkValue(player)*4)
{
color = K_RainbowColor();
color = (UINT8)(1 + (leveltime % (MAXSKINCOLORS-1)));
}
else if (charge >= K_GetKartDriftSparkValue(player)*2)
{
@@ -5390,7 +5371,7 @@ static UINT8 K_GetSpeedLineColor(player_t *player, boolean colorSpeed)
else if (player->kartstuff[k_driftboost] <= 50)
speedcolor = SKINCOLOR_RASPBERRY;
else if (player->kartstuff[k_driftboost] <= 125)
speedcolor = K_RainbowColor();
speedcolor = (UINT8)(1 + (leveltime % (MAXSKINCOLORS-1)));
if (cv_coloredspeedlines.value == 2)
speedcolor = (leveltime & 1) ? playercolor : speedcolor;
-1
View File
@@ -19,7 +19,6 @@ extern "C" {
extern UINT8 colortranslations[MAXTRANSLATIONS][16];
extern const char *KartColor_Names[MAXSKINCOLORS];
extern const UINT8 KartColor_Opposite[MAXSKINCOLORS*2];
UINT8 K_RainbowColor(void);
void K_RainbowColormap(UINT8 *dest_colormap, UINT8 skincolor);
void K_GenerateKartColormap(UINT8 *dest_colormap, INT32 skinnum, UINT8 color, boolean local);
UINT8 K_GetKartColorByName(const char *name);
-139
View File
@@ -42,123 +42,6 @@ boolean luaL_checkboolean(lua_State *L, int narg) {
return lua_toboolean(L, narg);
}
static int ref_open, ref_iowrite, ref_fwrite; // original versions of io functions
#define FILELIMIT 1024*1024 // Size limit for reading/writing files
static const char *whitelist[] = { // Allow scripters to write files of these types to SRB2's folder
".txt",
".sav2",
".cfg",
".png",
".bmp"
};
static int StartsWith(const char *a, const char *b) // this is wolfs being lazy yet again
{
if(strncmp(a, b, strlen(b)) == 0) return 1;
return 0;
};
// Wrapper for opening files
static int lib_open(lua_State *L)
{
const char *filename = luaL_checkstring(L, 1);
int pass = 0;
size_t i;
int length = strlen(filename);
char *splitter, *forward, *backward;
char *destFilename;
for (i = 0; i < (sizeof (whitelist) / sizeof(const char *)); i++)
{
if (!stricmp(&filename[length - strlen(whitelist[i])], whitelist[i]))
{
pass = 1;
break;
}
}
if (strstr(filename, "..") || strchr(filename, ':') || StartsWith(filename, "\\")
|| StartsWith(filename, "/") || !pass)
{
return luaL_error(L,"access denied to %s", filename);
}
destFilename = va("%s"PATHSEP"luafiles"PATHSEP"%s", srb2home, filename);
// Make directories as needed
splitter = destFilename;
forward = strchr(splitter, '/');
backward = strchr(splitter, '\\');
while ((splitter = (forward && backward) ? min(forward, backward) : (forward ?: backward)))
{
*splitter = 0;
I_mkdir(destFilename, 0755);
*splitter = '/';
splitter++;
forward = strchr(splitter, '/');
backward = strchr(splitter, '\\');
}
// replace the filename string
lua_pushstring(L, destFilename);
lua_replace(L, 1);
// now call the real io.open
lua_rawgeti(L, LUA_REGISTRYINDEX, ref_open);
lua_insert(L, 1);
lua_call(L, lua_gettop(L)-1, LUA_MULTRET);
return lua_gettop(L);
}
// Wrapper for writing to files
static int lib_write(lua_State *L, int arg)
{
int top = lua_gettop(L);
boolean error = true;
size_t len, size = 0;
int ogref = ref_iowrite;
if (arg != 1) {
ogref = ref_fwrite;
FILE *fp = *(FILE **)luaL_checkudata(L, 1, LUA_FILEHANDLE);
if (fp == NULL) goto call; // real file:write will throw
size = ftell(fp);
}
// check the size of each argument. if there's too much data,
// cut off the stack and print an error
for (; arg <= top; arg++) {
if (lua_tolstring(L, arg, &len) == NULL) goto call;
if ((size += len) > FILELIMIT) {
// oops! too many bytes!
lua_settop(L, arg-1);
goto call;
}
}
error = false;
call:
lua_rawgeti(L, LUA_REGISTRYINDEX, ogref);
lua_insert(L, 1);
lua_call(L, lua_gettop(L)-1, LUA_MULTRET);
if (error)
return luaL_error(L,"write limit bypassed in file. Changes have been discarded.");
return lua_gettop(L);
}
static int lib_write_f(lua_State *L)
{
return lib_write(L, 2);
}
static int lib_write_io(lua_State *L)
{
return lib_write(L, 1);
}
// String concatination
static int lib_concat(lua_State *L)
{
@@ -3465,28 +3348,6 @@ int LUA_BaseLib(lua_State *L)
lua_setfield(L,-2,"__add"); // ... store it as mathematical addition
lua_pop(L, 2); // pop metatable and dummy string
// replaces an existing function with another,
// saving the original as a reference
#define REPLACE(name, func, ref) \
lua_pushliteral(L, name); \
lua_rawget(L, -2); \
ref = luaL_ref(L, LUA_REGISTRYINDEX); \
lua_pushliteral(L, name); \
lua_pushcclosure(L, &func, 0); \
lua_rawset(L, -3);
// replace io.open
lua_getglobal(L, "io");
REPLACE("open", lib_open, ref_open)
REPLACE("write", lib_write_io, ref_iowrite)
lua_pop(L, 1);
// replace file:write
luaL_getmetatable(L, LUA_FILEHANDLE);
REPLACE("write", lib_write_f, ref_fwrite)
lua_pop(L, 1);
#undef REPLACE
lua_newtable(L);
lua_setfield(L, LUA_REGISTRYINDEX, LREG_EXTVARS);
+27 -41
View File
@@ -324,14 +324,13 @@ static int lib_cvRegisterVar(lua_State *L)
const char* category = NULL;
const char* menu_name = NULL;
boolean hasfunc = false;
int funcref = 0;
luaL_checktype(L, 1, LUA_TTABLE);
lua_settop(L, 1); // Clear out all other possible arguments, leaving only the first one.
NOHUD
cvar = ZZ_Calloc(sizeof(consvar_t));
LUA_PushUserdata(L, cvar, META_CVAR);
cvar = lua_newuserdata(L, sizeof(consvar_t));
luaL_getmetatable(L, META_CVAR);
lua_setmetatable(L, -2);
#define FIELDERROR(f, e) luaL_error(L, "bad value for " LUA_QL(f) " in table passed to " LUA_QL("CV_RegisterVar") " (%s)", e);
#define TYPEERROR(f, t) FIELDERROR(f, va("%s expected, got %s", lua_typename(L, t), luaL_typename(L, -1)))
@@ -405,38 +404,27 @@ static int lib_cvRegisterVar(lua_State *L)
cvpv[i].value = 0;
cvpv[i].strvalue = NULL;
cvar->PossibleValue = cvpv;
// MIN and MAX are expected to be at hardcoded indices apparently
// so, sigh, here goes...
#define SWAP(from, to) \
INT32 val = cvpv[from].value; \
const char *strval = cvpv[from].strvalue; \
cvpv[from].value = cvpv[to].value; \
cvpv[from].strvalue = cvpv[to].strvalue; \
cvpv[to].value = val; \
cvpv[to].strvalue = strval;
for (int j = 0; j < i; j++) {
if (!strcmp(cvpv[j].strvalue, "MIN") && j != 0) {
SWAP(j, 0)
} else if (!strcmp(cvpv[j].strvalue, "MAX") && j != 1) {
SWAP(j, 1)
}
}
} else
FIELDERROR("PossibleValue", va("%s or CV_PossibleValue_t expected, got %s", lua_typename(L, LUA_TTABLE), luaL_typename(L, -1)))
} else if (i == 5 || (k && fasticmp(k, "func"))) {
if (!lua_isfunction(L, 4))
TYPEERROR("func", LUA_TFUNCTION)
if (hasfunc)
luaL_unref(L, LUA_REGISTRYINDEX, funcref); // real clever, huh?
funcref = luaL_ref(L, LUA_REGISTRYINDEX);
hasfunc = true;
continue;
lua_getfield(L, LUA_REGISTRYINDEX, "CV_OnChange");
I_Assert(lua_istable(L, 5));
lua_pushvalue(L, 4);
lua_setfield(L, 5, cvar->name);
lua_pop(L, 1);
cvar->func = Lua_OnChange;
}
else if (i == 6 || (k && fasticmp(k, "category")))
else if (((i == 5 && !(cvar->flags & CV_CALL))
|| (cvar->flags & CV_CALL && i == 6))
|| (k && fasticmp(k, "category")))
{
category = lua_isnoneornil(L, 4) ? NULL : lua_tostring(L, 4);
}
else if (i == 7 || (k && fasticmp(k, "menuname")))
else if (((i == 6 && !(cvar->flags & CV_CALL))
|| (cvar->flags & CV_CALL && i == 7))
|| (k && fasticmp(k, "menuname")))
{
menu_name = lua_isnoneornil(L, 4) ? NULL : lua_tostring(L, 4);
}
@@ -446,16 +434,6 @@ static int lib_cvRegisterVar(lua_State *L)
#undef TYPEERROR
// stack: cvar table, cvar userdata
if (hasfunc) {
lua_getfield(L, LUA_REGISTRYINDEX, "CV_OnChange");
I_Assert(lua_istable(L, 3));
lua_rawgeti(L, LUA_REGISTRYINDEX, funcref);
lua_setfield(L, 3, cvar->name);
lua_pop(L, 1);
cvar->func = Lua_OnChange;
luaL_unref(L, LUA_REGISTRYINDEX, funcref);
}
lua_getfield(L, LUA_REGISTRYINDEX, "CV_Vars");
I_Assert(lua_istable(L, 3));
@@ -501,7 +479,15 @@ static int lib_cvFindVar(lua_State *L)
consvar_t *cv;
if (( cv = CV_FindVar(luaL_checkstring(L,1)) ))
{
LUA_PushUserdata(L, cv, META_CVAR);
lua_settop(L,1);/* We only want one argument in the stack. */
lua_pushlightuserdata(L, cv);/* Now the second value on stack. */
luaL_getmetatable(L, META_CVAR);
/*
The metatable is the last value on the stack, so this
applies it to the second value, which is the cvar.
*/
lua_setmetatable(L,2);
lua_pushvalue(L,2);
return 1;
}
else
@@ -514,7 +500,7 @@ static int CVarSetFunction
void (*Set)(consvar_t *, const char *),
void (*SetValue)(consvar_t *, INT32)
){
consvar_t *cvar = *((consvar_t **)luaL_checkudata(L, 1, META_CVAR));
consvar_t *cvar = (consvar_t *)luaL_checkudata(L, 1, META_CVAR);
switch (lua_type(L, 2))
{
@@ -543,7 +529,7 @@ static int lib_cvStealthSet(lua_State *L)
static int lib_cvAddValue(lua_State *L)
{
consvar_t *cvar = *((consvar_t **)luaL_checkudata(L, 1, META_CVAR));
consvar_t *cvar = (consvar_t *)luaL_checkudata(L, 1, META_CVAR);
CV_AddValue(cvar, (INT32)luaL_checknumber(L, 2));
return 0;
}
@@ -618,7 +604,7 @@ static int cvar_fields_ref = LUA_NOREF;
static int cvar_get(lua_State *L)
{
consvar_t *cvar = *((consvar_t **)luaL_checkudata(L, 1, META_CVAR));
consvar_t *cvar = (consvar_t *)luaL_checkudata(L, 1, META_CVAR);
enum cvar_e field = Lua_optoption(L, 2, -1, cvar_fields_ref);
switch (field)
+1 -12
View File
@@ -12,11 +12,7 @@
#include "lua_hudlib_drawlist.h"
#include "lua_hud.h"
#ifndef HAVE_BLUAJIT
#include "blua/lstate.h" // shhhhhh
#else
#include "lua_script.h"
#endif
#include "lua_libs.h"
#include <string.h>
@@ -332,15 +328,8 @@ static UINT64 GetItemId(void)
if (!hud_interpolate)
return 0;
#ifndef HAVE_BLUAJIT
UINT64 id = (uintptr_t)gL->savedpc;
#else
// he who controls the JIT controls the API
const void *p = lua_getpc(gL, 1);
UINT64 id = (uintptr_t)p;
#endif
// leave bits 0 and 1 free for the string mode
id = (id << 32) | (hud_interpcounter << 10) | (hud_interptag << 2);
UINT64 id = ((UINT64)(uintptr_t)gL->savedpc << 32) | (hud_interpcounter << 10) | (hud_interptag << 2);
if (hud_interplatch)
{
-5
View File
@@ -11,12 +11,7 @@
/// \brief libraries for Lua scripting
#include "doomtype.h"
#ifndef HAVE_BLUAJIT
#include "blua/lua.h"
#else
#include <lua.h>
#endif
extern lua_State *gL;
-50
View File
@@ -35,14 +35,6 @@
#include "doomstat.h"
#ifdef HAVE_BLUAJIT
#include "d_main.h"
#include "i_system.h"
static void LuaJit_OnChange(void);
static void print_jit_status(boolean verbose);
consvar_t cv_luajit = {"luajit", "On", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, LuaJit_OnChange, 0, NULL, NULL, 0, 0, NULL};
#endif
lua_State *gL = NULL;
// Mathlib global state
@@ -69,21 +61,6 @@ static lua_CFunction liblist[] = {
NULL
};
#ifdef HAVE_BLUAJIT
static void LuaJit_OnChange(void)
{
if (!gL)
LUA_ClearState();
lua_getfield(gL, LUA_REGISTRYINDEX, "_LOADED");
lua_getfield(gL, -1, "jit");
lua_remove(gL, -2);
lua_getfield(gL, -1, cv_luajit.value ? "on" : "off");
lua_remove(gL, -2);
lua_call(gL, 0, 0);
print_jit_status(false);
}
#endif
// Lua asks for memory using this.
static void *LUA_Alloc(void *ud, void *ptr, size_t osize, size_t nsize)
{
@@ -208,29 +185,6 @@ static int noglobals(lua_State *L)
return luaL_error(L, "Implicit global " LUA_QS " prevented. Create a local variable instead.", csname);
}
#ifdef HAVE_BLUAJIT
// print all the ISA extensions because it looks cool!
// absolutely not stolen from luajit.c
static void print_jit_status(boolean verbose)
{
int n;
const char *s;
lua_getfield(gL, LUA_REGISTRYINDEX, "_LOADED");
lua_getfield(gL, -1, "jit"); /* Get jit.* module table. */
lua_remove(gL, -2);
lua_getfield(gL, -1, "status");
lua_remove(gL, -2);
n = lua_gettop(gL);
lua_call(gL, 0, LUA_MULTRET);
CONS_Printf(lua_toboolean(gL, n) ? "JIT: ON" : "JIT: OFF");
if (verbose)
for (n++; (s = lua_tostring(gL, n)); n++)
CONS_Printf(" %s", s);
CONS_Printf("\n");
lua_settop(gL, 0); /* clear stack */
}
#endif
// Clear and create a new Lua state, laddo!
// There's SCRIPTIN to be had!
void LUA_ClearState(void)
@@ -273,10 +227,6 @@ void LUA_ClearState(void)
// lua state is ready!
gL = L;
#ifdef HAVE_BLUAJIT
print_jit_status(true);
#endif
}
#ifdef _DEBUG
-10
View File
@@ -18,19 +18,9 @@
#include "d_player.h"
#include "p_saveg.h"
#ifndef HAVE_BLUAJIT
#include "blua/lua.h"
#include "blua/lualib.h"
#include "blua/lauxlib.h"
#else
#include "command.h"
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#define abs_index(L, i) ((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : \
lua_gettop(L) + (i) + 1)
extern consvar_t cv_luajit;
#endif
#define lua_optboolean(L, i) (!lua_isnoneornil(L, i) && lua_toboolean(L, i))
#define lua_opttrueboolean(L, i) (lua_isnoneornil(L, i) || lua_toboolean(L, i))
+273 -256
View File
@@ -1,6 +1,6 @@
// SONIC ROBO BLAST 2
//-----------------------------------------------------------------------------
// Copyright (C) 1995-1996 by the Free Software Foundation, Inc.
// Copyright (C) 1995-2025 by the Free Software Foundation, Inc.
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.
@@ -33,7 +33,7 @@
#include "endian.h"
#if defined (SRB2_BIG_ENDIAN)
#define SWAP(n) \
#define SWAP(n) \
(((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
#else
#define SWAP(n) (n)
@@ -46,27 +46,31 @@ static const unsigned char fillbuf[64] = { 0x80, 0 /*, 0, 0, ... */ };
/* Structure to save state of computation between the single steps. */
struct md5_ctx
{
md5_uint32 A;
md5_uint32 B;
md5_uint32 C;
md5_uint32 D;
md5_uint32 A;
md5_uint32 B;
md5_uint32 C;
md5_uint32 D;
md5_uint32 total[2];
md5_uint32 buflen;
char buffer[128];
md5_uint32 total[2];
md5_uint32 buflen;
union
{
char buffer[128];
md5_uint32 buffer32[32];
};
};
/* Initialize structure containing state of computation.
(RFC 1321, 3.3: Step 3) */
static void md5_init_ctx (struct md5_ctx *ctx)
static void md5_init_ctx(struct md5_ctx *ctx)
{
ctx->A = 0x67452301;
ctx->B = 0xefcdab89;
ctx->C = 0x98badcfe;
ctx->D = 0x10325476;
ctx->A = 0x67452301;
ctx->B = 0xefcdab89;
ctx->C = 0x98badcfe;
ctx->D = 0x10325476;
ctx->total[0] = ctx->total[1] = 0;
ctx->buflen = 0;
ctx->total[0] = ctx->total[1] = 0;
ctx->buflen = 0;
}
/* Put result from CTX in first 16 bytes following RESBUF. The result
@@ -74,14 +78,14 @@ static void md5_init_ctx (struct md5_ctx *ctx)
IMPORTANT: On some systems it is required that RESBUF is correctly
aligned for a 32 bits value. */
static void *md5_read_ctx (const struct md5_ctx *ctx, void *resbuf)
static void *md5_read_ctx(const struct md5_ctx *ctx, void *resbuf)
{
((md5_uint32 *) resbuf)[0] = SWAP (ctx->A);
((md5_uint32 *) resbuf)[1] = SWAP (ctx->B);
((md5_uint32 *) resbuf)[2] = SWAP (ctx->C);
((md5_uint32 *) resbuf)[3] = SWAP (ctx->D);
((md5_uint32 *) resbuf)[0] = SWAP(ctx->A);
((md5_uint32 *) resbuf)[1] = SWAP(ctx->B);
((md5_uint32 *) resbuf)[2] = SWAP(ctx->C);
((md5_uint32 *) resbuf)[3] = SWAP(ctx->D);
return resbuf;
return resbuf;
}
/* These are the four functions used in the four steps of the MD5 algorithm
@@ -96,200 +100,215 @@ static void *md5_read_ctx (const struct md5_ctx *ctx, void *resbuf)
/* Process LEN bytes of BUFFER, accumulating context into CTX.
It is assumed that LEN % 64 == 0. */
static void md5_process_block (const void *buffer, size_t len, struct md5_ctx *ctx)
static void md5_process_block(const void *buffer, size_t len, struct md5_ctx *ctx)
{
md5_uint32 correct_words[16];
const md5_uint32 *words = buffer;
size_t nwords = len / sizeof (md5_uint32);
const md5_uint32 *endp = words + nwords;
md5_uint32 A = ctx->A;
md5_uint32 B = ctx->B;
md5_uint32 C = ctx->C;
md5_uint32 D = ctx->D;
md5_uint32 correct_words[16];
const md5_uint32 *words = buffer;
size_t nwords = len / sizeof (md5_uint32);
const md5_uint32 *endp = words + nwords;
md5_uint32 A = ctx->A;
md5_uint32 B = ctx->B;
md5_uint32 C = ctx->C;
md5_uint32 D = ctx->D;
md5_uint32 lolen = len;
/* First increment the byte count. RFC 1321 specifies the possible
length of the file up to 2^64 bits. Here we only compute the
number of bytes. Do a double word increment. */
ctx->total[0] = (md5_uint32)(len+ctx->total[0]);
if (ctx->total[0] < len)
++ctx->total[1];
/* First increment the byte count. RFC 1321 specifies the possible
length of the file up to 2^64 bits. Here we only compute the
number of bytes. Do a double word increment. */
ctx->total[0] += lolen;
ctx->total[1] += (len >> 31 >> 1) + (ctx->total[0] < lolen);
/* Process all bytes in the buffer with 64 bytes in each round of
the loop. */
while (words < endp)
{
md5_uint32 *cwp = correct_words;
md5_uint32 A_save = A;
md5_uint32 B_save = B;
md5_uint32 C_save = C;
md5_uint32 D_save = D;
/* Process all bytes in the buffer with 64 bytes in each round of
the loop. */
while (words < endp)
{
md5_uint32 *cwp = correct_words;
md5_uint32 A_save = A;
md5_uint32 B_save = B;
md5_uint32 C_save = C;
md5_uint32 D_save = D;
/* First round: using the given function, the context and a constant
the next context is computed. Because the algorithms processing
unit is a 32-bit word and it is determined to work on words in
little endian byte order we perhaps have to change the byte order
before the computation. To reduce the work for the next steps
we store the swapped words in the array CORRECT_WORDS. */
/* First round: using the given function, the context and a constant
the next context is computed. Because the algorithms processing
unit is a 32-bit word and it is determined to work on words in
little endian byte order we perhaps have to change the byte order
before the computation. To reduce the work for the next steps
we store the swapped words in the array CORRECT_WORDS. */
#define OP(a, b, c, d, s, T) \
do \
{ \
a += FF (b, c, d) + (*cwp++ = SWAP (*words)) + T; \
++words; \
CYCLIC (a, s); \
a += b; \
} \
while (0)
#define OP(a, b, c, d, s, T) \
do \
{ \
a += FF (b, c, d) + (*cwp++ = SWAP (*words)) + T; \
++words; \
CYCLIC (a, s); \
a += b; \
} \
while (0)
/* It is unfortunate that C does not provide an operator for
cyclic rotation. Hope the C compiler is smart enough. */
/* It is unfortunate that C does not provide an operator for
cyclic rotation. Hope the C compiler is smart enough. */
#define CYCLIC(w, s) (w = (w << s) | (w >> (32 - s)))
/* Before we start, one word to the strange constants.
They are defined in RFC 1321 as
/* Before we start, one word to the strange constants.
They are defined in RFC 1321 as
T[i] = (int) (4294967296.0 * fabs (sin (i))), i = 1..64
*/
T[i] = (int) (4294967296.0 * fabs (sin (i))), i=1..64
*/
/* Round 1. */
OP (A, B, C, D, 7, 0xd76aa478);
OP (D, A, B, C, 12, 0xe8c7b756);
OP (C, D, A, B, 17, 0x242070db);
OP (B, C, D, A, 22, 0xc1bdceee);
OP (A, B, C, D, 7, 0xf57c0faf);
OP (D, A, B, C, 12, 0x4787c62a);
OP (C, D, A, B, 17, 0xa8304613);
OP (B, C, D, A, 22, 0xfd469501);
OP (A, B, C, D, 7, 0x698098d8);
OP (D, A, B, C, 12, 0x8b44f7af);
OP (C, D, A, B, 17, 0xffff5bb1);
OP (B, C, D, A, 22, 0x895cd7be);
OP (A, B, C, D, 7, 0x6b901122);
OP (D, A, B, C, 12, 0xfd987193);
OP (C, D, A, B, 17, 0xa679438e);
OP (B, C, D, A, 22, 0x49b40821);
/* Round 1. */
OP (A, B, C, D, 7, 0xd76aa478);
OP (D, A, B, C, 12, 0xe8c7b756);
OP (C, D, A, B, 17, 0x242070db);
OP (B, C, D, A, 22, 0xc1bdceee);
OP (A, B, C, D, 7, 0xf57c0faf);
OP (D, A, B, C, 12, 0x4787c62a);
OP (C, D, A, B, 17, 0xa8304613);
OP (B, C, D, A, 22, 0xfd469501);
OP (A, B, C, D, 7, 0x698098d8);
OP (D, A, B, C, 12, 0x8b44f7af);
OP (C, D, A, B, 17, 0xffff5bb1);
OP (B, C, D, A, 22, 0x895cd7be);
OP (A, B, C, D, 7, 0x6b901122);
OP (D, A, B, C, 12, 0xfd987193);
OP (C, D, A, B, 17, 0xa679438e);
OP (B, C, D, A, 22, 0x49b40821);
/* For the second to fourth round we have the possibly swapped words
in CORRECT_WORDS. Redefine the macro to take an additional first
argument specifying the function to use. */
/* For the second to fourth round we have the possibly swapped words
in CORRECT_WORDS. Redefine the macro to take an additional first
argument specifying the function to use. */
#undef OP
#define OP(f, a, b, c, d, k, s, T) \
do \
{ \
a += f (b, c, d) + correct_words[k] + T; \
CYCLIC (a, s); \
a += b; \
} \
while (0)
#define OP(f, a, b, c, d, k, s, T) \
do \
{ \
a += f (b, c, d) + correct_words[k] + T; \
CYCLIC (a, s); \
a += b; \
} \
while (0)
/* Round 2. */
OP (FG, A, B, C, D, 1, 5, 0xf61e2562);
OP (FG, D, A, B, C, 6, 9, 0xc040b340);
OP (FG, C, D, A, B, 11, 14, 0x265e5a51);
OP (FG, B, C, D, A, 0, 20, 0xe9b6c7aa);
OP (FG, A, B, C, D, 5, 5, 0xd62f105d);
OP (FG, D, A, B, C, 10, 9, 0x02441453);
OP (FG, C, D, A, B, 15, 14, 0xd8a1e681);
OP (FG, B, C, D, A, 4, 20, 0xe7d3fbc8);
OP (FG, A, B, C, D, 9, 5, 0x21e1cde6);
OP (FG, D, A, B, C, 14, 9, 0xc33707d6);
OP (FG, C, D, A, B, 3, 14, 0xf4d50d87);
OP (FG, B, C, D, A, 8, 20, 0x455a14ed);
OP (FG, A, B, C, D, 13, 5, 0xa9e3e905);
OP (FG, D, A, B, C, 2, 9, 0xfcefa3f8);
OP (FG, C, D, A, B, 7, 14, 0x676f02d9);
OP (FG, B, C, D, A, 12, 20, 0x8d2a4c8a);
/* Round 2. */
OP (FG, A, B, C, D, 1, 5, 0xf61e2562);
OP (FG, D, A, B, C, 6, 9, 0xc040b340);
OP (FG, C, D, A, B, 11, 14, 0x265e5a51);
OP (FG, B, C, D, A, 0, 20, 0xe9b6c7aa);
OP (FG, A, B, C, D, 5, 5, 0xd62f105d);
OP (FG, D, A, B, C, 10, 9, 0x02441453);
OP (FG, C, D, A, B, 15, 14, 0xd8a1e681);
OP (FG, B, C, D, A, 4, 20, 0xe7d3fbc8);
OP (FG, A, B, C, D, 9, 5, 0x21e1cde6);
OP (FG, D, A, B, C, 14, 9, 0xc33707d6);
OP (FG, C, D, A, B, 3, 14, 0xf4d50d87);
OP (FG, B, C, D, A, 8, 20, 0x455a14ed);
OP (FG, A, B, C, D, 13, 5, 0xa9e3e905);
OP (FG, D, A, B, C, 2, 9, 0xfcefa3f8);
OP (FG, C, D, A, B, 7, 14, 0x676f02d9);
OP (FG, B, C, D, A, 12, 20, 0x8d2a4c8a);
/* Round 3. */
OP (FH, A, B, C, D, 5, 4, 0xfffa3942);
OP (FH, D, A, B, C, 8, 11, 0x8771f681);
OP (FH, C, D, A, B, 11, 16, 0x6d9d6122);
OP (FH, B, C, D, A, 14, 23, 0xfde5380c);
OP (FH, A, B, C, D, 1, 4, 0xa4beea44);
OP (FH, D, A, B, C, 4, 11, 0x4bdecfa9);
OP (FH, C, D, A, B, 7, 16, 0xf6bb4b60);
OP (FH, B, C, D, A, 10, 23, 0xbebfbc70);
OP (FH, A, B, C, D, 13, 4, 0x289b7ec6);
OP (FH, D, A, B, C, 0, 11, 0xeaa127fa);
OP (FH, C, D, A, B, 3, 16, 0xd4ef3085);
OP (FH, B, C, D, A, 6, 23, 0x04881d05);
OP (FH, A, B, C, D, 9, 4, 0xd9d4d039);
OP (FH, D, A, B, C, 12, 11, 0xe6db99e5);
OP (FH, C, D, A, B, 15, 16, 0x1fa27cf8);
OP (FH, B, C, D, A, 2, 23, 0xc4ac5665);
/* Round 3. */
OP (FH, A, B, C, D, 5, 4, 0xfffa3942);
OP (FH, D, A, B, C, 8, 11, 0x8771f681);
OP (FH, C, D, A, B, 11, 16, 0x6d9d6122);
OP (FH, B, C, D, A, 14, 23, 0xfde5380c);
OP (FH, A, B, C, D, 1, 4, 0xa4beea44);
OP (FH, D, A, B, C, 4, 11, 0x4bdecfa9);
OP (FH, C, D, A, B, 7, 16, 0xf6bb4b60);
OP (FH, B, C, D, A, 10, 23, 0xbebfbc70);
OP (FH, A, B, C, D, 13, 4, 0x289b7ec6);
OP (FH, D, A, B, C, 0, 11, 0xeaa127fa);
OP (FH, C, D, A, B, 3, 16, 0xd4ef3085);
OP (FH, B, C, D, A, 6, 23, 0x04881d05);
OP (FH, A, B, C, D, 9, 4, 0xd9d4d039);
OP (FH, D, A, B, C, 12, 11, 0xe6db99e5);
OP (FH, C, D, A, B, 15, 16, 0x1fa27cf8);
OP (FH, B, C, D, A, 2, 23, 0xc4ac5665);
/* Round 4. */
OP (FI, A, B, C, D, 0, 6, 0xf4292244);
OP (FI, D, A, B, C, 7, 10, 0x432aff97);
OP (FI, C, D, A, B, 14, 15, 0xab9423a7);
OP (FI, B, C, D, A, 5, 21, 0xfc93a039);
OP (FI, A, B, C, D, 12, 6, 0x655b59c3);
OP (FI, D, A, B, C, 3, 10, 0x8f0ccc92);
OP (FI, C, D, A, B, 10, 15, 0xffeff47d);
OP (FI, B, C, D, A, 1, 21, 0x85845dd1);
OP (FI, A, B, C, D, 8, 6, 0x6fa87e4f);
OP (FI, D, A, B, C, 15, 10, 0xfe2ce6e0);
OP (FI, C, D, A, B, 6, 15, 0xa3014314);
OP (FI, B, C, D, A, 13, 21, 0x4e0811a1);
OP (FI, A, B, C, D, 4, 6, 0xf7537e82);
OP (FI, D, A, B, C, 11, 10, 0xbd3af235);
OP (FI, C, D, A, B, 2, 15, 0x2ad7d2bb);
OP (FI, B, C, D, A, 9, 21, 0xeb86d391);
/* Round 4. */
OP (FI, A, B, C, D, 0, 6, 0xf4292244);
OP (FI, D, A, B, C, 7, 10, 0x432aff97);
OP (FI, C, D, A, B, 14, 15, 0xab9423a7);
OP (FI, B, C, D, A, 5, 21, 0xfc93a039);
OP (FI, A, B, C, D, 12, 6, 0x655b59c3);
OP (FI, D, A, B, C, 3, 10, 0x8f0ccc92);
OP (FI, C, D, A, B, 10, 15, 0xffeff47d);
OP (FI, B, C, D, A, 1, 21, 0x85845dd1);
OP (FI, A, B, C, D, 8, 6, 0x6fa87e4f);
OP (FI, D, A, B, C, 15, 10, 0xfe2ce6e0);
OP (FI, C, D, A, B, 6, 15, 0xa3014314);
OP (FI, B, C, D, A, 13, 21, 0x4e0811a1);
OP (FI, A, B, C, D, 4, 6, 0xf7537e82);
OP (FI, D, A, B, C, 11, 10, 0xbd3af235);
OP (FI, C, D, A, B, 2, 15, 0x2ad7d2bb);
OP (FI, B, C, D, A, 9, 21, 0xeb86d391);
/* Add the starting values of the context. */
A += A_save;
B += B_save;
C += C_save;
D += D_save;
}
/* Add the starting values of the context. */
A += A_save;
B += B_save;
C += C_save;
D += D_save;
}
/* Put checksum in context given as argument. */
ctx->A = A;
ctx->B = B;
ctx->C = C;
ctx->D = D;
/* Put checksum in context given as argument. */
ctx->A = A;
ctx->B = B;
ctx->C = C;
ctx->D = D;
}
static void md5_process_bytes (const void *buffer, size_t len, struct md5_ctx *ctx)
static void md5_process_bytes(const void *buffer, size_t len, struct md5_ctx *ctx)
{
/* When we already have some bits in our internal buffer concatenate
both inputs first. */
if (ctx->buflen != 0)
{
size_t left_over = ctx->buflen;
size_t add = 128 - left_over > len ? len : 128 - left_over;
memcpy (&ctx->buffer[left_over], buffer, add);
ctx->buflen = (md5_uint32)(add+ctx->buflen);
if (left_over + add > 64)
/* When we already have some bits in our internal buffer concatenate
* both inputs first. */
if (ctx->buflen != 0)
{
md5_process_block (ctx->buffer, (left_over + add) & ~63, ctx);
/* The regions in the following copy operation cannot overlap. */
memcpy (ctx->buffer, &ctx->buffer[(left_over + add) & ~63],
(left_over + add) & 63);
ctx->buflen = (md5_uint32)((left_over + add) & 63);
size_t left_over = ctx->buflen;
size_t add = 128 - left_over > len ? len : 128 - left_over;
memcpy (&ctx->buffer[left_over], buffer, add);
ctx->buflen += add;
if (ctx->buflen > 64)
{
md5_process_block(ctx->buffer, ctx->buflen & ~63, ctx);
ctx->buflen &= 63;
/* The regions in the following copy operation cannot overlap. */
memcpy (ctx->buffer, &ctx->buffer[(left_over + add) & ~63],
ctx->buflen);
}
buffer = (const char *) buffer + add;
len -= add;
}
buffer = (const char *) buffer + add;
len -= add;
}
/* Process available complete blocks. */
if (len >= 64)
{
while (len > 64)
{
md5_process_block(memcpy(ctx->buffer, buffer, 64), 64, ctx);
buffer = (const char *) buffer + 64;
len -= 64;
}
}
/* Process available complete blocks. */
if (len > 64)
{
md5_process_block (buffer, len & ~63, ctx);
buffer = (const char *) buffer + (len & ~63);
len &= 63;
}
/* Move remaining bytes in internal buffer. */
if (len > 0)
{
size_t left_over = ctx->buflen;
/* Move remaining bytes in internal buffer. */
if (len > 0)
{
memcpy (ctx->buffer, buffer, len);
ctx->buflen = (md5_uint32)len;
}
memcpy(&ctx->buffer[left_over], buffer, len);
left_over += len;
if (left_over >= 64)
{
md5_process_block (ctx->buffer, 64, ctx);
left_over -= 64;
memcpy(ctx->buffer, &ctx->buffer[64], left_over);
}
ctx->buflen = left_over;
}
}
@@ -298,100 +317,98 @@ static void md5_process_bytes (const void *buffer, size_t len, struct md5_ctx *c
IMPORTANT: On some systems it is required that RESBUF is correctly
aligned for a 32 bits value. */
static void *md5_finish_ctx (struct md5_ctx *ctx, void *resbuf)
static void *md5_finish_ctx(struct md5_ctx *ctx, void *resbuf)
{
/* Take yet unprocessed bytes into account. */
md5_uint32 bytes = ctx->buflen;
size_t pad;
md5_uint32 *buffer = NULL;
/* Take yet unprocessed bytes into account. */
md5_uint32 bytes = ctx->buflen;
size_t pad;
/* Now count remaining bytes. */
ctx->total[0] += bytes;
if (ctx->total[0] < bytes)
++ctx->total[1];
/* Now count remaining bytes. */
ctx->total[0] += bytes;
if (ctx->total[0] < bytes)
++ctx->total[1];
pad = bytes >= 56 ? 64 + 56 - bytes : 56 - bytes;
memcpy (&ctx->buffer[bytes], fillbuf, pad);
pad = bytes >= 56 ? 64 + 56 - bytes : 56 - bytes;
memcpy(&ctx->buffer[bytes], fillbuf, pad);
/* Put the 64-bit file length in *bits* at the end of the buffer. */
buffer = (void *)&ctx->buffer[bytes + pad];
*buffer = SWAP (ctx->total[0] << 3);
buffer = (void *)&ctx->buffer[bytes + pad + 4];
*buffer = SWAP ((ctx->total[1] << 3) | (ctx->total[0] >> 29));
/* Put the 64-bit file length in *bits* at the end of the buffer. */
ctx->buffer32[(bytes + pad) / 4] = SWAP (ctx->total[0] << 3);
ctx->buffer32[(bytes + pad + 4) / 4] = SWAP ((ctx->total[1] << 3)
| (ctx->total[0] >> 29));
/* Process last bytes. */
md5_process_block (ctx->buffer, bytes + pad + 8, ctx);
/* Process last bytes. */
md5_process_block(ctx->buffer, bytes + pad + 8, ctx);
return md5_read_ctx (ctx, resbuf);
return md5_read_ctx(ctx, resbuf);
}
/* Compute MD5 message digest for bytes read from STREAM. The
resulting message digest number will be written into the 16 bytes
beginning at RESBLOCK. */
int md5_stream (FILE *stream, void *resblock)
int md5_stream(FILE *stream, void *resblock)
{
/* Important: BLOCKSIZE must be a multiple of 64. */
/* Important: BLOCKSIZE must be a multiple of 64. */
#define BLOCKSIZE 4096
struct md5_ctx ctx;
char buffer[BLOCKSIZE + 72];
size_t sum = 0;
struct md5_ctx ctx;
char buffer[BLOCKSIZE + 72];
size_t sum = 0;
/* Initialize the computation context. */
md5_init_ctx (&ctx);
/* Initialize the computation context. */
md5_init_ctx(&ctx);
/* Iterate over full file contents. */
while (1)
{
/* We read the file in blocks of BLOCKSIZE bytes. One call of the
computation function processes the whole buffer so that with the
next round of the loop another block can be read. */
size_t n;
sum = 0;
/* Read block. Take care for partial reads. */
do
/* Iterate over full file contents. */
while (1)
{
n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
/* We read the file in blocks of BLOCKSIZE bytes. One call of the
computation function processes the whole buffer so that with the
next round of the loop another block can be read. */
size_t n;
sum = 0;
sum += n;
/* Read block. Take care for partial reads. */
do
{
n = fread(buffer + sum, 1, BLOCKSIZE - sum, stream);
sum += n;
}
while (sum < BLOCKSIZE && n != 0);
if (n == 0 && ferror(stream))
return 1;
/* If end of file is reached, end the loop. */
if (n == 0)
break;
/* Process buffer with BLOCKSIZE bytes. Note that
BLOCKSIZE % 64 == 0
*/
md5_process_block(buffer, BLOCKSIZE, &ctx);
}
while (sum < BLOCKSIZE && n != 0);
if (n == 0 && ferror (stream))
return 1;
/* If end of file is reached, end the loop. */
if (n == 0)
break;
/* Add the last bytes if necessary. */
if (sum > 0)
md5_process_bytes(buffer, sum, &ctx);
/* Process buffer with BLOCKSIZE bytes. Note that
BLOCKSIZE % 64 == 0
*/
md5_process_block (buffer, BLOCKSIZE, &ctx);
}
/* Add the last bytes if necessary. */
if (sum > 0)
md5_process_bytes (buffer, sum, &ctx);
/* Construct result in desired memory. */
md5_finish_ctx (&ctx, resblock);
return 0;
/* Construct result in desired memory. */
md5_finish_ctx(&ctx, resblock);
return 0;
}
/* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
result is always in little endian byte order, so that a byte-wise
output yields to the wanted ASCII representation of the message
digest. */
void *md5_buffer (const char *buffer, size_t len, void *resblock)
void *md5_buffer(const char *buffer, size_t len, void *resblock)
{
struct md5_ctx ctx;
struct md5_ctx ctx;
/* Initialize the computation context. */
md5_init_ctx (&ctx);
/* Initialize the computation context. */
md5_init_ctx(&ctx);
/* Process whole buffer but last len % 64 bytes. */
md5_process_bytes (buffer, len, &ctx);
/* Process whole buffer but last len % 64 bytes. */
md5_process_bytes (buffer, len, &ctx);
/* Put result in desired memory area. */
return md5_finish_ctx (&ctx, resblock);
/* Put result in desired memory area. */
return md5_finish_ctx(&ctx, resblock);
}
+24 -100
View File
@@ -1,6 +1,6 @@
// SONIC ROBO BLAST 2
//-----------------------------------------------------------------------------
// Copyright (C) 1995-1996 by the Free Software Foundation, Inc.
// Copyright (C) 1995-2025 by the Free Software Foundation, Inc.
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.
@@ -24,108 +24,32 @@
#define MD5_LEN 16
/* The following contortions are an attempt to use the C preprocessor
to determine an unsigned integral type that is 32 bits wide. An
alternative approach is to use autoconf's AC_CHECK_SIZEOF macro, but
doing that would require that the configure script compile and *run*
the resulting executable. Locally running cross-compiled executables
is usually not possible. */
/* The following contortions are an attempt to use the C preprocessor
to determine an unsigned integral type that is 32 bits wide. An
alternative approach is to use autoconf's AC_CHECK_SIZEOF macro, but
doing that would require that the configure script compile and *run*
the resulting executable. Locally running cross-compiled executables
is usually not possible. */
#ifdef _LIBC
# include <sys/types.h>
typedef u_int32_t md5_uint32;
#include <stdint.h>
typedef uint32_t md5_uint32;
typedef uintptr_t md5_uintptr;
#if defined (__THROW)
#define THROWFUNC __THROW
#else
# if defined __STDC__ && __STDC__
# define UINT_MAX_32_BITS 4294967295U
# else
# define UINT_MAX_32_BITS 0xFFFFFFFF
# endif
/* If UINT_MAX isn't defined, assume it's a 32-bit type.
This should be valid for all systems GNU cares about because
that doesn't include 16-bit systems, and only modern systems
(that certainly have <limits.h>) have 64+-bit integral types. */
# ifndef UINT_MAX
# define UINT_MAX UINT_MAX_32_BITS
# endif
# if UINT_MAX == UINT_MAX_32_BITS
typedef unsigned int md5_uint32;
# else
# if USHRT_MAX == UINT_MAX_32_BITS
typedef unsigned short md5_uint32;
# else
# if ULONG_MAX == UINT_MAX_32_BITS
typedef unsigned long md5_uint32;
# else
/* The following line is intended to evoke an error.
Using #error is not portable enough. */
"Cannot determine unsigned 32-bit data type."
# endif
# endif
# endif
#define THROWFUNC
#endif
#undef __P
#if defined (__STDC__) && __STDC__
#define __P(x) x
#else
#define __P(x) ()
#endif
/* Compute MD5 message digest for bytes read from STREAM. The
resulting message digest number will be written into the 16 bytes
beginning at RESBLOCK. */
int md5_stream(FILE *stream, void *resblock) THROWFUNC;
/*
* The following three functions are build up the low level used in
* the functions `md5_stream' and `md5_buffer'.
*/
#if 0
/* Initialize structure containing state of computation.
(RFC 1321, 3.3: Step 3) */
extern void md5_init_ctx __P ((struct md5_ctx *ctx));
/* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
result is always in little endian byte order, so that a byte-wise
output yields to the wanted ASCII representation of the message
digest. */
extern void *md5_buffer(const char *buffer, size_t len, void *resblock) THROWFUNC;
/* Starting with the result of former calls of this function (or the
initialization function update the context for the next LEN bytes
starting at BUFFER.
It is necessary that LEN is a multiple of 64!!! */
extern void md5_process_block __P ((const void *buffer, size_t len,
struct md5_ctx *ctx));
/* Starting with the result of former calls of this function (or the
initialization function update the context for the next LEN bytes
starting at BUFFER.
It is NOT required that LEN is a multiple of 64. */
extern void md5_process_bytes __P ((const void *buffer, size_t len,
struct md5_ctx *ctx));
/* Process the remaining bytes in the buffer and put result from CTX
in first 16 bytes following RESBUF. The result is always in little
endian byte order, so that a byte-wise output yields to the wanted
ASCII representation of the message digest.
IMPORTANT: On some systems it is required that RESBUF is correctly
aligned for a 32 bits value. */
extern void *md5_finish_ctx __P ((struct md5_ctx *ctx, void *resbuf));
/* Put result from CTX in first 16 bytes following RESBUF. The result is
always in little endian byte order, so that a byte-wise output yields
to the wanted ASCII representation of the message digest.
IMPORTANT: On some systems it is required that RESBUF is correctly
aligned for a 32 bits value. */
extern void *md5_read_ctx __P ((const struct md5_ctx *ctx, void *resbuf));
#endif
/* Compute MD5 message digest for bytes read from STREAM. The
resulting message digest number will be written into the 16 bytes
beginning at RESBLOCK. */
int md5_stream __P ((FILE *stream, void *resblock));
/* Compute MD5 message digest for LEN bytes beginning at BUFFER. The
result is always in little endian byte order, so that a byte-wise
output yields to the wanted ASCII representation of the message
digest. */
extern void *md5_buffer __P ((const char *buffer, size_t len, void *resblock));
#endif
#endif /* md5.h */
+3 -3
View File
@@ -6964,7 +6964,7 @@ static boolean P_MobjDeadThink(mobj_t *mobj)
if (mobj->flags2 & MF2_AMBUSH)
{
mobj->colorized = true;
mobj->color = K_RainbowColor();
mobj->color = (1 + (leveltime % (MAXSKINCOLORS-1)));
mobj->frame |= FF_FULLBRIGHT;
}
else
@@ -7806,7 +7806,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj)
P_SetScale(mobj, (mobj->destscale = mobj->target->scale));
if (mobj->target->player->kartstuff[k_driftcharge] >= K_GetKartDriftSparkValue(mobj->target->player)*4)
mobj->color = K_RainbowColor();
mobj->color = (UINT8)(1 + (leveltime % (MAXSKINCOLORS-1)));
else if (mobj->target->player->kartstuff[k_driftcharge] >= K_GetKartDriftSparkValue(mobj->target->player)*2)
mobj->color = SKINCOLOR_KETCHUP;
else if (mobj->target->player->kartstuff[k_driftcharge] >= K_GetKartDriftSparkValue(mobj->target->player))
@@ -8505,7 +8505,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj)
if (mobj->flags2 & MF2_AMBUSH)
{
mobj->colorized = true;
mobj->color = K_RainbowColor();
mobj->color = (1 + (leveltime % (MAXSKINCOLORS-1)));
mobj->frame |= FF_FULLBRIGHT;
}
else
+29 -24
View File
@@ -650,27 +650,6 @@ size_t P_PrecacheLevelFlats(void)
return flatmem;
}
// check if our flat contains cyan pixels
// not sure if this is the best way to do it but it works
static void P_CheckCyanFlat(levelflat_t *levelflat)
{
// only need this for software
if (rendermode != render_soft)
return;
const UINT8 *flat = R_GetFlat(levelflat->lumpnum);
const size_t size = W_LumpLength(levelflat->lumpnum);
for (size_t steppy = 0; steppy < size; steppy++)
{
if (flat[steppy] == TRANSPARENTPIXEL)
{
levelflat->cyan = true;
break;
}
}
}
// help function for P_LoadSectors, find a flat in the active wad files,
// allocate an id for it, and set the levelflat (to speedup search)
//
@@ -682,7 +661,7 @@ INT32 P_AddLevelFlat(const char *flatname, levelflat_t *levelflat)
// first scan through the already found flats
//
for (i = 0; i < numlevelflats; i++, levelflat++)
if (strnicmp(levelflat->name, flatname, 8) == 0)
if (strnicmp(levelflat->name,flatname,8) == 0)
break;
// that flat was already found in the level, return the id
@@ -696,7 +675,20 @@ INT32 P_AddLevelFlat(const char *flatname, levelflat_t *levelflat)
levelflat->lumpnum = R_GetFlatNumForName(flatname);
levelflat->baselumpnum = LUMPERROR;
P_CheckCyanFlat(levelflat);
// check if our flat contains cyan pixels
// not sure if this is the best way to do it but it works
{
const UINT8 *flat = (UINT8 *)W_CacheLumpNum(levelflat->lumpnum, PU_LEVEL);
size_t size = W_LumpLength(levelflat->lumpnum);
for (size_t steppy = 0; steppy < size; steppy++)
{
if (flat[steppy] == TRANSPARENTPIXEL)
{
levelflat->cyan = true;
break;
}
}
}
#ifndef ZDEBUG
CONS_Debug(DBG_SETUP, "flat #%03d: %s\n", atoi(sizeu1(numlevelflats)), levelflat->name);
@@ -743,7 +735,20 @@ INT32 P_AddLevelFlatRuntime(const char *flatname)
levelflat->lumpnum = R_GetFlatNumForName(flatname);
levelflat->baselumpnum = LUMPERROR;
P_CheckCyanFlat(levelflat);
// check if our flat contains cyan pixels
// not sure if this is the best way to do it but it works
{
const UINT8 *flat = (UINT8 *)W_CacheLumpNum(levelflat->lumpnum, PU_LEVEL);
size_t size = W_LumpLength(levelflat->lumpnum);
for (size_t steppy = 0; steppy < size; steppy++)
{
if (flat[steppy] == TRANSPARENTPIXEL)
{
levelflat->cyan = true;
break;
}
}
}
#ifndef ZDEBUG
CONS_Debug(DBG_SETUP, "flat #%03d: %s\n", atoi(sizeu1(numlevelflats)), levelflat->name);
+1 -1
View File
@@ -1641,7 +1641,7 @@ static void P_CheckInvincibilityTimer(player_t *player)
if (!player->powers[pw_invulnerability] && !player->kartstuff[k_invincibilitytimer])
return;
player->mo->color = K_RainbowColor();
player->mo->color = (UINT8)(1 + (leveltime % (MAXSKINCOLORS-1)));
// Resume normal music stuff.
if (player->powers[pw_invulnerability] == 1 || player->kartstuff[k_invincibilitytimer] == 1)
+3 -1
View File
@@ -1182,7 +1182,7 @@ void R_DrawSinglePlane(drawspandata_t* ds, visplane_t *pl, boolean allow_paralle
levelflat = &levelflats[pl->picnum];
// Get the texture
ds->source = R_GetFlat(levelflat->lumpnum);
ds->source = (UINT8 *)W_CacheLumpNum(levelflat->lumpnum, PU_STATIC); // Stay here until Z_ChangeTag
if (ds->source == NULL)
return;
@@ -1387,6 +1387,8 @@ using the palette colors.
}
}
#endif
Z_ChangeTag(ds->source, PU_CACHE);
}
void R_PlaneBounds(visplane_t *plane)