summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2009-10-14 14:58:07 +0000
committerPixel <pixel@nobis-crew.org>2009-10-14 14:58:07 +0000
commit89a2262f04c3452180b3fe5ec80a803b766b927b (patch)
tree0ab0b15b1002a2edd6bfce8ff9f9bd725291cec3
Initial import.HEADmaster
-rw-r--r--Makefile82
-rw-r--r--Makefile.mingw3272
-rw-r--r--src/plugin-luaslz.cc84
3 files changed, 238 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..da813fe
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,82 @@
+SYSTEM=$(shell uname)
+ifeq ($(SYSTEM),Darwin)
+ARCH_FLAGS=
+SHARED_FLAGS=-dynamiclib
+SHARED_EXT=dylib
+CPPFLAGS = -dynamic
+LD = g++
+else
+ARCH_FLAGS=-march=i686 -m32
+SHARED_FLAGS=-shared
+SHARED_EXT=so
+LD = g++ -m32
+endif
+CC = gcc
+CXX = g++
+STRIP = strip
+
+INCLUDES = \
+-I../Baltisot/include \
+-I../Baltisot/lib/zlib/include \
+-I../Baltisot/lib/lua/include -I../Baltisot/lib/lua/includes \
+-I /sw/include \
+-I../PSX-Bundle/includes -I../PSX-Bundle/psxdev \
+
+HAVES = -DHAVE_VSSCANF -DHAVE_FCNTL -DHAVE_UNISTD_H -DHAVE_FORK -DHAVE_PIPE -DHAVE_FSYNC -DHAVE_MALLOC_H -DHAVE_ASPRINTF -DHAVE_BYTESWAP_H -DHAVE_UCL
+
+CPPFLAGS += $(INCLUDES) -O4 -fexceptions -DSTDC_HEADERS -DREADLINE_STATIC -DHOOK_STDS -DWORDS_LITTLEENDIAN $(ARCH_FLAGS) $(HAVES)
+
+LDFLAGS += $(ARCH_FLAGS) $(SHARED_FLAGS) ./lua-interface.$(SHARED_EXT)
+
+vpath %.c ../Baltisot/lib:../Baltisot/src:../Baltisot/lib/zlib/src:../Baltisot/lib/lua/src:../Baltisot/lib/lua/src/LuaLib:src:../PSX-Bundle/lib:../PSX-Bundle/psxdev
+vpath %.cc ../Baltisot/lib:../Baltisot/src:../Baltisot/lib/zlib/src:../Baltisot/lib/lua/src:../Baltisot/lib/lua/src/LuaLib:src:../PSX-Bundle/lib:../PSX-Bundle/psxdev
+vpath %.cpp ../Baltisot/lib:../Baltisot/src:../Baltisot/lib/zlib/src:../Baltisot/lib/lua/src:../Baltisot/lib/lua/src/LuaLib:src:../PSX-Bundle/lib:../PSX-Bundle/psxdev
+vpath %.lua ../Baltisot/lib:../Baltisot/src
+
+LUASLZ_SOURCES = \
+plugin-luaslz.cc \
+lzss.cpp \
+
+WHOLE_SOURCES = \
+$(LUASLZ_SOURCES) \
+
+MODULES_LIST = \
+luaslz.$(SHARED_EXT) \
+
+ALL_OBJECTS = $(addsuffix .o, $(notdir $(basename $(WHOLE_SOURCES) $(LUA_LIB))))
+ALL_DEPS = $(addsuffix .dep, $(notdir $(basename $(WHOLE_SOURCES))))
+
+all: dep modules
+
+dist: modules
+ mkdir -p ../lua-interface-dist
+ cp $(MODULES_LIST) ../lua-interface-dist
+
+modules: $(MODULES_LIST)
+
+dep: $(ALL_DEPS)
+
+luaslz.$(SHARED_EXT): $(addsuffix .o, $(notdir $(basename $(LUASLZ_SOURCES))))
+ $(LD) $(LDFLAGS) -o $@ $+ $(LUASLZ_LIBS)
+
+clean:
+ rm -f *.o *.dep *.so *.dylib
+
+%.dep : %.c
+ $(CC) $(CPPFLAGS) -M -MF $@ $<
+
+%.dep : %.cpp
+ $(CXX) $(CPPFLAGS) -M -MF $@ $<
+
+%.dep : %.cc
+ $(CXX) $(CPPFLAGS) -M -MF $@ $<
+
+%.c : %.clua
+ bin2c $< $@ $(basename $@)
+
+%.clua : %.lua
+ ./luac -o $@ $<
+
+-include $(ALL_DEPS)
+
+.PHONY: clean dist
diff --git a/Makefile.mingw32 b/Makefile.mingw32
new file mode 100644
index 0000000..7b11ef1
--- /dev/null
+++ b/Makefile.mingw32
@@ -0,0 +1,72 @@
+SYSTEM=$(shell uname)
+ifeq ($(SYSTEM),Darwin)
+CC = i386-mingw32-gcc
+CXX = i386-mingw32-g++
+LD = i386-mingw32-g++
+STRIP = i386-mingw32-strip
+else
+CC = i586-mingw32msvc-gcc
+CXX = i586-mingw32msvc-g++
+LD = i586-mingw32msvc-g++
+STRIP = i586-mingw32msvc-strip
+endif
+
+INCLUDES = \
+-I ../Mesa-7.0.3-win32/include \
+-I../Baltisot/include \
+-I../Baltisot/lib/zlib/include \
+-I../Baltisot/lib/lua/include -I../Baltisot/lib/lua/includes \
+-I../PSX-Bundle/includes -I../PSX-Bundle/psxdev \
+
+HAVES = -DHAVE_VSSCANF -DHAVE_FCNTL -DHAVE_UNISTD_H -DHAVE_FORK -DHAVE_PIPE -DHAVE_FSYNC -DHAVE_MALLOC_H -DHAVE_ASPRINTF -DHAVE_BYTESWAP_H
+
+CPPFLAGS += $(INCLUDES) -g -DSTDC_HEADERS -DREADLINE_STATIC -DHOOK_STDS -DWORDS_LITTLEENDIAN -fexceptions -march=i686 $(HAVES)
+
+LDFLAGS += -g -fexception -shared -Wl,--export-dynamic ../lua-interface/lua-interface.a -Wl,--enable-auto-image-base --export-all-symbols -Wl,--enable-auto-import
+
+vpath %.c ../Baltisot/lib:../Baltisot/src:../Baltisot/lib/zlib/src:../Baltisot/lib/lua/src:../Baltisot/lib/lua/src/LuaLib:src:../PSX-Bundle/lib:../PSX-Bundle/psxdev
+vpath %.cc ../Baltisot/lib:../Baltisot/src:../Baltisot/lib/zlib/src:../Baltisot/lib/lua/src:../Baltisot/lib/lua/src/LuaLib:src:../PSX-Bundle/lib:../PSX-Bundle/psxdev
+vpath %.cpp ../Baltisot/lib:../Baltisot/src:../Baltisot/lib/zlib/src:../Baltisot/lib/lua/src:../Baltisot/lib/lua/src/LuaLib:src:../PSX-Bundle/lib:../PSX-Bundle/psxdev
+vpath %.lua ../Baltisot/lib:../Baltisot/src
+
+LUASLZ_SOURCES = \
+plugin-luaslz.cc \
+lzss.cpp \
+
+WHOLE_SOURCES = \
+$(LUASLZ_SOURCES) \
+
+MODULES_LIST = \
+luaslz.dll \
+
+ALL_OBJECTS = $(addsuffix .o, $(notdir $(basename $(WHOLE_SOURCES))))
+ALL_DEPS = $(addsuffix .dep, $(notdir $(basename $(WHOLE_SOURCES))))
+
+all: dep modules
+
+modules: $(ALL_OBJECTS) $(MODULES_LIST)
+
+dep: $(ALL_DEPS)
+
+luaslz.dll: $(addsuffix .o, $(notdir $(basename $(LUASLZ_SOURCES))))
+ $(LD) -o $@ $+ $(LDFLAGS)
+
+clean:
+ rm -f *.o *.dep *.dll
+
+%.dep : %.c
+ $(CC) $(CPPFLAGS) -M -MF $@ $<
+
+%.dep : %.cpp
+ $(CXX) $(CPPFLAGS) -M -MF $@ $<
+
+%.dep : %.cc
+ $(CXX) $(CPPFLAGS) -M -MF $@ $<
+
+%.c : %.clua
+ bin2c $< $@ $(basename $@)
+
+%.clua : %.lua
+ ./luac -o $@ $<
+
+-include $(ALL_DEPS)
diff --git a/src/plugin-luaslz.cc b/src/plugin-luaslz.cc
new file mode 100644
index 0000000..5f1cfd4
--- /dev/null
+++ b/src/plugin-luaslz.cc
@@ -0,0 +1,84 @@
+#include <BLua.h>
+#include <lzss.h>
+
+#ifndef WIN32
+#define WEAK __attribute__ ((weak))
+#else
+#define WEAK
+#endif
+
+class sLua_slz : public Base {
+ public:
+ static int slz_decomp(lua_State * __L) {
+ Lua * L = Lua::find(__L);
+ int n = L->gettop();
+ Handle * in, * out;
+ int slz_type;
+ lzss lzss_o;
+
+ if (n != 2)
+ L->error("Wrong number of arguments to slz_decomp; need two handles.");
+
+ in = lua_recast<Handle>(L, 1);
+ out = lua_recast<Handle>(L, 2);
+
+ Uint32 sig, siz_in, siz_out, file_siz;
+ sig = in->readU32();
+ siz_in = in->readU32();
+ siz_out = in->readU32();
+ file_siz = in->readU32();
+
+ switch (sig) {
+ case 0x05a4c53:
+ out->copyfrom(in, siz_in);
+ slz_type = 0;
+ break;
+ case 0x15a4c53:
+ slz_type = 1;
+ lzss_o.change_scheme(lzss_o.schemes[lzss_o.VP_1]);
+ lzss_o.lzss_decomp(in, out, siz_out, false);
+ break;
+ case 0x25a4c53:
+ slz_type = 2;
+ lzss_o.change_scheme(lzss_o.schemes[lzss_o.VP_2]);
+ lzss_o.lzss_decomp(in, out, siz_out, false);
+ break;
+ case 0x35a4c53:
+ slz_type = 3;
+ Handle::ucl_decompress(in, out, siz_out, siz_in);
+ break;
+ default:
+ L->error("Unknown slz scheme. Expected 0, 1, 2 or 3, got " + String(n));
+ break;
+ }
+
+ if (file_siz)
+ in->seek(file_siz - 16 - siz_in, SEEK_CUR);
+
+ L->push((lua_Number) file_siz);
+ L->push((lua_Number) slz_type);
+ return 2;
+ }
+ static void pushstatics(Lua * L) {
+ L->declarefunc("slz_decomp", slz_decomp);
+ };
+};
+
+static void _init_plugin(Lua * L) {
+ static bool done = false;
+ if (done) return;
+ done = true;
+ sLua_slz::pushstatics(L);
+}
+
+extern "C" {
+
+WEAK void init_plugin(Lua * L) {
+ _init_plugin(L);
+}
+
+void luaslz_init(Lua * L) {
+ _init_plugin(L);
+}
+
+}