Skip to content

Commit

Permalink
Merge branch 'chakracore'
Browse files Browse the repository at this point in the history
  • Loading branch information
kungfooman committed Mar 23, 2019
2 parents 302fa29 + 8180a6b commit 0c42b1e
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 22 deletions.
43 changes: 27 additions & 16 deletions chakracore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,40 @@
#include <stdio.h>
#include <Windows.h>

chakracore_init_t dll_chakracore_init = NULL;
chakracore_set_printf_t dll_chakracore_set_printf = NULL;
chakracore_eval_t dll_chakracore_eval = NULL;

typedef int (*printf_t)(const char *format, ...);
typedef int (*chakracore_init_t)();
typedef int (*chakracore_set_printf_t)(printf_t);

chakracore_init_t chakracore_init = NULL;
chakracore_set_printf_t chakracore_set_printf = NULL;

int chakracore_prepare() {
int chakracore_prepare(printf_t printer) {

HMODULE handle = LoadLibraryA("ChakraCoreInterface.dll");

chakracore_init = (chakracore_init_t )GetProcAddress(handle, "chakracore_init");
chakracore_set_printf = (chakracore_set_printf_t)GetProcAddress(handle, "chakracore_set_printf");
dll_chakracore_init = (chakracore_init_t )GetProcAddress(handle, "chakracore_init");
dll_chakracore_set_printf = (chakracore_set_printf_t)GetProcAddress(handle, "chakracore_set_printf");
dll_chakracore_eval = (chakracore_eval_t )GetProcAddress(handle, "chakracore_eval");

printf("cci handle=%d chakracore_init=%d chakracore_set_printf=%d\n", handle, chakracore_init, chakracore_set_printf);
#if 1
printf("cci handle=%d\n", handle);
printf("dll_chakracore_init = %d\n", dll_chakracore_init );
printf("dll_chakracore_set_printf = %d\n", dll_chakracore_set_printf);
printf("dll_chakracore_eval = %d\n", dll_chakracore_eval );
#endif

if (dll_chakracore_set_printf) {
dll_chakracore_set_printf(printer);
}

if (chakracore_init)
chakracore_init();
if (dll_chakracore_init)
dll_chakracore_init();

if (chakracore_set_printf) {
chakracore_set_printf(printf);
}

return 1;
}

int chakracore_eval(const char *code) {
if (dll_chakracore_eval == NULL) {
printf("dll_chakracore_eval == NULL\n");
return 0;
}
return dll_chakracore_eval(code);
}
10 changes: 9 additions & 1 deletion chakracore.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
#pragma once

int chakracore_prepare();


typedef int(*printf_t)(const char *format, ...);
typedef int(*chakracore_init_t)();
typedef int(*chakracore_set_printf_t)(printf_t);
typedef int(*chakracore_eval_t)(const char *code);

int chakracore_prepare(printf_t printer);
int chakracore_eval(const char *code);
15 changes: 12 additions & 3 deletions postevent.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
cd Release
upx.exe mss32.dll
cp mss32.dll "C:\Program Files (x86)\Steam\steamapps\common\Call of Duty 2\mss32.dll"
@echo off

if %username% == php (
cd Release
upx.exe mss32.dll
cp mss32.dll "C:\Program Files (x86)\Steam\steamapps\common\Call of Duty 2\mss32.dll"
)

if %username% == kung (
cd Release
copy mss32.dll C:\games\cod2_1_3_clean_for_mapping
)
14 changes: 12 additions & 2 deletions test_chakracore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
#include "chakracore.h"

int main() {
chakracore_prepare();
chakracore_prepare(printf);
chakracore_eval("console.log(\"^1hai\");");
chakracore_eval("console.log(1);");
chakracore_eval("console.log(2);");
chakracore_eval("console.log(3);");
chakracore_eval("console.log(4);");
chakracore_eval("console.log(5);");
chakracore_eval("a = 1");
chakracore_eval("b = 2");
chakracore_eval("c = a + b");
chakracore_eval("console.log(\"c is\", c)");
getchar();
}
}
5 changes: 5 additions & 0 deletions vs/f5/f5.vcxproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerWorkingDirectory>C:\games\cod2_1_3_clean_for_mapping\</LocalDebuggerWorkingDirectory>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerCommand>C:\games\cod2_1_3_clean_for_mapping\iw3mp.exe</LocalDebuggerCommand>
<LocalDebuggerWorkingDirectory>C:\games\cod2_1_3_clean_for_mapping</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>

0 comments on commit 0c42b1e

Please sign in to comment.