尝试重写 dofile 文件流成功
This commit is contained in:
parent
6237ecd17f
commit
b2d797c480
|
|
@ -1,5 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#define _CRT_SECURE_NO_WARNINGS
|
||||||
#define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容
|
#define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容
|
||||||
// Windows 头文件
|
// Windows 头文件
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
@ -7,4 +7,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "squirrel.h"
|
#include "squirrel.h"
|
||||||
#include "MinHook.h"
|
#include "MinHook.h"
|
||||||
|
|
||||||
|
#include <malloc.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
@ -111,6 +111,7 @@ typedef void* (SQDOFILEFunc)(uint32_t v, const wchar_t* filename, bool retval, b
|
||||||
static SQDOFILEFunc* SQDOFILE = (SQDOFILEFunc*)0x1356240;
|
static SQDOFILEFunc* SQDOFILE = (SQDOFILEFunc*)0x1356240;
|
||||||
|
|
||||||
|
|
||||||
|
typedef void*(*SQFILE)();
|
||||||
//SQ_io_file_lexfeed_编码
|
//SQ_io_file_lexfeed_编码
|
||||||
//typedef int(LSQLEXREADFUNC)(int n);
|
//typedef int(LSQLEXREADFUNC)(int n);
|
||||||
typedef int(*LSQLEXREADFUNC)(int n);
|
typedef int(*LSQLEXREADFUNC)(int n);
|
||||||
|
|
@ -119,7 +120,7 @@ static LSQLEXREADFUNC SQ_io_file_lexfeed_UCS2_BE = (LSQLEXREADFUNC)0x1356050;
|
||||||
static LSQLEXREADFUNC SQ_io_file_lexfeed_UCS2_LE = (LSQLEXREADFUNC)0x1356020;
|
static LSQLEXREADFUNC SQ_io_file_lexfeed_UCS2_LE = (LSQLEXREADFUNC)0x1356020;
|
||||||
static LSQLEXREADFUNC SQ_io_file_lexfeed_UTF8 = (LSQLEXREADFUNC)0x1355F90;
|
static LSQLEXREADFUNC SQ_io_file_lexfeed_UTF8 = (LSQLEXREADFUNC)0x1355F90;
|
||||||
//SQfopen
|
//SQfopen
|
||||||
typedef void* (SQfopenFunc)(const wchar_t* filename, const wchar_t* type);
|
typedef SQFILE* (SQfopenFunc)(const wchar_t* filename, const wchar_t* type);
|
||||||
static SQfopenFunc* SQfopen = (SQfopenFunc*)0x1355DC0;
|
static SQfopenFunc* SQfopen = (SQfopenFunc*)0x1355DC0;
|
||||||
//SQfread
|
//SQfread
|
||||||
typedef int(SQfreadFunc)(void* buffer, int a, int b, void* file);
|
typedef int(SQfreadFunc)(void* buffer, int a, int b, void* file);
|
||||||
|
|
|
||||||
39
test/函数块.cpp
39
test/函数块.cpp
|
|
@ -240,7 +240,9 @@ int GetEquAddr(int addr)
|
||||||
//¼ÓÔØ
|
//¼ÓÔØ
|
||||||
static int SQloadfile(uint32_t v, const wchar_t* filename, bool printerror)
|
static int SQloadfile(uint32_t v, const wchar_t* filename, bool printerror)
|
||||||
{
|
{
|
||||||
void* file = SQfopen(filename, L"rb");
|
SQFILE* file = SQfopen(filename, L"rb+");
|
||||||
|
//FILE* file;
|
||||||
|
//file = fopen(filename, "rb");
|
||||||
int ret;
|
int ret;
|
||||||
unsigned short us;
|
unsigned short us;
|
||||||
unsigned char uc;
|
unsigned char uc;
|
||||||
|
|
@ -283,18 +285,26 @@ static int SQloadfile(uint32_t v, const wchar_t* filename, bool printerror)
|
||||||
default: SQfseek(file, 0, 2); break; // ascii
|
default: SQfseek(file, 0, 2); break; // ascii
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *add = "newstr";
|
char* nstr = (char*)"IIIAAAB <- 6648";
|
||||||
int prevpos = SQftell(file);
|
//SQwrite(&add, 1, sizeof(add), file);
|
||||||
|
SQwrite(nstr, sizeof(nstr), strlen(nstr), file);
|
||||||
|
|
||||||
SQfseek(file, 0, 1);
|
SQfseek(file, 0, 1);
|
||||||
int length = SQftell(file);
|
int length = SQftell(file);
|
||||||
SQfseek(file, prevpos, 2);
|
SQfseek(file, 0, 2);
|
||||||
char temp[256];
|
std::cout << "lenth:" << length << std::endl;
|
||||||
SQwrite(&add, 1, sizeof(add), file);
|
//char temp[256];
|
||||||
SQfread(&temp, length + 10, sizeof(temp), file);
|
char* temp = new char[length];
|
||||||
std::cout << temp << std::endl;
|
//SQwrite(&add, 1, sizeof(add), file);
|
||||||
|
SQfread(temp, sizeof(temp), length, file);
|
||||||
|
temp[length] = '\0';
|
||||||
|
printf(temp);
|
||||||
|
printf("\n");
|
||||||
|
//std::cout << temp << std::endl;
|
||||||
|
|
||||||
|
//char* temp = new char[16 * 4];
|
||||||
|
|
||||||
|
SQfseek(file, 0, 2);
|
||||||
if (SQ_Compile(v, func, file, filename, printerror) >= 0)
|
if (SQ_Compile(v, func, file, filename, printerror) >= 0)
|
||||||
{
|
{
|
||||||
SQ__Fclose(file);
|
SQ__Fclose(file);
|
||||||
|
|
@ -361,7 +371,6 @@ void RegisterNutApi(const wchar_t* funcName, void* funcAddr, uint32_t v)
|
||||||
static int sq_Test(uint32_t v)
|
static int sq_Test(uint32_t v)
|
||||||
{
|
{
|
||||||
//sq_pushinteger(v, n1);
|
//sq_pushinteger(v, n1);
|
||||||
SQdofile(v, L"1.cpp", false, false);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
//¶ÁÈËÎï »ò ×°±¸ÊôÐÔ
|
//¶ÁÈËÎï »ò ×°±¸ÊôÐÔ
|
||||||
|
|
@ -618,6 +627,14 @@ static int LDofile(uint32_t v)
|
||||||
{
|
{
|
||||||
SQGetString(v, 2, &n1);
|
SQGetString(v, 2, &n1);
|
||||||
SQPopTop(v);
|
SQPopTop(v);
|
||||||
|
/*
|
||||||
|
size_t len = wcslen(n1) + 1;
|
||||||
|
size_t converted = 0;
|
||||||
|
char* CStr;
|
||||||
|
CStr = (char*)malloc(len * sizeof(char));
|
||||||
|
wcstombs_s(&converted, CStr, len, n1, _TRUNCATE);
|
||||||
|
*/
|
||||||
|
|
||||||
SQdofile(v, n1, false, false);
|
SQdofile(v, n1, false, false);
|
||||||
SQPushBool(v, true);
|
SQPushBool(v, true);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue