Browse Source

Init repo

tags/v0.2
Тим 10 months ago
commit
0a82c6da3e
7 changed files with 132 additions and 0 deletions
  1. 9
    0
      .gitmodules
  2. 1
    0
      HOOK-d
  3. 20
    0
      Makefile
  4. 1
    0
      VorbisFile-d
  5. 23
    0
      config.d
  6. 1
    0
      inifiled
  7. 77
    0
      loader.d

+ 9
- 0
.gitmodules View File

@@ -0,0 +1,9 @@
[submodule "inifiled"]
path = inifiled
url = https://github.com/burner/inifiled
[submodule "HOOK-d"]
path = HOOK-d
url = https://git.prime-hack.net/SR_team/HOOK-d
[submodule "VorbisFile-d"]
path = VorbisFile-d
url = https://git.prime-hack.net/AsiLoader/VorbisFile-d

+ 1
- 0
HOOK-d

@@ -0,0 +1 @@
Subproject commit af759eb83f30438c14f3a8817cf9c7d3d1d76d18

+ 20
- 0
Makefile View File

@@ -0,0 +1,20 @@
D=ldc2
PROJECT=VorbisFile
EXT=dll
SOURCES=*.d VorbisFile-d/*.d HOOK-d/*.d inifiled/source/*.d
TARGET=bin

all: clean build

build:
$(D) $(SOURCES) -shared -m32 -Os -of=$(TARGET)/$(PROJECT).$(EXT)

clean:
rm -rf $(TARGET)/*.obj

full-clean: clean
rm -rf $(TARGET)
help:
@echo "Change variable D, to select compiler."
@echo "For example compile with dmd: \`make D=dmd\`"

+ 1
- 0
VorbisFile-d

@@ -0,0 +1 @@
Subproject commit 4dd106450cc9ef2f3f2e9beab9f38ab4d0b82d0b

+ 23
- 0
config.d View File

@@ -0,0 +1,23 @@
module config;

import std.file;
import inifiled;

@INI("AsiLoader settings", "AsiLoader")
struct stAsiLoader{
@INI("Enable builtin asi loader") bool enable = true;
};

@INI("Main settings", "Config")
struct stConfig(string inifile){
void load(){
if (inifile.exists && inifile.isFile)
this.readINIFile(inifile);
}
void save(){
this.writeINIFile(inifile);
}
@INI("Proxy library for asi loader") string proxy;
@INI stAsiLoader asiLoader;
};

+ 1
- 0
inifiled

@@ -0,0 +1 @@
Subproject commit cecaff8037a60db2a51c9bded4802c87d938a44e

+ 77
- 0
loader.d View File

@@ -0,0 +1,77 @@
import std.string, std.file;
import core.sys.windows.windows, core.sys.windows.dll, core.runtime;
import hook.call, hook.asm86;
import vorbisfile;
import config;

alias Callback = extern (C) void function() @nogc nothrow pure @safe;
__gshared static stConfig!"VorbisFile.ini" ini;

void hook_mainloop()
{
auto asm86 = new Asm86Hook();
asm86.pushad;
asm86.pushfd;
asm86.call(&mainloop);
asm86.popfd;
asm86.popad;
asm86.insert(0x748DA3, 6);
asm86.ret;
call_hook(0x748DA3, 6, cast(void*)asm86.createFunc);
asm86.destroy;
}

extern (Windows) BOOL DllMain(HINSTANCE hInstance, ULONG ulReason, LPVOID pvReserved)
{
switch (ulReason)
{
case DLL_PROCESS_ATTACH:
Runtime.initialize();
hook_mainloop();
ini.load;
if (!ini.proxy.empty)
setVorbisFile(ini.proxy);
dll_process_attach(hInstance, true);
break;
case DLL_PROCESS_DETACH:
ini.save;
Runtime.terminate();
dll_process_detach(hInstance, true);
break;
case DLL_THREAD_ATTACH:
dll_thread_attach(true, true);
break;
case DLL_THREAD_DETACH:
dll_thread_detach(true, true);
break;
default:
break;
}
return true;
}

extern(Windows) void mainloop()
{
__gshared static bool asiLoaded = false;
__gshared static bool dllLoaded = false;
if (!asiLoaded && ini.asiLoader.enable){
asiLoaded = true;
foreach (string plugin; dirEntries(getcwd, "*.asi", SpanMode.shallow))
LoadLibraryA(plugin.toStringz);
}
if (!dllLoaded){
dllLoaded = true;
if ((getcwd ~ "/plugins").exists && (getcwd ~ "/plugins").isDir){
foreach (string plugin; dirEntries(getcwd ~ "/plugins", "*.dll", SpanMode.shallow)){
auto dll = LoadLibraryA(plugin.toStringz);
auto callback = cast(Callback)GetProcAddress(dll, "load");
if (!(callback is null))
callback();
}
}
else (getcwd ~ "/plugins").mkdir;
}
}

Loading…
Cancel
Save